L2AttackableAI.java 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.ai;
  16. import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
  17. import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
  18. import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
  19. import java.util.Collection;
  20. import java.util.concurrent.Future;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.GameTimeController;
  23. import com.l2jserver.gameserver.GeoData;
  24. import com.l2jserver.gameserver.Territory;
  25. import com.l2jserver.gameserver.ThreadPoolManager;
  26. import com.l2jserver.gameserver.datatables.NpcTable;
  27. import com.l2jserver.gameserver.instancemanager.DimensionalRiftManager;
  28. import com.l2jserver.gameserver.model.L2CharPosition;
  29. import com.l2jserver.gameserver.model.L2Object;
  30. import com.l2jserver.gameserver.model.L2Skill;
  31. import com.l2jserver.gameserver.model.L2Skill.SkillTargetType;
  32. import com.l2jserver.gameserver.model.actor.L2Attackable;
  33. import com.l2jserver.gameserver.model.actor.L2Character;
  34. import com.l2jserver.gameserver.model.actor.L2Npc;
  35. import com.l2jserver.gameserver.model.actor.L2Playable;
  36. import com.l2jserver.gameserver.model.actor.L2Summon;
  37. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  38. import com.l2jserver.gameserver.model.actor.instance.L2FestivalMonsterInstance;
  39. import com.l2jserver.gameserver.model.actor.instance.L2FriendlyMobInstance;
  40. import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  41. import com.l2jserver.gameserver.model.actor.instance.L2GuardInstance;
  42. import com.l2jserver.gameserver.model.actor.instance.L2MinionInstance;
  43. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  44. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  45. import com.l2jserver.gameserver.model.actor.instance.L2RaidBossInstance;
  46. import com.l2jserver.gameserver.model.actor.instance.L2RiftInvaderInstance;
  47. import com.l2jserver.gameserver.model.quest.Quest;
  48. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  49. import com.l2jserver.gameserver.templates.skills.L2EffectType;
  50. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  51. import com.l2jserver.gameserver.util.Util;
  52. import com.l2jserver.util.Rnd;
  53. /**
  54. * This class manages AI of L2Attackable.<BR><BR>
  55. *
  56. */
  57. public class L2AttackableAI extends L2CharacterAI implements Runnable
  58. {
  59. //protected static final Logger _log = Logger.getLogger(L2AttackableAI.class.getName());
  60. private static final int RANDOM_WALK_RATE = 30; // confirmed
  61. // private static final int MAX_DRIFT_RANGE = 300;
  62. private static final int MAX_ATTACK_TIMEOUT = 300; // int ticks, i.e. 30 seconds
  63. /** The L2Attackable AI task executed every 1s (call onEvtThink method)*/
  64. private Future<?> _aiTask;
  65. /** The delay after which the attacked is stopped */
  66. private int _attackTimeout;
  67. /** The L2Attackable aggro counter */
  68. private int _globalAggro;
  69. /** The flag used to indicate that a thinking action is in progress */
  70. private boolean _thinking; // to prevent recursive thinking
  71. private String clan;
  72. private String enemyClan;
  73. private int timepass = 0;
  74. private int chaostime = 0;
  75. private L2NpcTemplate _skillrender;
  76. int lastBuffTick;
  77. /**
  78. * Constructor of L2AttackableAI.<BR><BR>
  79. *
  80. * @param accessor The AI accessor of the L2Character
  81. *
  82. */
  83. public L2AttackableAI(L2Character.AIAccessor accessor)
  84. {
  85. super(accessor);
  86. _skillrender = NpcTable.getInstance().getTemplate(((L2Npc)_actor).getTemplate().npcId);
  87. //_selfAnalysis.init();
  88. _attackTimeout = Integer.MAX_VALUE;
  89. _globalAggro = -10; // 10 seconds timeout of ATTACK after respawn
  90. if (((L2Attackable)_actor).getEnemyClan() != "none")
  91. setEnemyClan(((L2Attackable)_actor).getEnemyClan());
  92. }
  93. public void run()
  94. {
  95. // Launch actions corresponding to the Event Think
  96. onEvtThink();
  97. }
  98. /**
  99. * Return True if the target is autoattackable (depends on the actor type).<BR><BR>
  100. *
  101. * <B><U> Actor is a L2GuardInstance</U> :</B><BR><BR>
  102. * <li>The target isn't a Folk or a Door</li>
  103. * <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
  104. * <li>The target is in the actor Aggro range and is at the same height</li>
  105. * <li>The L2PcInstance target has karma (=PK)</li>
  106. * <li>The L2MonsterInstance target is aggressive</li><BR><BR>
  107. *
  108. * <B><U> Actor is a L2SiegeGuardInstance</U> :</B><BR><BR>
  109. * <li>The target isn't a Folk or a Door</li>
  110. * <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
  111. * <li>The target is in the actor Aggro range and is at the same height</li>
  112. * <li>A siege is in progress</li>
  113. * <li>The L2PcInstance target isn't a Defender</li><BR><BR>
  114. *
  115. * <B><U> Actor is a L2FriendlyMobInstance</U> :</B><BR><BR>
  116. * <li>The target isn't a Folk, a Door or another L2Npc</li>
  117. * <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
  118. * <li>The target is in the actor Aggro range and is at the same height</li>
  119. * <li>The L2PcInstance target has karma (=PK)</li><BR><BR>
  120. *
  121. * <B><U> Actor is a L2MonsterInstance</U> :</B><BR><BR>
  122. * <li>The target isn't a Folk, a Door or another L2Npc</li>
  123. * <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
  124. * <li>The target is in the actor Aggro range and is at the same height</li>
  125. * <li>The actor is Aggressive</li><BR><BR>
  126. *
  127. * @param target The targeted L2Object
  128. *
  129. */
  130. private boolean autoAttackCondition(L2Character target)
  131. {
  132. if (target == null || _actor == null)
  133. return false;
  134. L2Attackable me = (L2Attackable) _actor;
  135. if(target instanceof L2Attackable)
  136. {
  137. setClan(((L2Attackable)target).getClan());
  138. }
  139. // Check if the target isn't invulnerable
  140. if (target.isInvul())
  141. {
  142. // However EffectInvincible requires to check GMs specially
  143. if (target instanceof L2PcInstance && ((L2PcInstance)target).isGM())
  144. return false;
  145. if (target instanceof L2Summon && ((L2Summon)target).getOwner().isGM())
  146. return false;
  147. }
  148. // Check if the target isn't a Folk or a Door
  149. if (target instanceof L2DoorInstance) return false;
  150. // Check if the target isn't dead, is in the Aggro range and is at the same height
  151. if (target.isAlikeDead() || (target instanceof L2PcInstance && !me.isInsideRadius(target, me.getAggroRange(), false, false))
  152. || Math.abs(me.getZ() - target.getZ()) > 300 || (target instanceof L2Summon && !me.isInsideRadius(target, me.getAggroRange(), false, false))) return false;
  153. // Check if the target is a L2PlayableInstance
  154. if (target instanceof L2Playable)
  155. {
  156. // Check if the AI isn't a Raid Boss, can See Silent Moving players and the target isn't in silent move mode
  157. if (!(me.isRaid()) && !(me.canSeeThroughSilentMove()) && ((L2Playable)target).isSilentMoving())
  158. return false;
  159. }
  160. // Check if the target is a L2PcInstance
  161. if (target instanceof L2PcInstance)
  162. {
  163. // Don't take the aggro if the GM has the access level below or equal to GM_DONT_TAKE_AGGRO
  164. if (((L2PcInstance)target).isGM() && !((L2PcInstance)target).getAccessLevel().canTakeAggro())
  165. return false;
  166. // TODO: Ideally, autoattack condition should be called from the AI script. In that case,
  167. // it should only implement the basic behaviors while the script will add more specific
  168. // behaviors (like varka/ketra alliance, etc). Once implemented, remove specialized stuff
  169. // from this location. (Fulminus)
  170. // Check if player is an ally (comparing mem addr)
  171. if ("varka".equals(me.getFactionId()) && ((L2PcInstance) target).isAlliedWithVarka())
  172. return false;
  173. if ("ketra".equals(me.getFactionId()) && ((L2PcInstance) target).isAlliedWithKetra())
  174. return false;
  175. // check if the target is within the grace period for JUST getting up from fake death
  176. if (((L2PcInstance) target).isRecentFakeDeath())
  177. return false;
  178. if (target.isInParty() && target.getParty().isInDimensionalRift())
  179. {
  180. byte riftType = target.getParty().getDimensionalRift().getType();
  181. byte riftRoom = target.getParty().getDimensionalRift().getCurrentRoom();
  182. if (me instanceof L2RiftInvaderInstance && !DimensionalRiftManager.getInstance().getRoom(riftType, riftRoom).checkIfInZone(me.getX(), me.getY(), me.getZ()))
  183. return false;
  184. }
  185. //if (_selfAnalysis.cannotMoveOnLand && !target.isInsideZone(L2Character.ZONE_WATER))
  186. // return false;
  187. }
  188. // Check if the target is a L2Summon
  189. if (target instanceof L2Summon)
  190. {
  191. L2PcInstance owner = ((L2Summon)target).getOwner();
  192. if (owner != null)
  193. {
  194. // Don't take the aggro if the GM has the access level below or equal to GM_DONT_TAKE_AGGRO
  195. if (owner.isGM() && (owner.isInvul() || !owner.getAccessLevel().canTakeAggro()))
  196. return false;
  197. // Check if player is an ally (comparing mem addr)
  198. if ("varka".equals(me.getFactionId()) && owner.isAlliedWithVarka())
  199. return false;
  200. if ("ketra".equals(me.getFactionId()) && owner.isAlliedWithKetra())
  201. return false;
  202. }
  203. }
  204. // Check if the actor is a L2GuardInstance
  205. if (_actor instanceof L2GuardInstance)
  206. {
  207. // Check if the L2PcInstance target has karma (=PK)
  208. if (target instanceof L2PcInstance && ((L2PcInstance) target).getKarma() > 0)
  209. // Los Check
  210. return GeoData.getInstance().canSeeTarget(me, target);
  211. //if (target instanceof L2Summon)
  212. // return ((L2Summon)target).getKarma() > 0;
  213. // Check if the L2MonsterInstance target is aggressive
  214. if (target instanceof L2MonsterInstance && Config.GUARD_ATTACK_AGGRO_MOB)
  215. return (((L2MonsterInstance) target).isAggressive() && GeoData.getInstance().canSeeTarget(me, target));
  216. return false;
  217. }
  218. else if (_actor instanceof L2FriendlyMobInstance)
  219. { // the actor is a L2FriendlyMobInstance
  220. // Check if the target isn't another L2Npc
  221. if (target instanceof L2Npc)
  222. return false;
  223. // Check if the L2PcInstance target has karma (=PK)
  224. if (target instanceof L2PcInstance && ((L2PcInstance) target).getKarma() > 0)
  225. return GeoData.getInstance().canSeeTarget(me, target); // Los Check
  226. else
  227. return false;
  228. }
  229. else
  230. {
  231. if(target instanceof L2Attackable)
  232. {
  233. if ("none".equals(((L2Attackable)_actor).getEnemyClan()) || "none".equals(((L2Attackable)target).getClan()))
  234. return false;
  235. if (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)target).getClan()))
  236. {
  237. if (_actor.isInsideRadius(target, ((L2Attackable)_actor).getEnemyRange(), false, false))
  238. {
  239. return GeoData.getInstance().canSeeTarget(_actor, target);
  240. }
  241. else return false;
  242. }
  243. if (((L2Attackable)_actor).getIsChaos() > 0 && me.isInsideRadius(target, ((L2Attackable)_actor).getIsChaos(), false, false) )
  244. {
  245. if (((L2Attackable)_actor).getFactionId() != null && ((L2Attackable)_actor).getFactionId().equals(((L2Attackable) target).getFactionId()))
  246. {
  247. return false;
  248. }
  249. // Los Check
  250. return GeoData.getInstance().canSeeTarget(me, target);
  251. }
  252. }
  253. if (target instanceof L2Attackable || target instanceof L2Npc)
  254. return false;
  255. // depending on config, do not allow mobs to attack _new_ players in peacezones,
  256. // unless they are already following those players from outside the peacezone.
  257. if (!Config.ALT_MOB_AGRO_IN_PEACEZONE && target.isInsideZone(L2Character.ZONE_PEACE))
  258. return false;
  259. if (me.isChampion() && Config.L2JMOD_CHAMPION_PASSIVE)
  260. return false;
  261. // Check if the actor is Aggressive
  262. return (me.isAggressive() && GeoData.getInstance().canSeeTarget(me, target));
  263. }
  264. }
  265. public void startAITask()
  266. {
  267. // If not idle - create an AI task (schedule onEvtThink repeatedly)
  268. if (_aiTask == null)
  269. {
  270. _aiTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(this, 1000, 1000);
  271. }
  272. }
  273. public void stopAITask()
  274. {
  275. if (_aiTask != null)
  276. {
  277. _aiTask.cancel(false);
  278. _aiTask = null;
  279. }
  280. }
  281. @Override
  282. protected void onEvtDead()
  283. {
  284. stopAITask();
  285. super.onEvtDead();
  286. }
  287. /**
  288. * Set the Intention of this L2CharacterAI and create an AI Task executed every 1s (call onEvtThink method) for this L2Attackable.<BR><BR>
  289. *
  290. * <FONT COLOR=#FF0000><B> <U>Caution</U> : If actor _knowPlayer isn't EMPTY, AI_INTENTION_IDLE will be change in AI_INTENTION_ACTIVE</B></FONT><BR><BR>
  291. *
  292. * @param intention The new Intention to set to the AI
  293. * @param arg0 The first parameter of the Intention
  294. * @param arg1 The second parameter of the Intention
  295. *
  296. */
  297. @Override
  298. synchronized void changeIntention(CtrlIntention intention, Object arg0, Object arg1)
  299. {
  300. if (intention == AI_INTENTION_IDLE || intention == AI_INTENTION_ACTIVE)
  301. {
  302. // Check if actor is not dead
  303. if (!_actor.isAlikeDead())
  304. {
  305. L2Attackable npc = (L2Attackable) _actor;
  306. // If its _knownPlayer isn't empty set the Intention to AI_INTENTION_ACTIVE
  307. if (!npc.getKnownList().getKnownPlayers().isEmpty())
  308. intention = AI_INTENTION_ACTIVE;
  309. else
  310. {
  311. if (npc.getSpawn() != null)
  312. {
  313. final int range = Config.MAX_DRIFT_RANGE;
  314. if (!npc.isInsideRadius(npc.getSpawn().getLocx(), npc.getSpawn().getLocy(), npc.getSpawn().getLocz(), range + range, true, false))
  315. intention = AI_INTENTION_ACTIVE;
  316. }
  317. }
  318. }
  319. if (intention == AI_INTENTION_IDLE)
  320. {
  321. // Set the Intention of this L2AttackableAI to AI_INTENTION_IDLE
  322. super.changeIntention(AI_INTENTION_IDLE, null, null);
  323. // Stop AI task and detach AI from NPC
  324. if (_aiTask != null)
  325. {
  326. _aiTask.cancel(true);
  327. _aiTask = null;
  328. }
  329. // Cancel the AI
  330. _accessor.detachAI();
  331. return;
  332. }
  333. }
  334. // Set the Intention of this L2AttackableAI to intention
  335. super.changeIntention(intention, arg0, arg1);
  336. // If not idle - create an AI task (schedule onEvtThink repeatedly)
  337. startAITask();
  338. }
  339. /**
  340. * Manage the Attack Intention : Stop current Attack (if necessary), Calculate attack timeout, Start a new Attack and Launch Think Event.<BR><BR>
  341. *
  342. * @param target The L2Character to attack
  343. *
  344. */
  345. @Override
  346. protected void onIntentionAttack(L2Character target)
  347. {
  348. // Calculate the attack timeout
  349. _attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks();
  350. // self and buffs
  351. if (lastBuffTick+30 < GameTimeController.getGameTicks())
  352. {
  353. if(_skillrender.hasBuffSkill())
  354. for (L2Skill sk : _skillrender._buffskills)
  355. if (Cast(sk))
  356. break;
  357. lastBuffTick = GameTimeController.getGameTicks();
  358. }
  359. // Manage the Attack Intention : Stop current Attack (if necessary), Start a new Attack and Launch Think Event
  360. super.onIntentionAttack(target);
  361. }
  362. /**
  363. * Manage AI standard thinks of a L2Attackable (called by onEvtThink).<BR><BR>
  364. *
  365. * <B><U> Actions</U> :</B><BR><BR>
  366. * <li>Update every 1s the _globalAggro counter to come close to 0</li>
  367. * <li>If the actor is Aggressive and can attack, add all autoAttackable L2Character in its Aggro Range to its _aggroList, chose a target and order to attack it</li>
  368. * <li>If the actor is a L2GuardInstance that can't attack, order to it to return to its home location</li>
  369. * <li>If the actor is a L2MonsterInstance that can't attack, order to it to random walk (1/100)</li><BR><BR>
  370. *
  371. */
  372. private void thinkActive()
  373. {
  374. L2Attackable npc = (L2Attackable) _actor;
  375. // Update every 1s the _globalAggro counter to come close to 0
  376. if (_globalAggro != 0)
  377. {
  378. if (_globalAggro < 0)
  379. _globalAggro++;
  380. else
  381. _globalAggro--;
  382. }
  383. // Add all autoAttackable L2Character in L2Attackable Aggro Range to its _aggroList with 0 damage and 1 hate
  384. // A L2Attackable isn't aggressive during 10s after its spawn because _globalAggro is set to -10
  385. if (_globalAggro >= 0)
  386. {
  387. // Get all visible objects inside its Aggro Range
  388. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  389. //synchronized (npc.getKnownList().getKnownObjects())
  390. {
  391. for (L2Object obj : objs)
  392. {
  393. if (!(obj instanceof L2Character))
  394. continue;
  395. L2Character target = (L2Character) obj;
  396. /*
  397. * Check to see if this is a festival mob spawn.
  398. * If it is, then check to see if the aggro trigger
  399. * is a festival participant...if so, move to attack it.
  400. */
  401. if ((_actor instanceof L2FestivalMonsterInstance) && obj instanceof L2PcInstance)
  402. {
  403. L2PcInstance targetPlayer = (L2PcInstance) obj;
  404. if (!(targetPlayer.isFestivalParticipant()))
  405. continue;
  406. }
  407. // TODO: The AI Script ought to handle aggro behaviors in onSee. Once implemented, aggro behaviors ought
  408. // to be removed from here. (Fulminus)
  409. // For each L2Character check if the target is autoattackable
  410. if (autoAttackCondition(target)) // check aggression
  411. {
  412. // Get the hate level of the L2Attackable against this L2Character target contained in _aggroList
  413. int hating = npc.getHating(target);
  414. // Add the attacker to the L2Attackable _aggroList with 0 damage and 1 hate
  415. if (hating == 0)
  416. npc.addDamageHate(target, 0, 0);
  417. }
  418. }
  419. }
  420. // Chose a target from its aggroList
  421. L2Character hated;
  422. if (_actor.isConfused())
  423. hated = getAttackTarget(); // effect handles selection
  424. else
  425. hated = npc.getMostHated();
  426. // Order to the L2Attackable to attack the target
  427. if (hated != null)
  428. {
  429. // Get the hate level of the L2Attackable against this L2Character target contained in _aggroList
  430. int aggro = npc.getHating(hated);
  431. if (aggro + _globalAggro > 0)
  432. {
  433. // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  434. if (!_actor.isRunning())
  435. _actor.setRunning();
  436. // Set the AI Intention to AI_INTENTION_ATTACK
  437. setIntention(CtrlIntention.AI_INTENTION_ATTACK, hated);
  438. }
  439. return;
  440. }
  441. }
  442. // Check if the actor is a L2GuardInstance
  443. if (_actor instanceof L2GuardInstance)
  444. {
  445. // Order to the L2GuardInstance to return to its home location because there's no target to attack
  446. ((L2GuardInstance) _actor).returnHome();
  447. }
  448. // If this is a festival monster, then it remains in the same location.
  449. if (_actor instanceof L2FestivalMonsterInstance)
  450. return;
  451. // Check if the mob should not return to spawn point
  452. if (!npc.canReturnToSpawnPoint())
  453. return;
  454. // Minions following leader
  455. if (_actor instanceof L2MinionInstance && ((L2MinionInstance) _actor).getLeader() != null)
  456. {
  457. int offset;
  458. if (_actor.isRaidMinion())
  459. offset = 500; // for Raids - need correction
  460. else
  461. offset = 200; // for normal minions - need correction :)
  462. if (((L2MinionInstance) _actor).getLeader().isRunning())
  463. _actor.setRunning();
  464. else
  465. _actor.setWalking();
  466. if (_actor.getPlanDistanceSq(((L2MinionInstance) _actor).getLeader()) > offset * offset)
  467. {
  468. int x1, y1, z1;
  469. x1 = ((L2MinionInstance) _actor).getLeader().getX() + Rnd.nextInt((offset - 30) * 2) - (offset - 30);
  470. y1 = ((L2MinionInstance) _actor).getLeader().getY() + Rnd.nextInt((offset - 30) * 2) - (offset - 30);
  471. z1 = ((L2MinionInstance) _actor).getLeader().getZ();
  472. // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
  473. moveTo(x1, y1, z1);
  474. return;
  475. }
  476. else if (Rnd.nextInt(RANDOM_WALK_RATE) == 0)
  477. {
  478. if(_skillrender.hasBuffSkill())
  479. for (L2Skill sk : _skillrender._buffskills)
  480. if (Cast(sk))
  481. return;
  482. }
  483. }
  484. // Order to the L2MonsterInstance to random walk (1/100)
  485. else if (npc.getSpawn() != null && Rnd.nextInt(RANDOM_WALK_RATE) == 0
  486. && !_actor.isNoRndWalk())
  487. {
  488. int x1, y1, z1;
  489. final int range = Config.MAX_DRIFT_RANGE;
  490. if(_skillrender.hasBuffSkill())
  491. for (L2Skill sk : _skillrender._buffskills)
  492. if (Cast(sk))
  493. return;
  494. // If NPC with random coord in territory
  495. if (npc.getSpawn().getLocx() == 0 && npc.getSpawn().getLocy() == 0)
  496. {
  497. // Calculate a destination point in the spawn area
  498. int p[] = Territory.getInstance().getRandomPoint(npc.getSpawn().getLocation());
  499. x1 = p[0];
  500. y1 = p[1];
  501. z1 = p[2];
  502. // Calculate the distance between the current position of the L2Character and the target (x,y)
  503. double distance2 = _actor.getPlanDistanceSq(x1, y1);
  504. if (distance2 > (range + range) * (range + range))
  505. {
  506. npc.setisReturningToSpawnPoint(true);
  507. float delay = (float) Math.sqrt(distance2) / range;
  508. x1 = _actor.getX() + (int) ((x1 - _actor.getX()) / delay);
  509. y1 = _actor.getY() + (int) ((y1 - _actor.getY()) / delay);
  510. }
  511. // If NPC with random fixed coord, don't move (unless needs to return to spawnpoint)
  512. if (Territory.getInstance().getProcMax(npc.getSpawn().getLocation()) > 0 && !npc.isReturningToSpawnPoint())
  513. return;
  514. }
  515. else
  516. {
  517. // If NPC with fixed coord
  518. x1 = npc.getSpawn().getLocx();
  519. y1 = npc.getSpawn().getLocy();
  520. z1 = npc.getSpawn().getLocz();
  521. if (!_actor.isInsideRadius(x1, y1, z1, range + range, true, false))
  522. npc.setisReturningToSpawnPoint(true);
  523. else
  524. {
  525. x1 += Rnd.nextInt(range * 2) - range;
  526. y1 += Rnd.nextInt(range * 2) - range;
  527. z1 = npc.getZ();
  528. }
  529. }
  530. //_log.config("Curent pos ("+getX()+", "+getY()+"), moving to ("+x1+", "+y1+").");
  531. // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
  532. moveTo(x1, y1, z1);
  533. }
  534. }
  535. /**
  536. * Manage AI attack thinks of a L2Attackable (called by onEvtThink).<BR><BR>
  537. *
  538. * <B><U> Actions</U> :</B><BR><BR>
  539. * <li>Update the attack timeout if actor is running</li>
  540. * <li>If target is dead or timeout is expired, stop this attack and set the Intention to AI_INTENTION_ACTIVE</li>
  541. * <li>Call all L2Object of its Faction inside the Faction Range</li>
  542. * <li>Chose a target and order to attack it with magic skill or physical attack</li><BR><BR>
  543. *
  544. * TODO: Manage casting rules to healer mobs (like Ant Nurses)
  545. *
  546. */
  547. private void thinkAttack()
  548. {
  549. if (_attackTimeout < GameTimeController.getGameTicks())
  550. {
  551. // Check if the actor is running
  552. if (_actor.isRunning())
  553. {
  554. // Set the actor movement type to walk and send Server->Client packet ChangeMoveType to all others L2PcInstance
  555. _actor.setWalking();
  556. // Calculate a new attack timeout
  557. _attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks();
  558. }
  559. }
  560. if (_actor.isCastingNow())
  561. return;
  562. L2Character originalAttackTarget = getAttackTarget();
  563. // Check if target is dead or if timeout is expired to stop this attack
  564. if (originalAttackTarget == null || originalAttackTarget.isAlikeDead()
  565. || _attackTimeout < GameTimeController.getGameTicks())
  566. {
  567. // Stop hating this target after the attack timeout or if target is dead
  568. if (originalAttackTarget != null)
  569. ((L2Attackable) _actor).stopHating(originalAttackTarget);
  570. // Set the AI Intention to AI_INTENTION_ACTIVE
  571. setIntention(AI_INTENTION_ACTIVE);
  572. _actor.setWalking();
  573. return;
  574. }
  575. // Handle all L2Object of its Faction inside the Faction Range
  576. if (((L2Npc) _actor).getFactionId() != null)
  577. {
  578. String faction_id = ((L2Npc) _actor).getFactionId();
  579. // Go through all L2Object that belong to its faction
  580. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  581. //synchronized (_actor.getKnownList().getKnownObjects())
  582. {
  583. for (L2Object obj : objs)
  584. {
  585. if (obj instanceof L2Npc)
  586. {
  587. L2Npc npc = (L2Npc) obj;
  588. //Handle SevenSigns mob Factions
  589. String npcfaction = npc.getFactionId();
  590. boolean sevenSignFaction = false;
  591. // TODO: Unhardcode this by AI scripts (DrHouse)
  592. //Catacomb mobs should assist lilim and nephilim other than dungeon
  593. if ("c_dungeon_clan".equals(faction_id) &&
  594. ("c_dungeon_lilim".equals(npcfaction) || "c_dungeon_nephi".equals(npcfaction)))
  595. sevenSignFaction = true;
  596. //Lilim mobs should assist other Lilim and catacomb mobs
  597. else if ("c_dungeon_lilim".equals(faction_id) &&
  598. "c_dungeon_clan".equals(npcfaction))
  599. sevenSignFaction = true;
  600. //Nephilim mobs should assist other Nephilim and catacomb mobs
  601. else if ("c_dungeon_nephi".equals(faction_id) &&
  602. "c_dungeon_clan".equals(npcfaction))
  603. sevenSignFaction = true;
  604. if (!faction_id.equals(npc.getFactionId()) && !sevenSignFaction)
  605. continue;
  606. // Check if the L2Object is inside the Faction Range of
  607. // the actor
  608. if (_actor.isInsideRadius(npc, npc.getFactionRange() + npc.getTemplate().collisionRadius, true, false) && npc.getAI() != null)
  609. {
  610. if (Math.abs(originalAttackTarget.getZ() - npc.getZ()) < 600 && _actor.getAttackByList().contains(originalAttackTarget)
  611. && (npc.getAI()._intention == CtrlIntention.AI_INTENTION_IDLE || npc.getAI()._intention == CtrlIntention.AI_INTENTION_ACTIVE) && GeoData.getInstance().canSeeTarget(_actor, npc))
  612. {
  613. if ((originalAttackTarget instanceof L2PcInstance) || (originalAttackTarget instanceof L2Summon))
  614. {
  615. if (npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_FACTION_CALL) != null)
  616. {
  617. L2PcInstance player = (originalAttackTarget instanceof L2PcInstance) ? (L2PcInstance) originalAttackTarget : ((L2Summon) originalAttackTarget).getOwner();
  618. for (Quest quest : npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_FACTION_CALL))
  619. quest.notifyFactionCall(npc, (L2Npc) _actor, player, (originalAttackTarget instanceof L2Summon));
  620. }
  621. }
  622. else if (npc instanceof L2Attackable && getAttackTarget() != null && npc.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
  623. {
  624. ((L2Attackable)npc).addDamageHate(getAttackTarget(), 0, ((L2Attackable)_actor).getHating(getAttackTarget()));
  625. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK,getAttackTarget());
  626. }
  627. }
  628. }
  629. }
  630. }
  631. }
  632. }
  633. /*
  634. if(_actor.getTarget() == null || this.getAttackTarget() == null || this.getAttackTarget().isDead() || ctarget == _actor)
  635. AggroReconsider();
  636. */
  637. //----------------------------------------------------------------
  638. //------------------------------------------------------------------------------
  639. //Initialize data
  640. double dist = 0;
  641. int dist2 = 0;
  642. int range = 0;
  643. L2Character MostHate = ((L2Attackable) _actor).getMostHated();
  644. //L2Character ctarget = (L2Character)_actor.getTarget();
  645. try
  646. {
  647. setAttackTarget(MostHate);
  648. _actor.setTarget(MostHate);
  649. dist = Math.sqrt(_actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY()));
  650. dist2= (int) dist - _actor.getTemplate().collisionRadius;
  651. range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  652. if(getAttackTarget().isMoving())
  653. {
  654. range = range + 50;
  655. if(_actor.isMoving())
  656. range = range + 50;
  657. }
  658. }
  659. catch (NullPointerException e)
  660. {
  661. setIntention(AI_INTENTION_ACTIVE);
  662. return;
  663. }
  664. //------------------------------------------------------
  665. // In case many mobs are trying to hit from same place, move a bit,
  666. // circling around the target
  667. if (!_actor.isRooted() && Rnd.nextInt(100) <= 33) // check it once per 3 seconds
  668. {
  669. int combinedCollision = _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  670. int collision = _actor.getTemplate().collisionRadius;
  671. for (L2Object nearby : _actor.getKnownList().getKnownCharactersInRadius(collision))
  672. {
  673. if (nearby instanceof L2Attackable && nearby != getAttackTarget())
  674. {
  675. int diffx = Rnd.get(combinedCollision, combinedCollision+40);
  676. if (Rnd.get(10)<5) diffx = -diffx;
  677. int diffy = Rnd.get(combinedCollision, combinedCollision+40);
  678. if (Rnd.get(10)<5) diffy = -diffy;
  679. moveTo(getAttackTarget().getX() + diffx, getAttackTarget().getY() + diffy, getAttackTarget().getZ());
  680. return;
  681. }
  682. }
  683. }
  684. //Dodge if its needed
  685. if(!_actor.isRooted() && ((L2Attackable)_actor).getCanDodge()>0)
  686. if (Rnd.get(100) <= ((L2Attackable)_actor).getCanDodge())
  687. {
  688. // Micht: kepping this one otherwise we should do 2 sqrt
  689. double distance2 = _actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY());
  690. if (Math.sqrt(distance2) <= (60+_actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius))
  691. {
  692. //Diasable the RND for increasing the performance
  693. //int chance = 60;
  694. //if (chance >= Rnd.get(100))
  695. //{
  696. int posX = _actor.getX();
  697. int posY = _actor.getY();
  698. int posZ = _actor.getZ();
  699. /*
  700. if (Rnd.get(1)>0)
  701. posX=((L2Attackable)_actor).getSpawn().getLocx()+Rnd.get(100);
  702. else
  703. posX=((L2Attackable)_actor).getSpawn().getLocx()-Rnd.get(100);
  704. if (Rnd.get(1)>0)
  705. posY=((L2Attackable)_actor).getSpawn().getLocy() + Rnd.get(100);
  706. else
  707. posY=((L2Attackable)_actor).getSpawn().getLocy()-Rnd.get(100);
  708. setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  709. */
  710. if (Rnd.get(1)>0)
  711. posX=posX+Rnd.get(100);
  712. else
  713. posX=posX-Rnd.get(100);
  714. if (Rnd.get(1)>0)
  715. posY=posY + Rnd.get(100);
  716. else
  717. posY=posY - Rnd.get(100);
  718. setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  719. return;
  720. //}
  721. }
  722. }
  723. //------------------------------------------------------------------------------
  724. // BOSS/Raid Minion Target Reconsider
  725. if (_actor.isRaid() || _actor.isRaidMinion())
  726. {
  727. chaostime++;
  728. if (_actor instanceof L2RaidBossInstance && !((L2MonsterInstance)_actor).hasMinions())
  729. {
  730. if (chaostime > Config.RAID_CHAOS_TIME)
  731. if (Rnd.get(100) <= 100-(_actor.getCurrentHp()*100/_actor.getMaxHp()))
  732. {
  733. AggroReconsider();
  734. chaostime = 0;
  735. }
  736. }
  737. else if (_actor instanceof L2RaidBossInstance && ((L2MonsterInstance)_actor).hasMinions())
  738. {
  739. if (chaostime > Config.RAID_CHAOS_TIME)
  740. if (Rnd.get(100) <= 100-(_actor.getCurrentHp()*200/_actor.getMaxHp()))
  741. {
  742. AggroReconsider();
  743. chaostime = 0;
  744. }
  745. }
  746. else if(_actor instanceof L2GrandBossInstance)
  747. {
  748. if(chaostime > Config.GRAND_CHAOS_TIME)
  749. {
  750. double chaosRate = 100 - (_actor.getCurrentHp() * 300 / _actor.getMaxHp());
  751. if ((chaosRate <= 10 && Rnd.get(100) <= 10) || (chaosRate > 10 && Rnd.get(100)<= chaosRate))
  752. {
  753. AggroReconsider();
  754. chaostime = 0;
  755. }
  756. }
  757. }
  758. else
  759. {
  760. if(chaostime > Config.MINION_CHAOS_TIME)
  761. if(Rnd.get(100)<= 100-(_actor.getCurrentHp()*200/_actor.getMaxHp()))
  762. {
  763. AggroReconsider();
  764. chaostime = 0;
  765. }
  766. }
  767. }
  768. if(_skillrender.hasSkill())
  769. {
  770. //-------------------------------------------------------------------------------
  771. //Heal Condition
  772. if(_skillrender.hasHealSkill() && _skillrender._healskills !=null)
  773. {
  774. double percentage = _actor.getCurrentHp()/_actor.getMaxHp()*100;
  775. if(_actor instanceof L2MinionInstance)
  776. {
  777. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  778. if(leader != null && !leader.isDead() && Rnd.get(100) > (leader.getCurrentHp() / leader.getMaxHp() * 100))
  779. for(L2Skill sk:_skillrender._healskills)
  780. {
  781. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF)
  782. continue;
  783. if((sk.getMpConsume()>=_actor.getCurrentMp()
  784. || _actor.isSkillDisabled(sk.getId())
  785. ||(sk.isMagic()&&_actor.isMuted())
  786. ||(!sk.isMagic()&&_actor.isPhysicalMuted())))
  787. {
  788. continue;
  789. }
  790. if(!Util.checkIfInRange((sk.getCastRange()+_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  791. && !isParty(sk) && !_actor.isMovementDisabled())
  792. {
  793. moveToPawn(leader,sk.getCastRange() +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  794. }
  795. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  796. {
  797. clientStopMoving(null);
  798. _actor.setTarget(leader);
  799. clientStopMoving(null);
  800. _actor.doCast(sk);
  801. return;
  802. }
  803. }
  804. }
  805. if(Rnd.get(100) < (100-percentage)/3)
  806. for(L2Skill sk:_skillrender._healskills)
  807. {
  808. if((sk.getMpConsume() >= _actor.getCurrentMp()
  809. || _actor.isSkillDisabled(sk.getId())
  810. ||(sk.isMagic() && _actor.isMuted()))
  811. ||(!sk.isMagic() && _actor.isPhysicalMuted()))
  812. {
  813. continue;
  814. }
  815. clientStopMoving(null);
  816. _actor.setTarget(_actor);
  817. _actor.doCast(sk);
  818. return;
  819. }
  820. for(L2Skill sk:_skillrender._healskills)
  821. {
  822. if((sk.getMpConsume() >= _actor.getCurrentMp()
  823. || _actor.isSkillDisabled(sk.getId())
  824. ||(sk.isMagic() && _actor.isMuted()))
  825. ||(!sk.isMagic() && _actor.isPhysicalMuted()))
  826. {
  827. continue;
  828. }
  829. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  830. for(L2Character obj: _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange() + _actor.getTemplate().collisionRadius))
  831. {
  832. if(!(obj instanceof L2Attackable) || obj.isDead())
  833. continue;
  834. L2Attackable targets = ((L2Attackable)obj);
  835. if(((L2Attackable)_actor).getFactionId() != targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  836. continue;
  837. percentage = targets.getCurrentHp()/targets.getMaxHp()*100;
  838. if(Rnd.get(100)< (100-percentage)/10)
  839. {
  840. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  841. {
  842. clientStopMoving(null);
  843. _actor.setTarget(obj);
  844. _actor.doCast(sk);
  845. return;
  846. }
  847. }
  848. }
  849. if(isParty(sk))
  850. {
  851. clientStopMoving(null);
  852. _actor.doCast(sk);
  853. return;
  854. }
  855. }
  856. }
  857. //-------------------------------------------------------------------------------
  858. //Res Skill Condition
  859. if(_skillrender.hasResSkill())
  860. {
  861. if(_actor instanceof L2MinionInstance)
  862. {
  863. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  864. if(leader != null && leader.isDead())
  865. for(L2Skill sk:_skillrender._resskills)
  866. {
  867. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF)
  868. continue;
  869. if((sk.getMpConsume() >= _actor.getCurrentMp()
  870. || _actor.isSkillDisabled(sk.getId())
  871. ||(sk.isMagic() && _actor.isMuted())
  872. ||(!sk.isMagic() && _actor.isPhysicalMuted())))
  873. {
  874. continue;
  875. }
  876. if(!Util.checkIfInRange((sk.getCastRange()+_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  877. && !isParty(sk) && !_actor.isRooted())
  878. {
  879. moveToPawn(leader,sk.getCastRange()
  880. +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  881. }
  882. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  883. {
  884. clientStopMoving(null);
  885. _actor.setTarget(((L2MinionInstance)_actor).getLeader());
  886. _actor.doCast(sk);
  887. return;
  888. }
  889. }
  890. }
  891. for(L2Skill sk:_skillrender._resskills)
  892. {
  893. if((sk.getMpConsume() >= _actor.getCurrentMp()
  894. || _actor.isSkillDisabled(sk.getId())
  895. ||(sk.isMagic() && _actor.isMuted()))
  896. ||(!sk.isMagic() && _actor.isPhysicalMuted()))
  897. {
  898. continue;
  899. }
  900. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  901. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange()+_actor.getTemplate().collisionRadius))
  902. {
  903. if(!(obj instanceof L2Attackable) || !obj.isDead())
  904. continue;
  905. L2Attackable targets = ((L2Attackable)obj);
  906. if(((L2Attackable)_actor).getFactionId() != targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  907. continue;
  908. if(Rnd.get(100) < 10)
  909. {
  910. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  911. {
  912. clientStopMoving(null);
  913. _actor.setTarget(obj);
  914. _actor.doCast(sk);
  915. return;
  916. }
  917. }
  918. }
  919. if(isParty(sk))
  920. {
  921. clientStopMoving(null);
  922. L2Object target = getAttackTarget();
  923. _actor.setTarget(_actor);
  924. _actor.doCast(sk);
  925. _actor.setTarget(target);
  926. return;
  927. }
  928. }
  929. }
  930. }
  931. //-------------------------------------------------------------------------------
  932. //Immobilize Condition
  933. if((_actor.isRooted() && (dist > range || getAttackTarget().isMoving()))
  934. ||(dist > range && getAttackTarget().isMoving()))
  935. {
  936. MovementDisable();
  937. return;
  938. }
  939. setTimepass(0);
  940. //--------------------------------------------------------------------------------
  941. //Skill Use
  942. if(_skillrender.hasSkill())
  943. {
  944. if(Rnd.get(100)<=((L2Npc)_actor).getSkillChance())
  945. {
  946. L2Skill skills = _skillrender._generalskills.get(Rnd.nextInt(_skillrender._generalskills.size()));
  947. if (Cast(skills))
  948. return;
  949. for(L2Skill sk:_skillrender._generalskills)
  950. if (Cast(sk))
  951. return;
  952. }
  953. //--------------------------------------------------------------------------------
  954. //Long/Short Range skill Usage
  955. if (((L2Npc)_actor).hasLSkill() || ((L2Npc)_actor).hasSSkill())
  956. {
  957. if (((L2Npc)_actor).hasSSkill() && dist2 <= 150 && Rnd.get(100) <= ((L2Npc)_actor).getSSkillChance())
  958. {
  959. SSkillRender();
  960. if (_skillrender._Srangeskills != null)
  961. {
  962. L2Skill skills = _skillrender._Srangeskills.get(Rnd.nextInt(_skillrender._Srangeskills.size()));
  963. if (Cast(skills))
  964. return;
  965. for(L2Skill sk : _skillrender._Srangeskills)
  966. if (Cast(sk))
  967. return;
  968. }
  969. }
  970. if (((L2Npc)_actor).hasLSkill() && dist2 > 150 && Rnd.get(100) <= ((L2Npc)_actor).getSSkillChance())
  971. {
  972. LSkillRender();
  973. if(_skillrender._Lrangeskills != null)
  974. {
  975. L2Skill skills = _skillrender._Lrangeskills.get(Rnd.nextInt(_skillrender._Lrangeskills.size()));
  976. if (Cast(skills))
  977. return;
  978. for(L2Skill sk : _skillrender._Lrangeskills)
  979. if (Cast(sk))
  980. return;
  981. }
  982. }
  983. }
  984. }
  985. //--------------------------------------------------------------------------------
  986. // Starts Melee or Primary Skill
  987. if(dist2>range || !GeoData.getInstance().canSeeTarget(_actor, getAttackTarget()))
  988. {
  989. if (_actor.isRooted())
  990. {
  991. TargetReconsider();
  992. return;
  993. }
  994. else
  995. {
  996. if(getAttackTarget().isMoving())
  997. range -= 100;
  998. if(range < 5)
  999. range = 5;
  1000. moveToPawn(getAttackTarget(), range);
  1001. return;
  1002. }
  1003. }
  1004. else
  1005. {
  1006. Melee(((L2Npc)_actor).getPrimaryAttack());
  1007. }
  1008. }
  1009. private void Melee(int type)
  1010. {
  1011. if(type!=0)
  1012. {
  1013. switch(type)
  1014. {
  1015. case -1:
  1016. {
  1017. if(_skillrender._generalskills != null)
  1018. for(L2Skill sk : _skillrender._generalskills)
  1019. if (Cast(sk))
  1020. return;
  1021. break;
  1022. }
  1023. case 1:
  1024. {
  1025. if(_skillrender.hasAtkSkill())
  1026. for(L2Skill sk : _skillrender._atkskills)
  1027. if (Cast(sk))
  1028. return;
  1029. break;
  1030. }
  1031. default:
  1032. {
  1033. if(_skillrender._generalskills != null)
  1034. for(L2Skill sk : _skillrender._generalskills)
  1035. if(sk.getId() == ((L2Npc)_actor).getPrimaryAttack())
  1036. if (Cast(sk))
  1037. return;
  1038. }
  1039. break;
  1040. }
  1041. }
  1042. _accessor.doAttack(getAttackTarget());
  1043. }
  1044. private boolean Cast(L2Skill sk)
  1045. {
  1046. if (sk == null)
  1047. return false;
  1048. if (sk.getMpConsume() >= _actor.getCurrentMp() || _actor.isSkillDisabled(sk.getId())
  1049. || (sk.isMagic() && _actor.isMuted()) || (!sk.isMagic() && _actor.isPhysicalMuted()))
  1050. return false;
  1051. if(getAttackTarget() == null)
  1052. if(((L2Attackable)_actor).getMostHated() != null)
  1053. setAttackTarget(((L2Attackable)_actor).getMostHated());
  1054. L2Character attackTarget = getAttackTarget();
  1055. if(attackTarget == null)
  1056. return false;
  1057. double dist = Math.sqrt(_actor.getPlanDistanceSq(attackTarget.getX(), attackTarget.getY()));
  1058. double dist2= dist - attackTarget.getTemplate().collisionRadius;
  1059. double range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + attackTarget.getTemplate().collisionRadius;
  1060. double srange = sk.getCastRange() + _actor.getTemplate().collisionRadius;
  1061. if(attackTarget.isMoving())
  1062. dist2 = dist2 - 30;
  1063. switch(sk.getSkillType())
  1064. {
  1065. case BUFF:
  1066. case REFLECT:
  1067. {
  1068. if (_actor.getFirstEffect(sk) == null)
  1069. {
  1070. clientStopMoving(null);
  1071. //L2Object target = attackTarget;
  1072. _actor.setTarget(_actor);
  1073. _actor.doCast(sk);
  1074. //_actor.setTarget(target);
  1075. return true;
  1076. }
  1077. //----------------------------------------
  1078. //If actor already have buff, start looking at others same faction mob to cast
  1079. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF)
  1080. return false;
  1081. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  1082. {
  1083. L2Character target = EffectTargetReconsider(sk,true);
  1084. if (target != null)
  1085. {
  1086. clientStopMoving(null);
  1087. L2Object targets = attackTarget;
  1088. _actor.setTarget(target);
  1089. _actor.doCast(sk);
  1090. _actor.setTarget(targets);
  1091. return true;
  1092. }
  1093. }
  1094. if(canParty(sk))
  1095. {
  1096. clientStopMoving(null);
  1097. L2Object targets = attackTarget;
  1098. _actor.setTarget(_actor);
  1099. _actor.doCast(sk);
  1100. _actor.setTarget(targets);
  1101. return true;
  1102. }
  1103. break;
  1104. }
  1105. case HEAL:
  1106. case HOT:
  1107. case HEAL_PERCENT:
  1108. case HEAL_STATIC:
  1109. case BALANCE_LIFE:
  1110. {
  1111. double percentage = _actor.getCurrentHp()/_actor.getMaxHp()*100;
  1112. if(_actor instanceof L2MinionInstance && sk.getTargetType() != L2Skill.SkillTargetType.TARGET_SELF)
  1113. {
  1114. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  1115. if(leader != null && !leader.isDead() && Rnd.get(100) > (leader.getCurrentHp()/leader.getMaxHp()*100))
  1116. {
  1117. if(!Util.checkIfInRange((sk.getCastRange() + _actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  1118. && !isParty(sk) && !_actor.isRooted())
  1119. {
  1120. moveToPawn(leader,sk.getCastRange() +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  1121. }
  1122. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  1123. {
  1124. clientStopMoving(null);
  1125. _actor.setTarget(leader);
  1126. _actor.doCast(sk);
  1127. return true;
  1128. }
  1129. }
  1130. }
  1131. if(Rnd.get(100) < (100-percentage)/3)
  1132. {
  1133. clientStopMoving(null);
  1134. _actor.setTarget(_actor);
  1135. _actor.doCast(sk);
  1136. return true;
  1137. }
  1138. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  1139. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange() + _actor.getTemplate().collisionRadius))
  1140. {
  1141. if(!(obj instanceof L2Attackable) || obj.isDead())
  1142. continue;
  1143. L2Attackable targets = ((L2Attackable)obj);
  1144. if(((L2Attackable)_actor).getFactionId() != targets.getFactionId()&&((L2Attackable)_actor).getFactionId() != null)
  1145. continue;
  1146. percentage = targets.getCurrentHp()/targets.getMaxHp()*100;
  1147. if(Rnd.get(100)< (100-percentage)/10)
  1148. {
  1149. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  1150. {
  1151. clientStopMoving(null);
  1152. _actor.setTarget(obj);
  1153. _actor.doCast(sk);
  1154. return true;
  1155. }
  1156. }
  1157. }
  1158. if(isParty(sk))
  1159. {
  1160. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius() + _actor.getTemplate().collisionRadius))
  1161. {
  1162. if(!(obj instanceof L2Attackable))
  1163. {
  1164. continue;
  1165. }
  1166. L2Npc targets = ((L2Npc)obj);
  1167. L2Npc actors = ((L2Npc)_actor);
  1168. if(actors.getFactionId() != null && targets.getFactionId().equals(actors.getFactionId()))
  1169. {
  1170. if(obj.getCurrentHp() < obj.getMaxHp() && Rnd.get(100) <= 20)
  1171. {
  1172. clientStopMoving(null);
  1173. _actor.setTarget(_actor);
  1174. _actor.doCast(sk);
  1175. return true;
  1176. }
  1177. }
  1178. }
  1179. }
  1180. break;
  1181. }
  1182. case RESURRECT:
  1183. {
  1184. if(!isParty(sk))
  1185. {
  1186. if(_actor instanceof L2MinionInstance && sk.getTargetType() != L2Skill.SkillTargetType.TARGET_SELF)
  1187. {
  1188. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  1189. if(leader != null && leader.isDead())
  1190. if(!Util.checkIfInRange((sk.getCastRange() + _actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  1191. && !isParty(sk) && !_actor.isRooted())
  1192. {
  1193. moveToPawn(leader,sk.getCastRange() +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  1194. }
  1195. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  1196. {
  1197. clientStopMoving(null);
  1198. _actor.setTarget(((L2MinionInstance)_actor).getLeader());
  1199. _actor.doCast(sk);
  1200. return true;
  1201. }
  1202. }
  1203. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange()+_actor.getTemplate().collisionRadius))
  1204. {
  1205. if(!(obj instanceof L2Attackable) || !obj.isDead())
  1206. continue;
  1207. L2Attackable targets = ((L2Attackable)obj);
  1208. if(((L2Attackable)_actor).getFactionId()!= targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  1209. continue;
  1210. if(Rnd.get(100)< 10)
  1211. {
  1212. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  1213. {
  1214. clientStopMoving(null);
  1215. _actor.setTarget(obj);
  1216. _actor.doCast(sk);
  1217. return true;
  1218. }
  1219. }
  1220. }
  1221. }
  1222. else if(isParty(sk))
  1223. {
  1224. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()+_actor.getTemplate().collisionRadius))
  1225. {
  1226. if(!(obj instanceof L2Attackable))
  1227. {
  1228. continue;
  1229. }
  1230. L2Npc targets = ((L2Npc)obj);
  1231. L2Npc actors = ((L2Npc)_actor);
  1232. if(actors.getFactionId() != null && actors.getFactionId().equals(targets.getFactionId()))
  1233. {
  1234. if(obj.getCurrentHp()<obj.getMaxHp() && Rnd.get(100)<=20)
  1235. {
  1236. clientStopMoving(null);
  1237. _actor.setTarget(_actor);
  1238. _actor.doCast(sk);
  1239. return true;
  1240. }
  1241. }
  1242. }
  1243. }
  1244. break;
  1245. }
  1246. case DEBUFF:
  1247. case WEAKNESS:
  1248. case POISON:
  1249. case DOT:
  1250. case MDOT:
  1251. case BLEED:
  1252. {
  1253. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget)
  1254. && !canAOE(sk) && !attackTarget.isDead() && dist2<=srange)
  1255. {
  1256. if (attackTarget.getFirstEffect(sk) == null)
  1257. {
  1258. clientStopMoving(null);
  1259. _actor.doCast(sk);
  1260. return true;
  1261. }
  1262. }
  1263. else if(canAOE(sk))
  1264. {
  1265. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1266. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1267. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1268. {
  1269. clientStopMoving(null);
  1270. //L2Object target = attackTarget;
  1271. //_actor.setTarget(_actor);
  1272. _actor.doCast(sk);
  1273. //_actor.setTarget(target);
  1274. return true;
  1275. }
  1276. if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1277. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1278. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1279. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1280. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1281. {
  1282. clientStopMoving(null);
  1283. _actor.doCast(sk);
  1284. return true;
  1285. }
  1286. }
  1287. else if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1288. {
  1289. L2Character target = EffectTargetReconsider(sk,false);
  1290. if (target != null)
  1291. {
  1292. clientStopMoving(null);
  1293. _actor.doCast(sk);
  1294. return true;
  1295. }
  1296. }
  1297. break;
  1298. }
  1299. case SLEEP:
  1300. {
  1301. if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1302. {
  1303. if(attackTarget != null && !attackTarget.isDead() && dist2<=srange)
  1304. {
  1305. if(dist2>range || attackTarget.isMoving())
  1306. {
  1307. if (attackTarget.getFirstEffect(sk) == null)
  1308. {
  1309. clientStopMoving(null);
  1310. //_actor.setTarget(attackTarget);
  1311. _actor.doCast(sk);
  1312. return true;
  1313. }
  1314. }
  1315. }
  1316. L2Character target = EffectTargetReconsider(sk,false);
  1317. if (target != null)
  1318. {
  1319. clientStopMoving(null);
  1320. _actor.doCast(sk);
  1321. return true;
  1322. }
  1323. }
  1324. else if(canAOE(sk))
  1325. {
  1326. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1327. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1328. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1329. {
  1330. clientStopMoving(null);
  1331. //L2Object target = attackTarget;
  1332. //_actor.setTarget(_actor);
  1333. _actor.doCast(sk);
  1334. //_actor.setTarget(target);
  1335. return true;
  1336. }
  1337. if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1338. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1339. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1340. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1341. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1342. {
  1343. clientStopMoving(null);
  1344. _actor.doCast(sk);
  1345. return true;
  1346. }
  1347. }
  1348. break;
  1349. }
  1350. case ROOT:
  1351. case STUN:
  1352. case PARALYZE:
  1353. {
  1354. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !canAOE(sk) && dist2<=srange)
  1355. {
  1356. if (attackTarget.getFirstEffect(sk) == null)
  1357. {
  1358. clientStopMoving(null);
  1359. _actor.doCast(sk);
  1360. return true;
  1361. }
  1362. }
  1363. else if(canAOE(sk))
  1364. {
  1365. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1366. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1367. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1368. {
  1369. clientStopMoving(null);
  1370. //L2Object target = attackTarget;
  1371. //_actor.setTarget(_actor);
  1372. _actor.doCast(sk);
  1373. //_actor.setTarget(target);
  1374. return true;
  1375. }
  1376. else if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1377. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1378. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1379. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1380. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1381. {
  1382. clientStopMoving(null);
  1383. _actor.doCast(sk);
  1384. return true;
  1385. }
  1386. }
  1387. else if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1388. {
  1389. L2Character target = EffectTargetReconsider(sk,false);
  1390. if (target != null)
  1391. {
  1392. clientStopMoving(null);
  1393. _actor.doCast(sk);
  1394. return true;
  1395. }
  1396. }
  1397. break;
  1398. }
  1399. case MUTE:
  1400. case FEAR:
  1401. {
  1402. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !canAOE(sk) && dist2<=srange)
  1403. {
  1404. if (attackTarget.getFirstEffect(sk) == null)
  1405. {
  1406. clientStopMoving(null);
  1407. _actor.doCast(sk);
  1408. return true;
  1409. }
  1410. }
  1411. else if(canAOE(sk))
  1412. {
  1413. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1414. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1415. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1416. {
  1417. clientStopMoving(null);
  1418. //L2Object target = attackTarget;
  1419. //_actor.setTarget(_actor);
  1420. _actor.doCast(sk);
  1421. //_actor.setTarget(target);
  1422. return true;
  1423. }
  1424. if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1425. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1426. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1427. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1428. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1429. {
  1430. clientStopMoving(null);
  1431. _actor.doCast(sk);
  1432. return true;
  1433. }
  1434. }
  1435. else if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1436. {
  1437. L2Character target = EffectTargetReconsider(sk,false);
  1438. if (target != null)
  1439. {
  1440. clientStopMoving(null);
  1441. _actor.doCast(sk);
  1442. return true;
  1443. }
  1444. }
  1445. break;
  1446. }
  1447. case CANCEL:
  1448. case NEGATE:
  1449. {
  1450. if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1451. {
  1452. if(attackTarget.getFirstEffect(L2EffectType.BUFF) != null
  1453. && GeoData.getInstance().canSeeTarget(_actor,attackTarget)
  1454. && !attackTarget.isDead()
  1455. && dist2<=srange)
  1456. {
  1457. clientStopMoving(null);
  1458. //L2Object target = attackTarget;
  1459. //_actor.setTarget(_actor);
  1460. _actor.doCast(sk);
  1461. //_actor.setTarget(target);
  1462. return true;
  1463. }
  1464. L2Character target = EffectTargetReconsider(sk,false);
  1465. if (target != null)
  1466. {
  1467. clientStopMoving(null);
  1468. L2Object targets = attackTarget;
  1469. _actor.setTarget(target);
  1470. _actor.doCast(sk);
  1471. _actor.setTarget(targets);
  1472. return true;
  1473. }
  1474. }
  1475. else if(canAOE(sk))
  1476. {
  1477. if((sk.getTargetType() == SkillTargetType.TARGET_AURA
  1478. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1479. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1480. && GeoData.getInstance().canSeeTarget(_actor,attackTarget))
  1481. {
  1482. clientStopMoving(null);
  1483. //L2Object target = attackTarget;
  1484. //_actor.setTarget(_actor);
  1485. _actor.doCast(sk);
  1486. //_actor.setTarget(target);
  1487. return true;
  1488. }
  1489. else if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1490. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1491. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1492. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1493. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1494. {
  1495. clientStopMoving(null);
  1496. _actor.doCast(sk);
  1497. return true;
  1498. }
  1499. }
  1500. break;
  1501. }
  1502. case PDAM:
  1503. case MDAM:
  1504. case BLOW:
  1505. case DRAIN:
  1506. case CHARGEDAM:
  1507. case DEATHLINK:
  1508. case CPDAM:
  1509. case MANADAM:
  1510. {
  1511. if(!canAura(sk))
  1512. {
  1513. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1514. {
  1515. clientStopMoving(null);
  1516. _actor.doCast(sk);
  1517. return true;
  1518. }
  1519. else
  1520. {
  1521. L2Character target = SkillTargetReconsider(sk);
  1522. if (target != null)
  1523. {
  1524. clientStopMoving(null);
  1525. L2Object targets = attackTarget;
  1526. _actor.setTarget(target);
  1527. _actor.doCast(sk);
  1528. _actor.setTarget(targets);
  1529. return true;
  1530. }
  1531. }
  1532. }
  1533. else
  1534. {
  1535. clientStopMoving(null);
  1536. _actor.doCast(sk);
  1537. return true;
  1538. }
  1539. break;
  1540. }
  1541. default :
  1542. {
  1543. if(!canAura(sk))
  1544. {
  1545. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1546. {
  1547. clientStopMoving(null);
  1548. _actor.doCast(sk);
  1549. return true;
  1550. }
  1551. else
  1552. {
  1553. L2Character target = SkillTargetReconsider(sk);
  1554. if (target != null)
  1555. {
  1556. clientStopMoving(null);
  1557. L2Object targets = attackTarget;
  1558. _actor.setTarget(target);
  1559. _actor.doCast(sk);
  1560. _actor.setTarget(targets);
  1561. return true;
  1562. }
  1563. }
  1564. }
  1565. else
  1566. {
  1567. clientStopMoving(null);
  1568. //L2Object targets = attackTarget;
  1569. //_actor.setTarget(_actor);
  1570. _actor.doCast(sk);
  1571. //_actor.setTarget(targets);
  1572. return true;
  1573. }
  1574. }
  1575. break;
  1576. }
  1577. return false;
  1578. }
  1579. /**
  1580. * This AI task will start when ACTOR cannot move and attack range larger than distance
  1581. */
  1582. private void MovementDisable()
  1583. {
  1584. double dist = 0;
  1585. double dist2 = 0;
  1586. int range = 0;
  1587. try
  1588. {
  1589. if(_actor.getTarget() == null)
  1590. _actor.setTarget(getAttackTarget());
  1591. dist = Math.sqrt(_actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY()));
  1592. dist2= dist - _actor.getTemplate().collisionRadius;
  1593. range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1594. if(getAttackTarget().isMoving())
  1595. {
  1596. dist = dist -30;
  1597. if(_actor.isMoving())
  1598. dist = dist -50;
  1599. }
  1600. }
  1601. catch (NullPointerException e)
  1602. {
  1603. setIntention(AI_INTENTION_ACTIVE);
  1604. return;
  1605. }
  1606. //Check if activeChar has any skill
  1607. if(_skillrender.hasSkill())
  1608. {
  1609. //-------------------------------------------------------------
  1610. //Try to stop the target or disable the target as priority
  1611. int random = Rnd.get(100);
  1612. if (_skillrender.hasImmobiliseSkill() && !getAttackTarget().isImmobilized() && random < 2)
  1613. {
  1614. for(L2Skill sk : _skillrender._immobiliseskills)
  1615. {
  1616. if(sk.getMpConsume() >= _actor.getCurrentMp()
  1617. || _actor.isSkillDisabled(sk.getId())
  1618. || (sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1619. || (sk.isMagic()&&_actor.isMuted())
  1620. || (!sk.isMagic()&&_actor.isPhysicalMuted()))
  1621. {
  1622. continue;
  1623. }
  1624. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1625. continue;
  1626. if (getAttackTarget().getFirstEffect(sk) == null)
  1627. {
  1628. clientStopMoving(null);
  1629. //L2Object target = getAttackTarget();
  1630. //_actor.setTarget(_actor);
  1631. _actor.doCast(sk);
  1632. //_actor.setTarget(target);
  1633. return;
  1634. }
  1635. }
  1636. }
  1637. //-------------------------------------------------------------
  1638. //Same as Above, but with Mute/FEAR etc....
  1639. if(_skillrender.hasCOTSkill() && random < 5)
  1640. {
  1641. for(L2Skill sk:_skillrender._cotskills)
  1642. {
  1643. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1644. || _actor.isSkillDisabled(sk.getId())
  1645. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1646. ||(sk.isMagic()&&_actor.isMuted())
  1647. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1648. {
  1649. continue;
  1650. }
  1651. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1652. continue;
  1653. if (getAttackTarget().getFirstEffect(sk) == null)
  1654. {
  1655. clientStopMoving(null);
  1656. //L2Object target = getAttackTarget();
  1657. //_actor.setTarget(_actor);
  1658. _actor.doCast(sk);
  1659. //_actor.setTarget(target);
  1660. return;
  1661. }
  1662. }
  1663. }
  1664. //-------------------------------------------------------------
  1665. if(_skillrender.hasDebuffSkill() && random < 8)
  1666. {
  1667. for(L2Skill sk:_skillrender._debuffskills)
  1668. {
  1669. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1670. || _actor.isSkillDisabled(sk.getId())
  1671. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1672. ||(sk.isMagic()&&_actor.isMuted())
  1673. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1674. {
  1675. continue;
  1676. }
  1677. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1678. continue;
  1679. if (getAttackTarget().getFirstEffect(sk) == null)
  1680. {
  1681. clientStopMoving(null);
  1682. //L2Object target = getAttackTarget();
  1683. //_actor.setTarget(_actor);
  1684. _actor.doCast(sk);
  1685. //_actor.setTarget(target);
  1686. return;
  1687. }
  1688. }
  1689. }
  1690. //-------------------------------------------------------------
  1691. //Some side effect skill like CANCEL or NEGATE
  1692. if(_skillrender.hasNegativeSkill() && random < 9)
  1693. {
  1694. for(L2Skill sk : _skillrender._negativeskills)
  1695. {
  1696. if(sk.getMpConsume() >= _actor.getCurrentMp()
  1697. || _actor.isSkillDisabled(sk.getId())
  1698. ||(sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1699. ||(sk.isMagic()&&_actor.isMuted())
  1700. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1701. {
  1702. continue;
  1703. }
  1704. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1705. continue;
  1706. if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  1707. {
  1708. clientStopMoving(null);
  1709. //L2Object target = getAttackTarget();
  1710. //_actor.setTarget(_actor);
  1711. _actor.doCast(sk);
  1712. //_actor.setTarget(target);
  1713. return;
  1714. }
  1715. }
  1716. }
  1717. //-------------------------------------------------------------
  1718. //Start ATK SKILL when nothing can be done
  1719. if(_skillrender.hasAtkSkill())
  1720. {
  1721. for(L2Skill sk:_skillrender._atkskills)
  1722. {
  1723. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1724. || _actor.isSkillDisabled(sk.getId())
  1725. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1726. ||(sk.isMagic()&&_actor.isMuted())
  1727. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1728. {
  1729. continue;
  1730. }
  1731. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1732. continue;
  1733. clientStopMoving(null);
  1734. //L2Object target = getAttackTarget();
  1735. //_actor.setTarget(_actor);
  1736. _actor.doCast(sk);
  1737. //_actor.setTarget(target);
  1738. return;
  1739. }
  1740. }
  1741. //-------------------------------------------------------------
  1742. //if there is no ATK skill to use, then try Universal skill
  1743. /*
  1744. if(_skillrender.hasUniversalSkill())
  1745. {
  1746. for(L2Skill sk:_skillrender._universalskills)
  1747. {
  1748. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1749. || _actor.isSkillDisabled(sk.getId())
  1750. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1751. ||(sk.isMagic()&&_actor.isMuted())
  1752. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1753. {
  1754. continue;
  1755. }
  1756. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1757. continue;
  1758. clientStopMoving(null);
  1759. L2Object target = getAttackTarget();
  1760. //_actor.setTarget(_actor);
  1761. _actor.doCast(sk);
  1762. //_actor.setTarget(target);
  1763. return;
  1764. }
  1765. }
  1766. */
  1767. }
  1768. //timepass = timepass + 1;
  1769. if (_actor.isRooted())
  1770. {
  1771. //timepass = 0;
  1772. TargetReconsider();
  1773. return;
  1774. }
  1775. //else if(timepass>=5)
  1776. //{
  1777. // timepass = 0;
  1778. // AggroReconsider();
  1779. // return;
  1780. //}
  1781. if(dist>range || !GeoData.getInstance().canSeeTarget(_actor, getAttackTarget()))
  1782. {
  1783. if(getAttackTarget().isMoving())
  1784. range -=100;if(range<5)range=5;
  1785. moveToPawn(getAttackTarget(), range);
  1786. return;
  1787. }
  1788. Melee(((L2Npc)_actor).getPrimaryAttack());
  1789. return;
  1790. }
  1791. private L2Character EffectTargetReconsider(L2Skill sk, boolean positive)
  1792. {
  1793. if (sk == null)
  1794. return null;
  1795. if(sk.getSkillType() != L2SkillType.NEGATE || sk.getSkillType() != L2SkillType.CANCEL )
  1796. {
  1797. if(!positive)
  1798. {
  1799. double dist = 0;
  1800. double dist2 = 0;
  1801. int range = 0;
  1802. L2Attackable actor = (L2Attackable)_actor;
  1803. if(actor.getAttackByList() != null)
  1804. for(L2Character obj: actor.getAttackByList())
  1805. {
  1806. if(obj == null || obj.isDead() || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj == getAttackTarget())
  1807. continue;
  1808. try
  1809. {
  1810. _actor.setTarget(getAttackTarget());
  1811. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1812. dist2= dist - _actor.getTemplate().collisionRadius;
  1813. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1814. if(obj.isMoving())
  1815. dist2 = dist2 - 70;
  1816. }
  1817. catch (NullPointerException e)
  1818. {
  1819. continue;
  1820. }
  1821. if(dist2<=range)
  1822. {
  1823. if (getAttackTarget().getFirstEffect(sk) == null)
  1824. return obj;
  1825. }
  1826. }
  1827. //----------------------------------------------------------------------
  1828. //If there is nearby Target with aggro, start going on random target that is attackable
  1829. for (L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(range))
  1830. {
  1831. if(obj.isDead() || obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj))
  1832. continue;
  1833. try
  1834. {
  1835. _actor.setTarget(getAttackTarget());
  1836. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1837. dist2= dist;
  1838. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1839. if(obj.isMoving())
  1840. dist2 = dist2 - 70;
  1841. }
  1842. catch (NullPointerException e)
  1843. {
  1844. continue;
  1845. }
  1846. if(obj instanceof L2Attackable)
  1847. {
  1848. if(((L2Attackable)_actor).getEnemyClan() != null && (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan())) && !"none".equals(((L2Attackable)_actor).getEnemyClan()))
  1849. {
  1850. if(dist2<=range)
  1851. {
  1852. if (getAttackTarget().getFirstEffect(sk) == null)
  1853. return obj;
  1854. }
  1855. }
  1856. }
  1857. if(obj instanceof L2PcInstance || obj instanceof L2Summon)
  1858. {
  1859. if(dist2<=range)
  1860. {
  1861. if (getAttackTarget().getFirstEffect(sk) == null)
  1862. return obj;
  1863. }
  1864. }
  1865. }
  1866. }
  1867. else if (positive)
  1868. {
  1869. double dist = 0;
  1870. double dist2 = 0;
  1871. int range = 0;
  1872. for(L2Character obj: _actor.getKnownList().getKnownCharactersInRadius(range))
  1873. {
  1874. if(!(obj instanceof L2Attackable) || obj.isDead() || obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj))
  1875. continue;
  1876. L2Attackable targets = ((L2Attackable)obj);
  1877. if(((L2Attackable)_actor).getFactionId()!= targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  1878. continue;
  1879. try
  1880. {
  1881. _actor.setTarget(getAttackTarget());
  1882. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1883. dist2= dist - _actor.getTemplate().collisionRadius;
  1884. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1885. if(obj.isMoving())
  1886. dist2 = dist2 - 70;
  1887. }
  1888. catch (NullPointerException e)
  1889. {
  1890. continue;
  1891. }
  1892. if(dist2<=range)
  1893. {
  1894. if (obj.getFirstEffect(sk) == null)
  1895. return obj;
  1896. }
  1897. }
  1898. }
  1899. return null;
  1900. }
  1901. else
  1902. {
  1903. double dist = 0;
  1904. double dist2 = 0;
  1905. int range = 0;
  1906. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1907. for (L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(range))
  1908. {
  1909. if(obj == null || obj.isDead() || !GeoData.getInstance().canSeeTarget(_actor,obj))
  1910. continue;
  1911. try
  1912. {
  1913. _actor.setTarget(getAttackTarget());
  1914. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1915. dist2= dist - _actor.getTemplate().collisionRadius;
  1916. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1917. if(obj.isMoving())
  1918. dist2 = dist2 - 70;
  1919. }
  1920. catch (NullPointerException e)
  1921. {
  1922. continue;
  1923. }
  1924. if(obj instanceof L2Attackable)
  1925. {
  1926. if(((L2Attackable)_actor).getEnemyClan() != null && (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan())) && !"none".equals(((L2Attackable)_actor).getEnemyClan()))
  1927. {
  1928. if(dist2<=range)
  1929. {
  1930. if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  1931. return obj;
  1932. }
  1933. }
  1934. }
  1935. if(obj instanceof L2PcInstance || obj instanceof L2Summon)
  1936. {
  1937. if(dist2<=range)
  1938. {
  1939. if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  1940. return obj;
  1941. }
  1942. }
  1943. }
  1944. return null;
  1945. }
  1946. }
  1947. private L2Character SkillTargetReconsider(L2Skill sk)
  1948. {
  1949. double dist = 0;
  1950. double dist2 = 0;
  1951. int range = 0;
  1952. L2Attackable actor = (L2Attackable)_actor;
  1953. if(actor.getHateList()!=null)
  1954. for(L2Character obj: actor.getHateList())
  1955. {
  1956. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead())
  1957. continue;
  1958. try
  1959. {
  1960. _actor.setTarget(getAttackTarget());
  1961. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1962. dist2= dist - _actor.getTemplate().collisionRadius;
  1963. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1964. //if(obj.isMoving())
  1965. // dist2 = dist2 - 40;
  1966. }
  1967. catch (NullPointerException e)
  1968. {
  1969. continue;
  1970. }
  1971. if(dist2<=range)
  1972. {
  1973. return obj;
  1974. }
  1975. }
  1976. if(!(_actor instanceof L2GuardInstance))
  1977. {
  1978. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  1979. for (L2Object target : objs)
  1980. {
  1981. try
  1982. {
  1983. _actor.setTarget(getAttackTarget());
  1984. dist = Math.sqrt(_actor.getPlanDistanceSq(target.getX(), target.getY()));
  1985. dist2= dist;
  1986. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1987. //if(obj.isMoving())
  1988. // dist2 = dist2 - 40;
  1989. }
  1990. catch (NullPointerException e)
  1991. {
  1992. continue;
  1993. }
  1994. L2Character obj = null;
  1995. if (target instanceof L2Character)
  1996. obj = (L2Character)target;
  1997. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || dist2 > range)
  1998. continue;
  1999. if(obj instanceof L2PcInstance)
  2000. {
  2001. return obj;
  2002. }
  2003. if(obj instanceof L2Attackable)
  2004. {
  2005. if(((L2Attackable)_actor).getEnemyClan() != null && (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan())) && !"none".equals(((L2Attackable)_actor).getEnemyClan()))
  2006. {
  2007. return obj;
  2008. }
  2009. if (((L2Attackable)_actor).getIsChaos() != 0)
  2010. {
  2011. if(((L2Attackable)obj).getFactionId() != null && ((L2Attackable)obj).getFactionId().equals(((L2Attackable)_actor).getFactionId()))
  2012. continue;
  2013. else
  2014. return obj;
  2015. }
  2016. }
  2017. if(obj instanceof L2Summon)
  2018. {
  2019. return obj;
  2020. }
  2021. }
  2022. }
  2023. return null;
  2024. }
  2025. private void TargetReconsider()
  2026. {
  2027. double dist = 0;
  2028. double dist2 = 0;
  2029. int range = 0;
  2030. L2Attackable actor = (L2Attackable)_actor;
  2031. L2Character MostHate = ((L2Attackable) _actor).getMostHated();
  2032. if(actor.getHateList()!=null)
  2033. for(L2Character obj : actor.getHateList())
  2034. {
  2035. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead() || obj!= MostHate || obj == _actor)
  2036. continue;
  2037. try
  2038. {
  2039. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  2040. dist2= dist - _actor.getTemplate().collisionRadius;
  2041. range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  2042. if(obj.isMoving())
  2043. dist2 = dist2 - 70;
  2044. }
  2045. catch (NullPointerException e)
  2046. {
  2047. continue;
  2048. }
  2049. if(dist2<=range)
  2050. {
  2051. if(MostHate!=null)
  2052. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2053. else
  2054. actor.addDamageHate(obj,2000,2000);
  2055. _actor.setTarget(obj);
  2056. setAttackTarget(obj);
  2057. return;
  2058. }
  2059. }
  2060. if(!(_actor instanceof L2GuardInstance))
  2061. {
  2062. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  2063. for (L2Object target : objs)
  2064. {
  2065. L2Character obj = null;
  2066. if (target instanceof L2Character)
  2067. obj = (L2Character)target;
  2068. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead() || obj!= MostHate || obj == _actor || obj == getAttackTarget())
  2069. continue;
  2070. if(obj instanceof L2PcInstance)
  2071. {
  2072. if(MostHate != null)
  2073. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2074. else
  2075. actor.addDamageHate(obj,2000,2000);
  2076. _actor.setTarget(obj);
  2077. setAttackTarget(obj);
  2078. }
  2079. else if(obj instanceof L2Attackable)
  2080. {
  2081. if(((L2Attackable)_actor).getEnemyClan() != null && (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan())) && !"none".equals(((L2Attackable)_actor).getEnemyClan()))
  2082. {
  2083. actor.addDamageHate(obj,0,actor.getHating(MostHate));
  2084. _actor.setTarget(obj);
  2085. }
  2086. if (((L2Attackable)_actor).getIsChaos() != 0)
  2087. {
  2088. if(((L2Attackable)obj).getFactionId() != null && ((L2Attackable)obj).getFactionId().equals(((L2Attackable)_actor).getFactionId()))
  2089. continue;
  2090. else
  2091. {
  2092. if(MostHate != null)
  2093. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2094. else
  2095. actor.addDamageHate(obj,2000,2000);
  2096. _actor.setTarget(obj);
  2097. setAttackTarget(obj);
  2098. }
  2099. }
  2100. }
  2101. else if(obj instanceof L2Summon)
  2102. {
  2103. if(MostHate != null)
  2104. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2105. else
  2106. actor.addDamageHate(obj,2000,2000);
  2107. _actor.setTarget(obj);
  2108. setAttackTarget(obj);
  2109. }
  2110. }
  2111. }
  2112. }
  2113. @SuppressWarnings("null")
  2114. private void AggroReconsider()
  2115. {
  2116. L2Attackable actor = (L2Attackable)_actor;
  2117. L2Character MostHate = ((L2Attackable) _actor).getMostHated();
  2118. if(actor.getHateList() != null)
  2119. {
  2120. int rand = Rnd.get(actor.getHateList().size());
  2121. int count = 0;
  2122. for(L2Character obj: actor.getHateList())
  2123. {
  2124. if(count < rand)
  2125. {
  2126. count++;
  2127. continue;
  2128. }
  2129. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead()|| obj == getAttackTarget() || obj == actor)
  2130. continue;
  2131. try
  2132. {
  2133. _actor.setTarget(getAttackTarget());
  2134. }
  2135. catch (NullPointerException e)
  2136. {
  2137. continue;
  2138. }
  2139. if(MostHate!=null)
  2140. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2141. else
  2142. actor.addDamageHate(obj,2000,2000);
  2143. _actor.setTarget(obj);
  2144. setAttackTarget(obj);
  2145. return;
  2146. }
  2147. }
  2148. if(!(_actor instanceof L2GuardInstance))
  2149. {
  2150. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  2151. for (L2Object target : objs)
  2152. {
  2153. L2Character obj = null;
  2154. if(target instanceof L2Character)
  2155. obj = (L2Character)target;
  2156. else
  2157. continue;
  2158. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead() || obj != MostHate || obj == _actor)
  2159. continue;
  2160. if(obj instanceof L2PcInstance)
  2161. {
  2162. if(MostHate!=null || !MostHate.isDead())
  2163. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2164. else
  2165. actor.addDamageHate(obj,2000,2000);
  2166. _actor.setTarget(obj);
  2167. setAttackTarget(obj);
  2168. }
  2169. else if(obj instanceof L2Attackable)
  2170. {
  2171. if(((L2Attackable)_actor).getEnemyClan() != null && (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan())) && !"none".equals(((L2Attackable)_actor).getEnemyClan()))
  2172. {
  2173. if(MostHate != null)
  2174. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2175. else
  2176. actor.addDamageHate(obj,2000,2000);
  2177. _actor.setTarget(obj);
  2178. }
  2179. if (((L2Attackable)_actor).getIsChaos() != 0)
  2180. {
  2181. if(((L2Attackable)obj).getFactionId() != null && ((L2Attackable)obj).getFactionId().equals(((L2Attackable)_actor).getFactionId()))
  2182. continue;
  2183. else
  2184. {
  2185. if(MostHate != null)
  2186. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2187. else
  2188. actor.addDamageHate(obj,2000,2000);
  2189. _actor.setTarget(obj);
  2190. setAttackTarget(obj);
  2191. }
  2192. }
  2193. }
  2194. else if(obj instanceof L2Summon)
  2195. {
  2196. if(MostHate != null)
  2197. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2198. else
  2199. actor.addDamageHate(obj,2000,2000);
  2200. _actor.setTarget(obj);
  2201. setAttackTarget(obj);
  2202. }
  2203. }
  2204. }
  2205. }
  2206. private void LSkillRender()
  2207. {
  2208. if(_skillrender._Lrangeskills == null)
  2209. _skillrender._Lrangeskills = ((L2Npc)_actor).getLrangeSkill();
  2210. }
  2211. private void SSkillRender()
  2212. {
  2213. if(_skillrender._Srangeskills == null)
  2214. _skillrender._Srangeskills = ((L2Npc)_actor).getSrangeSkill();
  2215. }
  2216. /**
  2217. * Manage AI thinking actions of a L2Attackable.<BR><BR>
  2218. */
  2219. @Override
  2220. protected void onEvtThink()
  2221. {
  2222. // Check if the actor can't use skills and if a thinking action isn't already in progress
  2223. if (_thinking || _actor.isAllSkillsDisabled()) return;
  2224. // Start thinking action
  2225. _thinking = true;
  2226. try
  2227. {
  2228. // Manage AI thinks of a L2Attackable
  2229. if (getIntention() == AI_INTENTION_ACTIVE) thinkActive();
  2230. else if (getIntention() == AI_INTENTION_ATTACK) thinkAttack();
  2231. }
  2232. finally
  2233. {
  2234. // Stop thinking action
  2235. _thinking = false;
  2236. }
  2237. }
  2238. /**
  2239. * Launch actions corresponding to the Event Attacked.<BR><BR>
  2240. *
  2241. * <B><U> Actions</U> :</B><BR><BR>
  2242. * <li>Init the attack : Calculate the attack timeout, Set the _globalAggro to 0, Add the attacker to the actor _aggroList</li>
  2243. * <li>Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance</li>
  2244. * <li>Set the Intention to AI_INTENTION_ATTACK</li><BR><BR>
  2245. *
  2246. * @param attacker The L2Character that attacks the actor
  2247. *
  2248. */
  2249. @Override
  2250. protected void onEvtAttacked(L2Character attacker)
  2251. {
  2252. //if (_actor instanceof L2ChestInstance && !((L2ChestInstance)_actor).isInteracted())
  2253. //{
  2254. //((L2ChestInstance)_actor).deleteMe();
  2255. //((L2ChestInstance)_actor).getSpawn().startRespawn();
  2256. //return;
  2257. //}
  2258. // Calculate the attack timeout
  2259. _attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks();
  2260. // Set the _globalAggro to 0 to permit attack even just after spawn
  2261. if (_globalAggro < 0) _globalAggro = 0;
  2262. // Add the attacker to the _aggroList of the actor
  2263. ((L2Attackable) _actor).addDamageHate(attacker, 0, 1);
  2264. // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  2265. if (!_actor.isRunning()) _actor.setRunning();
  2266. // Set the Intention to AI_INTENTION_ATTACK
  2267. if (getIntention() != AI_INTENTION_ATTACK)
  2268. {
  2269. setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  2270. }
  2271. else if (((L2Attackable) _actor).getMostHated() != getAttackTarget())
  2272. {
  2273. setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  2274. }
  2275. super.onEvtAttacked(attacker);
  2276. }
  2277. /**
  2278. * Launch actions corresponding to the Event Aggression.<BR><BR>
  2279. *
  2280. * <B><U> Actions</U> :</B><BR><BR>
  2281. * <li>Add the target to the actor _aggroList or update hate if already present </li>
  2282. * <li>Set the actor Intention to AI_INTENTION_ATTACK (if actor is L2GuardInstance check if it isn't too far from its home location)</li><BR><BR>
  2283. *
  2284. * @param attacker The L2Character that attacks
  2285. * @param aggro The value of hate to add to the actor against the target
  2286. *
  2287. */
  2288. @Override
  2289. protected void onEvtAggression(L2Character target, int aggro)
  2290. {
  2291. L2Attackable me = (L2Attackable) _actor;
  2292. if (target != null)
  2293. {
  2294. // Add the target to the actor _aggroList or update hate if already present
  2295. me.addDamageHate(target, 0, aggro);
  2296. // Set the actor AI Intention to AI_INTENTION_ATTACK
  2297. if (getIntention() != CtrlIntention.AI_INTENTION_ATTACK)
  2298. {
  2299. // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  2300. if (!_actor.isRunning()) _actor.setRunning();
  2301. setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  2302. }
  2303. }
  2304. }
  2305. @Override
  2306. protected void onIntentionActive()
  2307. {
  2308. // Cancel attack timeout
  2309. _attackTimeout = Integer.MAX_VALUE;
  2310. super.onIntentionActive();
  2311. }
  2312. public void setGlobalAggro(int value)
  2313. {
  2314. _globalAggro = value;
  2315. }
  2316. /**
  2317. * @param clan The clan to set.
  2318. */
  2319. public void setClan(String CL)
  2320. {
  2321. this.clan = CL;
  2322. }
  2323. /**
  2324. * @return Returns the clan.
  2325. */
  2326. public String getClan()
  2327. {
  2328. return clan;
  2329. }
  2330. /**
  2331. * @param enemyClan The enemyClan to set.
  2332. */
  2333. public void setEnemyClan(String EC)
  2334. {
  2335. this.enemyClan = EC;
  2336. }
  2337. /**
  2338. * @return Returns the enemyClan.
  2339. */
  2340. public String getEnemyClan()
  2341. {
  2342. return enemyClan;
  2343. }
  2344. /**
  2345. * @param timepass The timepass to set.
  2346. */
  2347. public void setTimepass(int TP)
  2348. {
  2349. this.timepass = TP;
  2350. }
  2351. /**
  2352. * @return Returns the timepass.
  2353. */
  2354. public int getTimepass()
  2355. {
  2356. return timepass;
  2357. }
  2358. }