Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 310.14 KB | None | 0 0
  1. /*
  2. * L2jFrozen Project - www.l2jfrozen.com
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2, or (at your option)
  7. * any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  17. * 02111-1307, USA.
  18. *
  19. * http://www.gnu.org/copyleft/gpl.html
  20. */
  21. package com.l2jfrozen.gameserver.model;
  22.  
  23. import static com.l2jfrozen.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
  24. import static com.l2jfrozen.gameserver.ai.CtrlIntention.AI_INTENTION_FOLLOW;
  25.  
  26. import java.util.Collections;
  27. import java.util.Iterator;
  28. import java.util.List;
  29. import java.util.Map;
  30. import java.util.concurrent.Future;
  31.  
  32. import javolution.util.FastList;
  33. import javolution.util.FastMap;
  34. import javolution.util.FastTable;
  35.  
  36. import org.apache.log4j.Logger;
  37.  
  38. import com.l2jfrozen.Config;
  39. import com.l2jfrozen.gameserver.ai.CtrlEvent;
  40. import com.l2jfrozen.gameserver.ai.CtrlIntention;
  41. import com.l2jfrozen.gameserver.ai.L2AttackableAI;
  42. import com.l2jfrozen.gameserver.ai.L2CharacterAI;
  43. import com.l2jfrozen.gameserver.controllers.GameTimeController;
  44. import com.l2jfrozen.gameserver.datatables.HeroSkillTable;
  45. import com.l2jfrozen.gameserver.datatables.SkillTable;
  46. import com.l2jfrozen.gameserver.datatables.csv.DoorTable;
  47. import com.l2jfrozen.gameserver.datatables.csv.MapRegionTable;
  48. import com.l2jfrozen.gameserver.datatables.csv.MapRegionTable.TeleportWhereType;
  49. import com.l2jfrozen.gameserver.datatables.sql.NpcTable;
  50. import com.l2jfrozen.gameserver.geo.GeoData;
  51. import com.l2jfrozen.gameserver.geo.pathfinding.Node;
  52. import com.l2jfrozen.gameserver.geo.pathfinding.PathFinding;
  53. import com.l2jfrozen.gameserver.handler.ISkillHandler;
  54. import com.l2jfrozen.gameserver.handler.SkillHandler;
  55. import com.l2jfrozen.gameserver.handler.itemhandlers.Potions;
  56. import com.l2jfrozen.gameserver.managers.DimensionalRiftManager;
  57. import com.l2jfrozen.gameserver.managers.DuelManager;
  58. import com.l2jfrozen.gameserver.managers.GrandBossManager;
  59. import com.l2jfrozen.gameserver.managers.RaidBossSpawnManager;
  60. import com.l2jfrozen.gameserver.managers.SpecialZoneManager;
  61. import com.l2jfrozen.gameserver.managers.TownManager;
  62. import com.l2jfrozen.gameserver.model.L2Skill.SkillTargetType;
  63. import com.l2jfrozen.gameserver.model.L2Skill.SkillType;
  64. import com.l2jfrozen.gameserver.model.actor.instance.L2BoatInstance;
  65. import com.l2jfrozen.gameserver.model.actor.instance.L2ControlTowerInstance;
  66. import com.l2jfrozen.gameserver.model.actor.instance.L2DoorInstance;
  67. import com.l2jfrozen.gameserver.model.actor.instance.L2EffectPointInstance;
  68. import com.l2jfrozen.gameserver.model.actor.instance.L2GrandBossInstance;
  69. import com.l2jfrozen.gameserver.model.actor.instance.L2GuardInstance;
  70. import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
  71. import com.l2jfrozen.gameserver.model.actor.instance.L2MinionInstance;
  72. import com.l2jfrozen.gameserver.model.actor.instance.L2MonsterInstance;
  73. import com.l2jfrozen.gameserver.model.actor.instance.L2NpcInstance;
  74. import com.l2jfrozen.gameserver.model.actor.instance.L2NpcWalkerInstance;
  75. import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  76. import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance.SkillDat;
  77. import com.l2jfrozen.gameserver.model.actor.instance.L2PetInstance;
  78. import com.l2jfrozen.gameserver.model.actor.instance.L2PlayableInstance;
  79. import com.l2jfrozen.gameserver.model.actor.instance.L2RaidBossInstance;
  80. import com.l2jfrozen.gameserver.model.actor.instance.L2RiftInvaderInstance;
  81. import com.l2jfrozen.gameserver.model.actor.instance.L2SiegeFlagInstance;
  82. import com.l2jfrozen.gameserver.model.actor.instance.L2SummonInstance;
  83. import com.l2jfrozen.gameserver.model.actor.knownlist.CharKnownList;
  84. import com.l2jfrozen.gameserver.model.actor.knownlist.ObjectKnownList.KnownListAsynchronousUpdateTask;
  85. import com.l2jfrozen.gameserver.model.actor.position.L2CharPosition;
  86. import com.l2jfrozen.gameserver.model.actor.position.ObjectPosition;
  87. import com.l2jfrozen.gameserver.model.actor.stat.CharStat;
  88. import com.l2jfrozen.gameserver.model.actor.status.CharStatus;
  89. import com.l2jfrozen.gameserver.model.entity.Duel;
  90. import com.l2jfrozen.gameserver.model.entity.event.CTF;
  91. import com.l2jfrozen.gameserver.model.entity.event.DM;
  92. import com.l2jfrozen.gameserver.model.entity.event.L2Event;
  93. import com.l2jfrozen.gameserver.model.entity.event.TvT;
  94. import com.l2jfrozen.gameserver.model.entity.event.VIP;
  95. import com.l2jfrozen.gameserver.model.entity.olympiad.Olympiad;
  96. import com.l2jfrozen.gameserver.model.extender.BaseExtender.EventType;
  97. import com.l2jfrozen.gameserver.model.quest.Quest;
  98. import com.l2jfrozen.gameserver.model.quest.QuestState;
  99. import com.l2jfrozen.gameserver.model.zone.type.L2BossZone;
  100. import com.l2jfrozen.gameserver.model.zone.type.L2TownZone;
  101. import com.l2jfrozen.gameserver.network.SystemMessageId;
  102. import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
  103. import com.l2jfrozen.gameserver.network.serverpackets.Attack;
  104. import com.l2jfrozen.gameserver.network.serverpackets.BeginRotation;
  105. import com.l2jfrozen.gameserver.network.serverpackets.ChangeMoveType;
  106. import com.l2jfrozen.gameserver.network.serverpackets.ChangeWaitType;
  107. import com.l2jfrozen.gameserver.network.serverpackets.CharInfo;
  108. import com.l2jfrozen.gameserver.network.serverpackets.CharMoveToLocation;
  109. import com.l2jfrozen.gameserver.network.serverpackets.ExOlympiadSpelledInfo;
  110. import com.l2jfrozen.gameserver.network.serverpackets.L2GameServerPacket;
  111. import com.l2jfrozen.gameserver.network.serverpackets.MagicEffectIcons;
  112. import com.l2jfrozen.gameserver.network.serverpackets.MagicSkillCanceld;
  113. import com.l2jfrozen.gameserver.network.serverpackets.MagicSkillLaunched;
  114. import com.l2jfrozen.gameserver.network.serverpackets.MagicSkillUser;
  115. import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
  116. import com.l2jfrozen.gameserver.network.serverpackets.NpcInfo;
  117. import com.l2jfrozen.gameserver.network.serverpackets.PartySpelled;
  118. import com.l2jfrozen.gameserver.network.serverpackets.PetInfo;
  119. import com.l2jfrozen.gameserver.network.serverpackets.RelationChanged;
  120. import com.l2jfrozen.gameserver.network.serverpackets.Revive;
  121. import com.l2jfrozen.gameserver.network.serverpackets.SetupGauge;
  122. import com.l2jfrozen.gameserver.network.serverpackets.StatusUpdate;
  123. import com.l2jfrozen.gameserver.network.serverpackets.StopMove;
  124. import com.l2jfrozen.gameserver.network.serverpackets.SystemMessage;
  125. import com.l2jfrozen.gameserver.network.serverpackets.TargetUnselected;
  126. import com.l2jfrozen.gameserver.network.serverpackets.TeleportToLocation;
  127. import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
  128. import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocationInVehicle;
  129. import com.l2jfrozen.gameserver.skills.Calculator;
  130. import com.l2jfrozen.gameserver.skills.Formulas;
  131. import com.l2jfrozen.gameserver.skills.Stats;
  132. import com.l2jfrozen.gameserver.skills.effects.EffectCharge;
  133. import com.l2jfrozen.gameserver.skills.funcs.Func;
  134. import com.l2jfrozen.gameserver.skills.holders.ISkillsHolder;
  135. import com.l2jfrozen.gameserver.templates.L2CharTemplate;
  136. import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
  137. import com.l2jfrozen.gameserver.templates.L2Weapon;
  138. import com.l2jfrozen.gameserver.templates.L2WeaponType;
  139. import com.l2jfrozen.gameserver.templates.StatsSet;
  140. import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
  141. import com.l2jfrozen.gameserver.util.Util;
  142. import com.l2jfrozen.util.Point3D;
  143. import com.l2jfrozen.util.random.Rnd;
  144.  
  145. /**
  146. * Mother class of all character objects of the world (PC, NPC...)<BR>
  147. * <BR>
  148. * L2Character :<BR>
  149. * <BR>
  150. * <li>L2CastleGuardInstance</li> <li>L2DoorInstance</li> <li>L2NpcInstance</li> <li>L2PlayableInstance</li><BR>
  151. * <BR>
  152. * <B><U> Concept of L2CharTemplate</U> :</B><BR>
  153. * <BR>
  154. * Each L2Character owns generic and static properties (ex : all Keltir have the same number of HP...). All of those properties are stored in a different template for each type of L2Character. Each template is loaded once in the server cache memory (reduce memory use). When a new instance of
  155. * L2Character is spawned, server just create a link between the instance and the template. This link is stored in <B>_template</B><BR>
  156. * <BR>
  157. * @version $Revision: 1.5.5 $ $Date: 2009/05/12 19:45:27 $
  158. * @authors eX1steam, programmos, L2Scoria dev&sword dev
  159. */
  160. public abstract class L2Character extends L2Object implements ISkillsHolder
  161. {
  162. /** The Constant LOGGER. */
  163. protected static final Logger LOGGER = Logger.getLogger(L2Character.class);
  164.  
  165. // =========================================================
  166. // Data Field
  167. /** The attack stance. */
  168. private long attackStance;
  169.  
  170. /** The _attack by list. */
  171. private List<L2Character> _attackByList;
  172. // private L2Character _attackingChar;
  173. /** The _last skill cast. */
  174. private L2Skill _lastSkillCast;
  175.  
  176. /** The _last potion cast. */
  177. private L2Skill _lastPotionCast;
  178.  
  179. /** The _is buff protected. */
  180. private boolean _isBuffProtected = false; // Protect From Debuffs
  181.  
  182. /** The _is afraid. */
  183. private boolean _isAfraid = false; // Flee in a random direction
  184.  
  185. /** The _is confused. */
  186. private boolean _isConfused = false; // Attack anyone randomly
  187.  
  188. /** The _is fake death. */
  189. private boolean _isFakeDeath = false; // Fake death
  190.  
  191. /** The _is flying. */
  192. private boolean _isFlying = false; // Is flying Wyvern?
  193.  
  194. /** The _is fallsdown. */
  195. private boolean _isFallsdown = false; // Falls down
  196.  
  197. /** The _is muted. */
  198. private boolean _isMuted = false; // Cannot use magic
  199.  
  200. /** The _is psychical muted. */
  201. private boolean _isPsychicalMuted = false; // Cannot use psychical skills
  202.  
  203. /** The _is killed already. */
  204. private boolean _isKilledAlready = false;
  205.  
  206. /** The _is imobilised. */
  207. private int _isImobilised = 0;
  208.  
  209. /** The _is overloaded. */
  210. private boolean _isOverloaded = false; // the char is carrying too much
  211.  
  212. /** The _is paralyzed. */
  213. private boolean _isParalyzed = false;
  214.  
  215. /** The _is riding. */
  216. private boolean _isRiding = false; // Is Riding strider?
  217.  
  218. /** The _is pending revive. */
  219. private boolean _isPendingRevive = false;
  220.  
  221. /** The _is rooted. */
  222. private boolean _isRooted = false; // Cannot move until root timed out
  223.  
  224. /** The _is running. */
  225. private boolean _isRunning = false;
  226.  
  227. /** The _is immobile until attacked. */
  228. private boolean _isImmobileUntilAttacked = false; // Is in immobile until attacked.
  229.  
  230. /** The _is sleeping. */
  231. private boolean _isSleeping = false; // Cannot move/attack until sleep timed out or monster is attacked
  232.  
  233. /** The _is stunned. */
  234. private boolean _isStunned = false; // Cannot move/attack until stun timed out
  235.  
  236. /** The _is betrayed. */
  237. private boolean _isBetrayed = false; // Betrayed by own summon
  238.  
  239. /** The _is block buff. */
  240. private boolean _isBlockBuff = false; // Got blocked buff bar
  241.  
  242. /** The _is block debuff. */
  243. private boolean _isBlockDebuff = false; // Got blocked debuff bar
  244.  
  245. /** The _is teleporting. */
  246. protected boolean _isTeleporting = false;
  247.  
  248. /** The _is invul. */
  249. protected boolean _isInvul = false;
  250.  
  251. /** The _is killable */
  252. protected boolean _isUnkillable = false;
  253.  
  254. /** The attackDisabled */
  255. protected boolean _isAttackDisabled = false;
  256.  
  257. /** The _last heal amount. */
  258. private int _lastHealAmount = 0;
  259.  
  260. /** The _stat. */
  261. private CharStat _stat;
  262.  
  263. /** The _status. */
  264. private CharStatus _status;
  265.  
  266. /** The _template. */
  267. private L2CharTemplate _template; // The link on the L2CharTemplate object containing generic and static properties of this L2Character type (ex : Max HP, Speed...)
  268.  
  269. /** The _title. */
  270. private String _title;
  271.  
  272. /** The _ai class. */
  273. private String _aiClass = "default";
  274.  
  275. /** The _hp update inc check. */
  276. private double _hpUpdateIncCheck = .0;
  277.  
  278. /** The _hp update dec check. */
  279. private double _hpUpdateDecCheck = .0;
  280.  
  281. /** The _hp update interval. */
  282. private double _hpUpdateInterval = .0;
  283.  
  284. /** The _champion. */
  285. private boolean _champion = false;
  286.  
  287. /** Table of Calculators containing all used calculator. */
  288. private Calculator[] _calculators;
  289.  
  290. /** FastMap(Integer, L2Skill) containing all skills of the L2Character. */
  291. protected final Map<Integer, L2Skill> _skills;
  292.  
  293. /** FastMap(Integer, L2Skill) containing all triggered skills of the L2PcInstance. */
  294. protected final Map<Integer, L2Skill> _triggeredSkills;
  295.  
  296. /** FastMap containing the active chance skills on this character. */
  297. protected ChanceSkillList _chanceSkills;
  298.  
  299. /** Current force buff this caster is casting to a target. */
  300. protected ForceBuff _forceBuff;
  301.  
  302. /** The _blocked. */
  303. private boolean _blocked;
  304.  
  305. /** The _meditated. */
  306. private boolean _meditated;
  307.  
  308. /**
  309. * Zone system<br>
  310. * x^2 or x*x.
  311. */
  312. public static final int ZONE_PVP = 1;
  313.  
  314. /** The Constant ZONE_PEACE. */
  315. public static final int ZONE_PEACE = 2;
  316.  
  317. /** The Constant ZONE_SIEGE. */
  318. public static final int ZONE_SIEGE = 4;
  319.  
  320. /** The Constant ZONE_MOTHERTREE. */
  321. public static final int ZONE_MOTHERTREE = 8;
  322.  
  323. /** The Constant ZONE_CLANHALL. */
  324. public static final int ZONE_CLANHALL = 16;
  325.  
  326. /** The Constant ZONE_UNUSED. */
  327. public static final int ZONE_UNUSED = 32;
  328.  
  329. /** The Constant ZONE_NOLANDING. */
  330. public static final int ZONE_NOLANDING = 64;
  331.  
  332. /** The Constant ZONE_WATER. */
  333. public static final int ZONE_WATER = 128;
  334.  
  335. /** The Constant ZONE_JAIL. */
  336. public static final int ZONE_JAIL = 256;
  337.  
  338. /** The Constant ZONE_MONSTERTRACK. */
  339. public static final int ZONE_MONSTERTRACK = 512;
  340.  
  341. /** The Constant ZONE_SWAMP. */
  342. public static final int ZONE_SWAMP = 1024;
  343.  
  344. /** The Constant ZONE_NOSUMMONFRIEND. */
  345. public static final int ZONE_NOSUMMONFRIEND = 2048;
  346.  
  347. /** The Constant ZONE_OLY. */
  348. public static final int ZONE_OLY = 4096;
  349.  
  350. /** The Constant ZONE_NOHQ. */
  351. public static final int ZONE_NOHQ = 8192;
  352.  
  353. /** The Constant ZONE_DANGERAREA. */
  354. public static final int ZONE_DANGERAREA = 16384;
  355.  
  356. /** The Constant ZONE_MULTIFUNCTION. */
  357. public static final int ZONE_MULTIFUNCTION = 32;
  358.  
  359. /** The Constant ZONE_NOSTORE. */
  360. public static final int ZONE_NOSTORE = 32768;
  361.  
  362. /** The Constant ZONE_SPECIAL. */
  363. public static final int ZONE_SPECIAL = 65536;
  364.  
  365. /** The _current zones. */
  366. private int _currentZones = 0;
  367.  
  368. /** Advance Headquarters */
  369. private boolean _advanceFlag = false;
  370. private int _advanceMultiplier = 1;
  371.  
  372. /**
  373. * Checks if is inside zone.
  374. * @param zone the zone
  375. * @return true, if is inside zone
  376. */
  377. public boolean isInsideZone(final int zone)
  378. {
  379. return (_currentZones & zone) != 0;
  380. }
  381.  
  382. /**
  383. * Sets the inside zone.
  384. * @param zone the zone
  385. * @param state the state
  386. */
  387. public void setInsideZone(final int zone, final boolean state)
  388. {
  389. if (state)
  390. {
  391. _currentZones |= zone;
  392. }
  393. else if (isInsideZone(zone))
  394. {
  395. _currentZones ^= zone;
  396. }
  397. }
  398.  
  399. /**
  400. * This will return true if the player is GM,<br>
  401. * but if the player is not GM it will return false.
  402. * @return GM status
  403. */
  404. public boolean charIsGM()
  405. {
  406. if (this instanceof L2PcInstance)
  407. {
  408. if (((L2PcInstance) this).isGM())
  409. {
  410. return true;
  411. }
  412. }
  413. return false;
  414. }
  415.  
  416. // =========================================================
  417. // Constructor
  418. /**
  419. * Constructor of L2Character.<BR>
  420. * <BR>
  421. * <B><U> Concept</U> :</B><BR>
  422. * <BR>
  423. * Each L2Character owns generic and static properties (ex : all Keltir have the same number of HP...). All of those properties are stored in a different template for each type of L2Character. Each template is loaded once in the server cache memory (reduce memory use). When a new instance of
  424. * L2Character is spawned, server just create a link between the instance and the template This link is stored in <B>_template</B><BR>
  425. * <BR>
  426. * <B><U> Actions</U> :</B><BR>
  427. * <BR>
  428. * <li>Set the _template of the L2Character</li> <li>Set _overloaded to false (the charcater can take more items)</li> <BR>
  429. * <BR>
  430. * <li>If L2Character is a L2NPCInstance, copy skills from template to object</li> <li>If L2Character is a L2NPCInstance, link _calculators to NPC_STD_CALCULATOR</li><BR>
  431. * <BR>
  432. * <li>If L2Character is NOT a L2NPCInstance, create an empty _skills slot</li> <li>If L2Character is a L2PcInstance or L2Summon, copy basic Calculator set to object</li><BR>
  433. * <BR>
  434. * @param objectId Identifier of the object to initialized
  435. * @param template The L2CharTemplate to apply to the object
  436. */
  437. // MAKE TO US From DREAM
  438. // int attackcountmax = (int) Math.round(calcStat(Stats.POLE_TARGERT_COUNT, 3, null, null));
  439. public L2Character(final int objectId, final L2CharTemplate template)
  440. {
  441. super(objectId);
  442. getKnownList();
  443.  
  444. // Set its template to the new L2Character
  445. _template = template;
  446.  
  447. _triggeredSkills = new FastMap<>();
  448.  
  449. if (template != null && this instanceof L2NpcInstance)
  450. {
  451. // Copy the Standard Calcultors of the L2NPCInstance in _calculators
  452. _calculators = NPC_STD_CALCULATOR;
  453.  
  454. // Copy the skills of the L2NPCInstance from its template to the L2Character Instance
  455. // The skills list can be affected by spell effects so it's necessary to make a copy
  456. // to avoid that a spell affecting a L2NPCInstance, affects others L2NPCInstance of the same type too.
  457. _skills = ((L2NpcTemplate) template).getSkills();
  458.  
  459. for (final Map.Entry<Integer, L2Skill> skill : _skills.entrySet())
  460. {
  461. addStatFuncs(skill.getValue().getStatFuncs(null, this));
  462. }
  463.  
  464. if (!Config.NPC_ATTACKABLE || !(this instanceof L2Attackable) && !(this instanceof L2ControlTowerInstance) && !(this instanceof L2SiegeFlagInstance) && !(this instanceof L2EffectPointInstance))
  465. {
  466. setIsInvul(true);
  467. }
  468. }
  469. else
  470. // not L2NpcInstance
  471. {
  472. // Initialize the FastMap _skills to null
  473. _skills = new FastMap<Integer, L2Skill>().shared();
  474.  
  475. // If L2Character is a L2PcInstance or a L2Summon, create the basic calculator set
  476. _calculators = new Calculator[Stats.NUM_STATS];
  477. Formulas.getInstance().addFuncsToNewCharacter(this);
  478.  
  479. if (!(this instanceof L2Attackable) && !this.isAttackable() && !(this instanceof L2DoorInstance))
  480. setIsInvul(true);
  481. }
  482.  
  483. /*
  484. * if(!(this instanceof L2PcInstance) && !(this instanceof L2MonsterInstance) && !(this instanceof L2GuardInstance) && !(this instanceof L2SiegeGuardInstance) && !(this instanceof L2ControlTowerInstance) && !(this instanceof L2DoorInstance) && !(this instanceof L2FriendlyMobInstance) &&
  485. * !(this instanceof L2SiegeSummonInstance) && !(this instanceof L2PetInstance) && !(this instanceof L2SummonInstance) && !(this instanceof L2SiegeFlagInstance) && !(this instanceof L2EffectPointInstance) && !(this instanceof L2CommanderInstance) && !(this instanceof
  486. * L2FortSiegeGuardInstance)) { ///////////////////////////////////////////////////////////////////////////////////////////// setIsInvul(true); }
  487. */
  488. }
  489.  
  490. /**
  491. * Inits the char status update values.
  492. */
  493. protected void initCharStatusUpdateValues()
  494. {
  495. _hpUpdateInterval = getMaxHp() / 352.0; // MAX_HP div MAX_HP_BAR_PX
  496. _hpUpdateIncCheck = getMaxHp();
  497. _hpUpdateDecCheck = getMaxHp() - _hpUpdateInterval;
  498. }
  499.  
  500. // =========================================================
  501. // Event - Public
  502. /**
  503. * Remove the L2Character from the world when the decay task is launched.<BR>
  504. * <BR>
  505. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T REMOVE the object from _allObjects of L2World </B></FONT><BR>
  506. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND Server->Client packets to players</B></FONT><BR>
  507. * <BR>
  508. */
  509. public void onDecay()
  510. {
  511. L2WorldRegion reg = getWorldRegion();
  512.  
  513. if (reg != null)
  514. {
  515. reg.removeFromZones(this);
  516. }
  517.  
  518. decayMe();
  519.  
  520. reg = null;
  521. }
  522.  
  523. /*
  524. * (non-Javadoc)
  525. * @see com.l2jfrozen.gameserver.model.L2Object#onSpawn()
  526. */
  527. @Override
  528. public void onSpawn()
  529. {
  530. super.onSpawn();
  531. revalidateZone();
  532. }
  533.  
  534. /**
  535. * On teleported.
  536. */
  537. public void onTeleported()
  538. {
  539. if (!isTeleporting())
  540. return;
  541.  
  542. final ObjectPosition pos = getPosition();
  543.  
  544. if (pos != null)
  545. spawnMe(getPosition().getX(), getPosition().getY(), getPosition().getZ());
  546.  
  547. setIsTeleporting(false);
  548.  
  549. if (_isPendingRevive)
  550. {
  551. doRevive();
  552. }
  553.  
  554. final L2Summon pet = getPet();
  555.  
  556. // Modify the position of the pet if necessary
  557. if (pet != null && pos != null)
  558. {
  559. pet.setFollowStatus(false);
  560. pet.teleToLocation(pos.getX() + Rnd.get(-100, 100), pos.getY() + Rnd.get(-100, 100), pos.getZ(), false);
  561. pet.setFollowStatus(true);
  562. }
  563.  
  564. }
  565.  
  566. // =========================================================
  567. // Method - Public
  568. /**
  569. * Add L2Character instance that is attacking to the attacker list.<BR>
  570. * <BR>
  571. * @param player The L2Character that attcks this one
  572. */
  573. public void addAttackerToAttackByList(final L2Character player)
  574. {
  575. if (player == null || player == this || getAttackByList() == null || getAttackByList().contains(player))
  576. return;
  577.  
  578. getAttackByList().add(player);
  579. }
  580.  
  581. /**
  582. * Send a packet to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character.<BR>
  583. * <BR>
  584. * <B><U> Concept</U> :</B><BR>
  585. * <BR>
  586. * L2PcInstance in the detection area of the L2Character are identified in <B>_knownPlayers</B>. 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>
  587. * <BR>
  588. */
  589.  
  590. protected byte _startingRotationCounter = 4;
  591.  
  592. /**
  593. * Checks if is starting rotation allowed.
  594. * @return true, if is starting rotation allowed
  595. */
  596. public synchronized boolean isStartingRotationAllowed()
  597. {
  598. // This function is called too often from movement arrow
  599. _startingRotationCounter--;
  600. if (_startingRotationCounter < 0)
  601. _startingRotationCounter = 4;
  602.  
  603. if (_startingRotationCounter == 4)
  604. {
  605. return true;
  606. }
  607. return false;
  608. }
  609.  
  610. /**
  611. * Broadcast packet.
  612. * @param mov the mov
  613. */
  614. public final void broadcastPacket(final L2GameServerPacket mov)
  615. {
  616. if (!(mov instanceof CharInfo))
  617. {
  618. sendPacket(mov);
  619. }
  620.  
  621. // don't broadcast anytime the rotating packet
  622. if (mov instanceof BeginRotation && !isStartingRotationAllowed())
  623. {
  624. return;
  625. }
  626.  
  627. // if (Config.DEBUG) LOGGER.fine("players to notify:" + knownPlayers.size() + " packet:"+mov.getType());
  628.  
  629. for (final L2PcInstance player : getKnownList().getKnownPlayers().values())
  630. {
  631. if (player != null)
  632. {
  633. /*
  634. * TEMP FIX: If player is not visible don't send packets broadcast to all his KnowList. This will avoid GM detection with l2net and olympiad's crash. We can now find old problems with invisible mode.
  635. */
  636. if (this instanceof L2PcInstance && !player.isGM() && (((L2PcInstance) this).getAppearance().getInvisible() || ((L2PcInstance) this).inObserverMode()))
  637. return;
  638.  
  639. try
  640. {
  641. player.sendPacket(mov);
  642.  
  643. if (mov instanceof CharInfo && this instanceof L2PcInstance)
  644. {
  645. final int relation = ((L2PcInstance) this).getRelation(player);
  646. if (getKnownList().getKnownRelations().get(player.getObjectId()) != null && getKnownList().getKnownRelations().get(player.getObjectId()) != relation)
  647. {
  648. player.sendPacket(new RelationChanged((L2PcInstance) this, relation, player.isAutoAttackable(this)));
  649. }
  650. }
  651. // if(Config.DEVELOPER && !isInsideRadius(player, 3500, false, false)) LOGGER.warn("broadcastPacket: Too far player see event!");
  652. }
  653. catch (final NullPointerException e)
  654. {
  655. e.printStackTrace();
  656. }
  657. }
  658. }
  659. }
  660.  
  661. /**
  662. * Send a packet to the L2Character AND to all L2PcInstance in the radius (max knownlist radius) from the L2Character.<BR>
  663. * <BR>
  664. * <B><U> Concept</U> :</B><BR>
  665. * <BR>
  666. * L2PcInstance in the detection area of the L2Character are identified in <B>_knownPlayers</B>. 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>
  667. * <BR>
  668. * @param mov the mov
  669. * @param radiusInKnownlist the radius in knownlist
  670. */
  671. public final void broadcastPacket(final L2GameServerPacket mov, final int radiusInKnownlist)
  672. {
  673. if (!(mov instanceof CharInfo))
  674. {
  675. sendPacket(mov);
  676. }
  677.  
  678. // if (Config.DEBUG) LOGGER.fine("players to notify:" + knownPlayers.size() + " packet:"+mov.getType());
  679.  
  680. for (final L2PcInstance player : getKnownList().getKnownPlayers().values())
  681. {
  682. try
  683. {
  684. if (!isInsideRadius(player, radiusInKnownlist, false, false))
  685. {
  686. continue;
  687. }
  688.  
  689. player.sendPacket(mov);
  690.  
  691. if (mov instanceof CharInfo && this instanceof L2PcInstance)
  692. {
  693. final int relation = ((L2PcInstance) this).getRelation(player);
  694. if (getKnownList().getKnownRelations().get(player.getObjectId()) != null && getKnownList().getKnownRelations().get(player.getObjectId()) != relation)
  695. {
  696. player.sendPacket(new RelationChanged((L2PcInstance) this, relation, player.isAutoAttackable(this)));
  697. }
  698. }
  699. }
  700. catch (final NullPointerException e)
  701. {
  702. e.printStackTrace();
  703. }
  704. }
  705. }
  706.  
  707. /**
  708. * Need hp update.
  709. * @param barPixels the bar pixels
  710. * @return true if hp update should be done, false if not
  711. */
  712. protected boolean needHpUpdate(final int barPixels)
  713. {
  714. final double currentHp = getCurrentHp();
  715.  
  716. if (currentHp <= 1.0 || getMaxHp() < barPixels)
  717. return true;
  718.  
  719. if (currentHp <= _hpUpdateDecCheck || currentHp >= _hpUpdateIncCheck)
  720. {
  721. if (currentHp == getMaxHp())
  722. {
  723. _hpUpdateIncCheck = currentHp + 1;
  724. _hpUpdateDecCheck = currentHp - _hpUpdateInterval;
  725. }
  726. else
  727. {
  728. final double doubleMulti = currentHp / _hpUpdateInterval;
  729. int intMulti = (int) doubleMulti;
  730.  
  731. _hpUpdateDecCheck = _hpUpdateInterval * (doubleMulti < intMulti ? intMulti-- : intMulti);
  732. _hpUpdateIncCheck = _hpUpdateDecCheck + _hpUpdateInterval;
  733. }
  734. return true;
  735. }
  736.  
  737. return false;
  738. }
  739.  
  740. /**
  741. * Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform.<BR>
  742. * <BR>
  743. * <B><U> Actions</U> :</B><BR>
  744. * <BR>
  745. * <li>Create the Server->Client packet StatusUpdate with current HP and MP</li> <li>Send the Server->Client packet StatusUpdate with current HP and MP to all L2Character called _statusListener that must be informed of HP/MP updates of this L2Character</li><BR>
  746. * <BR>
  747. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND CP information</B></FONT><BR>
  748. * <BR>
  749. * <B><U> Overriden in </U> :</B><BR>
  750. * <BR>
  751. * <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>
  752. * <BR>
  753. */
  754. public void broadcastStatusUpdate()
  755. {
  756. if (getStatus().getStatusListener().isEmpty())
  757. return;
  758.  
  759. if (!needHpUpdate(352))
  760. return;
  761.  
  762. if (Config.DEBUG)
  763. {
  764. LOGGER.debug("Broadcast Status Update for " + getObjectId() + "(" + getName() + "). HP: " + getCurrentHp());
  765. }
  766.  
  767. // Create the Server->Client packet StatusUpdate with current HP and MP
  768. StatusUpdate su = null;
  769. if (Config.FORCE_COMPLETE_STATUS_UPDATE && this instanceof L2PcInstance)
  770. {
  771. su = new StatusUpdate((L2PcInstance) this);
  772. }
  773. else
  774. {
  775. su = new StatusUpdate(getObjectId());
  776. su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
  777. su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
  778. }
  779.  
  780. // Go through the StatusListener
  781. // Send the Server->Client packet StatusUpdate with current HP and MP
  782. for (final L2Character temp : getStatus().getStatusListener())
  783. {
  784. if (temp != null)
  785. temp.sendPacket(su);
  786. }
  787. /*
  788. * synchronized (getStatus().getStatusListener()) { for(L2Character temp : getStatus().getStatusListener()) { try { temp.sendPacket(su); } catch(NullPointerException e) { e.printStackTrace(); } } }
  789. */
  790. }
  791.  
  792. /**
  793. * Not Implemented.<BR>
  794. * <BR>
  795. * <B><U> Overridden in </U> :</B><BR>
  796. * <BR>
  797. * <li>L2PcInstance</li><BR>
  798. * <BR>
  799. * @param mov the mov
  800. */
  801. public void sendPacket(final L2GameServerPacket mov)
  802. {
  803. // default implementation
  804. }
  805.  
  806. /** The _in town war. */
  807. private boolean _inTownWar;
  808.  
  809. /**
  810. * Checks if is in town war.
  811. * @return true, if is in town war
  812. */
  813. public final boolean isinTownWar()
  814. {
  815. return _inTownWar;
  816. }
  817.  
  818. /**
  819. * Sets the in town war.
  820. * @param value the new in town war
  821. */
  822. public final void setInTownWar(final boolean value)
  823. {
  824. _inTownWar = value;
  825. }
  826.  
  827. /*
  828. * public void teleToLocation(int x, int y, int z, boolean allowRandomOffset) { if(Config.TW_DISABLE_GK) { int x1,y1,z1; x1 = getX(); y1 = getY(); z1 = getZ(); L2TownZone Town; Town = TownManager.getInstance().getTown(x1,y1,z1); if(Town != null && isinTownWar() ) { if(Town.getTownId() ==
  829. * Config.TW_TOWN_ID && !Config.TW_ALL_TOWNS) { return; } else if(Config.TW_ALL_TOWNS) { return; } } } // Stop movement stopMove(null, false); abortAttack(); abortCast(); setIsTeleporting(true); setTarget(null); // Remove from world regions zones if(getWorldRegion() != null) {
  830. * getWorldRegion().removeFromZones(this); } getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE); if(Config.RESPAWN_RANDOM_ENABLED && allowRandomOffset) { x += Rnd.get(-Config.RESPAWN_RANDOM_MAX_OFFSET, Config.RESPAWN_RANDOM_MAX_OFFSET); y += Rnd.get(-Config.RESPAWN_RANDOM_MAX_OFFSET,
  831. * Config.RESPAWN_RANDOM_MAX_OFFSET); } //z = GeoData.getInstance().getHeight(x, y, z); z += 5; if(Config.DEBUG) { LOGGER.fine("Teleporting to: " + x + ", " + y + ", " + z); } // Send a Server->Client packet TeleportToLocationt to the L2Character AND to all L2PcInstance in the _KnownPlayers of
  832. * the L2Character broadcastPacket(new TeleportToLocation(this, x, y, z)); // Set the x,y,z position of the L2Object and if necessary modify its _worldRegion getPosition().setXYZ(x, y, z); decayMe(); // Set the x, y, z coords of the object, but do not update it's world region yet -
  833. * onTeleported() will do it getPosition().setWorldPosition(x, y, z); if(!(this instanceof L2PcInstance)) { onTeleported(); } }
  834. */
  835.  
  836. /**
  837. * Teleport a L2Character and its pet if necessary.<BR>
  838. * <BR>
  839. * <B><U> Actions</U> :</B><BR>
  840. * <BR>
  841. * <li>Stop the movement of the L2Character</li> <li>Set the x,y,z position of the L2Object and if necessary modify its _worldRegion</li> <li>Send a Server->Client packet TeleportToLocationt to the L2Character AND to all L2PcInstance in its _KnownPlayers</li> <li>Modify the position of the pet
  842. * if necessary</li><BR>
  843. * <BR>
  844. * @param x the x
  845. * @param y the y
  846. * @param z the z
  847. * @param allowRandomOffset the allow random offset
  848. */
  849. public void teleToLocation(int x, int y, int z, final boolean allowRandomOffset)
  850. {
  851. if (Config.TW_DISABLE_GK)
  852. {
  853. int x1, y1, z1;
  854. x1 = getX();
  855. y1 = getY();
  856. z1 = getZ();
  857. L2TownZone Town;
  858. Town = TownManager.getInstance().getTown(x1, y1, z1);
  859. if (Town != null && isinTownWar())
  860. {
  861. if (Town.getTownId() == Config.TW_TOWN_ID && !Config.TW_ALL_TOWNS)
  862. {
  863. return;
  864. }
  865. else if (Config.TW_ALL_TOWNS)
  866. {
  867. return;
  868. }
  869. }
  870. }
  871.  
  872. // Stop movement
  873. stopMove(null, false);
  874. abortAttack();
  875. abortCast();
  876.  
  877. setIsTeleporting(true);
  878. setTarget(null);
  879.  
  880. // Remove from world regions zones
  881. final L2WorldRegion region = getWorldRegion();
  882. if (region != null)
  883. region.removeFromZones(this);
  884.  
  885. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  886.  
  887. if (Config.RESPAWN_RANDOM_ENABLED && allowRandomOffset)
  888. {
  889. x += Rnd.get(-Config.RESPAWN_RANDOM_MAX_OFFSET, Config.RESPAWN_RANDOM_MAX_OFFSET);
  890. y += Rnd.get(-Config.RESPAWN_RANDOM_MAX_OFFSET, Config.RESPAWN_RANDOM_MAX_OFFSET);
  891. }
  892.  
  893. z += 5;
  894.  
  895. if (Config.DEBUG)
  896. LOGGER.debug("Teleporting to: " + x + ", " + y + ", " + z);
  897.  
  898. // Send a Server->Client packet TeleportToLocationt to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  899. broadcastPacket(new TeleportToLocation(this, x, y, z));
  900.  
  901. // remove the object from its old location
  902. decayMe();
  903.  
  904. // Set the x,y,z position of the L2Object and if necessary modify its _worldRegion
  905. getPosition().setXYZ(x, y, z);
  906.  
  907. // if (!(this instanceof L2PcInstance) || (((L2PcInstance)this).isOffline()))/*.getClient() != null && ((L2PcInstance)this).getClient().isDetached()))*/
  908. if (!(this instanceof L2PcInstance))
  909. onTeleported();
  910.  
  911. revalidateZone(true);
  912. }
  913.  
  914. /** The _zone validate counter. */
  915. protected byte _zoneValidateCounter = 4;
  916.  
  917. /**
  918. * Revalidate zone.
  919. * @param force the force
  920. */
  921. public void revalidateZone(final boolean force)
  922. {
  923. final L2WorldRegion region = getWorldRegion();
  924. if (region == null)
  925. return;
  926.  
  927. // This function is called too often from movement code
  928. if (force)
  929. _zoneValidateCounter = 4;
  930. else
  931. {
  932. _zoneValidateCounter--;
  933. if (_zoneValidateCounter < 0)
  934. _zoneValidateCounter = 4;
  935. else
  936. return;
  937. }
  938. region.revalidateZones(this);
  939. }
  940.  
  941. /**
  942. * Tele to location.
  943. * @param x the x
  944. * @param y the y
  945. * @param z the z
  946. */
  947. public void teleToLocation(final int x, final int y, final int z)
  948. {
  949. teleToLocation(x, y, z, false);
  950. }
  951.  
  952. /**
  953. * Tele to location.
  954. * @param loc the loc
  955. * @param allowRandomOffset the allow random offset
  956. */
  957. public void teleToLocation(final Location loc, final boolean allowRandomOffset)
  958. {
  959. int x = loc.getX();
  960. int y = loc.getY();
  961. int z = loc.getZ();
  962.  
  963. if (this instanceof L2PcInstance && DimensionalRiftManager.getInstance().checkIfInRiftZone(getX(), getY(), getZ(), true))
  964. { // true -> ignore waiting room :)
  965. L2PcInstance player = (L2PcInstance) this;
  966. player.sendMessage("You have been sent to the waiting room.");
  967.  
  968. if (player.isInParty() && player.getParty().isInDimensionalRift())
  969. {
  970. player.getParty().getDimensionalRift().usedTeleport(player);
  971. }
  972.  
  973. final int[] newCoords = DimensionalRiftManager.getInstance().getRoom((byte) 0, (byte) 0).getTeleportCoords();
  974.  
  975. x = newCoords[0];
  976. y = newCoords[1];
  977. z = newCoords[2];
  978.  
  979. player = null;
  980. }
  981. teleToLocation(x, y, z, allowRandomOffset);
  982. }
  983.  
  984. /**
  985. * Tele to location.
  986. * @param teleportWhere the teleport where
  987. */
  988. public void teleToLocation(final TeleportWhereType teleportWhere)
  989. {
  990. teleToLocation(MapRegionTable.getInstance().getTeleToLocation(this, teleportWhere), true);
  991. }
  992.  
  993. /*
  994. * // Fall Damage public void Falling(int fallHeight) { if(isDead() || isFlying() || isInvul() || (this instanceof L2PcInstance && isInFunEvent())) return; final int maxHp = getMaxHp(); final int curHp = (int) getCurrentHp(); final int damage = (int) calcStat(Stats.FALL, maxHp / 1000 *
  995. * fallHeight, null, null); if(curHp - damage < 1) setCurrentHp(1); else setCurrentHp(curHp - damage); sendPacket(new SystemMessage(SystemMessageId.FALL_DAMAGE_S1).addNumber(damage)); //YOU_RECEIVED_S1_DAMAGE_FROM_TAKING_A_HIGH_FALL }
  996. */
  997.  
  998. // =========================================================
  999. // Method - Private
  1000. /**
  1001. * Launch a physical attack against a target (Simple, Bow, Pole or Dual).<BR>
  1002. * <BR>
  1003. * <B><U> Actions</U> :</B><BR>
  1004. * <BR>
  1005. * <li>Get the active weapon (always equiped in the right hand)</li><BR>
  1006. * <BR>
  1007. * <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> <li>If weapon is a bow, consume MP and set the new period of bow non re-use</li><BR>
  1008. * <BR>
  1009. * <li>Get the Attack Speed of the L2Character (delay (in milliseconds) before next attack)</li> <li>Select the type of attack to start (Simple, Bow, Pole or Dual) and verify if SoulShot are charged then start calculation</li> <li>If the Server->Client packet Attack contains at least 1 hit, send
  1010. * the Server->Client packet Attack to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character</li> <li>Notify AI with EVT_READY_TO_ACT</li><BR>
  1011. * <BR>
  1012. * @param target The L2Character targeted
  1013. */
  1014. protected void doAttack(final L2Character target)
  1015. {
  1016. if (Config.DEBUG)
  1017. {
  1018. LOGGER.debug(getName() + " doAttack: target=" + target);
  1019. }
  1020.  
  1021. if (target == null)
  1022. return;
  1023.  
  1024. // Like L2OFF wait that the hit task finish and then player can move
  1025. if (this instanceof L2PcInstance && ((L2PcInstance) this).isMovingTaskDefined() && !((L2PcInstance) this).isAttackingNow())
  1026. {
  1027. final L2ItemInstance rhand = ((L2PcInstance) this).getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  1028. if ((rhand != null && rhand.getItemType() != L2WeaponType.BOW) || (rhand == null))
  1029. {
  1030. ((L2PcInstance) this).startMovingTask();
  1031. return;
  1032. }
  1033. }
  1034.  
  1035. if (isAlikeDead())
  1036. {
  1037. // If L2PcInstance is dead or the target is dead, the action is stoped
  1038. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1039.  
  1040. sendPacket(ActionFailed.STATIC_PACKET);
  1041. return;
  1042. }
  1043.  
  1044. if (this instanceof L2NpcInstance && target.isAlikeDead())
  1045. {
  1046. // If L2PcInstance is dead or the target is dead, the action is stoped
  1047. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1048.  
  1049. sendPacket(ActionFailed.STATIC_PACKET);
  1050. return;
  1051. }
  1052.  
  1053. if (this instanceof L2PcInstance && target.isDead() && !target.isFakeDeath())
  1054. {
  1055. // If L2PcInstance is dead or the target is dead, the action is stoped
  1056. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1057.  
  1058. sendPacket(ActionFailed.STATIC_PACKET);
  1059. return;
  1060. }
  1061.  
  1062. if (!getKnownList().knowsObject(target))
  1063. {
  1064. // If L2PcInstance is dead or the target is dead, the action is stoped
  1065. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1066.  
  1067. sendPacket(ActionFailed.STATIC_PACKET);
  1068. return;
  1069. }
  1070.  
  1071. if (this instanceof L2PcInstance && isDead())
  1072. {
  1073. // If L2PcInstance is dead or the target is dead, the action is stoped
  1074. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1075.  
  1076. sendPacket(ActionFailed.STATIC_PACKET);
  1077. return;
  1078. }
  1079.  
  1080. if (target instanceof L2PcInstance && ((L2PcInstance) target).getDuelState() == Duel.DUELSTATE_DEAD)
  1081. {
  1082. // If L2PcInstance is dead or the target is dead, the action is stoped
  1083. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1084.  
  1085. sendPacket(ActionFailed.STATIC_PACKET);
  1086. return;
  1087. }
  1088.  
  1089. if (target instanceof L2DoorInstance && !((L2DoorInstance) target).isAttackable(this))
  1090. return;
  1091.  
  1092. if (isAttackingDisabled())
  1093. return;
  1094.  
  1095. if (this instanceof L2PcInstance)
  1096. {
  1097. if (((L2PcInstance) this).inObserverMode())
  1098. {
  1099. sendPacket(new SystemMessage(SystemMessageId.OBSERVERS_CANNOT_PARTICIPATE));
  1100. sendPacket(ActionFailed.STATIC_PACKET);
  1101. return;
  1102. }
  1103.  
  1104. if (target instanceof L2PcInstance)
  1105. {
  1106. if (((L2PcInstance) target).isCursedWeaponEquiped() && ((L2PcInstance) this).getLevel() <= Config.MAX_LEVEL_NEWBIE)
  1107. {
  1108. ((L2PcInstance) this).sendMessage("Can't attack a cursed player when under level 21.");
  1109. sendPacket(ActionFailed.STATIC_PACKET);
  1110. return;
  1111. }
  1112.  
  1113. if (((L2PcInstance) this).isCursedWeaponEquiped() && ((L2PcInstance) target).getLevel() <= Config.MAX_LEVEL_NEWBIE)
  1114. {
  1115. ((L2PcInstance) this).sendMessage("Can't attack a newbie player using a cursed weapon.");
  1116. sendPacket(ActionFailed.STATIC_PACKET);
  1117. return;
  1118. }
  1119. }
  1120.  
  1121. // thank l2dot
  1122. if (getObjectId() == target.getObjectId())
  1123. {
  1124. sendPacket(ActionFailed.STATIC_PACKET);
  1125. return;
  1126. }
  1127.  
  1128. if (target instanceof L2NpcInstance && Config.DISABLE_ATTACK_NPC_TYPE)
  1129. {
  1130. final String mobtype = ((L2NpcInstance) target).getTemplate().type;
  1131. if (!Config.LIST_ALLOWED_NPC_TYPES.contains(mobtype))
  1132. {
  1133. final SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2);
  1134. sm.addString("Npc Type " + mobtype + " has Protection - No Attack Allowed!");
  1135. ((L2PcInstance) this).sendPacket(sm);
  1136. ((L2PcInstance) this).sendPacket(ActionFailed.STATIC_PACKET);
  1137. return;
  1138. }
  1139. }
  1140. }
  1141.  
  1142. // Get the active weapon instance (always equiped in the right hand)
  1143. L2ItemInstance weaponInst = getActiveWeaponInstance();
  1144.  
  1145. // Get the active weapon item corresponding to the active weapon instance (always equiped in the right hand)
  1146. L2Weapon weaponItem = getActiveWeaponItem();
  1147.  
  1148. if (weaponItem != null && weaponItem.getItemType() == L2WeaponType.ROD)
  1149. {
  1150. // You can't make an attack with a fishing pole.
  1151. ((L2PcInstance) this).sendPacket(new SystemMessage(SystemMessageId.CANNOT_ATTACK_WITH_FISHING_POLE));
  1152. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1153.  
  1154. sendPacket(ActionFailed.STATIC_PACKET);
  1155. return;
  1156. }
  1157.  
  1158. /*
  1159. * TEMPFIX: Check client Z coordinate instead of server z to avoid exploit killing Zaken from others floor
  1160. */
  1161. if ((target instanceof L2GrandBossInstance) && ((L2GrandBossInstance) target).getNpcId() == 29022)
  1162. {
  1163. if (Math.abs(this.getClientZ() - target.getZ()) > 200)
  1164. {
  1165. sendPacket(new SystemMessage(SystemMessageId.CANT_SEE_TARGET));
  1166. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1167. sendPacket(ActionFailed.STATIC_PACKET);
  1168. return;
  1169. }
  1170. }
  1171.  
  1172. // GeoData Los Check here (or dz > 1000)
  1173. if (!GeoData.getInstance().canSeeTarget(this, target))
  1174. {
  1175. sendPacket(new SystemMessage(SystemMessageId.CANT_SEE_TARGET));
  1176. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1177. sendPacket(ActionFailed.STATIC_PACKET);
  1178. return;
  1179. }
  1180.  
  1181. // Check for a bow
  1182. if (weaponItem != null && weaponItem.getItemType() == L2WeaponType.BOW)
  1183. {
  1184. // Equip arrows needed in left hand and send a Server->Client packet ItemList to the L2PcINstance then return True
  1185. if (!checkAndEquipArrows())
  1186. {
  1187. // Cancel the action because the L2PcInstance have no arrow
  1188. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1189.  
  1190. sendPacket(ActionFailed.STATIC_PACKET);
  1191. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ARROWS));
  1192. return;
  1193. }
  1194.  
  1195. // Check for arrows and MP
  1196. if (this instanceof L2PcInstance)
  1197. {
  1198. // Checking if target has moved to peace zone - only for player-bow attacks at the moment
  1199. // Other melee is checked in movement code and for offensive spells a check is done every time
  1200. if (target.isInsidePeaceZone((L2PcInstance) this))
  1201. {
  1202. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1203. sendPacket(ActionFailed.STATIC_PACKET);
  1204. return;
  1205. }
  1206.  
  1207. // Verify if the bow can be use
  1208. if (_disableBowAttackEndTime <= GameTimeController.getGameTicks())
  1209. {
  1210. // Verify if L2PcInstance owns enough MP
  1211. final int saMpConsume = (int) getStat().calcStat(Stats.MP_CONSUME, 0, null, null);
  1212. final int mpConsume = saMpConsume == 0 ? weaponItem.getMpConsume() : saMpConsume;
  1213.  
  1214. if (getCurrentMp() < mpConsume)
  1215. {
  1216. // If L2PcInstance doesn't have enough MP, stop the attack
  1217. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
  1218.  
  1219. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_MP));
  1220. sendPacket(ActionFailed.STATIC_PACKET);
  1221. return;
  1222. }
  1223. // If L2PcInstance have enough MP, the bow consummes it
  1224. getStatus().reduceMp(mpConsume);
  1225.  
  1226. // Set the period of bow non re-use
  1227. _disableBowAttackEndTime = 5 * GameTimeController.TICKS_PER_SECOND + GameTimeController.getGameTicks();
  1228. }
  1229. else
  1230. {
  1231. // Cancel the action because the bow can't be re-use at this moment
  1232. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
  1233.  
  1234. sendPacket(ActionFailed.STATIC_PACKET);
  1235. return;
  1236. }
  1237.  
  1238. }
  1239. else if (this instanceof L2NpcInstance)
  1240. {
  1241. if (_disableBowAttackEndTime > GameTimeController.getGameTicks())
  1242. return;
  1243. }
  1244. }
  1245.  
  1246. // Add the L2PcInstance to _knownObjects and _knownPlayer of the target
  1247. target.getKnownList().addKnownObject(this);
  1248.  
  1249. // Reduce the current CP if TIREDNESS configuration is activated
  1250. if (Config.ALT_GAME_TIREDNESS)
  1251. {
  1252. setCurrentCp(getCurrentCp() - 10);
  1253. }
  1254.  
  1255. final int timeAtk = calculateTimeBetweenAttacks(target, weaponItem);
  1256.  
  1257. // Recharge any active auto soulshot tasks for player (or player's summon if one exists).
  1258. if (this instanceof L2PcInstance)
  1259. {
  1260. ((L2PcInstance) this).rechargeAutoSoulShot(true, false, false, timeAtk);
  1261. }
  1262. else if (this instanceof L2Summon)
  1263. {
  1264. ((L2Summon) this).getOwner().rechargeAutoSoulShot(true, false, true, timeAtk);
  1265. }
  1266.  
  1267. // Verify if soulshots are charged.
  1268. boolean wasSSCharged;
  1269.  
  1270. if (this instanceof L2Summon && !(this instanceof L2PetInstance))
  1271. {
  1272. wasSSCharged = ((L2Summon) this).getChargedSoulShot() != L2ItemInstance.CHARGED_NONE;
  1273. }
  1274. else
  1275. {
  1276. wasSSCharged = weaponInst != null && weaponInst.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE;
  1277. }
  1278.  
  1279. // Get the Attack Speed of the L2Character (delay (in milliseconds) before next attack)
  1280. // the hit is calculated to happen halfway to the animation - might need further tuning e.g. in bow case
  1281. final int timeToHit = timeAtk / 2;
  1282. _attackEndTime = GameTimeController.getGameTicks();
  1283. _attackEndTime += (timeAtk / GameTimeController.MILLIS_IN_TICK);
  1284. _attackEndTime -= 1;
  1285.  
  1286. int ssGrade = 0;
  1287.  
  1288. if (weaponItem != null)
  1289. {
  1290. ssGrade = weaponItem.getCrystalType();
  1291. }
  1292.  
  1293. // Create a Server->Client packet Attack
  1294. Attack attack = new Attack(this, wasSSCharged, ssGrade);
  1295.  
  1296. boolean hitted;
  1297.  
  1298. // Set the Attacking Body part to CHEST
  1299. setAttackingBodypart();
  1300.  
  1301. // Heading calculation on every attack
  1302. this.setHeading(Util.calculateHeadingFrom(this.getX(), this.getY(), target.getX(), target.getY()));
  1303.  
  1304. // Get the Attack Reuse Delay of the L2Weapon
  1305. final int reuse = calculateReuseTime(target, weaponItem);
  1306.  
  1307. // Select the type of attack to start
  1308. if (weaponItem == null)
  1309. {
  1310. hitted = doAttackHitSimple(attack, target, timeToHit);
  1311. }
  1312. else if (weaponItem.getItemType() == L2WeaponType.BOW)
  1313. {
  1314. hitted = doAttackHitByBow(attack, target, timeAtk, reuse);
  1315. }
  1316. else if (weaponItem.getItemType() == L2WeaponType.POLE)
  1317. {
  1318. hitted = doAttackHitByPole(attack, timeToHit);
  1319. }
  1320. else if (isUsingDualWeapon())
  1321. {
  1322. hitted = doAttackHitByDual(attack, target, timeToHit);
  1323. }
  1324. else
  1325. {
  1326. hitted = doAttackHitSimple(attack, target, timeToHit);
  1327. }
  1328.  
  1329. // Flag the attacker if it's a L2PcInstance outside a PvP area
  1330. L2PcInstance player = null;
  1331.  
  1332. if (this instanceof L2PcInstance)
  1333. {
  1334. player = (L2PcInstance) this;
  1335. }
  1336. else if (this instanceof L2Summon)
  1337. {
  1338. player = ((L2Summon) this).getOwner();
  1339. }
  1340.  
  1341. if (player != null)
  1342. {
  1343. player.updatePvPStatus(target);
  1344. }
  1345.  
  1346. // Check if hit isn't missed
  1347. if (!hitted)
  1348. {
  1349. // MAJAX fix
  1350. sendPacket(new SystemMessage(SystemMessageId.MISSED_TARGET));
  1351. // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  1352. abortAttack();
  1353. }
  1354. else
  1355. {
  1356. /*
  1357. * ADDED BY nexus - 2006-08-17 As soon as we know that our hit landed, we must discharge any active soulshots. This must be done so to avoid unwanted soulshot consumption.
  1358. */
  1359.  
  1360. // If we didn't miss the hit, discharge the shoulshots, if any
  1361. if (this instanceof L2Summon && !(this instanceof L2PetInstance))
  1362. {
  1363. ((L2Summon) this).setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
  1364. }
  1365. else if (weaponInst != null)
  1366. {
  1367. weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  1368. }
  1369.  
  1370. if (player != null)
  1371. {
  1372. if (player.isCursedWeaponEquiped())
  1373. {
  1374. // If hitted by a cursed weapon, Cp is reduced to 0
  1375. if (!target.isInvul())
  1376. {
  1377. target.setCurrentCp(0);
  1378. }
  1379. }
  1380. else if (player.isHero())
  1381. {
  1382. if (target instanceof L2PcInstance && ((L2PcInstance) target).isCursedWeaponEquiped())
  1383. {
  1384. // If a cursed weapon is hitted by a Hero, Cp is reduced to 0
  1385. target.setCurrentCp(0);
  1386. }
  1387. }
  1388. }
  1389.  
  1390. weaponInst = null;
  1391. weaponItem = null;
  1392. }
  1393.  
  1394. // If the Server->Client packet Attack contains at least 1 hit, send the Server->Client packet Attack
  1395. // to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  1396. if (attack.hasHits())
  1397. {
  1398. broadcastPacket(attack);
  1399. fireEvent(EventType.ATTACK.name, new Object[]
  1400. {
  1401. getTarget()
  1402. });
  1403. }
  1404.  
  1405. // Like L2OFF mobs id 27181 can teleport players near cabrio
  1406. if (this instanceof L2MonsterInstance && ((L2MonsterInstance) this).getNpcId() == 27181)
  1407. {
  1408. final int rndNum = Rnd.get(100);
  1409. final L2PcInstance gettarget = (L2PcInstance) this.getTarget();
  1410.  
  1411. if (rndNum < 5 && gettarget != null)
  1412. gettarget.teleToLocation(179768, 6364, -2734);
  1413. }
  1414.  
  1415. // Like L2OFF if target is not auto attackable you give only one hit
  1416. if (this instanceof L2PcInstance && target instanceof L2PcInstance && !target.isAutoAttackable(this))
  1417. {
  1418. ((L2PcInstance) this).getAI().clientStopAutoAttack();
  1419. ((L2PcInstance) this).getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, this);
  1420. }
  1421.  
  1422. // Notify AI with EVT_READY_TO_ACT
  1423. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), timeAtk + reuse);
  1424.  
  1425. attack = null;
  1426. player = null;
  1427. }
  1428.  
  1429. /**
  1430. * Launch a Bow attack.<BR>
  1431. * <BR>
  1432. * <B><U> Actions</U> :</B><BR>
  1433. * <BR>
  1434. * <li>Calculate if hit is missed or not</li> <li>Consumme arrows</li> <li>If hit isn't missed, calculate if shield defense is efficient</li> <li>If hit isn't missed, calculate if hit is critical</li> <li>If hit isn't missed, calculate physical damages</li> <li>If the L2Character is a
  1435. * L2PcInstance, Send a Server->Client packet SetupGauge</li> <li>Create a new hit task with Medium priority</li> <li>Calculate and set the disable delay of the bow in function of the Attack Speed</li> <li>Add this hit to the Server-Client packet Attack</li><BR>
  1436. * <BR>
  1437. * @param attack Server->Client packet Attack in which the hit will be added
  1438. * @param target The L2Character targeted
  1439. * @param sAtk The Attack Speed of the attacker
  1440. * @param reuse the reuse
  1441. * @return True if the hit isn't missed
  1442. */
  1443. private boolean doAttackHitByBow(final Attack attack, final L2Character target, final int sAtk, final int reuse)
  1444. {
  1445. int damage1 = 0;
  1446. boolean shld1 = false;
  1447. boolean crit1 = false;
  1448.  
  1449. // Calculate if hit is missed or not
  1450. final boolean miss1 = Formulas.calcHitMiss(this, target);
  1451.  
  1452. // Consumme arrows
  1453. reduceArrowCount();
  1454.  
  1455. _move = null;
  1456.  
  1457. // Check if hit isn't missed
  1458. if (!miss1)
  1459. {
  1460. // Calculate if shield defense is efficient
  1461. shld1 = Formulas.calcShldUse(this, target);
  1462.  
  1463. // Calculate if hit is critical
  1464. crit1 = Formulas.calcCrit(getStat().getCriticalHit(target, null));
  1465.  
  1466. // Calculate physical damages
  1467. damage1 = (int) Formulas.calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
  1468. }
  1469.  
  1470. // Check if the L2Character is a L2PcInstance
  1471. if (this instanceof L2PcInstance)
  1472. {
  1473. // Send a system message
  1474. sendPacket(new SystemMessage(SystemMessageId.GETTING_READY_TO_SHOOT_AN_ARROW));
  1475.  
  1476. // Send a Server->Client packet SetupGauge
  1477. SetupGauge sg = new SetupGauge(SetupGauge.RED, sAtk + reuse);
  1478. sendPacket(sg);
  1479. sg = null;
  1480. }
  1481.  
  1482. // Create a new hit task with Medium priority
  1483. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
  1484.  
  1485. // Calculate and set the disable delay of the bow in function of the Attack Speed
  1486. _disableBowAttackEndTime = (sAtk + reuse) / GameTimeController.MILLIS_IN_TICK + GameTimeController.getGameTicks();
  1487.  
  1488. // Add this hit to the Server-Client packet Attack
  1489. attack.addHit(target, damage1, miss1, crit1, shld1);
  1490.  
  1491. // Return true if hit isn't missed
  1492. return !miss1;
  1493. }
  1494.  
  1495. /**
  1496. * Launch a Dual attack.<BR>
  1497. * <BR>
  1498. * <B><U> Actions</U> :</B><BR>
  1499. * <BR>
  1500. * <li>Calculate if hits are missed or not</li> <li>If hits aren't missed, calculate if shield defense is efficient</li> <li>If hits aren't missed, calculate if hit is critical</li> <li>If hits aren't missed, calculate physical damages</li> <li>Create 2 new hit tasks with Medium priority</li>
  1501. * <li>Add those hits to the Server-Client packet Attack</li><BR>
  1502. * <BR>
  1503. * @param attack Server->Client packet Attack in which the hit will be added
  1504. * @param target The L2Character targeted
  1505. * @param sAtk the s atk
  1506. * @return True if hit 1 or hit 2 isn't missed
  1507. */
  1508. private boolean doAttackHitByDual(final Attack attack, final L2Character target, final int sAtk)
  1509. {
  1510. int damage1 = 0;
  1511. int damage2 = 0;
  1512. boolean shld1 = false;
  1513. boolean shld2 = false;
  1514. boolean crit1 = false;
  1515. boolean crit2 = false;
  1516.  
  1517. // Calculate if hits are missed or not
  1518. final boolean miss1 = Formulas.calcHitMiss(this, target);
  1519. final boolean miss2 = Formulas.calcHitMiss(this, target);
  1520.  
  1521. // Check if hit 1 isn't missed
  1522. if (!miss1)
  1523. {
  1524. // Calculate if shield defense is efficient against hit 1
  1525. shld1 = Formulas.calcShldUse(this, target);
  1526.  
  1527. // Calculate if hit 1 is critical
  1528. crit1 = Formulas.calcCrit(getStat().getCriticalHit(target, null));
  1529.  
  1530. // Calculate physical damages of hit 1
  1531. damage1 = (int) Formulas.calcPhysDam(this, target, null, shld1, crit1, true, attack.soulshot);
  1532. damage1 /= 2;
  1533. }
  1534.  
  1535. // Check if hit 2 isn't missed
  1536. if (!miss2)
  1537. {
  1538. // Calculate if shield defense is efficient against hit 2
  1539. shld2 = Formulas.calcShldUse(this, target);
  1540.  
  1541. // Calculate if hit 2 is critical
  1542. crit2 = Formulas.calcCrit(getStat().getCriticalHit(target, null));
  1543.  
  1544. // Calculate physical damages of hit 2
  1545. damage2 = (int) Formulas.calcPhysDam(this, target, null, shld2, crit2, true, attack.soulshot);
  1546. damage2 /= 2;
  1547. }
  1548.  
  1549. // Create a new hit task with Medium priority for hit 1
  1550. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk / 2);
  1551.  
  1552. // Create a new hit task with Medium priority for hit 2 with a higher delay
  1553. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage2, crit2, miss2, attack.soulshot, shld2), sAtk);
  1554.  
  1555. // Add those hits to the Server-Client packet Attack
  1556. attack.addHit(target, damage1, miss1, crit1, shld1);
  1557. attack.addHit(target, damage2, miss2, crit2, shld2);
  1558.  
  1559. // Return true if hit 1 or hit 2 isn't missed
  1560. return !miss1 || !miss2;
  1561. }
  1562.  
  1563. /**
  1564. * Launch a Pole attack.<BR>
  1565. * <BR>
  1566. * <B><U> Actions</U> :</B><BR>
  1567. * <BR>
  1568. * <li>Get all visible objects in a spheric area near the L2Character to obtain possible targets</li> <li>If possible target is the L2Character targeted, launch a simple attack against it</li> <li>If possible target isn't the L2Character targeted but is attakable, launch a simple attack against
  1569. * it</li><BR>
  1570. * <BR>
  1571. * @param attack Server->Client packet Attack in which the hit will be added
  1572. * @param sAtk the s atk
  1573. * @return True if one hit isn't missed
  1574. */
  1575. private boolean doAttackHitByPole(final Attack attack, final int sAtk)
  1576. {
  1577. boolean hitted = false;
  1578.  
  1579. double angleChar, angleTarget;
  1580. final int maxRadius = (int) getStat().calcStat(Stats.POWER_ATTACK_RANGE, 66, null, null);
  1581. final int maxAngleDiff = (int) getStat().calcStat(Stats.POWER_ATTACK_ANGLE, 120, null, null);
  1582.  
  1583. if (getTarget() == null)
  1584. return false;
  1585.  
  1586. angleTarget = Util.calculateAngleFrom(this, getTarget());
  1587. setHeading((int) (angleTarget / 9.0 * 1610.0));
  1588.  
  1589. angleChar = Util.convertHeadingToDegree(getHeading());
  1590. double attackpercent = 85;
  1591. final int attackcountmax = (int) getStat().calcStat(Stats.ATTACK_COUNT_MAX, 3, null, null);
  1592. int attackcount = 0;
  1593.  
  1594. if (angleChar <= 0)
  1595. angleChar += 360;
  1596.  
  1597. L2Character target;
  1598. for (final L2Object obj : getKnownList().getKnownObjects().values())
  1599. {
  1600. if (obj instanceof L2Character)
  1601. {
  1602. if (obj instanceof L2PetInstance && this instanceof L2PcInstance && ((L2PetInstance) obj).getOwner() == (L2PcInstance) this)
  1603. {
  1604. continue;
  1605. }
  1606.  
  1607. if (!Util.checkIfInRange(maxRadius, this, obj, false))
  1608. {
  1609. continue;
  1610. }
  1611.  
  1612. if (Math.abs(obj.getZ() - getZ()) > Config.DIFFERENT_Z_CHANGE_OBJECT)
  1613. {
  1614. continue;
  1615. }
  1616.  
  1617. angleTarget = Util.calculateAngleFrom(this, obj);
  1618.  
  1619. if (Math.abs(angleChar - angleTarget) > maxAngleDiff && Math.abs(angleChar + 360 - angleTarget) > maxAngleDiff && Math.abs(angleChar - (angleTarget + 360)) > maxAngleDiff)
  1620. {
  1621. continue;
  1622. }
  1623.  
  1624. target = (L2Character) obj;
  1625.  
  1626. if (!target.isAlikeDead())
  1627. {
  1628. attackcount += 1;
  1629.  
  1630. if (attackcount <= attackcountmax)
  1631. {
  1632. if (target == getAI().getAttackTarget() || target.isAutoAttackable(this))
  1633. {
  1634. hitted |= doAttackHitSimple(attack, target, attackpercent, sAtk);
  1635. attackpercent /= 1.15;
  1636.  
  1637. // Flag player if the target is another player
  1638. if (this instanceof L2PcInstance && obj instanceof L2PcInstance)
  1639. ((L2PcInstance) this).updatePvPStatus(target);
  1640. }
  1641. }
  1642. }
  1643. }
  1644. }
  1645. target = null;
  1646. // Return true if one hit isn't missed
  1647. return hitted;
  1648. }
  1649.  
  1650. /**
  1651. * Launch a simple attack.<BR>
  1652. * <BR>
  1653. * <B><U> Actions</U> :</B><BR>
  1654. * <BR>
  1655. * <li>Calculate if hit is missed or not</li> <li>If hit isn't missed, calculate if shield defense is efficient</li> <li>If hit isn't missed, calculate if hit is critical</li> <li>If hit isn't missed, calculate physical damages</li> <li>Create a new hit task with Medium priority</li> <li>Add
  1656. * this hit to the Server-Client packet Attack</li><BR>
  1657. * <BR>
  1658. * @param attack Server->Client packet Attack in which the hit will be added
  1659. * @param target The L2Character targeted
  1660. * @param sAtk the s atk
  1661. * @return True if the hit isn't missed
  1662. */
  1663. private boolean doAttackHitSimple(final Attack attack, final L2Character target, final int sAtk)
  1664. {
  1665. return doAttackHitSimple(attack, target, 100, sAtk);
  1666. }
  1667.  
  1668. /**
  1669. * Do attack hit simple.
  1670. * @param attack the attack
  1671. * @param target the target
  1672. * @param attackpercent the attackpercent
  1673. * @param sAtk the s atk
  1674. * @return true, if successful
  1675. */
  1676. private boolean doAttackHitSimple(final Attack attack, final L2Character target, final double attackpercent, final int sAtk)
  1677. {
  1678. int damage1 = 0;
  1679. boolean shld1 = false;
  1680. boolean crit1 = false;
  1681.  
  1682. // Calculate if hit is missed or not
  1683. final boolean miss1 = Formulas.calcHitMiss(this, target);
  1684.  
  1685. // Check if hit isn't missed
  1686. if (!miss1)
  1687. {
  1688. // Calculate if shield defense is efficient
  1689. shld1 = Formulas.calcShldUse(this, target);
  1690.  
  1691. // Calculate if hit is critical
  1692. crit1 = Formulas.calcCrit(getStat().getCriticalHit(target, null));
  1693.  
  1694. // Calculate physical damages
  1695. damage1 = (int) Formulas.calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
  1696.  
  1697. if (attackpercent != 100)
  1698. {
  1699. damage1 = (int) (damage1 * attackpercent / 100);
  1700. }
  1701. }
  1702.  
  1703. // Create a new hit task with Medium priority
  1704. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
  1705.  
  1706. // Add this hit to the Server-Client packet Attack
  1707. attack.addHit(target, damage1, miss1, crit1, shld1);
  1708.  
  1709. // Return true if hit isn't missed
  1710. return !miss1;
  1711. }
  1712.  
  1713. /**
  1714. * Manage the casting task (casting and interrupt time, re-use delay...) and display the casting bar and animation on client.<BR>
  1715. * <BR>
  1716. * <B><U> Actions</U> :</B><BR>
  1717. * <BR>
  1718. * <li>Verify the possibilty of the the cast : skill is a spell, caster isn't muted...</li> <li>Get the list of all targets (ex : area effects) and define the L2Charcater targeted (its stats will be used in calculation)</li> <li>Calculate the casting time (base + modifier of MAtkSpd), interrupt
  1719. * time and re-use delay</li> <li>Send a Server->Client packet MagicSkillUser (to diplay casting animation), a packet SetupGauge (to display casting bar) and a system message</li> <li>Disable all skills during the casting time (create a task EnableAllSkills)</li> <li>Disable the skill during the
  1720. * re-use delay (create a task EnableSkill)</li> <li>Create a task MagicUseTask (that will call method onMagicUseTimer) to launch the Magic Skill at the end of the casting time</li><BR>
  1721. * <BR>
  1722. * @param skill The L2Skill to use
  1723. */
  1724. public void doCast(final L2Skill skill)
  1725. {
  1726. final L2Character activeChar = this;
  1727.  
  1728. if (skill == null)
  1729. {
  1730. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  1731. return;
  1732. }
  1733.  
  1734. // Check if the skill is a magic spell and if the L2Character is not muted
  1735. if (skill.isMagic() && isMuted() && !skill.isPotion())
  1736. {
  1737. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  1738. return;
  1739. }
  1740.  
  1741. // Check if the skill is psychical and if the L2Character is not psychical_muted
  1742. if (!skill.isMagic() && isPsychicalMuted() && !skill.isPotion())
  1743. {
  1744. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  1745. return;
  1746. }
  1747.  
  1748. // Can't use Hero and resurrect skills during Olympiad
  1749. if (activeChar instanceof L2PcInstance && ((L2PcInstance) activeChar).isInOlympiadMode() && (skill.isHeroSkill() || skill.getSkillType() == SkillType.RESURRECT))
  1750. {
  1751. SystemMessage sm = new SystemMessage(SystemMessageId.THIS_SKILL_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  1752. sendPacket(sm);
  1753. sm = null;
  1754. return;
  1755. }
  1756.  
  1757. // Like L2OFF you can't use skills when you are attacking now
  1758. if (activeChar instanceof L2PcInstance && !skill.isPotion())
  1759. {
  1760. final L2ItemInstance rhand = ((L2PcInstance) this).getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  1761. if ((rhand != null && rhand.getItemType() == L2WeaponType.BOW))
  1762. {
  1763. if (isAttackingNow())
  1764. return;
  1765. }
  1766. }
  1767.  
  1768. // prevent casting signets to peace zone
  1769. if (skill.getSkillType() == SkillType.SIGNET || skill.getSkillType() == SkillType.SIGNET_CASTTIME)
  1770. {
  1771. /*
  1772. * for (L2Effect effect : getAllEffects()) { if (effect.getEffectType() == L2Effect.EffectType.SIGNET_EFFECT || effect.getEffectType() == L2Effect.EffectType.SIGNET_GROUND) { SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED); sm.addSkillName(skill.getId());
  1773. * sendPacket(sm); return; } }
  1774. */
  1775.  
  1776. final L2WorldRegion region = getWorldRegion();
  1777. if (region == null)
  1778. return;
  1779. boolean canCast = true;
  1780. if (skill.getTargetType() == SkillTargetType.TARGET_GROUND && this instanceof L2PcInstance)
  1781. {
  1782. final Point3D wp = ((L2PcInstance) this).getCurrentSkillWorldPosition();
  1783. if (!region.checkEffectRangeInsidePeaceZone(skill, wp.getX(), wp.getY(), wp.getZ()))
  1784. canCast = false;
  1785. }
  1786. else if (!region.checkEffectRangeInsidePeaceZone(skill, getX(), getY(), getZ()))
  1787. canCast = false;
  1788. if (!canCast)
  1789. {
  1790. final SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  1791. sm.addSkillName(skill.getId());
  1792. sendPacket(sm);
  1793. return;
  1794. }
  1795. }
  1796.  
  1797. // Recharge AutoSoulShot
  1798.  
  1799. final int atkTime = Formulas.getInstance().calcMAtkSpd(activeChar, skill, skill.getHitTime());
  1800. if (skill.useSoulShot())
  1801. {
  1802. if (activeChar instanceof L2PcInstance)
  1803. {
  1804. ((L2PcInstance) activeChar).rechargeAutoSoulShot(true, false, false, atkTime);
  1805. }
  1806. else if (this instanceof L2Summon)
  1807. {
  1808. ((L2Summon) activeChar).getOwner().rechargeAutoSoulShot(true, false, true, atkTime);
  1809. }
  1810. }
  1811.  
  1812. // else if (skill.useFishShot())
  1813. // {
  1814. // if (this instanceof L2PcInstance)
  1815. // ((L2PcInstance)this).rechargeAutoSoulShot(true, false, false);
  1816. // }
  1817.  
  1818. // Get all possible targets of the skill in a table in function of the skill target type
  1819. final L2Object[] targets = skill.getTargetList(activeChar);
  1820. // Set the target of the skill in function of Skill Type and Target Type
  1821. L2Character target = null;
  1822.  
  1823. if (skill.getTargetType() == SkillTargetType.TARGET_AURA || skill.getTargetType() == SkillTargetType.TARGET_GROUND || skill.isPotion())
  1824. {
  1825. target = this;
  1826. }
  1827. else if (targets == null || targets.length == 0)
  1828. {
  1829. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  1830. return;
  1831. }
  1832. else if ((skill.getSkillType() == SkillType.BUFF || skill.getSkillType() == SkillType.HEAL || skill.getSkillType() == SkillType.COMBATPOINTHEAL || skill.getSkillType() == SkillType.COMBATPOINTPERCENTHEAL || skill.getSkillType() == SkillType.MANAHEAL || skill.getSkillType() == SkillType.REFLECT || skill.getSkillType() == SkillType.SEED || skill.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF || skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PET || skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY || skill.getTargetType() == L2Skill.SkillTargetType.TARGET_CLAN || skill.getTargetType() == L2Skill.SkillTargetType.TARGET_ALLY) && !skill.isPotion())
  1833. {
  1834. target = (L2Character) targets[0];
  1835.  
  1836. /*
  1837. * if (this instanceof L2PcInstance && target instanceof L2PcInstance && target.getAI().getIntention() == CtrlIntention.AI_INTENTION_ATTACK) { if(skill.getSkillType() == SkillType.BUFF || skill.getSkillType() == SkillType.HOT || skill.getSkillType() == SkillType.HEAL ||
  1838. * skill.getSkillType() == SkillType.HEAL_PERCENT || skill.getSkillType() == SkillType.MANAHEAL || skill.getSkillType() == SkillType.MANAHEAL_PERCENT || skill.getSkillType() == SkillType.BALANCE_LIFE) target.setLastBuffer(this); if (((L2PcInstance)this).isInParty() &&
  1839. * skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY) { for (L2PcInstance member : ((L2PcInstance)this).getParty().getPartyMembers()) member.setLastBuffer(this); } }
  1840. */
  1841. }
  1842. else
  1843. {
  1844. target = (L2Character) getTarget();
  1845. }
  1846.  
  1847. if (target == null)
  1848. {
  1849. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  1850. return;
  1851. }
  1852.  
  1853. // Player can't heal rb config
  1854. if (!Config.PLAYERS_CAN_HEAL_RB && activeChar instanceof L2PcInstance && !((L2PcInstance) activeChar).isGM() && (target instanceof L2RaidBossInstance || target instanceof L2GrandBossInstance) && (skill.getSkillType() == SkillType.HEAL || skill.getSkillType() == SkillType.HEAL_PERCENT))
  1855. {
  1856. this.sendPacket(ActionFailed.STATIC_PACKET);
  1857. return;
  1858. }
  1859.  
  1860. if (activeChar instanceof L2PcInstance && target instanceof L2NpcInstance && Config.DISABLE_ATTACK_NPC_TYPE)
  1861. {
  1862. final String mobtype = ((L2NpcInstance) target).getTemplate().type;
  1863. if (!Config.LIST_ALLOWED_NPC_TYPES.contains(mobtype))
  1864. {
  1865. final SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2);
  1866. sm.addString("Npc Type " + mobtype + " has Protection - No Attack Allowed!");
  1867. ((L2PcInstance) activeChar).sendPacket(sm);
  1868. ((L2PcInstance) activeChar).sendPacket(ActionFailed.STATIC_PACKET);
  1869. return;
  1870. }
  1871. }
  1872.  
  1873. if (skill.isPotion())
  1874. setLastPotionCast(skill);
  1875. else
  1876. setLastSkillCast(skill);
  1877.  
  1878. // Get the Identifier of the skill
  1879. final int magicId = skill.getId();
  1880.  
  1881. // Get the Display Identifier for a skill that client can't display
  1882. final int displayId = skill.getDisplayId();
  1883.  
  1884. // Get the level of the skill
  1885. int level = skill.getLevel();
  1886.  
  1887. if (level < 1)
  1888. {
  1889. level = 1;
  1890. }
  1891.  
  1892. // Get the casting time of the skill (base)
  1893. int hitTime = skill.getHitTime();
  1894. int coolTime = skill.getCoolTime();
  1895. final boolean effectWhileCasting = skill.hasEffectWhileCasting();
  1896.  
  1897. final boolean forceBuff = skill.getSkillType() == SkillType.FORCE_BUFF && target instanceof L2PcInstance;
  1898.  
  1899. // Calculate the casting time of the skill (base + modifier of MAtkSpd)
  1900. // Don't modify the skill time for FORCE_BUFF skills. The skill time for those skills represent the buff time.
  1901. if (!effectWhileCasting && !forceBuff && !skill.isStaticHitTime())
  1902. {
  1903. hitTime = Formulas.getInstance().calcMAtkSpd(activeChar, skill, hitTime);
  1904.  
  1905. if (coolTime > 0)
  1906. {
  1907. coolTime = Formulas.getInstance().calcMAtkSpd(activeChar, skill, coolTime);
  1908. }
  1909. }
  1910.  
  1911. // Calculate altered Cast Speed due to BSpS/SpS only for Magic skills
  1912. if ((checkBss() || checkSps()) && !skill.isStaticHitTime() && !skill.isPotion() && skill.isMagic())
  1913. {
  1914.  
  1915. // Only takes 70% of the time to cast a BSpS/SpS cast
  1916. hitTime = (int) (0.70 * hitTime);
  1917. coolTime = (int) (0.70 * coolTime);
  1918.  
  1919. // Because the following are magic skills that do not actively 'eat' BSpS/SpS,
  1920. // I must 'eat' them here so players don't take advantage of infinite speed increase
  1921. /* MANAHEAL, MANARECHARGE, RESURRECT, RECALL */
  1922. // if (skill.getSkillType() == SkillType.MANAHEAL || skill.getSkillType() == SkillType.MANARECHARGE || skill.getSkillType() == SkillType.RESURRECT || skill.getSkillType() == SkillType.RECALL)
  1923. // {
  1924. // if (checkBss())
  1925. // removeBss();
  1926. // else
  1927. // removeSps();
  1928. // }
  1929.  
  1930. }
  1931.  
  1932. /*
  1933. * // Calculate altered Cast Speed due to BSpS/SpS L2ItemInstance weaponInst = getActiveWeaponInstance(); if(weaponInst != null && skill.isMagic() && !forceBuff && skill.getTargetType() != SkillTargetType.TARGET_SELF && !skill.isStaticHitTime() && !skill.isPotion()) {
  1934. * if(weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT || weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT) { //Only takes 70% of the time to cast a BSpS/SpS cast hitTime = (int) (0.70 * hitTime); coolTime = (int) (0.70 * coolTime);
  1935. * //Because the following are magic skills that do not actively 'eat' BSpS/SpS, //I must 'eat' them here so players don't take advantage of infinite speed increase if(skill.getSkillType() == SkillType.BUFF || skill.getSkillType() == SkillType.MANAHEAL || skill.getSkillType() ==
  1936. * SkillType.RESURRECT || skill.getSkillType() == SkillType.RECALL || skill.getSkillType() == SkillType.DOT) { weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE); } } } weaponInst = null;
  1937. */
  1938.  
  1939. if (skill.isPotion())
  1940. {
  1941. // Set the _castEndTime and _castInterruptTim. +10 ticks for lag situations, will be reseted in onMagicFinalizer
  1942. _castPotionEndTime = 10 + GameTimeController.getGameTicks() + (coolTime + hitTime) / GameTimeController.MILLIS_IN_TICK;
  1943. _castPotionInterruptTime = -2 + GameTimeController.getGameTicks() + hitTime / GameTimeController.MILLIS_IN_TICK;
  1944.  
  1945. }
  1946. else
  1947. {
  1948. // Set the _castEndTime and _castInterruptTim. +10 ticks for lag situations, will be reseted in onMagicFinalizer
  1949. _castEndTime = 10 + GameTimeController.getGameTicks() + (coolTime + hitTime) / GameTimeController.MILLIS_IN_TICK;
  1950. _castInterruptTime = -2 + GameTimeController.getGameTicks() + hitTime / GameTimeController.MILLIS_IN_TICK;
  1951.  
  1952. }
  1953.  
  1954. // Init the reuse time of the skill
  1955. // int reuseDelay = (int)(skill.getReuseDelay() * getStat().getMReuseRate(skill));
  1956. // reuseDelay *= 333.0 / (skill.isMagic() ? getMAtkSpd() : getPAtkSpd());
  1957. int reuseDelay = skill.getReuseDelay();
  1958.  
  1959. if (activeChar instanceof L2PcInstance && Formulas.getInstance().calcSkillMastery(activeChar))
  1960. {
  1961. reuseDelay = 0;
  1962. }
  1963. else if (!skill.isStaticReuse() && !skill.isPotion())
  1964. {
  1965. if (skill.isMagic())
  1966. {
  1967. reuseDelay *= getStat().getMReuseRate(skill);
  1968. }
  1969. else
  1970. {
  1971. reuseDelay *= getStat().getPReuseRate(skill);
  1972. }
  1973.  
  1974. reuseDelay *= 333.0 / (skill.isMagic() ? getMAtkSpd() : getPAtkSpd());
  1975. }
  1976.  
  1977. // To turn local player in target direction
  1978. setHeading(Util.calculateHeadingFrom(getX(), getY(), target.getX(), target.getY()));
  1979.  
  1980. /*
  1981. * if(skill.isOffensive() && skill.getTargetType() != SkillTargetType.TARGET_AURA && target.isBehind(this)) { moveToLocation(target.getX(), target.getY(), target.getZ(), 0); stopMove(null); }
  1982. */
  1983.  
  1984. // Like L2OFF after a skill the player must stop the movement, also with toggle
  1985. if (!skill.isPotion() && this instanceof L2PcInstance)
  1986. ((L2PcInstance) this).stopMove(null);
  1987.  
  1988. // Start the effect as long as the player is casting.
  1989. if (effectWhileCasting)
  1990. {
  1991. callSkill(skill, targets);
  1992. }
  1993.  
  1994. // Send a Server->Client packet MagicSkillUser with target, displayId, level, skillTime, reuseDelay
  1995. // to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  1996. broadcastPacket(new MagicSkillUser(this, target, displayId, level, hitTime, reuseDelay));
  1997.  
  1998. // Send a system message USE_S1 to the L2Character
  1999. if (activeChar instanceof L2PcInstance && magicId != 1312)
  2000. {
  2001. if (skill.isPotion())
  2002. {
  2003. SystemMessage sm = new SystemMessage(SystemMessageId.USE_S1_);
  2004. if (magicId == 2005)
  2005. sm.addItemName(728);
  2006. else if (magicId == 2003)
  2007. sm.addItemName(726);
  2008. // Message greater cp potions like retail
  2009. else if (magicId == 2166 && skill.getLevel() == 2)
  2010. sm.addItemName(5592);
  2011. // Message cp potions like retail
  2012. else if (magicId == 2166 && skill.getLevel() == 1)
  2013. sm.addItemName(5591);
  2014. else
  2015. sm.addSkillName(magicId, skill.getLevel());
  2016. sendPacket(sm);
  2017. sm = null;
  2018. }
  2019. else
  2020. {
  2021. SystemMessage sm = new SystemMessage(SystemMessageId.USE_S1);
  2022. if (magicId == 2005)
  2023. sm.addItemName(728);
  2024. else if (magicId == 2003)
  2025. sm.addItemName(726);
  2026. // Message greater cp potions like retail
  2027. else if (magicId == 2166 && skill.getLevel() == 2)
  2028. sm.addItemName(5592);
  2029. // Message cp potions like retail
  2030. else if (magicId == 2166 && skill.getLevel() == 1)
  2031. sm.addItemName(5591);
  2032. else
  2033. sm.addSkillName(magicId, skill.getLevel());
  2034.  
  2035. // Skill 2046 is used only for animation on pets
  2036. if (magicId != 2046)
  2037. sendPacket(sm);
  2038. sm = null;
  2039. }
  2040. }
  2041.  
  2042. // Skill reuse check
  2043. if (reuseDelay > 30000)
  2044. {
  2045. addTimeStamp(skill, reuseDelay);
  2046. }
  2047.  
  2048. // Check if this skill consume mp on start casting
  2049. final int initmpcons = getStat().getMpInitialConsume(skill);
  2050.  
  2051. if (initmpcons > 0)
  2052. {
  2053. StatusUpdate su = new StatusUpdate(getObjectId());
  2054.  
  2055. if (skill.isDance())
  2056. {
  2057. getStatus().reduceMp(calcStat(Stats.DANCE_MP_CONSUME_RATE, initmpcons, null, null));
  2058. }
  2059. else if (skill.isMagic())
  2060. {
  2061. getStatus().reduceMp(calcStat(Stats.MAGICAL_MP_CONSUME_RATE, initmpcons, null, null));
  2062. }
  2063. else
  2064. {
  2065. getStatus().reduceMp(calcStat(Stats.PHYSICAL_MP_CONSUME_RATE, initmpcons, null, null));
  2066. }
  2067.  
  2068. su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
  2069. sendPacket(su);
  2070. su = null;
  2071. }
  2072.  
  2073. // 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
  2074. if (reuseDelay > 10)
  2075. {
  2076. disableSkill(skill, reuseDelay);
  2077. }
  2078.  
  2079. // For force buff skills, start the effect as long as the player is casting.
  2080. if (forceBuff)
  2081. {
  2082. startForceBuff(target, skill);
  2083. }
  2084.  
  2085. // launch the magic in hitTime milliseconds
  2086. if (hitTime > 210)
  2087. {
  2088. // Send a Server->Client packet SetupGauge with the color of the gauge and the casting time
  2089. if (activeChar instanceof L2PcInstance && !forceBuff)
  2090. {
  2091. SetupGauge sg = new SetupGauge(SetupGauge.BLUE, hitTime);
  2092. sendPacket(sg);
  2093. sg = null;
  2094. }
  2095.  
  2096. // Disable all skills during the casting
  2097. if (!skill.isPotion())
  2098. { // for particular potion is the timestamp to disable particular skill
  2099.  
  2100. disableAllSkills();
  2101.  
  2102. if (_skillCast != null) // delete previous skill cast
  2103. {
  2104. _skillCast.cancel(true);
  2105. _skillCast = null;
  2106. }
  2107.  
  2108. }
  2109.  
  2110. // Create a task MagicUseTask to launch the MagicSkill at the end of the casting time (hitTime)
  2111. // For client animation reasons (party buffs especially) 200 ms before!
  2112. if (getForceBuff() != null || effectWhileCasting)
  2113. {
  2114. if (skill.isPotion())
  2115. _potionCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 2), hitTime);
  2116.  
  2117. else
  2118. _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 2), hitTime);
  2119. }
  2120. else
  2121. {
  2122. if (skill.isPotion())
  2123. _potionCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 1), hitTime - 200);
  2124.  
  2125. else
  2126. _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 1), hitTime - 200);
  2127. }
  2128. }
  2129. else
  2130. {
  2131. onMagicLaunchedTimer(targets, skill, coolTime, true);
  2132. }
  2133. fireEvent(EventType.CAST.name, new Object[]
  2134. {
  2135. skill,
  2136. target,
  2137. targets
  2138. });
  2139.  
  2140. }
  2141.  
  2142. /**
  2143. * Index according to skill id the current timestamp of use.<br>
  2144. * @param skill the s
  2145. * @param r the r
  2146. */
  2147. public void addTimeStamp(final L2Skill skill, final int r)
  2148. {
  2149.  
  2150. }
  2151.  
  2152. /**
  2153. * Index according to skill id the current timestamp of use.<br>
  2154. * @param _skill the s
  2155. */
  2156. public void removeTimeStamp(final L2Skill _skill)
  2157. {
  2158.  
  2159. }
  2160.  
  2161. /**
  2162. * Starts a force buff on target.<br>
  2163. * @param target the target
  2164. * @param skill the skill
  2165. */
  2166. public void startForceBuff(final L2Character target, final L2Skill skill)
  2167. {
  2168. if (skill.getSkillType() != SkillType.FORCE_BUFF)
  2169. return;
  2170.  
  2171. if (_forceBuff == null)
  2172. {
  2173. _forceBuff = new ForceBuff(this, target, skill);
  2174. }
  2175. }
  2176.  
  2177. /**
  2178. * Kill the L2Character.<BR>
  2179. * <BR>
  2180. * <B><U> Actions</U> :</B><BR>
  2181. * <BR>
  2182. * <li>Set target to null and cancel Attack or Cast</li> <li>Stop movement</li> <li>Stop HP/MP/CP Regeneration task</li> <li>Stop all active skills effects in progress on the L2Character</li> <li>Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to
  2183. * inform</li> <li>Notify L2Character AI</li><BR>
  2184. * <BR>
  2185. * <B><U> Overriden in </U> :</B><BR>
  2186. * <BR>
  2187. * <li>L2NpcInstance : Create a DecayTask to remove the corpse of the L2NpcInstance after 7 seconds</li> <li>L2Attackable : Distribute rewards (EXP, SP, Drops...) and notify Quest Engine</li> <li>L2PcInstance : Apply Death Penalty, Manage gain/loss Karma and Item Drop</li><BR>
  2188. * <BR>
  2189. * @param killer The L2Character who killed it
  2190. * @return true, if successful
  2191. */
  2192. public boolean doDie(final L2Character killer)
  2193. {
  2194. // killing is only possible one time
  2195. synchronized (this)
  2196. {
  2197. if (isKilledAlready())
  2198. return false;
  2199.  
  2200. setIsKilledAlready(true);
  2201. }
  2202. // Set target to null and cancel Attack or Cast
  2203. setTarget(null);
  2204.  
  2205. // Stop fear to avoid possible bug with char position after death
  2206. if (isAfraid())
  2207. stopFear(null);
  2208.  
  2209. // Stop movement
  2210. stopMove(null);
  2211.  
  2212. // Stop HP/MP/CP Regeneration task
  2213. getStatus().stopHpMpRegeneration();
  2214.  
  2215. // Stop all active skills effects in progress on the L2Character,
  2216. // if the Character isn't affected by Soul of The Phoenix or Salvation
  2217. if (this instanceof L2PlayableInstance && ((L2PlayableInstance) this).isPhoenixBlessed())
  2218. {
  2219. if (((L2PlayableInstance) this).isNoblesseBlessed())
  2220. {
  2221. ((L2PlayableInstance) this).stopNoblesseBlessing(null);
  2222. }
  2223. if (((L2PlayableInstance) this).getCharmOfLuck())
  2224. {
  2225. ((L2PlayableInstance) this).stopCharmOfLuck(null);
  2226. }
  2227. }
  2228. // Same thing if the Character isn't a Noblesse Blessed L2PlayableInstance
  2229. else if (this instanceof L2PlayableInstance && ((L2PlayableInstance) this).isNoblesseBlessed())
  2230. {
  2231. ((L2PlayableInstance) this).stopNoblesseBlessing(null);
  2232.  
  2233. if (((L2PlayableInstance) this).getCharmOfLuck())
  2234. {
  2235. ((L2PlayableInstance) this).stopCharmOfLuck(null);
  2236. }
  2237. }
  2238. else
  2239. {
  2240. if (this instanceof L2PcInstance)
  2241. {
  2242.  
  2243. final L2PcInstance player = (L2PcInstance) this;
  2244.  
  2245. // to avoid Event Remove buffs on die
  2246. if (player._inEventDM && DM.is_started())
  2247. {
  2248. if (Config.DM_REMOVE_BUFFS_ON_DIE)
  2249. stopAllEffects();
  2250. }
  2251. else if (player._inEventTvT && TvT.is_started())
  2252. {
  2253. if (Config.TVT_REMOVE_BUFFS_ON_DIE)
  2254. stopAllEffects();
  2255. }
  2256. else if (player._inEventCTF && CTF.is_started())
  2257. {
  2258. if (Config.CTF_REMOVE_BUFFS_ON_DIE)
  2259. stopAllEffects();
  2260. }
  2261. else if (Config.LEAVE_BUFFS_ON_DIE) // this means that the player is not in event
  2262. {
  2263. stopAllEffects();
  2264. }
  2265. }
  2266. else
  2267. // this means all other characters, including Summons
  2268. {
  2269. stopAllEffects();
  2270. }
  2271. }
  2272.  
  2273. // if killer is the same then the most damager/hated
  2274. L2Character mostHated = null;
  2275. if (this instanceof L2Attackable)
  2276. {
  2277. mostHated = ((L2Attackable) this)._mostHated;
  2278. }
  2279.  
  2280. if (mostHated != null && isInsideRadius(mostHated, 200, false, false))
  2281. {
  2282. calculateRewards(mostHated);
  2283. }
  2284. else
  2285. {
  2286. calculateRewards(killer);
  2287. }
  2288.  
  2289. // Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  2290. broadcastStatusUpdate();
  2291.  
  2292. // Notify L2Character AI
  2293. getAI().notifyEvent(CtrlEvent.EVT_DEAD, null);
  2294.  
  2295. if (getWorldRegion() != null)
  2296. {
  2297. getWorldRegion().onDeath(this);
  2298. }
  2299.  
  2300. // Notify Quest of character's death
  2301. for (final QuestState qs : getNotifyQuestOfDeath())
  2302. {
  2303. qs.getQuest().notifyDeath((killer == null ? this : killer), this, qs);
  2304. }
  2305.  
  2306. getNotifyQuestOfDeath().clear();
  2307.  
  2308. getAttackByList().clear();
  2309.  
  2310. // If character is PhoenixBlessed a resurrection popup will show up
  2311. if (this instanceof L2PlayableInstance && ((L2PlayableInstance) this).isPhoenixBlessed())
  2312. {
  2313. ((L2PcInstance) this).reviveRequest(((L2PcInstance) this), null, false);
  2314. }
  2315. fireEvent(EventType.DIE.name, new Object[]
  2316. {
  2317. killer
  2318. });
  2319.  
  2320. // Update active skills in progress (In Use and Not In Use because stacked) icones on client
  2321. updateEffectIcons();
  2322.  
  2323. // After dead mob check if the killer got a moving task actived
  2324. if (killer instanceof L2PcInstance)
  2325. {
  2326. if (((L2PcInstance) killer).isMovingTaskDefined())
  2327. {
  2328. ((L2PcInstance) killer).startMovingTask();
  2329. }
  2330. }
  2331.  
  2332. return true;
  2333. }
  2334.  
  2335. /**
  2336. * Calculate rewards.
  2337. * @param killer the killer
  2338. */
  2339. protected void calculateRewards(final L2Character killer)
  2340. {
  2341. }
  2342.  
  2343. /** Sets HP, MP and CP and revives the L2Character. */
  2344. public void doRevive()
  2345. {
  2346. if (!isTeleporting())
  2347. {
  2348. setIsPendingRevive(false);
  2349.  
  2350. if (this instanceof L2PlayableInstance && ((L2PlayableInstance) this).isPhoenixBlessed())
  2351. {
  2352. ((L2PlayableInstance) this).stopPhoenixBlessing(null);
  2353.  
  2354. // Like L2OFF Soul of The Phoenix and Salvation restore all hp,cp,mp.
  2355. _status.setCurrentCp(getMaxCp());
  2356. _status.setCurrentHp(getMaxHp());
  2357. _status.setCurrentMp(getMaxMp());
  2358. }
  2359. else
  2360. {
  2361. _status.setCurrentCp(getMaxCp() * Config.RESPAWN_RESTORE_CP);
  2362. _status.setCurrentHp(getMaxHp() * Config.RESPAWN_RESTORE_HP);
  2363. }
  2364. }
  2365. // Start broadcast status
  2366. broadcastPacket(new Revive(this));
  2367.  
  2368. if (getWorldRegion() != null)
  2369. {
  2370. getWorldRegion().onRevive(this);
  2371. }
  2372. else
  2373. {
  2374. setIsPendingRevive(true);
  2375. }
  2376. fireEvent(EventType.REVIVE.name, (Object[]) null);
  2377. }
  2378.  
  2379. /**
  2380. * Revives the L2Character using skill.
  2381. * @param revivePower the revive power
  2382. */
  2383. public void doRevive(final double revivePower)
  2384. {
  2385. doRevive();
  2386. }
  2387.  
  2388. /**
  2389. * Check if the active L2Skill can be casted.<BR>
  2390. * <BR>
  2391. * <B><U> Actions</U> :</B><BR>
  2392. * <BR>
  2393. * <li>Check if the L2Character can cast (ex : not sleeping...)</li> <li>Check if the target is correct</li> <li>Notify the AI with AI_INTENTION_CAST and target</li><BR>
  2394. * <BR>
  2395. * @param skill The L2Skill to use
  2396. */
  2397. protected void useMagic(final L2Skill skill)
  2398. {
  2399. if (skill == null || isDead())
  2400. return;
  2401.  
  2402. // Check if the L2Character can cast
  2403. if (!skill.isPotion() && isAllSkillsDisabled())
  2404. // must be checked by caller
  2405. return;
  2406.  
  2407. // Ignore the passive skill request. why does the client send it anyway ??
  2408. if (skill.isPassive() || skill.isChance())
  2409. return;
  2410.  
  2411. // Get the target for the skill
  2412. L2Object target = null;
  2413.  
  2414. switch (skill.getTargetType())
  2415. {
  2416. case TARGET_AURA: // AURA, SELF should be cast even if no target has been found
  2417. case TARGET_SELF:
  2418. target = this;
  2419. break;
  2420. default:
  2421. // Get the first target of the list
  2422. target = skill.getFirstOfTargetList(this);
  2423. break;
  2424. }
  2425.  
  2426. // Notify the AI with AI_INTENTION_CAST and target
  2427. getAI().setIntention(CtrlIntention.AI_INTENTION_CAST, skill, target);
  2428. target = null;
  2429. }
  2430.  
  2431. // =========================================================
  2432. // Property - Public
  2433. /**
  2434. * Return the L2CharacterAI of the L2Character and if its null create a new one.
  2435. * @return the aI
  2436. */
  2437. public L2CharacterAI getAI()
  2438. {
  2439. if (_ai == null)
  2440. {
  2441. synchronized (this)
  2442. {
  2443. if (_ai == null)
  2444. {
  2445. _ai = new L2CharacterAI(new AIAccessor());
  2446. }
  2447. }
  2448. }
  2449.  
  2450. return _ai;
  2451. }
  2452.  
  2453. /**
  2454. * Sets the aI.
  2455. * @param newAI the new aI
  2456. */
  2457. public void setAI(final L2CharacterAI newAI)
  2458. {
  2459. L2CharacterAI oldAI = getAI();
  2460.  
  2461. if (oldAI != null && oldAI != newAI && oldAI instanceof L2AttackableAI)
  2462. {
  2463. ((L2AttackableAI) oldAI).stopAITask();
  2464. }
  2465. _ai = newAI;
  2466.  
  2467. oldAI = null;
  2468. }
  2469.  
  2470. /**
  2471. * Return True if the L2Character has a L2CharacterAI.
  2472. * @return true, if successful
  2473. */
  2474. public boolean hasAI()
  2475. {
  2476. return _ai != null;
  2477. }
  2478.  
  2479. /**
  2480. * Return True if the L2Character is RaidBoss or his minion.
  2481. * @return true, if is raid
  2482. */
  2483. @Override
  2484. public boolean isRaid()
  2485. {
  2486. return false;
  2487. }
  2488.  
  2489. /**
  2490. * Return True if the L2Character is an Npc.
  2491. * @return true, if is npc
  2492. */
  2493. @Override
  2494. public boolean isNpc()
  2495. {
  2496. return false;
  2497. }
  2498.  
  2499. /**
  2500. * Return a list of L2Character that attacked.
  2501. * @return the attack by list
  2502. */
  2503. public final List<L2Character> getAttackByList()
  2504. {
  2505. if (_attackByList == null)
  2506. {
  2507. _attackByList = new FastList<>();
  2508. }
  2509.  
  2510. return _attackByList;
  2511. }
  2512.  
  2513. /**
  2514. * Gets the last skill cast.
  2515. * @return the last skill cast
  2516. */
  2517. public final L2Skill getLastSkillCast()
  2518. {
  2519. return _lastSkillCast;
  2520. }
  2521.  
  2522. /**
  2523. * Sets the last skill cast.
  2524. * @param skill the new last skill cast
  2525. */
  2526. public void setLastSkillCast(final L2Skill skill)
  2527. {
  2528. _lastSkillCast = skill;
  2529. }
  2530.  
  2531. /**
  2532. * Gets the last potion cast.
  2533. * @return the last potion cast
  2534. */
  2535. public final L2Skill getLastPotionCast()
  2536. {
  2537. return _lastPotionCast;
  2538. }
  2539.  
  2540. /**
  2541. * Sets the last potion cast.
  2542. * @param skill the new last potion cast
  2543. */
  2544. public void setLastPotionCast(final L2Skill skill)
  2545. {
  2546. _lastPotionCast = skill;
  2547. }
  2548.  
  2549. /**
  2550. * Checks if is afraid.
  2551. * @return true, if is afraid
  2552. */
  2553. public final boolean isAfraid()
  2554. {
  2555. return _isAfraid;
  2556. }
  2557.  
  2558. /**
  2559. * Sets the checks if is afraid.
  2560. * @param value the new checks if is afraid
  2561. */
  2562. public final void setIsAfraid(final boolean value)
  2563. {
  2564. _isAfraid = value;
  2565. }
  2566.  
  2567. /**
  2568. * Return True if the L2Character is dead or use fake death.
  2569. * @return true, if is alike dead
  2570. */
  2571. public final boolean isAlikeDead()
  2572. {
  2573. return isFakeDeath() || !(getCurrentHp() > 0.01);
  2574. }
  2575.  
  2576. /**
  2577. * Return True if the L2Character can't use its skills (ex : stun, sleep...).
  2578. * @return true, if is all skills disabled
  2579. */
  2580. public final boolean isAllSkillsDisabled()
  2581. {
  2582. return _allSkillsDisabled || isImmobileUntilAttacked() || isStunned() || isSleeping() || isParalyzed();
  2583. }
  2584.  
  2585. /**
  2586. * Return True if the L2Character can't attack (stun, sleep, attackEndTime, fakeDeath, paralyse).
  2587. * @return true, if is attacking disabled
  2588. */
  2589. public boolean isAttackingDisabled()
  2590. {
  2591. return isImmobileUntilAttacked() || isStunned() || isSleeping() || isFallsdown() || _attackEndTime > GameTimeController.getGameTicks() || isFakeDeath() || isParalyzed() || isAttackDisabled();
  2592. }
  2593.  
  2594. /**
  2595. * Gets the calculators.
  2596. * @return the calculators
  2597. */
  2598. public final Calculator[] getCalculators()
  2599. {
  2600. return _calculators;
  2601. }
  2602.  
  2603. /**
  2604. * Checks if is confused.
  2605. * @return true, if is confused
  2606. */
  2607. public final boolean isConfused()
  2608. {
  2609. return _isConfused;
  2610. }
  2611.  
  2612. /**
  2613. * Sets the checks if is confused.
  2614. * @param value the new checks if is confused
  2615. */
  2616. public final void setIsConfused(final boolean value)
  2617. {
  2618. _isConfused = value;
  2619. }
  2620.  
  2621. /**
  2622. * Return True if the L2Character is dead.
  2623. * @return true, if is dead
  2624. */
  2625. public final boolean isDead()
  2626. {
  2627. return !isFakeDeath() && (getCurrentHp() < 0.5);
  2628. }
  2629.  
  2630. /**
  2631. * Checks if is fake death.
  2632. * @return true, if is fake death
  2633. */
  2634. public final boolean isFakeDeath()
  2635. {
  2636. return _isFakeDeath;
  2637. }
  2638.  
  2639. /**
  2640. * Sets the checks if is fake death.
  2641. * @param value the new checks if is fake death
  2642. */
  2643. public final void setIsFakeDeath(final boolean value)
  2644. {
  2645. _isFakeDeath = value;
  2646. }
  2647.  
  2648. /**
  2649. * Return True if the L2Character is flying.
  2650. * @return true, if is flying
  2651. */
  2652. public final boolean isFlying()
  2653. {
  2654. return _isFlying;
  2655. }
  2656.  
  2657. /**
  2658. * Set the L2Character flying mode to True.
  2659. * @param mode the new checks if is flying
  2660. */
  2661. public final void setIsFlying(final boolean mode)
  2662. {
  2663. _isFlying = mode;
  2664. }
  2665.  
  2666. /**
  2667. * Checks if is fallsdown.
  2668. * @return true, if is fallsdown
  2669. */
  2670. public final boolean isFallsdown()
  2671. {
  2672. return _isFallsdown;
  2673. }
  2674.  
  2675. /**
  2676. * Sets the checks if is fallsdown.
  2677. * @param value the new checks if is fallsdown
  2678. */
  2679. public final void setIsFallsdown(final boolean value)
  2680. {
  2681. _isFallsdown = value;
  2682. }
  2683.  
  2684. /**
  2685. * Checks if is imobilised.
  2686. * @return true, if is imobilised
  2687. */
  2688. public boolean isImobilised()
  2689. {
  2690. return _isImobilised > 0;
  2691. }
  2692.  
  2693. /**
  2694. * Sets the checks if is imobilised.
  2695. * @param value the new checks if is imobilised
  2696. */
  2697. public void setIsImobilised(final boolean value)
  2698. {
  2699. // Stop this if he is moving
  2700. this.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  2701.  
  2702. if (value)
  2703. {
  2704. _isImobilised++;
  2705. }
  2706. else
  2707. {
  2708. _isImobilised--;
  2709. }
  2710. }
  2711.  
  2712. /**
  2713. * Checks if is block buff.
  2714. * @return the _isBlockBuff
  2715. */
  2716. public boolean isBlockBuff()
  2717. {
  2718. return _isBlockBuff;
  2719. }
  2720.  
  2721. /**
  2722. * Sets the block buff.
  2723. * @param blockBuff the _isBlockBuff to set
  2724. */
  2725. public void setBlockBuff(final boolean blockBuff)
  2726. {
  2727. _isBlockBuff = blockBuff;
  2728. }
  2729.  
  2730. /**
  2731. * Checks if is block debuff.
  2732. * @return the _isBlockDebuff
  2733. */
  2734. public boolean isBlockDebuff()
  2735. {
  2736. return _isBlockDebuff;
  2737. }
  2738.  
  2739. /**
  2740. * Sets the block debuff.
  2741. * @param blockDebuff the _isBlockDebuff to set
  2742. */
  2743. public void setBlockDebuff(final boolean blockDebuff)
  2744. {
  2745. _isBlockDebuff = blockDebuff;
  2746. }
  2747.  
  2748. /**
  2749. * Checks if is killed already.
  2750. * @return true, if is killed already
  2751. */
  2752. public final boolean isKilledAlready()
  2753. {
  2754. return _isKilledAlready;
  2755. }
  2756.  
  2757. /**
  2758. * Sets the checks if is killed already.
  2759. * @param value the new checks if is killed already
  2760. */
  2761. public final void setIsKilledAlready(final boolean value)
  2762. {
  2763. _isKilledAlready = value;
  2764. }
  2765.  
  2766. /**
  2767. * Checks if is muted.
  2768. * @return true, if is muted
  2769. */
  2770. public final boolean isMuted()
  2771. {
  2772. return _isMuted;
  2773. }
  2774.  
  2775. /**
  2776. * Sets the checks if is muted.
  2777. * @param value the new checks if is muted
  2778. */
  2779. public final void setIsMuted(final boolean value)
  2780. {
  2781. _isMuted = value;
  2782. }
  2783.  
  2784. /**
  2785. * Checks if is psychical muted.
  2786. * @return true, if is psychical muted
  2787. */
  2788. public final boolean isPsychicalMuted()
  2789. {
  2790. return _isPsychicalMuted;
  2791. }
  2792.  
  2793. /**
  2794. * Sets the checks if is psychical muted.
  2795. * @param value the new checks if is psychical muted
  2796. */
  2797. public final void setIsPsychicalMuted(final boolean value)
  2798. {
  2799. _isPsychicalMuted = value;
  2800. }
  2801.  
  2802. /**
  2803. * Return True if the L2Character can't move (stun, root, sleep, overload, paralyzed).
  2804. * @return true, if is movement disabled
  2805. */
  2806. public boolean isMovementDisabled()
  2807. {
  2808. return isImmobileUntilAttacked() || isStunned() || isRooted() || isSleeping() || isOverloaded() || isParalyzed() || isImobilised() || isFakeDeath() || isFallsdown();
  2809. }
  2810.  
  2811. /**
  2812. * Return True if the L2Character can be controlled by the player (confused, afraid).
  2813. * @return true, if is out of control
  2814. */
  2815. public final boolean isOutOfControl()
  2816. {
  2817. return isConfused() || isAfraid() || isBlocked();
  2818. }
  2819.  
  2820. /**
  2821. * Checks if is overloaded.
  2822. * @return true, if is overloaded
  2823. */
  2824. public final boolean isOverloaded()
  2825. {
  2826. return _isOverloaded;
  2827. }
  2828.  
  2829. /**
  2830. * Set the overloaded status of the L2Character is overloaded (if True, the L2PcInstance can't take more item).
  2831. * @param value the new checks if is overloaded
  2832. */
  2833. public final void setIsOverloaded(final boolean value)
  2834. {
  2835. _isOverloaded = value;
  2836. }
  2837.  
  2838. /**
  2839. * Checks if is paralyzed.
  2840. * @return true, if is paralyzed
  2841. */
  2842. public final boolean isParalyzed()
  2843. {
  2844. return _isParalyzed;
  2845. }
  2846.  
  2847. /**
  2848. * Sets the checks if is paralyzed.
  2849. * @param value the new checks if is paralyzed
  2850. */
  2851. public final void setIsParalyzed(final boolean value)
  2852. {
  2853. if (_petrified)
  2854. return;
  2855. _isParalyzed = value;
  2856. }
  2857.  
  2858. /**
  2859. * Checks if is pending revive.
  2860. * @return true, if is pending revive
  2861. */
  2862. public final boolean isPendingRevive()
  2863. {
  2864. return isDead() && _isPendingRevive;
  2865. }
  2866.  
  2867. /**
  2868. * Sets the checks if is pending revive.
  2869. * @param value the new checks if is pending revive
  2870. */
  2871. public final void setIsPendingRevive(final boolean value)
  2872. {
  2873. _isPendingRevive = value;
  2874. }
  2875.  
  2876. /**
  2877. * Return the L2Summon of the L2Character.<BR>
  2878. * <BR>
  2879. * <B><U> Overriden in </U> :</B><BR>
  2880. * <BR>
  2881. * <li>L2PcInstance</li><BR>
  2882. * <BR>
  2883. * @return the pet
  2884. */
  2885. public L2Summon getPet()
  2886. {
  2887. return null;
  2888. }
  2889.  
  2890. /**
  2891. * Return True if the L2Character is ridding.
  2892. * @return true, if is riding
  2893. */
  2894. public final boolean isRiding()
  2895. {
  2896. return _isRiding;
  2897. }
  2898.  
  2899. /**
  2900. * Set the L2Character riding mode to True.
  2901. * @param mode the new checks if is riding
  2902. */
  2903. public final void setIsRiding(final boolean mode)
  2904. {
  2905. _isRiding = mode;
  2906. }
  2907.  
  2908. /**
  2909. * Checks if is rooted.
  2910. * @return true, if is rooted
  2911. */
  2912. public final boolean isRooted()
  2913. {
  2914. return _isRooted;
  2915. }
  2916.  
  2917. /**
  2918. * Sets the checks if is rooted.
  2919. * @param value the new checks if is rooted
  2920. */
  2921. public final void setIsRooted(final boolean value)
  2922. {
  2923. _isRooted = value;
  2924. }
  2925.  
  2926. /**
  2927. * Return True if the L2Character is running.
  2928. * @return true, if is running
  2929. */
  2930. public final boolean isRunning()
  2931. {
  2932. return _isRunning;
  2933. }
  2934.  
  2935. /**
  2936. * Sets the checks if is running.
  2937. * @param value the new checks if is running
  2938. */
  2939. public final void setIsRunning(final boolean value)
  2940. {
  2941. _isRunning = value;
  2942. broadcastPacket(new ChangeMoveType(this));
  2943. }
  2944.  
  2945. /**
  2946. * Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance.
  2947. */
  2948. public final void setRunning()
  2949. {
  2950. if (!isRunning())
  2951. {
  2952. setIsRunning(true);
  2953. }
  2954. }
  2955.  
  2956. /**
  2957. * Checks if is immobile until attacked.
  2958. * @return true, if is immobile until attacked
  2959. */
  2960. public final boolean isImmobileUntilAttacked()
  2961. {
  2962. return _isImmobileUntilAttacked;
  2963. }
  2964.  
  2965. /**
  2966. * Sets the checks if is immobile until attacked.
  2967. * @param value the new checks if is immobile until attacked
  2968. */
  2969. public final void setIsImmobileUntilAttacked(final boolean value)
  2970. {
  2971. _isImmobileUntilAttacked = value;
  2972. }
  2973.  
  2974. /**
  2975. * Checks if is sleeping.
  2976. * @return true, if is sleeping
  2977. */
  2978. public final boolean isSleeping()
  2979. {
  2980. return _isSleeping;
  2981. }
  2982.  
  2983. /**
  2984. * Sets the checks if is sleeping.
  2985. * @param value the new checks if is sleeping
  2986. */
  2987. public final void setIsSleeping(final boolean value)
  2988. {
  2989. _isSleeping = value;
  2990. }
  2991.  
  2992. /**
  2993. * Checks if is stunned.
  2994. * @return true, if is stunned
  2995. */
  2996. public final boolean isStunned()
  2997. {
  2998. return _isStunned;
  2999. }
  3000.  
  3001. /**
  3002. * Sets the checks if is stunned.
  3003. * @param value the new checks if is stunned
  3004. */
  3005. public final void setIsStunned(final boolean value)
  3006. {
  3007. _isStunned = value;
  3008. }
  3009.  
  3010. /**
  3011. * Checks if is betrayed.
  3012. * @return true, if is betrayed
  3013. */
  3014. public final boolean isBetrayed()
  3015. {
  3016. return _isBetrayed;
  3017. }
  3018.  
  3019. /**
  3020. * Sets the checks if is betrayed.
  3021. * @param value the new checks if is betrayed
  3022. */
  3023. public final void setIsBetrayed(final boolean value)
  3024. {
  3025. _isBetrayed = value;
  3026. }
  3027.  
  3028. /**
  3029. * Checks if is teleporting.
  3030. * @return true, if is teleporting
  3031. */
  3032. public final boolean isTeleporting()
  3033. {
  3034. return _isTeleporting;
  3035. }
  3036.  
  3037. /**
  3038. * Sets the checks if is teleporting.
  3039. * @param value the new checks if is teleporting
  3040. */
  3041. public void setIsTeleporting(final boolean value)
  3042. {
  3043. _isTeleporting = value;
  3044. }
  3045.  
  3046. /**
  3047. * Sets the checks if is invul.
  3048. * @param b the new checks if is invul
  3049. */
  3050. public void setIsInvul(final boolean b)
  3051. {
  3052. if (_petrified)
  3053. return;
  3054.  
  3055. _isInvul = b;
  3056. }
  3057.  
  3058. /**
  3059. * Checks if is invul.
  3060. * @return true, if is invul
  3061. */
  3062. public boolean isInvul()
  3063. {
  3064. return _isInvul || _isTeleporting;
  3065. }
  3066.  
  3067. /**
  3068. * Checks if is undead.
  3069. * @return true, if is undead
  3070. */
  3071. public boolean isUndead()
  3072. {
  3073. return _template.isUndead;
  3074. }
  3075.  
  3076. /*
  3077. * (non-Javadoc)
  3078. * @see com.l2jfrozen.gameserver.model.L2Object#getKnownList()
  3079. */
  3080. @Override
  3081. public CharKnownList getKnownList()
  3082. {
  3083. if (super.getKnownList() == null || !(super.getKnownList() instanceof CharKnownList))
  3084. {
  3085. setKnownList(new CharKnownList(this));
  3086. }
  3087.  
  3088. return (CharKnownList) super.getKnownList();
  3089. }
  3090.  
  3091. /**
  3092. * Gets the stat.
  3093. * @return the stat
  3094. */
  3095. public CharStat getStat()
  3096. {
  3097. if (_stat == null)
  3098. {
  3099. _stat = new CharStat(this);
  3100. }
  3101.  
  3102. return _stat;
  3103. }
  3104.  
  3105. /**
  3106. * Sets the stat.
  3107. * @param value the new stat
  3108. */
  3109. public final void setStat(final CharStat value)
  3110. {
  3111. _stat = value;
  3112. }
  3113.  
  3114. /**
  3115. * Gets the status.
  3116. * @return the status
  3117. */
  3118. public CharStatus getStatus()
  3119. {
  3120. if (_status == null)
  3121. {
  3122. _status = new CharStatus(this);
  3123. }
  3124.  
  3125. return _status;
  3126. }
  3127.  
  3128. /**
  3129. * Sets the status.
  3130. * @param value the new status
  3131. */
  3132. public final void setStatus(final CharStatus value)
  3133. {
  3134. _status = value;
  3135. }
  3136.  
  3137. /**
  3138. * Gets the template.
  3139. * @return the template
  3140. */
  3141. public L2CharTemplate getTemplate()
  3142. {
  3143. return _template;
  3144. }
  3145.  
  3146. /**
  3147. * Set the template of the L2Character.<BR>
  3148. * <BR>
  3149. * <B><U> Concept</U> :</B><BR>
  3150. * <BR>
  3151. * Each L2Character owns generic and static properties (ex : all Keltir have the same number of HP...). All of those properties are stored in a different template for each type of L2Character. Each template is loaded once in the server cache memory (reduce memory use). When a new instance of
  3152. * L2Character is spawned, server just create a link between the instance and the template This link is stored in <B>_template</B><BR>
  3153. * <BR>
  3154. * <B><U> Assert </U> :</B><BR>
  3155. * <BR>
  3156. * <li>this instanceof L2Character</li><BR>
  3157. * <BR
  3158. * @param template the new template
  3159. */
  3160. protected synchronized final void setTemplate(final L2CharTemplate template)
  3161. {
  3162. _template = template;
  3163. }
  3164.  
  3165. /**
  3166. * Return the Title of the L2Character.
  3167. * @return the title
  3168. */
  3169. public final String getTitle()
  3170. {
  3171. if (_title == null)
  3172. return "";
  3173.  
  3174. return _title;
  3175. }
  3176.  
  3177. /**
  3178. * Set the Title of the L2Character.
  3179. * @param value the new title
  3180. */
  3181. public final void setTitle(String value)
  3182. {
  3183. if (value == null)
  3184. value = "";
  3185.  
  3186. if (this instanceof L2PcInstance && value.length() > 16)
  3187. {
  3188. value = value.substring(0, 15);
  3189. }
  3190.  
  3191. _title = value; // public final void setTitle(String value) { _title = value; }
  3192. }
  3193.  
  3194. /**
  3195. * Set the L2Character movement type to walk and send Server->Client packet ChangeMoveType to all others L2PcInstance.
  3196. */
  3197. public final void setWalking()
  3198. {
  3199. if (isRunning())
  3200. {
  3201. setIsRunning(false);
  3202. }
  3203. }
  3204.  
  3205. /**
  3206. * Task lauching the function enableSkill().
  3207. */
  3208. class EnableSkill implements Runnable
  3209. {
  3210.  
  3211. /** The _skill id. */
  3212. L2Skill _skillId;
  3213.  
  3214. /**
  3215. * Instantiates a new enable skill.
  3216. * @param skill the skill
  3217. */
  3218. public EnableSkill(final L2Skill skill)
  3219. {
  3220. _skillId = skill;
  3221. }
  3222.  
  3223. /*
  3224. * (non-Javadoc)
  3225. * @see java.lang.Runnable#run()
  3226. */
  3227. @Override
  3228. public void run()
  3229. {
  3230. try
  3231. {
  3232. enableSkill(_skillId);
  3233. }
  3234. catch (final Throwable e)
  3235. {
  3236. LOGGER.error("", e);
  3237. }
  3238. }
  3239. }
  3240.  
  3241. /**
  3242. * Task lauching the function onHitTimer().<BR>
  3243. * <BR>
  3244. * <B><U> Actions</U> :</B><BR>
  3245. * <BR>
  3246. * <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> <li>If attack isn't aborted, send a message system (critical hit, missed...) to attacker/target if they are L2PcInstance</li>
  3247. * <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> <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>
  3248. * <BR>
  3249. */
  3250. class HitTask implements Runnable
  3251. {
  3252.  
  3253. /** The _hit target. */
  3254. L2Character _hitTarget;
  3255.  
  3256. /** The _damage. */
  3257. int _damage;
  3258.  
  3259. /** The _crit. */
  3260. boolean _crit;
  3261.  
  3262. /** The _miss. */
  3263. boolean _miss;
  3264.  
  3265. /** The _shld. */
  3266. boolean _shld;
  3267.  
  3268. /** The _soulshot. */
  3269. boolean _soulshot;
  3270.  
  3271. /**
  3272. * Instantiates a new hit task.
  3273. * @param target the target
  3274. * @param damage the damage
  3275. * @param crit the crit
  3276. * @param miss the miss
  3277. * @param soulshot the soulshot
  3278. * @param shld the shld
  3279. */
  3280. public HitTask(final L2Character target, final int damage, final boolean crit, final boolean miss, final boolean soulshot, final boolean shld)
  3281. {
  3282. _hitTarget = target;
  3283. _damage = damage;
  3284. _crit = crit;
  3285. _shld = shld;
  3286. _miss = miss;
  3287. _soulshot = soulshot;
  3288. }
  3289.  
  3290. /*
  3291. * (non-Javadoc)
  3292. * @see java.lang.Runnable#run()
  3293. */
  3294. @Override
  3295. public void run()
  3296. {
  3297. try
  3298. {
  3299. onHitTimer(_hitTarget, _damage, _crit, _miss, _soulshot, _shld);
  3300. }
  3301. catch (final Throwable e)
  3302. {
  3303. LOGGER.error("fixme:hit task unhandled exception", e);
  3304. }
  3305. }
  3306. }
  3307.  
  3308. /**
  3309. * Task lauching the magic skill phases.
  3310. */
  3311. class MagicUseTask implements Runnable
  3312. {
  3313.  
  3314. /** The _targets. */
  3315. L2Object[] _targets;
  3316.  
  3317. /** The _skill. */
  3318. L2Skill _skill;
  3319.  
  3320. /** The _cool time. */
  3321. int _coolTime;
  3322.  
  3323. /** The _phase. */
  3324. int _phase;
  3325.  
  3326. /**
  3327. * Instantiates a new magic use task.
  3328. * @param targets the targets
  3329. * @param skill the skill
  3330. * @param coolTime the cool time
  3331. * @param phase the phase
  3332. */
  3333. public MagicUseTask(final L2Object[] targets, final L2Skill skill, final int coolTime, final int phase)
  3334. {
  3335. _targets = targets;
  3336. _skill = skill;
  3337. _coolTime = coolTime;
  3338. _phase = phase;
  3339. }
  3340.  
  3341. /*
  3342. * (non-Javadoc)
  3343. * @see java.lang.Runnable#run()
  3344. */
  3345. @Override
  3346. public void run()
  3347. {
  3348. try
  3349. {
  3350. switch (_phase)
  3351. {
  3352. case 1:
  3353. onMagicLaunchedTimer(_targets, _skill, _coolTime, false);
  3354. break;
  3355. case 2:
  3356. onMagicHitTimer(_targets, _skill, _coolTime, false);
  3357. break;
  3358. case 3:
  3359. onMagicFinalizer(_targets, _skill);
  3360. break;
  3361. default:
  3362. break;
  3363. }
  3364. }
  3365. catch (final Throwable e)
  3366. {
  3367. LOGGER.error("", e);
  3368. e.printStackTrace();
  3369. enableAllSkills();
  3370. }
  3371. }
  3372. }
  3373.  
  3374. /**
  3375. * Task lauching the function useMagic().
  3376. */
  3377. class QueuedMagicUseTask implements Runnable
  3378. {
  3379.  
  3380. /** The _curr player. */
  3381. L2PcInstance _currPlayer;
  3382.  
  3383. /** The _queued skill. */
  3384. L2Skill _queuedSkill;
  3385.  
  3386. /** The _is ctrl pressed. */
  3387. boolean _isCtrlPressed;
  3388.  
  3389. /** The _is shift pressed. */
  3390. boolean _isShiftPressed;
  3391.  
  3392. /**
  3393. * Instantiates a new queued magic use task.
  3394. * @param currPlayer the curr player
  3395. * @param queuedSkill the queued skill
  3396. * @param isCtrlPressed the is ctrl pressed
  3397. * @param isShiftPressed the is shift pressed
  3398. */
  3399. public QueuedMagicUseTask(final L2PcInstance currPlayer, final L2Skill queuedSkill, final boolean isCtrlPressed, final boolean isShiftPressed)
  3400. {
  3401. _currPlayer = currPlayer;
  3402. _queuedSkill = queuedSkill;
  3403. _isCtrlPressed = isCtrlPressed;
  3404. _isShiftPressed = isShiftPressed;
  3405. }
  3406.  
  3407. /*
  3408. * (non-Javadoc)
  3409. * @see java.lang.Runnable#run()
  3410. */
  3411. @Override
  3412. public void run()
  3413. {
  3414. try
  3415. {
  3416. _currPlayer.useMagic(_queuedSkill, _isCtrlPressed, _isShiftPressed);
  3417. }
  3418. catch (final Throwable e)
  3419. {
  3420. LOGGER.error("", e);
  3421. }
  3422. }
  3423. }
  3424.  
  3425. /**
  3426. * Task of AI notification.
  3427. */
  3428. public class NotifyAITask implements Runnable
  3429. {
  3430.  
  3431. /** The _evt. */
  3432. private final CtrlEvent _evt;
  3433.  
  3434. /**
  3435. * Instantiates a new notify ai task.
  3436. * @param evt the evt
  3437. */
  3438. NotifyAITask(final CtrlEvent evt)
  3439. {
  3440. _evt = evt;
  3441. }
  3442.  
  3443. /*
  3444. * (non-Javadoc)
  3445. * @see java.lang.Runnable#run()
  3446. */
  3447. @Override
  3448. public void run()
  3449. {
  3450. try
  3451. {
  3452. getAI().notifyEvent(_evt, null);
  3453. }
  3454. catch (final Throwable t)
  3455. {
  3456. LOGGER.warn("", t);
  3457. }
  3458. }
  3459. }
  3460.  
  3461. /**
  3462. * Task lauching the function stopPvPFlag().
  3463. */
  3464. class PvPFlag implements Runnable
  3465. {
  3466.  
  3467. /**
  3468. * Instantiates a new pvp flag.
  3469. */
  3470. public PvPFlag()
  3471. {
  3472. // null
  3473. }
  3474.  
  3475. /*
  3476. * (non-Javadoc)
  3477. * @see java.lang.Runnable#run()
  3478. */
  3479. @Override
  3480. public void run()
  3481. {
  3482. try
  3483. {
  3484. // LOGGER.fine("Checking pvp time: " + getlastPvpAttack());
  3485. // "lastattack: " _lastAttackTime "currenttime: "
  3486. // System.currentTimeMillis());
  3487. if (System.currentTimeMillis() > getPvpFlagLasts())
  3488. {
  3489. // LOGGER.fine("Stopping PvP");
  3490. stopPvPFlag();
  3491. }
  3492. else if (System.currentTimeMillis() > getPvpFlagLasts() - 5000)
  3493. {
  3494. updatePvPFlag(2);
  3495. }
  3496. else
  3497. {
  3498. updatePvPFlag(1);
  3499. // Start a new PvP timer check
  3500. // checkPvPFlag();
  3501. }
  3502. }
  3503. catch (final Exception e)
  3504. {
  3505. LOGGER.warn("error in pvp flag task:", e);
  3506. }
  3507. }
  3508. }
  3509.  
  3510. // =========================================================
  3511.  
  3512. // =========================================================
  3513. // Abnormal Effect - NEED TO REMOVE ONCE L2CHARABNORMALEFFECT IS COMPLETE
  3514. // Data Field
  3515. /** Map 32 bits (0x0000) containing all abnormal effect in progress. */
  3516. private int _AbnormalEffects;
  3517.  
  3518. /**
  3519. * FastTable containing all active skills effects in progress of a L2Character.
  3520. */
  3521. private final FastTable<L2Effect> _effects = new FastTable<>();
  3522.  
  3523. /** The table containing the List of all stacked effect in progress for each Stack group Identifier. */
  3524. protected Map<String, List<L2Effect>> _stackedEffects = new FastMap<>();
  3525.  
  3526. /** The Constant ABNORMAL_EFFECT_BLEEDING. */
  3527. public static final int ABNORMAL_EFFECT_BLEEDING = 0x000001;
  3528.  
  3529. /** The Constant ABNORMAL_EFFECT_POISON. */
  3530. public static final int ABNORMAL_EFFECT_POISON = 0x000002;
  3531.  
  3532. /** The Constant ABNORMAL_EFFECT_REDCIRCLE. */
  3533. public static final int ABNORMAL_EFFECT_REDCIRCLE = 0x000004;
  3534.  
  3535. /** The Constant ABNORMAL_EFFECT_ICE. */
  3536. public static final int ABNORMAL_EFFECT_ICE = 0x000008;
  3537.  
  3538. /** The Constant ABNORMAL_EFFECT_WIND. */
  3539. public static final int ABNORMAL_EFFECT_WIND = 0x0000010;
  3540.  
  3541. /** The Constant ABNORMAL_EFFECT_FEAR. */
  3542. public static final int ABNORMAL_EFFECT_FEAR = 0x0000020;
  3543.  
  3544. /** The Constant ABNORMAL_EFFECT_STUN. */
  3545. public static final int ABNORMAL_EFFECT_STUN = 0x000040;
  3546.  
  3547. /** The Constant ABNORMAL_EFFECT_SLEEP. */
  3548. public static final int ABNORMAL_EFFECT_SLEEP = 0x000080;
  3549.  
  3550. /** The Constant ABNORMAL_EFFECT_MUTED. */
  3551. public static final int ABNORMAL_EFFECT_MUTED = 0x000100;
  3552.  
  3553. /** The Constant ABNORMAL_EFFECT_ROOT. */
  3554. public static final int ABNORMAL_EFFECT_ROOT = 0x000200;
  3555.  
  3556. /** The Constant ABNORMAL_EFFECT_HOLD_1. */
  3557. public static final int ABNORMAL_EFFECT_HOLD_1 = 0x000400;
  3558.  
  3559. /** The Constant ABNORMAL_EFFECT_HOLD_2. */
  3560. public static final int ABNORMAL_EFFECT_HOLD_2 = 0x000800;
  3561.  
  3562. /** The Constant ABNORMAL_EFFECT_UNKNOWN_13. */
  3563. public static final int ABNORMAL_EFFECT_UNKNOWN_13 = 0x001000;
  3564.  
  3565. /** The Constant ABNORMAL_EFFECT_BIG_HEAD. */
  3566. public static final int ABNORMAL_EFFECT_BIG_HEAD = 0x002000;
  3567.  
  3568. /** The Constant ABNORMAL_EFFECT_FLAME. */
  3569. public static final int ABNORMAL_EFFECT_FLAME = 0x004000;
  3570.  
  3571. /** The Constant ABNORMAL_EFFECT_UNKNOWN_16. */
  3572. public static final int ABNORMAL_EFFECT_UNKNOWN_16 = 0x008000;
  3573.  
  3574. /** The Constant ABNORMAL_EFFECT_GROW. */
  3575. public static final int ABNORMAL_EFFECT_GROW = 0x010000;
  3576.  
  3577. /** The Constant ABNORMAL_EFFECT_FLOATING_ROOT. */
  3578. public static final int ABNORMAL_EFFECT_FLOATING_ROOT = 0x020000;
  3579.  
  3580. /** The Constant ABNORMAL_EFFECT_DANCE_STUNNED. */
  3581. public static final int ABNORMAL_EFFECT_DANCE_STUNNED = 0x040000;
  3582.  
  3583. /** The Constant ABNORMAL_EFFECT_FIREROOT_STUN. */
  3584. public static final int ABNORMAL_EFFECT_FIREROOT_STUN = 0x080000;
  3585.  
  3586. /** The Constant ABNORMAL_EFFECT_STEALTH. */
  3587. public static final int ABNORMAL_EFFECT_STEALTH = 0x100000;
  3588.  
  3589. /** The Constant ABNORMAL_EFFECT_IMPRISIONING_1. */
  3590. public static final int ABNORMAL_EFFECT_IMPRISIONING_1 = 0x200000;
  3591.  
  3592. /** The Constant ABNORMAL_EFFECT_IMPRISIONING_2. */
  3593. public static final int ABNORMAL_EFFECT_IMPRISIONING_2 = 0x400000;
  3594.  
  3595. /** The Constant ABNORMAL_EFFECT_MAGIC_CIRCLE. */
  3596. public static final int ABNORMAL_EFFECT_MAGIC_CIRCLE = 0x800000;
  3597.  
  3598. /** The Constant ABNORMAL_EFFECT_CONFUSED. */
  3599. public static final int ABNORMAL_EFFECT_CONFUSED = 0x0020;
  3600.  
  3601. /** The Constant ABNORMAL_EFFECT_AFRAID. */
  3602. public static final int ABNORMAL_EFFECT_AFRAID = 0x0010;
  3603.  
  3604. // Method - Public
  3605. /**
  3606. * Launch and add L2Effect (including Stack Group management) to L2Character and update client magic icone.<BR>
  3607. * <BR>
  3608. * <B><U> Concept</U> :</B><BR>
  3609. * <BR>
  3610. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>. The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR>
  3611. * <BR>
  3612. * Several same effect can't be used on a L2Character at the same time. Indeed, effects are not stackable and the last cast will replace the previous in progress. More, some effects belong to the same Stack Group (ex WindWald and Haste Potion). If 2 effects of a same group are used at the same
  3613. * time on a L2Character, only the more efficient (identified by its priority order) will be preserve.<BR>
  3614. * <BR>
  3615. * <B><U> Actions</U> :</B><BR>
  3616. * <BR>
  3617. * <li>Add the L2Effect to the L2Character _effects</li> <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> <li>If this effect has higher priority in its Stack Group, add its Funcs to the Calculator
  3618. * set of the L2Character (remove previous stacked effect Funcs if necessary)</li> <li>If this effect has NOT higher priority in its Stack Group, set the effect to Not In Use</li> <li>Update active skills in progress icones on player client</li><BR>
  3619. * @param newEffect the new effect
  3620. */
  3621. public synchronized void addEffect(final L2Effect newEffect)
  3622. {
  3623. if (newEffect == null)
  3624. return;
  3625.  
  3626. final L2Effect[] effects = getAllEffects();
  3627.  
  3628. // Make sure there's no same effect previously
  3629. for (final L2Effect effect : effects)
  3630. {
  3631. if (effect == null)
  3632. {
  3633.  
  3634. synchronized (_effects)
  3635. {
  3636. _effects.remove(effect);
  3637. }
  3638. continue;
  3639. }
  3640.  
  3641. if (effect.getSkill().getId() == newEffect.getSkill().getId() && effect.getEffectType() == newEffect.getEffectType() && effect.getStackType() == newEffect.getStackType())
  3642. {
  3643. if (this instanceof L2PcInstance)
  3644. {
  3645.  
  3646. final L2PcInstance player = (L2PcInstance) this;
  3647.  
  3648. if (player.isInDuel())
  3649. {
  3650. DuelManager.getInstance().getDuel(player.getDuelId()).onBuffStop(player, effect);
  3651. }
  3652.  
  3653. }
  3654.  
  3655. if ((newEffect.getSkill().getSkillType() == SkillType.BUFF || newEffect.getEffectType() == L2Effect.EffectType.BUFF || newEffect.getEffectType() == L2Effect.EffectType.HEAL_OVER_TIME) && newEffect.getStackOrder() >= effect.getStackOrder())
  3656. {
  3657. effect.exit(false);
  3658. }
  3659. else
  3660. {
  3661. // newEffect.exit(false);
  3662. newEffect.stopEffectTask();
  3663. return;
  3664. }
  3665. }
  3666. }
  3667.  
  3668. final L2Skill tempskill = newEffect.getSkill();
  3669.  
  3670. // Remove first Buff if number of buffs > BUFFS_MAX_AMOUNT
  3671. if (getBuffCount() >= getMaxBuffCount() && !doesStack(tempskill) && (tempskill.getSkillType() == L2Skill.SkillType.BUFF || tempskill.getSkillType() == L2Skill.SkillType.REFLECT || tempskill.getSkillType() == L2Skill.SkillType.HEAL_PERCENT || tempskill.getSkillType() == L2Skill.SkillType.MANAHEAL_PERCENT) && !(tempskill.getId() > 4360 && tempskill.getId() < 4367) && !(tempskill.getId() > 4550 && tempskill.getId() < 4555))
  3672. {
  3673. if (newEffect.isHerbEffect())
  3674. {
  3675. newEffect.exit(false);
  3676. return;
  3677. }
  3678. removeFirstBuff(tempskill.getId());
  3679. }
  3680.  
  3681. // Remove first DeBuff if number of debuffs > DEBUFFS_MAX_AMOUNT
  3682. if (getDeBuffCount() >= Config.DEBUFFS_MAX_AMOUNT && !doesStack(tempskill) && tempskill.is_Debuff())
  3683. {
  3684. removeFirstDeBuff(tempskill.getId());
  3685. }
  3686.  
  3687. synchronized (_effects)
  3688. {
  3689. // Add the L2Effect to all effect in progress on the L2Character
  3690. if (!newEffect.getSkill().isToggle())
  3691. {
  3692. int pos = 0;
  3693.  
  3694. for (int i = 0; i < _effects.size(); i++)
  3695. {
  3696. if (_effects.get(i) == null)
  3697. {
  3698. _effects.remove(i);
  3699. i--;
  3700. continue;
  3701. }
  3702.  
  3703. if (_effects.get(i) != null)
  3704. {
  3705. final int skillid = _effects.get(i).getSkill().getId();
  3706.  
  3707. if (!_effects.get(i).getSkill().isToggle() && !(skillid > 4360 && skillid < 4367))
  3708. {
  3709. pos++;
  3710. }
  3711. }
  3712. else
  3713. {
  3714. break;
  3715. }
  3716. }
  3717. _effects.add(pos, newEffect);
  3718. }
  3719. else
  3720. {
  3721. _effects.addLast(newEffect);
  3722. }
  3723.  
  3724. }
  3725.  
  3726. // Check if a stack group is defined for this effect
  3727. if (newEffect.getStackType().equals("none"))
  3728. {
  3729. // Set this L2Effect to In Use
  3730. newEffect.setInUse(true);
  3731.  
  3732. // Add Funcs of this effect to the Calculator set of the L2Character
  3733. addStatFuncs(newEffect.getStatFuncs());
  3734.  
  3735. // Update active skills in progress icones on player client
  3736. updateEffectIcons();
  3737. return;
  3738. }
  3739.  
  3740. // Get the list of all stacked effects corresponding to the stack type of the L2Effect to add
  3741. List<L2Effect> stackQueue = _stackedEffects.get(newEffect.getStackType());
  3742.  
  3743. if (stackQueue == null)
  3744. {
  3745. stackQueue = new FastList<>();
  3746. }
  3747.  
  3748. // L2Effect tempEffect = null;
  3749.  
  3750. if (stackQueue.size() > 0)
  3751. {
  3752. // Get the first stacked effect of the Stack group selected
  3753. if (_effects.contains(stackQueue.get(0)))
  3754. {
  3755. // Remove all Func objects corresponding to this stacked effect from the Calculator set of the L2Character
  3756. removeStatsOwner(stackQueue.get(0));
  3757.  
  3758. // Set the L2Effect to Not In Use
  3759. stackQueue.get(0).setInUse(false);
  3760. }
  3761. }
  3762.  
  3763. // Add the new effect to the stack group selected at its position
  3764. stackQueue = effectQueueInsert(newEffect, stackQueue);
  3765.  
  3766. if (stackQueue == null)
  3767. return;
  3768.  
  3769. // Update the Stack Group table _stackedEffects of the L2Character
  3770. _stackedEffects.put(newEffect.getStackType(), stackQueue);
  3771.  
  3772. // Get the first stacked effect of the Stack group selected
  3773. if (_effects.contains(stackQueue.get(0)))
  3774. {
  3775. // Set this L2Effect to In Use
  3776. stackQueue.get(0).setInUse(true);
  3777.  
  3778. // Add all Func objects corresponding to this stacked effect to the Calculator set of the L2Character
  3779. addStatFuncs(stackQueue.get(0).getStatFuncs());
  3780. }
  3781.  
  3782. // Update active skills in progress (In Use and Not In Use because stacked) icones on client
  3783. updateEffectIcons();
  3784. }
  3785.  
  3786. /**
  3787. * Insert an effect at the specified position in a Stack Group.<BR>
  3788. * <BR>
  3789. * <B><U> Concept</U> :</B><BR>
  3790. * <BR>
  3791. * Several same effect can't be used on a L2Character at the same time. Indeed, effects are not stackable and the last cast will replace the previous in progress. More, some effects belong to the same Stack Group (ex WindWald and Haste Potion). If 2 effects of a same group are used at the same
  3792. * time on a L2Character, only the more efficient (identified by its priority order) will be preserve.<BR>
  3793. * <BR>
  3794. * @param newStackedEffect the new stacked effect
  3795. * @param stackQueue The Stack Group in wich the effect must be added
  3796. * @return the list
  3797. */
  3798. private List<L2Effect> effectQueueInsert(final L2Effect newStackedEffect, final List<L2Effect> stackQueue)
  3799. {
  3800. // Create an Iterator to go through the list of stacked effects in progress on the L2Character
  3801. Iterator<L2Effect> queueIterator = stackQueue.iterator();
  3802.  
  3803. int i = 0;
  3804. while (queueIterator.hasNext())
  3805. {
  3806. final L2Effect cur = queueIterator.next();
  3807. if (newStackedEffect.getStackOrder() < cur.getStackOrder())
  3808. {
  3809. i++;
  3810. }
  3811. else
  3812. {
  3813. break;
  3814. }
  3815. }
  3816.  
  3817. // Add the new effect to the Stack list in function of its position in the Stack group
  3818. stackQueue.add(i, newStackedEffect);
  3819.  
  3820. // skill.exit() could be used, if the users don't wish to see "effect
  3821. // removed" always when a timer goes off, even if the buff isn't active
  3822. // any more (has been replaced). but then check e.g. npc hold and raid petrify.
  3823. if (Config.EFFECT_CANCELING && !newStackedEffect.isHerbEffect() && stackQueue.size() > 1)
  3824. {
  3825. synchronized (_effects)
  3826. {
  3827.  
  3828. _effects.remove(stackQueue.get(1));
  3829.  
  3830. }
  3831.  
  3832. stackQueue.remove(1);
  3833. }
  3834.  
  3835. queueIterator = null;
  3836.  
  3837. return stackQueue;
  3838. }
  3839.  
  3840. /**
  3841. * Stop and remove L2Effect (including Stack Group management) from L2Character and update client magic icone.<BR>
  3842. * <BR>
  3843. * <B><U> Concept</U> :</B><BR>
  3844. * <BR>
  3845. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>. The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR>
  3846. * <BR>
  3847. * Several same effect can't be used on a L2Character at the same time. Indeed, effects are not stackable and the last cast will replace the previous in progress. More, some effects belong to the same Stack Group (ex WindWald and Haste Potion). If 2 effects of a same group are used at the same
  3848. * time on a L2Character, only the more efficient (identified by its priority order) will be preserve.<BR>
  3849. * <BR>
  3850. * <B><U> Actions</U> :</B><BR>
  3851. * <BR>
  3852. * <li>Remove Func added by this effect from the L2Character Calculator (Stop L2Effect)</li> <li>If the L2Effect belongs to a not empty Stack Group, replace theses Funcs by next stacked effect Funcs</li> <li>Remove the L2Effect from _effects of the L2Character</li> <li>Update active skills in
  3853. * progress icones on player client</li><BR>
  3854. * @param effect the effect
  3855. */
  3856. public final void removeEffect(final L2Effect effect)
  3857. {
  3858. if (effect == null/* || _effects == null */)
  3859. return;
  3860.  
  3861. if (effect.getStackType() == "none")
  3862. {
  3863. // Remove Func added by this effect from the L2Character Calculator
  3864. removeStatsOwner(effect);
  3865. }
  3866. else
  3867. {
  3868. if (_stackedEffects == null)
  3869. return;
  3870.  
  3871. // Get the list of all stacked effects corresponding to the stack type of the L2Effect to add
  3872. final List<L2Effect> stackQueue = _stackedEffects.get(effect.getStackType());
  3873.  
  3874. if (stackQueue == null || stackQueue.size() < 1)
  3875. return;
  3876.  
  3877. // Get the Identifier of the first stacked effect of the Stack group selected
  3878. final L2Effect frontEffect = stackQueue.get(0);
  3879.  
  3880. // Remove the effect from the Stack Group
  3881. final boolean removed = stackQueue.remove(effect);
  3882.  
  3883. if (removed)
  3884. {
  3885. // Check if the first stacked effect was the effect to remove
  3886. if (frontEffect == effect)
  3887. {
  3888. // Remove all its Func objects from the L2Character calculator set
  3889. removeStatsOwner(effect);
  3890.  
  3891. // Check if there's another effect in the Stack Group
  3892. if (stackQueue.size() > 0)
  3893. {
  3894. // Add its list of Funcs to the Calculator set of the L2Character
  3895. if (_effects.contains(stackQueue.get(0)))
  3896. {
  3897.  
  3898. // Add its list of Funcs to the Calculator set of the L2Character
  3899. addStatFuncs(stackQueue.get(0).getStatFuncs());
  3900. // Set the effect to In Use
  3901. stackQueue.get(0).setInUse(true);
  3902.  
  3903. }
  3904.  
  3905. }
  3906. }
  3907. if (stackQueue.isEmpty())
  3908. {
  3909. _stackedEffects.remove(effect.getStackType());
  3910. }
  3911. else
  3912. {
  3913. // Update the Stack Group table _stackedEffects of the L2Character
  3914. _stackedEffects.put(effect.getStackType(), stackQueue);
  3915. }
  3916. }
  3917.  
  3918. }
  3919.  
  3920. synchronized (_effects)
  3921. {
  3922. // Remove the active skill L2effect from _effects of the L2Character
  3923. _effects.remove(effect);
  3924.  
  3925. }
  3926.  
  3927. // Update active skills in progress (In Use and Not In Use because stacked) icones on client
  3928. updateEffectIcons();
  3929. }
  3930.  
  3931. /**
  3932. * Active abnormal effects flags in the binary mask and send Server->Client UserInfo/CharInfo packet.<BR>
  3933. * <BR>
  3934. * @param mask the mask
  3935. */
  3936. public final void startAbnormalEffect(final int mask)
  3937. {
  3938. _AbnormalEffects |= mask;
  3939. updateAbnormalEffect();
  3940. }
  3941.  
  3942. /**
  3943. * immobile start.
  3944. */
  3945. public final void startImmobileUntilAttacked()
  3946. {
  3947. setIsImmobileUntilAttacked(true);
  3948. abortAttack();
  3949. abortCast();
  3950. getAI().notifyEvent(CtrlEvent.EVT_SLEEPING);
  3951. updateAbnormalEffect();
  3952. }
  3953.  
  3954. /**
  3955. * Active the abnormal effect Confused flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  3956. * <BR>
  3957. */
  3958. public final void startConfused()
  3959. {
  3960. setIsConfused(true);
  3961. getAI().notifyEvent(CtrlEvent.EVT_CONFUSED);
  3962. updateAbnormalEffect();
  3963. }
  3964.  
  3965. /**
  3966. * Active the abnormal effect Fake Death flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  3967. * <BR>
  3968. */
  3969. public final void startFakeDeath()
  3970. {
  3971. setIsFallsdown(true);
  3972. setIsFakeDeath(true);
  3973. /* Aborts any attacks/casts if fake dead */
  3974. abortAttack();
  3975. abortCast();
  3976. stopMove(null);
  3977. getAI().notifyEvent(CtrlEvent.EVT_FAKE_DEATH, null);
  3978. broadcastPacket(new ChangeWaitType(this, ChangeWaitType.WT_START_FAKEDEATH));
  3979. }
  3980.  
  3981. /**
  3982. * Active the abnormal effect Fear flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  3983. * <BR>
  3984. */
  3985. public final void startFear()
  3986. {
  3987. setIsAfraid(true);
  3988. getAI().notifyEvent(CtrlEvent.EVT_AFFRAID);
  3989. updateAbnormalEffect();
  3990. }
  3991.  
  3992. /**
  3993. * Active the abnormal effect Muted flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  3994. * <BR>
  3995. */
  3996. public final void startMuted()
  3997. {
  3998. setIsMuted(true);
  3999. /* Aborts any casts if muted */
  4000. abortCast();
  4001. getAI().notifyEvent(CtrlEvent.EVT_MUTED);
  4002. updateAbnormalEffect();
  4003. }
  4004.  
  4005. /**
  4006. * Active the abnormal effect Psychical_Muted flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  4007. * <BR>
  4008. */
  4009. public final void startPsychicalMuted()
  4010. {
  4011. setIsPsychicalMuted(true);
  4012. getAI().notifyEvent(CtrlEvent.EVT_MUTED);
  4013. updateAbnormalEffect();
  4014. }
  4015.  
  4016. /**
  4017. * Active the abnormal effect Root flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  4018. * <BR>
  4019. */
  4020. public final void startRooted()
  4021. {
  4022. setIsRooted(true);
  4023. stopMove(null);
  4024. getAI().notifyEvent(CtrlEvent.EVT_ROOTED, null);
  4025. updateAbnormalEffect();
  4026. }
  4027.  
  4028. /**
  4029. * Active the abnormal effect Sleep flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  4030. * <BR>
  4031. */
  4032. public final void startSleeping()
  4033. {
  4034. setIsSleeping(true);
  4035. /* Aborts any attacks/casts if sleeped */
  4036. abortAttack();
  4037. abortCast();
  4038. stopMove(null);
  4039. getAI().notifyEvent(CtrlEvent.EVT_SLEEPING, null);
  4040. updateAbnormalEffect();
  4041. }
  4042.  
  4043. /**
  4044. * Launch a Stun Abnormal Effect on the L2Character.<BR>
  4045. * <BR>
  4046. * <B><U> Actions</U> :</B><BR>
  4047. * <BR>
  4048. * <li>Calculate the success rate of the Stun Abnormal Effect on this L2Character</li> <li>If Stun succeed, active the abnormal effect Stun flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet</li> <li>If Stun NOT succeed, send a system message Failed to the
  4049. * L2PcInstance attacker</li><BR>
  4050. * <BR>
  4051. */
  4052. public final void startStunning()
  4053. {
  4054. if (isStunned())
  4055. return;
  4056.  
  4057. setIsStunned(true);
  4058. /* Aborts any attacks/casts if stunned */
  4059. abortAttack();
  4060. abortCast();
  4061. getAI().stopFollow(); // Like L2OFF char stop to follow if sticked to another one
  4062. stopMove(null);
  4063. getAI().notifyEvent(CtrlEvent.EVT_STUNNED, null);
  4064. updateAbnormalEffect();
  4065. }
  4066.  
  4067. /**
  4068. * Start betray.
  4069. */
  4070. public final void startBetray()
  4071. {
  4072. setIsBetrayed(true);
  4073. getAI().notifyEvent(CtrlEvent.EVT_BETRAYED, null);
  4074. updateAbnormalEffect();
  4075. }
  4076.  
  4077. /**
  4078. * Stop betray.
  4079. */
  4080. public final void stopBetray()
  4081. {
  4082. stopEffects(L2Effect.EffectType.BETRAY);
  4083. setIsBetrayed(false);
  4084. updateAbnormalEffect();
  4085. }
  4086.  
  4087. /**
  4088. * Modify the abnormal effect map according to the mask.<BR>
  4089. * <BR>
  4090. * @param mask the mask
  4091. */
  4092. public final void stopAbnormalEffect(final int mask)
  4093. {
  4094. _AbnormalEffects &= ~mask;
  4095. updateAbnormalEffect();
  4096. }
  4097.  
  4098. /**
  4099. * Stop all active skills effects in progress on the L2Character.<BR>
  4100. * <BR>
  4101. */
  4102. public final void stopAllEffects()
  4103. {
  4104.  
  4105. final L2Effect[] effects = getAllEffects();
  4106.  
  4107. for (final L2Effect effect : effects)
  4108. {
  4109.  
  4110. if (effect != null)
  4111. {
  4112. effect.exit(true);
  4113. }
  4114. else
  4115. {
  4116. synchronized (_effects)
  4117. {
  4118. _effects.remove(effect);
  4119. }
  4120. }
  4121. }
  4122.  
  4123. if (this instanceof L2PcInstance)
  4124. {
  4125. ((L2PcInstance) this).updateAndBroadcastStatus(2);
  4126. }
  4127.  
  4128. }
  4129.  
  4130. /**
  4131. * Stop immobilization until attacked abnormal L2Effect.<BR>
  4132. * <BR>
  4133. * <B><U> Actions</U> :</B><BR>
  4134. * <BR>
  4135. * <li>Delete a specified/all (if effect=null) immobilization until attacked abnormal L2Effect from L2Character and update client magic icon</li> <li>Set the abnormal effect flag _muted to False</li> <li>Notify the L2Character AI</li> <li>Send Server->Client UserInfo/CharInfo packet</li><BR>
  4136. * <BR>
  4137. * @param effect the effect
  4138. */
  4139. public final void stopImmobileUntilAttacked(final L2Effect effect)
  4140. {
  4141. if (effect == null)
  4142. {
  4143. stopEffects(L2Effect.EffectType.IMMOBILEUNTILATTACKED);
  4144. }
  4145. else
  4146. {
  4147. removeEffect(effect);
  4148. stopSkillEffects(effect.getSkill().getNegateId());
  4149. }
  4150.  
  4151. setIsImmobileUntilAttacked(false);
  4152. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  4153. updateAbnormalEffect();
  4154. }
  4155.  
  4156. /**
  4157. * Stop a specified/all Confused abnormal L2Effect.<BR>
  4158. * <BR>
  4159. * <B><U> Actions</U> :</B><BR>
  4160. * <BR>
  4161. * <li>Delete a specified/all (if effect=null) Confused abnormal L2Effect from L2Character and update client magic icone</li> <li>Set the abnormal effect flag _confused to False</li> <li>Notify the L2Character AI</li> <li>Send Server->Client UserInfo/CharInfo packet</li><BR>
  4162. * <BR>
  4163. * @param effect the effect
  4164. */
  4165. public final void stopConfused(final L2Effect effect)
  4166. {
  4167. if (effect == null)
  4168. {
  4169. stopEffects(L2Effect.EffectType.CONFUSION);
  4170. }
  4171. else
  4172. {
  4173. removeEffect(effect);
  4174. }
  4175.  
  4176. setIsConfused(false);
  4177. getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
  4178. updateAbnormalEffect();
  4179. }
  4180.  
  4181. /**
  4182. * Stop and remove the L2Effects corresponding to the L2Skill Identifier and update client magic icone.<BR>
  4183. * <BR>
  4184. * <B><U> Concept</U> :</B><BR>
  4185. * <BR>
  4186. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>. The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR>
  4187. * <BR>
  4188. * @param skillId the skill id
  4189. */
  4190. public final void stopSkillEffects(final int skillId)
  4191. {
  4192. final L2Effect[] effects = getAllEffects();
  4193.  
  4194. for (final L2Effect effect : effects)
  4195. {
  4196.  
  4197. if (effect == null || effect.getSkill() == null)
  4198. {
  4199.  
  4200. synchronized (_effects)
  4201. {
  4202. _effects.remove(effect);
  4203. }
  4204. continue;
  4205.  
  4206. }
  4207.  
  4208. if (effect.getSkill().getId() == skillId)
  4209. {
  4210. effect.exit(true);
  4211. }
  4212.  
  4213. }
  4214.  
  4215. }
  4216.  
  4217. /**
  4218. * Stop and remove all L2Effect of the selected type (ex : BUFF, DMG_OVER_TIME...) from the L2Character and update client magic icone.<BR>
  4219. * <BR>
  4220. * <B><U> Concept</U> :</B><BR>
  4221. * <BR>
  4222. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>. The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR>
  4223. * <BR>
  4224. * <B><U> Actions</U> :</B><BR>
  4225. * <BR>
  4226. * <li>Remove Func added by this effect from the L2Character Calculator (Stop L2Effect)</li> <li>Remove the L2Effect from _effects of the L2Character</li> <li>Update active skills in progress icones on player client</li><BR>
  4227. * <BR>
  4228. * @param type The type of effect to stop ((ex : BUFF, DMG_OVER_TIME...)
  4229. */
  4230. public final void stopEffects(final L2Effect.EffectType type)
  4231. {
  4232. final L2Effect[] effects = getAllEffects();
  4233.  
  4234. for (final L2Effect effect : effects)
  4235. {
  4236.  
  4237. if (effect == null)
  4238. {
  4239.  
  4240. synchronized (_effects)
  4241. {
  4242. _effects.remove(effect);
  4243. }
  4244. continue;
  4245.  
  4246. }
  4247.  
  4248. // LOGGER.info("Character Effect Type: "+effects[i].getEffectType());
  4249. if (effect.getEffectType() == type)
  4250. {
  4251. effect.exit(true);
  4252. }
  4253.  
  4254. }
  4255.  
  4256. }
  4257.  
  4258. /**
  4259. * Stop and remove the L2Effects corresponding to the L2SkillType and update client magic icon.<BR>
  4260. * <BR>
  4261. * <B><U> Concept</U> :</B><BR>
  4262. * <BR>
  4263. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>. The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR>
  4264. * <BR>
  4265. * @param skillType The L2SkillType of the L2Effect to remove from _effects
  4266. * @param power the power
  4267. */
  4268. public final void stopSkillEffects(final SkillType skillType, final double power)
  4269. {
  4270. final L2Effect[] effects = getAllEffects();
  4271.  
  4272. for (final L2Effect effect : effects)
  4273. {
  4274.  
  4275. if (effect == null || effect.getSkill() == null)
  4276. {
  4277.  
  4278. synchronized (_effects)
  4279. {
  4280. _effects.remove(effect);
  4281. }
  4282. continue;
  4283.  
  4284. }
  4285.  
  4286. if (effect.getSkill().getSkillType() == skillType && (power == 0 || effect.getSkill().getPower() <= power))
  4287. {
  4288. effect.exit(true);
  4289. }
  4290.  
  4291. }
  4292.  
  4293. }
  4294.  
  4295. /**
  4296. * Stop skill effects.
  4297. * @param skillType the skill type
  4298. */
  4299. public final void stopSkillEffects(final SkillType skillType)
  4300. {
  4301. stopSkillEffects(skillType, -1);
  4302. }
  4303.  
  4304. /**
  4305. * Stop a specified/all Fake Death abnormal L2Effect.<BR>
  4306. * <BR>
  4307. * <B><U> Actions</U> :</B><BR>
  4308. * <BR>
  4309. * <li>Delete a specified/all (if effect=null) Fake Death abnormal L2Effect from L2Character and update client magic icone</li> <li>Set the abnormal effect flag _fake_death to False</li> <li>Notify the L2Character AI</li><BR>
  4310. * <BR>
  4311. * @param effect the effect
  4312. */
  4313. public final void stopFakeDeath(final L2Effect effect)
  4314. {
  4315. if (effect == null)
  4316. {
  4317. stopEffects(L2Effect.EffectType.FAKE_DEATH);
  4318. }
  4319. else
  4320. {
  4321. removeEffect(effect);
  4322. }
  4323.  
  4324. setIsFakeDeath(false);
  4325. setIsFallsdown(false);
  4326. // if this is a player instance, start the grace period for this character (grace from mobs only)!
  4327. if (this instanceof L2PcInstance)
  4328. {
  4329. ((L2PcInstance) this).setRecentFakeDeath(true);
  4330. }
  4331.  
  4332. ChangeWaitType revive = new ChangeWaitType(this, ChangeWaitType.WT_STOP_FAKEDEATH);
  4333. broadcastPacket(revive);
  4334. broadcastPacket(new Revive(this));
  4335. getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
  4336.  
  4337. revive = null;
  4338. }
  4339.  
  4340. /**
  4341. * Stop a specified/all Fear abnormal L2Effect.<BR>
  4342. * <BR>
  4343. * <B><U> Actions</U> :</B><BR>
  4344. * <BR>
  4345. * <li>Delete a specified/all (if effect=null) Fear abnormal L2Effect from L2Character and update client magic icone</li> <li>Set the abnormal effect flag _affraid to False</li> <li>Notify the L2Character AI</li> <li>Send Server->Client UserInfo/CharInfo packet</li><BR>
  4346. * <BR>
  4347. * @param effect the effect
  4348. */
  4349. public final void stopFear(final L2Effect effect)
  4350. {
  4351. if (effect == null)
  4352. {
  4353. stopEffects(L2Effect.EffectType.FEAR);
  4354. }
  4355. else
  4356. {
  4357. removeEffect(effect);
  4358. }
  4359.  
  4360. setIsAfraid(false);
  4361. updateAbnormalEffect();
  4362. }
  4363.  
  4364. /**
  4365. * Stop a specified/all Muted abnormal L2Effect.<BR>
  4366. * <BR>
  4367. * <B><U> Actions</U> :</B><BR>
  4368. * <BR>
  4369. * <li>Delete a specified/all (if effect=null) Muted abnormal L2Effect from L2Character and update client magic icone</li> <li>Set the abnormal effect flag _muted to False</li> <li>Notify the L2Character AI</li> <li>Send Server->Client UserInfo/CharInfo packet</li><BR>
  4370. * <BR>
  4371. * @param effect the effect
  4372. */
  4373. public final void stopMuted(final L2Effect effect)
  4374. {
  4375. if (effect == null)
  4376. {
  4377. stopEffects(L2Effect.EffectType.MUTE);
  4378. }
  4379. else
  4380. {
  4381. removeEffect(effect);
  4382. }
  4383.  
  4384. setIsMuted(false);
  4385. updateAbnormalEffect();
  4386. }
  4387.  
  4388. /**
  4389. * Stop psychical muted.
  4390. * @param effect the effect
  4391. */
  4392. public final void stopPsychicalMuted(final L2Effect effect)
  4393. {
  4394. if (effect == null)
  4395. {
  4396. stopEffects(L2Effect.EffectType.PSYCHICAL_MUTE);
  4397. }
  4398. else
  4399. {
  4400. removeEffect(effect);
  4401. }
  4402.  
  4403. setIsPsychicalMuted(false);
  4404. updateAbnormalEffect();
  4405. }
  4406.  
  4407. /**
  4408. * Stop a specified/all Root abnormal L2Effect.<BR>
  4409. * <BR>
  4410. * <B><U> Actions</U> :</B><BR>
  4411. * <BR>
  4412. * <li>Delete a specified/all (if effect=null) Root abnormal L2Effect from L2Character and update client magic icone</li> <li>Set the abnormal effect flag _rooted to False</li> <li>Notify the L2Character AI</li> <li>Send Server->Client UserInfo/CharInfo packet</li><BR>
  4413. * <BR>
  4414. * @param effect the effect
  4415. */
  4416. public final void stopRooting(final L2Effect effect)
  4417. {
  4418. if (effect == null)
  4419. {
  4420. stopEffects(L2Effect.EffectType.ROOT);
  4421. }
  4422. else
  4423. {
  4424. removeEffect(effect);
  4425. }
  4426.  
  4427. setIsRooted(false);
  4428. getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
  4429. updateAbnormalEffect();
  4430. }
  4431.  
  4432. /**
  4433. * Stop a specified/all Sleep abnormal L2Effect.<BR>
  4434. * <BR>
  4435. * <B><U> Actions</U> :</B><BR>
  4436. * <BR>
  4437. * <li>Delete a specified/all (if effect=null) Sleep abnormal L2Effect from L2Character and update client magic icone</li> <li>Set the abnormal effect flag _sleeping to False</li> <li>Notify the L2Character AI</li> <li>Send Server->Client UserInfo/CharInfo packet</li><BR>
  4438. * <BR>
  4439. * @param effect the effect
  4440. */
  4441. public final void stopSleeping(final L2Effect effect)
  4442. {
  4443. if (effect == null)
  4444. {
  4445. stopEffects(L2Effect.EffectType.SLEEP);
  4446. }
  4447. else
  4448. {
  4449. removeEffect(effect);
  4450. }
  4451.  
  4452. setIsSleeping(false);
  4453. getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
  4454. updateAbnormalEffect();
  4455. }
  4456.  
  4457. /**
  4458. * Stop a specified/all Stun abnormal L2Effect.<BR>
  4459. * <BR>
  4460. * <B><U> Actions</U> :</B><BR>
  4461. * <BR>
  4462. * <li>Delete a specified/all (if effect=null) Stun abnormal L2Effect from L2Character and update client magic icone</li> <li>Set the abnormal effect flag _stuned to False</li> <li>Notify the L2Character AI</li> <li>Send Server->Client UserInfo/CharInfo packet</li><BR>
  4463. * <BR>
  4464. * @param effect the effect
  4465. */
  4466. public final void stopStunning(final L2Effect effect)
  4467. {
  4468. if (!isStunned())
  4469. return;
  4470.  
  4471. if (effect == null)
  4472. {
  4473. stopEffects(L2Effect.EffectType.STUN);
  4474. }
  4475. else
  4476. {
  4477. removeEffect(effect);
  4478. }
  4479.  
  4480. setIsStunned(false);
  4481. getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
  4482. updateAbnormalEffect();
  4483. }
  4484.  
  4485. /**
  4486. * Not Implemented.<BR>
  4487. * <BR>
  4488. * <B><U> Overridden in</U> :</B><BR>
  4489. * <BR>
  4490. * <li>L2NPCInstance</li> <li>L2PcInstance</li> <li>L2Summon</li> <li>L2DoorInstance</li><BR>
  4491. * <BR>
  4492. */
  4493. public abstract void updateAbnormalEffect();
  4494.  
  4495. /**
  4496. * Update active skills in progress (In Use and Not In Use because stacked) icones on client.<BR>
  4497. * <BR>
  4498. * <B><U> Concept</U> :</B><BR>
  4499. * <BR>
  4500. * All active skills effects in progress (In Use and Not In Use because stacked) are represented by an icone on the client.<BR>
  4501. * <BR>
  4502. * <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>
  4503. * <BR>
  4504. */
  4505. public final void updateEffectIcons()
  4506. {
  4507. updateEffectIcons(false);
  4508. }
  4509.  
  4510. /**
  4511. * Update effect icons.
  4512. * @param partyOnly the party only
  4513. */
  4514. public final void updateEffectIcons(final boolean partyOnly)
  4515. {
  4516. // Create a L2PcInstance of this if needed
  4517. L2PcInstance player = null;
  4518.  
  4519. if (this instanceof L2PcInstance)
  4520. {
  4521. player = (L2PcInstance) this;
  4522. }
  4523.  
  4524. // Create a L2Summon of this if needed
  4525. L2Summon summon = null;
  4526. if (this instanceof L2Summon)
  4527. {
  4528. summon = (L2Summon) this;
  4529. player = summon.getOwner();
  4530. summon.getOwner().sendPacket(new PetInfo(summon));
  4531. }
  4532.  
  4533. // Create the main packet if needed
  4534. MagicEffectIcons mi = null;
  4535. if (!partyOnly)
  4536. {
  4537. mi = new MagicEffectIcons();
  4538. }
  4539.  
  4540. // Create the party packet if needed
  4541. PartySpelled ps = null;
  4542. if (summon != null)
  4543. {
  4544. ps = new PartySpelled(summon);
  4545. }
  4546. else if (player != null && player.isInParty())
  4547. {
  4548. ps = new PartySpelled(player);
  4549. }
  4550.  
  4551. // Create the olympiad spectator packet if needed
  4552. ExOlympiadSpelledInfo os = null;
  4553. if (player != null && player.isInOlympiadMode())
  4554. {
  4555. os = new ExOlympiadSpelledInfo(player);
  4556. }
  4557.  
  4558. if (mi == null && ps == null && os == null)
  4559. return; // nothing to do (should not happen)
  4560.  
  4561. // Add special effects
  4562. // Note: Now handled by EtcStatusUpdate packet
  4563. // NOTE: CHECK IF THEY WERE EVEN VISIBLE TO OTHERS...
  4564. /*
  4565. * if (player != null && mi != null) { if (player.getWeightPenalty() > 0) mi.addEffect(4270, player.getWeightPenalty(), -1); if (player.getExpertisePenalty() > 0) mi.addEffect(4267, 1, -1); if (player.getMessageRefusal()) mi.addEffect(4269, 1, -1); }
  4566. */
  4567.  
  4568. // Go through all effects if any
  4569. synchronized (_effects)
  4570. {
  4571.  
  4572. for (int i = 0; i < _effects.size(); i++)
  4573. {
  4574.  
  4575. if (_effects.get(i) == null || _effects.get(i).getSkill() == null)
  4576. {
  4577.  
  4578. _effects.remove(i);
  4579. i--;
  4580. continue;
  4581.  
  4582. }
  4583.  
  4584. if (_effects.get(i).getEffectType() == L2Effect.EffectType.CHARGE && player != null)
  4585. {
  4586. // handled by EtcStatusUpdate
  4587. continue;
  4588. }
  4589.  
  4590. if (_effects.get(i).getInUse())
  4591. {
  4592. if (mi != null)
  4593. {
  4594. _effects.get(i).addIcon(mi);
  4595. }
  4596. // Like L2OFF toggle and healing potions must not be showed on party buff list
  4597. if (ps != null && !_effects.get(i).getSkill().isToggle() && !(_effects.get(i).getSkill().getId() == 2031) && !(_effects.get(i).getSkill().getId() == 2037) && !(_effects.get(i).getSkill().getId() == 2032))
  4598. {
  4599. _effects.get(i).addPartySpelledIcon(ps);
  4600. }
  4601. if (os != null)
  4602. {
  4603. _effects.get(i).addOlympiadSpelledIcon(os);
  4604. }
  4605. }
  4606.  
  4607. }
  4608.  
  4609. }
  4610.  
  4611. // Send the packets if needed
  4612. if (mi != null)
  4613. {
  4614. sendPacket(mi);
  4615. }
  4616.  
  4617. if (ps != null && player != null)
  4618. {
  4619. // summon info only needs to go to the owner, not to the whole party
  4620. // player info: if in party, send to all party members except one's self.
  4621. // if not in party, send to self.
  4622. if (player.isInParty() && summon == null)
  4623. {
  4624. player.getParty().broadcastToPartyMembers(player, ps);
  4625. }
  4626. else
  4627. {
  4628. player.sendPacket(ps);
  4629. }
  4630. }
  4631.  
  4632. if (os != null)
  4633. {
  4634. if ((player != null) && Olympiad.getInstance().getSpectators(player.getOlympiadGameId()) != null)
  4635. {
  4636. for (final L2PcInstance spectator : Olympiad.getInstance().getSpectators(player.getOlympiadGameId()))
  4637. {
  4638. if (spectator == null)
  4639. {
  4640. continue;
  4641. }
  4642. spectator.sendPacket(os);
  4643. }
  4644. }
  4645. }
  4646.  
  4647. }
  4648.  
  4649. // Property - Public
  4650. /**
  4651. * Return a map of 16 bits (0x0000) containing all abnormal effect in progress for this L2Character.<BR>
  4652. * <BR>
  4653. * <B><U> Concept</U> :</B><BR>
  4654. * <BR>
  4655. * In Server->Client packet, each effect is represented by 1 bit of the map (ex : BLEEDING = 0x0001 (bit 1), SLEEP = 0x0080 (bit 8)...). The map is calculated by applying a BINARY OR operation on each effect.<BR>
  4656. * <BR>
  4657. * <B><U> Example of use </U> :</B><BR>
  4658. * <BR>
  4659. * <li>Server Packet : CharInfo, NpcInfo, NpcInfoPoly, UserInfo...</li><BR>
  4660. * <BR>
  4661. * @return the abnormal effect
  4662. */
  4663. public int getAbnormalEffect()
  4664. {
  4665. int ae = _AbnormalEffects;
  4666.  
  4667. if (isStunned())
  4668. {
  4669. ae |= ABNORMAL_EFFECT_STUN;
  4670. }
  4671. if (isRooted())
  4672. {
  4673. ae |= ABNORMAL_EFFECT_ROOT;
  4674. }
  4675. if (isSleeping())
  4676. {
  4677. ae |= ABNORMAL_EFFECT_SLEEP;
  4678. }
  4679. if (isConfused())
  4680. {
  4681. ae |= ABNORMAL_EFFECT_CONFUSED;
  4682. }
  4683. if (isMuted())
  4684. {
  4685. ae |= ABNORMAL_EFFECT_MUTED;
  4686. }
  4687. if (isAfraid())
  4688. {
  4689. ae |= ABNORMAL_EFFECT_AFRAID;
  4690. }
  4691. if (isPsychicalMuted())
  4692. {
  4693. ae |= ABNORMAL_EFFECT_MUTED;
  4694. }
  4695.  
  4696. return ae;
  4697. }
  4698.  
  4699. /**
  4700. * Return all active skills effects in progress on the L2Character.<BR>
  4701. * <BR>
  4702. * <B><U> Concept</U> :</B><BR>
  4703. * <BR>
  4704. * All active skills effects in progress on the L2Character are identified in <B>_effects</B>. The Integer key of _effects is the L2Skill Identifier that has created the effect.<BR>
  4705. * <BR>
  4706. * @return A table containing all active skills effect in progress on the L2Character
  4707. */
  4708. public final L2Effect[] getAllEffects()
  4709. {
  4710. synchronized (_effects)
  4711. {
  4712. final L2Effect[] output = _effects.toArray(new L2Effect[_effects.size()]);
  4713.  
  4714. return output;
  4715. }
  4716. }
  4717.  
  4718. /**
  4719. * Return L2Effect in progress on the L2Character corresponding to the L2Skill Identifier.<BR>
  4720. * <BR>
  4721. * <B><U> Concept</U> :</B><BR>
  4722. * <BR>
  4723. * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
  4724. * @param index The L2Skill Identifier of the L2Effect to return from the _effects
  4725. * @return The L2Effect corresponding to the L2Skill Identifier
  4726. */
  4727. public final L2Effect getFirstEffect(final int index)
  4728. {
  4729. final L2Effect[] effects = getAllEffects();
  4730.  
  4731. L2Effect effNotInUse = null;
  4732.  
  4733. for (final L2Effect effect : effects)
  4734. {
  4735.  
  4736. if (effect == null)
  4737. {
  4738. synchronized (_effects)
  4739. {
  4740. _effects.remove(effect);
  4741. }
  4742. continue;
  4743. }
  4744.  
  4745. if (effect.getSkill().getId() == index)
  4746. {
  4747. if (effect.getInUse())
  4748. return effect;
  4749.  
  4750. if (effNotInUse == null)
  4751. effNotInUse = effect;
  4752. }
  4753.  
  4754. }
  4755.  
  4756. return effNotInUse;
  4757.  
  4758. }
  4759.  
  4760. /**
  4761. * Gets the first effect.
  4762. * @param type the type
  4763. * @return the first effect
  4764. */
  4765. public final L2Effect getFirstEffect(final SkillType type)
  4766. {
  4767.  
  4768. final L2Effect[] effects = getAllEffects();
  4769.  
  4770. L2Effect effNotInUse = null;
  4771.  
  4772. for (final L2Effect effect : effects)
  4773. {
  4774.  
  4775. if (effect == null)
  4776. {
  4777. synchronized (_effects)
  4778. {
  4779. _effects.remove(effect);
  4780. }
  4781. continue;
  4782. }
  4783.  
  4784. if (effect.getSkill().getSkillType() == type)
  4785. {
  4786. if (effect.getInUse())
  4787. return effect;
  4788.  
  4789. if (effNotInUse == null)
  4790. effNotInUse = effect;
  4791. }
  4792.  
  4793. }
  4794.  
  4795. return effNotInUse;
  4796.  
  4797. }
  4798.  
  4799. /**
  4800. * Return the first L2Effect in progress on the L2Character created by the L2Skill.<BR>
  4801. * <BR>
  4802. * <B><U> Concept</U> :</B><BR>
  4803. * <BR>
  4804. * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
  4805. * @param skill The L2Skill whose effect must be returned
  4806. * @return The first L2Effect created by the L2Skill
  4807. */
  4808. public final L2Effect getFirstEffect(final L2Skill skill)
  4809. {
  4810. final L2Effect[] effects = getAllEffects();
  4811.  
  4812. L2Effect effNotInUse = null;
  4813.  
  4814. for (final L2Effect effect : effects)
  4815. {
  4816.  
  4817. if (effect == null)
  4818. {
  4819. synchronized (_effects)
  4820. {
  4821. _effects.remove(effect);
  4822. }
  4823. continue;
  4824. }
  4825.  
  4826. if (effect.getSkill() == skill)
  4827. {
  4828. if (effect.getInUse())
  4829. return effect;
  4830.  
  4831. if (effNotInUse == null)
  4832. effNotInUse = effect;
  4833. }
  4834.  
  4835. }
  4836.  
  4837. return effNotInUse;
  4838.  
  4839. }
  4840.  
  4841. /**
  4842. * Return the first L2Effect in progress on the L2Character corresponding to the Effect Type (ex : BUFF, STUN, ROOT...).<BR>
  4843. * <BR>
  4844. * <B><U> Concept</U> :</B><BR>
  4845. * <BR>
  4846. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>. The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR>
  4847. * <BR>
  4848. * @param tp The Effect Type of skills whose effect must be returned
  4849. * @return The first L2Effect corresponding to the Effect Type
  4850. */
  4851. public final L2Effect getFirstEffect(final L2Effect.EffectType tp)
  4852. {
  4853. final L2Effect[] effects = getAllEffects();
  4854.  
  4855. L2Effect effNotInUse = null;
  4856.  
  4857. for (final L2Effect effect : effects)
  4858. {
  4859.  
  4860. if (effect == null)
  4861. {
  4862. synchronized (_effects)
  4863. {
  4864. _effects.remove(effect);
  4865. }
  4866. continue;
  4867. }
  4868.  
  4869. if (effect.getEffectType() == tp)
  4870. {
  4871. if (effect.getInUse())
  4872. return effect;
  4873.  
  4874. if (effNotInUse == null)
  4875. effNotInUse = effect;
  4876. }
  4877.  
  4878. }
  4879.  
  4880. return effNotInUse;
  4881.  
  4882. }
  4883.  
  4884. /**
  4885. * Gets the charge effect.
  4886. * @return the charge effect
  4887. */
  4888. public EffectCharge getChargeEffect()
  4889. {
  4890.  
  4891. final L2Effect effect = getFirstEffect(SkillType.CHARGE);
  4892. if (effect != null)
  4893. return (EffectCharge) effect;
  4894.  
  4895. return null;
  4896.  
  4897. }
  4898.  
  4899. // =========================================================
  4900. // NEED TO ORGANIZE AND MOVE TO PROPER PLACE
  4901. /**
  4902. * This class permit to the L2Character AI to obtain informations and uses L2Character method.
  4903. */
  4904. public class AIAccessor
  4905. {
  4906.  
  4907. /**
  4908. * Instantiates a new aI accessor.
  4909. */
  4910. public AIAccessor()
  4911. {
  4912. // null
  4913. }
  4914.  
  4915. /**
  4916. * Return the L2Character managed by this Accessor AI.<BR>
  4917. * <BR>
  4918. * @return the actor
  4919. */
  4920. public L2Character getActor()
  4921. {
  4922. return L2Character.this;
  4923. }
  4924.  
  4925. /**
  4926. * Accessor to L2Character moveToLocation() method with an interaction area.<BR>
  4927. * <BR>
  4928. * @param x the x
  4929. * @param y the y
  4930. * @param z the z
  4931. * @param offset the offset
  4932. */
  4933. public void moveTo(final int x, final int y, final int z, final int offset)
  4934. {
  4935. moveToLocation(x, y, z, offset);
  4936. }
  4937.  
  4938. /**
  4939. * Accessor to L2Character moveToLocation() method without interaction area.<BR>
  4940. * <BR>
  4941. * @param x the x
  4942. * @param y the y
  4943. * @param z the z
  4944. */
  4945. public void moveTo(final int x, final int y, final int z)
  4946. {
  4947. moveToLocation(x, y, z, 0);
  4948. }
  4949.  
  4950. /**
  4951. * Accessor to L2Character stopMove() method.<BR>
  4952. * <BR>
  4953. * @param pos the pos
  4954. */
  4955. public void stopMove(final L2CharPosition pos)
  4956. {
  4957. L2Character.this.stopMove(pos);
  4958. }
  4959.  
  4960. /**
  4961. * Accessor to L2Character doAttack() method.<BR>
  4962. * <BR>
  4963. * @param target the target
  4964. */
  4965. public void doAttack(final L2Character target)
  4966. {
  4967. L2Character.this.doAttack(target);
  4968. }
  4969.  
  4970. /**
  4971. * Accessor to L2Character doCast() method.<BR>
  4972. * <BR>
  4973. * @param skill the skill
  4974. */
  4975. public void doCast(final L2Skill skill)
  4976. {
  4977. L2Character.this.doCast(skill);
  4978. }
  4979.  
  4980. /**
  4981. * Create a NotifyAITask.<BR>
  4982. * <BR>
  4983. * @param evt the evt
  4984. * @return the notify ai task
  4985. */
  4986. public NotifyAITask newNotifyTask(final CtrlEvent evt)
  4987. {
  4988. return new NotifyAITask(evt);
  4989. }
  4990.  
  4991. /**
  4992. * Cancel the AI.<BR>
  4993. * <BR>
  4994. */
  4995. public void detachAI()
  4996. {
  4997. _ai = null;
  4998. }
  4999. }
  5000.  
  5001. /**
  5002. * This class group all mouvement data.<BR>
  5003. * <BR>
  5004. * <B><U> Data</U> :</B><BR>
  5005. * <BR>
  5006. * <li>_moveTimestamp : Last time position update</li> <li>_xDestination, _yDestination, _zDestination : Position of the destination</li> <li>_xMoveFrom, _yMoveFrom, _zMoveFrom : Position of the origin</li> <li>_moveStartTime : Start time of the movement</li> <li>_ticksToMove : Nb of ticks
  5007. * between the start and the destination</li> <li>_xSpeedTicks, _ySpeedTicks : Speed in unit/ticks</li><BR>
  5008. * <BR>
  5009. */
  5010. public static class MoveData
  5011. {
  5012. // when we retrieve x/y/z we use GameTimeControl.getGameTicks()
  5013. // if we are moving, but move timestamp==gameticks, we don't need
  5014. // to recalculate position
  5015. /** The _move start time. */
  5016. public int _moveStartTime;
  5017.  
  5018. /** The _move timestamp. */
  5019. public int _moveTimestamp;
  5020.  
  5021. /** The _x destination. */
  5022. public int _xDestination;
  5023.  
  5024. /** The _y destination. */
  5025. public int _yDestination;
  5026.  
  5027. /** The _z destination. */
  5028. public int _zDestination;
  5029.  
  5030. /** The _x accurate. */
  5031. public double _xAccurate;
  5032.  
  5033. /** The _y accurate. */
  5034. public double _yAccurate;
  5035.  
  5036. /** The _z accurate. */
  5037. public double _zAccurate;
  5038.  
  5039. /** The _heading. */
  5040. public int _heading;
  5041.  
  5042. /** The disregarding geodata. */
  5043. public boolean disregardingGeodata;
  5044.  
  5045. /** The on geodata path index. */
  5046. public int onGeodataPathIndex;
  5047.  
  5048. /** The geo path. */
  5049. public Node[] geoPath;
  5050.  
  5051. /** The geo path accurate tx. */
  5052. public int geoPathAccurateTx;
  5053.  
  5054. /** The geo path accurate ty. */
  5055. public int geoPathAccurateTy;
  5056.  
  5057. /** The geo path gtx. */
  5058. public int geoPathGtx;
  5059.  
  5060. /** The geo path gty. */
  5061. public int geoPathGty;
  5062. }
  5063.  
  5064. /** Table containing all skillId that are disabled. */
  5065. protected List<Integer> _disabledSkills;
  5066.  
  5067. /** The _all skills disabled. */
  5068. private boolean _allSkillsDisabled;
  5069.  
  5070. // private int _flyingRunSpeed;
  5071. // private int _floatingWalkSpeed;
  5072. // private int _flyingWalkSpeed;
  5073. // private int _floatingRunSpeed;
  5074.  
  5075. /** Movement data of this L2Character. */
  5076. protected MoveData _move;
  5077.  
  5078. /** Orientation of the L2Character. */
  5079. private int _heading;
  5080.  
  5081. /** L2Charcater targeted by the L2Character. */
  5082. private L2Object _target;
  5083.  
  5084. // set by the start of casting, in game ticks
  5085. /** The _cast end time. */
  5086. private int _castEndTime;
  5087.  
  5088. /** The _cast interrupt time. */
  5089. private int _castInterruptTime;
  5090.  
  5091. // set by the start of casting, in game ticks
  5092. /** The _cast potion end time. */
  5093. private int _castPotionEndTime;
  5094.  
  5095. /** The _cast potion interrupt time. */
  5096. @SuppressWarnings("unused")
  5097. private int _castPotionInterruptTime;
  5098.  
  5099. // set by the start of attack, in game ticks
  5100. /** The _attack end time. */
  5101. int _attackEndTime;
  5102.  
  5103. /** The _attacking. */
  5104. private int _attacking;
  5105.  
  5106. /** The _disable bow attack end time. */
  5107. private int _disableBowAttackEndTime;
  5108.  
  5109. /** Table of calculators containing all standard NPC calculator (ex : ACCURACY_COMBAT, EVASION_RATE. */
  5110. private static final Calculator[] NPC_STD_CALCULATOR;
  5111. static
  5112. {
  5113. NPC_STD_CALCULATOR = Formulas.getInstance().getStdNPCCalculators();
  5114. }
  5115.  
  5116. /** The _ai. */
  5117. protected L2CharacterAI _ai;
  5118.  
  5119. /** Future Skill Cast. */
  5120. protected Future<?> _skillCast;
  5121.  
  5122. /** Future Potion Cast. */
  5123. protected Future<?> _potionCast;
  5124.  
  5125. /** Char Coords from Client. */
  5126. private int _clientX;
  5127.  
  5128. /** The _client y. */
  5129. private int _clientY;
  5130.  
  5131. /** The _client z. */
  5132. private int _clientZ;
  5133.  
  5134. /** The _client heading. */
  5135. private int _clientHeading;
  5136.  
  5137. /** List of all QuestState instance that needs to be notified of this character's death. */
  5138. private List<QuestState> _NotifyQuestOfDeathList = new FastList<>();
  5139.  
  5140. /**
  5141. * Add QuestState instance that is to be notified of character's death.<BR>
  5142. * <BR>
  5143. * @param qs The QuestState that subscribe to this event
  5144. */
  5145. public void addNotifyQuestOfDeath(final QuestState qs)
  5146. {
  5147. if (qs == null || _NotifyQuestOfDeathList.contains(qs))
  5148. return;
  5149.  
  5150. _NotifyQuestOfDeathList.add(qs);
  5151. }
  5152.  
  5153. /**
  5154. * Return a list of L2Character that attacked.<BR>
  5155. * <BR>
  5156. * @return the notify quest of death
  5157. */
  5158. public final List<QuestState> getNotifyQuestOfDeath()
  5159. {
  5160. if (_NotifyQuestOfDeathList == null)
  5161. {
  5162. _NotifyQuestOfDeathList = new FastList<>();
  5163. }
  5164.  
  5165. return _NotifyQuestOfDeathList;
  5166. }
  5167.  
  5168. /**
  5169. * Add a Func to the Calculator set of the L2Character.<BR>
  5170. * <BR>
  5171. * <B><U> Concept</U> :</B><BR>
  5172. * <BR>
  5173. * A L2Character owns a table of Calculators called <B>_calculators</B>. Each Calculator (a calculator per state) own a table of Func object. A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...). To reduce cache memory use,
  5174. * L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR>
  5175. * <BR>
  5176. * 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 must be create in its _calculators before addind new Func object.<BR>
  5177. * <BR>
  5178. * <B><U> Actions</U> :</B><BR>
  5179. * <BR>
  5180. * <li>If _calculators is linked to NPC_STD_CALCULATOR, create a copy of NPC_STD_CALCULATOR in _calculators</li> <li>Add the Func object to _calculators</li><BR>
  5181. * <BR>
  5182. * @param f The Func object to add to the Calculator corresponding to the state affected
  5183. */
  5184. public final synchronized void addStatFunc(final Func f)
  5185. {
  5186. if (f == null)
  5187. return;
  5188.  
  5189. // Check if Calculator set is linked to the standard Calculator set of NPC
  5190. if (_calculators == NPC_STD_CALCULATOR)
  5191. {
  5192. // Create a copy of the standard NPC Calculator set
  5193. _calculators = new Calculator[Stats.NUM_STATS];
  5194.  
  5195. for (int i = 0; i < Stats.NUM_STATS; i++)
  5196. {
  5197. if (NPC_STD_CALCULATOR[i] != null)
  5198. {
  5199. _calculators[i] = new Calculator(NPC_STD_CALCULATOR[i]);
  5200. }
  5201. }
  5202. }
  5203.  
  5204. // Select the Calculator of the affected state in the Calculator set
  5205. final int stat = f.stat.ordinal();
  5206.  
  5207. if (_calculators[stat] == null)
  5208. {
  5209. _calculators[stat] = new Calculator();
  5210. }
  5211.  
  5212. // Add the Func to the calculator corresponding to the state
  5213. _calculators[stat].addFunc(f);
  5214.  
  5215. }
  5216.  
  5217. /**
  5218. * Add a list of Funcs to the Calculator set of the L2Character.<BR>
  5219. * <BR>
  5220. * <B><U> Concept</U> :</B><BR>
  5221. * <BR>
  5222. * A L2Character owns a table of Calculators called <B>_calculators</B>. Each Calculator (a calculator per state) own a table of Func object. A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...). <BR>
  5223. * <BR>
  5224. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method is ONLY for L2PcInstance</B></FONT><BR>
  5225. * <BR>
  5226. * <B><U> Example of use </U> :</B><BR>
  5227. * <BR>
  5228. * <li>Equip an item from inventory</li> <li>Learn a new passive skill</li> <li>Use an active skill</li><BR>
  5229. * <BR>
  5230. * @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
  5231. */
  5232. public final synchronized void addStatFuncs(final Func[] funcs)
  5233. {
  5234.  
  5235. FastList<Stats> modifiedStats = new FastList<>();
  5236.  
  5237. for (final Func f : funcs)
  5238. {
  5239. modifiedStats.add(f.stat);
  5240. addStatFunc(f);
  5241. }
  5242.  
  5243. broadcastModifiedStats(modifiedStats);
  5244.  
  5245. modifiedStats = null;
  5246. }
  5247.  
  5248. /**
  5249. * Remove a Func from the Calculator set of the L2Character.<BR>
  5250. * <BR>
  5251. * <B><U> Concept</U> :</B><BR>
  5252. * <BR>
  5253. * A L2Character owns a table of Calculators called <B>_calculators</B>. Each Calculator (a calculator per state) own a table of Func object. A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...). To reduce cache memory use,
  5254. * L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR>
  5255. * <BR>
  5256. * 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 must be create in its _calculators before addind new Func object.<BR>
  5257. * <BR>
  5258. * <B><U> Actions</U> :</B><BR>
  5259. * <BR>
  5260. * <li>Remove the Func object from _calculators</li><BR>
  5261. * <BR>
  5262. * <li>If L2Character is a L2NPCInstance and _calculators is equal to NPC_STD_CALCULATOR, free cache memory and just create a link on NPC_STD_CALCULATOR in _calculators</li><BR>
  5263. * <BR>
  5264. * @param f The Func object to remove from the Calculator corresponding to the state affected
  5265. */
  5266. public final synchronized void removeStatFunc(final Func f)
  5267. {
  5268. if (f == null)
  5269. return;
  5270.  
  5271. // Select the Calculator of the affected state in the Calculator set
  5272. final int stat = f.stat.ordinal();
  5273.  
  5274. if (_calculators[stat] == null)
  5275. return;
  5276.  
  5277. // Remove the Func object from the Calculator
  5278. _calculators[stat].removeFunc(f);
  5279.  
  5280. if (_calculators[stat].size() == 0)
  5281. {
  5282. _calculators[stat] = null;
  5283. }
  5284.  
  5285. // If possible, free the memory and just create a link on NPC_STD_CALCULATOR
  5286. if (this instanceof L2NpcInstance)
  5287. {
  5288. int i = 0;
  5289.  
  5290. for (; i < Stats.NUM_STATS; i++)
  5291. {
  5292. if (!Calculator.equalsCals(_calculators[i], NPC_STD_CALCULATOR[i]))
  5293. {
  5294. break;
  5295. }
  5296. }
  5297.  
  5298. if (i >= Stats.NUM_STATS)
  5299. {
  5300. _calculators = NPC_STD_CALCULATOR;
  5301. }
  5302. }
  5303. }
  5304.  
  5305. /**
  5306. * Remove a list of Funcs from the Calculator set of the L2PcInstance.<BR>
  5307. * <BR>
  5308. * <B><U> Concept</U> :</B><BR>
  5309. * <BR>
  5310. * A L2Character owns a table of Calculators called <B>_calculators</B>. Each Calculator (a calculator per state) own a table of Func object. A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...). <BR>
  5311. * <BR>
  5312. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method is ONLY for L2PcInstance</B></FONT><BR>
  5313. * <BR>
  5314. * <B><U> Example of use </U> :</B><BR>
  5315. * <BR>
  5316. * <li>Unequip an item from inventory</li> <li>Stop an active skill</li><BR>
  5317. * <BR>
  5318. * @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
  5319. */
  5320. public final synchronized void removeStatFuncs(final Func[] funcs)
  5321. {
  5322.  
  5323. FastList<Stats> modifiedStats = new FastList<>();
  5324.  
  5325. for (final Func f : funcs)
  5326. {
  5327. modifiedStats.add(f.stat);
  5328. removeStatFunc(f);
  5329. }
  5330.  
  5331. broadcastModifiedStats(modifiedStats);
  5332.  
  5333. modifiedStats = null;
  5334. }
  5335.  
  5336. /**
  5337. * Remove all Func objects with the selected owner from the Calculator set of the L2Character.<BR>
  5338. * <BR>
  5339. * <B><U> Concept</U> :</B><BR>
  5340. * <BR>
  5341. * A L2Character owns a table of Calculators called <B>_calculators</B>. Each Calculator (a calculator per state) own a table of Func object. A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...). To reduce cache memory use,
  5342. * L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR>
  5343. * <BR>
  5344. * 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 must be create in its _calculators before addind new Func object.<BR>
  5345. * <BR>
  5346. * <B><U> Actions</U> :</B><BR>
  5347. * <BR>
  5348. * <li>Remove all Func objects of the selected owner from _calculators</li><BR>
  5349. * <BR>
  5350. * <li>If L2Character is a L2NPCInstance and _calculators is equal to NPC_STD_CALCULATOR, free cache memory and just create a link on NPC_STD_CALCULATOR in _calculators</li><BR>
  5351. * <BR>
  5352. * <B><U> Example of use </U> :</B><BR>
  5353. * <BR>
  5354. * <li>Unequip an item from inventory</li> <li>Stop an active skill</li><BR>
  5355. * <BR>
  5356. * @param owner The Object(Skill, Item...) that has created the effect
  5357. */
  5358. public final void removeStatsOwner(final Object owner)
  5359. {
  5360. FastList<Stats> modifiedStats = null;
  5361.  
  5362. int i = 0;
  5363. // Go through the Calculator set
  5364. synchronized (_calculators)
  5365. {
  5366. for (final Calculator calc : _calculators)
  5367. {
  5368. if (calc != null)
  5369. {
  5370. // Delete all Func objects of the selected owner
  5371. if (modifiedStats != null)
  5372. {
  5373. modifiedStats.addAll(calc.removeOwner(owner));
  5374. }
  5375. else
  5376. {
  5377. modifiedStats = calc.removeOwner(owner);
  5378. }
  5379.  
  5380. if (calc.size() == 0)
  5381. {
  5382. _calculators[i] = null;
  5383. }
  5384. }
  5385. i++;
  5386. }
  5387.  
  5388. // If possible, free the memory and just create a link on NPC_STD_CALCULATOR
  5389. if (this instanceof L2NpcInstance)
  5390. {
  5391. i = 0;
  5392. for (; i < Stats.NUM_STATS; i++)
  5393. {
  5394. if (!Calculator.equalsCals(_calculators[i], NPC_STD_CALCULATOR[i]))
  5395. {
  5396. break;
  5397. }
  5398. }
  5399.  
  5400. if (i >= Stats.NUM_STATS)
  5401. {
  5402. _calculators = NPC_STD_CALCULATOR;
  5403. }
  5404. }
  5405.  
  5406. if (owner instanceof L2Effect && !((L2Effect) owner).preventExitUpdate)
  5407. {
  5408. broadcastModifiedStats(modifiedStats);
  5409. }
  5410. }
  5411.  
  5412. modifiedStats = null;
  5413. }
  5414.  
  5415. /**
  5416. * Broadcast modified stats.
  5417. * @param stats the stats
  5418. */
  5419. public void broadcastModifiedStats(final FastList<Stats> stats)
  5420. {
  5421. if (stats == null || stats.isEmpty())
  5422. return;
  5423.  
  5424. boolean broadcastFull = false;
  5425. boolean otherStats = false;
  5426. StatusUpdate su = null;
  5427.  
  5428. for (final Stats stat : stats)
  5429. {
  5430. if (stat == Stats.POWER_ATTACK_SPEED)
  5431. {
  5432. if (su == null)
  5433. {
  5434. su = new StatusUpdate(getObjectId());
  5435. }
  5436.  
  5437. su.addAttribute(StatusUpdate.ATK_SPD, getPAtkSpd());
  5438. }
  5439. else if (stat == Stats.MAGIC_ATTACK_SPEED)
  5440. {
  5441. if (su == null)
  5442. {
  5443. su = new StatusUpdate(getObjectId());
  5444. }
  5445.  
  5446. su.addAttribute(StatusUpdate.CAST_SPD, getMAtkSpd());
  5447. }
  5448. // else if (stat==Stats.MAX_HP) //
  5449. // {
  5450. // if (su == null) su = new StatusUpdate(getObjectId());
  5451. // su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
  5452. // }
  5453. else if (stat == Stats.MAX_CP)
  5454. {
  5455. if (this instanceof L2PcInstance)
  5456. {
  5457. if (su == null)
  5458. {
  5459. su = new StatusUpdate(getObjectId());
  5460. }
  5461.  
  5462. su.addAttribute(StatusUpdate.MAX_CP, getMaxCp());
  5463. }
  5464. }
  5465. // else if (stat==Stats.MAX_MP)
  5466. // {
  5467. // if (su == null) su = new StatusUpdate(getObjectId());
  5468. // su.addAttribute(StatusUpdate.MAX_MP, getMaxMp());
  5469. // }
  5470. else if (stat == Stats.RUN_SPEED)
  5471. {
  5472. broadcastFull = true;
  5473. }
  5474. else
  5475. {
  5476. otherStats = true;
  5477. }
  5478. }
  5479.  
  5480. if (this instanceof L2PcInstance)
  5481. {
  5482. if (broadcastFull)
  5483. {
  5484. ((L2PcInstance) this).updateAndBroadcastStatus(2);
  5485. }
  5486. else
  5487. {
  5488. if (otherStats)
  5489. {
  5490. ((L2PcInstance) this).updateAndBroadcastStatus(1);
  5491. if (su != null)
  5492. {
  5493. for (final L2PcInstance player : getKnownList().getKnownPlayers().values())
  5494. {
  5495. try
  5496. {
  5497. player.sendPacket(su);
  5498. }
  5499. catch (final NullPointerException e)
  5500. {
  5501. e.printStackTrace();
  5502. }
  5503. }
  5504. }
  5505. }
  5506. else if (su != null)
  5507. {
  5508. broadcastPacket(su);
  5509. }
  5510. }
  5511. }
  5512. else if (this instanceof L2NpcInstance)
  5513. {
  5514. if (broadcastFull && getKnownList() != null && getKnownList().getKnownPlayers() != null)
  5515. {
  5516. for (final L2PcInstance player : getKnownList().getKnownPlayers().values())
  5517. if (player != null)
  5518. {
  5519. player.sendPacket(new NpcInfo((L2NpcInstance) this, player));
  5520. }
  5521. }
  5522. else if (su != null)
  5523. {
  5524. broadcastPacket(su);
  5525. }
  5526. }
  5527. else if (this instanceof L2Summon)
  5528. {
  5529. if (broadcastFull)
  5530. {
  5531. for (final L2PcInstance player : getKnownList().getKnownPlayers().values())
  5532. if (player != null)
  5533. {
  5534. player.sendPacket(new NpcInfo((L2Summon) this, player));
  5535. }
  5536. }
  5537. else if (su != null)
  5538. {
  5539. broadcastPacket(su);
  5540. }
  5541. }
  5542. else if (su != null)
  5543. {
  5544. broadcastPacket(su);
  5545. }
  5546.  
  5547. su = null;
  5548. }
  5549.  
  5550. /**
  5551. * Return the orientation of the L2Character.<BR>
  5552. * <BR>
  5553. * @return the heading
  5554. */
  5555. public final int getHeading()
  5556. {
  5557. return _heading;
  5558. }
  5559.  
  5560. /**
  5561. * Set the orientation of the L2Character.<BR>
  5562. * <BR>
  5563. * @param heading the new heading
  5564. */
  5565. public final void setHeading(final int heading)
  5566. {
  5567. _heading = heading;
  5568. }
  5569.  
  5570. /**
  5571. * Return the X destination of the L2Character or the X position if not in movement.<BR>
  5572. * <BR>
  5573. * @return the client x
  5574. */
  5575. public final int getClientX()
  5576. {
  5577. return _clientX;
  5578. }
  5579.  
  5580. /**
  5581. * Gets the client y.
  5582. * @return the client y
  5583. */
  5584. public final int getClientY()
  5585. {
  5586. return _clientY;
  5587. }
  5588.  
  5589. /**
  5590. * Gets the client z.
  5591. * @return the client z
  5592. */
  5593. public final int getClientZ()
  5594. {
  5595. return _clientZ;
  5596. }
  5597.  
  5598. /**
  5599. * Gets the client heading.
  5600. * @return the client heading
  5601. */
  5602. public final int getClientHeading()
  5603. {
  5604. return _clientHeading;
  5605. }
  5606.  
  5607. /**
  5608. * Sets the client x.
  5609. * @param val the new client x
  5610. */
  5611. public final void setClientX(final int val)
  5612. {
  5613. _clientX = val;
  5614. }
  5615.  
  5616. /**
  5617. * Sets the client y.
  5618. * @param val the new client y
  5619. */
  5620. public final void setClientY(final int val)
  5621. {
  5622. _clientY = val;
  5623. }
  5624.  
  5625. /**
  5626. * Sets the client z.
  5627. * @param val the new client z
  5628. */
  5629. public final void setClientZ(final int val)
  5630. {
  5631. _clientZ = val;
  5632. }
  5633.  
  5634. /**
  5635. * Sets the client heading.
  5636. * @param val the new client heading
  5637. */
  5638. public final void setClientHeading(final int val)
  5639. {
  5640. _clientHeading = val;
  5641. }
  5642.  
  5643. /**
  5644. * Gets the xdestination.
  5645. * @return the xdestination
  5646. */
  5647. public final int getXdestination()
  5648. {
  5649. final MoveData m = _move;
  5650.  
  5651. if (m != null)
  5652. return m._xDestination;
  5653.  
  5654. return getX();
  5655. }
  5656.  
  5657. /**
  5658. * Return the Y destination of the L2Character or the Y position if not in movement.<BR>
  5659. * <BR>
  5660. * @return the ydestination
  5661. */
  5662. public final int getYdestination()
  5663. {
  5664. final MoveData m = _move;
  5665.  
  5666. if (m != null)
  5667. return m._yDestination;
  5668.  
  5669. return getY();
  5670. }
  5671.  
  5672. /**
  5673. * Return the Z destination of the L2Character or the Z position if not in movement.<BR>
  5674. * <BR>
  5675. * @return the zdestination
  5676. */
  5677. public final int getZdestination()
  5678. {
  5679. final MoveData m = _move;
  5680.  
  5681. if (m != null)
  5682. return m._zDestination;
  5683.  
  5684. return getZ();
  5685. }
  5686.  
  5687. /**
  5688. * Return True if the L2Character is in combat.<BR>
  5689. * <BR>
  5690. * @return true, if is in combat
  5691. */
  5692. public boolean isInCombat()
  5693. {
  5694. return (getAI().getAttackTarget() != null || getAI().isAutoAttacking());
  5695. }
  5696.  
  5697. /**
  5698. * Return True if the L2Character is moving.<BR>
  5699. * <BR>
  5700. * @return true, if is moving
  5701. */
  5702. public final boolean isMoving()
  5703. {
  5704. return _move != null;
  5705. }
  5706.  
  5707. /**
  5708. * Return True if the L2Character is travelling a calculated path.<BR>
  5709. * <BR>
  5710. * @return true, if is on geodata path
  5711. */
  5712. public final boolean isOnGeodataPath()
  5713. {
  5714. final MoveData move = _move;
  5715.  
  5716. if (move == null)
  5717. return false;
  5718.  
  5719. try
  5720. {
  5721. if (move.onGeodataPathIndex == -1)
  5722. return false;
  5723.  
  5724. if (move.onGeodataPathIndex == move.geoPath.length - 1)
  5725. return false;
  5726. }
  5727. catch (final NullPointerException e)
  5728. {
  5729. e.printStackTrace();
  5730. return false;
  5731. }
  5732.  
  5733. return true;
  5734. }
  5735.  
  5736. /**
  5737. * Return True if the L2Character is casting.<BR>
  5738. * <BR>
  5739. * @return true, if is casting now
  5740. */
  5741. public final boolean isCastingNow()
  5742. {
  5743.  
  5744. final L2Effect mog = getFirstEffect(L2Effect.EffectType.SIGNET_GROUND);
  5745. if (mog != null)
  5746. {
  5747. return true;
  5748. }
  5749.  
  5750. return _castEndTime > GameTimeController.getGameTicks();
  5751. }
  5752.  
  5753. /**
  5754. * Return True if the L2Character is casting.<BR>
  5755. * <BR>
  5756. * @return true, if is casting potion now
  5757. */
  5758. public final boolean isCastingPotionNow()
  5759. {
  5760. return _castPotionEndTime > GameTimeController.getGameTicks();
  5761. }
  5762.  
  5763. /**
  5764. * Return True if the cast of the L2Character can be aborted.<BR>
  5765. * <BR>
  5766. * @return true, if successful
  5767. */
  5768. public final boolean canAbortCast()
  5769. {
  5770. return _castInterruptTime > GameTimeController.getGameTicks();
  5771. }
  5772.  
  5773. /**
  5774. * Return True if the L2Character is attacking.<BR>
  5775. * <BR>
  5776. * @return true, if is attacking now
  5777. */
  5778. public final boolean isAttackingNow()
  5779. {
  5780. return _attackEndTime > GameTimeController.getGameTicks();
  5781. }
  5782.  
  5783. /**
  5784. * Return True if the L2Character has aborted its attack.<BR>
  5785. * <BR>
  5786. * @return true, if is attack aborted
  5787. */
  5788. public final boolean isAttackAborted()
  5789. {
  5790. return _attacking <= 0;
  5791. }
  5792.  
  5793. /**
  5794. * Abort the attack of the L2Character and send Server->Client ActionFailed packet.<BR>
  5795. * <BR>
  5796. * see com.l2jfrozen.gameserver.model.L2Character
  5797. */
  5798. public final void abortAttack()
  5799. {
  5800. if (isAttackingNow())
  5801. {
  5802. _attacking = 0;
  5803. sendPacket(ActionFailed.STATIC_PACKET);
  5804. }
  5805. }
  5806.  
  5807. /**
  5808. * Returns body part (paperdoll slot) we are targeting right now.
  5809. * @return the attacking body part
  5810. */
  5811. public final int getAttackingBodyPart()
  5812. {
  5813. return _attacking;
  5814. }
  5815.  
  5816. /**
  5817. * Abort the cast of the L2Character and send Server->Client MagicSkillCanceld/ActionFailed packet.<BR>
  5818. * <BR>
  5819. */
  5820. public final void abortCast()
  5821. {
  5822. abortCast(false);
  5823.  
  5824. }
  5825.  
  5826. /**
  5827. * Abort the cast of the L2Character and send Server->Client MagicSkillCanceld/ActionFailed packet.<BR>
  5828. * <BR>
  5829. * @param force the force
  5830. */
  5831. public final void abortCast(final boolean force)
  5832. {
  5833. if (isCastingNow() || force)
  5834. {
  5835. _castEndTime = 0;
  5836. _castInterruptTime = 0;
  5837.  
  5838. if (_skillCast != null)
  5839. {
  5840. _skillCast.cancel(true);
  5841. _skillCast = null;
  5842. }
  5843.  
  5844. if (getForceBuff() != null)
  5845. {
  5846. getForceBuff().onCastAbort();
  5847. }
  5848.  
  5849. final L2Effect mog = getFirstEffect(L2Effect.EffectType.SIGNET_GROUND);
  5850. if (mog != null)
  5851. {
  5852. mog.exit(true);
  5853. }
  5854.  
  5855. // cancels the skill hit scheduled task
  5856. enableAllSkills(); // re-enables the skills
  5857. if (this instanceof L2PcInstance)
  5858. {
  5859. getAI().notifyEvent(CtrlEvent.EVT_FINISH_CASTING); // setting back previous intention
  5860. }
  5861.  
  5862. broadcastPacket(new MagicSkillCanceld(getObjectId())); // broadcast packet to stop animations client-side
  5863. sendPacket(ActionFailed.STATIC_PACKET); // send an "action failed" packet to the caster
  5864.  
  5865. }
  5866. /*
  5867. * can't abort potion cast if(isCastingPotionNow()){ _castPotionEndTime = 0; _castPotionInterruptTime = 0; if(_potionCast != null) { _potionCast.cancel(true); _potionCast = null; } }
  5868. */
  5869. }
  5870.  
  5871. /**
  5872. * Update the position of the L2Character during a movement and return True if the movement is finished.<BR>
  5873. * <BR>
  5874. * <B><U> Concept</U> :</B><BR>
  5875. * <BR>
  5876. * 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. 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>
  5877. * <BR>
  5878. * 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. Note, that the current server position can differe from the current client position even if each movement is straight foward. That's
  5879. * why, client send regularly a Client->Server ValidatePosition packet to eventually correct the gap on the server. But, it's always the server position that is used in range calculation.<BR>
  5880. * <BR>
  5881. * 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>
  5882. * <BR>
  5883. * <FONT COLOR=#FF0000><B> <U>Caution</U> : The current Z position is obtained FROM THE CLIENT by the Client->Server ValidatePosition Packet. But x and y positions must be calculated to avoid that players try to modify their movement speed.</B></FONT><BR>
  5884. * <BR>
  5885. * @param gameTicks Nb of ticks since the server start
  5886. * @return True if the movement is finished
  5887. */
  5888. public boolean updatePosition(final int gameTicks)
  5889. {
  5890. // Get movement data
  5891. final MoveData m = _move;
  5892.  
  5893. if (m == null)
  5894. return true;
  5895.  
  5896. if (!isVisible())
  5897. {
  5898. _move = null;
  5899. return true;
  5900. }
  5901.  
  5902. if (m._moveTimestamp == 0)
  5903. {
  5904. m._moveTimestamp = m._moveStartTime;
  5905. m._xAccurate = getX();
  5906. m._yAccurate = getY();
  5907. }
  5908.  
  5909. // Check if the position has alreday be calculated
  5910. if (m._moveTimestamp == gameTicks)
  5911. return false;
  5912.  
  5913. final int xPrev = getX();
  5914. final int yPrev = getY();
  5915. int zPrev = getZ();
  5916.  
  5917. double dx, dy, dz, distFraction;
  5918. if (Config.COORD_SYNCHRONIZE == 1)
  5919. // the only method that can modify x,y while moving (otherwise _move would/should be set null)
  5920. {
  5921. dx = m._xDestination - xPrev;
  5922. dy = m._yDestination - yPrev;
  5923. }
  5924. else
  5925. // otherwise we need saved temporary values to avoid rounding errors
  5926. {
  5927. dx = m._xDestination - m._xAccurate;
  5928. dy = m._yDestination - m._yAccurate;
  5929. }
  5930. // Z coordinate will follow geodata or client values
  5931. if (Config.GEODATA > 0 && Config.COORD_SYNCHRONIZE == 2 && !isFlying() && !isInsideZone(L2Character.ZONE_WATER) && !m.disregardingGeodata && GameTimeController.getGameTicks() % 10 == 0 // once a second to reduce possible cpu load
  5932. && !(this instanceof L2BoatInstance))
  5933. {
  5934. final short geoHeight = GeoData.getInstance().getSpawnHeight(xPrev, yPrev, zPrev - 30, zPrev + 30, getObjectId());
  5935. dz = m._zDestination - geoHeight;
  5936. // quite a big difference, compare to validatePosition packet
  5937. if (this instanceof L2PcInstance && Math.abs(((L2PcInstance) this).getClientZ() - geoHeight) > 200 && Math.abs(((L2PcInstance) this).getClientZ() - geoHeight) < 1500)
  5938. {
  5939. dz = m._zDestination - zPrev; // allow diff
  5940. }
  5941. else if (isInCombat() && Math.abs(dz) > 200 && dx * dx + dy * dy < 40000) // allow mob to climb up to pcinstance
  5942. {
  5943. dz = m._zDestination - zPrev; // climbing
  5944. }
  5945. else
  5946. {
  5947. zPrev = geoHeight;
  5948. }
  5949. }
  5950. else
  5951. {
  5952. dz = m._zDestination - zPrev;
  5953. }
  5954.  
  5955. float speed;
  5956. if (this instanceof L2BoatInstance)
  5957. {
  5958. speed = ((L2BoatInstance) this).boatSpeed;
  5959. }
  5960. else
  5961. {
  5962. speed = getStat().getMoveSpeed();
  5963. }
  5964.  
  5965. final double distPassed = speed * (gameTicks - m._moveTimestamp) / GameTimeController.TICKS_PER_SECOND;
  5966. if (dx * dx + dy * dy < 10000 && dz * dz > 2500) // close enough, allows error between client and server geodata if it cannot be avoided
  5967. {
  5968. distFraction = distPassed / Math.sqrt(dx * dx + dy * dy);
  5969. }
  5970. else
  5971. {
  5972. distFraction = distPassed / Math.sqrt(dx * dx + dy * dy + dz * dz);
  5973. }
  5974.  
  5975. // if (Config.DEVELOPER) LOGGER.warn("Move Ticks:" + (gameTicks - m._moveTimestamp) + ", distPassed:" + distPassed + ", distFraction:" + distFraction);
  5976.  
  5977. if (distFraction > 1) // already there
  5978. {
  5979. // Set the position of the L2Character to the destination
  5980. super.getPosition().setXYZ(m._xDestination, m._yDestination, m._zDestination);
  5981. if (this instanceof L2BoatInstance)
  5982. {
  5983. ((L2BoatInstance) this).updatePeopleInTheBoat(m._xDestination, m._yDestination, m._zDestination);
  5984. }
  5985. else
  5986. {
  5987. revalidateZone();
  5988. }
  5989. }
  5990. else
  5991. {
  5992. m._xAccurate += dx * distFraction;
  5993. m._yAccurate += dy * distFraction;
  5994.  
  5995. // Set the position of the L2Character to estimated after parcial move
  5996. super.getPosition().setXYZ((int) m._xAccurate, (int) m._yAccurate, zPrev + (int) (dz * distFraction + 0.5));
  5997. if (this instanceof L2BoatInstance)
  5998. {
  5999. ((L2BoatInstance) this).updatePeopleInTheBoat((int) m._xAccurate, (int) m._yAccurate, zPrev + (int) (dz * distFraction + 0.5));
  6000. }
  6001. else
  6002. {
  6003. revalidateZone();
  6004. }
  6005. }
  6006.  
  6007. // Set the timer of last position update to now
  6008. m._moveTimestamp = gameTicks;
  6009.  
  6010. return distFraction > 1;
  6011. }
  6012.  
  6013. /**
  6014. * Revalidate zone.
  6015. */
  6016. public void revalidateZone()
  6017. {
  6018. if (getWorldRegion() == null)
  6019. return;
  6020.  
  6021. getWorldRegion().revalidateZones(this);
  6022. }
  6023.  
  6024. /**
  6025. * Stop movement of the L2Character (Called by AI Accessor only).<BR>
  6026. * <BR>
  6027. * <B><U> Actions</U> :</B><BR>
  6028. * <BR>
  6029. * <li>Delete movement data of the L2Character</li> <li>Set the current position (x,y,z), its current L2WorldRegion if necessary and its heading</li> <li>Remove the L2Object object from _gmList** of GmListTable</li> <li>Remove object from _knownObjects and _knownPlayer* of all surrounding
  6030. * L2WorldRegion L2Characters</li><BR>
  6031. * <BR>
  6032. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T send Server->Client packet StopMove/StopRotation </B></FONT><BR>
  6033. * <BR>
  6034. * @param pos the pos
  6035. */
  6036. public void stopMove(final L2CharPosition pos)
  6037. {
  6038. stopMove(pos, true);
  6039. }
  6040.  
  6041. /**
  6042. * TODO: test broadcast head packets ffro !in boat.
  6043. * @param pos the pos
  6044. * @param updateKnownObjects the update known objects
  6045. */
  6046. public void stopMove(final L2CharPosition pos, final boolean updateKnownObjects)
  6047. {
  6048. // Delete movement data of the L2Character
  6049. _move = null;
  6050.  
  6051. // Set AI_INTENTION_IDLE
  6052. if (this instanceof L2PcInstance && getAI() != null)
  6053. ((L2PcInstance) this).getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  6054.  
  6055. // Set the current position (x,y,z), its current L2WorldRegion if necessary and its heading
  6056. // All data are contained in a L2CharPosition object
  6057. if (pos != null)
  6058. {
  6059. getPosition().setXYZ(pos.x, pos.y, GeoData.getInstance().getHeight(pos.x, pos.y, pos.z));
  6060. setHeading(pos.heading);
  6061.  
  6062. if (this instanceof L2PcInstance)
  6063. {
  6064. ((L2PcInstance) this).revalidateZone(true);
  6065.  
  6066. if (((L2PcInstance) this).isInBoat())
  6067. broadcastPacket(new ValidateLocationInVehicle(this));
  6068. }
  6069. }
  6070.  
  6071. broadcastPacket(new StopMove(this));
  6072.  
  6073. if (updateKnownObjects)
  6074. ThreadPoolManager.getInstance().executeTask(new KnownListAsynchronousUpdateTask(this));
  6075. }
  6076.  
  6077. /**
  6078. * Target a L2Object (add the target to the L2Character _target, _knownObject and L2Character to _KnownObject of the L2Object).<BR>
  6079. * <BR>
  6080. * <B><U> Concept</U> :</B><BR>
  6081. * <BR>
  6082. * The L2Object (including L2Character) targeted is identified in <B>_target</B> of the L2Character<BR>
  6083. * <BR>
  6084. * <B><U> Actions</U> :</B><BR>
  6085. * <BR>
  6086. * <li>Set the _target of L2Character to L2Object</li> <li>If necessary, add L2Object to _knownObject of the L2Character</li> <li>If necessary, add L2Character to _KnownObject of the L2Object</li> <li>If object==null, cancel Attak or Cast</li><BR>
  6087. * <BR>
  6088. * <B><U> Overriden in </U> :</B><BR>
  6089. * <BR>
  6090. * <li>L2PcInstance : Remove the L2PcInstance from the old target _statusListener and add it to the new target if it was a L2Character</li><BR>
  6091. * <BR>
  6092. * @param object L2object to target
  6093. */
  6094. public void setTarget(L2Object object)
  6095. {
  6096. if (object != null && !object.isVisible())
  6097. {
  6098. object = null;
  6099. }
  6100.  
  6101. if (object != null && object != _target)
  6102. {
  6103. getKnownList().addKnownObject(object);
  6104. object.getKnownList().addKnownObject(this);
  6105. }
  6106.  
  6107. // If object==null, Cancel Attak or Cast
  6108. if (object == null)
  6109. {
  6110. if (_target != null)
  6111. {
  6112. final TargetUnselected my = new TargetUnselected(this);
  6113.  
  6114. // No need to broadcast the packet to all players
  6115. if (this instanceof L2PcInstance)
  6116. {
  6117. // Send packet just to me and to party, not to any other that does not use the information
  6118. if (!this.isInParty())
  6119. {
  6120. this.sendPacket(my);
  6121. }
  6122. else
  6123. {
  6124. this.getParty().broadcastToPartyMembers(my);
  6125. }
  6126. }
  6127. else
  6128. {
  6129. sendPacket(new TargetUnselected(this));
  6130. }
  6131. }
  6132. }
  6133.  
  6134. _target = object;
  6135. }
  6136.  
  6137. /**
  6138. * Return the identifier of the L2Object targeted or -1.<BR>
  6139. * <BR>
  6140. * @return the target id
  6141. */
  6142. public final int getTargetId()
  6143. {
  6144. if (_target != null)
  6145. return _target.getObjectId();
  6146.  
  6147. return -1;
  6148. }
  6149.  
  6150. /**
  6151. * Return the L2Object targeted or null.<BR>
  6152. * <BR>
  6153. * @return the target
  6154. */
  6155. public final L2Object getTarget()
  6156. {
  6157. return _target;
  6158. }
  6159.  
  6160. // called from AIAccessor only
  6161. /**
  6162. * Calculate movement data for a move to location action and add the L2Character to movingObjects of GameTimeController (only called by AI Accessor).<BR>
  6163. * <BR>
  6164. * <B><U> Concept</U> :</B><BR>
  6165. * <BR>
  6166. * 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. 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>
  6167. * <BR>
  6168. * 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>
  6169. * <BR>
  6170. * <B><U> Actions</U> :</B><BR>
  6171. * <BR>
  6172. * <li>Get current position of the L2Character</li> <li>Calculate distance (dx,dy) between current position and destination including offset</li> <li>Create and Init a MoveData object</li> <li>Set the L2Character _move object to MoveData object</li> <li>Add the L2Character to movingObjects of
  6173. * the GameTimeController</li> <li>Create a task to notify the AI that L2Character arrives at a check point of the movement</li><BR>
  6174. * <BR>
  6175. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T send Server->Client packet MoveToPawn/CharMoveToLocation </B></FONT><BR>
  6176. * <BR>
  6177. * <B><U> Example of use </U> :</B><BR>
  6178. * <BR>
  6179. * <li>AI : onIntentionMoveTo(L2CharPosition), onIntentionPickUp(L2Object), onIntentionInteract(L2Object)</li> <li>FollowTask</li><BR>
  6180. * <BR>
  6181. * @param x The X position of the destination
  6182. * @param y The Y position of the destination
  6183. * @param z The Y position of the destination
  6184. * @param offset The size of the interaction area of the L2Character targeted
  6185. */
  6186. protected void moveToLocation(int x, int y, int z, int offset)
  6187. {
  6188. // Block movment during Event start
  6189. if (this instanceof L2PcInstance)
  6190. {
  6191. if (L2Event.active && ((L2PcInstance) this).eventSitForced)
  6192. {
  6193. ((L2PcInstance) this).sendMessage("A dark force beyond your mortal understanding makes your knees to shake when you try to stand up...");
  6194. ((L2PcInstance) this).getClient().sendPacket(ActionFailed.STATIC_PACKET);
  6195. return;
  6196. }
  6197. else if ((TvT.is_sitForced() && ((L2PcInstance) this)._inEventTvT) || (CTF.is_sitForced() && ((L2PcInstance) this)._inEventCTF) || (DM.is_sitForced() && ((L2PcInstance) this)._inEventDM))
  6198. {
  6199. ((L2PcInstance) this).sendMessage("A dark force beyond your mortal understanding makes your knees to shake when you try to stand up...");
  6200. ((L2PcInstance) this).getClient().sendPacket(ActionFailed.STATIC_PACKET);
  6201. return;
  6202. }
  6203. else if (VIP._sitForced && ((L2PcInstance) this)._inEventVIP)
  6204. {
  6205. ((L2PcInstance) this).sendMessage("A dark force beyond your mortal understanding makes your knees to shake when you try to stand up...");
  6206. ((L2PcInstance) this).sendPacket(ActionFailed.STATIC_PACKET);
  6207. return;
  6208. }
  6209. }
  6210.  
  6211. // when start to move again, it has to stop sitdown task
  6212. if (this instanceof L2PcInstance)
  6213. ((L2PcInstance) this).setPosticipateSit(false);
  6214.  
  6215. // Fix archer bug with movment/hittask
  6216. if (this instanceof L2PcInstance && this.isAttackingNow())
  6217. {
  6218. final L2ItemInstance rhand = ((L2PcInstance) this).getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  6219. if ((rhand != null && rhand.getItemType() == L2WeaponType.BOW))
  6220. return;
  6221. }
  6222.  
  6223. // Get the Move Speed of the L2Charcater
  6224. final float speed = getStat().getMoveSpeed();
  6225.  
  6226. if (speed <= 0 || isMovementDisabled())
  6227. return;
  6228.  
  6229. // Get current position of the L2Character
  6230. final int curX = super.getX();
  6231. final int curY = super.getY();
  6232. final int curZ = super.getZ();
  6233.  
  6234. // Calculate distance (dx,dy) between current position and destination
  6235. //
  6236. double dx = x - curX;
  6237. double dy = y - curY;
  6238. double dz = z - curZ;
  6239. double distance = Math.sqrt(dx * dx + dy * dy);
  6240.  
  6241. if (Config.GEODATA > 0 && isInsideZone(ZONE_WATER) && distance > 700)
  6242. {
  6243. final double divider = 700 / distance;
  6244. x = curX + (int) (divider * dx);
  6245. y = curY + (int) (divider * dy);
  6246. z = curZ + (int) (divider * dz);
  6247. dx = x - curX;
  6248. dy = y - curY;
  6249. dz = z - curZ;
  6250. distance = Math.sqrt(dx * dx + dy * dy);
  6251. }
  6252.  
  6253. /*
  6254. * if(Config.DEBUG) { LOGGER.fine("distance to target:" + distance); }
  6255. */
  6256.  
  6257. // Define movement angles needed
  6258. // ^
  6259. // | X (x,y)
  6260. // | /
  6261. // | /distance
  6262. // | /
  6263. // |/ angle
  6264. // X ---------->
  6265. // (curx,cury)
  6266.  
  6267. double cos;
  6268. double sin;
  6269.  
  6270. // Check if a movement offset is defined or no distance to go through
  6271. if (offset > 0 || distance < 1)
  6272. {
  6273. // approximation for moving closer when z coordinates are different
  6274. //
  6275. offset -= Math.abs(dz);
  6276.  
  6277. if (offset < 5)
  6278. {
  6279. offset = 5;
  6280. }
  6281.  
  6282. // If no distance to go through, the movement is canceled
  6283. if (distance < 1 || distance - offset <= 0)
  6284. {
  6285. sin = 0;
  6286. cos = 1;
  6287. distance = 0;
  6288. x = curX;
  6289. y = curY;
  6290.  
  6291. if (Config.DEBUG)
  6292. {
  6293. LOGGER.debug("Already in range, no movement needed.");
  6294. }
  6295.  
  6296. // Notify the AI that the L2Character is arrived at destination
  6297. getAI().notifyEvent(CtrlEvent.EVT_ARRIVED, null);
  6298.  
  6299. return;
  6300. }
  6301. // Calculate movement angles needed
  6302. sin = dy / distance;
  6303. cos = dx / distance;
  6304.  
  6305. distance -= offset - 5; // due to rounding error, we have to move a bit closer to be in range
  6306.  
  6307. // Calculate the new destination with offset included
  6308. x = curX + (int) (distance * cos);
  6309. y = curY + (int) (distance * sin);
  6310.  
  6311. }
  6312. else
  6313. {
  6314. // Calculate movement angles needed
  6315. sin = dy / distance;
  6316. cos = dx / distance;
  6317. }
  6318.  
  6319. // Create and Init a MoveData object
  6320. MoveData m = new MoveData();
  6321.  
  6322. // GEODATA MOVEMENT CHECKS AND PATHFINDING
  6323.  
  6324. m.onGeodataPathIndex = -1; // Initialize not on geodata path
  6325. m.disregardingGeodata = false;
  6326.  
  6327. if (Config.GEODATA > 0 && !isFlying() && (!isInsideZone(ZONE_WATER) || isInsideZone(ZONE_SIEGE)) && !(this instanceof L2NpcWalkerInstance))
  6328. {
  6329. final double originalDistance = distance;
  6330. final int originalX = x;
  6331. final int originalY = y;
  6332. final int originalZ = z;
  6333. final int gtx = originalX - L2World.MAP_MIN_X >> 4;
  6334. final int gty = originalY - L2World.MAP_MIN_Y >> 4;
  6335.  
  6336. // Movement checks:
  6337. // when geodata == 2, for all characters except mobs returning home (could be changed later to teleport if pathfinding fails)
  6338. // when geodata == 1, for l2playableinstance and l2riftinstance only
  6339. if (Config.GEODATA > 0 && !(this instanceof L2Attackable && ((L2Attackable) this).isReturningToSpawnPoint()) || this instanceof L2PcInstance || this instanceof L2Summon && !(getAI().getIntention() == AI_INTENTION_FOLLOW) || this instanceof L2RiftInvaderInstance || isAfraid())
  6340. {
  6341. if (isOnGeodataPath())
  6342. {
  6343. try
  6344. {
  6345. if (gtx == _move.geoPathGtx && gty == _move.geoPathGty)
  6346. return;
  6347. _move.onGeodataPathIndex = -1; // Set not on geodata path
  6348. }
  6349. catch (final NullPointerException e)
  6350. {
  6351. e.printStackTrace();
  6352. }
  6353. }
  6354.  
  6355. if (curX < L2World.MAP_MIN_X || curX > L2World.MAP_MAX_X || curY < L2World.MAP_MIN_Y || curY > L2World.MAP_MAX_Y)
  6356. {
  6357. // Temporary fix for character outside world region errors
  6358. LOGGER.warn("Character " + getName() + " outside world area, in coordinates x:" + curX + " y:" + curY);
  6359. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  6360. if (this instanceof L2PcInstance)
  6361. {
  6362. ((L2PcInstance) this).deleteMe();
  6363. }
  6364. else
  6365. {
  6366. onDecay();
  6367. }
  6368.  
  6369. return;
  6370. }
  6371. final Location destiny = GeoData.getInstance().moveCheck(curX, curY, curZ, x, y, z);
  6372. // location different if destination wasn't reached (or just z coord is different)
  6373. x = destiny.getX();
  6374. y = destiny.getY();
  6375. z = destiny.getZ();
  6376. distance = Math.sqrt((x - curX) * (x - curX) + (y - curY) * (y - curY));
  6377.  
  6378. }
  6379. // Pathfinding checks. Only when geodata setting is 2, the LoS check gives shorter result
  6380. // than the original movement was and the LoS gives a shorter distance than 2000
  6381. // This way of detecting need for pathfinding could be changed.
  6382. if (((this instanceof L2PcInstance) && Config.ALLOW_PLAYERS_PATHNODE || !(this instanceof L2PcInstance)) && Config.GEODATA == 2 && originalDistance - distance > 100 && distance < 2000 && !isAfraid())
  6383. {
  6384. // Path calculation
  6385. // Overrides previous movement check
  6386. if (this instanceof L2PlayableInstance || isInCombat() || this instanceof L2MinionInstance)
  6387. {
  6388. // int gx = (curX - L2World.MAP_MIN_X) >> 4;
  6389. // int gy = (curY - L2World.MAP_MIN_Y) >> 4;
  6390.  
  6391. m.geoPath = PathFinding.getInstance().findPath(curX, curY, curZ, originalX, originalY, originalZ);
  6392. if (m.geoPath == null || m.geoPath.length < 2) // No path found
  6393. {
  6394. // Even though there's no path found (remember geonodes aren't perfect),
  6395. // the mob is attacking and right now we set it so that the mob will go
  6396. // after target anyway, is dz is small enough. Summons will follow their masters no matter what.
  6397. if (Config.ALLOW_PLAYERS_PATHNODE && (this instanceof L2PcInstance)/* this instanceof L2PcInstance || */
  6398. || (!(this instanceof L2PlayableInstance) && Math.abs(z - curZ) > 140) || (this instanceof L2Summon && !((L2Summon) this).getFollowStatus()))
  6399. {
  6400. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  6401. return;
  6402. }
  6403. m.disregardingGeodata = true;
  6404. x = originalX;
  6405. y = originalY;
  6406. z = originalZ;
  6407. distance = originalDistance;
  6408. }
  6409. else
  6410. {
  6411. m.onGeodataPathIndex = 0; // on first segment
  6412. m.geoPathGtx = gtx;
  6413. m.geoPathGty = gty;
  6414. m.geoPathAccurateTx = originalX;
  6415. m.geoPathAccurateTy = originalY;
  6416.  
  6417. x = m.geoPath[m.onGeodataPathIndex].getX();
  6418. y = m.geoPath[m.onGeodataPathIndex].getY();
  6419. z = m.geoPath[m.onGeodataPathIndex].getZ();
  6420.  
  6421. // check for doors in the route
  6422. if (DoorTable.getInstance().checkIfDoorsBetween(curX, curY, curZ, x, y, z))
  6423. {
  6424. m.geoPath = null;
  6425. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  6426. return;
  6427. }
  6428.  
  6429. for (int i = 0; i < m.geoPath.length - 1; i++)
  6430. {
  6431. if (DoorTable.getInstance().checkIfDoorsBetween(m.geoPath[i], m.geoPath[i + 1]))
  6432. {
  6433. m.geoPath = null;
  6434. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  6435. return;
  6436. }
  6437. }
  6438.  
  6439. dx = x - curX;
  6440. dy = y - curY;
  6441. distance = Math.sqrt(dx * dx + dy * dy);
  6442. sin = dy / distance;
  6443. cos = dx / distance;
  6444. }
  6445. }
  6446. }
  6447. // If no distance to go through, the movement is canceled
  6448. if (((this instanceof L2PcInstance) && Config.ALLOW_PLAYERS_PATHNODE || !(this instanceof L2PcInstance)) && distance < 1 && (Config.GEODATA == 2 || this instanceof L2PlayableInstance || this instanceof L2RiftInvaderInstance || isAfraid()))
  6449. {
  6450. /*
  6451. * sin = 0; cos = 1; distance = 0; x = curX; y = curY;
  6452. */
  6453.  
  6454. if (this instanceof L2Summon)
  6455. {
  6456. ((L2Summon) this).setFollowStatus(false);
  6457. }
  6458.  
  6459. // getAI().notifyEvent(CtrlEvent.EVT_ARRIVED, null);
  6460. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  6461.  
  6462. return;
  6463. }
  6464. }
  6465.  
  6466. // Caclulate the Nb of ticks between the current position and the destination
  6467. // One tick added for rounding reasons
  6468. final int ticksToMove = 1 + (int) (GameTimeController.TICKS_PER_SECOND * distance / speed);
  6469.  
  6470. // Calculate and set the heading of the L2Character
  6471. setHeading((int) (Math.atan2(-sin, -cos) * 10430.37835) + 32768);
  6472.  
  6473. /*
  6474. * if(Config.DEBUG) { LOGGER.fine("dist:" + distance + "speed:" + speed + " ttt:" + ticksToMove + " heading:" + getHeading()); }
  6475. */
  6476.  
  6477. m._xDestination = x;
  6478. m._yDestination = y;
  6479. m._zDestination = z; // this is what was requested from client
  6480. m._heading = 0;
  6481.  
  6482. m._moveStartTime = GameTimeController.getGameTicks();
  6483.  
  6484. /*
  6485. * if(Config.DEBUG) { LOGGER.fine("time to target:" + ticksToMove); }
  6486. */
  6487.  
  6488. // Set the L2Character _move object to MoveData object
  6489. _move = m;
  6490.  
  6491. // Add the L2Character to movingObjects of the GameTimeController
  6492. // The GameTimeController manage objects movement
  6493. GameTimeController.getInstance().registerMovingObject(this);
  6494.  
  6495. // Create a task to notify the AI that L2Character arrives at a check point of the movement
  6496. if (ticksToMove * GameTimeController.MILLIS_IN_TICK > 3000)
  6497. {
  6498. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_ARRIVED_REVALIDATE), 2000);
  6499. }
  6500.  
  6501. // the CtrlEvent.EVT_ARRIVED will be sent when the character will actually arrive
  6502. // to destination by GameTimeController
  6503.  
  6504. m = null;
  6505. }
  6506.  
  6507. /**
  6508. * Move to next route point.
  6509. * @return true, if successful
  6510. */
  6511. public boolean moveToNextRoutePoint()
  6512. {
  6513. if (!isOnGeodataPath())
  6514. {
  6515. // Cancel the move action
  6516. _move = null;
  6517. return false;
  6518. }
  6519.  
  6520. // Get the Move Speed of the L2Charcater
  6521. final float speed = getStat().getMoveSpeed();
  6522.  
  6523. if (speed <= 0 || isMovementDisabled())
  6524. {
  6525. // Cancel the move action
  6526. _move = null;
  6527. return false;
  6528. }
  6529.  
  6530. MoveData md = _move;
  6531. if (md == null)
  6532. return false;
  6533.  
  6534. // Create and Init a MoveData object
  6535. MoveData m = new MoveData();
  6536.  
  6537. // Update MoveData object
  6538. m.onGeodataPathIndex = md.onGeodataPathIndex + 1; // next segment
  6539. m.geoPath = md.geoPath;
  6540. m.geoPathGtx = md.geoPathGtx;
  6541. m.geoPathGty = md.geoPathGty;
  6542. m.geoPathAccurateTx = md.geoPathAccurateTx;
  6543. m.geoPathAccurateTy = md.geoPathAccurateTy;
  6544.  
  6545. if (md.onGeodataPathIndex == md.geoPath.length - 2)
  6546. {
  6547. m._xDestination = md.geoPathAccurateTx;
  6548. m._yDestination = md.geoPathAccurateTy;
  6549. m._zDestination = md.geoPath[m.onGeodataPathIndex].getZ();
  6550. }
  6551. else
  6552. {
  6553. m._xDestination = md.geoPath[m.onGeodataPathIndex].getX();
  6554. m._yDestination = md.geoPath[m.onGeodataPathIndex].getY();
  6555. m._zDestination = md.geoPath[m.onGeodataPathIndex].getZ();
  6556. }
  6557.  
  6558. final double dx = m._xDestination - super.getX();
  6559. final double dy = m._yDestination - super.getY();
  6560. final double distance = Math.sqrt(dx * dx + dy * dy);
  6561. final double sin = dy / distance;
  6562. final double cos = dx / distance;
  6563.  
  6564. // Caclulate the Nb of ticks between the current position and the destination
  6565. // One tick added for rounding reasons
  6566. final int ticksToMove = 1 + (int) (GameTimeController.TICKS_PER_SECOND * distance / speed);
  6567.  
  6568. setHeading((int) (Math.atan2(-sin, -cos) * 10430.37835) + 32768);
  6569. m._heading = 0; // ?
  6570.  
  6571. m._moveStartTime = GameTimeController.getGameTicks();
  6572.  
  6573. if (Config.DEBUG)
  6574. {
  6575. LOGGER.debug("Time to target:" + ticksToMove);
  6576. }
  6577.  
  6578. // Set the L2Character _move object to MoveData object
  6579. _move = m;
  6580.  
  6581. // Add the L2Character to movingObjects of the GameTimeController
  6582. // The GameTimeController manage objects movement
  6583. GameTimeController.getInstance().registerMovingObject(this);
  6584.  
  6585. // Create a task to notify the AI that L2Character arrives at a check point of the movement
  6586. if (ticksToMove * GameTimeController.MILLIS_IN_TICK > 3000)
  6587. {
  6588. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_ARRIVED_REVALIDATE), 2000);
  6589. }
  6590.  
  6591. // the CtrlEvent.EVT_ARRIVED will be sent when the character will actually arrive
  6592. // to destination by GameTimeController
  6593.  
  6594. // Send a Server->Client packet CharMoveToLocation to the actor and all L2PcInstance in its _knownPlayers
  6595. CharMoveToLocation msg = new CharMoveToLocation(this);
  6596. broadcastPacket(msg);
  6597.  
  6598. msg = null;
  6599. m = null;
  6600. md = null;
  6601.  
  6602. return true;
  6603. }
  6604.  
  6605. /**
  6606. * Validate movement heading.
  6607. * @param heading the heading
  6608. * @return true, if successful
  6609. */
  6610. public boolean validateMovementHeading(final int heading)
  6611. {
  6612. MoveData md = _move;
  6613.  
  6614. if (md == null)
  6615. return true;
  6616.  
  6617. boolean result = true;
  6618.  
  6619. if (md._heading != heading)
  6620. {
  6621. result = md._heading == 0;
  6622. md._heading = heading;
  6623. }
  6624.  
  6625. md = null;
  6626.  
  6627. return result;
  6628. }
  6629.  
  6630. /**
  6631. * Return the distance between the current position of the L2Character and the target (x,y).<BR>
  6632. * <BR>
  6633. * @param x X position of the target
  6634. * @param y Y position of the target
  6635. * @return the plan distance
  6636. * @deprecated use getPlanDistanceSq(int x, int y, int z)
  6637. */
  6638. @Deprecated
  6639. public final double getDistance(final int x, final int y)
  6640. {
  6641. final double dx = x - getX();
  6642. final double dy = y - getY();
  6643.  
  6644. return Math.sqrt(dx * dx + dy * dy);
  6645. }
  6646.  
  6647. /**
  6648. * Return the distance between the current position of the L2Character and the target (x,y).<BR>
  6649. * <BR>
  6650. * @param x X position of the target
  6651. * @param y Y position of the target
  6652. * @param z the z
  6653. * @return the plan distance
  6654. * @deprecated use getPlanDistanceSq(int x, int y, int z)
  6655. */
  6656. @Deprecated
  6657. public final double getDistance(final int x, final int y, final int z)
  6658. {
  6659. final double dx = x - getX();
  6660. final double dy = y - getY();
  6661. final double dz = z - getZ();
  6662.  
  6663. return Math.sqrt(dx * dx + dy * dy + dz * dz);
  6664. }
  6665.  
  6666. /**
  6667. * Return the squared distance between the current position of the L2Character and the given object.<BR>
  6668. * <BR>
  6669. * @param object L2Object
  6670. * @return the squared distance
  6671. */
  6672. public final double getDistanceSq(final L2Object object)
  6673. {
  6674. return getDistanceSq(object.getX(), object.getY(), object.getZ());
  6675. }
  6676.  
  6677. /**
  6678. * Return the squared distance between the current position of the L2Character and the given x, y, z.<BR>
  6679. * <BR>
  6680. * @param x X position of the target
  6681. * @param y Y position of the target
  6682. * @param z Z position of the target
  6683. * @return the squared distance
  6684. */
  6685. public final double getDistanceSq(final int x, final int y, final int z)
  6686. {
  6687. final double dx = x - getX();
  6688. final double dy = y - getY();
  6689. final double dz = z - getZ();
  6690.  
  6691. return dx * dx + dy * dy + dz * dz;
  6692. }
  6693.  
  6694. /**
  6695. * Return the squared plan distance between the current position of the L2Character and the given object.<BR>
  6696. * (check only x and y, not z)<BR>
  6697. * <BR>
  6698. * @param object L2Object
  6699. * @return the squared plan distance
  6700. */
  6701. public final double getPlanDistanceSq(final L2Object object)
  6702. {
  6703. return getPlanDistanceSq(object.getX(), object.getY());
  6704. }
  6705.  
  6706. /**
  6707. * Return the squared plan distance between the current position of the L2Character and the given x, y, z.<BR>
  6708. * (check only x and y, not z)<BR>
  6709. * <BR>
  6710. * @param x X position of the target
  6711. * @param y Y position of the target
  6712. * @return the squared plan distance
  6713. */
  6714. public final double getPlanDistanceSq(final int x, final int y)
  6715. {
  6716. final double dx = x - getX();
  6717. final double dy = y - getY();
  6718.  
  6719. return dx * dx + dy * dy;
  6720. }
  6721.  
  6722. /**
  6723. * Check if this object is inside the given radius around the given object. Warning: doesn't cover collision radius!<BR>
  6724. * <BR>
  6725. * @param object the target
  6726. * @param radius the radius around the target
  6727. * @param checkZ should we check Z axis also
  6728. * @param strictCheck true if (distance < radius), false if (distance <= radius)
  6729. * @return true is the L2Character is inside the radius.
  6730. */
  6731. public final boolean isInsideRadius(final L2Object object, final int radius, final boolean checkZ, final boolean strictCheck)
  6732. {
  6733. if (object != null)
  6734. return isInsideRadius(object.getX(), object.getY(), object.getZ(), radius, checkZ, strictCheck);
  6735. return false;
  6736. }
  6737.  
  6738. /**
  6739. * Check if this object is inside the given plan radius around the given point. Warning: doesn't cover collision radius!<BR>
  6740. * <BR>
  6741. * @param x X position of the target
  6742. * @param y Y position of the target
  6743. * @param radius the radius around the target
  6744. * @param strictCheck true if (distance < radius), false if (distance <= radius)
  6745. * @return true is the L2Character is inside the radius.
  6746. */
  6747. public final boolean isInsideRadius(final int x, final int y, final int radius, final boolean strictCheck)
  6748. {
  6749. return isInsideRadius(x, y, 0, radius, false, strictCheck);
  6750. }
  6751.  
  6752. /**
  6753. * Check if this object is inside the given radius around the given point.<BR>
  6754. * <BR>
  6755. * @param x X position of the target
  6756. * @param y Y position of the target
  6757. * @param z Z position of the target
  6758. * @param radius the radius around the target
  6759. * @param checkZ should we check Z axis also
  6760. * @param strictCheck true if (distance < radius), false if (distance <= radius)
  6761. * @return true is the L2Character is inside the radius.
  6762. */
  6763. public final boolean isInsideRadius(final int x, final int y, final int z, final int radius, final boolean checkZ, final boolean strictCheck)
  6764. {
  6765. final double dx = x - getX();
  6766. final double dy = y - getY();
  6767. final double dz = z - getZ();
  6768.  
  6769. if (strictCheck)
  6770. {
  6771. if (checkZ)
  6772. return dx * dx + dy * dy + dz * dz < radius * radius;
  6773. return dx * dx + dy * dy < radius * radius;
  6774. }
  6775. if (checkZ)
  6776. return dx * dx + dy * dy + dz * dz <= radius * radius;
  6777. return dx * dx + dy * dy <= radius * radius;
  6778. }
  6779.  
  6780. // /**
  6781. // * event that is called when the destination coordinates are reached
  6782. // */
  6783. // public void onTargetReached()
  6784. // {
  6785. // L2Character pawn = getPawnTarget();
  6786. //
  6787. // if (pawn != null)
  6788. // {
  6789. // int x = pawn.getX(), y=pawn.getY(),z = pawn.getZ();
  6790. //
  6791. // double distance = getDistance(x,y);
  6792. // if (getCurrentState() == STATE_FOLLOW)
  6793. // {
  6794. // calculateMovement(x,y,z,distance);
  6795. // return;
  6796. // }
  6797. //
  6798. // // takes care of moving away but distance is 0 so i won't follow problem
  6799. //
  6800. //
  6801. // if (((distance > getAttackRange()) && (getCurrentState() == STATE_ATTACKING)) || (pawn.isMoving() && getCurrentState() != STATE_ATTACKING))
  6802. // {
  6803. // calculateMovement(x,y,z,distance);
  6804. // return;
  6805. // }
  6806. //
  6807. // }
  6808. // // update x,y,z with the current calculated position
  6809. // stopMove();
  6810. //
  6811. // if (Config.DEBUG)
  6812. // LOGGER.fine(this.getName() +":: target reached at: x "+getX()+" y "+getY()+ " z:" + getZ());
  6813. //
  6814. // if (getPawnTarget() != null)
  6815. // {
  6816. //
  6817. // setPawnTarget(null);
  6818. // setMovingToPawn(false);
  6819. // }
  6820. // }
  6821. //
  6822. // public void setTo(int x, int y, int z, int heading)
  6823. // {
  6824. // setX(x);
  6825. // setY(y);
  6826. // setZ(z);
  6827. // setHeading(heading);
  6828. // updateCurrentWorldRegion();
  6829. // if (isMoving())
  6830. // {
  6831. // setCurrentState(STATE_IDLE);
  6832. // StopMove setto = new StopMove(this);
  6833. // broadcastPacket(setto);
  6834. // }
  6835. // else
  6836. // {
  6837. // ValidateLocation setto = new ValidateLocation(this);
  6838. // broadcastPacket(setto);
  6839. // }
  6840. //
  6841. // FinishRotation fr = new FinishRotation(this);
  6842. // broadcastPacket(fr);
  6843. // }
  6844.  
  6845. // protected void startCombat()
  6846. // {
  6847. // if (_currentAttackTask == null )//&& !isInCombat())
  6848. // {
  6849. // _currentAttackTask = ThreadPoolManager.getInstance().scheduleMed(new AttackTask(), 0);
  6850. // }
  6851. // else
  6852. // {
  6853. // LOGGER.info("multiple attacks want to start in parallel. prevented.");
  6854. // }
  6855. // }
  6856. //
  6857.  
  6858. /**
  6859. * Return the Weapon Expertise Penalty of the L2Character.<BR>
  6860. * <BR>
  6861. * @return the weapon expertise penalty
  6862. */
  6863. public float getWeaponExpertisePenalty()
  6864. {
  6865. return 1.f;
  6866. }
  6867.  
  6868. /**
  6869. * Return the Armour Expertise Penalty of the L2Character.<BR>
  6870. * <BR>
  6871. * @return the armour expertise penalty
  6872. */
  6873. public float getArmourExpertisePenalty()
  6874. {
  6875. return 1.f;
  6876. }
  6877.  
  6878. /**
  6879. * Set _attacking corresponding to Attacking Body part to CHEST.<BR>
  6880. * <BR>
  6881. */
  6882. public void setAttackingBodypart()
  6883. {
  6884. _attacking = Inventory.PAPERDOLL_CHEST;
  6885. }
  6886.  
  6887. /**
  6888. * Retun True if arrows are available.<BR>
  6889. * <BR>
  6890. * <B><U> Overriden in </U> :</B><BR>
  6891. * <BR>
  6892. * <li>L2PcInstance</li><BR>
  6893. * <BR>
  6894. * @return true, if successful
  6895. */
  6896. protected boolean checkAndEquipArrows()
  6897. {
  6898. return true;
  6899. }
  6900.  
  6901. /**
  6902. * Add Exp and Sp to the L2Character.<BR>
  6903. * <BR>
  6904. * <B><U> Overriden in </U> :</B><BR>
  6905. * <BR>
  6906. * <li>L2PcInstance</li> <li>L2PetInstance</li><BR>
  6907. * <BR>
  6908. * @param addToExp the add to exp
  6909. * @param addToSp the add to sp
  6910. */
  6911. public void addExpAndSp(final long addToExp, final int addToSp)
  6912. {
  6913. // Dummy method (overridden by players and pets)
  6914. }
  6915.  
  6916. /**
  6917. * Return the active weapon instance (always equiped in the right hand).<BR>
  6918. * <BR>
  6919. * <B><U> Overriden in </U> :</B><BR>
  6920. * <BR>
  6921. * <li>L2PcInstance</li><BR>
  6922. * <BR>
  6923. * @return the active weapon instance
  6924. */
  6925. public abstract L2ItemInstance getActiveWeaponInstance();
  6926.  
  6927. /**
  6928. * Return the active weapon item (always equiped in the right hand).<BR>
  6929. * <BR>
  6930. * <B><U> Overriden in </U> :</B><BR>
  6931. * <BR>
  6932. * <li>L2PcInstance</li><BR>
  6933. * <BR>
  6934. * @return the active weapon item
  6935. */
  6936. public abstract L2Weapon getActiveWeaponItem();
  6937.  
  6938. /**
  6939. * Return the secondary weapon instance (always equiped in the left hand).<BR>
  6940. * <BR>
  6941. * <B><U> Overriden in </U> :</B><BR>
  6942. * <BR>
  6943. * <li>L2PcInstance</li><BR>
  6944. * <BR>
  6945. * @return the secondary weapon instance
  6946. */
  6947. public abstract L2ItemInstance getSecondaryWeaponInstance();
  6948.  
  6949. /**
  6950. * Return the secondary weapon item (always equiped in the left hand).<BR>
  6951. * <BR>
  6952. * <B><U> Overriden in </U> :</B><BR>
  6953. * <BR>
  6954. * <li>L2PcInstance</li><BR>
  6955. * <BR>
  6956. * @return the secondary weapon item
  6957. */
  6958. public abstract L2Weapon getSecondaryWeaponItem();
  6959.  
  6960. /**
  6961. * Manage hit process (called by Hit Task).<BR>
  6962. * <BR>
  6963. * <B><U> Actions</U> :</B><BR>
  6964. * <BR>
  6965. * <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> <li>If attack isn't aborted, send a message system (critical hit, missed...) to attacker/target if they are L2PcInstance</li>
  6966. * <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> <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>
  6967. * <BR>
  6968. * @param target The L2Character targeted
  6969. * @param damage Nb of HP to reduce
  6970. * @param crit True if hit is critical
  6971. * @param miss True if hit is missed
  6972. * @param soulshot True if SoulShot are charged
  6973. * @param shld True if shield is efficient
  6974. */
  6975. protected void onHitTimer(final L2Character target, int damage, final boolean crit, final boolean miss, final boolean soulshot, final boolean shld)
  6976. {
  6977. // If the attacker/target is dead or use fake death, notify the AI with EVT_CANCEL
  6978. // and send a Server->Client packet ActionFailed (if attacker is a L2PcInstance)
  6979. if (target == null || isAlikeDead() || this instanceof L2NpcInstance && ((L2NpcInstance) this).isEventMob)
  6980. {
  6981. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  6982. return;
  6983. }
  6984.  
  6985. if (this instanceof L2NpcInstance && target.isAlikeDead() || target.isDead() || !getKnownList().knowsObject(target) && !(this instanceof L2DoorInstance))
  6986. {
  6987. // getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE, null);
  6988. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  6989.  
  6990. sendPacket(ActionFailed.STATIC_PACKET);
  6991. return;
  6992. }
  6993.  
  6994. if (miss)
  6995. {
  6996. if (target instanceof L2PcInstance)
  6997. {
  6998. SystemMessage sm = new SystemMessage(SystemMessageId.AVOIDED_S1S_ATTACK);
  6999.  
  7000. if (this instanceof L2Summon)
  7001. {
  7002. final int mobId = ((L2Summon) this).getTemplate().npcId;
  7003. sm.addNpcName(mobId);
  7004. }
  7005. else
  7006. {
  7007. sm.addString(getName());
  7008. }
  7009.  
  7010. ((L2PcInstance) target).sendPacket(sm);
  7011.  
  7012. sm = null;
  7013. }
  7014. }
  7015.  
  7016. // If attack isn't aborted, send a message system (critical hit, missed...) to attacker/target if they are L2PcInstance
  7017. if (!isAttackAborted())
  7018. {
  7019. if (Config.ALLOW_RAID_BOSS_PETRIFIED && (this instanceof L2PcInstance || this instanceof L2Summon)) // Check if option is True Or False.
  7020. {
  7021. boolean to_be_cursed = false;
  7022.  
  7023. // check on BossZone raid lvl
  7024. if (!(target instanceof L2PlayableInstance) && !(target instanceof L2SummonInstance))
  7025. { // this must work just on mobs/raids
  7026.  
  7027. if ((target.isRaid() && getLevel() > target.getLevel() + 8) || (!(target instanceof L2PcInstance) && (target.getTarget() != null && target.getTarget() instanceof L2RaidBossInstance && getLevel() > ((L2RaidBossInstance) target.getTarget()).getLevel() + 8)) || (!(target instanceof L2PcInstance) && (target.getTarget() != null && target.getTarget() instanceof L2GrandBossInstance && getLevel() > ((L2GrandBossInstance) target.getTarget()).getLevel() + 8)))
  7028.  
  7029. {
  7030. to_be_cursed = true;
  7031. }
  7032.  
  7033. // advanced check too if not already cursed
  7034. if (!to_be_cursed)
  7035. {
  7036. int boss_id = -1;
  7037. L2NpcTemplate boss_template = null;
  7038. final L2BossZone boss_zone = GrandBossManager.getInstance().getZone(this);
  7039.  
  7040. if (boss_zone != null)
  7041. {
  7042. boss_id = boss_zone.getBossId();
  7043. }
  7044.  
  7045. // boolean alive = false;
  7046.  
  7047. if (boss_id != -1)
  7048. {
  7049. boss_template = NpcTable.getInstance().getTemplate(boss_id);
  7050.  
  7051. if (boss_template != null && getLevel() > boss_template.getLevel() + 8)
  7052. {
  7053. L2MonsterInstance boss_instance = null;
  7054.  
  7055. if (boss_template.type.equals("L2RaidBoss"))
  7056. {
  7057. final StatsSet actual_boss_stat = RaidBossSpawnManager.getInstance().getStatsSet(boss_id);
  7058. if (actual_boss_stat != null)
  7059. {
  7060. // alive = actual_boss_stat.getLong("respawnTime") == 0;
  7061. boss_instance = RaidBossSpawnManager.getInstance().getBoss(boss_id);
  7062. }
  7063. }
  7064. else if (boss_template.type.equals("L2GrandBoss"))
  7065. {
  7066. final StatsSet actual_boss_stat = GrandBossManager.getInstance().getStatsSet(boss_id);
  7067. if (actual_boss_stat != null)
  7068. {
  7069. // alive = actual_boss_stat.getLong("respawn_time") == 0;
  7070. boss_instance = GrandBossManager.getInstance().getBoss(boss_id);
  7071. }
  7072. }
  7073.  
  7074. // max allowed rage into take cursed is 3000
  7075. if (boss_instance != null/* && alive */&& boss_instance.isInsideRadius(this, 3000, false, false))
  7076. {
  7077. to_be_cursed = true;
  7078. }
  7079. }
  7080. }
  7081. }
  7082. }
  7083.  
  7084. if (to_be_cursed)
  7085. {
  7086. L2Skill skill = SkillTable.getInstance().getInfo(4515, 1);
  7087.  
  7088. if (skill != null)
  7089. {
  7090. abortAttack();
  7091. abortCast();
  7092. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  7093. skill.getEffects(target, this, false, false, false);
  7094.  
  7095. if (this instanceof L2Summon)
  7096. {
  7097. final L2Summon src = ((L2Summon) this);
  7098. if (src.getOwner() != null)
  7099. {
  7100. src.getOwner().abortAttack();
  7101. src.getOwner().abortCast();
  7102. src.getOwner().getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  7103. skill.getEffects(target, src.getOwner(), false, false, false);
  7104. }
  7105. }
  7106. }
  7107. else
  7108. LOGGER.warn("Skill 4515 at level 1 is missing in DP.");
  7109.  
  7110. skill = null;
  7111.  
  7112. if (target instanceof L2MinionInstance)
  7113. {
  7114. ((L2MinionInstance) target).getLeader().stopHating(this);
  7115.  
  7116. List<L2MinionInstance> spawnedMinions = ((L2MinionInstance) target).getLeader().getSpawnedMinions();
  7117. if (spawnedMinions != null && spawnedMinions.size() > 0)
  7118. {
  7119. Iterator<L2MinionInstance> itr = spawnedMinions.iterator();
  7120. L2MinionInstance minion;
  7121. while (itr.hasNext())
  7122. {
  7123. minion = itr.next();
  7124. if (((L2MinionInstance) target).getLeader().getMostHated() == null)
  7125. {
  7126. ((L2AttackableAI) minion.getAI()).setGlobalAggro(-25);
  7127. minion.clearAggroList();
  7128. minion.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  7129. minion.setWalking();
  7130. }
  7131. if (minion != null && !minion.isDead())
  7132. {
  7133. ((L2AttackableAI) minion.getAI()).setGlobalAggro(-25);
  7134. minion.clearAggroList();
  7135. minion.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  7136. minion.addDamage(((L2MinionInstance) target).getLeader().getMostHated(), 100);
  7137. }
  7138. }
  7139. itr = null;
  7140. spawnedMinions = null;
  7141. minion = null;
  7142. }
  7143. }
  7144. else
  7145. {
  7146. ((L2Attackable) target).stopHating(this);
  7147. List<L2MinionInstance> spawnedMinions = ((L2MonsterInstance) target).getSpawnedMinions();
  7148. if (spawnedMinions != null && spawnedMinions.size() > 0)
  7149. {
  7150. Iterator<L2MinionInstance> itr = spawnedMinions.iterator();
  7151. L2MinionInstance minion;
  7152. while (itr.hasNext())
  7153. {
  7154. minion = itr.next();
  7155. if (((L2Attackable) target).getMostHated() == null)
  7156. {
  7157. ((L2AttackableAI) minion.getAI()).setGlobalAggro(-25);
  7158. minion.clearAggroList();
  7159. minion.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  7160. minion.setWalking();
  7161. }
  7162. if (minion != null && !minion.isDead())
  7163. {
  7164. ((L2AttackableAI) minion.getAI()).setGlobalAggro(-25);
  7165. minion.clearAggroList();
  7166. minion.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  7167. minion.addDamage(((L2Attackable) target).getMostHated(), 100);
  7168. }
  7169. }
  7170. itr = null;
  7171. spawnedMinions = null;
  7172. minion = null;
  7173. }
  7174. }
  7175.  
  7176. damage = 0; // prevents messing up drop calculation
  7177. }
  7178. }
  7179.  
  7180. sendDamageMessage(target, damage, false, crit, miss);
  7181.  
  7182. // If L2Character target is a L2PcInstance, send a system message
  7183. if (target instanceof L2PcInstance)
  7184. {
  7185. L2PcInstance enemy = (L2PcInstance) target;
  7186.  
  7187. // Check if shield is efficient
  7188. if (shld)
  7189. {
  7190. enemy.sendPacket(new SystemMessage(SystemMessageId.SHIELD_DEFENCE_SUCCESSFULL));
  7191. // else if (!miss && damage < 1)
  7192. // enemy.sendMessage("You hit the target's armor.");
  7193. }
  7194.  
  7195. enemy = null;
  7196. }
  7197. else if (target instanceof L2Summon)
  7198. {
  7199. L2Summon activeSummon = (L2Summon) target;
  7200.  
  7201. SystemMessage sm = new SystemMessage(SystemMessageId.PET_RECEIVED_S2_DAMAGE_BY_S1);
  7202. sm.addString(getName());
  7203. sm.addNumber(damage);
  7204. activeSummon.getOwner().sendPacket(sm);
  7205.  
  7206. sm = null;
  7207. activeSummon = null;
  7208. }
  7209.  
  7210. if (!miss && damage > 0)
  7211. {
  7212. L2Weapon weapon = getActiveWeaponItem();
  7213. final boolean isBow = weapon != null && weapon.getItemType().toString().equalsIgnoreCase("Bow");
  7214.  
  7215. if (!isBow) // Do not reflect or absorb if weapon is of type bow
  7216. {
  7217. // Absorb HP from the damage inflicted
  7218. final double absorbPercent = getStat().calcStat(Stats.ABSORB_DAMAGE_PERCENT, 0, null, null);
  7219.  
  7220. if (absorbPercent > 0)
  7221. {
  7222. final int maxCanAbsorb = (int) (getMaxHp() - getCurrentHp());
  7223. int absorbDamage = (int) (absorbPercent / 100. * damage);
  7224.  
  7225. if (absorbDamage > maxCanAbsorb)
  7226. {
  7227. absorbDamage = maxCanAbsorb; // Can't absord more than max hp
  7228. }
  7229.  
  7230. if (absorbDamage > 0)
  7231. {
  7232. setCurrentHp(getCurrentHp() + absorbDamage);
  7233.  
  7234. // Custom messages - nice but also more network load
  7235. /*
  7236. * if (this instanceof L2PcInstance) ((L2PcInstance)this).sendMessage("You absorbed " + absorbDamage + " damage."); else if (this instanceof L2Summon) ((L2Summon)this).getOwner().sendMessage("Summon absorbed " + absorbDamage + " damage."); else if (Config.DEBUG)
  7237. * LOGGER.info(getName() + " absorbed " + absorbDamage + " damage.");
  7238. */
  7239. }
  7240. }
  7241.  
  7242. // Reduce HP of the target and calculate reflection damage to reduce HP of attacker if necessary
  7243. final double reflectPercent = target.getStat().calcStat(Stats.REFLECT_DAMAGE_PERCENT, 0, null, null);
  7244.  
  7245. if (reflectPercent > 0)
  7246. {
  7247. int reflectedDamage = (int) (reflectPercent / 100. * damage);
  7248. damage -= reflectedDamage;
  7249.  
  7250. if (reflectedDamage > target.getMaxHp())
  7251. {
  7252. reflectedDamage = target.getMaxHp();
  7253. }
  7254.  
  7255. getStatus().reduceHp(reflectedDamage, target, true);
  7256.  
  7257. // Custom messages - nice but also more network load
  7258. /*
  7259. * if (target instanceof L2PcInstance) ((L2PcInstance)target).sendMessage("You reflected " + reflectedDamage + " damage."); else if (target instanceof L2Summon) ((L2Summon)target).getOwner().sendMessage("Summon reflected " + reflectedDamage + " damage."); if (this instanceof
  7260. * L2PcInstance) ((L2PcInstance)this).sendMessage("Target reflected to you " + reflectedDamage + " damage."); else if (this instanceof L2Summon) ((L2Summon)this).getOwner().sendMessage("Target reflected to your summon " + reflectedDamage + " damage.");
  7261. */
  7262. }
  7263. }
  7264.  
  7265. target.reduceCurrentHp(damage, this);
  7266.  
  7267. // Notify AI with EVT_ATTACKED
  7268. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, this);
  7269. getAI().clientStartAutoAttack();
  7270.  
  7271. // Manage attack or cast break of the target (calculating rate, sending message...)
  7272. if (!target.isRaid() && Formulas.calcAtkBreak(target, damage))
  7273. {
  7274. target.breakAttack();
  7275. target.breakCast();
  7276. }
  7277.  
  7278. // Maybe launch chance skills on us
  7279. if (_chanceSkills != null)
  7280. {
  7281. _chanceSkills.onHit(target, false, crit);
  7282. }
  7283.  
  7284. // Maybe launch chance skills on target
  7285. if (target.getChanceSkills() != null)
  7286. {
  7287. target.getChanceSkills().onHit(this, true, crit);
  7288. }
  7289.  
  7290. weapon = null;
  7291. }
  7292.  
  7293. // Launch weapon Special ability effect if available
  7294. L2Weapon activeWeapon = getActiveWeaponItem();
  7295.  
  7296. if (activeWeapon != null)
  7297. {
  7298. activeWeapon.getSkillEffects(this, target, crit);
  7299. }
  7300.  
  7301. /*
  7302. * COMMENTED OUT BY nexus - 2006-08-17 We must not discharge the soulshouts at the onHitTimer method, as this can cause unwanted soulshout consumption if the attacker recharges the soulshot right after an attack request but before his hit actually lands on the target. The soulshot
  7303. * discharging has been moved to the doAttack method: As soon as we know that we didn't missed the hit there, then we must discharge any charged soulshots.
  7304. */
  7305. /*
  7306. * L2ItemInstance weapon = getActiveWeaponInstance(); if (!miss) { if (this instanceof L2Summon && !(this instanceof L2PetInstance)) { if (((L2Summon)this).getChargedSoulShot() != L2ItemInstance.CHARGED_NONE) ((L2Summon)this).setChargedSoulShot(L2ItemInstance.CHARGED_NONE); } else { if
  7307. * (weapon != null && weapon.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE) weapon.setChargedSoulshot(L2ItemInstance.CHARGED_NONE); } }
  7308. */
  7309.  
  7310. activeWeapon = null;
  7311.  
  7312. if (this instanceof L2PcInstance && ((L2PcInstance) this).isMovingTaskDefined())
  7313. {
  7314. final L2ItemInstance rhand = ((L2PcInstance) this).getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  7315. if (rhand != null && rhand.getItemType() == L2WeaponType.BOW)
  7316. ((L2PcInstance) this).startMovingTask();
  7317. }
  7318. return;
  7319. }
  7320.  
  7321. if (this instanceof L2PcInstance && ((L2PcInstance) this).isMovingTaskDefined())
  7322. {
  7323. final L2ItemInstance rhand = ((L2PcInstance) this).getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  7324. if (rhand != null && rhand.getItemType() == L2WeaponType.BOW)
  7325. ((L2PcInstance) this).startMovingTask();
  7326. }
  7327.  
  7328. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  7329. }
  7330.  
  7331. /**
  7332. * Break an attack and send Server->Client ActionFailed packet and a System Message to the L2Character.<BR>
  7333. * <BR>
  7334. */
  7335. public void breakAttack()
  7336. {
  7337. if (isAttackingNow())
  7338. {
  7339. // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  7340. abortAttack();
  7341.  
  7342. if (this instanceof L2PcInstance)
  7343. {
  7344. sendPacket(ActionFailed.STATIC_PACKET);
  7345.  
  7346. // Send a system message
  7347. sendPacket(new SystemMessage(SystemMessageId.ATTACK_FAILED));
  7348. }
  7349. }
  7350. }
  7351.  
  7352. /**
  7353. * Break a cast and send Server->Client ActionFailed packet and a System Message to the L2Character.<BR>
  7354. * <BR>
  7355. */
  7356. public void breakCast()
  7357. {
  7358. // damage can only cancel magical skills
  7359. if (isCastingNow() && canAbortCast() && getLastSkillCast() != null && getLastSkillCast().isMagic())
  7360. {
  7361. // Abort the cast of the L2Character and send Server->Client MagicSkillCanceld/ActionFailed packet.
  7362. abortCast();
  7363.  
  7364. if (this instanceof L2PcInstance)
  7365. {
  7366. // Send a system message
  7367. sendPacket(new SystemMessage(SystemMessageId.CASTING_INTERRUPTED));
  7368. }
  7369. }
  7370. }
  7371.  
  7372. /**
  7373. * Reduce the arrow number of the L2Character.<BR>
  7374. * <BR>
  7375. * <B><U> Overriden in </U> :</B><BR>
  7376. * <BR>
  7377. * <li>L2PcInstance</li><BR>
  7378. * <BR>
  7379. */
  7380. protected void reduceArrowCount()
  7381. {
  7382. // default is to do nothin
  7383. }
  7384.  
  7385. /**
  7386. * Manage Forced attack (shift + select target).<BR>
  7387. * <BR>
  7388. * <B><U> Actions</U> :</B><BR>
  7389. * <BR>
  7390. * <li>If L2Character or target is in a town area, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed</li> <li>If target is confused, send a Server->Client packet ActionFailed</li> <li>If L2Character is a L2ArtefactInstance, send a Server->Client packet ActionFailed</li>
  7391. * <li>Send a Server->Client packet MyTargetSelected to start attack and Notify AI with AI_INTENTION_ATTACK</li><BR>
  7392. * <BR>
  7393. * @param player The L2PcInstance to attack
  7394. */
  7395. @Override
  7396. public void onForcedAttack(final L2PcInstance player)
  7397. {
  7398. if (player.getTarget() == null || !(player.getTarget() instanceof L2Character))
  7399. {
  7400. // If target is not attackable, send a Server->Client packet ActionFailed
  7401. player.sendPacket(ActionFailed.STATIC_PACKET);
  7402. return;
  7403. }
  7404.  
  7405. if (isInsidePeaceZone(player))
  7406. {
  7407. // If L2Character or target is in a peace zone, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed
  7408. player.sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  7409. player.sendPacket(ActionFailed.STATIC_PACKET);
  7410. return;
  7411. }
  7412.  
  7413. if (player.isInOlympiadMode() && player.getTarget() != null && player.getTarget() instanceof L2PlayableInstance)
  7414. {
  7415. L2PcInstance target;
  7416.  
  7417. if (player.getTarget() instanceof L2Summon)
  7418. {
  7419. target = ((L2Summon) player.getTarget()).getOwner();
  7420. }
  7421. else
  7422. {
  7423. target = (L2PcInstance) player.getTarget();
  7424. }
  7425.  
  7426. if (target.isInOlympiadMode() && !player.isOlympiadStart() && player.getOlympiadGameId() == target.getOlympiadGameId())
  7427. {
  7428. // if L2PcInstance is in Olympia and the match isn't already start, send a Server->Client packet ActionFailed
  7429. player.sendPacket(ActionFailed.STATIC_PACKET);
  7430. return;
  7431. }
  7432.  
  7433. target = null;
  7434. }
  7435.  
  7436. if (player.isConfused() || player.isBlocked())
  7437. {
  7438. // If target is confused, send a Server->Client packet ActionFailed
  7439. player.sendPacket(ActionFailed.STATIC_PACKET);
  7440. return;
  7441. }
  7442.  
  7443. // GeoData Los Check or dz > 1000
  7444. if (!GeoData.getInstance().canSeeTarget(player, this))
  7445. {
  7446. player.sendPacket(new SystemMessage(SystemMessageId.CANT_SEE_TARGET));
  7447. player.sendPacket(ActionFailed.STATIC_PACKET);
  7448. return;
  7449. }
  7450. // Notify AI with AI_INTENTION_ATTACK
  7451. player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
  7452. }
  7453.  
  7454. /**
  7455. * Return True if inside peace zone.<BR>
  7456. * <BR>
  7457. * @param attacker the attacker
  7458. * @return true, if is inside peace zone
  7459. */
  7460. public boolean isInsidePeaceZone(final L2PcInstance attacker)
  7461. {
  7462. return isInsidePeaceZone(attacker, this);
  7463.  
  7464. }
  7465.  
  7466. /**
  7467. * Checks if is inside peace zone.
  7468. * @param attacker the attacker
  7469. * @param target the target
  7470. * @return true, if is inside peace zone
  7471. */
  7472. public static boolean isInsidePeaceZone(final L2Object attacker, final L2Object target)
  7473. {
  7474. if (target == null)
  7475. return false;
  7476.  
  7477. if (target instanceof L2NpcInstance && Config.DISABLE_ATTACK_NPC_TYPE)
  7478. {
  7479. final String mobtype = ((L2NpcInstance) target).getTemplate().type;
  7480. if (Config.LIST_ALLOWED_NPC_TYPES.contains(mobtype))
  7481. {
  7482. return false;
  7483. }
  7484. }
  7485.  
  7486. // Attack Monster on Peace Zone like L2OFF.
  7487. if (target instanceof L2MonsterInstance || attacker instanceof L2MonsterInstance && Config.ALT_MOB_AGRO_IN_PEACEZONE)
  7488. return false;
  7489.  
  7490. // Attack Guard on Peace Zone like L2OFF.
  7491. if (target instanceof L2GuardInstance || attacker instanceof L2GuardInstance)
  7492. return false;
  7493. // Attack NPC on Peace Zone like L2OFF.
  7494. if (target instanceof L2NpcInstance || attacker instanceof L2NpcInstance)
  7495. return false;
  7496.  
  7497. if (Config.ALT_GAME_KARMA_PLAYER_CAN_BE_KILLED_IN_PEACEZONE)
  7498. {
  7499. // allows red to be attacked and red to attack flagged players
  7500. if (target instanceof L2PcInstance && ((L2PcInstance) target).getKarma() > 0)
  7501. return false;
  7502.  
  7503. if (target instanceof L2Summon && ((L2Summon) target).getOwner().getKarma() > 0)
  7504. return false;
  7505.  
  7506. if (attacker instanceof L2PcInstance && ((L2PcInstance) attacker).getKarma() > 0)
  7507. {
  7508. if (target instanceof L2PcInstance && ((L2PcInstance) target).getPvpFlag() > 0)
  7509. return false;
  7510.  
  7511. if (target instanceof L2Summon && ((L2Summon) target).getOwner().getPvpFlag() > 0)
  7512. return false;
  7513. }
  7514.  
  7515. if (attacker instanceof L2Summon && ((L2Summon) attacker).getOwner().getKarma() > 0)
  7516. {
  7517. if (target instanceof L2PcInstance && ((L2PcInstance) target).getPvpFlag() > 0)
  7518. return false;
  7519.  
  7520. if (target instanceof L2Summon && ((L2Summon) target).getOwner().getPvpFlag() > 0)
  7521. return false;
  7522. }
  7523. }
  7524.  
  7525. // Right now only L2PcInstance has up-to-date zone status...
  7526. //
  7527. L2PcInstance src = null;
  7528. L2PcInstance dst = null;
  7529.  
  7530. if (attacker instanceof L2PlayableInstance && target instanceof L2PlayableInstance)
  7531. {
  7532. if (attacker instanceof L2PcInstance)
  7533. {
  7534. src = (L2PcInstance) attacker;
  7535. }
  7536. else if (attacker instanceof L2Summon)
  7537. {
  7538. src = ((L2Summon) attacker).getOwner();
  7539. }
  7540.  
  7541. if (target instanceof L2PcInstance)
  7542. {
  7543. dst = (L2PcInstance) target;
  7544. }
  7545. else if (target instanceof L2Summon)
  7546. {
  7547. dst = ((L2Summon) target).getOwner();
  7548. }
  7549. }
  7550.  
  7551. if (src != null && src.getAccessLevel().allowPeaceAttack())
  7552. {
  7553. return false;
  7554. }
  7555.  
  7556. // checks on event status
  7557. if (src != null && dst != null)
  7558. {
  7559. // Attacker and target can fight in olympiad with peace zone
  7560. if (src.isInOlympiadMode() && src.isOlympiadStart() && dst.isInOlympiadMode() && dst.isOlympiadStart())
  7561. return false;
  7562.  
  7563. if (dst.isInFunEvent() && src.isInFunEvent())
  7564. {
  7565.  
  7566. if (src.isInStartedTVTEvent() && dst.isInStartedTVTEvent())
  7567. return false;
  7568. else if (src.isInStartedDMEvent() && dst.isInStartedDMEvent())
  7569. return false;
  7570. else if (src.isInStartedCTFEvent() && dst.isInStartedCTFEvent())
  7571. return false;
  7572. else if (src.isInStartedVIPEvent() && dst.isInStartedVIPEvent())
  7573. return false;
  7574. else if (src.isInStartedVIPEvent() && dst.isInStartedVIPEvent())
  7575. return false;
  7576. // else
  7577. // different events in same location --> already checked
  7578. }
  7579. }
  7580.  
  7581. if (attacker instanceof L2Character && ((L2Character) attacker).isInsideZone(ZONE_PEACE)
  7582. // the townzone has to be already peace zone
  7583. // || TownManager.getInstance().getTown(attacker.getX(), attacker.getY(), attacker.getZ())!= null
  7584. )
  7585. return true;
  7586.  
  7587. if (target instanceof L2Character && ((L2Character) target).isInsideZone(ZONE_PEACE)
  7588. // the townzone has to be already peace zone
  7589. // || TownManager.getInstance().getTown(target.getX(), target.getY(), target.getZ())!= null
  7590. )
  7591. return true;
  7592.  
  7593. return false;
  7594. }
  7595.  
  7596. /**
  7597. * return true if this character is inside an active grid.
  7598. * @return the boolean
  7599. */
  7600. public Boolean isInActiveRegion()
  7601. {
  7602. try
  7603. {
  7604. final L2WorldRegion region = L2World.getInstance().getRegion(getX(), getY());
  7605. return region != null && region.isActive();
  7606. }
  7607. catch (final Exception e)
  7608. {
  7609. if (this instanceof L2PcInstance)
  7610. {
  7611. LOGGER.warn("Player " + getName() + " at bad coords: (x: " + getX() + ", y: " + getY() + ", z: " + getZ() + ").");
  7612.  
  7613. ((L2PcInstance) this).sendMessage("Error with your coordinates! Please reboot your game fully!");
  7614. ((L2PcInstance) this).teleToLocation(80753, 145481, -3532, false); // Near Giran luxury shop
  7615. }
  7616. else
  7617. {
  7618. LOGGER.warn("Object " + getName() + " at bad coords: (x: " + getX() + ", y: " + getY() + ", z: " + getZ() + ").");
  7619. decayMe();
  7620. }
  7621. return false;
  7622. }
  7623. }
  7624.  
  7625. /**
  7626. * Return True if the L2Character has a Party in progress.<BR>
  7627. * <BR>
  7628. * @return true, if is in party
  7629. */
  7630. public boolean isInParty()
  7631. {
  7632. return false;
  7633. }
  7634.  
  7635. /**
  7636. * Return the L2Party object of the L2Character.<BR>
  7637. * <BR>
  7638. * @return the party
  7639. */
  7640. public L2Party getParty()
  7641. {
  7642. return null;
  7643. }
  7644.  
  7645. /**
  7646. * Return the Attack Speed of the L2Character (delay (in milliseconds) before next attack).<BR>
  7647. * <BR>
  7648. * @param target the target
  7649. * @param weapon the weapon
  7650. * @return the int
  7651. */
  7652. public int calculateTimeBetweenAttacks(final L2Character target, final L2Weapon weapon)
  7653. {
  7654. double atkSpd = 0;
  7655. if (weapon != null)
  7656. {
  7657. switch (weapon.getItemType())
  7658. {
  7659. case BOW:
  7660. atkSpd = getStat().getPAtkSpd();
  7661. return (int) (1500 * 345 / atkSpd);
  7662. case DAGGER:
  7663. atkSpd = getStat().getPAtkSpd();
  7664. // atkSpd /= 1.15;
  7665. break;
  7666. default:
  7667. atkSpd = getStat().getPAtkSpd();
  7668. }
  7669. }
  7670. else
  7671. {
  7672. atkSpd = getPAtkSpd();
  7673. }
  7674.  
  7675. return Formulas.getInstance().calcPAtkSpd(this, target, atkSpd);
  7676. }
  7677.  
  7678. /**
  7679. * Calculate reuse time.
  7680. * @param target the target
  7681. * @param weapon the weapon
  7682. * @return the int
  7683. */
  7684. public int calculateReuseTime(final L2Character target, final L2Weapon weapon)
  7685. {
  7686. if (weapon == null)
  7687. return 0;
  7688.  
  7689. int reuse = weapon.getAttackReuseDelay();
  7690.  
  7691. // only bows should continue for now
  7692. if (reuse == 0)
  7693. return 0;
  7694.  
  7695. // else if (reuse < 10) reuse = 1500;
  7696. reuse *= getStat().getReuseModifier(target);
  7697.  
  7698. final double atkSpd = getStat().getPAtkSpd();
  7699.  
  7700. switch (weapon.getItemType())
  7701. {
  7702. case BOW:
  7703. return (int) (reuse * 345 / atkSpd);
  7704. default:
  7705. return (int) (reuse * 312 / atkSpd);
  7706. }
  7707. }
  7708.  
  7709. /**
  7710. * Return True if the L2Character use a dual weapon.<BR>
  7711. * <BR>
  7712. * @return true, if is using dual weapon
  7713. */
  7714. public boolean isUsingDualWeapon()
  7715. {
  7716. return false;
  7717. }
  7718.  
  7719. /**
  7720. * Add a skill to the L2Character _skills and its Func objects to the calculator set of the L2Character.<BR>
  7721. * <BR>
  7722. * <B><U> Concept</U> :</B><BR>
  7723. * <BR>
  7724. * All skills own by a L2Character are identified in <B>_skills</B><BR>
  7725. * <BR>
  7726. * <B><U> Actions</U> :</B><BR>
  7727. * <BR>
  7728. * <li>Replace oldSkill by newSkill or Add the newSkill</li> <li>If an old skill has been replaced, remove all its Func objects of L2Character calculator set</li> <li>Add Func objects of newSkill to the calculator set of the L2Character</li><BR>
  7729. * <BR>
  7730. * <B><U> Overriden in </U> :</B><BR>
  7731. * <BR>
  7732. * <li>L2PcInstance : Save update in the character_skills table of the database</li><BR>
  7733. * <BR>
  7734. * @param newSkill The L2Skill to add to the L2Character
  7735. * @return The L2Skill replaced or null if just added a new L2Skill
  7736. */
  7737. @Override
  7738. public L2Skill addSkill(final L2Skill newSkill)
  7739. {
  7740. L2Skill oldSkill = null;
  7741.  
  7742. if (newSkill != null)
  7743. {
  7744. // Replace oldSkill by newSkill or Add the newSkill
  7745. oldSkill = _skills.put(newSkill.getId(), newSkill);
  7746.  
  7747. // If an old skill has been replaced, remove all its Func objects
  7748. if (oldSkill != null)
  7749. {
  7750. // if skill came with another one, we should delete the other one too.
  7751. if (oldSkill.triggerAnotherSkill())
  7752. {
  7753. if (Config.DEBUG)
  7754. LOGGER.info("Removing Triggherable Skill: " + oldSkill.getTriggeredId());
  7755.  
  7756. _triggeredSkills.remove(oldSkill.getTriggeredId());
  7757. removeSkill(oldSkill.getTriggeredId(), true);
  7758. }
  7759. removeStatsOwner(oldSkill);
  7760.  
  7761. // final Func[] skill_funcs = oldSkill.getStatFuncs(null, this);
  7762.  
  7763. // // Remove old func if single effect skill is defined
  7764. // if(newSkill.is_singleEffect()
  7765. // && skill_funcs.length>0)
  7766. // removeStatFuncs(skill_funcs);
  7767.  
  7768. }
  7769.  
  7770. // Add Func objects of newSkill to the calculator set of the L2Character
  7771. addStatFuncs(newSkill.getStatFuncs(null, this));
  7772.  
  7773. if (oldSkill != null && _chanceSkills != null)
  7774. {
  7775. removeChanceSkill(oldSkill.getId());
  7776. }
  7777. if (newSkill.isChance())
  7778. {
  7779. addChanceSkill(newSkill);
  7780. }
  7781.  
  7782. if (newSkill.isChance() && newSkill.triggerAnotherSkill())
  7783. {
  7784. final L2Skill triggeredSkill = SkillTable.getInstance().getInfo(newSkill.getTriggeredId(), newSkill.getTriggeredLevel());
  7785. addSkill(triggeredSkill);
  7786. }
  7787.  
  7788. if (newSkill.triggerAnotherSkill())
  7789. {
  7790. if (Config.DEBUG)
  7791. LOGGER.info("Adding Triggherable Skill: " + newSkill.getTriggeredId());
  7792. _triggeredSkills.put(newSkill.getTriggeredId(), SkillTable.getInstance().getInfo(newSkill.getTriggeredId(), newSkill.getTriggeredLevel()));
  7793. }
  7794.  
  7795. }
  7796.  
  7797. return oldSkill;
  7798. }
  7799.  
  7800. /**
  7801. * Adds the chance skill.
  7802. * @param skill the skill
  7803. */
  7804. public void addChanceSkill(final L2Skill skill)
  7805. {
  7806. synchronized (this)
  7807. {
  7808. if (_chanceSkills == null)
  7809. {
  7810. _chanceSkills = new ChanceSkillList(this);
  7811. }
  7812.  
  7813. _chanceSkills.put(skill, skill.getChanceCondition());
  7814. }
  7815. }
  7816.  
  7817. /**
  7818. * Removes the chance skill.
  7819. * @param id the id
  7820. */
  7821. public void removeChanceSkill(final int id)
  7822. {
  7823. synchronized (this)
  7824. {
  7825. for (final L2Skill skill : _chanceSkills.keySet())
  7826. {
  7827. if (skill.getId() == id)
  7828. {
  7829. _chanceSkills.remove(skill);
  7830. }
  7831. }
  7832.  
  7833. if (_chanceSkills.size() == 0)
  7834. {
  7835. _chanceSkills = null;
  7836. }
  7837. }
  7838. }
  7839.  
  7840. /**
  7841. * Remove a skill from the L2Character and its Func objects from calculator set of the L2Character.<BR>
  7842. * <BR>
  7843. * <B><U> Concept</U> :</B><BR>
  7844. * <BR>
  7845. * All skills own by a L2Character are identified in <B>_skills</B><BR>
  7846. * <BR>
  7847. * <B><U> Actions</U> :</B><BR>
  7848. * <BR>
  7849. * <li>Remove the skill from the L2Character _skills</li> <li>Remove all its Func objects from the L2Character calculator set</li><BR>
  7850. * <BR>
  7851. * <B><U> Overriden in </U> :</B><BR>
  7852. * <BR>
  7853. * <li>L2PcInstance : Save update in the character_skills table of the database</li><BR>
  7854. * <BR>
  7855. * @param skill The L2Skill to remove from the L2Character
  7856. * @return The L2Skill removed
  7857. */
  7858. public synchronized L2Skill removeSkill(final L2Skill skill)
  7859. {
  7860. if (skill == null)
  7861. return null;
  7862.  
  7863. // Remove the skill from the L2Character _skills
  7864. return removeSkill(skill.getId());
  7865. }
  7866.  
  7867. /**
  7868. * Removes the skill.
  7869. * @param skillId the skill id
  7870. * @return the l2 skill
  7871. */
  7872. public L2Skill removeSkill(final int skillId)
  7873. {
  7874. return removeSkill(skillId, true);
  7875. }
  7876.  
  7877. /**
  7878. * Removes the skill.
  7879. * @param skillId the skill id
  7880. * @param cancelEffect the cancel effect
  7881. * @return the l2 skill
  7882. */
  7883. public L2Skill removeSkill(final int skillId, final boolean cancelEffect)
  7884. {
  7885. // Remove the skill from the L2Character _skills
  7886. final L2Skill oldSkill = _skills.remove(skillId);
  7887. // Remove all its Func objects from the L2Character calculator set
  7888. if (oldSkill != null)
  7889. {
  7890. // this is just a fail-safe againts buggers and gm dummies...
  7891. if (oldSkill.triggerAnotherSkill())
  7892. {
  7893. if (Config.DEBUG)
  7894. LOGGER.info("Removing Triggherable Skill: " + oldSkill.getTriggeredId());
  7895. removeSkill(oldSkill.getTriggeredId(), true);
  7896. _triggeredSkills.remove(oldSkill.getTriggeredId());
  7897. }
  7898.  
  7899. // Stop casting if this skill is used right now
  7900. if (getLastSkillCast() != null && isCastingNow())
  7901. {
  7902. if (oldSkill.getId() == getLastSkillCast().getId())
  7903. {
  7904. abortCast();
  7905. }
  7906. }
  7907.  
  7908. if (cancelEffect || oldSkill.isToggle())
  7909. {
  7910. final L2Effect e = getFirstEffect(oldSkill);
  7911. if (e == null)
  7912. {
  7913. removeStatsOwner(oldSkill);
  7914. stopSkillEffects(oldSkill.getId());
  7915. }
  7916. }
  7917.  
  7918. if (oldSkill.isChance() && _chanceSkills != null)
  7919. {
  7920. removeChanceSkill(oldSkill.getId());
  7921. }
  7922. removeStatsOwner(oldSkill);
  7923. }
  7924. return oldSkill;
  7925. }
  7926.  
  7927. /**
  7928. * Return all skills own by the L2Character in a table of L2Skill.<BR>
  7929. * <BR>
  7930. * <B><U> Concept</U> :</B><BR>
  7931. * <BR>
  7932. * All skills own by a L2Character are identified in <B>_skills</B> the L2Character <BR>
  7933. * <BR>
  7934. * @return the all skills
  7935. */
  7936. public final L2Skill[] getAllSkills()
  7937. {
  7938. return _skills.values().toArray(new L2Skill[_skills.values().size()]);
  7939. }
  7940.  
  7941. /**
  7942. * @return the map containing this character skills.
  7943. */
  7944. @Override
  7945. public Map<Integer, L2Skill> getSkills()
  7946. {
  7947. return _skills;
  7948. }
  7949.  
  7950. /**
  7951. * Gets the chance skills.
  7952. * @return the chance skills
  7953. */
  7954. public ChanceSkillList getChanceSkills()
  7955. {
  7956. return _chanceSkills;
  7957. }
  7958.  
  7959. /**
  7960. * Return the level of a skill owned by the L2Character.<BR>
  7961. * <BR>
  7962. * @param skillId The identifier of the L2Skill whose level must be returned
  7963. * @return The level of the L2Skill identified by skillId
  7964. */
  7965. @Override
  7966. public int getSkillLevel(final int skillId)
  7967. {
  7968. final L2Skill skill = _skills.get(skillId);
  7969.  
  7970. if (skill == null)
  7971. return -1;
  7972.  
  7973. return skill.getLevel();
  7974. }
  7975.  
  7976. /**
  7977. * Return True if the skill is known by the L2Character.<BR>
  7978. * <BR>
  7979. * @param skillId The identifier of the L2Skill to check the knowledge
  7980. * @return the known skill
  7981. */
  7982. @Override
  7983. public final L2Skill getKnownSkill(final int skillId)
  7984. {
  7985. return _skills.get(skillId);
  7986. }
  7987.  
  7988. /**
  7989. * Return the number of skills of type(Buff, Debuff, HEAL_PERCENT, MANAHEAL_PERCENT) affecting this L2Character.<BR>
  7990. * <BR>
  7991. * @return The number of Buffs affecting this L2Character
  7992. */
  7993. public int getBuffCount()
  7994. {
  7995. final L2Effect[] effects = getAllEffects();
  7996.  
  7997. int numBuffs = 0;
  7998.  
  7999. for (final L2Effect e : effects)
  8000. {
  8001. if (e == null)
  8002. {
  8003. synchronized (_effects)
  8004. {
  8005. _effects.remove(e);
  8006. }
  8007. continue;
  8008. }
  8009.  
  8010. if ((e.getSkill().getSkillType() == L2Skill.SkillType.BUFF || e.getSkill().getId() == 1416 || e.getSkill().getSkillType() == L2Skill.SkillType.REFLECT || e.getSkill().getSkillType() == L2Skill.SkillType.HEAL_PERCENT || e.getSkill().getSkillType() == L2Skill.SkillType.MANAHEAL_PERCENT) && !(e.getSkill().getId() > 4360 && e.getSkill().getId() < 4367)) // 7s
  8011. // buffs
  8012. {
  8013. numBuffs++;
  8014. }
  8015. }
  8016.  
  8017. return numBuffs;
  8018. }
  8019.  
  8020. /**
  8021. * Return the number of skills of type(Debuff, poison, slow, etc.) affecting this L2Character.<BR>
  8022. * <BR>
  8023. * @return The number of debuff affecting this L2Character
  8024. */
  8025. public int getDeBuffCount()
  8026. {
  8027. final L2Effect[] effects = getAllEffects();
  8028. int numDeBuffs = 0;
  8029.  
  8030. for (final L2Effect e : effects)
  8031. {
  8032. if (e == null)
  8033. {
  8034. synchronized (_effects)
  8035. {
  8036. _effects.remove(e);
  8037. }
  8038. continue;
  8039. }
  8040.  
  8041. // Check for all debuff skills
  8042. if (e.getSkill().is_Debuff())
  8043. {
  8044. numDeBuffs++;
  8045. }
  8046. }
  8047.  
  8048. return numDeBuffs;
  8049. }
  8050.  
  8051. /**
  8052. * Gets the max buff count.
  8053. * @return the max buff count
  8054. */
  8055. public int getMaxBuffCount()
  8056. {
  8057. return Config.BUFFS_MAX_AMOUNT + Math.max(0, getSkillLevel(L2Skill.SKILL_DIVINE_INSPIRATION));
  8058. }
  8059.  
  8060. /**
  8061. * Removes the first Buff of this L2Character.<BR>
  8062. * <BR>
  8063. * @param preferSkill If != 0 the given skill Id will be removed instead of first
  8064. */
  8065. public void removeFirstBuff(final int preferSkill)
  8066. {
  8067. final L2Effect[] effects = getAllEffects();
  8068.  
  8069. L2Effect removeMe = null;
  8070.  
  8071. for (final L2Effect e : effects)
  8072. {
  8073. if (e == null)
  8074. {
  8075. synchronized (_effects)
  8076. {
  8077. _effects.remove(e);
  8078. }
  8079. continue;
  8080. }
  8081.  
  8082. if ((e.getSkill().getSkillType() == L2Skill.SkillType.BUFF || e.getSkill().getSkillType() == L2Skill.SkillType.REFLECT || e.getSkill().getSkillType() == L2Skill.SkillType.HEAL_PERCENT || e.getSkill().getSkillType() == L2Skill.SkillType.MANAHEAL_PERCENT) && !(e.getSkill().getId() > 4360 && e.getSkill().getId() < 4367))
  8083. {
  8084. if (preferSkill == 0)
  8085. {
  8086. removeMe = e;
  8087. break;
  8088. }
  8089. else if (e.getSkill().getId() == preferSkill)
  8090. {
  8091. removeMe = e;
  8092. break;
  8093. }
  8094. else if (removeMe == null)
  8095. {
  8096. removeMe = e;
  8097. }
  8098. }
  8099. }
  8100.  
  8101. if (removeMe != null)
  8102. {
  8103. removeMe.exit(true);
  8104. }
  8105. }
  8106.  
  8107. /**
  8108. * Removes the first DeBuff of this L2Character.<BR>
  8109. * <BR>
  8110. * @param preferSkill If != 0 the given skill Id will be removed instead of first
  8111. */
  8112. public void removeFirstDeBuff(final int preferSkill)
  8113. {
  8114. final L2Effect[] effects = getAllEffects();
  8115.  
  8116. L2Effect removeMe = null;
  8117.  
  8118. for (final L2Effect e : effects)
  8119. {
  8120. if (e == null)
  8121. {
  8122.  
  8123. synchronized (_effects)
  8124. {
  8125. _effects.remove(e);
  8126. }
  8127. continue;
  8128. }
  8129.  
  8130. if (e.getSkill().is_Debuff())
  8131. {
  8132. if (preferSkill == 0)
  8133. {
  8134. removeMe = e;
  8135. break;
  8136. }
  8137. else if (e.getSkill().getId() == preferSkill)
  8138. {
  8139. removeMe = e;
  8140. break;
  8141. }
  8142. else if (removeMe == null)
  8143. {
  8144. removeMe = e;
  8145. }
  8146. }
  8147. }
  8148.  
  8149. if (removeMe != null)
  8150. {
  8151. removeMe.exit(true);
  8152. }
  8153. }
  8154.  
  8155. /**
  8156. * Gets the dance count.
  8157. * @return the dance count
  8158. */
  8159. public int getDanceCount()
  8160. {
  8161. int danceCount = 0;
  8162.  
  8163. final L2Effect[] effects = getAllEffects();
  8164.  
  8165. for (final L2Effect e : effects)
  8166. {
  8167. if (e == null)
  8168. {
  8169. synchronized (_effects)
  8170. {
  8171. _effects.remove(e);
  8172. }
  8173. continue;
  8174. }
  8175.  
  8176. if (e.getSkill().isDance() && e.getInUse())
  8177. {
  8178. danceCount++;
  8179. }
  8180. }
  8181.  
  8182. return danceCount;
  8183. }
  8184.  
  8185. /**
  8186. * Checks if the given skill stacks with an existing one.<BR>
  8187. * <BR>
  8188. * @param checkSkill the skill to be checked
  8189. * @return Returns whether or not this skill will stack
  8190. */
  8191. public boolean doesStack(final L2Skill checkSkill)
  8192. {
  8193. if (_effects.size() < 1 || checkSkill._effectTemplates == null || checkSkill._effectTemplates.length < 1 || checkSkill._effectTemplates[0].stackType == null)
  8194. return false;
  8195.  
  8196. final String stackType = checkSkill._effectTemplates[0].stackType;
  8197.  
  8198. if (stackType.equals("none"))
  8199. return false;
  8200.  
  8201. final L2Effect[] effects = getAllEffects();
  8202.  
  8203. for (final L2Effect e : effects)
  8204. {
  8205. if (e == null)
  8206. {
  8207. synchronized (_effects)
  8208. {
  8209. _effects.remove(e);
  8210. }
  8211. continue;
  8212. }
  8213.  
  8214. if (e.getStackType() != null && e.getStackType().equals(stackType))
  8215. return true;
  8216. }
  8217.  
  8218. return false;
  8219. }
  8220.  
  8221. /**
  8222. * Manage the magic skill launching task (MP, HP, Item consummation...) and display the magic skill animation on client.<BR>
  8223. * <BR>
  8224. * <B><U> Actions</U> :</B><BR>
  8225. * <BR>
  8226. * <li>Send a Server->Client packet MagicSkillLaunched (to display magic skill animation) to all L2PcInstance of L2Charcater _knownPlayers</li> <li>Consumme MP, HP and Item if necessary</li> <li>Send a Server->Client packet StatusUpdate with MP modification to the L2PcInstance</li> <li>Launch
  8227. * the magic skill in order to calculate its effects</li> <li>If the skill type is PDAM, notify the AI of the target with AI_INTENTION_ATTACK</li> <li>Notify the AI of the L2Character with EVT_FINISH_CASTING</li><BR>
  8228. * <BR>
  8229. * <FONT COLOR=#FF0000><B> <U>Caution</U> : A magic skill casting MUST BE in progress</B></FONT><BR>
  8230. * <BR>
  8231. * @param targets the targets
  8232. * @param skill The L2Skill to use
  8233. * @param coolTime the cool time
  8234. * @param instant the instant
  8235. */
  8236. public void onMagicLaunchedTimer(final L2Object[] targets, final L2Skill skill, final int coolTime, final boolean instant)
  8237. {
  8238. if (skill == null || (targets == null || targets.length <= 0) && skill.getTargetType() != SkillTargetType.TARGET_AURA)
  8239. {
  8240. _skillCast = null;
  8241. enableAllSkills();
  8242. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  8243.  
  8244. return;
  8245. }
  8246.  
  8247. // Escaping from under skill's radius and peace zone check. First version, not perfect in AoE skills.
  8248. int escapeRange = 0;
  8249.  
  8250. if (skill.getEffectRange() > escapeRange)
  8251. {
  8252. escapeRange = skill.getEffectRange();
  8253. }
  8254. else if (skill.getCastRange() < 0 && skill.getSkillRadius() > 80)
  8255. {
  8256. escapeRange = skill.getSkillRadius();
  8257. }
  8258.  
  8259. L2Object[] final_targets = null;
  8260. int _skipped = 0;
  8261.  
  8262. if (escapeRange > 0)
  8263. {
  8264. List<L2Character> targetList = new FastList<>();
  8265.  
  8266. for (int i = 0; targets != null && i < targets.length; i++)
  8267. {
  8268. if (targets[i] instanceof L2Character)
  8269. {
  8270. if (!Util.checkIfInRange(escapeRange, this, targets[i], true))
  8271. {
  8272. continue;
  8273. }
  8274.  
  8275. // Check if the target is behind a wall
  8276. if (skill.getSkillRadius() > 0 && skill.isOffensive() && Config.GEODATA > 0 && !GeoData.getInstance().canSeeTarget(this, targets[i]))
  8277. {
  8278. _skipped++;
  8279. continue;
  8280. }
  8281.  
  8282. if (skill.isOffensive())
  8283. {
  8284. if (this instanceof L2PcInstance)
  8285. {
  8286. if (((L2Character) targets[i]).isInsidePeaceZone((L2PcInstance) this))
  8287. {
  8288. continue;
  8289. }
  8290. }
  8291. else
  8292. {
  8293. if (L2Character.isInsidePeaceZone(this, targets[i]))
  8294. {
  8295. continue;
  8296. }
  8297. }
  8298. }
  8299. targetList.add((L2Character) targets[i]);
  8300. }
  8301. // else
  8302. // {
  8303. // if (Config.DEBUG)
  8304. // LOGGER.warn("Class cast bad: "+targets[i].getClass().toString());
  8305. // }
  8306. }
  8307. if (targetList.isEmpty() && skill.getTargetType() != SkillTargetType.TARGET_AURA)
  8308. {
  8309. if (this instanceof L2PcInstance)
  8310. {
  8311. for (int i = 0; i < _skipped; i++)
  8312. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CANT_SEE_TARGET));
  8313.  
  8314. }
  8315.  
  8316. abortCast();
  8317. return;
  8318. }
  8319. final_targets = targetList.toArray(new L2Character[targetList.size()]);
  8320. targetList = null;
  8321.  
  8322. }
  8323. else
  8324. {
  8325.  
  8326. final_targets = targets;
  8327.  
  8328. }
  8329.  
  8330. // if the skill is not a potion and player
  8331. // is not casting now
  8332. // Ensure that a cast is in progress
  8333. // Check if player is using fake death.
  8334. // Potions can be used while faking death.
  8335. if (!skill.isPotion())
  8336. {
  8337. if (!isCastingNow() || isAlikeDead())
  8338. {
  8339. _skillCast = null;
  8340. enableAllSkills();
  8341.  
  8342. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  8343.  
  8344. _castEndTime = 0;
  8345. _castInterruptTime = 0;
  8346. return;
  8347. }
  8348. }/*
  8349. * else{ if(!isCastingPotionNow()) { _potionCast = null; enableAllSkills(); getAI().notifyEvent(CtrlEvent.EVT_CANCEL); _castPotionEndTime = 0; _castPotionInterruptTime = 0; return; } }
  8350. */
  8351.  
  8352. // Get the display identifier of the skill
  8353. final int magicId = skill.getDisplayId();
  8354.  
  8355. // Get the level of the skill
  8356. int level = getSkillLevel(skill.getId());
  8357.  
  8358. if (level < 1)
  8359. {
  8360. level = 1;
  8361. }
  8362.  
  8363. // Send a Server->Client packet MagicSkillLaunched to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  8364. if (!skill.isPotion())
  8365. {
  8366. broadcastPacket(new MagicSkillLaunched(this, magicId, level, final_targets));
  8367. }
  8368.  
  8369. if (instant)
  8370. {
  8371. onMagicHitTimer(final_targets, skill, coolTime, true);
  8372. }
  8373. else
  8374. {
  8375. if (skill.isPotion())
  8376. _potionCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(final_targets, skill, coolTime, 2), 200);
  8377. else
  8378. _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(final_targets, skill, coolTime, 2), 200);
  8379.  
  8380. }
  8381.  
  8382. }
  8383.  
  8384. /*
  8385. * Runs in the end of skill casting
  8386. */
  8387. /**
  8388. * On magic hit timer.
  8389. * @param targets the targets
  8390. * @param skill the skill
  8391. * @param coolTime the cool time
  8392. * @param instant the instant
  8393. */
  8394. public void onMagicHitTimer(final L2Object[] targets, final L2Skill skill, final int coolTime, final boolean instant)
  8395. {
  8396. if (skill == null || (targets == null || targets.length <= 0) && skill.getTargetType() != SkillTargetType.TARGET_AURA)
  8397. {
  8398. _skillCast = null;
  8399. enableAllSkills();
  8400. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  8401.  
  8402. return;
  8403. }
  8404.  
  8405. if (getForceBuff() != null)
  8406. {
  8407. _skillCast = null;
  8408. enableAllSkills();
  8409.  
  8410. getForceBuff().onCastAbort();
  8411.  
  8412. return;
  8413. }
  8414.  
  8415. final L2Effect mog = getFirstEffect(L2Effect.EffectType.SIGNET_GROUND);
  8416. if (mog != null)
  8417. {
  8418. _skillCast = null;
  8419. enableAllSkills();
  8420.  
  8421. // close skill if it's not SIGNET_CASTTIME
  8422. if (mog.getSkill().getSkillType() != SkillType.SIGNET_CASTTIME)
  8423. {
  8424. mog.exit(true);
  8425. }
  8426.  
  8427. final L2Object target = targets == null ? null : targets[0];
  8428. if (target != null)
  8429. {
  8430. notifyQuestEventSkillFinished(skill, target);
  8431. }
  8432. return;
  8433. }
  8434.  
  8435. final L2Object[] targets2 = targets;
  8436. try
  8437. {
  8438. if (targets2 != null && targets2.length != 0)
  8439. {
  8440.  
  8441. // Go through targets table
  8442. for (final L2Object target2 : targets2)
  8443. {
  8444. if (target2 == null)
  8445. {
  8446. continue;
  8447. }
  8448.  
  8449. if (target2 instanceof L2PlayableInstance)
  8450. {
  8451. L2Character target = (L2Character) target2;
  8452.  
  8453. // If the skill is type STEALTH(ex: Dance of Shadow)
  8454. if (skill.isAbnormalEffectByName(ABNORMAL_EFFECT_STEALTH))
  8455. {
  8456. final L2Effect silentMove = target.getFirstEffect(L2Effect.EffectType.SILENT_MOVE);
  8457. if (silentMove != null)
  8458. silentMove.exit(true);
  8459. }
  8460.  
  8461. if (skill.getSkillType() == SkillType.BUFF || skill.getSkillType() == SkillType.SEED)
  8462. {
  8463. SystemMessage smsg = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  8464. smsg.addString(skill.getName());
  8465. target.sendPacket(smsg);
  8466. smsg = null;
  8467. }
  8468.  
  8469. if (this instanceof L2PcInstance && target instanceof L2Summon)
  8470. {
  8471. ((L2Summon) target).getOwner().sendPacket(new PetInfo((L2Summon) target));
  8472. sendPacket(new NpcInfo((L2Summon) target, this));
  8473.  
  8474. // The PetInfo packet wipes the PartySpelled (list of active spells' icons). Re-add them
  8475. ((L2Summon) target).updateEffectIcons(true);
  8476. }
  8477.  
  8478. target = null;
  8479. }
  8480. }
  8481.  
  8482. }
  8483.  
  8484. }
  8485. catch (final Exception e)
  8486. {
  8487. e.printStackTrace();
  8488. }
  8489.  
  8490. try
  8491. {
  8492.  
  8493. StatusUpdate su = new StatusUpdate(getObjectId());
  8494. boolean isSendStatus = false;
  8495.  
  8496. // Consume MP of the L2Character and Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  8497. final double mpConsume = getStat().getMpConsume(skill);
  8498.  
  8499. if (mpConsume > 0)
  8500. {
  8501. if (skill.isDance())
  8502. {
  8503. getStatus().reduceMp(calcStat(Stats.DANCE_MP_CONSUME_RATE, mpConsume, null, null));
  8504. }
  8505. else if (skill.isMagic())
  8506. {
  8507. getStatus().reduceMp(calcStat(Stats.MAGICAL_MP_CONSUME_RATE, mpConsume, null, null));
  8508. }
  8509. else
  8510. {
  8511. getStatus().reduceMp(calcStat(Stats.PHYSICAL_MP_CONSUME_RATE, mpConsume, null, null));
  8512. }
  8513.  
  8514. su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
  8515. isSendStatus = true;
  8516. }
  8517.  
  8518. // Consume HP if necessary and Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  8519. if (skill.getHpConsume() > 0)
  8520. {
  8521. double consumeHp;
  8522.  
  8523. consumeHp = calcStat(Stats.HP_CONSUME_RATE, skill.getHpConsume(), null, null);
  8524.  
  8525. if (consumeHp + 1 >= getCurrentHp())
  8526. {
  8527. consumeHp = getCurrentHp() - 1.0;
  8528. }
  8529.  
  8530. getStatus().reduceHp(consumeHp, this);
  8531.  
  8532. su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
  8533. isSendStatus = true;
  8534. }
  8535.  
  8536. // Send a Server->Client packet StatusUpdate with MP modification to the L2PcInstance
  8537. if (isSendStatus)
  8538. {
  8539. sendPacket(su);
  8540. }
  8541.  
  8542. // Consume Items if necessary and Send the Server->Client packet InventoryUpdate with Item modification to all the L2Character
  8543. if (skill.getItemConsume() > 0)
  8544. {
  8545. consumeItem(skill.getItemConsumeId(), skill.getItemConsume());
  8546. }
  8547.  
  8548. // Launch the magic skill in order to calculate its effects
  8549. callSkill(skill, targets);
  8550.  
  8551. su = null;
  8552.  
  8553. }
  8554. catch (final Exception e)
  8555. {
  8556. e.printStackTrace();
  8557. }
  8558.  
  8559. if (instant || coolTime == 0)
  8560. {
  8561.  
  8562. onMagicFinalizer(targets, skill);
  8563.  
  8564. }
  8565. else
  8566. {
  8567. if (skill.isPotion())
  8568. _potionCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 3), coolTime);
  8569. else
  8570. _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 3), coolTime);
  8571.  
  8572. }
  8573. }
  8574.  
  8575. /*
  8576. * Runs after skill hitTime+coolTime
  8577. */
  8578. /**
  8579. * On magic finalizer.
  8580. * @param targets the targets
  8581. * @param skill the skill
  8582. */
  8583. public void onMagicFinalizer(final L2Object[] targets, final L2Skill skill)
  8584. {
  8585. if (skill.isPotion())
  8586. {
  8587. _potionCast = null;
  8588. _castPotionEndTime = 0;
  8589. _castPotionInterruptTime = 0;
  8590. }
  8591. else
  8592. {
  8593. _skillCast = null;
  8594. _castEndTime = 0;
  8595. _castInterruptTime = 0;
  8596.  
  8597. enableAllSkills();
  8598.  
  8599. // if the skill has changed the character's state to something other than STATE_CASTING
  8600. // then just leave it that way, otherwise switch back to STATE_IDLE.
  8601. // if(isCastingNow())
  8602. // getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE, null);
  8603. if (skill.getId() != 345 && skill.getId() != 346)
  8604. {
  8605. // Like L2OFF while use a skill and next interntion == null the char stop auto attack
  8606. if (getAI().getNextIntention() == null && (skill.getSkillType() == SkillType.PDAM && skill.getCastRange() < 400) || skill.getSkillType() == SkillType.BLOW || skill.getSkillType() == SkillType.DRAIN_SOUL || skill.getSkillType() == SkillType.SOW || skill.getSkillType() == SkillType.SPOIL)
  8607. {
  8608. if (this instanceof L2PcInstance)
  8609. {
  8610. final L2PcInstance currPlayer = (L2PcInstance) this;
  8611. final SkillDat skilldat = currPlayer.getCurrentSkill();
  8612. // Like L2OFF if the skill is BLOW the player doesn't auto attack
  8613. // If on XML skill nextActionAttack = true the char auto attack
  8614. // If CTRL is pressed the autoattack is aborted (like L2OFF)
  8615. if (skilldat != null && !skilldat.isCtrlPressed() && skill.nextActionIsAttack() && getTarget() != null && getTarget() instanceof L2Character)
  8616. {
  8617. getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, getTarget());
  8618. }
  8619. }
  8620. else
  8621. // case NPC
  8622. {
  8623. if (skill.nextActionIsAttack() && getTarget() != null && getTarget() instanceof L2Character)
  8624. {
  8625. getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, getTarget());
  8626. }
  8627. else if ((skill.isOffensive()) && !(skill.getSkillType() == SkillType.UNLOCK) && !(skill.getSkillType() == SkillType.BLOW) && !(skill.getSkillType() == SkillType.DELUXE_KEY_UNLOCK) && skill.getId() != 345 && skill.getId() != 346)
  8628. {
  8629. getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, getTarget());
  8630. getAI().clientStartAutoAttack();
  8631. }
  8632. }
  8633. }
  8634. if (this instanceof L2PcInstance)
  8635. {
  8636. final L2PcInstance currPlayer = (L2PcInstance) this;
  8637. final SkillDat skilldat = currPlayer.getCurrentSkill();
  8638. if (skilldat != null && !skilldat.isCtrlPressed() && (skill.isOffensive()) && !(skill.getSkillType() == SkillType.UNLOCK) && !(skill.getSkillType() == SkillType.BLOW) && !(skill.getSkillType() == SkillType.DELUXE_KEY_UNLOCK) && skill.getId() != 345 && skill.getId() != 346)
  8639. {
  8640. if (!skill.isMagic() && skill.nextActionIsAttack())
  8641. getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, getTarget());
  8642.  
  8643. getAI().clientStartAutoAttack();
  8644. }
  8645. }
  8646. else
  8647. // case npc
  8648. {
  8649. if ((skill.isOffensive()) && !(skill.getSkillType() == SkillType.UNLOCK) && !(skill.getSkillType() == SkillType.BLOW) && !(skill.getSkillType() == SkillType.DELUXE_KEY_UNLOCK) && skill.getId() != 345 && skill.getId() != 346)
  8650. {
  8651. if (!skill.isMagic())
  8652. getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, getTarget());
  8653.  
  8654. getAI().clientStartAutoAttack();
  8655. }
  8656. }
  8657. }
  8658. else
  8659. {
  8660. getAI().clientStopAutoAttack();
  8661. }
  8662.  
  8663. // Notify the AI of the L2Character with EVT_FINISH_CASTING
  8664. getAI().notifyEvent(CtrlEvent.EVT_FINISH_CASTING);
  8665.  
  8666. notifyQuestEventSkillFinished(skill, getTarget());
  8667.  
  8668. /*
  8669. * If character is a player, then wipe their current cast state and check if a skill is queued. If there is a queued skill, launch it and wipe the queue.
  8670. */
  8671. if (this instanceof L2PcInstance)
  8672. {
  8673. L2PcInstance currPlayer = (L2PcInstance) this;
  8674. SkillDat queuedSkill = currPlayer.getQueuedSkill();
  8675.  
  8676. currPlayer.setCurrentSkill(null, false, false);
  8677.  
  8678. if (queuedSkill != null)
  8679. {
  8680. currPlayer.setQueuedSkill(null, false, false);
  8681.  
  8682. // DON'T USE : Recursive call to useMagic() method
  8683. // currPlayer.useMagic(queuedSkill.getSkill(), queuedSkill.isCtrlPressed(), queuedSkill.isShiftPressed());
  8684. ThreadPoolManager.getInstance().executeTask(new QueuedMagicUseTask(currPlayer, queuedSkill.getSkill(), queuedSkill.isCtrlPressed(), queuedSkill.isShiftPressed()));
  8685. }
  8686.  
  8687. queuedSkill = null;
  8688.  
  8689. final L2Weapon activeWeapon = getActiveWeaponItem();
  8690. // Launch weapon Special ability skill effect if available
  8691. if (activeWeapon != null)
  8692. {
  8693. try
  8694. {
  8695. if (targets != null && targets.length > 0)
  8696. {
  8697. for (final L2Object target : targets)
  8698. {
  8699. if (target != null && target instanceof L2Character && !((L2Character) target).isDead())
  8700. {
  8701. final L2Character player = (L2Character) target;
  8702.  
  8703. if (activeWeapon.getSkillEffects(this, player, skill))
  8704. {
  8705. sendPacket(SystemMessage.sendString("Target affected by weapon special ability!"));
  8706. }
  8707. }
  8708.  
  8709. }
  8710. }
  8711. }
  8712. catch (final Exception e)
  8713. {
  8714. e.printStackTrace();
  8715. }
  8716. }
  8717.  
  8718. currPlayer = null;
  8719. }
  8720. }
  8721. }
  8722.  
  8723. // Quest event ON_SPELL_FNISHED
  8724. /**
  8725. * Notify quest event skill finished.
  8726. * @param skill the skill
  8727. * @param target the target
  8728. */
  8729. private void notifyQuestEventSkillFinished(final L2Skill skill, final L2Object target)
  8730. {
  8731. if (this instanceof L2NpcInstance && (target instanceof L2PcInstance || target instanceof L2Summon))
  8732. {
  8733.  
  8734. final L2PcInstance player = target instanceof L2PcInstance ? (L2PcInstance) target : ((L2Summon) target).getOwner();
  8735.  
  8736. for (final Quest quest : ((L2NpcTemplate) getTemplate()).getEventQuests(Quest.QuestEventType.ON_SPELL_FINISHED))
  8737. {
  8738. quest.notifySpellFinished(((L2NpcInstance) this), player, skill);
  8739. }
  8740. }
  8741. }
  8742.  
  8743. /**
  8744. * Reduce the item number of the L2Character.<BR>
  8745. * <BR>
  8746. * <B><U> Overriden in </U> :</B><BR>
  8747. * <BR>
  8748. * <li>L2PcInstance</li><BR>
  8749. * <BR>
  8750. * @param itemConsumeId the item consume id
  8751. * @param itemCount the item count
  8752. */
  8753. public void consumeItem(final int itemConsumeId, final int itemCount)
  8754. {
  8755. }
  8756.  
  8757. /**
  8758. * Enable a skill (remove it from _disabledSkills of the L2Character).<BR>
  8759. * <BR>
  8760. * <B><U> Concept</U> :</B><BR>
  8761. * <BR>
  8762. * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the L2Character <BR>
  8763. * <BR>
  8764. * @param _skill
  8765. */
  8766. public void enableSkill(final L2Skill _skill)
  8767. {
  8768. if (_disabledSkills == null)
  8769. return;
  8770.  
  8771. _disabledSkills.remove(new Integer(_skill.getReuseHashCode()));
  8772.  
  8773. if (this instanceof L2PcInstance)
  8774. {
  8775. removeTimeStamp(_skill);
  8776. }
  8777. }
  8778.  
  8779. /**
  8780. * Disable a skill (add it to _disabledSkills of the L2Character).<BR>
  8781. * <BR>
  8782. * <B><U> Concept</U> :</B><BR>
  8783. * <BR>
  8784. * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the L2Character <BR>
  8785. * <BR>
  8786. * @param skill The identifier of the L2Skill to disable
  8787. */
  8788. public void disableSkill(final L2Skill skill)
  8789. {
  8790. if (_disabledSkills == null)
  8791. {
  8792. _disabledSkills = Collections.synchronizedList(new FastList<Integer>());
  8793. }
  8794.  
  8795. _disabledSkills.add(skill.getReuseHashCode());
  8796. }
  8797.  
  8798. /**
  8799. * Disable this skill id for the duration of the delay in milliseconds.
  8800. * @param skill the skill thats going to be disabled
  8801. * @param delay (seconds * 1000)
  8802. */
  8803. public void disableSkill(final L2Skill skill, final long delay)
  8804. {
  8805. if (skill == null)
  8806. return;
  8807.  
  8808. disableSkill(skill);
  8809.  
  8810. if (delay > 10)
  8811. {
  8812. ThreadPoolManager.getInstance().scheduleAi(new EnableSkill(skill), delay);
  8813. }
  8814. }
  8815.  
  8816. /**
  8817. * Check if a skill is disabled.<BR>
  8818. * <BR>
  8819. * <B><U> Concept</U> :</B><BR>
  8820. * <BR>
  8821. * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the L2Character <BR>
  8822. * <BR>
  8823. * @param _skill the skill to know if its disabled
  8824. * @return true, if is skill disabled
  8825. */
  8826. public boolean isSkillDisabled(final L2Skill _skill)
  8827. {
  8828. final L2Skill skill = _skill;
  8829.  
  8830. if (isAllSkillsDisabled() && !skill.isPotion())
  8831. return true;
  8832.  
  8833. if (this instanceof L2PcInstance)
  8834. {
  8835. final L2PcInstance activeChar = (L2PcInstance) this;
  8836.  
  8837. if ((skill.getSkillType() == SkillType.FISHING || skill.getSkillType() == SkillType.REELING || skill.getSkillType() == SkillType.PUMPING) && !activeChar.isFishing() && (activeChar.getActiveWeaponItem() != null && activeChar.getActiveWeaponItem().getItemType() != L2WeaponType.ROD))
  8838. {
  8839. if (skill.getSkillType() == SkillType.PUMPING)
  8840. {
  8841. // Pumping skill is available only while fishing
  8842. activeChar.sendPacket(new SystemMessage(SystemMessageId.CAN_USE_PUMPING_ONLY_WHILE_FISHING));
  8843. }
  8844. else if (skill.getSkillType() == SkillType.REELING)
  8845. {
  8846. // Reeling skill is available only while fishing
  8847. activeChar.sendPacket(new SystemMessage(SystemMessageId.CAN_USE_REELING_ONLY_WHILE_FISHING));
  8848. }
  8849. else if (skill.getSkillType() == SkillType.FISHING)
  8850. {
  8851. // Player hasn't fishing pole equiped
  8852. activeChar.sendPacket(new SystemMessage(SystemMessageId.FISHING_POLE_NOT_EQUIPPED));
  8853. }
  8854.  
  8855. final SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  8856. sm.addString(skill.getName());
  8857. activeChar.sendPacket(sm);
  8858. return true;
  8859. }
  8860.  
  8861. if ((skill.getSkillType() == SkillType.FISHING || skill.getSkillType() == SkillType.REELING || skill.getSkillType() == SkillType.PUMPING) && activeChar.getActiveWeaponItem() == null)
  8862. {
  8863. final SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  8864. sm.addString(skill.getName());
  8865. activeChar.sendPacket(sm);
  8866. return true;
  8867. }
  8868.  
  8869. if ((skill.getSkillType() == SkillType.REELING || skill.getSkillType() == SkillType.PUMPING) && !activeChar.isFishing() && (activeChar.getActiveWeaponItem() != null && activeChar.getActiveWeaponItem().getItemType() == L2WeaponType.ROD))
  8870. {
  8871. if (skill.getSkillType() == SkillType.PUMPING)
  8872. {
  8873. // Pumping skill is available only while fishing
  8874. activeChar.sendPacket(new SystemMessage(SystemMessageId.CAN_USE_PUMPING_ONLY_WHILE_FISHING));
  8875. }
  8876. else if (skill.getSkillType() == SkillType.REELING)
  8877. {
  8878. // Reeling skill is available only while fishing
  8879. activeChar.sendPacket(new SystemMessage(SystemMessageId.CAN_USE_REELING_ONLY_WHILE_FISHING));
  8880. }
  8881.  
  8882. final SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  8883. sm.addString(skill.getName());
  8884. activeChar.sendPacket(sm);
  8885. return true;
  8886. }
  8887.  
  8888. if (activeChar.isHero() && HeroSkillTable.isHeroSkill(_skill.getId()) && activeChar.isInOlympiadMode() && activeChar.isOlympiadStart())
  8889. {
  8890. activeChar.sendMessage("You can't use Hero skills during Olympiad match.");
  8891. return true;
  8892. }
  8893. }
  8894.  
  8895. if (_disabledSkills == null)
  8896. return false;
  8897.  
  8898. return _disabledSkills.contains(_skill.getReuseHashCode());
  8899. }
  8900.  
  8901. /**
  8902. * Disable all skills (set _allSkillsDisabled to True).<BR>
  8903. * <BR>
  8904. */
  8905. public void disableAllSkills()
  8906. {
  8907. if (Config.DEBUG)
  8908. {
  8909. LOGGER.debug("All skills disabled");
  8910. }
  8911.  
  8912. _allSkillsDisabled = true;
  8913. }
  8914.  
  8915. /**
  8916. * Enable all skills (set _allSkillsDisabled to False).<BR>
  8917. * <BR>
  8918. */
  8919. public void enableAllSkills()
  8920. {
  8921. if (Config.DEBUG)
  8922. {
  8923. LOGGER.debug("All skills enabled");
  8924. }
  8925.  
  8926. _allSkillsDisabled = false;
  8927. }
  8928.  
  8929. /**
  8930. * Launch the magic skill and calculate its effects on each target contained in the targets table.<BR>
  8931. * <BR>
  8932. * @param skill The L2Skill to use
  8933. * @param targets The table of L2Object targets
  8934. */
  8935. public void callSkill(final L2Skill skill, final L2Object[] targets)
  8936. {
  8937. try
  8938. {
  8939. if (skill.isToggle() && getFirstEffect(skill.getId()) != null)
  8940. return;
  8941.  
  8942. if (targets == null || targets.length == 0)
  8943. {
  8944. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  8945. return;
  8946. }
  8947.  
  8948. // Do initial checkings for skills and set pvp flag/draw aggro when needed
  8949. for (final L2Object target : targets)
  8950. {
  8951. if (target instanceof L2Character)
  8952. {
  8953. // Set some values inside target's instance for later use
  8954. L2Character player = (L2Character) target;
  8955.  
  8956. if (skill.getEffectType() == L2Skill.SkillType.BUFF)
  8957. if (player.isBlockBuff())
  8958. continue;
  8959.  
  8960. /*
  8961. * LOGGER.info("--"+skill.getId()); L2Weapon activeWeapon = getActiveWeaponItem(); // Launch weapon Special ability skill effect if available if(activeWeapon != null && !((L2Character) target).isDead()) { if(activeWeapon.getSkillEffects(this, player, skill).length > 0 && this
  8962. * instanceof L2PcInstance) { sendPacket(SystemMessage.sendString("Target affected by weapon special ability!")); } }
  8963. */
  8964.  
  8965. if (target instanceof L2Character)
  8966. {
  8967. final L2Character targ = (L2Character) target;
  8968.  
  8969. if (ChanceSkillList.canTriggerByCast(this, targ, skill))
  8970. {
  8971. // Maybe launch chance skills on us
  8972. if (_chanceSkills != null)
  8973. {
  8974. _chanceSkills.onSkillHit(targ, false, skill.isMagic(), skill.isOffensive());
  8975. }
  8976. // Maybe launch chance skills on target
  8977. if (targ.getChanceSkills() != null)
  8978. {
  8979. targ.getChanceSkills().onSkillHit(this, true, skill.isMagic(), skill.isOffensive());
  8980. }
  8981. }
  8982. }
  8983.  
  8984. if (Config.ALLOW_RAID_BOSS_PETRIFIED && (this instanceof L2PcInstance || this instanceof L2Summon)) // Check if option is True Or False.
  8985. {
  8986. boolean to_be_cursed = false;
  8987.  
  8988. // check on BossZone raid lvl
  8989. if (!(player.getTarget() instanceof L2PlayableInstance) && !(player.getTarget() instanceof L2SummonInstance))
  8990. { // this must work just on mobs/raids
  8991.  
  8992. if ((player.isRaid() && getLevel() > player.getLevel() + 8) || (!(player instanceof L2PcInstance) && (player.getTarget() != null && player.getTarget() instanceof L2RaidBossInstance && getLevel() > ((L2RaidBossInstance) player.getTarget()).getLevel() + 8)) || (!(player instanceof L2PcInstance) && (player.getTarget() != null && player.getTarget() instanceof L2GrandBossInstance && getLevel() > ((L2GrandBossInstance) player.getTarget()).getLevel() + 8)))
  8993. {
  8994. to_be_cursed = true;
  8995. }
  8996.  
  8997. // advanced check too if not already cursed
  8998. if (!to_be_cursed)
  8999. {
  9000. int boss_id = -1;
  9001. L2NpcTemplate boss_template = null;
  9002. final L2BossZone boss_zone = GrandBossManager.getInstance().getZone(this);
  9003.  
  9004. if (boss_zone != null)
  9005. {
  9006. boss_id = boss_zone.getBossId();
  9007. }
  9008.  
  9009. // boolean alive = false;
  9010.  
  9011. if (boss_id != -1)
  9012. {
  9013. boss_template = NpcTable.getInstance().getTemplate(boss_id);
  9014.  
  9015. if (boss_template != null && getLevel() > boss_template.getLevel() + 8)
  9016. {
  9017. L2MonsterInstance boss_instance = null;
  9018.  
  9019. if (boss_template.type.equals("L2RaidBoss"))
  9020. {
  9021. final StatsSet actual_boss_stat = RaidBossSpawnManager.getInstance().getStatsSet(boss_id);
  9022. if (actual_boss_stat != null)
  9023. {
  9024. // alive = actual_boss_stat.getLong("respawnTime") == 0;
  9025. boss_instance = RaidBossSpawnManager.getInstance().getBoss(boss_id);
  9026. }
  9027. }
  9028. else if (boss_template.type.equals("L2GrandBoss"))
  9029. {
  9030. final StatsSet actual_boss_stat = GrandBossManager.getInstance().getStatsSet(boss_id);
  9031. if (actual_boss_stat != null)
  9032. {
  9033. // alive = actual_boss_stat.getLong("respawn_time") == 0;
  9034. boss_instance = GrandBossManager.getInstance().getBoss(boss_id);
  9035. }
  9036. }
  9037.  
  9038. // max allowed rage into take cursed is 3000
  9039. if (boss_instance != null/* && alive */&& boss_instance.isInsideRadius(this, 3000, false, false))
  9040. {
  9041. to_be_cursed = true;
  9042. }
  9043. }
  9044. }
  9045. }
  9046. }
  9047.  
  9048. if (to_be_cursed)
  9049. {
  9050. if (skill.isMagic())
  9051. {
  9052. L2Skill tempSkill = SkillTable.getInstance().getInfo(4215, 1);
  9053. if (tempSkill != null)
  9054. {
  9055. abortAttack();
  9056. abortCast();
  9057. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  9058. tempSkill.getEffects(player, this, false, false, false);
  9059.  
  9060. if (this instanceof L2Summon)
  9061. {
  9062.  
  9063. final L2Summon src = ((L2Summon) this);
  9064. if (src.getOwner() != null)
  9065. {
  9066. src.getOwner().abortAttack();
  9067. src.getOwner().abortCast();
  9068. src.getOwner().getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  9069. tempSkill.getEffects(player, src.getOwner(), false, false, false);
  9070. }
  9071. }
  9072.  
  9073. }
  9074. else
  9075. LOGGER.warn("Skill 4215 at level 1 is missing in DP.");
  9076.  
  9077. tempSkill = null;
  9078. }
  9079. else
  9080. {
  9081. L2Skill tempSkill = SkillTable.getInstance().getInfo(4515, 1);
  9082. if (tempSkill != null)
  9083. {
  9084. tempSkill.getEffects(player, this, false, false, false);
  9085. }
  9086. else
  9087. {
  9088. LOGGER.warn("Skill 4515 at level 1 is missing in DP.");
  9089. }
  9090.  
  9091. tempSkill = null;
  9092.  
  9093. if (player instanceof L2MinionInstance)
  9094. {
  9095. ((L2MinionInstance) player).getLeader().stopHating(this);
  9096. List<L2MinionInstance> spawnedMinions = ((L2MonsterInstance) player).getSpawnedMinions();
  9097. if (spawnedMinions != null && spawnedMinions.size() > 0)
  9098. {
  9099. Iterator<L2MinionInstance> itr = spawnedMinions.iterator();
  9100. L2MinionInstance minion;
  9101. while (itr.hasNext())
  9102. {
  9103. minion = itr.next();
  9104. if (((L2Attackable) player).getMostHated() == null)
  9105. {
  9106. ((L2AttackableAI) minion.getAI()).setGlobalAggro(-25);
  9107. minion.clearAggroList();
  9108. minion.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  9109. minion.setWalking();
  9110. }
  9111. if (minion != null && !minion.isDead())
  9112. {
  9113. ((L2AttackableAI) minion.getAI()).setGlobalAggro(-25);
  9114. minion.clearAggroList();
  9115. minion.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  9116. minion.addDamage(((L2Attackable) player).getMostHated(), 100);
  9117. }
  9118. }
  9119. itr = null;
  9120. spawnedMinions = null;
  9121. minion = null;
  9122. }
  9123. }
  9124. else
  9125. {
  9126. ((L2Attackable) player).stopHating(this);
  9127. List<L2MinionInstance> spawnedMinions = ((L2MonsterInstance) player).getSpawnedMinions();
  9128. if (spawnedMinions != null && spawnedMinions.size() > 0)
  9129. {
  9130. Iterator<L2MinionInstance> itr = spawnedMinions.iterator();
  9131. L2MinionInstance minion;
  9132. while (itr.hasNext())
  9133. {
  9134. minion = itr.next();
  9135. if (((L2Attackable) player).getMostHated() == null)
  9136. {
  9137. ((L2AttackableAI) minion.getAI()).setGlobalAggro(-25);
  9138. minion.clearAggroList();
  9139. minion.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  9140. minion.setWalking();
  9141. }
  9142. if (minion != null && !minion.isDead())
  9143. {
  9144. ((L2AttackableAI) minion.getAI()).setGlobalAggro(-25);
  9145. minion.clearAggroList();
  9146. minion.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  9147. minion.addDamage(((L2Attackable) player).getMostHated(), 100);
  9148. }
  9149. }
  9150. itr = null;
  9151. spawnedMinions = null;
  9152. minion = null;
  9153. }
  9154. }
  9155. }
  9156. return;
  9157. }
  9158. }
  9159.  
  9160. L2PcInstance activeChar = null;
  9161.  
  9162. if (this instanceof L2PcInstance)
  9163. {
  9164. activeChar = (L2PcInstance) this;
  9165. }
  9166. else if (this instanceof L2Summon)
  9167. {
  9168. activeChar = ((L2Summon) this).getOwner();
  9169. }
  9170.  
  9171. if (activeChar != null)
  9172. {
  9173. if (skill.isOffensive())
  9174. {
  9175. if (player instanceof L2PcInstance || player instanceof L2Summon)
  9176. {
  9177. // Signets are a special case, casted on target_self but don't harm self
  9178. if (skill.getSkillType() != L2Skill.SkillType.SIGNET && skill.getSkillType() != L2Skill.SkillType.SIGNET_CASTTIME)
  9179. {
  9180. player.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  9181. activeChar.updatePvPStatus(player);
  9182. }
  9183. }
  9184. else if (player instanceof L2Attackable)
  9185. {
  9186. switch (skill.getSkillType())
  9187. {
  9188. case AGGREDUCE:
  9189. case AGGREDUCE_CHAR:
  9190. case AGGREMOVE:
  9191. break;
  9192. default:
  9193. ((L2Character) target).addAttackerToAttackByList(this);
  9194. /*
  9195. * ((L2Character) target).getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, this); - Deprecated Notify the AI that is being attacked. It should be notified once the skill is finished in order to avoid AI action previous to skill end. IE: Backstab on monsters, the AI
  9196. * rotates previous to skill end so it doesn't make affect. We calculate the hit time to know when the AI should rotate.
  9197. */
  9198. int hitTime = Formulas.getInstance().calcMAtkSpd(activeChar, skill, skill.getHitTime());
  9199. if ((checkBss() || checkSps()) && !skill.isStaticHitTime() && !skill.isPotion() && skill.isMagic())
  9200. hitTime = (int) (0.70 * hitTime);
  9201. ThreadPoolManager.getInstance().scheduleGeneral(new notifyAiTaskDelayed(CtrlEvent.EVT_ATTACKED, this, target), hitTime);
  9202. break;
  9203. }
  9204. }
  9205. }
  9206. else
  9207. {
  9208. if (player instanceof L2PcInstance)
  9209. {
  9210. // Casting non offensive skill on player with pvp flag set or with karma
  9211. if (!player.equals(this) && (((L2PcInstance) player).getPvpFlag() > 0 || ((L2PcInstance) player).getKarma() > 0))
  9212. {
  9213. activeChar.updatePvPStatus();
  9214. }
  9215. }
  9216. else if (player instanceof L2Attackable && !(skill.getSkillType() == L2Skill.SkillType.SUMMON) && !(skill.getSkillType() == L2Skill.SkillType.BEAST_FEED) && !(skill.getSkillType() == L2Skill.SkillType.UNLOCK) && !(skill.getSkillType() == L2Skill.SkillType.DELUXE_KEY_UNLOCK))
  9217. {
  9218. activeChar.updatePvPStatus(this);
  9219. }
  9220. }
  9221. player = null;
  9222. // activeWeapon = null;
  9223. }
  9224. activeChar = null;
  9225. }
  9226. if (target instanceof L2MonsterInstance)
  9227. {
  9228. if (!skill.isOffensive() && skill.getSkillType() != SkillType.UNLOCK && skill.getSkillType() != SkillType.SUMMON && skill.getSkillType() != SkillType.DELUXE_KEY_UNLOCK && skill.getSkillType() != SkillType.BEAST_FEED)
  9229. {
  9230. L2PcInstance activeChar = null;
  9231.  
  9232. if (this instanceof L2PcInstance)
  9233. {
  9234. activeChar = (L2PcInstance) this;
  9235. activeChar.updatePvPStatus(activeChar);
  9236. }
  9237. else if (this instanceof L2Summon)
  9238. {
  9239. activeChar = ((L2Summon) this).getOwner();
  9240. }
  9241. }
  9242. }
  9243. }
  9244.  
  9245. ISkillHandler handler = null;
  9246.  
  9247. if (skill.isToggle())
  9248. {
  9249. // Check if the skill effects are already in progress on the L2Character
  9250. if (getFirstEffect(skill.getId()) != null)
  9251. {
  9252. handler = SkillHandler.getInstance().getSkillHandler(skill.getSkillType());
  9253.  
  9254. if (handler != null)
  9255. {
  9256. handler.useSkill(this, skill, targets);
  9257. }
  9258. else
  9259. {
  9260. skill.useSkill(this, targets);
  9261. }
  9262.  
  9263. return;
  9264. }
  9265. }/*
  9266. * TODO else { if(this instanceof L2PcInstance || this instanceof L2Summon) { L2PcInstance caster = this instanceof L2PcInstance ? (L2PcInstance) this : ((L2Summon) this).getOwner(); for(L2Object target : targets) { if(target instanceof L2NpcInstance) { if (((L2NpcInstance)
  9267. * target).getTemplate().getEventQuests(Quest.QuestEventType.ON_SKILL_USE) != null) { for(Quest quest : ((L2NpcInstance) target).getTemplate().getEventQuests(Quest.QuestEventType.ON_SKILL_USE)) { quest.notifySkillUse((L2NpcInstance) target, caster, skill); } } } } caster = null; } }
  9268. */
  9269.  
  9270. // Check if over-hit is possible
  9271. if (skill.isOverhit())
  9272. {
  9273. // Set the "over-hit enabled" flag on each of the possible targets
  9274. for (final L2Object target : targets)
  9275. {
  9276. L2Character player = (L2Character) target;
  9277. if (player instanceof L2Attackable)
  9278. {
  9279. ((L2Attackable) player).overhitEnabled(true);
  9280. }
  9281.  
  9282. player = null;
  9283. }
  9284. }
  9285.  
  9286. // Get the skill handler corresponding to the skill type (PDAM, MDAM, SWEEP...) started in gameserver
  9287. handler = SkillHandler.getInstance().getSkillHandler(skill.getSkillType());
  9288.  
  9289. // Launch the magic skill and calculate its effects
  9290. if (handler != null)
  9291. {
  9292. handler.useSkill(this, skill, targets);
  9293. }
  9294. else
  9295. {
  9296. skill.useSkill(this, targets);
  9297. }
  9298.  
  9299. // if the skill is a potion, must delete the potion item
  9300. if (skill.isPotion() && this instanceof L2PlayableInstance)
  9301. {
  9302. Potions.delete_Potion_Item((L2PlayableInstance) this, skill.getId(), skill.getLevel());
  9303. }
  9304.  
  9305. if (this instanceof L2PcInstance || this instanceof L2Summon)
  9306. {
  9307. L2PcInstance caster = this instanceof L2PcInstance ? (L2PcInstance) this : ((L2Summon) this).getOwner();
  9308. for (final L2Object target : targets)
  9309. {
  9310. if (target instanceof L2NpcInstance)
  9311. {
  9312. L2NpcInstance npc = (L2NpcInstance) target;
  9313.  
  9314. for (final Quest quest : npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_SKILL_USE))
  9315. {
  9316. quest.notifySkillUse(npc, caster, skill);
  9317. }
  9318.  
  9319. npc = null;
  9320. }
  9321. }
  9322.  
  9323. if (skill.getAggroPoints() > 0)
  9324. {
  9325. for (final L2Object spMob : caster.getKnownList().getKnownObjects().values())
  9326. if (spMob instanceof L2NpcInstance)
  9327. {
  9328. L2NpcInstance npcMob = (L2NpcInstance) spMob;
  9329.  
  9330. if (npcMob.isInsideRadius(caster, 1000, true, true) && npcMob.hasAI() && npcMob.getAI().getIntention() == AI_INTENTION_ATTACK)
  9331. {
  9332. L2Object npcTarget = npcMob.getTarget();
  9333.  
  9334. for (final L2Object target : targets)
  9335. if (npcTarget == target || npcMob == target)
  9336. {
  9337. npcMob.seeSpell(caster, target, skill);
  9338. }
  9339.  
  9340. npcTarget = null;
  9341. }
  9342.  
  9343. npcMob = null;
  9344. }
  9345. }
  9346.  
  9347. caster = null;
  9348. }
  9349.  
  9350. handler = null;
  9351. }
  9352. catch (final Exception e)
  9353. {
  9354. LOGGER.warn("", e);
  9355. }
  9356.  
  9357. if (this instanceof L2PcInstance && ((L2PcInstance) this).isMovingTaskDefined() && !skill.isPotion())
  9358. ((L2PcInstance) this).startMovingTask();
  9359. }
  9360.  
  9361. /**
  9362. * See spell.
  9363. * @param caster the caster
  9364. * @param target the target
  9365. * @param skill the skill
  9366. */
  9367. public void seeSpell(final L2PcInstance caster, final L2Object target, final L2Skill skill)
  9368. {
  9369. if (this instanceof L2Attackable)
  9370. {
  9371. ((L2Attackable) this).addDamageHate(caster, 0, -skill.getAggroPoints());
  9372. }
  9373. }
  9374.  
  9375. /**
  9376. * Return True if the L2Character is behind the target and can't be seen.<BR>
  9377. * <BR>
  9378. * @param target the target
  9379. * @return true, if is behind
  9380. */
  9381. public boolean isBehind(final L2Object target)
  9382. {
  9383. double angleChar, angleTarget, angleDiff; //
  9384. final double maxAngleDiff = 40;
  9385.  
  9386. if (target == null)
  9387. return false;
  9388.  
  9389. if (target instanceof L2Character)
  9390. {
  9391. ((L2Character) target).sendPacket(new ValidateLocation(this));
  9392. this.sendPacket(new ValidateLocation(((L2Character) target)));
  9393.  
  9394. L2Character target1 = (L2Character) target;
  9395. angleChar = Util.calculateAngleFrom(target1, this);
  9396. angleTarget = Util.convertHeadingToDegree(target1.getHeading());
  9397. angleDiff = angleChar - angleTarget;
  9398.  
  9399. if (angleDiff <= -360 + maxAngleDiff)
  9400. {
  9401. angleDiff += 360;
  9402. }
  9403.  
  9404. if (angleDiff >= 360 - maxAngleDiff)
  9405. {
  9406. angleDiff -= 360;
  9407. }
  9408.  
  9409. if (Math.abs(angleDiff) <= maxAngleDiff)
  9410. {
  9411. if (Config.DEBUG)
  9412. {
  9413. LOGGER.info("Char " + getName() + " is behind " + target.getName());
  9414. }
  9415.  
  9416. return true;
  9417. }
  9418.  
  9419. target1 = null;
  9420. }
  9421.  
  9422. return false;
  9423. }
  9424.  
  9425. /**
  9426. * Checks if is behind target.
  9427. * @return true, if is behind target
  9428. */
  9429. public boolean isBehindTarget()
  9430. {
  9431. return isBehind(getTarget());
  9432. }
  9433.  
  9434. /**
  9435. * Returns true if target is in front of L2Character (shield def etc).
  9436. * @param target the target
  9437. * @param maxAngle the max angle
  9438. * @return true, if is facing
  9439. */
  9440. public boolean isFacing(final L2Object target, final int maxAngle)
  9441. {
  9442. double angleChar, angleTarget, angleDiff, maxAngleDiff;
  9443. if (target == null)
  9444. return false;
  9445. maxAngleDiff = maxAngle / 2;
  9446. angleTarget = Util.calculateAngleFrom(this, target);
  9447. angleChar = Util.convertHeadingToDegree(this.getHeading());
  9448. angleDiff = angleChar - angleTarget;
  9449. if (angleDiff <= -360 + maxAngleDiff)
  9450. angleDiff += 360;
  9451. if (angleDiff >= 360 - maxAngleDiff)
  9452. angleDiff -= 360;
  9453. if (Math.abs(angleDiff) <= maxAngleDiff)
  9454. return true;
  9455. return false;
  9456. }
  9457.  
  9458. /**
  9459. * Return True if the L2Character is behind the target and can't be seen.<BR>
  9460. * <BR>
  9461. * @param target the target
  9462. * @return true, if is front
  9463. */
  9464. public boolean isFront(final L2Object target)
  9465. {
  9466. double angleChar, angleTarget, angleDiff;
  9467. final double maxAngleDiff = 40;
  9468.  
  9469. if (target == null)
  9470. return false;
  9471.  
  9472. if (target instanceof L2Character)
  9473. {
  9474. ((L2Character) target).sendPacket(new ValidateLocation(this));
  9475. this.sendPacket(new ValidateLocation(((L2Character) target)));
  9476.  
  9477. L2Character target1 = (L2Character) target;
  9478. angleChar = Util.calculateAngleFrom(target1, this);
  9479. angleTarget = Util.convertHeadingToDegree(target1.getHeading());
  9480. angleDiff = angleChar - angleTarget;
  9481.  
  9482. if (angleDiff <= -180 + maxAngleDiff)
  9483. {
  9484. angleDiff += 180;
  9485. }
  9486.  
  9487. if (angleDiff >= 180 - maxAngleDiff)
  9488. {
  9489. angleDiff -= 180;
  9490. }
  9491.  
  9492. if (Math.abs(angleDiff) <= maxAngleDiff)
  9493. {
  9494. if (isBehindTarget())
  9495. return false;
  9496.  
  9497. if (Config.DEBUG)
  9498. {
  9499. LOGGER.info("Char " + getName() + " is side " + target.getName());
  9500. }
  9501.  
  9502. return true;
  9503. }
  9504.  
  9505. target1 = null;
  9506. }
  9507.  
  9508. return false;
  9509. }
  9510.  
  9511. /**
  9512. * Checks if is front target.
  9513. * @return true, if is front target
  9514. */
  9515. public boolean isFrontTarget()
  9516. {
  9517. return isFront(getTarget());
  9518. }
  9519.  
  9520. /**
  9521. * Return True if the L2Character is side the target and can't be seen.<BR>
  9522. * <BR>
  9523. * @param target the target
  9524. * @return true, if is side
  9525. */
  9526. public boolean isSide(final L2Object target)
  9527. {
  9528. if (target == null)
  9529. return false;
  9530.  
  9531. if (target instanceof L2Character)
  9532. {
  9533. if (isBehindTarget() || isFrontTarget())
  9534. return false;
  9535. }
  9536.  
  9537. return true;
  9538. }
  9539.  
  9540. /**
  9541. * Checks if is side target.
  9542. * @return true, if is side target
  9543. */
  9544. public boolean isSideTarget()
  9545. {
  9546. return isSide(getTarget());
  9547. }
  9548.  
  9549. /**
  9550. * Return 1.<BR>
  9551. * <BR>
  9552. * @return the level mod
  9553. */
  9554. public double getLevelMod()
  9555. {
  9556. return 1;
  9557. }
  9558.  
  9559. /**
  9560. * Sets the skill cast.
  9561. * @param newSkillCast the new skill cast
  9562. */
  9563. public final void setSkillCast(final Future<?> newSkillCast)
  9564. {
  9565. _skillCast = newSkillCast;
  9566. }
  9567.  
  9568. /**
  9569. * Sets the skill cast end time.
  9570. * @param newSkillCastEndTime the new skill cast end time
  9571. */
  9572. public final void setSkillCastEndTime(final int newSkillCastEndTime)
  9573. {
  9574. _castEndTime = newSkillCastEndTime;
  9575. // for interrupt -12 ticks; first removing the extra second and then -200 ms
  9576. _castInterruptTime = newSkillCastEndTime - 12;
  9577. }
  9578.  
  9579. /** The _ pvp reg task. */
  9580. private Future<?> _PvPRegTask;
  9581.  
  9582. /** The _pvp flag lasts. */
  9583. private long _pvpFlagLasts;
  9584.  
  9585. /**
  9586. * Sets the pvp flag lasts.
  9587. * @param time the new pvp flag lasts
  9588. */
  9589. public void setPvpFlagLasts(final long time)
  9590. {
  9591. _pvpFlagLasts = time;
  9592. }
  9593.  
  9594. /**
  9595. * Gets the pvp flag lasts.
  9596. * @return the pvp flag lasts
  9597. */
  9598. public long getPvpFlagLasts()
  9599. {
  9600. return _pvpFlagLasts;
  9601. }
  9602.  
  9603. /**
  9604. * Start pvp flag.
  9605. */
  9606. public void startPvPFlag()
  9607. {
  9608. updatePvPFlag(1);
  9609. boolean startTask = true;
  9610. startTask = (isInsideZone(L2Character.ZONE_SPECIAL) && SpecialZoneManager.getInstance().getZone(this) != null && !SpecialZoneManager.getInstance().getZone(this).givePvPFlagOnEnter()) || !isInsideZone(L2Character.ZONE_SPECIAL);
  9611.  
  9612. if (startTask)
  9613. _PvPRegTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new PvPFlag(), 1000, 1000);
  9614. else if (_PvPRegTask != null)
  9615. _PvPRegTask.cancel(true);
  9616. }
  9617.  
  9618. /**
  9619. * Stop pvp reg task.
  9620. */
  9621. public void stopPvpRegTask()
  9622. {
  9623. if (_PvPRegTask != null)
  9624. {
  9625. _PvPRegTask.cancel(true);
  9626. }
  9627. }
  9628.  
  9629. /**
  9630. * Stop pvp flag.
  9631. */
  9632. public void stopPvPFlag()
  9633. {
  9634. stopPvpRegTask();
  9635.  
  9636. updatePvPFlag(0);
  9637.  
  9638. _PvPRegTask = null;
  9639. }
  9640.  
  9641. /**
  9642. * Update pvp flag.
  9643. * @param value the value
  9644. */
  9645. public void updatePvPFlag(final int value)
  9646. {
  9647. // Overridden in L2PcInstance
  9648. //
  9649. // if (!(this instanceof L2PcInstance))
  9650. // return;
  9651. // L2PcInstance player = (L2PcInstance)this;
  9652. // if (player.getPvpFlag() == value)
  9653. // return;
  9654. // player.setPvpFlag(value);
  9655. //
  9656. // player.sendPacket(new UserInfo(player));
  9657. // for (L2PcInstance target : getKnownList().getKnownPlayers().values())
  9658. // {
  9659. // target.sendPacket(new RelationChanged(player, player.getRelation(player), player.isAutoAttackable(target)));
  9660. // }
  9661. }
  9662.  
  9663. // public void checkPvPFlag()
  9664. // {
  9665. // if (Config.DEBUG) LOGGER.fine("Checking PvpFlag");
  9666. // _PvPRegTask = ThreadPoolManager.getInstance().scheduleLowAtFixedRate(new PvPFlag(), 1000, 5000);
  9667. // _PvPRegActive = true;
  9668. // // LOGGER.fine("PvP recheck");
  9669. // }
  9670. //
  9671.  
  9672. /**
  9673. * Return a Random Damage in function of the weapon.<BR>
  9674. * <BR>
  9675. * @param target the target
  9676. * @return the random damage
  9677. */
  9678. public final int getRandomDamage(final L2Character target)
  9679. {
  9680. final L2Weapon weaponItem = getActiveWeaponItem();
  9681.  
  9682. if (weaponItem == null)
  9683. return 5 + (int) Math.sqrt(getLevel());
  9684.  
  9685. return weaponItem.getRandomDamage();
  9686. }
  9687.  
  9688. /*
  9689. * (non-Javadoc)
  9690. * @see com.l2jfrozen.gameserver.model.L2Object#toString()
  9691. */
  9692. @Override
  9693. public String toString()
  9694. {
  9695. return "mob " + getObjectId();
  9696. }
  9697.  
  9698. /**
  9699. * Gets the attack end time.
  9700. * @return the attack end time
  9701. */
  9702. public int getAttackEndTime()
  9703. {
  9704. return _attackEndTime;
  9705. }
  9706.  
  9707. /**
  9708. * Not Implemented.<BR>
  9709. * <BR>
  9710. * @return the level
  9711. */
  9712. public abstract int getLevel();
  9713.  
  9714. // =========================================================
  9715.  
  9716. // =========================================================
  9717. // Stat - NEED TO REMOVE ONCE L2CHARSTAT IS COMPLETE
  9718. // Property - Public
  9719. /**
  9720. * Calc stat.
  9721. * @param stat the stat
  9722. * @param init the init
  9723. * @param target the target
  9724. * @param skill the skill
  9725. * @return the double
  9726. */
  9727. public final double calcStat(final Stats stat, final double init, final L2Character target, final L2Skill skill)
  9728. {
  9729. return getStat().calcStat(stat, init, target, skill);
  9730. }
  9731.  
  9732. // Property - Public
  9733. /**
  9734. * Gets the accuracy.
  9735. * @return the accuracy
  9736. */
  9737. public int getAccuracy()
  9738. {
  9739. return getStat().getAccuracy();
  9740. }
  9741.  
  9742. /**
  9743. * Gets the attack speed multiplier.
  9744. * @return the attack speed multiplier
  9745. */
  9746. public final float getAttackSpeedMultiplier()
  9747. {
  9748. return getStat().getAttackSpeedMultiplier();
  9749. }
  9750.  
  9751. /**
  9752. * Gets the cON.
  9753. * @return the cON
  9754. */
  9755. public int getCON()
  9756. {
  9757. return getStat().getCON();
  9758. }
  9759.  
  9760. /**
  9761. * Gets the dEX.
  9762. * @return the dEX
  9763. */
  9764. public int getDEX()
  9765. {
  9766. return getStat().getDEX();
  9767. }
  9768.  
  9769. /**
  9770. * Gets the critical dmg.
  9771. * @param target the target
  9772. * @param init the init
  9773. * @return the critical dmg
  9774. */
  9775. public final double getCriticalDmg(final L2Character target, final double init)
  9776. {
  9777. return getStat().getCriticalDmg(target, init);
  9778. }
  9779.  
  9780. /**
  9781. * Gets the critical hit.
  9782. * @param target the target
  9783. * @param skill the skill
  9784. * @return the critical hit
  9785. */
  9786. public int getCriticalHit(final L2Character target, final L2Skill skill)
  9787. {
  9788. return getStat().getCriticalHit(target, skill);
  9789. }
  9790.  
  9791. /**
  9792. * Gets the evasion rate.
  9793. * @param target the target
  9794. * @return the evasion rate
  9795. */
  9796. public int getEvasionRate(final L2Character target)
  9797. {
  9798. return getStat().getEvasionRate(target);
  9799. }
  9800.  
  9801. /**
  9802. * Gets the iNT.
  9803. * @return the iNT
  9804. */
  9805. public int getINT()
  9806. {
  9807. return getStat().getINT();
  9808. }
  9809.  
  9810. /**
  9811. * Gets the magical attack range.
  9812. * @param skill the skill
  9813. * @return the magical attack range
  9814. */
  9815. public final int getMagicalAttackRange(final L2Skill skill)
  9816. {
  9817. return getStat().getMagicalAttackRange(skill);
  9818. }
  9819.  
  9820. /**
  9821. * Gets the max cp.
  9822. * @return the max cp
  9823. */
  9824. public final int getMaxCp()
  9825. {
  9826. return getStat().getMaxCp();
  9827. }
  9828.  
  9829. /**
  9830. * Gets the m atk.
  9831. * @param target the target
  9832. * @param skill the skill
  9833. * @return the m atk
  9834. */
  9835. public int getMAtk(final L2Character target, final L2Skill skill)
  9836. {
  9837. return getStat().getMAtk(target, skill);
  9838. }
  9839.  
  9840. /**
  9841. * Gets the m atk spd.
  9842. * @return the m atk spd
  9843. */
  9844. public int getMAtkSpd()
  9845. {
  9846. return getStat().getMAtkSpd();
  9847. }
  9848.  
  9849. /**
  9850. * Gets the max mp.
  9851. * @return the max mp
  9852. */
  9853. public int getMaxMp()
  9854. {
  9855. return getStat().getMaxMp();
  9856. }
  9857.  
  9858. /**
  9859. * Gets the max hp.
  9860. * @return the max hp
  9861. */
  9862. public int getMaxHp()
  9863. {
  9864. return getStat().getMaxHp();
  9865. }
  9866.  
  9867. /**
  9868. * Gets the m critical hit.
  9869. * @param target the target
  9870. * @param skill the skill
  9871. * @return the m critical hit
  9872. */
  9873. public final int getMCriticalHit(final L2Character target, final L2Skill skill)
  9874. {
  9875. return getStat().getMCriticalHit(target, skill);
  9876. }
  9877.  
  9878. /**
  9879. * Gets the m def.
  9880. * @param target the target
  9881. * @param skill the skill
  9882. * @return the m def
  9883. */
  9884. public int getMDef(final L2Character target, final L2Skill skill)
  9885. {
  9886. return getStat().getMDef(target, skill);
  9887. }
  9888.  
  9889. /**
  9890. * Gets the mEN.
  9891. * @return the mEN
  9892. */
  9893. public int getMEN()
  9894. {
  9895. return getStat().getMEN();
  9896. }
  9897.  
  9898. /**
  9899. * Gets the m reuse rate.
  9900. * @param skill the skill
  9901. * @return the m reuse rate
  9902. */
  9903. public double getMReuseRate(final L2Skill skill)
  9904. {
  9905. return getStat().getMReuseRate(skill);
  9906. }
  9907.  
  9908. /**
  9909. * Gets the movement speed multiplier.
  9910. * @return the movement speed multiplier
  9911. */
  9912. public float getMovementSpeedMultiplier()
  9913. {
  9914. return getStat().getMovementSpeedMultiplier();
  9915. }
  9916.  
  9917. /**
  9918. * Gets the p atk.
  9919. * @param target the target
  9920. * @return the p atk
  9921. */
  9922. public int getPAtk(final L2Character target)
  9923. {
  9924. return getStat().getPAtk(target);
  9925. }
  9926.  
  9927. /**
  9928. * Gets the p atk animals.
  9929. * @param target the target
  9930. * @return the p atk animals
  9931. */
  9932. public double getPAtkAnimals(final L2Character target)
  9933. {
  9934. return getStat().getPAtkAnimals(target);
  9935. }
  9936.  
  9937. /**
  9938. * Gets the p atk dragons.
  9939. * @param target the target
  9940. * @return the p atk dragons
  9941. */
  9942. public double getPAtkDragons(final L2Character target)
  9943. {
  9944. return getStat().getPAtkDragons(target);
  9945. }
  9946.  
  9947. /**
  9948. * Gets the p atk angels.
  9949. * @param target the target
  9950. * @return the p atk angels
  9951. */
  9952. public double getPAtkAngels(final L2Character target)
  9953. {
  9954. return getStat().getPAtkAngels(target);
  9955. }
  9956.  
  9957. /**
  9958. * Gets the p atk insects.
  9959. * @param target the target
  9960. * @return the p atk insects
  9961. */
  9962. public double getPAtkInsects(final L2Character target)
  9963. {
  9964. return getStat().getPAtkInsects(target);
  9965. }
  9966.  
  9967. /**
  9968. * Gets the p atk monsters.
  9969. * @param target the target
  9970. * @return the p atk monsters
  9971. */
  9972. public double getPAtkMonsters(final L2Character target)
  9973. {
  9974. return getStat().getPAtkMonsters(target);
  9975. }
  9976.  
  9977. /**
  9978. * Gets the p atk plants.
  9979. * @param target the target
  9980. * @return the p atk plants
  9981. */
  9982. public double getPAtkPlants(final L2Character target)
  9983. {
  9984. return getStat().getPAtkPlants(target);
  9985. }
  9986.  
  9987. /**
  9988. * Gets the p atk spd.
  9989. * @return the p atk spd
  9990. */
  9991. public int getPAtkSpd()
  9992. {
  9993. return getStat().getPAtkSpd();
  9994. }
  9995.  
  9996. /**
  9997. * Gets the p atk undead.
  9998. * @param target the target
  9999. * @return the p atk undead
  10000. */
  10001. public double getPAtkUndead(final L2Character target)
  10002. {
  10003. return getStat().getPAtkUndead(target);
  10004. }
  10005.  
  10006. /**
  10007. * Gets the p def undead.
  10008. * @param target the target
  10009. * @return the p def undead
  10010. */
  10011. public double getPDefUndead(final L2Character target)
  10012. {
  10013. return getStat().getPDefUndead(target);
  10014. }
  10015.  
  10016. /**
  10017. * Gets the p def plants.
  10018. * @param target the target
  10019. * @return the p def plants
  10020. */
  10021. public double getPDefPlants(final L2Character target)
  10022. {
  10023. return getStat().getPDefPlants(target);
  10024. }
  10025.  
  10026. /**
  10027. * Gets the p def insects.
  10028. * @param target the target
  10029. * @return the p def insects
  10030. */
  10031. public double getPDefInsects(final L2Character target)
  10032. {
  10033. return getStat().getPDefInsects(target);
  10034. }
  10035.  
  10036. /**
  10037. * Gets the p def animals.
  10038. * @param target the target
  10039. * @return the p def animals
  10040. */
  10041. public double getPDefAnimals(final L2Character target)
  10042. {
  10043. return getStat().getPDefAnimals(target);
  10044. }
  10045.  
  10046. /**
  10047. * Gets the p def monsters.
  10048. * @param target the target
  10049. * @return the p def monsters
  10050. */
  10051. public double getPDefMonsters(final L2Character target)
  10052. {
  10053. return getStat().getPDefMonsters(target);
  10054. }
  10055.  
  10056. /**
  10057. * Gets the p def dragons.
  10058. * @param target the target
  10059. * @return the p def dragons
  10060. */
  10061. public double getPDefDragons(final L2Character target)
  10062. {
  10063. return getStat().getPDefDragons(target);
  10064. }
  10065.  
  10066. /**
  10067. * Gets the p def angels.
  10068. * @param target the target
  10069. * @return the p def angels
  10070. */
  10071. public double getPDefAngels(final L2Character target)
  10072. {
  10073. return getStat().getPDefAngels(target);
  10074. }
  10075.  
  10076. /**
  10077. * Gets the p def.
  10078. * @param target the target
  10079. * @return the p def
  10080. */
  10081. public int getPDef(final L2Character target)
  10082. {
  10083. return getStat().getPDef(target);
  10084. }
  10085.  
  10086. /**
  10087. * Gets the p atk giants.
  10088. * @param target the target
  10089. * @return the p atk giants
  10090. */
  10091. public double getPAtkGiants(final L2Character target)
  10092. {
  10093. return getStat().getPAtkGiants(target);
  10094. }
  10095.  
  10096. /**
  10097. * Gets the p atk magic creatures.
  10098. * @param target the target
  10099. * @return the p atk magic creatures
  10100. */
  10101. public double getPAtkMagicCreatures(final L2Character target)
  10102. {
  10103. return getStat().getPAtkMagicCreatures(target);
  10104. }
  10105.  
  10106. /**
  10107. * Gets the p def giants.
  10108. * @param target the target
  10109. * @return the p def giants
  10110. */
  10111. public double getPDefGiants(final L2Character target)
  10112. {
  10113. return getStat().getPDefGiants(target);
  10114. }
  10115.  
  10116. /**
  10117. * Gets the p def magic creatures.
  10118. * @param target the target
  10119. * @return the p def magic creatures
  10120. */
  10121. public double getPDefMagicCreatures(final L2Character target)
  10122. {
  10123. return getStat().getPDefMagicCreatures(target);
  10124. }
  10125.  
  10126. /**
  10127. * Gets the physical attack range.
  10128. * @return the physical attack range
  10129. */
  10130. public final int getPhysicalAttackRange()
  10131. {
  10132. return getStat().getPhysicalAttackRange();
  10133. }
  10134.  
  10135. /**
  10136. * Gets the run speed.
  10137. * @return the run speed
  10138. */
  10139. public int getRunSpeed()
  10140. {
  10141. return getStat().getRunSpeed();
  10142. }
  10143.  
  10144. /**
  10145. * Gets the shld def.
  10146. * @return the shld def
  10147. */
  10148. public final int getShldDef()
  10149. {
  10150. return getStat().getShldDef();
  10151. }
  10152.  
  10153. /**
  10154. * Gets the sTR.
  10155. * @return the sTR
  10156. */
  10157. public int getSTR()
  10158. {
  10159. return getStat().getSTR();
  10160. }
  10161.  
  10162. /**
  10163. * Gets the walk speed.
  10164. * @return the walk speed
  10165. */
  10166. public final int getWalkSpeed()
  10167. {
  10168. return getStat().getWalkSpeed();
  10169. }
  10170.  
  10171. /**
  10172. * Gets the wIT.
  10173. * @return the wIT
  10174. */
  10175. public int getWIT()
  10176. {
  10177. return getStat().getWIT();
  10178. }
  10179.  
  10180. // =========================================================
  10181.  
  10182. // =========================================================
  10183. // Status - NEED TO REMOVE ONCE L2CHARTATUS IS COMPLETE
  10184. // Method - Public
  10185. /**
  10186. * Adds the status listener.
  10187. * @param object the object
  10188. */
  10189. public void addStatusListener(final L2Character object)
  10190. {
  10191. getStatus().addStatusListener(object);
  10192. }
  10193.  
  10194. /**
  10195. * Reduce current hp.
  10196. * @param i the i
  10197. * @param attacker the attacker
  10198. */
  10199. public void reduceCurrentHp(final double i, final L2Character attacker)
  10200. {
  10201. reduceCurrentHp(i, attacker, true);
  10202. }
  10203.  
  10204. /**
  10205. * Reduce current hp.
  10206. * @param i the i
  10207. * @param attacker the attacker
  10208. * @param awake the awake
  10209. */
  10210. public void reduceCurrentHp(final double i, final L2Character attacker, final boolean awake)
  10211. {
  10212. if (this instanceof L2NpcInstance)
  10213. if (Config.INVUL_NPC_LIST.contains(Integer.valueOf(((L2NpcInstance) this).getNpcId())))
  10214. return;
  10215.  
  10216. if (Config.L2JMOD_CHAMPION_ENABLE && isChampion() && Config.L2JMOD_CHAMPION_HP != 0)
  10217. {
  10218. getStatus().reduceHp(i / Config.L2JMOD_CHAMPION_HP, attacker, awake);
  10219. }
  10220. else if (is_advanceFlag())
  10221. {
  10222. getStatus().reduceHp(i / _advanceMultiplier, attacker, awake);
  10223. }
  10224. else if (isUnkillable())
  10225. {
  10226. final double hpToReduce = this.getCurrentHp() - 1;
  10227. if (i > this.getCurrentHp())
  10228. getStatus().reduceHp(hpToReduce, attacker, awake);
  10229. else
  10230. getStatus().reduceHp(i, attacker, awake);
  10231. }
  10232. else
  10233. {
  10234. getStatus().reduceHp(i, attacker, awake);
  10235. }
  10236. }
  10237.  
  10238. private long _nextReducingHPByOverTime = -1;
  10239.  
  10240. public void reduceCurrentHpByDamOverTime(final double i, final L2Character attacker, final boolean awake, final int period)
  10241. {
  10242. if (_nextReducingHPByOverTime > System.currentTimeMillis())
  10243. {
  10244. return;
  10245. }
  10246.  
  10247. _nextReducingHPByOverTime = System.currentTimeMillis() + (period * 1000);
  10248. reduceCurrentHp(i, attacker, awake);
  10249.  
  10250. }
  10251.  
  10252. private long _nextReducingMPByOverTime = -1;
  10253.  
  10254. public void reduceCurrentMpByDamOverTime(final double i, final int period)
  10255. {
  10256. if (_nextReducingMPByOverTime > System.currentTimeMillis())
  10257. {
  10258. return;
  10259. }
  10260.  
  10261. _nextReducingMPByOverTime = System.currentTimeMillis() + (period * 1000);
  10262. reduceCurrentMp(i);
  10263.  
  10264. }
  10265.  
  10266. /**
  10267. * Reduce current mp.
  10268. * @param i the i
  10269. */
  10270. public void reduceCurrentMp(final double i)
  10271. {
  10272. getStatus().reduceMp(i);
  10273. }
  10274.  
  10275. /**
  10276. * Removes the status listener.
  10277. * @param object the object
  10278. */
  10279. public void removeStatusListener(final L2Character object)
  10280. {
  10281. getStatus().removeStatusListener(object);
  10282. }
  10283.  
  10284. /**
  10285. * Stop hp mp regeneration.
  10286. */
  10287. protected void stopHpMpRegeneration()
  10288. {
  10289. getStatus().stopHpMpRegeneration();
  10290. }
  10291.  
  10292. // Property - Public
  10293. /**
  10294. * Gets the current cp.
  10295. * @return the current cp
  10296. */
  10297. public final double getCurrentCp()
  10298. {
  10299. return getStatus().getCurrentCp();
  10300. }
  10301.  
  10302. /**
  10303. * Sets the current cp.
  10304. * @param newCp the new current cp
  10305. */
  10306. public final void setCurrentCp(final Double newCp)
  10307. {
  10308. setCurrentCp((double) newCp);
  10309. }
  10310.  
  10311. /**
  10312. * Sets the current cp.
  10313. * @param newCp the new current cp
  10314. */
  10315. public final void setCurrentCp(final double newCp)
  10316. {
  10317. getStatus().setCurrentCp(newCp);
  10318. }
  10319.  
  10320. /**
  10321. * Gets the current hp.
  10322. * @return the current hp
  10323. */
  10324. public final double getCurrentHp()
  10325. {
  10326. return getStatus().getCurrentHp();
  10327. }
  10328.  
  10329. /**
  10330. * Gets the current enemy hp after death
  10331. * @return the current hp
  10332. */
  10333. public final int getCurrentShowHpPvp()
  10334. {
  10335. return (int) getStatus().getCurrentHp();
  10336. }
  10337. /**
  10338. * Sets the current hp.
  10339. * @param newHp the new current hp
  10340. */
  10341. public final void setCurrentHp(final double newHp)
  10342. {
  10343. getStatus().setCurrentHp(newHp);
  10344. }
  10345.  
  10346. /**
  10347. * Sets the current hp direct.
  10348. * @param newHp the new current hp direct
  10349. */
  10350. public final void setCurrentHpDirect(final double newHp)
  10351. {
  10352. getStatus().setCurrentHpDirect(newHp);
  10353. }
  10354.  
  10355. /**
  10356. * Sets the current cp direct.
  10357. * @param newCp the new current cp direct
  10358. */
  10359. public final void setCurrentCpDirect(final double newCp)
  10360. {
  10361. getStatus().setCurrentCpDirect(newCp);
  10362. }
  10363.  
  10364. /**
  10365. * Sets the current mp direct.
  10366. * @param newMp the new current mp direct
  10367. */
  10368. public final void setCurrentMpDirect(final double newMp)
  10369. {
  10370. getStatus().setCurrentMpDirect(newMp);
  10371. }
  10372.  
  10373. /**
  10374. * Sets the current hp mp.
  10375. * @param newHp the new hp
  10376. * @param newMp the new mp
  10377. */
  10378. public final void setCurrentHpMp(final double newHp, final double newMp)
  10379. {
  10380. getStatus().setCurrentHpMp(newHp, newMp);
  10381. }
  10382.  
  10383. /**
  10384. * Gets the current mp.
  10385. * @return the current mp
  10386. */
  10387. public final double getCurrentMp()
  10388. {
  10389. return getStatus().getCurrentMp();
  10390. }
  10391.  
  10392. /**
  10393. * Sets the current mp.
  10394. * @param newMp the new current mp
  10395. */
  10396. public final void setCurrentMp(final Double newMp)
  10397. {
  10398. setCurrentMp((double) newMp);
  10399. }
  10400.  
  10401. /**
  10402. * Sets the current mp.
  10403. * @param newMp the new current mp
  10404. */
  10405. public final void setCurrentMp(final double newMp)
  10406. {
  10407. getStatus().setCurrentMp(newMp);
  10408. }
  10409.  
  10410. // =========================================================
  10411.  
  10412. /**
  10413. * Sets the ai class.
  10414. * @param aiClass the new ai class
  10415. */
  10416. public void setAiClass(final String aiClass)
  10417. {
  10418. _aiClass = aiClass;
  10419. }
  10420.  
  10421. /**
  10422. * Gets the ai class.
  10423. * @return the ai class
  10424. */
  10425. public String getAiClass()
  10426. {
  10427. return _aiClass;
  10428. }
  10429.  
  10430. /*
  10431. * public L2Character getLastBuffer() { return _lastBuffer; }
  10432. */
  10433.  
  10434. /**
  10435. * Sets the champion.
  10436. * @param champ the new champion
  10437. */
  10438. public void setChampion(final boolean champ)
  10439. {
  10440. _champion = champ;
  10441. }
  10442.  
  10443. /**
  10444. * Checks if is champion.
  10445. * @return true, if is champion
  10446. */
  10447. public boolean isChampion()
  10448. {
  10449. return _champion;
  10450. }
  10451.  
  10452. /**
  10453. * Gets the last heal amount.
  10454. * @return the last heal amount
  10455. */
  10456. public int getLastHealAmount()
  10457. {
  10458. return _lastHealAmount;
  10459. }
  10460.  
  10461. /*
  10462. * public void setLastBuffer(L2Character buffer) { _lastBuffer = buffer; }
  10463. */
  10464.  
  10465. /**
  10466. * Sets the last heal amount.
  10467. * @param hp the new last heal amount
  10468. */
  10469. public void setLastHealAmount(final int hp)
  10470. {
  10471. _lastHealAmount = hp;
  10472. }
  10473.  
  10474. /**
  10475. * @return the _advanceFlag
  10476. */
  10477. public boolean is_advanceFlag()
  10478. {
  10479. return _advanceFlag;
  10480. }
  10481.  
  10482. /**
  10483. * @param advanceFlag
  10484. */
  10485. public void set_advanceFlag(final boolean advanceFlag)
  10486. {
  10487. _advanceFlag = advanceFlag;
  10488. }
  10489.  
  10490. /**
  10491. * @param advanceMultiplier
  10492. */
  10493. public void set_advanceMultiplier(final int advanceMultiplier)
  10494. {
  10495. _advanceMultiplier = advanceMultiplier;
  10496. }
  10497.  
  10498. /**
  10499. * Check if character reflected skill.
  10500. * @param skill the skill
  10501. * @return true, if successful
  10502. */
  10503. public boolean reflectSkill(final L2Skill skill)
  10504. {
  10505. final double reflect = calcStat(skill.isMagic() ? Stats.REFLECT_SKILL_MAGIC : Stats.REFLECT_SKILL_PHYSIC, 0, null, null);
  10506.  
  10507. if (Rnd.get(100) < reflect)
  10508. return true;
  10509.  
  10510. return false;
  10511. }
  10512.  
  10513. /**
  10514. * Vengeance skill.
  10515. * @param skill the skill
  10516. * @return true, if successful
  10517. */
  10518. public boolean vengeanceSkill(final L2Skill skill)
  10519. {
  10520. if (!skill.isMagic() && skill.getCastRange() <= 40)
  10521. {
  10522. final double venganceChance = calcStat(Stats.VENGEANCE_SKILL_PHYSICAL_DAMAGE, 0, null, skill);
  10523. if (venganceChance > Rnd.get(100))
  10524. return true;
  10525. }
  10526. return false;
  10527. }
  10528.  
  10529. /**
  10530. * Send system message about damage.<BR>
  10531. * <BR>
  10532. * <B><U> Overriden in </U> :</B><BR>
  10533. * <BR>
  10534. * <li>L2PcInstance <li>L2SummonInstance <li>L2PetInstance</li><BR>
  10535. * <BR>
  10536. * @param target the target
  10537. * @param damage the damage
  10538. * @param mcrit the mcrit
  10539. * @param pcrit the pcrit
  10540. * @param miss the miss
  10541. */
  10542. public void sendDamageMessage(final L2Character target, final int damage, final boolean mcrit, final boolean pcrit, final boolean miss)
  10543. {
  10544. }
  10545.  
  10546. /**
  10547. * Gets the force buff.
  10548. * @return the force buff
  10549. */
  10550. public ForceBuff getForceBuff()
  10551. {
  10552. return _forceBuff;
  10553. }
  10554.  
  10555. /**
  10556. * Sets the force buff.
  10557. * @param fb the new force buff
  10558. */
  10559. public void setForceBuff(final ForceBuff fb)
  10560. {
  10561. _forceBuff = fb;
  10562. }
  10563.  
  10564. /**
  10565. * Checks if is fear immune.
  10566. * @return true, if is fear immune
  10567. */
  10568. public boolean isFearImmune()
  10569. {
  10570. return false;
  10571. }
  10572.  
  10573. /**
  10574. * Restore hpmp.
  10575. */
  10576. public void restoreHPMP()
  10577. {
  10578. getStatus().setCurrentHpMp(getMaxHp(), getMaxMp());
  10579. }
  10580.  
  10581. /**
  10582. * Restore cp.
  10583. */
  10584. public void restoreCP()
  10585. {
  10586. getStatus().setCurrentCp(getMaxCp());
  10587. }
  10588.  
  10589. /**
  10590. * Block.
  10591. */
  10592. public void block()
  10593. {
  10594. _blocked = true;
  10595. }
  10596.  
  10597. /**
  10598. * Unblock.
  10599. */
  10600. public void unblock()
  10601. {
  10602. _blocked = false;
  10603. }
  10604.  
  10605. /**
  10606. * Checks if is blocked.
  10607. * @return true, if is blocked
  10608. */
  10609. public boolean isBlocked()
  10610. {
  10611. return _blocked;
  10612. }
  10613.  
  10614. /**
  10615. * Checks if is meditated.
  10616. * @return true, if is meditated
  10617. */
  10618. public boolean isMeditated()
  10619. {
  10620. return _meditated;
  10621. }
  10622.  
  10623. /**
  10624. * Sets the meditated.
  10625. * @param meditated the new meditated
  10626. */
  10627. public void setMeditated(final boolean meditated)
  10628. {
  10629. _meditated = meditated;
  10630. }
  10631.  
  10632. /**
  10633. * Update attack stance.
  10634. */
  10635. public void updateAttackStance()
  10636. {
  10637. attackStance = System.currentTimeMillis();
  10638. }
  10639.  
  10640. /**
  10641. * Gets the attack stance.
  10642. * @return the attack stance
  10643. */
  10644. public long getAttackStance()
  10645. {
  10646. return attackStance;
  10647. }
  10648.  
  10649. /** The _petrified. */
  10650. private boolean _petrified = false;
  10651.  
  10652. /**
  10653. * Checks if is petrified.
  10654. * @return the petrified
  10655. */
  10656. public boolean isPetrified()
  10657. {
  10658. return _petrified;
  10659. }
  10660.  
  10661. /**
  10662. * Sets the petrified.
  10663. * @param petrified the petrified to set
  10664. */
  10665. public void setPetrified(final boolean petrified)
  10666. {
  10667. if (petrified)
  10668. {
  10669. setIsParalyzed(petrified);
  10670. setIsInvul(petrified);
  10671. _petrified = petrified;
  10672. }
  10673. else
  10674. {
  10675. _petrified = petrified;
  10676. setIsParalyzed(petrified);
  10677. setIsInvul(petrified);
  10678. }
  10679. }
  10680.  
  10681. /**
  10682. * Check bss.
  10683. * @return true, if successful
  10684. */
  10685. public boolean checkBss()
  10686. {
  10687.  
  10688. boolean bss = false;
  10689.  
  10690. final L2ItemInstance weaponInst = this.getActiveWeaponInstance();
  10691.  
  10692. if (weaponInst != null)
  10693. {
  10694. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  10695. {
  10696. bss = true;
  10697. // ponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  10698. }
  10699.  
  10700. }
  10701. // If there is no weapon equipped, check for an active summon.
  10702. else if (this instanceof L2Summon)
  10703. {
  10704. final L2Summon activeSummon = (L2Summon) this;
  10705.  
  10706. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  10707. {
  10708. bss = true;
  10709. // activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  10710. }
  10711.  
  10712. }
  10713.  
  10714. return bss;
  10715. }
  10716.  
  10717. /**
  10718. * Removes the bss.
  10719. */
  10720. synchronized public void removeBss()
  10721. {
  10722.  
  10723. final L2ItemInstance weaponInst = this.getActiveWeaponInstance();
  10724.  
  10725. if (weaponInst != null)
  10726. {
  10727. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  10728. {
  10729. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  10730. }
  10731.  
  10732. }
  10733. // If there is no weapon equipped, check for an active summon.
  10734. else if (this instanceof L2Summon)
  10735. {
  10736. final L2Summon activeSummon = (L2Summon) this;
  10737.  
  10738. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  10739. {
  10740. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  10741. }
  10742.  
  10743. }
  10744.  
  10745. reloadShots(true);
  10746. }
  10747.  
  10748. /**
  10749. * Check sps.
  10750. * @return true, if successful
  10751. */
  10752. public boolean checkSps()
  10753. {
  10754.  
  10755. boolean ss = false;
  10756.  
  10757. final L2ItemInstance weaponInst = this.getActiveWeaponInstance();
  10758.  
  10759. if (weaponInst != null)
  10760. {
  10761. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  10762. {
  10763. ss = true;
  10764. // weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  10765. }
  10766. }
  10767. // If there is no weapon equipped, check for an active summon.
  10768. else if (this instanceof L2Summon)
  10769. {
  10770. final L2Summon activeSummon = (L2Summon) this;
  10771.  
  10772. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  10773. {
  10774. ss = true;
  10775. // activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  10776. }
  10777. }
  10778.  
  10779. return ss;
  10780.  
  10781. }
  10782.  
  10783. /**
  10784. * Removes the sps.
  10785. */
  10786. synchronized public void removeSps()
  10787. {
  10788.  
  10789. final L2ItemInstance weaponInst = this.getActiveWeaponInstance();
  10790.  
  10791. if (weaponInst != null)
  10792. {
  10793. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  10794. {
  10795. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  10796. }
  10797. }
  10798. // If there is no weapon equipped, check for an active summon.
  10799. else if (this instanceof L2Summon)
  10800. {
  10801. final L2Summon activeSummon = (L2Summon) this;
  10802.  
  10803. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  10804. {
  10805. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  10806. }
  10807. }
  10808.  
  10809. reloadShots(true);
  10810. }
  10811.  
  10812. /**
  10813. * Check ss.
  10814. * @return true, if successful
  10815. */
  10816. public boolean checkSs()
  10817. {
  10818.  
  10819. boolean ss = false;
  10820.  
  10821. final L2ItemInstance weaponInst = this.getActiveWeaponInstance();
  10822.  
  10823. if (weaponInst != null)
  10824. {
  10825. if (weaponInst.getChargedSoulshot() == L2ItemInstance.CHARGED_SOULSHOT)
  10826. {
  10827. ss = true;
  10828. // weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  10829. }
  10830. }
  10831. // If there is no weapon equipped, check for an active summon.
  10832. else if (this instanceof L2Summon)
  10833. {
  10834. final L2Summon activeSummon = (L2Summon) this;
  10835.  
  10836. if (activeSummon.getChargedSoulShot() == L2ItemInstance.CHARGED_SOULSHOT)
  10837. {
  10838. ss = true;
  10839. // activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  10840. }
  10841. }
  10842.  
  10843. return ss;
  10844.  
  10845. }
  10846.  
  10847. /**
  10848. * Removes the ss.
  10849. */
  10850. public void removeSs()
  10851. {
  10852.  
  10853. final L2ItemInstance weaponInst = this.getActiveWeaponInstance();
  10854.  
  10855. if (weaponInst != null)
  10856. {
  10857. if (weaponInst.getChargedSoulshot() == L2ItemInstance.CHARGED_SOULSHOT)
  10858. {
  10859. weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  10860. }
  10861. }
  10862. // If there is no weapon equipped, check for an active summon.
  10863. else if (this instanceof L2Summon)
  10864. {
  10865. final L2Summon activeSummon = (L2Summon) this;
  10866.  
  10867. if (activeSummon.getChargedSoulShot() == L2ItemInstance.CHARGED_SOULSHOT)
  10868. {
  10869. activeSummon.setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
  10870. }
  10871. }
  10872. reloadShots(false);
  10873. }
  10874.  
  10875. /**
  10876. * Return a multiplier based on weapon random damage<BR>
  10877. * <BR>
  10878. * .
  10879. * @return the random damage multiplier
  10880. */
  10881. public final double getRandomDamageMultiplier()
  10882. {
  10883. final L2Weapon activeWeapon = getActiveWeaponItem();
  10884. int random;
  10885.  
  10886. if (activeWeapon != null)
  10887. random = activeWeapon.getRandomDamage();
  10888. else
  10889. random = 5 + (int) Math.sqrt(getLevel());
  10890.  
  10891. return (1 + ((double) Rnd.get(0 - random, random) / 100));
  10892. }
  10893.  
  10894. /**
  10895. * Sets the checks if is buff protected.
  10896. * @param value the new checks if is buff protected
  10897. */
  10898. public final void setIsBuffProtected(final boolean value)
  10899. {
  10900. _isBuffProtected = value;
  10901. }
  10902.  
  10903. /**
  10904. * Checks if is buff protected.
  10905. * @return true, if is buff protected
  10906. */
  10907. public boolean isBuffProtected()
  10908. {
  10909. return _isBuffProtected;
  10910. }
  10911.  
  10912. /**
  10913. * Gets the _triggered skills.
  10914. * @return the _triggeredSkills
  10915. */
  10916. public Map<Integer, L2Skill> get_triggeredSkills()
  10917. {
  10918. return _triggeredSkills;
  10919. }
  10920.  
  10921. /**
  10922. * Set target of L2Attackable and update it.
  10923. * @author: Nefer
  10924. * @param trasformedNpc
  10925. */
  10926. public void setTargetTrasformedNpc(final L2Attackable trasformedNpc)
  10927. {
  10928. if (trasformedNpc == null)
  10929. return;
  10930.  
  10931. // Set the target of the L2PcInstance player
  10932. this.setTarget(trasformedNpc);
  10933.  
  10934. // Send a Server->Client packet MyTargetSelected to the L2PcInstance player
  10935. // The player.getLevel() - getLevel() permit to display the correct color in the select window
  10936. MyTargetSelected my = new MyTargetSelected(trasformedNpc.getObjectId(), this.getLevel() - trasformedNpc.getLevel());
  10937. this.sendPacket(my);
  10938. my = null;
  10939.  
  10940. // Send a Server->Client packet StatusUpdate of the L2NpcInstance to the L2PcInstance to update its HP bar
  10941. StatusUpdate su = new StatusUpdate(trasformedNpc.getObjectId());
  10942. su.addAttribute(StatusUpdate.CUR_HP, (int) trasformedNpc.getCurrentHp());
  10943. su.addAttribute(StatusUpdate.MAX_HP, trasformedNpc.getMaxHp());
  10944. this.sendPacket(su);
  10945. su = null;
  10946. }
  10947.  
  10948. /**
  10949. * @return if the object can be killed
  10950. */
  10951. public boolean isUnkillable()
  10952. {
  10953. return _isUnkillable;
  10954. }
  10955.  
  10956. /**
  10957. * @param value the _isKillable to set
  10958. */
  10959. public void setIsUnkillable(final boolean value)
  10960. {
  10961. _isUnkillable = value;
  10962. }
  10963.  
  10964. /**
  10965. * @return the _isAttackDisabled
  10966. */
  10967. public boolean isAttackDisabled()
  10968. {
  10969. return _isAttackDisabled;
  10970. }
  10971.  
  10972. /**
  10973. * @param value the _isAttackDisabled to set
  10974. */
  10975. public void setIsAttackDisabled(final boolean value)
  10976. {
  10977. _isAttackDisabled = value;
  10978. }
  10979.  
  10980. /*
  10981. * AI not. Task
  10982. */
  10983. static class notifyAiTaskDelayed implements Runnable
  10984. {
  10985.  
  10986. CtrlEvent event;
  10987. Object object;
  10988. L2Object tgt;
  10989.  
  10990. notifyAiTaskDelayed(final CtrlEvent evt, final Object obj, final L2Object target)
  10991. {
  10992. event = evt;
  10993. object = obj;
  10994. tgt = target;
  10995. }
  10996.  
  10997. @Override
  10998. public void run()
  10999. {
  11000. ((L2Character) tgt).getAI().notifyEvent(event, object);
  11001. }
  11002.  
  11003. }
  11004.  
  11005. synchronized public void reloadShots(final boolean isMagic)
  11006. {
  11007. if (this instanceof L2PcInstance)
  11008. {
  11009. ((L2PcInstance) this).rechargeAutoSoulShot(!isMagic, isMagic, false);
  11010. }
  11011. else if (this instanceof L2Summon)
  11012. {
  11013. ((L2Summon) this).getOwner().rechargeAutoSoulShot(!isMagic, isMagic, true);
  11014. }
  11015. }
  11016. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement