Guest User

Untitled

a guest
Jul 24th, 2016
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 229.49 KB | None | 0 0
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.model.actor;
  16.  
  17. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
  18. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_FOLLOW;
  19.  
  20. import java.util.Collection;
  21. import java.util.Collections;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.concurrent.Future;
  25. import java.util.logging.Level;
  26. import java.util.logging.Logger;
  27.  
  28. import javolution.util.FastList;
  29. import javolution.util.FastMap;
  30. import net.sf.l2j.Config;
  31. import net.sf.l2j.gameserver.GameTimeController;
  32. import net.sf.l2j.gameserver.GeoData;
  33. import net.sf.l2j.gameserver.ThreadPoolManager;
  34. import net.sf.l2j.gameserver.ai.CtrlEvent;
  35. import net.sf.l2j.gameserver.ai.CtrlIntention;
  36. import net.sf.l2j.gameserver.ai.L2AttackableAI;
  37. import net.sf.l2j.gameserver.ai.L2CharacterAI;
  38. import net.sf.l2j.gameserver.datatables.DoorTable;
  39. import net.sf.l2j.gameserver.datatables.MapRegionTable;
  40. import net.sf.l2j.gameserver.datatables.SkillTable;
  41. import net.sf.l2j.gameserver.datatables.MapRegionTable.TeleportWhereType;
  42. import net.sf.l2j.gameserver.handler.ISkillHandler;
  43. import net.sf.l2j.gameserver.handler.SkillHandler;
  44. import net.sf.l2j.gameserver.instancemanager.DimensionalRiftManager;
  45. import net.sf.l2j.gameserver.instancemanager.InstanceManager;
  46. import net.sf.l2j.gameserver.instancemanager.TownManager;
  47. import net.sf.l2j.gameserver.model.ChanceSkillList;
  48. import net.sf.l2j.gameserver.model.CharEffectList;
  49. import net.sf.l2j.gameserver.model.FusionSkill;
  50. import net.sf.l2j.gameserver.model.IChanceSkillTrigger;
  51. import net.sf.l2j.gameserver.model.L2CharPosition;
  52. import net.sf.l2j.gameserver.model.L2Effect;
  53. import net.sf.l2j.gameserver.model.L2ItemInstance;
  54. import net.sf.l2j.gameserver.model.L2Object;
  55. import net.sf.l2j.gameserver.model.L2Party;
  56. import net.sf.l2j.gameserver.model.L2Skill;
  57. import net.sf.l2j.gameserver.model.L2World;
  58. import net.sf.l2j.gameserver.model.L2WorldRegion;
  59. import net.sf.l2j.gameserver.model.Location;
  60. import net.sf.l2j.gameserver.model.L2Skill.SkillTargetType;
  61. import net.sf.l2j.gameserver.model.actor.instance.L2AirShipInstance;
  62. import net.sf.l2j.gameserver.model.actor.instance.L2BoatInstance;
  63. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  64. import net.sf.l2j.gameserver.model.actor.instance.L2MinionInstance;
  65. import net.sf.l2j.gameserver.model.actor.instance.L2NpcWalkerInstance;
  66. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  67. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  68. import net.sf.l2j.gameserver.model.actor.instance.L2RiftInvaderInstance;
  69. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance.SkillDat;
  70. import net.sf.l2j.gameserver.model.actor.knownlist.CharKnownList;
  71. import net.sf.l2j.gameserver.model.actor.position.CharPosition;
  72. import net.sf.l2j.gameserver.model.actor.stat.CharStat;
  73. import net.sf.l2j.gameserver.model.actor.status.CharStatus;
  74. import net.sf.l2j.gameserver.model.events.CoastGuard;
  75. import net.sf.l2j.gameserver.model.events.CoastGuard.EventState;
  76. import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  77. import net.sf.l2j.gameserver.model.quest.Quest;
  78. import net.sf.l2j.gameserver.network.SystemMessageId;
  79. import net.sf.l2j.gameserver.network.serverpackets.AbstractNpcInfo;
  80. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  81. import net.sf.l2j.gameserver.network.serverpackets.Attack;
  82. import net.sf.l2j.gameserver.network.serverpackets.ChangeMoveType;
  83. import net.sf.l2j.gameserver.network.serverpackets.ChangeWaitType;
  84. import net.sf.l2j.gameserver.network.serverpackets.FlyToLocation;
  85. import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
  86. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillCanceld;
  87. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillLaunched;
  88. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  89. import net.sf.l2j.gameserver.network.serverpackets.MoveToLocation;
  90. import net.sf.l2j.gameserver.network.serverpackets.Revive;
  91. import net.sf.l2j.gameserver.network.serverpackets.ServerObjectInfo;
  92. import net.sf.l2j.gameserver.network.serverpackets.SetupGauge;
  93. import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  94. import net.sf.l2j.gameserver.network.serverpackets.StopMove;
  95. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  96. import net.sf.l2j.gameserver.network.serverpackets.TeleportToLocation;
  97. import net.sf.l2j.gameserver.network.serverpackets.ValidateLocation;
  98. import net.sf.l2j.gameserver.network.serverpackets.FlyToLocation.FlyType;
  99. import net.sf.l2j.gameserver.pathfinding.AbstractNodeLoc;
  100. import net.sf.l2j.gameserver.pathfinding.PathFinding;
  101. import net.sf.l2j.gameserver.skills.AbnormalEffect;
  102. import net.sf.l2j.gameserver.skills.Calculator;
  103. import net.sf.l2j.gameserver.skills.Formulas;
  104. import net.sf.l2j.gameserver.skills.Stats;
  105. import net.sf.l2j.gameserver.skills.effects.EffectChanceSkillTrigger;
  106. import net.sf.l2j.gameserver.skills.funcs.Func;
  107. import net.sf.l2j.gameserver.skills.l2skills.L2SkillAgathion;
  108. import net.sf.l2j.gameserver.skills.l2skills.L2SkillMount;
  109. import net.sf.l2j.gameserver.skills.l2skills.L2SkillSummon;
  110. import net.sf.l2j.gameserver.templates.chars.L2CharTemplate;
  111. import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
  112. import net.sf.l2j.gameserver.templates.item.L2Weapon;
  113. import net.sf.l2j.gameserver.templates.item.L2WeaponType;
  114. import net.sf.l2j.gameserver.templates.skills.L2EffectType;
  115. import net.sf.l2j.gameserver.templates.skills.L2SkillType;
  116. import net.sf.l2j.gameserver.util.Util;
  117. import net.sf.l2j.util.Point3D;
  118. import net.sf.l2j.util.Rnd;
  119. /**
  120. * Mother class of all character objects of the world (PC, NPC...)<BR><BR>
  121. *
  122. * L2Character :<BR><BR>
  123. * <li>L2CastleGuardInstance</li>
  124. * <li>L2DoorInstance</li>
  125. * <li>L2NpcInstance</li>
  126. * <li>L2PlayableInstance </li><BR><BR>
  127. *
  128. *
  129. * <B><U> Concept of L2CharTemplate</U> :</B><BR><BR>
  130. * Each L2Character owns generic and static properties (ex : all Keltir have the same number of HP...).
  131. * All of those properties are stored in a different template for each type of L2Character.
  132. * Each template is loaded once in the server cache memory (reduce memory use).
  133. * When a new instance of L2Character is spawned, server just create a link between the instance and the template.
  134. * This link is stored in <B>_template</B><BR><BR>
  135. *
  136. *
  137. * @version $Revision: 1.53.2.45.2.34 $ $Date: 2005/04/11 10:06:08 $
  138. */
  139. public abstract class L2Character extends L2Object
  140. {
  141. public static final Logger _log = Logger.getLogger(L2Character.class.getName());
  142.  
  143. // =========================================================
  144. // Data Field
  145. private List<L2Character> _attackByList;
  146. private volatile boolean _isCastingNow = false;
  147. private volatile boolean _isCastingSimultaneouslyNow = false;
  148. private L2Skill _lastSkillCast;
  149. private L2Skill _lastSimultaneousSkillCast;
  150. private boolean _isAfraid = false; // Flee in a random direction
  151. private boolean _isConfused = false; // Attack anyone randomly
  152. private boolean _isMuted = false; // Cannot use magic
  153. private boolean _isPhysicalMuted = false; // Cannot use physical skills
  154. private boolean _isPhysicalAttackMuted = false; // Cannot use attack
  155. private boolean _isDead = false;
  156. private boolean _isImmobilized = false;
  157. private boolean _isOverloaded = false; // the char is carrying too much
  158. private boolean _isParalyzed = false;
  159. private boolean _isDisarmed = false;
  160. private boolean _isPendingRevive = false;
  161. private boolean _isRooted = false; // Cannot move until root timed out
  162. private boolean _isRunning = false;
  163. private boolean _isNoRndWalk = false; // Is no random walk
  164. private boolean _isImmobileUntilAttacked = false; // Is in immobile until attacked.
  165. private boolean _isSleeping = false; // Cannot move/attack until sleep timed out or monster is attacked
  166. private boolean _isStunned = false; // Cannot move/attack until stun timed out
  167. private boolean _isBetrayed = false; // Betrayed by own summon
  168. protected boolean _showSummonAnimation = false;
  169. protected boolean _isTeleporting = false;
  170. private L2Character _lastBuffer = null;
  171. protected boolean _isInvul = false;
  172. protected L2Effect _invulEffect = null;
  173. private int _lastHealAmount = 0;
  174. private CharStat _stat;
  175. private CharStatus _status;
  176. private L2CharTemplate _template; // The link on the L2CharTemplate object containing generic and static properties of this L2Character type (ex : Max HP, Speed...)
  177. private String _title;
  178. private String _aiClass = "default";
  179. private double _hpUpdateIncCheck = .0;
  180. private double _hpUpdateDecCheck = .0;
  181. private double _hpUpdateInterval = .0;
  182. private boolean _champion = false;
  183. /** Table of Calculators containing all used calculator */
  184. private Calculator[] _calculators;
  185.  
  186. /** FastMap(Integer, L2Skill) containing all skills of the L2Character */
  187. private final Map<Integer, L2Skill> _skills;
  188. /** FastMap containing the active chance skills on this character */
  189. protected ChanceSkillList _chanceSkills;
  190.  
  191. /** Current force buff this caster is casting to a target */
  192. protected FusionSkill _fusionSkill;
  193.  
  194. /** Zone system */
  195. public static final byte ZONE_PVP = 0;
  196. public static final byte ZONE_PEACE = 1;
  197. public static final byte ZONE_SIEGE = 2;
  198. public static final byte ZONE_MOTHERTREE = 3;
  199. public static final byte ZONE_CLANHALL = 4;
  200. public static final byte ZONE_LANDING = 5;
  201. public static final byte ZONE_NOLANDING = 6;
  202. public static final byte ZONE_WATER = 7;
  203. public static final byte ZONE_JAIL = 8;
  204. public static final byte ZONE_MONSTERTRACK = 9;
  205. public static final byte ZONE_CASTLE = 10;
  206. public static final byte ZONE_SWAMP = 11;
  207. public static final byte ZONE_NOSUMMONFRIEND = 12;
  208. public static final byte ZONE_FORT = 13;
  209. public static final byte ZONE_NOSTORE = 14;
  210. public static final byte ZONE_TOWN = 15;
  211. public static final byte ZONE_SCRIPT = 16;
  212. public static final byte ZONE_NOHQ = 17;
  213.  
  214. private final byte[] _zones = new byte[18];
  215. protected byte _zoneValidateCounter = 4;
  216.  
  217. private boolean _isRaid = false;
  218.  
  219. private boolean _isFlying;
  220.  
  221. /**
  222. * Returns character inventory, default null, overridden in L2Playable types and in L2NPcInstance
  223. */
  224. public Inventory getInventory()
  225. {
  226. return null;
  227. }
  228. public boolean destroyItemByItemId(String process, int itemId, long count, L2Object reference, boolean sendMessage)
  229. {
  230. // Default: NPCs consume virtual items for their skills
  231. // TODO: should be logged if even happens.. should be false
  232. return true;
  233. }
  234. public boolean destroyItem(String process, int objectId, long count, L2Object reference, boolean sendMessage)
  235. {
  236. // Default: NPCs consume virtual items for their skills
  237. // TODO: should be logged if even happens.. should be false
  238. return true;
  239. }
  240.  
  241. /**
  242. *
  243. * @param zone
  244. * @return
  245. */
  246. public final boolean isInsideZone(final byte zone)
  247. {
  248. switch (zone)
  249. {
  250. case ZONE_PVP:
  251. if (InstanceManager.getInstance().getInstance(this.getInstanceId()).isPvPInstance())
  252. return true;
  253. return _zones[ZONE_PVP] > 0 && _zones[ZONE_PEACE] == 0;
  254. case ZONE_PEACE:
  255. if (InstanceManager.getInstance().getInstance(this.getInstanceId()).isPvPInstance())
  256. return false;
  257. }
  258. return _zones[zone] > 0;
  259. }
  260.  
  261. /**
  262. *
  263. * @param zone
  264. * @param state
  265. */
  266. public final void setInsideZone(final byte zone, final boolean state)
  267. {
  268. if (state)
  269. _zones[zone]++;
  270. else
  271. {
  272. _zones[zone]--;
  273. if (_zones[zone] < 0)
  274. _zones[zone] = 0;
  275. }
  276. }
  277.  
  278. /**
  279. * This will return true if the player is transformed,<br>
  280. * but if the player is not transformed it will return false.
  281. * @return transformation status
  282. */
  283. public boolean isTransformed()
  284. {
  285. return false;
  286. }
  287.  
  288. /**
  289. * This will untransform a player if they are an instance of L2Pcinstance
  290. * and if they are transformed.
  291. * @return untransform
  292. */
  293. public void untransform()
  294. {
  295. // Just a place holder
  296. }
  297.  
  298. /**
  299. * This will return true if the player is GM,<br>
  300. * but if the player is not GM it will return false.
  301. * @return GM status
  302. */
  303. public boolean isGM()
  304. {
  305. return false;
  306. }
  307.  
  308. // =========================================================
  309. // Constructor
  310. /**
  311. * Constructor of L2Character.<BR><BR>
  312. *
  313. * <B><U> Concept</U> :</B><BR><BR>
  314. * Each L2Character owns generic and static properties (ex : all Keltir have the same number of HP...).
  315. * All of those properties are stored in a different template for each type of L2Character.
  316. * Each template is loaded once in the server cache memory (reduce memory use).
  317. * When a new instance of L2Character is spawned, server just create a link between the instance and the template
  318. * This link is stored in <B>_template</B><BR><BR>
  319. *
  320. * <B><U> Actions</U> :</B><BR><BR>
  321. * <li>Set the _template of the L2Character </li>
  322. * <li>Set _overloaded to false (the charcater can take more items)</li><BR><BR>
  323. *
  324. * <li>If L2Character is a L2NPCInstance, copy skills from template to object</li>
  325. * <li>If L2Character is a L2NPCInstance, link _calculators to NPC_STD_CALCULATOR</li><BR><BR>
  326. *
  327. * <li>If L2Character is NOT a L2NPCInstance, create an empty _skills slot</li>
  328. * <li>If L2Character is a L2PcInstance or L2Summon, copy basic Calculator set to object</li><BR><BR>
  329. *
  330. * @param objectId Identifier of the object to initialized
  331. * @param template The L2CharTemplate to apply to the object
  332. */
  333. public L2Character(int objectId, L2CharTemplate template)
  334. {
  335. super(objectId);
  336. initCharStat();
  337. initCharStatus();
  338.  
  339. // Set its template to the new L2Character
  340. _template = template;
  341.  
  342. if (template != null && this instanceof L2Npc)
  343. {
  344. // Copy the Standard Calcultors of the L2NPCInstance in _calculators
  345. if (this instanceof L2DoorInstance)
  346. _calculators = Formulas.getStdDoorCalculators();
  347. else
  348. _calculators = NPC_STD_CALCULATOR;
  349.  
  350. // Copy the skills of the L2NPCInstance from its template to the L2Character Instance
  351. // The skills list can be affected by spell effects so it's necessary to make a copy
  352. // to avoid that a spell affecting a L2NPCInstance, affects others L2NPCInstance of the same type too.
  353. _skills = ((L2NpcTemplate)template).getSkills();
  354. if (_skills != null)
  355. {
  356. for(Map.Entry<Integer, L2Skill> skill : _skills.entrySet())
  357. addStatFuncs(skill.getValue().getStatFuncs(null, this));
  358. }
  359. }
  360. else
  361. {
  362. // If L2Character is a L2PcInstance or a L2Summon, create the basic calculator set
  363. _calculators = new Calculator[Stats.NUM_STATS];
  364.  
  365. if (this instanceof L2Summon)
  366. {
  367. // Copy the skills of the L2Summon from its template to the L2Character Instance
  368. // The skills list can be affected by spell effects so it's necessary to make a copy
  369. // to avoid that a spell affecting a L2Summon, affects others L2Summon of the same type too.
  370. _skills = ((L2NpcTemplate)template).getSkills();
  371. if (_skills != null)
  372. {
  373. for(Map.Entry<Integer, L2Skill> skill : _skills.entrySet())
  374. addStatFuncs(skill.getValue().getStatFuncs(null, this));
  375. }
  376. }
  377. else
  378. {
  379. // Initialize the FastMap _skills to null
  380. _skills = new FastMap<Integer,L2Skill>().setShared(true);
  381. }
  382.  
  383. Formulas.addFuncsToNewCharacter(this);
  384. }
  385.  
  386. setIsInvul(true);
  387. }
  388.  
  389. protected void initCharStatusUpdateValues()
  390. {
  391. _hpUpdateInterval = getMaxHp()/352.0; // MAX_HP div MAX_HP_BAR_PX
  392. _hpUpdateIncCheck = getMaxHp();
  393. _hpUpdateDecCheck = getMaxHp()-_hpUpdateInterval;
  394. }
  395.  
  396. // =========================================================
  397. // Event - Public
  398. /**
  399. * Remove the L2Character from the world when the decay task is launched.<BR><BR>
  400. *
  401. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T REMOVE the object from _allObjects of L2World </B></FONT><BR>
  402. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND Server->Client packets to players</B></FONT><BR><BR>
  403. *
  404. */
  405. public void onDecay()
  406. {
  407. L2WorldRegion reg = getWorldRegion();
  408. decayMe();
  409. if(reg != null) reg.removeFromZones(this);
  410. _effects.clear();
  411. }
  412.  
  413. @Override
  414. public void onSpawn()
  415. {
  416. super.onSpawn();
  417. this.revalidateZone(true);
  418. }
  419.  
  420. public void onTeleported()
  421. {
  422. if (!isTeleporting())
  423. return;
  424. if (this instanceof L2Summon)
  425. {
  426. ((L2Summon)this).getOwner().sendPacket(new TeleportToLocation(this, getPosition().getX(), getPosition().getY(), getPosition().getZ(), getPosition().getHeading()));
  427.  
  428. }
  429. spawnMe(getPosition().getX(), getPosition().getY(), getPosition().getZ());
  430.  
  431. setIsTeleporting(false);
  432.  
  433. if (_isPendingRevive)
  434. doRevive();
  435. }
  436.  
  437. // =========================================================
  438. // Method - Public
  439. /**
  440. * Add L2Character instance that is attacking to the attacker list.<BR><BR>
  441. * @param player The L2Character that attacks this one
  442. */
  443. public void addAttackerToAttackByList (L2Character player)
  444. {
  445. if (player == null || player == this || getAttackByList() == null || getAttackByList().contains(player)) return;
  446. getAttackByList().add(player);
  447. }
  448.  
  449. /**
  450. * Send a packet to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character.<BR><BR>
  451. *
  452. * <B><U> Concept</U> :</B><BR><BR>
  453. * L2PcInstance in the detection area of the L2Character are identified in <B>_knownPlayers</B>.
  454. * In order to inform other players of state modification on the L2Character, server just need to go through _knownPlayers to send Server->Client Packet<BR><BR>
  455. *
  456. */
  457. public void broadcastPacket(L2GameServerPacket mov)
  458. {
  459. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  460. //synchronized (getKnownList().getKnownPlayers())
  461. {
  462. for (L2PcInstance player : plrs)
  463. player.sendPacket(mov);
  464. }
  465. }
  466.  
  467. /**
  468. * Send a packet to the L2Character AND to all L2PcInstance in the radius (max knownlist radius) from the L2Character.<BR><BR>
  469. *
  470. * <B><U> Concept</U> :</B><BR><BR>
  471. * L2PcInstance in the detection area of the L2Character are identified in <B>_knownPlayers</B>.
  472. * In order to inform other players of state modification on the L2Character, server just need to go through _knownPlayers to send Server->Client Packet<BR><BR>
  473. *
  474. */
  475. public void broadcastPacket(L2GameServerPacket mov, int radiusInKnownlist)
  476. {
  477. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  478. //synchronized (getKnownList().getKnownPlayers())
  479. {
  480. for (L2PcInstance player : plrs)
  481. {
  482. if (isInsideRadius(player, radiusInKnownlist, false, false))
  483. player.sendPacket(mov);
  484. }
  485. }
  486. }
  487.  
  488. /**
  489. * Returns true if hp update should be done, false if not
  490. * @return boolean
  491. */
  492. protected boolean needHpUpdate(int barPixels)
  493. {
  494. double currentHp = getCurrentHp();
  495.  
  496. if (currentHp <= 1.0 || getMaxHp() < barPixels)
  497. return true;
  498.  
  499. if (currentHp <= _hpUpdateDecCheck || currentHp >= _hpUpdateIncCheck)
  500. {
  501. if (currentHp == getMaxHp())
  502. {
  503. _hpUpdateIncCheck = currentHp + 1;
  504. _hpUpdateDecCheck = currentHp - _hpUpdateInterval;
  505. }
  506. else
  507. {
  508. double doubleMulti = currentHp / _hpUpdateInterval;
  509. int intMulti = (int)doubleMulti;
  510.  
  511. _hpUpdateDecCheck = _hpUpdateInterval * (doubleMulti < intMulti ? intMulti-- : intMulti);
  512. _hpUpdateIncCheck = _hpUpdateDecCheck + _hpUpdateInterval;
  513. }
  514.  
  515. return true;
  516. }
  517.  
  518. return false;
  519. }
  520.  
  521. /**
  522. * Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform.<BR><BR>
  523. *
  524. * <B><U> Actions</U> :</B><BR><BR>
  525. * <li>Create the Server->Client packet StatusUpdate with current HP and MP </li>
  526. * <li>Send the Server->Client packet StatusUpdate with current HP and MP to all
  527. * L2Character called _statusListener that must be informed of HP/MP updates of this L2Character </li><BR><BR>
  528. *
  529. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND CP information</B></FONT><BR><BR>
  530. *
  531. * <B><U> Overridden in </U> :</B><BR><BR>
  532. * <li> L2PcInstance : Send current HP,MP and CP to the L2PcInstance and only current HP, MP and Level to all other L2PcInstance of the Party</li><BR><BR>
  533. *
  534. */
  535. public void broadcastStatusUpdate()
  536. {
  537. if (getStatus().getStatusListener().isEmpty()) return;
  538.  
  539. if (!needHpUpdate(352))
  540. return;
  541.  
  542. if (Config.DEBUG)
  543. _log.fine("Broadcast Status Update for " + getObjectId() + "(" + getName() + "). HP: " + getCurrentHp());
  544.  
  545. // Create the Server->Client packet StatusUpdate with current HP and MP
  546. StatusUpdate su = new StatusUpdate(getObjectId());
  547. su.addAttribute(StatusUpdate.CUR_HP, (int)getCurrentHp());
  548. su.addAttribute(StatusUpdate.CUR_MP, (int)getCurrentMp());
  549.  
  550. // Go through the StatusListener
  551. // Send the Server->Client packet StatusUpdate with current HP and MP
  552.  
  553. synchronized (getStatus().getStatusListener())
  554. {
  555. for (L2Character temp : getStatus().getStatusListener())
  556. {
  557. try { temp.sendPacket(su); } catch (NullPointerException e) {}
  558. }
  559. }
  560. }
  561.  
  562. /**
  563. * Not Implemented.<BR><BR>
  564. *
  565. * <B><U> Overridden in </U> :</B><BR><BR>
  566. * <li> L2PcInstance</li><BR><BR>
  567. */
  568. public void sendPacket(L2GameServerPacket mov)
  569. {
  570. // default implementation
  571. }
  572.  
  573. /**
  574. * Not Implemented.<BR><BR>
  575. *
  576. * <B><U> Overridden in </U> :</B><BR><BR>
  577. * <li> L2PcInstance</li><BR><BR>
  578. */
  579. public void sendMessage(String text)
  580. {
  581. // default implementation
  582. }
  583.  
  584. /**
  585. * Teleport a L2Character and its pet if necessary.<BR><BR>
  586. *
  587. * <B><U> Actions</U> :</B><BR><BR>
  588. * <li>Stop the movement of the L2Character</li>
  589. * <li>Set the x,y,z position of the L2Object and if necessary modify its _worldRegion</li>
  590. * <li>Send a Server->Client packet TeleportToLocationt to the L2Character AND to all L2PcInstance in its _KnownPlayers</li>
  591. * <li>Modify the position of the pet if necessary</li><BR><BR>
  592. *
  593. */
  594. public void teleToLocation(int x, int y, int z, int heading, boolean allowRandomOffset)
  595. {
  596. // Stop movement
  597. stopMove(null, false);
  598. abortAttack();
  599. abortCast();
  600.  
  601. setIsTeleporting(true);
  602. setTarget(null);
  603.  
  604. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  605.  
  606. if (Config.RESPAWN_RANDOM_ENABLED && allowRandomOffset)
  607. {
  608. x += Rnd.get(-Config.RESPAWN_RANDOM_MAX_OFFSET, Config.RESPAWN_RANDOM_MAX_OFFSET);
  609. y += Rnd.get(-Config.RESPAWN_RANDOM_MAX_OFFSET, Config.RESPAWN_RANDOM_MAX_OFFSET);
  610. }
  611.  
  612. z += 5;
  613.  
  614. if (Config.DEBUG)
  615. _log.fine("Teleporting to: " + x + ", " + y + ", " + z);
  616.  
  617. // remove the object from its old location
  618. decayMe();
  619.  
  620. // Send a Server->Client packet TeleportToLocationt to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  621. broadcastPacket(new TeleportToLocation(this, x, y, z, heading));
  622.  
  623. // Set the x,y,z position of the L2Object and if necessary modify its _worldRegion
  624. getPosition().setXYZ(x, y, z);
  625.  
  626. // temporary fix for heading on teleports
  627. if (heading != 0)
  628. getPosition().setHeading(heading);
  629.  
  630. if (!(this instanceof L2PcInstance)
  631. // allow recall of the detached characters
  632. || (((L2PcInstance)this).getClient() != null && ((L2PcInstance)this).getClient().isDetached()))
  633. onTeleported();
  634.  
  635. revalidateZone(true);
  636. }
  637.  
  638. public void teleToLocation(int x, int y, int z) { teleToLocation(x, y, z, getHeading(), false); }
  639.  
  640. public void teleToLocation(int x, int y, int z, boolean allowRandomOffset) { teleToLocation(x, y, z, getHeading(), allowRandomOffset); }
  641.  
  642. public void teleToLocation(Location loc, boolean allowRandomOffset)
  643. {
  644. int x = loc.getX();
  645. int y = loc.getY();
  646. int z = loc.getZ();
  647.  
  648. if (this instanceof L2PcInstance && DimensionalRiftManager.getInstance().checkIfInRiftZone(getX(), getY(), getZ(), true)) // true -> ignore waiting room :)
  649. {
  650. L2PcInstance player = (L2PcInstance)this;
  651. player.sendMessage("You have been sent to the waiting room.");
  652. if(player.isInParty() && player.getParty().isInDimensionalRift())
  653. {
  654. player.getParty().getDimensionalRift().usedTeleport(player);
  655. }
  656. int[] newCoords = DimensionalRiftManager.getInstance().getRoom((byte) 0, (byte) 0).getTeleportCoords();
  657. x = newCoords[0];
  658. y = newCoords[1];
  659. z = newCoords[2];
  660. }
  661. teleToLocation(x, y, z, getHeading(), allowRandomOffset);
  662. }
  663.  
  664. public void teleToLocation(TeleportWhereType teleportWhere) { teleToLocation(MapRegionTable.getInstance().getTeleToLocation(this, teleportWhere), true); }
  665.  
  666. // =========================================================
  667. // Method - Private
  668. /**
  669. * Launch a physical attack against a target (Simple, Bow, Pole or Dual).<BR><BR>
  670. *
  671. * <B><U> Actions</U> :</B><BR><BR>
  672. * <li>Get the active weapon (always equiped in the right hand) </li><BR><BR>
  673. * <li>If weapon is a bow, check for arrows, MP and bow re-use delay (if necessary, equip the L2PcInstance with arrows in left hand)</li>
  674. * <li>If weapon is a bow, consume MP and set the new period of bow non re-use </li><BR><BR>
  675. * <li>Get the Attack Speed of the L2Character (delay (in milliseconds) before next attack) </li>
  676. * <li>Select the type of attack to start (Simple, Bow, Pole or Dual) and verify if SoulShot are charged then start calculation</li>
  677. * <li>If the Server->Client packet Attack contains at least 1 hit, send the Server->Client packet Attack to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character</li>
  678. * <li>Notify AI with EVT_READY_TO_ACT</li><BR><BR>
  679. *
  680. * @param target The L2Character targeted
  681. *
  682. */
  683. protected void doAttack(L2Character target)
  684. {
  685. if (Config.DEBUG)
  686. _log.fine(getName()+" doAttack: target="+target);
  687.  
  688. if (CoastGuard.getInstance().getState() != EventState.INACTIVE && ((L2Attackable)this).getNpcId() == 65534)
  689. {
  690. getKnownList().addKnownObject(target);
  691. }
  692.  
  693. if (!isAlikeDead() && target != null)
  694. {
  695. if (this instanceof L2Npc && target.isAlikeDead()
  696. || !getKnownList().knowsObject(target))
  697. {
  698. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  699. sendPacket(ActionFailed.STATIC_PACKET);
  700. return;
  701. }
  702. else if (this instanceof L2PcInstance)
  703. {
  704. if (target.isDead())
  705. {
  706. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  707. sendPacket(ActionFailed.STATIC_PACKET);
  708. return;
  709. }
  710.  
  711. L2PcInstance actor = (L2PcInstance)this;
  712. /*
  713. * Players riding wyvern or with special (flying) transformations can do melee attacks, only with skills
  714. */
  715. if ((actor.isMounted() && actor.getMountNpcId() == 12621)
  716. || (actor.isTransformed() && !actor.getTransformation().canDoMeleeAttack()))
  717. {
  718. sendPacket(ActionFailed.STATIC_PACKET);
  719. return;
  720. }
  721. }
  722. }
  723.  
  724. if (isAttackingDisabled())
  725. return;
  726.  
  727. if (this instanceof L2PcInstance)
  728. {
  729. if (((L2PcInstance)this).inObserverMode())
  730. {
  731. sendPacket(new SystemMessage(SystemMessageId.OBSERVERS_CANNOT_PARTICIPATE));
  732. sendPacket(ActionFailed.STATIC_PACKET);
  733. return;
  734. }
  735.  
  736. if (target instanceof L2PcInstance)
  737. {
  738. if (((L2PcInstance)target).isCursedWeaponEquipped() && ((L2PcInstance)this).getLevel()<=20){
  739. ((L2PcInstance)this).sendMessage("Can't attack a cursed player when under level 21.");
  740. sendPacket(ActionFailed.STATIC_PACKET);
  741. return;
  742. }
  743.  
  744. if (((L2PcInstance)this).isCursedWeaponEquipped() && ((L2PcInstance)target).getLevel()<=20){
  745. ((L2PcInstance)this).sendMessage("Can't attack a newbie player using a cursed weapon.");
  746. sendPacket(ActionFailed.STATIC_PACKET);
  747. return;
  748. }
  749. }
  750. // Checking if target has moved to peace zone
  751. if (target.isInsidePeaceZone((L2PcInstance)this))
  752. {
  753. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  754. sendPacket(ActionFailed.STATIC_PACKET);
  755. return;
  756. }
  757. // TODO: unhardcode this to support boolean if with that weapon u can attack or not (for ex transform weapons)
  758. if (((L2PcInstance)this).getActiveWeaponItem() != null && ((L2PcInstance)this).getActiveWeaponItem().getItemId() == 9819)
  759. {
  760. sendPacket(new SystemMessage(SystemMessageId.THAT_WEAPON_CANT_ATTACK));
  761. sendPacket(ActionFailed.STATIC_PACKET);
  762. return;
  763. }
  764.  
  765. }
  766. else if (isInsidePeaceZone(this, target))
  767. {
  768. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  769. sendPacket(ActionFailed.STATIC_PACKET);
  770. return;
  771. }
  772.  
  773.  
  774. // Get the active weapon instance (always equiped in the right hand)
  775. L2ItemInstance weaponInst = getActiveWeaponInstance();
  776.  
  777. // Get the active weapon item corresponding to the active weapon instance (always equiped in the right hand)
  778. L2Weapon weaponItem = getActiveWeaponItem();
  779.  
  780. if (weaponItem != null && weaponItem.getItemType() == L2WeaponType.ROD)
  781. {
  782. // You can't make an attack with a fishing pole.
  783. sendPacket(new SystemMessage(SystemMessageId.CANNOT_ATTACK_WITH_FISHING_POLE));
  784. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  785.  
  786. sendPacket(ActionFailed.STATIC_PACKET);
  787. return;
  788. }
  789.  
  790. // GeoData Los Check here (or dz > 1000)
  791. if (!GeoData.getInstance().canSeeTarget(this, target))
  792. {
  793. sendPacket(new SystemMessage(SystemMessageId.CANT_SEE_TARGET));
  794. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  795. sendPacket(ActionFailed.STATIC_PACKET);
  796. return;
  797. }
  798.  
  799. // BOW and CROSSBOW checks
  800. if (weaponItem != null && !isTransformed())
  801. {
  802. if (weaponItem.getItemType() == L2WeaponType.BOW)
  803. {
  804. //Check for arrows and MP
  805. if (this instanceof L2PcInstance)
  806. {
  807. // Equip arrows needed in left hand and send a Server->Client packet ItemList to the L2PcINstance then return True
  808. if (!checkAndEquipArrows())
  809. {
  810. // Cancel the action because the L2PcInstance have no arrow
  811. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  812. sendPacket(ActionFailed.STATIC_PACKET);
  813. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ARROWS));
  814. return;
  815. }
  816.  
  817. // Verify if the bow can be use
  818. if (_disableBowAttackEndTime <= GameTimeController.getGameTicks())
  819. {
  820. // Verify if L2PcInstance owns enough MP
  821. int saMpConsume = (int)getStat().calcStat(Stats.MP_CONSUME, 0, null, null);
  822. int mpConsume = saMpConsume == 0 ? weaponItem.getMpConsume() : saMpConsume;
  823. mpConsume = (int)calcStat(Stats.BOW_MP_CONSUME_RATE, mpConsume, null, null);
  824.  
  825. if (getCurrentMp() < mpConsume)
  826. {
  827. // If L2PcInstance doesn't have enough MP, stop the attack
  828. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
  829. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_MP));
  830. sendPacket(ActionFailed.STATIC_PACKET);
  831. return;
  832. }
  833. // If L2PcInstance have enough MP, the bow consumes it
  834. if (mpConsume > 0)
  835. getStatus().reduceMp(mpConsume);
  836.  
  837. // Set the period of bow no re-use
  838. _disableBowAttackEndTime = 5 * GameTimeController.TICKS_PER_SECOND + GameTimeController.getGameTicks();
  839. }
  840. else
  841. {
  842. // Cancel the action because the bow can't be re-use at this moment
  843. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
  844.  
  845. sendPacket(ActionFailed.STATIC_PACKET);
  846. return;
  847. }
  848. }
  849. }
  850. if (weaponItem.getItemType() == L2WeaponType.CROSSBOW)
  851. {
  852. //Check for bolts
  853. if (this instanceof L2PcInstance)
  854. {
  855. // Checking if target has moved to peace zone - only for player-crossbow attacks at the moment
  856. // Other melee is checked in movement code and for offensive spells a check is done every time
  857. if (target.isInsidePeaceZone((L2PcInstance)this))
  858. {
  859. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  860. sendPacket(ActionFailed.STATIC_PACKET);
  861. return;
  862. }
  863.  
  864. // Equip bolts needed in left hand and send a Server->Client packet ItemList to the L2PcINstance then return True
  865. if (!checkAndEquipBolts())
  866. {
  867. // Cancel the action because the L2PcInstance have no arrow
  868. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  869. sendPacket(ActionFailed.STATIC_PACKET);
  870. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_BOLTS));
  871. return;
  872. }
  873.  
  874. // Verify if the crossbow can be use
  875. if (_disableCrossBowAttackEndTime <= GameTimeController.getGameTicks())
  876. {
  877. // Set the period of crossbow no re-use
  878. _disableCrossBowAttackEndTime = 5 * GameTimeController.TICKS_PER_SECOND + GameTimeController.getGameTicks();
  879. }
  880. else
  881. {
  882. // Cancel the action because the crossbow can't be re-use at this moment
  883. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
  884. sendPacket(ActionFailed.STATIC_PACKET);
  885. return;
  886. }
  887. }
  888. else if (this instanceof L2Npc)
  889. {
  890. if (_disableCrossBowAttackEndTime > GameTimeController.getGameTicks())
  891. return;
  892. }
  893. }
  894. }
  895.  
  896. // Add the L2PcInstance to _knownObjects and _knownPlayer of the target
  897. target.getKnownList().addKnownObject(this);
  898.  
  899. // Reduce the current CP if TIREDNESS configuration is activated
  900. if (Config.ALT_GAME_TIREDNESS)
  901. setCurrentCp(getCurrentCp() - 10);
  902.  
  903. // Recharge any active auto soulshot tasks for player (or player's summon if one exists).
  904. if (this instanceof L2PcInstance)
  905. ((L2PcInstance)this).rechargeAutoSoulShot(true, false, false);
  906. else if (this instanceof L2Summon)
  907. ((L2Summon)this).getOwner().rechargeAutoSoulShot(true, false, true);
  908.  
  909. // Verify if soulshots are charged.
  910. boolean wasSSCharged;
  911.  
  912. if (this instanceof L2Npc)
  913. wasSSCharged = ((L2Npc)this).rechargeAutoSoulShot(true, false);
  914. else if (this instanceof L2Summon && !(this instanceof L2PetInstance))
  915. wasSSCharged = (((L2Summon)this).getChargedSoulShot() != L2ItemInstance.CHARGED_NONE);
  916. else
  917. wasSSCharged = (weaponInst != null && weaponInst.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE);
  918.  
  919. // Get the Attack Speed of the L2Character (delay (in milliseconds) before next attack)
  920. int timeAtk = calculateTimeBetweenAttacks(target, weaponItem);
  921. // the hit is calculated to happen halfway to the animation - might need further tuning e.g. in bow case
  922. int timeToHit = timeAtk/2;
  923. _attackEndTime = GameTimeController.getGameTicks();
  924. _attackEndTime += (timeAtk / GameTimeController.MILLIS_IN_TICK);
  925. _attackEndTime -= 1;
  926.  
  927. int ssGrade = 0;
  928.  
  929. if (weaponItem != null)
  930. ssGrade = weaponItem.getItemGradeSPlus();
  931.  
  932. // Create a Server->Client packet Attack
  933. Attack attack = new Attack(this, target, wasSSCharged, ssGrade);
  934.  
  935. // Set the Attacking Body part to CHEST
  936. setAttackingBodypart();
  937. // Make sure that char is facing selected target
  938. // also works: setHeading(Util.convertDegreeToClientHeading(Util.calculateAngleFrom(this, target)));
  939. setHeading(Util.calculateHeadingFrom(this, target));
  940.  
  941. // Get the Attack Reuse Delay of the L2Weapon
  942. int reuse = calculateReuseTime(target, weaponItem);
  943. boolean hitted;
  944. // Select the type of attack to start
  945. if (weaponItem == null || isTransformed())
  946. hitted = doAttackHitSimple(attack, target, timeToHit);
  947. else if (weaponItem.getItemType() == L2WeaponType.BOW)
  948. hitted = doAttackHitByBow(attack, target, timeAtk, reuse);
  949. else if (weaponItem.getItemType() == L2WeaponType.CROSSBOW)
  950. hitted = doAttackHitByCrossBow(attack, target, timeAtk, reuse);
  951. else if (weaponItem.getItemType() == L2WeaponType.POLE)
  952. hitted = doAttackHitByPole(attack, target, timeToHit);
  953. else if (isUsingDualWeapon())
  954. hitted = doAttackHitByDual(attack, target, timeToHit);
  955. else
  956. hitted = doAttackHitSimple(attack, target, timeToHit);
  957.  
  958. // Flag the attacker if it's a L2PcInstance outside a PvP area
  959. L2PcInstance player = getActingPlayer();
  960.  
  961. if (player != null)
  962. {
  963. if (player.getPet() != target)
  964. player.updatePvPStatus(target);
  965. }
  966. // Check if hit isn't missed
  967. if (!hitted)
  968. // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  969. abortAttack();
  970. else
  971. {
  972. /* ADDED BY nexus - 2006-08-17
  973. *
  974. * As soon as we know that our hit landed, we must discharge any active soulshots.
  975. * This must be done so to avoid unwanted soulshot consumption.
  976. */
  977.  
  978. // If we didn't miss the hit, discharge the shoulshots, if any
  979. if (this instanceof L2Summon && !(this instanceof L2PetInstance))
  980. ((L2Summon)this).setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
  981. else
  982. if (weaponInst != null)
  983. weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  984.  
  985.  
  986. if (player != null)
  987. {
  988. if (player.isCursedWeaponEquipped())
  989. {
  990. // If hitted by a cursed weapon, Cp is reduced to 0
  991. if (!target.isInvul())
  992. target.setCurrentCp(0);
  993. } else if (player.isHero())
  994. {
  995. if (target instanceof L2PcInstance && ((L2PcInstance)target).isCursedWeaponEquipped())
  996. // If a cursed weapon is hitted by a Hero, Cp is reduced to 0
  997. target.setCurrentCp(0);
  998. }
  999. }
  1000. }
  1001.  
  1002. // If the Server->Client packet Attack contains at least 1 hit, send the Server->Client packet Attack
  1003. // to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  1004. if (attack.hasHits())
  1005. broadcastPacket(attack);
  1006.  
  1007. // Notify AI with EVT_READY_TO_ACT
  1008. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), timeAtk+reuse);
  1009. }
  1010.  
  1011. /**
  1012. * Launch a Bow attack.<BR><BR>
  1013. *
  1014. * <B><U> Actions</U> :</B><BR><BR>
  1015. * <li>Calculate if hit is missed or not </li>
  1016. * <li>Consume arrows </li>
  1017. * <li>If hit isn't missed, calculate if shield defense is efficient </li>
  1018. * <li>If hit isn't missed, calculate if hit is critical </li>
  1019. * <li>If hit isn't missed, calculate physical damages </li>
  1020. * <li>If the L2Character is a L2PcInstance, Send a Server->Client packet SetupGauge </li>
  1021. * <li>Create a new hit task with Medium priority</li>
  1022. * <li>Calculate and set the disable delay of the bow in function of the Attack Speed</li>
  1023. * <li>Add this hit to the Server-Client packet Attack </li><BR><BR>
  1024. *
  1025. * @param attack Server->Client packet Attack in which the hit will be added
  1026. * @param target The L2Character targeted
  1027. * @param sAtk The Attack Speed of the attacker
  1028. *
  1029. * @return True if the hit isn't missed
  1030. *
  1031. */
  1032. private boolean doAttackHitByBow(Attack attack, L2Character target, int sAtk, int reuse)
  1033. {
  1034. int damage1 = 0;
  1035. byte shld1 = 0;
  1036. boolean crit1 = false;
  1037.  
  1038. // Calculate if hit is missed or not
  1039. boolean miss1 = Formulas.calcHitMiss(this, target);
  1040.  
  1041. // Consume arrows
  1042. reduceArrowCount(false);
  1043.  
  1044. _move = null;
  1045.  
  1046. // Check if hit isn't missed
  1047. if (!miss1)
  1048. {
  1049. // Calculate if shield defense is efficient
  1050. shld1 = Formulas.calcShldUse(this, target);
  1051.  
  1052. // Calculate if hit is critical
  1053. crit1 = Formulas.calcCrit(getStat().getCriticalHit(target, null), target);
  1054.  
  1055. // Calculate physical damages
  1056. damage1 = (int)Formulas.calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
  1057. }
  1058.  
  1059. // Check if the L2Character is a L2PcInstance
  1060. if (this instanceof L2PcInstance)
  1061. {
  1062. // Send a system message
  1063. sendPacket(new SystemMessage(SystemMessageId.GETTING_READY_TO_SHOOT_AN_ARROW));
  1064.  
  1065. // Send a Server->Client packet SetupGauge
  1066. SetupGauge sg = new SetupGauge(SetupGauge.RED, sAtk+reuse);
  1067. sendPacket(sg);
  1068. }
  1069.  
  1070. // Create a new hit task with Medium priority
  1071. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
  1072.  
  1073. // Calculate and set the disable delay of the bow in function of the Attack Speed
  1074. _disableBowAttackEndTime = (sAtk+reuse)/GameTimeController.MILLIS_IN_TICK + GameTimeController.getGameTicks();
  1075.  
  1076. // Add this hit to the Server-Client packet Attack
  1077. attack.hit(attack.createHit(target, damage1, miss1, crit1, shld1));
  1078.  
  1079. // Return true if hit isn't missed
  1080. return !miss1;
  1081. }
  1082.  
  1083. /**
  1084. * Launch a CrossBow attack.<BR><BR>
  1085. *
  1086. * <B><U> Actions</U> :</B><BR><BR>
  1087. * <li>Calculate if hit is missed or not </li>
  1088. * <li>Consume bolts </li>
  1089. * <li>If hit isn't missed, calculate if shield defense is efficient </li>
  1090. * <li>If hit isn't missed, calculate if hit is critical </li>
  1091. * <li>If hit isn't missed, calculate physical damages </li>
  1092. * <li>If the L2Character is a L2PcInstance, Send a Server->Client packet SetupGauge </li>
  1093. * <li>Create a new hit task with Medium priority</li>
  1094. * <li>Calculate and set the disable delay of the crossbow in function of the Attack Speed</li>
  1095. * <li>Add this hit to the Server-Client packet Attack </li><BR><BR>
  1096. *
  1097. * @param attack Server->Client packet Attack in which the hit will be added
  1098. * @param target The L2Character targeted
  1099. * @param sAtk The Attack Speed of the attacker
  1100. *
  1101. * @return True if the hit isn't missed
  1102. *
  1103. */
  1104. private boolean doAttackHitByCrossBow(Attack attack, L2Character target, int sAtk, int reuse)
  1105. {
  1106. int damage1 = 0;
  1107. byte shld1 = 0;
  1108. boolean crit1 = false;
  1109.  
  1110. // Calculate if hit is missed or not
  1111. boolean miss1 = Formulas.calcHitMiss(this, target);
  1112.  
  1113. // Consume bolts
  1114. reduceArrowCount(true);
  1115.  
  1116. _move = null;
  1117.  
  1118. // Check if hit isn't missed
  1119. if (!miss1)
  1120. {
  1121. // Calculate if shield defense is efficient
  1122. shld1 = Formulas.calcShldUse(this, target);
  1123.  
  1124. // Calculate if hit is critical
  1125. crit1 = Formulas.calcCrit(getStat().getCriticalHit(target, null), target);
  1126.  
  1127. // Calculate physical damages
  1128. damage1 = (int)Formulas.calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
  1129. }
  1130.  
  1131. // Check if the L2Character is a L2PcInstance
  1132. if (this instanceof L2PcInstance)
  1133. {
  1134. // Send a system message
  1135. sendPacket(new SystemMessage(SystemMessageId.CROSSBOW_PREPARING_TO_FIRE));
  1136.  
  1137. // Send a Server->Client packet SetupGauge
  1138. SetupGauge sg = new SetupGauge(SetupGauge.RED, sAtk+reuse);
  1139. sendPacket(sg);
  1140. }
  1141.  
  1142. // Create a new hit task with Medium priority
  1143. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
  1144.  
  1145. // Calculate and set the disable delay of the bow in function of the Attack Speed
  1146. _disableCrossBowAttackEndTime = (sAtk+reuse)/GameTimeController.MILLIS_IN_TICK + GameTimeController.getGameTicks();
  1147.  
  1148. // Add this hit to the Server-Client packet Attack
  1149. attack.hit(attack.createHit(target, damage1, miss1, crit1, shld1));
  1150.  
  1151. // Return true if hit isn't missed
  1152. return !miss1;
  1153. }
  1154.  
  1155. /**
  1156. * Launch a Dual attack.<BR><BR>
  1157. *
  1158. * <B><U> Actions</U> :</B><BR><BR>
  1159. * <li>Calculate if hits are missed or not </li>
  1160. * <li>If hits aren't missed, calculate if shield defense is efficient </li>
  1161. * <li>If hits aren't missed, calculate if hit is critical </li>
  1162. * <li>If hits aren't missed, calculate physical damages </li>
  1163. * <li>Create 2 new hit tasks with Medium priority</li>
  1164. * <li>Add those hits to the Server-Client packet Attack </li><BR><BR>
  1165. *
  1166. * @param attack Server->Client packet Attack in which the hit will be added
  1167. * @param target The L2Character targeted
  1168. *
  1169. * @return True if hit 1 or hit 2 isn't missed
  1170. *
  1171. */
  1172. private boolean doAttackHitByDual(Attack attack, L2Character target, int sAtk)
  1173. {
  1174. int damage1 = 0;
  1175. int damage2 = 0;
  1176. byte shld1 = 0;
  1177. byte shld2 = 0;
  1178. boolean crit1 = false;
  1179. boolean crit2 = false;
  1180.  
  1181. // Calculate if hits are missed or not
  1182. boolean miss1 = Formulas.calcHitMiss(this, target);
  1183. boolean miss2 = Formulas.calcHitMiss(this, target);
  1184.  
  1185. // Check if hit 1 isn't missed
  1186. if (!miss1)
  1187. {
  1188. // Calculate if shield defense is efficient against hit 1
  1189. shld1 = Formulas.calcShldUse(this, target);
  1190.  
  1191. // Calculate if hit 1 is critical
  1192. crit1 = Formulas.calcCrit(getStat().getCriticalHit(target, null), target);
  1193.  
  1194. // Calculate physical damages of hit 1
  1195. damage1 = (int)Formulas.calcPhysDam(this, target, null, shld1, crit1, true, attack.soulshot);
  1196. damage1 /= 2;
  1197. }
  1198.  
  1199. // Check if hit 2 isn't missed
  1200. if (!miss2)
  1201. {
  1202. // Calculate if shield defense is efficient against hit 2
  1203. shld2 = Formulas.calcShldUse(this, target);
  1204.  
  1205. // Calculate if hit 2 is critical
  1206. crit2 = Formulas.calcCrit(getStat().getCriticalHit(target, null), target);
  1207.  
  1208. // Calculate physical damages of hit 2
  1209. damage2 = (int)Formulas.calcPhysDam(this, target, null, shld2, crit2, true, attack.soulshot);
  1210. damage2 /= 2;
  1211. }
  1212.  
  1213. // Create a new hit task with Medium priority for hit 1
  1214. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk/2);
  1215.  
  1216. // Create a new hit task with Medium priority for hit 2 with a higher delay
  1217. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage2, crit2, miss2, attack.soulshot, shld2), sAtk);
  1218.  
  1219. // Add those hits to the Server-Client packet Attack
  1220. attack.hit(attack.createHit(target, damage1, miss1, crit1, shld1),
  1221. attack.createHit(target, damage2, miss2, crit2, shld2));
  1222.  
  1223. // Return true if hit 1 or hit 2 isn't missed
  1224. return (!miss1 || !miss2);
  1225. }
  1226.  
  1227. /**
  1228. * Launch a Pole attack.<BR><BR>
  1229. *
  1230. * <B><U> Actions</U> :</B><BR><BR>
  1231. * <li>Get all visible objects in a spherical area near the L2Character to obtain possible targets </li>
  1232. * <li>If possible target is the L2Character targeted, launch a simple attack against it </li>
  1233. * <li>If possible target isn't the L2Character targeted but is attackable, launch a simple attack against it </li><BR><BR>
  1234. *
  1235. * @param attack Server->Client packet Attack in which the hit will be added
  1236. *
  1237. * @return True if one hit isn't missed
  1238. *
  1239. */
  1240. private boolean doAttackHitByPole(Attack attack, L2Character target, int sAtk)
  1241. {
  1242. double angleChar;
  1243. int maxRadius = getPhysicalAttackRange();
  1244. int maxAngleDiff = (int)getStat().calcStat(Stats.POWER_ATTACK_ANGLE, 120, null, null);
  1245.  
  1246. if (Config.DEBUG)
  1247. {
  1248. _log.info("doAttackHitByPole: Max radius = " + maxRadius);
  1249. _log.info("doAttackHitByPole: Max angle = " + maxAngleDiff);
  1250. }
  1251.  
  1252. // o1 x: 83420 y: 148158 (Giran)
  1253. // o2 x: 83379 y: 148081 (Giran)
  1254. // dx = -41
  1255. // dy = -77
  1256. // distance between o1 and o2 = 87.24
  1257. // arctan2 = -120 (240) degree (excel arctan2(dx, dy); java arctan2(dy, dx))
  1258. //
  1259. // o2
  1260. //
  1261. // o1 ----- (heading)
  1262. // In the diagram above:
  1263. // o1 has a heading of 0/360 degree from horizontal (facing East)
  1264. // Degree of o2 in respect to o1 = -120 (240) degree
  1265. //
  1266. // o2 / (heading)
  1267. // /
  1268. // o1
  1269. // In the diagram above
  1270. // o1 has a heading of -80 (280) degree from horizontal (facing north east)
  1271. // Degree of o2 in respect to 01 = -40 (320) degree
  1272.  
  1273. // Get char's heading degree
  1274. angleChar = Util.convertHeadingToDegree(getHeading());
  1275. int attackRandomCountMax = (int)getStat().calcStat(Stats.ATTACK_COUNT_MAX, 3, null, null) - 1;
  1276. int attackcount = 0;
  1277.  
  1278. if (angleChar <= 0)
  1279. angleChar += 360;
  1280. // ===========================================================
  1281.  
  1282. boolean hitted = doAttackHitSimple(attack, target, 100, sAtk);
  1283. double attackpercent = 85;
  1284. L2Character temp;
  1285. Collection<L2Object> objs = getKnownList().getKnownObjects().values();
  1286. //synchronized (getKnownList().getKnownObjects())
  1287. {
  1288. for (L2Object obj : objs)
  1289. {
  1290. if (obj == target)
  1291. continue; // do not hit twice
  1292. // Check if the L2Object is a L2Character
  1293. if (obj instanceof L2Character)
  1294. {
  1295. if (obj instanceof L2PetInstance
  1296. && this instanceof L2PcInstance
  1297. && ((L2PetInstance) obj).getOwner() == ((L2PcInstance) this))
  1298. continue;
  1299.  
  1300. if (!Util.checkIfInRange(maxRadius, this, obj, false))
  1301. continue;
  1302.  
  1303. // otherwise hit too high/low. 650 because mob z coord
  1304. // sometimes wrong on hills
  1305. if (Math.abs(obj.getZ() - getZ()) > 650)
  1306. continue;
  1307. if (!isFacing(obj, maxAngleDiff))
  1308. continue;
  1309.  
  1310. temp = (L2Character) obj;
  1311.  
  1312. // Launch a simple attack against the L2Character targeted
  1313. if (!temp.isAlikeDead())
  1314. {
  1315. attackcount += 1;
  1316. if (attackcount <= attackRandomCountMax)
  1317. {
  1318. if (temp == getAI().getAttackTarget()
  1319. || temp.isAutoAttackable(this))
  1320. {
  1321.  
  1322. hitted |= doAttackHitSimple(attack, temp, attackpercent, sAtk);
  1323. attackpercent /= 1.15;
  1324. }
  1325. }
  1326. }
  1327. }
  1328. }
  1329. }
  1330.  
  1331. // Return true if one hit isn't missed
  1332. return hitted;
  1333. }
  1334.  
  1335. /**
  1336. * Launch a simple attack.<BR><BR>
  1337. *
  1338. * <B><U> Actions</U> :</B><BR><BR>
  1339. * <li>Calculate if hit is missed or not </li>
  1340. * <li>If hit isn't missed, calculate if shield defense is efficient </li>
  1341. * <li>If hit isn't missed, calculate if hit is critical </li>
  1342. * <li>If hit isn't missed, calculate physical damages </li>
  1343. * <li>Create a new hit task with Medium priority</li>
  1344. * <li>Add this hit to the Server-Client packet Attack </li><BR><BR>
  1345. *
  1346. * @param attack Server->Client packet Attack in which the hit will be added
  1347. * @param target The L2Character targeted
  1348. *
  1349. * @return True if the hit isn't missed
  1350. *
  1351. */
  1352. private boolean doAttackHitSimple(Attack attack, L2Character target, int sAtk)
  1353. {
  1354. return doAttackHitSimple(attack, target, 100, sAtk);
  1355. }
  1356.  
  1357. private boolean doAttackHitSimple(Attack attack, L2Character target, double attackpercent, int sAtk)
  1358. {
  1359. int damage1 = 0;
  1360. byte shld1 = 0;
  1361. boolean crit1 = false;
  1362.  
  1363. // Calculate if hit is missed or not
  1364. boolean miss1 = Formulas.calcHitMiss(this, target);
  1365.  
  1366. // Check if hit isn't missed
  1367. if (!miss1)
  1368. {
  1369. // Calculate if shield defense is efficient
  1370. shld1 = Formulas.calcShldUse(this, target);
  1371.  
  1372. // Calculate if hit is critical
  1373. crit1 = Formulas.calcCrit(getStat().getCriticalHit(target, null), target);
  1374.  
  1375. // Calculate physical damages
  1376. damage1 = (int)Formulas.calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
  1377.  
  1378. if (attackpercent != 100)
  1379. damage1 = (int)(damage1*attackpercent/100);
  1380. }
  1381.  
  1382. // Create a new hit task with Medium priority
  1383. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
  1384.  
  1385. // Add this hit to the Server-Client packet Attack
  1386. attack.hit(attack.createHit(target, damage1, miss1, crit1, shld1));
  1387.  
  1388. // Return true if hit isn't missed
  1389. return !miss1;
  1390. }
  1391.  
  1392. /**
  1393. * Manage the casting task (casting and interrupt time, re-use delay...) and display the casting bar and animation on client.<BR><BR>
  1394. *
  1395. * <B><U> Actions</U> :</B><BR><BR>
  1396. * <li>Verify the possibilty of the the cast : skill is a spell, caster isn't muted... </li>
  1397. * <li>Get the list of all targets (ex : area effects) and define the L2Charcater targeted (its stats will be used in calculation)</li>
  1398. * <li>Calculate the casting time (base + modifier of MAtkSpd), interrupt time and re-use delay</li>
  1399. * <li>Send a Server->Client packet MagicSkillUser (to diplay casting animation), a packet SetupGauge (to display casting bar) and a system message </li>
  1400. * <li>Disable all skills during the casting time (create a task EnableAllSkills)</li>
  1401. * <li>Disable the skill during the re-use delay (create a task EnableSkill)</li>
  1402. * <li>Create a task MagicUseTask (that will call method onMagicUseTimer) to launch the Magic Skill at the end of the casting time</li><BR><BR>
  1403. *
  1404. * @param skill The L2Skill to use
  1405. *
  1406. */
  1407. public void doCast(L2Skill skill)
  1408. {
  1409. beginCast(skill, false);
  1410. }
  1411.  
  1412. public void doSimultaneousCast(L2Skill skill)
  1413. {
  1414. beginCast(skill, true);
  1415. }
  1416.  
  1417. private void beginCast(L2Skill skill, boolean simultaneously)
  1418. {
  1419. if (!checkDoCastConditions(skill))
  1420. {
  1421. if (simultaneously)
  1422. setIsCastingSimultaneouslyNow(false);
  1423. else
  1424. setIsCastingNow(false);
  1425. if (this instanceof L2PcInstance)
  1426. {
  1427. getAI().setIntention(AI_INTENTION_ACTIVE);
  1428. }
  1429. return;
  1430. }
  1431.  
  1432. //Recharge AutoSoulShot
  1433. if (skill.useSoulShot())
  1434. {
  1435. if (this instanceof L2Npc)
  1436. ((L2Npc)this).rechargeAutoSoulShot(true, false);
  1437. else if (this instanceof L2PcInstance)
  1438. ((L2PcInstance)this).rechargeAutoSoulShot(true, false, false);
  1439. else if (this instanceof L2Summon)
  1440. ((L2Summon)this).getOwner().rechargeAutoSoulShot(true, false, true);
  1441. }
  1442. else if (skill.useSpiritShot())
  1443. {
  1444. if (this instanceof L2PcInstance)
  1445. ((L2PcInstance)this).rechargeAutoSoulShot(false, true, false);
  1446. else if (this instanceof L2Summon)
  1447. ((L2Summon)this).getOwner().rechargeAutoSoulShot(false, true, true);
  1448. }
  1449.  
  1450. // Set the target of the skill in function of Skill Type and Target Type
  1451. L2Character target = null;
  1452. // Get all possible targets of the skill in a table in function of the skill target type
  1453. L2Object[] targets = skill.getTargetList(this);
  1454.  
  1455. boolean doit = false;
  1456.  
  1457. // AURA skills should always be using caster as target
  1458. switch (skill.getTargetType())
  1459. {
  1460. case TARGET_AURA:
  1461. case TARGET_FRONT_AURA:
  1462. case TARGET_BEHIND_AURA:
  1463. case TARGET_GROUND:
  1464. target = this;
  1465. break;
  1466. case TARGET_SELF:
  1467. case TARGET_PET:
  1468. case TARGET_SUMMON:
  1469. case TARGET_OWNER_PET:
  1470. case TARGET_PARTY:
  1471. case TARGET_CLAN:
  1472. case TARGET_PARTY_CLAN:
  1473. case TARGET_ALLY:
  1474. doit = true;
  1475. default:
  1476. if (targets.length == 0)
  1477. {
  1478. if (simultaneously)
  1479. setIsCastingSimultaneouslyNow(false);
  1480. else
  1481. setIsCastingNow(false);
  1482. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1483. if (this instanceof L2PcInstance)
  1484. {
  1485. sendPacket(ActionFailed.STATIC_PACKET);
  1486. getAI().setIntention(AI_INTENTION_ACTIVE);
  1487. }
  1488. return;
  1489. }
  1490.  
  1491. switch (skill.getSkillType())
  1492. {
  1493. case BUFF:
  1494. case HEAL:
  1495. case COMBATPOINTHEAL:
  1496. case MANAHEAL:
  1497. case REFLECT:
  1498. doit = true;
  1499. break;
  1500. }
  1501.  
  1502. /*
  1503. * handled on first switch
  1504. switch (skill.getTargetType())
  1505. {
  1506. case TARGET_SELF:
  1507. case TARGET_PET:
  1508. case TARGET_SUMMON:
  1509. case TARGET_PARTY:
  1510. case TARGET_CLAN:
  1511. case TARGET_ALLY:
  1512. doit = true;
  1513. break;
  1514. }*/
  1515.  
  1516. if (doit)
  1517. {
  1518. target = (L2Character) targets[0];
  1519.  
  1520. if (this instanceof L2PcInstance && target instanceof L2PcInstance
  1521. && target.getAI().getIntention() == CtrlIntention.AI_INTENTION_ATTACK)
  1522. {
  1523. switch (skill.getSkillType())
  1524. {
  1525. case BUFF:
  1526. case HOT:
  1527. case HEAL:
  1528. case HEAL_PERCENT:
  1529. case MANAHEAL:
  1530. case MANAHEAL_PERCENT:
  1531. case BALANCE_LIFE:
  1532. target.setLastBuffer(this);
  1533. break;
  1534. }
  1535.  
  1536. if (((L2PcInstance)this).isInParty() && skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY)
  1537. {
  1538. for (L2PcInstance member : ((L2PcInstance)this).getParty().getPartyMembers())
  1539. member.setLastBuffer(this);
  1540. }
  1541. }
  1542. }
  1543. else target = (L2Character) getTarget();
  1544.  
  1545. }
  1546.  
  1547. if (target == null)
  1548. {
  1549. if (simultaneously)
  1550. setIsCastingSimultaneouslyNow(false);
  1551. else
  1552. setIsCastingNow(false);
  1553. if (this instanceof L2PcInstance)
  1554. {
  1555. sendPacket(ActionFailed.STATIC_PACKET);
  1556. getAI().setIntention(AI_INTENTION_ACTIVE);
  1557. }
  1558. return;
  1559. }
  1560.  
  1561. // Get the Identifier of the skill
  1562. int magicId = skill.getId();
  1563.  
  1564. // Get the Display Identifier for a skill that client can't display
  1565. int displayId = skill.getDisplayId();
  1566.  
  1567. // Get the level of the skill
  1568. int level = skill.getLevel();
  1569.  
  1570. if (level < 1)
  1571. level = 1;
  1572.  
  1573. // Get the casting time of the skill (base)
  1574. int hitTime = skill.getHitTime();
  1575. int coolTime = skill.getCoolTime();
  1576.  
  1577. boolean effectWhileCasting = skill.getSkillType() == L2SkillType.FUSION
  1578. || skill.getSkillType() == L2SkillType.SIGNET_CASTTIME;
  1579.  
  1580. // Calculate the casting time of the skill (base + modifier of MAtkSpd)
  1581. // Don't modify the skill time for FORCE_BUFF skills. The skill time for those skills represent the buff time.
  1582. if(!effectWhileCasting)
  1583. {
  1584. hitTime = Formulas.calcAtkSpd(this, skill, hitTime);
  1585. if (coolTime > 0)
  1586. coolTime = Formulas.calcAtkSpd(this, skill, coolTime);
  1587. }
  1588.  
  1589. // Calculate altered Cast Speed due to BSpS/SpS
  1590. L2ItemInstance weaponInst = getActiveWeaponInstance();
  1591.  
  1592. if (weaponInst != null && skill.isMagic() && !effectWhileCasting && skill.getTargetType() != SkillTargetType.TARGET_SELF)
  1593. {
  1594. if ((weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  1595. || (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT))
  1596. {
  1597. //Only takes 70% of the time to cast a BSpS/SpS cast
  1598. hitTime = (int)(0.70 * hitTime);
  1599. coolTime = (int)(0.70 * coolTime);
  1600.  
  1601. //Because the following are magic skills that do not actively 'eat' BSpS/SpS,
  1602. //I must 'eat' them here so players don't take advantage of infinite speed increase
  1603. switch (skill.getSkillType())
  1604. {
  1605. case BUFF:
  1606. case MANAHEAL:
  1607. case RESURRECT:
  1608. case RECALL:
  1609. case DOT:
  1610. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  1611. break;
  1612. }
  1613. }
  1614. }
  1615. else if (this instanceof L2Npc && skill.useSpiritShot() && !effectWhileCasting)
  1616. {
  1617. if(((L2Npc)this).rechargeAutoSoulShot(false, true))
  1618. {
  1619. hitTime = (int)(0.70 * hitTime);
  1620. coolTime = (int)(0.70 * coolTime);
  1621. }
  1622. }
  1623.  
  1624. // Don't modify skills HitTime if staticHitTime is specified for skill in datapack.
  1625. if (skill.isStaticHitTime())
  1626. {
  1627. hitTime = skill.getHitTime();
  1628. coolTime = skill.getCoolTime();
  1629. }
  1630. // if basic hitTime is higher than 500 than the min hitTime is 500
  1631. else if (skill.getHitTime() >= 500 && hitTime < 500)
  1632. hitTime = 500;
  1633.  
  1634. // queue herbs and potions
  1635. if (isCastingSimultaneouslyNow() && simultaneously)
  1636. {
  1637. ThreadPoolManager.getInstance().scheduleAi(new UsePotionTask(this, skill), 100 );
  1638. return;
  1639. }
  1640.  
  1641. // Set the _castInterruptTime and casting status (L2PcInstance already has this true)
  1642. if (simultaneously)
  1643. setIsCastingSimultaneouslyNow(true);
  1644. else
  1645. setIsCastingNow(true);
  1646. // Note: _castEndTime = GameTimeController.getGameTicks() + (coolTime + hitTime) / GameTimeController.MILLIS_IN_TICK;
  1647. if (!simultaneously)
  1648. {
  1649. _castInterruptTime = -2 + GameTimeController.getGameTicks() + hitTime / GameTimeController.MILLIS_IN_TICK;
  1650. setLastSkillCast(skill);
  1651. }
  1652. else
  1653. setLastSimultaneousSkillCast(skill);
  1654.  
  1655. // Init the reuse time of the skill
  1656. int reuseDelay;
  1657.  
  1658. if (skill.isStaticReuse())
  1659. {
  1660. reuseDelay = (skill.getReuseDelay());
  1661. }
  1662. else
  1663. {
  1664. if(skill.isMagic())
  1665. {
  1666. reuseDelay = (int)(skill.getReuseDelay() * getStat().getMReuseRate(skill));
  1667. }
  1668. else
  1669. {
  1670. reuseDelay = (int)(skill.getReuseDelay() * getStat().getPReuseRate(skill));
  1671. }
  1672. }
  1673.  
  1674. boolean skillMastery = Formulas.calcSkillMastery(this, skill);
  1675.  
  1676. // Skill reuse check
  1677. if (reuseDelay > 30000 && !skillMastery) addTimeStamp(skill.getId(),reuseDelay);
  1678.  
  1679. // Check if this skill consume mp on start casting
  1680. int initmpcons = getStat().getMpInitialConsume(skill);
  1681. if (initmpcons > 0)
  1682. {
  1683. StatusUpdate su = new StatusUpdate(getObjectId());
  1684. if (skill.isDance())
  1685. {
  1686. getStatus().reduceMp(calcStat(Stats.DANCE_MP_CONSUME_RATE, initmpcons, null, null));
  1687. }
  1688. else if (skill.isMagic())
  1689. {
  1690. getStatus().reduceMp(calcStat(Stats.MAGICAL_MP_CONSUME_RATE, initmpcons, null, null));
  1691. }
  1692. else
  1693. {
  1694. getStatus().reduceMp(calcStat(Stats.PHYSICAL_MP_CONSUME_RATE, initmpcons, null, null));
  1695. }
  1696. su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
  1697. sendPacket(su);
  1698. }
  1699.  
  1700. // Disable the skill during the re-use delay and create a task EnableSkill with Medium priority to enable it at the end of the re-use delay
  1701. if (reuseDelay > 10)
  1702. {
  1703. if (skillMastery)
  1704. {
  1705. reuseDelay = 100;
  1706.  
  1707. if (getActingPlayer() != null)
  1708. {
  1709. SystemMessage sm = new SystemMessage(SystemMessageId.SKILL_READY_TO_USE_AGAIN);
  1710. getActingPlayer().sendPacket(sm);
  1711. sm = null;
  1712. }
  1713. }
  1714.  
  1715. disableSkill(skill.getId(), reuseDelay);
  1716. }
  1717.  
  1718. // Make sure that char is facing selected target
  1719. if (target != this)
  1720. setHeading(Util.calculateHeadingFrom(this, target));
  1721.  
  1722. // For force buff skills, start the effect as long as the player is casting.
  1723. if(effectWhileCasting)
  1724. {
  1725. // Consume Items if necessary and Send the Server->Client packet InventoryUpdate with Item modification to all the L2Character
  1726. if (skill.getItemConsume() > 0)
  1727. {
  1728. if (!destroyItemByItemId("Consume", skill.getItemConsumeId(), skill.getItemConsume(), null, false))
  1729. {
  1730. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ITEMS));
  1731. if (simultaneously)
  1732. setIsCastingSimultaneouslyNow(false);
  1733. else
  1734. setIsCastingNow(false);
  1735. if (this instanceof L2PcInstance)
  1736. getAI().setIntention(AI_INTENTION_ACTIVE);
  1737. return;
  1738. }
  1739. }
  1740.  
  1741. // Consume Souls if necessary
  1742. if (skill.getSoulConsumeCount() > 0 || skill.getMaxSoulConsumeCount() > 0)
  1743. {
  1744. if (this instanceof L2PcInstance)
  1745. {
  1746. if ( !((L2PcInstance)this).decreaseSouls(skill.getSoulConsumeCount(),skill))
  1747. return;
  1748. }
  1749. }
  1750.  
  1751. if (skill.getSkillType() == L2SkillType.FUSION)
  1752. startFusionSkill(target, skill);
  1753. else
  1754. callSkill(skill, targets);
  1755. }
  1756.  
  1757. // Send a Server->Client packet MagicSkillUser with target, displayId, level, skillTime, reuseDelay
  1758. // to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  1759. broadcastPacket(new MagicSkillUse(this, target, displayId, level, hitTime, reuseDelay));
  1760.  
  1761. // Send a system message USE_S1 to the L2Character
  1762. if (this instanceof L2PcInstance && magicId != 1312)
  1763. {
  1764. SystemMessage sm = new SystemMessage(SystemMessageId.USE_S1);
  1765. sm.addSkillName(skill);
  1766. sendPacket(sm);
  1767. }
  1768.  
  1769. // Before start AI Cast Broadcast Fly Effect is Need
  1770. if (skill.getFlyType() != null && (this instanceof L2PcInstance))
  1771. {
  1772. ThreadPoolManager.getInstance().scheduleEffect(new FlyToLocationTask(this, target, skill), 50);
  1773. }
  1774.  
  1775. // launch the magic in hitTime milliseconds
  1776. if (hitTime > 210)
  1777. {
  1778. // Send a Server->Client packet SetupGauge with the color of the gauge and the casting time
  1779. if (this instanceof L2PcInstance && !effectWhileCasting)
  1780. {
  1781. SetupGauge sg = new SetupGauge(SetupGauge.BLUE, hitTime);
  1782. sendPacket(sg);
  1783. }
  1784.  
  1785. if (simultaneously)
  1786. {
  1787. if (_skillCast2 != null)
  1788. {
  1789. _skillCast2.cancel(true);
  1790. _skillCast2 = null;
  1791. }
  1792. // Create a task MagicUseTask to launch the MagicSkill at the end of the casting time (hitTime)
  1793. // For client animation reasons (party buffs especially) 200 ms before!
  1794. if (effectWhileCasting)
  1795. _skillCast2 = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 2, simultaneously), hitTime);
  1796. else
  1797. _skillCast2 = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 1, simultaneously), hitTime-200);
  1798.  
  1799. }
  1800. else
  1801. {
  1802. if (_skillCast != null)
  1803. {
  1804. _skillCast.cancel(true);
  1805. _skillCast = null;
  1806. }
  1807. // Create a task MagicUseTask to launch the MagicSkill at the end of the casting time (hitTime)
  1808. // For client animation reasons (party buffs especially) 200 ms before!
  1809. if (effectWhileCasting)
  1810. _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 2, simultaneously), hitTime);
  1811. else
  1812. _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 1, simultaneously), hitTime-200);
  1813.  
  1814. }
  1815.  
  1816. }
  1817. else
  1818. {
  1819. onMagicLaunchedTimer(targets, skill, coolTime, true, simultaneously);
  1820. }
  1821. }
  1822.  
  1823. private boolean checkDoCastConditions(L2Skill skill)
  1824. {
  1825. if (skill == null || isSkillDisabled(skill.getId()))
  1826. {
  1827. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1828. sendPacket(ActionFailed.STATIC_PACKET);
  1829. return false;
  1830. }
  1831.  
  1832. // Check if the caster has enough MP
  1833. if (getCurrentMp() < getStat().getMpConsume(skill) + getStat().getMpInitialConsume(skill))
  1834. {
  1835. // Send a System Message to the caster
  1836. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_MP));
  1837.  
  1838. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1839. sendPacket(ActionFailed.STATIC_PACKET);
  1840. return false;
  1841. }
  1842.  
  1843. // Check if the caster has enough HP
  1844. if (getCurrentHp() <= skill.getHpConsume())
  1845. {
  1846. // Send a System Message to the caster
  1847. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_HP));
  1848.  
  1849. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1850. sendPacket(ActionFailed.STATIC_PACKET);
  1851. return false;
  1852. }
  1853.  
  1854. switch (skill.getSkillType())
  1855. {
  1856. case SUMMON_TRAP:
  1857. {
  1858. if (isInsideZone(ZONE_PEACE))
  1859. {
  1860. if (this instanceof L2PcInstance)
  1861. ((L2PcInstance)this).sendPacket(new SystemMessage(SystemMessageId.A_MALICIOUS_SKILL_CANNOT_BE_USED_IN_PEACE_ZONE));
  1862. return false;
  1863. }
  1864. if (this instanceof L2PcInstance && ((L2PcInstance)this).getTrap() != null)
  1865. {
  1866. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1867. sendPacket(ActionFailed.STATIC_PACKET);
  1868. return false;
  1869. }
  1870. break;
  1871. }
  1872. case SUMMON:
  1873. {
  1874. if (!((L2SkillSummon)skill).isCubic() && this instanceof L2PcInstance &&(((L2PcInstance)this).getPet() != null || ((L2PcInstance)this).isMounted()))
  1875. {
  1876. if (Config.DEBUG)
  1877. _log.fine("player has a pet already. ignore summon skill");
  1878.  
  1879. sendPacket(new SystemMessage(SystemMessageId.YOU_ALREADY_HAVE_A_PET));
  1880. return false;
  1881. }
  1882. }
  1883. }
  1884.  
  1885. if(!skill.isPotion())
  1886. {
  1887. // Check if the skill is a magic spell and if the L2Character is not muted
  1888. if (skill.isMagic())
  1889. {
  1890. if(isMuted())
  1891. {
  1892. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1893. sendPacket(ActionFailed.STATIC_PACKET);
  1894. return false;
  1895. }
  1896. }
  1897. else
  1898. {
  1899. // Check if the skill is physical and if the L2Character is not physical_muted
  1900. if (isPhysicalMuted())
  1901. {
  1902. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1903. sendPacket(ActionFailed.STATIC_PACKET);
  1904. return false;
  1905. }
  1906. else if (isPhysicalAttackMuted()) // Prevent use attack
  1907. {
  1908. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1909. sendPacket(ActionFailed.STATIC_PACKET);
  1910. return false;
  1911. }
  1912. }
  1913. }
  1914.  
  1915. // TODO: Should possibly be checked only in L2PcInstance's useMagic
  1916. // Can't use Hero and resurrect skills during Olympiad
  1917. if (this instanceof L2PcInstance && ((L2PcInstance)this).isInOlympiadMode() &&
  1918. (skill.isHeroSkill() || skill.getSkillType() == L2SkillType.RESURRECT))
  1919. {
  1920. SystemMessage sm = new SystemMessage(SystemMessageId.THIS_SKILL_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  1921. sendPacket(sm);
  1922. return false;
  1923. }
  1924.  
  1925. // prevent casting signets to peace zone
  1926. if (skill.getSkillType() == L2SkillType.SIGNET || skill.getSkillType() == L2SkillType.SIGNET_CASTTIME)
  1927. {
  1928. L2WorldRegion region = getWorldRegion();
  1929. if (region == null)
  1930. return false;
  1931. boolean canCast = true;
  1932. if (skill.getTargetType() == SkillTargetType.TARGET_GROUND && this instanceof L2PcInstance)
  1933. {
  1934. Point3D wp = ((L2PcInstance) this).getCurrentSkillWorldPosition();
  1935. if (!region.checkEffectRangeInsidePeaceZone(skill, wp.getX(), wp.getY(), wp.getZ()))
  1936. canCast = false;
  1937. }
  1938. else if (!region.checkEffectRangeInsidePeaceZone(skill, getX(), getY(), getZ()))
  1939. canCast = false;
  1940. if (!canCast)
  1941. {
  1942. SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  1943. sm.addSkillName(skill);
  1944. sendPacket(sm);
  1945. return false;
  1946. }
  1947. }
  1948.  
  1949. // Check if the caster owns the weapon needed
  1950. if (!skill.getWeaponDependancy(this))
  1951. {
  1952. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1953. sendPacket(ActionFailed.STATIC_PACKET);
  1954. return false;
  1955. }
  1956.  
  1957. // Check if the spell consumes an Item
  1958. // TODO: combine check and consume
  1959. if (skill.getItemConsume() > 0 && getInventory() != null)
  1960. {
  1961. // Get the L2ItemInstance consumed by the spell
  1962. L2ItemInstance requiredItems = getInventory().getItemByItemId(skill.getItemConsumeId());
  1963.  
  1964. // Check if the caster owns enough consumed Item to cast
  1965. if (requiredItems == null || requiredItems.getCount() < skill.getItemConsume())
  1966. {
  1967. // Checked: when a summon skill failed, server show required consume item count
  1968. if (skill.getSkillType() == L2SkillType.SUMMON)
  1969. {
  1970. SystemMessage sm = new SystemMessage(SystemMessageId.SUMMONING_SERVITOR_COSTS_S2_S1);
  1971. sm.addItemName(skill.getItemConsumeId());
  1972. sm.addNumber(skill.getItemConsume());
  1973. sendPacket(sm);
  1974. return false;
  1975. }
  1976. else
  1977. {
  1978. // Send a System Message to the caster
  1979. sendPacket(new SystemMessage(SystemMessageId.THERE_ARE_NOT_ENOUGH_NECESSARY_ITEMS_TO_USE_THE_SKILL));
  1980. return false;
  1981. }
  1982. }
  1983. }
  1984.  
  1985. if (this instanceof L2PcInstance)
  1986. {
  1987. int charges = ((L2PcInstance)this).getCharges();
  1988.  
  1989. // Check if the spell using charges or not in AirShip
  1990. if (charges < skill.getRequiredCharges()
  1991. || (skill.getMaxCharges() == 0 && charges < skill.getNumCharges())
  1992. || ((L2PcInstance)this).isInAirShip())
  1993. {
  1994. SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  1995. sm.addSkillName(skill);
  1996. sendPacket(sm);
  1997. abortCast();
  1998. return false;
  1999. }
  2000. }
  2001. return true;
  2002. }
  2003.  
  2004. /**
  2005. * Index according to skill id the current timestamp of use.<br><br>
  2006. *
  2007. * @param skill id
  2008. * @param reuse delay
  2009. * <BR><B>Overridden in :</B> (L2PcInstance)
  2010. */
  2011. public void addTimeStamp(int s, int r) {/***/}
  2012.  
  2013. /**
  2014. * Index according to skill id the current timestamp of use.<br><br>
  2015. *
  2016. * @param skill id
  2017. * <BR><B>Overridden in :</B> (L2PcInstance)
  2018. */
  2019. public void removeTimeStamp(int s) {/***/}
  2020.  
  2021. public void startFusionSkill(L2Character target, L2Skill skill)
  2022. {
  2023. if (skill.getSkillType() != L2SkillType.FUSION)
  2024. return;
  2025.  
  2026. if (_fusionSkill == null)
  2027. _fusionSkill = new FusionSkill(this, target, skill);
  2028. }
  2029.  
  2030. /**
  2031. * Kill the L2Character.<BR><BR>
  2032. *
  2033. * <B><U> Actions</U> :</B><BR><BR>
  2034. * <li>Set target to null and cancel Attack or Cast </li>
  2035. * <li>Stop movement </li>
  2036. * <li>Stop HP/MP/CP Regeneration task </li>
  2037. * <li>Stop all active skills effects in progress on the L2Character </li>
  2038. * <li>Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform </li>
  2039. * <li>Notify L2Character AI </li><BR><BR>
  2040. *
  2041. * <B><U> Overridden in </U> :</B><BR><BR>
  2042. * <li> L2NpcInstance : Create a DecayTask to remove the corpse of the L2NpcInstance after 7 seconds </li>
  2043. * <li> L2Attackable : Distribute rewards (EXP, SP, Drops...) and notify Quest Engine </li>
  2044. * <li> L2PcInstance : Apply Death Penalty, Manage gain/loss Karma and Item Drop </li><BR><BR>
  2045. *
  2046. * @param killer The L2Character who killed it
  2047. *
  2048. */
  2049. public boolean doDie(L2Character killer)
  2050. {
  2051. // killing is only possible one time
  2052. synchronized (this)
  2053. {
  2054. if (isDead()) return false;
  2055. // now reset currentHp to zero
  2056. setCurrentHp(0);
  2057. setIsDead(true);
  2058. }
  2059.  
  2060. // Set target to null and cancel Attack or Cast
  2061. setTarget(null);
  2062.  
  2063. // Stop movement
  2064. stopMove(null);
  2065.  
  2066. // Stop HP/MP/CP Regeneration task
  2067. getStatus().stopHpMpRegeneration();
  2068.  
  2069. // Stop all active skills effects in progress on the L2Character,
  2070. // if the Character isn't affected by Soul of The Phoenix or Salvation
  2071. if (this instanceof L2Playable && ((L2Playable)this).isPhoenixBlessed())
  2072. {
  2073. if (((L2Playable)this).getCharmOfLuck()) //remove Lucky Charm if player has SoulOfThePhoenix/Salvation buff
  2074. ((L2Playable)this).stopCharmOfLuck(null);
  2075. if (((L2Playable)this).isNoblesseBlessed())
  2076. ((L2Playable)this).stopNoblesseBlessing(null);
  2077. }
  2078. // Same thing if the Character isn't a Noblesse Blessed L2PlayableInstance
  2079. else if (this instanceof L2Playable && ((L2Playable)this).isNoblesseBlessed())
  2080. {
  2081. ((L2Playable)this).stopNoblesseBlessing(null);
  2082.  
  2083. if (((L2Playable)this).getCharmOfLuck()) //remove Lucky Charm if player have Nobless blessing buff
  2084. ((L2Playable)this).stopCharmOfLuck(null);
  2085. }
  2086. else
  2087. stopAllEffectsExceptThoseThatLastThroughDeath();
  2088.  
  2089. if (this instanceof L2PcInstance && ((L2PcInstance)this).getAgathionId() != 0)
  2090. ((L2PcInstance)this).setAgathionId(0);
  2091. calculateRewards(killer);
  2092.  
  2093. // Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  2094. broadcastStatusUpdate();
  2095.  
  2096. // Notify L2Character AI
  2097. getAI().notifyEvent(CtrlEvent.EVT_DEAD);
  2098.  
  2099. if (getWorldRegion() != null)
  2100. getWorldRegion().onDeath(this);
  2101.  
  2102. getAttackByList().clear();
  2103. // If character is PhoenixBlessed
  2104. // or has charm of courage inside siege battlefield (exact operation to be confirmed)
  2105. // a resurrection popup will show up
  2106. if (this instanceof L2Summon)
  2107. {
  2108. if (((L2Summon)this).isPhoenixBlessed() && ((L2Summon)this).getOwner() != null)
  2109. ((L2Summon)this).getOwner().reviveRequest(((L2Summon)this).getOwner(), null, true);
  2110. }
  2111. if (this instanceof L2PcInstance)
  2112. {
  2113. if(((L2Playable)this).isPhoenixBlessed())
  2114. ((L2PcInstance)this).reviveRequest(((L2PcInstance)this),null,false);
  2115. else if (((L2PcInstance)this).getCharmOfCourage()
  2116. && ((L2PcInstance)this).isInSiege())
  2117. {
  2118. ((L2PcInstance)this).reviveRequest(((L2PcInstance)this),null,false);
  2119. }
  2120. }
  2121. try
  2122. {
  2123. if (_fusionSkill != null)
  2124. abortCast();
  2125.  
  2126. for (L2Character character : getKnownList().getKnownCharacters())
  2127. if (character.getFusionSkill() != null && character.getFusionSkill().getTarget() == this)
  2128. character.abortCast();
  2129. }
  2130. catch (Exception e)
  2131. {
  2132. _log.log(Level.SEVERE, "deleteMe()", e);
  2133. }
  2134. return true;
  2135. }
  2136.  
  2137. protected void calculateRewards(L2Character killer)
  2138. {
  2139. }
  2140.  
  2141. /** Sets HP, MP and CP and revives the L2Character. */
  2142. public void doRevive()
  2143. {
  2144. if (!isDead()) return;
  2145. if (!isTeleporting())
  2146. {
  2147. setIsPendingRevive(false);
  2148. setIsDead(false);
  2149. boolean restorefull = false;
  2150.  
  2151. if (this instanceof L2Playable && ((L2Playable)this).isPhoenixBlessed())
  2152. {
  2153. restorefull = true;
  2154. ((L2Playable)this).stopPhoenixBlessing(null);
  2155. }
  2156. if(restorefull)
  2157. {
  2158. //_status.setCurrentCp(getMaxCp()); //this is not confirmed...
  2159. _status.setCurrentHp(getMaxHp()); //confirmed
  2160. _status.setCurrentMp(getMaxMp()); //and also confirmed
  2161. }
  2162. else
  2163. _status.setCurrentHp(getMaxHp() * Config.RESPAWN_RESTORE_HP);
  2164. //_status.setCurrentCp(getMaxCp() * Config.RESPAWN_RESTORE_CP);
  2165. //_Status.setCurrentMp(getMaxMp() * Config.RESPAWN_RESTORE_MP);
  2166.  
  2167. // Start broadcast status
  2168. broadcastPacket(new Revive(this));
  2169. if (getWorldRegion() != null)
  2170. getWorldRegion().onRevive(this);
  2171. }
  2172. else
  2173. setIsPendingRevive(true);
  2174. }
  2175.  
  2176. /** Revives the L2Character using skill. */
  2177. public void doRevive(double revivePower) { doRevive(); }
  2178.  
  2179. // =========================================================
  2180. // Property - Public
  2181. /**
  2182. * Return the L2CharacterAI of the L2Character and if its null create a new one.
  2183. */
  2184. public L2CharacterAI getAI()
  2185. {
  2186. L2CharacterAI ai = _ai; // copy handle
  2187. if (ai == null)
  2188. {
  2189. synchronized(this)
  2190. {
  2191. if (_ai == null) _ai = new L2CharacterAI(new AIAccessor());
  2192. return _ai;
  2193. }
  2194. }
  2195. return ai;
  2196. }
  2197.  
  2198.  
  2199. public void setAI(L2CharacterAI newAI)
  2200. {
  2201. L2CharacterAI oldAI = getAI();
  2202. if(oldAI != null && oldAI != newAI && oldAI instanceof L2AttackableAI)
  2203. ((L2AttackableAI)oldAI).stopAITask();
  2204. _ai = newAI;
  2205. }
  2206.  
  2207. /** Return True if the L2Character has a L2CharacterAI. */
  2208. public boolean hasAI() { return _ai != null; }
  2209.  
  2210. /** Return True if the L2Character is RaidBoss or his minion. */
  2211. public boolean isRaid()
  2212. {
  2213. return _isRaid ;
  2214. }
  2215.  
  2216. /**
  2217. * Set this Npc as a Raid instance.<BR><BR>
  2218. * @param isRaid
  2219. */
  2220. public void setIsRaid(boolean isRaid)
  2221. {
  2222. _isRaid = isRaid;
  2223. }
  2224.  
  2225. /** Return a list of L2Character that attacked. */
  2226. public final List<L2Character> getAttackByList ()
  2227. {
  2228. if (_attackByList == null) _attackByList = new FastList<L2Character>();
  2229. return _attackByList;
  2230. }
  2231.  
  2232. public final L2Skill getLastSimultaneousSkillCast() { return _lastSimultaneousSkillCast; }
  2233. public void setLastSimultaneousSkillCast (L2Skill skill) { _lastSimultaneousSkillCast = skill; }
  2234.  
  2235. public final L2Skill getLastSkillCast() { return _lastSkillCast; }
  2236. public void setLastSkillCast (L2Skill skill) { _lastSkillCast = skill; }
  2237.  
  2238. public final boolean isNoRndWalk() { return _isNoRndWalk; }
  2239. public final void setIsNoRndWalk(boolean value) { _isNoRndWalk = value; }
  2240.  
  2241. public final boolean isAfraid() { return _isAfraid; }
  2242. public final void setIsAfraid(boolean value) { _isAfraid = value; }
  2243.  
  2244. /** Return True if the L2Character can't use its skills (ex : stun, sleep...). */
  2245. public final boolean isAllSkillsDisabled() { return _allSkillsDisabled || isImmobileUntilAttacked() || isStunned() || isSleeping() || isParalyzed(); }
  2246.  
  2247. /** Return True if the L2Character can't attack (stun, sleep, attackEndTime, fakeDeath, paralyse, attackMute). */
  2248. public boolean isAttackingDisabled() { return isFlying() || isStunned() || isImmobileUntilAttacked() || isSleeping() || _attackEndTime > GameTimeController.getGameTicks() || isAlikeDead() || isParalyzed() || isPhysicalAttackMuted() || isCoreAIDisabled(); }
  2249.  
  2250. public final Calculator[] getCalculators() { return _calculators; }
  2251.  
  2252. public final boolean isConfused() { return _isConfused; }
  2253. public final void setIsConfused(boolean value) { _isConfused = value; }
  2254.  
  2255. /** Return True if the L2Character is dead or use fake death. */
  2256. public boolean isAlikeDead() { return _isDead; }
  2257.  
  2258. /** Return True if the L2Character is dead. */
  2259. public final boolean isDead() { return _isDead; }
  2260. public final void setIsDead(boolean value) { _isDead = value; }
  2261.  
  2262. public boolean isImmobilized() { return _isImmobilized; }
  2263. public void setIsImmobilized(boolean value){ _isImmobilized = value; }
  2264.  
  2265. public final boolean isMuted() { return _isMuted; }
  2266. public final void setIsMuted(boolean value) { _isMuted = value; }
  2267.  
  2268. public final boolean isPhysicalMuted() { return _isPhysicalMuted; }
  2269. public final void setIsPhysicalMuted(boolean value) { _isPhysicalMuted = value; }
  2270.  
  2271. public final boolean isPhysicalAttackMuted() { return _isPhysicalAttackMuted; }
  2272. public final void setIsPhysicalAttackMuted(boolean value) { _isPhysicalAttackMuted = value; }
  2273.  
  2274. /** Return True if the L2Character can't move (stun, root, sleep, overload, paralyzed). */
  2275. public boolean isMovementDisabled()
  2276. {
  2277. // check for isTeleporting to prevent teleport cheating (if appear packet not received)
  2278. return isStunned() || isRooted() || isSleeping() || isOverloaded() || isParalyzed()
  2279. || isImmobilized() || isAlikeDead() || isTeleporting();
  2280. }
  2281.  
  2282. /** Return True if the L2Character can not be controlled by the player (confused, afraid). */
  2283. public final boolean isOutOfControl() { return isConfused() || isAfraid(); }
  2284.  
  2285. public final boolean isOverloaded() { return _isOverloaded; }
  2286. /** Set the overloaded status of the L2Character is overloaded (if True, the L2PcInstance can't take more item). */
  2287. public final void setIsOverloaded(boolean value) { _isOverloaded = value; }
  2288.  
  2289. public final boolean isParalyzed() { return _isParalyzed; }
  2290. public final void setIsParalyzed(boolean value) { _isParalyzed = value; }
  2291.  
  2292. public final boolean isPendingRevive() { return isDead() && _isPendingRevive; }
  2293. public final void setIsPendingRevive(boolean value) { _isPendingRevive = value; }
  2294.  
  2295. public final boolean isDisarmed() { return _isDisarmed; }
  2296. public final void setIsDisarmed(boolean value) { _isDisarmed = value; }
  2297.  
  2298. /**
  2299. * Return the L2Summon of the L2Character.<BR><BR>
  2300. * <B><U> Overridden in </U> :</B><BR><BR>
  2301. * <li> L2PcInstance</li><BR><BR>
  2302. */
  2303. public L2Summon getPet() { return null; }
  2304.  
  2305. public final boolean isRooted() { return _isRooted; }
  2306. public final void setIsRooted(boolean value) { _isRooted = value; }
  2307.  
  2308. /** Return True if the L2Character is running. */
  2309. public boolean isRunning() { return _isRunning; }
  2310. public final void setIsRunning(boolean value)
  2311. {
  2312. _isRunning = value;
  2313. if (getRunSpeed() != 0)
  2314. broadcastPacket(new ChangeMoveType(this));
  2315. if (this instanceof L2PcInstance)
  2316. ((L2PcInstance)this).broadcastUserInfo();
  2317. else if (this instanceof L2Summon)
  2318. {
  2319. ((L2Summon)this).broadcastStatusUpdate();
  2320. }
  2321. else if (this instanceof L2Npc)
  2322. {
  2323. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  2324. //synchronized (character.getKnownList().getKnownPlayers())
  2325. {
  2326. for (L2PcInstance player : plrs)
  2327. {
  2328. if (getRunSpeed() == 0)
  2329. player.sendPacket(new ServerObjectInfo((L2Npc) this, player));
  2330. else
  2331. player.sendPacket(new AbstractNpcInfo.NpcInfo((L2Npc) this, player));
  2332. }
  2333. }
  2334. }
  2335. }
  2336. /** Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance. */
  2337. public final void setRunning() { if (!isRunning()) setIsRunning(true); }
  2338.  
  2339. public final boolean isImmobileUntilAttacked() {return _isImmobileUntilAttacked; }
  2340. public final void setIsImmobileUntilAttacked(boolean value) { _isImmobileUntilAttacked = value; }
  2341.  
  2342. public final boolean isSleeping() { return _isSleeping; }
  2343. public final void setIsSleeping(boolean value) { _isSleeping = value; }
  2344.  
  2345. public final boolean isStunned() { return _isStunned; }
  2346. public final void setIsStunned(boolean value) { _isStunned = value; }
  2347.  
  2348. public final boolean isBetrayed() { return _isBetrayed; }
  2349. public final void setIsBetrayed(boolean value) { _isBetrayed = value; }
  2350.  
  2351. public final boolean isTeleporting() { return _isTeleporting; }
  2352. public void setIsTeleporting(boolean value) { _isTeleporting = value; }
  2353. public void setIsInvul(boolean b){_isInvul = b;}
  2354. public void setIsInvulByEffect(boolean b, L2Effect effect){
  2355. _isInvul = b;
  2356. _invulEffect = effect;}
  2357. public L2Effect getInvulEffect() {return _invulEffect;}
  2358. public boolean isInvul(){return _isInvul || _isTeleporting;}
  2359. public boolean isUndead() { return _template.isUndead; }
  2360.  
  2361. public final boolean isFlying() { return _isFlying; }
  2362. public final void setIsFlying(boolean mode) { _isFlying = mode; }
  2363.  
  2364. @Override
  2365. public CharKnownList getKnownList()
  2366. {
  2367. return ((CharKnownList)super.getKnownList());
  2368. }
  2369.  
  2370. @Override
  2371. public void initKnownList()
  2372. {
  2373. setKnownList(new CharKnownList(this));
  2374. }
  2375.  
  2376. public CharStat getStat()
  2377. {
  2378. return _stat;
  2379. }
  2380. /**
  2381. * Initializes the CharStat class of the L2Object,
  2382. * is overwritten in classes that require a different CharStat Type.
  2383. *
  2384. * Removes the need for instanceof checks.
  2385. */
  2386. public void initCharStat()
  2387. {
  2388. _stat = new CharStat(this);
  2389. }
  2390. public final void setStat(CharStat value) { _stat = value; }
  2391.  
  2392. public CharStatus getStatus()
  2393. {
  2394. return _status;
  2395. }
  2396. /**
  2397. * Initializes the CharStatus class of the L2Object,
  2398. * is overwritten in classes that require a different CharStatus Type.
  2399. *
  2400. * Removes the need for instanceof checks.
  2401. */
  2402. public void initCharStatus()
  2403. {
  2404. _status = new CharStatus(this);
  2405. }
  2406. public final void setStatus(CharStatus value) { _status = value; }
  2407.  
  2408. @Override
  2409. public CharPosition getPosition()
  2410. {
  2411. return (CharPosition)super.getPosition();
  2412. }
  2413.  
  2414. @Override
  2415. public void initPosition()
  2416. {
  2417. setObjectPosition(new CharPosition(this));
  2418. }
  2419.  
  2420. public L2CharTemplate getTemplate() { return _template; }
  2421. /**
  2422. * Set the template of the L2Character.<BR><BR>
  2423. *
  2424. * <B><U> Concept</U> :</B><BR><BR>
  2425. * Each L2Character owns generic and static properties (ex : all Keltir have the same number of HP...).
  2426. * All of those properties are stored in a different template for each type of L2Character.
  2427. * Each template is loaded once in the server cache memory (reduce memory use).
  2428. * When a new instance of L2Character is spawned, server just create a link between the instance and the template
  2429. * This link is stored in <B>_template</B><BR><BR>
  2430. *
  2431. * <B><U> Assert </U> :</B><BR><BR>
  2432. * <li> this instanceof L2Character</li><BR><BR
  2433. */
  2434. protected final void setTemplate(L2CharTemplate template) { _template = template; }
  2435.  
  2436. /** Return the Title of the L2Character. */
  2437. public final String getTitle() { return _title; }
  2438. /** Set the Title of the L2Character. */
  2439. public final void setTitle(String value)
  2440. {
  2441. if (value == null)
  2442. _title = "";
  2443. else
  2444. _title = value.length() > 16 ? value.substring(0,15) : value;
  2445. }
  2446.  
  2447. /** Set the L2Character movement type to walk and send Server->Client packet ChangeMoveType to all others L2PcInstance. */
  2448. public final void setWalking() { if (isRunning()) setIsRunning(false); }
  2449.  
  2450. /** Task lauching the function enableSkill() */
  2451. class EnableSkill implements Runnable
  2452. {
  2453. int _skillId;
  2454.  
  2455. public EnableSkill(int skillId)
  2456. {
  2457. _skillId = skillId;
  2458. }
  2459.  
  2460. public void run()
  2461. {
  2462. try
  2463. {
  2464. enableSkill(_skillId);
  2465. }
  2466. catch (Exception e)
  2467. {
  2468. _log.log(Level.SEVERE, "Failed executing enableSkill().", e);
  2469. }
  2470. }
  2471. }
  2472.  
  2473. /**
  2474. * Task lauching the function onHitTimer().<BR><BR>
  2475. *
  2476. * <B><U> Actions</U> :</B><BR><BR>
  2477. * <li>If the attacker/target is dead or use fake death, notify the AI with EVT_CANCEL and send a Server->Client packet ActionFailed (if attacker is a L2PcInstance)</li>
  2478. * <li>If attack isn't aborted, send a message system (critical hit, missed...) to attacker/target if they are L2PcInstance </li>
  2479. * <li>If attack isn't aborted and hit isn't missed, reduce HP of the target and calculate reflection damage to reduce HP of attacker if necessary </li>
  2480. * <li>if attack isn't aborted and hit isn't missed, manage attack or cast break of the target (calculating rate, sending message...) </li><BR><BR>
  2481. *
  2482. */
  2483. class HitTask implements Runnable
  2484. {
  2485. L2Character _hitTarget;
  2486. int _damage;
  2487. boolean _crit;
  2488. boolean _miss;
  2489. byte _shld;
  2490. boolean _soulshot;
  2491.  
  2492. public HitTask(L2Character target, int damage, boolean crit, boolean miss, boolean soulshot, byte shld)
  2493. {
  2494. _hitTarget = target;
  2495. _damage = damage;
  2496. _crit = crit;
  2497. _shld = shld;
  2498. _miss = miss;
  2499. _soulshot = soulshot;
  2500. }
  2501.  
  2502. public void run()
  2503. {
  2504. try
  2505. {
  2506. onHitTimer(_hitTarget, _damage, _crit, _miss, _soulshot, _shld);
  2507. }
  2508. catch (Exception e)
  2509. {
  2510. _log.log(Level.SEVERE, "Failed executing HitTask.", e);
  2511. }
  2512. }
  2513. }
  2514.  
  2515. /** Task lauching the magic skill phases */
  2516. class MagicUseTask implements Runnable
  2517. {
  2518. L2Object[] _targets;
  2519. L2Skill _skill;
  2520. int _coolTime;
  2521. int _phase;
  2522. boolean _simultaneously;
  2523.  
  2524. public MagicUseTask(L2Object[] targets, L2Skill skill, int coolTime, int phase, boolean simultaneously)
  2525. {
  2526. _targets = targets;
  2527. _skill = skill;
  2528. _coolTime = coolTime;
  2529. _phase = phase;
  2530. _simultaneously = simultaneously;
  2531. }
  2532.  
  2533. public void run()
  2534. {
  2535. try
  2536. {
  2537. switch (_phase)
  2538. {
  2539. case 1:
  2540. onMagicLaunchedTimer(_targets, _skill, _coolTime, false, _simultaneously);
  2541. break;
  2542. case 2:
  2543. onMagicHitTimer(_targets, _skill, _coolTime, false, _simultaneously);
  2544. break;
  2545. case 3:
  2546. onMagicFinalizer(_skill, _targets[0], _simultaneously);
  2547. break;
  2548. default:
  2549. break;
  2550. }
  2551. }
  2552. catch (Exception e)
  2553. {
  2554. _log.log(Level.SEVERE, "Failed executing MagicUseTask.", e);
  2555. if (_simultaneously)
  2556. setIsCastingSimultaneouslyNow(false);
  2557. else
  2558. setIsCastingNow(false);
  2559. }
  2560. }
  2561. }
  2562.  
  2563. /** Task launching the function useMagic() */
  2564. class QueuedMagicUseTask implements Runnable
  2565. {
  2566. L2PcInstance _currPlayer;
  2567. L2Skill _queuedSkill;
  2568. boolean _isCtrlPressed;
  2569. boolean _isShiftPressed;
  2570.  
  2571. public QueuedMagicUseTask(L2PcInstance currPlayer, L2Skill queuedSkill, boolean isCtrlPressed, boolean isShiftPressed)
  2572. {
  2573. _currPlayer = currPlayer;
  2574. _queuedSkill = queuedSkill;
  2575. _isCtrlPressed = isCtrlPressed;
  2576. _isShiftPressed = isShiftPressed;
  2577. }
  2578.  
  2579. public void run()
  2580. {
  2581. try
  2582. {
  2583. _currPlayer.useMagic(_queuedSkill, _isCtrlPressed, _isShiftPressed);
  2584. }
  2585. catch (Exception e)
  2586. {
  2587. _log.log(Level.SEVERE, "Failed executing QueuedMagicUseTask.", e);
  2588. }
  2589. }
  2590. }
  2591.  
  2592. /** Task of AI notification */
  2593. public class NotifyAITask implements Runnable
  2594. {
  2595. private final CtrlEvent _evt;
  2596.  
  2597. NotifyAITask(CtrlEvent evt)
  2598. {
  2599. _evt = evt;
  2600. }
  2601.  
  2602. public void run()
  2603. {
  2604. try
  2605. {
  2606. getAI().notifyEvent(_evt, null);
  2607. }
  2608. catch (Exception e)
  2609. {
  2610. _log.log(Level.WARNING, "", e);
  2611. }
  2612. }
  2613. }
  2614.  
  2615. /** Task lauching the function stopPvPFlag() */
  2616. class PvPFlag implements Runnable
  2617. {
  2618. public PvPFlag()
  2619. {
  2620.  
  2621. }
  2622.  
  2623. public void run()
  2624. {
  2625. try
  2626. {
  2627. if (System.currentTimeMillis() > getPvpFlagLasts())
  2628. {
  2629. stopPvPFlag();
  2630. }
  2631. else if (System.currentTimeMillis() > (getPvpFlagLasts() - 20000))
  2632. {
  2633. updatePvPFlag(2);
  2634. }
  2635. else
  2636. {
  2637. updatePvPFlag(1);
  2638. // Start a new PvP timer check
  2639. //checkPvPFlag();
  2640. }
  2641. }
  2642. catch (Exception e)
  2643. {
  2644. _log.log(Level.WARNING, "error in pvp flag task:", e);
  2645. }
  2646. }
  2647. }
  2648. // =========================================================
  2649.  
  2650.  
  2651.  
  2652. /** Task lauching the magic skill phases */
  2653. class FlyToLocationTask implements Runnable
  2654. {
  2655. private final L2Object _tgt;
  2656. private final L2Character _actor;
  2657. private final L2Skill _skill;
  2658.  
  2659. public FlyToLocationTask(L2Character actor, L2Object target, L2Skill skill)
  2660. {
  2661. _actor = actor;
  2662. _tgt = target;
  2663. _skill = skill;
  2664. }
  2665.  
  2666. public void run()
  2667. {
  2668. try
  2669. {
  2670. FlyType _flyType;
  2671.  
  2672. _flyType = FlyType.valueOf(_skill.getFlyType());
  2673.  
  2674. broadcastPacket(new FlyToLocation(_actor,_tgt,_flyType));
  2675. setXYZ(_tgt.getX(), _tgt.getY(), _tgt.getZ());
  2676. broadcastPacket(new ValidateLocation(_actor));
  2677. }
  2678. catch (Exception e)
  2679. {
  2680. _log.log(Level.SEVERE, "Failed executing FlyToLocationTask.", e);
  2681. }
  2682. }
  2683. }
  2684.  
  2685.  
  2686.  
  2687.  
  2688.  
  2689. // =========================================================
  2690. // Abnormal Effect - NEED TO REMOVE ONCE L2CHARABNORMALEFFECT IS COMPLETE
  2691. // Data Field
  2692. /** Map 32 bits (0x0000) containing all abnormal effect in progress */
  2693. private int _AbnormalEffects;
  2694.  
  2695. protected CharEffectList _effects = new CharEffectList(this);
  2696.  
  2697. private int _SpecialEffects;
  2698. // Method - Public
  2699. /**
  2700. * Launch and add L2Effect (including Stack Group management) to L2Character and update client magic icon.<BR><BR>
  2701. *
  2702. * <B><U> Concept</U> :</B><BR><BR>
  2703. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
  2704. * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
  2705. *
  2706. * Several same effect can't be used on a L2Character at the same time.
  2707. * Indeed, effects are not stackable and the last cast will replace the previous in progress.
  2708. * More, some effects belong to the same Stack Group (ex WindWald and Haste Potion).
  2709. * If 2 effects of a same group are used at the same time on a L2Character, only the more efficient (identified by its priority order) will be preserve.<BR><BR>
  2710. *
  2711. * <B><U> Actions</U> :</B><BR><BR>
  2712. * <li>Add the L2Effect to the L2Character _effects</li>
  2713. * <li>If this effect doesn't belong to a Stack Group, add its Funcs to the Calculator set of the L2Character (remove the old one if necessary)</li>
  2714. * <li>If this effect has higher priority in its Stack Group, add its Funcs to the Calculator set of the L2Character (remove previous stacked effect Funcs if necessary)</li>
  2715. * <li>If this effect has NOT higher priority in its Stack Group, set the effect to Not In Use</li>
  2716. * <li>Update active skills in progress icons on player client</li><BR>
  2717. *
  2718. */
  2719. public void addEffect(L2Effect newEffect)
  2720. {
  2721. _effects.queueEffect(newEffect, false);
  2722. }
  2723.  
  2724. /**
  2725. * Stop and remove L2Effect (including Stack Group management) from L2Character and update client magic icon.<BR><BR>
  2726. *
  2727. * <B><U> Concept</U> :</B><BR><BR>
  2728. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
  2729. * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
  2730. *
  2731. * Several same effect can't be used on a L2Character at the same time.
  2732. * Indeed, effects are not stackable and the last cast will replace the previous in progress.
  2733. * More, some effects belong to the same Stack Group (ex WindWald and Haste Potion).
  2734. * If 2 effects of a same group are used at the same time on a L2Character, only the more efficient (identified by its priority order) will be preserve.<BR><BR>
  2735. *
  2736. * <B><U> Actions</U> :</B><BR><BR>
  2737. * <li>Remove Func added by this effect from the L2Character Calculator (Stop L2Effect)</li>
  2738. * <li>If the L2Effect belongs to a not empty Stack Group, replace theses Funcs by next stacked effect Funcs</li>
  2739. * <li>Remove the L2Effect from _effects of the L2Character</li>
  2740. * <li>Update active skills in progress icons on player client</li><BR>
  2741. *
  2742. */
  2743. public final void removeEffect(L2Effect effect)
  2744. {
  2745. _effects.queueEffect(effect, true);
  2746. }
  2747.  
  2748. /**
  2749. * Active abnormal effects flags in the binary mask and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2750. */
  2751. public final void startAbnormalEffect(AbnormalEffect mask)
  2752. {
  2753. _AbnormalEffects |= mask.getMask();
  2754. updateAbnormalEffect();
  2755. }
  2756.  
  2757. /**
  2758. * Active special effects flags in the binary mask and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2759. */
  2760. public final void startSpecialEffect(AbnormalEffect mask)
  2761. {
  2762. _SpecialEffects |= mask.getMask();
  2763. updateAbnormalEffect();
  2764. }
  2765.  
  2766. public final void startAbnormalEffect(int mask)
  2767. {
  2768. _AbnormalEffects |= mask;
  2769. updateAbnormalEffect();
  2770. }
  2771.  
  2772. public final void startSpecialEffect(int mask)
  2773. {
  2774. _SpecialEffects |= mask;
  2775. updateAbnormalEffect();
  2776. }
  2777.  
  2778. /**
  2779. * Active the abnormal effect Confused flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2780. */
  2781. public final void startConfused()
  2782. {
  2783. setIsConfused(true);
  2784. getAI().notifyEvent(CtrlEvent.EVT_CONFUSED);
  2785. updateAbnormalEffect();
  2786. }
  2787.  
  2788. /**
  2789. * Active the abnormal effect Fake Death flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2790. */
  2791. public final void startFakeDeath()
  2792. {
  2793. if (!(this instanceof L2PcInstance))
  2794. return;
  2795.  
  2796. ((L2PcInstance)this).setIsFakeDeath(true);
  2797. /* Aborts any attacks/casts if fake dead */
  2798. abortAttack();
  2799. abortCast();
  2800. stopMove(null);
  2801. getAI().notifyEvent(CtrlEvent.EVT_FAKE_DEATH);
  2802. broadcastPacket(new ChangeWaitType(this,ChangeWaitType.WT_START_FAKEDEATH));
  2803. }
  2804.  
  2805. /**
  2806. * Active the abnormal effect Fear flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2807. */
  2808. public final void startFear()
  2809. {
  2810. setIsAfraid(true);
  2811. getAI().notifyEvent(CtrlEvent.EVT_AFRAID);
  2812. updateAbnormalEffect();
  2813. }
  2814.  
  2815. /**
  2816. * Active the abnormal effect Muted flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2817. */
  2818. public final void startMuted()
  2819. {
  2820. setIsMuted(true);
  2821. /* Aborts any casts if muted */
  2822. abortCast();
  2823. getAI().notifyEvent(CtrlEvent.EVT_MUTED);
  2824. updateAbnormalEffect();
  2825. }
  2826.  
  2827. /**
  2828. * Active the abnormal effect Psychical_Muted flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2829. */
  2830. public final void startPsychicalMuted()
  2831. {
  2832. setIsPhysicalMuted(true);
  2833. getAI().notifyEvent(CtrlEvent.EVT_MUTED);
  2834. updateAbnormalEffect();
  2835. }
  2836.  
  2837. /**
  2838. * Active the abnormal effect Root flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2839. */
  2840. public final void startRooted()
  2841. {
  2842. setIsRooted(true);
  2843. stopMove(null);
  2844. getAI().notifyEvent(CtrlEvent.EVT_ROOTED);
  2845. updateAbnormalEffect();
  2846. }
  2847.  
  2848. /**
  2849. * Active the abnormal effect Sleep flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2850. */
  2851. public final void startImmobileUntilAttacked()
  2852. {
  2853. setIsImmobileUntilAttacked(true);
  2854. abortAttack();
  2855. abortCast();
  2856. stopMove(null);
  2857. getAI().notifyEvent(CtrlEvent.EVT_SLEEPING);
  2858. updateAbnormalEffect();
  2859. }
  2860.  
  2861. /**
  2862. * Active the abnormal effect Sleep flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2863. */
  2864. public final void startSleeping()
  2865. {
  2866. setIsSleeping(true);
  2867. /* Aborts any attacks/casts if sleeped */
  2868. abortAttack();
  2869. abortCast();
  2870. stopMove(null);
  2871. getAI().notifyEvent(CtrlEvent.EVT_SLEEPING);
  2872. updateAbnormalEffect();
  2873. }
  2874.  
  2875. /**
  2876. * Launch a Stun Abnormal Effect on the L2Character.<BR><BR>
  2877. *
  2878. * <B><U> Actions</U> :</B><BR><BR>
  2879. * <li>Calculate the success rate of the Stun Abnormal Effect on this L2Character</li>
  2880. * <li>If Stun succeed, active the abnormal effect Stun flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet</li>
  2881. * <li>If Stun NOT succeed, send a system message Failed to the L2PcInstance attacker</li><BR><BR>
  2882. *
  2883. */
  2884. public final void startStunning()
  2885. {
  2886. setIsStunned(true);
  2887. /* Aborts any attacks/casts if stunned */
  2888. abortAttack();
  2889. abortCast();
  2890. stopMove(null);
  2891. getAI().notifyEvent(CtrlEvent.EVT_STUNNED);
  2892. updateAbnormalEffect();
  2893. }
  2894.  
  2895. public final void startParalyze()
  2896. {
  2897. setIsParalyzed(true);
  2898. /* Aborts any attacks/casts if paralyzed */
  2899. abortAttack();
  2900. abortCast();
  2901. stopMove(null);
  2902. getAI().notifyEvent(CtrlEvent.EVT_PARALYZED);
  2903. updateAbnormalEffect();
  2904. }
  2905.  
  2906. public final void startBetray()
  2907. {
  2908. setIsBetrayed(true);
  2909. getAI().notifyEvent(CtrlEvent.EVT_BETRAYED);
  2910. updateAbnormalEffect();
  2911. }
  2912.  
  2913. public final void stopBetray()
  2914. {
  2915. stopEffects(L2EffectType.BETRAY);
  2916. setIsBetrayed(false);
  2917. updateAbnormalEffect();
  2918. }
  2919. /**
  2920. * Modify the abnormal effect map according to the mask.<BR><BR>
  2921. */
  2922. public final void stopAbnormalEffect(AbnormalEffect mask)
  2923. {
  2924. _AbnormalEffects &= ~mask.getMask();
  2925. updateAbnormalEffect();
  2926. }
  2927.  
  2928. /**
  2929. * Modify the special effect map according to the mask.<BR><BR>
  2930. */
  2931. public final void stopSpecialEffect(AbnormalEffect mask)
  2932. {
  2933. _SpecialEffects &= ~mask.getMask();
  2934. updateAbnormalEffect();
  2935. }
  2936.  
  2937. public final void stopAbnormalEffect(int mask)
  2938. {
  2939. _AbnormalEffects &= ~mask;
  2940. updateAbnormalEffect();
  2941. }
  2942.  
  2943. public final void stopSpecialEffect(int mask)
  2944. {
  2945. _SpecialEffects &= ~mask;
  2946. updateAbnormalEffect();
  2947. }
  2948. /**
  2949. * Stop all active skills effects in progress on the L2Character.<BR><BR>
  2950. */
  2951. public void stopAllEffects()
  2952. {
  2953. _effects.stopAllEffects();
  2954. }
  2955.  
  2956. public void stopAllEffectsExceptThoseThatLastThroughDeath()
  2957. {
  2958. _effects.stopAllEffectsExceptThoseThatLastThroughDeath();
  2959. }
  2960.  
  2961. /**
  2962. * Stop a specified/all Confused abnormal L2Effect.<BR><BR>
  2963. *
  2964. * <B><U> Actions</U> :</B><BR><BR>
  2965. * <li>Delete a specified/all (if effect=null) Confused abnormal L2Effect from L2Character and update client magic icon </li>
  2966. * <li>Set the abnormal effect flag _confused to False </li>
  2967. * <li>Notify the L2Character AI</li>
  2968. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  2969. *
  2970. */
  2971. public final void stopConfused(L2Effect effect)
  2972. {
  2973. if (effect == null)
  2974. stopEffects(L2EffectType.CONFUSION);
  2975. else
  2976. removeEffect(effect);
  2977.  
  2978. setIsConfused(false);
  2979. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  2980. updateAbnormalEffect();
  2981. }
  2982.  
  2983. /**
  2984. * Stop and remove the L2Effects corresponding to the L2Skill Identifier and update client magic icon.<BR><BR>
  2985. *
  2986. * <B><U> Concept</U> :</B><BR><BR>
  2987. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
  2988. * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
  2989. *
  2990. * @param effectId The L2Skill Identifier of the L2Effect to remove from _effects
  2991. *
  2992. */
  2993. public final void stopSkillEffects(int skillId)
  2994. {
  2995. _effects.stopSkillEffects(skillId);
  2996. }
  2997.  
  2998. /**
  2999. * Stop and remove all L2Effect of the selected type (ex : BUFF, DMG_OVER_TIME...) from the L2Character and update client magic icon.<BR><BR>
  3000. *
  3001. * <B><U> Concept</U> :</B><BR><BR>
  3002. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
  3003. * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
  3004. *
  3005. * <B><U> Actions</U> :</B><BR><BR>
  3006. * <li>Remove Func added by this effect from the L2Character Calculator (Stop L2Effect)</li>
  3007. * <li>Remove the L2Effect from _effects of the L2Character</li>
  3008. * <li>Update active skills in progress icons on player client</li><BR><BR>
  3009. *
  3010. * @param type The type of effect to stop ((ex : BUFF, DMG_OVER_TIME...)
  3011. *
  3012. */
  3013. public final void stopEffects(L2EffectType type)
  3014. {
  3015. _effects.stopEffects(type);
  3016. }
  3017.  
  3018. /**
  3019. * Stop a specified/all Fake Death abnormal L2Effect.<BR><BR>
  3020. *
  3021. * <B><U> Actions</U> :</B><BR><BR>
  3022. * <li>Delete a specified/all (if effect=null) Fake Death abnormal L2Effect from L2Character and update client magic icon </li>
  3023. * <li>Set the abnormal effect flag _fake_death to False </li>
  3024. * <li>Notify the L2Character AI</li><BR><BR>
  3025. *
  3026. */
  3027. public final void stopFakeDeath(L2Effect effect)
  3028. {
  3029. if (effect == null)
  3030. stopEffects(L2EffectType.FAKE_DEATH);
  3031. else
  3032. removeEffect(effect);
  3033.  
  3034. // if this is a player instance, start the grace period for this character (grace from mobs only)!
  3035. if (this instanceof L2PcInstance)
  3036. {
  3037. ((L2PcInstance) this).setIsFakeDeath(false);
  3038. ((L2PcInstance) this).setRecentFakeDeath(true);
  3039. }
  3040.  
  3041. ChangeWaitType revive = new ChangeWaitType(this,ChangeWaitType.WT_STOP_FAKEDEATH);
  3042. broadcastPacket(revive);
  3043. //TODO: Temp hack: players see FD on ppl that are moving: Teleport to someone who uses FD - if he gets up he will fall down again for that client -
  3044. // even tho he is actually standing... Probably bad info in CharInfo packet?
  3045. broadcastPacket(new Revive(this));
  3046. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  3047. }
  3048.  
  3049. /**
  3050. * Stop a specified/all Fear abnormal L2Effect.<BR><BR>
  3051. *
  3052. * <B><U> Actions</U> :</B><BR><BR>
  3053. * <li>Delete a specified/all (if effect=null) Fear abnormal L2Effect from L2Character and update client magic icon </li>
  3054. * <li>Set the abnormal effect flag _affraid to False </li>
  3055. * <li>Notify the L2Character AI</li>
  3056. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  3057. *
  3058. */
  3059. public final void stopFear(L2Effect effect)
  3060. {
  3061. if (effect == null)
  3062. stopEffects(L2EffectType.FEAR);
  3063. else
  3064. removeEffect(effect);
  3065.  
  3066. setIsAfraid(false);
  3067. updateAbnormalEffect();
  3068. }
  3069.  
  3070. /**
  3071. * Stop a specified/all Muted abnormal L2Effect.<BR><BR>
  3072. *
  3073. * <B><U> Actions</U> :</B><BR><BR>
  3074. * <li>Delete a specified/all (if effect=null) Muted abnormal L2Effect from L2Character and update client magic icon </li>
  3075. * <li>Set the abnormal effect flag _muted to False </li>
  3076. * <li>Notify the L2Character AI</li>
  3077. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  3078. *
  3079. */
  3080. public final void stopMuted(L2Effect effect)
  3081. {
  3082. if (effect == null)
  3083. stopEffects(L2EffectType.MUTE);
  3084. else
  3085. removeEffect(effect);
  3086.  
  3087. setIsMuted(false);
  3088. updateAbnormalEffect();
  3089. }
  3090.  
  3091. public final void stopPsychicalMuted(L2Effect effect)
  3092. {
  3093. if (effect == null)
  3094. stopEffects(L2EffectType.PHYSICAL_MUTE);
  3095. else
  3096. removeEffect(effect);
  3097.  
  3098. setIsPhysicalMuted(false);
  3099. updateAbnormalEffect();
  3100. }
  3101.  
  3102. /**
  3103. * Stop a specified/all Root abnormal L2Effect.<BR><BR>
  3104. *
  3105. * <B><U> Actions</U> :</B><BR><BR>
  3106. * <li>Delete a specified/all (if effect=null) Root abnormal L2Effect from L2Character and update client magic icon </li>
  3107. * <li>Set the abnormal effect flag _rooted to False </li>
  3108. * <li>Notify the L2Character AI</li>
  3109. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  3110. *
  3111. */
  3112. public final void stopRooting(L2Effect effect)
  3113. {
  3114. if (effect == null)
  3115. stopEffects(L2EffectType.ROOT);
  3116. else
  3117. removeEffect(effect);
  3118.  
  3119. setIsRooted(false);
  3120. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  3121. updateAbnormalEffect();
  3122. }
  3123.  
  3124. /**
  3125. * Stop immobilization until attacked abnormal L2Effect.<BR><BR>
  3126. *
  3127. * <B><U> Actions</U> :</B><BR><BR>
  3128. * <li>Delete a specified/all (if effect=null) immobilization until attacked abnormal L2Effect from L2Character and update client magic icon </li>
  3129. * <li>Set the abnormal effect flag _muted to False </li>
  3130. * <li>Notify the L2Character AI</li>
  3131. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  3132. *
  3133. */
  3134. public final void stopImmobileUntilAttacked(L2Effect effect)
  3135. {
  3136. if (effect == null)
  3137. stopEffects(L2EffectType.IMMOBILEUNTILATTACKED);
  3138. else
  3139. {
  3140. removeEffect(effect);
  3141. if (effect.getSkill().getNegateId().length != 0)
  3142. {
  3143. for (int i = 0; i < effect.getSkill().getNegateId().length; i++)
  3144. {
  3145. if (effect.getSkill().getNegateId()[i] != 0)
  3146. stopSkillEffects(effect.getSkill().getNegateId()[i]);
  3147. }
  3148. }
  3149. }
  3150.  
  3151. setIsImmobileUntilAttacked(false);
  3152. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  3153. updateAbnormalEffect();
  3154. }
  3155.  
  3156. /**
  3157. * Stop a specified/all Sleep abnormal L2Effect.<BR><BR>
  3158. *
  3159. * <B><U> Actions</U> :</B><BR><BR>
  3160. * <li>Delete a specified/all (if effect=null) Sleep abnormal L2Effect from L2Character and update client magic icon </li>
  3161. * <li>Set the abnormal effect flag _sleeping to False </li>
  3162. * <li>Notify the L2Character AI</li>
  3163. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  3164. *
  3165. */
  3166. public final void stopSleeping(L2Effect effect)
  3167. {
  3168. if (effect == null)
  3169. stopEffects(L2EffectType.SLEEP);
  3170. else
  3171. removeEffect(effect);
  3172.  
  3173. setIsSleeping(false);
  3174. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  3175. updateAbnormalEffect();
  3176. }
  3177.  
  3178. /**
  3179. * Stop a specified/all Stun abnormal L2Effect.<BR><BR>
  3180. *
  3181. * <B><U> Actions</U> :</B><BR><BR>
  3182. * <li>Delete a specified/all (if effect=null) Stun abnormal L2Effect from L2Character and update client magic icon </li>
  3183. * <li>Set the abnormal effect flag _stuned to False </li>
  3184. * <li>Notify the L2Character AI</li>
  3185. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  3186. *
  3187. */
  3188. public final void stopStunning(L2Effect effect)
  3189. {
  3190. if (effect == null)
  3191. stopEffects(L2EffectType.STUN);
  3192. else
  3193. removeEffect(effect);
  3194.  
  3195. setIsStunned(false);
  3196. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  3197. updateAbnormalEffect();
  3198. }
  3199.  
  3200. public final void stopParalyze(L2Effect effect)
  3201. {
  3202. if (effect == null)
  3203. stopEffects(L2EffectType.PARALYZE);
  3204. else
  3205. removeEffect(effect);
  3206.  
  3207. setIsParalyzed(false);
  3208. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  3209. updateAbnormalEffect();
  3210. }
  3211.  
  3212. /**
  3213. * Stop L2Effect: Transformation<BR><BR>
  3214. *
  3215. * <B><U> Actions</U> :</B><BR><BR>
  3216. * <li>Remove Transformation Effect</li>
  3217. * <li>Notify the L2Character AI</li>
  3218. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  3219. *
  3220. */
  3221. public final void stopTransformation(L2Effect effect)
  3222. {
  3223. if (effect == null)
  3224. {
  3225. stopEffects(L2EffectType.TRANSFORMATION);
  3226. }
  3227. else
  3228. {
  3229. removeEffect(effect);
  3230. }
  3231.  
  3232. // if this is a player instance, then untransform, also set the transform_id column equal to 0 if not cursed.
  3233. if (this instanceof L2PcInstance)
  3234. {
  3235. if (((L2PcInstance) this).getTransformation() != null)
  3236. {
  3237. ((L2PcInstance) this).untransform();
  3238. }
  3239. }
  3240.  
  3241. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  3242. updateAbnormalEffect();
  3243. }
  3244.  
  3245. /**
  3246. * Not Implemented.<BR><BR>
  3247. *
  3248. * <B><U> Overridden in</U> :</B><BR><BR>
  3249. * <li>L2NPCInstance</li>
  3250. * <li>L2PcInstance</li>
  3251. * <li>L2Summon</li>
  3252. * <li>L2DoorInstance</li><BR><BR>
  3253. *
  3254. */
  3255. public abstract void updateAbnormalEffect();
  3256.  
  3257. /**
  3258. * Update active skills in progress (In Use and Not In Use because stacked) icons on client.<BR><BR>
  3259. *
  3260. * <B><U> Concept</U> :</B><BR><BR>
  3261. * All active skills effects in progress (In Use and Not In Use because stacked) are represented by an icon on the client.<BR><BR>
  3262. *
  3263. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method ONLY UPDATE the client of the player and not clients of all players in the party.</B></FONT><BR><BR>
  3264. *
  3265. */
  3266. public final void updateEffectIcons()
  3267. {
  3268. updateEffectIcons(false);
  3269. }
  3270.  
  3271. /**
  3272. * Updates Effect Icons for this character(palyer/summon) and his party if any<BR>
  3273. *
  3274. * Overridden in:<BR>
  3275. * L2PcInstance<BR>
  3276. * L2Summon<BR>
  3277. *
  3278. * @param partyOnly
  3279. */
  3280. public void updateEffectIcons(boolean partyOnly)
  3281. {
  3282. // overridden
  3283. }
  3284.  
  3285. // Property - Public
  3286. /**
  3287. * Return a map of 16 bits (0x0000) containing all abnormal effect in progress for this L2Character.<BR><BR>
  3288. *
  3289. * <B><U> Concept</U> :</B><BR><BR>
  3290. * In Server->Client packet, each effect is represented by 1 bit of the map (ex : BLEEDING = 0x0001 (bit 1), SLEEP = 0x0080 (bit 8)...).
  3291. * The map is calculated by applying a BINARY OR operation on each effect.<BR><BR>
  3292. *
  3293. * <B><U> Example of use </U> :</B><BR><BR>
  3294. * <li> Server Packet : CharInfo, NpcInfo, NpcInfoPoly, UserInfo...</li><BR><BR>
  3295. */
  3296. public int getAbnormalEffect()
  3297. {
  3298. int ae = _AbnormalEffects;
  3299. if (!isFlying() && isStunned()) ae |= AbnormalEffect.STUN.getMask();
  3300. if (!isFlying() && isRooted()) ae |= AbnormalEffect.ROOT.getMask();
  3301. if (isSleeping()) ae |= AbnormalEffect.SLEEP.getMask();
  3302. if (isConfused()) ae |= AbnormalEffect.CONFUSED.getMask();
  3303. if (isMuted()) ae |= AbnormalEffect.MUTED.getMask();
  3304. if (isPhysicalMuted()) ae |= AbnormalEffect.MUTED.getMask();
  3305. return ae;
  3306. }
  3307.  
  3308. /**
  3309. * Return a map of 32 bits (0x00000000) containing all special effect in progress for this L2Character.<BR><BR>
  3310. *
  3311. * <B><U> Concept</U> :</B><BR><BR>
  3312. * In Server->Client packet, each effect is represented by 1 bit of the map (ex : INVULNERABLE = 0x0001 (bit 1), PINK_AFFRO = 0x0020 (bit 6)...).
  3313. * The map is calculated by applying a BINARY OR operation on each effect.<BR><BR>
  3314. *
  3315. * <B><U> Example of use </U> :</B><BR><BR>
  3316. * <li> Server Packet : CharInfo, UserInfo...</li><BR><BR>
  3317. */
  3318. public int getSpecialEffect()
  3319. {
  3320. int se = _SpecialEffects;
  3321. if (isFlying() && isStunned()) se |= AbnormalEffect.S_AIR_STUN.getMask();
  3322. if (isFlying() && isRooted()) se |= AbnormalEffect.S_AIR_ROOT.getMask();
  3323. return se;
  3324. }
  3325. /**
  3326. * Return all active skills effects in progress on the L2Character.<BR><BR>
  3327. *
  3328. * <B><U> Concept</U> :</B><BR><BR>
  3329. * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
  3330. * The Integer key of _effects is the L2Skill Identifier that has created the effect.<BR><BR>
  3331. *
  3332. * @return A table containing all active skills effect in progress on the L2Character
  3333. *
  3334. */
  3335. public final L2Effect[] getAllEffects()
  3336. {
  3337. return _effects.getAllEffects();
  3338. }
  3339.  
  3340. /**
  3341. * Return L2Effect in progress on the L2Character corresponding to the L2Skill Identifier.<BR><BR>
  3342. *
  3343. * <B><U> Concept</U> :</B><BR><BR>
  3344. * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
  3345. *
  3346. * @param index The L2Skill Identifier of the L2Effect to return from the _effects
  3347. *
  3348. * @return The L2Effect corresponding to the L2Skill Identifier
  3349. *
  3350. */
  3351. public final L2Effect getFirstEffect(int index)
  3352. {
  3353. return _effects.getFirstEffect(index);
  3354. }
  3355.  
  3356. /**
  3357. * Return the first L2Effect in progress on the L2Character created by the L2Skill.<BR><BR>
  3358. *
  3359. * <B><U> Concept</U> :</B><BR><BR>
  3360. * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
  3361. *
  3362. * @param skill The L2Skill whose effect must be returned
  3363. *
  3364. * @return The first L2Effect created by the L2Skill
  3365. *
  3366. */
  3367. public final L2Effect getFirstEffect(L2Skill skill)
  3368. {
  3369. return _effects.getFirstEffect(skill);
  3370. }
  3371.  
  3372. /**
  3373. * Return the first L2Effect in progress on the L2Character corresponding to the Effect Type (ex : BUFF, STUN, ROOT...).<BR><BR>
  3374. *
  3375. * <B><U> Concept</U> :</B><BR><BR>
  3376. * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
  3377. *
  3378. * @param tp The Effect Type of skills whose effect must be returned
  3379. *
  3380. * @return The first L2Effect corresponding to the Effect Type
  3381. *
  3382. */
  3383. public final L2Effect getFirstEffect(L2EffectType tp)
  3384. {
  3385. return _effects.getFirstEffect(tp);
  3386. }
  3387.  
  3388. // =========================================================
  3389. // =========================================================
  3390. // NEED TO ORGANIZE AND MOVE TO PROPER PLACE
  3391. /** This class permit to the L2Character AI to obtain informations and uses L2Character method */
  3392. public class AIAccessor
  3393. {
  3394. public AIAccessor() {}
  3395.  
  3396. /**
  3397. * Return the L2Character managed by this Accessor AI.<BR><BR>
  3398. */
  3399. public L2Character getActor()
  3400. {
  3401. return L2Character.this;
  3402. }
  3403.  
  3404. /**
  3405. * Accessor to L2Character moveToLocation() method with an interaction area.<BR><BR>
  3406. */
  3407. public void moveTo(int x, int y, int z, int offset)
  3408. {
  3409. L2Character.this.moveToLocation(x, y, z, offset);
  3410. }
  3411.  
  3412. /**
  3413. * Accessor to L2Character moveToLocation() method without interaction area.<BR><BR>
  3414. */
  3415. public void moveTo(int x, int y, int z)
  3416. {
  3417. L2Character.this.moveToLocation(x, y, z, 0);
  3418. }
  3419.  
  3420. /**
  3421. * Accessor to L2Character stopMove() method.<BR><BR>
  3422. */
  3423. public void stopMove(L2CharPosition pos)
  3424. {
  3425. L2Character.this.stopMove(pos);
  3426. }
  3427.  
  3428. /**
  3429. * Accessor to L2Character doAttack() method.<BR><BR>
  3430. */
  3431. public void doAttack(L2Character target)
  3432. {
  3433. L2Character.this.doAttack(target);
  3434. }
  3435.  
  3436. /**
  3437. * Accessor to L2Character doCast() method.<BR><BR>
  3438. */
  3439. public void doCast(L2Skill skill)
  3440. {
  3441. L2Character.this.doCast(skill);
  3442. }
  3443.  
  3444. /**
  3445. * Create a NotifyAITask.<BR><BR>
  3446. */
  3447. public NotifyAITask newNotifyTask(CtrlEvent evt)
  3448. {
  3449. return new NotifyAITask(evt);
  3450. }
  3451.  
  3452. /**
  3453. * Cancel the AI.<BR><BR>
  3454. */
  3455. public void detachAI()
  3456. {
  3457. _ai = null;
  3458. }
  3459. }
  3460.  
  3461.  
  3462. /**
  3463. * This class group all mouvement data.<BR><BR>
  3464. *
  3465. * <B><U> Data</U> :</B><BR><BR>
  3466. * <li>_moveTimestamp : Last time position update</li>
  3467. * <li>_xDestination, _yDestination, _zDestination : Position of the destination</li>
  3468. * <li>_xMoveFrom, _yMoveFrom, _zMoveFrom : Position of the origin</li>
  3469. * <li>_moveStartTime : Start time of the movement</li>
  3470. * <li>_ticksToMove : Nb of ticks between the start and the destination</li>
  3471. * <li>_xSpeedTicks, _ySpeedTicks : Speed in unit/ticks</li><BR><BR>
  3472. *
  3473. * */
  3474. public static class MoveData
  3475. {
  3476. // when we retrieve x/y/z we use GameTimeControl.getGameTicks()
  3477. // if we are moving, but move timestamp==gameticks, we don't need
  3478. // to recalculate position
  3479. public int _moveStartTime;
  3480. public int _moveTimestamp; // last update
  3481. public int _xDestination;
  3482. public int _yDestination;
  3483. public int _zDestination;
  3484. public double _xAccurate; // otherwise there would be rounding errors
  3485. public double _yAccurate;
  3486. public double _zAccurate;
  3487. public int _heading;
  3488.  
  3489. public boolean disregardingGeodata;
  3490. public int onGeodataPathIndex;
  3491. public List<AbstractNodeLoc> geoPath;
  3492. public int geoPathAccurateTx;
  3493. public int geoPathAccurateTy;
  3494. public int geoPathGtx;
  3495. public int geoPathGty;
  3496. }
  3497.  
  3498.  
  3499. /** Table containing all skillId that are disabled */
  3500. protected List<Integer> _disabledSkills;
  3501. private boolean _allSkillsDisabled;
  3502.  
  3503. // private int _flyingRunSpeed;
  3504. // private int _floatingWalkSpeed;
  3505. // private int _flyingWalkSpeed;
  3506. // private int _floatingRunSpeed;
  3507.  
  3508. /** Movement data of this L2Character */
  3509. protected MoveData _move;
  3510.  
  3511. /** Orientation of the L2Character */
  3512. private int _heading;
  3513.  
  3514. /** L2Charcater targeted by the L2Character */
  3515. private L2Object _target;
  3516.  
  3517. // set by the start of attack, in game ticks
  3518. private int _attackEndTime;
  3519. private int _attacking;
  3520. private int _disableBowAttackEndTime;
  3521. private int _disableCrossBowAttackEndTime;
  3522.  
  3523. private int _castInterruptTime;
  3524.  
  3525. /** Table of calculators containing all standard NPC calculator (ex : ACCURACY_COMBAT, EVASION_RATE */
  3526. private static final Calculator[] NPC_STD_CALCULATOR;
  3527.  
  3528.  
  3529. static {NPC_STD_CALCULATOR = Formulas.getStdNPCCalculators();}
  3530.  
  3531. protected L2CharacterAI _ai;
  3532.  
  3533. /** Future Skill Cast */
  3534. protected Future<?> _skillCast;
  3535. protected Future<?> _skillCast2;
  3536.  
  3537. /** Char Coords from Client */
  3538. private int _clientX;
  3539. private int _clientY;
  3540. private int _clientZ;
  3541. private int _clientHeading;
  3542.  
  3543. /**
  3544. * Add a Func to the Calculator set of the L2Character.<BR><BR>
  3545. *
  3546. * <B><U> Concept</U> :</B><BR><BR>
  3547. * A L2Character owns a table of Calculators called <B>_calculators</B>.
  3548. * Each Calculator (a calculator per state) own a table of Func object.
  3549. * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...).
  3550. * To reduce cache memory use, L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR><BR>
  3551. *
  3552. * That's why, if a L2NPCInstance is under a skill/spell effect that modify one of its state, a copy of the NPC_STD_CALCULATOR
  3553. * must be create in its _calculators before addind new Func object.<BR><BR>
  3554. *
  3555. * <B><U> Actions</U> :</B><BR><BR>
  3556. * <li>If _calculators is linked to NPC_STD_CALCULATOR, create a copy of NPC_STD_CALCULATOR in _calculators</li>
  3557. * <li>Add the Func object to _calculators</li><BR><BR>
  3558. *
  3559. * @param f The Func object to add to the Calculator corresponding to the state affected
  3560. */
  3561. public final void addStatFunc(Func f)
  3562. {
  3563. if (f == null)
  3564. return;
  3565.  
  3566. synchronized(_calculators)
  3567. {
  3568. // Check if Calculator set is linked to the standard Calculator set of NPC
  3569. if (_calculators == NPC_STD_CALCULATOR)
  3570. {
  3571. // Create a copy of the standard NPC Calculator set
  3572. _calculators = new Calculator[Stats.NUM_STATS];
  3573.  
  3574. for (int i=0; i < Stats.NUM_STATS; i++)
  3575. {
  3576. if (NPC_STD_CALCULATOR[i] != null)
  3577. _calculators[i] = new Calculator(NPC_STD_CALCULATOR[i]);
  3578. }
  3579. }
  3580.  
  3581. // Select the Calculator of the affected state in the Calculator set
  3582. int stat = f.stat.ordinal();
  3583.  
  3584. if (_calculators[stat] == null)
  3585. _calculators[stat] = new Calculator();
  3586.  
  3587. // Add the Func to the calculator corresponding to the state
  3588. _calculators[stat].addFunc(f);
  3589. }
  3590. }
  3591.  
  3592.  
  3593. /**
  3594. * Add a list of Funcs to the Calculator set of the L2Character.<BR><BR>
  3595. *
  3596. * <B><U> Concept</U> :</B><BR><BR>
  3597. * A L2Character owns a table of Calculators called <B>_calculators</B>.
  3598. * Each Calculator (a calculator per state) own a table of Func object.
  3599. * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...). <BR><BR>
  3600. *
  3601. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method is ONLY for L2PcInstance</B></FONT><BR><BR>
  3602. *
  3603. * <B><U> Example of use </U> :</B><BR><BR>
  3604. * <li> Equip an item from inventory</li>
  3605. * <li> Learn a new passive skill</li>
  3606. * <li> Use an active skill</li><BR><BR>
  3607. *
  3608. * @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
  3609. */
  3610. public final void addStatFuncs(Func[] funcs)
  3611. {
  3612.  
  3613. FastList<Stats> modifiedStats = new FastList<Stats>();
  3614.  
  3615. for (Func f : funcs)
  3616. {
  3617. modifiedStats.add(f.stat);
  3618. addStatFunc(f);
  3619. }
  3620. broadcastModifiedStats(modifiedStats);
  3621. }
  3622.  
  3623.  
  3624. /**
  3625. * Remove a Func from the Calculator set of the L2Character.<BR><BR>
  3626. *
  3627. * <B><U> Concept</U> :</B><BR><BR>
  3628. * A L2Character owns a table of Calculators called <B>_calculators</B>.
  3629. * Each Calculator (a calculator per state) own a table of Func object.
  3630. * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...).
  3631. * To reduce cache memory use, L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR><BR>
  3632. *
  3633. * That's why, if a L2NPCInstance is under a skill/spell effect that modify one of its state, a copy of the NPC_STD_CALCULATOR
  3634. * must be create in its _calculators before addind new Func object.<BR><BR>
  3635. *
  3636. * <B><U> Actions</U> :</B><BR><BR>
  3637. * <li>Remove the Func object from _calculators</li><BR><BR>
  3638. * <li>If L2Character is a L2NPCInstance and _calculators is equal to NPC_STD_CALCULATOR,
  3639. * free cache memory and just create a link on NPC_STD_CALCULATOR in _calculators</li><BR><BR>
  3640. *
  3641. * @param f The Func object to remove from the Calculator corresponding to the state affected
  3642. */
  3643. public final void removeStatFunc(Func f)
  3644. {
  3645. if (f == null)
  3646. return;
  3647.  
  3648. // Select the Calculator of the affected state in the Calculator set
  3649. int stat = f.stat.ordinal();
  3650.  
  3651. synchronized(_calculators)
  3652. {
  3653. if (_calculators[stat] == null)
  3654. return;
  3655.  
  3656. // Remove the Func object from the Calculator
  3657. _calculators[stat].removeFunc(f);
  3658.  
  3659. if (_calculators[stat].size() == 0)
  3660. _calculators[stat] = null;
  3661.  
  3662.  
  3663. // If possible, free the memory and just create a link on NPC_STD_CALCULATOR
  3664. if (this instanceof L2Npc)
  3665. {
  3666. int i = 0;
  3667. for (; i < Stats.NUM_STATS; i++)
  3668. {
  3669. if (!Calculator.equalsCals(_calculators[i], NPC_STD_CALCULATOR[i]))
  3670. break;
  3671. }
  3672.  
  3673. if (i >= Stats.NUM_STATS)
  3674. _calculators = NPC_STD_CALCULATOR;
  3675. }
  3676. }
  3677. }
  3678.  
  3679.  
  3680. /**
  3681. * Remove a list of Funcs from the Calculator set of the L2PcInstance.<BR><BR>
  3682. *
  3683. * <B><U> Concept</U> :</B><BR><BR>
  3684. * A L2Character owns a table of Calculators called <B>_calculators</B>.
  3685. * Each Calculator (a calculator per state) own a table of Func object.
  3686. * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...). <BR><BR>
  3687. *
  3688. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method is ONLY for L2PcInstance</B></FONT><BR><BR>
  3689. *
  3690. * <B><U> Example of use </U> :</B><BR><BR>
  3691. * <li> Unequip an item from inventory</li>
  3692. * <li> Stop an active skill</li><BR><BR>
  3693. *
  3694. * @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
  3695. */
  3696. public final void removeStatFuncs(Func[] funcs)
  3697. {
  3698.  
  3699. FastList<Stats> modifiedStats = new FastList<Stats>();
  3700.  
  3701. for (Func f : funcs)
  3702. {
  3703. modifiedStats.add(f.stat);
  3704. removeStatFunc(f);
  3705. }
  3706.  
  3707. broadcastModifiedStats(modifiedStats);
  3708.  
  3709. }
  3710.  
  3711. /**
  3712. * Remove all Func objects with the selected owner from the Calculator set of the L2Character.<BR><BR>
  3713. *
  3714. * <B><U> Concept</U> :</B><BR><BR>
  3715. * A L2Character owns a table of Calculators called <B>_calculators</B>.
  3716. * Each Calculator (a calculator per state) own a table of Func object.
  3717. * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...).
  3718. * To reduce cache memory use, L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR><BR>
  3719. *
  3720. * That's why, if a L2NPCInstance is under a skill/spell effect that modify one of its state, a copy of the NPC_STD_CALCULATOR
  3721. * must be create in its _calculators before addind new Func object.<BR><BR>
  3722. *
  3723. * <B><U> Actions</U> :</B><BR><BR>
  3724. * <li>Remove all Func objects of the selected owner from _calculators</li><BR><BR>
  3725. * <li>If L2Character is a L2NPCInstance and _calculators is equal to NPC_STD_CALCULATOR,
  3726. * free cache memory and just create a link on NPC_STD_CALCULATOR in _calculators</li><BR><BR>
  3727. *
  3728. * <B><U> Example of use </U> :</B><BR><BR>
  3729. * <li> Unequip an item from inventory</li>
  3730. * <li> Stop an active skill</li><BR><BR>
  3731. *
  3732. * @param owner The Object(Skill, Item...) that has created the effect
  3733. */
  3734. public final void removeStatsOwner(Object owner)
  3735. {
  3736.  
  3737. FastList<Stats> modifiedStats = null;
  3738.  
  3739. int i = 0;
  3740. // Go through the Calculator set
  3741. synchronized(_calculators)
  3742. {
  3743. for (Calculator calc: _calculators)
  3744. {
  3745. if (calc != null)
  3746. {
  3747. // Delete all Func objects of the selected owner
  3748. if (modifiedStats != null)
  3749. modifiedStats.addAll(calc.removeOwner(owner));
  3750. else
  3751. modifiedStats = calc.removeOwner(owner);
  3752.  
  3753. if (calc.size() == 0)
  3754. _calculators[i] = null;
  3755. }
  3756. i++;
  3757. }
  3758.  
  3759. // If possible, free the memory and just create a link on NPC_STD_CALCULATOR
  3760. if (this instanceof L2Npc)
  3761. {
  3762. i = 0;
  3763. for (; i < Stats.NUM_STATS; i++)
  3764. {
  3765. if (!Calculator.equalsCals(_calculators[i], NPC_STD_CALCULATOR[i]))
  3766. break;
  3767. }
  3768.  
  3769. if (i >= Stats.NUM_STATS)
  3770. _calculators = NPC_STD_CALCULATOR;
  3771. }
  3772.  
  3773. if (owner instanceof L2Effect && !((L2Effect)owner).preventExitUpdate)
  3774. broadcastModifiedStats(modifiedStats);
  3775. }
  3776. }
  3777.  
  3778. private void broadcastModifiedStats(FastList<Stats> stats)
  3779. {
  3780. if (stats == null || stats.isEmpty()) return;
  3781.  
  3782. boolean broadcastFull = false;
  3783. boolean otherStats = false;
  3784. StatusUpdate su = null;
  3785.  
  3786. for (Stats stat : stats)
  3787. {
  3788. if (this instanceof L2Summon && ((L2Summon)this).getOwner() != null)
  3789. {
  3790. ((L2Summon)this).updateAndBroadcastStatus(1);
  3791. break;
  3792.  
  3793. }
  3794. else if (stat==Stats.POWER_ATTACK_SPEED)
  3795. {
  3796. if (su == null) su = new StatusUpdate(getObjectId());
  3797. su.addAttribute(StatusUpdate.ATK_SPD, getPAtkSpd());
  3798. }
  3799. else if (stat==Stats.MAGIC_ATTACK_SPEED)
  3800. {
  3801. if (su == null) su = new StatusUpdate(getObjectId());
  3802. su.addAttribute(StatusUpdate.CAST_SPD, getMAtkSpd());
  3803. }
  3804. //else if (stat==Stats.MAX_HP) // TODO: self only and add more stats...
  3805. //{
  3806. // if (su == null) su = new StatusUpdate(getObjectId());
  3807. // su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
  3808. //}
  3809. else if (stat==Stats.MAX_CP)
  3810. {
  3811. if (this instanceof L2PcInstance)
  3812. {
  3813. if (su == null) su = new StatusUpdate(getObjectId());
  3814. su.addAttribute(StatusUpdate.MAX_CP, getMaxCp());
  3815. }
  3816. }
  3817. //else if (stat==Stats.MAX_MP)
  3818. //{
  3819. // if (su == null) su = new StatusUpdate(getObjectId());
  3820. // su.addAttribute(StatusUpdate.MAX_MP, getMaxMp());
  3821. //}
  3822. else if (stat==Stats.RUN_SPEED)
  3823. {
  3824. broadcastFull = true;
  3825. }
  3826. else
  3827. otherStats = true;
  3828. }
  3829.  
  3830. if (this instanceof L2PcInstance)
  3831. {
  3832. if (broadcastFull)
  3833. ((L2PcInstance)this).updateAndBroadcastStatus(2);
  3834. else
  3835. {
  3836. if (otherStats)
  3837. {
  3838. ((L2PcInstance)this).updateAndBroadcastStatus(1);
  3839. if (su != null)
  3840. {
  3841. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  3842. //synchronized (getKnownList().getKnownPlayers())
  3843. {
  3844. for (L2PcInstance player : plrs)
  3845. {
  3846. try
  3847. {
  3848. player.sendPacket(su);
  3849. }
  3850. catch (NullPointerException e)
  3851. {
  3852. }
  3853. }
  3854. }
  3855. }
  3856. }
  3857. else if (su != null) broadcastPacket(su);
  3858. }
  3859. }
  3860. else if (this instanceof L2Npc)
  3861. {
  3862. if (broadcastFull)
  3863. {
  3864. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  3865. //synchronized (getKnownList().getKnownPlayers())
  3866. {
  3867. for (L2PcInstance player : plrs)
  3868. {
  3869. if (getRunSpeed() == 0)
  3870. player.sendPacket(new ServerObjectInfo((L2Npc)this, player));
  3871. else
  3872. player.sendPacket(new AbstractNpcInfo.NpcInfo((L2Npc)this, player));
  3873. }
  3874. }
  3875. }
  3876. else if (su != null)
  3877. broadcastPacket(su);
  3878. }
  3879. else if (su != null)
  3880. broadcastPacket(su);
  3881. }
  3882.  
  3883. /**
  3884. * Return the orientation of the L2Character.<BR><BR>
  3885. */
  3886. public final int getHeading()
  3887. {
  3888. return _heading;
  3889. }
  3890.  
  3891. /**
  3892. * Set the orientation of the L2Character.<BR><BR>
  3893. */
  3894. public final void setHeading(int heading)
  3895. {
  3896. _heading = heading;
  3897. }
  3898.  
  3899. /**
  3900. * Return the X destination of the L2Character or the X position if not in movement.<BR><BR>
  3901. */
  3902. public final int getClientX()
  3903. {
  3904. return _clientX;
  3905. }
  3906. public final int getClientY()
  3907. {
  3908. return _clientY;
  3909. }
  3910. public final int getClientZ()
  3911. {
  3912. return _clientZ;
  3913. }
  3914. public final int getClientHeading()
  3915. {
  3916. return _clientHeading;
  3917. }
  3918. public final void setClientX(int val)
  3919. {
  3920. _clientX=val;
  3921. }
  3922. public final void setClientY(int val)
  3923. {
  3924. _clientY=val;
  3925. }
  3926. public final void setClientZ(int val)
  3927. {
  3928. _clientZ=val;
  3929. }
  3930. public final void setClientHeading(int val)
  3931. {
  3932. _clientHeading=val;
  3933. }
  3934. public final int getXdestination()
  3935. {
  3936. MoveData m = _move;
  3937.  
  3938. if (m != null)
  3939. return m._xDestination;
  3940.  
  3941. return getX();
  3942. }
  3943.  
  3944. /**
  3945. * Return the Y destination of the L2Character or the Y position if not in movement.<BR><BR>
  3946. */
  3947. public final int getYdestination()
  3948. {
  3949. MoveData m = _move;
  3950.  
  3951. if (m != null)
  3952. return m._yDestination;
  3953.  
  3954. return getY();
  3955. }
  3956.  
  3957. /**
  3958. * Return the Z destination of the L2Character or the Z position if not in movement.<BR><BR>
  3959. */
  3960. public final int getZdestination()
  3961. {
  3962. MoveData m = _move;
  3963.  
  3964. if (m != null)
  3965. return m._zDestination;
  3966.  
  3967. return getZ();
  3968. }
  3969.  
  3970. /**
  3971. * Return True if the L2Character is in combat.<BR><BR>
  3972. */
  3973. public boolean isInCombat()
  3974. {
  3975. return (getAI().getAttackTarget() != null || getAI().isAutoAttacking());
  3976. }
  3977.  
  3978. /**
  3979. * Return True if the L2Character is moving.<BR><BR>
  3980. */
  3981. public final boolean isMoving()
  3982. {
  3983. return _move != null;
  3984. }
  3985.  
  3986. /**
  3987. * Return True if the L2Character is travelling a calculated path.<BR><BR>
  3988. */
  3989. public final boolean isOnGeodataPath()
  3990. {
  3991. MoveData m = _move;
  3992. if (m == null)
  3993. return false;
  3994. if (m.onGeodataPathIndex == -1)
  3995. return false;
  3996. if (m.onGeodataPathIndex == m.geoPath.size()-1)
  3997. return false;
  3998. return true;
  3999. }
  4000.  
  4001.  
  4002. /**
  4003. * Return True if the L2Character is casting.<BR><BR>
  4004. */
  4005. public final boolean isCastingNow()
  4006. {
  4007. return _isCastingNow;
  4008. }
  4009. public void setIsCastingNow(boolean value)
  4010. {
  4011. _isCastingNow = value;
  4012. }
  4013.  
  4014. public final boolean isCastingSimultaneouslyNow()
  4015. {
  4016. return _isCastingSimultaneouslyNow;
  4017. }
  4018. public void setIsCastingSimultaneouslyNow(boolean value)
  4019. {
  4020. _isCastingSimultaneouslyNow = value;
  4021. }
  4022.  
  4023. /**
  4024. * Return True if the cast of the L2Character can be aborted.<BR><BR>
  4025. */
  4026. public final boolean canAbortCast()
  4027. {
  4028. return _castInterruptTime > GameTimeController.getGameTicks();
  4029. }
  4030.  
  4031. public int getCastInterruptTime()
  4032. {
  4033. return _castInterruptTime;
  4034. }
  4035.  
  4036. /**
  4037. * Return True if the L2Character is attacking.<BR><BR>
  4038. */
  4039. public boolean isAttackingNow()
  4040. {
  4041. return _attackEndTime > GameTimeController.getGameTicks();
  4042. }
  4043.  
  4044. /**
  4045. * Return True if the L2Character has aborted its attack.<BR><BR>
  4046. */
  4047. public final boolean isAttackAborted()
  4048. {
  4049. return _attacking <= 0;
  4050. }
  4051.  
  4052.  
  4053. /**
  4054. * Abort the attack of the L2Character and send Server->Client ActionFailed packet.<BR><BR>
  4055. */
  4056. public final void abortAttack()
  4057. {
  4058. if (isAttackingNow())
  4059. {
  4060. _attacking = 0;
  4061. sendPacket(ActionFailed.STATIC_PACKET);
  4062. }
  4063. }
  4064.  
  4065. /**
  4066. * Returns body part (paperdoll slot) we are targeting right now
  4067. */
  4068. public final int getAttackingBodyPart()
  4069. {
  4070. return _attacking;
  4071. }
  4072.  
  4073. /**
  4074. * Abort the cast of the L2Character and send Server->Client MagicSkillCanceld/ActionFailed packet.<BR><BR>
  4075. */
  4076. public final void abortCast()
  4077. {
  4078. if (isCastingNow() || isCastingSimultaneouslyNow())
  4079. {
  4080. // cancels the skill hit scheduled task
  4081. if (_skillCast != null)
  4082. {
  4083. try
  4084. {
  4085. _skillCast.cancel(true);
  4086. }
  4087. catch (NullPointerException e) {}
  4088.  
  4089. _skillCast = null;
  4090. }
  4091. if (_skillCast2 != null)
  4092. {
  4093. try
  4094. {
  4095. _skillCast2.cancel(true);
  4096. }
  4097. catch (NullPointerException e) {}
  4098.  
  4099. _skillCast2 = null;
  4100. }
  4101.  
  4102. if (getFusionSkill() != null)
  4103. getFusionSkill().onCastAbort();
  4104.  
  4105. L2Effect mog = getFirstEffect(L2EffectType.SIGNET_GROUND);
  4106. if (mog != null)
  4107. mog.exit();
  4108.  
  4109. if (_allSkillsDisabled) enableAllSkills(); // this remains for forced skill use, e.g. scroll of escape
  4110. setIsCastingNow(false);
  4111. setIsCastingSimultaneouslyNow(false);
  4112. // safeguard for cannot be interrupt any more
  4113. _castInterruptTime = 0;
  4114. if (this instanceof L2PcInstance) getAI().notifyEvent(CtrlEvent.EVT_FINISH_CASTING); // setting back previous intention
  4115. broadcastPacket(new MagicSkillCanceld(getObjectId())); // broadcast packet to stop animations client-side
  4116. sendPacket(ActionFailed.STATIC_PACKET); // send an "action failed" packet to the caster
  4117. }
  4118. }
  4119.  
  4120. /**
  4121. * Update the position of the L2Character during a movement and return True if the movement is finished.<BR><BR>
  4122. *
  4123. * <B><U> Concept</U> :</B><BR><BR>
  4124. * At the beginning of the move action, all properties of the movement are stored in the MoveData object called <B>_move</B> of the L2Character.
  4125. * The position of the start point and of the destination permit to estimated in function of the movement speed the time to achieve the destination.<BR><BR>
  4126. *
  4127. * When the movement is started (ex : by MovetoLocation), this method will be called each 0.1 sec to estimate and update the L2Character position on the server.
  4128. * Note, that the current server position can differe from the current client position even if each movement is straight foward.
  4129. * That's why, client send regularly a Client->Server ValidatePosition packet to eventually correct the gap on the server.
  4130. * But, it's always the server position that is used in range calculation.<BR><BR>
  4131. *
  4132. * At the end of the estimated movement time, the L2Character position is automatically set to the destination position even if the movement is not finished.<BR><BR>
  4133. *
  4134. * <FONT COLOR=#FF0000><B> <U>Caution</U> : The current Z position is obtained FROM THE CLIENT by the Client->Server ValidatePosition Packet.
  4135. * But x and y positions must be calculated to avoid that players try to modify their movement speed.</B></FONT><BR><BR>
  4136. *
  4137. * @param gameTicks Nb of ticks since the server start
  4138. * @return True if the movement is finished
  4139. */
  4140. public boolean updatePosition(int gameTicks)
  4141. {
  4142. // Get movement data
  4143. MoveData m = _move;
  4144.  
  4145. if (m == null)
  4146. return true;
  4147.  
  4148. if (!isVisible())
  4149. {
  4150. _move = null;
  4151. return true;
  4152. }
  4153.  
  4154. // Check if this is the first update
  4155. if (m._moveTimestamp == 0)
  4156. {
  4157. m._moveTimestamp = m._moveStartTime;
  4158. m._xAccurate = getX();
  4159. m._yAccurate = getY();
  4160. }
  4161.  
  4162. // Check if the position has already been calculated
  4163. if (m._moveTimestamp == gameTicks)
  4164. return false;
  4165.  
  4166. int xPrev = getX();
  4167. int yPrev = getY();
  4168. int zPrev = getZ(); // the z coordinate may be modified by coordinate synchronizations
  4169.  
  4170. double dx, dy, dz, distFraction;
  4171. if (Config.COORD_SYNCHRONIZE == 1)
  4172. // the only method that can modify x,y while moving (otherwise _move would/should be set null)
  4173. {
  4174. dx = m._xDestination - xPrev;
  4175. dy = m._yDestination - yPrev;
  4176. }
  4177. else // otherwise we need saved temporary values to avoid rounding errors
  4178. {
  4179. dx = m._xDestination - m._xAccurate;
  4180. dy = m._yDestination - m._yAccurate;
  4181. }
  4182. // Z coordinate will follow geodata or client values
  4183. if (Config.GEODATA > 0 && Config.COORD_SYNCHRONIZE == 2
  4184. && !isFlying()
  4185. && !isInsideZone(L2Character.ZONE_WATER)
  4186. && !m.disregardingGeodata
  4187. && GameTimeController.getGameTicks() % 10 == 0 // once a second to reduce possible cpu load
  4188. && GeoData.getInstance().hasGeo(xPrev, yPrev)
  4189. && !(this instanceof L2BoatInstance)
  4190. && !(this instanceof L2AirShipInstance))
  4191. {
  4192. short geoHeight = GeoData.getInstance().getSpawnHeight(xPrev, yPrev, zPrev-30, zPrev+30, this.getObjectId());
  4193. dz = m._zDestination - geoHeight;
  4194. // quite a big difference, compare to validatePosition packet
  4195. if (this instanceof L2PcInstance && Math.abs(((L2PcInstance)this).getClientZ()-geoHeight) > 200 && Math.abs(((L2PcInstance)this).getClientZ()-geoHeight) < 1500)
  4196. {
  4197. dz = m._zDestination - zPrev; // allow diff
  4198. }
  4199. else if (this.isInCombat() && Math.abs(dz) > 200 && (dx*dx + dy*dy) < 40000) // allow mob to climb up to pcinstance
  4200. {
  4201. dz = m._zDestination - zPrev; // climbing
  4202. }
  4203. else
  4204. {
  4205. zPrev = geoHeight;
  4206. }
  4207. }
  4208. else
  4209. dz = m._zDestination - zPrev;
  4210.  
  4211. float speed;
  4212. if (this instanceof L2BoatInstance)
  4213. {
  4214. speed = ((L2BoatInstance)this).boatSpeed;
  4215. }
  4216. else if (this instanceof L2AirShipInstance)
  4217. {
  4218. speed = ((L2AirShipInstance)this).boatSpeed;
  4219. }
  4220. else
  4221. {
  4222. speed = getStat().getMoveSpeed();
  4223. }
  4224.  
  4225. double distPassed = speed * (gameTicks - m._moveTimestamp) / GameTimeController.TICKS_PER_SECOND;
  4226. if ((dx*dx + dy*dy) < 10000 && (dz*dz > 2500)) // close enough, allows error between client and server geodata if it cannot be avoided
  4227. {
  4228. distFraction = distPassed / Math.sqrt(dx*dx + dy*dy);
  4229. }
  4230. else
  4231. distFraction = distPassed / Math.sqrt(dx*dx + dy*dy + dz*dz);
  4232.  
  4233. // if (Config.DEVELOPER) _log.warning("Move Ticks:" + (gameTicks - m._moveTimestamp) + ", distPassed:" + distPassed + ", distFraction:" + distFraction);
  4234.  
  4235. if (distFraction > 1) // already there
  4236. {
  4237. // Set the position of the L2Character to the destination
  4238. super.getPosition().setXYZ(m._xDestination, m._yDestination, m._zDestination);
  4239. if (this instanceof L2BoatInstance)
  4240. {
  4241. ((L2BoatInstance)this).updatePeopleInTheBoat(m._xDestination, m._yDestination, m._zDestination);
  4242. }
  4243. else if (this instanceof L2AirShipInstance)
  4244. {
  4245. ((L2AirShipInstance)this).updatePeopleInTheAirShip(m._xDestination, m._yDestination, m._zDestination);
  4246. }
  4247. else
  4248. {
  4249. revalidateZone(false);
  4250. }
  4251. }
  4252. else
  4253. {
  4254. m._xAccurate += dx * distFraction;
  4255. m._yAccurate += dy * distFraction;
  4256.  
  4257. // Set the position of the L2Character to estimated after parcial move
  4258. super.getPosition().setXYZ((int)(m._xAccurate), (int)(m._yAccurate), zPrev + (int)(dz * distFraction + 0.5));
  4259. if(this instanceof L2BoatInstance )
  4260. {
  4261. ((L2BoatInstance)this).updatePeopleInTheBoat((int)(m._xAccurate), (int)(m._yAccurate), zPrev + (int)(dz * distFraction + 0.5));
  4262. }
  4263. else if (this instanceof L2AirShipInstance)
  4264. {
  4265. ((L2AirShipInstance)this).updatePeopleInTheAirShip(m._xDestination, m._yDestination, m._zDestination);
  4266. }
  4267. else
  4268. {
  4269. revalidateZone(false);
  4270. }
  4271. }
  4272.  
  4273. // Set the timer of last position update to now
  4274. m._moveTimestamp = gameTicks;
  4275.  
  4276. return (distFraction > 1);
  4277. }
  4278.  
  4279. public void revalidateZone(boolean force)
  4280. {
  4281. if (getWorldRegion() == null) return;
  4282.  
  4283. // This function is called too often from movement code
  4284. if (force) _zoneValidateCounter = 4;
  4285. else
  4286. {
  4287. _zoneValidateCounter--;
  4288. if (_zoneValidateCounter < 0)
  4289. _zoneValidateCounter = 4;
  4290. else return;
  4291. }
  4292.  
  4293. getWorldRegion().revalidateZones(this);
  4294. }
  4295.  
  4296.  
  4297. /**
  4298. * Stop movement of the L2Character (Called by AI Accessor only).<BR><BR>
  4299. *
  4300. * <B><U> Actions</U> :</B><BR><BR>
  4301. * <li>Delete movement data of the L2Character </li>
  4302. * <li>Set the current position (x,y,z), its current L2WorldRegion if necessary and its heading </li>
  4303. * <li>Remove the L2Object object from _gmList** of GmListTable </li>
  4304. * <li>Remove object from _knownObjects and _knownPlayer* of all surrounding L2WorldRegion L2Characters </li><BR><BR>
  4305. *
  4306. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T send Server->Client packet StopMove/StopRotation </B></FONT><BR><BR>
  4307. *
  4308. */
  4309. public void stopMove(L2CharPosition pos) { stopMove(pos, false); }
  4310. public void stopMove(L2CharPosition pos, boolean updateKnownObjects)
  4311. {
  4312. // Delete movement data of the L2Character
  4313. _move = null;
  4314.  
  4315. //if (getAI() != null)
  4316. // getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  4317.  
  4318. // Set the current position (x,y,z), its current L2WorldRegion if necessary and its heading
  4319. // All data are contained in a L2CharPosition object
  4320. if (pos != null)
  4321. {
  4322. getPosition().setXYZ(pos.x, pos.y, pos.z);
  4323. setHeading(pos.heading);
  4324. revalidateZone(true);
  4325. }
  4326. broadcastPacket(new StopMove(this));
  4327. if (Config.MOVE_BASED_KNOWNLIST && updateKnownObjects) this.getKnownList().findObjects();
  4328. }
  4329.  
  4330. /**
  4331. * @return Returns the showSummonAnimation.
  4332. */
  4333. public boolean isShowSummonAnimation()
  4334. {
  4335. return _showSummonAnimation;
  4336. }
  4337.  
  4338. /**
  4339. * @param showSummonAnimation The showSummonAnimation to set.
  4340. */
  4341. public void setShowSummonAnimation(boolean showSummonAnimation)
  4342. {
  4343. _showSummonAnimation = showSummonAnimation;
  4344. }
  4345.  
  4346. /**
  4347. * Target a L2Object (add the target to the L2Character _target, _knownObject and L2Character to _KnownObject of the L2Object).<BR><BR>
  4348. *
  4349. * <B><U> Concept</U> :</B><BR><BR>
  4350. * The L2Object (including L2Character) targeted is identified in <B>_target</B> of the L2Character<BR><BR>
  4351. *
  4352. * <B><U> Actions</U> :</B><BR><BR>
  4353. * <li>Set the _target of L2Character to L2Object </li>
  4354. * <li>If necessary, add L2Object to _knownObject of the L2Character </li>
  4355. * <li>If necessary, add L2Character to _KnownObject of the L2Object </li>
  4356. * <li>If object==null, cancel Attak or Cast </li><BR><BR>
  4357. *
  4358. * <B><U> Overridden in </U> :</B><BR><BR>
  4359. * <li> L2PcInstance : Remove the L2PcInstance from the old target _statusListener and add it to the new target if it was a L2Character</li><BR><BR>
  4360. *
  4361. * @param object L2object to target
  4362. *
  4363. */
  4364. public void setTarget(L2Object object)
  4365. {
  4366. if (object != null && !object.isVisible())
  4367. object = null;
  4368.  
  4369. if (object != null && object != _target)
  4370. {
  4371. getKnownList().addKnownObject(object);
  4372. object.getKnownList().addKnownObject(this);
  4373. }
  4374.  
  4375. _target = object;
  4376. }
  4377.  
  4378. /**
  4379. * Return the identifier of the L2Object targeted or -1.<BR><BR>
  4380. */
  4381. public final int getTargetId()
  4382. {
  4383. if (_target != null)
  4384. {
  4385. return _target.getObjectId();
  4386. }
  4387.  
  4388. return -1;
  4389. }
  4390.  
  4391. /**
  4392. * Return the L2Object targeted or null.<BR><BR>
  4393. */
  4394. public final L2Object getTarget()
  4395. {
  4396. return _target;
  4397. }
  4398.  
  4399. // called from AIAccessor only
  4400. /**
  4401. * Calculate movement data for a move to location action and add the L2Character to movingObjects of GameTimeController (only called by AI Accessor).<BR><BR>
  4402. *
  4403. * <B><U> Concept</U> :</B><BR><BR>
  4404. * At the beginning of the move action, all properties of the movement are stored in the MoveData object called <B>_move</B> of the L2Character.
  4405. * The position of the start point and of the destination permit to estimated in function of the movement speed the time to achieve the destination.<BR><BR>
  4406. * All L2Character in movement are identified in <B>movingObjects</B> of GameTimeController that will call the updatePosition method of those L2Character each 0.1s.<BR><BR>
  4407. *
  4408. * <B><U> Actions</U> :</B><BR><BR>
  4409. * <li>Get current position of the L2Character </li>
  4410. * <li>Calculate distance (dx,dy) between current position and destination including offset </li>
  4411. * <li>Create and Init a MoveData object </li>
  4412. * <li>Set the L2Character _move object to MoveData object </li>
  4413. * <li>Add the L2Character to movingObjects of the GameTimeController </li>
  4414. * <li>Create a task to notify the AI that L2Character arrives at a check point of the movement </li><BR><BR>
  4415. *
  4416. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T send Server->Client packet MoveToPawn/CharMoveToLocation </B></FONT><BR><BR>
  4417. *
  4418. * <B><U> Example of use </U> :</B><BR><BR>
  4419. * <li> AI : onIntentionMoveTo(L2CharPosition), onIntentionPickUp(L2Object), onIntentionInteract(L2Object) </li>
  4420. * <li> FollowTask </li><BR><BR>
  4421. *
  4422. * @param x The X position of the destination
  4423. * @param y The Y position of the destination
  4424. * @param z The Y position of the destination
  4425. * @param offset The size of the interaction area of the L2Character targeted
  4426. *
  4427. */
  4428. protected void moveToLocation(int x, int y, int z, int offset)
  4429. {
  4430. // Get the Move Speed of the L2Charcater
  4431. float speed = getStat().getMoveSpeed();
  4432. if (speed <= 0 || isMovementDisabled()) return;
  4433.  
  4434. // Get current position of the L2Character
  4435. final int curX = super.getX();
  4436. final int curY = super.getY();
  4437. final int curZ = super.getZ();
  4438.  
  4439. // Calculate distance (dx,dy) between current position and destination
  4440. // TODO: improve Z axis move/follow support when dx,dy are small compared to dz
  4441. double dx = (x - curX);
  4442. double dy = (y - curY);
  4443. double dz = (z - curZ);
  4444. double distance = Math.sqrt(dx*dx + dy*dy);
  4445.  
  4446. // make water move short and use no geodata checks for swimming chars
  4447. // distance in a click can easily be over 3000
  4448. if (Config.GEODATA > 0 && isInsideZone(ZONE_WATER) && distance > 700)
  4449. {
  4450. double divider = 700/distance;
  4451. x = curX + (int)(divider * dx);
  4452. y = curY + (int)(divider * dy);
  4453. z = curZ + (int)(divider * dz);
  4454. dx = (x - curX);
  4455. dy = (y - curY);
  4456. dz = (z - curZ);
  4457. distance = Math.sqrt(dx*dx + dy*dy);
  4458. }
  4459.  
  4460. if (Config.DEBUG) _log.fine("distance to target:" + distance);
  4461.  
  4462. // Define movement angles needed
  4463. // ^
  4464. // | X (x,y)
  4465. // | /
  4466. // | /distance
  4467. // | /
  4468. // |/ angle
  4469. // X ---------->
  4470. // (curx,cury)
  4471.  
  4472. double cos;
  4473. double sin;
  4474.  
  4475. // Check if a movement offset is defined or no distance to go through
  4476. if (offset > 0 || distance < 1)
  4477. {
  4478. // approximation for moving closer when z coordinates are different
  4479. // TODO: handle Z axis movement better
  4480. offset -= Math.abs(dz);
  4481. if (offset < 5) offset = 5;
  4482.  
  4483. // If no distance to go through, the movement is canceled
  4484. if (distance < 1 || distance - offset <= 0)
  4485. {
  4486. if (Config.DEBUG) _log.fine("already in range, no movement needed.");
  4487.  
  4488. // Notify the AI that the L2Character is arrived at destination
  4489. getAI().notifyEvent(CtrlEvent.EVT_ARRIVED);
  4490.  
  4491. return;
  4492. }
  4493. // Calculate movement angles needed
  4494. sin = dy/distance;
  4495. cos = dx/distance;
  4496.  
  4497. distance -= (offset-5); // due to rounding error, we have to move a bit closer to be in range
  4498.  
  4499. // Calculate the new destination with offset included
  4500. x = curX + (int)(distance * cos);
  4501. y = curY + (int)(distance * sin);
  4502.  
  4503. }
  4504. else
  4505. {
  4506. // Calculate movement angles needed
  4507. sin = dy/distance;
  4508. cos = dx/distance;
  4509. }
  4510.  
  4511. // Create and Init a MoveData object
  4512. MoveData m = new MoveData();
  4513.  
  4514. // GEODATA MOVEMENT CHECKS AND PATHFINDING
  4515. m.onGeodataPathIndex = -1; // Initialize not on geodata path
  4516. m.disregardingGeodata = false;
  4517.  
  4518. if (Config.GEODATA > 0
  4519. && !isFlying() // flying chars not checked - even canSeeTarget doesn't work yet
  4520. && (!isInsideZone(ZONE_WATER) || isInsideZone(ZONE_SIEGE)) // swimming also not checked unless in siege zone - but distance is limited
  4521. && !(this instanceof L2NpcWalkerInstance)) // npc walkers not checked
  4522. {
  4523. double originalDistance = distance;
  4524. int originalX = x;
  4525. int originalY = y;
  4526. int originalZ = z;
  4527. int gtx = (originalX - L2World.MAP_MIN_X) >> 4;
  4528. int gty = (originalY - L2World.MAP_MIN_Y) >> 4;
  4529.  
  4530. // Movement checks:
  4531. // when geodata == 2, for all characters except mobs returning home (could be changed later to teleport if pathfinding fails)
  4532. // when geodata == 1, for l2playableinstance and l2riftinstance only
  4533. if ((Config.GEODATA == 2 && !(this instanceof L2Attackable && ((L2Attackable)this).isReturningToSpawnPoint()))
  4534. || this instanceof L2PcInstance
  4535. || (this instanceof L2Summon && !(this.getAI().getIntention() == AI_INTENTION_FOLLOW)) // assuming intention_follow only when following owner
  4536. || isAfraid()
  4537. || this instanceof L2RiftInvaderInstance)
  4538. {
  4539. if (isOnGeodataPath())
  4540. {
  4541. try {
  4542. if (gtx == _move.geoPathGtx && gty == _move.geoPathGty)
  4543. return;
  4544. else
  4545. _move.onGeodataPathIndex = -1; // Set not on geodata path
  4546. } catch (NullPointerException e)
  4547. {
  4548. // nothing
  4549. }
  4550. }
  4551.  
  4552. if (curX < L2World.MAP_MIN_X || curX > L2World.MAP_MAX_X || curY < L2World.MAP_MIN_Y || curY > L2World.MAP_MAX_Y)
  4553. {
  4554. // Temporary fix for character outside world region errors
  4555. _log.warning("Character "+this.getName()+" outside world area, in coordinates x:"+curX+" y:"+curY);
  4556. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  4557. if (this instanceof L2PcInstance) ((L2PcInstance)this).deleteMe();
  4558. else if (this instanceof L2Summon) return; // preventation when summon get out of world coords, player will not loose him, unsummon handled from pcinstance
  4559. else this.onDecay();
  4560. return;
  4561. }
  4562. Location destiny = GeoData.getInstance().moveCheck(curX, curY, curZ, x, y, z, getInstanceId());
  4563. // location different if destination wasn't reached (or just z coord is different)
  4564. x = destiny.getX();
  4565. y = destiny.getY();
  4566. z = destiny.getZ();
  4567. distance = Math.sqrt((x - curX)*(x - curX) + (y - curY)*(y - curY));
  4568.  
  4569. }
  4570. // Pathfinding checks. Only when geodata setting is 2, the LoS check gives shorter result
  4571. // than the original movement was and the LoS gives a shorter distance than 2000
  4572. // This way of detecting need for pathfinding could be changed.
  4573. if(Config.GEODATA == 2 && originalDistance-distance > 100 && distance < 2000 && !this.isAfraid())
  4574. {
  4575. // Path calculation
  4576. // Overrides previous movement check
  4577. if(this instanceof L2Playable || this.isInCombat() || this instanceof L2MinionInstance)
  4578. {
  4579.  
  4580. m.geoPath = PathFinding.getInstance().findPath(curX, curY, curZ, originalX, originalY, originalZ, getInstanceId());
  4581. if (m.geoPath == null || m.geoPath.size() < 2) // No path found
  4582. {
  4583. // * Even though there's no path found (remember geonodes aren't perfect),
  4584. // the mob is attacking and right now we set it so that the mob will go
  4585. // after target anyway, is dz is small enough.
  4586. // * With cellpathfinding this approach could be changed but would require taking
  4587. // off the geonodes and some more checks.
  4588. // * Summons will follow their masters no matter what.
  4589. // * Currently minions also must move freely since L2AttackableAI commands
  4590. // them to move along with their leader
  4591. if (this instanceof L2PcInstance
  4592. || (!(this instanceof L2Playable)
  4593. && !(this instanceof L2MinionInstance)
  4594. && Math.abs(z - curZ) > 140)
  4595. || (this instanceof L2Summon && !((L2Summon)this).getFollowStatus()))
  4596. {
  4597. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  4598. return;
  4599. }
  4600. else
  4601. {
  4602. m.disregardingGeodata = true;
  4603. x = originalX;
  4604. y = originalY;
  4605. z = originalZ;
  4606. distance = originalDistance;
  4607. }
  4608. }
  4609. else
  4610. {
  4611. m.onGeodataPathIndex = 0; // on first segment
  4612. m.geoPathGtx = gtx;
  4613. m.geoPathGty = gty;
  4614. m.geoPathAccurateTx = originalX;
  4615. m.geoPathAccurateTy = originalY;
  4616.  
  4617. x = m.geoPath.get(m.onGeodataPathIndex).getX();
  4618. y = m.geoPath.get(m.onGeodataPathIndex).getY();
  4619. z = m.geoPath.get(m.onGeodataPathIndex).getZ();
  4620.  
  4621. // check for doors in the route
  4622. if (DoorTable.getInstance().checkIfDoorsBetween(curX, curY, curZ, x, y, z, getInstanceId()))
  4623. {
  4624. m.geoPath = null;
  4625. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  4626. return;
  4627. }
  4628. for (int i = 0; i < m.geoPath.size()-1; i++)
  4629. {
  4630. if (DoorTable.getInstance().checkIfDoorsBetween(m.geoPath.get(i),m.geoPath.get(i+1),getInstanceId()))
  4631. {
  4632. m.geoPath = null;
  4633. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  4634. return;
  4635. }
  4636. }
  4637.  
  4638. dx = (x - curX);
  4639. dy = (y - curY);
  4640. distance = Math.sqrt(dx*dx + dy*dy);
  4641. sin = dy/distance;
  4642. cos = dx/distance;
  4643. }
  4644. }
  4645. }
  4646. // If no distance to go through, the movement is canceled
  4647. if (distance < 1 && (Config.GEODATA == 2
  4648. || this instanceof L2Playable
  4649. || this.isAfraid()
  4650. || this instanceof L2RiftInvaderInstance))
  4651. {
  4652. if(this instanceof L2Summon) ((L2Summon)this).setFollowStatus(false);
  4653. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  4654. return;
  4655. }
  4656. }
  4657.  
  4658. // Caclulate the Nb of ticks between the current position and the destination
  4659. // One tick added for rounding reasons
  4660. int ticksToMove = 1+(int)(GameTimeController.TICKS_PER_SECOND * distance / speed);
  4661. m._xDestination = x;
  4662. m._yDestination = y;
  4663. m._zDestination = z; // this is what was requested from client
  4664.  
  4665. // Calculate and set the heading of the L2Character
  4666. m._heading = 0; // initial value for coordinate sync
  4667. setHeading(Util.calculateHeadingFrom(cos, sin));
  4668.  
  4669. if (Config.DEBUG)
  4670. _log.fine("dist:"+ distance +"speed:" + speed + " ttt:" + ticksToMove +
  4671. " heading:" + getHeading());
  4672.  
  4673. m._moveStartTime = GameTimeController.getGameTicks();
  4674.  
  4675. // Set the L2Character _move object to MoveData object
  4676. _move = m;
  4677.  
  4678. // Add the L2Character to movingObjects of the GameTimeController
  4679. // The GameTimeController manage objects movement
  4680. GameTimeController.getInstance().registerMovingObject(this);
  4681.  
  4682. // Create a task to notify the AI that L2Character arrives at a check point of the movement
  4683. if (ticksToMove*GameTimeController.MILLIS_IN_TICK > 3000)
  4684. ThreadPoolManager.getInstance().scheduleAi( new NotifyAITask(CtrlEvent.EVT_ARRIVED_REVALIDATE), 2000);
  4685.  
  4686. // the CtrlEvent.EVT_ARRIVED will be sent when the character will actually arrive
  4687. // to destination by GameTimeController
  4688. }
  4689.  
  4690. public boolean moveToNextRoutePoint()
  4691. {
  4692. if(!this.isOnGeodataPath())
  4693. {
  4694. // Cancel the move action
  4695. _move = null;
  4696. return false;
  4697. }
  4698.  
  4699. // Get the Move Speed of the L2Charcater
  4700. float speed = getStat().getMoveSpeed();
  4701. if (speed <= 0 || isMovementDisabled())
  4702. {
  4703. // Cancel the move action
  4704. _move = null;
  4705. return false;
  4706. }
  4707.  
  4708. MoveData md = _move;
  4709. if (md == null)
  4710. return false;
  4711.  
  4712. // Create and Init a MoveData object
  4713. MoveData m = new MoveData();
  4714.  
  4715. // Update MoveData object
  4716. m.onGeodataPathIndex = md.onGeodataPathIndex + 1; // next segment
  4717. m.geoPath = md.geoPath;
  4718. m.geoPathGtx = md.geoPathGtx;
  4719. m.geoPathGty = md.geoPathGty;
  4720. m.geoPathAccurateTx = md.geoPathAccurateTx;
  4721. m.geoPathAccurateTy = md.geoPathAccurateTy;
  4722.  
  4723. if (md.onGeodataPathIndex == md.geoPath.size()-2)
  4724. {
  4725. m._xDestination = md.geoPathAccurateTx;
  4726. m._yDestination = md.geoPathAccurateTy;
  4727. m._zDestination = md.geoPath.get(m.onGeodataPathIndex).getZ();
  4728. }
  4729. else
  4730. {
  4731. m._xDestination = md.geoPath.get(m.onGeodataPathIndex).getX();
  4732. m._yDestination = md.geoPath.get(m.onGeodataPathIndex).getY();
  4733. m._zDestination = md.geoPath.get(m.onGeodataPathIndex).getZ();
  4734. }
  4735. double dx = (m._xDestination - super.getX());
  4736. double dy = (m._yDestination - super.getY());
  4737. double distance = Math.sqrt(dx*dx + dy*dy);
  4738. double sin = dy/distance;
  4739. double cos = dx/distance;
  4740.  
  4741. // Caclulate the Nb of ticks between the current position and the destination
  4742. // One tick added for rounding reasons
  4743. int ticksToMove = 1+(int)(GameTimeController.TICKS_PER_SECOND * distance / speed);
  4744.  
  4745. // Calculate and set the heading of the L2Character
  4746. int heading = (int) (Math.atan2(-sin, -cos) * 10430.378);
  4747. heading += 32768;
  4748. setHeading(heading);
  4749. m._heading = 0; // initial value for coordinate sync
  4750.  
  4751. m._moveStartTime = GameTimeController.getGameTicks();
  4752.  
  4753. if (Config.DEBUG) _log.fine("time to target:" + ticksToMove);
  4754.  
  4755. // Set the L2Character _move object to MoveData object
  4756. _move = m;
  4757.  
  4758. // Add the L2Character to movingObjects of the GameTimeController
  4759. // The GameTimeController manage objects movement
  4760. GameTimeController.getInstance().registerMovingObject(this);
  4761.  
  4762. // Create a task to notify the AI that L2Character arrives at a check point of the movement
  4763. if (ticksToMove*GameTimeController.MILLIS_IN_TICK > 3000)
  4764. ThreadPoolManager.getInstance().scheduleAi( new NotifyAITask(CtrlEvent.EVT_ARRIVED_REVALIDATE), 2000);
  4765.  
  4766. // the CtrlEvent.EVT_ARRIVED will be sent when the character will actually arrive
  4767. // to destination by GameTimeController
  4768.  
  4769. // Send a Server->Client packet CharMoveToLocation to the actor and all L2PcInstance in its _knownPlayers
  4770. MoveToLocation msg = new MoveToLocation(this);
  4771. broadcastPacket(msg);
  4772.  
  4773. return true;
  4774. }
  4775.  
  4776. public boolean validateMovementHeading(int heading)
  4777. {
  4778. MoveData m = _move;
  4779.  
  4780. if (m == null) return true;
  4781.  
  4782. boolean result = true;
  4783. if (m._heading != heading)
  4784. {
  4785. result = (m._heading == 0); // initial value or false
  4786. m._heading = heading;
  4787. }
  4788.  
  4789. return result;
  4790. }
  4791.  
  4792. /**
  4793. * Return the distance between the current position of the L2Character and the target (x,y).<BR><BR>
  4794. *
  4795. * @param x X position of the target
  4796. * @param y Y position of the target
  4797. * @return the plan distance
  4798. *
  4799. * @deprecated use getPlanDistanceSq(int x, int y, int z)
  4800. */
  4801. @Deprecated
  4802. public final double getDistance(int x, int y)
  4803. {
  4804. double dx = x - getX();
  4805. double dy = y - getY();
  4806.  
  4807. return Math.sqrt(dx*dx + dy*dy);
  4808. }
  4809.  
  4810. /**
  4811. * Return the distance between the current position of the L2Character and the target (x,y).<BR><BR>
  4812. *
  4813. * @param x X position of the target
  4814. * @param y Y position of the target
  4815. * @return the plan distance
  4816. *
  4817. * @deprecated use getPlanDistanceSq(int x, int y, int z)
  4818. */
  4819. @Deprecated
  4820. public final double getDistance(int x, int y, int z)
  4821. {
  4822. double dx = x - getX();
  4823. double dy = y - getY();
  4824. double dz = z - getZ();
  4825.  
  4826. return Math.sqrt(dx*dx + dy*dy + dz*dz);
  4827. }
  4828.  
  4829. /**
  4830. * Return the squared distance between the current position of the L2Character and the given object.<BR><BR>
  4831. *
  4832. * @param object L2Object
  4833. * @return the squared distance
  4834. */
  4835. public final double getDistanceSq(L2Object object)
  4836. {
  4837. return getDistanceSq(object.getX(), object.getY(), object.getZ());
  4838. }
  4839.  
  4840. /**
  4841. * Return the squared distance between the current position of the L2Character and the given x, y, z.<BR><BR>
  4842. *
  4843. * @param x X position of the target
  4844. * @param y Y position of the target
  4845. * @param z Z position of the target
  4846. * @return the squared distance
  4847. */
  4848. public final double getDistanceSq(int x, int y, int z)
  4849. {
  4850. double dx = x - getX();
  4851. double dy = y - getY();
  4852. double dz = z - getZ();
  4853.  
  4854. return (dx*dx + dy*dy + dz*dz);
  4855. }
  4856.  
  4857. /**
  4858. * Return the squared plan distance between the current position of the L2Character and the given object.<BR>
  4859. * (check only x and y, not z)<BR><BR>
  4860. *
  4861. * @param object L2Object
  4862. * @return the squared plan distance
  4863. */
  4864. public final double getPlanDistanceSq(L2Object object)
  4865. {
  4866. return getPlanDistanceSq(object.getX(), object.getY());
  4867. }
  4868. /**
  4869. * Return the squared plan distance between the current position of the L2Character and the given x, y, z.<BR>
  4870. * (check only x and y, not z)<BR><BR>
  4871. *
  4872. * @param x X position of the target
  4873. * @param y Y position of the target
  4874. * @return the squared plan distance
  4875. */
  4876. public final double getPlanDistanceSq(int x, int y)
  4877. {
  4878. double dx = x - getX();
  4879. double dy = y - getY();
  4880.  
  4881. return (dx*dx + dy*dy);
  4882. }
  4883.  
  4884. /**
  4885. * Check if this object is inside the given radius around the given object. Warning: doesn't cover collision radius!<BR><BR>
  4886. *
  4887. * @param object the target
  4888. * @param radius the radius around the target
  4889. * @param checkZ should we check Z axis also
  4890. * @param strictCheck true if (distance < radius), false if (distance <= radius)
  4891. * @return true is the L2Character is inside the radius.
  4892. *
  4893. * @see net.sf.l2j.gameserver.model.L2Character.isInsideRadius(int x, int y, int z, int radius, boolean checkZ, boolean strictCheck)
  4894. */
  4895. public final boolean isInsideRadius(L2Object object, int radius, boolean checkZ, boolean strictCheck)
  4896. {
  4897. return isInsideRadius(object.getX(), object.getY(), object.getZ(), radius, checkZ, strictCheck);
  4898. }
  4899. /**
  4900. * Check if this object is inside the given plan radius around the given point. Warning: doesn't cover collision radius!<BR><BR>
  4901. *
  4902. * @param x X position of the target
  4903. * @param y Y position of the target
  4904. * @param radius the radius around the target
  4905. * @param strictCheck true if (distance < radius), false if (distance <= radius)
  4906. * @return true is the L2Character is inside the radius.
  4907. */
  4908. public final boolean isInsideRadius(int x, int y, int radius, boolean strictCheck)
  4909. {
  4910. return isInsideRadius(x, y, 0, radius, false, strictCheck);
  4911. }
  4912. /**
  4913. * Check if this object is inside the given radius around the given point.<BR><BR>
  4914. *
  4915. * @param x X position of the target
  4916. * @param y Y position of the target
  4917. * @param z Z position of the target
  4918. * @param radius the radius around the target
  4919. * @param checkZ should we check Z axis also
  4920. * @param strictCheck true if (distance < radius), false if (distance <= radius)
  4921. * @return true is the L2Character is inside the radius.
  4922. */
  4923. public final boolean isInsideRadius(int x, int y, int z, int radius, boolean checkZ, boolean strictCheck)
  4924. {
  4925. double dx = x - getX();
  4926. double dy = y - getY();
  4927. double dz = z - getZ();
  4928.  
  4929. if (strictCheck)
  4930. {
  4931. if (checkZ)
  4932. return (dx*dx + dy*dy + dz*dz) < radius * radius;
  4933. else
  4934. return (dx*dx + dy*dy) < radius * radius;
  4935. } else
  4936. {
  4937. if (checkZ)
  4938. return (dx*dx + dy*dy + dz*dz) <= radius * radius;
  4939. else
  4940. return (dx*dx + dy*dy) <= radius * radius;
  4941. }
  4942. }
  4943.  
  4944. // /**
  4945. // * event that is called when the destination coordinates are reached
  4946. // */
  4947. // public void onTargetReached()
  4948. // {
  4949. // L2Character pawn = getPawnTarget();
  4950. //
  4951. // if (pawn != null)
  4952. // {
  4953. // int x = pawn.getX(), y=pawn.getY(),z = pawn.getZ();
  4954. //
  4955. // double distance = getDistance(x,y);
  4956. // if (getCurrentState() == STATE_FOLLOW)
  4957. // {
  4958. // calculateMovement(x,y,z,distance);
  4959. // return;
  4960. // }
  4961. //
  4962. // // takes care of moving away but distance is 0 so i won't follow problem
  4963. //
  4964. //
  4965. // if (((distance > getAttackRange()) && (getCurrentState() == STATE_ATTACKING)) || (pawn.isMoving() && getCurrentState() != STATE_ATTACKING))
  4966. // {
  4967. // calculateMovement(x,y,z,distance);
  4968. // return;
  4969. // }
  4970. //
  4971. // }
  4972. // // update x,y,z with the current calculated position
  4973. // stopMove();
  4974. //
  4975. // if (Config.DEBUG)
  4976. // _log.fine(this.getName() +":: target reached at: x "+getX()+" y "+getY()+ " z:" + getZ());
  4977. //
  4978. // if (getPawnTarget() != null)
  4979. // {
  4980. //
  4981. // setPawnTarget(null);
  4982. // setMovingToPawn(false);
  4983. // }
  4984. // }
  4985. //
  4986. // public void setTo(int x, int y, int z, int heading)
  4987. // {
  4988. // setX(x);
  4989. // setY(y);
  4990. // setZ(z);
  4991. // setHeading(heading);
  4992. // updateCurrentWorldRegion(); //TODO: maybe not needed here
  4993. // if (isMoving())
  4994. // {
  4995. // setCurrentState(STATE_IDLE);
  4996. // StopMove setto = new StopMove(this);
  4997. // broadcastPacket(setto);
  4998. // }
  4999. // else
  5000. // {
  5001. // ValidateLocation setto = new ValidateLocation(this);
  5002. // broadcastPacket(setto);
  5003. // }
  5004. //
  5005. // FinishRotation fr = new FinishRotation(this);
  5006. // broadcastPacket(fr);
  5007. // }
  5008.  
  5009.  
  5010. // protected void startCombat()
  5011. // {
  5012. // if (_currentAttackTask == null )//&& !isInCombat())
  5013. // {
  5014. // _currentAttackTask = ThreadPoolManager.getInstance().scheduleMed(new AttackTask(), 0);
  5015. // }
  5016. // else
  5017. // {
  5018. // _log.info("multiple attacks want to start in parallel. prevented.");
  5019. // }
  5020. // }
  5021. //
  5022.  
  5023. /**
  5024. * Return the Weapon Expertise Penalty of the L2Character.<BR><BR>
  5025. */
  5026. public float getWeaponExpertisePenalty()
  5027. {
  5028. return 1.f;
  5029. }
  5030.  
  5031. /**
  5032. * Return the Armour Expertise Penalty of the L2Character.<BR><BR>
  5033. */
  5034. public float getArmourExpertisePenalty()
  5035. {
  5036. return 1.f;
  5037. }
  5038.  
  5039.  
  5040. /**
  5041. * Set _attacking corresponding to Attacking Body part to CHEST.<BR><BR>
  5042. */
  5043. public void setAttackingBodypart()
  5044. {
  5045. _attacking = Inventory.PAPERDOLL_CHEST;
  5046. }
  5047.  
  5048. /**
  5049. * Retun True if arrows are available.<BR><BR>
  5050. *
  5051. * <B><U> Overridden in </U> :</B><BR><BR>
  5052. * <li> L2PcInstance</li><BR><BR>
  5053. *
  5054. */
  5055. protected boolean checkAndEquipArrows()
  5056. {
  5057. return true;
  5058. }
  5059.  
  5060. /**
  5061. * Retun True if bolts are available.<BR><BR>
  5062. *
  5063. * <B><U> Overridden in </U> :</B><BR><BR>
  5064. * <li> L2PcInstance</li><BR><BR>
  5065. *
  5066. */
  5067. protected boolean checkAndEquipBolts()
  5068. {
  5069. return true;
  5070. }
  5071.  
  5072. /**
  5073. * Add Exp and Sp to the L2Character.<BR><BR>
  5074. *
  5075. * <B><U> Overridden in </U> :</B><BR><BR>
  5076. * <li> L2PcInstance</li>
  5077. * <li> L2PetInstance</li><BR><BR>
  5078. *
  5079. */
  5080. public void addExpAndSp(long addToExp, int addToSp)
  5081. {
  5082. // Dummy method (overridden by players and pets)
  5083. }
  5084.  
  5085. /**
  5086. * Return the active weapon instance (always equiped in the right hand).<BR><BR>
  5087. *
  5088. * <B><U> Overridden in </U> :</B><BR><BR>
  5089. * <li> L2PcInstance</li><BR><BR>
  5090. *
  5091. */
  5092. public abstract L2ItemInstance getActiveWeaponInstance();
  5093.  
  5094. /**
  5095. * Return the active weapon item (always equiped in the right hand).<BR><BR>
  5096. *
  5097. * <B><U> Overridden in </U> :</B><BR><BR>
  5098. * <li> L2PcInstance</li><BR><BR>
  5099. *
  5100. */
  5101. public abstract L2Weapon getActiveWeaponItem();
  5102.  
  5103. /**
  5104. * Return the secondary weapon instance (always equiped in the left hand).<BR><BR>
  5105. *
  5106. * <B><U> Overridden in </U> :</B><BR><BR>
  5107. * <li> L2PcInstance</li><BR><BR>
  5108. *
  5109. */
  5110. public abstract L2ItemInstance getSecondaryWeaponInstance();
  5111.  
  5112. /**
  5113. * Return the secondary weapon item (always equiped in the left hand).<BR><BR>
  5114. *
  5115. * <B><U> Overridden in </U> :</B><BR><BR>
  5116. * <li> L2PcInstance</li><BR><BR>
  5117. *
  5118. */
  5119. public abstract L2Weapon getSecondaryWeaponItem();
  5120.  
  5121.  
  5122. /**
  5123. * Manage hit process (called by Hit Task).<BR><BR>
  5124. *
  5125. * <B><U> Actions</U> :</B><BR><BR>
  5126. * <li>If the attacker/target is dead or use fake death, notify the AI with EVT_CANCEL and send a Server->Client packet ActionFailed (if attacker is a L2PcInstance)</li>
  5127. * <li>If attack isn't aborted, send a message system (critical hit, missed...) to attacker/target if they are L2PcInstance </li>
  5128. * <li>If attack isn't aborted and hit isn't missed, reduce HP of the target and calculate reflection damage to reduce HP of attacker if necessary </li>
  5129. * <li>if attack isn't aborted and hit isn't missed, manage attack or cast break of the target (calculating rate, sending message...) </li><BR><BR>
  5130. *
  5131. * @param target The L2Character targeted
  5132. * @param damage Nb of HP to reduce
  5133. * @param crit True if hit is critical
  5134. * @param miss True if hit is missed
  5135. * @param soulshot True if SoulShot are charged
  5136. * @param shld True if shield is efficient
  5137. *
  5138. */
  5139. protected void onHitTimer(L2Character target, int damage, boolean crit, boolean miss, boolean soulshot, byte shld)
  5140. {
  5141. // If the attacker/target is dead or use fake death, notify the AI with EVT_CANCEL
  5142. // and send a Server->Client packet ActionFailed (if attacker is a L2PcInstance)
  5143. if (target == null || isAlikeDead() ||(this instanceof L2Npc && ((L2Npc) this).isEventMob))
  5144. {
  5145. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  5146. return;
  5147. }
  5148.  
  5149. if ((this instanceof L2Npc && target.isAlikeDead()) || target.isDead()
  5150. || (!getKnownList().knowsObject(target) && !(this instanceof L2DoorInstance)))
  5151. {
  5152. //getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE, null);
  5153. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  5154.  
  5155. sendPacket(ActionFailed.STATIC_PACKET);
  5156. return;
  5157. }
  5158.  
  5159. if (miss)
  5160. {
  5161. // ON_EVADED_HIT
  5162. if (target.getChanceSkills() != null)
  5163. target.getChanceSkills().onEvadedHit(this);
  5164.  
  5165. if (target instanceof L2PcInstance)
  5166. {
  5167. SystemMessage sm = new SystemMessage(SystemMessageId.AVOIDED_C1_ATTACK);
  5168. sm.addCharName(this);
  5169. target.sendPacket(sm);
  5170. }
  5171. }
  5172.  
  5173. // If attack isn't aborted, send a message system (critical hit, missed...) to attacker/target if they are L2PcInstance
  5174. if (!isAttackAborted())
  5175. {
  5176. // Check Raidboss attack
  5177. // Character will be petrified if attacking a raid that's more
  5178. // than 8 levels lower
  5179. if (target.isRaid() && !Config.RAID_DISABLE_CURSE && getActingPlayer() != null)
  5180. {
  5181. int level = getActingPlayer().getLevel();
  5182.  
  5183. if (level > target.getLevel() + 8)
  5184. {
  5185. L2Skill skill = SkillTable.getInstance().getInfo(4515, 1);
  5186.  
  5187. if (skill != null)
  5188. skill.getEffects(target, this);
  5189. else
  5190. _log.warning("Skill 4515 at level 1 is missing in DP.");
  5191.  
  5192. damage = 0; // prevents messing up drop calculation
  5193. }
  5194. }
  5195.  
  5196. sendDamageMessage(target, damage, false, crit, miss);
  5197.  
  5198. // If L2Character target is a L2PcInstance, send a system message
  5199. if (target instanceof L2PcInstance)
  5200. {
  5201. L2PcInstance enemy = (L2PcInstance)target;
  5202. enemy.getAI().clientStartAutoAttack();
  5203.  
  5204. /*if (shld && 100 - Config.ALT_PERFECT_SHLD_BLOCK < Rnd.get(100))
  5205. {
  5206. if (100 - Config.ALT_PERFECT_SHLD_BLOCK < Rnd.get(100))
  5207. {
  5208. damage = 1;
  5209. enemy.sendPacket(new SystemMessage(SystemMessageId.YOUR_EXCELLENT_SHIELD_DEFENSE_WAS_A_SUCCESS)); //SHIELD_DEFENCE faultless
  5210. }
  5211. else
  5212. enemy.sendPacket(new SystemMessage(SystemMessageId.SHIELD_DEFENCE_SUCCESSFULL));
  5213. }*/
  5214. }
  5215.  
  5216. if (!miss && damage > 0)
  5217. {
  5218. L2Weapon weapon = getActiveWeaponItem();
  5219. boolean isBow = (weapon != null && (weapon.getItemType() == L2WeaponType.BOW || weapon.getItemType() == L2WeaponType.CROSSBOW));
  5220. int reflectedDamage = 0;
  5221.  
  5222. if (!isBow && !target.isInvul()) // Do not reflect if weapon is of type bow or target is invunlerable
  5223. {
  5224. // quick fix for no drop from raid if boss attack high-level char with damage reflection
  5225. if (!target.isRaid()
  5226. || getActingPlayer() == null
  5227. || getActingPlayer().getLevel() <= target.getLevel() + 8)
  5228. {
  5229. // Reduce HP of the target and calculate reflection damage to reduce HP of attacker if necessary
  5230. double reflectPercent = target.getStat().calcStat(Stats.REFLECT_DAMAGE_PERCENT,0,null,null);
  5231.  
  5232. if (reflectPercent > 0)
  5233. {
  5234. reflectedDamage = (int)(reflectPercent / 100. * damage);
  5235. damage -= reflectedDamage;
  5236.  
  5237. if(reflectedDamage > target.getMaxHp()) // to prevent extreme damage when hitting a low lvl char...
  5238. reflectedDamage = target.getMaxHp();
  5239. }
  5240. }
  5241. }
  5242.  
  5243. // reduce targets HP
  5244. target.reduceCurrentHp(damage, this, null);
  5245.  
  5246. if (reflectedDamage > 0)
  5247. {
  5248. reduceCurrentHp(reflectedDamage, target, true, false, null);
  5249.  
  5250. // Custom messages - nice but also more network load
  5251. /*
  5252. if (target instanceof L2PcInstance)
  5253. ((L2PcInstance)target).sendMessage("You reflected " + reflectedDamage + " damage.");
  5254. else if (target instanceof L2Summon)
  5255. ((L2Summon)target).getOwner().sendMessage("Summon reflected " + reflectedDamage + " damage.");
  5256.  
  5257. if (this instanceof L2PcInstance)
  5258. ((L2PcInstance)this).sendMessage("Target reflected to you " + reflectedDamage + " damage.");
  5259. else if (this instanceof L2Summon)
  5260. ((L2Summon)this).getOwner().sendMessage("Target reflected to your summon " + reflectedDamage + " damage.");
  5261. */
  5262. }
  5263.  
  5264. if (!isBow) // Do not absorb if weapon is of type bow
  5265. {
  5266. // Absorb HP from the damage inflicted
  5267. double absorbPercent = getStat().calcStat(Stats.ABSORB_DAMAGE_PERCENT,0, null,null);
  5268.  
  5269. if (absorbPercent > 0)
  5270. {
  5271. int maxCanAbsorb = (int)(getMaxHp() - getCurrentHp());
  5272. int absorbDamage = (int)(absorbPercent / 100. * damage);
  5273.  
  5274. if (absorbDamage > maxCanAbsorb)
  5275. absorbDamage = maxCanAbsorb; // Can't absord more than max hp
  5276.  
  5277. if (absorbDamage > 0)
  5278. setCurrentHp(getCurrentHp() + absorbDamage);
  5279. }
  5280.  
  5281. // Absorb MP from the damage inflicted
  5282. absorbPercent = getStat().calcStat(Stats.ABSORB_MANA_DAMAGE_PERCENT, 0, null, null);
  5283.  
  5284. if (absorbPercent > 0)
  5285. {
  5286. int maxCanAbsorb = (int) (getMaxMp() - getCurrentMp());
  5287. int absorbDamage = (int) (absorbPercent / 100. * damage);
  5288.  
  5289. if (absorbDamage > maxCanAbsorb)
  5290. absorbDamage = maxCanAbsorb; // Can't absord more than max hp
  5291.  
  5292. if (absorbDamage > 0)
  5293. setCurrentMp(getCurrentMp() + absorbDamage);
  5294. }
  5295.  
  5296. }
  5297.  
  5298. // Notify AI with EVT_ATTACKED
  5299. if (target.hasAI())
  5300. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, this);
  5301. getAI().clientStartAutoAttack();
  5302. if (this instanceof L2Summon)
  5303. {
  5304. L2PcInstance owner = ((L2Summon)this).getOwner();
  5305. if (owner != null)
  5306. {
  5307. owner.getAI().clientStartAutoAttack();
  5308. }
  5309. }
  5310.  
  5311. // Manage attack or cast break of the target (calculating rate, sending message...)
  5312. if (!target.isRaid() && Formulas.calcAtkBreak(target, damage))
  5313. {
  5314. target.breakAttack();
  5315. target.breakCast();
  5316. }
  5317.  
  5318. // Maybe launch chance skills on us
  5319. if (_chanceSkills != null)
  5320. _chanceSkills.onHit(target, false, crit);
  5321.  
  5322. // Maybe launch chance skills on target
  5323. if (target.getChanceSkills() != null)
  5324. target.getChanceSkills().onHit(this, true, crit);
  5325. }
  5326.  
  5327. // Launch weapon Special ability effect if available
  5328. L2Weapon activeWeapon = getActiveWeaponItem();
  5329.  
  5330. if (activeWeapon != null)
  5331. activeWeapon.getSkillEffects(this, target, crit);
  5332.  
  5333. /* COMMENTED OUT BY nexus - 2006-08-17
  5334. *
  5335. * We must not discharge the soulshouts at the onHitTimer method,
  5336. * as this can cause unwanted soulshout consumption if the attacker
  5337. * recharges the soulshot right after an attack request but before
  5338. * his hit actually lands on the target.
  5339. *
  5340. * The soulshot discharging has been moved to the doAttack method:
  5341. * As soon as we know that we didn't missed the hit there, then we
  5342. * must discharge any charged soulshots.
  5343. */
  5344. /*
  5345. L2ItemInstance weapon = getActiveWeaponInstance();
  5346.  
  5347. if (!miss)
  5348. {
  5349. if (this instanceof L2Summon && !(this instanceof L2PetInstance))
  5350. {
  5351. if (((L2Summon)this).getChargedSoulShot() != L2ItemInstance.CHARGED_NONE)
  5352. ((L2Summon)this).setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
  5353. }
  5354. else
  5355. {
  5356. if (weapon != null && weapon.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE)
  5357. weapon.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  5358. }
  5359. }
  5360. */
  5361.  
  5362. return;
  5363. }
  5364.  
  5365. if (!isCastingNow() && !isCastingSimultaneouslyNow())
  5366. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  5367. }
  5368.  
  5369. /**
  5370. * Break an attack and send Server->Client ActionFailed packet and a System Message to the L2Character.<BR><BR>
  5371. */
  5372. public void breakAttack()
  5373. {
  5374. if (isAttackingNow())
  5375. {
  5376. // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  5377. abortAttack();
  5378.  
  5379. if (this instanceof L2PcInstance)
  5380. {
  5381. //TODO Remove sendPacket because it's always done in abortAttack
  5382. sendPacket(ActionFailed.STATIC_PACKET);
  5383.  
  5384. // Send a system message
  5385. sendPacket(new SystemMessage(SystemMessageId.ATTACK_FAILED));
  5386. }
  5387. }
  5388. }
  5389.  
  5390.  
  5391. /**
  5392. * Break a cast and send Server->Client ActionFailed packet and a System Message to the L2Character.<BR><BR>
  5393. */
  5394. public void breakCast()
  5395. {
  5396. // damage can only cancel magical skills
  5397. if (isCastingNow() && canAbortCast() && getLastSkillCast() != null && getLastSkillCast().isMagic())
  5398. {
  5399. // Abort the cast of the L2Character and send Server->Client MagicSkillCanceld/ActionFailed packet.
  5400. abortCast();
  5401.  
  5402. if (this instanceof L2PcInstance)
  5403. {
  5404. // Send a system message
  5405. sendPacket(new SystemMessage(SystemMessageId.CASTING_INTERRUPTED));
  5406. }
  5407. }
  5408. }
  5409.  
  5410. /**
  5411. * Reduce the arrow number of the L2Character.<BR><BR>
  5412. *
  5413. * <B><U> Overridden in </U> :</B><BR><BR>
  5414. * <li> L2PcInstance</li><BR><BR>
  5415. *
  5416. */
  5417. protected void reduceArrowCount(boolean bolts)
  5418. {
  5419. // default is to do nothing
  5420. }
  5421.  
  5422. /**
  5423. * Manage Forced attack (shift + select target).<BR><BR>
  5424. *
  5425. * <B><U> Actions</U> :</B><BR><BR>
  5426. * <li>If L2Character or target is in a town area, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed </li>
  5427. * <li>If target is confused, send a Server->Client packet ActionFailed </li>
  5428. * <li>If L2Character is a L2ArtefactInstance, send a Server->Client packet ActionFailed </li>
  5429. * <li>Send a Server->Client packet MyTargetSelected to start attack and Notify AI with AI_INTENTION_ATTACK </li><BR><BR>
  5430. *
  5431. * @param player The L2PcInstance to attack
  5432. *
  5433. */
  5434. @Override
  5435. public void onForcedAttack(L2PcInstance player)
  5436. {
  5437. if (isInsidePeaceZone(player))
  5438. {
  5439. // If L2Character or target is in a peace zone, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed
  5440. player.sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  5441. player.sendPacket(ActionFailed.STATIC_PACKET);
  5442. return;
  5443. }
  5444. if (player.isInOlympiadMode() && player.getTarget() != null && player.getTarget() instanceof L2Playable)
  5445. {
  5446. L2PcInstance target;
  5447. if (player.getTarget() instanceof L2Summon)
  5448. target=((L2Summon)player.getTarget()).getOwner();
  5449. else
  5450. target=(L2PcInstance)player.getTarget();
  5451.  
  5452. if (target == null
  5453. || (target.isInOlympiadMode()
  5454. && (!player.isOlympiadStart()
  5455. || player.getOlympiadGameId() != target.getOlympiadGameId())))
  5456. {
  5457. // if L2PcInstance is in Olympia and the match isn't already start, send a Server->Client packet ActionFailed
  5458. player.sendPacket(ActionFailed.STATIC_PACKET);
  5459. return;
  5460. }
  5461. }
  5462. if (player.getTarget() != null && !player.getTarget().isAttackable() && !player.getAccessLevel().allowPeaceAttack())
  5463. {
  5464. // If target is not attackable, send a Server->Client packet ActionFailed
  5465. player.sendPacket(ActionFailed.STATIC_PACKET);
  5466. return;
  5467. }
  5468. if (player.isConfused())
  5469. {
  5470. // If target is confused, send a Server->Client packet ActionFailed
  5471. player.sendPacket(ActionFailed.STATIC_PACKET);
  5472. return;
  5473. }
  5474. // GeoData Los Check or dz > 1000
  5475. if (!GeoData.getInstance().canSeeTarget(player, this))
  5476. {
  5477. player.sendPacket(new SystemMessage(SystemMessageId.CANT_SEE_TARGET));
  5478. player.sendPacket(ActionFailed.STATIC_PACKET);
  5479. return;
  5480. }
  5481. // Notify AI with AI_INTENTION_ATTACK
  5482. player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
  5483. }
  5484.  
  5485. /**
  5486. * Return True if inside peace zone.<BR><BR>
  5487. */
  5488. public boolean isInsidePeaceZone(L2PcInstance attacker)
  5489. {
  5490. return isInsidePeaceZone(attacker, this);
  5491. }
  5492.  
  5493. public boolean isInsidePeaceZone(L2PcInstance attacker, L2Object target)
  5494. {
  5495. return (
  5496. !attacker.getAccessLevel().allowPeaceAttack() &&
  5497. isInsidePeaceZone((L2Object)attacker, target)
  5498. );
  5499. }
  5500.  
  5501. public boolean isInsidePeaceZone(L2Object attacker, L2Object target)
  5502. {
  5503. if (target == null)
  5504. return false;
  5505. if (!(target instanceof L2Playable && attacker instanceof L2Playable))
  5506. return false;
  5507. if (InstanceManager.getInstance().getInstance(this.getInstanceId()).isPvPInstance())
  5508. return false;
  5509.  
  5510. if (Config.ALT_GAME_KARMA_PLAYER_CAN_BE_KILLED_IN_PEACEZONE)
  5511. {
  5512. // allows red to be attacked and red to attack flagged players
  5513. if (target.getActingPlayer() != null && target.getActingPlayer().getKarma() > 0)
  5514. return false;
  5515. if (attacker.getActingPlayer() != null && attacker.getActingPlayer().getKarma() > 0
  5516. && target.getActingPlayer() != null && target.getActingPlayer().getPvpFlag() > 0)
  5517. return false;
  5518.  
  5519. if (attacker instanceof L2Character && target instanceof L2Character)
  5520. {
  5521. return (((L2Character)target).isInsideZone(ZONE_PEACE) || ((L2Character)attacker).isInsideZone(ZONE_PEACE));
  5522. }
  5523. if (attacker instanceof L2Character)
  5524. {
  5525. return (TownManager.getTown(target.getX(), target.getY(), target.getZ()) != null || ((L2Character)attacker).isInsideZone(ZONE_PEACE));
  5526. }
  5527. }
  5528.  
  5529. if (attacker instanceof L2Character && target instanceof L2Character)
  5530. {
  5531. return (((L2Character)target).isInsideZone(ZONE_PEACE) || ((L2Character)attacker).isInsideZone(ZONE_PEACE));
  5532. }
  5533. if (attacker instanceof L2Character)
  5534. {
  5535. return (TownManager.getTown(target.getX(), target.getY(), target.getZ()) != null || ((L2Character)attacker).isInsideZone(ZONE_PEACE));
  5536. }
  5537. return (TownManager.getTown(target.getX(), target.getY(), target.getZ()) != null ||
  5538. TownManager.getTown(attacker.getX(), attacker.getY(), attacker.getZ()) != null);
  5539. }
  5540.  
  5541. /**
  5542. * return true if this character is inside an active grid.
  5543. */
  5544. public Boolean isInActiveRegion()
  5545. {
  5546. L2WorldRegion region = getWorldRegion();
  5547. return ((region !=null) && (region.isActive()));
  5548. }
  5549.  
  5550. /**
  5551. * Return True if the L2Character has a Party in progress.<BR><BR>
  5552. */
  5553. public boolean isInParty()
  5554. {
  5555. return false;
  5556. }
  5557.  
  5558. /**
  5559. * Return the L2Party object of the L2Character.<BR><BR>
  5560. */
  5561. public L2Party getParty()
  5562. {
  5563. return null;
  5564. }
  5565. /**
  5566. * Return the Attack Speed of the L2Character (delay (in milliseconds) before next attack).<BR><BR>
  5567. */
  5568. public int calculateTimeBetweenAttacks(L2Character target, L2Weapon weapon)
  5569. {
  5570. double atkSpd = 0;
  5571. if (weapon !=null && !isTransformed())
  5572. {
  5573. switch (weapon.getItemType())
  5574. {
  5575. case BOW:
  5576. atkSpd = getStat().getPAtkSpd();
  5577. return (int)(1500*345/atkSpd);
  5578. case CROSSBOW:
  5579. atkSpd = getStat().getPAtkSpd();
  5580. return (int)(1200*345/atkSpd);
  5581. case DAGGER:
  5582. atkSpd = getStat().getPAtkSpd();
  5583. //atkSpd /= 1.15;
  5584. break;
  5585. default:
  5586. atkSpd = getStat().getPAtkSpd();
  5587. }
  5588. }
  5589. else
  5590. atkSpd = getPAtkSpd();
  5591.  
  5592. return Formulas.calcPAtkSpd(this, target, atkSpd);
  5593. }
  5594.  
  5595. public int calculateReuseTime(L2Character target, L2Weapon weapon)
  5596. {
  5597. if (weapon == null || isTransformed()) return 0;
  5598.  
  5599. int reuse = weapon.getAttackReuseDelay();
  5600. // only bows should continue for now
  5601. if (reuse == 0) return 0;
  5602. // else if (reuse < 10) reuse = 1500;
  5603.  
  5604. reuse *= getStat().getWeaponReuseModifier(target);
  5605. double atkSpd = getStat().getPAtkSpd();
  5606. switch (weapon.getItemType())
  5607. {
  5608. case BOW:
  5609. case CROSSBOW:
  5610. return (int)(reuse*345/atkSpd);
  5611. default:
  5612. return (int)(reuse*312/atkSpd);
  5613. }
  5614. }
  5615.  
  5616. /**
  5617. * Return True if the L2Character use a dual weapon.<BR><BR>
  5618. */
  5619. public boolean isUsingDualWeapon()
  5620. {
  5621. return false;
  5622. }
  5623.  
  5624. /**
  5625. * Add a skill to the L2Character _skills and its Func objects to the calculator set of the L2Character.<BR><BR>
  5626. *
  5627. * <B><U> Concept</U> :</B><BR><BR>
  5628. * All skills own by a L2Character are identified in <B>_skills</B><BR><BR>
  5629. *
  5630. * <B><U> Actions</U> :</B><BR><BR>
  5631. * <li>Replace oldSkill by newSkill or Add the newSkill </li>
  5632. * <li>If an old skill has been replaced, remove all its Func objects of L2Character calculator set</li>
  5633. * <li>Add Func objects of newSkill to the calculator set of the L2Character </li><BR><BR>
  5634. *
  5635. * <B><U> Overridden in </U> :</B><BR><BR>
  5636. * <li> L2PcInstance : Save update in the character_skills table of the database</li><BR><BR>
  5637. *
  5638. * @param newSkill The L2Skill to add to the L2Character
  5639. *
  5640. * @return The L2Skill replaced or null if just added a new L2Skill
  5641. *
  5642. */
  5643. public L2Skill addSkill(L2Skill newSkill)
  5644. {
  5645. L2Skill oldSkill = null;
  5646.  
  5647. if (newSkill != null)
  5648. {
  5649. // Replace oldSkill by newSkill or Add the newSkill
  5650. oldSkill = _skills.put(newSkill.getId(), newSkill);
  5651.  
  5652. // If an old skill has been replaced, remove all its Func objects
  5653. if (oldSkill != null)
  5654. {
  5655. // if skill came with another one, we should delete the other one too.
  5656. if(( oldSkill.triggerAnotherSkill()))
  5657. {
  5658. removeSkill(oldSkill.getTriggeredId(),true);
  5659. }
  5660. removeStatsOwner(oldSkill);
  5661. }
  5662. // Add Func objects of newSkill to the calculator set of the L2Character
  5663. addStatFuncs(newSkill.getStatFuncs(null, this));
  5664.  
  5665. if (oldSkill != null && _chanceSkills != null)
  5666. {
  5667. removeChanceSkill(oldSkill.getId());
  5668. }
  5669. if (newSkill.isChance())
  5670. {
  5671. addChanceSkill(newSkill);
  5672. }
  5673.  
  5674. /*if (!newSkill.isChance() && newSkill.triggerAnotherSkill() )
  5675. {
  5676. L2Skill bestowed = SkillTable.getInstance().getInfo(newSkill.getTriggeredId(), newSkill.getTriggeredLevel());
  5677. addSkill(bestowed);
  5678. //bestowed skills are invisible for player. Visible for gm's looking thru gm window.
  5679. //those skills should always be chance or passive, to prevent hlapex.
  5680. }
  5681.  
  5682. if(newSkill.isChance() && newSkill.triggerAnotherSkill())
  5683. {
  5684. L2Skill triggeredSkill = SkillTable.getInstance().getInfo(newSkill.getTriggeredId(),newSkill.getTriggeredLevel());
  5685. addSkill(triggeredSkill);
  5686. }*/
  5687. }
  5688.  
  5689. return oldSkill;
  5690. }
  5691.  
  5692. /**
  5693. * Remove a skill from the L2Character and its Func objects from calculator set of the L2Character.<BR><BR>
  5694. *
  5695. * <B><U> Concept</U> :</B><BR><BR>
  5696. * All skills own by a L2Character are identified in <B>_skills</B><BR><BR>
  5697. *
  5698. * <B><U> Actions</U> :</B><BR><BR>
  5699. * <li>Remove the skill from the L2Character _skills </li>
  5700. * <li>Remove all its Func objects from the L2Character calculator set</li><BR><BR>
  5701. *
  5702. * <B><U> Overridden in </U> :</B><BR><BR>
  5703. * <li> L2PcInstance : Save update in the character_skills table of the database</li><BR><BR>
  5704. *
  5705. * @param skill The L2Skill to remove from the L2Character
  5706. *
  5707. * @return The L2Skill removed
  5708. *
  5709. */
  5710. public L2Skill removeSkill(L2Skill skill)
  5711. {
  5712. if (skill == null) return null;
  5713.  
  5714. return removeSkill(skill.getId(), true);
  5715. }
  5716.  
  5717. public L2Skill removeSkill(L2Skill skill, boolean cancelEffect)
  5718. {
  5719. if (skill == null) return null;
  5720.  
  5721. // Remove the skill from the L2Character _skills
  5722. return removeSkill(skill.getId(), cancelEffect);
  5723. }
  5724.  
  5725. public L2Skill removeSkill(int skillId)
  5726. {
  5727. return removeSkill(skillId, true);
  5728. }
  5729.  
  5730. public L2Skill removeSkill(int skillId, boolean cancelEffect)
  5731. {
  5732. // Remove the skill from the L2Character _skills
  5733. L2Skill oldSkill = _skills.remove(skillId);
  5734. // Remove all its Func objects from the L2Character calculator set
  5735. if (oldSkill != null)
  5736. {
  5737. //this is just a fail-safe againts buggers and gm dummies...
  5738. if((oldSkill.triggerAnotherSkill()) && oldSkill.getTriggeredId()>0)
  5739. {
  5740. removeSkill(oldSkill.getTriggeredId(),true);
  5741. }
  5742.  
  5743. // does not abort casting of the transformation dispell
  5744. if (oldSkill.getSkillType() != L2SkillType.TRANSFORMDISPEL)
  5745. {
  5746. // Stop casting if this skill is used right now
  5747. if (getLastSkillCast() != null && isCastingNow())
  5748. {
  5749. if (oldSkill.getId() == getLastSkillCast().getId())
  5750. abortCast();
  5751. }
  5752. if (getLastSimultaneousSkillCast() != null && isCastingSimultaneouslyNow())
  5753. {
  5754. if (oldSkill.getId() == getLastSimultaneousSkillCast().getId())
  5755. abortCast();
  5756. }
  5757. }
  5758.  
  5759. if (cancelEffect || oldSkill.isToggle())
  5760. {
  5761. // for now, to support transformations, we have to let their
  5762. // effects stay when skill is removed
  5763. L2Effect e = getFirstEffect(oldSkill);
  5764. if (e == null || e.getEffectType() != L2EffectType.TRANSFORMATION)
  5765. {
  5766. removeStatsOwner(oldSkill);
  5767. stopSkillEffects(oldSkill.getId());
  5768. }
  5769. }
  5770.  
  5771. if (oldSkill instanceof L2SkillAgathion && this instanceof L2PcInstance && ((L2PcInstance)this).getAgathionId() > 0)
  5772. {
  5773. ((L2PcInstance)this).setAgathionId(0);
  5774. ((L2PcInstance)this).broadcastUserInfo();
  5775. }
  5776.  
  5777. if (oldSkill instanceof L2SkillMount && this instanceof L2PcInstance && ((L2PcInstance)this).isMounted())
  5778. ((L2PcInstance)this).dismount();
  5779.  
  5780. if (oldSkill.isChance() && _chanceSkills != null)
  5781. {
  5782. removeChanceSkill(oldSkill.getId());
  5783. }
  5784. if (oldSkill instanceof L2SkillSummon && oldSkill.getId() == 710 && this instanceof L2PcInstance && ((L2PcInstance)this).getPet() != null && ((L2PcInstance)this).getPet().getNpcId() == 14870)
  5785. {
  5786. ((L2PcInstance)this).getPet().unSummon(((L2PcInstance)this));
  5787. }
  5788. }
  5789.  
  5790. return oldSkill;
  5791. }
  5792.  
  5793. public synchronized void addChanceSkill(L2Skill skill)
  5794. {
  5795. if (_chanceSkills == null)
  5796. _chanceSkills = new ChanceSkillList(this);
  5797.  
  5798. _chanceSkills.put(skill, skill.getChanceCondition());
  5799. }
  5800.  
  5801. public synchronized void removeChanceSkill(int id)
  5802. {
  5803. if (_chanceSkills == null) return;
  5804. for (IChanceSkillTrigger trigger : _chanceSkills.keySet())
  5805. {
  5806. if (!(trigger instanceof L2Skill))
  5807. continue;
  5808.  
  5809. L2Skill skill = (L2Skill)trigger;
  5810.  
  5811. if (skill.getId() == id)
  5812. _chanceSkills.remove(skill);
  5813. }
  5814.  
  5815. if (_chanceSkills.isEmpty())
  5816. _chanceSkills = null;
  5817. }
  5818.  
  5819. public synchronized void addChanceEffect(EffectChanceSkillTrigger effect)
  5820. {
  5821. if (_chanceSkills == null)
  5822. _chanceSkills = new ChanceSkillList(this);
  5823.  
  5824. _chanceSkills.put(effect, effect.getTriggeredChanceCondition());
  5825. }
  5826.  
  5827. public synchronized void removeChanceEffect(EffectChanceSkillTrigger effect)
  5828. {
  5829. if (_chanceSkills == null) return;
  5830.  
  5831. _chanceSkills.remove(effect);
  5832.  
  5833. if (_chanceSkills.isEmpty())
  5834. _chanceSkills = null;
  5835. }
  5836.  
  5837. /**
  5838. * Return all skills own by the L2Character in a table of L2Skill.<BR><BR>
  5839. *
  5840. * <B><U> Concept</U> :</B><BR><BR>
  5841. * All skills own by a L2Character are identified in <B>_skills</B> the L2Character <BR><BR>
  5842. *
  5843. */
  5844. public final L2Skill[] getAllSkills()
  5845. {
  5846. if (_skills == null)
  5847. return new L2Skill[0];
  5848.  
  5849. return _skills.values().toArray(new L2Skill[_skills.values().size()]);
  5850. }
  5851.  
  5852. public ChanceSkillList getChanceSkills()
  5853. {
  5854. return _chanceSkills;
  5855. }
  5856.  
  5857. /**
  5858. * Return the level of a skill owned by the L2Character.<BR><BR>
  5859. *
  5860. * @param skillId The identifier of the L2Skill whose level must be returned
  5861. *
  5862. * @return The level of the L2Skill identified by skillId
  5863. *
  5864. */
  5865. public int getSkillLevel(int skillId)
  5866. {
  5867. final L2Skill skill = getKnownSkill(skillId);
  5868. if (skill == null)
  5869. return -1;
  5870.  
  5871. return skill.getLevel();
  5872. }
  5873.  
  5874. /**
  5875. * Return True if the skill is known by the L2Character.<BR><BR>
  5876. *
  5877. * @param skillId The identifier of the L2Skill to check the knowledge
  5878. *
  5879. */
  5880. public final L2Skill getKnownSkill(int skillId)
  5881. {
  5882. if (_skills == null)
  5883. return null;
  5884.  
  5885. return _skills.get(skillId);
  5886. }
  5887.  
  5888.  
  5889. /**
  5890. * Return the number of buffs affecting this L2Character.<BR><BR>
  5891. *
  5892. * @return The number of Buffs affecting this L2Character
  5893. */
  5894. public int getBuffCount()
  5895. {
  5896. return _effects.getBuffCount();
  5897. }
  5898.  
  5899. public int getDanceCount()
  5900. {
  5901. return _effects.getDanceCount();
  5902. }
  5903.  
  5904. /**
  5905. * Manage the magic skill launching task (MP, HP, Item consummation...) and display the magic skill animation on client.<BR><BR>
  5906. *
  5907. * <B><U> Actions</U> :</B><BR><BR>
  5908. * <li>Send a Server->Client packet MagicSkillLaunched (to display magic skill animation) to all L2PcInstance of L2Charcater _knownPlayers</li>
  5909. * <li>Consumme MP, HP and Item if necessary</li>
  5910. * <li>Send a Server->Client packet StatusUpdate with MP modification to the L2PcInstance</li>
  5911. * <li>Launch the magic skill in order to calculate its effects</li>
  5912. * <li>If the skill type is PDAM, notify the AI of the target with AI_INTENTION_ATTACK</li>
  5913. * <li>Notify the AI of the L2Character with EVT_FINISH_CASTING</li><BR><BR>
  5914. *
  5915. * <FONT COLOR=#FF0000><B> <U>Caution</U> : A magic skill casting MUST BE in progress</B></FONT><BR><BR>
  5916. *
  5917. * @param skill The L2Skill to use
  5918. *
  5919. */
  5920. public void onMagicLaunchedTimer(L2Object[] targets, L2Skill skill, int coolTime, boolean instant, boolean simultaneously)
  5921. {
  5922. if (skill == null || targets == null || targets.length <= 0)
  5923. {
  5924. abortCast();
  5925. return;
  5926. }
  5927.  
  5928. // Escaping from under skill's radius and peace zone check. First version, not perfect in AoE skills.
  5929. int escapeRange = 0;
  5930. if(skill.getEffectRange() > escapeRange) escapeRange = skill.getEffectRange();
  5931. else if(skill.getCastRange() < 0 && skill.getSkillRadius() > 80) escapeRange = skill.getSkillRadius();
  5932.  
  5933. if (escapeRange > 0)
  5934. {
  5935. List<L2Character> targetList = new FastList<L2Character>();
  5936. for (L2Object target: targets)
  5937. {
  5938. if (target instanceof L2Character)
  5939. {
  5940. if (!Util.checkIfInRange(escapeRange, this, target, true))
  5941. continue;
  5942. if(skill.isOffensive() && !skill.isNeutral())
  5943. {
  5944. if(this instanceof L2PcInstance)
  5945. {
  5946. if(((L2Character)target).isInsidePeaceZone((L2PcInstance)this))
  5947. continue;
  5948. }
  5949. else
  5950. {
  5951. if(((L2Character)target).isInsidePeaceZone(this, target))
  5952. continue;
  5953. }
  5954. }
  5955. targetList.add((L2Character)target);
  5956. }
  5957. //else
  5958. //{
  5959. // if (Config.DEBUG)
  5960. // _log.warning("Class cast bad: "+targets[i].getClass().toString());
  5961. //}
  5962. }
  5963. if(targetList.isEmpty())
  5964. {
  5965. abortCast();
  5966. return;
  5967. }
  5968. else targets = targetList.toArray(new L2Character[targetList.size()]);
  5969. }
  5970.  
  5971. // Ensure that a cast is in progress
  5972. // Check if player is using fake death.
  5973. // Potions can be used while faking death.
  5974. if ((simultaneously && !isCastingSimultaneouslyNow())
  5975. || (!simultaneously && !isCastingNow())
  5976. || (isAlikeDead() && !skill.isPotion()))
  5977. {
  5978. // now cancels both, simultaneous and normal
  5979. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  5980. return;
  5981. }
  5982.  
  5983. // Get the display identifier of the skill
  5984. int magicId = skill.getDisplayId();
  5985.  
  5986. // Get the level of the skill
  5987. int level = getSkillLevel(skill.getId());
  5988.  
  5989. if (level < 1)
  5990. level = 1;
  5991.  
  5992. // Send a Server->Client packet MagicSkillLaunched to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  5993. if (!skill.isPotion()) broadcastPacket(new MagicSkillLaunched(this, magicId, level, targets));
  5994.  
  5995. if (instant)
  5996. onMagicHitTimer(targets, skill, coolTime, true, simultaneously);
  5997. else
  5998. _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 2, simultaneously), 200);
  5999.  
  6000. }
  6001.  
  6002. /*
  6003. * Runs in the end of skill casting
  6004. */
  6005. public void onMagicHitTimer(L2Object[] targets, L2Skill skill, int coolTime, boolean instant, boolean simultaneously)
  6006. {
  6007. if (skill == null || targets == null || targets.length <= 0)
  6008. {
  6009. abortCast();
  6010. return;
  6011. }
  6012. if(getFusionSkill() != null)
  6013. {
  6014. if (simultaneously)
  6015. {
  6016. _skillCast2 = null;
  6017. setIsCastingSimultaneouslyNow(false);
  6018. }
  6019. else
  6020. {
  6021. _skillCast = null;
  6022. setIsCastingNow(false);
  6023. }
  6024. getFusionSkill().onCastAbort();
  6025. notifyQuestEventSkillFinished(skill, targets[0]);
  6026. return;
  6027. }
  6028. L2Effect mog = getFirstEffect(L2EffectType.SIGNET_GROUND);
  6029. if (mog != null)
  6030. {
  6031. if (simultaneously)
  6032. {
  6033. _skillCast2 = null;
  6034. setIsCastingSimultaneouslyNow(false);
  6035. }
  6036. else
  6037. {
  6038. _skillCast = null;
  6039. setIsCastingNow(false);
  6040. }
  6041. mog.exit();
  6042. notifyQuestEventSkillFinished(skill, targets[0]);
  6043. return;
  6044. }
  6045.  
  6046. try
  6047. {
  6048. // Go through targets table
  6049. for (L2Object tgt: targets)
  6050. {
  6051. if (tgt instanceof L2Playable)
  6052. {
  6053. L2Character target = (L2Character) tgt;
  6054.  
  6055. if (skill.getSkillType() == L2SkillType.BUFF)
  6056. {
  6057. SystemMessage smsg = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  6058. smsg.addSkillName(skill);
  6059. target.sendPacket(smsg);
  6060. }
  6061.  
  6062. if (this instanceof L2PcInstance
  6063. && target instanceof L2Summon)
  6064. {
  6065. ((L2Summon) target).updateAndBroadcastStatus(1);
  6066. }
  6067. }
  6068. }
  6069.  
  6070. StatusUpdate su = new StatusUpdate(getObjectId());
  6071. boolean isSendStatus = false;
  6072.  
  6073. // Consume MP of the L2Character and Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  6074. double mpConsume = getStat().getMpConsume(skill);
  6075.  
  6076. if (mpConsume > 0)
  6077. {
  6078. if (skill.isDance())
  6079. {
  6080. getStatus().reduceMp(calcStat(Stats.DANCE_MP_CONSUME_RATE, mpConsume, null, null));
  6081. }
  6082. else if (skill.isMagic())
  6083. {
  6084. getStatus().reduceMp(calcStat(Stats.MAGICAL_MP_CONSUME_RATE, mpConsume, null, null));
  6085. }
  6086. else
  6087. {
  6088. getStatus().reduceMp(calcStat(Stats.PHYSICAL_MP_CONSUME_RATE, mpConsume, null, null));
  6089. }
  6090. su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
  6091. isSendStatus = true;
  6092. }
  6093.  
  6094. // Consume HP if necessary and Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  6095. if (skill.getHpConsume() > 0)
  6096. {
  6097. double consumeHp;
  6098.  
  6099. consumeHp = calcStat(Stats.HP_CONSUME_RATE, skill.getHpConsume(), null, null);
  6100. if (consumeHp + 1 >= getCurrentHp())
  6101. consumeHp = getCurrentHp() - 1.0;
  6102.  
  6103. getStatus().reduceHp(consumeHp, this, true);
  6104.  
  6105. su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
  6106. isSendStatus = true;
  6107. }
  6108.  
  6109. // Consume CP if necessary and Send the Server->Client packet StatusUpdate with current CP/HP and MP to all other L2PcInstance to inform
  6110. if (skill.getCpConsume() > 0)
  6111. {
  6112. double consumeCp;
  6113.  
  6114. consumeCp = skill.getCpConsume();
  6115. if (consumeCp + 1 >= getCurrentHp())
  6116. consumeCp = getCurrentHp() - 1.0;
  6117.  
  6118. getStatus().reduceCp((int)consumeCp);
  6119. su.addAttribute(StatusUpdate.CUR_CP, (int) getCurrentCp());
  6120. isSendStatus = true;
  6121. }
  6122.  
  6123. // Send a Server->Client packet StatusUpdate with MP modification to the L2PcInstance
  6124. if (isSendStatus) sendPacket(su);
  6125.  
  6126. // Consume Items if necessary and Send the Server->Client packet InventoryUpdate with Item modification to all the L2Character
  6127. if (skill.getItemConsume() > 0)
  6128. {
  6129. if (!destroyItemByItemId("Consume", skill.getItemConsumeId(), skill.getItemConsume(), null, false))
  6130. {
  6131. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ITEMS));
  6132. abortCast();
  6133. return;
  6134. }
  6135. }
  6136.  
  6137. if (this instanceof L2PcInstance)
  6138. {
  6139. int charges = ((L2PcInstance)this).getCharges();
  6140. // check for charges
  6141. if (charges < skill.getRequiredCharges()
  6142. || (skill.getMaxCharges() == 0 && charges < skill.getNumCharges()))
  6143. {
  6144. SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  6145. sm.addSkillName(skill);
  6146. sendPacket(sm);
  6147. abortCast();
  6148. return;
  6149. }
  6150. // generate charges if any
  6151. if (skill.getNumCharges() > 0)
  6152. {
  6153. if (skill.getMaxCharges() > 0)
  6154. ((L2PcInstance)this).increaseCharges(skill.getNumCharges(), skill.getMaxCharges());
  6155. else
  6156. ((L2PcInstance)this).decreaseCharges(skill.getNumCharges());
  6157. }
  6158. // Consume Souls if necessary
  6159. if (skill.getSoulConsumeCount() > 0 || skill.getMaxSoulConsumeCount() > 0)
  6160. {
  6161. if (!((L2PcInstance)this).decreaseSouls(skill.getSoulConsumeCount() > 0 ? skill.getSoulConsumeCount():skill.getMaxSoulConsumeCount(),skill))
  6162. return;
  6163. }
  6164.  
  6165. }
  6166. // Launch the magic skill in order to calculate its effects
  6167. callSkill(skill, targets);
  6168. }
  6169. catch (NullPointerException e) {}
  6170.  
  6171. if (instant || coolTime == 0)
  6172. onMagicFinalizer(skill, targets[0], simultaneously);
  6173. else
  6174. {
  6175. if (simultaneously)
  6176. _skillCast2 = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 3, simultaneously), coolTime);
  6177. else
  6178. _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 3, simultaneously), coolTime);
  6179. }
  6180.  
  6181. }
  6182. /*
  6183. * Runs after skill hitTime+coolTime
  6184. */
  6185. public void onMagicFinalizer(L2Skill skill, L2Object target, boolean simultaneously)
  6186. {
  6187. if (simultaneously)
  6188. {
  6189. _skillCast2 = null;
  6190. setIsCastingSimultaneouslyNow(false);
  6191. return;
  6192. }
  6193. else
  6194. {
  6195. _skillCast = null;
  6196. setIsCastingNow(false);
  6197. _castInterruptTime = 0;
  6198. }
  6199.  
  6200. // If the skill type is listed here, notify the AI of the target with AI_INTENTION_ATTACK
  6201. // for offensive skills the nextintention is always null unless player wants action after skill
  6202. // Note: this might also work
  6203. // if (skill.isOffensive() && getAI().getNextIntention() == null
  6204. // && !(skill.getSkillType() == SkillType.UNLOCK) && !(skill.getSkillType() == SkillType.DELUXE_KEY_UNLOCK) && !(skill.getSkillType() == SkillType.MDAM))
  6205. if (getAI().getNextIntention() == null)
  6206. {
  6207. switch (skill.getSkillType())
  6208. {
  6209. case PDAM:
  6210. case BLOW:
  6211. case DRAIN_SOUL:
  6212. case SOW:
  6213. case CHARGEDAM:
  6214. case SPOIL:
  6215. if (getTarget() instanceof L2Character && getTarget() != this && target == getTarget())
  6216. getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, getTarget());
  6217. break;
  6218. }
  6219. }
  6220.  
  6221. if (skill.isOffensive() && !skill.isNeutral() && !(skill.getSkillType() == L2SkillType.UNLOCK) && !(skill.getSkillType() == L2SkillType.DELUXE_KEY_UNLOCK))
  6222. getAI().clientStartAutoAttack();
  6223.  
  6224. // Notify the AI of the L2Character with EVT_FINISH_CASTING
  6225. getAI().notifyEvent(CtrlEvent.EVT_FINISH_CASTING);
  6226.  
  6227. notifyQuestEventSkillFinished(skill, target);
  6228. /*
  6229. * If character is a player, then wipe their current cast state and
  6230. * check if a skill is queued.
  6231. *
  6232. * If there is a queued skill, launch it and wipe the queue.
  6233. */
  6234. if (this instanceof L2PcInstance)
  6235. {
  6236. L2PcInstance currPlayer = (L2PcInstance)this;
  6237. SkillDat queuedSkill = currPlayer.getQueuedSkill();
  6238.  
  6239. currPlayer.setCurrentSkill(null, false, false);
  6240.  
  6241. if (queuedSkill != null)
  6242. {
  6243. currPlayer.setQueuedSkill(null, false, false);
  6244.  
  6245. // DON'T USE : Recursive call to useMagic() method
  6246. // currPlayer.useMagic(queuedSkill.getSkill(), queuedSkill.isCtrlPressed(), queuedSkill.isShiftPressed());
  6247. ThreadPoolManager.getInstance().executeTask(new QueuedMagicUseTask(currPlayer, queuedSkill.getSkill(), queuedSkill.isCtrlPressed(), queuedSkill.isShiftPressed()) );
  6248. }
  6249. }
  6250. }
  6251.  
  6252. // Quest event ON_SPELL_FNISHED
  6253. private void notifyQuestEventSkillFinished(L2Skill skill, L2Object target)
  6254. {
  6255. if (this instanceof L2Npc)
  6256. {
  6257. try
  6258. {
  6259. if (((L2NpcTemplate) getTemplate()).getEventQuests(Quest.QuestEventType.ON_SPELL_FINISHED) != null)
  6260. {
  6261. L2PcInstance player = target.getActingPlayer();
  6262. for (Quest quest : ((L2NpcTemplate) getTemplate()).getEventQuests(Quest.QuestEventType.ON_SPELL_FINISHED))
  6263. {
  6264. quest.notifySpellFinished(((L2Npc) this), player, skill);
  6265. }
  6266. }
  6267. }
  6268. catch (Exception e)
  6269. {
  6270. _log.log(Level.SEVERE, "", e);
  6271. }
  6272. }
  6273. }
  6274.  
  6275. /**
  6276. * Enable a skill (remove it from _disabledSkills of the L2Character).<BR><BR>
  6277. *
  6278. * <B><U> Concept</U> :</B><BR><BR>
  6279. * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the L2Character <BR><BR>
  6280. *
  6281. * @param skillId The identifier of the L2Skill to enable
  6282. *
  6283. */
  6284. public void enableSkill(int skillId)
  6285. {
  6286. if (_disabledSkills == null) return;
  6287.  
  6288. _disabledSkills.remove(Integer.valueOf(skillId));
  6289.  
  6290. if (this instanceof L2PcInstance)
  6291. removeTimeStamp(skillId);
  6292. }
  6293.  
  6294. /**
  6295. * Disable a skill (add it to _disabledSkills of the L2Character).<BR><BR>
  6296. *
  6297. * <B><U> Concept</U> :</B><BR><BR>
  6298. * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the L2Character <BR><BR>
  6299. *
  6300. * @param skillId The identifier of the L2Skill to disable
  6301. *
  6302. */
  6303. public void disableSkill(int skillId)
  6304. {
  6305. if (_disabledSkills == null) _disabledSkills = Collections.synchronizedList(new FastList<Integer>());
  6306.  
  6307. _disabledSkills.add(skillId);
  6308. }
  6309.  
  6310. /**
  6311. * Disable this skill id for the duration of the delay in milliseconds.
  6312. * @param skillId
  6313. * @param delay (seconds * 1000)
  6314. */
  6315. public void disableSkill(int skillId, long delay)
  6316. {
  6317. disableSkill(skillId);
  6318. if (delay > 10) ThreadPoolManager.getInstance().scheduleAi(new EnableSkill(skillId), delay);
  6319. }
  6320.  
  6321. /**
  6322. * Check if a skill is disabled.<BR><BR>
  6323. *
  6324. * <B><U> Concept</U> :</B><BR><BR>
  6325. * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the L2Character <BR><BR>
  6326. *
  6327. * @param skillId The identifier of the L2Skill to disable
  6328. *
  6329. */
  6330. public boolean isSkillDisabled(int skillId)
  6331. {
  6332. if (isAllSkillsDisabled()) return true;
  6333.  
  6334. if (_disabledSkills == null) return false;
  6335.  
  6336. return _disabledSkills.contains(skillId);
  6337. }
  6338.  
  6339. /**
  6340. * Disable all skills (set _allSkillsDisabled to True).<BR><BR>
  6341. */
  6342. public void disableAllSkills()
  6343. {
  6344. if (Config.DEBUG) _log.fine("all skills disabled");
  6345. _allSkillsDisabled = true;
  6346. }
  6347.  
  6348. /**
  6349. * Enable all skills (set _allSkillsDisabled to False).<BR><BR>
  6350. */
  6351. public void enableAllSkills()
  6352. {
  6353. if (Config.DEBUG) _log.fine("all skills enabled");
  6354. _allSkillsDisabled = false;
  6355. }
  6356.  
  6357. /**
  6358. * Launch the magic skill and calculate its effects on each target contained in the targets table.<BR><BR>
  6359. *
  6360. * @param skill The L2Skill to use
  6361. * @param targets The table of L2Object targets
  6362. *
  6363. */
  6364. public void callSkill(L2Skill skill, L2Object[] targets)
  6365. {
  6366. try
  6367. {
  6368. // Get the skill handler corresponding to the skill type (PDAM, MDAM, SWEEP...) started in gameserver
  6369. ISkillHandler handler = SkillHandler.getInstance().getSkillHandler(skill.getSkillType());
  6370. L2Weapon activeWeapon = getActiveWeaponItem();
  6371.  
  6372. // Check if the toggle skill effects are already in progress on the L2Character
  6373. if(skill.isToggle() && getFirstEffect(skill.getId()) != null)
  6374. return;
  6375.  
  6376. // Initial checks
  6377. for (L2Object trg : targets)
  6378. {
  6379. if (trg instanceof L2Character)
  6380. {
  6381. // Set some values inside target's instance for later use
  6382. L2Character target = (L2Character) trg;
  6383.  
  6384. // Check Raidboss attack and
  6385. // check buffing chars who attack raidboss. Results in mute.
  6386. L2Character targetsAttackTarget = null;
  6387. L2Character targetsCastTarget = null;
  6388. if (target.hasAI())
  6389. {
  6390. targetsAttackTarget = target.getAI().getAttackTarget();
  6391. targetsCastTarget = target.getAI().getCastTarget();
  6392. }
  6393. if (!Config.RAID_DISABLE_CURSE
  6394. && ((target.isRaid() && getLevel() > target.getLevel() + 8)
  6395. ||
  6396. (!skill.isOffensive() && targetsAttackTarget != null && targetsAttackTarget.isRaid()
  6397. && targetsAttackTarget.getAttackByList().contains(target) // has attacked raid
  6398. && getLevel() > targetsAttackTarget.getLevel() + 8)
  6399. ||
  6400. (!skill.isOffensive() && targetsCastTarget != null && targetsCastTarget.isRaid()
  6401. && targetsCastTarget.getAttackByList().contains(target) // has attacked raid
  6402. && getLevel() > targetsCastTarget.getLevel() + 8))
  6403. )
  6404. {
  6405. if (skill.isMagic())
  6406. {
  6407. L2Skill tempSkill = SkillTable.getInstance().getInfo(4215, 1);
  6408. if(tempSkill != null)
  6409. tempSkill.getEffects(target, this);
  6410. else
  6411. _log.warning("Skill 4215 at level 1 is missing in DP.");
  6412. }
  6413. else
  6414. {
  6415. L2Skill tempSkill = SkillTable.getInstance().getInfo(4515, 1);
  6416. if(tempSkill != null)
  6417. tempSkill.getEffects(target, this);
  6418. else
  6419. _log.warning("Skill 4515 at level 1 is missing in DP.");
  6420. }
  6421. return;
  6422. }
  6423.  
  6424. // Check if over-hit is possible
  6425. if(skill.isOverhit())
  6426. {
  6427. if(target instanceof L2Attackable)
  6428. ((L2Attackable)target).overhitEnabled(true);
  6429. }
  6430.  
  6431. // crafting does not trigger any chance skills
  6432. // possibly should be unhardcoded
  6433. switch (skill.getSkillType())
  6434. {
  6435. case COMMON_CRAFT:
  6436. case DWARVEN_CRAFT:
  6437. break;
  6438. default:
  6439. // Launch weapon Special ability skill effect if available
  6440. if (activeWeapon != null && !target.isDead())
  6441. {
  6442. if (activeWeapon.getSkillEffects(this, target, skill).length > 0 && this instanceof L2PcInstance)
  6443. {
  6444. sendMessage("Target affected by weapon special ability!");
  6445. }
  6446. }
  6447.  
  6448. // Maybe launch chance skills on us
  6449. if (_chanceSkills != null)
  6450. _chanceSkills.onSkillHit(target, false, skill.isMagic(), skill.isOffensive(), skill.getElement());
  6451. // Maybe launch chance skills on target
  6452. if (target.getChanceSkills() != null)
  6453. target.getChanceSkills().onSkillHit(this, true, skill.isMagic(), skill.isOffensive(), skill.getElement());
  6454. }
  6455. }
  6456. }
  6457.  
  6458. // Launch the magic skill and calculate its effects
  6459. if (handler != null)
  6460. handler.useSkill(this, skill, targets);
  6461. else
  6462. skill.useSkill(this, targets);
  6463.  
  6464. L2PcInstance player = getActingPlayer();
  6465. if (player != null)
  6466. {
  6467. for (L2Object target : targets)
  6468. {
  6469. // EVT_ATTACKED and PvPStatus
  6470. if (target instanceof L2Character)
  6471. {
  6472. if (skill.isNeutral())
  6473. {
  6474. // no flags
  6475. }
  6476. else if (skill.isOffensive())
  6477. {
  6478. if (target instanceof L2PcInstance || target instanceof L2Summon || target instanceof L2Trap)
  6479. {
  6480. // Signets are a special case, casted on target_self but don't harm self
  6481. if (skill.getSkillType() != L2SkillType.SIGNET && skill.getSkillType() != L2SkillType.SIGNET_CASTTIME)
  6482. {
  6483. if (skill.getSkillType() != L2SkillType.AGGREDUCE
  6484. && skill.getSkillType() != L2SkillType.AGGREDUCE_CHAR
  6485. && skill.getSkillType() != L2SkillType.AGGREMOVE)
  6486. {
  6487. // notify target AI about the attack
  6488. ((L2Character)target).getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, player);
  6489. }
  6490. if (target instanceof L2PcInstance)
  6491. {
  6492. ((L2PcInstance)target).getAI().clientStartAutoAttack();
  6493. }
  6494. else if (target instanceof L2Summon)
  6495. {
  6496. L2PcInstance owner =((L2Summon)target).getOwner();
  6497. if (owner != null)
  6498. {
  6499. owner.getAI().clientStartAutoAttack();
  6500. }
  6501. }
  6502. if (!(target instanceof L2Summon) || player.getPet() != target)
  6503. player.updatePvPStatus((L2Character)target);
  6504. }
  6505. }
  6506. else if (target instanceof L2Attackable)
  6507. {
  6508. switch (skill.getSkillType())
  6509. {
  6510. case AGGREDUCE:
  6511. case AGGREDUCE_CHAR:
  6512. case AGGREMOVE:
  6513. break;
  6514. default:
  6515. switch (skill.getId())
  6516. {
  6517. case 51: // Lure
  6518. case 511: // Temptation
  6519. break;
  6520. default:
  6521. // add attacker into list
  6522. ((L2Character)target).addAttackerToAttackByList(this);
  6523. }
  6524. // notify target AI about the attack
  6525. ((L2Character)target).getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, this);
  6526. break;
  6527. }
  6528. }
  6529. }
  6530. else
  6531. {
  6532. if (target instanceof L2PcInstance)
  6533. {
  6534. // Casting non offensive skill on player with pvp flag set or with karma
  6535. if (!(target.equals(this) || target.equals(player)) &&
  6536. (((L2PcInstance)target).getPvpFlag() > 0 ||
  6537. ((L2PcInstance)target).getKarma() > 0)) player.updatePvPStatus();
  6538. }
  6539. else if (target instanceof L2Attackable
  6540. && !(skill.getSkillType() == L2SkillType.SUMMON)
  6541. && !(skill.getSkillType() == L2SkillType.BEAST_FEED)
  6542. && !(skill.getSkillType() == L2SkillType.UNLOCK)
  6543. && !(skill.getSkillType() == L2SkillType.DELUXE_KEY_UNLOCK)
  6544. && (!(target instanceof L2Summon) || player.getPet() != target)
  6545. )
  6546. player.updatePvPStatus();
  6547. }
  6548. }
  6549. }
  6550. // Mobs in range 1000 see spell
  6551. Collection<L2Object> objs = player.getKnownList().getKnownObjects().values();
  6552. //synchronized (player.getKnownList().getKnownObjects())
  6553. {
  6554. for (L2Object spMob : objs)
  6555. {
  6556. if (spMob instanceof L2Npc)
  6557. {
  6558. L2Npc npcMob = (L2Npc) spMob;
  6559.  
  6560. if ((npcMob.isInsideRadius(player, 1000, true, true))
  6561. && (npcMob.getTemplate().getEventQuests(Quest.QuestEventType.ON_SKILL_SEE) != null))
  6562. for (Quest quest : npcMob.getTemplate().getEventQuests(Quest.QuestEventType.ON_SKILL_SEE))
  6563. quest.notifySkillSee(npcMob, player, skill, targets, this instanceof L2Summon);
  6564. }
  6565. }
  6566. }
  6567. }
  6568. }
  6569. catch (Exception e)
  6570. {
  6571. _log.log(Level.WARNING, "", e);
  6572. }
  6573. }
  6574.  
  6575. /**
  6576. * Return True if the L2Character is behind the target and can't be seen.<BR><BR>
  6577. */
  6578. public boolean isBehind(L2Object target)
  6579. {
  6580. double angleChar, angleTarget, angleDiff, maxAngleDiff = 45;
  6581.  
  6582. if(target == null)
  6583. return false;
  6584.  
  6585. if (target instanceof L2Character)
  6586. {
  6587. L2Character target1 = (L2Character) target;
  6588. angleChar = Util.calculateAngleFrom(this, target1);
  6589. angleTarget = Util.convertHeadingToDegree(target1.getHeading());
  6590. angleDiff = angleChar - angleTarget;
  6591. if (angleDiff <= -360 + maxAngleDiff) angleDiff += 360;
  6592. if (angleDiff >= 360 - maxAngleDiff) angleDiff -= 360;
  6593. if (Math.abs(angleDiff) <= maxAngleDiff)
  6594. {
  6595. if (Config.DEBUG)
  6596. _log.info("Char " + getName() + " is behind " + target.getName());
  6597. return true;
  6598. }
  6599. }
  6600. else
  6601. {
  6602. _log.fine("isBehindTarget's target not an L2 Character.");
  6603. }
  6604. return false;
  6605. }
  6606.  
  6607. public boolean isBehindTarget()
  6608. {
  6609. return isBehind(getTarget());
  6610. }
  6611.  
  6612. /**
  6613. * Return True if the target is facing the L2Character.<BR><BR>
  6614. */
  6615. public boolean isInFrontOf(L2Character target)
  6616. {
  6617. double angleChar, angleTarget, angleDiff, maxAngleDiff = 45;
  6618. if(target == null)
  6619. return false;
  6620.  
  6621. angleTarget = Util.calculateAngleFrom(target, this);
  6622. angleChar = Util.convertHeadingToDegree(target.getHeading());
  6623. angleDiff = angleChar - angleTarget;
  6624. if (angleDiff <= -360 + maxAngleDiff) angleDiff += 360;
  6625. if (angleDiff >= 360 - maxAngleDiff) angleDiff -= 360;
  6626. if (Math.abs(angleDiff) <= maxAngleDiff)
  6627. return true;
  6628. return false;
  6629. }
  6630.  
  6631. /** Returns true if target is in front of L2Character (shield def etc) */
  6632. public boolean isFacing(L2Object target, int maxAngle)
  6633. {
  6634. double angleChar, angleTarget, angleDiff, maxAngleDiff;
  6635. if(target == null)
  6636. return false;
  6637. maxAngleDiff = maxAngle / 2;
  6638. angleTarget = Util.calculateAngleFrom(this, target);
  6639. angleChar = Util.convertHeadingToDegree(this.getHeading());
  6640. angleDiff = angleChar - angleTarget;
  6641. if (angleDiff <= -360 + maxAngleDiff) angleDiff += 360;
  6642. if (angleDiff >= 360 - maxAngleDiff) angleDiff -= 360;
  6643. if (Math.abs(angleDiff) <= maxAngleDiff)
  6644. return true;
  6645. return false;
  6646. }
  6647.  
  6648. public boolean isInFrontOfTarget()
  6649. {
  6650. L2Object target = getTarget();
  6651. if (target instanceof L2Character)
  6652. return isInFrontOf((L2Character)target);
  6653. else
  6654. return false;
  6655. }
  6656.  
  6657.  
  6658. /**
  6659. * Return 1.<BR><BR>
  6660. */
  6661. public double getLevelMod()
  6662. {
  6663. return 1;
  6664. }
  6665.  
  6666. public final void setSkillCast(Future<?> newSkillCast)
  6667. {
  6668. _skillCast = newSkillCast;
  6669. }
  6670. /** Sets _isCastingNow to true and _castInterruptTime is calculated from end time (ticks) */
  6671. public final void forceIsCasting(int newSkillCastEndTick)
  6672. {
  6673. setIsCastingNow(true);
  6674. // for interrupt -200 ms
  6675. _castInterruptTime = newSkillCastEndTick-2;
  6676. }
  6677.  
  6678. private Future<?> _PvPRegTask;
  6679.  
  6680. private long _pvpFlagLasts;
  6681.  
  6682. private boolean _AIdisabled = false;
  6683.  
  6684. private boolean _isMinion = false;
  6685.  
  6686. public void setPvpFlagLasts(long time)
  6687. {
  6688. _pvpFlagLasts = time;
  6689. }
  6690.  
  6691. public long getPvpFlagLasts()
  6692. {
  6693. return _pvpFlagLasts;
  6694. }
  6695.  
  6696. public void startPvPFlag()
  6697. {
  6698. updatePvPFlag(1);
  6699.  
  6700. _PvPRegTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new PvPFlag(), 1000, 1000);
  6701. }
  6702.  
  6703. public void stopPvpRegTask()
  6704. {
  6705. if (_PvPRegTask != null)
  6706. _PvPRegTask.cancel(true);
  6707. }
  6708.  
  6709. public void stopPvPFlag()
  6710. {
  6711. stopPvpRegTask();
  6712.  
  6713. updatePvPFlag(0);
  6714.  
  6715. _PvPRegTask = null;
  6716. }
  6717.  
  6718. public void updatePvPFlag(int value)
  6719. {
  6720. // Overridden in L2PcInstance
  6721. }
  6722.  
  6723. /**
  6724. * Return a Random Damage in function of the weapon.<BR><BR>
  6725. */
  6726. public final int getRandomDamage(L2Character target)
  6727. {
  6728. L2Weapon weaponItem = getActiveWeaponItem();
  6729.  
  6730. if (weaponItem == null)
  6731. return 5+(int)Math.sqrt(getLevel());
  6732.  
  6733. return weaponItem.getRandomDamage();
  6734. }
  6735.  
  6736. @Override
  6737. public String toString()
  6738. {
  6739. return "mob "+getObjectId();
  6740. }
  6741.  
  6742. public int getAttackEndTime()
  6743. {
  6744. return _attackEndTime;
  6745. }
  6746.  
  6747. /**
  6748. * Not Implemented.<BR><BR>
  6749. */
  6750. public abstract int getLevel();
  6751. // =========================================================
  6752.  
  6753.  
  6754.  
  6755.  
  6756.  
  6757.  
  6758. // =========================================================
  6759. // Stat - NEED TO REMOVE ONCE L2CHARSTAT IS COMPLETE
  6760. // Property - Public
  6761. public final double calcStat(Stats stat, double init, L2Character target, L2Skill skill) { return getStat().calcStat(stat, init, target, skill); }
  6762.  
  6763. // Property - Public
  6764. public int getAccuracy() { return getStat().getAccuracy(); }
  6765. public final float getAttackSpeedMultiplier() { return getStat().getAttackSpeedMultiplier(); }
  6766. public int getCON() { return getStat().getCON(); }
  6767. public int getDEX() { return getStat().getDEX(); }
  6768. public final double getCriticalDmg(L2Character target, double init) { return getStat().getCriticalDmg(target, init); }
  6769. public int getCriticalHit(L2Character target, L2Skill skill) { return getStat().getCriticalHit(target, skill); }
  6770. public int getEvasionRate(L2Character target) { return getStat().getEvasionRate(target); }
  6771. public int getINT() { return getStat().getINT(); }
  6772. public final int getMagicalAttackRange(L2Skill skill) { return getStat().getMagicalAttackRange(skill); }
  6773. public final int getMaxCp() { return getStat().getMaxCp(); }
  6774. public int getMAtk(L2Character target, L2Skill skill) { return getStat().getMAtk(target, skill); }
  6775. public int getMAtkSpd() { return getStat().getMAtkSpd(); }
  6776. public int getMaxMp() { return getStat().getMaxMp(); }
  6777. public int getMaxHp() { return getStat().getMaxHp(); }
  6778. public final int getMCriticalHit(L2Character target, L2Skill skill) { return getStat().getMCriticalHit(target, skill); }
  6779. public int getMDef(L2Character target, L2Skill skill) { return getStat().getMDef(target, skill); }
  6780. public int getMEN() { return getStat().getMEN(); }
  6781. public double getMReuseRate(L2Skill skill) { return getStat().getMReuseRate(skill); }
  6782. public float getMovementSpeedMultiplier() { return getStat().getMovementSpeedMultiplier(); }
  6783. public int getPAtk(L2Character target) { return getStat().getPAtk(target); }
  6784. public double getPAtkAnimals(L2Character target) { return getStat().getPAtkAnimals(target); }
  6785. public double getPAtkDragons(L2Character target) { return getStat().getPAtkDragons(target); }
  6786. public double getPAtkInsects(L2Character target) { return getStat().getPAtkInsects(target); }
  6787. public double getPAtkMonsters(L2Character target) { return getStat().getPAtkMonsters(target); }
  6788. public double getPAtkPlants(L2Character target) { return getStat().getPAtkPlants(target); }
  6789. public double getPAtkGiants(L2Character target) { return getStat().getPAtkGiants(target); }
  6790. public double getPAtkMCreatures(L2Character target) { return getStat().getPAtkMCreatures(target); }
  6791. public double getPDefAnimals(L2Character target) { return getStat().getPDefAnimals(target); }
  6792. public double getPDefDragons(L2Character target) { return getStat().getPDefDragons(target); }
  6793. public double getPDefInsects(L2Character target) { return getStat().getPDefInsects(target); }
  6794. public double getPDefMonsters(L2Character target) { return getStat().getPDefMonsters(target); }
  6795. public double getPDefPlants(L2Character target) { return getStat().getPDefPlants(target); }
  6796. public double getPDefGiants(L2Character target) { return getStat().getPDefGiants(target); }
  6797.  
  6798. public int getPAtkSpd() { return getStat().getPAtkSpd(); }
  6799. public int getPDef(L2Character target) { return getStat().getPDef(target); }
  6800. public final int getPhysicalAttackRange() { return getStat().getPhysicalAttackRange(); }
  6801. public int getRunSpeed() { return getStat().getRunSpeed(); }
  6802. public final int getShldDef() { return getStat().getShldDef(); }
  6803. public int getSTR() { return getStat().getSTR(); }
  6804. public final int getWalkSpeed() { return getStat().getWalkSpeed(); }
  6805. public int getWIT() { return getStat().getWIT(); }
  6806. // =========================================================
  6807.  
  6808.  
  6809. // =========================================================
  6810. // Status - NEED TO REMOVE ONCE L2CHARTATUS IS COMPLETE
  6811. // Method - Public
  6812. public void addStatusListener(L2Character object) { getStatus().addStatusListener(object); }
  6813. public void reduceCurrentHp(double i, L2Character attacker, L2Skill skill) { reduceCurrentHp(i, attacker, true, false, skill); }
  6814. public void reduceCurrentHpByDOT(double i, L2Character attacker, L2Skill skill) { reduceCurrentHp(i, attacker, !skill.isToggle(), true, skill); }
  6815. public void reduceCurrentHp(double i, L2Character attacker, boolean awake, boolean isDOT, L2Skill skill)
  6816. {
  6817. if (Config.L2JMOD_CHAMPION_ENABLE && isChampion() && Config.L2JMOD_CHAMPION_HP != 0)
  6818. getStatus().reduceHp(i/Config.L2JMOD_CHAMPION_HP, attacker, awake, isDOT, false);
  6819. else
  6820. getStatus().reduceHp(i, attacker, awake, isDOT, false);
  6821. }
  6822. public void reduceCurrentMp(double i) { getStatus().reduceMp(i); }
  6823. public void removeStatusListener(L2Character object) { getStatus().removeStatusListener(object); }
  6824. protected void stopHpMpRegeneration() { getStatus().stopHpMpRegeneration(); }
  6825.  
  6826. // Property - Public
  6827. public final double getCurrentCp() { return getStatus().getCurrentCp(); }
  6828. public final void setCurrentCp(Double newCp) { setCurrentCp((double) newCp); }
  6829. public final void setCurrentCp(double newCp) { getStatus().setCurrentCp(newCp); }
  6830. public final double getCurrentHp() { return getStatus().getCurrentHp(); }
  6831. public final void setCurrentHp(double newHp) { getStatus().setCurrentHp(newHp); }
  6832. public final int getCurrentShowHpPvp()
  6833. {
  6834. return (int) getStatus().getCurrentHp();
  6835. }
  6836. public final void setCurrentHpMp(double newHp, double newMp){ getStatus().setCurrentHpMp(newHp, newMp); }
  6837. public final double getCurrentMp() { return getStatus().getCurrentMp(); }
  6838. public final void setCurrentMp(Double newMp) { setCurrentMp((double)newMp); }
  6839. public final void setCurrentMp(double newMp) { getStatus().setCurrentMp(newMp); }
  6840. // =========================================================
  6841.  
  6842. public void setAiClass(String aiClass)
  6843. {
  6844. _aiClass = aiClass;
  6845. }
  6846.  
  6847. public String getAiClass()
  6848. {
  6849. return _aiClass;
  6850. }
  6851.  
  6852. public L2Character getLastBuffer()
  6853. {
  6854. return _lastBuffer;
  6855. }
  6856.  
  6857. public void setChampion(boolean champ)
  6858. {
  6859. _champion = champ;
  6860. }
  6861.  
  6862. public boolean isChampion()
  6863. {
  6864. return _champion;
  6865. }
  6866.  
  6867. public int getLastHealAmount()
  6868. {
  6869. return _lastHealAmount;
  6870. }
  6871.  
  6872. public void setLastBuffer(L2Character buffer)
  6873. {
  6874. _lastBuffer = buffer;
  6875. }
  6876.  
  6877. public void setLastHealAmount(int hp)
  6878. {
  6879. _lastHealAmount = hp;
  6880. }
  6881.  
  6882. /**
  6883. * Check player max buff count
  6884. * @return max buff count
  6885. */
  6886. public int getMaxBuffCount()
  6887. {
  6888. return Config.BUFFS_MAX_AMOUNT + Math.max(0, getSkillLevel(L2Skill.SKILL_DIVINE_INSPIRATION));
  6889. }
  6890.  
  6891. /**
  6892. * Send system message about damage.<BR><BR>
  6893. *
  6894. * <B><U> Overridden in </U> :</B><BR><BR>
  6895. * <li> L2PcInstance
  6896. * <li> L2SummonInstance
  6897. * <li> L2PetInstance</li><BR><BR>
  6898. *
  6899. */
  6900. public void sendDamageMessage(L2Character target, int damage, boolean mcrit, boolean pcrit, boolean miss)
  6901. {
  6902. }
  6903.  
  6904. public FusionSkill getFusionSkill()
  6905. {
  6906. return _fusionSkill;
  6907. }
  6908.  
  6909. public void setFusionSkill(FusionSkill fb)
  6910. {
  6911. _fusionSkill = fb;
  6912. }
  6913.  
  6914. public byte getAttackElement()
  6915. {
  6916. return getStat().getAttackElement();
  6917. }
  6918.  
  6919. public int getAttackElementValue(byte attackAttribute)
  6920. {
  6921. return getStat().getAttackElementValue(attackAttribute);
  6922. }
  6923.  
  6924. public int getDefenseElementValue(byte defenseAttribute)
  6925. {
  6926. return getStat().getDefenseElementValue(defenseAttribute);
  6927. }
  6928.  
  6929. public final void startPhysicalAttackMuted()
  6930. {
  6931. setIsPhysicalAttackMuted(true);
  6932. abortAttack();
  6933. }
  6934.  
  6935. public final void stopPhysicalAttackMuted(L2Effect effect)
  6936. {
  6937. if (effect == null)
  6938. stopEffects(L2EffectType.PHYSICAL_ATTACK_MUTE);
  6939. else
  6940. removeEffect(effect);
  6941.  
  6942. setIsPhysicalAttackMuted(false);
  6943. }
  6944. public void disableCoreAI(boolean val)
  6945. {
  6946. _AIdisabled = val;
  6947. }
  6948.  
  6949. public boolean isCoreAIDisabled()
  6950. {
  6951. return _AIdisabled;
  6952. }
  6953.  
  6954. /** Task for potion and herb queue */
  6955. private class UsePotionTask implements Runnable
  6956. {
  6957. private L2Character _activeChar;
  6958. private L2Skill _skill;
  6959.  
  6960. UsePotionTask(L2Character activeChar, L2Skill skill)
  6961. {
  6962. _activeChar = activeChar;
  6963. _skill = skill;
  6964. }
  6965.  
  6966. public void run()
  6967. {
  6968. try
  6969. {
  6970. _activeChar.doSimultaneousCast(_skill);
  6971. }
  6972. catch (Exception e)
  6973. {
  6974. _log.log(Level.WARNING, "", e);
  6975. }
  6976. }
  6977. }
  6978. public boolean isRaidMinion()
  6979. {
  6980. return _isMinion ;
  6981. }
  6982.  
  6983. /**
  6984. * Set this Npc as a Minion instance.<BR><BR>
  6985. * @param val
  6986. */
  6987. public void setIsRaidMinion(boolean val)
  6988. {
  6989. _isRaid = val;
  6990. _isMinion = val;
  6991. }
  6992. }
Advertisement
Add Comment
Please, Sign In to add comment