Merged with released L2J-Unity files.
This commit is contained in:
@ -1,285 +1,316 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
|
||||
/**
|
||||
* Loads name and access level for all players.
|
||||
* @version 2005/03/27
|
||||
*/
|
||||
public class CharNameTable
|
||||
{
|
||||
private static Logger _log = Logger.getLogger(CharNameTable.class.getName());
|
||||
|
||||
private final Map<Integer, String> _chars = new ConcurrentHashMap<>();
|
||||
private final Map<Integer, Integer> _accessLevels = new ConcurrentHashMap<>();
|
||||
|
||||
protected CharNameTable()
|
||||
{
|
||||
if (Config.CACHE_CHAR_NAMES)
|
||||
{
|
||||
loadAll();
|
||||
}
|
||||
}
|
||||
|
||||
public final void addName(L2PcInstance player)
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
addName(player.getObjectId(), player.getName());
|
||||
_accessLevels.put(player.getObjectId(), player.getAccessLevel().getLevel());
|
||||
}
|
||||
|
||||
private final void addName(int objectId, String name)
|
||||
{
|
||||
if ((name != null) && !name.equals(_chars.get(objectId)))
|
||||
{
|
||||
_chars.put(objectId, name);
|
||||
}
|
||||
}
|
||||
|
||||
public final void removeName(int objId)
|
||||
{
|
||||
_chars.remove(objId);
|
||||
_accessLevels.remove(objId);
|
||||
}
|
||||
|
||||
public final int getIdByName(String name)
|
||||
{
|
||||
if ((name == null) || name.isEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (Entry<Integer, String> entry : _chars.entrySet())
|
||||
{
|
||||
if (entry.getValue().equalsIgnoreCase(name))
|
||||
{
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.CACHE_CHAR_NAMES)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int id = -1;
|
||||
int accessLevel = 0;
|
||||
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT charId,accesslevel FROM characters WHERE char_name=?"))
|
||||
{
|
||||
ps.setString(1, name);
|
||||
try (ResultSet rs = ps.executeQuery())
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
id = rs.getInt(1);
|
||||
accessLevel = rs.getInt(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not check existing char name: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
if (id <= 0)
|
||||
{
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
_chars.put(id, name);
|
||||
_accessLevels.put(id, accessLevel);
|
||||
return id;
|
||||
}
|
||||
|
||||
public final String getNameById(int id)
|
||||
{
|
||||
if (id <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String name = _chars.get(id);
|
||||
if (name != null)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
if (Config.CACHE_CHAR_NAMES)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT char_name,accesslevel FROM characters WHERE charId=?"))
|
||||
{
|
||||
ps.setInt(1, id);
|
||||
try (ResultSet rset = ps.executeQuery())
|
||||
{
|
||||
if (rset.next())
|
||||
{
|
||||
name = rset.getString(1);
|
||||
_chars.put(id, name);
|
||||
_accessLevels.put(id, rset.getInt(2));
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not check existing char id: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null; // not found
|
||||
}
|
||||
|
||||
public final int getAccessLevelById(int objectId)
|
||||
{
|
||||
return getNameById(objectId) != null ? _accessLevels.get(objectId) : 0;
|
||||
}
|
||||
|
||||
public synchronized boolean doesCharNameExist(String name)
|
||||
{
|
||||
boolean result = true;
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT account_name FROM characters WHERE char_name=?"))
|
||||
{
|
||||
ps.setString(1, name);
|
||||
try (ResultSet rs = ps.executeQuery())
|
||||
{
|
||||
result = rs.next();
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not check existing charname: " + e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getAccountCharacterCount(String account)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT COUNT(char_name) FROM characters WHERE account_name=?"))
|
||||
{
|
||||
ps.setString(1, account);
|
||||
try (ResultSet rset = ps.executeQuery())
|
||||
{
|
||||
while (rset.next())
|
||||
{
|
||||
return rset.getInt(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not check existing char count: " + e.getMessage(), e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getLevelById(int objectId)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT level FROM characters WHERE charId = ?"))
|
||||
{
|
||||
ps.setInt(1, objectId);
|
||||
try (ResultSet rset = ps.executeQuery())
|
||||
{
|
||||
while (rset.next())
|
||||
{
|
||||
return rset.getInt(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not check existing char count: " + e.getMessage(), e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getClassIdById(int objectId)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT classid FROM characters WHERE charId = ?"))
|
||||
{
|
||||
ps.setInt(1, objectId);
|
||||
try (ResultSet rset = ps.executeQuery())
|
||||
{
|
||||
while (rset.next())
|
||||
{
|
||||
return rset.getInt(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not check existing char count: " + e.getMessage(), e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void loadAll()
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery("SELECT charId, char_name, accesslevel FROM characters"))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final int id = rs.getInt(1);
|
||||
_chars.put(id, rs.getString(2));
|
||||
_accessLevels.put(id, rs.getInt(3));
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not load char name: " + e.getMessage(), e);
|
||||
}
|
||||
_log.info(getClass().getSimpleName() + ": Loaded " + _chars.size() + " char names.");
|
||||
}
|
||||
|
||||
public static CharNameTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final CharNameTable _instance = new CharNameTable();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
|
||||
/**
|
||||
* Loads name and access level for all players.
|
||||
* @version 2005/03/27
|
||||
*/
|
||||
public class CharNameTable
|
||||
{
|
||||
private static Logger _log = Logger.getLogger(CharNameTable.class.getName());
|
||||
|
||||
private final Map<Integer, String> _chars = new ConcurrentHashMap<>();
|
||||
private final Map<Integer, Integer> _accessLevels = new ConcurrentHashMap<>();
|
||||
|
||||
protected CharNameTable()
|
||||
{
|
||||
if (Config.CACHE_CHAR_NAMES)
|
||||
{
|
||||
loadAll();
|
||||
}
|
||||
}
|
||||
|
||||
public final void addName(L2PcInstance player)
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
addName(player.getObjectId(), player.getName());
|
||||
_accessLevels.put(player.getObjectId(), player.getAccessLevel().getLevel());
|
||||
}
|
||||
}
|
||||
|
||||
private final void addName(int objectId, String name)
|
||||
{
|
||||
if (name != null)
|
||||
{
|
||||
if (!name.equals(_chars.get(objectId)))
|
||||
{
|
||||
_chars.put(objectId, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void removeName(int objId)
|
||||
{
|
||||
_chars.remove(objId);
|
||||
_accessLevels.remove(objId);
|
||||
}
|
||||
|
||||
public final int getIdByName(String name)
|
||||
{
|
||||
if ((name == null) || name.isEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (Entry<Integer, String> entry : _chars.entrySet())
|
||||
{
|
||||
if (entry.getValue().equalsIgnoreCase(name))
|
||||
{
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.CACHE_CHAR_NAMES)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int id = -1;
|
||||
int accessLevel = 0;
|
||||
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT charId,accesslevel FROM characters WHERE char_name=?"))
|
||||
{
|
||||
ps.setString(1, name);
|
||||
try (ResultSet rs = ps.executeQuery())
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
id = rs.getInt("charId");
|
||||
accessLevel = rs.getInt("accesslevel");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not check existing char name: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
if (id > 0)
|
||||
{
|
||||
_chars.put(id, name);
|
||||
_accessLevels.put(id, accessLevel);
|
||||
return id;
|
||||
}
|
||||
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
public final String getNameById(int id)
|
||||
{
|
||||
if (id <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String name = _chars.get(id);
|
||||
if (name != null)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
if (Config.CACHE_CHAR_NAMES)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT char_name,accesslevel FROM characters WHERE charId=?"))
|
||||
{
|
||||
ps.setInt(1, id);
|
||||
try (ResultSet rset = ps.executeQuery())
|
||||
{
|
||||
if (rset.next())
|
||||
{
|
||||
name = rset.getString("char_name");
|
||||
_chars.put(id, name);
|
||||
_accessLevels.put(id, rset.getInt("accesslevel"));
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not check existing char id: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null; // not found
|
||||
}
|
||||
|
||||
public final int getAccessLevelById(int objectId)
|
||||
{
|
||||
if (getNameById(objectId) != null)
|
||||
{
|
||||
return _accessLevels.get(objectId);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public synchronized boolean doesCharNameExist(String name)
|
||||
{
|
||||
boolean result = false;
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) as count FROM characters WHERE char_name=?"))
|
||||
{
|
||||
ps.setString(1, name);
|
||||
try (ResultSet rs = ps.executeQuery())
|
||||
{
|
||||
if (rs.next())
|
||||
{
|
||||
result = rs.getInt("count") > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not check existing charname: " + e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getAccountCharacterCount(String account)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT COUNT(char_name) as count FROM characters WHERE account_name=?"))
|
||||
{
|
||||
ps.setString(1, account);
|
||||
try (ResultSet rset = ps.executeQuery())
|
||||
{
|
||||
if (rset.next())
|
||||
{
|
||||
return rset.getInt("count");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Couldn't retrieve account for id: " + e.getMessage(), e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getLevelById(int objectId)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT level FROM characters WHERE charId = ?"))
|
||||
{
|
||||
ps.setInt(1, objectId);
|
||||
try (ResultSet rset = ps.executeQuery())
|
||||
{
|
||||
if (rset.next())
|
||||
{
|
||||
return rset.getInt("level");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not check existing char count: " + e.getMessage(), e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getClassIdById(int objectId)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT classid FROM characters WHERE charId = ?"))
|
||||
{
|
||||
ps.setInt(1, objectId);
|
||||
try (ResultSet rset = ps.executeQuery())
|
||||
{
|
||||
if (rset.next())
|
||||
{
|
||||
return rset.getInt("classid");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Couldn't retrieve class for id: " + e.getMessage(), e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getClanIdById(int objectId)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT clanId FROM characters WHERE charId = ?"))
|
||||
{
|
||||
ps.setInt(1, objectId);
|
||||
try (ResultSet rset = ps.executeQuery())
|
||||
{
|
||||
while (rset.next())
|
||||
{
|
||||
return rset.getInt("clanId");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not check existing char count: " + e.getMessage(), e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void loadAll()
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery("SELECT charId, char_name, accesslevel FROM characters"))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final int id = rs.getInt("charId");
|
||||
_chars.put(id, rs.getString("char_name"));
|
||||
_accessLevels.put(id, rs.getInt("accesslevel"));
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Couldn't retrieve all char id/name/access: " + e.getMessage(), e);
|
||||
}
|
||||
_log.info(getClass().getSimpleName() + ": Loaded " + _chars.size() + " char names.");
|
||||
}
|
||||
|
||||
public static CharNameTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final CharNameTable _instance = new CharNameTable();
|
||||
}
|
||||
}
|
||||
|
@ -1,256 +1,256 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.PetDataTable;
|
||||
import com.l2jmobius.gameserver.datatables.SkillData;
|
||||
import com.l2jmobius.gameserver.model.L2PetData;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PetInstance;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2ServitorInstance;
|
||||
import com.l2jmobius.gameserver.model.actor.templates.L2NpcTemplate;
|
||||
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
||||
import com.l2jmobius.gameserver.model.skills.Skill;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.PetItemList;
|
||||
|
||||
/**
|
||||
* @author Nyaran
|
||||
*/
|
||||
public class CharSummonTable
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(CharSummonTable.class.getName());
|
||||
private static final Map<Integer, Integer> _pets = new ConcurrentHashMap<>();
|
||||
private static final Map<Integer, Set<Integer>> _servitors = new ConcurrentHashMap<>();
|
||||
|
||||
// SQL
|
||||
private static final String INIT_PET = "SELECT ownerId, item_obj_id FROM pets WHERE restore = 'true'";
|
||||
private static final String INIT_SUMMONS = "SELECT ownerId, summonId FROM character_summons";
|
||||
private static final String LOAD_SUMMON = "SELECT summonSkillId, summonId, curHp, curMp, time FROM character_summons WHERE ownerId = ?";
|
||||
private static final String REMOVE_SUMMON = "DELETE FROM character_summons WHERE ownerId = ? and summonId = ?";
|
||||
private static final String SAVE_SUMMON = "REPLACE INTO character_summons (ownerId,summonId,summonSkillId,curHp,curMp,time) VALUES (?,?,?,?,?,?)";
|
||||
|
||||
public Map<Integer, Integer> getPets()
|
||||
{
|
||||
return _pets;
|
||||
}
|
||||
|
||||
public Map<Integer, Set<Integer>> getServitors()
|
||||
{
|
||||
return _servitors;
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
if (Config.RESTORE_SERVITOR_ON_RECONNECT)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery(INIT_SUMMONS))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
_servitors.computeIfAbsent(rs.getInt("ownerId"), k -> ConcurrentHashMap.newKeySet()).add(rs.getInt("summonId"));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Error while loading saved servitor: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.RESTORE_PET_ON_RECONNECT)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery(INIT_PET))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
_pets.put(rs.getInt("ownerId"), rs.getInt("item_obj_id"));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Error while loading saved pet: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeServitor(L2PcInstance activeChar, int summonObjectId)
|
||||
{
|
||||
_servitors.computeIfPresent(activeChar.getObjectId(), (k, v) ->
|
||||
{
|
||||
v.remove(summonObjectId);
|
||||
return !v.isEmpty() ? v : null;
|
||||
});
|
||||
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement(REMOVE_SUMMON))
|
||||
{
|
||||
ps.setInt(1, activeChar.getObjectId());
|
||||
ps.setInt(2, summonObjectId);
|
||||
ps.execute();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Summon cannot be removed: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public void restorePet(L2PcInstance activeChar)
|
||||
{
|
||||
final L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_pets.get(activeChar.getObjectId()));
|
||||
if (item == null)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Null pet summoning item for: " + activeChar);
|
||||
return;
|
||||
}
|
||||
final L2PetData petData = PetDataTable.getInstance().getPetDataByItemId(item.getId());
|
||||
if (petData == null)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Null pet data for: " + activeChar + " and summoning item: " + item);
|
||||
return;
|
||||
}
|
||||
final L2NpcTemplate npcTemplate = NpcData.getInstance().getTemplate(petData.getNpcId());
|
||||
if (npcTemplate == null)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Null pet NPC template for: " + activeChar + " and pet Id:" + petData.getNpcId());
|
||||
return;
|
||||
}
|
||||
|
||||
final L2PetInstance pet = L2PetInstance.spawnPet(npcTemplate, activeChar, item);
|
||||
if (pet == null)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Null pet instance for: " + activeChar + " and pet NPC template:" + npcTemplate);
|
||||
return;
|
||||
}
|
||||
|
||||
pet.setShowSummonAnimation(true);
|
||||
pet.setTitle(activeChar.getName());
|
||||
|
||||
if (!pet.isRespawned())
|
||||
{
|
||||
pet.setCurrentHp(pet.getMaxHp());
|
||||
pet.setCurrentMp(pet.getMaxMp());
|
||||
pet.getStat().setExp(pet.getExpForThisLevel());
|
||||
pet.setCurrentFed(pet.getMaxFed());
|
||||
}
|
||||
|
||||
pet.setRunning();
|
||||
|
||||
if (!pet.isRespawned())
|
||||
{
|
||||
pet.storeMe();
|
||||
}
|
||||
|
||||
item.setEnchantLevel(pet.getLevel());
|
||||
activeChar.setPet(pet);
|
||||
pet.spawnMe(activeChar.getX() + 50, activeChar.getY() + 100, activeChar.getZ());
|
||||
pet.startFeed();
|
||||
pet.setFollowStatus(true);
|
||||
pet.getOwner().sendPacket(new PetItemList(pet.getInventory().getItems()));
|
||||
pet.broadcastStatusUpdate();
|
||||
}
|
||||
|
||||
public void restoreServitor(L2PcInstance activeChar)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement(LOAD_SUMMON))
|
||||
{
|
||||
ps.setInt(1, activeChar.getObjectId());
|
||||
try (ResultSet rs = ps.executeQuery())
|
||||
{
|
||||
Skill skill;
|
||||
while (rs.next())
|
||||
{
|
||||
final int summonObjId = rs.getInt("summonId");
|
||||
final int skillId = rs.getInt("summonSkillId");
|
||||
final int curHp = rs.getInt("curHp");
|
||||
final int curMp = rs.getInt("curMp");
|
||||
final int time = rs.getInt("time");
|
||||
|
||||
skill = SkillData.getInstance().getSkill(skillId, activeChar.getSkillLevel(skillId));
|
||||
if ((skill == null) || !activeChar.hasServitor(summonObjId))
|
||||
{
|
||||
removeServitor(activeChar, summonObjId);
|
||||
return;
|
||||
}
|
||||
|
||||
skill.applyEffects(activeChar, activeChar);
|
||||
|
||||
final L2ServitorInstance summon = (L2ServitorInstance) activeChar.getServitor(summonObjId);
|
||||
summon.setCurrentHp(curHp);
|
||||
summon.setCurrentMp(curMp);
|
||||
summon.setLifeTimeRemaining(time);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Servitor cannot be restored: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveSummon(L2ServitorInstance summon)
|
||||
{
|
||||
if ((summon == null) || (summon.getLifeTimeRemaining() <= 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_servitors.computeIfAbsent(summon.getOwner().getObjectId(), k -> ConcurrentHashMap.newKeySet()).add(summon.getObjectId());
|
||||
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement(SAVE_SUMMON))
|
||||
{
|
||||
ps.setInt(1, summon.getOwner().getObjectId());
|
||||
ps.setInt(2, summon.getObjectId());
|
||||
ps.setInt(3, summon.getReferenceSkill());
|
||||
ps.setInt(4, (int) Math.round(summon.getCurrentHp()));
|
||||
ps.setInt(5, (int) Math.round(summon.getCurrentMp()));
|
||||
ps.setInt(6, summon.getLifeTimeRemaining());
|
||||
ps.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Failed to store summon: " + summon + " from " + summon.getOwner() + ", error: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static CharSummonTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final CharSummonTable _instance = new CharSummonTable();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.PetDataTable;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.SkillData;
|
||||
import com.l2jmobius.gameserver.model.L2PetData;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PetInstance;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2ServitorInstance;
|
||||
import com.l2jmobius.gameserver.model.actor.templates.L2NpcTemplate;
|
||||
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
||||
import com.l2jmobius.gameserver.model.skills.Skill;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.PetItemList;
|
||||
|
||||
/**
|
||||
* @author Nyaran
|
||||
*/
|
||||
public class CharSummonTable
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(CharSummonTable.class.getName());
|
||||
private static final Map<Integer, Integer> _pets = new ConcurrentHashMap<>();
|
||||
private static final Map<Integer, Set<Integer>> _servitors = new ConcurrentHashMap<>();
|
||||
|
||||
// SQL
|
||||
private static final String INIT_PET = "SELECT ownerId, item_obj_id FROM pets WHERE restore = 'true'";
|
||||
private static final String INIT_SUMMONS = "SELECT ownerId, summonId FROM character_summons";
|
||||
private static final String LOAD_SUMMON = "SELECT summonSkillId, summonId, curHp, curMp, time FROM character_summons WHERE ownerId = ?";
|
||||
private static final String REMOVE_SUMMON = "DELETE FROM character_summons WHERE ownerId = ? and summonId = ?";
|
||||
private static final String SAVE_SUMMON = "REPLACE INTO character_summons (ownerId,summonId,summonSkillId,curHp,curMp,time) VALUES (?,?,?,?,?,?)";
|
||||
|
||||
public Map<Integer, Integer> getPets()
|
||||
{
|
||||
return _pets;
|
||||
}
|
||||
|
||||
public Map<Integer, Set<Integer>> getServitors()
|
||||
{
|
||||
return _servitors;
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
if (Config.RESTORE_SERVITOR_ON_RECONNECT)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery(INIT_SUMMONS))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
_servitors.computeIfAbsent(rs.getInt("ownerId"), k -> ConcurrentHashMap.newKeySet()).add(rs.getInt("summonId"));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Error while loading saved servitor: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.RESTORE_PET_ON_RECONNECT)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery(INIT_PET))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
_pets.put(rs.getInt("ownerId"), rs.getInt("item_obj_id"));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Error while loading saved pet: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeServitor(L2PcInstance activeChar, int summonObjectId)
|
||||
{
|
||||
_servitors.computeIfPresent(activeChar.getObjectId(), (k, v) ->
|
||||
{
|
||||
v.remove(summonObjectId);
|
||||
return !v.isEmpty() ? v : null;
|
||||
});
|
||||
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement(REMOVE_SUMMON))
|
||||
{
|
||||
ps.setInt(1, activeChar.getObjectId());
|
||||
ps.setInt(2, summonObjectId);
|
||||
ps.execute();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Summon cannot be removed: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public void restorePet(L2PcInstance activeChar)
|
||||
{
|
||||
final L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_pets.get(activeChar.getObjectId()));
|
||||
if (item == null)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Null pet summoning item for: " + activeChar);
|
||||
return;
|
||||
}
|
||||
final L2PetData petData = PetDataTable.getInstance().getPetDataByItemId(item.getId());
|
||||
if (petData == null)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Null pet data for: " + activeChar + " and summoning item: " + item);
|
||||
return;
|
||||
}
|
||||
final L2NpcTemplate npcTemplate = NpcData.getInstance().getTemplate(petData.getNpcId());
|
||||
if (npcTemplate == null)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Null pet NPC template for: " + activeChar + " and pet Id:" + petData.getNpcId());
|
||||
return;
|
||||
}
|
||||
|
||||
final L2PetInstance pet = L2PetInstance.spawnPet(npcTemplate, activeChar, item);
|
||||
if (pet == null)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Null pet instance for: " + activeChar + " and pet NPC template:" + npcTemplate);
|
||||
return;
|
||||
}
|
||||
|
||||
pet.setShowSummonAnimation(true);
|
||||
pet.setTitle(activeChar.getName());
|
||||
|
||||
if (!pet.isRespawned())
|
||||
{
|
||||
pet.setCurrentHp(pet.getMaxHp());
|
||||
pet.setCurrentMp(pet.getMaxMp());
|
||||
pet.getStat().setExp(pet.getExpForThisLevel());
|
||||
pet.setCurrentFed(pet.getMaxFed());
|
||||
}
|
||||
|
||||
pet.setRunning();
|
||||
|
||||
if (!pet.isRespawned())
|
||||
{
|
||||
pet.storeMe();
|
||||
}
|
||||
|
||||
item.setEnchantLevel(pet.getLevel());
|
||||
activeChar.setPet(pet);
|
||||
pet.spawnMe(activeChar.getX() + 50, activeChar.getY() + 100, activeChar.getZ());
|
||||
pet.startFeed();
|
||||
pet.setFollowStatus(true);
|
||||
pet.getOwner().sendPacket(new PetItemList(pet.getInventory().getItems()));
|
||||
pet.broadcastStatusUpdate();
|
||||
}
|
||||
|
||||
public void restoreServitor(L2PcInstance activeChar)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement(LOAD_SUMMON))
|
||||
{
|
||||
ps.setInt(1, activeChar.getObjectId());
|
||||
try (ResultSet rs = ps.executeQuery())
|
||||
{
|
||||
Skill skill;
|
||||
while (rs.next())
|
||||
{
|
||||
final int summonObjId = rs.getInt("summonId");
|
||||
final int skillId = rs.getInt("summonSkillId");
|
||||
final int curHp = rs.getInt("curHp");
|
||||
final int curMp = rs.getInt("curMp");
|
||||
final int time = rs.getInt("time");
|
||||
|
||||
skill = SkillData.getInstance().getSkill(skillId, activeChar.getSkillLevel(skillId));
|
||||
if ((skill == null) || !activeChar.hasServitor(summonObjId))
|
||||
{
|
||||
removeServitor(activeChar, summonObjId);
|
||||
return;
|
||||
}
|
||||
|
||||
skill.applyEffects(activeChar, activeChar);
|
||||
|
||||
final L2ServitorInstance summon = (L2ServitorInstance) activeChar.getServitor(summonObjId);
|
||||
summon.setCurrentHp(curHp);
|
||||
summon.setCurrentMp(curMp);
|
||||
summon.setLifeTimeRemaining(time);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Servitor cannot be restored: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveSummon(L2ServitorInstance summon)
|
||||
{
|
||||
if ((summon == null) || (summon.getLifeTimeRemaining() <= 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_servitors.computeIfAbsent(summon.getOwner().getObjectId(), k -> ConcurrentHashMap.newKeySet()).add(summon.getObjectId());
|
||||
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement(SAVE_SUMMON))
|
||||
{
|
||||
ps.setInt(1, summon.getOwner().getObjectId());
|
||||
ps.setInt(2, summon.getObjectId());
|
||||
ps.setInt(3, summon.getReferenceSkill());
|
||||
ps.setInt(4, (int) Math.round(summon.getCurrentHp()));
|
||||
ps.setInt(5, (int) Math.round(summon.getCurrentMp()));
|
||||
ps.setInt(6, summon.getLifeTimeRemaining());
|
||||
ps.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Failed to store summon: " + summon + " from " + summon.getOwner() + ", error: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static CharSummonTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final CharSummonTable _instance = new CharSummonTable();
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,199 +0,0 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.model.holders.ItemHolder;
|
||||
import com.l2jmobius.gameserver.model.holders.SkillHolder;
|
||||
|
||||
public class NpcBufferTable
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(NpcBufferTable.class.getName());
|
||||
|
||||
private final Map<Integer, NpcBufferSkills> _buffers = new HashMap<>();
|
||||
|
||||
public static class NpcBufferData
|
||||
{
|
||||
private final SkillHolder _skill;
|
||||
private final ItemHolder _fee;
|
||||
|
||||
protected NpcBufferData(int skillId, int skillLevel, int feeId, int feeAmount)
|
||||
{
|
||||
_skill = new SkillHolder(skillId, skillLevel);
|
||||
_fee = new ItemHolder(feeId, feeAmount);
|
||||
}
|
||||
|
||||
public SkillHolder getSkill()
|
||||
{
|
||||
return _skill;
|
||||
}
|
||||
|
||||
public ItemHolder getFee()
|
||||
{
|
||||
return _fee;
|
||||
}
|
||||
}
|
||||
|
||||
private static class NpcBufferSkills
|
||||
{
|
||||
private final int _npcId;
|
||||
private final Map<Integer, NpcBufferData> _skills = new HashMap<>();
|
||||
|
||||
protected NpcBufferSkills(int npcId)
|
||||
{
|
||||
_npcId = npcId;
|
||||
}
|
||||
|
||||
public void addSkill(int skillId, int skillLevel, int skillFeeId, int skillFeeAmount, int buffGroup)
|
||||
{
|
||||
_skills.put(buffGroup, new NpcBufferData(skillId, skillLevel, skillFeeId, skillFeeAmount));
|
||||
}
|
||||
|
||||
public NpcBufferData getSkillGroupInfo(int buffGroup)
|
||||
{
|
||||
return _skills.get(buffGroup);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public int getNpcId()
|
||||
{
|
||||
return _npcId;
|
||||
}
|
||||
}
|
||||
|
||||
protected NpcBufferTable()
|
||||
{
|
||||
int skillCount = 0;
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rset = s.executeQuery("SELECT `npc_id`,`skill_id`,`skill_level`,`skill_fee_id`,`skill_fee_amount`,`buff_group` FROM `npc_buffer` ORDER BY `npc_id` ASC"))
|
||||
{
|
||||
int lastNpcId = 0;
|
||||
NpcBufferSkills skills = null;
|
||||
|
||||
while (rset.next())
|
||||
{
|
||||
final int npcId = rset.getInt("npc_id");
|
||||
final int skillId = rset.getInt("skill_id");
|
||||
final int skillLevel = rset.getInt("skill_level");
|
||||
final int skillFeeId = rset.getInt("skill_fee_id");
|
||||
final int skillFeeAmount = rset.getInt("skill_fee_amount");
|
||||
final int buffGroup = rset.getInt("buff_group");
|
||||
|
||||
if (npcId != lastNpcId)
|
||||
{
|
||||
if (lastNpcId != 0)
|
||||
{
|
||||
_buffers.put(lastNpcId, skills);
|
||||
}
|
||||
|
||||
skills = new NpcBufferSkills(npcId);
|
||||
skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
|
||||
}
|
||||
else if (skills != null)
|
||||
{
|
||||
skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
|
||||
}
|
||||
|
||||
lastNpcId = npcId;
|
||||
skillCount++;
|
||||
}
|
||||
|
||||
if (lastNpcId != 0)
|
||||
{
|
||||
_buffers.put(lastNpcId, skills);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading npc_buffer table: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
if (Config.CUSTOM_NPCBUFFER_TABLES)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rset = s.executeQuery("SELECT `npc_id`,`skill_id`,`skill_level`,`skill_fee_id`,`skill_fee_amount`,`buff_group` FROM `custom_npc_buffer` ORDER BY `npc_id` ASC"))
|
||||
{
|
||||
int lastNpcId = 0;
|
||||
NpcBufferSkills skills = null;
|
||||
while (rset.next())
|
||||
{
|
||||
final int npcId = rset.getInt("npc_id");
|
||||
final int skillId = rset.getInt("skill_id");
|
||||
final int skillLevel = rset.getInt("skill_level");
|
||||
final int skillFeeId = rset.getInt("skill_fee_id");
|
||||
final int skillFeeAmount = rset.getInt("skill_fee_amount");
|
||||
final int buffGroup = rset.getInt("buff_group");
|
||||
|
||||
if (npcId != lastNpcId)
|
||||
{
|
||||
if (lastNpcId != 0)
|
||||
{
|
||||
_buffers.put(lastNpcId, skills);
|
||||
}
|
||||
|
||||
skills = new NpcBufferSkills(npcId);
|
||||
skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
|
||||
}
|
||||
else if (skills != null)
|
||||
{
|
||||
skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
|
||||
}
|
||||
lastNpcId = npcId;
|
||||
skillCount++;
|
||||
}
|
||||
|
||||
if (lastNpcId != 0)
|
||||
{
|
||||
_buffers.put(lastNpcId, skills);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading custom_npc_buffer table: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _buffers.size() + " buffers and " + skillCount + " skills.");
|
||||
}
|
||||
|
||||
public NpcBufferData getSkillInfo(int npcId, int buffGroup)
|
||||
{
|
||||
final NpcBufferSkills skills = _buffers.get(npcId);
|
||||
return skills != null ? skills.getSkillGroupInfo(buffGroup) : null;
|
||||
}
|
||||
|
||||
public static NpcBufferTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final NpcBufferTable _instance = new NpcBufferTable();
|
||||
}
|
||||
}
|
@ -1,415 +1,445 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Calendar;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.LoginServerThread;
|
||||
import com.l2jmobius.gameserver.enums.PrivateStoreType;
|
||||
import com.l2jmobius.gameserver.model.L2ManufactureItem;
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.TradeItem;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.L2GameClient;
|
||||
import com.l2jmobius.gameserver.network.L2GameClient.GameClientState;
|
||||
|
||||
public class OfflineTradersTable
|
||||
{
|
||||
private static Logger LOGGER = Logger.getLogger(OfflineTradersTable.class.getName());
|
||||
|
||||
// SQL DEFINITIONS
|
||||
private static final String SAVE_OFFLINE_STATUS = "INSERT INTO character_offline_trade (`charId`,`time`,`type`,`title`) VALUES (?,?,?,?)";
|
||||
private static final String SAVE_ITEMS = "INSERT INTO character_offline_trade_items (`charId`,`item`,`count`,`price`) VALUES (?,?,?,?)";
|
||||
private static final String CLEAR_OFFLINE_TABLE = "DELETE FROM character_offline_trade";
|
||||
private static final String CLEAR_OFFLINE_TABLE_PLAYER = "DELETE FROM character_offline_trade WHERE `charId`=?";
|
||||
private static final String CLEAR_OFFLINE_TABLE_ITEMS = "DELETE FROM character_offline_trade_items";
|
||||
private static final String CLEAR_OFFLINE_TABLE_ITEMS_PLAYER = "DELETE FROM character_offline_trade_items WHERE `charId`=?";
|
||||
private static final String LOAD_OFFLINE_STATUS = "SELECT * FROM character_offline_trade";
|
||||
private static final String LOAD_OFFLINE_ITEMS = "SELECT * FROM character_offline_trade_items WHERE `charId`=?";
|
||||
|
||||
public void storeOffliners()
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement stm1 = con.prepareStatement(CLEAR_OFFLINE_TABLE);
|
||||
PreparedStatement stm2 = con.prepareStatement(CLEAR_OFFLINE_TABLE_ITEMS);
|
||||
PreparedStatement stm3 = con.prepareStatement(SAVE_OFFLINE_STATUS);
|
||||
PreparedStatement stm_items = con.prepareStatement(SAVE_ITEMS))
|
||||
{
|
||||
stm1.execute();
|
||||
stm2.execute();
|
||||
con.setAutoCommit(false); // avoid halfway done
|
||||
|
||||
for (L2PcInstance pc : L2World.getInstance().getPlayers())
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((pc.getPrivateStoreType() != PrivateStoreType.NONE) && pc.isInOfflineMode())
|
||||
{
|
||||
stm3.setInt(1, pc.getObjectId()); // Char Id
|
||||
stm3.setLong(2, pc.getOfflineStartTime());
|
||||
stm3.setInt(3, pc.getPrivateStoreType().getId()); // store type
|
||||
String title = null;
|
||||
|
||||
switch (pc.getPrivateStoreType())
|
||||
{
|
||||
case BUY:
|
||||
{
|
||||
if (!Config.OFFLINE_TRADE_ENABLE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
title = pc.getBuyList().getTitle();
|
||||
for (TradeItem i : pc.getBuyList().getItems())
|
||||
{
|
||||
stm_items.setInt(1, pc.getObjectId());
|
||||
stm_items.setInt(2, i.getItem().getId());
|
||||
stm_items.setLong(3, i.getCount());
|
||||
stm_items.setLong(4, i.getPrice());
|
||||
stm_items.executeUpdate();
|
||||
stm_items.clearParameters();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SELL:
|
||||
case PACKAGE_SELL:
|
||||
{
|
||||
if (!Config.OFFLINE_TRADE_ENABLE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
title = pc.getSellList().getTitle();
|
||||
for (TradeItem i : pc.getSellList().getItems())
|
||||
{
|
||||
stm_items.setInt(1, pc.getObjectId());
|
||||
stm_items.setInt(2, i.getObjectId());
|
||||
stm_items.setLong(3, i.getCount());
|
||||
stm_items.setLong(4, i.getPrice());
|
||||
stm_items.executeUpdate();
|
||||
stm_items.clearParameters();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MANUFACTURE:
|
||||
{
|
||||
if (!Config.OFFLINE_CRAFT_ENABLE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
title = pc.getStoreName();
|
||||
for (L2ManufactureItem i : pc.getManufactureItems().values())
|
||||
{
|
||||
stm_items.setInt(1, pc.getObjectId());
|
||||
stm_items.setInt(2, i.getRecipeId());
|
||||
stm_items.setLong(3, 0);
|
||||
stm_items.setLong(4, i.getCost());
|
||||
stm_items.executeUpdate();
|
||||
stm_items.clearParameters();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
stm3.setString(4, title);
|
||||
stm3.executeUpdate();
|
||||
stm3.clearParameters();
|
||||
con.commit(); // flush
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while saving offline trader: " + pc.getObjectId() + " " + e, e);
|
||||
}
|
||||
}
|
||||
LOGGER.info(getClass().getSimpleName() + ": Offline traders stored.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while saving offline traders: " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreOfflineTraders()
|
||||
{
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loading offline traders...");
|
||||
int nTraders = 0;
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement stm = con.createStatement();
|
||||
ResultSet rs = stm.executeQuery(LOAD_OFFLINE_STATUS))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final long time = rs.getLong("time");
|
||||
if (Config.OFFLINE_MAX_DAYS > 0)
|
||||
{
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(time);
|
||||
cal.add(Calendar.DAY_OF_YEAR, Config.OFFLINE_MAX_DAYS);
|
||||
if (cal.getTimeInMillis() <= System.currentTimeMillis())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
final PrivateStoreType type = PrivateStoreType.findById(rs.getInt("type"));
|
||||
if (type == null)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": PrivateStoreType with id " + rs.getInt("type") + " could not be found.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type == PrivateStoreType.NONE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
L2PcInstance player = null;
|
||||
|
||||
try
|
||||
{
|
||||
final L2GameClient client = new L2GameClient(null);
|
||||
client.setDetached(true);
|
||||
player = L2PcInstance.load(rs.getInt("charId"));
|
||||
client.setActiveChar(player);
|
||||
player.setOnlineStatus(true, false);
|
||||
client.setAccountName(player.getAccountNamePlayer());
|
||||
L2World.getInstance().addPlayerToWorld(player);
|
||||
client.setState(GameClientState.IN_GAME);
|
||||
player.setClient(client);
|
||||
player.setOfflineStartTime(time);
|
||||
player.spawnMe(player.getX(), player.getY(), player.getZ());
|
||||
LoginServerThread.getInstance().addGameServerLogin(player.getAccountName(), client);
|
||||
try (PreparedStatement stm_items = con.prepareStatement(LOAD_OFFLINE_ITEMS))
|
||||
{
|
||||
stm_items.setInt(1, player.getObjectId());
|
||||
try (ResultSet items = stm_items.executeQuery())
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case BUY:
|
||||
{
|
||||
while (items.next())
|
||||
{
|
||||
if (player.getBuyList().addItemByItemId(items.getInt(2), items.getLong(3), items.getLong(4), 0, 0, 0, new int[]
|
||||
{
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
}, 0) == null)
|
||||
{
|
||||
continue;
|
||||
// throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
player.getBuyList().setTitle(rs.getString("title"));
|
||||
break;
|
||||
}
|
||||
case SELL:
|
||||
case PACKAGE_SELL:
|
||||
{
|
||||
while (items.next())
|
||||
{
|
||||
if (player.getSellList().addItem(items.getInt(2), items.getLong(3), items.getLong(4)) == null)
|
||||
{
|
||||
continue;
|
||||
// throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
player.getSellList().setTitle(rs.getString("title"));
|
||||
player.getSellList().setPackaged(type == PrivateStoreType.PACKAGE_SELL);
|
||||
break;
|
||||
}
|
||||
case MANUFACTURE:
|
||||
{
|
||||
while (items.next())
|
||||
{
|
||||
player.getManufactureItems().put(items.getInt(2), new L2ManufactureItem(items.getInt(2), items.getLong(4)));
|
||||
}
|
||||
player.setStoreName(rs.getString("title"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
player.sitDown();
|
||||
if (Config.OFFLINE_SET_NAME_COLOR)
|
||||
{
|
||||
player.getAppearance().setNameColor(Config.OFFLINE_NAME_COLOR);
|
||||
}
|
||||
player.setPrivateStoreType(type);
|
||||
player.setOnlineStatus(true, true);
|
||||
player.restoreEffects();
|
||||
player.broadcastUserInfo();
|
||||
nTraders++;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading trader: " + player, e);
|
||||
if (player != null)
|
||||
{
|
||||
player.deleteMe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded: " + nTraders + " offline trader(s)");
|
||||
|
||||
if (!Config.STORE_OFFLINE_TRADE_IN_REALTIME)
|
||||
{
|
||||
try (Statement stm1 = con.createStatement())
|
||||
{
|
||||
stm1.execute(CLEAR_OFFLINE_TABLE);
|
||||
stm1.execute(CLEAR_OFFLINE_TABLE_ITEMS);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while loading offline traders: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void onTransaction(L2PcInstance trader, boolean finished, boolean firstCall)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement stm1 = con.prepareStatement(CLEAR_OFFLINE_TABLE_ITEMS_PLAYER);
|
||||
PreparedStatement stm2 = con.prepareStatement(CLEAR_OFFLINE_TABLE_PLAYER);
|
||||
PreparedStatement stm3 = con.prepareStatement(SAVE_ITEMS);
|
||||
PreparedStatement stm4 = con.prepareStatement(SAVE_OFFLINE_STATUS))
|
||||
{
|
||||
String title = null;
|
||||
|
||||
stm1.setInt(1, trader.getObjectId()); // Char Id
|
||||
stm1.execute();
|
||||
stm1.close();
|
||||
|
||||
// Trade is done - clear info
|
||||
if (finished)
|
||||
{
|
||||
stm2.setInt(1, trader.getObjectId()); // Char Id
|
||||
stm2.execute();
|
||||
stm2.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((trader.getClient() == null) || trader.getClient().isDetached())
|
||||
{
|
||||
switch (trader.getPrivateStoreType())
|
||||
{
|
||||
case BUY:
|
||||
{
|
||||
if (firstCall)
|
||||
{
|
||||
title = trader.getBuyList().getTitle();
|
||||
}
|
||||
for (TradeItem i : trader.getBuyList().getItems())
|
||||
{
|
||||
stm3.setInt(1, trader.getObjectId());
|
||||
stm3.setInt(2, i.getItem().getId());
|
||||
stm3.setLong(3, i.getCount());
|
||||
stm3.setLong(4, i.getPrice());
|
||||
stm3.executeUpdate();
|
||||
stm3.clearParameters();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SELL:
|
||||
case PACKAGE_SELL:
|
||||
{
|
||||
if (firstCall)
|
||||
{
|
||||
title = trader.getSellList().getTitle();
|
||||
}
|
||||
for (TradeItem i : trader.getSellList().getItems())
|
||||
{
|
||||
stm3.setInt(1, trader.getObjectId());
|
||||
stm3.setInt(2, i.getObjectId());
|
||||
stm3.setLong(3, i.getCount());
|
||||
stm3.setLong(4, i.getPrice());
|
||||
stm3.executeUpdate();
|
||||
stm3.clearParameters();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MANUFACTURE:
|
||||
{
|
||||
if (firstCall)
|
||||
{
|
||||
title = trader.getStoreName();
|
||||
}
|
||||
for (L2ManufactureItem i : trader.getManufactureItems().values())
|
||||
{
|
||||
stm3.setInt(1, trader.getObjectId());
|
||||
stm3.setInt(2, i.getRecipeId());
|
||||
stm3.setLong(3, 0);
|
||||
stm3.setLong(4, i.getCost());
|
||||
stm3.executeUpdate();
|
||||
stm3.clearParameters();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
stm3.close();
|
||||
if (firstCall)
|
||||
{
|
||||
stm4.setInt(1, trader.getObjectId()); // Char Id
|
||||
stm4.setLong(2, trader.getOfflineStartTime());
|
||||
stm4.setInt(3, trader.getPrivateStoreType().getId()); // store type
|
||||
stm4.setString(4, title);
|
||||
stm4.executeUpdate();
|
||||
stm4.clearParameters();
|
||||
stm4.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "OfflineTradersTable[storeTradeItems()]: Error while saving offline trader: " + trader.getObjectId() + " " + e, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "OfflineTradersTable[storeTradeItems()]: Error while saving offline traders: " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the single instance of OfflineTradersTable.
|
||||
* @return single instance of OfflineTradersTable
|
||||
*/
|
||||
public static OfflineTradersTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final OfflineTradersTable _instance = new OfflineTradersTable();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Calendar;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.LoginServerThread;
|
||||
import com.l2jmobius.gameserver.enums.PrivateStoreType;
|
||||
import com.l2jmobius.gameserver.model.L2ManufactureItem;
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.TradeItem;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.holders.SellBuffHolder;
|
||||
import com.l2jmobius.gameserver.network.client.ConnectionState;
|
||||
import com.l2jmobius.gameserver.network.client.L2GameClient;
|
||||
|
||||
public class OfflineTradersTable
|
||||
{
|
||||
private static Logger LOGGER = Logger.getLogger(OfflineTradersTable.class.getName());
|
||||
|
||||
// SQL DEFINITIONS
|
||||
private static final String SAVE_OFFLINE_STATUS = "INSERT INTO character_offline_trade (`charId`,`time`,`type`,`title`) VALUES (?,?,?,?)";
|
||||
private static final String SAVE_ITEMS = "INSERT INTO character_offline_trade_items (`charId`,`item`,`count`,`price`) VALUES (?,?,?,?)";
|
||||
private static final String CLEAR_OFFLINE_TABLE = "DELETE FROM character_offline_trade";
|
||||
private static final String CLEAR_OFFLINE_TABLE_PLAYER = "DELETE FROM character_offline_trade WHERE `charId`=?";
|
||||
private static final String CLEAR_OFFLINE_TABLE_ITEMS = "DELETE FROM character_offline_trade_items";
|
||||
private static final String CLEAR_OFFLINE_TABLE_ITEMS_PLAYER = "DELETE FROM character_offline_trade_items WHERE `charId`=?";
|
||||
private static final String LOAD_OFFLINE_STATUS = "SELECT * FROM character_offline_trade";
|
||||
private static final String LOAD_OFFLINE_ITEMS = "SELECT * FROM character_offline_trade_items WHERE `charId`=?";
|
||||
|
||||
public void storeOffliners()
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement stm1 = con.prepareStatement(CLEAR_OFFLINE_TABLE);
|
||||
PreparedStatement stm2 = con.prepareStatement(CLEAR_OFFLINE_TABLE_ITEMS);
|
||||
PreparedStatement stm3 = con.prepareStatement(SAVE_OFFLINE_STATUS);
|
||||
PreparedStatement stm_items = con.prepareStatement(SAVE_ITEMS))
|
||||
{
|
||||
stm1.execute();
|
||||
stm2.execute();
|
||||
con.setAutoCommit(false); // avoid halfway done
|
||||
|
||||
for (L2PcInstance pc : L2World.getInstance().getPlayers())
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((pc.getPrivateStoreType() != PrivateStoreType.NONE) && ((pc.getClient() == null) || pc.getClient().isDetached()))
|
||||
{
|
||||
stm3.setInt(1, pc.getObjectId()); // Char Id
|
||||
stm3.setLong(2, pc.getOfflineStartTime());
|
||||
stm3.setInt(3, pc.isSellingBuffs() ? 9 : pc.getPrivateStoreType().getId()); // store type
|
||||
String title = null;
|
||||
|
||||
switch (pc.getPrivateStoreType())
|
||||
{
|
||||
case BUY:
|
||||
{
|
||||
if (!Config.OFFLINE_TRADE_ENABLE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
title = pc.getBuyList().getTitle();
|
||||
for (TradeItem i : pc.getBuyList().getItems())
|
||||
{
|
||||
stm_items.setInt(1, pc.getObjectId());
|
||||
stm_items.setInt(2, i.getItem().getId());
|
||||
stm_items.setLong(3, i.getCount());
|
||||
stm_items.setLong(4, i.getPrice());
|
||||
stm_items.executeUpdate();
|
||||
stm_items.clearParameters();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SELL:
|
||||
case PACKAGE_SELL:
|
||||
{
|
||||
if (!Config.OFFLINE_TRADE_ENABLE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
title = pc.getSellList().getTitle();
|
||||
if (pc.isSellingBuffs())
|
||||
{
|
||||
for (SellBuffHolder holder : pc.getSellingBuffs())
|
||||
{
|
||||
stm_items.setInt(1, pc.getObjectId());
|
||||
stm_items.setInt(2, holder.getSkillId());
|
||||
stm_items.setLong(3, 0);
|
||||
stm_items.setLong(4, holder.getPrice());
|
||||
stm_items.executeUpdate();
|
||||
stm_items.clearParameters();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (TradeItem i : pc.getSellList().getItems())
|
||||
{
|
||||
stm_items.setInt(1, pc.getObjectId());
|
||||
stm_items.setInt(2, i.getObjectId());
|
||||
stm_items.setLong(3, i.getCount());
|
||||
stm_items.setLong(4, i.getPrice());
|
||||
stm_items.executeUpdate();
|
||||
stm_items.clearParameters();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MANUFACTURE:
|
||||
{
|
||||
if (!Config.OFFLINE_CRAFT_ENABLE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
title = pc.getStoreName();
|
||||
for (L2ManufactureItem i : pc.getManufactureItems().values())
|
||||
{
|
||||
stm_items.setInt(1, pc.getObjectId());
|
||||
stm_items.setInt(2, i.getRecipeId());
|
||||
stm_items.setLong(3, 0);
|
||||
stm_items.setLong(4, i.getCost());
|
||||
stm_items.executeUpdate();
|
||||
stm_items.clearParameters();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
stm3.setString(4, title);
|
||||
stm3.executeUpdate();
|
||||
stm3.clearParameters();
|
||||
con.commit(); // flush
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while saving offline trader: " + pc.getObjectId() + " " + e, e);
|
||||
}
|
||||
}
|
||||
LOGGER.info(getClass().getSimpleName() + ": Offline traders stored.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while saving offline traders: " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreOfflineTraders()
|
||||
{
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loading offline traders...");
|
||||
int nTraders = 0;
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement stm = con.createStatement();
|
||||
ResultSet rs = stm.executeQuery(LOAD_OFFLINE_STATUS))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final long time = rs.getLong("time");
|
||||
if (Config.OFFLINE_MAX_DAYS > 0)
|
||||
{
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(time);
|
||||
cal.add(Calendar.DAY_OF_YEAR, Config.OFFLINE_MAX_DAYS);
|
||||
if (cal.getTimeInMillis() <= System.currentTimeMillis())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
final int typeId = rs.getInt("type");
|
||||
boolean isSellBuff = false;
|
||||
|
||||
if (typeId == 9)
|
||||
{
|
||||
isSellBuff = true;
|
||||
}
|
||||
|
||||
final PrivateStoreType type = isSellBuff ? PrivateStoreType.PACKAGE_SELL : PrivateStoreType.findById(typeId);
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": PrivateStoreType with id " + rs.getInt("type") + " could not be found.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type == PrivateStoreType.NONE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
L2PcInstance player = null;
|
||||
|
||||
try
|
||||
{
|
||||
final L2GameClient client = new L2GameClient();
|
||||
client.setDetached(true);
|
||||
player = L2PcInstance.load(rs.getInt("charId"));
|
||||
client.setActiveChar(player);
|
||||
player.setOnlineStatus(true, false);
|
||||
client.setAccountName(player.getAccountNamePlayer());
|
||||
client.setConnectionState(ConnectionState.IN_GAME);
|
||||
player.setClient(client);
|
||||
player.setOfflineStartTime(time);
|
||||
|
||||
if (isSellBuff)
|
||||
{
|
||||
player.setIsSellingBuffs(true);
|
||||
}
|
||||
|
||||
player.spawnMe(player.getX(), player.getY(), player.getZ());
|
||||
LoginServerThread.getInstance().addGameServerLogin(player.getAccountName(), client);
|
||||
try (PreparedStatement stm_items = con.prepareStatement(LOAD_OFFLINE_ITEMS))
|
||||
{
|
||||
stm_items.setInt(1, player.getObjectId());
|
||||
try (ResultSet items = stm_items.executeQuery())
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case BUY:
|
||||
{
|
||||
while (items.next())
|
||||
{
|
||||
if (player.getBuyList().addItemByItemId(items.getInt(2), items.getLong(3), items.getLong(4)) == null)
|
||||
{
|
||||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
player.getBuyList().setTitle(rs.getString("title"));
|
||||
break;
|
||||
}
|
||||
case SELL:
|
||||
case PACKAGE_SELL:
|
||||
{
|
||||
if (player.isSellingBuffs())
|
||||
{
|
||||
while (items.next())
|
||||
{
|
||||
player.getSellingBuffs().add(new SellBuffHolder(items.getInt("item"), items.getLong("price")));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (items.next())
|
||||
{
|
||||
if (player.getSellList().addItem(items.getInt(2), items.getLong(3), items.getLong(4)) == null)
|
||||
{
|
||||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
}
|
||||
player.getSellList().setTitle(rs.getString("title"));
|
||||
player.getSellList().setPackaged(type == PrivateStoreType.PACKAGE_SELL);
|
||||
break;
|
||||
}
|
||||
case MANUFACTURE:
|
||||
{
|
||||
while (items.next())
|
||||
{
|
||||
player.getManufactureItems().put(items.getInt(2), new L2ManufactureItem(items.getInt(2), items.getLong(4)));
|
||||
}
|
||||
player.setStoreName(rs.getString("title"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
player.sitDown();
|
||||
if (Config.OFFLINE_SET_NAME_COLOR)
|
||||
{
|
||||
player.getAppearance().setNameColor(Config.OFFLINE_NAME_COLOR);
|
||||
}
|
||||
player.setPrivateStoreType(type);
|
||||
player.setOnlineStatus(true, true);
|
||||
player.restoreEffects();
|
||||
player.broadcastUserInfo();
|
||||
nTraders++;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading trader: " + player, e);
|
||||
if (player != null)
|
||||
{
|
||||
player.deleteMe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded: " + nTraders + " offline trader(s)");
|
||||
|
||||
if (!Config.STORE_OFFLINE_TRADE_IN_REALTIME)
|
||||
{
|
||||
try (Statement stm1 = con.createStatement())
|
||||
{
|
||||
stm1.execute(CLEAR_OFFLINE_TABLE);
|
||||
stm1.execute(CLEAR_OFFLINE_TABLE_ITEMS);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while loading offline traders: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void onTransaction(L2PcInstance trader, boolean finished, boolean firstCall)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement stm1 = con.prepareStatement(CLEAR_OFFLINE_TABLE_ITEMS_PLAYER);
|
||||
PreparedStatement stm2 = con.prepareStatement(CLEAR_OFFLINE_TABLE_PLAYER);
|
||||
PreparedStatement stm3 = con.prepareStatement(SAVE_ITEMS);
|
||||
PreparedStatement stm4 = con.prepareStatement(SAVE_OFFLINE_STATUS))
|
||||
{
|
||||
String title = null;
|
||||
|
||||
stm1.setInt(1, trader.getObjectId()); // Char Id
|
||||
stm1.execute();
|
||||
stm1.close();
|
||||
|
||||
// Trade is done - clear info
|
||||
if (finished)
|
||||
{
|
||||
stm2.setInt(1, trader.getObjectId()); // Char Id
|
||||
stm2.execute();
|
||||
stm2.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((trader.getClient() == null) || trader.getClient().isDetached())
|
||||
{
|
||||
switch (trader.getPrivateStoreType())
|
||||
{
|
||||
case BUY:
|
||||
{
|
||||
if (firstCall)
|
||||
{
|
||||
title = trader.getBuyList().getTitle();
|
||||
}
|
||||
for (TradeItem i : trader.getBuyList().getItems())
|
||||
{
|
||||
stm3.setInt(1, trader.getObjectId());
|
||||
stm3.setInt(2, i.getItem().getId());
|
||||
stm3.setLong(3, i.getCount());
|
||||
stm3.setLong(4, i.getPrice());
|
||||
stm3.executeUpdate();
|
||||
stm3.clearParameters();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SELL:
|
||||
case PACKAGE_SELL:
|
||||
{
|
||||
if (firstCall)
|
||||
{
|
||||
title = trader.getSellList().getTitle();
|
||||
}
|
||||
for (TradeItem i : trader.getSellList().getItems())
|
||||
{
|
||||
stm3.setInt(1, trader.getObjectId());
|
||||
stm3.setInt(2, i.getObjectId());
|
||||
stm3.setLong(3, i.getCount());
|
||||
stm3.setLong(4, i.getPrice());
|
||||
stm3.executeUpdate();
|
||||
stm3.clearParameters();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MANUFACTURE:
|
||||
{
|
||||
if (firstCall)
|
||||
{
|
||||
title = trader.getStoreName();
|
||||
}
|
||||
for (L2ManufactureItem i : trader.getManufactureItems().values())
|
||||
{
|
||||
stm3.setInt(1, trader.getObjectId());
|
||||
stm3.setInt(2, i.getRecipeId());
|
||||
stm3.setLong(3, 0);
|
||||
stm3.setLong(4, i.getCost());
|
||||
stm3.executeUpdate();
|
||||
stm3.clearParameters();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
stm3.close();
|
||||
if (firstCall)
|
||||
{
|
||||
stm4.setInt(1, trader.getObjectId()); // Char Id
|
||||
stm4.setLong(2, trader.getOfflineStartTime());
|
||||
stm4.setInt(3, trader.getPrivateStoreType().getId()); // store type
|
||||
stm4.setString(4, title);
|
||||
stm4.executeUpdate();
|
||||
stm4.clearParameters();
|
||||
stm4.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "OfflineTradersTable[storeTradeItems()]: Error while saving offline trader: " + trader.getObjectId() + " " + e, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "OfflineTradersTable[storeTradeItems()]: Error while saving offline traders: " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the single instance of OfflineTradersTable.
|
||||
* @return single instance of OfflineTradersTable
|
||||
*/
|
||||
public static OfflineTradersTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final OfflineTradersTable _instance = new OfflineTradersTable();
|
||||
}
|
||||
}
|
||||
|
@ -1,175 +1,92 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.l2jmobius.gameserver.model.actor.L2Summon;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PetInstance;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2ServitorInstance;
|
||||
import com.l2jmobius.gameserver.model.skills.Skill;
|
||||
|
||||
/**
|
||||
* @author Nyaran
|
||||
*/
|
||||
public class SummonEffectsTable
|
||||
{
|
||||
/** Servitors **/
|
||||
// Map tree
|
||||
// -> key: charObjectId, value: classIndex Map
|
||||
// --> key: classIndex, value: servitors Map
|
||||
// ---> key: servitorSkillId, value: Effects list
|
||||
private final Map<Integer, Map<Integer, Map<Integer, Map<Integer, SummonEffect>>>> _servitorEffects = new HashMap<>();
|
||||
/** Pets **/
|
||||
// key: petItemObjectId, value: Effects list
|
||||
private final Map<Integer, Map<Integer, SummonEffect>> _petEffects = new HashMap<>();
|
||||
|
||||
private Map<Integer, Map<Integer, SummonEffect>> getServitorEffects(L2PcInstance owner)
|
||||
{
|
||||
final Map<Integer, Map<Integer, Map<Integer, SummonEffect>>> servitorMap = _servitorEffects.get(owner.getObjectId());
|
||||
return servitorMap == null ? null : servitorMap.get(owner.getClassIndex());
|
||||
}
|
||||
|
||||
private Map<Integer, SummonEffect> getServitorEffects(L2PcInstance owner, int referenceSkill)
|
||||
{
|
||||
return containsOwner(owner) ? getServitorEffects(owner).get(referenceSkill) : null;
|
||||
}
|
||||
|
||||
private boolean containsOwner(L2PcInstance owner)
|
||||
{
|
||||
return _servitorEffects.getOrDefault(owner.getObjectId(), Collections.emptyMap()).containsKey(owner.getClassIndex());
|
||||
}
|
||||
|
||||
private void removeEffects(Map<Integer, SummonEffect> map, int skillId)
|
||||
{
|
||||
if (map != null)
|
||||
{
|
||||
map.remove(skillId);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyEffects(L2Summon summon, Map<Integer, SummonEffect> map)
|
||||
{
|
||||
if (map == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (SummonEffect se : map.values())
|
||||
{
|
||||
if (se != null)
|
||||
{
|
||||
se.getSkill().applyEffects(summon, summon, false, se.getEffectCurTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsSkill(L2PcInstance owner, int referenceSkill)
|
||||
{
|
||||
return containsOwner(owner) && getServitorEffects(owner).containsKey(referenceSkill);
|
||||
}
|
||||
|
||||
public void clearServitorEffects(L2PcInstance owner, int referenceSkill)
|
||||
{
|
||||
if (containsOwner(owner))
|
||||
{
|
||||
getServitorEffects(owner).getOrDefault(referenceSkill, Collections.emptyMap()).clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void addServitorEffect(L2PcInstance owner, int referenceSkill, Skill skill, int effectCurTime)
|
||||
{
|
||||
_servitorEffects.putIfAbsent(owner.getObjectId(), new HashMap<Integer, Map<Integer, Map<Integer, SummonEffect>>>());
|
||||
_servitorEffects.get(owner.getObjectId()).putIfAbsent(owner.getClassIndex(), new HashMap<Integer, Map<Integer, SummonEffect>>());
|
||||
getServitorEffects(owner).putIfAbsent(referenceSkill, new ConcurrentHashMap<Integer, SummonEffect>());
|
||||
getServitorEffects(owner).get(referenceSkill).put(skill.getId(), new SummonEffect(skill, effectCurTime));
|
||||
}
|
||||
|
||||
public void removeServitorEffects(L2PcInstance owner, int referenceSkill, int skillId)
|
||||
{
|
||||
removeEffects(getServitorEffects(owner, referenceSkill), skillId);
|
||||
}
|
||||
|
||||
public void applyServitorEffects(L2ServitorInstance servitor, L2PcInstance owner, int referenceSkill)
|
||||
{
|
||||
applyEffects(servitor, getServitorEffects(owner, referenceSkill));
|
||||
}
|
||||
|
||||
public void addPetEffect(int controlObjectId, Skill skill, int effectCurTime)
|
||||
{
|
||||
_petEffects.computeIfAbsent(controlObjectId, k -> new ConcurrentHashMap<>()).put(skill.getId(), new SummonEffect(skill, effectCurTime));
|
||||
}
|
||||
|
||||
public boolean containsPetId(int controlObjectId)
|
||||
{
|
||||
return _petEffects.containsKey(controlObjectId);
|
||||
}
|
||||
|
||||
public void applyPetEffects(L2PetInstance l2PetInstance, int controlObjectId)
|
||||
{
|
||||
applyEffects(l2PetInstance, _petEffects.get(controlObjectId));
|
||||
}
|
||||
|
||||
public void clearPetEffects(int controlObjectId)
|
||||
{
|
||||
final Map<Integer, SummonEffect> effects = _petEffects.get(controlObjectId);
|
||||
if (effects != null)
|
||||
{
|
||||
effects.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void removePetEffects(int controlObjectId, int skillId)
|
||||
{
|
||||
removeEffects(_petEffects.get(controlObjectId), skillId);
|
||||
}
|
||||
|
||||
private class SummonEffect
|
||||
{
|
||||
Skill _skill;
|
||||
int _effectCurTime;
|
||||
|
||||
public SummonEffect(Skill skill, int effectCurTime)
|
||||
{
|
||||
_skill = skill;
|
||||
_effectCurTime = effectCurTime;
|
||||
}
|
||||
|
||||
public Skill getSkill()
|
||||
{
|
||||
return _skill;
|
||||
}
|
||||
|
||||
public int getEffectCurTime()
|
||||
{
|
||||
return _effectCurTime;
|
||||
}
|
||||
}
|
||||
|
||||
public static SummonEffectsTable getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final SummonEffectsTable INSTANCE = new SummonEffectsTable();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.skills.Skill;
|
||||
|
||||
/**
|
||||
* @author Nyaran
|
||||
*/
|
||||
public class SummonEffectsTable
|
||||
{
|
||||
/** Servitors **/
|
||||
// Map tree
|
||||
// -> key: charObjectId, value: classIndex Map
|
||||
// --> key: classIndex, value: servitors Map
|
||||
// ---> key: servitorSkillId, value: Effects list
|
||||
private final Map<Integer, Map<Integer, Map<Integer, List<SummonEffect>>>> _servitorEffects = new HashMap<>();
|
||||
|
||||
public Map<Integer, Map<Integer, Map<Integer, List<SummonEffect>>>> getServitorEffectsOwner()
|
||||
{
|
||||
return _servitorEffects;
|
||||
}
|
||||
|
||||
public Map<Integer, List<SummonEffect>> getServitorEffects(L2PcInstance owner)
|
||||
{
|
||||
final Map<Integer, Map<Integer, List<SummonEffect>>> servitorMap = _servitorEffects.get(owner.getObjectId());
|
||||
if (servitorMap == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return servitorMap.get(owner.getClassIndex());
|
||||
}
|
||||
|
||||
/** Pets **/
|
||||
private final Map<Integer, List<SummonEffect>> _petEffects = new HashMap<>(); // key: petItemObjectId, value: Effects list
|
||||
|
||||
public Map<Integer, List<SummonEffect>> getPetEffects()
|
||||
{
|
||||
return _petEffects;
|
||||
}
|
||||
|
||||
public static class SummonEffect
|
||||
{
|
||||
Skill _skill;
|
||||
int _effectCurTime;
|
||||
|
||||
public SummonEffect(Skill skill, int effectCurTime)
|
||||
{
|
||||
_skill = skill;
|
||||
_effectCurTime = effectCurTime;
|
||||
}
|
||||
|
||||
public Skill getSkill()
|
||||
{
|
||||
return _skill;
|
||||
}
|
||||
|
||||
public int getEffectCurTime()
|
||||
{
|
||||
return _effectCurTime;
|
||||
}
|
||||
}
|
||||
|
||||
public static SummonEffectsTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final SummonEffectsTable _instance = new SummonEffectsTable();
|
||||
}
|
||||
}
|
||||
|
@ -1,179 +1,179 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.datatables.SkillData;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Summon;
|
||||
|
||||
public class SummonSkillsTable
|
||||
{
|
||||
private static Logger LOGGER = Logger.getLogger(SummonSkillsTable.class.getName());
|
||||
private final Map<Integer, Map<Integer, L2PetSkillLearn>> _skillTrees = new HashMap<>();
|
||||
|
||||
protected SummonSkillsTable()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
_skillTrees.clear();
|
||||
int count = 0;
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery("SELECT templateId, minLvl, skillId, skillLvl FROM pets_skills"))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final int npcId = rs.getInt("templateId");
|
||||
Map<Integer, L2PetSkillLearn> skillTree = _skillTrees.get(npcId);
|
||||
if (skillTree == null)
|
||||
{
|
||||
skillTree = new HashMap<>();
|
||||
_skillTrees.put(npcId, skillTree);
|
||||
}
|
||||
|
||||
final int id = rs.getInt("skillId");
|
||||
final int lvl = rs.getInt("skillLvl");
|
||||
skillTree.put(SkillData.getSkillHashCode(id, lvl + 1), new L2PetSkillLearn(id, lvl, rs.getInt("minLvl")));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, getClass().getSimpleName() + ": Error while loading pet skill tree:", e);
|
||||
}
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + count + " skills.");
|
||||
}
|
||||
|
||||
public int getAvailableLevel(L2Summon cha, int skillId)
|
||||
{
|
||||
int lvl = 0;
|
||||
if (!_skillTrees.containsKey(cha.getId()))
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Pet id " + cha.getId() + " does not have any skills assigned.");
|
||||
return lvl;
|
||||
}
|
||||
final Collection<L2PetSkillLearn> skills = _skillTrees.get(cha.getId()).values();
|
||||
for (L2PetSkillLearn temp : skills)
|
||||
{
|
||||
if (temp.getId() != skillId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (temp.getLevel() == 0)
|
||||
{
|
||||
if (cha.getLevel() < 70)
|
||||
{
|
||||
lvl = cha.getLevel() / 10;
|
||||
if (lvl <= 0)
|
||||
{
|
||||
lvl = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lvl = 7 + ((cha.getLevel() - 70) / 5);
|
||||
}
|
||||
|
||||
// formula usable for skill that have 10 or more skill levels
|
||||
final int maxLvl = SkillData.getInstance().getMaxLevel(temp.getId());
|
||||
if (lvl > maxLvl)
|
||||
{
|
||||
lvl = maxLvl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((temp.getMinLevel() <= cha.getLevel()) && (temp.getLevel() > lvl))
|
||||
{
|
||||
lvl = temp.getLevel();
|
||||
}
|
||||
}
|
||||
return lvl;
|
||||
}
|
||||
|
||||
public List<Integer> getAvailableSkills(L2Summon cha)
|
||||
{
|
||||
final List<Integer> skillIds = new ArrayList<>();
|
||||
if (!_skillTrees.containsKey(cha.getId()))
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Pet id " + cha.getId() + " does not have any skills assigned.");
|
||||
return skillIds;
|
||||
}
|
||||
final Collection<L2PetSkillLearn> skills = _skillTrees.get(cha.getId()).values();
|
||||
for (L2PetSkillLearn temp : skills)
|
||||
{
|
||||
if (skillIds.contains(temp.getId()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
skillIds.add(temp.getId());
|
||||
}
|
||||
return skillIds;
|
||||
}
|
||||
|
||||
public static final class L2PetSkillLearn
|
||||
{
|
||||
private final int _id;
|
||||
private final int _level;
|
||||
private final int _minLevel;
|
||||
|
||||
public L2PetSkillLearn(int id, int lvl, int minLvl)
|
||||
{
|
||||
_id = id;
|
||||
_level = lvl;
|
||||
_minLevel = minLvl;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public int getLevel()
|
||||
{
|
||||
return _level;
|
||||
}
|
||||
|
||||
public int getMinLevel()
|
||||
{
|
||||
return _minLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public static SummonSkillsTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final SummonSkillsTable _instance = new SummonSkillsTable();
|
||||
}
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.SkillData;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Summon;
|
||||
|
||||
public class SummonSkillsTable
|
||||
{
|
||||
private static Logger LOGGER = Logger.getLogger(SummonSkillsTable.class.getName());
|
||||
private final Map<Integer, Map<Integer, L2PetSkillLearn>> _skillTrees = new HashMap<>();
|
||||
|
||||
protected SummonSkillsTable()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
_skillTrees.clear();
|
||||
int count = 0;
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery("SELECT templateId, minLvl, skillId, skillLvl FROM pets_skills"))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final int npcId = rs.getInt("templateId");
|
||||
Map<Integer, L2PetSkillLearn> skillTree = _skillTrees.get(npcId);
|
||||
if (skillTree == null)
|
||||
{
|
||||
skillTree = new HashMap<>();
|
||||
_skillTrees.put(npcId, skillTree);
|
||||
}
|
||||
|
||||
final int id = rs.getInt("skillId");
|
||||
final int lvl = rs.getInt("skillLvl");
|
||||
skillTree.put(SkillData.getSkillHashCode(id, lvl + 1), new L2PetSkillLearn(id, lvl, rs.getInt("minLvl")));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, getClass().getSimpleName() + ": Error while loading pet skill tree:", e);
|
||||
}
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + count + " skills.");
|
||||
}
|
||||
|
||||
public int getAvailableLevel(L2Summon cha, int skillId)
|
||||
{
|
||||
int lvl = 0;
|
||||
if (!_skillTrees.containsKey(cha.getId()))
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Pet id " + cha.getId() + " does not have any skills assigned.");
|
||||
return lvl;
|
||||
}
|
||||
final Collection<L2PetSkillLearn> skills = _skillTrees.get(cha.getId()).values();
|
||||
for (L2PetSkillLearn temp : skills)
|
||||
{
|
||||
if (temp.getId() != skillId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (temp.getLevel() == 0)
|
||||
{
|
||||
if (cha.getLevel() < 70)
|
||||
{
|
||||
lvl = cha.getLevel() / 10;
|
||||
if (lvl <= 0)
|
||||
{
|
||||
lvl = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lvl = 7 + ((cha.getLevel() - 70) / 5);
|
||||
}
|
||||
|
||||
// formula usable for skill that have 10 or more skill levels
|
||||
final int maxLvl = SkillData.getInstance().getMaxLevel(temp.getId());
|
||||
if (lvl > maxLvl)
|
||||
{
|
||||
lvl = maxLvl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((temp.getMinLevel() <= cha.getLevel()) && (temp.getLevel() > lvl))
|
||||
{
|
||||
lvl = temp.getLevel();
|
||||
}
|
||||
}
|
||||
return lvl;
|
||||
}
|
||||
|
||||
public List<Integer> getAvailableSkills(L2Summon cha)
|
||||
{
|
||||
final List<Integer> skillIds = new ArrayList<>();
|
||||
if (!_skillTrees.containsKey(cha.getId()))
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Pet id " + cha.getId() + " does not have any skills assigned.");
|
||||
return skillIds;
|
||||
}
|
||||
final Collection<L2PetSkillLearn> skills = _skillTrees.get(cha.getId()).values();
|
||||
for (L2PetSkillLearn temp : skills)
|
||||
{
|
||||
if (skillIds.contains(temp.getId()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
skillIds.add(temp.getId());
|
||||
}
|
||||
return skillIds;
|
||||
}
|
||||
|
||||
public static final class L2PetSkillLearn
|
||||
{
|
||||
private final int _id;
|
||||
private final int _level;
|
||||
private final int _minLevel;
|
||||
|
||||
public L2PetSkillLearn(int id, int lvl, int minLvl)
|
||||
{
|
||||
_id = id;
|
||||
_level = lvl;
|
||||
_minLevel = minLvl;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public int getLevel()
|
||||
{
|
||||
return _level;
|
||||
}
|
||||
|
||||
public int getMinLevel()
|
||||
{
|
||||
return _minLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public static SummonSkillsTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final SummonSkillsTable _instance = new SummonSkillsTable();
|
||||
}
|
||||
}
|
@ -1,125 +1,123 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.model.L2TeleportLocation;
|
||||
|
||||
public class TeleportLocationTable
|
||||
{
|
||||
private static Logger LOGGER = Logger.getLogger(TeleportLocationTable.class.getName());
|
||||
|
||||
private final Map<Integer, L2TeleportLocation> _teleports = new HashMap<>();
|
||||
|
||||
protected TeleportLocationTable()
|
||||
{
|
||||
reloadAll();
|
||||
}
|
||||
|
||||
public void reloadAll()
|
||||
{
|
||||
_teleports.clear();
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery("SELECT id, loc_x, loc_y, loc_z, price, fornoble, itemId FROM teleport"))
|
||||
{
|
||||
L2TeleportLocation teleport;
|
||||
while (rs.next())
|
||||
{
|
||||
teleport = new L2TeleportLocation();
|
||||
|
||||
teleport.setTeleId(rs.getInt("id"));
|
||||
teleport.setLocX(rs.getInt("loc_x"));
|
||||
teleport.setLocY(rs.getInt("loc_y"));
|
||||
teleport.setLocZ(rs.getInt("loc_z"));
|
||||
teleport.setPrice(rs.getInt("price"));
|
||||
teleport.setIsForNoble(rs.getInt("fornoble") == 1);
|
||||
teleport.setItemId(rs.getInt("itemId"));
|
||||
|
||||
_teleports.put(teleport.getTeleId(), teleport);
|
||||
}
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _teleports.size() + " Teleport Location Templates.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, getClass().getSimpleName() + ": Error loading Teleport Table.", e);
|
||||
}
|
||||
|
||||
if (!Config.CUSTOM_TELEPORT_TABLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int _cTeleCount = _teleports.size();
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery("SELECT id, loc_x, loc_y, loc_z, price, fornoble, itemId FROM custom_teleport"))
|
||||
{
|
||||
L2TeleportLocation teleport;
|
||||
while (rs.next())
|
||||
{
|
||||
teleport = new L2TeleportLocation();
|
||||
teleport.setTeleId(rs.getInt("id"));
|
||||
teleport.setLocX(rs.getInt("loc_x"));
|
||||
teleport.setLocY(rs.getInt("loc_y"));
|
||||
teleport.setLocZ(rs.getInt("loc_z"));
|
||||
teleport.setPrice(rs.getInt("price"));
|
||||
teleport.setIsForNoble(rs.getInt("fornoble") == 1);
|
||||
teleport.setItemId(rs.getInt("itemId"));
|
||||
|
||||
_teleports.put(teleport.getTeleId(), teleport);
|
||||
}
|
||||
_cTeleCount = _teleports.size() - _cTeleCount;
|
||||
if (_cTeleCount > 0)
|
||||
{
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _cTeleCount + " Custom Teleport Location Templates.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while creating custom teleport table " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public L2TeleportLocation getTemplate(int id)
|
||||
{
|
||||
return _teleports.get(id);
|
||||
}
|
||||
|
||||
public static TeleportLocationTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final TeleportLocationTable _instance = new TeleportLocationTable();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.model.L2TeleportLocation;
|
||||
|
||||
public class TeleportLocationTable
|
||||
{
|
||||
private static Logger LOGGER = Logger.getLogger(TeleportLocationTable.class.getName());
|
||||
|
||||
private final Map<Integer, L2TeleportLocation> _teleports = new HashMap<>();
|
||||
|
||||
protected TeleportLocationTable()
|
||||
{
|
||||
reloadAll();
|
||||
}
|
||||
|
||||
public void reloadAll()
|
||||
{
|
||||
_teleports.clear();
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery("SELECT id, loc_x, loc_y, loc_z, price, fornoble, itemId FROM teleport"))
|
||||
{
|
||||
L2TeleportLocation teleport;
|
||||
while (rs.next())
|
||||
{
|
||||
teleport = new L2TeleportLocation();
|
||||
|
||||
teleport.setTeleId(rs.getInt("id"));
|
||||
teleport.setLocX(rs.getInt("loc_x"));
|
||||
teleport.setLocY(rs.getInt("loc_y"));
|
||||
teleport.setLocZ(rs.getInt("loc_z"));
|
||||
teleport.setPrice(rs.getInt("price"));
|
||||
teleport.setIsForNoble(rs.getInt("fornoble") == 1);
|
||||
teleport.setItemId(rs.getInt("itemId"));
|
||||
|
||||
_teleports.put(teleport.getTeleId(), teleport);
|
||||
}
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _teleports.size() + " Teleport Location Templates.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, getClass().getSimpleName() + ": Error loading Teleport Table.", e);
|
||||
}
|
||||
|
||||
if (Config.CUSTOM_TELEPORT_TABLE)
|
||||
{
|
||||
int cTeleCount = _teleports.size();
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery("SELECT id, loc_x, loc_y, loc_z, price, fornoble, itemId FROM custom_teleport"))
|
||||
{
|
||||
L2TeleportLocation teleport;
|
||||
while (rs.next())
|
||||
{
|
||||
teleport = new L2TeleportLocation();
|
||||
teleport.setTeleId(rs.getInt("id"));
|
||||
teleport.setLocX(rs.getInt("loc_x"));
|
||||
teleport.setLocY(rs.getInt("loc_y"));
|
||||
teleport.setLocZ(rs.getInt("loc_z"));
|
||||
teleport.setPrice(rs.getInt("price"));
|
||||
teleport.setIsForNoble(rs.getInt("fornoble") == 1);
|
||||
teleport.setItemId(rs.getInt("itemId"));
|
||||
|
||||
_teleports.put(teleport.getTeleId(), teleport);
|
||||
}
|
||||
cTeleCount = _teleports.size() - cTeleCount;
|
||||
if (cTeleCount > 0)
|
||||
{
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + cTeleCount + " Custom Teleport Location Templates.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while creating custom teleport table " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public L2TeleportLocation getTemplate(int id)
|
||||
{
|
||||
return _teleports.get(id);
|
||||
}
|
||||
|
||||
public static TeleportLocationTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final TeleportLocationTable _instance = new TeleportLocationTable();
|
||||
}
|
||||
}
|
||||
|
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.data.sql.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.model.L2Territory;
|
||||
import com.l2jmobius.gameserver.model.Location;
|
||||
|
||||
/**
|
||||
* @author Balancer, Mr
|
||||
*/
|
||||
public class TerritoryTable
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(TerritoryTable.class.getName());
|
||||
|
||||
private static final Map<Integer, L2Territory> _territory = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new territory.
|
||||
*/
|
||||
protected TerritoryTable()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the random point.
|
||||
* @param terr the territory Id?
|
||||
* @return the random point
|
||||
*/
|
||||
public Location getRandomPoint(int terr)
|
||||
{
|
||||
return _territory.get(terr).getRandomPoint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the proc max.
|
||||
* @param terr the territory Id?
|
||||
* @return the proc max
|
||||
*/
|
||||
public int getProcMax(int terr)
|
||||
{
|
||||
return _territory.get(terr).getProcMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the data from database.
|
||||
*/
|
||||
public void load()
|
||||
{
|
||||
_territory.clear();
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rset = stmt.executeQuery("SELECT * FROM locations WHERE loc_id>0"))
|
||||
{
|
||||
while (rset.next())
|
||||
{
|
||||
final int terrId = rset.getInt("loc_id");
|
||||
L2Territory terr = _territory.get(terrId);
|
||||
if (terr == null)
|
||||
{
|
||||
terr = new L2Territory(terrId);
|
||||
_territory.put(terrId, terr);
|
||||
}
|
||||
terr.add(rset.getInt("loc_x"), rset.getInt("loc_y"), rset.getInt("loc_zmin"), rset.getInt("loc_zmax"), rset.getInt("proc"));
|
||||
}
|
||||
LOGGER.info("TerritoryTable: Loaded " + _territory.size() + " territories from database.");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, "TerritoryTable: Failed to load territories from database!", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the single instance of Territory.
|
||||
* @return single instance of Territory
|
||||
*/
|
||||
public static TerritoryTable getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final TerritoryTable _instance = new TerritoryTable();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user