*/
public static L2Player restore(final int objectId)
{
L2Player player = null;
ThreadConnection con = null;
FiltredStatement statement = null;
FiltredStatement statement2 = null;
ResultSet pl_rset = null;
ResultSet ps_rset = null;
try
{
// Retrieve the L2Player from the characters table of the database
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.createStatement();
statement2 = con.createStatement();
pl_rset = statement.executeQuery("SELECT * FROM `characters` WHERE `obj_Id`=" + objectId + " LIMIT 1");
ps_rset = statement2.executeQuery("SELECT `class_id` FROM `character_subclasses` WHERE `char_obj_id`=" + objectId + " AND `isBase`=1 LIMIT 1");
if(pl_rset.next() && ps_rset.next())
{
final int classId = ps_rset.getInt("class_id");
final boolean female = pl_rset.getInt("sex") == 1;
final L2PlayerTemplate template = CharTemplateTable.getInstance().getTemplate(classId, female);
player = new L2Player(objectId, template);
player.loadVariables();
player.bookmarks.setCapacity(pl_rset.getInt("bookmarks"));
player.setBaseClass(classId);
player._accountName = pl_rset.getString("account_name");
player.setName(pl_rset.getString("char_name"));
player.setFace(pl_rset.getByte("face"));
player.setHairStyle(pl_rset.getByte("hairStyle"));
player.setHairColor(pl_rset.getByte("hairColor"));
player.setHeading(pl_rset.getInt("heading"));
player.setKarma(pl_rset.getInt("karma"));
player.setPvpKills(pl_rset.getInt("pvpkills"));
player.setPkKills(pl_rset.getInt("pkkills"));
player.setLeaveClanTime(pl_rset.getLong("leaveclan") * 1000L);
if(player.getLeaveClanTime() > 0 && player.canJoinClan())
{
player.setLeaveClanTime(0);
}
player.setDeleteClanTime(pl_rset.getLong("deleteclan") * 1000L);
if(player.getDeleteClanTime() > 0 && player.canCreateClan())
{
player.setDeleteClanTime(0);
}
player.setNoChannel(pl_rset.getLong("nochannel") * 1000L);
if(player.getNoChannel() > 0 && player.getNoChannelRemained() < 0)
{
player.updateNoChannel(0);
}
player.setOnlineTime(pl_rset.getLong("onlinetime") * 1000L);
final int clanId = pl_rset.getInt("clanid");
if(clanId > 0)
{
player.setClan(ClanTable.getInstance().getClan(clanId));
player.setPledgeType(pl_rset.getInt("pledge_type"));
player.setPowerGrade(pl_rset.getInt("pledge_rank"));
player.setLvlJoinedAcademy(pl_rset.getInt("lvl_joined_academy"));
player.setApprentice(pl_rset.getInt("apprentice"));
}
player.setCreateTime(pl_rset.getLong("createtime") * 1000L);
player.setDeleteTimer(pl_rset.getInt("deletetime"));
player.setTitle(pl_rset.getString("title"));
if(player.getVar("namecolor") == null)
{
if(player.isGM())
{
player.setNameColor(Config.GM_NAME_COLOUR);
}
else if(player.getClan() != null && player.getClan().getLeaderId() == player.getObjectId())
{
player.setNameColor(Config.CLANLEADER_NAME_COLOUR);
}
else
{
player.setNameColor(Config.NORMAL_NAME_COLOUR);
}
}
else
{
player.setNameColor(Integer.decode("0x" + player.getVar("namecolor")));
}
if(Config.AUTO_LOOT_INDIVIDUAL)
{
player.AutoLoot = player.getVarB("AutoLoot", Config.AUTO_LOOT);
player.AutoLootHerbs = player.getVarB("AutoLootHerbs", Config.AUTO_LOOT_HERBS);
}
String recomList = player.getVar("recomChars");
if(recomList != null && !recomList.isEmpty())
{
for(String recom : recomList.split(","))
{
if(!recom.isEmpty())
{
player._recomChars.add(Integer.decode("0x" + recom));
}
}
}
player.setFistsWeaponItem(player.findFistsWeaponItem(classId));
player.setUptime(System.currentTimeMillis());
player.setLastAccess(pl_rset.getLong("lastAccess"));
player.setRecomHave(pl_rset.getInt("rec_have"));
player.setRecomLeft(pl_rset.getInt("rec_left"));
player.setKeyBindings(pl_rset.getBytes("key_bindings"));
player.setPcBangPoints(pl_rset.getInt("pcBangPoints"));
player.setFame(pl_rset.getInt("fame"), null);
player.restoreRecipeBook();
if(Config.ENABLE_OLYMPIAD)
{
player.setHero(Hero.getInstance().isHero(player.getObjectId()));
player.setNoble(Olympiad.isNoble(player.getObjectId()));
}
player.updatePledgeClass();
player.updateKetraVarka();
player.updateRam();
// для сервиса виверн - возврат денег если сервер упал во время полета
String wm = player.getVar("wyvern_moneyback");
if(wm != null && Integer.parseInt(wm) > 0)
{
player.addAdena(Integer.parseInt(wm));
}
player.unsetVar("wyvern_moneyback");
long reflection = 0;
// Set the x,y,z position of the L2Player and make it invisible
if(player.getVar("jailed") != null && System.currentTimeMillis() / 1000 < Integer.parseInt(player.getVar("jailed")) + 60)
{
player.setXYZInvisible(-114648, -249384, -2984);
String[] re = player.getVar("jailedFrom").split(";");
Location loc = new Location(Integer.parseInt(re[0]), Integer.parseInt(re[1]), Integer.parseInt(re[2]));
reflection = -3;
player._unjailTask = ThreadPoolManager.getInstance().scheduleGeneral(new TeleportTask(player, loc, re.length > 3 ? Integer.parseInt(re[3]) : 0), Integer.parseInt(player.getVar("jailed")) * 1000L);
}
else
{
player.setXYZInvisible(pl_rset.getInt("x"), pl_rset.getInt("y"), pl_rset.getInt("z"));
wm = player.getVar("reflection");
if(wm != null)
{
reflection = Long.parseLong(wm);
if(reflection > 0)
{
if(!Config.RepairPlayerToInstance || ReflectionTable.getInstance().get(reflection) == null)
{
String back = player.getVar("backCoords");
if(back != null)
{
player.setXYZInvisible(new Location(back));
player.unsetVar("backCoords");
}
reflection = 0;
}
}
}
}
player.setReflection(reflection);
player.restoreTradeList();
if(player.getVar("storemode") != null)
{
if(player.getVar("offline") != null) // оффтрейдеры выбивают других, онтрейдеры нет
{
if(Config.SERVICES_TRADE_ONLY_FAR)
{
L2WorldRegion currentRegion = L2World.getRegion(player.getLoc(), player.getReflectionId());
if(currentRegion != null)
{
GArray<L2WorldRegion> neighbors = currentRegion.getNeighbors();
int size = 0;
for(L2WorldRegion region : neighbors)
{
size += region.getPlayersSize();
}
GArray<L2Player> result = new GArray<L2Player>(size);
for(L2WorldRegion region : neighbors)
{
region.getPlayersList(result, 0, player.getReflection(), player.getX(), player.getY(), player.getZ(), Config.SERVICES_TRADE_RADIUS * Config.SERVICES_TRADE_RADIUS, 200);
}
for(L2Player p : result)
{
if(p.isInStoreMode())
{
if(p.isInOfflineMode())
{
L2TradeList.cancelStore(p);
}
else
{
p.setPrivateStoreType(L2Player.STORE_PRIVATE_NONE);
p.broadcastUserInfo(true);
}
}
}
}
}
player.setPrivateStoreType(Short.parseShort(player.getVar("storemode")));
player.setSitting(true);
}
else
{
short type = Short.parseShort(player.getVar("storemode"));
if(player.checksForShop(type == STORE_PRIVATE_MANUFACTURE))
{
player.setPrivateStoreType(type);
player.setSitting(true);
}
else
{
player.unsetVar("storemode");
}
}
}
if(TerritorySiege.isInProgress())
{
player.setTerritorySiege(TerritorySiege.getTerritoryForPlayer(objectId));
}
Quest.playerEnter(player);
player._hidden = true;
restoreCharSubClasses(player);
player._hidden = false;
// 2 очка в минуту оффлайна, на оффе 4, но там очки вдвое легче
player.setVitality(pl_rset.getInt("vitality") + (int) ((System.currentTimeMillis() / 1000 - pl_rset.getLong("lastAccess")) / 30.));
// 15 секунд после входа в игру на персонажа не агрятся мобы
player.setNonAggroTime(System.currentTimeMillis() + 15000);
try
{
String var = player.getVar("ExpandInventory");
if(var != null)
{
player.setExpandInventory(Integer.parseInt(var));
}
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
String var = player.getVar("ExpandWarehouse");
if(var != null)
{
player.setExpandWarehouse(Integer.parseInt(var));
}
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
String var = player.getVar("notShowBuffAnim");
if(var != null)
{
player.setNotShowBuffAnim(Boolean.parseBoolean(var));
}
}
catch(Exception e)
{
e.printStackTrace();
}
FiltredPreparedStatement stmt = null;
ResultSet chars = null;
try
{
stmt = con.prepareStatement("SELECT obj_Id, char_name FROM characters WHERE account_name=? AND obj_Id!=?");
stmt.setString(1, player._accountName);
stmt.setInt(2, objectId);
chars = stmt.executeQuery();
while(chars.next())
{
final Integer charId = chars.getInt("obj_Id");
final String charName = chars.getString("char_name");
player._chars.put(charId, charName);
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DatabaseUtils.closeDatabaseSR(stmt, chars);
}
if(Config.KILL_COUNTER)
{
// Restore kills stat
FiltredStatement stt = null;
ResultSet rstkills = null;
try
{
stt = con.createStatement();
rstkills = stt.executeQuery("SELECT `npc_id`, `count` FROM `killcount` WHERE `char_id`=" + objectId);
player._StatKills = new HashMap<Integer, Long>(128);
while(rstkills.next())
{
player._StatKills.put(rstkills.getInt("npc_id"), rstkills.getLong("count"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DatabaseUtils.closeDatabaseSR(stt, rstkills);
}
}
//Restore craft stat
if(Config.CRAFT_COUNTER)
{
FiltredStatement stcraft = null;
ResultSet rstcraft = null;
try
{
stcraft = con.createStatement();
rstcraft = stcraft.executeQuery("SELECT `item_id`, `count` FROM `craftcount` WHERE `char_id`=" + objectId);
player._StatCraft = new HashMap<Integer, Long>(32);
while(rstcraft.next())
{
player._StatCraft.put(rstcraft.getInt("item_id"), rstcraft.getLong("count"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DatabaseUtils.closeDatabaseSR(stcraft, rstcraft);
}
}
if(Config.DROP_COUNTER)
{
//Restore drop stat
FiltredStatement stdrop = null;
ResultSet rstdrop = null;
try
{
stdrop = con.createStatement();
rstdrop = stdrop.executeQuery("SELECT `item_id`, `count` FROM `dropcount` WHERE `char_id`=" + objectId);
player._StatDrop = new HashMap<Integer, Long>(128);
while(rstdrop.next())
{
player._StatDrop.put(rstdrop.getInt("item_id"), rstdrop.getLong("count"));
}