Addition of C1 branch.

This commit is contained in:
MobiusDevelopment
2019-11-20 21:08:33 +00:00
parent 2630024926
commit 1e5fa7291f
1106 changed files with 102537 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius;
import org.l2jmobius.util.PropertiesParser;
/**
* @author Mobius
*/
public class Config
{
// --------------------------------------------------
// Constants
// --------------------------------------------------
public static final String EOL = System.lineSeparator();
// --------------------------------------------------
// Config File Definitions
// --------------------------------------------------
private static final String SERVER_CONFIG_FILE = "config/server.ini";
private static final String RATES_CONFIG_FILE = "config/rates.ini";
// Game
public static String _ip;
public static int SERVER_PORT;
public static String SERVER_HOST_NAME;
public static int CLIENT_PROTOCOL_VERSION;
public static int MAXIMUM_ONLINE_PLAYERS;
// Login
public static String LOGIN_HOST_NAME;
public static String EXTERNAL_HOST_NAME;
public static String INTERNAL_HOST_NAME;
public static boolean AUTO_CREATE_ACCOUNTS;
// Other
public static boolean LOG_UNKNOWN_PACKETS;
// Rates
public static float RATE_XP;
public static float RATE_SP;
public static float RATE_DROP;
public static float RATE_ADENA;
public static void load()
{
// Load server config file (if exists)
final PropertiesParser serverSettings = new PropertiesParser(SERVER_CONFIG_FILE);
// Game
SERVER_HOST_NAME = serverSettings.getString("GameserverHostname", "*");
SERVER_PORT = serverSettings.getInt("GameserverPort", 7777);
CLIENT_PROTOCOL_VERSION = serverSettings.getInt("ClientProtocolVersion", 417);
MAXIMUM_ONLINE_PLAYERS = serverSettings.getInt("MaximumOnlineUsers", 2000);
// Login
LOGIN_HOST_NAME = serverSettings.getString("LoginserverHostname", "*");
EXTERNAL_HOST_NAME = serverSettings.getString("ExternalHostname", "127.0.0.1");
if (EXTERNAL_HOST_NAME == null)
{
EXTERNAL_HOST_NAME = "localhost";
}
INTERNAL_HOST_NAME = serverSettings.getString("InternalHostname", "127.0.0.1");
if (INTERNAL_HOST_NAME == null)
{
INTERNAL_HOST_NAME = "localhost";
}
AUTO_CREATE_ACCOUNTS = serverSettings.getBoolean("AutoCreateAccounts", true);
// Other
LOG_UNKNOWN_PACKETS = serverSettings.getBoolean("LogUnknownPackets", false);
// Load rates config file (if exists)
final PropertiesParser ratesSettings = new PropertiesParser(RATES_CONFIG_FILE);
RATE_XP = ratesSettings.getFloat("RateXp", 1);
RATE_SP = ratesSettings.getFloat("RateSp", 1);
RATE_DROP = ratesSettings.getFloat("RateDrop", 1);
RATE_ADENA = ratesSettings.getFloat("RateAdena", 1);
}
}

View File

@@ -0,0 +1,62 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.logging.LogManager;
import org.l2jmobius.gameserver.GameServer;
import org.l2jmobius.gameserver.ui.Gui;
import org.l2jmobius.loginserver.LoginServer;
public class Server
{
public static void main(String[] args) throws Exception
{
// Create log folder
final File logFolder = new File(".", "log");
logFolder.mkdir();
// Create input stream for log file -- or store file data into memory
try (InputStream is = new FileInputStream(new File("log.cfg")))
{
LogManager.getLogManager().readConfiguration(is);
}
// Load configs.
Config.load();
// GUI
if (!GraphicsEnvironment.isHeadless())
{
System.out.println("Server: Running in GUI mode.");
new Gui();
}
// Start game server.
GameServer gameServer = new GameServer();
gameServer.start();
// Start login server.
LoginServer loginServer = new LoginServer();
loginServer.start();
}
}

View File

@@ -0,0 +1,203 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.accountmanager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
public class AccountManager
{
private static String _uname = "";
private static String _pass = "";
private static String _level = "";
private static String _mode = "";
public static void main(String[] args) throws IOException, NoSuchAlgorithmException
{
System.out.println("Welcome to l2j account manager.");
System.out.println("Please choose one: ");
System.out.println("1 - Create new account or update existing one (change pass and access level)");
System.out.println("2 - Change access level");
System.out.println("3 - Delete existing account (this option _keeps_ character files)");
System.out.println("4 - List accounts & access levels");
System.out.println("5 - exit");
LineNumberReader _in = new LineNumberReader(new InputStreamReader(System.in));
while (!(_mode.equals("1") || _mode.equals("2") || _mode.equals("3") || _mode.equals("4") || _mode.equals("5")))
{
System.out.print("Your choice: ");
_mode = _in.readLine();
}
if (_mode.equals("1") || _mode.equals("2") || _mode.equals("3"))
{
if (_mode.equals("1") || _mode.equals("2") || _mode.equals("3"))
{
while (_uname.length() == 0)
{
System.out.print("username: ");
_uname = _in.readLine();
}
}
if (_mode.equals("1"))
{
while (_pass.length() == 0)
{
System.out.print("password: ");
_pass = _in.readLine();
}
}
if (_mode.equals("1") || _mode.equals("2"))
{
while (_level.length() == 0)
{
System.out.print("access level: ");
_level = _in.readLine();
}
}
}
if (_mode.equals("3"))
{
System.out.print("Do you really want to delete this account ? Y/N : ");
String yesno = _in.readLine();
if (!yesno.equals("Y"))
{
_mode = "5";
}
}
if (!_mode.equals("4") && !_mode.equals("5"))
{
AccountManager.updateAccounts("data/accounts.txt", "data/logins.tmp");
}
if (_mode.equals("4"))
{
AccountManager.printAccInfo("data/accounts.txt");
}
System.out.println("Have fun playing lineage2.");
}
private static void printAccInfo(String fin) throws FileNotFoundException, IOException
{
File _test = new File(fin);
if (!_test.exists())
{
_test.createNewFile();
}
FileInputStream in = new FileInputStream(fin);
@SuppressWarnings("resource")
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(in));
String line = null;
int count = 0;
System.out.println("--------------");
System.out.println("Account -> Access Level");
while ((line = lnr.readLine()) != null)
{
System.out.println(line.substring(0, line.indexOf("\t")) + " -> " + line.substring(line.lastIndexOf("\t")));
++count;
}
System.out.println("Number of accounts: " + count);
}
private static void updateAccounts(String fin, String fout) throws FileNotFoundException, IOException, NoSuchAlgorithmException
{
File _test = new File(fin);
if (!_test.exists())
{
_test.createNewFile();
}
FileInputStream in = new FileInputStream(fin);
FileWriter out = new FileWriter(fout);
MessageDigest md = MessageDigest.getInstance("SHA");
byte[] newpass = _pass.getBytes("UTF-8");
newpass = md.digest(newpass);
try
{
@SuppressWarnings("resource")
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(in));
String line = null;
boolean added = false;
while ((line = lnr.readLine()) != null)
{
if (line.startsWith(_uname))
{
if (_mode.equals("1"))
{
line = _uname + "\t" + Base64.getEncoder().encodeToString(newpass) + "\t" + _level;
added = true;
System.out.println("Password/access level changed for user " + _uname);
}
else if (_mode.equals("2"))
{
line = line.substring(0, line.lastIndexOf("\t") + 1) + _level;
added = true;
System.out.println("Access level changed for user " + _uname);
}
else if (_mode.equals("3"))
{
line = "";
System.out.println("Account for user " + _uname + " deleted");
}
}
if (line == "")
{
continue;
}
out.write(line + "\r\n");
}
if (!added && _mode.equals("1"))
{
out.write(_uname + "\t" + Base64.getEncoder().encodeToString(newpass) + "\t" + _level + "\r\n");
System.out.println("New account added for user " + _uname);
}
}
catch (Throwable throwable)
{
try
{
out.close();
in.close();
File _fin = new File(fin);
File _fout = new File(fout);
_fin.delete();
_fout.renameTo(_fin);
}
catch (Exception e)
{
}
throw throwable;
}
try
{
out.close();
in.close();
File _fin = new File(fin);
File _fout = new File(fout);
_fin.delete();
_fout.renameTo(_fin);
}
catch (Exception e)
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,218 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.CreatureSay;
import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
public class Announcements
{
private static Logger _log = Logger.getLogger(Announcements.class.getName());
private static Announcements _instance;
private final List<String> _announcements = new ArrayList<>();
public Announcements()
{
loadAnnouncements();
}
public static Announcements getInstance()
{
if (_instance == null)
{
_instance = new Announcements();
}
return _instance;
}
public void loadAnnouncements()
{
_announcements.clear();
File file = new File("data/announcements.txt");
if (file.exists())
{
try
{
readFromDisk(file);
}
catch (IOException e)
{
e.printStackTrace();
}
}
else
{
_log.config("data/announcements.txt does not exist.");
}
}
public void showAnnouncements(PlayerInstance activeChar)
{
for (int i = 0; i < _announcements.size(); ++i)
{
CreatureSay cs = new CreatureSay(0, 10, activeChar.getName(), _announcements.get(i).toString());
activeChar.sendPacket(cs);
}
}
public void listAnnouncements(PlayerInstance activeChar)
{
NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
StringBuffer replyMSG = new StringBuffer("<html><title>Announcements:</title>");
replyMSG.append("<body>");
for (int i = 0; i < _announcements.size(); ++i)
{
replyMSG.append(_announcements.get(i).toString());
replyMSG.append("<center><button value=\"Delete\" action=\"bypass -h admin_del_announcement " + i + "\" width=110 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></center>");
}
replyMSG.append("<br>");
replyMSG.append("Add a new announcement:");
replyMSG.append("<center><multiedit var=\"add_announcement\" width=240 height=40></center>");
replyMSG.append("<center><button value=\"Add\" action=\"bypass -h admin_add_announcement $add_announcement\" width=110 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></center>");
replyMSG.append("<center><button value=\"Reload\" action=\"bypass -h admin_reload_announcements\" width=110 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></center>");
replyMSG.append("<center><button value=\"Announce\" action=\"bypass -h admin_announce_announcements\" width=110 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></center>");
replyMSG.append("<br><br>");
replyMSG.append("<right><button value=\"Back\" action=\"bypass -h admin_show\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></right>");
replyMSG.append("</body></html>");
adminReply.setHtml(replyMSG.toString());
activeChar.sendPacket(adminReply);
}
public void addAnnouncement(String text)
{
_announcements.add(text);
saveToDisk();
}
public void delAnnouncement(int line)
{
_announcements.remove(line);
saveToDisk();
}
private void readFromDisk(File file) throws IOException
{
BufferedReader lnr = null;
int i = 0;
String line = null;
try
{
lnr = new LineNumberReader(new FileReader(file));
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
StringTokenizer st = new StringTokenizer(line, "\n\r");
if (!st.hasMoreTokens())
{
continue;
}
String announcement = st.nextToken();
_announcements.add(announcement);
++i;
}
_log.config("Loaded " + i + " announcements.");
lnr.close();
return;
}
catch (FileNotFoundException e)
{
try
{
if (lnr != null)
{
lnr.close();
}
return;
}
catch (IOException e1)
{
try
{
e1.printStackTrace();
}
catch (Throwable throwable)
{
try
{
lnr.close();
throw throwable;
}
catch (Exception e2)
{
// empty catch block
}
throw throwable;
}
try
{
lnr.close();
return;
}
catch (Exception e2)
{
return;
}
}
}
}
private void saveToDisk()
{
File file = new File("data/announcements.txt");
FileWriter save = null;
try
{
save = new FileWriter(file);
for (int i = 0; i < _announcements.size(); ++i)
{
save.write(_announcements.get(i).toString());
save.write("\r\n");
}
}
catch (IOException e)
{
_log.warning("Saving the announcements file has failed: " + e);
e.printStackTrace();
}
finally
{
try
{
if (save != null)
{
save.close();
}
}
catch (Exception e1)
{
}
}
}
}

View File

@@ -0,0 +1,794 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.List;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.data.CharNameTable;
import org.l2jmobius.gameserver.data.ClanTable;
import org.l2jmobius.gameserver.data.ItemTable;
import org.l2jmobius.gameserver.data.SkillTable;
import org.l2jmobius.gameserver.model.Clan;
import org.l2jmobius.gameserver.model.ShortCut;
import org.l2jmobius.gameserver.model.Skill;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.PacketHandler;
import org.l2jmobius.gameserver.templates.L2Item;
import org.l2jmobius.loginserver.LoginController;
public class ClientThread extends Thread
{
private static Logger _log = Logger.getLogger(ClientThread.class.getName());
private String _loginName;
private PlayerInstance _activeChar;
private final int _sessionId;
private final byte[] _cryptkey = new byte[]
{
-108,
53,
0,
0,
-95,
108,
84,
-121
};
private File _charFolder;
private final long _autoSaveTime;
private final Connection _connection;
private final PacketHandler _handler;
private final World _world;
private int _accessLevel;
public ClientThread(Socket client) throws IOException
{
_connection = new Connection(client, _cryptkey);
_sessionId = 305419896;
_handler = new PacketHandler(this);
_world = World.getInstance();
_autoSaveTime = 900000L;
start();
}
@Override
public void run()
{
_log.fine("thread[C] started");
long starttime = System.currentTimeMillis();
try
{
try
{
do
{
if ((_activeChar != null) && (_autoSaveTime < (System.currentTimeMillis() - starttime)))
{
saveCharToDisk(_activeChar);
starttime = System.currentTimeMillis();
}
byte[] decrypt = _connection.getPacket();
_handler.handlePacket(decrypt);
}
while (true);
}
catch (IOException io)
{
try
{
if (_activeChar != null)
{
_activeChar.deleteMe();
try
{
saveCharToDisk(_activeChar);
}
catch (Exception e2)
{
// empty catch block
}
}
_connection.close();
}
catch (Exception e1)
{
_log.warning(e1.toString());
}
finally
{
LoginController.getInstance().removeGameServerLogin(getLoginName());
}
}
catch (Exception e)
{
e.printStackTrace();
try
{
if (_activeChar != null)
{
_activeChar.deleteMe();
try
{
saveCharToDisk(_activeChar);
}
catch (Exception e2)
{
// empty catch block
}
}
_connection.close();
LoginController.getInstance().removeGameServerLogin(getLoginName());
}
catch (Exception e1)
{
try
{
}
catch (Throwable throwable)
{
LoginController.getInstance().removeGameServerLogin(getLoginName());
throw throwable;
}
_log.warning(e1.toString());
LoginController.getInstance().removeGameServerLogin(getLoginName());
}
}
}
catch (Throwable throwable)
{
try
{
if (_activeChar != null)
{
_activeChar.deleteMe();
try
{
saveCharToDisk(_activeChar);
}
catch (Exception e2)
{
// empty catch block
}
}
_connection.close();
LoginController.getInstance().removeGameServerLogin(getLoginName());
}
catch (Exception e1)
{
try
{
}
catch (Throwable throwable2)
{
LoginController.getInstance().removeGameServerLogin(getLoginName());
throw throwable2;
}
_log.warning(e1.toString());
LoginController.getInstance().removeGameServerLogin(getLoginName());
}
throw throwable;
}
_log.fine("gameserver thread[C] stopped");
}
public void saveCharToDisk(PlayerInstance cha)
{
if (_charFolder != null)
{
File saveFile = new File(_charFolder, cha.getName() + "_char.csv");
storeChar(cha, saveFile);
saveFile = new File(_charFolder, cha.getName() + "_items.csv");
storeInventory(cha, saveFile);
saveFile = new File(_charFolder, cha.getName() + "_skills.csv");
storeSkills(cha, saveFile);
saveFile = new File(_charFolder, cha.getName() + "_shortcuts.csv");
storeShortcuts(cha, saveFile);
saveFile = new File(_charFolder, cha.getName() + "_warehouse.csv");
storeWarehouse(cha, saveFile);
}
IdFactory.getInstance().saveCurrentState();
}
private void storeShortcuts(PlayerInstance cha, File saveFile)
{
OutputStreamWriter out = null;
try
{
ShortCut[] scs = cha.getAllShortCuts();
out = new FileWriter(saveFile);
out.write("slot;type;id;level;unknown\r\n");
for (ShortCut sc : scs)
{
out.write(sc.getSlot() + ";");
out.write(sc.getType() + ";");
out.write(sc.getId() + ";");
out.write(sc.getLevel() + ";");
out.write(sc.getUnk() + "\r\n");
}
}
catch (Exception e)
{
_log.warning("could not store shortcuts:" + e.toString());
}
finally
{
try
{
if (out != null)
{
out.close();
}
}
catch (Exception e1)
{
}
}
}
public void deleteCharFromDisk(int charslot)
{
if (getActiveChar() != null)
{
saveCharToDisk(getActiveChar());
_log.fine("active Char saved");
_activeChar = null;
}
File[] chars = _charFolder.listFiles((FilenameFilter) (dir, name) -> name.endsWith("_char.csv"));
chars[charslot].delete();
chars = _charFolder.listFiles((FilenameFilter) (dir, name) -> name.endsWith("_items.csv"));
chars[charslot].delete();
chars = _charFolder.listFiles((FilenameFilter) (dir, name) -> name.endsWith("_skills.csv"));
chars[charslot].delete();
chars = _charFolder.listFiles((FilenameFilter) (dir, name) -> name.endsWith("_shortcuts.csv"));
chars[charslot].delete();
chars = _charFolder.listFiles((FilenameFilter) (dir, name) -> name.endsWith("_warehouse.csv"));
chars[charslot].delete();
CharNameTable.getInstance().deleteCharName(chars[charslot].getName().replaceAll("_warehouse.csv", "").toLowerCase());
}
public PlayerInstance loadCharFromDisk(int charslot)
{
PlayerInstance character = new PlayerInstance();
File[] chars = _charFolder.listFiles((FilenameFilter) (dir, name) -> name.endsWith("_char.csv"));
character = restoreChar(chars[charslot]);
if (character != null)
{
restoreInventory(new File(_charFolder, character.getName() + "_items.csv"), character);
restoreSkills(new File(_charFolder, character.getName() + "_skills.csv"), character);
restoreShortCuts(new File(_charFolder, character.getName() + "_shortcuts.csv"), character);
restoreWarehouse(new File(_charFolder, character.getName() + "_warehouse.csv"), character);
if (character.getClanId() != 0)
{
Clan clan = ClanTable.getInstance().getClan(character.getClanId());
if (!clan.isMember(character.getName()))
{
character.setClanId(0);
character.setTitle("");
}
else
{
character.setClan(clan);
character.setIsClanLeader(clan.getLeaderId() == character.getObjectId());
}
}
}
else
{
_log.warning("could not restore " + chars[charslot]);
}
return character;
}
private void restoreShortCuts(File file, PlayerInstance restored)
{
BufferedReader lnr = null;
try
{
lnr = new LineNumberReader(new BufferedReader(new FileReader(file)));
((LineNumberReader) lnr).readLine();
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
StringTokenizer st = new StringTokenizer(line, ";");
int slot = Integer.parseInt(st.nextToken());
int type = Integer.parseInt(st.nextToken());
int id = Integer.parseInt(st.nextToken());
int level = Integer.parseInt(st.nextToken());
int unk = Integer.parseInt(st.nextToken());
ShortCut sc = new ShortCut(slot, type, id, level, unk);
restored.registerShortCut(sc);
}
}
catch (Exception e)
{
_log.warning("could not restore shortcuts:" + e);
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private void storeInventory(PlayerInstance cha, File saveFile)
{
OutputStreamWriter out = null;
try
{
ItemInstance[] items = cha.getInventory().getItems();
out = new FileWriter(saveFile);
out.write("objectId;itemId;name;count;price;equipSlot;\r\n");
for (ItemInstance item : items)
{
out.write(item.getObjectId() + ";");
out.write(item.getItemId() + ";");
out.write(item.getItem().getName() + ";");
out.write(item.getCount() + ";");
out.write(item.getPrice() + ";");
if ((item.getItemId() == 17) || (item.getItemId() == 1341) || (item.getItemId() == 1342) || (item.getItemId() == 1343) || (item.getItemId() == 1344) || (item.getItemId() == 1345))
{
out.write("-1\r\n");
continue;
}
out.write(item.getEquipSlot() + "\r\n");
}
}
catch (Exception e)
{
_log.warning("could not store inventory:" + e);
}
finally
{
try
{
if (out != null)
{
out.close();
}
}
catch (Exception e1)
{
}
}
}
private void storeSkills(PlayerInstance cha, File saveFile)
{
OutputStreamWriter out = null;
try
{
Skill[] skills = cha.getAllSkills();
out = new FileWriter(saveFile);
out.write("skillId;skillLevel;skillName\r\n");
for (Skill skill : skills)
{
out.write(skill.getId() + ";");
out.write(skill.getLevel() + ";");
out.write(skill.getName() + "\r\n");
}
}
catch (Exception e)
{
_log.warning("could not store skills:" + e);
}
finally
{
try
{
if (out != null)
{
out.close();
}
}
catch (Exception e1)
{
}
}
}
private void storeChar(PlayerInstance cha, File charFile)
{
FileWriter out = null;
try
{
out = new FileWriter(charFile);
out.write("objId;charName;level;maxHp;curHp;maxMp;curMp;acc;crit;evasion;mAtk;mDef;mSpd;pAtk;pDef;pSpd;runSpd;walkSpd;str;con;dex;int;men;wit;face;hairStyle;hairColor;sex;heading;x;y;z;unk1;unk2;colRad;colHeight;exp;sp;karma;pvpkills;pkkills;clanid;maxload;race;classid;deletetime;cancraft;title;allyId\r\n");
out.write(cha.getObjectId() + ";");
out.write(cha.getName() + ";");
out.write(cha.getLevel() + ";");
out.write(cha.getMaxHp() + ";");
out.write(cha.getCurrentHp() + ";");
out.write(cha.getMaxMp() + ";");
out.write(cha.getCurrentMp() + ";");
out.write(cha.getAccuracy() + ";");
out.write(cha.getCriticalHit() + ";");
out.write(cha.getEvasionRate() + ";");
out.write(cha.getMagicalAttack() + ";");
out.write(cha.getMagicalDefense() + ";");
out.write(cha.getMagicalSpeed() + ";");
out.write(cha.getPhysicalAttack() + ";");
out.write(cha.getPhysicalDefense() + ";");
out.write(cha.getPhysicalSpeed() + ";");
out.write(cha.getRunSpeed() + ";");
out.write(cha.getWalkSpeed() + ";");
out.write(cha.getStr() + ";");
out.write(cha.getCon() + ";");
out.write(cha.getDex() + ";");
out.write(cha.getInt() + ";");
out.write(cha.getMen() + ";");
out.write(cha.getWit() + ";");
out.write(cha.getFace() + ";");
out.write(cha.getHairStyle() + ";");
out.write(cha.getHairColor() + ";");
out.write(cha.getSex() + ";");
out.write(cha.getHeading() + ";");
out.write(cha.getX() + ";");
out.write(cha.getY() + ";");
out.write(cha.getZ() + ";");
out.write(cha.getMovementMultiplier() + ";");
out.write(cha.getAttackSpeedMultiplier() + ";");
out.write(cha.getCollisionRadius() + ";");
out.write(cha.getCollisionHeight() + ";");
out.write(cha.getExp() + ";");
out.write(cha.getSp() + ";");
out.write(cha.getKarma() + ";");
out.write(cha.getPvpKills() + ";");
out.write(cha.getPkKills() + ";");
out.write(cha.getClanId() + ";");
out.write(cha.getMaxLoad() + ";");
out.write(cha.getRace() + ";");
out.write(cha.getClassId() + ";");
out.write(cha.getDeleteTimer() + ";");
out.write(cha.getCanCraft() + ";");
out.write(" " + cha.getTitle() + ";");
out.write(cha.getAllyId() + ";");
}
catch (IOException e)
{
_log.warning("could not store char data:" + e);
}
finally
{
try
{
if (out != null)
{
out.close();
}
}
catch (Exception e1)
{
}
}
}
private void restoreWarehouse(File wfile, PlayerInstance cha)
{
BufferedReader lnr = null;
try
{
lnr = new LineNumberReader(new BufferedReader(new FileReader(wfile)));
((LineNumberReader) lnr).readLine();
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
StringTokenizer st = new StringTokenizer(line, ";");
ItemInstance item = new ItemInstance();
item.setObjectId(Integer.parseInt(st.nextToken()));
int itemId = Integer.parseInt(st.nextToken());
L2Item itemTemp = ItemTable.getInstance().getTemplate(itemId);
item.setItem(itemTemp);
st.nextToken();
item.setCount(Integer.parseInt(st.nextToken()));
cha.getWarehouse().addItem(item);
_world.storeObject(item);
}
}
catch (Exception e)
{
_log.warning("could not restore warehouse:" + e);
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private void storeWarehouse(PlayerInstance cha, File saveFile)
{
OutputStreamWriter out = null;
try
{
List<ItemInstance> items = cha.getWarehouse().getItems();
out = new FileWriter(saveFile);
out.write("#objectId;itemId;name;count;\n");
for (int i = 0; i < items.size(); ++i)
{
ItemInstance item = items.get(i);
out.write(item.getObjectId() + ";");
out.write(item.getItemId() + ";");
out.write(item.getItem().getName() + ";");
out.write(item.getCount() + "\n");
}
}
catch (Exception e)
{
_log.warning("could not store warehouse:" + e);
}
finally
{
try
{
if (out != null)
{
out.close();
}
}
catch (Exception e1)
{
}
}
}
private void restoreInventory(File inventory, PlayerInstance cha)
{
BufferedReader lnr = null;
try
{
lnr = new LineNumberReader(new BufferedReader(new FileReader(inventory)));
((LineNumberReader) lnr).readLine();
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
StringTokenizer st = new StringTokenizer(line, ";");
ItemInstance item = new ItemInstance();
item.setObjectId(Integer.parseInt(st.nextToken()));
int itemId = Integer.parseInt(st.nextToken());
L2Item itemTemp = ItemTable.getInstance().getTemplate(itemId);
item.setItem(itemTemp);
st.nextToken();
item.setCount(Integer.parseInt(st.nextToken()));
item.setPrice(Integer.parseInt(st.nextToken()));
item.setEquipSlot(Integer.parseInt(st.nextToken()));
cha.getInventory().addItem(item);
if (item.isEquipped())
{
cha.getInventory().equipItem(item);
}
_world.storeObject(item);
}
}
catch (Exception e)
{
_log.warning("could not restore inventory:" + e);
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private void restoreSkills(File inventory, PlayerInstance cha)
{
BufferedReader lnr = null;
try
{
lnr = new LineNumberReader(new BufferedReader(new FileReader(inventory)));
((LineNumberReader) lnr).readLine();
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
StringTokenizer st = new StringTokenizer(line, ";");
int id = Integer.parseInt(st.nextToken());
int level = Integer.parseInt(st.nextToken());
st.nextToken();
Skill skill = SkillTable.getInstance().getInfo(id, level);
cha.addSkill(skill);
}
}
catch (Exception e)
{
_log.warning("could not restore skills:" + e);
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private PlayerInstance restoreChar(File charFile)
{
PlayerInstance oldChar = new PlayerInstance();
BufferedReader lnr = null;
try
{
lnr = new LineNumberReader(new BufferedReader(new FileReader(charFile)));
((LineNumberReader) lnr).readLine();
String line = ((LineNumberReader) lnr).readLine();
StringTokenizer st = new StringTokenizer(line, ";");
oldChar.setObjectId(Integer.parseInt(st.nextToken()));
oldChar.setName(st.nextToken());
oldChar.setLevel(Integer.parseInt(st.nextToken()));
oldChar.setMaxHp(Integer.parseInt(st.nextToken()));
oldChar.setCurrentHp(Double.parseDouble(st.nextToken()));
oldChar.setMaxMp(Integer.parseInt(st.nextToken()));
oldChar.setCurrentMp(Double.parseDouble(st.nextToken()));
oldChar.setAccuracy(Integer.parseInt(st.nextToken()));
oldChar.setCriticalHit(Integer.parseInt(st.nextToken()));
oldChar.setEvasionRate(Integer.parseInt(st.nextToken()));
oldChar.setMagicalAttack(Integer.parseInt(st.nextToken()));
oldChar.setMagicalDefense(Integer.parseInt(st.nextToken()));
oldChar.setMagicalSpeed(Integer.parseInt(st.nextToken()));
oldChar.setPhysicalAttack(Integer.parseInt(st.nextToken()));
oldChar.setPhysicalDefense(Integer.parseInt(st.nextToken()));
oldChar.setPhysicalSpeed(Integer.parseInt(st.nextToken()));
oldChar.setRunSpeed(Integer.parseInt(st.nextToken()));
oldChar.setWalkSpeed(Integer.parseInt(st.nextToken()));
oldChar.setStr(Integer.parseInt(st.nextToken()));
oldChar.setCon(Integer.parseInt(st.nextToken()));
oldChar.setDex(Integer.parseInt(st.nextToken()));
oldChar.setInt(Integer.parseInt(st.nextToken()));
oldChar.setMen(Integer.parseInt(st.nextToken()));
oldChar.setWit(Integer.parseInt(st.nextToken()));
oldChar.setFace(Integer.parseInt(st.nextToken()));
oldChar.setHairStyle(Integer.parseInt(st.nextToken()));
oldChar.setHairColor(Integer.parseInt(st.nextToken()));
oldChar.setSex(Integer.parseInt(st.nextToken()));
oldChar.setHeading(Integer.parseInt(st.nextToken()));
oldChar.setX(Integer.parseInt(st.nextToken()));
oldChar.setY(Integer.parseInt(st.nextToken()));
oldChar.setZ(Integer.parseInt(st.nextToken()));
oldChar.setMovementMultiplier(Double.parseDouble(st.nextToken()));
oldChar.setAttackSpeedMultiplier(Double.parseDouble(st.nextToken()));
oldChar.setCollisionRadius(Double.parseDouble(st.nextToken()));
oldChar.setCollisionHeight(Double.parseDouble(st.nextToken()));
oldChar.setExp(Integer.parseInt(st.nextToken()));
oldChar.setSp(Integer.parseInt(st.nextToken()));
oldChar.setKarma(Integer.parseInt(st.nextToken()));
oldChar.setPvpKills(Integer.parseInt(st.nextToken()));
oldChar.setPkKills(Integer.parseInt(st.nextToken()));
oldChar.setClanId(Integer.parseInt(st.nextToken()));
oldChar.setMaxLoad(Integer.parseInt(st.nextToken()));
oldChar.setRace(Integer.parseInt(st.nextToken()));
oldChar.setClassId(Integer.parseInt(st.nextToken()));
oldChar.setFistsWeaponItem(oldChar.findFistsWeaponItem(oldChar.getClassId()));
oldChar.setDeleteTimer(Integer.parseInt(st.nextToken()));
oldChar.setCanCraft(Integer.parseInt(st.nextToken()));
oldChar.setTitle(st.nextToken().trim());
oldChar.setAllyId(Integer.parseInt(st.nextToken()));
World.getInstance().storeObject(oldChar);
oldChar.setUptime(System.currentTimeMillis());
}
catch (Exception e)
{
_log.warning("could not restore char data:" + e);
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
return oldChar;
}
public Connection getConnection()
{
return _connection;
}
public PlayerInstance getActiveChar()
{
return _activeChar;
}
public int getSessionId()
{
return _sessionId;
}
public String getLoginName()
{
return _loginName;
}
public void setLoginFolder(String folder)
{
_charFolder = new File("data/accounts", _loginName);
_charFolder.mkdirs();
}
public void setLoginName(String loginName)
{
_loginName = loginName;
}
public void setActiveChar(PlayerInstance cha)
{
_activeChar = cha;
if (cha != null)
{
_activeChar.setNetConnection(_connection);
_world.storeObject(_activeChar);
}
}
public void setAccessLevel(int access)
{
_accessLevel = access;
}
public int getAccessLevel()
{
return _accessLevel;
}
}

View File

@@ -0,0 +1,200 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.StringTokenizer;
import org.l2jmobius.Config;
import org.l2jmobius.gameserver.data.CharTemplateTable;
import org.l2jmobius.gameserver.data.ExperienceTable;
import org.l2jmobius.gameserver.model.Clan;
import org.l2jmobius.gameserver.model.ClanMember;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.CreatureSay;
import org.l2jmobius.gameserver.network.serverpackets.ShowBoard;
public class CommunityBoard
{
private static CommunityBoard _instance;
public static CommunityBoard getInstance()
{
if (_instance == null)
{
_instance = new CommunityBoard();
}
return _instance;
}
public void handleCommands(ClientThread client, String command)
{
PlayerInstance activeChar = client.getActiveChar();
if (command.startsWith("bbs_"))
{
StringBuffer htmlCode = new StringBuffer("<html imgsrc=\"sek.cbui353\"><body><br><table border=0><tr><td FIXWIDTH=15></td><td align=center>L2J Community Board<img src=\"sek.cbui355\" width=610 height=1></td></tr><tr><td FIXWIDTH=15></td><td>");
if (command.equals("bbs_default"))
{
PlayerInstance[] players = World.getInstance().getAllPlayers();
htmlCode.append("<table border=0>");
int t = GameTimeController.getInstance().getGameTime();
int h = t / 60;
int m = t % 60;
SimpleDateFormat format = new SimpleDateFormat("h:mm a");
Calendar cal = Calendar.getInstance();
cal.set(11, h);
cal.set(12, m);
htmlCode.append("<tr><td>Game Time: " + format.format(cal.getTime()) + "</td></tr>");
htmlCode.append("<tr><td>XP Rate: " + Config.RATE_XP + "</td></tr>");
htmlCode.append("<tr><td>SP Rate: " + Config.RATE_SP + "</td></tr>");
htmlCode.append("<tr><td>Adena Rate: " + Config.RATE_ADENA + "</td></tr>");
htmlCode.append("<tr><td>Drop Rate: " + Config.RATE_DROP + "</td></tr>");
htmlCode.append("<tr><td><img src=\"sek.cbui355\" width=610 height=1><br></td></tr>");
htmlCode.append("<tr><td>" + players.length + " Player(s) Online:</td></tr><tr><td><table border=0><tr>");
int n = 1;
for (PlayerInstance player : players)
{
htmlCode.append("<td><a action=\"bypass bbs_player_info " + player.getName() + "\">" + player.getName() + "</a></td><td FIXWIDTH=15></td>");
if (n == 5)
{
htmlCode.append("</tr><tr>");
n = 0;
}
++n;
}
htmlCode.append("</tr></table></td></tr></table>");
}
else if (command.equals("bbs_top"))
{
htmlCode.append("<center>" + command + "</center>");
}
else if (command.equals("bbs_up"))
{
htmlCode.append("<center>" + command + "</center>");
}
else if (command.equals("bbs_favorate"))
{
htmlCode.append("<center>" + command + "</center>");
}
else if (command.equals("bbs_add_fav"))
{
htmlCode.append("<center>" + command + "</center>");
}
else if (command.equals("bbs_region"))
{
htmlCode.append("<center>" + command + "</center>");
}
else if (command.equals("bbs_clan"))
{
Clan clan = activeChar.getClan();
htmlCode.append("<table border=0><tr><td>" + clan.getName() + " (Level " + clan.getLevel() + "):</td></tr><tr><td><table border=0>");
String title = "";
if (!clan.getClanMember(clan.getLeaderName()).getTitle().equals(""))
{
title = "<td>[" + clan.getClanMember(clan.getLeaderName()).getTitle() + "]</td><td FIXWIDTH=5></td>";
}
String name = clan.getLeaderName();
if (clan.getClanMember(clan.getLeaderName()).isOnline())
{
name = "<a action=\"bypass bbs_player_info " + clan.getLeaderName() + "\">" + clan.getLeaderName() + "</a>";
}
htmlCode.append("<tr>" + title + "<td>" + name + "</td></tr>");
htmlCode.append("<tr><td><br></td></tr>");
ClanMember[] members = clan.getMembers();
for (ClanMember member : members)
{
if (member.getName() == clan.getLeaderName())
{
continue;
}
title = "";
if (!member.getTitle().equals(""))
{
title = "<td>[" + member.getTitle() + "]</td><td FIXWIDTH=5></td>";
}
name = member.getName();
if (member.isOnline())
{
name = "<a action=\"bypass bbs_player_info " + member.getName() + "\">" + member.getName() + "</a>";
}
htmlCode.append("<tr>" + title + "<td>" + name + "</td></tr>");
}
htmlCode.append("</table></td></tr></table>");
}
else if (command.startsWith("bbs_player_info"))
{
String name = command.substring(16);
PlayerInstance player = World.getInstance().getPlayer(name);
String sex = "Male";
if (player.getSex() == 1)
{
sex = "Female";
}
htmlCode.append("<table border=0><tr><td>" + player.getName() + " (" + sex + " " + CharTemplateTable.getInstance().getTemplate(player.getClassId()).getClassName() + "):</td></tr>");
htmlCode.append("<tr><td>Level: " + player.getLevel() + "</td></tr>");
htmlCode.append("<tr><td><br></td></tr>");
int nextLevelExp = 0;
int nextLevelExpNeeded = 0;
if (player.getLevel() < 60)
{
nextLevelExp = ExperienceTable.getInstance().getExp(player.getLevel() + 1);
nextLevelExpNeeded = ExperienceTable.getInstance().getExp(player.getLevel() + 1) - player.getExp();
}
htmlCode.append("<tr><td>Experience: " + player.getExp() + "/" + nextLevelExp + "</td></tr>");
htmlCode.append("<tr><td>Experience needed for level up: " + nextLevelExpNeeded + "</td></tr>");
htmlCode.append("<tr><td><br></td></tr>");
int uptime = (int) player.getUptime() / 1000;
int h = uptime / 3600;
int m = (uptime - (h * 3600)) / 60;
int s = uptime - (h * 3600) - (m * 60);
htmlCode.append("<tr><td>Uptime: " + h + "h " + m + "m " + s + "s</td></tr>");
htmlCode.append("<tr><td><br></td></tr>");
if (player.getClan() != null)
{
htmlCode.append("<tr><td>Clan: " + player.getClan().getName() + "</td></tr>");
htmlCode.append("<tr><td><br></td></tr>");
}
htmlCode.append("<tr><td><multiedit var=\"pm\" width=240 height=40><button value=\"Send PM\" action=\"bypass bbs_player_pm " + player.getName() + " $pm\" width=110 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr><tr><td><br><button value=\"Back\" action=\"bypass bbs_default\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr></table>");
}
else if (command.startsWith("bbs_player_pm"))
{
try
{
String val = command.substring(14);
StringTokenizer st = new StringTokenizer(val);
String name = st.nextToken();
String message = val.substring(name.length() + 1);
PlayerInstance reciever = World.getInstance().getPlayer(name);
CreatureSay cs = new CreatureSay(activeChar.getObjectId(), 2, activeChar.getName(), message);
reciever.sendPacket(cs);
activeChar.sendPacket(cs);
htmlCode.append("Message Sent<br><button value=\"Back\" action=\"bypass bbs_player_info " + reciever.getName() + "\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
}
catch (StringIndexOutOfBoundsException e)
{
// empty catch block
}
}
htmlCode.append("</td></tr></table></body></html>");
ShowBoard sb = new ShowBoard(activeChar, htmlCode.toString());
activeChar.sendPacket(sb);
}
}
}

View File

@@ -0,0 +1,188 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.network.serverpackets.ServerBasePacket;
public class Connection
{
private static Logger _log = Logger.getLogger(Connection.class.getName());
private final Crypt _inCrypt;
private final Crypt _outCrypt;
private final byte[] _cryptkey;
private final Socket _csocket;
private final InputStream _in;
private final OutputStream _out;
public Connection(Socket client, byte[] cryptKey) throws IOException
{
_csocket = client;
_in = client.getInputStream();
_out = new BufferedOutputStream(client.getOutputStream());
_inCrypt = new Crypt();
_outCrypt = new Crypt();
_cryptkey = cryptKey;
}
public byte[] getPacket() throws IOException
{
int receivedBytes;
int lengthHi = 0;
int lengthLo = 0;
int length = 0;
lengthLo = _in.read();
lengthHi = _in.read();
length = (lengthHi * 256) + lengthLo;
if (lengthHi < 0)
{
_log.warning("client terminated connection");
throw new IOException("EOF");
}
byte[] incoming = new byte[length];
incoming[0] = (byte) lengthLo;
incoming[1] = (byte) lengthHi;
int newBytes = 0;
for (receivedBytes = 0; (newBytes != -1) && (receivedBytes < (length - 2)); receivedBytes += newBytes)
{
newBytes = _in.read(incoming, 2, length - 2);
}
if (receivedBytes != (length - 2))
{
_log.warning("Incomplete Packet is sent to the server, closing connection.");
throw new IOException();
}
byte[] decrypt = new byte[incoming.length - 2];
System.arraycopy(incoming, 2, decrypt, 0, decrypt.length);
_inCrypt.decrypt(decrypt);
// int packetType = decrypt[0] & 0xFF;
return decrypt;
}
public void sendPacket(byte[] data) throws IOException
{
Connection connection = this;
synchronized (connection)
{
if (_log.isLoggable(Level.FINEST))
{
_log.finest("\n" + printData(data, data.length));
}
_outCrypt.encrypt(data);
int length = data.length + 2;
_out.write(length & 0xFF);
_out.write((length >> 8) & 0xFF);
_out.flush();
_out.write(data);
_out.flush();
}
}
public void sendPacket(ServerBasePacket bp) throws IOException
{
byte[] data = bp.getContent();
this.sendPacket(data);
}
public void activateCryptKey()
{
_inCrypt.setKey(_cryptkey);
_outCrypt.setKey(_cryptkey);
}
public byte[] getCryptKey()
{
return _cryptkey;
}
public void close() throws IOException
{
_csocket.close();
}
private String printData(byte[] data, int len)
{
int a;
int charpoint;
byte t1;
StringBuffer result = new StringBuffer();
int counter = 0;
for (int i = 0; i < len; ++i)
{
if ((counter % 16) == 0)
{
result.append(fillHex(i, 4) + ": ");
}
result.append(fillHex(data[i] & 0xFF, 2) + " ");
if (++counter != 16)
{
continue;
}
result.append(" ");
charpoint = i - 15;
for (a = 0; a < 16; ++a)
{
if (((t1 = data[charpoint++]) > 31) && (t1 < 128))
{
result.append((char) t1);
continue;
}
result.append('.');
}
result.append("\n");
counter = 0;
}
int rest = data.length % 16;
if (rest > 0)
{
for (int i = 0; i < (17 - rest); ++i)
{
result.append(" ");
}
charpoint = data.length - rest;
for (a = 0; a < rest; ++a)
{
if (((t1 = data[charpoint++]) > 31) && (t1 < 128))
{
result.append((char) t1);
continue;
}
result.append('.');
}
result.append("\n");
}
return result.toString();
}
private String fillHex(int data, int digits)
{
String number = Integer.toHexString(data);
for (int i = number.length(); i < digits; ++i)
{
number = "0" + number;
}
return number;
}
}

View File

@@ -0,0 +1,89 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver;
public class Crypt
{
byte[] _key;
public void setKey(byte[] key)
{
_key = new byte[key.length];
System.arraycopy(key, 0, _key, 0, key.length);
}
public long decrypt(byte[] raw)
{
if (_key == null)
{
return 0L;
}
int temp = 0;
int j = 0;
for (int i = 0; i < raw.length; ++i)
{
int temp2 = raw[i] & 0xFF;
raw[i] = (byte) (temp2 ^ (_key[j++] & 0xFF) ^ temp);
temp = temp2;
if (j <= 7)
{
continue;
}
j = 0;
}
long old = _key[0] & 0xFF;
old |= (_key[1] << 8) & 0xFF00;
old |= (_key[2] << 16) & 0xFF0000;
old |= (_key[3] << 24) & 0xFF000000;
_key[0] = (byte) ((old += raw.length) & 0xFFL);
_key[1] = (byte) ((old >> 8) & 0xFFL);
_key[2] = (byte) ((old >> 16) & 0xFFL);
_key[3] = (byte) ((old >> 24) & 0xFFL);
return old;
}
public long encrypt(byte[] raw)
{
if (_key == null)
{
return 0L;
}
int temp = 0;
int j = 0;
for (int i = 0; i < raw.length; ++i)
{
int temp2 = raw[i] & 0xFF;
raw[i] = (byte) (temp2 ^ (_key[j++] & 0xFF) ^ temp);
temp = raw[i];
if (j <= 7)
{
continue;
}
j = 0;
}
long old = _key[0] & 0xFF;
old |= (_key[1] << 8) & 0xFF00;
old |= (_key[2] << 16) & 0xFF0000;
old |= (_key[3] << 24) & 0xFF000000;
_key[0] = (byte) ((old += raw.length) & 0xFFL);
_key[1] = (byte) ((old >> 8) & 0xFFL);
_key[2] = (byte) ((old >> 16) & 0xFFL);
_key[3] = (byte) ((old >> 24) & 0xFFL);
return old;
}
}

View File

@@ -0,0 +1,190 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.gameserver.data.CharNameTable;
import org.l2jmobius.gameserver.data.CharStatsTable;
import org.l2jmobius.gameserver.data.CharTemplateTable;
import org.l2jmobius.gameserver.data.ClanTable;
import org.l2jmobius.gameserver.data.ExperienceTable;
import org.l2jmobius.gameserver.data.ItemTable;
import org.l2jmobius.gameserver.data.LevelUpData;
import org.l2jmobius.gameserver.data.MapRegionTable;
import org.l2jmobius.gameserver.data.NpcTable;
import org.l2jmobius.gameserver.data.PriceListTable;
import org.l2jmobius.gameserver.data.SkillTable;
import org.l2jmobius.gameserver.data.SkillTreeTable;
import org.l2jmobius.gameserver.data.SpawnTable;
import org.l2jmobius.gameserver.data.TeleportLocationTable;
import org.l2jmobius.gameserver.data.TradeController;
import org.l2jmobius.gameserver.handler.ItemHandler;
import org.l2jmobius.gameserver.handler.SkillHandler;
import org.l2jmobius.gameserver.handler.itemhandlers.PetSummon;
import org.l2jmobius.gameserver.handler.itemhandlers.Potions;
import org.l2jmobius.gameserver.handler.itemhandlers.ScrollOfEscape;
import org.l2jmobius.gameserver.handler.itemhandlers.SoulShots;
import org.l2jmobius.gameserver.handler.itemhandlers.WorldMap;
import org.l2jmobius.gameserver.handler.skillhandlers.DamageSkill;
import org.l2jmobius.gameserver.handler.skillhandlers.HealSkill;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.loginserver.LoginController;
public class GameServer extends Thread
{
static Logger _log = Logger.getLogger(GameServer.class.getName());
private ServerSocket _serverSocket;
private final ItemTable _itemTable;
private final SkillTable _skillTable;
private final NpcTable _npcTable;
private final ItemHandler _itemHandler;
private final SkillHandler _skillHandler;
private final LoginController _loginController;
protected final TradeController _tradeController;
protected final SkillTreeTable _skillTreeTable;
protected final ClanTable _clanTable;
protected final ExperienceTable _expTable;
protected final TeleportLocationTable _teleTable;
protected final LevelUpData _levelUpData;
protected final CharStatsTable _modifiers;
protected final World _world;
protected final CharTemplateTable _charTemplates;
protected final IdFactory _idFactory;
protected final SpawnTable _spawnTable;
protected final CharNameTable _charNametable;
protected final GameTimeController _gameTimeController;
protected final Announcements _announcements;
protected final MapRegionTable _mapRegions;
protected final PriceListTable _pricelist;
protected final GmListTable _gmList;
public static void main(String[] args) throws Exception
{
GameServer server = new GameServer();
_log.config("GameServer Listening on port 7777");
server.start();
}
@Override
public void run()
{
do
{
try
{
do
{
_log.fine("Used mem:" + getUsedMemoryMB() + "MB");
// _log.info("Waiting for client connection...");
Socket connection = _serverSocket.accept();
new ClientThread(connection);
}
while (true);
}
catch (IOException e)
{
continue;
}
}
while (true);
}
public long getUsedMemoryMB()
{
return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024L / 1024L;
}
public GameServer() throws Exception
{
super("GameServer");
if (!Config.SERVER_HOST_NAME.equals("*"))
{
InetAddress adr = InetAddress.getByName(Config.SERVER_HOST_NAME);
Config._ip = adr.getHostAddress();
_serverSocket = new ServerSocket(Config.SERVER_PORT, 50, adr);
_log.config("GameServer listening on IP:" + Config._ip + " Port " + Config.SERVER_PORT);
}
else
{
_serverSocket = new ServerSocket(Config.SERVER_PORT);
_log.config("GameServer listening on all available IPs on Port " + Config.SERVER_PORT);
}
_log.finest("Used mem:" + getUsedMemoryMB() + "MB");
_log.config("Maximum Numbers of Connected Players: " + Config.MAXIMUM_ONLINE_PLAYERS);
new File("data/clans").mkdirs();
new File("data/crests").mkdirs();
_loginController = LoginController.getInstance();
_loginController.setMaxAllowedOnlinePlayers(Config.MAXIMUM_ONLINE_PLAYERS);
_charNametable = CharNameTable.getInstance();
_idFactory = IdFactory.getInstance();
_itemTable = ItemTable.getInstance();
if (!_itemTable.isInitialized())
{
_log.severe("Could not find the extraced files. Please run convertData.");
throw new Exception("Could not initialize the item table");
}
_tradeController = TradeController.getInstance();
_skillTable = SkillTable.getInstance();
if (!_skillTable.isInitialized())
{
_log.severe("Could not find the extraced files. Please run convertData.");
throw new Exception("Could not initialize the skill table");
}
_skillTreeTable = SkillTreeTable.getInstance();
_charTemplates = CharTemplateTable.getInstance();
_clanTable = ClanTable.getInstance();
_npcTable = NpcTable.getInstance();
if (!_npcTable.isInitialized())
{
_log.severe("Could not find the extraced files. Please run convertData.");
throw new Exception("Could not initialize the npc table");
}
_expTable = ExperienceTable.getInstance();
_teleTable = TeleportLocationTable.getInstance();
_levelUpData = LevelUpData.getInstance();
_modifiers = CharStatsTable.getInstance();
_world = World.getInstance();
_spawnTable = SpawnTable.getInstance();
_gameTimeController = GameTimeController.getInstance();
_announcements = Announcements.getInstance();
_mapRegions = MapRegionTable.getInstance();
_pricelist = PriceListTable.getInstance();
_itemHandler = ItemHandler.getInstance();
_itemHandler.registerItemHandler(new PetSummon());
_itemHandler.registerItemHandler(new ScrollOfEscape());
_itemHandler.registerItemHandler(new SoulShots());
_itemHandler.registerItemHandler(new WorldMap());
_itemHandler.registerItemHandler(new Potions());
_skillHandler = SkillHandler.getInstance();
_skillHandler.registerSkillHandler(new HealSkill());
_skillHandler.registerSkillHandler(new DamageSkill());
_gmList = GmListTable.getInstance();
}
}

View File

@@ -0,0 +1,86 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.ServerBasePacket;
import org.l2jmobius.gameserver.network.serverpackets.SunRise;
import org.l2jmobius.gameserver.network.serverpackets.SunSet;
public class GameTimeController extends Thread
{
private static Logger _log = Logger.getLogger(GameTimeController.class.getName());
private static GameTimeController _instance;
private long _gameStartTime = System.currentTimeMillis() - 3600000L;
public static GameTimeController getInstance()
{
if (_instance == null)
{
_instance = new GameTimeController();
_instance.start();
}
return _instance;
}
private GameTimeController()
{
super("GameTimeController");
}
public int getGameTime()
{
long time = (System.currentTimeMillis() - _gameStartTime) / 10000L;
return (int) time;
}
@Override
public void run()
{
try
{
do
{
broadcastToPlayers(new SunRise());
_log.fine("SunRise");
Thread.sleep(21600000L);
_gameStartTime = System.currentTimeMillis();
broadcastToPlayers(new SunSet());
_log.fine("SunSet");
Thread.sleep(3600000L);
}
while (true);
}
catch (InterruptedException e1)
{
return;
}
}
private void broadcastToPlayers(ServerBasePacket packet)
{
PlayerInstance[] players = World.getInstance().getAllPlayers();
for (PlayerInstance player : players)
{
player.sendPacket(packet);
}
}
}

View File

@@ -0,0 +1,87 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.ServerBasePacket;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
public class GmListTable
{
private static Logger _log = Logger.getLogger(GmListTable.class.getName());
private static GmListTable _instance;
private final List<PlayerInstance> _gmList = new ArrayList<>();
public static GmListTable getInstance()
{
if (_instance == null)
{
_instance = new GmListTable();
}
return _instance;
}
private GmListTable()
{
}
public void addGm(PlayerInstance player)
{
_log.fine("added gm: " + player.getName());
_gmList.add(player);
}
public void deleteGm(PlayerInstance player)
{
_log.fine("deleted gm: " + player.getName());
_gmList.remove(player);
}
public void sendListToPlayer(PlayerInstance player)
{
if (_gmList.isEmpty())
{
SystemMessage sm = new SystemMessage(614);
sm.addString("No GM online");
}
else
{
SystemMessage sm = new SystemMessage(614);
sm.addString("" + _gmList.size() + " GM's online:");
player.sendPacket(sm);
for (int i = 0; i < _gmList.size(); ++i)
{
sm = new SystemMessage(614);
sm.addString(_gmList.get(i).getName());
player.sendPacket(sm);
}
}
}
public void broadcastToGMs(ServerBasePacket packet)
{
for (int i = 0; i < _gmList.size(); ++i)
{
_gmList.get(i).sendPacket(packet);
}
}
}

View File

@@ -0,0 +1,96 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Stack;
import java.util.logging.Logger;
public class IdFactory
{
private static Logger _log = Logger.getLogger(IdFactory.class.getName());
private int _curOID;
private Stack<Integer> _oldOIDs;
private static int FIRST_OID = 268435456;
private static IdFactory _instance;
@SuppressWarnings("unchecked")
private IdFactory()
{
try
{
FileInputStream fis = new FileInputStream("data/idstate.dat");
BufferedInputStream bis = new BufferedInputStream(fis);
ObjectInputStream oos = new ObjectInputStream(bis);
_curOID = (Integer) oos.readObject();
_oldOIDs = (Stack<Integer>) oos.readObject();
oos.close();
}
catch (Exception e)
{
_curOID = FIRST_OID;
_oldOIDs = new Stack<>();
}
}
public static IdFactory getInstance()
{
if (_instance == null)
{
_instance = new IdFactory();
}
return _instance;
}
public synchronized int getNextId()
{
if (_oldOIDs.isEmpty())
{
return _curOID++;
}
return _oldOIDs.pop();
}
public void releaseId(int id)
{
_oldOIDs.push(id);
}
public void saveCurrentState()
{
try
{
FileOutputStream fos = new FileOutputStream("data/idstate.dat");
BufferedOutputStream bos = new BufferedOutputStream(fos);
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(_curOID);
oos.writeObject(_oldOIDs);
oos.close();
}
catch (IOException e)
{
_log.warning("IdState couldnt be saved." + e.getMessage());
}
}
}

View File

@@ -0,0 +1,66 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver;
/**
* @author Mobius
*/
public class PlayerCountManager
{
private static volatile int connectedCount = 0;
private static volatile int maxConnectedCount = 0;
protected PlayerCountManager()
{
}
public int getConnectedCount()
{
return connectedCount;
}
public int getMaxConnectedCount()
{
return maxConnectedCount;
}
public synchronized void incConnectedCount()
{
connectedCount++;
maxConnectedCount = Math.max(maxConnectedCount, connectedCount);
}
public void decConnectedCount()
{
connectedCount--;
}
public static PlayerCountManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final PlayerCountManager INSTANCE = new PlayerCountManager();
}
public void setConnectedCount(int count)
{
connectedCount = count;
}
}

View File

@@ -0,0 +1,83 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
public class CharNameTable
{
private static Logger _log = Logger.getLogger(CharNameTable.class.getName());
private static CharNameTable _instance;
private final List<String> _charNames;
public static CharNameTable getInstance()
{
if (_instance == null)
{
_instance = new CharNameTable();
}
return _instance;
}
private CharNameTable()
{
File _accountsFolder = new File("data/accounts");
_accountsFolder.mkdirs();
_charNames = new ArrayList<>();
File[] accounts = _accountsFolder.listFiles();
for (File account : accounts)
{
try
{
File _charFolder = new File("data/accounts/" + account.getName());
File[] chars = _charFolder.listFiles((FilenameFilter) (dir, name) -> name.endsWith("_char.csv"));
for (File c : chars)
{
_charNames.add(c.getName().replaceAll("_char.csv", "").toLowerCase());
}
continue;
}
catch (NullPointerException e)
{
// empty catch block
}
}
_log.fine("Loaded " + _charNames.size() + " charnames to the memory.");
}
public void addCharName(String name)
{
_log.fine("Added charname: " + name + " to the memory.");
_charNames.add(name.toLowerCase());
}
public void deleteCharName(String name)
{
_log.fine("Deleted charname: " + name + " from the memory.");
_charNames.remove(name.toLowerCase());
}
public boolean doesCharNameExist(String name)
{
return _charNames.contains(name.toLowerCase());
}
}

View File

@@ -0,0 +1,107 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.StatModifiers;
public class CharStatsTable
{
private static Logger _log = Logger.getLogger(CharStatsTable.class.getName());
private static CharStatsTable _instance;
private final Map<Integer, StatModifiers> _modifiers = new HashMap<>();
public static CharStatsTable getInstance()
{
if (_instance == null)
{
_instance = new CharStatsTable();
}
return _instance;
}
private CharStatsTable()
{
BufferedReader lnr = null;
try
{
File ModifierData = new File("data/char_stats.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(ModifierData)));
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
StatModifiers modif = parseList(line);
_modifiers.put(modif.getClassid(), modif);
}
_log.config("Loaded " + _modifiers.size() + " character stat modifiers.");
}
catch (FileNotFoundException e)
{
_log.warning("char_stats.csv is missing in data folder.");
}
catch (Exception e)
{
_log.warning("Error while creating character modifier table " + e);
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private StatModifiers parseList(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
StatModifiers modifier = new StatModifiers();
modifier.setClassid(Integer.parseInt(st.nextToken()));
modifier.setModstr(Integer.parseInt(st.nextToken()));
modifier.setModcon(Integer.parseInt(st.nextToken()));
modifier.setModdex(Integer.parseInt(st.nextToken()));
modifier.setModint(Integer.parseInt(st.nextToken()));
modifier.setModmen(Integer.parseInt(st.nextToken()));
modifier.setModwit(Integer.parseInt(st.nextToken()));
return modifier;
}
public StatModifiers getTemplate(int id)
{
return _modifiers.get(id);
}
}

View File

@@ -0,0 +1,138 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.templates.L2CharTemplate;
public class CharTemplateTable
{
private static Logger _log = Logger.getLogger(CharTemplateTable.class.getName());
private static CharTemplateTable _instance;
private final Map<Integer, L2CharTemplate> _templates = new HashMap<>();
public static CharTemplateTable getInstance()
{
if (_instance == null)
{
_instance = new CharTemplateTable();
}
return _instance;
}
private CharTemplateTable()
{
BufferedReader lnr = null;
try
{
File skillData = new File("data/char_templates.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(skillData)));
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
L2CharTemplate ct = new L2CharTemplate();
StringTokenizer st = new StringTokenizer(line, ";");
ct.setClassId(Integer.parseInt(st.nextToken()));
ct.setClassName(st.nextToken());
ct.setRaceId(Integer.parseInt(st.nextToken()));
ct.setStr(Integer.parseInt(st.nextToken()));
ct.setCon(Integer.parseInt(st.nextToken()));
ct.setDex(Integer.parseInt(st.nextToken()));
ct.setInt(Integer.parseInt(st.nextToken()));
ct.setWit(Integer.parseInt(st.nextToken()));
ct.setMen(Integer.parseInt(st.nextToken()));
ct.setHp(Integer.parseInt(st.nextToken()));
ct.setMp(Integer.parseInt(st.nextToken()));
ct.setPatk(Integer.parseInt(st.nextToken()));
ct.setPdef(Integer.parseInt(st.nextToken()));
ct.setMatk(Integer.parseInt(st.nextToken()));
ct.setMdef(Integer.parseInt(st.nextToken()));
ct.setPspd(Integer.parseInt(st.nextToken()));
ct.setMspd(Integer.parseInt(st.nextToken()));
ct.setAcc(Integer.parseInt(st.nextToken()));
ct.setCrit(Integer.parseInt(st.nextToken()));
ct.setEvas(Integer.parseInt(st.nextToken()));
ct.setMoveSpd(Integer.parseInt(st.nextToken()));
ct.setLoad(Integer.parseInt(st.nextToken()));
ct.setX(Integer.parseInt(st.nextToken()));
ct.setY(Integer.parseInt(st.nextToken()));
ct.setZ(Integer.parseInt(st.nextToken()));
ct.setCanCraft(Integer.parseInt(st.nextToken()));
ct.setMUnk1(Double.parseDouble(st.nextToken()));
ct.setMUnk2(Double.parseDouble(st.nextToken()));
ct.setMColR(Double.parseDouble(st.nextToken()));
ct.setMColH(Double.parseDouble(st.nextToken()));
ct.setFUnk1(Double.parseDouble(st.nextToken()));
ct.setFUnk2(Double.parseDouble(st.nextToken()));
ct.setFColR(Double.parseDouble(st.nextToken()));
ct.setFColH(Double.parseDouble(st.nextToken()));
while (st.hasMoreTokens())
{
ct.addItem(Integer.parseInt(st.nextToken()));
}
_templates.put(ct.getClassId(), ct);
}
_log.config("Loaded " + _templates.size() + " char templates.");
}
catch (FileNotFoundException e)
{
_log.warning("char_templates.csv is missing in data folder, char creation will fail.");
}
catch (Exception e)
{
_log.warning("Error while loading char templates " + e);
e.printStackTrace();
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
public L2CharTemplate getTemplate(int classId)
{
return _templates.get(classId);
}
public L2CharTemplate[] getAllTemplates()
{
return _templates.values().toArray(new L2CharTemplate[_templates.size()]);
}
}

View File

@@ -0,0 +1,172 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.IdFactory;
import org.l2jmobius.gameserver.model.Clan;
import org.l2jmobius.gameserver.model.ClanMember;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
public class ClanTable
{
private static Logger _log = Logger.getLogger(ClanTable.class.getName());
private static ClanTable _instance;
private final Map<Integer, Clan> _clans = new HashMap<>();
public static ClanTable getInstance()
{
if (_instance == null)
{
_instance = new ClanTable();
}
return _instance;
}
private ClanTable()
{
try
{
File clanFolder = new File("data/clans");
clanFolder.mkdirs();
File[] clans = clanFolder.listFiles((FilenameFilter) (dir, name) -> name.endsWith(".csv"));
for (File clan2 : clans)
{
Clan clan = restoreClan(clan2);
_clans.put(clan.getClanId(), clan);
}
_log.config("Restored " + _clans.size() + " clans.");
}
catch (Exception e)
{
_log.warning("Error while creating clan table " + e);
}
}
private Clan restoreClan(File file)
{
BufferedReader lnr = null;
Clan clan = null;
try
{
lnr = new LineNumberReader(new BufferedReader(new FileReader(file)));
((LineNumberReader) lnr).readLine();
clan = parseClanData(((LineNumberReader) lnr).readLine());
((LineNumberReader) lnr).readLine();
String line = null;
boolean first = true;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
ClanMember member = parseMembers(line);
if (first)
{
clan.setLeader(member);
first = false;
continue;
}
clan.addClanMember(member);
}
}
catch (IOException e)
{
_log.warning("Could not read clan file:" + e.getMessage());
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
return clan;
}
private Clan parseClanData(String line)
{
Clan clan = new Clan();
StringTokenizer st = new StringTokenizer(line, ";");
clan.setClanId(Integer.parseInt(st.nextToken()));
clan.setName(st.nextToken());
clan.setLevel(Integer.parseInt(st.nextToken()));
clan.setHasCastle(Integer.parseInt(st.nextToken()));
clan.setHasHideout(Integer.parseInt(st.nextToken()));
clan.setAllyId(Integer.parseInt(st.nextToken()));
clan.setAllyName(st.nextToken());
return clan;
}
private ClanMember parseMembers(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
String name = st.nextToken();
int level = Integer.parseInt(st.nextToken());
int classId = Integer.parseInt(st.nextToken());
int objectId = Integer.parseInt(st.nextToken());
return new ClanMember(name, level, classId, objectId);
}
public Clan getClan(int clanId)
{
return _clans.get(clanId);
}
public Clan createClan(PlayerInstance player, String clanName)
{
Iterator<Clan> iter = _clans.values().iterator();
while (iter.hasNext())
{
Clan oldClans = iter.next();
if (!oldClans.getName().equalsIgnoreCase(clanName))
{
continue;
}
return null;
}
Clan clan = new Clan();
clan.setClanId(IdFactory.getInstance().getNextId());
clan.setName(clanName);
clan.setLevel(0);
clan.setHasCastle(0);
clan.setHasHideout(0);
clan.setAllyId(0);
clan.setAllyName(" ");
_log.fine("New clan created: " + clan.getClanId());
ClanMember leader = new ClanMember(player.getName(), player.getLevel(), player.getClassId(), player.getObjectId());
clan.setLeader(leader);
_clans.put(clan.getClanId(), clan);
clan.store();
return clan;
}
}

View File

@@ -0,0 +1,86 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
public class ExperienceTable
{
private static Logger _log = Logger.getLogger(ExperienceTable.class.getName());
private static final Map<Integer, Integer> _exp = new HashMap<>();
private static ExperienceTable _instance;
private ExperienceTable()
{
try
{
File expData = new File("data/exp.csv");
if (expData.isFile() && expData.exists())
{
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(expData)));
String line = null;
while ((line = lnr.readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
StringTokenizer expLine = new StringTokenizer(line, ";");
String level = expLine.nextToken().trim();
String exp = expLine.nextToken().trim();
_exp.put(Integer.parseInt(level), Integer.parseInt(exp));
}
lnr.close();
_log.config("Loaded " + _exp.size() + " exp mappings.");
}
else
{
_log.warning("File exp.csv is missing in data folder.");
}
}
catch (Exception e)
{
_log.warning("Error while creating exp map " + e);
}
}
public static ExperienceTable getInstance()
{
if (_instance == null)
{
_instance = new ExperienceTable();
}
return _instance;
}
public int getExp(int level)
{
if (_exp.containsKey(level))
{
return _exp.get(level);
}
return Integer.MAX_VALUE;
}
}

View File

@@ -0,0 +1,542 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.IdFactory;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.templates.L2Armor;
import org.l2jmobius.gameserver.templates.L2EtcItem;
import org.l2jmobius.gameserver.templates.L2Item;
import org.l2jmobius.gameserver.templates.L2Weapon;
public class ItemTable
{
private static Logger _log = Logger.getLogger(ItemTable.class.getName());
// private static final int TYPE_ETC_ITEM = 0;
// private static final int TYPE_ARMOR = 1;
// private static final int TYPE_WEAPON = 2;
private static final HashMap<String, Integer> _materials = new HashMap<>();
static
{
_materials.put("steel", 0);
_materials.put("fine_steel", 1);
_materials.put("cotton", 1);
_materials.put("blood_steel", 2);
_materials.put("bronze", 3);
_materials.put("silver", 4);
_materials.put("gold", 5);
_materials.put("mithril", 6);
_materials.put("oriharukon", 7);
_materials.put("paper", 8);
_materials.put("wood", 9);
_materials.put("cloth", 10);
_materials.put("leather", 11);
_materials.put("bone", 12);
_materials.put("horn", 13);
_materials.put("damascus", 14);
_materials.put("adamantaite", 15);
_materials.put("chrysolite", 16);
_materials.put("crystal", 17);
_materials.put("liquid", 18);
_materials.put("scale_of_dragon", 19);
_materials.put("dyestuff", 20);
_materials.put("cobweb", 21);
}
private static final HashMap<String, Integer> _crystalTypes = new HashMap<>();
static
{
_crystalTypes.put("none", 1);
_crystalTypes.put("d", 2);
_crystalTypes.put("c", 3);
_crystalTypes.put("b", 4);
_crystalTypes.put("a", 5);
_crystalTypes.put("s", 6);
}
private static final HashMap<String, Integer> _weaponTypes = new HashMap<>();
static
{
_weaponTypes.put("none", 1);
_weaponTypes.put("sword", 2);
_weaponTypes.put("blunt", 3);
_weaponTypes.put("dagger", 4);
_weaponTypes.put("bow", 5);
_weaponTypes.put("pole", 6);
_weaponTypes.put("etc", 7);
_weaponTypes.put("fist", 8);
_weaponTypes.put("dual", 9);
_weaponTypes.put("dualfist", 10);
}
private static final HashMap<String, Integer> _armorTypes = new HashMap<>();
static
{
_armorTypes.put("none", 1);
_armorTypes.put("light", 2);
_armorTypes.put("heavy", 3);
_armorTypes.put("magic", 4);
}
private static final HashMap<String, Integer> _slots = new HashMap<>();
static
{
_slots.put("none", 0);
_slots.put("underwear", 1);
_slots.put("rear,lear", 6);
_slots.put("neck", 8);
_slots.put("rfinger,lfinger", 48);
_slots.put("head", 64);
_slots.put("rhand", 128);
_slots.put("lhand", 256);
_slots.put("gloves", 512);
_slots.put("chest", 1024);
_slots.put("legs", 2048);
_slots.put("chest,legs", 3072);
_slots.put("feet", 4096);
_slots.put("back", 8192);
_slots.put("lrhand", 16384);
_slots.put("fullarmor", 32768);
}
private L2Item[] _allTemplates;
private HashMap<Integer, L2Item> _etcItems;
private HashMap<Integer, L2Item> _armors;
private HashMap<Integer, L2Item> _weapons;
private boolean _initialized = true;
private static ItemTable _instance;
public static ItemTable getInstance()
{
if (_instance == null)
{
_instance = new ItemTable();
}
return _instance;
}
public ItemTable()
{
File weaponFile;
File armorFile;
File etcItemFile = new File("data/etcitem.csv");
if (!etcItemFile.isFile() && !etcItemFile.canRead())
{
_initialized = false;
}
if (!(armorFile = new File("data/armor.csv")).isFile() && !armorFile.canRead())
{
_initialized = false;
}
if (!(weaponFile = new File("data/weapon.csv")).isFile() && !weaponFile.canRead())
{
_initialized = false;
}
parseEtcItems(etcItemFile);
parseArmors(armorFile);
parseWeapons(weaponFile);
buildFastLookupTable();
}
public boolean isInitialized()
{
return _initialized;
}
private void parseEtcItems(File data)
{
_etcItems = parseFile(data, 0);
_log.config("Loaded " + _etcItems.size() + " etc items.");
fixEtcItems(_etcItems);
}
private void fixEtcItems(HashMap<Integer, L2Item> items)
{
Iterator<Integer> iter = items.keySet().iterator();
while (iter.hasNext())
{
Integer key = iter.next();
L2EtcItem item = (L2EtcItem) items.get(key);
if ((item.getWeight() == 0) && (item.getEtcItemType() != 7) && !item.getName().startsWith("world_map") && !item.getName().startsWith("crystal_"))
{
item.setType2(3);
item.setEtcItemType(6);
continue;
}
if (item.getName().startsWith("sb_"))
{
item.setType2(5);
item.setEtcItemType(9);
continue;
}
if (item.getName().startsWith("rp_"))
{
item.setType2(5);
item.setEtcItemType(4);
continue;
}
if (!item.getName().startsWith("q_"))
{
continue;
}
item.setType2(3);
item.setEtcItemType(6);
}
}
private HashMap<Integer, L2Item> parseFile(File dataFile, int type)
{
HashMap<Integer, L2Item> result = new HashMap<>();
LineNumberReader lnr = null;
L2Item temp = null;
try
{
lnr = new LineNumberReader(new BufferedReader(new FileReader(dataFile)));
String line = null;
while ((line = lnr.readLine()) != null)
{
try
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
switch (type)
{
case 0:
{
temp = parseEtcLine(line);
break;
}
case 1:
{
temp = parseArmorLine(line);
break;
}
case 2:
{
temp = parseWeaponLine(line);
}
}
if (temp != null)
{
result.put(temp.getItemId(), temp);
}
}
catch (Exception e)
{
_log.warning("Error while parsing item:" + line + " " + e);
}
}
}
catch (Exception e)
{
_log.warning("Error while parsing items:" + e);
}
return result;
}
private L2EtcItem parseEtcLine(String line)
{
L2EtcItem result = new L2EtcItem();
try
{
StringTokenizer st = new StringTokenizer(line, ";");
result.setItemId(Integer.parseInt(st.nextToken()));
result.setName(st.nextToken());
result.setCrystallizable(Boolean.valueOf(st.nextToken()));
String itemType = st.nextToken();
result.setType1(4);
if (itemType.equals("none"))
{
result.setType2(5);
result.setEtcItemType(8);
}
else if (itemType.equals("arrow"))
{
result.setType2(5);
result.setEtcItemType(0);
result.setBodyPart(256);
}
else if (itemType.equals("castle_guard"))
{
result.setType2(5);
result.setEtcItemType(5);
}
else if (itemType.equals("material"))
{
result.setType2(5);
result.setEtcItemType(1);
}
else if (itemType.equals("pet_collar"))
{
result.setType2(5);
result.setEtcItemType(2);
}
else if (itemType.equals("potion"))
{
result.setType2(5);
result.setEtcItemType(3);
}
else if (itemType.equals("recipe"))
{
result.setType2(5);
result.setEtcItemType(4);
}
else if (itemType.equals("scroll"))
{
result.setType2(5);
result.setEtcItemType(5);
}
else
{
_log.warning("Unknown etcitem type:" + itemType);
}
result.setWeight(Integer.parseInt(st.nextToken()));
String consume = st.nextToken();
if (consume.equals("asset"))
{
result.setStackable(true);
result.setEtcItemType(7);
result.setType2(4);
}
else if (consume.equals("stackable"))
{
result.setStackable(true);
}
Integer material = _materials.get(st.nextToken());
result.setMaterialType(material);
Integer crystal = _crystalTypes.get(st.nextToken());
result.setCrystalType(crystal);
result.setDurability(Integer.parseInt(st.nextToken()));
}
catch (Exception e)
{
_log.warning("Data error on etc item:" + result + " " + e);
}
return result;
}
private L2Armor parseArmorLine(String line)
{
L2Armor result = new L2Armor();
try
{
StringTokenizer st = new StringTokenizer(line, ";");
result.setItemId(Integer.parseInt(st.nextToken()));
result.setName(st.nextToken());
Integer bodyPart = _slots.get(st.nextToken());
result.setBodyPart(bodyPart);
result.setCrystallizable(Boolean.valueOf(st.nextToken()));
Integer armor = _armorTypes.get(st.nextToken());
result.setArmorType(armor);
int slot = result.getBodyPart();
if ((slot == 8) || ((slot & 4) != 0) || ((slot & 0x20) != 0))
{
result.setType1(0);
result.setType2(2);
}
else
{
result.setType1(1);
result.setType2(1);
}
result.setWeight(Integer.parseInt(st.nextToken()));
Integer material = _materials.get(st.nextToken());
result.setMaterialType(material);
Integer crystal = _crystalTypes.get(st.nextToken());
result.setCrystalType(crystal);
result.setAvoidModifier(Integer.parseInt(st.nextToken()));
result.setDurability(Integer.parseInt(st.nextToken()));
result.setPDef(Integer.parseInt(st.nextToken()));
result.setMDef(Integer.parseInt(st.nextToken()));
result.setMpBonus(Integer.parseInt(st.nextToken()));
}
catch (Exception e)
{
_log.warning("Data error on armor:" + result + " line: " + line);
e.printStackTrace();
}
return result;
}
private L2Weapon parseWeaponLine(String line)
{
L2Weapon result = new L2Weapon();
try
{
StringTokenizer st = new StringTokenizer(line, ";");
result.setItemId(Integer.parseInt(st.nextToken()));
result.setName(st.nextToken());
result.setType1(0);
result.setType2(0);
Integer bodyPart = _slots.get(st.nextToken());
result.setBodyPart(bodyPart);
result.setCrystallizable(Boolean.valueOf(st.nextToken()));
result.setWeight(Integer.parseInt(st.nextToken()));
result.setSoulShotCount(Integer.parseInt(st.nextToken()));
result.setSpiritShotCount(Integer.parseInt(st.nextToken()));
Integer material = _materials.get(st.nextToken());
result.setMaterialType(material);
Integer crystal = _crystalTypes.get(st.nextToken());
result.setCrystalType(crystal);
result.setPDamage(Integer.parseInt(st.nextToken()));
result.setRandomDamage(Integer.parseInt(st.nextToken()));
Integer weapon = _weaponTypes.get(st.nextToken());
result.setWeaponType(weapon);
if (weapon == 1)
{
result.setType1(1);
result.setType2(1);
}
result.setCritical(Integer.parseInt(st.nextToken()));
result.setHitModifier(Double.parseDouble(st.nextToken()));
result.setAvoidModifier(Integer.parseInt(st.nextToken()));
result.setShieldDef(Integer.parseInt(st.nextToken()));
result.setShieldDefRate(Integer.parseInt(st.nextToken()));
result.setAttackSpeed(Integer.parseInt(st.nextToken()));
result.setMpConsume(Integer.parseInt(st.nextToken()));
result.setMDamage(Integer.parseInt(st.nextToken()));
result.setDurability(Integer.parseInt(st.nextToken()));
}
catch (Exception e)
{
_log.warning("Data error on weapon:" + result + " line: " + line);
e.printStackTrace();
}
return result;
}
private void parseArmors(File data)
{
_armors = parseFile(data, 1);
_log.config("Loaded " + _armors.size() + " armors.");
}
private void parseWeapons(File data)
{
_weapons = parseFile(data, 2);
_log.config("Laoded " + _weapons.size() + " weapons.");
}
private void buildFastLookupTable()
{
L2Item item;
Integer id;
int highestId = 0;
Iterator<Integer> iter = _armors.keySet().iterator();
while (iter.hasNext())
{
id = iter.next();
item = _armors.get(id);
if (item.getItemId() <= highestId)
{
continue;
}
highestId = item.getItemId();
}
iter = _weapons.keySet().iterator();
while (iter.hasNext())
{
id = iter.next();
item = _weapons.get(id);
if (item.getItemId() <= highestId)
{
continue;
}
highestId = item.getItemId();
}
iter = _etcItems.keySet().iterator();
while (iter.hasNext())
{
id = iter.next();
item = _etcItems.get(id);
if (item.getItemId() <= highestId)
{
continue;
}
highestId = item.getItemId();
}
_log.fine("Highest item id used: " + highestId);
_allTemplates = new L2Item[highestId + 1];
iter = _armors.keySet().iterator();
while (iter.hasNext())
{
id = iter.next();
_allTemplates[id.intValue()] = item = _armors.get(id);
}
iter = _weapons.keySet().iterator();
while (iter.hasNext())
{
id = iter.next();
_allTemplates[id.intValue()] = item = _weapons.get(id);
}
iter = _etcItems.keySet().iterator();
while (iter.hasNext())
{
id = iter.next();
_allTemplates[id.intValue()] = item = _etcItems.get(id);
}
}
public L2Item getTemplate(int id)
{
return _allTemplates[id];
}
public ItemInstance createItem(int itemId)
{
ItemInstance temp = new ItemInstance();
temp.setObjectId(IdFactory.getInstance().getNextId());
temp.setItem(getTemplate(itemId));
_log.fine("Item created oid: " + temp.getObjectId() + " itemid: " + itemId);
World.getInstance().storeObject(temp);
return temp;
}
public ItemInstance createDummyItem(int itemId)
{
ItemInstance temp = new ItemInstance();
temp.setObjectId(0);
L2Item item = null;
try
{
item = getTemplate(itemId);
}
catch (ArrayIndexOutOfBoundsException e)
{
// empty catch block
}
if (item == null)
{
_log.warning("Item template missing. id: " + itemId);
}
else
{
temp.setItem(item);
}
return temp;
}
}

View File

@@ -0,0 +1,108 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.LvlupData;
public class LevelUpData
{
private static Logger _log = Logger.getLogger(LevelUpData.class.getName());
private final Map<Integer, LvlupData> _lvltable = new HashMap<>();
private static LevelUpData _instance;
public static LevelUpData getInstance()
{
if (_instance == null)
{
_instance = new LevelUpData();
}
return _instance;
}
private LevelUpData()
{
BufferedReader lnr = null;
try
{
File spawnDataFile = new File("data/lvlupgain.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(spawnDataFile)));
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
LvlupData lvlupData = parseList(line);
_lvltable.put(lvlupData.getClassid(), lvlupData);
}
_log.config("Loaded " + _lvltable.size() + " Lvl up data templates.");
}
catch (FileNotFoundException e)
{
_log.warning("lvlupgain.csv is missing in data folder.");
}
catch (Exception e)
{
_log.warning("Error while creating npc data table " + e);
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private LvlupData parseList(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
LvlupData lvlDat = new LvlupData();
lvlDat.setClassid(Integer.parseInt(st.nextToken()));
lvlDat.setDefaulthp(Double.parseDouble(st.nextToken()));
lvlDat.setDefaulthpadd(Double.parseDouble(st.nextToken()));
lvlDat.setDefaulthpbonus(Double.parseDouble(st.nextToken()));
lvlDat.setDefaultmp(Double.parseDouble(st.nextToken()));
lvlDat.setDefaultmpadd(Double.parseDouble(st.nextToken()));
lvlDat.setDefaultmpbonus(Double.parseDouble(st.nextToken()));
return lvlDat;
}
public LvlupData getTemplate(int classId)
{
return _lvltable.get(classId);
}
}

View File

@@ -0,0 +1,176 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.actor.Creature;
public class MapRegionTable
{
private static Logger _log = Logger.getLogger(MapRegionTable.class.getName());
private static int[][] _regions = new int[19][21];
private static MapRegionTable _instance;
public static MapRegionTable getInstance()
{
if (_instance == null)
{
_instance = new MapRegionTable();
}
return _instance;
}
private MapRegionTable()
{
super();
int count = 0;
int count2 = 0;
LineNumberReader lnr = null;
try
{
File regionDataFile = new File("data/mapregion.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(regionDataFile)));
String line = null;
while ((line = lnr.readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
StringTokenizer st = new StringTokenizer(line, ";");
for (int j = 0; j < 10; ++count2, ++j)
{
MapRegionTable._regions[j][count] = Integer.parseInt(st.nextToken());
}
++count;
}
try
{
_log.fine("Loaded " + count2 + " map regions.");
lnr.close();
return;
}
catch (FileNotFoundException e)
{
_log.warning("mapregion.csv is missing in data folder.");
try
{
}
catch (Exception e1)
{
return;
}
_log.fine("Loaded " + count2 + " map regions.");
lnr.close();
return;
}
catch (Exception e)
{
_log.warning("Rrror while creating map region data: " + e);
try
{
}
catch (Exception e1)
{
return;
}
_log.fine("Loaded " + count2 + " map regions.");
lnr.close();
return;
}
}
catch (Throwable throwable)
{
_log.fine("Loaded " + count2 + " map regions.");
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (IOException e)
{
}
}
}
public int getMapRegion(int posX, int posY)
{
int tileX = (posX >> 15) + 4;
int tileY = (posY >> 15) + 10;
return _regions[tileX][tileY];
}
public String getClosestTownCords(Creature activeChar)
{
int[][] pos = new int[13][3];
pos[0][0] = -84176;
pos[0][1] = 243382;
pos[0][2] = -3126;
pos[1][0] = 45525;
pos[1][1] = 48376;
pos[1][2] = -3059;
pos[2][0] = 12181;
pos[2][1] = 16675;
pos[2][2] = -4580;
pos[3][0] = -45232;
pos[3][1] = -113603;
pos[3][2] = -224;
pos[4][0] = 115074;
pos[4][1] = -178115;
pos[4][2] = -880;
pos[5][0] = -14138;
pos[5][1] = 122042;
pos[5][2] = -2988;
pos[6][0] = -82856;
pos[6][1] = 150901;
pos[6][2] = -3128;
pos[7][0] = 18823;
pos[7][1] = 145048;
pos[7][2] = -3126;
pos[8][0] = 83235;
pos[8][1] = 148497;
pos[8][2] = -3404;
pos[9][0] = 80853;
pos[9][1] = 54653;
pos[9][2] = -1524;
pos[10][0] = 147391;
pos[10][1] = 25967;
pos[10][2] = -2012;
pos[11][0] = 117163;
pos[11][1] = 76511;
pos[11][2] = -2712;
pos[12][0] = 83235;
pos[12][1] = 148497;
pos[12][2] = -3404;
int closest = getMapRegion(activeChar.getX(), activeChar.getY());
String ClosestTownCords = pos[closest][0] + "!" + pos[closest][1] + "!" + pos[closest][2];
return ClosestTownCords;
}
}

View File

@@ -0,0 +1,275 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.DropData;
import org.l2jmobius.gameserver.templates.L2Npc;
public class NpcTable
{
private static Logger _log = Logger.getLogger(NpcTable.class.getName());
private static NpcTable _instance;
private final Map<Integer, L2Npc> _npcs = new HashMap<>();
private boolean _initialized = true;
public static NpcTable getInstance()
{
if (_instance == null)
{
_instance = new NpcTable();
}
return _instance;
}
private NpcTable()
{
parseData();
parseAdditionalData();
parseDropData();
}
public boolean isInitialized()
{
return _initialized;
}
private void parseData()
{
BufferedReader lnr = null;
try
{
File skillData = new File("data/npc.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(skillData)));
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
L2Npc npc = parseList(line);
_npcs.put(npc.getNpcId(), npc);
}
_log.config("Loaded " + _npcs.size() + " NPC templates.");
}
catch (FileNotFoundException e)
{
_initialized = false;
_log.warning("npc.csv is missing in data folder.");
}
catch (Exception e)
{
_initialized = false;
_log.warning("Error while creating npc table " + e);
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private L2Npc parseList(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
L2Npc npc = new L2Npc();
int id = Integer.parseInt(st.nextToken());
if (id > 1000000)
{
id -= 1000000;
}
npc.setNpcId(id);
npc.setName(st.nextToken());
npc.setType(st.nextToken());
npc.setRadius(Double.parseDouble(st.nextToken()));
npc.setHeight(Double.parseDouble(st.nextToken()));
return npc;
}
private void parseAdditionalData()
{
BufferedReader lnr = null;
try
{
File npcDataFile = new File("data/npc2.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(npcDataFile)));
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
try
{
parseAdditionalDataLine(line);
}
catch (Exception e)
{
_log.warning("Parsing error in npc2.csv, line " + ((LineNumberReader) lnr).getLineNumber() + " / " + e.toString());
}
}
}
catch (FileNotFoundException e)
{
_log.warning("npc2.csv is missing in data folder.");
}
catch (Exception e)
{
_log.warning("Error while creating npc data table " + e);
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private void parseAdditionalDataLine(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
int id = Integer.parseInt(st.nextToken());
L2Npc npcDat = _npcs.get(id);
if (npcDat == null)
{
_log.warning("Missing npc template id:" + id);
return;
}
st.nextToken();
npcDat.setLevel(Integer.parseInt(st.nextToken()));
npcDat.setSex(st.nextToken());
npcDat.setType(st.nextToken());
npcDat.setAttackRange(Integer.parseInt(st.nextToken()));
npcDat.setHp(Integer.parseInt(st.nextToken()));
npcDat.setMp(Integer.parseInt(st.nextToken()));
npcDat.setExp(Integer.parseInt(st.nextToken()));
npcDat.setSp(Integer.parseInt(st.nextToken()));
npcDat.setPatk(Integer.parseInt(st.nextToken()));
npcDat.setPdef(Integer.parseInt(st.nextToken()));
npcDat.setMatk(Integer.parseInt(st.nextToken()));
npcDat.setMdef(Integer.parseInt(st.nextToken()));
npcDat.setAtkspd(Integer.parseInt(st.nextToken()));
npcDat.setAgro(Integer.parseInt(st.nextToken()) == 1);
npcDat.setMatkspd(Integer.parseInt(st.nextToken()));
npcDat.setRhand(Integer.parseInt(st.nextToken()));
npcDat.setLhand(Integer.parseInt(st.nextToken()));
npcDat.setArmor(Integer.parseInt(st.nextToken()));
npcDat.setWalkSpeed(Integer.parseInt(st.nextToken()));
npcDat.setRunSpeed(Integer.parseInt(st.nextToken()));
}
private void parseDropData()
{
BufferedReader lnr = null;
try
{
File dropDataFile = new File("data/droplist.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(dropDataFile)));
String line = null;
int n = 0;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
try
{
parseDropLine(line);
++n;
}
catch (Exception e)
{
_log.warning("Parsing error in droplist.csv, line " + ((LineNumberReader) lnr).getLineNumber() + " / " + e.toString());
}
}
_log.config("Loaded " + n + " drop data templates.");
}
catch (FileNotFoundException e)
{
_log.warning("droplist.csv is missing in data folder.");
}
catch (Exception e)
{
_log.warning("Error while creating drop data table " + e);
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private void parseDropLine(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
int mobId = Integer.parseInt(st.nextToken());
L2Npc npc = _npcs.get(mobId);
if (npc == null)
{
_log.warning("Could not add drop data for npcid:" + mobId);
return;
}
DropData dropDat = new DropData();
dropDat.setItemId(Integer.parseInt(st.nextToken()));
dropDat.setMinDrop(Integer.parseInt(st.nextToken()));
dropDat.setMaxDrop(Integer.parseInt(st.nextToken()));
dropDat.setSweep(Integer.parseInt(st.nextToken()) == 1);
dropDat.setChance(Integer.parseInt(st.nextToken()));
npc.addDropData(dropDat);
}
public L2Npc getTemplate(int id)
{
return _npcs.get(id);
}
}

View File

@@ -0,0 +1,133 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.templates.L2Item;
public class PriceListTable
{
private static Logger _log = Logger.getLogger(PriceListTable.class.getName());
private static PriceListTable _instance;
public PriceListTable()
{
loadPriceList();
}
public static PriceListTable getInstance()
{
if (_instance == null)
{
_instance = new PriceListTable();
}
return _instance;
}
public void loadPriceList()
{
File file = new File("data/pricelist.csv");
if (file.exists())
{
try
{
readFromDisk(file);
}
catch (IOException e)
{
}
}
else
{
_log.config("data/pricelist.csv is missing!");
}
}
private void readFromDisk(File file) throws IOException
{
BufferedReader lnr = null;
int i = 0;
String line = null;
lnr = new LineNumberReader(new FileReader(file));
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
if (line.startsWith("#"))
{
continue;
}
StringTokenizer st = new StringTokenizer(line, ";");
int itemId = Integer.parseInt(st.nextToken().toString());
int price = Integer.parseInt(st.nextToken().toString());
L2Item temp = ItemTable.getInstance().getTemplate(itemId);
temp.setItemId(itemId);
temp.setReferencePrice(price);
++i;
}
_log.config("Loaded " + i + " prices.");
try
{
lnr.close();
return;
}
catch (FileNotFoundException e)
{
try
{
lnr.close();
return;
}
catch (IOException e1)
{
try
{
e1.printStackTrace();
}
catch (Throwable throwable)
{
try
{
lnr.close();
throw throwable;
}
catch (Exception e2)
{
// empty catch block
}
throw throwable;
}
try
{
lnr.close();
return;
}
catch (Exception e2)
{
return;
}
}
}
}
}

View File

@@ -0,0 +1,185 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.Skill;
public class SkillTable
{
private static Logger _log = Logger.getLogger(SkillTable.class.getName());
private static SkillTable _instance;
private final Map<Integer, Skill> _skills = new HashMap<>();
private boolean _initialized = true;
public static SkillTable getInstance()
{
if (_instance == null)
{
_instance = new SkillTable();
}
return _instance;
}
private SkillTable()
{
BufferedReader lnr = null;
try
{
File skillData = new File("data/skills.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(skillData)));
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
Skill skill = parseList(line);
_skills.put((skill.getId() * 100) + skill.getLevel(), skill);
}
skillData = new File("data/skills2.csv");
lnr.close();
lnr = new LineNumberReader(new BufferedReader(new FileReader(skillData)));
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
parseList2(line);
}
_log.config("Loaded " + _skills.size() + " skills.");
}
catch (FileNotFoundException e)
{
_initialized = false;
_log.warning("Skills.csv or skills2.csv is missing in data folder: " + e.toString());
}
catch (Exception e)
{
_initialized = false;
_log.warning("Error while creating skill table: " + e.toString());
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
public boolean isInitialized()
{
return _initialized;
}
private void parseList2(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
int id = Integer.parseInt(st.nextToken());
st.nextToken();
int level = Integer.parseInt(st.nextToken());
int key = (id * 100) + level;
Skill skill = _skills.get(key);
if (skill == null)
{
return;
}
String target = st.nextToken();
if (target.equalsIgnoreCase("self"))
{
skill.setTargetType(Skill.TARGET_SELF);
}
else if (target.equalsIgnoreCase("one"))
{
skill.setTargetType(Skill.TARGET_ONE);
}
else if (target.equalsIgnoreCase("party"))
{
skill.setTargetType(Skill.TARGET_PARTY);
}
else if (target.equalsIgnoreCase("clan"))
{
skill.setTargetType(Skill.TARGET_CLAN);
}
else if (target.equalsIgnoreCase("pet"))
{
skill.setTargetType(Skill.TARGET_PET);
}
skill.setPower(Integer.parseInt(st.nextToken()));
}
private Skill parseList(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
Skill skill = new Skill();
skill.setId(Integer.parseInt(st.nextToken()));
skill.setName(st.nextToken());
skill.setLevel(Integer.parseInt(st.nextToken()));
String opType = st.nextToken();
if (opType.equalsIgnoreCase("once"))
{
skill.setOperateType(Skill.OP_ONCE);
}
else if (opType.equalsIgnoreCase("always"))
{
skill.setOperateType(Skill.OP_ALWAYS);
}
else if (opType.equalsIgnoreCase("duration"))
{
skill.setOperateType(Skill.OP_DURATION);
}
else if (opType.equalsIgnoreCase("toggle"))
{
skill.setOperateType(Skill.OP_TOGGLE);
}
skill.setMagic(Boolean.valueOf(st.nextToken())); // ?
skill.setMpConsume(Integer.parseInt(st.nextToken()));
skill.setHpConsume(Integer.parseInt(st.nextToken()));
skill.setItemConsumeId(Integer.parseInt(st.nextToken()));
skill.setItemConsume(Integer.parseInt(st.nextToken()));
skill.setCastRange(Integer.parseInt(st.nextToken()));
skill.setSkillTime(Integer.parseInt(st.nextToken()));
skill.setReuseDelay(Integer.parseInt(st.nextToken()));
skill.setBuffDuration(Integer.parseInt(st.nextToken()));
skill.setHitTime(Integer.parseInt(st.nextToken()));
return skill;
}
public Skill getInfo(int magicId, int level)
{
return _skills.get((magicId * 100) + level);
}
}

View File

@@ -0,0 +1,271 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.Skill;
import org.l2jmobius.gameserver.model.SkillLearn;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
public class SkillTreeTable
{
private static Logger _log = Logger.getLogger(SkillTreeTable.class.getName());
private static SkillTreeTable _instance;
private final Map<Integer, List<SkillLearn>> _skillTrees = new HashMap<>();
public static SkillTreeTable getInstance()
{
if (_instance == null)
{
_instance = new SkillTreeTable();
}
return _instance;
}
private SkillTreeTable()
{
File skillData = new File("data/skilltrees/D_Fighter.csv");
readFile(skillData, 53, -1);
skillData = new File("data/skilltrees/DE_Fighter.csv");
readFile(skillData, 31, -1);
skillData = new File("data/skilltrees/DE_Mage.csv");
readFile(skillData, 38, -1);
skillData = new File("data/skilltrees/E_Fighter.csv");
readFile(skillData, 18, -1);
skillData = new File("data/skilltrees/E_Mage.csv");
readFile(skillData, 25, -1);
skillData = new File("data/skilltrees/H_Fighter.csv");
readFile(skillData, 0, -1);
skillData = new File("data/skilltrees/H_Mage.csv");
readFile(skillData, 10, -1);
skillData = new File("data/skilltrees/O_Fighter.csv");
readFile(skillData, 44, -1);
skillData = new File("data/skilltrees/O_Mage.csv");
readFile(skillData, 49, -1);
skillData = new File("data/skilltrees/H_Knight.csv");
readFile(skillData, 4, 0);
skillData = new File("data/skilltrees/H_Warrior.csv");
readFile(skillData, 1, 0);
skillData = new File("data/skilltrees/H_Rogue.csv");
readFile(skillData, 7, 0);
skillData = new File("data/skilltrees/H_Cleric.csv");
readFile(skillData, 15, 10);
skillData = new File("data/skilltrees/H_Wizard.csv");
readFile(skillData, 11, 10);
skillData = new File("data/skilltrees/E_Knight.csv");
readFile(skillData, 19, 18);
skillData = new File("data/skilltrees/E_Scout.csv");
readFile(skillData, 22, 18);
skillData = new File("data/skilltrees/E_Wizard.csv");
readFile(skillData, 26, 25);
skillData = new File("data/skilltrees/E_Oracle.csv");
readFile(skillData, 29, 25);
skillData = new File("data/skilltrees/DE_PaulusKnight.csv");
readFile(skillData, 32, 31);
skillData = new File("data/skilltrees/DE_Assassin.csv");
readFile(skillData, 35, 31);
skillData = new File("data/skilltrees/DE_DarkWizard.csv");
readFile(skillData, 39, 38);
skillData = new File("data/skilltrees/DE_ShillienOracle.csv");
readFile(skillData, 42, 38);
skillData = new File("data/skilltrees/O_Monk.csv");
readFile(skillData, 47, 44);
skillData = new File("data/skilltrees/O_Raider.csv");
readFile(skillData, 45, 44);
skillData = new File("data/skilltrees/O_Shaman.csv");
readFile(skillData, 50, 49);
skillData = new File("data/skilltrees/D_Artisan.csv");
readFile(skillData, 56, 53);
skillData = new File("data/skilltrees/D_Scavenger.csv");
readFile(skillData, 54, 53);
skillData = new File("data/skilltrees/H_DarkAvenger.csv");
readFile(skillData, 6, 4);
skillData = new File("data/skilltrees/H_Paladin.csv");
readFile(skillData, 5, 4);
skillData = new File("data/skilltrees/H_TreasureHunter.csv");
readFile(skillData, 8, 7);
skillData = new File("data/skilltrees/H_Hawkeye.csv");
readFile(skillData, 9, 7);
skillData = new File("data/skilltrees/H_Gladiator.csv");
readFile(skillData, 2, 1);
skillData = new File("data/skilltrees/H_Warlord.csv");
readFile(skillData, 3, 1);
skillData = new File("data/skilltrees/H_Sorceror.csv");
readFile(skillData, 12, 11);
skillData = new File("data/skilltrees/H_Necromancer.csv");
readFile(skillData, 13, 11);
skillData = new File("data/skilltrees/H_Warlock.csv");
readFile(skillData, 14, 11);
skillData = new File("data/skilltrees/H_Bishop.csv");
readFile(skillData, 16, 15);
skillData = new File("data/skilltrees/H_Prophet.csv");
readFile(skillData, 17, 15);
skillData = new File("data/skilltrees/E_TempleKnight.csv");
readFile(skillData, 20, 19);
skillData = new File("data/skilltrees/E_SwordSinger.csv");
readFile(skillData, 21, 19);
skillData = new File("data/skilltrees/E_SilverRanger.csv");
readFile(skillData, 24, 22);
skillData = new File("data/skilltrees/E_PlainsWalker.csv");
readFile(skillData, 23, 22);
skillData = new File("data/skilltrees/E_ElementalSummoner.csv");
readFile(skillData, 28, 26);
skillData = new File("data/skilltrees/E_SpellSinger.csv");
readFile(skillData, 27, 26);
skillData = new File("data/skilltrees/E_Elder.csv");
readFile(skillData, 30, 29);
skillData = new File("data/skilltrees/DE_ShillienKnight.csv");
readFile(skillData, 33, 32);
skillData = new File("data/skilltrees/DE_BladeDancer.csv");
readFile(skillData, 34, 32);
skillData = new File("data/skilltrees/DE_AbyssWalker.csv");
readFile(skillData, 36, 35);
skillData = new File("data/skilltrees/DE_PhantomRanger.csv");
readFile(skillData, 37, 35);
skillData = new File("data/skilltrees/DE_ShillienElder.csv");
readFile(skillData, 43, 42);
skillData = new File("data/skilltrees/DE_PhantomSummoner.csv");
readFile(skillData, 41, 39);
skillData = new File("data/skilltrees/DE_Spellhowler.csv");
readFile(skillData, 40, 39);
skillData = new File("data/skilltrees/D_Warsmith.csv");
readFile(skillData, 57, 56);
skillData = new File("data/skilltrees/D_BountyHunter.csv");
readFile(skillData, 55, 54);
skillData = new File("data/skilltrees/O_Destroyer.csv");
readFile(skillData, 46, 45);
skillData = new File("data/skilltrees/O_Tyrant.csv");
readFile(skillData, 48, 47);
skillData = new File("data/skilltrees/O_Overlord.csv");
readFile(skillData, 51, 50);
skillData = new File("data/skilltrees/O_Warcryer.csv");
readFile(skillData, 52, 50);
}
private void readFile(File skillData, int classId, int parentClassId)
{
BufferedReader lnr = null;
String line = null;
try
{
lnr = new LineNumberReader(new BufferedReader(new FileReader(skillData)));
List<SkillLearn> list = new ArrayList<>();
if (parentClassId != -1)
{
List<SkillLearn> parentList = _skillTrees.get(parentClassId);
list.addAll(parentList);
}
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
SkillLearn skill = parseList(line);
list.add(skill);
}
_skillTrees.put(classId, list);
_log.config("Skill tree for class " + classId + " has " + list.size() + " skills.");
}
catch (FileNotFoundException e)
{
_log.warning("SkillTree file for classId " + classId + " is missing in data folder.");
}
catch (Exception e)
{
_log.warning("Error while creating skill tree for classId " + classId + " " + line + " " + e);
e.printStackTrace();
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private SkillLearn parseList(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
SkillLearn skill = new SkillLearn();
skill.setId(Integer.parseInt(st.nextToken()));
skill.setName(st.nextToken());
skill.setLevel(Integer.parseInt(st.nextToken()));
skill.setSpCost(Integer.parseInt(st.nextToken()));
skill.setMinLevel(Integer.parseInt(st.nextToken()));
return skill;
}
public SkillLearn[] getAvailableSkills(PlayerInstance cha)
{
List<SkillLearn> result = new ArrayList<>();
List<SkillLearn> skills = _skillTrees.get(cha.getClassId());
if (skills == null)
{
_log.warning("Skilltree for class " + cha.getClassId() + " is not defined !");
return new SkillLearn[0];
}
Skill[] oldSkills = cha.getAllSkills();
for (int i = 0; i < skills.size(); ++i)
{
SkillLearn temp = skills.get(i);
if (temp.getMinLevel() > cha.getLevel())
{
continue;
}
boolean knownSkill = false;
for (int j = 0; (j < oldSkills.length) && !knownSkill; ++j)
{
if (oldSkills[j].getId() != temp.getId())
{
continue;
}
knownSkill = true;
if (oldSkills[j].getLevel() != (temp.getLevel() - 1))
{
continue;
}
result.add(temp);
}
if (knownSkill || (temp.getLevel() != 1))
{
continue;
}
result.add(temp);
}
return result.toArray(new SkillLearn[result.size()]);
}
}

View File

@@ -0,0 +1,144 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.templates.L2Npc;
public class SpawnTable
{
private static Logger _log = Logger.getLogger(SpawnTable.class.getName());
private static SpawnTable _instance;
private final Map<Integer, Spawn> _spawntable = new HashMap<>();
private int _npcSpawnCount;
private int _highestId;
public static SpawnTable getInstance()
{
if (_instance == null)
{
_instance = new SpawnTable();
}
return _instance;
}
private SpawnTable()
{
BufferedReader lnr = null;
try
{
File spawnDataFile = new File("data/spawnlist.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(spawnDataFile)));
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
try
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
Spawn spawn = parseList(line);
_spawntable.put(spawn.getId(), spawn);
if (spawn.getId() <= _highestId)
{
continue;
}
_highestId = spawn.getId();
}
catch (Exception e1)
{
_log.warning("Spawn could not be initialized: " + e1);
}
}
_log.config("Created " + _spawntable.size() + " spawn handlers.");
_log.fine("Spawning completed, total number of NPCs in the world: " + _npcSpawnCount);
}
catch (FileNotFoundException e)
{
_log.warning("spawnlist.csv is missing in data folder");
}
catch (Exception e)
{
_log.warning("error while creating spawn list " + e);
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private Spawn parseList(String line) throws SecurityException, ClassNotFoundException
{
StringTokenizer st = new StringTokenizer(line, ";");
int spawnId = Integer.parseInt(st.nextToken());
String location = st.nextToken();
int count = Integer.parseInt(st.nextToken());
int npcId = Integer.parseInt(st.nextToken());
L2Npc template1 = NpcTable.getInstance().getTemplate(npcId);
if (template1 == null)
{
_log.warning("Monster data for id:" + npcId + " missing in npc.csv");
return null;
}
Spawn spawnDat = new Spawn(template1);
spawnDat.setId(spawnId);
spawnDat.setLocation(location); // ?
spawnDat.setAmount(count);
spawnDat.setLocx(Integer.parseInt(st.nextToken()));
spawnDat.setLocy(Integer.parseInt(st.nextToken()));
spawnDat.setLocz(Integer.parseInt(st.nextToken()));
spawnDat.setRandomx(Integer.parseInt(st.nextToken()));
spawnDat.setRandomy(Integer.parseInt(st.nextToken()));
spawnDat.setHeading(Integer.parseInt(st.nextToken()));
spawnDat.setRespawnDelay(Integer.parseInt(st.nextToken()));
_npcSpawnCount += spawnDat.init();
return spawnDat;
}
public Spawn getTemplate(int Id)
{
return _spawntable.get(Id);
}
public void addNewSpawn(Spawn spawn)
{
++_highestId;
spawn.setId(_highestId);
_spawntable.put(spawn.getId(), spawn);
}
}

View File

@@ -0,0 +1,105 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.TeleportLocation;
public class TeleportLocationTable
{
private static Logger _log = Logger.getLogger(TeleportLocationTable.class.getName());
private static TeleportLocationTable _instance;
private final Map<Integer, TeleportLocation> _teleports = new HashMap<>();
public static TeleportLocationTable getInstance()
{
if (_instance == null)
{
_instance = new TeleportLocationTable();
}
return _instance;
}
private TeleportLocationTable()
{
BufferedReader lnr = null;
try
{
File teleData = new File("data/teleport.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(teleData)));
String line = null;
while ((line = ((LineNumberReader) lnr).readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
TeleportLocation tele = parseList(line);
_teleports.put(tele.getTeleId(), tele);
}
_log.config("Loaded " + _teleports.size() + " Teleport templates.");
}
catch (FileNotFoundException e)
{
_log.warning("teleport.csv is missing in data folder.");
}
catch (Exception e)
{
_log.warning("Error while creating teleport table " + e);
}
finally
{
try
{
if (lnr != null)
{
lnr.close();
}
}
catch (Exception e1)
{
}
}
}
private TeleportLocation parseList(String line)
{
StringTokenizer st = new StringTokenizer(line, ";");
TeleportLocation teleport = new TeleportLocation();
teleport.setTeleId(Integer.parseInt(st.nextToken()));
teleport.setLocX(Integer.parseInt(st.nextToken()));
teleport.setLocY(Integer.parseInt(st.nextToken()));
teleport.setLocZ(Integer.parseInt(st.nextToken()));
teleport.setPrice(Integer.parseInt(st.nextToken()));
return teleport;
}
public TeleportLocation getTemplate(int id)
{
return _teleports.get(id);
}
}

View File

@@ -0,0 +1,101 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.data;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.TradeList;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
public class TradeController
{
private static Logger _log = Logger.getLogger(TradeController.class.getName());
private static TradeController _instance;
private final Map<Integer, TradeList> _lists = new HashMap<>();
public static TradeController getInstance()
{
if (_instance == null)
{
_instance = new TradeController();
}
return _instance;
}
private TradeController()
{
String line = null;
LineNumberReader lnr = null;
int dummyItemCount = 0;
try
{
File buylistData = new File("data/buylists.csv");
lnr = new LineNumberReader(new BufferedReader(new FileReader(buylistData)));
while ((line = lnr.readLine()) != null)
{
if ((line.trim().length() == 0) || line.startsWith("#"))
{
continue;
}
dummyItemCount += parseList(line);
}
_log.fine("Created " + dummyItemCount + " Dummy-Items for buylists.");
_log.config("Loaded " + _lists.size() + " buylists.");
}
catch (Exception e)
{
if (lnr != null)
{
_log.warning("Error while creating trade controller in linenr: " + lnr.getLineNumber());
e.printStackTrace();
}
_log.warning("No buylists were found in data folder.");
}
}
private int parseList(String line)
{
int itemCreated = 0;
StringTokenizer st = new StringTokenizer(line, ";");
int listId = Integer.parseInt(st.nextToken());
TradeList buy1 = new TradeList(listId);
while (st.hasMoreTokens())
{
int itemId = Integer.parseInt(st.nextToken());
int price = Integer.parseInt(st.nextToken());
ItemInstance item = ItemTable.getInstance().createDummyItem(itemId);
item.setPrice(price);
buy1.addItem(item);
++itemCreated;
}
_lists.put(buy1.getListId(), buy1);
return itemCreated;
}
public TradeList getBuyList(int listId)
{
return _lists.get(listId);
}
}

View File

@@ -0,0 +1,30 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.handler;
import java.io.IOException;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
public interface IItemHandler
{
public int useItem(PlayerInstance var1, ItemInstance var2) throws IOException;
public int[] getItemIds();
}

View File

@@ -0,0 +1,31 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.handler;
import java.io.IOException;
import org.l2jmobius.gameserver.model.Skill;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
public interface ISkillHandler
{
public void useSkill(PlayerInstance var1, Skill var2, WorldObject var3) throws IOException;
public int[] getSkillIds();
}

View File

@@ -0,0 +1,54 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.handler;
import java.util.Map;
import java.util.TreeMap;
public class ItemHandler
{
private static ItemHandler _instance;
private final Map<Integer, IItemHandler> _datatable = new TreeMap<>();
public static ItemHandler getInstance()
{
if (_instance == null)
{
_instance = new ItemHandler();
}
return _instance;
}
private ItemHandler()
{
}
public void registerItemHandler(IItemHandler handler)
{
int[] ids = handler.getItemIds();
for (int id : ids)
{
_datatable.put(id, handler);
}
}
public IItemHandler getItemHandler(int itemId)
{
return _datatable.get(itemId);
}
}

View File

@@ -0,0 +1,54 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.handler;
import java.util.Map;
import java.util.TreeMap;
public class SkillHandler
{
private static SkillHandler _instance;
private final Map<Integer, ISkillHandler> _datatable = new TreeMap<>();
public static SkillHandler getInstance()
{
if (_instance == null)
{
_instance = new SkillHandler();
}
return _instance;
}
private SkillHandler()
{
}
public void registerSkillHandler(ISkillHandler handler)
{
int[] ids = handler.getSkillIds();
for (int id : ids)
{
_datatable.put(id, handler);
}
}
public ISkillHandler getSkillHandler(int skillId)
{
return _datatable.get(skillId);
}
}

View File

@@ -0,0 +1,138 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.handler.itemhandlers;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.IdFactory;
import org.l2jmobius.gameserver.data.ExperienceTable;
import org.l2jmobius.gameserver.data.NpcTable;
import org.l2jmobius.gameserver.handler.IItemHandler;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PetInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.MagicSkillLaunched;
import org.l2jmobius.gameserver.network.serverpackets.MagicSkillUser;
import org.l2jmobius.gameserver.network.serverpackets.NpcInfo;
import org.l2jmobius.gameserver.network.serverpackets.PetInfo;
import org.l2jmobius.gameserver.network.serverpackets.PetItemList;
import org.l2jmobius.gameserver.templates.L2Npc;
public class PetSummon implements IItemHandler
{
private static Logger _log = Logger.getLogger(PetSummon.class.getName());
private static int[] _itemIds = new int[]
{
2375,
3500,
3501,
3502
};
@Override
public int useItem(PlayerInstance activeChar, ItemInstance item)
{
int npcId;
if (activeChar.getPet() != null)
{
_log.fine("player has a pet already. ignore use item");
return 0;
}
switch (item.getItemId())
{
case 2375:
{
npcId = 12077;
break;
}
case 3500:
{
npcId = 12311;
break;
}
case 3501:
{
npcId = 12312;
break;
}
case 3502:
{
npcId = 12313;
break;
}
default:
{
return 0;
}
}
L2Npc petTemplate = NpcTable.getInstance().getTemplate(npcId);
PetInstance newpet = new PetInstance(petTemplate);
newpet.setTitle(activeChar.getName());
newpet.setControlItemId(item.getObjectId());
newpet.setObjectId(IdFactory.getInstance().getNextId());
newpet.setX(activeChar.getX() + 50);
newpet.setY(activeChar.getY() + 100);
newpet.setZ(activeChar.getZ());
newpet.setLevel(petTemplate.getLevel());
newpet.setExp(ExperienceTable.getInstance().getExp(newpet.getLevel()));
newpet.setLastLevel(ExperienceTable.getInstance().getExp(newpet.getLevel()));
newpet.setNextLevel(ExperienceTable.getInstance().getExp(newpet.getLevel() + 1));
newpet.setMaxHp(petTemplate.getHp());
newpet.setSummonHp(petTemplate.getHp());
newpet.setWalkSpeed(petTemplate.getWalkSpeed());
newpet.setRunSpeed(petTemplate.getRunSpeed());
newpet.setPhysicalAttack(petTemplate.getPatk());
newpet.setPhysicalDefense(petTemplate.getPdef());
newpet.setHeading(activeChar.getHeading());
newpet.setMovementMultiplier(1.08);
newpet.setAttackSpeedMultiplier(0.9983664);
newpet.setAttackRange(petTemplate.getAttackRange());
newpet.setRunning(true);
World.getInstance().storeObject(newpet);
World.getInstance().addVisibleObject(newpet);
MagicSkillUser msk = new MagicSkillUser(activeChar, 2046, 1, 1000, 600000);
activeChar.sendPacket(msk);
PetInfo ownerni = new PetInfo(newpet);
NpcInfo ni = new NpcInfo(newpet);
activeChar.broadcastPacket(ni);
activeChar.sendPacket(ownerni);
activeChar.sendPacket(new PetItemList(newpet));
try
{
Thread.sleep(900L);
}
catch (InterruptedException e)
{
// empty catch block
}
activeChar.sendPacket(new MagicSkillLaunched(activeChar, 2046, 1));
activeChar.setPet(newpet);
newpet.setOwner(activeChar);
newpet.addKnownObject(activeChar);
newpet.setFollowStatus(true);
newpet.followOwner(activeChar);
return 0;
}
@Override
public int[] getItemIds()
{
return _itemIds;
}
}

View File

@@ -0,0 +1,76 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.handler.itemhandlers;
import org.l2jmobius.gameserver.handler.IItemHandler;
import org.l2jmobius.gameserver.model.Potion;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.MagicSkillUser;
public class Potions implements IItemHandler
{
private static int[] _itemIds = new int[]
{
65,
725,
727,
1060,
1061,
1073,
1539,
1540,
726,
728
};
@Override
public int useItem(PlayerInstance activeChar, ItemInstance item)
{
Potion Potion = new Potion();
int itemId = item.getItemId();
if ((itemId == 65) || (itemId == 725) || (itemId == 727) || (itemId == 1060) || (itemId == 1061) || (itemId == 1539) || (itemId == 1540) || (itemId == 1073))
{
WorldObject OldTarget = activeChar.getTarget();
activeChar.setTarget(activeChar);
MagicSkillUser MSU = new MagicSkillUser(activeChar, 2038, 1, 0, 0);
activeChar.sendPacket(MSU);
activeChar.broadcastPacket(MSU);
activeChar.setTarget(OldTarget);
Potion.setCurrentHpPotion1(activeChar, itemId);
}
else if ((itemId == 726) || (itemId == 728))
{
WorldObject OldTarget = activeChar.getTarget();
activeChar.setTarget(activeChar);
MagicSkillUser MSU = new MagicSkillUser(activeChar, 2038, 1, 0, 0);
activeChar.sendPacket(MSU);
activeChar.broadcastPacket(MSU);
activeChar.setTarget(OldTarget);
Potion.setCurrentMpPotion1(activeChar, itemId);
}
return 1;
}
@Override
public int[] getItemIds()
{
return _itemIds;
}
}

View File

@@ -0,0 +1,96 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.handler.itemhandlers;
import org.l2jmobius.gameserver.data.MapRegionTable;
import org.l2jmobius.gameserver.data.SkillTable;
import org.l2jmobius.gameserver.handler.IItemHandler;
import org.l2jmobius.gameserver.model.Skill;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.MagicSkillUser;
import org.l2jmobius.gameserver.network.serverpackets.SetupGauge;
import org.l2jmobius.gameserver.network.serverpackets.StopMove;
import org.l2jmobius.gameserver.network.serverpackets.TeleportToLocation;
public class ScrollOfEscape implements IItemHandler
{
private static int[] _itemIds = new int[]
{
736
};
@Override
public int useItem(PlayerInstance activeChar, ItemInstance item)
{
String townCordsString = MapRegionTable.getInstance().getClosestTownCords(activeChar);
String[] temp = null;
temp = townCordsString.split("!");
int townX = Integer.parseInt(temp[0]);
int townY = Integer.parseInt(temp[1]);
int townZ = Integer.parseInt(temp[2]);
activeChar.setTarget(activeChar);
Skill skill = SkillTable.getInstance().getInfo(1050, 1);
MagicSkillUser msk = new MagicSkillUser(activeChar, 1050, 1, 20000, 0);
activeChar.sendPacket(msk);
activeChar.broadcastPacket(msk);
SetupGauge sg = new SetupGauge(0, skill.getSkillTime());
activeChar.sendPacket(sg);
if (skill.getSkillTime() > 200)
{
try
{
Thread.sleep(skill.getSkillTime() - 200);
}
catch (InterruptedException e)
{
// empty catch block
}
}
StopMove sm = new StopMove(activeChar);
activeChar.sendPacket(sm);
activeChar.broadcastPacket(sm);
ActionFailed af = new ActionFailed();
activeChar.sendPacket(af);
World.getInstance().removeVisibleObject(activeChar);
activeChar.removeAllKnownObjects();
TeleportToLocation teleport = new TeleportToLocation(activeChar, townX, townY, townZ);
activeChar.sendPacket(teleport);
activeChar.broadcastPacket(teleport);
activeChar.setX(townX);
activeChar.setY(townY);
activeChar.setZ(townZ);
try
{
Thread.sleep(2000L);
}
catch (InterruptedException e)
{
// empty catch block
}
return 1;
}
@Override
public int[] getItemIds()
{
return _itemIds;
}
}

View File

@@ -0,0 +1,88 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.handler.itemhandlers;
import org.l2jmobius.gameserver.handler.IItemHandler;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.MagicSkillUser;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import org.l2jmobius.gameserver.templates.L2Weapon;
public class SoulShots implements IItemHandler
{
private static int[] _itemIds = new int[]
{
1835,
1463,
1464,
1465,
1466,
1467
};
@Override
public int useItem(PlayerInstance activeChar, ItemInstance item)
{
if (activeChar.getActiveSoulshotGrade() != 0)
{
return 0;
}
int SoulshotId = item.getItemId();
L2Weapon weapon = activeChar.getActiveWeapon();
if (weapon == null)
{
activeChar.sendPacket(new SystemMessage(339));
return 0;
}
int grade = weapon.getCrystalType();
int soulShotConsumption = weapon.getSoulShotCount();
int count = item.getCount();
if (soulShotConsumption == 0)
{
activeChar.sendPacket(new SystemMessage(339));
return 0;
}
if (((grade == 1) && (SoulshotId != 1835)) || ((grade == 2) && (SoulshotId != 1463)) || ((grade == 3) && (SoulshotId != 1464)) || ((grade == 4) && (SoulshotId != 1465)) || ((grade == 5) && (SoulshotId != 1466)) || ((grade == 6) && (SoulshotId != 1467)))
{
activeChar.sendPacket(new SystemMessage(337));
return 0;
}
if (count < soulShotConsumption)
{
activeChar.sendPacket(new SystemMessage(338));
return 0;
}
activeChar.setActiveSoulshotGrade(grade);
activeChar.sendPacket(new SystemMessage(342));
WorldObject OldTarget = activeChar.getTarget();
activeChar.setTarget(activeChar);
MagicSkillUser MSU = new MagicSkillUser(activeChar, 2039, 1, 0, 0);
activeChar.sendPacket(MSU);
activeChar.broadcastPacket(MSU);
activeChar.setTarget(OldTarget);
return soulShotConsumption;
}
@Override
public int[] getItemIds()
{
return _itemIds;
}
}

View File

@@ -0,0 +1,45 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.handler.itemhandlers;
import org.l2jmobius.gameserver.handler.IItemHandler;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.ShowMiniMap;
public class WorldMap implements IItemHandler
{
private static int[] _itemIds = new int[]
{
1665,
1863
};
@Override
public int useItem(PlayerInstance activeChar, ItemInstance item)
{
activeChar.sendPacket(new ShowMiniMap(item.getItemId()));
return 0;
}
@Override
public int[] getItemIds()
{
return _itemIds;
}
}

View File

@@ -0,0 +1,74 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.handler.skillhandlers;
import org.l2jmobius.gameserver.handler.ISkillHandler;
import org.l2jmobius.gameserver.model.Skill;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
public class DamageSkill implements ISkillHandler
{
public static final int POWER_STRIKE = 3;
public static final int WIND_STRIKE = 1177;
public static final int FLAME_STRIKE = 1181;
public static final int MORTAL_BLOW = 16;
public static final int POWER_SHOT = 56;
public static final int IRON_PUNCH = 29;
private static int[] _skillIds = new int[]
{
3,
1177,
1181,
16,
56,
29
};
@Override
public void useSkill(PlayerInstance activeChar, Skill skill, WorldObject target)
{
if (target instanceof Creature)
{
Creature targetChar = (Creature) target;
int mdef = targetChar.getMagicalDefense();
if (mdef == 0)
{
mdef = 350;
}
int dmg = (int) ((91 * skill.getPower() * Math.sqrt(activeChar.getMagicalAttack())) / mdef);
SystemMessage sm = new SystemMessage(35);
sm.addNumber(dmg);
activeChar.sendPacket(sm);
targetChar.reduceCurrentHp(dmg, activeChar);
if (targetChar.getCurrentHp() > targetChar.getMaxHp())
{
targetChar.setCurrentHp(targetChar.getMaxHp());
}
}
}
@Override
public int[] getSkillIds()
{
return _skillIds;
}
}

View File

@@ -0,0 +1,91 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.handler.skillhandlers;
import java.util.List;
import org.l2jmobius.gameserver.handler.ISkillHandler;
import org.l2jmobius.gameserver.model.Skill;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.instance.PetInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.StatusUpdate;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
public class HealSkill implements ISkillHandler
{
private static final int SELF_HEAL = 1216;
private static final int DEVINE_HEAL = 45;
private static final int ELEMENTAL_HEAL = 58;
private static final int HEAL = 1011;
private static final int BATTLE_HEAL = 1015;
private static final int GROUP_HEAL = 1027;
private static final int SERVITOR_HEAL = 1127;
private static final int GREATER_GROUP_HEAL = 1219;
private static int[] _skillIds = new int[]
{
SELF_HEAL,
DEVINE_HEAL,
ELEMENTAL_HEAL,
HEAL,
BATTLE_HEAL,
GROUP_HEAL,
SERVITOR_HEAL,
GREATER_GROUP_HEAL
};
@Override
public void useSkill(PlayerInstance activeChar, Skill skill, WorldObject target)
{
if (skill.getTargetType() == Skill.TARGET_PET)
{
PetInstance pet = activeChar.getPet();
double hp = pet.getCurrentHp();
pet.setCurrentHp(hp += skill.getPower());
}
else if ((skill.getTargetType() == Skill.TARGET_PARTY) && activeChar.isInParty())
{
List<PlayerInstance> players = activeChar.getParty().getPartyMembers();
for (int i = 0; i < players.size(); ++i)
{
PlayerInstance player = players.get(i);
double hp = player.getCurrentHp();
player.setCurrentHp(hp += skill.getPower());
StatusUpdate su = new StatusUpdate(player.getObjectId());
su.addAttribute(StatusUpdate.CUR_HP, (int) hp);
player.sendPacket(su);
player.sendPacket(new SystemMessage(25));
}
}
else
{
double hp = activeChar.getCurrentHp();
activeChar.setCurrentHp(hp += skill.getPower());
StatusUpdate su = new StatusUpdate(activeChar.getObjectId());
su.addAttribute(StatusUpdate.CUR_HP, (int) hp);
activeChar.sendPacket(su);
activeChar.sendPacket(new SystemMessage(25));
}
}
@Override
public int[] getSkillIds()
{
return _skillIds;
}
}

View File

@@ -0,0 +1,220 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class CharSelectInfoPackage
{
private String _name;
private int _charId = 199546;
private int _exp = 0;
private int _sp = 0;
private int _clanId = 0;
private int _race = 0;
private int _classId = 0;
private int _deleteTimer = 0;
private int _face = 0;
private int _hairStyle = 0;
private int _hairColor = 0;
private int _sex = 0;
private int _level = 1;
private int _maxHp = 0;
private double _currentHp = 0.0;
private int _maxMp = 0;
private double _currentMp = 0.0;
private Inventory _inventory = new Inventory();
public int getCharId()
{
return _charId;
}
public void setCharId(int charId)
{
_charId = charId;
}
public int getClanId()
{
return _clanId;
}
public void setClanId(int clanId)
{
_clanId = clanId;
}
public int getClassId()
{
return _classId;
}
public void setClassId(int classId)
{
_classId = classId;
}
public double getCurrentHp()
{
return _currentHp;
}
public void setCurrentHp(double currentHp)
{
_currentHp = currentHp;
}
public double getCurrentMp()
{
return _currentMp;
}
public void setCurrentMp(double currentMp)
{
_currentMp = currentMp;
}
public int getDeleteTimer()
{
return _deleteTimer;
}
public void setDeleteTimer(int deleteTimer)
{
_deleteTimer = deleteTimer;
}
public int getExp()
{
return _exp;
}
public void setExp(int exp)
{
_exp = exp;
}
public int getFace()
{
return _face;
}
public void setFace(int face)
{
_face = face;
}
public int getHairColor()
{
return _hairColor;
}
public void setHairColor(int hairColor)
{
_hairColor = hairColor;
}
public int getHairStyle()
{
return _hairStyle;
}
public void setHairStyle(int hairStyle)
{
_hairStyle = hairStyle;
}
public Inventory getInventory()
{
return _inventory;
}
public void setInventory(Inventory inventory)
{
_inventory = inventory;
}
public int getLevel()
{
return _level;
}
public void setLevel(int level)
{
_level = level;
}
public int getMaxHp()
{
return _maxHp;
}
public void setMaxHp(int maxHp)
{
_maxHp = maxHp;
}
public int getMaxMp()
{
return _maxMp;
}
public void setMaxMp(int maxMp)
{
_maxMp = maxMp;
}
public String getName()
{
return _name;
}
public void setName(String name)
{
_name = name;
}
public int getRace()
{
return _race;
}
public void setRace(int race)
{
_race = race;
}
public int getSex()
{
return _sex;
}
public void setSex(int sex)
{
_sex = sex;
}
public int getSp()
{
return _sp;
}
public void setSp(int sp)
{
_sp = sp;
}
}

View File

@@ -0,0 +1,267 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.ServerBasePacket;
public class Clan
{
private static final Logger _log = Logger.getLogger(Clan.class.getName());
private String _name;
private int _clanId;
private ClanMember _leader;
private final Map<String, ClanMember> _members = new TreeMap<>();
private String _allyName;
private int _allyId;
private int _level;
private int _hasCastle;
private int _hasHideout;
public int getClanId()
{
return _clanId;
}
public void setClanId(int clanId)
{
_clanId = clanId;
}
public int getLeaderId()
{
return _leader.getObjectId();
}
public void setLeader(ClanMember leader)
{
_leader = leader;
_members.put(leader.getName(), leader);
}
public String getLeaderName()
{
return _leader.getName();
}
public String getName()
{
return _name;
}
public void setName(String name)
{
_name = name;
}
public void addClanMember(ClanMember member)
{
_members.put(member.getName(), member);
}
public void addClanMember(PlayerInstance player)
{
ClanMember member = new ClanMember(player);
this.addClanMember(member);
}
public ClanMember getClanMember(String name)
{
return _members.get(name);
}
public void removeClanMember(String name)
{
_members.remove(name);
}
public ClanMember[] getMembers()
{
return _members.values().toArray(new ClanMember[_members.size()]);
}
public PlayerInstance[] getOnlineMembers(String exclude)
{
List<PlayerInstance> result = new ArrayList<>();
Iterator<ClanMember> iter = _members.values().iterator();
while (iter.hasNext())
{
ClanMember temp = iter.next();
if (!temp.isOnline() || temp.getName().equals(exclude))
{
continue;
}
result.add(temp.getPlayerInstance());
}
return result.toArray(new PlayerInstance[result.size()]);
}
public int getAllyId()
{
return _allyId;
}
public String getAllyName()
{
return _allyName;
}
public int getAllyCrestId()
{
return _allyId;
}
public int getLevel()
{
return _level;
}
public int getHasCastle()
{
return _hasCastle;
}
public int getHasHideout()
{
return _hasHideout;
}
public int getCrestId()
{
return _clanId;
}
public void setAllyId(int allyId)
{
_allyId = allyId;
}
public void setAllyName(String allyName)
{
_allyName = allyName;
}
public void setHasCastle(int hasCastle)
{
_hasCastle = hasCastle;
}
public void setHasHideout(int hasHideout)
{
_hasHideout = hasHideout;
}
public void setLevel(int level)
{
_level = level;
}
public boolean isMember(String name)
{
return _members.containsKey(name);
}
public void store()
{
File clanFile = new File("data/clans/" + getName() + ".csv");
FileWriter out = null;
try
{
int i;
out = new FileWriter(clanFile);
out.write("#clanId;clanName;clanLevel;hasCastle;hasHideout;allianceId;allianceName\r\n");
out.write(getClanId() + ";");
out.write(getName() + ";");
out.write(getLevel() + ";");
out.write(getHasCastle() + ";");
out.write(getHasHideout() + ";");
out.write(getAllyId() + ";");
out.write("none\r\n");
out.write("#memberName;memberLevel;classId;objectId\r\n");
ClanMember[] members = getMembers();
for (i = 0; i < members.length; ++i)
{
if (members[i].getObjectId() != getLeaderId())
{
continue;
}
out.write(members[i].getName() + ";");
out.write(members[i].getLevel() + ";");
out.write(members[i].getClassId() + ";");
out.write(members[i].getObjectId() + "\r\n");
}
for (i = 0; i < members.length; ++i)
{
if (members[i].getObjectId() == getLeaderId())
{
continue;
}
out.write(members[i].getName() + ";");
out.write(members[i].getLevel() + ";");
out.write(members[i].getClassId() + ";");
out.write(members[i].getObjectId() + "\r\n");
}
}
catch (Exception e)
{
_log.warning("could not store clan:" + e.toString());
}
finally
{
try
{
if (out != null)
{
out.close();
}
}
catch (Exception e1)
{
}
}
}
public void broadcastToOnlineMembers(ServerBasePacket packet)
{
Iterator<ClanMember> iter = _members.values().iterator();
while (iter.hasNext())
{
ClanMember member = iter.next();
if (!member.isOnline())
{
continue;
}
member.getPlayerInstance().sendPacket(packet);
}
}
@Override
public String toString()
{
return getName();
}
}

View File

@@ -0,0 +1,109 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
public class ClanMember
{
private int _objectId;
private String _name;
private int _level;
private int _classId;
private PlayerInstance _player;
public ClanMember(String name, int level, int classId, int objectId)
{
_name = name;
_level = level;
_classId = classId;
_objectId = objectId;
}
public ClanMember(PlayerInstance player)
{
_player = player;
}
public void setPlayerInstance(PlayerInstance player)
{
if ((player == null) && (_player != null))
{
_name = _player.getName();
_level = _player.getLevel();
_classId = _player.getClassId();
_objectId = _player.getObjectId();
}
_player = player;
}
public PlayerInstance getPlayerInstance()
{
return _player;
}
public boolean isOnline()
{
return _player != null;
}
public int getClassId()
{
if (_player != null)
{
return _player.getClassId();
}
return _classId;
}
public int getLevel()
{
if (_player != null)
{
return _player.getLevel();
}
return _level;
}
public String getName()
{
if (_player != null)
{
return _player.getName();
}
return _name;
}
public int getObjectId()
{
if (_player != null)
{
return _player.getObjectId();
}
return _objectId;
}
public String getTitle()
{
if (_player != null)
{
return _player.getTitle();
}
return " ";
}
}

View File

@@ -0,0 +1,80 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class ClassId
{
public static final int fighter = 0;
public static final int warrior = 1;
public static final int gladiator = 2;
public static final int warlord = 3;
public static final int knight = 4;
public static final int paladin = 5;
public static final int darkAvenger = 6;
public static final int rogue = 7;
public static final int treasureHunter = 8;
public static final int hawkeye = 9;
public static final int mage = 10;
public static final int wizard = 11;
public static final int sorceror = 12;
public static final int necromancer = 13;
public static final int warlock = 14;
public static final int cleric = 15;
public static final int bishop = 16;
public static final int prophet = 17;
public static final int elvenFighter = 18;
public static final int elvenKnight = 19;
public static final int templeKnight = 20;
public static final int swordSinger = 21;
public static final int elvenScout = 22;
public static final int plainsWalker = 23;
public static final int silverRanger = 24;
public static final int elvenMage = 25;
public static final int elvenWizard = 26;
public static final int spellsinger = 27;
public static final int elementalSummoner = 28;
public static final int oracle = 29;
public static final int elder = 30;
public static final int darkFighter = 31;
public static final int palusKnight = 32;
public static final int shillienKnight = 33;
public static final int bladedancer = 34;
public static final int assassin = 35;
public static final int abyssWalker = 36;
public static final int phantomRanger = 37;
public static final int darkMage = 38;
public static final int darkWizard = 39;
public static final int spellhowler = 40;
public static final int phantomSummoner = 41;
public static final int shillienOracle = 42;
public static final int shillenElder = 43;
public static final int orcFighter = 44;
public static final int orcRaider = 45;
public static final int destroyer = 46;
public static final int orcMonk = 47;
public static final int tyrant = 48;
public static final int orcMage = 49;
public static final int orcShaman = 50;
public static final int overlord = 51;
public static final int warcryer = 52;
public static final int dwarvenFighter = 53;
public static final int scavenger = 54;
public static final int bountyHunter = 55;
public static final int artisan = 56;
public static final int warsmith = 57;
}

View File

@@ -0,0 +1,78 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class DropData
{
public static final int MAX_CHANCE = 1000000;
private int _itemId;
private int _mindrop;
private int _maxdrop;
private boolean _sweep;
private int _chance;
public int getItemId()
{
return _itemId;
}
public void setItemId(int itemId)
{
_itemId = itemId;
}
public int getMinDrop()
{
return _mindrop;
}
public int getMaxDrop()
{
return _maxdrop;
}
public boolean isSweep()
{
return _sweep;
}
public int getChance()
{
return _chance;
}
public void setMinDrop(int mindrop)
{
_mindrop = mindrop;
}
public void setMaxDrop(int maxdrop)
{
_maxdrop = maxdrop;
}
public void setSweep(boolean sweep)
{
_sweep = sweep;
}
public void setChance(int chance)
{
_chance = chance;
}
}

View File

@@ -0,0 +1,623 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.data.ItemTable;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.templates.L2Item;
import org.l2jmobius.gameserver.templates.L2Weapon;
public class Inventory
{
private static Logger _log = Logger.getLogger(Inventory.class.getName());
public static final int PAPERDOLL_UNDER = 0;
public static final int PAPERDOLL_LEAR = 1;
public static final int PAPERDOLL_REAR = 2;
public static final int PAPERDOLL_NECK = 3;
public static final int PAPERDOLL_LFINGER = 4;
public static final int PAPERDOLL_RFINGER = 5;
public static final int PAPERDOLL_HEAD = 6;
public static final int PAPERDOLL_RHAND = 7;
public static final int PAPERDOLL_LHAND = 8;
public static final int PAPERDOLL_GLOVES = 9;
public static final int PAPERDOLL_CHEST = 10;
public static final int PAPERDOLL_LEGS = 11;
public static final int PAPERDOLL_FEET = 12;
public static final int PAPERDOLL_BACK = 13;
public static final int PAPERDOLL_LRHAND = 14;
private final ItemInstance[] _paperdoll = new ItemInstance[16];
private ItemInstance _adena;
private final List<ItemInstance> _items = new CopyOnWriteArrayList<>();
private int _totalWeight;
public int getSize()
{
return _items.size();
}
public ItemInstance[] getItems()
{
return _items.toArray(new ItemInstance[_items.size()]);
}
public ItemInstance addItem(ItemInstance newItem)
{
ItemInstance old;
ItemInstance result = newItem;
boolean stackableFound = false;
if (newItem.getItemId() == 57)
{
addAdena(newItem.getCount());
return _adena;
}
if (newItem.isStackable() && ((old = findItemByItemId(newItem.getItemId())) != null))
{
old.setCount(old.getCount() + newItem.getCount());
stackableFound = true;
old.setLastChange(2);
result = old;
}
if (!stackableFound)
{
_items.add(newItem);
newItem.setLastChange(1);
}
refreshWeight();
return result;
}
public ItemInstance findItemByItemId(int itemId)
{
for (int i = 0; i < _items.size(); ++i)
{
ItemInstance temp = _items.get(i);
if (temp.getItemId() != itemId)
{
continue;
}
return temp;
}
return null;
}
public ItemInstance getPaperdollItem(int slot)
{
return _paperdoll[slot];
}
public int getPaperdollItemId(int slot)
{
if (_paperdoll[slot] != null)
{
return _paperdoll[slot].getItemId();
}
return 0;
}
public int getPaperdollObjectId(int slot)
{
if (_paperdoll[slot] != null)
{
return _paperdoll[slot].getObjectId();
}
return 0;
}
public void setPaperdollItem(int slot, ItemInstance item)
{
_paperdoll[slot] = item;
item.setEquipSlot(slot);
refreshWeight();
}
public ItemInstance[] unEquipItemInBodySlot(int slot)
{
List<ItemInstance> unequipedItems = new ArrayList<>();
// _log.fine("--- unequip body slot:" + slot);
int pdollSlot = -1;
switch (slot)
{
case 4:
{
pdollSlot = 1;
break;
}
case 2:
{
pdollSlot = 2;
break;
}
case 8:
{
pdollSlot = 3;
break;
}
case 16:
{
pdollSlot = 5;
break;
}
case 32:
{
pdollSlot = 4;
break;
}
case 64:
{
pdollSlot = 6;
break;
}
case 128:
{
pdollSlot = 7;
break;
}
case 256:
{
pdollSlot = 8;
break;
}
case 512:
{
pdollSlot = 9;
break;
}
case 1024:
case 32768:
{
pdollSlot = 10;
break;
}
case 2048:
{
pdollSlot = 11;
break;
}
case 16384:
{
this.unEquipSlot(unequipedItems, 8);
this.unEquipSlot(7);
pdollSlot = 14;
break;
}
case 8192:
{
pdollSlot = 13;
break;
}
case 4096:
{
pdollSlot = 12;
break;
}
case 1:
{
pdollSlot = 0;
}
}
this.unEquipSlot(unequipedItems, pdollSlot);
return unequipedItems.toArray(new ItemInstance[unequipedItems.size()]);
}
public ItemInstance[] unEquipItemOnPaperdoll(int pdollSlot)
{
List<ItemInstance> unequipedItems = new ArrayList<>();
// _log.fine("--- unequip body slot:" + pdollSlot);
if (pdollSlot == 14)
{
this.unEquipSlot(unequipedItems, 8);
this.unEquipSlot(7);
}
this.unEquipSlot(unequipedItems, pdollSlot);
return unequipedItems.toArray(new ItemInstance[unequipedItems.size()]);
}
public List<ItemInstance> equipItem(ItemInstance item)
{
ArrayList<ItemInstance> changedItems = new ArrayList<>();
int targetSlot = item.getItem().getBodyPart();
switch (targetSlot)
{
case 16384:
{
ItemInstance arrow;
this.unEquipSlot(changedItems, 8);
ItemInstance old1 = this.unEquipSlot(14);
if (old1 != null)
{
changedItems.add(old1);
this.unEquipSlot(7);
this.unEquipSlot(changedItems, 8);
}
else
{
this.unEquipSlot(changedItems, 7);
}
setPaperdollItem(7, item);
setPaperdollItem(14, item);
if ((((L2Weapon) item.getItem()).getWeaponType() != 5) || ((arrow = findArrowForBow(item.getItem())) == null))
{
break;
}
setPaperdollItem(8, arrow);
arrow.setLastChange(2);
changedItems.add(arrow);
break;
}
case 256:
{
ItemInstance old1 = this.unEquipSlot(14);
if (old1 != null)
{
this.unEquipSlot(changedItems, 7);
}
this.unEquipSlot(changedItems, 8);
setPaperdollItem(8, item);
break;
}
case 128:
{
if (this.unEquipSlot(changedItems, 14))
{
this.unEquipSlot(changedItems, 8);
this.unEquipSlot(7);
}
else
{
this.unEquipSlot(changedItems, 7);
}
setPaperdollItem(7, item);
break;
}
case 6:
{
if (_paperdoll[1] == null)
{
setPaperdollItem(1, item);
break;
}
if (_paperdoll[2] == null)
{
setPaperdollItem(2, item);
break;
}
this.unEquipSlot(changedItems, 1);
setPaperdollItem(1, item);
break;
}
case 48:
{
if (_paperdoll[4] == null)
{
setPaperdollItem(4, item);
break;
}
if (_paperdoll[5] == null)
{
setPaperdollItem(5, item);
break;
}
this.unEquipSlot(changedItems, 4);
setPaperdollItem(4, item);
break;
}
case 8:
{
this.unEquipSlot(changedItems, 3);
setPaperdollItem(3, item);
break;
}
case 32768:
{
this.unEquipSlot(changedItems, 10);
this.unEquipSlot(changedItems, 11);
setPaperdollItem(10, item);
break;
}
case 1024:
{
this.unEquipSlot(changedItems, 10);
setPaperdollItem(10, item);
break;
}
case 2048:
{
ItemInstance chest = getPaperdollItem(10);
if ((chest != null) && (chest.getItem().getBodyPart() == 32768))
{
this.unEquipSlot(changedItems, 10);
}
this.unEquipSlot(changedItems, 11);
setPaperdollItem(11, item);
break;
}
case 4096:
{
this.unEquipSlot(changedItems, 12);
setPaperdollItem(12, item);
break;
}
case 512:
{
this.unEquipSlot(changedItems, 9);
setPaperdollItem(9, item);
break;
}
case 64:
{
this.unEquipSlot(changedItems, 6);
setPaperdollItem(6, item);
break;
}
case 1:
{
this.unEquipSlot(changedItems, 0);
setPaperdollItem(0, item);
break;
}
case 8192:
{
this.unEquipSlot(changedItems, 13);
setPaperdollItem(13, item);
break;
}
default:
{
_log.warning("unknown body slot:" + targetSlot);
}
}
changedItems.add(item);
item.setLastChange(2);
return changedItems;
}
private ItemInstance unEquipSlot(int slot)
{
_log.fine("--- unEquipSlot: " + slot);
ItemInstance item = _paperdoll[slot];
if (item != null)
{
item.setEquipSlot(-1);
item.setLastChange(2);
_paperdoll[slot] = null;
}
return item;
}
private boolean unEquipSlot(List<ItemInstance> changedItems, int slot)
{
if (slot == -1)
{
return false;
}
ItemInstance item = _paperdoll[slot];
if (item != null)
{
item.setEquipSlot(-1);
changedItems.add(item);
item.setLastChange(2);
_paperdoll[slot] = null;
}
return item != null;
}
public ItemInstance getItem(int objectId)
{
for (int i = 0; i < _items.size(); ++i)
{
ItemInstance temp = _items.get(i);
if (temp.getObjectId() != objectId)
{
continue;
}
return temp;
}
return null;
}
public ItemInstance getAdenaInstance()
{
return _adena;
}
public int getAdena()
{
if (_adena == null)
{
return 0;
}
return _adena.getCount();
}
public void setAdena(int adena)
{
if (adena == 0)
{
if ((_adena != null) && _items.contains(_adena))
{
_items.remove(_adena);
_adena = null;
}
}
else
{
if (_adena == null)
{
_adena = ItemTable.getInstance().createItem(57);
}
_adena.setCount(adena);
if (!_items.contains(_adena))
{
_items.add(_adena);
}
}
}
public void addAdena(int adena)
{
setAdena(getAdena() + adena);
}
public void reduceAdena(int adena)
{
setAdena(getAdena() - adena);
}
public ItemInstance destroyItem(int objectId, int count)
{
ItemInstance item = getItem(objectId);
if (item.getCount() == count)
{
_items.remove(item);
item.setCount(0);
item.setLastChange(3);
}
else
{
item.setCount(item.getCount() - count);
item.setLastChange(2);
}
refreshWeight();
return item;
}
public ItemInstance destroyItemByItemId(int itemId, int count)
{
ItemInstance item = findItemByItemId(itemId);
if (item.getCount() == count)
{
_items.remove(item);
item.setCount(0);
item.setLastChange(3);
}
else
{
item.setCount(item.getCount() - count);
item.setLastChange(2);
}
refreshWeight();
return item;
}
public ItemInstance dropItem(int objectId, int count)
{
ItemInstance oldItem = getItem(objectId);
return this.dropItem(oldItem, count);
}
public ItemInstance dropItem(ItemInstance oldItem, int count)
{
if (oldItem == null)
{
_log.warning("DropItem: item id does not exist in inventory");
return null;
}
if (oldItem.isEquipped())
{
unEquipItemInBodySlot(oldItem.getItem().getBodyPart());
}
if (oldItem.getItemId() == 57)
{
reduceAdena(count);
ItemInstance adena = ItemTable.getInstance().createItem(oldItem.getItemId());
adena.setCount(count);
return adena;
}
if (oldItem.getCount() == count)
{
_log.fine(" count = count --> remove");
_items.remove(oldItem);
oldItem.setLastChange(3);
refreshWeight();
return oldItem;
}
_log.fine(" count != count --> reduce");
oldItem.setCount(oldItem.getCount() - count);
oldItem.setLastChange(2);
ItemInstance newItem = ItemTable.getInstance().createItem(oldItem.getItemId());
newItem.setCount(count);
refreshWeight();
return newItem;
}
private void refreshWeight()
{
int weight = 0;
Iterator<ItemInstance> iter = _items.iterator();
while (iter.hasNext())
{
ItemInstance element = iter.next();
weight += element.getItem().getWeight() * element.getCount();
}
_totalWeight = weight;
}
public int getTotalWeight()
{
return _totalWeight;
}
public ItemInstance findArrowForBow(L2Item bow)
{
int arrowsId = 0;
switch (bow.getCrystalType())
{
case 1:
{
arrowsId = 17;
break;
}
case 2:
{
arrowsId = 1341;
break;
}
case 3:
{
arrowsId = 1342;
break;
}
case 4:
{
arrowsId = 1343;
break;
}
case 5:
{
arrowsId = 1344;
break;
}
case 6:
{
arrowsId = 1345;
break;
}
default:
{
arrowsId = 17;
}
}
return findItemByItemId(arrowsId);
}
}

View File

@@ -0,0 +1,47 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class Location
{
private final int _x;
private final int _y;
private final int _z;
public Location(int x, int y, int z)
{
_x = x;
_y = y;
_z = z;
}
public int getX()
{
return _x;
}
public int getY()
{
return _y;
}
public int getZ()
{
return _z;
}
}

View File

@@ -0,0 +1,99 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class LvlupData
{
private int _classid;
private double _defaulthp;
private double _defaulthpadd;
private double _defaulthpbonus;
private double _defaultmp;
private double _defaultmpadd;
private double _defaultmpbonus;
public int getClassid()
{
return _classid;
}
public double getDefaulthp()
{
return _defaulthp;
}
public double getDefaulthpadd()
{
return _defaulthpadd;
}
public double getDefaulthpbonus()
{
return _defaulthpbonus;
}
public double getDefaultmp()
{
return _defaultmp;
}
public double getDefaultmpadd()
{
return _defaultmpadd;
}
public double getDefaultmpbonus()
{
return _defaultmpbonus;
}
public void setClassid(int classid)
{
_classid = classid;
}
public void setDefaulthp(double defaulthp)
{
_defaulthp = defaulthp;
}
public void setDefaulthpadd(double defaulthpadd)
{
_defaulthpadd = defaulthpadd;
}
public void setDefaulthpbonus(double defaulthpbonus)
{
_defaulthpbonus = defaulthpbonus;
}
public void setDefaultmp(double defaultmp)
{
_defaultmp = defaultmp;
}
public void setDefaultmpadd(double defaultmpadd)
{
_defaultmpadd = defaultmpadd;
}
public void setDefaultmpbonus(double defaultmpbonus)
{
_defaultmpbonus = defaultmpbonus;
}
}

View File

@@ -0,0 +1,274 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
import java.util.ArrayList;
import java.util.List;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
import org.l2jmobius.gameserver.network.serverpackets.PartySmallWindowAdd;
import org.l2jmobius.gameserver.network.serverpackets.PartySmallWindowAll;
import org.l2jmobius.gameserver.network.serverpackets.PartySmallWindowDelete;
import org.l2jmobius.gameserver.network.serverpackets.PartySmallWindowDeleteAll;
import org.l2jmobius.gameserver.network.serverpackets.ServerBasePacket;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
import org.l2jmobius.util.Rnd;
public class Party
{
private final List<PlayerInstance> _members = new ArrayList<>();
private boolean _randomLoot = false;
private int _partyLvl = 0;
public Party(PlayerInstance leader, boolean randomLoot)
{
_randomLoot = randomLoot;
_members.add(leader);
_partyLvl = leader.getLevel() * leader.getLevel();
}
public int getMemberCount()
{
return _members.size();
}
public List<PlayerInstance> getPartyMembers()
{
return _members;
}
private PlayerInstance getRandomMember()
{
return (PlayerInstance) _members.toArray()[Rnd.get(_members.size())];
}
public boolean isLeader(PlayerInstance player)
{
return _members.get(0).equals(player);
}
public void broadcastToPartyMembers(ServerBasePacket msg)
{
for (int i = 0; i < _members.size(); ++i)
{
PlayerInstance member = _members.get(i);
member.sendPacket(msg);
}
}
public void broadcastToPartyMembers(PlayerInstance player, ServerBasePacket msg)
{
for (int i = 0; i < _members.size(); ++i)
{
PlayerInstance member = _members.get(i);
if (member.equals(player))
{
continue;
}
member.sendPacket(msg);
}
}
public void addPartyMember(PlayerInstance player)
{
PartySmallWindowAll window = new PartySmallWindowAll();
window.setPartyList(_members);
player.sendPacket(window);
SystemMessage msg = new SystemMessage(106);
msg.addString(_members.get(0).getName());
player.sendPacket(msg);
msg = new SystemMessage(107);
msg.addString(player.getName());
this.broadcastToPartyMembers(msg);
this.broadcastToPartyMembers(new PartySmallWindowAdd(player));
_members.add(player);
_partyLvl += player.getLevel() * player.getLevel();
}
public void removePartyMember(PlayerInstance player)
{
if (_members.contains(player))
{
_members.remove(player);
_partyLvl -= player.getLevel() * player.getLevel();
SystemMessage msg = new SystemMessage(200);
player.sendPacket(msg);
player.sendPacket(new PartySmallWindowDeleteAll());
player.setParty(null);
msg = new SystemMessage(108);
msg.addString(player.getName());
this.broadcastToPartyMembers(msg);
this.broadcastToPartyMembers(new PartySmallWindowDelete(player));
if (_members.size() == 1)
{
_members.get(0).setParty(null);
}
}
}
private PlayerInstance getPlayerByName(String name)
{
for (int i = 0; i < _members.size(); ++i)
{
PlayerInstance temp = _members.get(i);
if (!temp.getName().equals(name))
{
continue;
}
return temp;
}
return null;
}
public void oustPartyMember(PlayerInstance player)
{
if (_members.contains(player))
{
if (isLeader(player))
{
dissolveParty();
}
else
{
removePartyMember(player);
}
}
}
public void oustPartyMember(String name)
{
PlayerInstance player = getPlayerByName(name);
if (player != null)
{
if (isLeader(player))
{
dissolveParty();
}
else
{
removePartyMember(player);
}
}
}
private void dissolveParty()
{
SystemMessage msg = new SystemMessage(203);
for (int i = 0; i < _members.size(); ++i)
{
PlayerInstance temp = _members.get(i);
temp.sendPacket(msg);
temp.sendPacket(new PartySmallWindowDeleteAll());
temp.setParty(null);
}
}
public void distributeItem(PlayerInstance player, ItemInstance item)
{
SystemMessage smsg;
PlayerInstance target = null;
target = _randomLoot ? getRandomMember() : player;
if (item.getCount() == 1)
{
smsg = new SystemMessage(30);
smsg.addItemName(item.getItemId());
target.sendPacket(smsg);
smsg = new SystemMessage(300);
smsg.addString(target.getName());
smsg.addItemName(item.getItemId());
this.broadcastToPartyMembers(target, smsg);
}
else
{
smsg = new SystemMessage(29);
smsg.addNumber(item.getCount());
smsg.addItemName(item.getItemId());
target.sendPacket(smsg);
smsg = new SystemMessage(299);
smsg.addString(target.getName());
smsg.addNumber(item.getCount());
smsg.addItemName(item.getItemId());
this.broadcastToPartyMembers(target, smsg);
}
ItemInstance item2 = target.getInventory().addItem(item);
InventoryUpdate iu = new InventoryUpdate();
if (item2.getLastChange() == 1)
{
iu.addNewItem(item);
}
else
{
iu.addModifiedItem(item2);
}
target.sendPacket(iu);
UserInfo ci = new UserInfo(target);
target.sendPacket(ci);
}
public void distributeAdena(ItemInstance adena)
{
adena.setCount(adena.getCount() / _members.size());
SystemMessage smsg = new SystemMessage(28);
smsg.addNumber(adena.getCount());
for (int i = 0; i < _members.size(); ++i)
{
PlayerInstance member = _members.get(i);
ItemInstance item2 = member.getInventory().addItem(adena);
InventoryUpdate iu = new InventoryUpdate();
if (item2.getLastChange() == 1)
{
iu.addNewItem(adena);
}
else
{
iu.addModifiedItem(item2);
}
member.sendPacket(smsg);
member.sendPacket(iu);
}
}
public void distributeXpAndSp(int partyDmg, int maxHp, int xpReward, int spReward)
{
double mul = (Math.pow(1.07, _members.size() - 1) * partyDmg) / maxHp;
double xpTotal = mul * xpReward;
double spTotal = mul * spReward;
for (int i = 0; i < _members.size(); ++i)
{
PlayerInstance player = _members.get(i);
mul = ((double) player.getLevel() * (double) player.getLevel()) / _partyLvl;
int xp = (int) (mul * xpTotal);
int sp = (int) (mul * spTotal);
player.addExpAndSp(xp, sp);
}
}
public void recalculatePartyLevel()
{
int newlevel = 0;
for (int i = 0; i < _members.size(); ++i)
{
int plLevel = _members.get(i).getLevel();
newlevel += plLevel * plLevel;
}
_partyLvl = newlevel;
}
}

View File

@@ -0,0 +1,280 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.actor.Creature;
public class Potion extends WorldObject
{
private static final Logger _log = Logger.getLogger(Potion.class.getName());
Creature _target;
private static Timer _regenTimer = new Timer(true);
private PotionHpHealing _potionhpRegTask;
// private boolean _potionhpRegenActive;
private PotionMpHealing _potionmpRegTask;
// private boolean _potionmpRegenActive;
private int _seconds;
private double _effect;
private int _duration;
private int _potion;
private final Object _mpLock;
private final Object _hpLock;
public Potion()
{
_potionhpRegTask = new PotionHpHealing(_target);
_potionmpRegTask = new PotionMpHealing(_target);
_mpLock = new Object();
_hpLock = new Object();
}
private void startPotionHpRegeneration(Creature activeChar)
{
_potionhpRegTask = new PotionHpHealing(activeChar);
_regenTimer.schedule(_potionhpRegTask, 1000L, _seconds);
// this._potionhpRegenActive = true;
// _log.fine("Potion HP regen Started");
}
public void stopPotionHpRegeneration()
{
if (_potionhpRegTask != null)
{
_potionhpRegTask.cancel();
}
_potionhpRegTask = null;
// this._potionhpRegenActive = false;
// _log.fine("Potion HP regen stop");
}
public void setCurrentHpPotion2(Creature activeChar)
{
if (_duration == 0)
{
stopPotionHpRegeneration();
}
}
public void setCurrentHpPotion1(Creature activeChar, int item)
{
_potion = item;
_target = activeChar;
switch (_potion)
{
case 65:
{
_seconds = 3000;
_duration = 15;
_effect = 2.0;
startPotionHpRegeneration(activeChar);
break;
}
case 725:
{
_seconds = 1000;
_duration = 20;
_effect = 1.5;
startPotionHpRegeneration(activeChar);
break;
}
case 727:
{
_seconds = 1000;
_duration = 20;
_effect = 1.5;
startPotionHpRegeneration(activeChar);
break;
}
case 1060:
{
_seconds = 3000;
_duration = 15;
_effect = 4.0;
startPotionHpRegeneration(activeChar);
break;
}
case 1061:
{
_seconds = 3000;
_duration = 15;
_effect = 14.0;
startPotionHpRegeneration(activeChar);
break;
}
case 1073:
{
_seconds = 3000;
_duration = 15;
_effect = 2.0;
startPotionHpRegeneration(activeChar);
break;
}
case 1539:
{
_seconds = 3000;
_duration = 15;
_effect = 32.0;
startPotionHpRegeneration(activeChar);
break;
}
case 1540:
{
double nowHp = activeChar.getCurrentHp();
nowHp += 435.0;
if (nowHp >= activeChar.getMaxHp())
{
nowHp = activeChar.getMaxHp();
}
activeChar.setCurrentHp(nowHp);
}
}
}
private void startPotionMpRegeneration(Creature activeChar)
{
_potionmpRegTask = new PotionMpHealing(activeChar);
_regenTimer.schedule(_potionmpRegTask, 1000L, _seconds);
// this._potionmpRegenActive = true;
// _log.fine("Potion MP regen Started");
}
public void stopPotionMpRegeneration()
{
if (_potionmpRegTask != null)
{
_potionmpRegTask.cancel();
}
_potionmpRegTask = null;
// this._potionmpRegenActive = false;
// _log.fine("Potion MP regen stop");
}
public void setCurrentMpPotion2(Creature activeChar)
{
if (_duration == 0)
{
stopPotionMpRegeneration();
}
}
public void setCurrentMpPotion1(Creature activeChar, int item)
{
_potion = item;
_target = activeChar;
switch (_potion)
{
case 726:
{
_seconds = 1000;
_duration = 20;
_effect = 1.5;
startPotionMpRegeneration(activeChar);
break;
}
case 728:
{
double nowMp = activeChar.getMaxMp();
nowMp += 435.0;
if (nowMp >= activeChar.getMaxMp())
{
nowMp = activeChar.getMaxMp();
}
activeChar.setCurrentMp(nowMp);
}
}
}
class PotionMpHealing extends TimerTask
{
Creature _instance;
public PotionMpHealing(Creature instance)
{
_instance = instance;
}
@Override
public void run()
{
try
{
Object object = _mpLock;
synchronized (object)
{
double nowMp = _instance.getCurrentMp();
if (_duration == 0)
{
stopPotionMpRegeneration();
}
if (_duration != 0)
{
_instance.setCurrentMp(nowMp += _effect);
_duration = _duration - (_seconds / 1000);
setCurrentMpPotion2(_instance);
}
}
}
catch (Exception e)
{
_log.warning("error in mp potion task:" + e);
}
}
}
class PotionHpHealing extends TimerTask
{
Creature _instance;
public PotionHpHealing(Creature instance)
{
_instance = instance;
}
@Override
public void run()
{
try
{
Object object = _hpLock;
synchronized (object)
{
double nowHp = _instance.getCurrentHp();
if (_duration == 0)
{
stopPotionHpRegeneration();
}
if (_duration != 0)
{
_instance.setCurrentHp(nowHp += _effect);
_duration = _duration - (_seconds / 1000);
setCurrentHpPotion2(_instance);
}
}
}
catch (Exception e)
{
_log.warning("Error in hp potion task:" + e);
}
}
}
}

View File

@@ -0,0 +1,27 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class Race
{
public static final int human = 0;
public static final int elf = 1;
public static final int darkelf = 2;
public static final int orc = 3;
public static final int dwarf = 4;
}

View File

@@ -0,0 +1,24 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class Sex
{
public static final int male = 0;
public static final int female = 1;
}

View File

@@ -0,0 +1,89 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class ShortCut
{
public static final int TYPE_SKILL = 2;
public static final int TYPE_ACTION = 3;
public static final int TYPE_ITEM = 1;
private int _slot;
private int _type;
private int _id;
private int _level;
private int _unk;
public ShortCut(int slot, int type, int id, int level, int unk)
{
_slot = slot;
_type = type;
_id = id;
_level = level;
_unk = unk;
}
public int getId()
{
return _id;
}
public void setId(int id)
{
_id = id;
}
public int getLevel()
{
return _level;
}
public void setLevel(int level)
{
_level = level;
}
public int getSlot()
{
return _slot;
}
public void setSlot(int slot)
{
_slot = slot;
}
public int getType()
{
return _type;
}
public void setType(int type)
{
_type = type;
}
public int getUnk()
{
return _unk;
}
public void setUnk(int unk)
{
_unk = unk;
}
}

View File

@@ -0,0 +1,214 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class Skill
{
public static int OP_ALWAYS = 1;
public static int OP_ONCE = 2;
public static int OP_DURATION = 3;
public static int OP_TOGGLE = 4;
public static int TARGET_SELF = 0;
public static int TARGET_ONE = 1;
public static int TARGET_PARTY = 2;
public static int TARGET_CLAN = 3;
public static int TARGET_PET = 4;
public static int TARGET_ENEMY = 5;
public static int TARGET_FRIEND = 6;
private int _id;
private int _level;
private String _name;
private int _operateType;
private boolean _magic;
private int _mpConsume;
private int _hpConsume;
private int _itemConsume;
private int _itemConsumeId;
private int _castRange;
private int _skillTime;
private int _hitTime;
private int _reuseDelay;
private int _buffDuration;
private int _targetType;
private int _power;
public int getPower()
{
return _power;
}
public void setPower(int power)
{
_power = power;
}
public int getBuffDuration()
{
return _buffDuration;
}
public void setBuffDuration(int buffDuration)
{
_buffDuration = buffDuration;
}
public int getCastRange()
{
return _castRange;
}
public void setCastRange(int castRange)
{
_castRange = castRange;
}
public int getHitTime()
{
return _hitTime;
}
public void setHitTime(int hitTime)
{
_hitTime = hitTime;
}
public int getHpConsume()
{
return _hpConsume;
}
public void setHpConsume(int hpConsume)
{
_hpConsume = hpConsume;
}
public int getId()
{
return _id;
}
public void setId(int id)
{
_id = id;
}
public int getItemConsume()
{
return _itemConsume;
}
public void setItemConsume(int itemConsume)
{
_itemConsume = itemConsume;
}
public int getItemConsumeId()
{
return _itemConsumeId;
}
public void setItemConsumeId(int itemConsumeId)
{
_itemConsumeId = itemConsumeId;
}
public int getLevel()
{
return _level;
}
public void setLevel(int level)
{
_level = level;
}
public boolean isMagic()
{
return _magic;
}
public void setMagic(boolean magic)
{
_magic = magic;
}
public int getMpConsume()
{
return _mpConsume;
}
public void setMpConsume(int mpConsume)
{
_mpConsume = mpConsume;
}
public String getName()
{
return _name;
}
public void setName(String name)
{
_name = name;
}
public int getOperateType()
{
return _operateType;
}
public void setOperateType(int operateType)
{
_operateType = operateType;
}
public int getReuseDelay()
{
return _reuseDelay;
}
public void setReuseDelay(int reuseDelay)
{
_reuseDelay = reuseDelay;
}
public int getSkillTime()
{
return _skillTime;
}
public void setSkillTime(int skillTime)
{
_skillTime = skillTime;
}
public int getTargetType()
{
return _targetType;
}
public void setTargetType(int targetType)
{
_targetType = targetType;
}
public boolean isPassive()
{
return _operateType == OP_ALWAYS;
}
}

View File

@@ -0,0 +1,77 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class SkillLearn
{
private int _id;
private int _level;
private String _name;
private int _spCost;
private int _minLevel;
public int getId()
{
return _id;
}
public void setId(int id)
{
_id = id;
}
public int getLevel()
{
return _level;
}
public void setLevel(int level)
{
_level = level;
}
public int getMinLevel()
{
return _minLevel;
}
public void setMinLevel(int minLevel)
{
_minLevel = minLevel;
}
public String getName()
{
return _name;
}
public void setName(String name)
{
_name = name;
}
public int getSpCost()
{
return _spCost;
}
public void setSpCost(int spCost)
{
_spCost = spCost;
}
}

View File

@@ -0,0 +1,285 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
import java.lang.reflect.Constructor;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.IdFactory;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
import org.l2jmobius.gameserver.templates.L2Npc;
import org.l2jmobius.util.Rnd;
public class Spawn
{
private static Logger _log = Logger.getLogger(Spawn.class.getName());
private final L2Npc _template;
private int _id;
private String _location;
private int _maximumCount;
private int _currentCount;
private int _scheduledCount;
private int _npcid;
private int _locx;
private int _locy;
private int _locz;
private int _randomx;
private int _randomy;
private int _heading;
private int _respawnDelay;
private static Timer _spawnTimer = new Timer(true);
private final Constructor<?> _constructor;
public Spawn(L2Npc mobTemplate) throws SecurityException, ClassNotFoundException
{
_template = mobTemplate;
String implementationName = _template.getType();
_constructor = Class.forName("org.l2jmobius.gameserver.model.actor.instance." + implementationName + "Instance").getConstructors()[0];
}
public int getAmount()
{
return _maximumCount;
}
public int getId()
{
return _id;
}
public String getLocation()
{
return _location;
}
public int getLocx()
{
return _locx;
}
public int getLocy()
{
return _locy;
}
public int getLocz()
{
return _locz;
}
public int getNpcid()
{
return _npcid;
}
public int getHeading()
{
return _heading;
}
public int getRandomx()
{
return _randomx;
}
public int getRandomy()
{
return _randomy;
}
public void setAmount(int amount)
{
_maximumCount = amount;
}
public void setId(int id)
{
_id = id;
}
public void setLocation(String location)
{
_location = location;
}
public void setLocx(int locx)
{
_locx = locx;
}
public void setLocy(int locy)
{
_locy = locy;
}
public void setLocz(int locz)
{
_locz = locz;
}
public void setNpcid(int npcid)
{
_npcid = npcid;
}
public void setHeading(int heading)
{
_heading = heading;
}
public void setRandomx(int randomx)
{
_randomx = randomx;
}
public void setRandomy(int randomy)
{
_randomy = randomy;
}
public void decreaseCount(int npcId)
{
--_currentCount;
if ((_scheduledCount + _currentCount) < _maximumCount)
{
++_scheduledCount;
SpawnTask task = new SpawnTask(npcId);
_spawnTimer.schedule(task, _respawnDelay);
}
}
public int init()
{
while (_currentCount < _maximumCount)
{
doSpawn();
}
return _currentCount;
}
public void doSpawn()
{
NpcInstance mob = null;
try
{
Object[] parameters = new Object[]
{
_template
};
mob = (NpcInstance) _constructor.newInstance(parameters);
mob.setObjectId(IdFactory.getInstance().getNextId());
if (mob instanceof MonsterInstance)
{
mob.setAttackable(true);
}
else
{
mob.setAttackable(false);
}
if (getRandomx() > 0)
{
int random1 = Rnd.get(getRandomx());
int newlocx = (getLocx() + Rnd.get(getRandomx())) - random1;
mob.setX(newlocx);
}
else
{
mob.setX(getLocx());
}
if (getRandomy() > 0)
{
int random2 = Rnd.get(getRandomy());
int newlocy = (getLocy() + Rnd.get(getRandomy())) - random2;
mob.setY(newlocy);
}
else
{
mob.setY(getLocy());
}
mob.setZ(getLocz());
mob.setLevel(_template.getLevel());
mob.setExpReward(_template.getExp());
mob.setSpReward(_template.getSp());
mob.setMaxHp(_template.getHp());
mob.setCurrentHp(_template.getHp());
mob.setWalkSpeed(_template.getWalkSpeed());
mob.setRunSpeed(_template.getRunSpeed());
mob.setPhysicalAttack(_template.getPatk());
mob.setPhysicalDefense(_template.getPdef());
mob.setMagicalAttack(_template.getMatk());
mob.setMagicalDefense(_template.getMdef());
mob.setMagicalSpeed(_template.getMatkspd());
if (getHeading() == -1)
{
mob.setHeading(Rnd.get(61794));
}
else
{
mob.setHeading(getHeading());
}
mob.setMovementMultiplier(1.08);
mob.setAttackSpeedMultiplier(0.983664);
mob.setAttackRange(_template.getAttackRange());
mob.setAggressive(_template.getAgro());
mob.setRightHandItem(_template.getRhand());
mob.setLeftHandItem(_template.getLhand());
mob.setSpawn(this);
World.getInstance().storeObject(mob);
World.getInstance().addVisibleObject(mob);
_log.finest("spawned Mob ID: " + _template.getNpcId() + " ,at: " + mob.getX() + " x, " + mob.getY() + " y, " + mob.getZ() + " z");
++_currentCount;
}
catch (Exception e)
{
_log.warning("NPC class not found");
}
}
public void setRespawnDelay(int i)
{
_respawnDelay = i * 1000;
}
class SpawnTask extends TimerTask
{
NpcInstance _instance;
int _objId;
public SpawnTask(int objid)
{
_objId = objid;
}
@Override
public void run()
{
try
{
doSpawn();
}
catch (Exception e)
{
e.printStackTrace();
}
_scheduledCount--;
}
}
}

View File

@@ -0,0 +1,99 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class StatModifiers
{
private int _classid;
private int _modstr;
private int _modcon;
private int _moddex;
private int _modint;
private int _modmen;
private int _modwit;
public int getClassid()
{
return _classid;
}
public int getModcon()
{
return _modcon;
}
public int getModdex()
{
return _moddex;
}
public int getModint()
{
return _modint;
}
public int getModmen()
{
return _modmen;
}
public int getModstr()
{
return _modstr;
}
public int getModwit()
{
return _modwit;
}
public void setClassid(int classid)
{
_classid = classid;
}
public void setModcon(int modcon)
{
_modcon = modcon;
}
public void setModdex(int moddex)
{
_moddex = moddex;
}
public void setModint(int modint)
{
_modint = modint;
}
public void setModmen(int modmen)
{
_modmen = modmen;
}
public void setModstr(int modstr)
{
_modstr = modstr;
}
public void setModwit(int modwit)
{
_modwit = modwit;
}
}

View File

@@ -0,0 +1,77 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class TeleportLocation
{
private int _teleId;
private int _locX;
private int _locY;
private int _locZ;
private int _price;
public void setTeleId(int id)
{
_teleId = id;
}
public void setLocX(int locX)
{
_locX = locX;
}
public void setLocY(int locY)
{
_locY = locY;
}
public void setLocZ(int locZ)
{
_locZ = locZ;
}
public void setPrice(int price)
{
_price = price;
}
public int getTeleId()
{
return _teleId;
}
public int getLocX()
{
return _locX;
}
public int getLocY()
{
return _locY;
}
public int getLocZ()
{
return _locZ;
}
public int getPrice()
{
return _price;
}
}

View File

@@ -0,0 +1,77 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class TradeItem
{
private int _ObjectId;
private int _ItemId;
private int _Price;
private int _storePrice;
private int _count;
public void setObjectId(int id)
{
_ObjectId = id;
}
public int getObjectId()
{
return _ObjectId;
}
public void setItemId(int id)
{
_ItemId = id;
}
public int getItemId()
{
return _ItemId;
}
public void setOwnersPrice(int price)
{
_Price = price;
}
public int getOwnersPrice()
{
return _Price;
}
public void setstorePrice(int price)
{
_storePrice = price;
}
public int getStorePrice()
{
return _storePrice;
}
public void setCount(int count)
{
_count = count;
}
public int getCount()
{
return _count;
}
}

View File

@@ -0,0 +1,352 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
import java.util.ArrayList;
import java.util.List;
import org.l2jmobius.gameserver.data.ItemTable;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
public class TradeList
{
private final List<ItemInstance> _items = new ArrayList<>();
private final int _listId;
private boolean _confirmed;
private String _Buystorename;
private String _Sellstorename;
public TradeList(int listId)
{
_listId = listId;
_confirmed = false;
}
public void addItem(ItemInstance item)
{
_items.add(item);
}
public int getListId()
{
return _listId;
}
public void setSellStoreName(String name)
{
_Sellstorename = name;
}
public String getSellStoreName()
{
return _Sellstorename;
}
public void setBuyStoreName(String name)
{
_Buystorename = name;
}
public String getBuyStoreName()
{
return _Buystorename;
}
public List<ItemInstance> getItems()
{
return _items;
}
public int getPriceForItemId(int itemId)
{
for (int i = 0; i < _items.size(); ++i)
{
ItemInstance item = _items.get(i);
if (item.getItemId() != itemId)
{
continue;
}
return item.getPrice();
}
return -1;
}
public ItemInstance getItem(int ObjectId)
{
for (int i = 0; i < _items.size(); ++i)
{
ItemInstance item = _items.get(i);
if (item.getObjectId() != ObjectId)
{
continue;
}
return item;
}
return null;
}
public void setConfirmedTrade(boolean x)
{
_confirmed = x;
}
public boolean hasConfirmed()
{
return _confirmed;
}
public void removeItem(int objId, int count)
{
for (int y = 0; y < _items.size(); ++y)
{
ItemInstance temp = _items.get(y);
if (temp.getObjectId() != objId)
{
continue;
}
if (count != temp.getCount())
{
break;
}
_items.remove(temp);
break;
}
}
public boolean contains(int objId)
{
boolean bool = false;
for (int y = 0; y < _items.size(); ++y)
{
ItemInstance temp = _items.get(y);
if (temp.getObjectId() != objId)
{
continue;
}
bool = true;
break;
}
return bool;
}
public void tradeItems(PlayerInstance player, PlayerInstance reciever)
{
Inventory playersInv = player.getInventory();
Inventory recieverInv = reciever.getInventory();
InventoryUpdate update = new InventoryUpdate();
ItemTable itemTable = ItemTable.getInstance();
for (int y = 0; y < _items.size(); ++y)
{
ItemInstance temp = _items.get(y);
ItemInstance playerItem = playersInv.getItem(temp.getObjectId());
ItemInstance newitem = itemTable.createItem(playerItem.getItemId());
newitem.setCount(temp.getCount());
playerItem = playersInv.destroyItem(playerItem.getObjectId(), temp.getCount());
ItemInstance recieverItem = recieverInv.addItem(newitem);
if (playerItem.getLastChange() == 2)
{
update.addModifiedItem(playerItem);
}
else
{
World world = World.getInstance();
world.removeObject(playerItem);
update.addRemovedItem(playerItem);
}
player.sendPacket(update);
update = new InventoryUpdate();
if (recieverItem.getLastChange() == 2)
{
update.addModifiedItem(recieverItem);
}
else
{
update.addNewItem(recieverItem);
}
reciever.sendPacket(update);
}
}
public void updateBuyList(PlayerInstance player, List<TradeItem> list)
{
Inventory playersInv = player.getInventory();
for (int count = 0; count != list.size(); ++count)
{
TradeItem temp = list.get(count);
ItemInstance temp2 = playersInv.findItemByItemId(temp.getItemId());
if (temp2 == null)
{
list.remove(count);
--count;
continue;
}
if (temp.getCount() != 0)
{
continue;
}
list.remove(count);
--count;
}
}
public void updateSellList(PlayerInstance player, List<TradeItem> list)
{
Inventory playersInv = player.getInventory();
for (int count = 0; count != list.size(); ++count)
{
TradeItem temp = list.get(count);
ItemInstance temp2 = playersInv.getItem(temp.getObjectId());
if (temp2 == null)
{
list.remove(count);
--count;
continue;
}
if (temp2.getCount() >= temp.getCount())
{
continue;
}
temp.setCount(temp2.getCount());
}
}
public synchronized void BuySellItems(PlayerInstance buyer, List<TradeItem> buyerlist, PlayerInstance seller, List<TradeItem> sellerlist)
{
int x;
int y;
Inventory sellerInv = seller.getInventory();
Inventory buyerInv = buyer.getInventory();
TradeItem temp2 = null;
WorldObject sellerItem = null;
ItemInstance newitem = null;
InventoryUpdate buyerupdate = new InventoryUpdate();
InventoryUpdate sellerupdate = new InventoryUpdate();
ItemTable itemTable = ItemTable.getInstance();
int cost = 0;
List<SystemMessage> sysmsgs = new ArrayList<>();
for (y = 0; y < buyerlist.size(); ++y)
{
SystemMessage msg;
TradeItem buyerItem = buyerlist.get(y);
for (x = 0; x < sellerlist.size(); ++x)
{
temp2 = sellerlist.get(x);
if (temp2.getItemId() != buyerItem.getItemId())
{
continue;
}
sellerItem = sellerInv.findItemByItemId(buyerItem.getItemId());
break;
}
if ((sellerItem == null) || (temp2 == null))
{
continue;
}
int amount = buyerItem.getCount() > temp2.getCount() ? temp2.getCount() : buyerItem.getCount();
sellerItem = sellerInv.destroyItem(sellerItem.getObjectId(), amount);
cost = buyerItem.getCount() * buyerItem.getOwnersPrice();
seller.addAdena(cost);
newitem = itemTable.createItem(((ItemInstance) sellerItem).getItemId());
newitem.setCount(amount);
ItemInstance temp = buyerInv.addItem(newitem);
if (amount == 1)
{
msg = new SystemMessage(378);
msg.addString(buyer.getName());
msg.addItemName(((ItemInstance) sellerItem).getItemId());
sysmsgs.add(msg);
msg = new SystemMessage(378);
msg.addString("You");
msg.addItemName(((ItemInstance) sellerItem).getItemId());
sysmsgs.add(msg);
}
else
{
msg = new SystemMessage(380);
msg.addString(buyer.getName());
msg.addItemName(((ItemInstance) sellerItem).getItemId());
msg.addNumber(amount);
sysmsgs.add(msg);
msg = new SystemMessage(380);
msg.addString("You");
msg.addItemName(((ItemInstance) sellerItem).getItemId());
msg.addNumber(amount);
sysmsgs.add(msg);
}
buyer.reduceAdena(cost);
if (temp2.getCount() == buyerItem.getCount())
{
sellerlist.remove(x);
buyerItem.setCount(0);
}
else if (buyerItem.getCount() < temp2.getCount())
{
temp2.setCount(temp2.getCount() - buyerItem.getCount());
}
else
{
buyerItem.setCount(buyerItem.getCount() - temp2.getCount());
}
if (((ItemInstance) sellerItem).getLastChange() == 2)
{
sellerupdate.addModifiedItem((ItemInstance) sellerItem);
}
else
{
World world = World.getInstance();
world.removeObject(sellerItem);
sellerupdate.addRemovedItem((ItemInstance) sellerItem);
}
if (temp.getLastChange() == 2)
{
buyerupdate.addModifiedItem(temp);
}
else
{
buyerupdate.addNewItem(temp);
}
sellerItem = null;
}
if (newitem != null)
{
ItemInstance adena = seller.getInventory().getAdenaInstance();
adena.setLastChange(2);
sellerupdate.addModifiedItem(adena);
adena = buyer.getInventory().getAdenaInstance();
adena.setLastChange(2);
buyerupdate.addModifiedItem(adena);
seller.sendPacket(sellerupdate);
buyer.sendPacket(buyerupdate);
y = 0;
for (x = 0; x < sysmsgs.size(); ++x)
{
if (y == 0)
{
seller.sendPacket(sysmsgs.get(x));
y = 1;
continue;
}
buyer.sendPacket(sysmsgs.get(x));
y = 0;
}
}
}
}

View File

@@ -0,0 +1,112 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
public class Warehouse
{
private static Logger _log = Logger.getLogger(Warehouse.class.getName());
private final List<ItemInstance> _items = new ArrayList<>();
public int getSize()
{
return _items.size();
}
public List<ItemInstance> getItems()
{
return _items;
}
public ItemInstance addItem(ItemInstance newItem)
{
ItemInstance old;
ItemInstance result = newItem;
boolean stackableFound = false;
if (newItem.isStackable() && ((old = findItemId(newItem.getItemId())) != null))
{
old.setCount(old.getCount() + newItem.getCount());
stackableFound = true;
old.setLastChange(2);
result = old;
}
if (!stackableFound)
{
_items.add(newItem);
newItem.setLastChange(1);
}
return result;
}
private ItemInstance findItemId(int itemId)
{
for (int i = 0; i < _items.size(); ++i)
{
ItemInstance temp = _items.get(i);
if (temp.getItemId() != itemId)
{
continue;
}
return temp;
}
return null;
}
public ItemInstance getItem(int objectId)
{
for (int i = 0; i < _items.size(); ++i)
{
ItemInstance temp = _items.get(i);
if (temp.getObjectId() != objectId)
{
continue;
}
return temp;
}
return null;
}
public ItemInstance destroyItem(int itemId, int count)
{
ItemInstance item = findItemId(itemId);
if (item != null)
{
if (item.getCount() == count)
{
_items.remove(item);
item.setCount(0);
item.setLastChange(3);
}
else
{
item.setCount(item.getCount() - count);
item.setLastChange(2);
}
}
else
{
_log.fine("can't destroy " + count + " item(s) " + itemId);
}
return item;
}
}

View File

@@ -0,0 +1,167 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.PlayerCountManager;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PetInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
public class World
{
private static Logger _log = Logger.getLogger(World.class.getName());
private final Map<String, WorldObject> _allPlayers = new ConcurrentHashMap<>();
private final Map<Integer, WorldObject> _allObjects = new ConcurrentHashMap<>();
private final Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
private static World _instance;
private World()
{
}
public static World getInstance()
{
if (_instance == null)
{
_instance = new World();
}
return _instance;
}
public void storeObject(WorldObject temp)
{
_allObjects.put(temp.getObjectId(), temp);
}
public void removeObject(WorldObject object)
{
_allObjects.remove(object.getObjectId());
}
public WorldObject findObject(int oID)
{
return _allObjects.get(oID);
}
public void addVisibleObject(WorldObject object)
{
if (object instanceof PlayerInstance)
{
_allPlayers.put(((PlayerInstance) object).getName().toLowerCase(), object);
WorldObject[] visible = getVisibleObjects(object, 2000);
_log.finest("Objects in range:" + visible.length);
for (WorldObject element : visible)
{
object.addKnownObject(element);
if ((object instanceof ItemInstance) && element.getKnownObjects().contains(object))
{
continue;
}
element.addKnownObject(object);
}
PlayerCountManager.getInstance().incConnectedCount();
}
else if ((_allPlayers.size() != 0) && !(object instanceof PetInstance) && !(object instanceof ItemInstance))
{
int x = object.getX();
int y = object.getY();
int sqRadius = 4000000;
Iterator<WorldObject> iter = _allPlayers.values().iterator();
while (iter.hasNext())
{
long dy;
PlayerInstance player = (PlayerInstance) iter.next();
int x1 = player.getX();
long dx = x1 - x;
long sqDist = (dx * dx) + ((dy = player.getY() - y) * dy);
if (sqDist >= sqRadius)
{
continue;
}
player.addKnownObject(object);
object.addKnownObject(player);
}
}
_visibleObjects.put(object.getObjectId(), object);
}
public void removeVisibleObject(WorldObject object)
{
_visibleObjects.remove(object.getObjectId());
// _log.fine("World has now " + this._visibleObjects.size() + " visible objects");
Object[] temp = object.getKnownObjects().toArray();
for (Object element : temp)
{
WorldObject temp1 = (WorldObject) element;
temp1.removeKnownObject(object);
object.removeKnownObject(temp1);
}
if (object instanceof PlayerInstance)
{
_allPlayers.remove(((PlayerInstance) object).getName().toLowerCase());
// TODO: Make sure the normal way works.
// PlayerCountManager.getInstance().decConnectedCount();
PlayerCountManager.getInstance().setConnectedCount(_allPlayers.size());
}
}
public WorldObject[] getVisibleObjects(WorldObject object, int radius)
{
int x = object.getX();
int y = object.getY();
int sqRadius = radius * radius;
List<WorldObject> result = new ArrayList<>();
Iterator<WorldObject> iter = _visibleObjects.values().iterator();
while (iter.hasNext())
{
@SuppressWarnings("unused")
int x1;
@SuppressWarnings("unused")
int y1;
long dx;
long dy;
@SuppressWarnings("unused")
long sqDist;
WorldObject element = iter.next();
if (element.equals(object) || ((sqDist = ((dx = (x1 = element.getX()) - x) * dx) + ((dy = (y1 = element.getY()) - y) * dy)) >= sqRadius))
{
continue;
}
result.add(element);
}
return result.toArray(new WorldObject[result.size()]);
}
public PlayerInstance[] getAllPlayers()
{
return _allPlayers.values().toArray(new PlayerInstance[_allPlayers.size()]);
}
public PlayerInstance getPlayer(String name)
{
return (PlayerInstance) _allPlayers.get(name.toLowerCase());
}
}

View File

@@ -0,0 +1,129 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
import java.io.Serializable;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
public class WorldObject implements Serializable
{
private int _objectId;
private int _x;
private int _y;
private int _z;
protected Set<WorldObject> _knownObjects = ConcurrentHashMap.newKeySet();
private final Set<PlayerInstance> _knownPlayer = ConcurrentHashMap.newKeySet();
public int getObjectId()
{
return _objectId;
}
public void setObjectId(int objectId)
{
_objectId = objectId;
}
public int getX()
{
return _x;
}
public void setX(int x)
{
_x = x;
}
public int getY()
{
return _y;
}
public void setY(int y)
{
_y = y;
}
public int getZ()
{
return _z;
}
public void setZ(int z)
{
_z = z;
}
public void onAction(PlayerInstance player)
{
player.sendPacket(new ActionFailed());
}
public void onActionShift(ClientThread client)
{
client.getActiveChar().sendPacket(new ActionFailed());
}
public void onForcedAttack(PlayerInstance player)
{
player.sendPacket(new ActionFailed());
}
public Set<WorldObject> getKnownObjects()
{
return _knownObjects;
}
public void addKnownObject(WorldObject object)
{
_knownObjects.add(object);
if (object instanceof PlayerInstance)
{
_knownPlayer.add((PlayerInstance) object);
}
}
public void removeKnownObject(WorldObject object)
{
_knownObjects.remove(object);
if (object instanceof PlayerInstance)
{
_knownPlayer.remove(object);
}
}
public void removeAllKnownObjects()
{
WorldObject[] notifyList = _knownObjects.toArray(new WorldObject[_knownObjects.size()]);
_knownObjects.clear();
for (WorldObject element : notifyList)
{
element.removeKnownObject(this);
}
}
public Set<PlayerInstance> getKnownPlayers()
{
return _knownPlayer;
}
}

View File

@@ -0,0 +1,22 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model;
public class WorldRegion
{
}

View File

@@ -0,0 +1,501 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.gameserver.data.ItemTable;
import org.l2jmobius.gameserver.model.DropData;
import org.l2jmobius.gameserver.model.Party;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.DropItem;
import org.l2jmobius.gameserver.templates.L2Npc;
import org.l2jmobius.gameserver.templates.L2Weapon;
import org.l2jmobius.util.Rnd;
public class Attackable extends NpcInstance
{
private static Logger _log = Logger.getLogger(Attackable.class.getName());
// private int _moveRadius;
private boolean _active;
private AITask _currentAiTask;
private AIAttackeTask _currentAIAttackeTask;
private static Timer _aiTimer = new Timer(true);
private static Timer _attackTimer = new Timer(true);
private final Map<WorldObject, Integer> _aggroList = new HashMap<>();
private L2Weapon _dummyWeapon;
private boolean _sweepActive;
private boolean _killedAlready = false;
public Attackable(L2Npc template)
{
super(template);
}
public boolean getCondition2(PlayerInstance player)
{
return false;
}
@Override
public void onTargetReached()
{
super.onTargetReached();
switch (getCurrentState())
{
case 1:
{
break;
}
case 5:
{
startCombat();
break;
}
case 6:
{
randomWalk();
break;
}
}
}
private void randomWalk()
{
if (_active)
{
_log.fine(getObjectId() + ": target reached ! new target calculated.");
int wait = (10 + Rnd.get(120)) * 1000;
_currentAiTask = new AITask(this);
_aiTimer.schedule(_currentAiTask, wait);
}
else
{
_log.fine(getObjectId() + ": target reached ! noone around .. cancel movement.");
}
}
protected void startRandomWalking()
{
_currentAiTask = new AITask(this);
int wait = (10 + Rnd.get(120)) * 1000;
_aiTimer.schedule(_currentAiTask, wait);
setCurrentState((byte) 6);
}
protected synchronized void startTargetScan()
{
if ((_currentAIAttackeTask == null) && (getTarget() == null))
{
_currentAIAttackeTask = new AIAttackeTask(this);
_attackTimer.scheduleAtFixedRate(_currentAIAttackeTask, 100L, 1000L);
}
}
@Override
public void startAttack(Creature target)
{
stopTargetScan();
super.startAttack(target);
}
@Override
public void setX(int x)
{
super.setX(x);
}
@Override
public void setY(int y)
{
super.setY(y);
}
@Override
public void setZ(int z)
{
super.setZ(z);
}
@Override
public void removeKnownObject(WorldObject object)
{
super.removeKnownObject(object);
if (object instanceof Creature)
{
_aggroList.remove(object);
}
}
@Override
public void reduceCurrentHp(int damage, Creature attacker)
{
super.reduceCurrentHp(damage, attacker);
calculateAggro(damage, attacker);
if (!isDead() && (attacker != null))
{
if (!isInCombat())
{
stopRandomWalking();
startAttack(attacker);
}
else
{
_log.fine("already attacking");
}
}
else if (isDead())
{
Attackable Attackable = this;
synchronized (Attackable)
{
if (!_killedAlready)
{
_killedAlready = true;
stopRandomWalking();
stopTargetScan();
calculateRewards(attacker);
}
}
}
}
private void calculateRewards(Creature lastAttacker)
{
Iterator<WorldObject> it = _aggroList.keySet().iterator();
// int numberOfAttackers = this._aggroList.size();
int npcID = getNpcTemplate().getNpcId();
// int npcLvl = this.getLevel();
while (it.hasNext())
{
PlayerInstance temp;
Creature attacker = (Creature) it.next();
Integer value = _aggroList.get(attacker);
Party attackerParty = null;
if ((attacker instanceof PlayerInstance) && (temp = (PlayerInstance) attacker).isInParty())
{
attackerParty = temp.getParty();
}
if ((npcID > 0) && (value != null) && (attackerParty == null))
{
int diff;
int newXp = 0;
int newSp = 0;
int dmg = value;
if (dmg > getMaxHp())
{
dmg = getMaxHp();
}
if (((diff = attacker.getLevel() - getLevel()) > 0) && (diff <= 9) && attacker.knownsObject(this))
{
newXp = getExpReward() * (dmg / getMaxHp());
newSp = getSpReward() * (dmg / getMaxHp());
newXp -= (int) ((diff / 10.0) * newXp);
newSp -= (int) ((diff / 10.0) * newSp);
}
else if ((diff <= 0) && attacker.knownsObject(this))
{
newXp = getExpReward() * (dmg / getMaxHp());
newSp = getSpReward() * (dmg / getMaxHp());
}
else if ((diff > 9) && attacker.knownsObject(this))
{
newXp = 0;
newSp = 0;
}
if (newXp <= 0)
{
newXp = 0;
newSp = 0;
}
else if ((newSp <= 0) && (newXp > 0))
{
newSp = 0;
}
attacker.addExpAndSp(newXp, newSp);
_aggroList.remove(attacker);
it = _aggroList.keySet().iterator();
continue;
}
int partyDmg = 0;
if (attackerParty != null)
{
List<PlayerInstance> members = attackerParty.getPartyMembers();
for (int i = 0; i < members.size(); ++i)
{
PlayerInstance tmp = members.get(i);
if (!_aggroList.containsKey(tmp))
{
continue;
}
partyDmg += _aggroList.get(tmp).intValue();
_aggroList.remove(tmp);
}
it = _aggroList.keySet().iterator();
if (partyDmg > getMaxHp())
{
partyDmg = getMaxHp();
}
attackerParty.distributeXpAndSp(partyDmg, getMaxHp(), getExpReward(), getSpReward());
}
}
doItemDrop();
}
private void calculateAggro(int damage, Creature attacker)
{
int newAggro = damage;
Integer aggroValue = _aggroList.get(attacker);
if (aggroValue != null)
{
newAggro += aggroValue.intValue();
}
_aggroList.put(attacker, newAggro);
if (_aggroList.size() == 1)
{
setTarget(attacker);
}
else
{
setTarget(attacker);
}
}
public void doItemDrop()
{
List<DropData> drops = getNpcTemplate().getDropData();
_log.finer("This npc has " + drops.size() + " drops defined.");
Iterator<DropData> iter = drops.iterator();
while (iter.hasNext())
{
DropData drop = iter.next();
if (drop.isSweep() || (Rnd.get(1000000) >= (drop.getChance() * Config.RATE_DROP)))
{
continue;
}
ItemInstance dropit = ItemTable.getInstance().createItem(drop.getItemId());
int min = drop.getMinDrop();
int max = drop.getMaxDrop();
int itemCount = 0;
itemCount = min < max ? Rnd.get(max - min) + min : 1;
if (dropit.getItemId() == 57)
{
itemCount *= Config.RATE_ADENA;
}
if (itemCount != 0)
{
dropit.setCount(itemCount);
_log.fine("Item id to drop: " + drop.getItemId() + " amount: " + dropit.getCount());
dropit.setX(getX());
dropit.setY(getY());
dropit.setZ(getZ() + 100);
dropit.setOnTheGround(true);
DropItem dis = new DropItem(dropit, getObjectId());
Creature[] players = broadcastPacket(dis);
for (Creature player : players)
{
((PlayerInstance) player).addKnownObjectWithoutCreate(dropit);
}
World.getInstance().addVisibleObject(dropit);
continue;
}
_log.finer("Roll produced 0 items to drop... Cancelling.");
}
}
protected void stopRandomWalking()
{
if (_currentAiTask != null)
{
_currentAiTask.cancel();
_currentAiTask = null;
}
}
protected boolean isTargetScanActive()
{
return _currentAIAttackeTask != null;
}
protected synchronized void stopTargetScan()
{
if (_currentAIAttackeTask != null)
{
_currentAIAttackeTask.cancel();
_currentAIAttackeTask = null;
}
}
@Override
public void setCurrentHp(double currentHp)
{
super.setCurrentHp(currentHp);
}
@Override
public L2Weapon getActiveWeapon()
{
return _dummyWeapon;
}
@Override
public void setPhysicalAttack(int physicalAttack)
{
super.setPhysicalAttack(physicalAttack);
_dummyWeapon = new L2Weapon();
_dummyWeapon.setPDamage(physicalAttack);
int randDmg = getLevel();
_dummyWeapon.setRandomDamage(randDmg);
}
public boolean noTarget()
{
return _aggroList.isEmpty();
}
public boolean containsTarget(Creature player)
{
return _aggroList.containsKey(player);
}
public void clearAggroList()
{
_aggroList.clear();
}
public boolean isActive()
{
return _active;
}
public void setActive(boolean b)
{
_active = b;
}
// public void setMoveRadius(int i)
// {
// this._moveRadius = i;
// }
public boolean isSweepActive()
{
return _sweepActive;
}
public void setSweepActive(boolean sweepActive)
{
_sweepActive = sweepActive;
}
class AIAttackeTask extends TimerTask
{
Creature _instance;
public AIAttackeTask(Creature instance)
{
_instance = instance;
}
@Override
public void run()
{
try
{
if (!isInCombat())
{
_log.finer(getObjectId() + ": monster knows " + getKnownPlayers().size() + " players");
Set<PlayerInstance> knownPlayers = getKnownPlayers();
Iterator<PlayerInstance> iter = knownPlayers.iterator();
while (iter.hasNext())
{
PlayerInstance player = iter.next();
if (!getCondition2(player) || !(getDistance(player.getX(), player.getY()) <= (getCollisionRadius() + 200.0)))
{
continue;
}
_log.fine(getObjectId() + ": Player " + player.getObjectId() + " in aggro range. Attacking!");
if (_currentAiTask != null)
{
_currentAiTask.cancel();
}
setTarget(player);
startAttack(player);
}
}
else if (_currentAIAttackeTask != null)
{
_currentAIAttackeTask.cancel();
}
}
catch (Throwable e)
{
_log.warning(getObjectId() + ": Problem occured in AiAttackTask:" + e);
StringWriter pw = new StringWriter();
PrintWriter prw = new PrintWriter(pw);
e.printStackTrace(prw);
_log.severe(pw.toString());
}
}
}
class AITask extends TimerTask
{
Creature _instance;
public AITask(Creature instance)
{
_instance = instance;
}
@Override
public void run()
{
try
{
int x1 = (getX() + Rnd.get(500)) - 250;
int y1 = (getY() + Rnd.get(500)) - 250;
moveTo(x1, y1, getZ(), 0);
}
catch (Throwable e)
{
_log.warning(getObjectId() + ": Problem occured in AiTask:" + e);
StringWriter pw = new StringWriter();
PrintWriter prw = new PrintWriter(pw);
e.printStackTrace(prw);
_log.severe(pw.toString());
}
}
}
}

View File

@@ -0,0 +1,161 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor.instance;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.CharInfo;
import org.l2jmobius.gameserver.network.serverpackets.MyTargetSelected;
import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
import org.l2jmobius.gameserver.network.serverpackets.SetToLocation;
import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
import org.l2jmobius.gameserver.templates.L2Npc;
public class ClassMasterInstance extends NpcInstance
{
private static Logger _log = Logger.getLogger(ClassMasterInstance.class.getName());
public ClassMasterInstance(L2Npc template)
{
super(template);
}
@Override
public void onAction(PlayerInstance player)
{
if (getObjectId() != player.getTargetId())
{
player.setCurrentState((byte) 0);
_log.fine("ClassMaster selected:" + getObjectId());
player.setTarget(this);
MyTargetSelected my = new MyTargetSelected(getObjectId(), player.getLevel() - getLevel());
player.sendPacket(my);
player.sendPacket(new SetToLocation(this));
}
else
{
_log.fine("ClassMaster activated");
int classId = player.getClassId();
int jobLevel = 0;
int level = player.getLevel();
switch (classId)
{
case 0:
case 10:
case 18:
case 25:
case 31:
case 38:
case 44:
case 49:
case 53:
{
jobLevel = 1;
break;
}
case 1:
case 4:
case 7:
case 11:
case 15:
case 19:
case 22:
case 26:
case 29:
case 32:
case 35:
case 39:
case 42:
case 45:
case 47:
case 50:
case 54:
case 56:
{
jobLevel = 2;
break;
}
default:
{
jobLevel = 3;
}
}
if (((level >= 20) && (jobLevel == 1)) || ((level >= 40) && (jobLevel == 2)))
{
showChatWindow(player, classId);
}
else
{
NpcHtmlMessage html = new NpcHtmlMessage(1);
switch (jobLevel)
{
case 1:
{
html.setHtml("<html><head><body>Come back here when you reached level 20.</body></html>");
break;
}
case 2:
{
html.setHtml("<html><head><body>Come back here when you reached level 40.</body></html>");
break;
}
case 3:
{
html.setHtml("<html><head><body>There is nothing more you can learn.</body></html>");
}
}
player.sendPacket(html);
}
player.sendPacket(new ActionFailed());
}
}
@Override
public String getHtmlPath(int npcId, int val)
{
return "data/html/classmaster/" + val + ".htm";
}
@Override
public void onBypassFeedback(PlayerInstance player, String command)
{
if (command.startsWith("change_class"))
{
int val = Integer.parseInt(command.substring(13));
changeClass(player, val);
}
else
{
super.onBypassFeedback(player, command);
}
}
private void changeClass(PlayerInstance player, int val)
{
// _log.fine("Changing class to ClassId:" + val);
player.setClassId(val);
// _log.fine("name:" + player.getName());
// _log.fine("level:" + player.getLevel());
// _log.fine("classId:" + player.getClassId());
UserInfo ui = new UserInfo(player);
player.sendPacket(ui);
CharInfo info = new CharInfo(player);
player.broadcastPacket(info);
}
}

View File

@@ -0,0 +1,77 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor.instance;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.WorldObject;
public class DoorInstance extends WorldObject
{
private static Logger _log = Logger.getLogger(DoorInstance.class.getName());
private int _damage;
private int _open;
private int _enemy;
private int _unknown;
@Override
public void onAction(PlayerInstance player)
{
_log.fine("Door activated");
}
public int getDamage()
{
return _damage;
}
public void setDamage(int damage)
{
_damage = damage;
}
public int getEnemy()
{
return _enemy;
}
public void setEnemy(int enemy)
{
_enemy = enemy;
}
public int getOpen()
{
return _open;
}
public void setOpen(int open)
{
_open = open;
}
public int getUnknown()
{
return _unknown;
}
public void setUnknown(int unknown)
{
_unknown = unknown;
}
}

View File

@@ -0,0 +1,140 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor.instance;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.MyTargetSelected;
import org.l2jmobius.gameserver.network.serverpackets.SetToLocation;
import org.l2jmobius.gameserver.templates.L2Npc;
public class GuardInstance extends Attackable
{
private static Logger _log = Logger.getLogger(GuardInstance.class.getName());
private static final int INTERACTION_DISTANCE = 150;
private int _homeX;
private int _homeY;
private int _homeZ;
private boolean _hasHome;
public GuardInstance(L2Npc template)
{
super(template);
setCurrentState((byte) 0);
}
@Override
public void addKnownObject(WorldObject object)
{
PlayerInstance player;
if (!_hasHome)
{
getHomeLocation();
}
super.addKnownObject(object);
if ((object instanceof PlayerInstance) && ((player = (PlayerInstance) object).getKarma() > 0) && !isTargetScanActive())
{
_log.fine(getObjectId() + ": PK " + player.getObjectId() + " entered scan range");
startTargetScan();
}
}
@Override
public void removeKnownObject(WorldObject object)
{
super.removeKnownObject(object);
if (getKnownPlayers().isEmpty())
{
setActive(false);
clearAggroList();
removeAllKnownObjects();
stopTargetScan();
}
if (noTarget())
{
returnHome();
}
}
private void getHomeLocation()
{
_hasHome = true;
_homeX = getX();
_homeY = getY();
_homeZ = getZ();
_log.finer(getObjectId() + ": Home location set to X:" + _homeX + " Y:" + _homeY + " Z:" + _homeZ);
}
private void returnHome()
{
_log.fine(getObjectId() + ": moving home");
clearAggroList();
moveTo(_homeX, _homeY, _homeZ, 0);
}
@Override
public boolean getCondition2(PlayerInstance player)
{
return !player.isDead() && (player.getKarma() > 0) && (Math.abs(getZ() - player.getZ()) <= 100);
}
@Override
public String getHtmlPath(int npcId, int val)
{
String pom = "";
pom = val == 0 ? "" + npcId : npcId + "-" + val;
return "data/html/guard/" + pom + ".htm";
}
@Override
public void onAction(PlayerInstance player)
{
if (getObjectId() != player.getTargetId())
{
player.setCurrentState((byte) 0);
_log.fine(player.getObjectId() + ": Targetted guard " + getObjectId());
player.setTarget(this);
MyTargetSelected my = new MyTargetSelected(getObjectId(), 0);
player.sendPacket(my);
player.sendPacket(new SetToLocation(this));
}
else if (containsTarget(player))
{
_log.fine(player.getObjectId() + ": Attacked guard " + getObjectId());
player.startAttack(this);
}
else
{
double distance = getDistance(player.getX(), player.getY());
if (distance > INTERACTION_DISTANCE)
{
player.setCurrentState((byte) 7);
player.moveTo(getX(), getY(), getZ(), 150);
}
else
{
showChatWindow(player, 0);
player.sendPacket(new ActionFailed());
player.setCurrentState((byte) 0);
}
}
}
}

View File

@@ -0,0 +1,136 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor.instance;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.templates.L2EtcItem;
import org.l2jmobius.gameserver.templates.L2Item;
public class ItemInstance extends WorldObject
{
private int _count = 1;
private int _itemId;
private L2Item _item;
private int _equippedSlot = -1;
private int _price;
private int _enchantLevel;
public static final int ADDED = 1;
public static final int REMOVED = 3;
public static final int MODIFIED = 2;
private int _lastChange = 2;
private boolean _onTheGround;
public int getCount()
{
return _count;
}
public void setCount(int count)
{
_count = count;
}
public boolean isEquipable()
{
return (_item.getBodyPart() != 0) && !(_item instanceof L2EtcItem);
}
public boolean isEquipped()
{
return _equippedSlot != -1;
}
public void setEquipSlot(int slot)
{
_equippedSlot = slot;
}
public int getEquipSlot()
{
return _equippedSlot;
}
public L2Item getItem()
{
return _item;
}
public void setItem(L2Item item)
{
_item = item;
_itemId = item.getItemId();
}
public int getItemId()
{
return _itemId;
}
public int getPrice()
{
return _price;
}
public void setPrice(int price)
{
_price = price;
}
public int getLastChange()
{
return _lastChange;
}
public void setLastChange(int lastChange)
{
_lastChange = lastChange;
}
public boolean isStackable()
{
return _item.isStackable();
}
@Override
public void onAction(PlayerInstance player)
{
player.setCurrentState((byte) 1);
player.setTarget(this);
player.moveTo(getX(), getY(), getZ(), 0);
}
public int getEnchantLevel()
{
return _enchantLevel;
}
public void setEnchantLevel(int enchantLevel)
{
_enchantLevel = enchantLevel;
}
public boolean isOnTheGround()
{
return _onTheGround;
}
public void setOnTheGround(boolean b)
{
_onTheGround = b;
}
}

View File

@@ -0,0 +1,96 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor.instance;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.data.TradeController;
import org.l2jmobius.gameserver.model.TradeList;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.BuyList;
import org.l2jmobius.gameserver.network.serverpackets.SellList;
import org.l2jmobius.gameserver.templates.L2Npc;
public class MerchantInstance extends NpcInstance
{
private static Logger _log = Logger.getLogger(MerchantInstance.class.getName());
public MerchantInstance(L2Npc template)
{
super(template);
}
@Override
public void onAction(PlayerInstance player)
{
// _log.fine("Merchant activated");
super.onAction(player);
}
@Override
public String getHtmlPath(int npcId, int val)
{
String pom = "";
pom = val == 0 ? "" + npcId : npcId + "-" + val;
return "data/html/merchant/" + pom + ".htm";
}
private void showBuyWindow(PlayerInstance player, int val)
{
_log.fine("Showing buylist");
TradeList list = TradeController.getInstance().getBuyList(val);
if (list != null)
{
BuyList bl = new BuyList(list, player.getAdena());
player.sendPacket(bl);
}
else
{
_log.warning("no buylist with id:" + val);
}
player.sendPacket(new ActionFailed());
}
private void showSellWindow(PlayerInstance player)
{
// _log.fine("Showing selllist");
SellList sl = new SellList(player);
player.sendPacket(sl);
// _log.fine("Showing sell window");
player.sendPacket(new ActionFailed());
}
@Override
public void onBypassFeedback(PlayerInstance player, String command)
{
super.onBypassFeedback(player, command);
if (command.startsWith("Buy"))
{
int val = Integer.parseInt(command.substring(4));
showBuyWindow(player, val);
}
else if (command.equals("Sell"))
{
showSellWindow(player);
}
else
{
super.onBypassFeedback(player, command);
}
}
}

View File

@@ -0,0 +1,88 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor.instance;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.templates.L2Npc;
public class MonsterInstance extends Attackable
{
public MonsterInstance(L2Npc template)
{
super(template);
// this.setMoveRadius(2000);
setCurrentState((byte) 6);
}
@Override
public void addKnownObject(WorldObject object)
{
super.addKnownObject(object);
if ((object instanceof PlayerInstance) && !isActive())
{
setActive(true);
startRandomWalking();
if (isAggressive() && !isTargetScanActive())
{
startTargetScan();
}
}
}
@Override
public void removeKnownObject(WorldObject object)
{
super.removeKnownObject(object);
Creature temp = (Creature) object;
if (getTarget() == temp)
{
setTarget(null);
stopMove();
setPawnTarget(null);
setMovingToPawn(false);
}
if (getKnownPlayers().isEmpty())
{
setActive(false);
clearAggroList();
removeAllKnownObjects();
stopRandomWalking();
if (isAggressive())
{
stopTargetScan();
}
return;
}
if ((getCurrentState() != 6) && !isDead() && (getTarget() == null))
{
startRandomWalking();
if (isAggressive())
{
startTargetScan();
}
}
}
@Override
public boolean getCondition2(PlayerInstance player)
{
return !player.isInvul() && !player.isDead() && (Math.abs(getZ() - player.getZ()) <= 100);
}
}

View File

@@ -0,0 +1,361 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor.instance;
import java.io.File;
import java.io.FileInputStream;
import java.util.Timer;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.ChangeMoveType;
import org.l2jmobius.gameserver.network.serverpackets.MyTargetSelected;
import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
import org.l2jmobius.gameserver.network.serverpackets.SetToLocation;
import org.l2jmobius.gameserver.network.serverpackets.StatusUpdate;
import org.l2jmobius.gameserver.templates.L2Npc;
import org.l2jmobius.gameserver.templates.L2Weapon;
public class NpcInstance extends Creature
{
private static Logger _log = Logger.getLogger(NpcInstance.class.getName());
private static final int INTERACTION_DISTANCE = 150;
private final L2Npc _npcTemplate;
private boolean _attackable;
private int _rightHandItem;
private int _leftHandItem;
private int _expReward;
private int _spReward;
private int _attackRange;
private boolean _aggressive;
private Creature.DecayTask _decayTask;
private static Timer _decayTimer = new Timer(true);
private Spawn _spawn;
public NpcInstance(L2Npc template)
{
_npcTemplate = template;
setCollisionHeight(template.getHeight());
setCollisionRadius(template.getRadius());
}
public boolean isAggressive()
{
return _aggressive;
}
@Override
public void startAttack(Creature target)
{
if (!isRunning())
{
setRunning(true);
ChangeMoveType move = new ChangeMoveType(this, ChangeMoveType.RUN);
broadcastPacket(move);
}
super.startAttack(target);
}
public void setAggressive(boolean aggressive)
{
_aggressive = aggressive;
}
public L2Npc getNpcTemplate()
{
return _npcTemplate;
}
public boolean isAttackable()
{
return _attackable;
}
public void setAttackable(boolean b)
{
_attackable = b;
}
public int getLeftHandItem()
{
return _leftHandItem;
}
public int getRightHandItem()
{
return _rightHandItem;
}
public void setLeftHandItem(int i)
{
_leftHandItem = i;
}
public void setRightHandItem(int i)
{
_rightHandItem = i;
}
@Override
public void onAction(PlayerInstance player)
{
if (this != player.getTarget())
{
if (player.getCurrentState() == 2)
{
player.cancelCastMagic();
}
player.setCurrentState((byte) 0);
_log.fine("new target selected:" + getObjectId());
player.setTarget(this);
MyTargetSelected my = new MyTargetSelected(getObjectId(), player.getLevel() - getLevel());
player.sendPacket(my);
if (isAttackable())
{
StatusUpdate su = new StatusUpdate(getObjectId());
su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
player.sendPacket(su);
}
player.sendPacket(new SetToLocation(this));
}
else
{
if (isAttackable() && !isDead() && !player.isInCombat() && (Math.abs(player.getZ() - getZ()) < 200))
{
player.startAttack(this);
}
if (!isAttackable())
{
double distance = getDistance(player.getX(), player.getY());
if (distance > INTERACTION_DISTANCE)
{
player.setCurrentState((byte) 7);
player.setInteractTarget(this);
player.moveTo(getX(), getY(), getZ(), 150);
}
else
{
showChatWindow(player, 0);
player.sendPacket(new ActionFailed());
player.setCurrentState((byte) 0);
}
}
}
}
@Override
public void onActionShift(ClientThread client)
{
PlayerInstance player = client.getActiveChar();
if (client.getAccessLevel() >= 100)
{
NpcHtmlMessage html = new NpcHtmlMessage(1);
StringBuffer html1 = new StringBuffer("<html><body><table border=0>");
html1.append("<tr><td>Current Target:</td></tr>");
html1.append("<tr><td><br></td></tr>");
html1.append("<tr><td>Object ID: " + getObjectId() + "</td></tr>");
html1.append("<tr><td>Template ID: " + getNpcTemplate().getNpcId() + "</td></tr>");
html1.append("<tr><td><br></td></tr>");
html1.append("<tr><td>HP: " + getCurrentHp() + "</td></tr>");
html1.append("<tr><td>MP: " + getCurrentMp() + "</td></tr>");
html1.append("<tr><td>Level: " + getLevel() + "</td></tr>");
html1.append("<tr><td><br></td></tr>");
html1.append("<tr><td>Class: " + this.getClass().getName() + "</td></tr>");
html1.append("<tr><td><br></td></tr>");
html1.append("<tr><td><button value=\"Kill\" action=\"bypass -h admin_kill " + getObjectId() + "\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr>");
html1.append("<tr><td><button value=\"Delete\" action=\"bypass -h admin_delete " + getObjectId() + "\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr>");
html1.append("</table></body></html>");
html.setHtml(html1.toString());
player.sendPacket(html);
}
player.sendPacket(new ActionFailed());
}
public void onBypassFeedback(PlayerInstance player, String command)
{
double distance = getDistance(player.getX(), player.getY());
if (distance > 150.0)
{
player.moveTo(getX(), getY(), getZ(), 150);
}
else if (command.startsWith("Quest"))
{
int val = Integer.parseInt(command.substring(6));
showQuestWindow(player, val);
}
else if (command.startsWith("Chat"))
{
int val = Integer.parseInt(command.substring(5));
showChatWindow(player, val);
}
}
@Override
public L2Weapon getActiveWeapon()
{
return null;
}
public void insertObjectIdAndShowChatWindow(PlayerInstance player, String content)
{
content = content.replaceAll("%objectId%", String.valueOf(getObjectId()));
NpcHtmlMessage npcReply = new NpcHtmlMessage(5);
npcReply.setHtml(content);
player.sendPacket(npcReply);
}
protected void showQuestWindow(PlayerInstance player, int val)
{
_log.fine("Showing quest window");
NpcHtmlMessage html = new NpcHtmlMessage(1);
html.setHtml("<html><head><body>There is no quests here yet.</body></html>");
player.sendPacket(html);
player.sendPacket(new ActionFailed());
}
public String getHtmlPath(int npcId, int val)
{
String pom = "";
pom = val == 0 ? "" + npcId : npcId + "-" + val;
String temp = "data/html/default/" + pom + ".htm";
File mainText = new File(temp);
if (mainText.exists())
{
return temp;
}
return "data/html/npcdefault.htm";
}
public void showChatWindow(PlayerInstance player, int val)
{
int npcId = getNpcTemplate().getNpcId();
String filename = getHtmlPath(npcId, val);
File file = new File(filename);
if (!file.exists())
{
NpcHtmlMessage html = new NpcHtmlMessage(1);
html.setHtml("<html><head><body>My Text is missing:<br>" + filename + "</body></html>");
player.sendPacket(html);
player.sendPacket(new ActionFailed());
}
else
{
FileInputStream fis = null;
try
{
fis = new FileInputStream(file);
byte[] raw = new byte[fis.available()];
fis.read(raw);
String content = new String(raw, "UTF-8");
insertObjectIdAndShowChatWindow(player, content);
}
catch (Exception e)
{
_log.warning("problem with npc text " + e);
}
finally
{
try
{
if (fis != null)
{
fis.close();
}
}
catch (Exception e1)
{
}
}
}
player.sendPacket(new ActionFailed());
}
public void setExpReward(int exp)
{
_expReward = exp;
}
public void setSpReward(int sp)
{
_spReward = sp;
}
public int getExpReward()
{
return (int) (_expReward * Config.RATE_XP);
}
public int getSpReward()
{
return (int) (_spReward * Config.RATE_SP);
}
@Override
public int getAttackRange()
{
return _attackRange;
}
public void setAttackRange(int range)
{
_attackRange = range;
}
@Override
public void reduceCurrentHp(int i, Creature attacker)
{
super.reduceCurrentHp(i, attacker);
if (isDead())
{
NpcInstance NpcInstance = this;
synchronized (NpcInstance)
{
if (_decayTask == null)
{
_decayTask = new Creature.DecayTask(this);
_decayTimer.schedule(_decayTask, 7000L);
}
}
}
}
public void setSpawn(Spawn spawn)
{
_spawn = spawn;
}
@Override
public void onDecay()
{
super.onDecay();
_spawn.decreaseCount(_npcTemplate.getNpcId());
}
public void deleteMe()
{
World.getInstance().removeVisibleObject(this);
World.getInstance().removeObject(this);
removeAllKnownObjects();
}
}

View File

@@ -0,0 +1,619 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor.instance;
import java.util.Timer;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.data.ExperienceTable;
import org.l2jmobius.gameserver.model.Inventory;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.ChangeMoveType;
import org.l2jmobius.gameserver.network.serverpackets.CharInfo;
import org.l2jmobius.gameserver.network.serverpackets.DeleteObject;
import org.l2jmobius.gameserver.network.serverpackets.DropItem;
import org.l2jmobius.gameserver.network.serverpackets.GetItem;
import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
import org.l2jmobius.gameserver.network.serverpackets.ItemList;
import org.l2jmobius.gameserver.network.serverpackets.MyTargetSelected;
import org.l2jmobius.gameserver.network.serverpackets.PetDelete;
import org.l2jmobius.gameserver.network.serverpackets.PetInventoryUpdate;
import org.l2jmobius.gameserver.network.serverpackets.PetItemList;
import org.l2jmobius.gameserver.network.serverpackets.PetStatusShow;
import org.l2jmobius.gameserver.network.serverpackets.PetStatusUpdate;
import org.l2jmobius.gameserver.network.serverpackets.SocialAction;
import org.l2jmobius.gameserver.network.serverpackets.StatusUpdate;
import org.l2jmobius.gameserver.network.serverpackets.StopMove;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
import org.l2jmobius.gameserver.templates.L2Npc;
import org.l2jmobius.gameserver.templates.L2Weapon;
public class PetInstance extends Creature
{
private static Logger _log = Logger.getLogger(PetInstance.class.getName());
private byte _petId = 1;
private int _exp = 0;
private int _sp = 0;
private int _pkKills;
private int _maxFed = 5;
private int _curFed = 5;
private PlayerInstance _owner;
private int _karma = 0;
private final Inventory _inventory = new Inventory();
private L2Weapon _dummyWeapon;
private final L2Npc _template;
private int _attackRange = 36;
private boolean _follow = true;
private Creature.DecayTask _decayTask;
private static Timer _decayTimer = new Timer(true);
private int _controlItemId;
private int _nextLevel;
private int _lastLevel;
private byte updateKnownCounter = 0;
public PetInstance(L2Npc template)
{
setCollisionHeight(template.getHeight());
setCollisionRadius(template.getRadius());
setCurrentState((byte) 0);
setPhysicalAttack(9999);
_template = template;
}
@Override
public void onAction(PlayerInstance player)
{
if (player == _owner)
{
player.sendPacket(new PetStatusShow(2));
player.sendPacket(new PetStatusUpdate(this));
player.sendPacket(new ActionFailed());
}
player.setCurrentState((byte) 0);
_log.fine("new target selected:" + getObjectId());
player.setTarget(this);
MyTargetSelected my = new MyTargetSelected(getObjectId(), player.getLevel() - getLevel());
player.sendPacket(my);
}
public void setSummonHp(int hp)
{
if (hp == 0)
{
hp = 5000;
}
if (getMaxHp() < hp)
{
super.setMaxHp(hp);
}
super.setCurrentHp(hp);
}
public void setNextLevel(int level)
{
_nextLevel = level;
}
public int getNextLevel()
{
return _nextLevel;
}
public void setLastLevel(int level)
{
_lastLevel = level;
}
public int getLastLevel()
{
return _lastLevel;
}
@Override
public void setWalkSpeed(int walkSpeed)
{
if (walkSpeed < 24)
{
walkSpeed = 24;
}
super.setWalkSpeed(walkSpeed);
}
@Override
public void setPhysicalDefense(int pdef)
{
if (pdef < 100)
{
pdef = 100;
}
super.setPhysicalDefense(pdef);
}
@Override
public void setRunSpeed(int runSpeed)
{
if (runSpeed < 125)
{
runSpeed = 125;
}
super.setRunSpeed(runSpeed);
}
public int getPetId()
{
return _petId;
}
public void setPetId(byte petid)
{
_petId = petid;
}
public int getControlItemId()
{
return _controlItemId;
}
public void setControlItemId(int controlItemId)
{
_controlItemId = controlItemId;
}
public int getKarma()
{
return _karma;
}
public void setKarma(int karma)
{
_karma = karma;
}
public int getMaxFed()
{
return _maxFed;
}
public void setMaxFed(int num)
{
_maxFed = num;
}
public int getCurrentFed()
{
return _curFed;
}
public void setCurrentFed(int num)
{
_curFed = num;
}
public void setOwner(PlayerInstance owner)
{
_owner = owner;
}
public Creature getOwner()
{
return _owner;
}
public int getNpcId()
{
return _template.getNpcId();
}
public void setPkKills(int pkKills)
{
_pkKills = pkKills;
}
public int getPkKills()
{
return _pkKills;
}
public int getExp()
{
return _exp;
}
public void setExp(int exp)
{
_exp = exp;
}
public int getSp()
{
return _sp;
}
public void setSp(int sp)
{
_sp = sp;
}
@Override
public void addExpAndSp(int addToExp, int addToSp)
{
_log.fine("adding " + addToExp + " exp and " + addToSp + " sp to " + getName());
_exp += addToExp;
_sp += addToSp;
PetStatusUpdate su = new PetStatusUpdate(this);
_owner.sendPacket(su);
while (_exp >= getNextLevel())
{
increaseLevel();
}
}
@Override
public void increaseLevel()
{
_log.finest("Increasing level of " + getName());
setLastLevel(getNextLevel());
setLevel(getLevel() + 1);
setNextLevel(ExperienceTable.getInstance().getExp(getLevel() + 1));
PetStatusUpdate ps = new PetStatusUpdate(this);
_owner.sendPacket(ps);
StatusUpdate su = new StatusUpdate(getObjectId());
su.addAttribute(StatusUpdate.LEVEL, getLevel());
broadcastPacket(su);
SocialAction sa = new SocialAction(getObjectId(), 15);
broadcastPacket(sa);
_owner.sendPacket(new SystemMessage(96));
}
public void followOwner(PlayerInstance owner)
{
setCurrentState((byte) 8);
setTarget(owner);
moveTo(owner.getX(), owner.getY(), owner.getZ(), 30);
broadcastPacket(new PetStatusUpdate(this));
}
@Override
public void onTargetReached()
{
super.onTargetReached();
updateKnownObjects();
try
{
switch (getCurrentState())
{
case 1:
{
doPickupItem();
break;
}
case 5:
{
startCombat();
break;
}
}
}
catch (Exception io)
{
io.printStackTrace();
}
}
@Override
public L2Weapon getActiveWeapon()
{
return _dummyWeapon;
}
@Override
public void setPhysicalAttack(int physicalAttack)
{
if (physicalAttack < 100)
{
physicalAttack = 100;
}
super.setPhysicalAttack(physicalAttack);
_dummyWeapon = new L2Weapon();
_dummyWeapon.setPDamage(physicalAttack);
_dummyWeapon.setRandomDamage(getLevel());
}
public Inventory getInventory()
{
return _inventory;
}
private void doPickupItem()
{
StopMove sm = new StopMove(getObjectId(), getX(), getY(), getZ(), getHeading());
_log.fine("Pet pickup pos: " + getTarget().getX() + " " + getTarget().getY() + " " + getTarget().getZ());
broadcastPacket(sm);
if (!(getTarget() instanceof ItemInstance))
{
_log.warning("trying to pickup wrong target." + getTarget());
_owner.sendPacket(new ActionFailed());
return;
}
ItemInstance target = (ItemInstance) getTarget();
boolean pickupOk = false;
ItemInstance ItemInstance = target;
synchronized (ItemInstance)
{
if (target.isOnTheGround())
{
pickupOk = true;
target.setOnTheGround(false);
}
}
if (!pickupOk)
{
_owner.sendPacket(new ActionFailed());
setCurrentState((byte) 0);
return;
}
GetItem gi = new GetItem(target, getObjectId());
broadcastPacket(gi);
World.getInstance().removeVisibleObject(target);
DeleteObject del = new DeleteObject(target);
broadcastPacket(del);
getInventory().addItem(target);
PetItemList iu = new PetItemList(this);
_owner.sendPacket(iu);
setCurrentState((byte) 0);
if (getFollowStatus())
{
followOwner(_owner);
}
}
@Override
public void reduceCurrentHp(int damage, Creature attacker)
{
super.reduceCurrentHp(damage, attacker);
if (!isDead() && (attacker != null))
{
if (!isInCombat())
{
startAttack(attacker);
}
else
{
_log.fine("already attacking");
}
}
if (isDead())
{
PetInstance PetInstance = this;
synchronized (PetInstance)
{
if (_decayTask == null)
{
_decayTask = new Creature.DecayTask(this);
_decayTimer.schedule(_decayTask, 10000L);
}
}
}
}
@Override
public void onDecay()
{
deleteMe(_owner);
}
public void giveAllToOwner()
{
try
{
Inventory petInventory = getInventory();
ItemInstance[] items = petInventory.getItems();
for (ItemInstance giveit : items)
{
if (((giveit.getItem().getWeight() * giveit.getCount()) + _owner.getInventory().getTotalWeight()) < _owner.getMaxLoad())
{
giveItemToOwner(giveit);
continue;
}
dropItemHere(giveit);
}
}
catch (Exception e)
{
_log.fine("Give all items error " + e);
}
}
public void giveItemToOwner(ItemInstance item)
{
try
{
_owner.getInventory().addItem(item);
getInventory().dropItem(item, item.getCount());
PetInventoryUpdate petiu = new PetInventoryUpdate();
ItemList PlayerUI = new ItemList(_owner, false);
petiu.addRemovedItem(item);
_owner.sendPacket(petiu);
_owner.sendPacket(PlayerUI);
}
catch (Exception e)
{
_log.fine("Error while giving item to owner: " + e);
}
}
@Override
public void broadcastStatusUpdate()
{
super.broadcastStatusUpdate();
if (getOwner() != null)
{
getOwner().sendPacket(new PetStatusUpdate(this));
}
}
public void deleteMe(PlayerInstance owner)
{
unSummon(owner);
destroyControlItem(owner);
owner.sendPacket(new PetDelete(getObjectId(), 2));
}
public void unSummon(PlayerInstance owner)
{
giveAllToOwner();
World.getInstance().removeVisibleObject(this);
removeAllKnownObjects();
owner.setPet(null);
setTarget(null);
}
public void destroyControlItem(PlayerInstance owner)
{
try
{
ItemInstance removedItem = owner.getInventory().destroyItem(getControlItemId(), 1);
InventoryUpdate iu = new InventoryUpdate();
iu.addRemovedItem(removedItem);
owner.sendPacket(iu);
StatusUpdate su = new StatusUpdate(owner.getObjectId());
su.addAttribute(StatusUpdate.CUR_LOAD, owner.getCurrentLoad());
owner.sendPacket(su);
UserInfo ui = new UserInfo(owner);
owner.sendPacket(ui);
CharInfo info = new CharInfo(owner);
owner.broadcastPacket(info);
World world = World.getInstance();
world.removeObject(removedItem);
}
catch (Exception e)
{
_log.fine("Error while destroying control item: " + e);
}
}
public void dropAllItems()
{
try
{
ItemInstance[] items = getInventory().getItems();
for (ItemInstance item : items)
{
dropItemHere(item);
}
}
catch (Exception e)
{
_log.fine("Pet Drop Error: " + e);
}
}
public void dropItemHere(ItemInstance dropit)
{
dropit = getInventory().dropItem(dropit.getObjectId(), dropit.getCount());
if (dropit != null)
{
_log.fine("Item id to drop: " + dropit.getItemId() + " amount: " + dropit.getCount());
dropit.setX(getX());
dropit.setY(getY());
dropit.setZ(getZ() + 100);
dropit.setOnTheGround(true);
DropItem dis = new DropItem(dropit, getObjectId());
Creature[] players = broadcastPacket(dis);
for (Creature player : players)
{
((PlayerInstance) player).addKnownObjectWithoutCreate(dropit);
}
World.getInstance().addVisibleObject(dropit);
}
}
@Override
public void startAttack(Creature target)
{
if (!knownsObject(target))
{
target.addKnownObject(this);
addKnownObject(target);
}
if (!isRunning())
{
setRunning(true);
ChangeMoveType move = new ChangeMoveType(this, ChangeMoveType.RUN);
broadcastPacket(move);
}
super.startAttack(target);
}
@Override
public int getAttackRange()
{
return _attackRange;
}
public void setAttackRange(int range)
{
if (range < 36)
{
range = 36;
}
_attackRange = range;
}
public void setFollowStatus(boolean state)
{
_follow = state;
}
public boolean getFollowStatus()
{
return _follow;
}
public void updateKnownObjects()
{
updateKnownCounter = (byte) (updateKnownCounter + 1);
if (updateKnownCounter > 3)
{
if (getKnownObjects().size() != 0)
{
WorldObject[] knownobjects = _knownObjects.toArray(new WorldObject[_knownObjects.size()]);
for (int x = 0; x < knownobjects.length; ++x)
{
if (!(getDistance(knownobjects[x].getX(), knownobjects[x].getY()) > 4000.0))
{
continue;
}
if (knownobjects[x] instanceof MonsterInstance)
{
removeKnownObject(knownobjects[x]);
((MonsterInstance) knownobjects[x]).removeKnownObject(this);
continue;
}
removeKnownObject(knownobjects[x]);
knownobjects[x].removeKnownObject(this);
}
}
updateKnownCounter = 0;
}
}
}

View File

@@ -0,0 +1,90 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor.instance;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.data.TeleportLocationTable;
import org.l2jmobius.gameserver.model.TeleportLocation;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import org.l2jmobius.gameserver.network.serverpackets.TeleportToLocation;
import org.l2jmobius.gameserver.templates.L2Npc;
public class TeleporterInstance extends NpcInstance
{
private static Logger _log = Logger.getLogger(TeleporterInstance.class.getName());
public TeleporterInstance(L2Npc template)
{
super(template);
}
@Override
public void onBypassFeedback(PlayerInstance player, String command)
{
super.onBypassFeedback(player, command);
if (command.startsWith("goto"))
{
int val = Integer.parseInt(command.substring(5));
doTeleport(player, val);
}
}
@Override
public String getHtmlPath(int npcId, int val)
{
String pom = "";
pom = val == 0 ? "" + npcId : npcId + "-" + val;
return "data/html/teleporter/" + pom + ".htm";
}
@Override
public void onAction(PlayerInstance player)
{
_log.fine("Teleporter activated");
super.onAction(player);
}
private void doTeleport(PlayerInstance player, int val)
{
TeleportLocation list = TeleportLocationTable.getInstance().getTemplate(val);
if (list != null)
{
if (player.getAdena() >= list.getPrice())
{
_log.fine("Teleporting to new location: " + list.getLocX() + ":" + list.getLocY() + ":" + list.getLocZ());
player.reduceAdena(list.getPrice());
_log.fine("Took: " + list.getPrice() + " Adena from player for teleport");
TeleportToLocation Tloc = new TeleportToLocation(player, list.getLocX(), list.getLocY(), list.getLocZ());
player.sendPacket(Tloc);
}
else
{
_log.fine("Not enough adena to teleport");
SystemMessage sm = new SystemMessage(279);
player.sendPacket(sm);
}
}
else
{
_log.warning("No teleport destination with id:" + val);
}
player.sendPacket(new ActionFailed());
}
}

View File

@@ -0,0 +1,77 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor.instance;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.data.SkillTreeTable;
import org.l2jmobius.gameserver.model.SkillLearn;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.AquireSkillList;
import org.l2jmobius.gameserver.templates.L2Npc;
public class TrainerInstance extends NpcInstance
{
private static Logger _log = Logger.getLogger(TrainerInstance.class.getName());
public TrainerInstance(L2Npc template)
{
super(template);
}
@Override
public void onAction(PlayerInstance player)
{
_log.fine("Trainer activated");
super.onAction(player);
}
@Override
public String getHtmlPath(int npcId, int val)
{
String pom = "";
pom = val == 0 ? "" + npcId : npcId + "-" + val;
return "data/html/trainer/" + pom + ".htm";
}
public void showSkillList(PlayerInstance player)
{
_log.fine("SkillList activated on: " + getObjectId());
SkillLearn[] skills = SkillTreeTable.getInstance().getAvailableSkills(player);
AquireSkillList asl = new AquireSkillList();
for (SkillLearn skill : skills)
{
asl.addSkill(skill.getId(), skill.getLevel(), skill.getLevel(), skill.getSpCost(), 0);
}
player.sendPacket(asl);
player.sendPacket(new ActionFailed());
}
@Override
public void onBypassFeedback(PlayerInstance player, String command)
{
if (command.startsWith("SkillList"))
{
showSkillList(player);
}
else
{
super.onBypassFeedback(player, command);
}
}
}

View File

@@ -0,0 +1,102 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor.instance;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.data.ClanTable;
import org.l2jmobius.gameserver.model.Clan;
import org.l2jmobius.gameserver.network.serverpackets.PledgeShowInfoUpdate;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
import org.l2jmobius.gameserver.templates.L2Npc;
public class VillageMasterInstance extends NpcInstance
{
private static Logger _log = Logger.getLogger(VillageMasterInstance.class.getName());
public VillageMasterInstance(L2Npc template)
{
super(template);
}
@Override
public void onBypassFeedback(PlayerInstance player, String command)
{
super.onBypassFeedback(player, command);
if (command.startsWith("create_clan"))
{
String val = command.substring(12);
createClan(player, val);
}
}
@Override
public String getHtmlPath(int npcId, int val)
{
String pom = "";
pom = val == 0 ? "" + npcId : npcId + "-" + val;
return "data/html/villagemaster/" + pom + ".htm";
}
@Override
public void onAction(PlayerInstance player)
{
_log.fine("Village Master activated");
super.onAction(player);
}
public void createClan(PlayerInstance player, String clanName)
{
_log.fine(player.getObjectId() + "(" + player.getName() + ") requested clan creation from " + getObjectId() + "(" + getName() + ")");
if (player.getLevel() < 10)
{
SystemMessage sm = new SystemMessage(190);
player.sendPacket(sm);
return;
}
if (player.getClanId() != 0)
{
SystemMessage sm = new SystemMessage(190);
player.sendPacket(sm);
return;
}
if (clanName.length() > 16)
{
SystemMessage sm = new SystemMessage(262);
player.sendPacket(sm);
return;
}
Clan clan = ClanTable.getInstance().createClan(player, clanName);
if (clan == null)
{
SystemMessage sm = new SystemMessage(261);
player.sendPacket(sm);
return;
}
player.setClan(clan);
player.setClanId(clan.getClanId());
player.setIsClanLeader(true);
PledgeShowInfoUpdate pu = new PledgeShowInfoUpdate(clan, player);
player.sendPacket(pu);
UserInfo ui = new UserInfo(player);
player.sendPacket(ui);
SystemMessage sm = new SystemMessage(189);
player.sendPacket(sm);
}
}

View File

@@ -0,0 +1,119 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.model.actor.instance;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.model.Warehouse;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
import org.l2jmobius.gameserver.network.serverpackets.WareHouseDepositList;
import org.l2jmobius.gameserver.network.serverpackets.WareHouseWithdrawalList;
import org.l2jmobius.gameserver.templates.L2Npc;
public class WarehouseInstance extends NpcInstance
{
private static Logger _log = Logger.getLogger(WarehouseInstance.class.getName());
public WarehouseInstance(L2Npc template)
{
super(template);
}
@Override
public void onAction(PlayerInstance player)
{
_log.fine("Warehouse activated");
super.onAction(player);
}
@Override
public String getHtmlPath(int npcId, int val)
{
String pom = "";
pom = val == 0 ? "" + npcId : npcId + "-" + val;
return "data/html/warehouse/" + pom + ".htm";
}
private void showRetrieveWindow(PlayerInstance player)
{
_log.fine("Showing stored items");
Warehouse list = player.getWarehouse();
if (list != null)
{
WareHouseWithdrawalList wl = new WareHouseWithdrawalList(player);
player.sendPacket(wl);
}
else
{
_log.warning("no items stored");
}
player.sendPacket(new ActionFailed());
}
private void showDepositWindow(PlayerInstance player)
{
_log.fine("Showing items to deposit");
WareHouseDepositList dl = new WareHouseDepositList(player);
player.sendPacket(dl);
player.sendPacket(new ActionFailed());
}
private void showDepositWindowClan(PlayerInstance player)
{
NpcHtmlMessage html = new NpcHtmlMessage(1);
html.setHtml("<html><body>Clans are not supported yet.</body></html>");
player.sendPacket(html);
_log.fine("Showing items to deposit - clan");
player.sendPacket(new ActionFailed());
}
private void showWithdrawWindowClan(PlayerInstance player)
{
NpcHtmlMessage html = new NpcHtmlMessage(1);
html.setHtml("<html><body>Clans are not supported yet.</body></html>");
player.sendPacket(html);
_log.fine("Showing items to deposit - clan");
player.sendPacket(new ActionFailed());
}
@Override
public void onBypassFeedback(PlayerInstance player, String command)
{
if (command.startsWith("WithdrawP"))
{
showRetrieveWindow(player);
}
else if (command.equals("DepositP"))
{
showDepositWindow(player);
}
else if (command.equals("WithdrawC"))
{
showWithdrawWindowClan(player);
}
else if (command.equals("DepositC"))
{
showDepositWindowClan(player);
}
else
{
super.onBypassFeedback(player, command);
}
}
}

View File

@@ -0,0 +1,606 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network;
import java.io.IOException;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.network.clientpackets.Action;
import org.l2jmobius.gameserver.network.clientpackets.AddTradeItem;
import org.l2jmobius.gameserver.network.clientpackets.AnswerTradeRequest;
import org.l2jmobius.gameserver.network.clientpackets.Appearing;
import org.l2jmobius.gameserver.network.clientpackets.AttackRequest;
import org.l2jmobius.gameserver.network.clientpackets.AuthLogin;
import org.l2jmobius.gameserver.network.clientpackets.ChangeMoveType2;
import org.l2jmobius.gameserver.network.clientpackets.ChangeWaitType2;
import org.l2jmobius.gameserver.network.clientpackets.CharacterCreate;
import org.l2jmobius.gameserver.network.clientpackets.CharacterDelete;
import org.l2jmobius.gameserver.network.clientpackets.CharacterRestore;
import org.l2jmobius.gameserver.network.clientpackets.CharacterSelected;
import org.l2jmobius.gameserver.network.clientpackets.EnterWorld;
import org.l2jmobius.gameserver.network.clientpackets.FinishRotating;
import org.l2jmobius.gameserver.network.clientpackets.Logout;
import org.l2jmobius.gameserver.network.clientpackets.MoveBackwardToLocation;
import org.l2jmobius.gameserver.network.clientpackets.NewCharacter;
import org.l2jmobius.gameserver.network.clientpackets.ProtocolVersion;
import org.l2jmobius.gameserver.network.clientpackets.RequestActionUse;
import org.l2jmobius.gameserver.network.clientpackets.RequestAllyCrest;
import org.l2jmobius.gameserver.network.clientpackets.RequestAnswerJoinParty;
import org.l2jmobius.gameserver.network.clientpackets.RequestAnswerJoinPledge;
import org.l2jmobius.gameserver.network.clientpackets.RequestAquireSkill;
import org.l2jmobius.gameserver.network.clientpackets.RequestAquireSkillInfo;
import org.l2jmobius.gameserver.network.clientpackets.RequestBuyItem;
import org.l2jmobius.gameserver.network.clientpackets.RequestBypassToServer;
import org.l2jmobius.gameserver.network.clientpackets.RequestChangePetName;
import org.l2jmobius.gameserver.network.clientpackets.RequestDestroyItem;
import org.l2jmobius.gameserver.network.clientpackets.RequestDropItem;
import org.l2jmobius.gameserver.network.clientpackets.RequestGMCommand;
import org.l2jmobius.gameserver.network.clientpackets.RequestGetItemFromPet;
import org.l2jmobius.gameserver.network.clientpackets.RequestGiveItemToPet;
import org.l2jmobius.gameserver.network.clientpackets.RequestGiveNickName;
import org.l2jmobius.gameserver.network.clientpackets.RequestGmList;
import org.l2jmobius.gameserver.network.clientpackets.RequestItemList;
import org.l2jmobius.gameserver.network.clientpackets.RequestJoinParty;
import org.l2jmobius.gameserver.network.clientpackets.RequestJoinPledge;
import org.l2jmobius.gameserver.network.clientpackets.RequestMagicSkillUse;
import org.l2jmobius.gameserver.network.clientpackets.RequestOustPartyMember;
import org.l2jmobius.gameserver.network.clientpackets.RequestOustPledgeMember;
import org.l2jmobius.gameserver.network.clientpackets.RequestPartyMatchConfig;
import org.l2jmobius.gameserver.network.clientpackets.RequestPartyMatchDetail;
import org.l2jmobius.gameserver.network.clientpackets.RequestPartyMatchList;
import org.l2jmobius.gameserver.network.clientpackets.RequestPetGetItem;
import org.l2jmobius.gameserver.network.clientpackets.RequestPledgeCrest;
import org.l2jmobius.gameserver.network.clientpackets.RequestPledgeInfo;
import org.l2jmobius.gameserver.network.clientpackets.RequestPledgeMemberList;
import org.l2jmobius.gameserver.network.clientpackets.RequestPrivateStoreBuyManage;
import org.l2jmobius.gameserver.network.clientpackets.RequestPrivateStoreManage;
import org.l2jmobius.gameserver.network.clientpackets.RequestPrivateStoreQuitBuy;
import org.l2jmobius.gameserver.network.clientpackets.RequestPrivateStoreQuitSell;
import org.l2jmobius.gameserver.network.clientpackets.RequestQuestList;
import org.l2jmobius.gameserver.network.clientpackets.RequestRestart;
import org.l2jmobius.gameserver.network.clientpackets.RequestRestartPoint;
import org.l2jmobius.gameserver.network.clientpackets.RequestSellItem;
import org.l2jmobius.gameserver.network.clientpackets.RequestSetPledgeCrest;
import org.l2jmobius.gameserver.network.clientpackets.RequestShortCutDel;
import org.l2jmobius.gameserver.network.clientpackets.RequestShortCutReg;
import org.l2jmobius.gameserver.network.clientpackets.RequestShowBoard;
import org.l2jmobius.gameserver.network.clientpackets.RequestSkillList;
import org.l2jmobius.gameserver.network.clientpackets.RequestSocialAction;
import org.l2jmobius.gameserver.network.clientpackets.RequestTargetCanceld;
import org.l2jmobius.gameserver.network.clientpackets.RequestUnEquipItem;
import org.l2jmobius.gameserver.network.clientpackets.RequestWithDrawalParty;
import org.l2jmobius.gameserver.network.clientpackets.RequestWithdrawalPledge;
import org.l2jmobius.gameserver.network.clientpackets.Say2;
import org.l2jmobius.gameserver.network.clientpackets.SendBypassBuildCmd;
import org.l2jmobius.gameserver.network.clientpackets.SendPrivateStoreBuyBuyList;
import org.l2jmobius.gameserver.network.clientpackets.SendPrivateStoreBuyList;
import org.l2jmobius.gameserver.network.clientpackets.SendWareHouseDepositList;
import org.l2jmobius.gameserver.network.clientpackets.SendWareHouseWithDrawList;
import org.l2jmobius.gameserver.network.clientpackets.SetPrivateStoreListBuy;
import org.l2jmobius.gameserver.network.clientpackets.SetPrivateStoreListSell;
import org.l2jmobius.gameserver.network.clientpackets.SetPrivateStoreMsgBuy;
import org.l2jmobius.gameserver.network.clientpackets.SetPrivateStoreMsgSell;
import org.l2jmobius.gameserver.network.clientpackets.StartRotating;
import org.l2jmobius.gameserver.network.clientpackets.StopMove;
import org.l2jmobius.gameserver.network.clientpackets.TradeDone;
import org.l2jmobius.gameserver.network.clientpackets.TradeRequest;
import org.l2jmobius.gameserver.network.clientpackets.UseItem;
import org.l2jmobius.gameserver.network.clientpackets.ValidatePosition;
public class PacketHandler
{
private static Logger _log = Logger.getLogger(PacketHandler.class.getName());
private final ClientThread _client;
public PacketHandler(ClientThread client)
{
_client = client;
}
public void handlePacket(byte[] data) throws IOException
{
int id = data[0] & 0xFF;
switch (id)
{
case 0:
{
new ProtocolVersion(data, _client);
break;
}
case 1:
{
new MoveBackwardToLocation(data, _client);
break;
}
case 3:
{
new EnterWorld(data, _client);
break;
}
case 4:
{
new Action(data, _client);
break;
}
case 8:
{
new AuthLogin(data, _client);
break;
}
case 9:
{
new Logout(data, _client);
break;
}
case 10:
{
new AttackRequest(data, _client);
break;
}
case 11:
{
new CharacterCreate(data, _client);
break;
}
case 12:
{
new CharacterDelete(data, _client);
break;
}
case 13:
{
new CharacterSelected(data, _client);
break;
}
case 14:
{
new NewCharacter(data, _client);
break;
}
case 15:
{
new RequestItemList(data, _client);
break;
}
case 17:
{
new RequestUnEquipItem(data, _client);
break;
}
case 18:
{
new RequestDropItem(data, _client);
break;
}
case 20:
{
new UseItem(data, _client);
break;
}
case 21:
{
new TradeRequest(data, _client);
break;
}
case 22:
{
new AddTradeItem(data, _client);
break;
}
case 23:
{
new TradeDone(data, _client);
break;
}
case 27:
{
new RequestSocialAction(data, _client);
break;
}
case 28:
{
new ChangeMoveType2(data, _client);
break;
}
case 29:
{
new ChangeWaitType2(data, _client);
break;
}
case 30:
{
new RequestSellItem(data, _client);
break;
}
case 31:
{
new RequestBuyItem(data, _client);
break;
}
case 33:
{
new RequestBypassToServer(data, _client);
break;
}
case 36:
{
new RequestJoinPledge(data, _client);
break;
}
case 37:
{
new RequestAnswerJoinPledge(data, _client);
break;
}
case 38:
{
new RequestWithdrawalPledge(data, _client);
break;
}
case 39:
{
new RequestOustPledgeMember(data, _client);
break;
}
case 41:
{
new RequestJoinParty(data, _client);
break;
}
case 42:
{
new RequestAnswerJoinParty(data, _client);
break;
}
case 43:
{
new RequestWithDrawalParty(data, _client.getActiveChar());
break;
}
case 44:
{
new RequestOustPartyMember(data, _client);
break;
}
case 47:
{
new RequestMagicSkillUse(data, _client);
break;
}
case 48:
{
new Appearing(data, _client);
break;
}
case 49:
{
new SendWareHouseDepositList(data, _client);
break;
}
case 50:
{
new SendWareHouseWithDrawList(data, _client);
break;
}
case 51:
{
new RequestShortCutReg(data, _client);
break;
}
case 53:
{
new RequestShortCutDel(data, _client);
break;
}
case 54:
{
new StopMove(data, _client);
break;
}
case 55:
{
new RequestTargetCanceld(data, _client);
break;
}
case 56:
{
new Say2(data, _client);
break;
}
case 60:
{
new RequestPledgeMemberList(data, _client);
break;
}
case 63:
{
new RequestSkillList(data, _client);
break;
}
case 68:
{
new AnswerTradeRequest(data, _client);
break;
}
case 69:
{
new RequestActionUse(data, _client);
break;
}
case 70:
{
new RequestRestart(data, _client);
break;
}
case 72:
{
new ValidatePosition(data, _client);
break;
}
case 74:
{
new StartRotating(data, _client);
break;
}
case 75:
{
new FinishRotating(data, _client);
break;
}
case 83:
{
new RequestSetPledgeCrest(data, _client);
break;
}
case 85:
{
new RequestGiveNickName(data, _client);
break;
}
case 87:
{
new RequestShowBoard(data, _client);
break;
}
case 89:
{
new RequestDestroyItem(data, _client);
break;
}
case 91:
{
new SendBypassBuildCmd(data, _client);
break;
}
case 98:
{
new CharacterRestore(data, _client);
break;
}
case 99:
{
new RequestQuestList(data, _client);
break;
}
case 102:
{
new RequestPledgeInfo(data, _client);
break;
}
case 104:
{
new RequestPledgeCrest(data, _client);
break;
}
case 107:
{
new RequestAquireSkillInfo(data, _client);
break;
}
case 108:
{
new RequestAquireSkill(data, _client);
break;
}
case 109:
{
new RequestRestartPoint(data, _client);
break;
}
case 110:
{
new RequestGMCommand(data, _client);
break;
}
case 111:
{
new RequestPartyMatchConfig(data, _client);
break;
}
case 112:
{
new RequestPartyMatchList(data, _client);
break;
}
case 113:
{
new RequestPartyMatchDetail(data, _client);
break;
}
case 115:
{
new RequestPrivateStoreManage(data, _client);
break;
}
case 116:
{
new SetPrivateStoreListSell(data, _client);
break;
}
case 118:
{
new RequestPrivateStoreQuitSell(data, _client);
break;
}
case 119:
{
new SetPrivateStoreMsgSell(data, _client);
break;
}
case 121:
{
new SendPrivateStoreBuyList(data, _client);
break;
}
case 129:
{
new RequestGmList(data, _client);
break;
}
case 136:
{
new RequestAllyCrest(data, _client);
break;
}
case 137:
{
new RequestChangePetName(data, _client);
break;
}
case 139:
{
new RequestGiveItemToPet(data, _client);
break;
}
case 140:
{
new RequestGetItemFromPet(data, _client);
break;
}
case 143:
{
new RequestPetGetItem(data, _client);
break;
}
case 144:
{
new RequestPrivateStoreBuyManage(data, _client);
break;
}
case 145:
{
new SetPrivateStoreListBuy(data, _client);
break;
}
case 147:
{
new RequestPrivateStoreQuitBuy(data, _client);
break;
}
case 148:
{
new SetPrivateStoreMsgBuy(data, _client);
break;
}
case 150:
{
new SendPrivateStoreBuyBuyList(data, _client);
break;
}
case 157:
{
// _log.warning("Request Skill Cool Time .. ignored");
break;
}
default:
{
if (Config.LOG_UNKNOWN_PACKETS)
{
_log.warning("Unknown Packet: " + id);
_log.warning(printData(data, data.length));
}
}
}
}
private String printData(byte[] data, int len)
{
int a;
int charpoint;
byte t1;
StringBuffer result = new StringBuffer();
int counter = 0;
for (int i = 0; i < len; ++i)
{
if ((counter % 16) == 0)
{
result.append(fillHex(i, 4) + ": ");
}
result.append(fillHex(data[i] & 0xFF, 2) + " ");
if (++counter != 16)
{
continue;
}
result.append(" ");
charpoint = i - 15;
for (a = 0; a < 16; ++a)
{
if (((t1 = data[charpoint++]) > 31) && (t1 < 128))
{
result.append((char) t1);
continue;
}
result.append('.');
}
result.append("\n");
counter = 0;
}
int rest = data.length % 16;
if (rest > 0)
{
for (int i = 0; i < (17 - rest); ++i)
{
result.append(" ");
}
charpoint = data.length - rest;
for (a = 0; a < rest; ++a)
{
if (((t1 = data[charpoint++]) > 31) && (t1 < 128))
{
result.append((char) t1);
continue;
}
result.append('.');
}
result.append("\n");
}
return result.toString();
}
private String fillHex(int data, int digits)
{
String number = Integer.toHexString(data);
for (int i = number.length(); i < digits; ++i)
{
number = "0" + number;
}
return number;
}
}

View File

@@ -0,0 +1,75 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
public class Action extends ClientBasePacket
{
private static final String ACTION__C__04 = "[C] 04 Action";
private static Logger _log = Logger.getLogger(Action.class.getName());
public Action(byte[] decrypt, ClientThread client)
{
super(decrypt);
int objectId = readD();
@SuppressWarnings("unused")
int originX = readD();
@SuppressWarnings("unused")
int originY = readD();
@SuppressWarnings("unused")
int originZ = readD();
int actionId = readC();
_log.fine("Action:" + actionId);
_log.fine("oid:" + objectId);
PlayerInstance activeChar = client.getActiveChar();
WorldObject obj = World.getInstance().findObject(objectId);
if ((obj != null) && !activeChar.isDead() && (activeChar.getPrivateStoreType() == 0) && (activeChar.getTransactionRequester() == null))
{
switch (actionId)
{
case 0:
{
obj.onAction(activeChar);
break;
}
case 1:
{
obj.onActionShift(client);
}
}
}
else
{
_log.warning("object not found, oid " + objectId + " or player is dead");
activeChar.sendPacket(new ActionFailed());
}
}
@Override
public String getType()
{
return ACTION__C__04;
}
}

View File

@@ -0,0 +1,105 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.model.TradeList;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.SendTradeDone;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import org.l2jmobius.gameserver.network.serverpackets.TradeOtherAdd;
import org.l2jmobius.gameserver.network.serverpackets.TradeOwnAdd;
public class AddTradeItem extends ClientBasePacket
{
private static final String _C__16_ADDTRADEITEM = "[C] 16 AddTradeItem";
public AddTradeItem(byte[] decrypt, ClientThread client)
{
super(decrypt);
@SuppressWarnings("unused")
int tradeId = readD();
int objectId = readD();
int amount = readD();
PlayerInstance player = client.getActiveChar();
PlayerInstance requestor = player.getTransactionRequester();
if (requestor.getTransactionRequester() != null)
{
TradeList playerItemList = player.getTradeList();
player.getTradeList().setConfirmedTrade(false);
requestor.getTradeList().setConfirmedTrade(false);
if (playerItemList.getItems().size() > 0)
{
if (!playerItemList.contains(objectId))
{
ItemInstance temp = new ItemInstance();
temp.setObjectId(player.getInventory().getItem(objectId).getObjectId());
temp.setCount(amount);
playerItemList.addItem(temp);
player.sendPacket(new TradeOwnAdd(player.getInventory().getItem(objectId), amount));
requestor.sendPacket(new TradeOtherAdd(player.getInventory().getItem(objectId), amount));
}
else
{
ItemInstance tempTradeItem;
int InvItemCount = player.getInventory().getItem(objectId).getCount();
if (InvItemCount != (tempTradeItem = playerItemList.getItem(objectId)).getCount())
{
if ((amount + tempTradeItem.getCount()) >= InvItemCount)
{
tempTradeItem.setCount(InvItemCount);
player.sendPacket(new TradeOwnAdd(player.getInventory().getItem(objectId), amount));
requestor.sendPacket(new TradeOtherAdd(player.getInventory().getItem(objectId), amount));
}
else
{
tempTradeItem.setCount(amount + tempTradeItem.getCount());
player.sendPacket(new TradeOwnAdd(player.getInventory().getItem(objectId), amount));
requestor.sendPacket(new TradeOtherAdd(player.getInventory().getItem(objectId), amount));
}
}
}
}
else
{
ItemInstance temp = new ItemInstance();
temp.setObjectId(objectId);
temp.setCount(amount);
playerItemList.addItem(temp);
player.sendPacket(new TradeOwnAdd(player.getInventory().getItem(objectId), amount));
requestor.sendPacket(new TradeOtherAdd(player.getInventory().getItem(objectId), amount));
}
}
else
{
player.sendPacket(new SendTradeDone(0));
SystemMessage msg = new SystemMessage(145);
player.sendPacket(msg);
player.setTransactionRequester(null);
requestor.getTradeList().getItems().clear();
player.getTradeList().getItems().clear();
}
}
@Override
public String getType()
{
return _C__16_ADDTRADEITEM;
}
}

View File

@@ -0,0 +1,81 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.model.TradeList;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.SendTradeDone;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import org.l2jmobius.gameserver.network.serverpackets.TradeStart;
public class AnswerTradeRequest extends ClientBasePacket
{
private static final String _C__40_ANSWERTRADEREQUEST = "[C] 40 AnswerTradeRequest";
public AnswerTradeRequest(byte[] decrypt, ClientThread client)
{
super(decrypt);
int response = readD();
PlayerInstance player = client.getActiveChar();
PlayerInstance requestor = player.getTransactionRequester();
if (requestor.getTransactionRequester() != null)
{
if (response == 1)
{
SystemMessage msg = new SystemMessage(120);
msg.addString(player.getName());
requestor.sendPacket(msg);
requestor.sendPacket(new TradeStart(requestor));
if (requestor.getTradeList() == null)
{
requestor.setTradeList(new TradeList(0));
}
msg = new SystemMessage(120);
msg.addString(requestor.getName());
player.sendPacket(msg);
player.sendPacket(new TradeStart(player));
if (player.getTradeList() == null)
{
player.setTradeList(new TradeList(0));
}
}
else
{
SystemMessage msg = new SystemMessage(119);
msg.addString(player.getName());
requestor.sendPacket(msg);
requestor.setTransactionRequester(null);
player.setTransactionRequester(null);
}
}
else if (response != 0)
{
player.sendPacket(new SendTradeDone(0));
SystemMessage msg = new SystemMessage(145);
player.sendPacket(msg);
player.setTransactionRequester(null);
}
}
@Override
public String getType()
{
return _C__40_ANSWERTRADEREQUEST;
}
}

View File

@@ -0,0 +1,94 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.io.IOException;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.Connection;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
import org.l2jmobius.gameserver.model.actor.instance.PetInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.CharInfo;
import org.l2jmobius.gameserver.network.serverpackets.NpcInfo;
import org.l2jmobius.gameserver.network.serverpackets.SpawnItem;
import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
public class Appearing extends ClientBasePacket
{
private static final String _C__30_APPEARING = "[C] 30 Appearing";
public Appearing(byte[] decrypt, ClientThread client) throws IOException
{
super(decrypt);
PlayerInstance activeChar = client.getActiveChar();
activeChar.removeAllKnownObjects();
Connection con = client.getConnection();
UserInfo ui = new UserInfo(activeChar);
con.sendPacket(ui);
WorldObject[] visible = World.getInstance().getVisibleObjects(activeChar, 2000);
_log.fine("npc in range:" + visible.length);
for (int i = 0; i < visible.length; ++i)
{
NpcInfo ni;
Creature npc;
activeChar.addKnownObject(visible[i]);
if (visible[i] instanceof ItemInstance)
{
SpawnItem si = new SpawnItem((ItemInstance) visible[i]);
con.sendPacket(si);
continue;
}
if (visible[i] instanceof NpcInstance)
{
ni = new NpcInfo((NpcInstance) visible[i]);
con.sendPacket(ni);
npc = (NpcInstance) visible[i];
npc.addKnownObject(activeChar);
continue;
}
if (visible[i] instanceof PetInstance)
{
ni = new NpcInfo((PetInstance) visible[i]);
con.sendPacket(ni);
npc = (PetInstance) visible[i];
npc.addKnownObject(activeChar);
continue;
}
if (!(visible[i] instanceof PlayerInstance))
{
continue;
}
PlayerInstance player = (PlayerInstance) visible[i];
con.sendPacket(new CharInfo(player));
player.addKnownObject(activeChar);
player.getNetConnection().sendPacket(new CharInfo(activeChar));
}
World.getInstance().addVisibleObject(activeChar);
}
@Override
public String getType()
{
return _C__30_APPEARING;
}
}

View File

@@ -0,0 +1,63 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
public class AttackRequest extends ClientBasePacket
{
private static final String _C__0A_ATTACKREQUEST = "[C] 0A AttackRequest";
public AttackRequest(byte[] decrypt, ClientThread client)
{
super(decrypt);
int objectId = readD();
@SuppressWarnings("unused")
int originX = readD();
@SuppressWarnings("unused")
int originY = readD();
@SuppressWarnings("unused")
int originZ = readD();
@SuppressWarnings("unused")
int attackId = readC();
PlayerInstance activeChar = client.getActiveChar();
WorldObject target = World.getInstance().findObject(objectId);
if ((target != null) && (activeChar.getTarget() != target))
{
target.onAction(activeChar);
}
else if ((target != null) && (target.getObjectId() != activeChar.getObjectId()) && (activeChar.getPrivateStoreType() == 0) && (activeChar.getTransactionRequester() == null))
{
target.onForcedAttack(activeChar);
}
else
{
activeChar.sendPacket(new ActionFailed());
}
}
@Override
public String getType()
{
return _C__0A_ATTACKREQUEST;
}
}

View File

@@ -0,0 +1,69 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.io.IOException;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.network.serverpackets.AuthLoginFail;
import org.l2jmobius.gameserver.network.serverpackets.CharSelectInfo;
import org.l2jmobius.loginserver.LoginController;
public class AuthLogin extends ClientBasePacket
{
private static final String _C__08_AUTHLOGIN = "[C] 08 AuthLogin";
public AuthLogin(byte[] decrypt, ClientThread client) throws IOException
{
super(decrypt);
String loginName = readS().toLowerCase();
long key1 = readD();
long key2 = readD();
int access = LoginController.getInstance().getGmAccessLevel(loginName);
if (!LoginController.getInstance().loginPossible(access))
{
_log.warning("Server is full. client is blocked: " + loginName);
client.getConnection().sendPacket(new AuthLoginFail(AuthLoginFail.SYSTEM_ERROR_LOGIN_LATER));
return;
}
_log.fine("user:" + loginName);
_log.fine("key:" + Long.toHexString(key1) + " " + Long.toHexString(key2));
client.setLoginName(loginName);
client.setLoginFolder(loginName);
int sessionKey = LoginController.getInstance().getKeyForAccount(loginName);
if (sessionKey != key2)
{
_log.warning("session key is not correct. closing connection");
client.getConnection().sendPacket(new AuthLoginFail(1));
}
else
{
LoginController.getInstance().addGameServerLogin(loginName, client.getConnection());
CharSelectInfo cl = new CharSelectInfo(loginName, client.getSessionId());
client.getConnection().sendPacket(cl);
}
client.setAccessLevel(access);
_log.fine("access level is set to " + access);
}
@Override
public String getType()
{
return _C__08_AUTHLOGIN;
}
}

View File

@@ -0,0 +1,42 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.network.serverpackets.ChangeMoveType;
public class ChangeMoveType2 extends ClientBasePacket
{
private static final String _C__1C_CHANGEMOVETYPE2 = "[C] 1C ChangeMoveType2";
public ChangeMoveType2(byte[] decrypt, ClientThread client)
{
super(decrypt);
int type = readD();
ChangeMoveType cmt = new ChangeMoveType(client.getActiveChar(), type);
client.getActiveChar().setMoveType(type);
client.getActiveChar().sendPacket(cmt);
client.getActiveChar().broadcastPacket(cmt);
}
@Override
public String getType()
{
return _C__1C_CHANGEMOVETYPE2;
}
}

View File

@@ -0,0 +1,42 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.network.serverpackets.ChangeWaitType;
public class ChangeWaitType2 extends ClientBasePacket
{
private static final String _C__1D_CHANGEWAITTYPE2 = "[C] 1D ChangeWaitType2";
public ChangeWaitType2(byte[] decrypt, ClientThread client)
{
super(decrypt);
int type = readD();
ChangeWaitType cwt = new ChangeWaitType(client.getActiveChar(), type);
client.getActiveChar().setWaitType(type);
client.getActiveChar().sendPacket(cwt);
client.getActiveChar().broadcastPacket(cwt);
}
@Override
public String getType()
{
return _C__1D_CHANGEWAITTYPE2;
}
}

View File

@@ -0,0 +1,178 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.IdFactory;
import org.l2jmobius.gameserver.data.CharNameTable;
import org.l2jmobius.gameserver.data.CharTemplateTable;
import org.l2jmobius.gameserver.data.ItemTable;
import org.l2jmobius.gameserver.data.SkillTable;
import org.l2jmobius.gameserver.data.SkillTreeTable;
import org.l2jmobius.gameserver.model.SkillLearn;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.CharCreateFail;
import org.l2jmobius.gameserver.network.serverpackets.CharCreateOk;
import org.l2jmobius.gameserver.network.serverpackets.CharSelectInfo;
import org.l2jmobius.gameserver.templates.L2CharTemplate;
public class CharacterCreate extends ClientBasePacket
{
private static final String _C__0B_CHARACTERCREATE = "[C] 0B CharacterCreate";
public CharacterCreate(byte[] decrypt, ClientThread client) throws IOException
{
super(decrypt);
PlayerInstance newChar = new PlayerInstance();
newChar.setName(readS());
newChar.setRace(readD());
newChar.setSex(readD());
newChar.setClassId(readD());
newChar.setInt(readD());
newChar.setStr(readD());
newChar.setCon(readD());
newChar.setMen(readD());
newChar.setDex(readD());
newChar.setWit(readD());
newChar.setHairStyle(readD());
newChar.setHairColor(readD());
newChar.setFace(readD());
if (CharNameTable.getInstance().doesCharNameExist(newChar.getName()))
{
_log.fine("charname: " + newChar.getName() + " already exists. creation failed.");
CharCreateFail ccf = new CharCreateFail(CharCreateFail.REASON_NAME_ALREADY_EXISTS);
client.getConnection().sendPacket(ccf);
}
else if ((newChar.getName().length() <= 16) && isAlphaNumeric(newChar.getName()))
{
_log.fine("charname: " + newChar.getName() + " classId: " + newChar.getClassId());
CharCreateOk cco = new CharCreateOk();
client.getConnection().sendPacket(cco);
initNewChar(client, newChar);
CharNameTable.getInstance().addCharName(newChar.getName());
}
else
{
_log.fine("charname: " + newChar.getName() + " is invalid. creation failed.");
CharCreateFail ccf = new CharCreateFail(CharCreateFail.REASON_16_ENG_CHARS);
client.getConnection().sendPacket(ccf);
}
}
private boolean isAlphaNumeric(String text)
{
boolean result = true;
char[] chars = text.toCharArray();
for (char c : chars)
{
if (Character.isLetterOrDigit(c))
{
continue;
}
result = false;
break;
}
return result;
}
private void initNewChar(ClientThread client, PlayerInstance newChar) throws FileNotFoundException, IOException
{
_log.fine("Character init start");
newChar.setObjectId(IdFactory.getInstance().getNextId());
World.getInstance().storeObject(newChar);
L2CharTemplate template = CharTemplateTable.getInstance().getTemplate(newChar.getClassId());
newChar.setAccuracy(template.getAcc());
newChar.setCon(template.getCon());
newChar.setCriticalHit(template.getCrit());
newChar.setMaxHp(template.getHp());
newChar.setCurrentHp(template.getHp());
newChar.setMaxLoad(template.getLoad());
newChar.setMaxMp(template.getMp());
newChar.setCurrentMp(template.getMp());
newChar.setDex(template.getDex());
newChar.setEvasionRate(template.getEvas());
newChar.setExp(0);
newChar.setInt(template.getInt());
newChar.setKarma(0);
newChar.setLevel(1);
newChar.setMagicalAttack(template.getMatk());
newChar.setMagicalDefense(template.getMdef());
newChar.setMagicalSpeed(template.getMspd());
newChar.setPhysicalAttack(template.getPatk());
newChar.setPhysicalDefense(template.getPdef());
newChar.setPhysicalSpeed(template.getPspd());
newChar.setMen(template.getMen());
newChar.setPvpKills(0);
newChar.setPkKills(0);
newChar.setSp(0);
newChar.setStr(template.getStr());
newChar.setRunSpeed(template.getMoveSpd());
newChar.setWalkSpeed((int) (template.getMoveSpd() * 0.7));
newChar.setWit(template.getWit());
newChar.setPvpFlag(0);
newChar.addAdena(5000);
newChar.setCanCraft(template.getCanCraft());
newChar.setX(template.getX());
newChar.setY(template.getY());
newChar.setZ(template.getZ());
if (newChar.isMale())
{
newChar.setMovementMultiplier(template.getMUnk1());
newChar.setAttackSpeedMultiplier(template.getMUnk2());
newChar.setCollisionRadius(template.getMColR());
newChar.setCollisionHeight(template.getMColH());
}
else
{
newChar.setMovementMultiplier(template.getFUnk1());
newChar.setAttackSpeedMultiplier(template.getFUnk2());
newChar.setCollisionRadius(template.getFColR());
newChar.setCollisionHeight(template.getFColH());
}
ItemTable itemTable = ItemTable.getInstance();
Integer[] items = template.getItems();
for (Integer item2 : items)
{
ItemInstance item = itemTable.createItem(item2);
newChar.getInventory().addItem(item);
}
newChar.setTitle("");
newChar.setClanId(0);
SkillLearn[] startSkills = SkillTreeTable.getInstance().getAvailableSkills(newChar);
for (SkillLearn startSkill : startSkills)
{
newChar.addSkill(SkillTable.getInstance().getInfo(startSkill.getId(), startSkill.getLevel()));
_log.fine("adding starter skill:" + startSkill.getId() + " / " + startSkill.getLevel());
}
client.saveCharToDisk(newChar);
CharSelectInfo cl = new CharSelectInfo(client.getLoginName(), client.getSessionId());
client.getConnection().sendPacket(cl);
_log.fine("Character init end");
}
@Override
public String getType()
{
return _C__0B_CHARACTERCREATE;
}
}

View File

@@ -0,0 +1,49 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.io.IOException;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.Connection;
import org.l2jmobius.gameserver.network.serverpackets.CharDeleteOk;
import org.l2jmobius.gameserver.network.serverpackets.CharSelectInfo;
public class CharacterDelete extends ClientBasePacket
{
private static final String _C__0C_CHARACTERDELETE = "[C] 0C CharacterDelete";
public CharacterDelete(byte[] decrypt, ClientThread client) throws IOException
{
super(decrypt);
int charSlot = readD();
_log.fine("deleting slot:" + charSlot);
Connection con = client.getConnection();
client.deleteCharFromDisk(charSlot);
CharDeleteOk ccf = new CharDeleteOk();
con.sendPacket(ccf);
CharSelectInfo cl = new CharSelectInfo(client.getLoginName(), client.getSessionId());
con.sendPacket(cl);
}
@Override
public String getType()
{
return _C__0C_CHARACTERDELETE;
}
}

View File

@@ -0,0 +1,43 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.io.IOException;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.network.serverpackets.CharSelectInfo;
public class CharacterRestore extends ClientBasePacket
{
private static final String _C__62_CHARACTERRESTORE = "[C] 62 CharacterRestore";
public CharacterRestore(byte[] decrypt, ClientThread client) throws IOException
{
super(decrypt);
@SuppressWarnings("unused")
int charSlot = readD();
CharSelectInfo cl = new CharSelectInfo(client.getLoginName(), client.getSessionId());
client.getConnection().sendPacket(cl);
}
@Override
public String getType()
{
return _C__62_CHARACTERRESTORE;
}
}

View File

@@ -0,0 +1,47 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.io.IOException;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.CharSelected;
public class CharacterSelected extends ClientBasePacket
{
private static final String _C__0D_CHARACTERSELECTED = "[C] 0D CharacterSelected";
public CharacterSelected(byte[] decrypt, ClientThread client) throws IOException
{
super(decrypt);
int charSlot = readD();
PlayerInstance cha = client.loadCharFromDisk(charSlot);
cha.setMoveType(1);
cha.setWaitType(1);
CharSelected cs = new CharSelected(cha, client.getSessionId());
client.getConnection().sendPacket(cs);
client.setActiveChar(cha);
}
@Override
public String getType()
{
return _C__0D_CHARACTERSELECTED;
}
}

View File

@@ -0,0 +1,93 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.util.logging.Logger;
public abstract class ClientBasePacket
{
static Logger _log = Logger.getLogger(ClientBasePacket.class.getName());
private final byte[] _decrypt;
private int _off;
public ClientBasePacket(byte[] decrypt)
{
_log.finest(getType());
_decrypt = decrypt;
_off = 1;
}
public int readD()
{
int result = _decrypt[_off++] & 0xFF;
result |= (_decrypt[_off++] << 8) & 0xFF00;
result |= (_decrypt[_off++] << 16) & 0xFF0000;
return result |= (_decrypt[_off++] << 24) & 0xFF000000;
}
public int readC()
{
int result = _decrypt[_off++] & 0xFF;
return result;
}
public int readH()
{
int result = _decrypt[_off++] & 0xFF;
return result |= (_decrypt[_off++] << 8) & 0xFF00;
}
public double readF()
{
long result = _decrypt[_off++] & 0xFF;
result |= (_decrypt[_off++] << 8) & 0xFF00;
result |= (_decrypt[_off++] << 16) & 0xFF0000;
result |= (_decrypt[_off++] << 24) & 0xFF000000;
result |= ((long) _decrypt[_off++] << 32) & 0xFF00000000L;
result |= ((long) _decrypt[_off++] << 40) & 0xFF0000000000L;
result |= ((long) _decrypt[_off++] << 48) & 0xFF000000000000L;
return Double.longBitsToDouble(result |= ((long) _decrypt[_off++] << 56) & 0xFF00000000000000L);
}
public String readS()
{
String result = null;
try
{
result = new String(_decrypt, _off, _decrypt.length - _off, "UTF-16LE");
result = result.substring(0, result.indexOf(0));
}
catch (Exception e)
{
result = "";
}
_off += (result.length() * 2) + 2;
return result;
}
public byte[] readB(int length)
{
byte[] result = new byte[length];
System.arraycopy(_decrypt, _off, result, 0, length);
_off += length;
return result;
}
public abstract String getType();
}

View File

@@ -0,0 +1,114 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.io.IOException;
import org.l2jmobius.gameserver.Announcements;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.Connection;
import org.l2jmobius.gameserver.GmListTable;
import org.l2jmobius.gameserver.model.Clan;
import org.l2jmobius.gameserver.model.ShortCut;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.Die;
import org.l2jmobius.gameserver.network.serverpackets.ItemList;
import org.l2jmobius.gameserver.network.serverpackets.ShortCutInit;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
public class EnterWorld extends ClientBasePacket
{
private static final String _C__03_ENTERWORLD = "[C] 03 EnterWorld";
public EnterWorld(byte[] decrypt, ClientThread client) throws IOException
{
super(decrypt);
PlayerInstance activeChar = client.getActiveChar();
Connection con = client.getConnection();
if (client.getAccessLevel() >= 100)
{
activeChar.setIsGM(true);
GmListTable.getInstance().addGm(activeChar);
}
SystemMessage sm = new SystemMessage(34);
con.sendPacket(sm);
Announcements.getInstance().showAnnouncements(activeChar);
ItemList il = new ItemList(activeChar, false);
activeChar.sendPacket(il);
ShortCutInit sci = new ShortCutInit();
ShortCut[] shortcuts = activeChar.getAllShortCuts();
block5: for (ShortCut shortcut : shortcuts)
{
switch (shortcut.getType())
{
case 3:
{
sci.addActionShotCut(shortcut.getSlot(), shortcut.getId(), shortcut.getUnk());
continue block5;
}
case 2:
{
sci.addSkillShotCut(shortcut.getSlot(), shortcut.getId(), shortcut.getLevel(), shortcut.getUnk());
continue block5;
}
case 1:
{
sci.addItemShotCut(shortcut.getSlot(), shortcut.getId(), shortcut.getUnk());
continue block5;
}
default:
{
_log.warning("unknown shortcut type " + shortcut.getType());
}
}
}
con.sendPacket(sci);
UserInfo ui = new UserInfo(activeChar);
con.sendPacket(ui);
if (activeChar.isDead())
{
activeChar.sendPacket(new Die(activeChar));
}
World.getInstance().addVisibleObject(activeChar);
notifyClanMembers(activeChar);
}
private void notifyClanMembers(PlayerInstance activeChar)
{
Clan clan = activeChar.getClan();
if (clan != null)
{
clan.getClanMember(activeChar.getName()).setPlayerInstance(activeChar);
SystemMessage msg = new SystemMessage(304);
msg.addString(activeChar.getName());
PlayerInstance[] clanMembers = clan.getOnlineMembers(activeChar.getName());
for (PlayerInstance clanMember : clanMembers)
{
clanMember.sendPacket(msg);
}
}
}
@Override
public String getType()
{
return _C__03_ENTERWORLD;
}
}

View File

@@ -0,0 +1,43 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.network.serverpackets.StopRotation;
public class FinishRotating extends ClientBasePacket
{
private static final String _C__4B_FINISHROTATING = "[C] 4B FinishRotating";
public FinishRotating(byte[] decrypt, ClientThread client)
{
super(decrypt);
int degree = readD();
@SuppressWarnings("unused")
int unknown = readD();
StopRotation sr = new StopRotation(client.getActiveChar(), degree);
client.getActiveChar().sendPacket(sr);
client.getActiveChar().broadcastPacket(sr);
}
@Override
public String getType()
{
return _C__4B_FINISHROTATING;
}
}

View File

@@ -0,0 +1,48 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.io.IOException;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.LeaveWorld;
public class Logout extends ClientBasePacket
{
private static final String _C__09_LOGOUT = "[C] 09 Logout";
public Logout(byte[] decrypt, ClientThread client) throws IOException
{
super(decrypt);
LeaveWorld ql = new LeaveWorld();
client.getConnection().sendPacket(ql);
PlayerInstance player = client.getActiveChar();
if (player != null)
{
player.deleteMe();
client.saveCharToDisk(player);
}
}
@Override
public String getType()
{
return _C__09_LOGOUT;
}
}

View File

@@ -0,0 +1,65 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.AttackCanceld;
public class MoveBackwardToLocation extends ClientBasePacket
{
private static final String _C__01_MOVEBACKWARDTOLOC = "[C] 01 MoveBackwardToLoc";
public MoveBackwardToLocation(byte[] decrypt, ClientThread client)
{
super(decrypt);
int targetX = readD();
int targetY = readD();
int targetZ = readD();
int originX = readD();
int originY = readD();
int originZ = readD();
PlayerInstance activeChar = client.getActiveChar();
if (activeChar.getCurrentState() == 2)
{
activeChar.sendPacket(new ActionFailed());
}
else
{
if (activeChar.getCurrentState() == 5)
{
AttackCanceld ac = new AttackCanceld(activeChar.getObjectId());
activeChar.sendPacket(ac);
activeChar.broadcastPacket(ac);
}
activeChar.setInCombat(false);
activeChar.setCurrentState((byte) 0);
activeChar.setX(originX);
activeChar.setY(originY);
activeChar.setZ(originZ);
activeChar.moveTo(targetX, targetY, targetZ, 0);
}
}
@Override
public String getType()
{
return _C__01_MOVEBACKWARDTOLOC;
}
}

View File

@@ -0,0 +1,63 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.io.IOException;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.data.CharTemplateTable;
import org.l2jmobius.gameserver.network.serverpackets.CharTemplates;
import org.l2jmobius.gameserver.templates.L2CharTemplate;
public class NewCharacter extends ClientBasePacket
{
private static final String _C__0E_NEWCHARACTER = "[C] 0E NewCharacter";
public NewCharacter(byte[] rawPacket, ClientThread client) throws IOException
{
super(rawPacket);
CharTemplates ct = new CharTemplates();
L2CharTemplate template = CharTemplateTable.getInstance().getTemplate(0);
ct.addChar(template);
template = CharTemplateTable.getInstance().getTemplate(0);
ct.addChar(template);
template = CharTemplateTable.getInstance().getTemplate(10);
ct.addChar(template);
template = CharTemplateTable.getInstance().getTemplate(18);
ct.addChar(template);
template = CharTemplateTable.getInstance().getTemplate(25);
ct.addChar(template);
template = CharTemplateTable.getInstance().getTemplate(31);
ct.addChar(template);
template = CharTemplateTable.getInstance().getTemplate(38);
ct.addChar(template);
template = CharTemplateTable.getInstance().getTemplate(44);
ct.addChar(template);
template = CharTemplateTable.getInstance().getTemplate(49);
ct.addChar(template);
template = CharTemplateTable.getInstance().getTemplate(53);
ct.addChar(template);
client.getConnection().sendPacket(ct);
}
@Override
public String getType()
{
return _C__0E_NEWCHARACTER;
}
}

View File

@@ -0,0 +1,53 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.io.IOException;
import org.l2jmobius.Config;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.Connection;
import org.l2jmobius.gameserver.network.serverpackets.KeyPacket;
public class ProtocolVersion extends ClientBasePacket
{
private static final String _C__00_PROTOCOLVERSION = "[C] 00 ProtocolVersion";
public ProtocolVersion(byte[] rawPacket, ClientThread client) throws IOException
{
super(rawPacket);
int version = readD();
// _log.fine("Protocol Revision:" + version);
if (version != Config.CLIENT_PROTOCOL_VERSION)
{
_log.warning("Client " + client.getLoginName() + " tryied to login with client protocol " + version);
throw new IOException("Wrong Protocol Version: " + version);
}
Connection con = client.getConnection();
KeyPacket pk = new KeyPacket();
pk.setKey(con.getCryptKey());
con.sendPacket(pk);
con.activateCryptKey();
}
@Override
public String getType()
{
return _C__00_PROTOCOLVERSION;
}
}

View File

@@ -0,0 +1,140 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.l2jmobius.gameserver.network.clientpackets;
import org.l2jmobius.gameserver.ClientThread;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.ChangeMoveType;
import org.l2jmobius.gameserver.network.serverpackets.ChangeWaitType;
import org.l2jmobius.gameserver.network.serverpackets.StopMove;
public class RequestActionUse extends ClientBasePacket
{
private static final String _C__45_REQUESTACTIONUSE = "[C] 45 RequestActionUse";
public RequestActionUse(byte[] rawPacket, ClientThread client)
{
super(rawPacket);
int actionId = readD();
int data2 = readD();
int data3 = readC();
_log.fine("request Action use: id " + actionId + " 2:" + data2 + " 3:" + data3);
PlayerInstance activeChar = client.getActiveChar();
if (activeChar.isDead())
{
activeChar.sendPacket(new ActionFailed());
return;
}
switch (actionId)
{
case 0:
{
int waitType = activeChar.getWaitType() ^ 1;
_log.fine("new wait type: " + waitType);
ChangeWaitType cmt = new ChangeWaitType(activeChar, waitType);
activeChar.setWaitType(waitType);
activeChar.sendPacket(cmt);
activeChar.broadcastPacket(cmt);
break;
}
case 1:
{
int moveType = activeChar.getMoveType() ^ 1;
_log.fine("new move type: " + moveType);
ChangeMoveType cmt = new ChangeMoveType(activeChar, moveType);
activeChar.setMoveType(moveType);
activeChar.sendPacket(cmt);
activeChar.broadcastPacket(cmt);
break;
}
case 15:
{
if (activeChar.getPet() == null)
{
break;
}
if (activeChar.getPet().getCurrentState() != 8)
{
activeChar.getPet().setCurrentState((byte) 8);
activeChar.getPet().setFollowStatus(true);
activeChar.getPet().followOwner(activeChar);
break;
}
activeChar.getPet().setCurrentState((byte) 0);
activeChar.getPet().setFollowStatus(false);
activeChar.getPet().setMovingToPawn(false);
activeChar.getPet().setPawnTarget(null);
activeChar.getPet().stopMove();
activeChar.getPet().broadcastPacket(new StopMove(activeChar.getPet()));
break;
}
case 16:
{
if ((activeChar.getTarget() == null) || (activeChar.getPet() == null) || (activeChar.getPet() == activeChar.getTarget()))
{
break;
}
activeChar.getPet().startAttack((Creature) activeChar.getTarget());
break;
}
case 17:
{
if (activeChar.getPet() == null)
{
break;
}
if (activeChar.getPet().getCurrentState() == 8)
{
activeChar.getPet().setFollowStatus(false);
activeChar.getPet().setMovingToPawn(false);
activeChar.getPet().setPawnTarget(null);
}
activeChar.getPet().setCurrentState((byte) 0);
activeChar.getPet().stopMove();
activeChar.getPet().broadcastPacket(new StopMove(activeChar.getPet()));
break;
}
case 18:
{
_log.warning("unhandled action type 18");
break;
}
case 19:
{
if (activeChar.getPet() == null)
{
break;
}
activeChar.getPet().unSummon(activeChar);
break;
}
case 20:
{
_log.warning("unhandled action type 20");
}
}
}
@Override
public String getType()
{
return _C__45_REQUESTACTIONUSE;
}
}

Some files were not shown because too many files have changed in this diff Show More