Dropped ElementalSpiritInstanceManager class.
This commit is contained in:
parent
6ad50ede46
commit
efa24bed93
@ -1,107 +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 org.l2jmobius.gameserver.instancemanager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||
import org.l2jmobius.gameserver.model.holders.ElementalSpiritDataHolder;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ElementalSpiritInstanceManager
|
||||
{
|
||||
private static final String LOAD_QUERY = "SELECT * FROM character_spirits WHERE charId=?";
|
||||
private static final String STORE_QUERY = "REPLACE INTO character_spirits (charId, type, level, stage, experience, attack_points, defense_points, crit_rate_points, crit_damage_points, in_use) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
public List<ElementalSpiritDataHolder> findByPlayerId(int playerId)
|
||||
{
|
||||
final List<ElementalSpiritDataHolder> result = new ArrayList<>();
|
||||
try (Connection con = DatabaseFactory.getConnection();
|
||||
PreparedStatement stmt = con.prepareStatement(LOAD_QUERY))
|
||||
{
|
||||
stmt.setInt(1, playerId);
|
||||
try (ResultSet rset = stmt.executeQuery())
|
||||
{
|
||||
while (rset.next())
|
||||
{
|
||||
final ElementalSpiritDataHolder newHolder = new ElementalSpiritDataHolder();
|
||||
newHolder.setCharId(rset.getInt("charId"));
|
||||
newHolder.setType(rset.getByte("type"));
|
||||
newHolder.setLevel(rset.getByte("level"));
|
||||
newHolder.setStage(rset.getByte("stage"));
|
||||
newHolder.setExperience(rset.getLong("experience"));
|
||||
newHolder.setAttackPoints(rset.getByte("attack_points"));
|
||||
newHolder.setDefensePoints(rset.getByte("defense_points"));
|
||||
newHolder.setCritRatePoints(rset.getByte("crit_rate_points"));
|
||||
newHolder.setCritDamagePoints(rset.getByte("crit_damage_points"));
|
||||
newHolder.setInUse(rset.getByte("in_use") == 1);
|
||||
result.add(newHolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void save(ElementalSpiritDataHolder data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try (Connection con = DatabaseFactory.getConnection();
|
||||
PreparedStatement statement = con.prepareStatement(STORE_QUERY))
|
||||
{
|
||||
statement.setInt(1, data.getCharId());
|
||||
statement.setInt(2, data.getType());
|
||||
statement.setInt(3, data.getLevel());
|
||||
statement.setInt(4, data.getStage());
|
||||
statement.setLong(5, data.getExperience());
|
||||
statement.setInt(6, data.getAttackPoints());
|
||||
statement.setInt(7, data.getDefensePoints());
|
||||
statement.setInt(8, data.getCritRatePoints());
|
||||
statement.setInt(9, data.getCritDamagePoints());
|
||||
statement.setInt(10, data.isInUse() ? 1 : 0);
|
||||
statement.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static ElementalSpiritInstanceManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final ElementalSpiritInstanceManager INSTANCE = new ElementalSpiritInstanceManager();
|
||||
}
|
||||
}
|
@ -18,12 +18,14 @@ package org.l2jmobius.gameserver.model;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.List;
|
||||
|
||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.ElementalSpiritData;
|
||||
import org.l2jmobius.gameserver.enums.ElementalType;
|
||||
import org.l2jmobius.gameserver.enums.UserInfoType;
|
||||
import org.l2jmobius.gameserver.instancemanager.ElementalSpiritInstanceManager;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnElementalSpiritUpgrade;
|
||||
@ -42,6 +44,8 @@ import org.l2jmobius.gameserver.network.serverpackets.elementalspirits.ExElement
|
||||
*/
|
||||
public class ElementalSpirit
|
||||
{
|
||||
private static final String STORE_ELEMENTAL_SPIRIT_QUERY = "REPLACE INTO character_spirits (charId, type, level, stage, experience, attack_points, defense_points, crit_rate_points, crit_damage_points, in_use) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
private final PlayerInstance _owner;
|
||||
private ElementalSpiritTemplateHolder _template;
|
||||
private final ElementalSpiritDataHolder _data;
|
||||
@ -235,7 +239,25 @@ public class ElementalSpirit
|
||||
|
||||
public void save()
|
||||
{
|
||||
ElementalSpiritInstanceManager.getInstance().save(_data);
|
||||
try (Connection con = DatabaseFactory.getConnection();
|
||||
PreparedStatement statement = con.prepareStatement(STORE_ELEMENTAL_SPIRIT_QUERY))
|
||||
{
|
||||
statement.setInt(1, _data.getCharId());
|
||||
statement.setInt(2, _data.getType());
|
||||
statement.setInt(3, _data.getLevel());
|
||||
statement.setInt(4, _data.getStage());
|
||||
statement.setLong(5, _data.getExperience());
|
||||
statement.setInt(6, _data.getAttackPoints());
|
||||
statement.setInt(7, _data.getDefensePoints());
|
||||
statement.setInt(8, _data.getCritRatePoints());
|
||||
statement.setInt(9, _data.getCritDamagePoints());
|
||||
statement.setInt(10, _data.isInUse() ? 1 : 0);
|
||||
statement.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void addAttackPoints(byte attackPoints)
|
||||
|
@ -110,7 +110,6 @@ import org.l2jmobius.gameserver.instancemanager.AntiFeedManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.CastleManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.DuelManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.ElementalSpiritInstanceManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.FortManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.FortSiegeManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.GlobalVariablesManager;
|
||||
@ -395,11 +394,14 @@ public final class PlayerInstance extends Playable
|
||||
// Character Shortcut SQL String Definitions:
|
||||
private static final String DELETE_CHAR_SHORTCUTS = "DELETE FROM character_shortcuts WHERE charId=? AND class_index=?";
|
||||
|
||||
// Character Recipe List Save
|
||||
// Character Recipe List Save:
|
||||
private static final String DELETE_CHAR_RECIPE_SHOP = "DELETE FROM character_recipeshoplist WHERE charId=?";
|
||||
private static final String INSERT_CHAR_RECIPE_SHOP = "REPLACE INTO character_recipeshoplist (`charId`, `recipeId`, `price`, `index`) VALUES (?, ?, ?, ?)";
|
||||
private static final String RESTORE_CHAR_RECIPE_SHOP = "SELECT * FROM character_recipeshoplist WHERE charId=? ORDER BY `index`";
|
||||
|
||||
// Elemental Spirits:
|
||||
private static final String RESTORE_ELEMENTAL_SPIRITS = "SELECT * FROM character_spirits WHERE charId=?";
|
||||
|
||||
private static final String COND_OVERRIDE_KEY = "cond_override";
|
||||
|
||||
public static final String NEWBIE_KEY = "NEWBIE";
|
||||
@ -13990,11 +13992,39 @@ public final class PlayerInstance extends Playable
|
||||
|
||||
private void tryLoadSpirits()
|
||||
{
|
||||
final List<ElementalSpiritDataHolder> spiritsData = ElementalSpiritInstanceManager.getInstance().findByPlayerId(getObjectId());
|
||||
if (!spiritsData.isEmpty())
|
||||
final List<ElementalSpiritDataHolder> restoredSpirits = new ArrayList<>();
|
||||
try (Connection con = DatabaseFactory.getConnection();
|
||||
PreparedStatement stmt = con.prepareStatement(RESTORE_ELEMENTAL_SPIRITS))
|
||||
{
|
||||
stmt.setInt(1, getObjectId());
|
||||
try (ResultSet rset = stmt.executeQuery())
|
||||
{
|
||||
while (rset.next())
|
||||
{
|
||||
final ElementalSpiritDataHolder newHolder = new ElementalSpiritDataHolder();
|
||||
newHolder.setCharId(rset.getInt("charId"));
|
||||
newHolder.setType(rset.getByte("type"));
|
||||
newHolder.setLevel(rset.getByte("level"));
|
||||
newHolder.setStage(rset.getByte("stage"));
|
||||
newHolder.setExperience(rset.getLong("experience"));
|
||||
newHolder.setAttackPoints(rset.getByte("attack_points"));
|
||||
newHolder.setDefensePoints(rset.getByte("defense_points"));
|
||||
newHolder.setCritRatePoints(rset.getByte("crit_rate_points"));
|
||||
newHolder.setCritDamagePoints(rset.getByte("crit_damage_points"));
|
||||
newHolder.setInUse(rset.getByte("in_use") == 1);
|
||||
restoredSpirits.add(newHolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!restoredSpirits.isEmpty())
|
||||
{
|
||||
_spirits = new ElementalSpirit[ElementalType.values().length - 1];
|
||||
for (ElementalSpiritDataHolder spiritData : spiritsData)
|
||||
for (ElementalSpiritDataHolder spiritData : restoredSpirits)
|
||||
{
|
||||
_spirits[spiritData.getType() - 1] = new ElementalSpirit(spiritData, this);
|
||||
if (spiritData.isInUse())
|
||||
|
@ -1,107 +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 org.l2jmobius.gameserver.instancemanager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||
import org.l2jmobius.gameserver.model.holders.ElementalSpiritDataHolder;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ElementalSpiritInstanceManager
|
||||
{
|
||||
private static final String LOAD_QUERY = "SELECT * FROM character_spirits WHERE charId=?";
|
||||
private static final String STORE_QUERY = "REPLACE INTO character_spirits (charId, type, level, stage, experience, attack_points, defense_points, crit_rate_points, crit_damage_points, in_use) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
public List<ElementalSpiritDataHolder> findByPlayerId(int playerId)
|
||||
{
|
||||
final List<ElementalSpiritDataHolder> result = new ArrayList<>();
|
||||
try (Connection con = DatabaseFactory.getConnection();
|
||||
PreparedStatement stmt = con.prepareStatement(LOAD_QUERY))
|
||||
{
|
||||
stmt.setInt(1, playerId);
|
||||
try (ResultSet rset = stmt.executeQuery())
|
||||
{
|
||||
while (rset.next())
|
||||
{
|
||||
final ElementalSpiritDataHolder newHolder = new ElementalSpiritDataHolder();
|
||||
newHolder.setCharId(rset.getInt("charId"));
|
||||
newHolder.setType(rset.getByte("type"));
|
||||
newHolder.setLevel(rset.getByte("level"));
|
||||
newHolder.setStage(rset.getByte("stage"));
|
||||
newHolder.setExperience(rset.getLong("experience"));
|
||||
newHolder.setAttackPoints(rset.getByte("attack_points"));
|
||||
newHolder.setDefensePoints(rset.getByte("defense_points"));
|
||||
newHolder.setCritRatePoints(rset.getByte("crit_rate_points"));
|
||||
newHolder.setCritDamagePoints(rset.getByte("crit_damage_points"));
|
||||
newHolder.setInUse(rset.getByte("in_use") == 1);
|
||||
result.add(newHolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void save(ElementalSpiritDataHolder data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try (Connection con = DatabaseFactory.getConnection();
|
||||
PreparedStatement statement = con.prepareStatement(STORE_QUERY))
|
||||
{
|
||||
statement.setInt(1, data.getCharId());
|
||||
statement.setInt(2, data.getType());
|
||||
statement.setInt(3, data.getLevel());
|
||||
statement.setInt(4, data.getStage());
|
||||
statement.setLong(5, data.getExperience());
|
||||
statement.setInt(6, data.getAttackPoints());
|
||||
statement.setInt(7, data.getDefensePoints());
|
||||
statement.setInt(8, data.getCritRatePoints());
|
||||
statement.setInt(9, data.getCritDamagePoints());
|
||||
statement.setInt(10, data.isInUse() ? 1 : 0);
|
||||
statement.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static ElementalSpiritInstanceManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final ElementalSpiritInstanceManager INSTANCE = new ElementalSpiritInstanceManager();
|
||||
}
|
||||
}
|
@ -18,12 +18,14 @@ package org.l2jmobius.gameserver.model;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.List;
|
||||
|
||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.ElementalSpiritData;
|
||||
import org.l2jmobius.gameserver.enums.ElementalType;
|
||||
import org.l2jmobius.gameserver.enums.UserInfoType;
|
||||
import org.l2jmobius.gameserver.instancemanager.ElementalSpiritInstanceManager;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnElementalSpiritUpgrade;
|
||||
@ -42,6 +44,8 @@ import org.l2jmobius.gameserver.network.serverpackets.elementalspirits.ExElement
|
||||
*/
|
||||
public class ElementalSpirit
|
||||
{
|
||||
private static final String STORE_ELEMENTAL_SPIRIT_QUERY = "REPLACE INTO character_spirits (charId, type, level, stage, experience, attack_points, defense_points, crit_rate_points, crit_damage_points, in_use) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
private final PlayerInstance _owner;
|
||||
private ElementalSpiritTemplateHolder _template;
|
||||
private final ElementalSpiritDataHolder _data;
|
||||
@ -235,7 +239,25 @@ public class ElementalSpirit
|
||||
|
||||
public void save()
|
||||
{
|
||||
ElementalSpiritInstanceManager.getInstance().save(_data);
|
||||
try (Connection con = DatabaseFactory.getConnection();
|
||||
PreparedStatement statement = con.prepareStatement(STORE_ELEMENTAL_SPIRIT_QUERY))
|
||||
{
|
||||
statement.setInt(1, _data.getCharId());
|
||||
statement.setInt(2, _data.getType());
|
||||
statement.setInt(3, _data.getLevel());
|
||||
statement.setInt(4, _data.getStage());
|
||||
statement.setLong(5, _data.getExperience());
|
||||
statement.setInt(6, _data.getAttackPoints());
|
||||
statement.setInt(7, _data.getDefensePoints());
|
||||
statement.setInt(8, _data.getCritRatePoints());
|
||||
statement.setInt(9, _data.getCritDamagePoints());
|
||||
statement.setInt(10, _data.isInUse() ? 1 : 0);
|
||||
statement.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void addAttackPoints(byte attackPoints)
|
||||
|
@ -110,7 +110,6 @@ import org.l2jmobius.gameserver.instancemanager.AntiFeedManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.CastleManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.DuelManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.ElementalSpiritInstanceManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.FortManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.FortSiegeManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.GlobalVariablesManager;
|
||||
@ -395,11 +394,14 @@ public final class PlayerInstance extends Playable
|
||||
// Character Shortcut SQL String Definitions:
|
||||
private static final String DELETE_CHAR_SHORTCUTS = "DELETE FROM character_shortcuts WHERE charId=? AND class_index=?";
|
||||
|
||||
// Character Recipe List Save
|
||||
// Character Recipe List Save:
|
||||
private static final String DELETE_CHAR_RECIPE_SHOP = "DELETE FROM character_recipeshoplist WHERE charId=?";
|
||||
private static final String INSERT_CHAR_RECIPE_SHOP = "REPLACE INTO character_recipeshoplist (`charId`, `recipeId`, `price`, `index`) VALUES (?, ?, ?, ?)";
|
||||
private static final String RESTORE_CHAR_RECIPE_SHOP = "SELECT * FROM character_recipeshoplist WHERE charId=? ORDER BY `index`";
|
||||
|
||||
// Elemental Spirits:
|
||||
private static final String RESTORE_ELEMENTAL_SPIRITS = "SELECT * FROM character_spirits WHERE charId=?";
|
||||
|
||||
private static final String COND_OVERRIDE_KEY = "cond_override";
|
||||
|
||||
public static final String NEWBIE_KEY = "NEWBIE";
|
||||
@ -13990,11 +13992,39 @@ public final class PlayerInstance extends Playable
|
||||
|
||||
private void tryLoadSpirits()
|
||||
{
|
||||
final List<ElementalSpiritDataHolder> spiritsData = ElementalSpiritInstanceManager.getInstance().findByPlayerId(getObjectId());
|
||||
if (!spiritsData.isEmpty())
|
||||
final List<ElementalSpiritDataHolder> restoredSpirits = new ArrayList<>();
|
||||
try (Connection con = DatabaseFactory.getConnection();
|
||||
PreparedStatement stmt = con.prepareStatement(RESTORE_ELEMENTAL_SPIRITS))
|
||||
{
|
||||
stmt.setInt(1, getObjectId());
|
||||
try (ResultSet rset = stmt.executeQuery())
|
||||
{
|
||||
while (rset.next())
|
||||
{
|
||||
final ElementalSpiritDataHolder newHolder = new ElementalSpiritDataHolder();
|
||||
newHolder.setCharId(rset.getInt("charId"));
|
||||
newHolder.setType(rset.getByte("type"));
|
||||
newHolder.setLevel(rset.getByte("level"));
|
||||
newHolder.setStage(rset.getByte("stage"));
|
||||
newHolder.setExperience(rset.getLong("experience"));
|
||||
newHolder.setAttackPoints(rset.getByte("attack_points"));
|
||||
newHolder.setDefensePoints(rset.getByte("defense_points"));
|
||||
newHolder.setCritRatePoints(rset.getByte("crit_rate_points"));
|
||||
newHolder.setCritDamagePoints(rset.getByte("crit_damage_points"));
|
||||
newHolder.setInUse(rset.getByte("in_use") == 1);
|
||||
restoredSpirits.add(newHolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!restoredSpirits.isEmpty())
|
||||
{
|
||||
_spirits = new ElementalSpirit[ElementalType.values().length - 1];
|
||||
for (ElementalSpiritDataHolder spiritData : spiritsData)
|
||||
for (ElementalSpiritDataHolder spiritData : restoredSpirits)
|
||||
{
|
||||
_spirits[spiritData.getType() - 1] = new ElementalSpirit(spiritData, this);
|
||||
if (spiritData.isInUse())
|
||||
|
Loading…
Reference in New Issue
Block a user