NpcInfo.java
Скрытый текст/* * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*/
package net.sf.l2j.gameserver.serverpackets;
import net.sf.l2j.Config;
import net.sf.l2j.gameserver.model.L2Character;
import net.sf.l2j.gameserver.datatables.ClanTable;
import net.sf.l2j.gameserver.instancemanager.TownManager;
import net.sf.l2j.gameserver.model.L2Clan;
import net.sf.l2j.gameserver.model.zone.type.L2TownZone;
import net.sf.l2j.gameserver.model.L2Summon;
import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
/**
* This class ...
*
* @version $Revision: 1.7.2.4.2.9 $ $Date: 2005/04/11 10:05:54 $
*/
public class NpcInfo extends L2GameServerPacket
{
// ddddddddddddddddddffffdddcccccSSddd dddddc
// ddddddddddddddddddffffdddcccccSSddd dddddccffd
private static final String _S__22_NPCINFO = " 16 NpcInfo";
private L2Character _activeChar;
private int _x, _y, _z, _heading;
private int _idTemplate;
private boolean _isAttackable, _isSummoned;
private int _mAtkSpd, _pAtkSpd;
private int _runSpd, _walkSpd, _swimRunSpd, _swimWalkSpd, _flRunSpd, _flWalkSpd, _flyRunSpd, _flyWalkSpd;
private int _rhand, _lhand;
private int _collisionHeight, _collisionRadius;
private String _name = "";
private String _title = "";
private int _agro;
private byte _team = 0;
private int _clanCrest;
private int _clanId;
private int _allyCrest;
private int _allyId;
/**
* @param _characters
*/
public NpcInfo(L2NpcInstance cha, L2Character attacker)
{
_activeChar = cha;
_idTemplate = cha.getTemplate().idTemplate;
_isAttackable = cha.isAutoAttackable(attacker);
_rhand = cha.getRightHandItem();
_lhand = cha.getLeftHandItem();
_isSummoned = false;
_collisionHeight = cha.getCollisionHeight();
_collisionRadius = cha.getCollisionRadius();
_agro = cha.getAggroRange();
if (cha.getTemplate().serverSideName)
{
_name = cha.getTemplate().name;
}
if(cha.isChampion())
{
_title = ("Champion");
if(cha.isRedChampion())
_team = 2;
else
_team = 1;
}
else if (cha.getTemplate().serverSideTitle)
{
_title = cha.getTemplate().title;
}
else
{
_title = cha.getTitle();
}
if ((Config.SHOW_NPC_CREST) &&
(cha instanceof L2NpcInstance) && (cha.isInsideZone(2)) && (cha.getCastle().getOwnerId() != 0))
{
int _x = cha.getX();
int _y = cha.getY();
int _z = cha.getZ();
L2TownZone Town = TownManager.getInstance().getTown(_x, _y, _z);
if (Town != null)
{
int townId = Town.getTownId();
if ((townId != 33) && (townId != 22))
{
L2Clan clan = ClanTable.getInstance().getClan(cha.getCastle().getOwnerId());
this._clanCrest = clan.getCrestId();
this._clanId = clan.getClanId();
this._allyCrest = clan.getAllyCrestId();
this._allyId = clan.getAllyId();
}
}
}
if (Config.SHOW_NPC_LVL && _activeChar instanceof L2MonsterInstance)
{
String t = "Lv " + cha.getLevel() + (cha.getAggroRange() > 0 ? "*" : "");
if (_title != null)
t += " " + _title;
_title = t;
}
_x = _activeChar.getX();
_y = _activeChar.getY();
_z = _activeChar.getZ();
_heading = _activeChar.getHeading();
_mAtkSpd = _activeChar.getMAtkSpd();
_pAtkSpd = _activeChar.getPAtkSpd();
_runSpd = _activeChar.getRunSpeed();
_walkSpd = _activeChar.getWalkSpeed();
_swimRunSpd = _flRunSpd = _flyRunSpd = _runSpd;
_swimWalkSpd = _flWalkSpd = _flyWalkSpd = _walkSpd;
}
public NpcInfo(L2Summon cha, L2Character attacker)
{
_activeChar = cha;
_idTemplate = cha.getTemplate().idTemplate;
_isAttackable = cha.isAutoAttackable(attacker); //(cha.getKarma() > 0);
_rhand = 0;
_lhand = 0;
_isSummoned = cha.isShowSummonAnimation();
_collisionHeight = _activeChar.getTemplate().collisionHeight;
_collisionRadius = _activeChar.getTemplate().collisionRadius;
_name = _activeChar.getName();
_title = cha.getTitle();
_x = _activeChar.getX();
_y = _activeChar.getY();
_z = _activeChar.getZ();
_heading = _activeChar.getHeading();
_mAtkSpd = _activeChar.getMAtkSpd();
_pAtkSpd = _activeChar.getPAtkSpd();
_runSpd = _activeChar.getRunSpeed();
_walkSpd = _activeChar.getWalkSpeed();
_swimRunSpd = _flRunSpd = _flyRunSpd = _runSpd;
_swimWalkSpd = _flWalkSpd = _flyWalkSpd = _walkSpd;
}
@Override
protected final void writeImpl()
{
if (_activeChar instanceof L2Summon)
if (((L2Summon)_activeChar).getOwner() != null
&& ((L2Summon)_activeChar).getOwner().getAppearance().getInvisible())
return;
writeC(0x16);
writeD(_activeChar.getObjectId());
writeD(_idTemplate+1000000); // npctype id
writeD(_isAttackable ? 1 : 0);
writeD(_x);
writeD(_y);
writeD(_z);
writeD(_heading);
writeD(0x00);
writeD(_mAtkSpd);
writeD(_pAtkSpd);
writeD(_runSpd);
writeD(_walkSpd);
writeD(_swimRunSpd/*0x32*/); // swimspeed
writeD(_swimWalkSpd/*0x32*/); // swimspeed
writeD(_flRunSpd);
writeD(_flWalkSpd);
writeD(_flyRunSpd);
writeD(_flyWalkSpd);
writeF(1.1/*_activeChar.getProperMultiplier()*/);
//writeF(1/*_activeChar.getAttackSpeedMultiplier()*/);
writeF(_pAtkSpd/277.478340719);
writeF(_collisionRadius);
writeF(_collisionHeight);
writeD(_rhand); // right hand weapon
writeD(0);
writeD(_lhand); // left hand weapon
writeC(1); // name above char 1=true ... ??
writeC(_activeChar.isRunning() ? 1 : 0);
writeC(_activeChar.isInCombat() ? 1 : 0);
writeC(_activeChar.isAlikeDead() ? 1 : 0);
writeC(_isSummoned ? 2 : 0); // invisible ?? 0=false 1=true 2=summoned (only works if model has a summon animation)
writeS(_name);
writeS(_title);
writeD(0); // Title color 0=client default
writeD(0);
if((_agro > 0) && Config.SET_AGRO_COLOR_TITLE)
{
writeD(0001); // hmm karma ??
}
else
{
writeD(0000);
}
writeD(_activeChar.getAbnormalEffect()); // C2
writeD(0000); // C2
writeD(0000); // C2
writeD(0000); // C2
writeD(0000); // C2
writeC(0000); // C2
if (Config.SHOW_NPC_CREST)
{
writeD(this._clanId);
writeD(this._clanCrest);
writeD(this._allyId);
writeD(this._allyCrest);
}
else
{
writeD(0);
writeD(0);
writeD(0);
writeD(0);
writeC(0);
}
writeC(_team); // C3 team circle 1-blue, 2-red
writeF(_collisionRadius);
writeF(_collisionHeight);
writeD(0x00); // C4
writeD(0x00); // C6
}
/* (non-Javadoc)
* @see net.sf.l2j.gameserver.serverpackets.ServerBasePacket#getType()
*/
@Override
public String getType()
{
return _S__22_NPCINFO;
}
}
config.java
Скрытый текст
public static int MAX_MULTISELL;
public static boolean RB_HEAL;
public static boolean SHOW_NPC_CREST;
MP_RESTORE = Integer.parseInt(LacostaSettings.getProperty("MPRestore", "1000"));
MAX_MULTISELL = Integer.parseInt(LacostaSettings.getProperty("MaxMultisell","5000"));
SHOW_NPC_CREST = Boolean.parseBoolean(LacostaSettings.getProperty("ShowNpcCrest","False"));
Castle.java
Скрытый текст
/* * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*/
package net.sf.l2j.gameserver.model.entity;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Logger;
import java.util.Map;
import net.sf.l2j.Config;
import javolution.util.FastList;
import javolution.util.FastMap;
import net.sf.l2j.database.DatabaseUtils;
import net.sf.l2j.database.FiltredPreparedStatement;
import net.sf.l2j.database.L2DatabaseFactory;
import net.sf.l2j.database.ThreadConnection;
import net.sf.l2j.gameserver.Announcements;
import net.sf.l2j.gameserver.CastleUpdater;
import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.datatables.ClanTable;
import net.sf.l2j.gameserver.datatables.DoorTable;
import net.sf.l2j.gameserver.instancemanager.CastleManager;
import net.sf.l2j.gameserver.instancemanager.CastleManorManager;
import net.sf.l2j.gameserver.instancemanager.CastleManorManager.CropProcure;
import net.sf.l2j.gameserver.instancemanager.CastleManorManager.SeedProduction;
import net.sf.l2j.gameserver.instancemanager.CrownManager;
import net.sf.l2j.gameserver.model.L2Clan;
import net.sf.l2j.gameserver.model.L2Manor;
import net.sf.l2j.gameserver.model.L2Object;
import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.serverpackets.PledgeShowInfoUpdate;
import net.sf.l2j.gameserver.SevenSigns;
import net.sf.l2j.gameserver.model.zone.type.L2CastleZone;
public class Castle
{
protected static Logger _log = Logger.getLogger(Castle.class.getName());
// =========================================================
// Data Field
private FastList<CropProcure> _procure = new FastList<CropProcure>();
private FastList<SeedProduction> _production = new FastList<SeedProduction>();
private FastList<CropProcure> _procureNext = new FastList<CropProcure>();
private FastList<SeedProduction> _productionNext = new FastList<SeedProduction>();
private boolean _isNextPeriodApproved = false;
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=?";
// =========================================================
// Data Field
private int _castleId = 0;
private List<L2DoorInstance> _doors = new FastList<L2DoorInstance>();
private List<String> _doorDefault = new FastList<String>();
private String _name = "";
private int _ownerId = 0;
private Siege _siege = null;
private Calendar _siegeDate;
private int _siegeDayOfWeek = 7; // Default to saturday
private int _siegeHourOfDay = 20; // Default to 8 pm server time
private int _taxPercent = 0;
private double _taxRate = 0;
private int _treasury = 0;
private L2CastleZone _zone;
private L2Clan _formerOwner = null;
private int _nbArtifact = 1;
private Map<Integer, Integer> _engrave = new FastMap<Integer, Integer>();
private boolean _showNpcCrest = false;
// =========================================================
// Constructor
public Castle(int castleId)
{
if(_castleId == 7 || castleId == 9) // Goddard and Schuttgart
{
_nbArtifact = 2;
}
_castleId = castleId;
load();
}
// =========================================================
// Method - Public
public void Engrave(L2Clan clan, int objId)
{
_engrave.put(objId, clan.getClanId());
if (_engrave.size() == _nbArtifact)
{
boolean rst = true;
for (int id : _engrave.values())
{
if (id != clan.getClanId())
{
rst = false;
}
}
if(rst)
{
_engrave.clear();
setOwner(clan);
}
else
{
getSiege().announceToPlayer("Clan " + clan.getName() + " has finished to engrave one of the rulers.", true);
}
}
else
{
getSiege().announceToPlayer("Clan " + clan.getName() + " has finished to engrave one of the rulers.", true);
}
}
// This method add to the treasury
/** Add amount to castle instance's treasury (warehouse). */
public void addToTreasury(int amount)
{
if (getOwnerId() <= 0) return;
if (_name.equalsIgnoreCase("Schuttgart") || _name.equalsIgnoreCase("Goddard"))
{
Castle rune = CastleManager.getInstance().getCastle("rune");
if (rune != null )
{
int runeTax = (int)(amount * rune.getTaxRate());
if (rune.getOwnerId() > 0 ) rune.addToTreasury(runeTax);
amount -= runeTax;
}
}
if (!_name.equalsIgnoreCase("aden") && !_name.equalsIgnoreCase("Rune") && !_name.equalsIgnoreCase("Schuttgart") && !_name.equalsIgnoreCase("Goddard")) // If current castle instance is not Aden, Rune, Goddard or Schuttgart.
{
Castle aden = CastleManager.getInstance().getCastle("aden");
if (aden != null)
{
int adenTax = (int)(amount * aden.getTaxRate()); // Find out what Aden gets from the current castle instance's income
if (aden.getOwnerId() > 0) aden.addToTreasury(adenTax); // Only bother to really add the tax to the treasury if not npc owned
amount -= adenTax; // Subtract Aden's income from current castle instance's income
}
}
addToTreasuryNoTax(amount);
}
/** Add amount to castle instance's treasury (warehouse), no tax paying. */
public boolean addToTreasuryNoTax(int amount)
{
if (getOwnerId() <= 0)
{
return false;
}
/* why is that ?? example:
_treasury = 2,100,000,000
amount = -2,000,000,000 (i want to withdraw)
so Integer.MAX_VALUE -(-2,000,000,000) < 2,100,000,000 will allways be false
so you can withdraw money but it will stay in castle WH -> EXPLOIT FTW !!!!!!!!!!!
*/
if (amount < 0)
{
amount *= -1;
if (_treasury < amount)
{
return false;
}
_treasury -= amount;
}
else
{
if ((long)_treasury + amount > Integer.MAX_VALUE)
{
_treasury = Integer.MAX_VALUE;
}
else
{
_treasury += amount;
}
}
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("UPDATE castle SET treasury = ? WHERE id = ?");
statement.setInt(1, getTreasury());
statement.setInt(2, getCastleId());
statement.execute();
}
catch (Exception e) {}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
return true;
}
/**
* Move non clan members off castle area and to nearest town.<BR><BR>
*/
public void banishForeigners()
{
_zone.banishForeigners(getOwnerId());
}
/**
* Return true if object is inside the zone
*/
public boolean checkIfInZone(int x, int y, int z)
{
return _zone.isInsideZone(x, y, z);
}
/**
* Sets this castles zone
* @param zone
*/
public void setZone(L2CastleZone zone)
{
_zone = zone;
}
public L2CastleZone getZone()
{
return _zone;
}
/**
* Get the objects distance to this castle
* @param obj
* @return
*/
public double getDistance(L2Object obj)
{
return _zone.getDistanceToZone(obj);
}
public void closeDoor(L2PcInstance activeChar, int doorId)
{
openCloseDoor(activeChar, doorId, false);
}
public void openDoor(L2PcInstance activeChar, int doorId)
{
openCloseDoor(activeChar, doorId, true);
}
public void openCloseDoor(L2PcInstance activeChar, int doorId, boolean open)
{
if (activeChar.getClanId() != getOwnerId())
{
return;
}
L2DoorInstance door = getDoor(doorId);
if (door != null)
{
if (open)
{
door.openMe();
}
else
{
door.closeMe();
}
}
}
// This method is used to begin removing all castle upgrades
public void removeUpgrade()
{
removeDoorUpgrade();
}
// This method updates the castle tax rate
public void setOwner(L2Clan clan)
{
// Remove old owner
if (getOwnerId() > 0 && (clan == null || clan.getClanId() != getOwnerId()))
{
L2Clan oldOwner = ClanTable.getInstance().getClan(getOwnerId()); // Try to find clan instance
if (oldOwner != null)
{
if (_formerOwner == null)
{
_formerOwner = oldOwner;
if (Config.REMOVE_CASTLE_CIRCLETS)
{
CastleManager.getInstance().removeCirclet(_formerOwner,getCastleId());
}
}
oldOwner.setHasCastle(0); // Unset has castle flag for old owner
new Announcements().announceToAll(oldOwner.getName() + " has lost " + getName() + " castle!");
// remove crowns
CrownManager.getInstance().removeCrowns(oldOwner);
}
}
// Update in database
updateOwnerInDB(clan);
setShowNpcCrest(false);
if (getSiege().getIsInProgress()) // If siege in progress
{
getSiege().midVictory(); // Mid victory phase of siege
}
updateClansReputation();
}
public void removeOwner(L2Clan clan)
{
if (clan != null)
{
_formerOwner = clan;
if (Config.REMOVE_CASTLE_CIRCLETS)
{
CastleManager.getInstance().removeCirclet(_formerOwner,getCastleId());
}
clan.setHasCastle(0);
new Announcements().announceToAll(clan.getName() + " has lost " +getName() + " castle");
clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
}
updateOwnerInDB(null);
if (getSiege().getIsInProgress())
{
getSiege().midVictory();
}
updateClansReputation();
}
// This method updates the castle tax rate
public void setTaxPercent(L2PcInstance activeChar, int taxPercent)
{
int maxTax;
switch(SevenSigns.getInstance().getSealOwner(SevenSigns.SEAL_STRIFE))
{
case SevenSigns.CABAL_DAWN:
maxTax = 25;
break;
case SevenSigns.CABAL_DUSK:
maxTax = 5;
break;
default: // no owner
maxTax = 15;
}
if (taxPercent < 0 || taxPercent > maxTax)
{
activeChar.sendMessage("Tax value must be between 0 and "+maxTax+".");
return;
}
setTaxPercent(taxPercent);
activeChar.sendMessage(getName() + " castle tax changed to " + taxPercent + "%.");
}
public void setTaxPercent(int taxPercent)
{
_taxPercent = taxPercent;
_taxRate = _taxPercent / 100.0;
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("UPDATE castle SET taxPercent = ? WHERE id = ?");
statement.setInt(1, taxPercent);
statement.setInt(2, getCastleId());
statement.execute();
}
catch (Exception e) {}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}
/**
* Respawn all doors on castle grounds<BR><BR>
*/
public void spawnDoor()
{
spawnDoor(false, false);
}
/**
* Respawn all doors on castle grounds<BR><BR>
*/
public void spawnDoor(boolean isDoorWeak, boolean destroyable)
{
for (int i = 0; i < getDoors().size(); i++)
{
L2DoorInstance door = getDoors().get(i);
if (door.getCurrentHp() <= 0)
{
door.decayMe(); // Kill current if not killed already
door.setCurrentHp(isDoorWeak ? door.getMaxHp() / 2 : door.getMaxHp());
door.spawnMe(door.getX(), door.getY(),door.getZ());
}
else if (!door.isOpen())
{
door.closeMe();
}
door.setDestroyable(destroyable);
}
loadDoorUpgrade(); // Check for any upgrade the doors may have
}
// This method upgrade door
public void upgradeDoor(int doorId, int hp, int pDef, int mDef, boolean save)
{
L2DoorInstance door = getDoor(doorId);
if (door == null)
return;
door.setCurrentHp(door.getMaxHp() + hp);
if (save)
saveDoorUpgrade(doorId, hp, pDef, mDef);
}
// =========================================================
// Method - Private
// This method loads castle
private void load()
{
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
ResultSet rs = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT * FROM castle WHERE id = ?");
statement.setInt(1, getCastleId());
rs = statement.executeQuery();
while (rs.next())
{
_name = rs.getString("name");
//_OwnerId = rs.getInt("ownerId");
_siegeDate = Calendar.getInstance();
_siegeDate.setTimeInMillis(rs.getLong("siegeDate"));
_siegeDayOfWeek = rs.getInt("siegeDayOfWeek");
if (_siegeDayOfWeek < 1 || _siegeDayOfWeek > 7)
{
_siegeDayOfWeek = 7;
}
_siegeHourOfDay = rs.getInt("siegeHourOfDay");
if (_siegeHourOfDay < 0 || _siegeHourOfDay > 23)
{
_siegeHourOfDay = 20;
}
_taxPercent = rs.getInt("taxPercent");
_treasury = rs.getInt("treasury");
_showNpcCrest = rs.getBoolean("showNpcCrest");
}
statement.close();
_taxRate = _taxPercent / 100.0;
statement = con.prepareStatement("SELECT clan_id FROM clan_data WHERE hasCastle = ?");
statement.setInt(1, getCastleId());
rs = statement.executeQuery();
while (rs.next())
{
_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
}
statement.close();
}
catch (Exception e)
{
System.out.println("Exception: loadCastleData(): " + e.getMessage());
e.printStackTrace();
}
finally
{
DatabaseUtils.closeDatabaseCSR(con, statement, rs);
}
}
// This method loads door data from database
public void loadDoor()
{
int id = 0;
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
ResultSet rset = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT id FROM siege_door WHERE unitId = ?");
statement.setInt(1, getCastleId());
rset = statement.executeQuery();
while(rset.next())
{
id = rset.getInt("id");
L2DoorInstance door = DoorTable.getInstance().getDoor(rset.getInt("id"));
_doors.add(door);
}
}
catch(Exception e)
{
_log.warning("Exception: loadDoor(), id = " + id + ", error: " + e);
e.printStackTrace();
}
finally
{
DatabaseUtils.closeDatabaseCSR(con, statement, rset);
}
}
// This method loads castle door upgrade data from database
private void loadDoorUpgrade()
{
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
ResultSet rset = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT * FROM castle_doorupgrade WHERE doorId IN (SELECT Id FROM siege_door WHERE unitId = ?)");
statement.setInt(1, getCastleId());
ResultSet rs = statement.executeQuery();
while (rs.next())
{
upgradeDoor(rs.getInt("id"), rs.getInt("hp"), rs.getInt("pDef"), rs.getInt("mDef"), false);
}
}
catch (Exception e)
{
System.out.println("Exception: loadCastleDoorUpgrade(): " + e.getMessage());
e.printStackTrace();
}
finally
{
DatabaseUtils.closeDatabaseCSR(con, statement, rset);
}
}
private void removeDoorUpgrade()
{
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("DELETE FROM castle_doorupgrade WHERE doorId IN (SELECT id FROM siege_door WHERE unitId=?)");
statement.setInt(1, getCastleId());
statement.execute();
}
catch (Exception e)
{
System.out.println("Exception: removeDoorUpgrade(): " + e.getMessage());
e.printStackTrace();
}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}
private void saveDoorUpgrade(int doorId, int hp, int pDef, int mDef)
{
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("INSERT INTO castle_doorupgrade (doorId, hp, pDef, mDef) values (?,?,?,?)");
statement.setInt(1, doorId);
statement.setInt(2, hp);
statement.setInt(3, pDef);
statement.setInt(4, mDef);
statement.execute();
}
catch (Exception e)
{
System.out.println("Exception: saveDoorUpgrade(int doorId, int hp, int pDef, int mDef): " + e.getMessage());
e.printStackTrace();
}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}
private void updateOwnerInDB(L2Clan clan)
{
if (clan != null)
{
_ownerId = clan.getClanId(); // Update owner id property
}
else
{
_ownerId = 0; // Remove owner
}
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
// ============================================================================
// NEED TO REMOVE HAS CASTLE FLAG FROM CLAN_DATA
// SHOULD BE CHECKED FROM CASTLE TABLE
statement = con.prepareStatement("UPDATE clan_data SET hasCastle=0 WHERE hasCastle=?");
statement.setInt(1, getCastleId());
statement.execute();
statement.close();
statement = con.prepareStatement("UPDATE clan_data SET hasCastle=? WHERE clan_id=?");
statement.setInt(1, getCastleId());
statement.setInt(2, getOwnerId());
statement.execute();
statement.close();
// ============================================================================
// Announce to clan memebers
if (clan != null)
{
clan.setHasCastle(getCastleId()); // Set has castle flag for new owner
new Announcements().announceToAll(clan.getName() + " has taken " + getName() + " castle!");
clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
// give crowns
CrownManager.getInstance().giveCrowns(clan,this.getCastleId());
ThreadPoolManager.getInstance().scheduleGeneral(new CastleUpdater(clan, 1), 3600000); // Schedule owner tasks to start running
}
}
catch (Exception e)
{
System.out.println("Exception: updateOwnerInDB(L2Clan clan): " + e.getMessage());
e.printStackTrace();
}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}
// =========================================================
// Property
public final int getCastleId()
{
return _castleId;
}
public final L2DoorInstance getDoor(int doorId)
{
if (doorId <= 0)
{
return null;
}
for (int i = 0; i < getDoors().size(); i++)
{
L2DoorInstance door = getDoors().get(i);
if (door.getDoorId() == doorId)
{
return door;
}
}
return null;
}
public final List<L2DoorInstance> getDoors()
{
return _doors;
}
public final String getName()
{
return _name;
}
public final int getOwnerId()
{
return _ownerId;
}
public final Siege getSiege()
{
if (_siege == null) _siege = new Siege(new Castle[] {this});
return _siege;
}
public final Calendar getSiegeDate() { return _siegeDate; }
public final int getSiegeDayOfWeek() { return _siegeDayOfWeek; }
public final int getSiegeHourOfDay() { return _siegeHourOfDay; }
public final int getTaxPercent()
{
return _taxPercent;
}
public final double getTaxRate()
{
return _taxRate;
}
public final int getTreasury()
{
return _treasury;
}
public final boolean getShowNpcCrest()
{
return _showNpcCrest;
}
public final void setShowNpcCrest(boolean showNpcCrest)
{
if(_showNpcCrest != showNpcCrest)
{
_showNpcCrest = showNpcCrest;
updateShowNpcCrest();
}
}
public FastList<SeedProduction> getSeedProduction(int period)
{
return (period == CastleManorManager.PERIOD_CURRENT ? _production : _productionNext);
}
public FastList<CropProcure> getCropProcure(int period)
{
return (period == CastleManorManager.PERIOD_CURRENT ? _procure : _procureNext);
}
public void setSeedProduction(FastList<SeedProduction> seed, int period)
{
if (period == CastleManorManager.PERIOD_CURRENT)
{
_production = seed;
}
else
{
_productionNext = seed;
}
}
public void setCropProcure(FastList<CropProcure> crop, int period)
{
if (period == CastleManorManager.PERIOD_CURRENT)
{
_procure = crop;
}
else
{
_procureNext = crop;
}
}
public void updateShowNpcCrest()
{
Connection con = null;
PreparedStatement statement;
try
{
con = (Connection) L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("UPDATE castle SET showNpcCrest = ? WHERE id = ?");
statement.setString(1, String.valueOf(getShowNpcCrest()));
statement.setInt(2, getCastleId());
statement.execute();
statement.close();
}
catch (Exception e)
{
_log.info("Error saving showNpcCrest for castle " + getName() + ": " + e.getMessage());
}
finally
{
try
{
con.close();
}
catch (Exception e)
{
}
}
}
public synchronized SeedProduction getSeed(int seedId, int period)
{
for (SeedProduction seed : getSeedProduction(period))
{
if (seed.getId() == seedId)
{
return seed;
}
}
return null;
}
public synchronized CropProcure getCrop(int cropId, int period)
{
for (CropProcure crop : getCropProcure(period) )
{
if (crop.getId() == cropId)
{
return crop;
}
}
return null;
}
public int getCropRewardType(int crop)
{
int rw = 0;
for(CropProcure cp : _procure)
if(cp.getId() == crop)
rw = cp.getReward();
return rw;
}
public int getManorCost (int period)
{
FastList<CropProcure> procure;
FastList<SeedProduction> production;
if (period == CastleManorManager.PERIOD_CURRENT)
{
procure = _procure;
production = _production;
}
else
{
procure = _procureNext;
production = _productionNext;
}
int total = 0;
if (production != null)
{
for (SeedProduction seed : production)
{
total += L2Manor.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()
{
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement(CASTLE_MANOR_DELETE_PRODUCTION);
statement.setInt(1, getCastleId());
statement.execute();
statement.close();
if (_production != null)
{
int count = 0;
String query = "INSERT INTO castle_manor_production VALUES ";
String values[] = new String[_production.size()];
for(SeedProduction s : _production)
{
values[count] = "("+getCastleId()+","+s.getId()+","+s.getCanProduce()+","+s.getStartProduce()+","+s.getPrice()+","+CastleManorManager.PERIOD_CURRENT+")";
count++;
}
if (values.length > 0)
{
query += values[0];
for (int i=1; i<values.length; i++)
{
query += "," + values;
}
statement = con.prepareStatement(query);
statement.execute();
statement.close();
}
}
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] = "("+getCastleId()+","+s.getId()+","+s.getCanProduce()+","+s.getStartProduce()+","+s.getPrice()+","+CastleManorManager.PERIOD_NEXT+")";
count++;
}
if (values.length > 0)
{
query += values[0];
for (int i=1;i<values.length;i++)
{
query += "," + values;
}
statement = con.prepareStatement(query);
statement.execute();
statement.close();
}
}
}
catch (Exception e)
{
_log.info("Error adding seed production data for castle " + getName() +": " + e.getMessage());
}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}
//save manor production data for specified period
public void saveSeedData(int period)
{
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement(CASTLE_MANOR_DELETE_PRODUCTION_PERIOD);
statement.setInt(1, getCastleId());
statement.setInt(2, period);
statement.execute();
statement.close();
FastList<SeedProduction> prod = null;
prod = getSeedProduction(period);
if (prod != null)
{
int count = 0;
String query = "INSERT INTO castle_manor_production VALUES ";
String values[] = new String[prod.size()];
for(SeedProduction s : prod)
{
values[count] = "("+getCastleId()+","+s.getId()+","+s.getCanProduce()+","+s.getStartProduce()+","+s.getPrice()+","+period+")";
count++;
}
if (values.length > 0)
{
query += values[0];
for (int i=1;i<values.length;i++)
{
query += "," + values;
}
statement = con.prepareStatement(query);
statement.execute();
statement.close();
}
}
} catch (Exception e)
{
_log.info("Error adding seed production data for castle " + getName() +": " + e.getMessage());
}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}
//save crop procure data
public void saveCropData()
{
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement(CASTLE_MANOR_DELETE_PROCURE);
statement.setInt(1, getCastleId());
statement.execute();
statement.close();
if (_procure != null)
{
int count = 0;
String query = "INSERT INTO castle_manor_procure VALUES ";
String values[] = new String[_procure.size()];
for (CropProcure cp : _procure)
{
values[count] = "("+getCastleId()+","+cp.getId()+","+cp.getAmount()+","+cp.getStartAmount()+","+cp.getPrice()+","+cp.getReward()+","+CastleManorManager.PERIOD_CURRENT+")";
count++;
}
if (values.length > 0)
{
query += values[0];
for (int i=1;i<values.length;i++)
{
query += "," + values;
}
statement = con.prepareStatement(query);
statement.execute();
statement.close();
}
}
if (_procureNext != null)
{
int count = 0;
String query = "INSERT INTO castle_manor_procure VALUES ";
String values[] = new String[_procureNext.size()];
for (CropProcure cp : _procureNext)
{
values[count] = "("+getCastleId()+","+cp.getId()+","+cp.getAmount()+","+cp.getStartAmount()+","+cp.getPrice()+","+cp.getReward()+","+CastleManorManager.PERIOD_NEXT+")";
count++;
}
if (values.length > 0)
{
query += values[0];
for (int i=1;i<values.length;i++)
{
query += "," + values;
}
statement = con.prepareStatement(query);
statement.execute();
statement.close();
}
}
}
catch (Exception e)
{
_log.info("Error adding crop data for castle " + getName() +": " + e.getMessage());
}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}
// save crop procure data for specified period
public void saveCropData(int period)
{
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement(CASTLE_MANOR_DELETE_PROCURE_PERIOD);
statement.setInt(1, getCastleId());
statement.setInt(2, period);
statement.execute();
statement.close();
FastList<CropProcure> proc = null;
proc = getCropProcure(period);
if (proc != null)
{
int count = 0;
String query = "INSERT INTO castle_manor_procure VALUES ";
String values[] = new String[proc.size()];
for (CropProcure cp : proc)
{
values[count] = "("+getCastleId()+","+cp.getId()+","+cp.getAmount()+","+cp.getStartAmount()+","+cp.getPrice()+","+cp.getReward()+","+period+")";
count++;
}
if (values.length > 0)
{
query += values[0];
for (int i=1;i<values.length;i++)
{
query += "," + values;
}
statement = con.prepareStatement(query);
statement.execute();
statement.close();
}
}
}
catch (Exception e)
{
_log.info("Error adding crop data for castle " + getName() +": " + e.getMessage());
}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}
public void updateCrop (int cropId, int amount, int period)
{
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement(CASTLE_UPDATE_CROP);
statement.setInt(1, amount);
statement.setInt(2, cropId);
statement.setInt(3, getCastleId());
statement.setInt(4, period);
statement.execute();
}
catch (Exception e)
{
_log.info("Error adding crop data for castle " + getName() +": " + e.getMessage());
}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}
public void updateSeed (int seedId, int amount, int period)
{
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement(CASTLE_UPDATE_SEED);
statement.setInt(1, amount);
statement.setInt(2, seedId);
statement.setInt(3, getCastleId());
statement.setInt(4, period);
statement.execute();
}
catch (Exception e)
{
_log.info("Error adding seed production data for castle " + getName() +": " + e.getMessage());
}
finally
{
DatabaseUtils.closeDatabaseCS(con, statement);
}
}
public boolean isNextPeriodApproved()
{
return _isNextPeriodApproved;
}
public void setNextPeriodApproved(boolean val)
{
_isNextPeriodApproved = val;
}
public void updateClansReputation()
{
if (_formerOwner != null )
{
if (_formerOwner != ClanTable.getInstance().getClan(getOwnerId()))
{
int maxreward = Math.max(0,_formerOwner.getReputationScore());
_formerOwner.setReputationScore(_formerOwner.getReputationScore()-1000, true);
L2Clan owner = ClanTable.getInstance().getClan(getOwnerId());
if (owner != null)
{
owner.setReputationScore(owner.getReputationScore()+Math.min(1000,maxreward), true);
owner.broadcastToOnlineMembers(new PledgeShowInfoUpdate(owner));
}
}
else
{
_formerOwner.setReputationScore(_formerOwner.getReputationScore()+500, true);
}
_formerOwner.broadcastToOnlineMembers(new PledgeShowInfoUpdate(_formerOwner));
}
else
{
L2Clan owner = ClanTable.getInstance().getClan(getOwnerId());
if (owner != null)
{
owner.setReputationScore(owner.getReputationScore()+1000, true);
owner.broadcastToOnlineMembers(new PledgeShowInfoUpdate(owner));
}
}
}
}
все что выделено красным я добавлял сам =)