|
@@ -32,11 +32,9 @@ import javolution.util.FastMap;
|
|
|
|
|
|
import com.l2jserver.Config;
|
|
|
import com.l2jserver.L2DatabaseFactory;
|
|
|
-import com.l2jserver.gameserver.CastleUpdater;
|
|
|
import com.l2jserver.gameserver.ThreadPoolManager;
|
|
|
import com.l2jserver.gameserver.datatables.ClanTable;
|
|
|
import com.l2jserver.gameserver.datatables.DoorTable;
|
|
|
-import com.l2jserver.gameserver.datatables.ManorData;
|
|
|
import com.l2jserver.gameserver.datatables.SkillData;
|
|
|
import com.l2jserver.gameserver.datatables.SkillTreesData;
|
|
|
import com.l2jserver.gameserver.enums.MountType;
|
|
@@ -47,11 +45,9 @@ import com.l2jserver.gameserver.instancemanager.SiegeManager;
|
|
|
import com.l2jserver.gameserver.instancemanager.TerritoryWarManager;
|
|
|
import com.l2jserver.gameserver.instancemanager.TerritoryWarManager.Territory;
|
|
|
import com.l2jserver.gameserver.instancemanager.ZoneManager;
|
|
|
-import com.l2jserver.gameserver.model.CropProcure;
|
|
|
import com.l2jserver.gameserver.model.L2Clan;
|
|
|
import com.l2jserver.gameserver.model.L2Object;
|
|
|
import com.l2jserver.gameserver.model.L2SkillLearn;
|
|
|
-import com.l2jserver.gameserver.model.SeedProduction;
|
|
|
import com.l2jserver.gameserver.model.TowerSpawn;
|
|
|
import com.l2jserver.gameserver.model.actor.instance.L2ArtefactInstance;
|
|
|
import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
|
|
@@ -70,13 +66,6 @@ public final class Castle extends AbstractResidence
|
|
|
{
|
|
|
protected static final Logger _log = Logger.getLogger(Castle.class.getName());
|
|
|
|
|
|
- private static final String CASTLE_MANOR_DELETE_PRODUCTION = "DELETE FROM castle_manor_production WHERE castle_id=?;";
|
|
|
- private static final String CASTLE_MANOR_DELETE_PRODUCTION_PERIOD = "DELETE FROM castle_manor_production WHERE castle_id=? AND period=?;";
|
|
|
- private static final String CASTLE_MANOR_DELETE_PROCURE = "DELETE FROM castle_manor_procure WHERE castle_id=?;";
|
|
|
- private static final String CASTLE_MANOR_DELETE_PROCURE_PERIOD = "DELETE FROM castle_manor_procure WHERE castle_id=? AND period=?;";
|
|
|
- private static final String CASTLE_UPDATE_CROP = "UPDATE castle_manor_procure SET can_buy=? WHERE crop_id=? AND castle_id=? AND period=?";
|
|
|
- private static final String CASTLE_UPDATE_SEED = "UPDATE castle_manor_production SET can_produce=? WHERE seed_id=? AND castle_id=? AND period=?";
|
|
|
-
|
|
|
private final List<L2DoorInstance> _doors = new ArrayList<>();
|
|
|
private int _ownerId = 0;
|
|
|
private Siege _siege = null;
|
|
@@ -94,12 +83,6 @@ public final class Castle extends AbstractResidence
|
|
|
private final Map<Integer, CastleFunction> _function;
|
|
|
private int _ticketBuyCount = 0;
|
|
|
|
|
|
- private List<CropProcure> _procure = new ArrayList<>();
|
|
|
- private List<SeedProduction> _production = new ArrayList<>();
|
|
|
- private List<CropProcure> _procureNext = new ArrayList<>();
|
|
|
- private List<SeedProduction> _productionNext = new ArrayList<>();
|
|
|
- private boolean _isNextPeriodApproved = false;
|
|
|
-
|
|
|
/** Castle Functions */
|
|
|
public static final int FUNC_TELEPORT = 1;
|
|
|
public static final int FUNC_RESTORE_HP = 2;
|
|
@@ -685,12 +668,6 @@ public final class Castle extends AbstractResidence
|
|
|
_ownerId = rs.getInt("clan_id");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (getOwnerId() > 0)
|
|
|
- {
|
|
|
- L2Clan clan = ClanTable.getInstance().getClan(getOwnerId()); // Try to find clan instance
|
|
|
- ThreadPoolManager.getInstance().scheduleGeneral(new CastleUpdater(clan, 1), 3600000); // Schedule owner tasks to start running
|
|
|
- }
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
@@ -876,7 +853,7 @@ public final class Castle extends AbstractResidence
|
|
|
else
|
|
|
{
|
|
|
_ownerId = 0; // Remove owner
|
|
|
- resetManor();
|
|
|
+ CastleManorManager.getInstance().resetManorData(getResidenceId());
|
|
|
}
|
|
|
|
|
|
try (Connection con = L2DatabaseFactory.getInstance().getConnection())
|
|
@@ -901,7 +878,6 @@ public final class Castle extends AbstractResidence
|
|
|
clan.setCastleId(getResidenceId()); // Set has castle flag for new owner
|
|
|
clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
|
|
|
clan.broadcastToOnlineMembers(new PlaySound(1, "Siege_Victory", 0, 0, 0, 0, 0));
|
|
|
- ThreadPoolManager.getInstance().scheduleGeneral(new CastleUpdater(clan, 1), 3600000); // Schedule owner tasks to start running
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e)
|
|
@@ -937,6 +913,11 @@ public final class Castle extends AbstractResidence
|
|
|
return _ownerId;
|
|
|
}
|
|
|
|
|
|
+ public final L2Clan getOwner()
|
|
|
+ {
|
|
|
+ return (_ownerId != 0) ? ClanTable.getInstance().getClan(_ownerId) : null;
|
|
|
+ }
|
|
|
+
|
|
|
public final Siege getSiege()
|
|
|
{
|
|
|
if (_siege == null)
|
|
@@ -999,359 +980,6 @@ public final class Castle extends AbstractResidence
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public List<SeedProduction> getSeedProduction(int period)
|
|
|
- {
|
|
|
- return (period == CastleManorManager.PERIOD_CURRENT ? _production : _productionNext);
|
|
|
- }
|
|
|
-
|
|
|
- public List<CropProcure> getCropProcure(int period)
|
|
|
- {
|
|
|
- return (period == CastleManorManager.PERIOD_CURRENT ? _procure : _procureNext);
|
|
|
- }
|
|
|
-
|
|
|
- public void setSeedProduction(List<SeedProduction> seed, int period)
|
|
|
- {
|
|
|
- if (period == CastleManorManager.PERIOD_CURRENT)
|
|
|
- {
|
|
|
- _production = seed;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _productionNext = seed;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void setCropProcure(List<CropProcure> crop, int period)
|
|
|
- {
|
|
|
- if (period == CastleManorManager.PERIOD_CURRENT)
|
|
|
- {
|
|
|
- _procure = crop;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _procureNext = crop;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public SeedProduction getSeed(int seedId, int period)
|
|
|
- {
|
|
|
- for (SeedProduction seed : getSeedProduction(period))
|
|
|
- {
|
|
|
- if (seed.getId() == seedId)
|
|
|
- {
|
|
|
- return seed;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public CropProcure getCrop(int cropId, int period)
|
|
|
- {
|
|
|
- for (CropProcure crop : getCropProcure(period))
|
|
|
- {
|
|
|
- if (crop.getId() == cropId)
|
|
|
- {
|
|
|
- return crop;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public long getManorCost(int period)
|
|
|
- {
|
|
|
- List<CropProcure> procure;
|
|
|
- List<SeedProduction> production;
|
|
|
-
|
|
|
- if (period == CastleManorManager.PERIOD_CURRENT)
|
|
|
- {
|
|
|
- procure = _procure;
|
|
|
- production = _production;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- procure = _procureNext;
|
|
|
- production = _productionNext;
|
|
|
- }
|
|
|
-
|
|
|
- long total = 0;
|
|
|
- if (production != null)
|
|
|
- {
|
|
|
- for (SeedProduction seed : production)
|
|
|
- {
|
|
|
- total += ManorData.getInstance().getSeedBuyPrice(seed.getId()) * seed.getStartProduce();
|
|
|
- }
|
|
|
- }
|
|
|
- if (procure != null)
|
|
|
- {
|
|
|
- for (CropProcure crop : procure)
|
|
|
- {
|
|
|
- total += crop.getPrice() * crop.getStartAmount();
|
|
|
- }
|
|
|
- }
|
|
|
- return total;
|
|
|
- }
|
|
|
-
|
|
|
- // save manor production data
|
|
|
- public void saveSeedData()
|
|
|
- {
|
|
|
- try (Connection con = L2DatabaseFactory.getInstance().getConnection())
|
|
|
- {
|
|
|
- try (PreparedStatement ps1 = con.prepareStatement(CASTLE_MANOR_DELETE_PRODUCTION))
|
|
|
- {
|
|
|
- ps1.setInt(1, getResidenceId());
|
|
|
- ps1.execute();
|
|
|
- }
|
|
|
-
|
|
|
- if (_production != null)
|
|
|
- {
|
|
|
- int count = 0;
|
|
|
- StringBuilder query = new StringBuilder();
|
|
|
- query.append("INSERT INTO castle_manor_production VALUES ");
|
|
|
- String values[] = new String[_production.size()];
|
|
|
- for (SeedProduction s : _production)
|
|
|
- {
|
|
|
- values[count++] = "(" + getResidenceId() + "," + s.getId() + "," + s.getCanProduce() + "," + s.getStartProduce() + "," + s.getPrice() + "," + CastleManorManager.PERIOD_CURRENT + ")";
|
|
|
- }
|
|
|
- if (values.length > 0)
|
|
|
- {
|
|
|
- query.append(values[0]);
|
|
|
- for (int i = 1; i < values.length; i++)
|
|
|
- {
|
|
|
- query.append(',');
|
|
|
- query.append(values[i]);
|
|
|
- }
|
|
|
- try (PreparedStatement ps2 = con.prepareStatement(query.toString()))
|
|
|
- {
|
|
|
- ps2.execute();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (_productionNext != null)
|
|
|
- {
|
|
|
- int count = 0;
|
|
|
- String query = "INSERT INTO castle_manor_production VALUES ";
|
|
|
- String values[] = new String[_productionNext.size()];
|
|
|
- for (SeedProduction s : _productionNext)
|
|
|
- {
|
|
|
- values[count++] = "(" + getResidenceId() + "," + s.getId() + "," + s.getCanProduce() + "," + s.getStartProduce() + "," + s.getPrice() + "," + CastleManorManager.PERIOD_NEXT + ")";
|
|
|
- }
|
|
|
- if (values.length > 0)
|
|
|
- {
|
|
|
- query += values[0];
|
|
|
- for (int i = 1; i < values.length; i++)
|
|
|
- {
|
|
|
- query += "," + values[i];
|
|
|
- }
|
|
|
- try (PreparedStatement ps3 = con.prepareStatement(query))
|
|
|
- {
|
|
|
- ps3.execute();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- _log.info("Error adding seed production data for castle " + getName() + ": " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // save manor production data for specified period
|
|
|
- public void saveSeedData(int period)
|
|
|
- {
|
|
|
- try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
|
|
- PreparedStatement ps = con.prepareStatement(CASTLE_MANOR_DELETE_PRODUCTION_PERIOD))
|
|
|
- {
|
|
|
- ps.setInt(1, getResidenceId());
|
|
|
- ps.setInt(2, period);
|
|
|
- ps.execute();
|
|
|
-
|
|
|
- List<SeedProduction> prod = null;
|
|
|
- prod = getSeedProduction(period);
|
|
|
-
|
|
|
- if (prod != null)
|
|
|
- {
|
|
|
- int count = 0;
|
|
|
- StringBuilder query = new StringBuilder();
|
|
|
- query.append("INSERT INTO castle_manor_production VALUES ");
|
|
|
- String values[] = new String[prod.size()];
|
|
|
- for (SeedProduction s : prod)
|
|
|
- {
|
|
|
- values[count++] = "(" + getResidenceId() + "," + s.getId() + "," + s.getCanProduce() + "," + s.getStartProduce() + "," + s.getPrice() + "," + period + ")";
|
|
|
- }
|
|
|
- if (values.length > 0)
|
|
|
- {
|
|
|
- query.append(values[0]);
|
|
|
- for (int i = 1; i < values.length; i++)
|
|
|
- {
|
|
|
- query.append(',').append(values[i]);
|
|
|
- }
|
|
|
- try (PreparedStatement insert = con.prepareStatement(query.toString()))
|
|
|
- {
|
|
|
- insert.execute();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- _log.info("Error adding seed production data for castle " + getName() + ": " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // save crop procure data
|
|
|
- public void saveCropData()
|
|
|
- {
|
|
|
- try (Connection con = L2DatabaseFactory.getInstance().getConnection())
|
|
|
- {
|
|
|
- try (PreparedStatement ps1 = con.prepareStatement(CASTLE_MANOR_DELETE_PROCURE))
|
|
|
- {
|
|
|
- ps1.setInt(1, getResidenceId());
|
|
|
- ps1.execute();
|
|
|
- }
|
|
|
-
|
|
|
- if (!_procure.isEmpty())
|
|
|
- {
|
|
|
- int count = 0;
|
|
|
- StringBuilder query = new StringBuilder();
|
|
|
- query.append("INSERT INTO castle_manor_procure VALUES ");
|
|
|
- String values[] = new String[_procure.size()];
|
|
|
- for (CropProcure cp : _procure)
|
|
|
- {
|
|
|
- values[count++] = "(" + getResidenceId() + "," + cp.getId() + "," + cp.getAmount() + "," + cp.getStartAmount() + "," + cp.getPrice() + "," + cp.getReward() + "," + CastleManorManager.PERIOD_CURRENT + ")";
|
|
|
- }
|
|
|
- if (values.length > 0)
|
|
|
- {
|
|
|
- query.append(values[0]);
|
|
|
- for (int i = 1; i < values.length; i++)
|
|
|
- {
|
|
|
- query.append(',');
|
|
|
- query.append(values[i]);
|
|
|
- }
|
|
|
- try (PreparedStatement ps2 = con.prepareStatement(query.toString()))
|
|
|
- {
|
|
|
- ps2.execute();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (!_procureNext.isEmpty())
|
|
|
- {
|
|
|
- int count = 0;
|
|
|
- String query = "INSERT INTO castle_manor_procure VALUES ";
|
|
|
- String values[] = new String[_procureNext.size()];
|
|
|
- for (CropProcure cp : _procureNext)
|
|
|
- {
|
|
|
- values[count++] = "(" + getResidenceId() + "," + cp.getId() + "," + cp.getAmount() + "," + cp.getStartAmount() + "," + cp.getPrice() + "," + cp.getReward() + "," + CastleManorManager.PERIOD_NEXT + ")";
|
|
|
- }
|
|
|
- if (values.length > 0)
|
|
|
- {
|
|
|
- query += values[0];
|
|
|
- for (int i = 1; i < values.length; i++)
|
|
|
- {
|
|
|
- query += "," + values[i];
|
|
|
- }
|
|
|
- try (PreparedStatement ps3 = con.prepareStatement(query))
|
|
|
- {
|
|
|
- ps3.execute();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- _log.info("Error adding crop data for castle " + getName() + ": " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // save crop procure data for specified period
|
|
|
- public void saveCropData(int period)
|
|
|
- {
|
|
|
- try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
|
|
- PreparedStatement ps = con.prepareStatement(CASTLE_MANOR_DELETE_PROCURE_PERIOD))
|
|
|
- {
|
|
|
- ps.setInt(1, getResidenceId());
|
|
|
- ps.setInt(2, period);
|
|
|
- ps.execute();
|
|
|
-
|
|
|
- List<CropProcure> proc = null;
|
|
|
- proc = getCropProcure(period);
|
|
|
-
|
|
|
- if ((proc != null) && (proc.size() > 0))
|
|
|
- {
|
|
|
- int count = 0;
|
|
|
- StringBuilder query = new StringBuilder();
|
|
|
- query.append("INSERT INTO castle_manor_procure VALUES ");
|
|
|
- String values[] = new String[proc.size()];
|
|
|
-
|
|
|
- for (CropProcure cp : proc)
|
|
|
- {
|
|
|
- values[count++] = "(" + getResidenceId() + "," + cp.getId() + "," + cp.getAmount() + "," + cp.getStartAmount() + "," + cp.getPrice() + "," + cp.getReward() + "," + period + ")";
|
|
|
- }
|
|
|
- if (values.length > 0)
|
|
|
- {
|
|
|
- query.append(values[0]);
|
|
|
- for (int i = 1; i < values.length; i++)
|
|
|
- {
|
|
|
- query.append(',');
|
|
|
- query.append(values[i]);
|
|
|
- }
|
|
|
- try (PreparedStatement insert = con.prepareStatement(query.toString()))
|
|
|
- {
|
|
|
- insert.execute();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- _log.info("Error adding crop data for castle " + getName() + ": " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void updateCrop(int cropId, long amount, int period)
|
|
|
- {
|
|
|
- try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
|
|
- PreparedStatement ps = con.prepareStatement(CASTLE_UPDATE_CROP))
|
|
|
- {
|
|
|
- ps.setLong(1, amount);
|
|
|
- ps.setInt(2, cropId);
|
|
|
- ps.setInt(3, getResidenceId());
|
|
|
- ps.setInt(4, period);
|
|
|
- ps.execute();
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- _log.info("Error adding crop data for castle " + getName() + ": " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void updateSeed(int seedId, long amount, int period)
|
|
|
- {
|
|
|
- try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
|
|
- PreparedStatement ps = con.prepareStatement(CASTLE_UPDATE_SEED))
|
|
|
- {
|
|
|
- ps.setLong(1, amount);
|
|
|
- ps.setInt(2, seedId);
|
|
|
- ps.setInt(3, getResidenceId());
|
|
|
- ps.setInt(4, period);
|
|
|
- ps.execute();
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- _log.info("Error adding seed production data for castle " + getName() + ": " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isNextPeriodApproved()
|
|
|
- {
|
|
|
- return _isNextPeriodApproved;
|
|
|
- }
|
|
|
-
|
|
|
- public void setNextPeriodApproved(boolean val)
|
|
|
- {
|
|
|
- _isNextPeriodApproved = val;
|
|
|
- }
|
|
|
-
|
|
|
public void updateClansReputation()
|
|
|
{
|
|
|
if (_formerOwner != null)
|
|
@@ -1461,19 +1089,6 @@ public final class Castle extends AbstractResidence
|
|
|
return _artefacts;
|
|
|
}
|
|
|
|
|
|
- public void resetManor()
|
|
|
- {
|
|
|
- setCropProcure(new ArrayList<CropProcure>(), CastleManorManager.PERIOD_CURRENT);
|
|
|
- setCropProcure(new ArrayList<CropProcure>(), CastleManorManager.PERIOD_NEXT);
|
|
|
- setSeedProduction(new ArrayList<SeedProduction>(), CastleManorManager.PERIOD_CURRENT);
|
|
|
- setSeedProduction(new ArrayList<SeedProduction>(), CastleManorManager.PERIOD_NEXT);
|
|
|
- if (Config.ALT_MANOR_SAVE_ALL_ACTIONS)
|
|
|
- {
|
|
|
- saveCropData();
|
|
|
- saveSeedData();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* @return the tickets exchanged for this castle
|
|
|
*/
|