Advertisement
Tammy-Street

L2Character

Mar 29th, 2023
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 309.81 KB | None | 0 0
  1. /*
  2.  * l2jlegacy Project - www.l2jlegacy.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.l2jlegacy.gameserver.model;
  22.  
  23. import static com.l2jlegacy.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
  24. import static com.l2jlegacy.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.l2jlegacy.Config;
  39. import com.l2jlegacy.gameserver.ai.CtrlEvent;
  40. import com.l2jlegacy.gameserver.ai.CtrlIntention;
  41. import com.l2jlegacy.gameserver.ai.L2AttackableAI;
  42. import com.l2jlegacy.gameserver.ai.L2CharacterAI;
  43. import com.l2jlegacy.gameserver.controllers.GameTimeController;
  44. import com.l2jlegacy.gameserver.datatables.HeroSkillTable;
  45. import com.l2jlegacy.gameserver.datatables.SkillTable;
  46. import com.l2jlegacy.gameserver.datatables.csv.DoorTable;
  47. import com.l2jlegacy.gameserver.datatables.csv.MapRegionTable;
  48. import com.l2jlegacy.gameserver.datatables.csv.MapRegionTable.TeleportWhereType;
  49. import com.l2jlegacy.gameserver.datatables.sql.NpcTable;
  50. import com.l2jlegacy.gameserver.geo.GeoData;
  51. import com.l2jlegacy.gameserver.geo.pathfinding.Node;
  52. import com.l2jlegacy.gameserver.geo.pathfinding.PathFinding;
  53. import com.l2jlegacy.gameserver.handler.ISkillHandler;
  54. import com.l2jlegacy.gameserver.handler.SkillHandler;
  55. import com.l2jlegacy.gameserver.handler.itemhandlers.Potions;
  56. import com.l2jlegacy.gameserver.managers.DimensionalRiftManager;
  57. import com.l2jlegacy.gameserver.managers.DuelManager;
  58. import com.l2jlegacy.gameserver.managers.GrandBossManager;
  59. import com.l2jlegacy.gameserver.managers.RaidBossSpawnManager;
  60. import com.l2jlegacy.gameserver.managers.TownManager;
  61. import com.l2jlegacy.gameserver.model.L2Skill.SkillTargetType;
  62. import com.l2jlegacy.gameserver.model.L2Skill.SkillType;
  63. import com.l2jlegacy.gameserver.model.actor.instance.L2BoatInstance;
  64. import com.l2jlegacy.gameserver.model.actor.instance.L2ControlTowerInstance;
  65. import com.l2jlegacy.gameserver.model.actor.instance.L2DoorInstance;
  66. import com.l2jlegacy.gameserver.model.actor.instance.L2EffectPointInstance;
  67. import com.l2jlegacy.gameserver.model.actor.instance.L2GrandBossInstance;
  68. import com.l2jlegacy.gameserver.model.actor.instance.L2GuardInstance;
  69. import com.l2jlegacy.gameserver.model.actor.instance.L2ItemInstance;
  70. import com.l2jlegacy.gameserver.model.actor.instance.L2MinionInstance;
  71. import com.l2jlegacy.gameserver.model.actor.instance.L2MonsterInstance;
  72. import com.l2jlegacy.gameserver.model.actor.instance.L2NpcInstance;
  73. import com.l2jlegacy.gameserver.model.actor.instance.L2NpcWalkerInstance;
  74. import com.l2jlegacy.gameserver.model.actor.instance.L2PcInstance;
  75. import com.l2jlegacy.gameserver.model.actor.instance.L2PetInstance;
  76. import com.l2jlegacy.gameserver.model.actor.instance.L2PlayableInstance;
  77. import com.l2jlegacy.gameserver.model.actor.instance.L2RaidBossInstance;
  78. import com.l2jlegacy.gameserver.model.actor.instance.L2RiftInvaderInstance;
  79. import com.l2jlegacy.gameserver.model.actor.instance.L2SiegeFlagInstance;
  80. import com.l2jlegacy.gameserver.model.actor.instance.L2SummonInstance;
  81. import com.l2jlegacy.gameserver.model.actor.instance.L2PcInstance.SkillDat;
  82. import com.l2jlegacy.gameserver.model.actor.knownlist.CharKnownList;
  83. import com.l2jlegacy.gameserver.model.actor.knownlist.ObjectKnownList.KnownListAsynchronousUpdateTask;
  84. import com.l2jlegacy.gameserver.model.actor.position.L2CharPosition;
  85. import com.l2jlegacy.gameserver.model.actor.position.ObjectPosition;
  86. import com.l2jlegacy.gameserver.model.actor.stat.CharStat;
  87. import com.l2jlegacy.gameserver.model.actor.status.CharStatus;
  88. import com.l2jlegacy.gameserver.model.entity.Duel;
  89. import com.l2jlegacy.gameserver.model.entity.event.CTF;
  90. import com.l2jlegacy.gameserver.model.entity.event.DM;
  91. import com.l2jlegacy.gameserver.model.entity.event.L2Event;
  92. import com.l2jlegacy.gameserver.model.entity.event.TvT;
  93. import com.l2jlegacy.gameserver.model.entity.event.VIP;
  94. import com.l2jlegacy.gameserver.model.entity.olympiad.Olympiad;
  95. import com.l2jlegacy.gameserver.model.extender.BaseExtender.EventType;
  96. import com.l2jlegacy.gameserver.model.quest.Quest;
  97. import com.l2jlegacy.gameserver.model.quest.QuestState;
  98. import com.l2jlegacy.gameserver.model.zone.type.L2BossZone;
  99. import com.l2jlegacy.gameserver.model.zone.type.L2TownZone;
  100. import com.l2jlegacy.gameserver.network.SystemMessageId;
  101. import com.l2jlegacy.gameserver.network.serverpackets.ActionFailed;
  102. import com.l2jlegacy.gameserver.network.serverpackets.Attack;
  103. import com.l2jlegacy.gameserver.network.serverpackets.BeginRotation;
  104. import com.l2jlegacy.gameserver.network.serverpackets.ChangeMoveType;
  105. import com.l2jlegacy.gameserver.network.serverpackets.ChangeWaitType;
  106. import com.l2jlegacy.gameserver.network.serverpackets.CharInfo;
  107. import com.l2jlegacy.gameserver.network.serverpackets.CharMoveToLocation;
  108. import com.l2jlegacy.gameserver.network.serverpackets.ExOlympiadSpelledInfo;
  109. import com.l2jlegacy.gameserver.network.serverpackets.L2GameServerPacket;
  110. import com.l2jlegacy.gameserver.network.serverpackets.MagicEffectIcons;
  111. import com.l2jlegacy.gameserver.network.serverpackets.MagicSkillCanceld;
  112. import com.l2jlegacy.gameserver.network.serverpackets.MagicSkillLaunched;
  113. import com.l2jlegacy.gameserver.network.serverpackets.MagicSkillUser;
  114. import com.l2jlegacy.gameserver.network.serverpackets.MyTargetSelected;
  115. import com.l2jlegacy.gameserver.network.serverpackets.NpcInfo;
  116. import com.l2jlegacy.gameserver.network.serverpackets.PartySpelled;
  117. import com.l2jlegacy.gameserver.network.serverpackets.PetInfo;
  118. import com.l2jlegacy.gameserver.network.serverpackets.RelationChanged;
  119. import com.l2jlegacy.gameserver.network.serverpackets.Revive;
  120. import com.l2jlegacy.gameserver.network.serverpackets.SetupGauge;
  121. import com.l2jlegacy.gameserver.network.serverpackets.StatusUpdate;
  122. import com.l2jlegacy.gameserver.network.serverpackets.StopMove;
  123. import com.l2jlegacy.gameserver.network.serverpackets.SystemMessage;
  124. import com.l2jlegacy.gameserver.network.serverpackets.TargetUnselected;
  125. import com.l2jlegacy.gameserver.network.serverpackets.TeleportToLocation;
  126. import com.l2jlegacy.gameserver.network.serverpackets.ValidateLocation;
  127. import com.l2jlegacy.gameserver.network.serverpackets.ValidateLocationInVehicle;
  128. import com.l2jlegacy.gameserver.skills.Calculator;
  129. import com.l2jlegacy.gameserver.skills.Formulas;
  130. import com.l2jlegacy.gameserver.skills.Stats;
  131. import com.l2jlegacy.gameserver.skills.effects.EffectCharge;
  132. import com.l2jlegacy.gameserver.skills.funcs.Func;
  133. import com.l2jlegacy.gameserver.skills.holders.ISkillsHolder;
  134. import com.l2jlegacy.gameserver.templates.L2CharTemplate;
  135. import com.l2jlegacy.gameserver.templates.L2NpcTemplate;
  136. import com.l2jlegacy.gameserver.templates.L2Weapon;
  137. import com.l2jlegacy.gameserver.templates.L2WeaponType;
  138. import com.l2jlegacy.gameserver.templates.StatsSet;
  139. import com.l2jlegacy.gameserver.thread.ThreadPoolManager;
  140. import com.l2jlegacy.gameserver.util.Util;
  141. import com.l2jlegacy.util.Point3D;
  142. import com.l2jlegacy.util.random.Rnd;
  143.  
  144. /**
  145.  * Mother class of all character objects of the world (PC, NPC...)<BR>
  146.  * <BR>
  147.  * L2Character :<BR>
  148.  * <BR>
  149.  * <li>L2CastleGuardInstance</li> <li>L2DoorInstance</li> <li>L2NpcInstance</li> <li>L2PlayableInstance</li><BR>
  150.  * <BR>
  151.  * <B><U> Concept of L2CharTemplate</U> :</B><BR>
  152.  * <BR>
  153.  * 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
  154.  * L2Character is spawned, server just create a link between the instance and the template. This link is stored in <B>_template</B><BR>
  155.  * <BR>
  156.  * @version $Revision: 1.5.5 $ $Date: 2009/05/12 19:45:27 $
  157.  * @authors eX1steam, programmos, L2Scoria dev&sword dev
  158.  */
  159. public abstract class L2Character extends L2Object implements ISkillsHolder
  160. {
  161.     /** The Constant LOGGER. */
  162.     protected static final Logger LOGGER = Logger.getLogger(L2Character.class);
  163.    
  164.     // =========================================================
  165.     // Data Field
  166.     /** The attack stance. */
  167.     private long attackStance;
  168.    
  169.     /** The _attack by list. */
  170.     private List<L2Character> _attackByList;
  171.     // private L2Character _attackingChar;
  172.     /** The _last skill cast. */
  173.     private L2Skill _lastSkillCast;
  174.    
  175.     /** The _last potion cast. */
  176.     private L2Skill _lastPotionCast;
  177.    
  178.     /** The _is buff protected. */
  179.     private boolean _isBuffProtected = false; // Protect From Debuffs
  180.    
  181.     /** The _is afraid. */
  182.     private boolean _isAfraid = false; // Flee in a random direction
  183.    
  184.     /** The _is confused. */
  185.     private boolean _isConfused = false; // Attack anyone randomly
  186.    
  187.     /** The _is fake death. */
  188.     private boolean _isFakeDeath = false; // Fake death
  189.    
  190.     /** The _is flying. */
  191.     private boolean _isFlying = false; // Is flying Wyvern?
  192.    
  193.     /** The _is fallsdown. */
  194.     private boolean _isFallsdown = false; // Falls down
  195.    
  196.     /** The _is muted. */
  197.     private boolean _isMuted = false; // Cannot use magic
  198.    
  199.     /** The _is psychical muted. */
  200.     private boolean _isPsychicalMuted = false; // Cannot use psychical skills
  201.    
  202.     /** The _is killed already. */
  203.     private boolean _isKilledAlready = false;
  204.    
  205.     /** The _is imobilised. */
  206.     private int _isImmobilized = 0;
  207.    
  208.     /** The _is overloaded. */
  209.     private boolean _isOverloaded = false; // the char is carrying too much
  210.    
  211.     /** The _is paralyzed. */
  212.     private boolean _isParalyzed = false;
  213.    
  214.     /** The _is riding. */
  215.     private boolean _isRiding = false; // Is Riding strider?
  216.    
  217.     /** The _is pending revive. */
  218.     private boolean _isPendingRevive = false;
  219.    
  220.     /** The _is rooted. */
  221.     private boolean _isRooted = false; // Cannot move until root timed out
  222.    
  223.     /** The _is running. */
  224.     private boolean _isRunning = false;
  225.    
  226.     /** The _is immobile until attacked. */
  227.     private boolean _isImmobileUntilAttacked = false; // Is in immobile until attacked.
  228.    
  229.     /** The _is sleeping. */
  230.     private boolean _isSleeping = false; // Cannot move/attack until sleep timed out or monster is attacked
  231.    
  232.     /** The _is stunned. */
  233.     private boolean _isStunned = false; // Cannot move/attack until stun timed out
  234.    
  235.     /** The _is betrayed. */
  236.     private boolean _isBetrayed = false; // Betrayed by own summon
  237.    
  238.     /** The _is block buff. */
  239.     private boolean _isBlockBuff = false; // Got blocked buff bar
  240.    
  241.     /** The _is block debuff. */
  242.     private boolean _isBlockDebuff = false; // Got blocked debuff bar
  243.    
  244.     /** The _is teleporting. */
  245.     protected boolean _isTeleporting = false;
  246.    
  247.     /** The _is invul. */
  248.     protected boolean _isInvul = false;
  249.    
  250.     /** The _is killable */
  251.     protected boolean _isUnkillable = false;
  252.    
  253.     /** The attackDisabled */
  254.     protected boolean _isAttackDisabled = false;
  255.    
  256.     /** The _last heal amount. */
  257.     private int _lastHealAmount = 0;
  258.    
  259.     /** The _stat. */
  260.     private CharStat _stat;
  261.    
  262.     /** The _status. */
  263.     private CharStatus _status;
  264.    
  265.     /** The _template. */
  266.     private L2CharTemplate _template; // The link on the L2CharTemplate object containing generic and static properties of this L2Character type (ex : Max HP, Speed...)
  267.    
  268.     /** The _title. */
  269.     private String _title;
  270.    
  271.     /** The _ai class. */
  272.     private String _aiClass = "default";
  273.    
  274.     /** The _hp update inc check. */
  275.     private double _hpUpdateIncCheck = .0;
  276.    
  277.     /** The _hp update dec check. */
  278.     private double _hpUpdateDecCheck = .0;
  279.    
  280.     /** The _hp update interval. */
  281.     private double _hpUpdateInterval = .0;
  282.    
  283.     /** The _champion. */
  284.     private boolean _champion = false;
  285.    
  286.     /** Table of Calculators containing all used calculator. */
  287.     private Calculator[] _calculators;
  288.    
  289.     /** FastMap(Integer, L2Skill) containing all skills of the L2Character. */
  290.     protected final Map<Integer, L2Skill> _skills;
  291.    
  292.     /** FastMap(Integer, L2Skill) containing all triggered skills of the L2PcInstance. */
  293.     protected final Map<Integer, L2Skill> _triggeredSkills;
  294.    
  295.     /** FastMap containing the active chance skills on this character. */
  296.     protected ChanceSkillList _chanceSkills;
  297.    
  298.     /** Current force buff this caster is casting to a target. */
  299.     protected ForceBuff _forceBuff;
  300.    
  301.     /** The _blocked. */
  302.     private boolean _blocked;
  303.    
  304.     /** The _meditated. */
  305.     private boolean _meditated;
  306.    
  307.     /**
  308.      * Zone system<br>
  309.      * x^2 or x*x.
  310.      */
  311.     public static final int ZONE_PVP = 1;
  312.    
  313.     /** The Constant ZONE_PEACE. */
  314.     public static final int ZONE_PEACE = 2;
  315.    
  316.     /** The Constant ZONE_SIEGE. */
  317.     public static final int ZONE_SIEGE = 4;
  318.    
  319.     /** The Constant ZONE_MOTHERTREE. */
  320.     public static final int ZONE_MOTHERTREE = 8;
  321.    
  322.     /** The Constant ZONE_CLANHALL. */
  323.     public static final int ZONE_CLANHALL = 16;
  324.    
  325.     /** The Constant ZONE_UNUSED. */
  326.     public static final int ZONE_UNUSED = 32;
  327.    
  328.     /** The Constant ZONE_NOLANDING. */
  329.     public static final int ZONE_NOLANDING = 64;
  330.    
  331.     /** The Constant ZONE_WATER. */
  332.     public static final int ZONE_WATER = 128;
  333.    
  334.     /** The Constant ZONE_JAIL. */
  335.     public static final int ZONE_JAIL = 256;
  336.    
  337.     /** The Constant ZONE_MONSTERTRACK. */
  338.     public static final int ZONE_MONSTERTRACK = 512;
  339.    
  340.     /** The Constant ZONE_SWAMP. */
  341.     public static final int ZONE_SWAMP = 1024;
  342.    
  343.     /** The Constant ZONE_NOSUMMONFRIEND. */
  344.     public static final int ZONE_NOSUMMONFRIEND = 2048;
  345.    
  346.     /** The Constant ZONE_OLY. */
  347.     public static final int ZONE_OLY = 4096;
  348.    
  349.     /** The Constant ZONE_NOHQ. */
  350.     public static final int ZONE_NOHQ = 8192;
  351.    
  352.     /** The Constant ZONE_DANGERAREA. */
  353.     public static final int ZONE_DANGERAREA = 16384;
  354.    
  355.     /** The Constant ZONE_NOSTORE. */
  356.     public static final int ZONE_NOSTORE = 32768;
  357.    
  358.     /** The _current zones. */
  359.     private int _currentZones = 0;
  360.    
  361.     /** Advance Headquarters */
  362.     private boolean _advanceFlag = false;
  363.     private int _advanceMultiplier = 1;
  364.    
  365.     /**
  366.      * Checks if is inside zone.
  367.      * @param zone the zone
  368.      * @return true, if is inside zone
  369.      */
  370.     public boolean isInsideZone(final int zone)
  371.     {
  372.         return (_currentZones & zone) != 0;
  373.     }
  374.    
  375.     /**
  376.      * Sets the inside zone.
  377.      * @param zone the zone
  378.      * @param state the state
  379.      */
  380.     public void setInsideZone(final int zone, final boolean state)
  381.     {
  382.         if (state)
  383.         {
  384.             _currentZones |= zone;
  385.         }
  386.         else if (isInsideZone(zone))
  387.         {
  388.             _currentZones ^= zone;
  389.         }
  390.     }
  391.    
  392.     /**
  393.      * This will return true if the player is GM,<br>
  394.      * but if the player is not GM it will return false.
  395.      * @return GM status
  396.      */
  397.     public boolean charIsGM()
  398.     {
  399.         if (this instanceof L2PcInstance)
  400.         {
  401.             if (((L2PcInstance) this).isGM())
  402.             {
  403.                 return true;
  404.             }
  405.         }
  406.         return false;
  407.     }
  408.    
  409.     // =========================================================
  410.     // Constructor
  411.     /**
  412.      * Constructor of L2Character.<BR>
  413.      * <BR>
  414.      * <B><U> Concept</U> :</B><BR>
  415.      * <BR>
  416.      * 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
  417.      * L2Character is spawned, server just create a link between the instance and the template This link is stored in <B>_template</B><BR>
  418.      * <BR>
  419.      * <B><U> Actions</U> :</B><BR>
  420.      * <BR>
  421.      * <li>Set the _template of the L2Character</li> <li>Set _overloaded to false (the charcater can take more items)</li> <BR>
  422.      * <BR>
  423.      * <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>
  424.      * <BR>
  425.      * <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>
  426.      * <BR>
  427.      * @param objectId Identifier of the object to initialized
  428.      * @param template The L2CharTemplate to apply to the object
  429.      */
  430.     // MAKE TO US From DREAM
  431.     // int attackcountmax = (int) Math.round(calcStat(Stats.POLE_TARGERT_COUNT, 3, null, null));
  432.     public L2Character(final int objectId, final L2CharTemplate template)
  433.     {
  434.         super(objectId);
  435.         getKnownList();
  436.        
  437.         // Set its template to the new L2Character
  438.         _template = template;
  439.        
  440.         _triggeredSkills = new FastMap<>();
  441.        
  442.         if (template != null && this instanceof L2NpcInstance)
  443.         {
  444.             // Copy the Standard Calcultors of the L2NPCInstance in _calculators
  445.             _calculators = NPC_STD_CALCULATOR;
  446.            
  447.             // Copy the skills of the L2NPCInstance from its template to the L2Character Instance
  448.             // The skills list can be affected by spell effects so it's necessary to make a copy
  449.             // to avoid that a spell affecting a L2NPCInstance, affects others L2NPCInstance of the same type too.
  450.             _skills = ((L2NpcTemplate) template).getSkills();
  451.            
  452.             for (final Map.Entry<Integer, L2Skill> skill : _skills.entrySet())
  453.             {
  454.                 addStatFuncs(skill.getValue().getStatFuncs(null, this));
  455.             }
  456.            
  457.             if (!Config.NPC_ATTACKABLE || !(this instanceof L2Attackable) && !(this instanceof L2ControlTowerInstance) && !(this instanceof L2SiegeFlagInstance) && !(this instanceof L2EffectPointInstance))
  458.             {
  459.                 setIsInvul(true);
  460.             }
  461.         }
  462.         else
  463.         // not L2NpcInstance
  464.         {
  465.             // Initialize the FastMap _skills to null
  466.             _skills = new FastMap<Integer, L2Skill>().shared();
  467.            
  468.             // If L2Character is a L2PcInstance or a L2Summon, create the basic calculator set
  469.             _calculators = new Calculator[Stats.NUM_STATS];
  470.             Formulas.getInstance().addFuncsToNewCharacter(this);
  471.            
  472.             if (!(this instanceof L2Attackable) && !this.isAttackable() && !(this instanceof L2DoorInstance))
  473.                 setIsInvul(true);
  474.         }
  475.        
  476.         /*
  477.          * if(!(this instanceof L2PcInstance) && !(this instanceof L2MonsterInstance) && !(this instanceof L2GuardInstance) && !(this instanceof L2SiegeGuardInstance) && !(this instanceof L2ControlTowerInstance) && !(this instanceof L2DoorInstance) && !(this instanceof L2FriendlyMobInstance) &&
  478.          * !(this instanceof L2SiegeSummonInstance) && !(this instanceof L2PetInstance) && !(this instanceof L2SummonInstance) && !(this instanceof L2SiegeFlagInstance) && !(this instanceof L2EffectPointInstance) && !(this instanceof L2CommanderInstance) && !(this instanceof
  479.          * L2FortSiegeGuardInstance)) { ///////////////////////////////////////////////////////////////////////////////////////////// setIsInvul(true); }
  480.          */
  481.     }
  482.    
  483.     /**
  484.      * Inits the char status update values.
  485.      */
  486.     protected void initCharStatusUpdateValues()
  487.     {
  488.         _hpUpdateInterval = getMaxHp() / 352.0; // MAX_HP div MAX_HP_BAR_PX
  489.         _hpUpdateIncCheck = getMaxHp();
  490.         _hpUpdateDecCheck = getMaxHp() - _hpUpdateInterval;
  491.     }
  492.    
  493.     // =========================================================
  494.     // Event - Public
  495.     /**
  496.      * Remove the L2Character from the world when the decay task is launched.<BR>
  497.      * <BR>
  498.      * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T REMOVE the object from _allObjects of L2World </B></FONT><BR>
  499.      * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND Server->Client packets to players</B></FONT><BR>
  500.      * <BR>
  501.      */
  502.     public void onDecay()
  503.     {
  504.         L2WorldRegion reg = getWorldRegion();
  505.        
  506.         if (reg != null)
  507.         {
  508.             reg.removeFromZones(this);
  509.         }
  510.        
  511.         decayMe();
  512.        
  513.         reg = null;
  514.     }
  515.    
  516.     /*
  517.      * (non-Javadoc)
  518.      * @see com.l2jlegacy.gameserver.model.L2Object#onSpawn()
  519.      */
  520.     @Override
  521.     public void onSpawn()
  522.     {
  523.         super.onSpawn();
  524.         revalidateZone();
  525.     }
  526.    
  527.     /**
  528.      * On teleported.
  529.      */
  530.     public void onTeleported()
  531.     {
  532.         if (!isTeleporting())
  533.             return;
  534.        
  535.         final ObjectPosition pos = getPosition();
  536.        
  537.         if (pos != null)
  538.             spawnMe(getPosition().getX(), getPosition().getY(), getPosition().getZ());
  539.        
  540.         setIsTeleporting(false);
  541.        
  542.         if (_isPendingRevive)
  543.         {
  544.             doRevive();
  545.         }
  546.        
  547.         final L2Summon pet = getPet();
  548.        
  549.         // Modify the position of the pet if necessary
  550.         if (pet != null && pos != null)
  551.         {
  552.             pet.setFollowStatus(false);
  553.             pet.teleToLocation(pos.getX() + Rnd.get(-100, 100), pos.getY() + Rnd.get(-100, 100), pos.getZ(), false);
  554.             pet.setFollowStatus(true);
  555.         }
  556.        
  557.     }
  558.    
  559.     // =========================================================
  560.     // Method - Public
  561.     /**
  562.      * Add L2Character instance that is attacking to the attacker list.<BR>
  563.      * <BR>
  564.      * @param player The L2Character that attcks this one
  565.      */
  566.     public void addAttackerToAttackByList(final L2Character player)
  567.     {
  568.         if (player == null || player == this || getAttackByList() == null || getAttackByList().contains(player))
  569.             return;
  570.        
  571.         getAttackByList().add(player);
  572.     }
  573.    
  574.     /**
  575.      * Send a packet to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character.<BR>
  576.      * <BR>
  577.      * <B><U> Concept</U> :</B><BR>
  578.      * <BR>
  579.      * 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>
  580.      * <BR>
  581.      */
  582.    
  583.     protected byte _startingRotationCounter = 4;
  584.    
  585.     /**
  586.      * Checks if is starting rotation allowed.
  587.      * @return true, if is starting rotation allowed
  588.      */
  589.     public synchronized boolean isStartingRotationAllowed()
  590.     {
  591.         // This function is called too often from movement arrow
  592.         _startingRotationCounter--;
  593.         if (_startingRotationCounter < 0)
  594.             _startingRotationCounter = 4;
  595.        
  596.         if (_startingRotationCounter == 4)
  597.         {
  598.             return true;
  599.         }
  600.         return false;
  601.     }
  602.    
  603.     /**
  604.      * Broadcast packet.
  605.      * @param mov the mov
  606.      */
  607.     public final void broadcastPacket(final L2GameServerPacket mov)
  608.     {
  609.         if (!(mov instanceof CharInfo))
  610.         {
  611.             sendPacket(mov);
  612.         }
  613.        
  614.         // don't broadcast anytime the rotating packet
  615.         if (mov instanceof BeginRotation && !isStartingRotationAllowed())
  616.         {
  617.             return;
  618.         }
  619.        
  620.         // if (Config.DEBUG) LOGGER.fine("players to notify:" + knownPlayers.size() + " packet:"+mov.getType());
  621.        
  622.         for (final L2PcInstance player : getKnownList().getKnownPlayers().values())
  623.         {
  624.             if (player != null)
  625.             {
  626.                 /*
  627.                  * 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.
  628.                  */
  629.                 if (this instanceof L2PcInstance && !player.isGM() && (((L2PcInstance) this).getAppearance().getInvisible() || ((L2PcInstance) this).inObserverMode()))
  630.                     return;
  631.                
  632.                 try
  633.                 {
  634.                     player.sendPacket(mov);
  635.                    
  636.                     if (mov instanceof CharInfo && this instanceof L2PcInstance)
  637.                     {
  638.                         final int relation = ((L2PcInstance) this).getRelation(player);
  639.                         if (getKnownList().getKnownRelations().get(player.getObjectId()) != null && getKnownList().getKnownRelations().get(player.getObjectId()) != relation)
  640.                         {
  641.                             player.sendPacket(new RelationChanged((L2PcInstance) this, relation, player.isAutoAttackable(this)));
  642.                         }
  643.                     }
  644.                     // if(Config.DEVELOPER && !isInsideRadius(player, 3500, false, false)) LOGGER.warn("broadcastPacket: Too far player see event!");
  645.                 }
  646.                 catch (final NullPointerException e)
  647.                 {
  648.                     e.printStackTrace();
  649.                 }
  650.             }
  651.         }
  652.     }
  653.    
  654.     /**
  655.      * Send a packet to the L2Character AND to all L2PcInstance in the radius (max knownlist radius) from the L2Character.<BR>
  656.      * <BR>
  657.      * <B><U> Concept</U> :</B><BR>
  658.      * <BR>
  659.      * 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>
  660.      * <BR>
  661.      * @param mov the mov
  662.      * @param radiusInKnownlist the radius in knownlist
  663.      */
  664.     public final void broadcastPacket(final L2GameServerPacket mov, final int radiusInKnownlist)
  665.     {
  666.         if (!(mov instanceof CharInfo))
  667.         {
  668.             sendPacket(mov);
  669.         }
  670.        
  671.         // if (Config.DEBUG) LOGGER.fine("players to notify:" + knownPlayers.size() + " packet:"+mov.getType());
  672.        
  673.         for (final L2PcInstance player : getKnownList().getKnownPlayers().values())
  674.         {
  675.             try
  676.             {
  677.                 if (!isInsideRadius(player, radiusInKnownlist, false, false))
  678.                 {
  679.                     continue;
  680.                 }
  681.                
  682.                 player.sendPacket(mov);
  683.                
  684.                 if (mov instanceof CharInfo && this instanceof L2PcInstance)
  685.                 {
  686.                     final int relation = ((L2PcInstance) this).getRelation(player);
  687.                     if (getKnownList().getKnownRelations().get(player.getObjectId()) != null && getKnownList().getKnownRelations().get(player.getObjectId()) != relation)
  688.                     {
  689.                         player.sendPacket(new RelationChanged((L2PcInstance) this, relation, player.isAutoAttackable(this)));
  690.                     }
  691.                 }
  692.             }
  693.             catch (final NullPointerException e)
  694.             {
  695.                 e.printStackTrace();
  696.             }
  697.         }
  698.     }
  699.    
  700.     /**
  701.      * Need hp update.
  702.      * @param barPixels the bar pixels
  703.      * @return true if hp update should be done, false if not
  704.      */
  705.     protected boolean needHpUpdate(final int barPixels)
  706.     {
  707.         final double currentHp = getCurrentHp();
  708.        
  709.         if (currentHp <= 1.0 || getMaxHp() < barPixels)
  710.             return true;
  711.        
  712.         if (currentHp <= _hpUpdateDecCheck || currentHp >= _hpUpdateIncCheck)
  713.         {
  714.             if (currentHp == getMaxHp())
  715.             {
  716.                 _hpUpdateIncCheck = currentHp + 1;
  717.                 _hpUpdateDecCheck = currentHp - _hpUpdateInterval;
  718.             }
  719.             else
  720.             {
  721.                 final double doubleMulti = currentHp / _hpUpdateInterval;
  722.                 int intMulti = (int) doubleMulti;
  723.                
  724.                 _hpUpdateDecCheck = _hpUpdateInterval * (doubleMulti < intMulti ? intMulti-- : intMulti);
  725.                 _hpUpdateIncCheck = _hpUpdateDecCheck + _hpUpdateInterval;
  726.             }
  727.             return true;
  728.         }
  729.        
  730.         return false;
  731.     }
  732.    
  733.     /**
  734.      * Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform.<BR>
  735.      * <BR>
  736.      * <B><U> Actions</U> :</B><BR>
  737.      * <BR>
  738.      * <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>
  739.      * <BR>
  740.      * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND CP information</B></FONT><BR>
  741.      * <BR>
  742.      * <B><U> Overriden in </U> :</B><BR>
  743.      * <BR>
  744.      * <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>
  745.      * <BR>
  746.      */
  747.     public void broadcastStatusUpdate()
  748.     {
  749.         if (getStatus().getStatusListener().isEmpty())
  750.             return;
  751.        
  752.         if (!needHpUpdate(352))
  753.             return;
  754.        
  755.         if (Config.DEBUG)
  756.         {
  757.             LOGGER.debug("Broadcast Status Update for " + getObjectId() + "(" + getName() + "). HP: " + getCurrentHp());
  758.         }
  759.        
  760.         // Create the Server->Client packet StatusUpdate with current HP and MP
  761.         StatusUpdate su = null;
  762.         if (Config.FORCE_COMPLETE_STATUS_UPDATE && this instanceof L2PcInstance)
  763.         {
  764.             su = new StatusUpdate((L2PcInstance) this);
  765.         }
  766.         else
  767.         {
  768.             su = new StatusUpdate(getObjectId());
  769.             su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
  770.             su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
  771.         }
  772.        
  773.         // Go through the StatusListener
  774.         // Send the Server->Client packet StatusUpdate with current HP and MP
  775.         for (final L2Character temp : getStatus().getStatusListener())
  776.         {
  777.             if (temp != null)
  778.                 temp.sendPacket(su);
  779.         }
  780.         /*
  781.          * synchronized (getStatus().getStatusListener()) { for(L2Character temp : getStatus().getStatusListener()) { try { temp.sendPacket(su); } catch(NullPointerException e) { e.printStackTrace(); } } }
  782.          */
  783.     }
  784.    
  785.     /**
  786.      * Not Implemented.<BR>
  787.      * <BR>
  788.      * <B><U> Overridden in </U> :</B><BR>
  789.      * <BR>
  790.      * <li>L2PcInstance</li><BR>
  791.      * <BR>
  792.      * @param mov the mov
  793.      */
  794.     public void sendPacket(final L2GameServerPacket mov)
  795.     {
  796.         // default implementation
  797.     }
  798.    
  799.     /** The _in town war. */
  800.     private boolean _inTownWar;
  801.    
  802.     /**
  803.      * Checks if is in town war.
  804.      * @return true, if is in town war
  805.      */
  806.     public final boolean isinTownWar()
  807.     {
  808.         return _inTownWar;
  809.     }
  810.    
  811.     /**
  812.      * Sets the in town war.
  813.      * @param value the new in town war
  814.      */
  815.     public final void setInTownWar(final boolean value)
  816.     {
  817.         _inTownWar = value;
  818.     }
  819.    
  820.     /*
  821.      * 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() ==
  822.      * 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) {
  823.      * 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,
  824.      * 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
  825.      * 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 -
  826.      * onTeleported() will do it getPosition().setWorldPosition(x, y, z); if(!(this instanceof L2PcInstance)) { onTeleported(); } }
  827.      */
  828.    
  829.     /**
  830.      * Teleport a L2Character and its pet if necessary.<BR>
  831.      * <BR>
  832.      * <B><U> Actions</U> :</B><BR>
  833.      * <BR>
  834.      * <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
  835.      * if necessary</li><BR>
  836.      * <BR>
  837.      * @param x the x
  838.      * @param y the y
  839.      * @param z the z
  840.      * @param allowRandomOffset the allow random offset
  841.      */
  842.     public void teleToLocation(int x, int y, int z, final boolean allowRandomOffset)
  843.     {
  844.         if (Config.TW_DISABLE_GK)
  845.         {
  846.             int x1, y1, z1;
  847.             x1 = getX();
  848.             y1 = getY();
  849.             z1 = getZ();
  850.             L2TownZone Town;
  851.             Town = TownManager.getInstance().getTown(x1, y1, z1);
  852.             if (Town != null && isinTownWar())
  853.             {
  854.                 if (Town.getTownId() == Config.TW_TOWN_ID && !Config.TW_ALL_TOWNS)
  855.                 {
  856.                     return;
  857.                 }
  858.                 else if (Config.TW_ALL_TOWNS)
  859.                 {
  860.                     return;
  861.                 }
  862.             }
  863.         }
  864.        
  865.         // Stop movement
  866.         stopMove(null, false);
  867.         abortAttack();
  868.         abortCast();
  869.        
  870.         setIsTeleporting(true);
  871.         setTarget(null);
  872.        
  873.         // Remove from world regions zones
  874.         final L2WorldRegion region = getWorldRegion();
  875.         if (region != null)
  876.             region.removeFromZones(this);
  877.        
  878.         getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  879.        
  880.         if (Config.RESPAWN_RANDOM_ENABLED && allowRandomOffset)
  881.         {
  882.             x += Rnd.get(-Config.RESPAWN_RANDOM_MAX_OFFSET, Config.RESPAWN_RANDOM_MAX_OFFSET);
  883.             y += Rnd.get(-Config.RESPAWN_RANDOM_MAX_OFFSET, Config.RESPAWN_RANDOM_MAX_OFFSET);
  884.         }
  885.        
  886.         z += 5;
  887.        
  888.         if (Config.DEBUG)
  889.             LOGGER.debug("Teleporting to: " + x + ", " + y + ", " + z);
  890.        
  891.         // Send a Server->Client packet TeleportToLocationt to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  892.         broadcastPacket(new TeleportToLocation(this, x, y, z));
  893.        
  894.         // remove the object from its old location
  895.         decayMe();
  896.        
  897.         // Set the x,y,z position of the L2Object and if necessary modify its _worldRegion
  898.         getPosition().setXYZ(x, y, z);
  899.        
  900.         // if (!(this instanceof L2PcInstance) || (((L2PcInstance)this).isOffline()))/*.getClient() != null && ((L2PcInstance)this).getClient().isDetached()))*/
  901.         if (!(this instanceof L2PcInstance))
  902.             onTeleported();
  903.        
  904.         revalidateZone(true);
  905.     }
  906.    
  907.     /** The _zone validate counter. */
  908.     protected byte _zoneValidateCounter = 4;
  909.    
  910.     /**
  911.      * Revalidate zone.
  912.      * @param force the force
  913.      */
  914.     public void revalidateZone(final boolean force)
  915.     {
  916.         final L2WorldRegion region = getWorldRegion();
  917.         if (region == null)
  918.             return;
  919.        
  920.         // This function is called too often from movement code
  921.         if (force)
  922.             _zoneValidateCounter = 4;
  923.         else
  924.         {
  925.             _zoneValidateCounter--;
  926.             if (_zoneValidateCounter < 0)
  927.                 _zoneValidateCounter = 4;
  928.             else
  929.                 return;
  930.         }
  931.         region.revalidateZones(this);
  932.     }
  933.    
  934.     /**
  935.      * Tele to location.
  936.      * @param x the x
  937.      * @param y the y
  938.      * @param z the z
  939.      */
  940.     public void teleToLocation(final int x, final int y, final int z)
  941.     {
  942.         teleToLocation(x, y, z, false);
  943.     }
  944.    
  945.     /**
  946.      * Tele to location.
  947.      * @param loc the loc
  948.      * @param allowRandomOffset the allow random offset
  949.      */
  950.     public void teleToLocation(final Location loc, final boolean allowRandomOffset)
  951.     {
  952.         int x = loc.getX();
  953.         int y = loc.getY();
  954.         int z = loc.getZ();
  955.        
  956.         if (this instanceof L2PcInstance && DimensionalRiftManager.getInstance().checkIfInRiftZone(getX(), getY(), getZ(), true))
  957.         { // true -> ignore waiting room :)
  958.             L2PcInstance player = (L2PcInstance) this;
  959.             player.sendMessage("You have been sent to the waiting room.");
  960.            
  961.             if (player.isInParty() && player.getParty().isInDimensionalRift())
  962.             {
  963.                 player.getParty().getDimensionalRift().usedTeleport(player);
  964.             }
  965.            
  966.             final int[] newCoords = DimensionalRiftManager.getInstance().getRoom((byte) 0, (byte) 0).getTeleportCoords();
  967.            
  968.             x = newCoords[0];
  969.             y = newCoords[1];
  970.             z = newCoords[2];
  971.            
  972.             player = null;
  973.         }
  974.         teleToLocation(x, y, z, allowRandomOffset);
  975.     }
  976.    
  977.     /**
  978.      * Tele to location.
  979.      * @param teleportWhere the teleport where
  980.      */
  981.     public void teleToLocation(final TeleportWhereType teleportWhere)
  982.     {
  983.         teleToLocation(MapRegionTable.getInstance().getTeleToLocation(this, teleportWhere), true);
  984.     }
  985.    
  986.     /*
  987.      * // 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 *
  988.      * 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 }
  989.      */
  990.    
  991.     // =========================================================
  992.     // Method - Private
  993.     /**
  994.      * Launch a physical attack against a target (Simple, Bow, Pole or Dual).<BR>
  995.      * <BR>
  996.      * <B><U> Actions</U> :</B><BR>
  997.      * <BR>
  998.      * <li>Get the active weapon (always equiped in the right hand)</li><BR>
  999.      * <BR>
  1000.      * <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>
  1001.      * <BR>
  1002.      * <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
  1003.      * 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>
  1004.      * <BR>
  1005.      * @param target The L2Character targeted
  1006.      */
  1007.     protected void doAttack(final L2Character target)
  1008.     {
  1009.         if (Config.DEBUG)
  1010.         {
  1011.             LOGGER.debug(getName() + " doAttack: target=" + target);
  1012.         }
  1013.        
  1014.         if (target == null)
  1015.             return;
  1016.        
  1017.         // Like L2OFF wait that the hit task finish and then player can move
  1018.         if (this instanceof L2PcInstance && ((L2PcInstance) this).isMovingTaskDefined() && !((L2PcInstance) this).isAttackingNow())
  1019.         {
  1020.             final L2ItemInstance rhand = ((L2PcInstance) this).getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  1021.             if ((rhand != null && rhand.getItemType() != L2WeaponType.BOW) || (rhand == null))
  1022.             {
  1023.                 ((L2PcInstance) this).startMovingTask();
  1024.                 return;
  1025.             }
  1026.         }
  1027.        
  1028.         if (isAlikeDead())
  1029.         {
  1030.             // If L2PcInstance is dead or the target is dead, the action is stoped
  1031.             getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1032.            
  1033.             sendPacket(ActionFailed.STATIC_PACKET);
  1034.             return;
  1035.         }
  1036.        
  1037.         if (this instanceof L2NpcInstance && target.isAlikeDead())
  1038.         {
  1039.             // If L2PcInstance is dead or the target is dead, the action is stoped
  1040.             getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1041.            
  1042.             sendPacket(ActionFailed.STATIC_PACKET);
  1043.             return;
  1044.         }
  1045.        
  1046.         if (this instanceof L2PcInstance && target.isDead() && !target.isFakeDeath())
  1047.         {
  1048.             // If L2PcInstance is dead or the target is dead, the action is stoped
  1049.             getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1050.            
  1051.             sendPacket(ActionFailed.STATIC_PACKET);
  1052.             return;
  1053.         }
  1054.        
  1055.         if (!getKnownList().knowsObject(target))
  1056.         {
  1057.             // If L2PcInstance is dead or the target is dead, the action is stoped
  1058.             getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1059.            
  1060.             sendPacket(ActionFailed.STATIC_PACKET);
  1061.             return;
  1062.         }
  1063.        
  1064.         if (this instanceof L2PcInstance && isDead())
  1065.         {
  1066.             // If L2PcInstance is dead or the target is dead, the action is stoped
  1067.             getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1068.            
  1069.             sendPacket(ActionFailed.STATIC_PACKET);
  1070.             return;
  1071.         }
  1072.        
  1073.         if (target instanceof L2PcInstance && ((L2PcInstance) target).getDuelState() == Duel.DUELSTATE_DEAD)
  1074.         {
  1075.             // If L2PcInstance is dead or the target is dead, the action is stoped
  1076.             getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1077.            
  1078.             sendPacket(ActionFailed.STATIC_PACKET);
  1079.             return;
  1080.         }
  1081.        
  1082.         if (target instanceof L2DoorInstance && !((L2DoorInstance) target).isAttackable(this))
  1083.             return;
  1084.        
  1085.         if (isAttackingDisabled())
  1086.             return;
  1087.        
  1088.         if (this instanceof L2PcInstance)
  1089.         {
  1090.             if (((L2PcInstance) this).inObserverMode())
  1091.             {
  1092.                 sendPacket(new SystemMessage(SystemMessageId.OBSERVERS_CANNOT_PARTICIPATE));
  1093.                 sendPacket(ActionFailed.STATIC_PACKET);
  1094.                 return;
  1095.             }
  1096.            
  1097.             if (target instanceof L2PcInstance)
  1098.             {
  1099.                 if (((L2PcInstance) target).isCursedWeaponEquiped() && ((L2PcInstance) this).getLevel() <= Config.MAX_LEVEL_NEWBIE)
  1100.                 {
  1101.                     ((L2PcInstance) this).sendMessage("Can't attack a cursed player when under level 21.");
  1102.                     sendPacket(ActionFailed.STATIC_PACKET);
  1103.                     return;
  1104.                 }
  1105.                
  1106.                 if (((L2PcInstance) this).isCursedWeaponEquiped() && ((L2PcInstance) target).getLevel() <= Config.MAX_LEVEL_NEWBIE)
  1107.                 {
  1108.                     ((L2PcInstance) this).sendMessage("Can't attack a newbie player using a cursed weapon.");
  1109.                     sendPacket(ActionFailed.STATIC_PACKET);
  1110.                     return;
  1111.                 }
  1112.             }
  1113.            
  1114.             // thank l2dot
  1115.             if (getObjectId() == target.getObjectId())
  1116.             {
  1117.                 sendPacket(ActionFailed.STATIC_PACKET);
  1118.                 return;
  1119.             }
  1120.            
  1121.             if (target instanceof L2NpcInstance && Config.DISABLE_ATTACK_NPC_TYPE)
  1122.             {
  1123.                 final String mobtype = ((L2NpcInstance) target).getTemplate().type;
  1124.                 if (!Config.LIST_ALLOWED_NPC_TYPES.contains(mobtype))
  1125.                 {
  1126.                     final SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2);
  1127.                     sm.addString("Npc Type " + mobtype + " has Protection - No Attack Allowed!");
  1128.                     ((L2PcInstance) this).sendPacket(sm);
  1129.                     ((L2PcInstance) this).sendPacket(ActionFailed.STATIC_PACKET);
  1130.                     return;
  1131.                 }
  1132.             }
  1133.         }
  1134.        
  1135.         // Get the active weapon instance (always equiped in the right hand)
  1136.         L2ItemInstance weaponInst = getActiveWeaponInstance();
  1137.        
  1138.         // Get the active weapon item corresponding to the active weapon instance (always equiped in the right hand)
  1139.         L2Weapon weaponItem = getActiveWeaponItem();
  1140.        
  1141.         if (weaponItem != null && weaponItem.getItemType() == L2WeaponType.ROD)
  1142.         {
  1143.             // You can't make an attack with a fishing pole.
  1144.             ((L2PcInstance) this).sendPacket(new SystemMessage(SystemMessageId.CANNOT_ATTACK_WITH_FISHING_POLE));
  1145.             getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1146.            
  1147.             sendPacket(ActionFailed.STATIC_PACKET);
  1148.             return;
  1149.         }
  1150.        
  1151.         /*
  1152.          * TEMPFIX: Check client Z coordinate instead of server z to avoid exploit killing Zaken from others floor
  1153.          */
  1154.         if ((target instanceof L2GrandBossInstance) && ((L2GrandBossInstance) target).getNpcId() == 29022)
  1155.         {
  1156.             if (Math.abs(this.getClientZ() - target.getZ()) > 200)
  1157.             {
  1158.                 sendPacket(new SystemMessage(SystemMessageId.CANT_SEE_TARGET));
  1159.                 getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1160.                 sendPacket(ActionFailed.STATIC_PACKET);
  1161.                 return;
  1162.             }
  1163.         }
  1164.        
  1165.         // GeoData Los Check here (or dz > 1000)
  1166.         if (!GeoData.getInstance().canSeeTarget(this, target))
  1167.         {
  1168.             sendPacket(new SystemMessage(SystemMessageId.CANT_SEE_TARGET));
  1169.             getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1170.             sendPacket(ActionFailed.STATIC_PACKET);
  1171.             return;
  1172.         }
  1173.        
  1174.         // Check for a bow
  1175.         if (weaponItem != null && weaponItem.getItemType() == L2WeaponType.BOW)
  1176.         {
  1177.             // Equip arrows needed in left hand and send a Server->Client packet ItemList to the L2PcINstance then return True
  1178.             if (!checkAndEquipArrows())
  1179.             {
  1180.                 // Cancel the action because the L2PcInstance have no arrow
  1181.                 getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1182.                
  1183.                 sendPacket(ActionFailed.STATIC_PACKET);
  1184.                 sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ARROWS));
  1185.                 return;
  1186.             }
  1187.            
  1188.             // Check for arrows and MP
  1189.             if (this instanceof L2PcInstance)
  1190.             {
  1191.                 // Checking if target has moved to peace zone - only for player-bow attacks at the moment
  1192.                 // Other melee is checked in movement code and for offensive spells a check is done every time
  1193.                 if (target.isInsidePeaceZone((L2PcInstance) this))
  1194.                 {
  1195.                     getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  1196.                     sendPacket(ActionFailed.STATIC_PACKET);
  1197.                     return;
  1198.                 }
  1199.                
  1200.                 // Verify if the bow can be use
  1201.                 if (_disableBowAttackEndTime <= GameTimeController.getGameTicks())
  1202.                 {
  1203.                     // Verify if L2PcInstance owns enough MP
  1204.                     final int saMpConsume = (int) getStat().calcStat(Stats.MP_CONSUME, 0, null, null);
  1205.                     final int mpConsume = saMpConsume == 0 ? weaponItem.getMpConsume() : saMpConsume;
  1206.                    
  1207.                     if (getCurrentMp() < mpConsume)
  1208.                     {
  1209.                         // If L2PcInstance doesn't have enough MP, stop the attack
  1210.                         ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
  1211.                        
  1212.                         sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_MP));
  1213.                         sendPacket(ActionFailed.STATIC_PACKET);
  1214.                         return;
  1215.                     }
  1216.                     // If L2PcInstance have enough MP, the bow consummes it
  1217.                     getStatus().reduceMp(mpConsume);
  1218.                    
  1219.                     // Set the period of bow non re-use
  1220.                     _disableBowAttackEndTime = 5 * GameTimeController.TICKS_PER_SECOND + GameTimeController.getGameTicks();
  1221.                 }
  1222.                 else
  1223.                 {
  1224.                     // Cancel the action because the bow can't be re-use at this moment
  1225.                     ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
  1226.                    
  1227.                     sendPacket(ActionFailed.STATIC_PACKET);
  1228.                     return;
  1229.                 }
  1230.                
  1231.             }
  1232.             else if (this instanceof L2NpcInstance)
  1233.             {
  1234.                 if (_disableBowAttackEndTime > GameTimeController.getGameTicks())
  1235.                     return;
  1236.             }
  1237.         }
  1238.        
  1239.         // Add the L2PcInstance to _knownObjects and _knownPlayer of the target
  1240.         target.getKnownList().addKnownObject(this);
  1241.        
  1242.         // Reduce the current CP if TIREDNESS configuration is activated
  1243.         if (Config.ALT_GAME_TIREDNESS)
  1244.         {
  1245.             setCurrentCp(getCurrentCp() - 10);
  1246.         }
  1247.        
  1248.         final int timeAtk = calculateTimeBetweenAttacks(target, weaponItem);
  1249.        
  1250.         // Recharge any active auto soulshot tasks for player (or player's summon if one exists).
  1251.         if (this instanceof L2PcInstance)
  1252.         {
  1253.             ((L2PcInstance) this).rechargeAutoSoulShot(true, false, false, timeAtk);
  1254.         }
  1255.         else if (this instanceof L2Summon)
  1256.         {
  1257.             ((L2Summon) this).getOwner().rechargeAutoSoulShot(true, false, true, timeAtk);
  1258.         }
  1259.        
  1260.         // Verify if soulshots are charged.
  1261.         boolean wasSSCharged;
  1262.        
  1263.         if (this instanceof L2Summon && !(this instanceof L2PetInstance))
  1264.         {
  1265.             wasSSCharged = ((L2Summon) this).getChargedSoulShot() != L2ItemInstance.CHARGED_NONE;
  1266.         }
  1267.         else
  1268.         {
  1269.             wasSSCharged = weaponInst != null && weaponInst.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE;
  1270.         }
  1271.        
  1272.         // Get the Attack Speed of the L2Character (delay (in milliseconds) before next attack)
  1273.         // the hit is calculated to happen halfway to the animation - might need further tuning e.g. in bow case
  1274.         final int timeToHit = timeAtk / 2;
  1275.         _attackEndTime = GameTimeController.getGameTicks();
  1276.         _attackEndTime += (timeAtk / GameTimeController.MILLIS_IN_TICK);
  1277.         _attackEndTime -= 1;
  1278.        
  1279.         int ssGrade = 0;
  1280.        
  1281.         if (weaponItem != null)
  1282.         {
  1283.             ssGrade = weaponItem.getCrystalType();
  1284.         }
  1285.        
  1286.         // Create a Server->Client packet Attack
  1287.         Attack attack = new Attack(this, wasSSCharged, ssGrade);
  1288.        
  1289.         boolean hitted;
  1290.        
  1291.         // Set the Attacking Body part to CHEST
  1292.         setAttackingBodypart();
  1293.        
  1294.         // Heading calculation on every attack
  1295.         this.setHeading(Util.calculateHeadingFrom(this.getX(), this.getY(), target.getX(), target.getY()));
  1296.        
  1297.         // Get the Attack Reuse Delay of the L2Weapon
  1298.         final int reuse = calculateReuseTime(target, weaponItem);
  1299.        
  1300.         // Select the type of attack to start
  1301.         if (weaponItem == null)
  1302.         {
  1303.             hitted = doAttackHitSimple(attack, target, timeToHit);
  1304.         }
  1305.         else if (weaponItem.getItemType() == L2WeaponType.BOW)
  1306.         {
  1307.             hitted = doAttackHitByBow(attack, target, timeAtk, reuse);
  1308.         }
  1309.         else if (weaponItem.getItemType() == L2WeaponType.POLE)
  1310.         {
  1311.             hitted = doAttackHitByPole(attack, timeToHit);
  1312.         }
  1313.         else if (isUsingDualWeapon())
  1314.         {
  1315.             hitted = doAttackHitByDual(attack, target, timeToHit);
  1316.         }
  1317.         else
  1318.         {
  1319.             hitted = doAttackHitSimple(attack, target, timeToHit);
  1320.         }
  1321.        
  1322.         // Flag the attacker if it's a L2PcInstance outside a PvP area
  1323.         L2PcInstance player = null;
  1324.        
  1325.         if (this instanceof L2PcInstance)
  1326.         {
  1327.             player = (L2PcInstance) this;
  1328.         }
  1329.         else if (this instanceof L2Summon)
  1330.         {
  1331.             player = ((L2Summon) this).getOwner();
  1332.         }
  1333.        
  1334.         if (player != null)
  1335.         {
  1336.             player.updatePvPStatus(target);
  1337.         }
  1338.        
  1339.         // Check if hit isn't missed
  1340.         if (!hitted)
  1341.         {
  1342.             // MAJAX fix
  1343.             sendPacket(new SystemMessage(SystemMessageId.MISSED_TARGET));
  1344.             // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  1345.             abortAttack();
  1346.         }
  1347.         else
  1348.         {
  1349.             /*
  1350.              * 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.
  1351.              */
  1352.            
  1353.             // If we didn't miss the hit, discharge the shoulshots, if any
  1354.             if (this instanceof L2Summon && !(this instanceof L2PetInstance))
  1355.             {
  1356.                 ((L2Summon) this).setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
  1357.             }
  1358.             else if (weaponInst != null)
  1359.             {
  1360.                 weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  1361.             }
  1362.            
  1363.             if (player != null)
  1364.             {
  1365.                 if (player.isCursedWeaponEquiped())
  1366.                 {
  1367.                     // If hitted by a cursed weapon, Cp is reduced to 0
  1368.                     if (!target.isInvul())
  1369.                     {
  1370.                         target.setCurrentCp(0);
  1371.                     }
  1372.                 }
  1373.                 else if (player.isHero())
  1374.                 {
  1375.                     if (target instanceof L2PcInstance && ((L2PcInstance) target).isCursedWeaponEquiped())
  1376.                     {
  1377.                         // If a cursed weapon is hitted by a Hero, Cp is reduced to 0
  1378.                         target.setCurrentCp(0);
  1379.                     }
  1380.                 }
  1381.             }
  1382.            
  1383.             weaponInst = null;
  1384.             weaponItem = null;
  1385.         }
  1386.        
  1387.         // If the Server->Client packet Attack contains at least 1 hit, send the Server->Client packet Attack
  1388.         // to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  1389.         if (attack.hasHits())
  1390.         {
  1391.             broadcastPacket(attack);
  1392.             fireEvent(EventType.ATTACK.name, new Object[]
  1393.             {
  1394.                 getTarget()
  1395.             });
  1396.         }
  1397.        
  1398.         // Like L2OFF mobs id 27181 can teleport players near cabrio
  1399.         if (this instanceof L2MonsterInstance && ((L2MonsterInstance) this).getNpcId() == 27181)
  1400.         {
  1401.             final int rndNum = Rnd.get(100);
  1402.             final L2PcInstance gettarget = (L2PcInstance) this.getTarget();
  1403.            
  1404.             if (rndNum < 5 && gettarget != null)
  1405.                 gettarget.teleToLocation(179768, 6364, -2734);
  1406.         }
  1407.        
  1408.         // Like L2OFF if target is not auto attackable you give only one hit
  1409.         if (this instanceof L2PcInstance && target instanceof L2PcInstance && !target.isAutoAttackable(this))
  1410.         {
  1411.             ((L2PcInstance) this).getAI().clientStopAutoAttack();
  1412.             ((L2PcInstance) this).getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, this);
  1413.         }
  1414.        
  1415.         // Notify AI with EVT_READY_TO_ACT
  1416.         ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), timeAtk + reuse);
  1417.        
  1418.         attack = null;
  1419.         player = null;
  1420.     }
  1421.    
  1422.     /**
  1423.      * Launch a Bow attack.<BR>
  1424.      * <BR>
  1425.      * <B><U> Actions</U> :</B><BR>
  1426.      * <BR>
  1427.      * <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
  1428.      * 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>
  1429.      * <BR>
  1430.      * @param attack Server->Client packet Attack in which the hit will be added
  1431.      * @param target The L2Character targeted
  1432.      * @param sAtk The Attack Speed of the attacker
  1433.      * @param reuse the reuse
  1434.      * @return True if the hit isn't missed
  1435.      */
  1436.     private boolean doAttackHitByBow(final Attack attack, final L2Character target, final int sAtk, final int reuse)
  1437.     {
  1438.         int damage1 = 0;
  1439.         boolean shld1 = false;
  1440.         boolean crit1 = false;
  1441.        
  1442.         // Calculate if hit is missed or not
  1443.         final boolean miss1 = Formulas.calcHitMiss(this, target);
  1444.        
  1445.         // Consumme arrows
  1446.         reduceArrowCount();
  1447.        
  1448.         _move = null;
  1449.        
  1450.         // Check if hit isn't missed
  1451.         if (!miss1)
  1452.         {
  1453.             // Calculate if shield defense is efficient
  1454.             shld1 = Formulas.calcShldUse(this, target);
  1455.            
  1456.             // Calculate if hit is critical
  1457.             crit1 = Formulas.calcCrit(getStat().getCriticalHit(target, null));
  1458.            
  1459.             // Calculate physical damages
  1460.             damage1 = (int) Formulas.calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
  1461.         }
  1462.        
  1463.         // Check if the L2Character is a L2PcInstance
  1464.         if (this instanceof L2PcInstance)
  1465.         {
  1466.             // Send a system message
  1467.             sendPacket(new SystemMessage(SystemMessageId.GETTING_READY_TO_SHOOT_AN_ARROW));
  1468.            
  1469.             // Send a Server->Client packet SetupGauge
  1470.             SetupGauge sg = new SetupGauge(SetupGauge.RED, sAtk + reuse);
  1471.             sendPacket(sg);
  1472.             sg = null;
  1473.         }
  1474.        
  1475.         // Create a new hit task with Medium priority
  1476.         ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
  1477.        
  1478.         // Calculate and set the disable delay of the bow in function of the Attack Speed
  1479.         _disableBowAttackEndTime = (sAtk + reuse) / GameTimeController.MILLIS_IN_TICK + GameTimeController.getGameTicks();
  1480.        
  1481.         // Add this hit to the Server-Client packet Attack
  1482.         attack.addHit(target, damage1, miss1, crit1, shld1);
  1483.        
  1484.         // Return true if hit isn't missed
  1485.         return !miss1;
  1486.     }
  1487.    
  1488.     /**
  1489.      * Launch a Dual attack.<BR>
  1490.      * <BR>
  1491.      * <B><U> Actions</U> :</B><BR>
  1492.      * <BR>
  1493.      * <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>
  1494.      * <li>Add those hits to the Server-Client packet Attack</li><BR>
  1495.      * <BR>
  1496.      * @param attack Server->Client packet Attack in which the hit will be added
  1497.      * @param target The L2Character targeted
  1498.      * @param sAtk the s atk
  1499.      * @return True if hit 1 or hit 2 isn't missed
  1500.      */
  1501.     private boolean doAttackHitByDual(final Attack attack, final L2Character target, final int sAtk)
  1502.     {
  1503.         int damage1 = 0;
  1504.         int damage2 = 0;
  1505.         boolean shld1 = false;
  1506.         boolean shld2 = false;
  1507.         boolean crit1 = false;
  1508.         boolean crit2 = false;
  1509.        
  1510.         // Calculate if hits are missed or not
  1511.         final boolean miss1 = Formulas.calcHitMiss(this, target);
  1512.         final boolean miss2 = Formulas.calcHitMiss(this, target);
  1513.        
  1514.         // Check if hit 1 isn't missed
  1515.         if (!miss1)
  1516.         {
  1517.             // Calculate if shield defense is efficient against hit 1
  1518.             shld1 = Formulas.calcShldUse(this, target);
  1519.            
  1520.             // Calculate if hit 1 is critical
  1521.             crit1 = Formulas.calcCrit(getStat().getCriticalHit(target, null));
  1522.            
  1523.             // Calculate physical damages of hit 1
  1524.             damage1 = (int) Formulas.calcPhysDam(this, target, null, shld1, crit1, true, attack.soulshot);
  1525.             damage1 /= 2;
  1526.         }
  1527.        
  1528.         // Check if hit 2 isn't missed
  1529.         if (!miss2)
  1530.         {
  1531.             // Calculate if shield defense is efficient against hit 2
  1532.             shld2 = Formulas.calcShldUse(this, target);
  1533.            
  1534.             // Calculate if hit 2 is critical
  1535.             crit2 = Formulas.calcCrit(getStat().getCriticalHit(target, null));
  1536.            
  1537.             // Calculate physical damages of hit 2
  1538.             damage2 = (int) Formulas.calcPhysDam(this, target, null, shld2, crit2, true, attack.soulshot);
  1539.             damage2 /= 2;
  1540.         }
  1541.        
  1542.         // Create a new hit task with Medium priority for hit 1
  1543.         ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk / 2);
  1544.        
  1545.         // Create a new hit task with Medium priority for hit 2 with a higher delay
  1546.         ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage2, crit2, miss2, attack.soulshot, shld2), sAtk);
  1547.        
  1548.         // Add those hits to the Server-Client packet Attack
  1549.         attack.addHit(target, damage1, miss1, crit1, shld1);
  1550.         attack.addHit(target, damage2, miss2, crit2, shld2);
  1551.        
  1552.         // Return true if hit 1 or hit 2 isn't missed
  1553.         return !miss1 || !miss2;
  1554.     }
  1555.    
  1556.     /**
  1557.      * Launch a Pole attack.<BR>
  1558.      * <BR>
  1559.      * <B><U> Actions</U> :</B><BR>
  1560.      * <BR>
  1561.      * <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
  1562.      * it</li><BR>
  1563.      * <BR>
  1564.      * @param attack Server->Client packet Attack in which the hit will be added
  1565.      * @param sAtk the s atk
  1566.      * @return True if one hit isn't missed
  1567.      */
  1568.     private boolean doAttackHitByPole(final Attack attack, final int sAtk)
  1569.     {
  1570.         boolean hitted = false;
  1571.        
  1572.         double angleChar, angleTarget;
  1573.         final int maxRadius = (int) getStat().calcStat(Stats.POWER_ATTACK_RANGE, 66, null, null);
  1574.         final int maxAngleDiff = (int) getStat().calcStat(Stats.POWER_ATTACK_ANGLE, 120, null, null);
  1575.        
  1576.         if (getTarget() == null)
  1577.             return false;
  1578.        
  1579.         angleTarget = Util.calculateAngleFrom(this, getTarget());
  1580.         setHeading((int) (angleTarget / 9.0 * 1610.0));
  1581.        
  1582.         angleChar = Util.convertHeadingToDegree(getHeading());
  1583.         double attackpercent = 85;
  1584.         final int attackcountmax = (int) getStat().calcStat(Stats.ATTACK_COUNT_MAX, 3, null, null);
  1585.         int attackcount = 0;
  1586.        
  1587.         if (angleChar <= 0)
  1588.             angleChar += 360;
  1589.        
  1590.         L2Character target;
  1591.         for (final L2Object obj : getKnownList().getKnownObjects().values())
  1592.         {
  1593.             if (obj instanceof L2Character)
  1594.             {
  1595.                 if (obj instanceof L2PetInstance && this instanceof L2PcInstance && ((L2PetInstance) obj).getOwner() == (L2PcInstance) this)
  1596.                 {
  1597.                     continue;
  1598.                 }
  1599.                
  1600.                 if (!Util.checkIfInRange(maxRadius, this, obj, false))
  1601.                 {
  1602.                     continue;
  1603.                 }
  1604.                
  1605.                 if (Math.abs(obj.getZ() - getZ()) > Config.DIFFERENT_Z_CHANGE_OBJECT)
  1606.                 {
  1607.                     continue;
  1608.                 }
  1609.                
  1610.                 angleTarget = Util.calculateAngleFrom(this, obj);
  1611.                
  1612.                 if (Math.abs(angleChar - angleTarget) > maxAngleDiff && Math.abs(angleChar + 360 - angleTarget) > maxAngleDiff && Math.abs(angleChar - (angleTarget + 360)) > maxAngleDiff)
  1613.                 {
  1614.                     continue;
  1615.                 }
  1616.                
  1617.                 target = (L2Character) obj;
  1618.                
  1619.                 if (!target.isAlikeDead())
  1620.                 {
  1621.                     attackcount += 1;
  1622.                    
  1623.                     if (attackcount <= attackcountmax)
  1624.                     {
  1625.                         if (target == getAI().getAttackTarget() || target.isAutoAttackable(this))
  1626.                         {
  1627.                             hitted |= doAttackHitSimple(attack, target, attackpercent, sAtk);
  1628.                             attackpercent /= 1.15;
  1629.                            
  1630.                             // Flag player if the target is another player
  1631.                             if (this instanceof L2PcInstance && obj instanceof L2PcInstance)
  1632.                                 ((L2PcInstance) this).updatePvPStatus(target);
  1633.                         }
  1634.                     }
  1635.                 }
  1636.             }
  1637.         }
  1638.         target = null;
  1639.         // Return true if one hit isn't missed
  1640.         return hitted;
  1641.     }
  1642.    
  1643.     /**
  1644.      * Launch a simple attack.<BR>
  1645.      * <BR>
  1646.      * <B><U> Actions</U> :</B><BR>
  1647.      * <BR>
  1648.      * <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
  1649.      * this hit to the Server-Client packet Attack</li><BR>
  1650.      * <BR>
  1651.      * @param attack Server->Client packet Attack in which the hit will be added
  1652.      * @param target The L2Character targeted
  1653.      * @param sAtk the s atk
  1654.      * @return True if the hit isn't missed
  1655.      */
  1656.     private boolean doAttackHitSimple(final Attack attack, final L2Character target, final int sAtk)
  1657.     {
  1658.         return doAttackHitSimple(attack, target, 100, sAtk);
  1659.     }
  1660.    
  1661.     /**
  1662.      * Do attack hit simple.
  1663.      * @param attack the attack
  1664.      * @param target the target
  1665.      * @param attackpercent the attackpercent
  1666.      * @param sAtk the s atk
  1667.      * @return true, if successful
  1668.      */
  1669.     private boolean doAttackHitSimple(final Attack attack, final L2Character target, final double attackpercent, final int sAtk)
  1670.     {
  1671.         int damage1 = 0;
  1672.         boolean shld1 = false;
  1673.         boolean crit1 = false;
  1674.        
  1675.         // Calculate if hit is missed or not
  1676.         final boolean miss1 = Formulas.calcHitMiss(this, target);
  1677.        
  1678.         // Check if hit isn't missed
  1679.         if (!miss1)
  1680.         {
  1681.             // Calculate if shield defense is efficient
  1682.             shld1 = Formulas.calcShldUse(this, target);
  1683.            
  1684.             // Calculate if hit is critical
  1685.             crit1 = Formulas.calcCrit(getStat().getCriticalHit(target, null));
  1686.            
  1687.             // Calculate physical damages
  1688.             damage1 = (int) Formulas.calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
  1689.            
  1690.             if (attackpercent != 100)
  1691.             {
  1692.                 damage1 = (int) (damage1 * attackpercent / 100);
  1693.             }
  1694.         }
  1695.        
  1696.         // Create a new hit task with Medium priority
  1697.         ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
  1698.        
  1699.         // Add this hit to the Server-Client packet Attack
  1700.         attack.addHit(target, damage1, miss1, crit1, shld1);
  1701.        
  1702.         // Return true if hit isn't missed
  1703.         return !miss1;
  1704.     }
  1705.    
  1706.     /**
  1707.      * Manage the casting task (casting and interrupt time, re-use delay...) and display the casting bar and animation on client.<BR>
  1708.      * <BR>
  1709.      * <B><U> Actions</U> :</B><BR>
  1710.      * <BR>
  1711.      * <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
  1712.      * 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
  1713.      * 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>
  1714.      * <BR>
  1715.      * @param skill The L2Skill to use
  1716.      */
  1717.     public void doCast(final L2Skill skill)
  1718.     {
  1719.         final L2Character activeChar = this;
  1720.        
  1721.         if (skill == null)
  1722.         {
  1723.             getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  1724.             return;
  1725.         }
  1726.        
  1727.         // Check if the skill is a magic spell and if the L2Character is not muted
  1728.         if (skill.isMagic() && isMuted() && !skill.isPotion())
  1729.         {
  1730.             getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  1731.             return;
  1732.         }
  1733.  
  1734.         if (this instanceof L2PcInstance)
  1735.         {
  1736.             L2PcInstance player = (L2PcInstance) this;
  1737.             if (player.getTarget() != null && player.getTarget() == player)
  1738.                 if (skill.getSkillType() == SkillType.CHARGEDAM)
  1739.                 {
  1740.                     player.sendMessage("修理:");
  1741.                     return;
  1742.                 }  
  1743.         }
  1744.  
  1745.         // Check if the skill is psychical and if the L2Character is not psychical_muted
  1746.         if (!skill.isMagic() && isPsychicalMuted() && !skill.isPotion())
  1747.         {
  1748.             getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  1749.             return;
  1750.         }
  1751.        
  1752.         // Can't use Hero and resurrect skills during Olympiad
  1753.         if (activeChar instanceof L2PcInstance && ((L2PcInstance) activeChar).isInOlympiadMode() && (skill.isHeroSkill() || skill.getSkillType() == SkillType.RESURRECT))
  1754.         {
  1755.             SystemMessage sm = new SystemMessage(SystemMessageId.THIS_SKILL_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  1756.             sendPacket(sm);
  1757.             sm = null;
  1758.             return;
  1759.         }
  1760.        
  1761.         // Like L2OFF you can't use skills when you are attacking now
  1762.         if (activeChar instanceof L2PcInstance && !skill.isPotion())
  1763.         {
  1764.             final L2ItemInstance rhand = ((L2PcInstance) this).getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  1765.             if ((rhand != null && rhand.getItemType() == L2WeaponType.BOW))
  1766.             {
  1767.                 if (isAttackingNow())
  1768.                     return;
  1769.             }
  1770.         }
  1771.        
  1772.         // prevent casting signets to peace zone
  1773.         if (skill.getSkillType() == SkillType.SIGNET || skill.getSkillType() == SkillType.SIGNET_CASTTIME)
  1774.         {
  1775.             /*
  1776.              * 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());
  1777.              * sendPacket(sm); return; } }
  1778.              */
  1779.            
  1780.             final L2WorldRegion region = getWorldRegion();
  1781.             if (region == null)
  1782.                 return;
  1783.             boolean canCast = true;
  1784.             if (skill.getTargetType() == SkillTargetType.TARGET_GROUND && this instanceof L2PcInstance)
  1785.             {
  1786.                 final Point3D wp = ((L2PcInstance) this).getCurrentSkillWorldPosition();
  1787.                 if (!region.checkEffectRangeInsidePeaceZone(skill, wp.getX(), wp.getY(), wp.getZ()))
  1788.                     canCast = false;
  1789.             }
  1790.             else if (!region.checkEffectRangeInsidePeaceZone(skill, getX(), getY(), getZ()))
  1791.                 canCast = false;
  1792.             if (!canCast)
  1793.             {
  1794.                 final SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  1795.                 sm.addSkillName(skill.getId());
  1796.                 sendPacket(sm);
  1797.                 return;
  1798.             }
  1799.         }
  1800.        
  1801.         // Recharge AutoSoulShot
  1802.        
  1803.         final int atkTime = Formulas.getInstance().calcMAtkSpd(activeChar, skill, skill.getHitTime());
  1804.         if (skill.useSoulShot())
  1805.         {
  1806.             if (activeChar instanceof L2PcInstance)
  1807.             {
  1808.                 ((L2PcInstance) activeChar).rechargeAutoSoulShot(true, false, false, atkTime);
  1809.             }
  1810.             else if (this instanceof L2Summon)
  1811.             {
  1812.                 ((L2Summon) activeChar).getOwner().rechargeAutoSoulShot(true, false, true, atkTime);
  1813.             }
  1814.         }
  1815.        
  1816.         // else if (skill.useFishShot())
  1817.         // {
  1818.         // if (this instanceof L2PcInstance)
  1819.         // ((L2PcInstance)this).rechargeAutoSoulShot(true, false, false);
  1820.         // }
  1821.        
  1822.         // Get all possible targets of the skill in a table in function of the skill target type
  1823.         final L2Object[] targets = skill.getTargetList(activeChar);
  1824.         // Set the target of the skill in function of Skill Type and Target Type
  1825.         L2Character target = null;
  1826.        
  1827.         if (skill.getTargetType() == SkillTargetType.TARGET_AURA || skill.getTargetType() == SkillTargetType.TARGET_GROUND || skill.isPotion())
  1828.         {
  1829.             target = this;
  1830.         }
  1831.         else if (targets == null || targets.length == 0)
  1832.         {
  1833.             getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  1834.             return;
  1835.         }
  1836.         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())
  1837.         {
  1838.             target = (L2Character) targets[0];
  1839.            
  1840.             /*
  1841.              * 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 ||
  1842.              * 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() &&
  1843.              * skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY) { for (L2PcInstance member : ((L2PcInstance)this).getParty().getPartyMembers()) member.setLastBuffer(this); } }
  1844.              */
  1845.         }
  1846.         else
  1847.         {
  1848.             target = (L2Character) getTarget();
  1849.         }
  1850.        
  1851.         if (target == null)
  1852.         {
  1853.             getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  1854.             return;
  1855.         }
  1856.        
  1857.         // Player can't heal rb config
  1858.         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))
  1859.         {
  1860.             this.sendPacket(ActionFailed.STATIC_PACKET);
  1861.             return;
  1862.         }
  1863.        
  1864.         if (activeChar instanceof L2PcInstance && target instanceof L2NpcInstance && Config.DISABLE_ATTACK_NPC_TYPE)
  1865.         {
  1866.             final String mobtype = ((L2NpcInstance) target).getTemplate().type;
  1867.             if (!Config.LIST_ALLOWED_NPC_TYPES.contains(mobtype))
  1868.             {
  1869.                 final SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2);
  1870.                 sm.addString("Npc Type " + mobtype + " has Protection - No Attack Allowed!");
  1871.                 ((L2PcInstance) activeChar).sendPacket(sm);
  1872.                 ((L2PcInstance) activeChar).sendPacket(ActionFailed.STATIC_PACKET);
  1873.                 return;
  1874.             }
  1875.         }
  1876.        
  1877.         if (skill.isPotion())
  1878.             setLastPotionCast(skill);
  1879.         else
  1880.             setLastSkillCast(skill);
  1881.        
  1882.         // Get the Identifier of the skill
  1883.         final int magicId = skill.getId();
  1884.        
  1885.         // Get the Display Identifier for a skill that client can't display
  1886.         final int displayId = skill.getDisplayId();
  1887.        
  1888.         // Get the level of the skill
  1889.         int level = skill.getLevel();
  1890.        
  1891.         if (level < 1)
  1892.         {
  1893.             level = 1;
  1894.         }
  1895.        
  1896.         // Get the casting time of the skill (base)
  1897.         int hitTime = skill.getHitTime();
  1898.         int coolTime = skill.getCoolTime();
  1899.         final boolean effectWhileCasting = skill.hasEffectWhileCasting();
  1900.        
  1901.         final boolean forceBuff = skill.getSkillType() == SkillType.FORCE_BUFF && target instanceof L2PcInstance;
  1902.        
  1903.         // Calculate the casting time of the skill (base + modifier of MAtkSpd)
  1904.         // Don't modify the skill time for FORCE_BUFF skills. The skill time for those skills represent the buff time.
  1905.         if (!effectWhileCasting && !forceBuff && !skill.isStaticHitTime())
  1906.         {
  1907.             hitTime = Formulas.getInstance().calcMAtkSpd(activeChar, skill, hitTime);
  1908.            
  1909.             if (coolTime > 0)
  1910.             {
  1911.                 coolTime = Formulas.getInstance().calcMAtkSpd(activeChar, skill, coolTime);
  1912.             }
  1913.         }
  1914.        
  1915.         // Calculate altered Cast Speed due to BSpS/SpS only for Magic skills
  1916.         if ((checkBss() || checkSps()) && !skill.isStaticHitTime() && !skill.isPotion() && skill.isMagic())
  1917.         {
  1918.            
  1919.             // Only takes 70% of the time to cast a BSpS/SpS cast
  1920.             hitTime = (int) (0.70 * hitTime);
  1921.             coolTime = (int) (0.70 * coolTime);
  1922.            
  1923.             // Because the following are magic skills that do not actively 'eat' BSpS/SpS,
  1924.             // I must 'eat' them here so players don't take advantage of infinite speed increase
  1925.             /* MANAHEAL, MANARECHARGE, RESURRECT, RECALL */
  1926.             // if (skill.getSkillType() == SkillType.MANAHEAL || skill.getSkillType() == SkillType.MANARECHARGE || skill.getSkillType() == SkillType.RESURRECT || skill.getSkillType() == SkillType.RECALL)
  1927.             // {
  1928.             // if (checkBss())
  1929.             // removeBss();
  1930.             // else
  1931.             // removeSps();
  1932.             // }
  1933.            
  1934.         }
  1935.        
  1936.         /*
  1937.          * // 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()) {
  1938.          * 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);
  1939.          * //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() ==
  1940.          * SkillType.RESURRECT || skill.getSkillType() == SkillType.RECALL || skill.getSkillType() == SkillType.DOT) { weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE); } } } weaponInst = null;
  1941.          */
  1942.        
  1943.         if (skill.isPotion())
  1944.         {
  1945.             // Set the _castEndTime and _castInterruptTim. +10 ticks for lag situations, will be reseted in onMagicFinalizer
  1946.             _castPotionEndTime = 10 + GameTimeController.getGameTicks() + (coolTime + hitTime) / GameTimeController.MILLIS_IN_TICK;
  1947.             _castPotionInterruptTime = -2 + GameTimeController.getGameTicks() + hitTime / GameTimeController.MILLIS_IN_TICK;
  1948.            
  1949.         }
  1950.         else
  1951.         {
  1952.             // Set the _castEndTime and _castInterruptTim. +10 ticks for lag situations, will be reseted in onMagicFinalizer
  1953.             _castEndTime = 10 + GameTimeController.getGameTicks() + (coolTime + hitTime) / GameTimeController.MILLIS_IN_TICK;
  1954.             _castInterruptTime = -2 + GameTimeController.getGameTicks() + hitTime / GameTimeController.MILLIS_IN_TICK;
  1955.            
  1956.         }
  1957.        
  1958.         // Init the reuse time of the skill
  1959.         // int reuseDelay = (int)(skill.getReuseDelay() * getStat().getMReuseRate(skill));
  1960.         // reuseDelay *= 333.0 / (skill.isMagic() ? getMAtkSpd() : getPAtkSpd());
  1961.         int reuseDelay = skill.getReuseDelay();
  1962.        
  1963.         if (activeChar instanceof L2PcInstance && Formulas.getInstance().calcSkillMastery(activeChar))
  1964.         {
  1965.             reuseDelay = 0;
  1966.         }
  1967.         else if (!skill.isStaticReuse() && !skill.isPotion())
  1968.         {
  1969.             if (skill.isMagic())
  1970.             {
  1971.                 reuseDelay *= getStat().getMReuseRate(skill);
  1972.             }
  1973.             else
  1974.             {
  1975.                 reuseDelay *= getStat().getPReuseRate(skill);
  1976.             }
  1977.            
  1978.             reuseDelay *= 333.0 / (skill.isMagic() ? getMAtkSpd() : getPAtkSpd());
  1979.         }
  1980.        
  1981.         // To turn local player in target direction
  1982.         setHeading(Util.calculateHeadingFrom(getX(), getY(), target.getX(), target.getY()));
  1983.        
  1984.         /*
  1985.          * if(skill.isOffensive() && skill.getTargetType() != SkillTargetType.TARGET_AURA && target.isBehind(this)) { moveToLocation(target.getX(), target.getY(), target.getZ(), 0); stopMove(null); }
  1986.          */
  1987.        
  1988.         // Like L2OFF after a skill the player must stop the movement, also with toggle
  1989.         if (!skill.isPotion() && this instanceof L2PcInstance)
  1990.             ((L2PcInstance) this).stopMove(null);
  1991.        
  1992.         // Start the effect as long as the player is casting.
  1993.         if (effectWhileCasting)
  1994.         {
  1995.             callSkill(skill, targets);
  1996.         }
  1997.        
  1998.         // Send a Server->Client packet MagicSkillUser with target, displayId, level, skillTime, reuseDelay
  1999.         // to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  2000.         broadcastPacket(new MagicSkillUser(this, target, displayId, level, hitTime, reuseDelay));
  2001.        
  2002.         // Send a system message USE_S1 to the L2Character
  2003.         if (activeChar instanceof L2PcInstance && magicId != 1312)
  2004.         {
  2005.             if (skill.isPotion())
  2006.             {
  2007.                 SystemMessage sm = new SystemMessage(SystemMessageId.USE_S1_);
  2008.                 if (magicId == 2005)
  2009.                     sm.addItemName(728);
  2010.                 else if (magicId == 2003)
  2011.                     sm.addItemName(726);
  2012.                 // Message greater cp potions like retail
  2013.                 else if (magicId == 2166 && skill.getLevel() == 2)
  2014.                     sm.addItemName(5592);
  2015.                 // Message cp potions like retail
  2016.                 else if (magicId == 2166 && skill.getLevel() == 1)
  2017.                     sm.addItemName(5591);
  2018.                 else
  2019.                     sm.addSkillName(magicId, skill.getLevel());
  2020.                 sendPacket(sm);
  2021.                 sm = null;
  2022.             }
  2023.             else
  2024.             {
  2025.                 SystemMessage sm = new SystemMessage(SystemMessageId.USE_S1);
  2026.                 if (magicId == 2005)
  2027.                     sm.addItemName(728);
  2028.                 else if (magicId == 2003)
  2029.                     sm.addItemName(726);
  2030.                 // Message greater cp potions like retail
  2031.                 else if (magicId == 2166 && skill.getLevel() == 2)
  2032.                     sm.addItemName(5592);
  2033.                 // Message cp potions like retail
  2034.                 else if (magicId == 2166 && skill.getLevel() == 1)
  2035.                     sm.addItemName(5591);
  2036.                 else
  2037.                     sm.addSkillName(magicId, skill.getLevel());
  2038.                
  2039.                 // Skill 2046 is used only for animation on pets
  2040.                 if (magicId != 2046)
  2041.                     sendPacket(sm);
  2042.                 sm = null;
  2043.             }
  2044.         }
  2045.        
  2046.         // Skill reuse check
  2047.         if (reuseDelay > 30000)
  2048.         {
  2049.             addTimeStamp(skill, reuseDelay);
  2050.         }
  2051.        
  2052.         // Check if this skill consume mp on start casting
  2053.         final int initmpcons = getStat().getMpInitialConsume(skill);
  2054.        
  2055.         if (initmpcons > 0)
  2056.         {
  2057.             StatusUpdate su = new StatusUpdate(getObjectId());
  2058.            
  2059.             if (skill.isDance())
  2060.             {
  2061.                 getStatus().reduceMp(calcStat(Stats.DANCE_MP_CONSUME_RATE, initmpcons, null, null));
  2062.             }
  2063.             else if (skill.isMagic())
  2064.             {
  2065.                 getStatus().reduceMp(calcStat(Stats.MAGICAL_MP_CONSUME_RATE, initmpcons, null, null));
  2066.             }
  2067.             else
  2068.             {
  2069.                 getStatus().reduceMp(calcStat(Stats.PHYSICAL_MP_CONSUME_RATE, initmpcons, null, null));
  2070.             }
  2071.            
  2072.             su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
  2073.             sendPacket(su);
  2074.             su = null;
  2075.         }
  2076.        
  2077.         // 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
  2078.         if (reuseDelay > 10)
  2079.         {
  2080.             disableSkill(skill, reuseDelay);
  2081.         }
  2082.        
  2083.         // For force buff skills, start the effect as long as the player is casting.
  2084.         if (forceBuff)
  2085.         {
  2086.             startForceBuff(target, skill);
  2087.         }
  2088.        
  2089.         // launch the magic in hitTime milliseconds
  2090.         if (hitTime > 210)
  2091.         {
  2092.             // Send a Server->Client packet SetupGauge with the color of the gauge and the casting time
  2093.             if (activeChar instanceof L2PcInstance && !forceBuff)
  2094.             {
  2095.                 SetupGauge sg = new SetupGauge(SetupGauge.BLUE, hitTime);
  2096.                 sendPacket(sg);
  2097.                 sg = null;
  2098.             }
  2099.            
  2100.             // Disable all skills during the casting
  2101.             if (!skill.isPotion())
  2102.             { // for particular potion is the timestamp to disable particular skill
  2103.            
  2104.                 disableAllSkills();
  2105.                
  2106.                 if (_skillCast != null) // delete previous skill cast
  2107.                 {
  2108.                     _skillCast.cancel(true);
  2109.                     _skillCast = null;
  2110.                 }
  2111.                
  2112.             }
  2113.            
  2114.             // Create a task MagicUseTask to launch the MagicSkill at the end of the casting time (hitTime)
  2115.             // For client animation reasons (party buffs especially) 200 ms before!
  2116.             if (getForceBuff() != null || effectWhileCasting)
  2117.             {
  2118.                 if (skill.isPotion())
  2119.                     _potionCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 2), hitTime);
  2120.                
  2121.                 else
  2122.                     _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 2), hitTime);
  2123.             }
  2124.             else
  2125.             {
  2126.                 if (skill.isPotion())
  2127.                     _potionCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 1), hitTime - 200);
  2128.                
  2129.                 else
  2130.                     _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 1), hitTime - 200);
  2131.             }
  2132.         }
  2133.         else
  2134.         {
  2135.             onMagicLaunchedTimer(targets, skill, coolTime, true);
  2136.         }
  2137.         fireEvent(EventType.CAST.name, new Object[]
  2138.         {
  2139.             skill,
  2140.             target,
  2141.             targets
  2142.         });
  2143.        
  2144.     }
  2145.    
  2146.     /**
  2147.      * Index according to skill id the current timestamp of use.<br>
  2148.      * @param skill the s
  2149.      * @param r the r
  2150.      */
  2151.     public void addTimeStamp(final L2Skill skill, final int r)
  2152.     {
  2153.        
  2154.     }
  2155.    
  2156.     /**
  2157.      * Index according to skill id the current timestamp of use.<br>
  2158.      * @param _skill the s
  2159.      */
  2160.     public void removeTimeStamp(final L2Skill _skill)
  2161.     {
  2162.        
  2163.     }
  2164.    
  2165.     /**
  2166.      * Starts a force buff on target.<br>
  2167.      * @param target the target
  2168.      * @param skill the skill
  2169.      */
  2170.     public void startForceBuff(final L2Character target, final L2Skill skill)
  2171.     {
  2172.         if (skill.getSkillType() != SkillType.FORCE_BUFF)
  2173.             return;
  2174.        
  2175.         if (_forceBuff == null)
  2176.         {
  2177.             _forceBuff = new ForceBuff(this, target, skill);
  2178.         }
  2179.     }
  2180.    
  2181.     /**
  2182.      * Kill the L2Character.<BR>
  2183.      * <BR>
  2184.      * <B><U> Actions</U> :</B><BR>
  2185.      * <BR>
  2186.      * <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
  2187.      * inform</li> <li>Notify L2Character AI</li><BR>
  2188.      * <BR>
  2189.      * <B><U> Overriden in </U> :</B><BR>
  2190.      * <BR>
  2191.      * <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>
  2192.      * <BR>
  2193.      * @param killer The L2Character who killed it
  2194.      * @return true, if successful
  2195.      */
  2196.     public boolean doDie(final L2Character killer)
  2197.     {
  2198.         // killing is only possible one time
  2199.         synchronized (this)
  2200.         {
  2201.             if (isKilledAlready())
  2202.                 return false;
  2203.            
  2204.             setIsKilledAlready(true);
  2205.         }
  2206.         // Set target to null and cancel Attack or Cast
  2207.         setTarget(null);
  2208.        
  2209.         // Stop fear to avoid possible bug with char position after death
  2210.         if (isAfraid())
  2211.             stopFear(null);
  2212.        
  2213.         // Stop movement
  2214.         stopMove(null);
  2215.        
  2216.         // Stop HP/MP/CP Regeneration task
  2217.         getStatus().stopHpMpRegeneration();
  2218.        
  2219.         // Stop all active skills effects in progress on the L2Character,
  2220.         // if the Character isn't affected by Soul of The Phoenix or Salvation
  2221.         if (this instanceof L2PlayableInstance && ((L2PlayableInstance) this).isPhoenixBlessed())
  2222.         {
  2223.             if (((L2PlayableInstance) this).isNoblesseBlessed())
  2224.             {
  2225.                 ((L2PlayableInstance) this).stopNoblesseBlessing(null);
  2226.             }
  2227.             if (((L2PlayableInstance) this).getCharmOfLuck())
  2228.             {
  2229.                 ((L2PlayableInstance) this).stopCharmOfLuck(null);
  2230.             }
  2231.         }
  2232.         // Same thing if the Character isn't a Noblesse Blessed L2PlayableInstance
  2233.         else if (this instanceof L2PlayableInstance && ((L2PlayableInstance) this).isNoblesseBlessed())
  2234.         {
  2235.             ((L2PlayableInstance) this).stopNoblesseBlessing(null);
  2236.            
  2237.             if (((L2PlayableInstance) this).getCharmOfLuck())
  2238.             {
  2239.                 ((L2PlayableInstance) this).stopCharmOfLuck(null);
  2240.             }
  2241.         }
  2242.         else
  2243.         {
  2244.             if (this instanceof L2PcInstance)
  2245.             {
  2246.                
  2247.                 final L2PcInstance player = (L2PcInstance) this;
  2248.                
  2249.                 // to avoid Event Remove buffs on die
  2250.                 if (player._inEventDM && DM.is_started())
  2251.                 {
  2252.                     if (Config.DM_REMOVE_BUFFS_ON_DIE)
  2253.                         stopAllEffects();
  2254.                 }
  2255.                 else if (player._inEventTvT && TvT.is_started())
  2256.                 {
  2257.                     if (Config.TVT_REMOVE_BUFFS_ON_DIE)
  2258.                         stopAllEffects();
  2259.                 }
  2260.                 else if (player._inEventCTF && CTF.is_started())
  2261.                 {
  2262.                     if (Config.CTF_REMOVE_BUFFS_ON_DIE)
  2263.                         stopAllEffects();
  2264.                 }
  2265.                 else if (Config.LEAVE_BUFFS_ON_DIE) // this means that the player is not in event
  2266.                 {
  2267.                     stopAllEffects();
  2268.                 }
  2269.             }
  2270.             else
  2271.             // this means all other characters, including Summons
  2272.             {
  2273.                 stopAllEffects();
  2274.             }
  2275.         }
  2276.        
  2277.         // if killer is the same then the most damager/hated
  2278.         L2Character mostHated = null;
  2279.         if (this instanceof L2Attackable)
  2280.         {
  2281.             mostHated = ((L2Attackable) this)._mostHated;
  2282.         }
  2283.        
  2284.         if (mostHated != null && isInsideRadius(mostHated, 200, false, false))
  2285.         {
  2286.             calculateRewards(mostHated);
  2287.         }
  2288.         else
  2289.         {
  2290.             calculateRewards(killer);
  2291.         }
  2292.        
  2293.         // Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  2294.         broadcastStatusUpdate();
  2295.        
  2296.         // Notify L2Character AI
  2297.         getAI().notifyEvent(CtrlEvent.EVT_DEAD, null);
  2298.        
  2299.         if (getWorldRegion() != null)
  2300.         {
  2301.             getWorldRegion().onDeath(this);
  2302.         }
  2303.        
  2304.         // Notify Quest of character's death
  2305.         for (final QuestState qs : getNotifyQuestOfDeath())
  2306.         {
  2307.             qs.getQuest().notifyDeath((killer == null ? this : killer), this, qs);
  2308.         }
  2309.        
  2310.         getNotifyQuestOfDeath().clear();
  2311.        
  2312.         getAttackByList().clear();
  2313.        
  2314.         // If character is PhoenixBlessed a resurrection popup will show up
  2315.         if (this instanceof L2PlayableInstance && ((L2PlayableInstance) this).isPhoenixBlessed())
  2316.         {
  2317.             ((L2PcInstance) this).reviveRequest(((L2PcInstance) this), null, false);
  2318.         }
  2319.         fireEvent(EventType.DIE.name, new Object[]
  2320.         {
  2321.             killer
  2322.         });
  2323.        
  2324.         // Update active skills in progress (In Use and Not In Use because stacked) icones on client
  2325.         updateEffectIcons();
  2326.        
  2327.         // After dead mob check if the killer got a moving task actived
  2328.         if (killer instanceof L2PcInstance)
  2329.         {
  2330.             if (((L2PcInstance) killer).isMovingTaskDefined())
  2331.             {
  2332.                 ((L2PcInstance) killer).startMovingTask();
  2333.             }
  2334.         }
  2335.        
  2336.         return true;
  2337.     }
  2338.    
  2339.     /**
  2340.      * Calculate rewards.
  2341.      * @param killer the killer
  2342.      */
  2343.     protected void calculateRewards(final L2Character killer)
  2344.     {
  2345.     }
  2346.    
  2347.     /** Sets HP, MP and CP and revives the L2Character. */
  2348.     public void doRevive()
  2349.     {
  2350.         if (!isTeleporting())
  2351.         {
  2352.             setIsPendingRevive(false);
  2353.            
  2354.             if (this instanceof L2PlayableInstance && ((L2PlayableInstance) this).isPhoenixBlessed())
  2355.             {
  2356.                 ((L2PlayableInstance) this).stopPhoenixBlessing(null);
  2357.                
  2358.                 // Like L2OFF Soul of The Phoenix and Salvation restore all hp,cp,mp.
  2359.                 _status.setCurrentCp(getMaxCp());
  2360.                 _status.setCurrentHp(getMaxHp());
  2361.                 _status.setCurrentMp(getMaxMp());
  2362.             }
  2363.             else
  2364.             {
  2365.                 _status.setCurrentCp(getMaxCp() * Config.RESPAWN_RESTORE_CP);
  2366.                 _status.setCurrentHp(getMaxHp() * Config.RESPAWN_RESTORE_HP);
  2367.             }
  2368.         }
  2369.         // Start broadcast status
  2370.         broadcastPacket(new Revive(this));
  2371.        
  2372.         if (getWorldRegion() != null)
  2373.         {
  2374.             getWorldRegion().onRevive(this);
  2375.         }
  2376.         else
  2377.         {
  2378.             setIsPendingRevive(true);
  2379.         }
  2380.         fireEvent(EventType.REVIVE.name, (Object[]) null);
  2381.     }
  2382.    
  2383.     /**
  2384.      * Revives the L2Character using skill.
  2385.      * @param revivePower the revive power
  2386.      */
  2387.     public void doRevive(final double revivePower)
  2388.     {
  2389.         doRevive();
  2390.     }
  2391.    
  2392.     /**
  2393.      * Check if the active L2Skill can be casted.<BR>
  2394.      * <BR>
  2395.      * <B><U> Actions</U> :</B><BR>
  2396.      * <BR>
  2397.      * <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>
  2398.      * <BR>
  2399.      * @param skill The L2Skill to use
  2400.      */
  2401.     protected void useMagic(final L2Skill skill)
  2402.     {
  2403.         if (skill == null || isDead())
  2404.             return;
  2405.        
  2406.         // Check if the L2Character can cast
  2407.         if (!skill.isPotion() && isAllSkillsDisabled())
  2408.             // must be checked by caller
  2409.             return;
  2410.        
  2411.         // Ignore the passive skill request. why does the client send it anyway ??
  2412.         if (skill.isPassive() || skill.isChance())
  2413.             return;
  2414.        
  2415.         // Get the target for the skill
  2416.         L2Object target = null;
  2417.        
  2418.         switch (skill.getTargetType())
  2419.         {
  2420.             case TARGET_AURA: // AURA, SELF should be cast even if no target has been found
  2421.             case TARGET_SELF:
  2422.                 target = this;
  2423.                 break;
  2424.             default:
  2425.                 // Get the first target of the list
  2426.                 target = skill.getFirstOfTargetList(this);
  2427.                 break;
  2428.         }
  2429.        
  2430.         // Notify the AI with AI_INTENTION_CAST and target
  2431.         getAI().setIntention(CtrlIntention.AI_INTENTION_CAST, skill, target);
  2432.         target = null;
  2433.     }
  2434.    
  2435.     // =========================================================
  2436.     // Property - Public
  2437.     /**
  2438.      * Return the L2CharacterAI of the L2Character and if its null create a new one.
  2439.      * @return the aI
  2440.      */
  2441.     public L2CharacterAI getAI()
  2442.     {
  2443.         if (_ai == null)
  2444.         {
  2445.             synchronized (this)
  2446.             {
  2447.                 if (_ai == null)
  2448.                 {
  2449.                     _ai = new L2CharacterAI(new AIAccessor());
  2450.                 }
  2451.             }
  2452.         }
  2453.        
  2454.         return _ai;
  2455.     }
  2456.    
  2457.     /**
  2458.      * Sets the aI.
  2459.      * @param newAI the new aI
  2460.      */
  2461.     public void setAI(final L2CharacterAI newAI)
  2462.     {
  2463.         L2CharacterAI oldAI = getAI();
  2464.        
  2465.         if (oldAI != null && oldAI != newAI && oldAI instanceof L2AttackableAI)
  2466.         {
  2467.             ((L2AttackableAI) oldAI).stopAITask();
  2468.         }
  2469.         _ai = newAI;
  2470.        
  2471.         oldAI = null;
  2472.     }
  2473.    
  2474.     /**
  2475.      * Return True if the L2Character has a L2CharacterAI.
  2476.      * @return true, if successful
  2477.      */
  2478.     public boolean hasAI()
  2479.     {
  2480.         return _ai != null;
  2481.     }
  2482.    
  2483.     /**
  2484.      * Return True if the L2Character is RaidBoss or his minion.
  2485.      * @return true, if is raid
  2486.      */
  2487.     @Override
  2488.     public boolean isRaid()
  2489.     {
  2490.         return false;
  2491.     }
  2492.    
  2493.     /**
  2494.      * Return True if the L2Character is an Npc.
  2495.      * @return true, if is npc
  2496.      */
  2497.     @Override
  2498.     public boolean isNpc()
  2499.     {
  2500.         return false;
  2501.     }
  2502.    
  2503.     /**
  2504.      * Return a list of L2Character that attacked.
  2505.      * @return the attack by list
  2506.      */
  2507.     public final List<L2Character> getAttackByList()
  2508.     {
  2509.         if (_attackByList == null)
  2510.         {
  2511.             _attackByList = new FastList<>();
  2512.         }
  2513.        
  2514.         return _attackByList;
  2515.     }
  2516.    
  2517.     /**
  2518.      * Gets the last skill cast.
  2519.      * @return the last skill cast
  2520.      */
  2521.     public final L2Skill getLastSkillCast()
  2522.     {
  2523.         return _lastSkillCast;
  2524.     }
  2525.    
  2526.     /**
  2527.      * Sets the last skill cast.
  2528.      * @param skill the new last skill cast
  2529.      */
  2530.     public void setLastSkillCast(final L2Skill skill)
  2531.     {
  2532.         _lastSkillCast = skill;
  2533.     }
  2534.    
  2535.     /**
  2536.      * Gets the last potion cast.
  2537.      * @return the last potion cast
  2538.      */
  2539.     public final L2Skill getLastPotionCast()
  2540.     {
  2541.         return _lastPotionCast;
  2542.     }
  2543.    
  2544.     /**
  2545.      * Sets the last potion cast.
  2546.      * @param skill the new last potion cast
  2547.      */
  2548.     public void setLastPotionCast(final L2Skill skill)
  2549.     {
  2550.         _lastPotionCast = skill;
  2551.     }
  2552.    
  2553.     /**
  2554.      * Checks if is afraid.
  2555.      * @return true, if is afraid
  2556.      */
  2557.     public final boolean isAfraid()
  2558.     {
  2559.         return _isAfraid;
  2560.     }
  2561.    
  2562.     /**
  2563.      * Sets the checks if is afraid.
  2564.      * @param value the new checks if is afraid
  2565.      */
  2566.     public final void setIsAfraid(final boolean value)
  2567.     {
  2568.         _isAfraid = value;
  2569.     }
  2570.    
  2571.     /**
  2572.      * Return True if the L2Character is dead or use fake death.
  2573.      * @return true, if is alike dead
  2574.      */
  2575.     public final boolean isAlikeDead()
  2576.     {
  2577.         return isFakeDeath() || !(getCurrentHp() > 0.01);
  2578.     }
  2579.    
  2580.     /**
  2581.      * Return True if the L2Character can't use its skills (ex : stun, sleep...).
  2582.      * @return true, if is all skills disabled
  2583.      */
  2584.     public final boolean isAllSkillsDisabled()
  2585.     {
  2586.         return _allSkillsDisabled || isImmobileUntilAttacked() || isStunned() || isSleeping() || isParalyzed();
  2587.     }
  2588.    
  2589.     /**
  2590.      * Return True if the L2Character can't attack (stun, sleep, attackEndTime, fakeDeath, paralyse).
  2591.      * @return true, if is attacking disabled
  2592.      */
  2593.     public boolean isAttackingDisabled()
  2594.     {
  2595.         return isImmobileUntilAttacked() || isStunned() || isSleeping() || isFallsdown() || _attackEndTime > GameTimeController.getGameTicks() || isFakeDeath() || isParalyzed() || isAttackDisabled();
  2596.     }
  2597.    
  2598.     /**
  2599.      * Gets the calculators.
  2600.      * @return the calculators
  2601.      */
  2602.     public final Calculator[] getCalculators()
  2603.     {
  2604.         return _calculators;
  2605.     }
  2606.    
  2607.     /**
  2608.      * Checks if is confused.
  2609.      * @return true, if is confused
  2610.      */
  2611.     public final boolean isConfused()
  2612.     {
  2613.         return _isConfused;
  2614.     }
  2615.    
  2616.     /**
  2617.      * Sets the checks if is confused.
  2618.      * @param value the new checks if is confused
  2619.      */
  2620.     public final void setIsConfused(final boolean value)
  2621.     {
  2622.         _isConfused = value;
  2623.     }
  2624.    
  2625.     /**
  2626.      * Return True if the L2Character is dead.
  2627.      * @return true, if is dead
  2628.      */
  2629.     public final boolean isDead()
  2630.     {
  2631.         return !isFakeDeath() && (getCurrentHp() < 0.5);
  2632.     }
  2633.    
  2634.     /**
  2635.      * Checks if is fake death.
  2636.      * @return true, if is fake death
  2637.      */
  2638.     public final boolean isFakeDeath()
  2639.     {
  2640.         return _isFakeDeath;
  2641.     }
  2642.    
  2643.     /**
  2644.      * Sets the checks if is fake death.
  2645.      * @param value the new checks if is fake death
  2646.      */
  2647.     public final void setIsFakeDeath(final boolean value)
  2648.     {
  2649.         _isFakeDeath = value;
  2650.     }
  2651.    
  2652.     /**
  2653.      * Return True if the L2Character is flying.
  2654.      * @return true, if is flying
  2655.      */
  2656.     public final boolean isFlying()
  2657.     {
  2658.         return _isFlying;
  2659.     }
  2660.    
  2661.     /**
  2662.      * Set the L2Character flying mode to True.
  2663.      * @param mode the new checks if is flying
  2664.      */
  2665.     public final void setIsFlying(final boolean mode)
  2666.     {
  2667.         _isFlying = mode;
  2668.     }
  2669.    
  2670.     /**
  2671.      * Checks if is fallsdown.
  2672.      * @return true, if is fallsdown
  2673.      */
  2674.     public final boolean isFallsdown()
  2675.     {
  2676.         return _isFallsdown;
  2677.     }
  2678.    
  2679.     /**
  2680.      * Sets the checks if is fallsdown.
  2681.      * @param value the new checks if is fallsdown
  2682.      */
  2683.     public final void setIsFallsdown(final boolean value)
  2684.     {
  2685.         _isFallsdown = value;
  2686.     }
  2687.    
  2688.     /**
  2689.      * Checks if is imobilised.
  2690.      * @return true, if is imobilised
  2691.      */
  2692.     public boolean isImobilised()
  2693.     {
  2694.         return _isImmobilized > 0;
  2695.     }
  2696.    
  2697.     /**
  2698.      * Sets the checks if is imobilised.
  2699.      * @param value the new checks if is imobilised
  2700.      */
  2701.     public void setIsImobilised(final boolean value)
  2702.     {
  2703.         // Stop this if he is moving
  2704.         this.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  2705.        
  2706.         if (value)
  2707.         {
  2708.             _isImmobilized++;
  2709.         }
  2710.         else
  2711.         {
  2712.             _isImmobilized--;
  2713.         }
  2714.     }
  2715.    
  2716.     /**
  2717.      * Checks if is block buff.
  2718.      * @return the _isBlockBuff
  2719.      */
  2720.     public boolean isBlockBuff()
  2721.     {
  2722.         return _isBlockBuff;
  2723.     }
  2724.    
  2725.     /**
  2726.      * Sets the block buff.
  2727.      * @param blockBuff the _isBlockBuff to set
  2728.      */
  2729.     public void setBlockBuff(final boolean blockBuff)
  2730.     {
  2731.         _isBlockBuff = blockBuff;
  2732.     }
  2733.    
  2734.     /**
  2735.      * Checks if is block debuff.
  2736.      * @return the _isBlockDebuff
  2737.      */
  2738.     public boolean isBlockDebuff()
  2739.     {
  2740.         return _isBlockDebuff;
  2741.     }
  2742.    
  2743.     /**
  2744.      * Sets the block debuff.
  2745.      * @param blockDebuff the _isBlockDebuff to set
  2746.      */
  2747.     public void setBlockDebuff(final boolean blockDebuff)
  2748.     {
  2749.         _isBlockDebuff = blockDebuff;
  2750.     }
  2751.    
  2752.     /**
  2753.      * Checks if is killed already.
  2754.      * @return true, if is killed already
  2755.      */
  2756.     public final boolean isKilledAlready()
  2757.     {
  2758.         return _isKilledAlready;
  2759.     }
  2760.    
  2761.     /**
  2762.      * Sets the checks if is killed already.
  2763.      * @param value the new checks if is killed already
  2764.      */
  2765.     public final void setIsKilledAlready(final boolean value)
  2766.     {
  2767.         _isKilledAlready = value;
  2768.     }
  2769.    
  2770.     /**
  2771.      * Checks if is muted.
  2772.      * @return true, if is muted
  2773.      */
  2774.     public final boolean isMuted()
  2775.     {
  2776.         return _isMuted;
  2777.     }
  2778.    
  2779.     /**
  2780.      * Sets the checks if is muted.
  2781.      * @param value the new checks if is muted
  2782.      */
  2783.     public final void setIsMuted(final boolean value)
  2784.     {
  2785.         _isMuted = value;
  2786.     }
  2787.    
  2788.     /**
  2789.      * Checks if is psychical muted.
  2790.      * @return true, if is psychical muted
  2791.      */
  2792.     public final boolean isPsychicalMuted()
  2793.     {
  2794.         return _isPsychicalMuted;
  2795.     }
  2796.    
  2797.     /**
  2798.      * Sets the checks if is psychical muted.
  2799.      * @param value the new checks if is psychical muted
  2800.      */
  2801.     public final void setIsPsychicalMuted(final boolean value)
  2802.     {
  2803.         _isPsychicalMuted = value;
  2804.     }
  2805.    
  2806.     /**
  2807.      * Return True if the L2Character can't move (stun, root, sleep, overload, paralyzed).
  2808.      * @return true, if is movement disabled
  2809.      */
  2810.     public boolean isMovementDisabled()
  2811.     {
  2812.         return isImmobileUntilAttacked() || isStunned() || isRooted() || isSleeping() || isOverloaded() || isParalyzed() || isImobilised() || isFakeDeath() || isFallsdown();
  2813.     }
  2814.    
  2815.     /**
  2816.      * Return True if the L2Character can be controlled by the player (confused, afraid).
  2817.      * @return true, if is out of control
  2818.      */
  2819.     public final boolean isOutOfControl()
  2820.     {
  2821.         return isConfused() || isAfraid() || isBlocked();
  2822.     }
  2823.    
  2824.     /**
  2825.      * Checks if is overloaded.
  2826.      * @return true, if is overloaded
  2827.      */
  2828.     public final boolean isOverloaded()
  2829.     {
  2830.         return _isOverloaded;
  2831.     }
  2832.    
  2833.     /**
  2834.      * Set the overloaded status of the L2Character is overloaded (if True, the L2PcInstance can't take more item).
  2835.      * @param value the new checks if is overloaded
  2836.      */
  2837.     public final void setIsOverloaded(final boolean value)
  2838.     {
  2839.         _isOverloaded = value;
  2840.     }
  2841.    
  2842.     /**
  2843.      * Checks if is paralyzed.
  2844.      * @return true, if is paralyzed
  2845.      */
  2846.     public final boolean isParalyzed()
  2847.     {
  2848.         return _isParalyzed;
  2849.     }
  2850.    
  2851.     /**
  2852.      * Sets the checks if is paralyzed.
  2853.      * @param value the new checks if is paralyzed
  2854.      */
  2855.     public final void setIsParalyzed(final boolean value)
  2856.     {
  2857.         if (_petrified)
  2858.             return;
  2859.         _isParalyzed = value;
  2860.     }
  2861.    
  2862.     /**
  2863.      * Checks if is pending revive.
  2864.      * @return true, if is pending revive
  2865.      */
  2866.     public final boolean isPendingRevive()
  2867.     {
  2868.         return isDead() && _isPendingRevive;
  2869.     }
  2870.    
  2871.     /**
  2872.      * Sets the checks if is pending revive.
  2873.      * @param value the new checks if is pending revive
  2874.      */
  2875.     public final void setIsPendingRevive(final boolean value)
  2876.     {
  2877.         _isPendingRevive = value;
  2878.     }
  2879.    
  2880.     /**
  2881.      * Return the L2Summon of the L2Character.<BR>
  2882.      * <BR>
  2883.      * <B><U> Overriden in </U> :</B><BR>
  2884.      * <BR>
  2885.      * <li>L2PcInstance</li><BR>
  2886.      * <BR>
  2887.      * @return the pet
  2888.      */
  2889.     public L2Summon getPet()
  2890.     {
  2891.         return null;
  2892.     }
  2893.    
  2894.     /**
  2895.      * Return True if the L2Character is ridding.
  2896.      * @return true, if is riding
  2897.      */
  2898.     public final boolean isRiding()
  2899.     {
  2900.         return _isRiding;
  2901.     }
  2902.    
  2903.     /**
  2904.      * Set the L2Character riding mode to True.
  2905.      * @param mode the new checks if is riding
  2906.      */
  2907.     public final void setIsRiding(final boolean mode)
  2908.     {
  2909.         _isRiding = mode;
  2910.     }
  2911.    
  2912.     /**
  2913.      * Checks if is rooted.
  2914.      * @return true, if is rooted
  2915.      */
  2916.     public final boolean isRooted()
  2917.     {
  2918.         return _isRooted;
  2919.     }
  2920.    
  2921.     /**
  2922.      * Sets the checks if is rooted.
  2923.      * @param value the new checks if is rooted
  2924.      */
  2925.     public final void setIsRooted(final boolean value)
  2926.     {
  2927.         _isRooted = value;
  2928.     }
  2929.    
  2930.     /**
  2931.      * Return True if the L2Character is running.
  2932.      * @return true, if is running
  2933.      */
  2934.     public final boolean isRunning()
  2935.     {
  2936.         return _isRunning;
  2937.     }
  2938.    
  2939.     /**
  2940.      * Sets the checks if is running.
  2941.      * @param value the new checks if is running
  2942.      */
  2943.     public final void setIsRunning(final boolean value)
  2944.     {
  2945.         _isRunning = value;
  2946.         broadcastPacket(new ChangeMoveType(this));
  2947.     }
  2948.    
  2949.     /**
  2950.      * Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance.
  2951.      */
  2952.     public final void setRunning()
  2953.     {
  2954.         if (!isRunning())
  2955.         {
  2956.             setIsRunning(true);
  2957.         }
  2958.     }
  2959.    
  2960.     /**
  2961.      * Checks if is immobile until attacked.
  2962.      * @return true, if is immobile until attacked
  2963.      */
  2964.     public final boolean isImmobileUntilAttacked()
  2965.     {
  2966.         return _isImmobileUntilAttacked;
  2967.     }
  2968.    
  2969.     /**
  2970.      * Sets the checks if is immobile until attacked.
  2971.      * @param value the new checks if is immobile until attacked
  2972.      */
  2973.     public final void setIsImmobileUntilAttacked(final boolean value)
  2974.     {
  2975.         _isImmobileUntilAttacked = value;
  2976.     }
  2977.    
  2978.     /**
  2979.      * Checks if is sleeping.
  2980.      * @return true, if is sleeping
  2981.      */
  2982.     public final boolean isSleeping()
  2983.     {
  2984.         return _isSleeping;
  2985.     }
  2986.    
  2987.     /**
  2988.      * Sets the checks if is sleeping.
  2989.      * @param value the new checks if is sleeping
  2990.      */
  2991.     public final void setIsSleeping(final boolean value)
  2992.     {
  2993.         _isSleeping = value;
  2994.     }
  2995.    
  2996.     /**
  2997.      * Checks if is stunned.
  2998.      * @return true, if is stunned
  2999.      */
  3000.     public final boolean isStunned()
  3001.     {
  3002.         return _isStunned;
  3003.     }
  3004.    
  3005.     /**
  3006.      * Sets the checks if is stunned.
  3007.      * @param value the new checks if is stunned
  3008.      */
  3009.     public final void setIsStunned(final boolean value)
  3010.     {
  3011.         _isStunned = value;
  3012.     }
  3013.    
  3014.     /**
  3015.      * Checks if is betrayed.
  3016.      * @return true, if is betrayed
  3017.      */
  3018.     public final boolean isBetrayed()
  3019.     {
  3020.         return _isBetrayed;
  3021.     }
  3022.    
  3023.     /**
  3024.      * Sets the checks if is betrayed.
  3025.      * @param value the new checks if is betrayed
  3026.      */
  3027.     public final void setIsBetrayed(final boolean value)
  3028.     {
  3029.         _isBetrayed = value;
  3030.     }
  3031.    
  3032.     /**
  3033.      * Checks if is teleporting.
  3034.      * @return true, if is teleporting
  3035.      */
  3036.     public final boolean isTeleporting()
  3037.     {
  3038.         return _isTeleporting;
  3039.     }
  3040.    
  3041.     /**
  3042.      * Sets the checks if is teleporting.
  3043.      * @param value the new checks if is teleporting
  3044.      */
  3045.     public void setIsTeleporting(final boolean value)
  3046.     {
  3047.         _isTeleporting = value;
  3048.     }
  3049.    
  3050.     /**
  3051.      * Sets the checks if is invul.
  3052.      * @param b the new checks if is invul
  3053.      */
  3054.     public void setIsInvul(final boolean b)
  3055.     {
  3056.         if (_petrified)
  3057.             return;
  3058.        
  3059.         _isInvul = b;
  3060.     }
  3061.    
  3062.     /**
  3063.      * Checks if is invul.
  3064.      * @return true, if is invul
  3065.      */
  3066.     public boolean isInvul()
  3067.     {
  3068.         return _isInvul || _isTeleporting;
  3069.     }
  3070.    
  3071.     /**
  3072.      * Checks if is undead.
  3073.      * @return true, if is undead
  3074.      */
  3075.     public boolean isUndead()
  3076.     {
  3077.         return _template.isUndead;
  3078.     }
  3079.    
  3080.     /*
  3081.      * (non-Javadoc)
  3082.      * @see com.l2jlegacy.gameserver.model.L2Object#getKnownList()
  3083.      */
  3084.     @Override
  3085.     public CharKnownList getKnownList()
  3086.     {
  3087.         if (super.getKnownList() == null || !(super.getKnownList() instanceof CharKnownList))
  3088.         {
  3089.             setKnownList(new CharKnownList(this));
  3090.         }
  3091.        
  3092.         return (CharKnownList) super.getKnownList();
  3093.     }
  3094.    
  3095.     /**
  3096.      * Gets the stat.
  3097.      * @return the stat
  3098.      */
  3099.     public CharStat getStat()
  3100.     {
  3101.         if (_stat == null)
  3102.         {
  3103.             _stat = new CharStat(this);
  3104.         }
  3105.        
  3106.         return _stat;
  3107.     }
  3108.    
  3109.     /**
  3110.      * Sets the stat.
  3111.      * @param value the new stat
  3112.      */
  3113.     public final void setStat(final CharStat value)
  3114.     {
  3115.         _stat = value;
  3116.     }
  3117.    
  3118.     /**
  3119.      * Gets the status.
  3120.      * @return the status
  3121.      */
  3122.     public CharStatus getStatus()
  3123.     {
  3124.         if (_status == null)
  3125.         {
  3126.             _status = new CharStatus(this);
  3127.         }
  3128.        
  3129.         return _status;
  3130.     }
  3131.    
  3132.     /**
  3133.      * Sets the status.
  3134.      * @param value the new status
  3135.      */
  3136.     public final void setStatus(final CharStatus value)
  3137.     {
  3138.         _status = value;
  3139.     }
  3140.    
  3141.     /**
  3142.      * Gets the template.
  3143.      * @return the template
  3144.      */
  3145.     public L2CharTemplate getTemplate()
  3146.     {
  3147.         return _template;
  3148.     }
  3149.    
  3150.     /**
  3151.      * Set the template of the L2Character.<BR>
  3152.      * <BR>
  3153.      * <B><U> Concept</U> :</B><BR>
  3154.      * <BR>
  3155.      * 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
  3156.      * L2Character is spawned, server just create a link between the instance and the template This link is stored in <B>_template</B><BR>
  3157.      * <BR>
  3158.      * <B><U> Assert </U> :</B><BR>
  3159.      * <BR>
  3160.      * <li>this instanceof L2Character</li><BR>
  3161.      * <BR
  3162.      * @param template the new template
  3163.      */
  3164.     protected synchronized final void setTemplate(final L2CharTemplate template)
  3165.     {
  3166.         _template = template;
  3167.     }
  3168.    
  3169.     /**
  3170.      * Return the Title of the L2Character.
  3171.      * @return the title
  3172.      */
  3173.     public final String getTitle()
  3174.     {
  3175.         if (_title == null)
  3176.             return "";
  3177.        
  3178.         return _title;
  3179.     }
  3180.    
  3181.     /**
  3182.      * Set the Title of the L2Character.
  3183.      * @param value the new title
  3184.      */
  3185.     public final void setTitle(String value)
  3186.     {
  3187.         if (value == null)
  3188.             value = "";
  3189.        
  3190.         if (this instanceof L2PcInstance && value.length() > 16)
  3191.         {
  3192.             value = value.substring(0, 15);
  3193.         }
  3194.        
  3195.         _title = value; // public final void setTitle(String value) { _title = value; }
  3196.     }
  3197.    
  3198.     /**
  3199.      * Set the L2Character movement type to walk and send Server->Client packet ChangeMoveType to all others L2PcInstance.
  3200.      */
  3201.     public final void setWalking()
  3202.     {
  3203.         if (isRunning())
  3204.         {
  3205.             setIsRunning(false);
  3206.         }
  3207.     }
  3208.    
  3209.     /**
  3210.      * Task lauching the function enableSkill().
  3211.      */
  3212.     class EnableSkill implements Runnable
  3213.     {
  3214.        
  3215.         /** The _skill id. */
  3216.         L2Skill _skillId;
  3217.        
  3218.         /**
  3219.          * Instantiates a new enable skill.
  3220.          * @param skill the skill
  3221.          */
  3222.         public EnableSkill(final L2Skill skill)
  3223.         {
  3224.             _skillId = skill;
  3225.         }
  3226.        
  3227.         /*
  3228.          * (non-Javadoc)
  3229.          * @see java.lang.Runnable#run()
  3230.          */
  3231.         @Override
  3232.         public void run()
  3233.         {
  3234.             try
  3235.             {
  3236.                 enableSkill(_skillId);
  3237.             }
  3238.             catch (final Throwable e)
  3239.             {
  3240.                 LOGGER.error("", e);
  3241.             }
  3242.         }
  3243.     }
  3244.    
  3245.     /**
  3246.      * Task lauching the function onHitTimer().<BR>
  3247.      * <BR>
  3248.      * <B><U> Actions</U> :</B><BR>
  3249.      * <BR>
  3250.      * <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>
  3251.      * <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>
  3252.      * <BR>
  3253.      */
  3254.     class HitTask implements Runnable
  3255.     {
  3256.        
  3257.         /** The _hit target. */
  3258.         L2Character _hitTarget;
  3259.        
  3260.         /** The _damage. */
  3261.         int _damage;
  3262.        
  3263.         /** The _crit. */
  3264.         boolean _crit;
  3265.        
  3266.         /** The _miss. */
  3267.         boolean _miss;
  3268.        
  3269.         /** The _shld. */
  3270.         boolean _shld;
  3271.        
  3272.         /** The _soulshot. */
  3273.         boolean _soulshot;
  3274.        
  3275.         /**
  3276.          * Instantiates a new hit task.
  3277.          * @param target the target
  3278.          * @param damage the damage
  3279.          * @param crit the crit
  3280.          * @param miss the miss
  3281.          * @param soulshot the soulshot
  3282.          * @param shld the shld
  3283.          */
  3284.         public HitTask(final L2Character target, final int damage, final boolean crit, final boolean miss, final boolean soulshot, final boolean shld)
  3285.         {
  3286.             _hitTarget = target;
  3287.             _damage = damage;
  3288.             _crit = crit;
  3289.             _shld = shld;
  3290.             _miss = miss;
  3291.             _soulshot = soulshot;
  3292.         }
  3293.        
  3294.         /*
  3295.          * (non-Javadoc)
  3296.          * @see java.lang.Runnable#run()
  3297.          */
  3298.         @Override
  3299.         public void run()
  3300.         {
  3301.             try
  3302.             {
  3303.                 onHitTimer(_hitTarget, _damage, _crit, _miss, _soulshot, _shld);
  3304.             }
  3305.             catch (final Throwable e)
  3306.             {
  3307.                 LOGGER.error("fixme:hit task unhandled exception", e);
  3308.             }
  3309.         }
  3310.     }
  3311.    
  3312.     /**
  3313.      * Task lauching the magic skill phases.
  3314.      */
  3315.     class MagicUseTask implements Runnable
  3316.     {
  3317.        
  3318.         /** The _targets. */
  3319.         L2Object[] _targets;
  3320.        
  3321.         /** The _skill. */
  3322.         L2Skill _skill;
  3323.        
  3324.         /** The _cool time. */
  3325.         int _coolTime;
  3326.        
  3327.         /** The _phase. */
  3328.         int _phase;
  3329.        
  3330.         /**
  3331.          * Instantiates a new magic use task.
  3332.          * @param targets the targets
  3333.          * @param skill the skill
  3334.          * @param coolTime the cool time
  3335.          * @param phase the phase
  3336.          */
  3337.         public MagicUseTask(final L2Object[] targets, final L2Skill skill, final int coolTime, final int phase)
  3338.         {
  3339.             _targets = targets;
  3340.             _skill = skill;
  3341.             _coolTime = coolTime;
  3342.             _phase = phase;
  3343.         }
  3344.        
  3345.         /*
  3346.          * (non-Javadoc)
  3347.          * @see java.lang.Runnable#run()
  3348.          */
  3349.         @Override
  3350.         public void run()
  3351.         {
  3352.             try
  3353.             {
  3354.                 switch (_phase)
  3355.                 {
  3356.                     case 1:
  3357.                         onMagicLaunchedTimer(_targets, _skill, _coolTime, false);
  3358.                         break;
  3359.                     case 2:
  3360.                         onMagicHitTimer(_targets, _skill, _coolTime, false);
  3361.                         break;
  3362.                     case 3:
  3363.                         onMagicFinalizer(_targets, _skill);
  3364.                         break;
  3365.                     default:
  3366.                         break;
  3367.                 }
  3368.             }
  3369.             catch (final Throwable e)
  3370.             {
  3371.                 LOGGER.error("", e);
  3372.                 e.printStackTrace();
  3373.                 enableAllSkills();
  3374.             }
  3375.         }
  3376.     }
  3377.    
  3378.     /**
  3379.      * Task lauching the function useMagic().
  3380.      */
  3381.     class QueuedMagicUseTask implements Runnable
  3382.     {
  3383.        
  3384.         /** The _curr player. */
  3385.         L2PcInstance _currPlayer;
  3386.        
  3387.         /** The _queued skill. */
  3388.         L2Skill _queuedSkill;
  3389.        
  3390.         /** The _is ctrl pressed. */
  3391.         boolean _isCtrlPressed;
  3392.        
  3393.         /** The _is shift pressed. */
  3394.         boolean _isShiftPressed;
  3395.        
  3396.         /**
  3397.          * Instantiates a new queued magic use task.
  3398.          * @param currPlayer the curr player
  3399.          * @param queuedSkill the queued skill
  3400.          * @param isCtrlPressed the is ctrl pressed
  3401.          * @param isShiftPressed the is shift pressed
  3402.          */
  3403.         public QueuedMagicUseTask(final L2PcInstance currPlayer, final L2Skill queuedSkill, final boolean isCtrlPressed, final boolean isShiftPressed)
  3404.         {
  3405.             _currPlayer = currPlayer;
  3406.             _queuedSkill = queuedSkill;
  3407.             _isCtrlPressed = isCtrlPressed;
  3408.             _isShiftPressed = isShiftPressed;
  3409.         }
  3410.        
  3411.         /*
  3412.          * (non-Javadoc)
  3413.          * @see java.lang.Runnable#run()
  3414.          */
  3415.         @Override
  3416.         public void run()
  3417.         {
  3418.             try
  3419.             {
  3420.                 _currPlayer.useMagic(_queuedSkill, _isCtrlPressed, _isShiftPressed);
  3421.             }
  3422.             catch (final Throwable e)
  3423.             {
  3424.                 LOGGER.error("", e);
  3425.             }
  3426.         }
  3427.     }
  3428.    
  3429.     /**
  3430.      * Task of AI notification.
  3431.      */
  3432.     public class NotifyAITask implements Runnable
  3433.     {
  3434.        
  3435.         /** The _evt. */
  3436.         private final CtrlEvent _evt;
  3437.        
  3438.         /**
  3439.          * Instantiates a new notify ai task.
  3440.          * @param evt the evt
  3441.          */
  3442.         NotifyAITask(final CtrlEvent evt)
  3443.         {
  3444.             _evt = evt;
  3445.         }
  3446.        
  3447.         /*
  3448.          * (non-Javadoc)
  3449.          * @see java.lang.Runnable#run()
  3450.          */
  3451.         @Override
  3452.         public void run()
  3453.         {
  3454.             try
  3455.             {
  3456.                 getAI().notifyEvent(_evt, null);
  3457.             }
  3458.             catch (final Throwable t)
  3459.             {
  3460.                 LOGGER.warn("", t);
  3461.             }
  3462.         }
  3463.     }
  3464.    
  3465.     /**
  3466.      * Task lauching the function stopPvPFlag().
  3467.      */
  3468.     class PvPFlag implements Runnable
  3469.     {
  3470.        
  3471.         /**
  3472.          * Instantiates a new pvp flag.
  3473.          */
  3474.         public PvPFlag()
  3475.         {
  3476.             // null
  3477.         }
  3478.        
  3479.         /*
  3480.          * (non-Javadoc)
  3481.          * @see java.lang.Runnable#run()
  3482.          */
  3483.         @Override
  3484.         public void run()
  3485.         {
  3486.             try
  3487.             {
  3488.                 // LOGGER.fine("Checking pvp time: " + getlastPvpAttack());
  3489.                 // "lastattack: " _lastAttackTime "currenttime: "
  3490.                 // System.currentTimeMillis());
  3491.                 if (System.currentTimeMillis() > getPvpFlagLasts())
  3492.                 {
  3493.                     // LOGGER.fine("Stopping PvP");
  3494.                     stopPvPFlag();
  3495.                 }
  3496.                 else if (System.currentTimeMillis() > getPvpFlagLasts() - 5000)
  3497.                 {
  3498.                     updatePvPFlag(2);
  3499.                 }
  3500.                 else
  3501.                 {
  3502.                     updatePvPFlag(1);
  3503.                     // Start a new PvP timer check
  3504.                     // checkPvPFlag();
  3505.                 }
  3506.             }
  3507.             catch (final Exception e)
  3508.             {
  3509.                 LOGGER.warn("error in pvp flag task:", e);
  3510.             }
  3511.         }
  3512.     }
  3513.    
  3514.     // =========================================================
  3515.    
  3516.     // =========================================================
  3517.     // Abnormal Effect - NEED TO REMOVE ONCE L2CHARABNORMALEFFECT IS COMPLETE
  3518.     // Data Field
  3519.     /** Map 32 bits (0x0000) containing all abnormal effect in progress. */
  3520.     private int _AbnormalEffects;
  3521.    
  3522.     /**
  3523.      * FastTable containing all active skills effects in progress of a L2Character.
  3524.      */
  3525.     private final FastTable<L2Effect> _effects = new FastTable<>();
  3526.    
  3527.     /** The table containing the List of all stacked effect in progress for each Stack group Identifier. */
  3528.     protected Map<String, List<L2Effect>> _stackedEffects = new FastMap<>();
  3529.    
  3530.     /** The Constant ABNORMAL_EFFECT_BLEEDING. */
  3531.     public static final int ABNORMAL_EFFECT_BLEEDING = 0x000001;
  3532.    
  3533.     /** The Constant ABNORMAL_EFFECT_POISON. */
  3534.     public static final int ABNORMAL_EFFECT_POISON = 0x000002;
  3535.    
  3536.     /** The Constant ABNORMAL_EFFECT_REDCIRCLE. */
  3537.     public static final int ABNORMAL_EFFECT_REDCIRCLE = 0x000004;
  3538.    
  3539.     /** The Constant ABNORMAL_EFFECT_ICE. */
  3540.     public static final int ABNORMAL_EFFECT_ICE = 0x000008;
  3541.    
  3542.     /** The Constant ABNORMAL_EFFECT_WIND. */
  3543.     public static final int ABNORMAL_EFFECT_WIND = 0x0000010;
  3544.    
  3545.     /** The Constant ABNORMAL_EFFECT_FEAR. */
  3546.     public static final int ABNORMAL_EFFECT_FEAR = 0x0000020;
  3547.    
  3548.     /** The Constant ABNORMAL_EFFECT_STUN. */
  3549.     public static final int ABNORMAL_EFFECT_STUN = 0x000040;
  3550.    
  3551.     /** The Constant ABNORMAL_EFFECT_SLEEP. */
  3552.     public static final int ABNORMAL_EFFECT_SLEEP = 0x000080;
  3553.    
  3554.     /** The Constant ABNORMAL_EFFECT_MUTED. */
  3555.     public static final int ABNORMAL_EFFECT_MUTED = 0x000100;
  3556.    
  3557.     /** The Constant ABNORMAL_EFFECT_ROOT. */
  3558.     public static final int ABNORMAL_EFFECT_ROOT = 0x000200;
  3559.    
  3560.     /** The Constant ABNORMAL_EFFECT_HOLD_1. */
  3561.     public static final int ABNORMAL_EFFECT_HOLD_1 = 0x000400;
  3562.    
  3563.     /** The Constant ABNORMAL_EFFECT_HOLD_2. */
  3564.     public static final int ABNORMAL_EFFECT_HOLD_2 = 0x000800;
  3565.    
  3566.     /** The Constant ABNORMAL_EFFECT_UNKNOWN_13. */
  3567.     public static final int ABNORMAL_EFFECT_UNKNOWN_13 = 0x001000;
  3568.    
  3569.     /** The Constant ABNORMAL_EFFECT_BIG_HEAD. */
  3570.     public static final int ABNORMAL_EFFECT_BIG_HEAD = 0x002000;
  3571.    
  3572.     /** The Constant ABNORMAL_EFFECT_FLAME. */
  3573.     public static final int ABNORMAL_EFFECT_FLAME = 0x004000;
  3574.    
  3575.     /** The Constant ABNORMAL_EFFECT_UNKNOWN_16. */
  3576.     public static final int ABNORMAL_EFFECT_UNKNOWN_16 = 0x008000;
  3577.    
  3578.     /** The Constant ABNORMAL_EFFECT_GROW. */
  3579.     public static final int ABNORMAL_EFFECT_GROW = 0x010000;
  3580.    
  3581.     /** The Constant ABNORMAL_EFFECT_FLOATING_ROOT. */
  3582.     public static final int ABNORMAL_EFFECT_FLOATING_ROOT = 0x020000;
  3583.    
  3584.     /** The Constant ABNORMAL_EFFECT_DANCE_STUNNED. */
  3585.     public static final int ABNORMAL_EFFECT_DANCE_STUNNED = 0x040000;
  3586.  
  3587.     /** The Constant ABNORMAL_EFFECT_PARALYZE. */
  3588.     public static final int ABNORMAL_EFFECT_PARALYZE = 0x0400;
  3589.  
  3590.     /** The Constant ABNORMAL_EFFECT_FIREROOT_STUN. */
  3591.     public static final int ABNORMAL_EFFECT_FIREROOT_STUN = 0x080000;
  3592.    
  3593.     /** The Constant ABNORMAL_EFFECT_STEALTH. */
  3594.     public static final int ABNORMAL_EFFECT_STEALTH = 0x100000;
  3595.    
  3596.     /** The Constant ABNORMAL_EFFECT_IMPRISIONING_1. */
  3597.     public static final int ABNORMAL_EFFECT_IMPRISIONING_1 = 0x200000;
  3598.    
  3599.     /** The Constant ABNORMAL_EFFECT_IMPRISIONING_2. */
  3600.     public static final int ABNORMAL_EFFECT_IMPRISIONING_2 = 0x400000;
  3601.    
  3602.     /** The Constant ABNORMAL_EFFECT_MAGIC_CIRCLE. */
  3603.     public static final int ABNORMAL_EFFECT_MAGIC_CIRCLE = 0x800000;
  3604.    
  3605.     /** The Constant ABNORMAL_EFFECT_CONFUSED. */
  3606.     public static final int ABNORMAL_EFFECT_CONFUSED = 0x0020;
  3607.    
  3608.     /** The Constant ABNORMAL_EFFECT_AFRAID. */
  3609.     public static final int ABNORMAL_EFFECT_AFRAID = 0x0010;
  3610.    
  3611.     // Method - Public
  3612.     /**
  3613.      * Launch and add L2Effect (including Stack Group management) to L2Character and update client magic icone.<BR>
  3614.      * <BR>
  3615.      * <B><U> Concept</U> :</B><BR>
  3616.      * <BR>
  3617.      * 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>
  3618.      * <BR>
  3619.      * 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
  3620.      * time on a L2Character, only the more efficient (identified by its priority order) will be preserve.<BR>
  3621.      * <BR>
  3622.      * <B><U> Actions</U> :</B><BR>
  3623.      * <BR>
  3624.      * <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
  3625.      * 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>
  3626.      * @param newEffect the new effect
  3627.      */
  3628.     public synchronized void addEffect(final L2Effect newEffect)
  3629.     {
  3630.         if (newEffect == null)
  3631.             return;
  3632.        
  3633.         final L2Effect[] effects = getAllEffects();
  3634.        
  3635.         // Make sure there's no same effect previously
  3636.         for (final L2Effect effect : effects)
  3637.         {
  3638.             if (effect == null)
  3639.             {
  3640.                
  3641.                 synchronized (_effects)
  3642.                 {
  3643.                     _effects.remove(effect);
  3644.                 }
  3645.                 continue;
  3646.             }
  3647.            
  3648.             if (effect.getSkill().getId() == newEffect.getSkill().getId() && effect.getEffectType() == newEffect.getEffectType() && effect.getStackType() == newEffect.getStackType())
  3649.             {
  3650.                 if (this instanceof L2PcInstance)
  3651.                 {
  3652.                    
  3653.                     final L2PcInstance player = (L2PcInstance) this;
  3654.                    
  3655.                     if (player.isInDuel())
  3656.                     {
  3657.                         DuelManager.getInstance().getDuel(player.getDuelId()).onBuffStop(player, effect);
  3658.                     }
  3659.                    
  3660.                 }
  3661.                
  3662.                 if ((newEffect.getSkill().getSkillType() == SkillType.BUFF || newEffect.getEffectType() == L2Effect.EffectType.BUFF || newEffect.getEffectType() == L2Effect.EffectType.HEAL_OVER_TIME) && newEffect.getStackOrder() >= effect.getStackOrder())
  3663.                 {
  3664.                     effect.exit(false);
  3665.                 }
  3666.                 else
  3667.                 {
  3668.                     // newEffect.exit(false);
  3669.                     newEffect.stopEffectTask();
  3670.                     return;
  3671.                 }
  3672.             }
  3673.         }
  3674.  
  3675.         final L2Skill tempskill = newEffect.getSkill();
  3676.        
  3677.         // Remove first Buff if number of buffs > BUFFS_MAX_AMOUNT
  3678.         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))
  3679.         {
  3680.             if (newEffect.isHerbEffect())
  3681.             {
  3682.                 newEffect.exit(false);
  3683.                 return;
  3684.             }
  3685.             removeFirstBuff(tempskill.getId());
  3686.         }
  3687.  
  3688.         // Remove first DeBuff if number of debuffs > DEBUFFS_MAX_AMOUNT
  3689.         if (getDeBuffCount() >= Config.DEBUFFS_MAX_AMOUNT && !doesStack(tempskill) && tempskill.is_Debuff())
  3690.         {
  3691.             removeFirstDeBuff(tempskill.getId());
  3692.         }
  3693.        
  3694.         synchronized (_effects)
  3695.         {
  3696.             // Add the L2Effect to all effect in progress on the L2Character
  3697.             if (!newEffect.getSkill().isToggle())
  3698.             {
  3699.                 int pos = 0;
  3700.                
  3701.                 for (int i = 0; i < _effects.size(); i++)
  3702.                 {
  3703.                     if (_effects.get(i) == null)
  3704.                     {
  3705.                         _effects.remove(i);
  3706.                         i--;
  3707.                         continue;
  3708.                     }
  3709.                    
  3710.                     if (_effects.get(i) != null)
  3711.                     {
  3712.                         final int skillid = _effects.get(i).getSkill().getId();
  3713.                        
  3714.                         if (!_effects.get(i).getSkill().isToggle() && !(skillid > 4360 && skillid < 4367))
  3715.                         {
  3716.                             pos++;
  3717.                         }
  3718.                     }
  3719.                     else
  3720.                     {
  3721.                         break;
  3722.                     }
  3723.                 }
  3724.                 _effects.add(pos, newEffect);
  3725.             }
  3726.             else
  3727.             {
  3728.                 _effects.addLast(newEffect);
  3729.             }
  3730.            
  3731.         }
  3732.        
  3733.         // Check if a stack group is defined for this effect
  3734.         if (newEffect.getStackType().equals("none"))
  3735.         {
  3736.             // Set this L2Effect to In Use
  3737.             newEffect.setInUse(true);
  3738.            
  3739.             // Add Funcs of this effect to the Calculator set of the L2Character
  3740.             addStatFuncs(newEffect.getStatFuncs());
  3741.            
  3742.             // Update active skills in progress icones on player client
  3743.             updateEffectIcons();
  3744.             return;
  3745.         }
  3746.        
  3747.         // Get the list of all stacked effects corresponding to the stack type of the L2Effect to add
  3748.         List<L2Effect> stackQueue = _stackedEffects.get(newEffect.getStackType());
  3749.        
  3750.         if (stackQueue == null)
  3751.         {
  3752.             stackQueue = new FastList<>();
  3753.         }
  3754.        
  3755.         // L2Effect tempEffect = null;
  3756.        
  3757.         if (stackQueue.size() > 0)
  3758.         {
  3759.             // Get the first stacked effect of the Stack group selected
  3760.             if (_effects.contains(stackQueue.get(0)))
  3761.             {
  3762.                 // Remove all Func objects corresponding to this stacked effect from the Calculator set of the L2Character
  3763.                 removeStatsOwner(stackQueue.get(0));
  3764.                
  3765.                 // Set the L2Effect to Not In Use
  3766.                 stackQueue.get(0).setInUse(false);
  3767.             }
  3768.         }
  3769.        
  3770.         // Add the new effect to the stack group selected at its position
  3771.         stackQueue = effectQueueInsert(newEffect, stackQueue);
  3772.        
  3773.         if (stackQueue == null)
  3774.             return;
  3775.        
  3776.         // Update the Stack Group table _stackedEffects of the L2Character
  3777.         _stackedEffects.put(newEffect.getStackType(), stackQueue);
  3778.        
  3779.         // Get the first stacked effect of the Stack group selected
  3780.         if (_effects.contains(stackQueue.get(0)))
  3781.         {
  3782.             // Set this L2Effect to In Use
  3783.             stackQueue.get(0).setInUse(true);
  3784.            
  3785.             // Add all Func objects corresponding to this stacked effect to the Calculator set of the L2Character
  3786.             addStatFuncs(stackQueue.get(0).getStatFuncs());
  3787.         }
  3788.        
  3789.         // Update active skills in progress (In Use and Not In Use because stacked) icones on client
  3790.         updateEffectIcons();
  3791.     }
  3792.    
  3793.     /**
  3794.      * Insert an effect at the specified position in a Stack Group.<BR>
  3795.      * <BR>
  3796.      * <B><U> Concept</U> :</B><BR>
  3797.      * <BR>
  3798.      * 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
  3799.      * time on a L2Character, only the more efficient (identified by its priority order) will be preserve.<BR>
  3800.      * <BR>
  3801.      * @param newStackedEffect the new stacked effect
  3802.      * @param stackQueue The Stack Group in wich the effect must be added
  3803.      * @return the list
  3804.      */
  3805.     private List<L2Effect> effectQueueInsert(final L2Effect newStackedEffect, final List<L2Effect> stackQueue)
  3806.     {
  3807.         // Create an Iterator to go through the list of stacked effects in progress on the L2Character
  3808.         Iterator<L2Effect> queueIterator = stackQueue.iterator();
  3809.        
  3810.         int i = 0;
  3811.         while (queueIterator.hasNext())
  3812.         {
  3813.             final L2Effect cur = queueIterator.next();
  3814.             if (newStackedEffect.getStackOrder() < cur.getStackOrder())
  3815.             {
  3816.                 i++;
  3817.             }
  3818.             else
  3819.             {
  3820.                 break;
  3821.             }
  3822.         }
  3823.        
  3824.         // Add the new effect to the Stack list in function of its position in the Stack group
  3825.         stackQueue.add(i, newStackedEffect);
  3826.        
  3827.         // skill.exit() could be used, if the users don't wish to see "effect
  3828.         // removed" always when a timer goes off, even if the buff isn't active
  3829.         // any more (has been replaced). but then check e.g. npc hold and raid petrify.
  3830.         if (Config.EFFECT_CANCELING && !newStackedEffect.isHerbEffect() && stackQueue.size() > 1)
  3831.         {
  3832.             synchronized (_effects)
  3833.             {
  3834.                
  3835.                 _effects.remove(stackQueue.get(1));
  3836.                
  3837.             }
  3838.            
  3839.             stackQueue.remove(1);
  3840.         }
  3841.        
  3842.         queueIterator = null;
  3843.        
  3844.         return stackQueue;
  3845.     }
  3846.    
  3847.     /**
  3848.      * Stop and remove L2Effect (including Stack Group management) from L2Character and update client magic icone.<BR>
  3849.      * <BR>
  3850.      * <B><U> Concept</U> :</B><BR>
  3851.      * <BR>
  3852.      * 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>
  3853.      * <BR>
  3854.      * 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
  3855.      * time on a L2Character, only the more efficient (identified by its priority order) will be preserve.<BR>
  3856.      * <BR>
  3857.      * <B><U> Actions</U> :</B><BR>
  3858.      * <BR>
  3859.      * <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
  3860.      * progress icones on player client</li><BR>
  3861.      * @param effect the effect
  3862.      */
  3863.     public final void removeEffect(final L2Effect effect)
  3864.     {
  3865.         if (effect == null/* || _effects == null */)
  3866.             return;
  3867.        
  3868.         if (effect.getStackType() == "none")
  3869.         {
  3870.             // Remove Func added by this effect from the L2Character Calculator
  3871.             removeStatsOwner(effect);
  3872.         }
  3873.         else
  3874.         {
  3875.             if (_stackedEffects == null)
  3876.                 return;
  3877.            
  3878.             // Get the list of all stacked effects corresponding to the stack type of the L2Effect to add
  3879.             final List<L2Effect> stackQueue = _stackedEffects.get(effect.getStackType());
  3880.            
  3881.             if (stackQueue == null || stackQueue.size() < 1)
  3882.                 return;
  3883.            
  3884.             // Get the Identifier of the first stacked effect of the Stack group selected
  3885.             final L2Effect frontEffect = stackQueue.get(0);
  3886.            
  3887.             // Remove the effect from the Stack Group
  3888.             final boolean removed = stackQueue.remove(effect);
  3889.            
  3890.             if (removed)
  3891.             {
  3892.                 // Check if the first stacked effect was the effect to remove
  3893.                 if (frontEffect == effect)
  3894.                 {
  3895.                     // Remove all its Func objects from the L2Character calculator set
  3896.                     removeStatsOwner(effect);
  3897.                    
  3898.                     // Check if there's another effect in the Stack Group
  3899.                     if (stackQueue.size() > 0)
  3900.                     {
  3901.                         // Add its list of Funcs to the Calculator set of the L2Character
  3902.                         if (_effects.contains(stackQueue.get(0)))
  3903.                         {
  3904.                            
  3905.                             // Add its list of Funcs to the Calculator set of the L2Character
  3906.                             addStatFuncs(stackQueue.get(0).getStatFuncs());
  3907.                             // Set the effect to In Use
  3908.                             stackQueue.get(0).setInUse(true);
  3909.                            
  3910.                         }
  3911.                        
  3912.                     }
  3913.                 }
  3914.                 if (stackQueue.isEmpty())
  3915.                 {
  3916.                     _stackedEffects.remove(effect.getStackType());
  3917.                 }
  3918.                 else
  3919.                 {
  3920.                     // Update the Stack Group table _stackedEffects of the L2Character
  3921.                     _stackedEffects.put(effect.getStackType(), stackQueue);
  3922.                 }
  3923.             }
  3924.            
  3925.         }
  3926.        
  3927.         synchronized (_effects)
  3928.         {
  3929.             // Remove the active skill L2effect from _effects of the L2Character
  3930.             _effects.remove(effect);
  3931.            
  3932.         }
  3933.        
  3934.         // Update active skills in progress (In Use and Not In Use because stacked) icones on client
  3935.         updateEffectIcons();
  3936.     }
  3937.    
  3938.     /**
  3939.      * Active abnormal effects flags in the binary mask and send Server->Client UserInfo/CharInfo packet.<BR>
  3940.      * <BR>
  3941.      * @param mask the mask
  3942.      */
  3943.     public final void startAbnormalEffect(final int mask)
  3944.     {
  3945.         _AbnormalEffects |= mask;
  3946.         updateAbnormalEffect();
  3947.     }
  3948.    
  3949.     /**
  3950.      * immobile start.
  3951.      */
  3952.     public final void startImmobileUntilAttacked()
  3953.     {
  3954.         setIsImmobileUntilAttacked(true);
  3955.         abortAttack();
  3956.         abortCast();
  3957.         getAI().notifyEvent(CtrlEvent.EVT_SLEEPING);
  3958.         updateAbnormalEffect();
  3959.     }
  3960.    
  3961.     /**
  3962.      * Active the abnormal effect Confused flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  3963.      * <BR>
  3964.      */
  3965.     public final void startConfused()
  3966.     {
  3967.         setIsConfused(true);
  3968.         getAI().notifyEvent(CtrlEvent.EVT_CONFUSED);
  3969.         updateAbnormalEffect();
  3970.     }
  3971.    
  3972.     /**
  3973.      * Active the abnormal effect Fake Death flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  3974.      * <BR>
  3975.      */
  3976.     public final void startFakeDeath()
  3977.     {
  3978.         setIsFallsdown(true);
  3979.         setIsFakeDeath(true);
  3980.         /* Aborts any attacks/casts if fake dead */
  3981.         abortAttack();
  3982.         abortCast();
  3983.         stopMove(null);
  3984.         getAI().notifyEvent(CtrlEvent.EVT_FAKE_DEATH, null);
  3985.         broadcastPacket(new ChangeWaitType(this, ChangeWaitType.WT_START_FAKEDEATH));
  3986.     }
  3987.    
  3988.     /**
  3989.      * Active the abnormal effect Fear flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  3990.      * <BR>
  3991.      */
  3992.     public final void startFear()
  3993.     {
  3994.         setIsAfraid(true);
  3995.         getAI().notifyEvent(CtrlEvent.EVT_AFFRAID);
  3996.         updateAbnormalEffect();
  3997.     }
  3998.    
  3999.     /**
  4000.      * Active the abnormal effect Muted flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  4001.      * <BR>
  4002.      */
  4003.     public final void startMuted()
  4004.     {
  4005.         setIsMuted(true);
  4006.         /* Aborts any casts if muted */
  4007.         abortCast();
  4008.         getAI().notifyEvent(CtrlEvent.EVT_MUTED);
  4009.         updateAbnormalEffect();
  4010.     }
  4011.    
  4012.     /**
  4013.      * Active the abnormal effect Psychical_Muted flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  4014.      * <BR>
  4015.      */
  4016.     public final void startPsychicalMuted()
  4017.     {
  4018.         setIsPsychicalMuted(true);
  4019.         getAI().notifyEvent(CtrlEvent.EVT_MUTED);
  4020.         updateAbnormalEffect();
  4021.     }
  4022.    
  4023.     /**
  4024.      * Active the abnormal effect Root flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  4025.      * <BR>
  4026.      */
  4027.     public final void startRooted()
  4028.     {
  4029.         setIsRooted(true);
  4030.         stopMove(null);
  4031.         getAI().notifyEvent(CtrlEvent.EVT_ROOTED, null);
  4032.         updateAbnormalEffect();
  4033.     }
  4034.    
  4035.     /**
  4036.      * Active the abnormal effect Sleep flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR>
  4037.      * <BR>
  4038.      */
  4039.     public final void startSleeping()
  4040.     {
  4041.         setIsSleeping(true);
  4042.         /* Aborts any attacks/casts if sleeped */
  4043.         abortAttack();
  4044.         abortCast();
  4045.         stopMove(null);
  4046.         getAI().notifyEvent(CtrlEvent.EVT_SLEEPING, null);
  4047.         updateAbnormalEffect();
  4048.     }
  4049.    
  4050.     /**
  4051.      * Launch a Stun Abnormal Effect on the L2Character.<BR>
  4052.      * <BR>
  4053.      * <B><U> Actions</U> :</B><BR>
  4054.      * <BR>
  4055.      * <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
  4056.      * L2PcInstance attacker</li><BR>
  4057.      * <BR>
  4058.      */
  4059.     public final void startStunning()
  4060.     {
  4061.         if (isStunned())
  4062.             return;
  4063.        
  4064.         setIsStunned(true);
  4065.         /* Aborts any attacks/casts if stunned */
  4066.         abortAttack();
  4067.         abortCast();
  4068.         getAI().stopFollow(); // Like L2OFF char stop to follow if sticked to another one
  4069.         stopMove(null);
  4070.         getAI().notifyEvent(CtrlEvent.EVT_STUNNED, null);
  4071.         updateAbnormalEffect();
  4072.     }
  4073.    
  4074.     /**
  4075.      * Start betray.
  4076.      */
  4077.     public final void startBetray()
  4078.     {
  4079.         setIsBetrayed(true);
  4080.         getAI().notifyEvent(CtrlEvent.EVT_BETRAYED, null);
  4081.         updateAbnormalEffect();
  4082.     }
  4083.    
  4084.     /**
  4085.      * Stop betray.
  4086.      */
  4087.     public final void stopBetray()
  4088.     {
  4089.         stopEffects(L2Effect.EffectType.BETRAY);
  4090.         setIsBetrayed(false);
  4091.         updateAbnormalEffect();
  4092.     }
  4093.    
  4094.     /**
  4095.      * Modify the abnormal effect map according to the mask.<BR>
  4096.      * <BR>
  4097.      * @param mask the mask
  4098.      */
  4099.     public final void stopAbnormalEffect(final int mask)
  4100.     {
  4101.         _AbnormalEffects &= ~mask;
  4102.         updateAbnormalEffect();
  4103.     }
  4104.    
  4105.     /**
  4106.      * Stop all active skills effects in progress on the L2Character.<BR>
  4107.      * <BR>
  4108.      */
  4109.     public final void stopAllEffects()
  4110.     {
  4111.        
  4112.         final L2Effect[] effects = getAllEffects();
  4113.        
  4114.         for (final L2Effect effect : effects)
  4115.         {
  4116.            
  4117.             if (effect != null)
  4118.             {
  4119.                 effect.exit(true);
  4120.             }
  4121.             else
  4122.             {
  4123.                 synchronized (_effects)
  4124.                 {
  4125.                     _effects.remove(effect);
  4126.                 }
  4127.             }
  4128.         }
  4129.        
  4130.         if (this instanceof L2PcInstance)
  4131.         {
  4132.             ((L2PcInstance) this).updateAndBroadcastStatus(2);
  4133.         }
  4134.        
  4135.     }
  4136.    
  4137.     /**
  4138.      * Stop immobilization until attacked abnormal L2Effect.<BR>
  4139.      * <BR>
  4140.      * <B><U> Actions</U> :</B><BR>
  4141.      * <BR>
  4142.      * <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>
  4143.      * <BR>
  4144.      * @param effect the effect
  4145.      */
  4146.     public final void stopImmobileUntilAttacked(final L2Effect effect)
  4147.     {
  4148.         if (effect == null)
  4149.         {
  4150.             stopEffects(L2Effect.EffectType.IMMOBILEUNTILATTACKED);
  4151.         }
  4152.         else
  4153.         {
  4154.             removeEffect(effect);
  4155.             stopSkillEffects(effect.getSkill().getNegateId());
  4156.         }
  4157.        
  4158.         setIsImmobileUntilAttacked(false);
  4159.         getAI().notifyEvent(CtrlEvent.EVT_THINK);
  4160.         updateAbnormalEffect();
  4161.     }
  4162.    
  4163.     /**
  4164.      * Stop a specified/all Confused abnormal L2Effect.<BR>
  4165.      * <BR>
  4166.      * <B><U> Actions</U> :</B><BR>
  4167.      * <BR>
  4168.      * <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>
  4169.      * <BR>
  4170.      * @param effect the effect
  4171.      */
  4172.     public final void stopConfused(final L2Effect effect)
  4173.     {
  4174.         if (effect == null)
  4175.         {
  4176.             stopEffects(L2Effect.EffectType.CONFUSION);
  4177.         }
  4178.         else
  4179.         {
  4180.             removeEffect(effect);
  4181.         }
  4182.        
  4183.         setIsConfused(false);
  4184.         getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
  4185.         updateAbnormalEffect();
  4186.     }
  4187.    
  4188.     /**
  4189.      * Stop and remove the L2Effects corresponding to the L2Skill Identifier and update client magic icone.<BR>
  4190.      * <BR>
  4191.      * <B><U> Concept</U> :</B><BR>
  4192.      * <BR>
  4193.      * 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>
  4194.      * <BR>
  4195.      * @param skillId the skill id
  4196.      */
  4197.     public final void stopSkillEffects(final int skillId)
  4198.     {
  4199.         final L2Effect[] effects = getAllEffects();
  4200.        
  4201.         for (final L2Effect effect : effects)
  4202.         {
  4203.            
  4204.             if (effect == null || effect.getSkill() == null)
  4205.             {
  4206.                
  4207.                 synchronized (_effects)
  4208.                 {
  4209.                     _effects.remove(effect);
  4210.                 }
  4211.                 continue;
  4212.                
  4213.             }
  4214.            
  4215.             if (effect.getSkill().getId() == skillId)
  4216.             {
  4217.                 effect.exit(true);
  4218.             }
  4219.            
  4220.         }
  4221.        
  4222.     }
  4223.    
  4224.     /**
  4225.      * Stop and remove all L2Effect of the selected type (ex : BUFF, DMG_OVER_TIME...) from the L2Character and update client magic icone.<BR>
  4226.      * <BR>
  4227.      * <B><U> Concept</U> :</B><BR>
  4228.      * <BR>
  4229.      * 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>
  4230.      * <BR>
  4231.      * <B><U> Actions</U> :</B><BR>
  4232.      * <BR>
  4233.      * <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>
  4234.      * <BR>
  4235.      * @param type The type of effect to stop ((ex : BUFF, DMG_OVER_TIME...)
  4236.      */
  4237.     public final void stopEffects(final L2Effect.EffectType type)
  4238.     {
  4239.         final L2Effect[] effects = getAllEffects();
  4240.        
  4241.         for (final L2Effect effect : effects)
  4242.         {
  4243.            
  4244.             if (effect == null)
  4245.             {
  4246.                
  4247.                 synchronized (_effects)
  4248.                 {
  4249.                     _effects.remove(effect);
  4250.                 }
  4251.                 continue;
  4252.                
  4253.             }
  4254.            
  4255.             // LOGGER.info("Character Effect Type: "+effects[i].getEffectType());
  4256.             if (effect.getEffectType() == type)
  4257.             {
  4258.                 effect.exit(true);
  4259.             }
  4260.            
  4261.         }
  4262.        
  4263.     }
  4264.    
  4265.     /**
  4266.      * Stop and remove the L2Effects corresponding to the L2SkillType and update client magic icon.<BR>
  4267.      * <BR>
  4268.      * <B><U> Concept</U> :</B><BR>
  4269.      * <BR>
  4270.      * 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>
  4271.      * <BR>
  4272.      * @param skillType The L2SkillType of the L2Effect to remove from _effects
  4273.      * @param power the power
  4274.      */
  4275.     public final void stopSkillEffects(final SkillType skillType, final double power)
  4276.     {
  4277.         final L2Effect[] effects = getAllEffects();
  4278.        
  4279.         for (final L2Effect effect : effects)
  4280.         {
  4281.            
  4282.             if (effect == null || effect.getSkill() == null)
  4283.             {
  4284.                
  4285.                 synchronized (_effects)
  4286.                 {
  4287.                     _effects.remove(effect);
  4288.                 }
  4289.                 continue;
  4290.                
  4291.             }
  4292.            
  4293.             if (effect.getSkill().getSkillType() == skillType && (power == 0 || effect.getSkill().getPower() <= power))
  4294.             {
  4295.                 effect.exit(true);
  4296.             }
  4297.            
  4298.         }
  4299.        
  4300.     }
  4301.    
  4302.     /**
  4303.      * Stop skill effects.
  4304.      * @param skillType the skill type
  4305.      */
  4306.     public final void stopSkillEffects(final SkillType skillType)
  4307.     {
  4308.         stopSkillEffects(skillType, -1);
  4309.     }
  4310.    
  4311.     /**
  4312.      * Stop a specified/all Fake Death abnormal L2Effect.<BR>
  4313.      * <BR>
  4314.      * <B><U> Actions</U> :</B><BR>
  4315.      * <BR>
  4316.      * <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>
  4317.      * <BR>
  4318.      * @param effect the effect
  4319.      */
  4320.     public final void stopFakeDeath(final L2Effect effect)
  4321.     {
  4322.         if (effect == null)
  4323.         {
  4324.             stopEffects(L2Effect.EffectType.FAKE_DEATH);
  4325.         }
  4326.         else
  4327.         {
  4328.             removeEffect(effect);
  4329.         }
  4330.        
  4331.         setIsFakeDeath(false);
  4332.         setIsFallsdown(false);
  4333.         // if this is a player instance, start the grace period for this character (grace from mobs only)!
  4334.         if (this instanceof L2PcInstance)
  4335.         {
  4336.             ((L2PcInstance) this).setRecentFakeDeath(true);
  4337.         }
  4338.        
  4339.         ChangeWaitType revive = new ChangeWaitType(this, ChangeWaitType.WT_STOP_FAKEDEATH);
  4340.         broadcastPacket(revive);
  4341.         broadcastPacket(new Revive(this));
  4342.         getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
  4343.        
  4344.         revive = null;
  4345.     }
  4346.    
  4347.     /**
  4348.      * Stop a specified/all Fear abnormal L2Effect.<BR>
  4349.      * <BR>
  4350.      * <B><U> Actions</U> :</B><BR>
  4351.      * <BR>
  4352.      * <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>
  4353.      * <BR>
  4354.      * @param effect the effect
  4355.      */
  4356.     public final void stopFear(final L2Effect effect)
  4357.     {
  4358.         if (effect == null)
  4359.         {
  4360.             stopEffects(L2Effect.EffectType.FEAR);
  4361.         }
  4362.         else
  4363.         {
  4364.             removeEffect(effect);
  4365.         }
  4366.        
  4367.         setIsAfraid(false);
  4368.         updateAbnormalEffect();
  4369.     }
  4370.    
  4371.     /**
  4372.      * Stop a specified/all Muted abnormal L2Effect.<BR>
  4373.      * <BR>
  4374.      * <B><U> Actions</U> :</B><BR>
  4375.      * <BR>
  4376.      * <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>
  4377.      * <BR>
  4378.      * @param effect the effect
  4379.      */
  4380.     public final void stopMuted(final L2Effect effect)
  4381.     {
  4382.         if (effect == null)
  4383.         {
  4384.             stopEffects(L2Effect.EffectType.MUTE);
  4385.         }
  4386.         else
  4387.         {
  4388.             removeEffect(effect);
  4389.         }
  4390.        
  4391.         setIsMuted(false);
  4392.         updateAbnormalEffect();
  4393.     }
  4394.    
  4395.     /**
  4396.      * Stop psychical muted.
  4397.      * @param effect the effect
  4398.      */
  4399.     public final void stopPsychicalMuted(final L2Effect effect)
  4400.     {
  4401.         if (effect == null)
  4402.         {
  4403.             stopEffects(L2Effect.EffectType.PSYCHICAL_MUTE);
  4404.         }
  4405.         else
  4406.         {
  4407.             removeEffect(effect);
  4408.         }
  4409.        
  4410.         setIsPsychicalMuted(false);
  4411.         updateAbnormalEffect();
  4412.     }
  4413.    
  4414.     /**
  4415.      * Stop a specified/all Root abnormal L2Effect.<BR>
  4416.      * <BR>
  4417.      * <B><U> Actions</U> :</B><BR>
  4418.      * <BR>
  4419.      * <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>
  4420.      * <BR>
  4421.      * @param effect the effect
  4422.      */
  4423.     public final void stopRooting(final L2Effect effect)
  4424.     {
  4425.         if (effect == null)
  4426.         {
  4427.             stopEffects(L2Effect.EffectType.ROOT);
  4428.         }
  4429.         else
  4430.         {
  4431.             removeEffect(effect);
  4432.         }
  4433.        
  4434.         setIsRooted(false);
  4435.         getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
  4436.         updateAbnormalEffect();
  4437.     }
  4438.    
  4439.     /**
  4440.      * Stop a specified/all Sleep abnormal L2Effect.<BR>
  4441.      * <BR>
  4442.      * <B><U> Actions</U> :</B><BR>
  4443.      * <BR>
  4444.      * <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>
  4445.      * <BR>
  4446.      * @param effect the effect
  4447.      */
  4448.     public final void stopSleeping(final L2Effect effect)
  4449.     {
  4450.         if (effect == null)
  4451.         {
  4452.             stopEffects(L2Effect.EffectType.SLEEP);
  4453.         }
  4454.         else
  4455.         {
  4456.             removeEffect(effect);
  4457.         }
  4458.        
  4459.         setIsSleeping(false);
  4460.         getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
  4461.         updateAbnormalEffect();
  4462.     }
  4463.    
  4464.     /**
  4465.      * Stop a specified/all Stun abnormal L2Effect.<BR>
  4466.      * <BR>
  4467.      * <B><U> Actions</U> :</B><BR>
  4468.      * <BR>
  4469.      * <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>
  4470.      * <BR>
  4471.      * @param effect the effect
  4472.      */
  4473.     public final void stopStunning(final L2Effect effect)
  4474.     {
  4475.         if (!isStunned())
  4476.             return;
  4477.        
  4478.         if (effect == null)
  4479.         {
  4480.             stopEffects(L2Effect.EffectType.STUN);
  4481.         }
  4482.         else
  4483.         {
  4484.             removeEffect(effect);
  4485.         }
  4486.        
  4487.         setIsStunned(false);
  4488.         getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
  4489.         updateAbnormalEffect();
  4490.     }
  4491.    
  4492.     /**
  4493.      * Not Implemented.<BR>
  4494.      * <BR>
  4495.      * <B><U> Overridden in</U> :</B><BR>
  4496.      * <BR>
  4497.      * <li>L2NPCInstance</li> <li>L2PcInstance</li> <li>L2Summon</li> <li>L2DoorInstance</li><BR>
  4498.      * <BR>
  4499.      */
  4500.     public abstract void updateAbnormalEffect();
  4501.    
  4502.     /**
  4503.      * Update active skills in progress (In Use and Not In Use because stacked) icones on client.<BR>
  4504.      * <BR>
  4505.      * <B><U> Concept</U> :</B><BR>
  4506.      * <BR>
  4507.      * All active skills effects in progress (In Use and Not In Use because stacked) are represented by an icone on the client.<BR>
  4508.      * <BR>
  4509.      * <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>
  4510.      * <BR>
  4511.      */
  4512.     public final void updateEffectIcons()
  4513.     {
  4514.         updateEffectIcons(false);
  4515.     }
  4516.    
  4517.     /**
  4518.      * Update effect icons.
  4519.      * @param partyOnly the party only
  4520.      */
  4521.     public final void updateEffectIcons(final boolean partyOnly)
  4522.     {
  4523.         // Create a L2PcInstance of this if needed
  4524.         L2PcInstance player = null;
  4525.        
  4526.         if (this instanceof L2PcInstance)
  4527.         {
  4528.             player = (L2PcInstance) this;
  4529.         }
  4530.        
  4531.         // Create a L2Summon of this if needed
  4532.         L2Summon summon = null;
  4533.         if (this instanceof L2Summon)
  4534.         {
  4535.             summon = (L2Summon) this;
  4536.             player = summon.getOwner();
  4537.             summon.getOwner().sendPacket(new PetInfo(summon));
  4538.         }
  4539.        
  4540.         // Create the main packet if needed
  4541.         MagicEffectIcons mi = null;
  4542.         if (!partyOnly)
  4543.         {
  4544.             mi = new MagicEffectIcons();
  4545.         }
  4546.        
  4547.         // Create the party packet if needed
  4548.         PartySpelled ps = null;
  4549.         if (summon != null)
  4550.         {
  4551.             ps = new PartySpelled(summon);
  4552.         }
  4553.         else if (player != null && player.isInParty())
  4554.         {
  4555.             ps = new PartySpelled(player);
  4556.         }
  4557.        
  4558.         // Create the olympiad spectator packet if needed
  4559.         ExOlympiadSpelledInfo os = null;
  4560.         if (player != null && player.isInOlympiadMode())
  4561.         {
  4562.             os = new ExOlympiadSpelledInfo(player);
  4563.         }
  4564.        
  4565.         if (mi == null && ps == null && os == null)
  4566.             return; // nothing to do (should not happen)
  4567.            
  4568.         // Add special effects
  4569.         // Note: Now handled by EtcStatusUpdate packet
  4570.         // NOTE: CHECK IF THEY WERE EVEN VISIBLE TO OTHERS...
  4571.         /*
  4572.          * 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); }
  4573.          */
  4574.        
  4575.         // Go through all effects if any
  4576.         synchronized (_effects)
  4577.         {
  4578.            
  4579.             for (int i = 0; i < _effects.size(); i++)
  4580.             {
  4581.                
  4582.                 if (_effects.get(i) == null || _effects.get(i).getSkill() == null)
  4583.                 {
  4584.                    
  4585.                     _effects.remove(i);
  4586.                     i--;
  4587.                     continue;
  4588.                    
  4589.                 }
  4590.                
  4591.                 if (_effects.get(i).getEffectType() == L2Effect.EffectType.CHARGE && player != null)
  4592.                 {
  4593.                     // handled by EtcStatusUpdate
  4594.                     continue;
  4595.                 }
  4596.                
  4597.                 if (_effects.get(i).getInUse())
  4598.                 {
  4599.                     if (mi != null)
  4600.                     {
  4601.                         _effects.get(i).addIcon(mi);
  4602.                     }
  4603.                     // Like L2OFF toggle and healing potions must not be showed on party buff list
  4604.                     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))
  4605.                     {
  4606.                         _effects.get(i).addPartySpelledIcon(ps);
  4607.                     }
  4608.                     if (os != null)
  4609.                     {
  4610.                         _effects.get(i).addOlympiadSpelledIcon(os);
  4611.                     }
  4612.                 }
  4613.                
  4614.             }
  4615.            
  4616.         }
  4617.        
  4618.         // Send the packets if needed
  4619.         if (mi != null)
  4620.         {
  4621.             sendPacket(mi);
  4622.         }
  4623.        
  4624.         if (ps != null && player != null)
  4625.         {
  4626.             // summon info only needs to go to the owner, not to the whole party
  4627.             // player info: if in party, send to all party members except one's self.
  4628.             // if not in party, send to self.
  4629.             if (player.isInParty() && summon == null)
  4630.             {
  4631.                 player.getParty().broadcastToPartyMembers(player, ps);
  4632.             }
  4633.             else
  4634.             {
  4635.                 player.sendPacket(ps);
  4636.             }
  4637.         }
  4638.        
  4639.         if (os != null)
  4640.         {
  4641.             if ((player != null) && Olympiad.getInstance().getSpectators(player.getOlympiadGameId()) != null)
  4642.             {
  4643.                 for (final L2PcInstance spectator : Olympiad.getInstance().getSpectators(player.getOlympiadGameId()))
  4644.                 {
  4645.                     if (spectator == null)
  4646.                     {
  4647.                         continue;
  4648.                     }
  4649.                     spectator.sendPacket(os);
  4650.                 }
  4651.             }
  4652.         }
  4653.        
  4654.     }
  4655.    
  4656.     // Property - Public
  4657.     /**
  4658.      * Return a map of 16 bits (0x0000) containing all abnormal effect in progress for this L2Character.<BR>
  4659.      * <BR>
  4660.      * <B><U> Concept</U> :</B><BR>
  4661.      * <BR>
  4662.      * 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>
  4663.      * <BR>
  4664.      * <B><U> Example of use </U> :</B><BR>
  4665.      * <BR>
  4666.      * <li>Server Packet : CharInfo, NpcInfo, NpcInfoPoly, UserInfo...</li><BR>
  4667.      * <BR>
  4668.      * @return the abnormal effect
  4669.      */
  4670.     public int getAbnormalEffect()
  4671.     {
  4672.         int ae = _AbnormalEffects;
  4673.        
  4674.         if (isStunned())
  4675.         {
  4676.             ae |= ABNORMAL_EFFECT_STUN;
  4677.         }
  4678.         if (isRooted())
  4679.         {
  4680.             ae |= ABNORMAL_EFFECT_ROOT;
  4681.         }
  4682.         if (isSleeping())
  4683.         {
  4684.             ae |= ABNORMAL_EFFECT_SLEEP;
  4685.         }
  4686.         if (isConfused())
  4687.         {
  4688.             ae |= ABNORMAL_EFFECT_CONFUSED;
  4689.         }
  4690.         if (isMuted())
  4691.         {
  4692.             ae |= ABNORMAL_EFFECT_MUTED;
  4693.         }
  4694.         if (isAfraid())
  4695.         {
  4696.             ae |= ABNORMAL_EFFECT_AFRAID;
  4697.         }
  4698.         if (isPsychicalMuted())
  4699.         {
  4700.             ae |= ABNORMAL_EFFECT_MUTED;
  4701.         }
  4702.        
  4703.         return ae;
  4704.     }
  4705.    
  4706.     /**
  4707.      * Return all active skills effects in progress on the L2Character.<BR>
  4708.      * <BR>
  4709.      * <B><U> Concept</U> :</B><BR>
  4710.      * <BR>
  4711.      * 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>
  4712.      * <BR>
  4713.      * @return A table containing all active skills effect in progress on the L2Character
  4714.      */
  4715.     public final L2Effect[] getAllEffects()
  4716.     {
  4717.         synchronized (_effects)
  4718.         {
  4719.             final L2Effect[] output = _effects.toArray(new L2Effect[_effects.size()]);
  4720.            
  4721.             return output;
  4722.         }
  4723.     }
  4724.    
  4725.     /**
  4726.      * Return L2Effect in progress on the L2Character corresponding to the L2Skill Identifier.<BR>
  4727.      * <BR>
  4728.      * <B><U> Concept</U> :</B><BR>
  4729.      * <BR>
  4730.      * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
  4731.      * @param index The L2Skill Identifier of the L2Effect to return from the _effects
  4732.      * @return The L2Effect corresponding to the L2Skill Identifier
  4733.      */
  4734.     public final L2Effect getFirstEffect(final int index)
  4735.     {
  4736.         final L2Effect[] effects = getAllEffects();
  4737.        
  4738.         L2Effect effNotInUse = null;
  4739.        
  4740.         for (final L2Effect effect : effects)
  4741.         {
  4742.            
  4743.             if (effect == null)
  4744.             {
  4745.                 synchronized (_effects)
  4746.                 {
  4747.                     _effects.remove(effect);
  4748.                 }
  4749.                 continue;
  4750.             }
  4751.            
  4752.             if (effect.getSkill().getId() == index)
  4753.             {
  4754.                 if (effect.getInUse())
  4755.                     return effect;
  4756.                
  4757.                 if (effNotInUse == null)
  4758.                     effNotInUse = effect;
  4759.             }
  4760.            
  4761.         }
  4762.        
  4763.         return effNotInUse;
  4764.        
  4765.     }
  4766.    
  4767.     /**
  4768.      * Gets the first effect.
  4769.      * @param type the type
  4770.      * @return the first effect
  4771.      */
  4772.     public final L2Effect getFirstEffect(final SkillType type)
  4773.     {
  4774.        
  4775.         final L2Effect[] effects = getAllEffects();
  4776.        
  4777.         L2Effect effNotInUse = null;
  4778.        
  4779.         for (final L2Effect effect : effects)
  4780.         {
  4781.            
  4782.             if (effect == null)
  4783.             {
  4784.                 synchronized (_effects)
  4785.                 {
  4786.                     _effects.remove(effect);
  4787.                 }
  4788.                 continue;
  4789.             }
  4790.            
  4791.             if (effect.getSkill().getSkillType() == type)
  4792.             {
  4793.                 if (effect.getInUse())
  4794.                     return effect;
  4795.                
  4796.                 if (effNotInUse == null)
  4797.                     effNotInUse = effect;
  4798.             }
  4799.            
  4800.         }
  4801.        
  4802.         return effNotInUse;
  4803.        
  4804.     }
  4805.    
  4806.     /**
  4807.      * Return the first L2Effect in progress on the L2Character created by the L2Skill.<BR>
  4808.      * <BR>
  4809.      * <B><U> Concept</U> :</B><BR>
  4810.      * <BR>
  4811.      * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
  4812.      * @param skill The L2Skill whose effect must be returned
  4813.      * @return The first L2Effect created by the L2Skill
  4814.      */
  4815.     public final L2Effect getFirstEffect(final L2Skill skill)
  4816.     {
  4817.         final L2Effect[] effects = getAllEffects();
  4818.        
  4819.         L2Effect effNotInUse = null;
  4820.        
  4821.         for (final L2Effect effect : effects)
  4822.         {
  4823.            
  4824.             if (effect == null)
  4825.             {
  4826.                 synchronized (_effects)
  4827.                 {
  4828.                     _effects.remove(effect);
  4829.                 }
  4830.                 continue;
  4831.             }
  4832.            
  4833.             if (effect.getSkill() == skill)
  4834.             {
  4835.                 if (effect.getInUse())
  4836.                     return effect;
  4837.                
  4838.                 if (effNotInUse == null)
  4839.                     effNotInUse = effect;
  4840.             }
  4841.            
  4842.         }
  4843.        
  4844.         return effNotInUse;
  4845.        
  4846.     }
  4847.    
  4848.     /**
  4849.      * Return the first L2Effect in progress on the L2Character corresponding to the Effect Type (ex : BUFF, STUN, ROOT...).<BR>
  4850.      * <BR>
  4851.      * <B><U> Concept</U> :</B><BR>
  4852.      * <BR>
  4853.      * 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>
  4854.      * <BR>
  4855.      * @param tp The Effect Type of skills whose effect must be returned
  4856.      * @return The first L2Effect corresponding to the Effect Type
  4857.      */
  4858.     public final L2Effect getFirstEffect(final L2Effect.EffectType tp)
  4859.     {
  4860.         final L2Effect[] effects = getAllEffects();
  4861.        
  4862.         L2Effect effNotInUse = null;
  4863.        
  4864.         for (final L2Effect effect : effects)
  4865.         {
  4866.            
  4867.             if (effect == null)
  4868.             {
  4869.                 synchronized (_effects)
  4870.                 {
  4871.                     _effects.remove(effect);
  4872.                 }
  4873.                 continue;
  4874.             }
  4875.            
  4876.             if (effect.getEffectType() == tp)
  4877.             {
  4878.                 if (effect.getInUse())
  4879.                     return effect;
  4880.                
  4881.                 if (effNotInUse == null)
  4882.                     effNotInUse = effect;
  4883.             }
  4884.            
  4885.         }
  4886.        
  4887.         return effNotInUse;
  4888.        
  4889.     }
  4890.    
  4891.     /**
  4892.      * Gets the charge effect.
  4893.      * @return the charge effect
  4894.      */
  4895.     public EffectCharge getChargeEffect()
  4896.     {
  4897.        
  4898.         final L2Effect effect = getFirstEffect(SkillType.CHARGE);
  4899.         if (effect != null)
  4900.             return (EffectCharge) effect;
  4901.        
  4902.         return null;
  4903.        
  4904.     }
  4905.    
  4906.     // =========================================================
  4907.     // NEED TO ORGANIZE AND MOVE TO PROPER PLACE
  4908.     /**
  4909.      * This class permit to the L2Character AI to obtain informations and uses L2Character method.
  4910.      */
  4911.     public class AIAccessor
  4912.     {
  4913.        
  4914.         /**
  4915.          * Instantiates a new aI accessor.
  4916.          */
  4917.         public AIAccessor()
  4918.         {
  4919.             // null
  4920.         }
  4921.        
  4922.         /**
  4923.          * Return the L2Character managed by this Accessor AI.<BR>
  4924.          * <BR>
  4925.          * @return the actor
  4926.          */
  4927.         public L2Character getActor()
  4928.         {
  4929.             return L2Character.this;
  4930.         }
  4931.        
  4932.         /**
  4933.          * Accessor to L2Character moveToLocation() method with an interaction area.<BR>
  4934.          * <BR>
  4935.          * @param x the x
  4936.          * @param y the y
  4937.          * @param z the z
  4938.          * @param offset the offset
  4939.          */
  4940.         public void moveTo(final int x, final int y, final int z, final int offset)
  4941.         {
  4942.             moveToLocation(x, y, z, offset);
  4943.         }
  4944.        
  4945.         /**
  4946.          * Accessor to L2Character moveToLocation() method without interaction area.<BR>
  4947.          * <BR>
  4948.          * @param x the x
  4949.          * @param y the y
  4950.          * @param z the z
  4951.          */
  4952.         public void moveTo(final int x, final int y, final int z)
  4953.         {
  4954.             moveToLocation(x, y, z, 0);
  4955.         }
  4956.        
  4957.         /**
  4958.          * Accessor to L2Character stopMove() method.<BR>
  4959.          * <BR>
  4960.          * @param pos the pos
  4961.          */
  4962.         public void stopMove(final L2CharPosition pos)
  4963.         {
  4964.             L2Character.this.stopMove(pos);
  4965.         }
  4966.        
  4967.         /**
  4968.          * Accessor to L2Character doAttack() method.<BR>
  4969.          * <BR>
  4970.          * @param target the target
  4971.          */
  4972.         public void doAttack(final L2Character target)
  4973.         {
  4974.             L2Character.this.doAttack(target);
  4975.         }
  4976.        
  4977.         /**
  4978.          * Accessor to L2Character doCast() method.<BR>
  4979.          * <BR>
  4980.          * @param skill the skill
  4981.          */
  4982.         public void doCast(final L2Skill skill)
  4983.         {
  4984.             L2Character.this.doCast(skill);
  4985.         }
  4986.        
  4987.         /**
  4988.          * Create a NotifyAITask.<BR>
  4989.          * <BR>
  4990.          * @param evt the evt
  4991.          * @return the notify ai task
  4992.          */
  4993.         public NotifyAITask newNotifyTask(final CtrlEvent evt)
  4994.         {
  4995.             return new NotifyAITask(evt);
  4996.         }
  4997.        
  4998.         /**
  4999.          * Cancel the AI.<BR>
  5000.          * <BR>
  5001.          */
  5002.         public void detachAI()
  5003.         {
  5004.             _ai = null;
  5005.         }
  5006.     }
  5007.    
  5008.     /**
  5009.      * This class group all mouvement data.<BR>
  5010.      * <BR>
  5011.      * <B><U> Data</U> :</B><BR>
  5012.      * <BR>
  5013.      * <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
  5014.      * between the start and the destination</li> <li>_xSpeedTicks, _ySpeedTicks : Speed in unit/ticks</li><BR>
  5015.      * <BR>
  5016.      */
  5017.     public static class MoveData
  5018.     {
  5019.         // when we retrieve x/y/z we use GameTimeControl.getGameTicks()
  5020.         // if we are moving, but move timestamp==gameticks, we don't need
  5021.         // to recalculate position
  5022.         /** The _move start time. */
  5023.         public int _moveStartTime;
  5024.        
  5025.         /** The _move timestamp. */
  5026.         public int _moveTimestamp;
  5027.        
  5028.         /** The _x destination. */
  5029.         public int _xDestination;
  5030.        
  5031.         /** The _y destination. */
  5032.         public int _yDestination;
  5033.        
  5034.         /** The _z destination. */
  5035.         public int _zDestination;
  5036.        
  5037.         /** The _x accurate. */
  5038.         public double _xAccurate;
  5039.        
  5040.         /** The _y accurate. */
  5041.         public double _yAccurate;
  5042.        
  5043.         /** The _z accurate. */
  5044.         public double _zAccurate;
  5045.        
  5046.         /** The _heading. */
  5047.         public int _heading;
  5048.        
  5049.         /** The disregarding geodata. */
  5050.         public boolean disregardingGeodata;
  5051.        
  5052.         /** The on geodata path index. */
  5053.         public int onGeodataPathIndex;
  5054.        
  5055.         /** The geo path. */
  5056.         public Node[] geoPath;
  5057.        
  5058.         /** The geo path accurate tx. */
  5059.         public int geoPathAccurateTx;
  5060.        
  5061.         /** The geo path accurate ty. */
  5062.         public int geoPathAccurateTy;
  5063.        
  5064.         /** The geo path gtx. */
  5065.         public int geoPathGtx;
  5066.        
  5067.         /** The geo path gty. */
  5068.         public int geoPathGty;
  5069.     }
  5070.    
  5071.     /** Table containing all skillId that are disabled. */
  5072.     protected List<Integer> _disabledSkills;
  5073.    
  5074.     /** The _all skills disabled. */
  5075.     private boolean _allSkillsDisabled;
  5076.    
  5077.     // private int _flyingRunSpeed;
  5078.     // private int _floatingWalkSpeed;
  5079.     // private int _flyingWalkSpeed;
  5080.     // private int _floatingRunSpeed;
  5081.    
  5082.     /** Movement data of this L2Character. */
  5083.     protected MoveData _move;
  5084.    
  5085.     /** Orientation of the L2Character. */
  5086.     private int _heading;
  5087.    
  5088.     /** L2Charcater targeted by the L2Character. */
  5089.     private L2Object _target;
  5090.    
  5091.     // set by the start of casting, in game ticks
  5092.     /** The _cast end time. */
  5093.     private int _castEndTime;
  5094.    
  5095.     /** The _cast interrupt time. */
  5096.     private int _castInterruptTime;
  5097.    
  5098.     // set by the start of casting, in game ticks
  5099.     /** The _cast potion end time. */
  5100.     private int _castPotionEndTime;
  5101.    
  5102.     /** The _cast potion interrupt time. */
  5103.     @SuppressWarnings("unused")
  5104.     private int _castPotionInterruptTime;
  5105.    
  5106.     // set by the start of attack, in game ticks
  5107.     /** The _attack end time. */
  5108.     int _attackEndTime;
  5109.    
  5110.     /** The _attacking. */
  5111.     private int _attacking;
  5112.    
  5113.     /** The _disable bow attack end time. */
  5114.     private int _disableBowAttackEndTime;
  5115.    
  5116.     /** Table of calculators containing all standard NPC calculator (ex : ACCURACY_COMBAT, EVASION_RATE. */
  5117.     private static final Calculator[] NPC_STD_CALCULATOR;
  5118.     static
  5119.     {
  5120.         NPC_STD_CALCULATOR = Formulas.getInstance().getStdNPCCalculators();
  5121.     }
  5122.    
  5123.     /** The _ai. */
  5124.     protected L2CharacterAI _ai;
  5125.    
  5126.     /** Future Skill Cast. */
  5127.     protected Future<?> _skillCast;
  5128.    
  5129.     /** Future Potion Cast. */
  5130.     protected Future<?> _potionCast;
  5131.    
  5132.     /** Char Coords from Client. */
  5133.     private int _clientX;
  5134.    
  5135.     /** The _client y. */
  5136.     private int _clientY;
  5137.    
  5138.     /** The _client z. */
  5139.     private int _clientZ;
  5140.    
  5141.     /** The _client heading. */
  5142.     private int _clientHeading;
  5143.    
  5144.     /** List of all QuestState instance that needs to be notified of this character's death. */
  5145.     private List<QuestState> _NotifyQuestOfDeathList = new FastList<>();
  5146.    
  5147.     /**
  5148.      * Add QuestState instance that is to be notified of character's death.<BR>
  5149.      * <BR>
  5150.      * @param qs The QuestState that subscribe to this event
  5151.      */
  5152.     public void addNotifyQuestOfDeath(final QuestState qs)
  5153.     {
  5154.         if (qs == null || _NotifyQuestOfDeathList.contains(qs))
  5155.             return;
  5156.        
  5157.         _NotifyQuestOfDeathList.add(qs);
  5158.     }
  5159.    
  5160.     /**
  5161.      * Return a list of L2Character that attacked.<BR>
  5162.      * <BR>
  5163.      * @return the notify quest of death
  5164.      */
  5165.     public final List<QuestState> getNotifyQuestOfDeath()
  5166.     {
  5167.         if (_NotifyQuestOfDeathList == null)
  5168.         {
  5169.             _NotifyQuestOfDeathList = new FastList<>();
  5170.         }
  5171.        
  5172.         return _NotifyQuestOfDeathList;
  5173.     }
  5174.    
  5175.     /**
  5176.      * Add a Func to the Calculator set of the L2Character.<BR>
  5177.      * <BR>
  5178.      * <B><U> Concept</U> :</B><BR>
  5179.      * <BR>
  5180.      * 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,
  5181.      * L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR>
  5182.      * <BR>
  5183.      * 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>
  5184.      * <BR>
  5185.      * <B><U> Actions</U> :</B><BR>
  5186.      * <BR>
  5187.      * <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>
  5188.      * <BR>
  5189.      * @param f The Func object to add to the Calculator corresponding to the state affected
  5190.      */
  5191.     public final synchronized void addStatFunc(final Func f)
  5192.     {
  5193.         if (f == null)
  5194.             return;
  5195.        
  5196.         // Check if Calculator set is linked to the standard Calculator set of NPC
  5197.         if (_calculators == NPC_STD_CALCULATOR)
  5198.         {
  5199.             // Create a copy of the standard NPC Calculator set
  5200.             _calculators = new Calculator[Stats.NUM_STATS];
  5201.            
  5202.             for (int i = 0; i < Stats.NUM_STATS; i++)
  5203.             {
  5204.                 if (NPC_STD_CALCULATOR[i] != null)
  5205.                 {
  5206.                     _calculators[i] = new Calculator(NPC_STD_CALCULATOR[i]);
  5207.                 }
  5208.             }
  5209.         }
  5210.        
  5211.         // Select the Calculator of the affected state in the Calculator set
  5212.         final int stat = f.stat.ordinal();
  5213.        
  5214.         if (_calculators[stat] == null)
  5215.         {
  5216.             _calculators[stat] = new Calculator();
  5217.         }
  5218.        
  5219.         // Add the Func to the calculator corresponding to the state
  5220.         _calculators[stat].addFunc(f);
  5221.        
  5222.     }
  5223.    
  5224.     /**
  5225.      * Add a list of Funcs to the Calculator set of the L2Character.<BR>
  5226.      * <BR>
  5227.      * <B><U> Concept</U> :</B><BR>
  5228.      * <BR>
  5229.      * 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>
  5230.      * <BR>
  5231.      * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method is ONLY for L2PcInstance</B></FONT><BR>
  5232.      * <BR>
  5233.      * <B><U> Example of use </U> :</B><BR>
  5234.      * <BR>
  5235.      * <li>Equip an item from inventory</li> <li>Learn a new passive skill</li> <li>Use an active skill</li><BR>
  5236.      * <BR>
  5237.      * @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
  5238.      */
  5239.     public final synchronized void addStatFuncs(final Func[] funcs)
  5240.     {
  5241.        
  5242.         FastList<Stats> modifiedStats = new FastList<>();
  5243.        
  5244.         for (final Func f : funcs)
  5245.         {
  5246.             modifiedStats.add(f.stat);
  5247.             addStatFunc(f);
  5248.         }
  5249.        
  5250.         broadcastModifiedStats(modifiedStats);
  5251.        
  5252.         modifiedStats = null;
  5253.     }
  5254.    
  5255.     /**
  5256.      * Remove a Func from the Calculator set of the L2Character.<BR>
  5257.      * <BR>
  5258.      * <B><U> Concept</U> :</B><BR>
  5259.      * <BR>
  5260.      * 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,
  5261.      * L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR>
  5262.      * <BR>
  5263.      * 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>
  5264.      * <BR>
  5265.      * <B><U> Actions</U> :</B><BR>
  5266.      * <BR>
  5267.      * <li>Remove the Func object from _calculators</li><BR>
  5268.      * <BR>
  5269.      * <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>
  5270.      * <BR>
  5271.      * @param f The Func object to remove from the Calculator corresponding to the state affected
  5272.      */
  5273.     public final synchronized void removeStatFunc(final Func f)
  5274.     {
  5275.         if (f == null)
  5276.             return;
  5277.        
  5278.         // Select the Calculator of the affected state in the Calculator set
  5279.         final int stat = f.stat.ordinal();
  5280.        
  5281.         if (_calculators[stat] == null)
  5282.             return;
  5283.        
  5284.         // Remove the Func object from the Calculator
  5285.         _calculators[stat].removeFunc(f);
  5286.        
  5287.         if (_calculators[stat].size() == 0)
  5288.         {
  5289.             _calculators[stat] = null;
  5290.         }
  5291.        
  5292.         // If possible, free the memory and just create a link on NPC_STD_CALCULATOR
  5293.         if (this instanceof L2NpcInstance)
  5294.         {
  5295.             int i = 0;
  5296.            
  5297.             for (; i < Stats.NUM_STATS; i++)
  5298.             {
  5299.                 if (!Calculator.equalsCals(_calculators[i], NPC_STD_CALCULATOR[i]))
  5300.                 {
  5301.                     break;
  5302.                 }
  5303.             }
  5304.            
  5305.             if (i >= Stats.NUM_STATS)
  5306.             {
  5307.                 _calculators = NPC_STD_CALCULATOR;
  5308.             }
  5309.         }
  5310.     }
  5311.    
  5312.     /**
  5313.      * Remove a list of Funcs from the Calculator set of the L2PcInstance.<BR>
  5314.      * <BR>
  5315.      * <B><U> Concept</U> :</B><BR>
  5316.      * <BR>
  5317.      * 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>
  5318.      * <BR>
  5319.      * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method is ONLY for L2PcInstance</B></FONT><BR>
  5320.      * <BR>
  5321.      * <B><U> Example of use </U> :</B><BR>
  5322.      * <BR>
  5323.      * <li>Unequip an item from inventory</li> <li>Stop an active skill</li><BR>
  5324.      * <BR>
  5325.      * @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
  5326.      */
  5327.     public final synchronized void removeStatFuncs(final Func[] funcs)
  5328.     {
  5329.        
  5330.         FastList<Stats> modifiedStats = new FastList<>();
  5331.        
  5332.         for (final Func f : funcs)
  5333.         {
  5334.             modifiedStats.add(f.stat);
  5335.             removeStatFunc(f);
  5336.         }
  5337.        
  5338.         broadcastModifiedStats(modifiedStats);
  5339.        
  5340.         modifiedStats = null;
  5341.     }
  5342.    
  5343.     /**
  5344.      * Remove all Func objects with the selected owner from the Calculator set of the L2Character.<BR>
  5345.      * <BR>
  5346.      * <B><U> Concept</U> :</B><BR>
  5347.      * <BR>
  5348.      * 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,
  5349.      * L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR>
  5350.      * <BR>
  5351.      * 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>
  5352.      * <BR>
  5353.      * <B><U> Actions</U> :</B><BR>
  5354.      * <BR>
  5355.      * <li>Remove all Func objects of the selected owner from _calculators</li><BR>
  5356.      * <BR>
  5357.      * <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>
  5358.      * <BR>
  5359.      * <B><U> Example of use </U> :</B><BR>
  5360.      * <BR>
  5361.      * <li>Unequip an item from inventory</li> <li>Stop an active skill</li><BR>
  5362.      * <BR>
  5363.      * @param owner The Object(Skill, Item...) that has created the effect
  5364.      */
  5365.     public final void removeStatsOwner(final Object owner)
  5366.     {
  5367.         FastList<Stats> modifiedStats = null;
  5368.        
  5369.         int i = 0;
  5370.         // Go through the Calculator set
  5371.         synchronized (_calculators)
  5372.         {
  5373.             for (final Calculator calc : _calculators)
  5374.             {
  5375.                 if (calc != null)
  5376.                 {
  5377.                     // Delete all Func objects of the selected owner
  5378.                     if (modifiedStats != null)
  5379.                     {
  5380.                         modifiedStats.addAll(calc.removeOwner(owner));
  5381.                     }
  5382.                     else
  5383.                     {
  5384.                         modifiedStats = calc.removeOwner(owner);
  5385.                     }
  5386.                    
  5387.                     if (calc.size() == 0)
  5388.                     {
  5389.                         _calculators[i] = null;
  5390.                     }
  5391.                 }
  5392.                 i++;
  5393.             }
  5394.            
  5395.             // If possible, free the memory and just create a link on NPC_STD_CALCULATOR
  5396.             if (this instanceof L2NpcInstance)
  5397.             {
  5398.                 i = 0;
  5399.                 for (; i < Stats.NUM_STATS; i++)
  5400.                 {
  5401.                     if (!Calculator.equalsCals(_calculators[i], NPC_STD_CALCULATOR[i]))
  5402.                     {
  5403.                         break;
  5404.                     }
  5405.                 }
  5406.                
  5407.                 if (i >= Stats.NUM_STATS)
  5408.                 {
  5409.                     _calculators = NPC_STD_CALCULATOR;
  5410.                 }
  5411.             }
  5412.            
  5413.             if (owner instanceof L2Effect && !((L2Effect) owner).preventExitUpdate)
  5414.             {
  5415.                 broadcastModifiedStats(modifiedStats);
  5416.             }
  5417.         }
  5418.        
  5419.         modifiedStats = null;
  5420.     }
  5421.    
  5422.     /**
  5423.      * Broadcast modified stats.
  5424.      * @param stats the stats
  5425.      */
  5426.     public void broadcastModifiedStats(final FastList<Stats> stats)
  5427.     {
  5428.         if (stats == null || stats.isEmpty())
  5429.             return;
  5430.        
  5431.         boolean broadcastFull = false;
  5432.         boolean otherStats = false;
  5433.         StatusUpdate su = null;
  5434.        
  5435.         for (final Stats stat : stats)
  5436.         {
  5437.             if (stat == Stats.POWER_ATTACK_SPEED)
  5438.             {
  5439.                 if (su == null)
  5440.                 {
  5441.                     su = new StatusUpdate(getObjectId());
  5442.                 }
  5443.                
  5444.                 su.addAttribute(StatusUpdate.ATK_SPD, getPAtkSpd());
  5445.             }
  5446.             else if (stat == Stats.MAGIC_ATTACK_SPEED)
  5447.             {
  5448.                 if (su == null)
  5449.                 {
  5450.                     su = new StatusUpdate(getObjectId());
  5451.                 }
  5452.                
  5453.                 su.addAttribute(StatusUpdate.CAST_SPD, getMAtkSpd());
  5454.             }
  5455.             // else if (stat==Stats.MAX_HP) //
  5456.             // {
  5457.             // if (su == null) su = new StatusUpdate(getObjectId());
  5458.             // su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
  5459.             // }
  5460.             else if (stat == Stats.MAX_CP)
  5461.             {
  5462.                 if (this instanceof L2PcInstance)
  5463.                 {
  5464.                     if (su == null)
  5465.                     {
  5466.                         su = new StatusUpdate(getObjectId());
  5467.                     }
  5468.                    
  5469.                     su.addAttribute(StatusUpdate.MAX_CP, getMaxCp());
  5470.                 }
  5471.             }
  5472.             // else if (stat==Stats.MAX_MP)
  5473.             // {
  5474.             // if (su == null) su = new StatusUpdate(getObjectId());
  5475.             // su.addAttribute(StatusUpdate.MAX_MP, getMaxMp());
  5476.             // }
  5477.             else if (stat == Stats.RUN_SPEED)
  5478.             {
  5479.                 broadcastFull = true;
  5480.             }
  5481.             else
  5482.             {
  5483.                 otherStats = true;
  5484.             }
  5485.         }
  5486.        
  5487.         if (this instanceof L2PcInstance)
  5488.         {
  5489.             if (broadcastFull)
  5490.             {
  5491.                 ((L2PcInstance) this).updateAndBroadcastStatus(2);
  5492.             }
  5493.             else
  5494.             {
  5495.                 if (otherStats)
  5496.                 {
  5497.                     ((L2PcInstance) this).updateAndBroadcastStatus(1);
  5498.                     if (su != null)
  5499.                     {
  5500.                         for (final L2PcInstance player : getKnownList().getKnownPlayers().values())
  5501.                         {
  5502.                             try
  5503.                             {
  5504.                                 player.sendPacket(su);
  5505.                             }
  5506.                             catch (final NullPointerException e)
  5507.                             {
  5508.                                 e.printStackTrace();
  5509.                             }
  5510.                         }
  5511.                     }
  5512.                 }
  5513.                 else if (su != null)
  5514.                 {
  5515.                     broadcastPacket(su);
  5516.                 }
  5517.             }
  5518.         }
  5519.         else if (this instanceof L2NpcInstance)
  5520.         {
  5521.             if (broadcastFull && getKnownList() != null && getKnownList().getKnownPlayers() != null)
  5522.             {
  5523.                 for (final L2PcInstance player : getKnownList().getKnownPlayers().values())
  5524.                     if (player != null)
  5525.                     {
  5526.                         player.sendPacket(new NpcInfo((L2NpcInstance) this, player));
  5527.                     }
  5528.             }
  5529.             else if (su != null)
  5530.             {
  5531.                 broadcastPacket(su);
  5532.             }
  5533.         }
  5534.         else if (this instanceof L2Summon)
  5535.         {
  5536.             if (broadcastFull)
  5537.             {
  5538.                 for (final L2PcInstance player : getKnownList().getKnownPlayers().values())
  5539.                     if (player != null)
  5540.                     {
  5541.                         player.sendPacket(new NpcInfo((L2Summon) this, player));
  5542.                     }
  5543.             }
  5544.             else if (su != null)
  5545.             {
  5546.                 broadcastPacket(su);
  5547.             }
  5548.         }
  5549.         else if (su != null)
  5550.         {
  5551.             broadcastPacket(su);
  5552.         }
  5553.        
  5554.         su = null;
  5555.     }
  5556.    
  5557.     /**
  5558.      * Return the orientation of the L2Character.<BR>
  5559.      * <BR>
  5560.      * @return the heading
  5561.      */
  5562.     public final int getHeading()
  5563.     {
  5564.         return _heading;
  5565.     }
  5566.    
  5567.     /**
  5568.      * Set the orientation of the L2Character.<BR>
  5569.      * <BR>
  5570.      * @param heading the new heading
  5571.      */
  5572.     public final void setHeading(final int heading)
  5573.     {
  5574.         _heading = heading;
  5575.     }
  5576.    
  5577.     /**
  5578.      * Return the X destination of the L2Character or the X position if not in movement.<BR>
  5579.      * <BR>
  5580.      * @return the client x
  5581.      */
  5582.     public final int getClientX()
  5583.     {
  5584.         return _clientX;
  5585.     }
  5586.    
  5587.     /**
  5588.      * Gets the client y.
  5589.      * @return the client y
  5590.      */
  5591.     public final int getClientY()
  5592.     {
  5593.         return _clientY;
  5594.     }
  5595.    
  5596.     /**
  5597.      * Gets the client z.
  5598.      * @return the client z
  5599.      */
  5600.     public final int getClientZ()
  5601.     {
  5602.         return _clientZ;
  5603.     }
  5604.    
  5605.     /**
  5606.      * Gets the client heading.
  5607.      * @return the client heading
  5608.      */
  5609.     public final int getClientHeading()
  5610.     {
  5611.         return _clientHeading;
  5612.     }
  5613.    
  5614.     /**
  5615.      * Sets the client x.
  5616.      * @param val the new client x
  5617.      */
  5618.     public final void setClientX(final int val)
  5619.     {
  5620.         _clientX = val;
  5621.     }
  5622.    
  5623.     /**
  5624.      * Sets the client y.
  5625.      * @param val the new client y
  5626.      */
  5627.     public final void setClientY(final int val)
  5628.     {
  5629.         _clientY = val;
  5630.     }
  5631.    
  5632.     /**
  5633.      * Sets the client z.
  5634.      * @param val the new client z
  5635.      */
  5636.     public final void setClientZ(final int val)
  5637.     {
  5638.         _clientZ = val;
  5639.     }
  5640.    
  5641.     /**
  5642.      * Sets the client heading.
  5643.      * @param val the new client heading
  5644.      */
  5645.     public final void setClientHeading(final int val)
  5646.     {
  5647.         _clientHeading = val;
  5648.     }
  5649.    
  5650.     /**
  5651.      * Gets the xdestination.
  5652.      * @return the xdestination
  5653.      */
  5654.     public final int getXdestination()
  5655.     {
  5656.         final MoveData m = _move;
  5657.        
  5658.         if (m != null)
  5659.             return m._xDestination;
  5660.        
  5661.         return getX();
  5662.     }
  5663.    
  5664.     /**
  5665.      * Return the Y destination of the L2Character or the Y position if not in movement.<BR>
  5666.      * <BR>
  5667.      * @return the ydestination
  5668.      */
  5669.     public final int getYdestination()
  5670.     {
  5671.         final MoveData m = _move;
  5672.        
  5673.         if (m != null)
  5674.             return m._yDestination;
  5675.        
  5676.         return getY();
  5677.     }
  5678.    
  5679.     /**
  5680.      * Return the Z destination of the L2Character or the Z position if not in movement.<BR>
  5681.      * <BR>
  5682.      * @return the zdestination
  5683.      */
  5684.     public final int getZdestination()
  5685.     {
  5686.         final MoveData m = _move;
  5687.        
  5688.         if (m != null)
  5689.             return m._zDestination;
  5690.        
  5691.         return getZ();
  5692.     }
  5693.    
  5694.     /**
  5695.      * Return True if the L2Character is in combat.<BR>
  5696.      * <BR>
  5697.      * @return true, if is in combat
  5698.      */
  5699.     public boolean isInCombat()
  5700.     {
  5701.         return (getAI().getAttackTarget() != null || getAI().isAutoAttacking());
  5702.     }
  5703.    
  5704.     /**
  5705.      * Return True if the L2Character is moving.<BR>
  5706.      * <BR>
  5707.      * @return true, if is moving
  5708.      */
  5709.     public final boolean isMoving()
  5710.     {
  5711.         return _move != null;
  5712.     }
  5713.    
  5714.     /**
  5715.      * Return True if the L2Character is travelling a calculated path.<BR>
  5716.      * <BR>
  5717.      * @return true, if is on geodata path
  5718.      */
  5719.     public final boolean isOnGeodataPath()
  5720.     {
  5721.         final MoveData move = _move;
  5722.        
  5723.         if (move == null)
  5724.             return false;
  5725.        
  5726.         try
  5727.         {
  5728.             if (move.onGeodataPathIndex == -1)
  5729.                 return false;
  5730.            
  5731.             if (move.onGeodataPathIndex == move.geoPath.length - 1)
  5732.                 return false;
  5733.         }
  5734.         catch (final NullPointerException e)
  5735.         {
  5736.             e.printStackTrace();
  5737.             return false;
  5738.         }
  5739.        
  5740.         return true;
  5741.     }
  5742.    
  5743.     /**
  5744.      * Return True if the L2Character is casting.<BR>
  5745.      * <BR>
  5746.      * @return true, if is casting now
  5747.      */
  5748.     public final boolean isCastingNow()
  5749.     {
  5750.        
  5751.         final L2Effect mog = getFirstEffect(L2Effect.EffectType.SIGNET_GROUND);
  5752.         if (mog != null)
  5753.         {
  5754.             return true;
  5755.         }
  5756.        
  5757.         return _castEndTime > GameTimeController.getGameTicks();
  5758.     }
  5759.    
  5760.     /**
  5761.      * Return True if the L2Character is casting.<BR>
  5762.      * <BR>
  5763.      * @return true, if is casting potion now
  5764.      */
  5765.     public final boolean isCastingPotionNow()
  5766.     {
  5767.         return _castPotionEndTime > GameTimeController.getGameTicks();
  5768.     }
  5769.    
  5770.     /**
  5771.      * Return True if the cast of the L2Character can be aborted.<BR>
  5772.      * <BR>
  5773.      * @return true, if successful
  5774.      */
  5775.     public final boolean canAbortCast()
  5776.     {
  5777.         return _castInterruptTime > GameTimeController.getGameTicks();
  5778.     }
  5779.    
  5780.     /**
  5781.      * Return True if the L2Character is attacking.<BR>
  5782.      * <BR>
  5783.      * @return true, if is attacking now
  5784.      */
  5785.     public final boolean isAttackingNow()
  5786.     {
  5787.         return _attackEndTime > GameTimeController.getGameTicks();
  5788.     }
  5789.    
  5790.     /**
  5791.      * Return True if the L2Character has aborted its attack.<BR>
  5792.      * <BR>
  5793.      * @return true, if is attack aborted
  5794.      */
  5795.     public final boolean isAttackAborted()
  5796.     {
  5797.         return _attacking <= 0;
  5798.     }
  5799.    
  5800.     /**
  5801.      * Abort the attack of the L2Character and send Server->Client ActionFailed packet.<BR>
  5802.      * <BR>
  5803.      * see com.l2jlegacy.gameserver.model.L2Character
  5804.      */
  5805.     public final void abortAttack()
  5806.     {
  5807.         if (isAttackingNow())
  5808.         {
  5809.             _attacking = 0;
  5810.             sendPacket(ActionFailed.STATIC_PACKET);
  5811.         }
  5812.     }
  5813.    
  5814.     /**
  5815.      * Returns body part (paperdoll slot) we are targeting right now.
  5816.      * @return the attacking body part
  5817.      */
  5818.     public final int getAttackingBodyPart()
  5819.     {
  5820.         return _attacking;
  5821.     }
  5822.    
  5823.     /**
  5824.      * Abort the cast of the L2Character and send Server->Client MagicSkillCanceld/ActionFailed packet.<BR>
  5825.      * <BR>
  5826.      */
  5827.     public final void abortCast()
  5828.     {
  5829.         abortCast(false);
  5830.        
  5831.     }
  5832.    
  5833.     /**
  5834.      * Abort the cast of the L2Character and send Server->Client MagicSkillCanceld/ActionFailed packet.<BR>
  5835.      * <BR>
  5836.      * @param force the force
  5837.      */
  5838.     public final void abortCast(final boolean force)
  5839.     {
  5840.         if (isCastingNow() || force)
  5841.         {
  5842.             _castEndTime = 0;
  5843.             _castInterruptTime = 0;
  5844.            
  5845.             if (_skillCast != null)
  5846.             {
  5847.                 _skillCast.cancel(true);
  5848.                 _skillCast = null;
  5849.             }
  5850.            
  5851.             if (getForceBuff() != null)
  5852.             {
  5853.                 getForceBuff().onCastAbort();
  5854.             }
  5855.            
  5856.             final L2Effect mog = getFirstEffect(L2Effect.EffectType.SIGNET_GROUND);
  5857.             if (mog != null)
  5858.             {
  5859.                 mog.exit(true);
  5860.             }
  5861.            
  5862.             // cancels the skill hit scheduled task
  5863.             enableAllSkills(); // re-enables the skills
  5864.             if (this instanceof L2PcInstance)
  5865.             {
  5866.                 getAI().notifyEvent(CtrlEvent.EVT_FINISH_CASTING); // setting back previous intention
  5867.             }
  5868.            
  5869.             broadcastPacket(new MagicSkillCanceld(getObjectId())); // broadcast packet to stop animations client-side
  5870.             sendPacket(ActionFailed.STATIC_PACKET); // send an "action failed" packet to the caster
  5871.            
  5872.         }
  5873.         /*
  5874.          * can't abort potion cast if(isCastingPotionNow()){ _castPotionEndTime = 0; _castPotionInterruptTime = 0; if(_potionCast != null) { _potionCast.cancel(true); _potionCast = null; } }
  5875.          */
  5876.     }
  5877.    
  5878.     /**
  5879.      * Update the position of the L2Character during a movement and return True if the movement is finished.<BR>
  5880.      * <BR>
  5881.      * <B><U> Concept</U> :</B><BR>
  5882.      * <BR>
  5883.      * 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>
  5884.      * <BR>
  5885.      * 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
  5886.      * 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>
  5887.      * <BR>
  5888.      * 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>
  5889.      * <BR>
  5890.      * <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>
  5891.      * <BR>
  5892.      * @param gameTicks Nb of ticks since the server start
  5893.      * @return True if the movement is finished
  5894.      */
  5895.     public boolean updatePosition(final int gameTicks)
  5896.     {
  5897.         // Get movement data
  5898.         final MoveData m = _move;
  5899.        
  5900.         if (m == null)
  5901.             return true;
  5902.        
  5903.         if (!isVisible())
  5904.         {
  5905.             _move = null;
  5906.             return true;
  5907.         }
  5908.        
  5909.         if (m._moveTimestamp == 0)
  5910.         {
  5911.             m._moveTimestamp = m._moveStartTime;
  5912.             m._xAccurate = getX();
  5913.             m._yAccurate = getY();
  5914.         }
  5915.        
  5916.         // Check if the position has alreday be calculated
  5917.         if (m._moveTimestamp == gameTicks)
  5918.             return false;
  5919.        
  5920.         final int xPrev = getX();
  5921.         final int yPrev = getY();
  5922.         int zPrev = getZ();
  5923.        
  5924.         double dx, dy, dz, distFraction;
  5925.         if (Config.COORD_SYNCHRONIZE == 1)
  5926.         // the only method that can modify x,y while moving (otherwise _move would/should be set null)
  5927.         {
  5928.             dx = m._xDestination - xPrev;
  5929.             dy = m._yDestination - yPrev;
  5930.         }
  5931.         else
  5932.         // otherwise we need saved temporary values to avoid rounding errors
  5933.         {
  5934.             dx = m._xDestination - m._xAccurate;
  5935.             dy = m._yDestination - m._yAccurate;
  5936.         }
  5937.         // Z coordinate will follow geodata or client values
  5938.         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
  5939.             && !(this instanceof L2BoatInstance))
  5940.         {
  5941.             final short geoHeight = GeoData.getInstance().getSpawnHeight(xPrev, yPrev, zPrev - 30, zPrev + 30, getObjectId());
  5942.             dz = m._zDestination - geoHeight;
  5943.             // quite a big difference, compare to validatePosition packet
  5944.             if (this instanceof L2PcInstance && Math.abs(((L2PcInstance) this).getClientZ() - geoHeight) > 200 && Math.abs(((L2PcInstance) this).getClientZ() - geoHeight) < 1500)
  5945.             {
  5946.                 dz = m._zDestination - zPrev; // allow diff
  5947.             }
  5948.             else if (isInCombat() && Math.abs(dz) > 200 && dx * dx + dy * dy < 40000) // allow mob to climb up to pcinstance
  5949.             {
  5950.                 dz = m._zDestination - zPrev; // climbing
  5951.             }
  5952.             else
  5953.             {
  5954.                 zPrev = geoHeight;
  5955.             }
  5956.         }
  5957.         else
  5958.         {
  5959.             dz = m._zDestination - zPrev;
  5960.         }
  5961.        
  5962.         float speed;
  5963.         if (this instanceof L2BoatInstance)
  5964.         {
  5965.             speed = ((L2BoatInstance) this).boatSpeed;
  5966.         }
  5967.         else
  5968.         {
  5969.             speed = getStat().getMoveSpeed();
  5970.         }
  5971.        
  5972.         final double distPassed = speed * (gameTicks - m._moveTimestamp) / GameTimeController.TICKS_PER_SECOND;
  5973.         if (dx * dx + dy * dy < 10000 && dz * dz > 2500) // close enough, allows error between client and server geodata if it cannot be avoided
  5974.         {
  5975.             distFraction = distPassed / Math.sqrt(dx * dx + dy * dy);
  5976.         }
  5977.         else
  5978.         {
  5979.             distFraction = distPassed / Math.sqrt(dx * dx + dy * dy + dz * dz);
  5980.         }
  5981.        
  5982.         // if (Config.DEVELOPER) LOGGER.warn("Move Ticks:" + (gameTicks - m._moveTimestamp) + ", distPassed:" + distPassed + ", distFraction:" + distFraction);
  5983.        
  5984.         if (distFraction > 1) // already there
  5985.         {
  5986.             // Set the position of the L2Character to the destination
  5987.             super.getPosition().setXYZ(m._xDestination, m._yDestination, m._zDestination);
  5988.             if (this instanceof L2BoatInstance)
  5989.             {
  5990.                 ((L2BoatInstance) this).updatePeopleInTheBoat(m._xDestination, m._yDestination, m._zDestination);
  5991.             }
  5992.             else
  5993.             {
  5994.                 revalidateZone();
  5995.             }
  5996.         }
  5997.         else
  5998.         {
  5999.             m._xAccurate += dx * distFraction;
  6000.             m._yAccurate += dy * distFraction;
  6001.            
  6002.             // Set the position of the L2Character to estimated after parcial move
  6003.             super.getPosition().setXYZ((int) m._xAccurate, (int) m._yAccurate, zPrev + (int) (dz * distFraction + 0.5));
  6004.             if (this instanceof L2BoatInstance)
  6005.             {
  6006.                 ((L2BoatInstance) this).updatePeopleInTheBoat((int) m._xAccurate, (int) m._yAccurate, zPrev + (int) (dz * distFraction + 0.5));
  6007.             }
  6008.             else
  6009.             {
  6010.                 revalidateZone();
  6011.             }
  6012.         }
  6013.        
  6014.         // Set the timer of last position update to now
  6015.         m._moveTimestamp = gameTicks;
  6016.        
  6017.         return distFraction > 1;
  6018.     }
  6019.    
  6020.     /**
  6021.      * Revalidate zone.
  6022.      */
  6023.     public void revalidateZone()
  6024.     {
  6025.         if (getWorldRegion() == null)
  6026.             return;
  6027.        
  6028.         getWorldRegion().revalidateZones(this);
  6029.     }
  6030.    
  6031.     /**
  6032.      * Stop movement of the L2Character (Called by AI Accessor only).<BR>
  6033.      * <BR>
  6034.      * <B><U> Actions</U> :</B><BR>
  6035.      * <BR>
  6036.      * <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
  6037.      * L2WorldRegion L2Characters</li><BR>
  6038.      * <BR>
  6039.      * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T send Server->Client packet StopMove/StopRotation </B></FONT><BR>
  6040.      * <BR>
  6041.      * @param pos the pos
  6042.      */
  6043.     public void stopMove(final L2CharPosition pos)
  6044.     {
  6045.         stopMove(pos, true);
  6046.     }
  6047.    
  6048.     /**
  6049.      * TODO: test broadcast head packets ffro !in boat.
  6050.      * @param pos the pos
  6051.      * @param updateKnownObjects the update known objects
  6052.      */
  6053.     public void stopMove(final L2CharPosition pos, final boolean updateKnownObjects)
  6054.     {
  6055.         // Delete movement data of the L2Character
  6056.         _move = null;
  6057.        
  6058.         // Set AI_INTENTION_IDLE
  6059.         if (this instanceof L2PcInstance && getAI() != null)
  6060.             ((L2PcInstance) this).getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  6061.        
  6062.         // Set the current position (x,y,z), its current L2WorldRegion if necessary and its heading
  6063.         // All data are contained in a L2CharPosition object
  6064.         if (pos != null)
  6065.         {
  6066.             getPosition().setXYZ(pos.x, pos.y, GeoData.getInstance().getHeight(pos.x, pos.y, pos.z));
  6067.             setHeading(pos.heading);
  6068.            
  6069.             if (this instanceof L2PcInstance)
  6070.             {
  6071.                 ((L2PcInstance) this).revalidateZone(true);
  6072.                
  6073.                 if (((L2PcInstance) this).isInBoat())
  6074.                     broadcastPacket(new ValidateLocationInVehicle(this));
  6075.             }
  6076.         }
  6077.        
  6078.         broadcastPacket(new StopMove(this));
  6079.        
  6080.         if (updateKnownObjects)
  6081.             ThreadPoolManager.getInstance().executeTask(new KnownListAsynchronousUpdateTask(this));
  6082.     }
  6083.    
  6084.     /**
  6085.      * Target a L2Object (add the target to the L2Character _target, _knownObject and L2Character to _KnownObject of the L2Object).<BR>
  6086.      * <BR>
  6087.      * <B><U> Concept</U> :</B><BR>
  6088.      * <BR>
  6089.      * The L2Object (including L2Character) targeted is identified in <B>_target</B> of the L2Character<BR>
  6090.      * <BR>
  6091.      * <B><U> Actions</U> :</B><BR>
  6092.      * <BR>
  6093.      * <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>
  6094.      * <BR>
  6095.      * <B><U> Overriden in </U> :</B><BR>
  6096.      * <BR>
  6097.      * <li>L2PcInstance : Remove the L2PcInstance from the old target _statusListener and add it to the new target if it was a L2Character</li><BR>
  6098.      * <BR>
  6099.      * @param object L2object to target
  6100.      */
  6101.     public void setTarget(L2Object object)
  6102.     {
  6103.         if (object != null && !object.isVisible())
  6104.         {
  6105.             object = null;
  6106.         }
  6107.        
  6108.         if (object != null && object != _target)
  6109.         {
  6110.             getKnownList().addKnownObject(object);
  6111.             object.getKnownList().addKnownObject(this);
  6112.         }
  6113.        
  6114.         // If object==null, Cancel Attak or Cast
  6115.         if (object == null)
  6116.         {
  6117.             if (_target != null)
  6118.             {
  6119.                 final TargetUnselected my = new TargetUnselected(this);
  6120.                
  6121.                 // No need to broadcast the packet to all players
  6122.                 if (this instanceof L2PcInstance)
  6123.                 {
  6124.                     // Send packet just to me and to party, not to any other that does not use the information
  6125.                     if (!this.isInParty())
  6126.                     {
  6127.                         this.sendPacket(my);
  6128.                     }
  6129.                     else
  6130.                     {
  6131.                         this.getParty().broadcastToPartyMembers(my);
  6132.                     }
  6133.                 }
  6134.                 else
  6135.                 {
  6136.                     sendPacket(new TargetUnselected(this));
  6137.                 }
  6138.             }
  6139.         }
  6140.        
  6141.         _target = object;
  6142.     }
  6143.    
  6144.     /**
  6145.      * Return the identifier of the L2Object targeted or -1.<BR>
  6146.      * <BR>
  6147.      * @return the target id
  6148.      */
  6149.     public final int getTargetId()
  6150.     {
  6151.         if (_target != null)
  6152.             return _target.getObjectId();
  6153.        
  6154.         return -1;
  6155.     }
  6156.    
  6157.     /**
  6158.      * Return the L2Object targeted or null.<BR>
  6159.      * <BR>
  6160.      * @return the target
  6161.      */
  6162.     public final L2Object getTarget()
  6163.     {
  6164.         return _target;
  6165.     }
  6166.    
  6167.     // called from AIAccessor only
  6168.     /**
  6169.      * Calculate movement data for a move to location action and add the L2Character to movingObjects of GameTimeController (only called by AI Accessor).<BR>
  6170.      * <BR>
  6171.      * <B><U> Concept</U> :</B><BR>
  6172.      * <BR>
  6173.      * 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>
  6174.      * <BR>
  6175.      * 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>
  6176.      * <BR>
  6177.      * <B><U> Actions</U> :</B><BR>
  6178.      * <BR>
  6179.      * <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
  6180.      * the GameTimeController</li> <li>Create a task to notify the AI that L2Character arrives at a check point of the movement</li><BR>
  6181.      * <BR>
  6182.      * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T send Server->Client packet MoveToPawn/CharMoveToLocation </B></FONT><BR>
  6183.      * <BR>
  6184.      * <B><U> Example of use </U> :</B><BR>
  6185.      * <BR>
  6186.      * <li>AI : onIntentionMoveTo(L2CharPosition), onIntentionPickUp(L2Object), onIntentionInteract(L2Object)</li> <li>FollowTask</li><BR>
  6187.      * <BR>
  6188.      * @param x The X position of the destination
  6189.      * @param y The Y position of the destination
  6190.      * @param z The Y position of the destination
  6191.      * @param offset The size of the interaction area of the L2Character targeted
  6192.      */
  6193.     protected void moveToLocation(int x, int y, int z, int offset)
  6194.     {
  6195.         // Block movment during Event start
  6196.         if (this instanceof L2PcInstance)
  6197.         {
  6198.             if (L2Event.active && ((L2PcInstance) this).eventSitForced)
  6199.             {
  6200.                 ((L2PcInstance) this).sendMessage("A dark force beyond your mortal understanding makes your knees to shake when you try to stand up...");
  6201.                 ((L2PcInstance) this).getClient().sendPacket(ActionFailed.STATIC_PACKET);
  6202.                 return;
  6203.             }
  6204.             else if ((TvT.is_sitForced() && ((L2PcInstance) this)._inEventTvT) || (CTF.is_sitForced() && ((L2PcInstance) this)._inEventCTF) || (DM.is_sitForced() && ((L2PcInstance) this)._inEventDM))
  6205.             {
  6206.                 ((L2PcInstance) this).sendMessage("A dark force beyond your mortal understanding makes your knees to shake when you try to stand up...");
  6207.                 ((L2PcInstance) this).getClient().sendPacket(ActionFailed.STATIC_PACKET);
  6208.                 return;
  6209.             }
  6210.             else if (VIP._sitForced && ((L2PcInstance) this)._inEventVIP)
  6211.             {
  6212.                 ((L2PcInstance) this).sendMessage("A dark force beyond your mortal understanding makes your knees to shake when you try to stand up...");
  6213.                 ((L2PcInstance) this).sendPacket(ActionFailed.STATIC_PACKET);
  6214.                 return;
  6215.             }
  6216.         }
  6217.        
  6218.         // when start to move again, it has to stop sitdown task
  6219.         if (this instanceof L2PcInstance)
  6220.             ((L2PcInstance) this).setPosticipateSit(false);
  6221.        
  6222.         // Fix archer bug with movment/hittask
  6223.         if (this instanceof L2PcInstance && this.isAttackingNow())
  6224.         {
  6225.             final L2ItemInstance rhand = ((L2PcInstance) this).getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  6226.             if ((rhand != null && rhand.getItemType() == L2WeaponType.BOW))
  6227.                 return;
  6228.         }
  6229.        
  6230.         // Get the Move Speed of the L2Charcater
  6231.         final float speed = getStat().getMoveSpeed();
  6232.        
  6233.         if (speed <= 0 || isMovementDisabled())
  6234.             return;
  6235.        
  6236.         // Get current position of the L2Character
  6237.         final int curX = super.getX();
  6238.         final int curY = super.getY();
  6239.         final int curZ = super.getZ();
  6240.        
  6241.         // Calculate distance (dx,dy) between current position and destination
  6242.         //
  6243.         double dx = x - curX;
  6244.         double dy = y - curY;
  6245.         double dz = z - curZ;
  6246.         double distance = Math.sqrt(dx * dx + dy * dy);
  6247.        
  6248.         if (Config.GEODATA > 0 && isInsideZone(ZONE_WATER) && distance > 700)
  6249.         {
  6250.             final double divider = 700 / distance;
  6251.             x = curX + (int) (divider * dx);
  6252.             y = curY + (int) (divider * dy);
  6253.             z = curZ + (int) (divider * dz);
  6254.             dx = x - curX;
  6255.             dy = y - curY;
  6256.             dz = z - curZ;
  6257.             distance = Math.sqrt(dx * dx + dy * dy);
  6258.         }
  6259.        
  6260.         /*
  6261.          * if(Config.DEBUG) { LOGGER.fine("distance to target:" + distance); }
  6262.       &nbs