L2AttackableAI.java 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534
  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)
  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(_actor.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. //Return when Attack been disable
  634. if(_actor.isAttackingDisabled())
  635. return;
  636. /*
  637. if(_actor.getTarget() == null || this.getAttackTarget() == null || this.getAttackTarget().isDead() || ctarget == _actor)
  638. AggroReconsider();
  639. */
  640. //----------------------------------------------------------------
  641. //------------------------------------------------------------------------------
  642. //Initialize data
  643. double dist = 0;
  644. int dist2 = 0;
  645. int range = 0;
  646. L2Character MostHate = ((L2Attackable) _actor).getMostHated();
  647. //L2Character ctarget = (L2Character)_actor.getTarget();
  648. try
  649. {
  650. setAttackTarget(MostHate);
  651. _actor.setTarget(MostHate);
  652. dist = Math.sqrt(_actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY()));
  653. dist2= (int)dist;
  654. range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  655. if(getAttackTarget().isMoving())
  656. {
  657. range = range + 50;
  658. if(_actor.isMoving())
  659. range = range + 50;
  660. }
  661. }
  662. catch (NullPointerException e)
  663. {
  664. setIntention(AI_INTENTION_ACTIVE);
  665. return;
  666. }
  667. //------------------------------------------------------
  668. // In case many mobs are trying to hit from same place, move a bit,
  669. // circling around the target
  670. if (!_actor.isRooted() && Rnd.nextInt(100) <= 33) // check it once per 3 seconds
  671. {
  672. int combinedCollision = _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  673. int collision = _actor.getTemplate().collisionRadius;
  674. for (L2Object nearby : _actor.getKnownList().getKnownCharactersInRadius(collision))
  675. {
  676. if (nearby instanceof L2Attackable && nearby != getAttackTarget())
  677. {
  678. int diffx = Rnd.get(combinedCollision, combinedCollision+40);
  679. if (Rnd.get(10)<5) diffx = -diffx;
  680. int diffy = Rnd.get(combinedCollision, combinedCollision+40);
  681. if (Rnd.get(10)<5) diffy = -diffy;
  682. moveTo(getAttackTarget().getX() + diffx, getAttackTarget().getY() + diffy, getAttackTarget().getZ());
  683. return;
  684. }
  685. }
  686. }
  687. //Dodge if its needed
  688. if(!_actor.isRooted() && ((L2Attackable)_actor).getCanDodge()>0)
  689. if (Rnd.get(100) <= ((L2Attackable)_actor).getCanDodge())
  690. {
  691. // Micht: kepping this one otherwise we should do 2 sqrt
  692. double distance2 = _actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY());
  693. if (Math.sqrt(distance2) <= (60+_actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius))
  694. {
  695. //Diasable the RND for increasing the performance
  696. //int chance = 60;
  697. //if (chance >= Rnd.get(100))
  698. //{
  699. int posX = _actor.getX();
  700. int posY = _actor.getY();
  701. int posZ = _actor.getZ();
  702. /*
  703. if (Rnd.get(1)>0)
  704. posX=((L2Attackable)_actor).getSpawn().getLocx()+Rnd.get(100);
  705. else
  706. posX=((L2Attackable)_actor).getSpawn().getLocx()-Rnd.get(100);
  707. if (Rnd.get(1)>0)
  708. posY=((L2Attackable)_actor).getSpawn().getLocy() + Rnd.get(100);
  709. else
  710. posY=((L2Attackable)_actor).getSpawn().getLocy()-Rnd.get(100);
  711. setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  712. */
  713. if (Rnd.get(1)>0)
  714. posX=posX+Rnd.get(100);
  715. else
  716. posX=posX-Rnd.get(100);
  717. if (Rnd.get(1)>0)
  718. posY=posY + Rnd.get(100);
  719. else
  720. posY=posY - Rnd.get(100);
  721. setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  722. return;
  723. //}
  724. }
  725. }
  726. //------------------------------------------------------------------------------
  727. // BOSS/Raid Minion Target Reconsider
  728. if (_actor.isRaid() || _actor.isRaidMinion())
  729. {
  730. chaostime++;
  731. if (_actor instanceof L2RaidBossInstance && !((L2MonsterInstance)_actor).hasMinions())
  732. {
  733. if (chaostime > Config.RAID_CHAOS_TIME)
  734. if (Rnd.get(100) <= 100-(_actor.getCurrentHp()*100/_actor.getMaxHp()))
  735. {
  736. AggroReconsider();
  737. chaostime = 0;
  738. }
  739. }
  740. else if (_actor instanceof L2RaidBossInstance && ((L2MonsterInstance)_actor).hasMinions())
  741. {
  742. if (chaostime > Config.RAID_CHAOS_TIME)
  743. if (Rnd.get(100) <= 100-(_actor.getCurrentHp()*200/_actor.getMaxHp()))
  744. {
  745. AggroReconsider();
  746. chaostime = 0;
  747. }
  748. }
  749. else if(_actor instanceof L2GrandBossInstance)
  750. {
  751. if(chaostime > Config.GRAND_CHAOS_TIME)
  752. if(Rnd.get(100) <= 100-(_actor.getCurrentHp()*300/_actor.getMaxHp()))
  753. {
  754. AggroReconsider();
  755. chaostime = 0;
  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. for(L2Skill sk:_skillrender._Srangeskills)
  962. if (Cast(sk))
  963. return;
  964. }
  965. if (((L2Npc)_actor).hasLSkill() && dist2 >= 300 && Rnd.get(100) <= ((L2Npc)_actor).getSSkillChance())
  966. {
  967. LSkillRender();
  968. if(_skillrender._Lrangeskills!=null)
  969. for(L2Skill sk:_skillrender._Lrangeskills)
  970. if (Cast(sk))
  971. return;
  972. }
  973. }
  974. }
  975. //--------------------------------------------------------------------------------
  976. // Starts Melee or Primary Skill
  977. if(dist2>range || !GeoData.getInstance().canSeeTarget(_actor, getAttackTarget()))
  978. {
  979. if (_actor.isRooted())
  980. {
  981. TargetReconsider();
  982. return;
  983. }
  984. else
  985. {
  986. if(getAttackTarget().isMoving())
  987. range -= 100;
  988. if(range < 5)
  989. range = 5;
  990. moveToPawn(getAttackTarget(), range);
  991. return;
  992. }
  993. }
  994. else
  995. {
  996. Melee(((L2Npc)_actor).getPrimaryAttack());
  997. }
  998. }
  999. private void Melee(int type)
  1000. {
  1001. if(type!=0)
  1002. {
  1003. switch(type)
  1004. {
  1005. case -1:
  1006. {
  1007. if(_skillrender._generalskills != null)
  1008. for(L2Skill sk : _skillrender._generalskills)
  1009. if (Cast(sk))
  1010. return;
  1011. break;
  1012. }
  1013. case 1:
  1014. {
  1015. if(_skillrender.hasAtkSkill())
  1016. for(L2Skill sk : _skillrender._atkskills)
  1017. if (Cast(sk))
  1018. return;
  1019. break;
  1020. }
  1021. default:
  1022. {
  1023. if(_skillrender._generalskills != null)
  1024. for(L2Skill sk : _skillrender._generalskills)
  1025. if(sk.getId() == ((L2Npc)_actor).getPrimaryAttack())
  1026. if (Cast(sk))
  1027. return;
  1028. }
  1029. break;
  1030. }
  1031. }
  1032. _accessor.doAttack(getAttackTarget());
  1033. }
  1034. private boolean Cast(L2Skill sk)
  1035. {
  1036. if (sk == null)
  1037. return false;
  1038. if (sk.getMpConsume() >= _actor.getCurrentMp() || _actor.isSkillDisabled(sk.getId())
  1039. || (sk.isMagic() && _actor.isMuted()) || (!sk.isMagic() && _actor.isPhysicalMuted()))
  1040. return false;
  1041. if(getAttackTarget() == null)
  1042. if(((L2Attackable)_actor).getMostHated() != null)
  1043. setAttackTarget(((L2Attackable)_actor).getMostHated());
  1044. if(getAttackTarget() == null)
  1045. return false;
  1046. double dist = Math.sqrt(_actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY()));
  1047. double dist2= dist + getAttackTarget().getTemplate().collisionRadius;
  1048. double range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1049. double srange = sk.getCastRange() + _actor.getTemplate().collisionRadius;
  1050. if(getAttackTarget().isMoving())
  1051. dist2 = dist2 - 400;
  1052. switch(sk.getSkillType())
  1053. {
  1054. case BUFF:
  1055. case REFLECT:
  1056. {
  1057. if (_actor.getFirstEffect(sk) == null)
  1058. {
  1059. clientStopMoving(null);
  1060. //L2Object target = getAttackTarget();
  1061. _actor.setTarget(_actor);
  1062. _actor.doCast(sk);
  1063. //_actor.setTarget(target);
  1064. return true;
  1065. }
  1066. //----------------------------------------
  1067. //If actor already have buff, start looking at others same faction mob to cast
  1068. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF)
  1069. return false;
  1070. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  1071. {
  1072. L2Character target = EffectTargetReconsider(sk,true);
  1073. if (target != null)
  1074. {
  1075. clientStopMoving(null);
  1076. L2Object targets = getAttackTarget();
  1077. _actor.setTarget(target);
  1078. _actor.doCast(sk);
  1079. _actor.setTarget(targets);
  1080. return true;
  1081. }
  1082. }
  1083. if(canParty(sk))
  1084. {
  1085. clientStopMoving(null);
  1086. L2Object targets = getAttackTarget();
  1087. _actor.setTarget(_actor);
  1088. _actor.doCast(sk);
  1089. _actor.setTarget(targets);
  1090. return true;
  1091. }
  1092. break;
  1093. }
  1094. case HEAL:
  1095. case HOT:
  1096. case HEAL_PERCENT:
  1097. case HEAL_STATIC:
  1098. case BALANCE_LIFE:
  1099. {
  1100. double percentage = _actor.getCurrentHp()/_actor.getMaxHp()*100;
  1101. if(_actor instanceof L2MinionInstance && sk.getTargetType() != L2Skill.SkillTargetType.TARGET_SELF)
  1102. {
  1103. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  1104. if(leader != null && !leader.isDead() && Rnd.get(100) > (leader.getCurrentHp()/leader.getMaxHp()*100))
  1105. {
  1106. if(!Util.checkIfInRange((sk.getCastRange() + _actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  1107. && !isParty(sk) && !_actor.isRooted())
  1108. {
  1109. moveToPawn(leader,sk.getCastRange() +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  1110. }
  1111. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  1112. {
  1113. clientStopMoving(null);
  1114. _actor.setTarget(leader);
  1115. _actor.doCast(sk);
  1116. return true;
  1117. }
  1118. }
  1119. }
  1120. if(Rnd.get(100) < (100-percentage)/3)
  1121. {
  1122. clientStopMoving(null);
  1123. _actor.setTarget(_actor);
  1124. _actor.doCast(sk);
  1125. return true;
  1126. }
  1127. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  1128. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange() + _actor.getTemplate().collisionRadius))
  1129. {
  1130. if(!(obj instanceof L2Attackable) || obj.isDead())
  1131. continue;
  1132. L2Attackable targets = ((L2Attackable)obj);
  1133. if(((L2Attackable)_actor).getFactionId() != targets.getFactionId()&&((L2Attackable)_actor).getFactionId() != null)
  1134. continue;
  1135. percentage = targets.getCurrentHp()/targets.getMaxHp()*100;
  1136. if(Rnd.get(100)< (100-percentage)/10)
  1137. {
  1138. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  1139. {
  1140. clientStopMoving(null);
  1141. _actor.setTarget(obj);
  1142. _actor.doCast(sk);
  1143. return true;
  1144. }
  1145. }
  1146. }
  1147. if(isParty(sk))
  1148. {
  1149. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius() + _actor.getTemplate().collisionRadius))
  1150. {
  1151. if(!(obj instanceof L2Attackable))
  1152. {
  1153. continue;
  1154. }
  1155. L2Npc targets = ((L2Npc)obj);
  1156. L2Npc actors = ((L2Npc)_actor);
  1157. if(actors.getFactionId() != null && targets.getFactionId().equals(actors.getFactionId()))
  1158. {
  1159. if(obj.getCurrentHp() < obj.getMaxHp() && Rnd.get(100) <= 20)
  1160. {
  1161. clientStopMoving(null);
  1162. _actor.setTarget(_actor);
  1163. _actor.doCast(sk);
  1164. return true;
  1165. }
  1166. }
  1167. }
  1168. }
  1169. break;
  1170. }
  1171. case RESURRECT:
  1172. {
  1173. if(!isParty(sk))
  1174. {
  1175. if(_actor instanceof L2MinionInstance && sk.getTargetType() != L2Skill.SkillTargetType.TARGET_SELF)
  1176. {
  1177. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  1178. if(leader != null && leader.isDead())
  1179. if(!Util.checkIfInRange((sk.getCastRange() + _actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  1180. && !isParty(sk) && !_actor.isRooted())
  1181. {
  1182. moveToPawn(leader,sk.getCastRange() +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  1183. }
  1184. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  1185. {
  1186. clientStopMoving(null);
  1187. _actor.setTarget(((L2MinionInstance)_actor).getLeader());
  1188. _actor.doCast(sk);
  1189. return true;
  1190. }
  1191. }
  1192. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange()+_actor.getTemplate().collisionRadius))
  1193. {
  1194. if(!(obj instanceof L2Attackable) || !obj.isDead())
  1195. continue;
  1196. L2Attackable targets = ((L2Attackable)obj);
  1197. if(((L2Attackable)_actor).getFactionId()!= targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  1198. continue;
  1199. if(Rnd.get(100)< 10)
  1200. {
  1201. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  1202. {
  1203. clientStopMoving(null);
  1204. _actor.setTarget(obj);
  1205. _actor.doCast(sk);
  1206. return true;
  1207. }
  1208. }
  1209. }
  1210. }
  1211. else if(isParty(sk))
  1212. {
  1213. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()+_actor.getTemplate().collisionRadius))
  1214. {
  1215. if(!(obj instanceof L2Attackable))
  1216. {
  1217. continue;
  1218. }
  1219. L2Npc targets = ((L2Npc)obj);
  1220. L2Npc actors = ((L2Npc)_actor);
  1221. if(actors.getFactionId() != null && actors.getFactionId().equals(targets.getFactionId()))
  1222. {
  1223. if(obj.getCurrentHp()<obj.getMaxHp() && Rnd.get(100)<=20)
  1224. {
  1225. clientStopMoving(null);
  1226. _actor.setTarget(_actor);
  1227. _actor.doCast(sk);
  1228. return true;
  1229. }
  1230. }
  1231. }
  1232. }
  1233. break;
  1234. }
  1235. case DEBUFF:
  1236. case WEAKNESS:
  1237. case POISON:
  1238. case DOT:
  1239. case MDOT:
  1240. case BLEED:
  1241. {
  1242. if(GeoData.getInstance().canSeeTarget(_actor,getAttackTarget())
  1243. && !canAOE(sk) && !getAttackTarget().isDead() && dist2<=srange)
  1244. {
  1245. if (getAttackTarget().getFirstEffect(sk) == null)
  1246. {
  1247. clientStopMoving(null);
  1248. _actor.doCast(sk);
  1249. return true;
  1250. }
  1251. }
  1252. else if(canAOE(sk))
  1253. {
  1254. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1255. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1256. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1257. {
  1258. clientStopMoving(null);
  1259. //L2Object target = getAttackTarget();
  1260. //_actor.setTarget(_actor);
  1261. _actor.doCast(sk);
  1262. //_actor.setTarget(target);
  1263. return true;
  1264. }
  1265. if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1266. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1267. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1268. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1269. && GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()) && !getAttackTarget().isDead() && dist2<=srange)
  1270. {
  1271. clientStopMoving(null);
  1272. _actor.doCast(sk);
  1273. return true;
  1274. }
  1275. }
  1276. else if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1277. {
  1278. L2Character target = EffectTargetReconsider(sk,false);
  1279. if (target != null)
  1280. {
  1281. clientStopMoving(null);
  1282. _actor.doCast(sk);
  1283. return true;
  1284. }
  1285. }
  1286. break;
  1287. }
  1288. case SLEEP:
  1289. {
  1290. if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1291. {
  1292. if(getAttackTarget() != null && !getAttackTarget().isDead() && dist2<=srange)
  1293. {
  1294. if(dist2>range || getAttackTarget().isMoving())
  1295. {
  1296. if (getAttackTarget().getFirstEffect(sk) == null)
  1297. {
  1298. clientStopMoving(null);
  1299. //_actor.setTarget(getAttackTarget());
  1300. _actor.doCast(sk);
  1301. return true;
  1302. }
  1303. }
  1304. }
  1305. L2Character target = EffectTargetReconsider(sk,false);
  1306. if (target != null)
  1307. {
  1308. clientStopMoving(null);
  1309. _actor.doCast(sk);
  1310. return true;
  1311. }
  1312. }
  1313. else if(canAOE(sk))
  1314. {
  1315. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1316. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1317. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1318. {
  1319. clientStopMoving(null);
  1320. //L2Object target = getAttackTarget();
  1321. //_actor.setTarget(_actor);
  1322. _actor.doCast(sk);
  1323. //_actor.setTarget(target);
  1324. return true;
  1325. }
  1326. if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1327. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1328. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1329. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1330. && GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()) && !getAttackTarget().isDead() && dist2<=srange)
  1331. {
  1332. clientStopMoving(null);
  1333. _actor.doCast(sk);
  1334. return true;
  1335. }
  1336. }
  1337. break;
  1338. }
  1339. case ROOT:
  1340. case STUN:
  1341. case PARALYZE:
  1342. {
  1343. if(GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()) && !canAOE(sk) && dist2<=srange)
  1344. {
  1345. if (getAttackTarget().getFirstEffect(sk) == null)
  1346. {
  1347. clientStopMoving(null);
  1348. _actor.doCast(sk);
  1349. return true;
  1350. }
  1351. }
  1352. else if(canAOE(sk))
  1353. {
  1354. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1355. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1356. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1357. {
  1358. clientStopMoving(null);
  1359. //L2Object target = getAttackTarget();
  1360. //_actor.setTarget(_actor);
  1361. _actor.doCast(sk);
  1362. //_actor.setTarget(target);
  1363. return true;
  1364. }
  1365. else if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1366. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1367. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1368. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1369. && GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()) && !getAttackTarget().isDead() && dist2<=srange)
  1370. {
  1371. clientStopMoving(null);
  1372. _actor.doCast(sk);
  1373. return true;
  1374. }
  1375. }
  1376. else if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1377. {
  1378. L2Character target = EffectTargetReconsider(sk,false);
  1379. if (target != null)
  1380. {
  1381. clientStopMoving(null);
  1382. _actor.doCast(sk);
  1383. return true;
  1384. }
  1385. }
  1386. break;
  1387. }
  1388. case MUTE:
  1389. case FEAR:
  1390. {
  1391. if(GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()) && !canAOE(sk) && dist2<=srange)
  1392. {
  1393. if (getAttackTarget().getFirstEffect(sk) == null)
  1394. {
  1395. clientStopMoving(null);
  1396. _actor.doCast(sk);
  1397. return true;
  1398. }
  1399. }
  1400. else if(canAOE(sk))
  1401. {
  1402. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1403. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1404. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1405. {
  1406. clientStopMoving(null);
  1407. //L2Object target = getAttackTarget();
  1408. //_actor.setTarget(_actor);
  1409. _actor.doCast(sk);
  1410. //_actor.setTarget(target);
  1411. return true;
  1412. }
  1413. if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1414. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1415. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1416. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1417. && GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()) && !getAttackTarget().isDead() && dist2<=srange)
  1418. {
  1419. clientStopMoving(null);
  1420. _actor.doCast(sk);
  1421. return true;
  1422. }
  1423. }
  1424. else if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1425. {
  1426. L2Character target = EffectTargetReconsider(sk,false);
  1427. if (target != null)
  1428. {
  1429. clientStopMoving(null);
  1430. _actor.doCast(sk);
  1431. return true;
  1432. }
  1433. }
  1434. break;
  1435. }
  1436. case CANCEL:
  1437. case NEGATE:
  1438. {
  1439. if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1440. {
  1441. if(getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null
  1442. && GeoData.getInstance().canSeeTarget(_actor,getAttackTarget())
  1443. && !getAttackTarget().isDead()
  1444. && dist2<=srange)
  1445. {
  1446. clientStopMoving(null);
  1447. //L2Object target = getAttackTarget();
  1448. //_actor.setTarget(_actor);
  1449. _actor.doCast(sk);
  1450. //_actor.setTarget(target);
  1451. return true;
  1452. }
  1453. L2Character target = EffectTargetReconsider(sk,false);
  1454. if (target != null)
  1455. {
  1456. clientStopMoving(null);
  1457. L2Object targets = getAttackTarget();
  1458. _actor.setTarget(target);
  1459. _actor.doCast(sk);
  1460. _actor.setTarget(targets);
  1461. return true;
  1462. }
  1463. }
  1464. else if(canAOE(sk))
  1465. {
  1466. if((sk.getTargetType() == SkillTargetType.TARGET_AURA
  1467. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1468. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1469. && GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1470. {
  1471. clientStopMoving(null);
  1472. //L2Object target = getAttackTarget();
  1473. //_actor.setTarget(_actor);
  1474. _actor.doCast(sk);
  1475. //_actor.setTarget(target);
  1476. return true;
  1477. }
  1478. else if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1479. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1480. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1481. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1482. && GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()) && !getAttackTarget().isDead() && dist2<=srange)
  1483. {
  1484. clientStopMoving(null);
  1485. _actor.doCast(sk);
  1486. return true;
  1487. }
  1488. }
  1489. break;
  1490. }
  1491. case PDAM:
  1492. case MDAM:
  1493. case BLOW:
  1494. case DRAIN:
  1495. case CHARGEDAM:
  1496. case DEATHLINK:
  1497. case CPDAM:
  1498. case MANADAM:
  1499. {
  1500. if(!canAura(sk))
  1501. {
  1502. if(GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()) && !getAttackTarget().isDead() && dist2<=srange)
  1503. {
  1504. clientStopMoving(null);
  1505. _actor.doCast(sk);
  1506. return true;
  1507. }
  1508. else
  1509. {
  1510. L2Character target = SkillTargetReconsider(sk);
  1511. if (target != null)
  1512. {
  1513. clientStopMoving(null);
  1514. L2Object targets = getAttackTarget();
  1515. _actor.setTarget(target);
  1516. _actor.doCast(sk);
  1517. _actor.setTarget(targets);
  1518. return true;
  1519. }
  1520. }
  1521. }
  1522. else
  1523. {
  1524. clientStopMoving(null);
  1525. _actor.doCast(sk);
  1526. return true;
  1527. }
  1528. break;
  1529. }
  1530. default :
  1531. {
  1532. if(!canAura(sk))
  1533. {
  1534. if(GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()) && !getAttackTarget().isDead() && dist2<=srange)
  1535. {
  1536. clientStopMoving(null);
  1537. _actor.doCast(sk);
  1538. return true;
  1539. }
  1540. else
  1541. {
  1542. L2Character target = SkillTargetReconsider(sk);
  1543. if (target != null)
  1544. {
  1545. clientStopMoving(null);
  1546. L2Object targets = getAttackTarget();
  1547. _actor.setTarget(target);
  1548. _actor.doCast(sk);
  1549. _actor.setTarget(targets);
  1550. return true;
  1551. }
  1552. }
  1553. }
  1554. else
  1555. {
  1556. clientStopMoving(null);
  1557. //L2Object targets = getAttackTarget();
  1558. //_actor.setTarget(_actor);
  1559. _actor.doCast(sk);
  1560. //_actor.setTarget(targets);
  1561. return true;
  1562. }
  1563. }
  1564. break;
  1565. }
  1566. return false;
  1567. }
  1568. /**
  1569. * This AI task will start when ACTOR cannot move and attack range larger than distance
  1570. */
  1571. private void MovementDisable()
  1572. {
  1573. double dist = 0;
  1574. double dist2 = 0;
  1575. int range = 0;
  1576. try
  1577. {
  1578. if(_actor.getTarget() == null)
  1579. _actor.setTarget(getAttackTarget());
  1580. dist = Math.sqrt(_actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY()));
  1581. dist2= dist;
  1582. range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1583. if(getAttackTarget().isMoving())
  1584. {
  1585. dist = dist -30;
  1586. if(_actor.isMoving())
  1587. dist = dist -50;
  1588. }
  1589. }
  1590. catch (NullPointerException e)
  1591. {
  1592. setIntention(AI_INTENTION_ACTIVE);
  1593. return;
  1594. }
  1595. //Check if activeChar has any skill
  1596. if(_skillrender.hasSkill())
  1597. {
  1598. //-------------------------------------------------------------
  1599. //Try to stop the target or disable the target as priority
  1600. if(_skillrender.hasImmobiliseSkill())
  1601. {
  1602. for(L2Skill sk : _skillrender._immobiliseskills)
  1603. {
  1604. if(sk.getMpConsume() >= _actor.getCurrentMp()
  1605. || _actor.isSkillDisabled(sk.getId())
  1606. || (sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1607. || (sk.isMagic()&&_actor.isMuted())
  1608. || (!sk.isMagic()&&_actor.isPhysicalMuted()))
  1609. {
  1610. continue;
  1611. }
  1612. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1613. continue;
  1614. if (getAttackTarget().getFirstEffect(sk) == null)
  1615. {
  1616. clientStopMoving(null);
  1617. //L2Object target = getAttackTarget();
  1618. //_actor.setTarget(_actor);
  1619. _actor.doCast(sk);
  1620. //_actor.setTarget(target);
  1621. return;
  1622. }
  1623. }
  1624. }
  1625. //-------------------------------------------------------------
  1626. //Same as Above, but with Mute/FEAR etc....
  1627. if(_skillrender.hasCOTSkill())
  1628. {
  1629. for(L2Skill sk:_skillrender._cotskills)
  1630. {
  1631. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1632. || _actor.isSkillDisabled(sk.getId())
  1633. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1634. ||(sk.isMagic()&&_actor.isMuted())
  1635. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1636. {
  1637. continue;
  1638. }
  1639. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1640. continue;
  1641. if (getAttackTarget().getFirstEffect(sk) == null)
  1642. {
  1643. clientStopMoving(null);
  1644. //L2Object target = getAttackTarget();
  1645. //_actor.setTarget(_actor);
  1646. _actor.doCast(sk);
  1647. //_actor.setTarget(target);
  1648. return;
  1649. }
  1650. }
  1651. }
  1652. //-------------------------------------------------------------
  1653. if(_skillrender.hasDebuffSkill()&&Rnd.get(10)<=2)
  1654. {
  1655. for(L2Skill sk:_skillrender._debuffskills)
  1656. {
  1657. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1658. || _actor.isSkillDisabled(sk.getId())
  1659. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1660. ||(sk.isMagic()&&_actor.isMuted())
  1661. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1662. {
  1663. continue;
  1664. }
  1665. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1666. continue;
  1667. if (getAttackTarget().getFirstEffect(sk) == null)
  1668. {
  1669. clientStopMoving(null);
  1670. //L2Object target = getAttackTarget();
  1671. //_actor.setTarget(_actor);
  1672. _actor.doCast(sk);
  1673. //_actor.setTarget(target);
  1674. return;
  1675. }
  1676. }
  1677. }
  1678. //-------------------------------------------------------------
  1679. //Some side effect skill like CANCEL or NEGATE
  1680. if(_skillrender.hasNegativeSkill() && Rnd.get(10) == 1)
  1681. {
  1682. for(L2Skill sk : _skillrender._negativeskills)
  1683. {
  1684. if(sk.getMpConsume() >= _actor.getCurrentMp()
  1685. || _actor.isSkillDisabled(sk.getId())
  1686. ||(sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1687. ||(sk.isMagic()&&_actor.isMuted())
  1688. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1689. {
  1690. continue;
  1691. }
  1692. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1693. continue;
  1694. if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  1695. {
  1696. clientStopMoving(null);
  1697. //L2Object target = getAttackTarget();
  1698. //_actor.setTarget(_actor);
  1699. _actor.doCast(sk);
  1700. //_actor.setTarget(target);
  1701. return;
  1702. }
  1703. }
  1704. }
  1705. //-------------------------------------------------------------
  1706. //Start ATK SKILL when nothing can be done
  1707. if(_skillrender.hasAtkSkill())
  1708. {
  1709. for(L2Skill sk:_skillrender._atkskills)
  1710. {
  1711. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1712. || _actor.isSkillDisabled(sk.getId())
  1713. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1714. ||(sk.isMagic()&&_actor.isMuted())
  1715. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1716. {
  1717. continue;
  1718. }
  1719. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1720. continue;
  1721. clientStopMoving(null);
  1722. //L2Object target = getAttackTarget();
  1723. //_actor.setTarget(_actor);
  1724. _actor.doCast(sk);
  1725. //_actor.setTarget(target);
  1726. return;
  1727. }
  1728. }
  1729. //-------------------------------------------------------------
  1730. //if there is no ATK skill to use, then try Universal skill
  1731. /*
  1732. if(_skillrender.hasUniversalSkill())
  1733. {
  1734. for(L2Skill sk:_skillrender._universalskills)
  1735. {
  1736. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1737. || _actor.isSkillDisabled(sk.getId())
  1738. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1739. ||(sk.isMagic()&&_actor.isMuted())
  1740. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1741. {
  1742. continue;
  1743. }
  1744. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1745. continue;
  1746. clientStopMoving(null);
  1747. L2Object target = getAttackTarget();
  1748. //_actor.setTarget(_actor);
  1749. _actor.doCast(sk);
  1750. //_actor.setTarget(target);
  1751. return;
  1752. }
  1753. }
  1754. */
  1755. }
  1756. //timepass = timepass + 1;
  1757. if (_actor.isRooted())
  1758. {
  1759. //timepass = 0;
  1760. TargetReconsider();
  1761. return;
  1762. }
  1763. //else if(timepass>=5)
  1764. //{
  1765. // timepass = 0;
  1766. // AggroReconsider();
  1767. // return;
  1768. //}
  1769. if(dist>range || !GeoData.getInstance().canSeeTarget(_actor, getAttackTarget()))
  1770. {
  1771. if(getAttackTarget().isMoving())
  1772. range -=100;if(range<5)range=5;
  1773. moveToPawn(getAttackTarget(), range);
  1774. return;
  1775. }
  1776. Melee(((L2Npc)_actor).getPrimaryAttack());
  1777. return;
  1778. }
  1779. private L2Character EffectTargetReconsider(L2Skill sk, boolean positive)
  1780. {
  1781. if (sk == null)
  1782. return null;
  1783. if(sk.getSkillType() != L2SkillType.NEGATE || sk.getSkillType() != L2SkillType.CANCEL )
  1784. {
  1785. if(!positive)
  1786. {
  1787. double dist = 0;
  1788. double dist2 = 0;
  1789. int range = 0;
  1790. L2Attackable actor = (L2Attackable)_actor;
  1791. if(actor.getAttackByList() != null)
  1792. for(L2Character obj: actor.getAttackByList())
  1793. {
  1794. if(obj == null || obj.isDead() || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj == getAttackTarget())
  1795. continue;
  1796. try
  1797. {
  1798. _actor.setTarget(getAttackTarget());
  1799. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1800. dist2= dist;
  1801. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1802. if(obj.isMoving())
  1803. dist2 = dist2 - 70;
  1804. }
  1805. catch (NullPointerException e)
  1806. {
  1807. continue;
  1808. }
  1809. if(dist2<=range)
  1810. {
  1811. if (getAttackTarget().getFirstEffect(sk) == null)
  1812. return obj;
  1813. }
  1814. }
  1815. //----------------------------------------------------------------------
  1816. //If there is nearby Target with aggro, start going on random target that is attackable
  1817. for (L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(range))
  1818. {
  1819. if(obj.isDead() || obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj))
  1820. continue;
  1821. try
  1822. {
  1823. _actor.setTarget(getAttackTarget());
  1824. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1825. dist2= dist;
  1826. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1827. if(obj.isMoving())
  1828. dist2 = dist2 - 70;
  1829. }
  1830. catch (NullPointerException e)
  1831. {
  1832. continue;
  1833. }
  1834. if(obj instanceof L2Attackable)
  1835. {
  1836. if(((L2Attackable)_actor).getEnemyClan() != null && (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan())) && !"none".equals(((L2Attackable)_actor).getEnemyClan()))
  1837. {
  1838. if(dist2<=range)
  1839. {
  1840. if (getAttackTarget().getFirstEffect(sk) == null)
  1841. return obj;
  1842. }
  1843. }
  1844. }
  1845. if(obj instanceof L2PcInstance || obj instanceof L2Summon)
  1846. {
  1847. if(dist2<=range)
  1848. {
  1849. if (getAttackTarget().getFirstEffect(sk) == null)
  1850. return obj;
  1851. }
  1852. }
  1853. }
  1854. }
  1855. else if (positive)
  1856. {
  1857. double dist = 0;
  1858. double dist2 = 0;
  1859. int range = 0;
  1860. for(L2Character obj: _actor.getKnownList().getKnownCharactersInRadius(range))
  1861. {
  1862. if(!(obj instanceof L2Attackable) || obj.isDead() || obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj))
  1863. continue;
  1864. L2Attackable targets = ((L2Attackable)obj);
  1865. if(((L2Attackable)_actor).getFactionId()!= targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  1866. continue;
  1867. try
  1868. {
  1869. _actor.setTarget(getAttackTarget());
  1870. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1871. dist2= dist;
  1872. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1873. if(obj.isMoving())
  1874. dist2 = dist2 - 70;
  1875. }
  1876. catch (NullPointerException e)
  1877. {
  1878. continue;
  1879. }
  1880. if(dist2<=range)
  1881. {
  1882. if (obj.getFirstEffect(sk) == null)
  1883. return obj;
  1884. }
  1885. }
  1886. }
  1887. return null;
  1888. }
  1889. else
  1890. {
  1891. double dist = 0;
  1892. double dist2 = 0;
  1893. int range = 0;
  1894. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1895. for (L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(range))
  1896. {
  1897. if(obj == null || obj.isDead() || !GeoData.getInstance().canSeeTarget(_actor,obj))
  1898. continue;
  1899. try
  1900. {
  1901. _actor.setTarget(getAttackTarget());
  1902. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1903. dist2= dist;
  1904. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1905. if(obj.isMoving())
  1906. dist2 = dist2 - 70;
  1907. }
  1908. catch (NullPointerException e)
  1909. {
  1910. continue;
  1911. }
  1912. if(obj instanceof L2Attackable)
  1913. {
  1914. if(((L2Attackable)_actor).getEnemyClan() != null && (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan())) && !"none".equals(((L2Attackable)_actor).getEnemyClan()))
  1915. {
  1916. if(dist2<=range)
  1917. {
  1918. if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  1919. return obj;
  1920. }
  1921. }
  1922. }
  1923. if(obj instanceof L2PcInstance || obj instanceof L2Summon)
  1924. {
  1925. if(dist2<=range)
  1926. {
  1927. if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  1928. return obj;
  1929. }
  1930. }
  1931. }
  1932. return null;
  1933. }
  1934. }
  1935. private L2Character SkillTargetReconsider(L2Skill sk)
  1936. {
  1937. double dist = 0;
  1938. double dist2 = 0;
  1939. int range = 0;
  1940. L2Attackable actor = (L2Attackable)_actor;
  1941. if(actor.getHateList()!=null)
  1942. for(L2Character obj: actor.getHateList())
  1943. {
  1944. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead())
  1945. continue;
  1946. try
  1947. {
  1948. _actor.setTarget(getAttackTarget());
  1949. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1950. dist2= dist;
  1951. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1952. //if(obj.isMoving())
  1953. // dist2 = dist2 - 40;
  1954. }
  1955. catch (NullPointerException e)
  1956. {
  1957. continue;
  1958. }
  1959. if(dist2<=range)
  1960. {
  1961. return obj;
  1962. }
  1963. }
  1964. if(!(_actor instanceof L2GuardInstance))
  1965. {
  1966. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  1967. for (L2Object target : objs)
  1968. {
  1969. try
  1970. {
  1971. _actor.setTarget(getAttackTarget());
  1972. dist = Math.sqrt(_actor.getPlanDistanceSq(target.getX(), target.getY()));
  1973. dist2= dist;
  1974. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1975. //if(obj.isMoving())
  1976. // dist2 = dist2 - 40;
  1977. }
  1978. catch (NullPointerException e)
  1979. {
  1980. continue;
  1981. }
  1982. L2Character obj = null;
  1983. if (target instanceof L2Character)
  1984. obj = (L2Character)target;
  1985. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || dist2 > range)
  1986. continue;
  1987. if(obj instanceof L2PcInstance)
  1988. {
  1989. return obj;
  1990. }
  1991. if(obj instanceof L2Attackable)
  1992. {
  1993. if(((L2Attackable)_actor).getEnemyClan() != null && (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan())) && !"none".equals(((L2Attackable)_actor).getEnemyClan()))
  1994. {
  1995. return obj;
  1996. }
  1997. if (((L2Attackable)_actor).getIsChaos() != 0)
  1998. {
  1999. if(((L2Attackable)obj).getFactionId() != null && ((L2Attackable)obj).getFactionId().equals(((L2Attackable)_actor).getFactionId()))
  2000. continue;
  2001. else
  2002. return obj;
  2003. }
  2004. }
  2005. if(obj instanceof L2Summon)
  2006. {
  2007. return obj;
  2008. }
  2009. }
  2010. }
  2011. return null;
  2012. }
  2013. private void TargetReconsider()
  2014. {
  2015. double dist = 0;
  2016. double dist2 = 0;
  2017. int range = 0;
  2018. L2Attackable actor = (L2Attackable)_actor;
  2019. L2Character MostHate = ((L2Attackable) _actor).getMostHated();
  2020. if(actor.getHateList()!=null)
  2021. for(L2Character obj : actor.getHateList())
  2022. {
  2023. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead() || obj!= MostHate || obj == _actor)
  2024. continue;
  2025. try
  2026. {
  2027. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  2028. dist2= dist;
  2029. range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  2030. if(obj.isMoving())
  2031. dist2 = dist2 - 70;
  2032. }
  2033. catch (NullPointerException e)
  2034. {
  2035. continue;
  2036. }
  2037. if(dist2<=range)
  2038. {
  2039. if(MostHate!=null)
  2040. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2041. else
  2042. actor.addDamageHate(obj,2000,2000);
  2043. _actor.setTarget(obj);
  2044. setAttackTarget(obj);
  2045. return;
  2046. }
  2047. }
  2048. if(!(_actor instanceof L2GuardInstance))
  2049. {
  2050. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  2051. for (L2Object target : objs)
  2052. {
  2053. L2Character obj = null;
  2054. if (target instanceof L2Character)
  2055. obj = (L2Character)target;
  2056. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead() || obj!= MostHate || obj == _actor || obj == getAttackTarget())
  2057. continue;
  2058. if(obj instanceof L2PcInstance)
  2059. {
  2060. if(MostHate != null)
  2061. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2062. else
  2063. actor.addDamageHate(obj,2000,2000);
  2064. _actor.setTarget(obj);
  2065. setAttackTarget(obj);
  2066. }
  2067. else if(obj instanceof L2Attackable)
  2068. {
  2069. if(((L2Attackable)_actor).getEnemyClan() != null && (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan())) && !"none".equals(((L2Attackable)_actor).getEnemyClan()))
  2070. {
  2071. actor.addDamageHate(obj,0,actor.getHating(MostHate));
  2072. _actor.setTarget(obj);
  2073. }
  2074. if (((L2Attackable)_actor).getIsChaos() != 0)
  2075. {
  2076. if(((L2Attackable)obj).getFactionId() != null && ((L2Attackable)obj).getFactionId().equals(((L2Attackable)_actor).getFactionId()))
  2077. continue;
  2078. else
  2079. {
  2080. if(MostHate != null)
  2081. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2082. else
  2083. actor.addDamageHate(obj,2000,2000);
  2084. _actor.setTarget(obj);
  2085. setAttackTarget(obj);
  2086. }
  2087. }
  2088. }
  2089. else if(obj instanceof L2Summon)
  2090. {
  2091. if(MostHate != null)
  2092. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2093. else
  2094. actor.addDamageHate(obj,2000,2000);
  2095. _actor.setTarget(obj);
  2096. setAttackTarget(obj);
  2097. }
  2098. }
  2099. }
  2100. }
  2101. @SuppressWarnings("null")
  2102. private void AggroReconsider()
  2103. {
  2104. L2Attackable actor = (L2Attackable)_actor;
  2105. L2Character MostHate = ((L2Attackable) _actor).getMostHated();
  2106. if(actor.getHateList() != null)
  2107. {
  2108. int rand = Rnd.get(actor.getHateList().size());
  2109. int count = 0;
  2110. for(L2Character obj: actor.getHateList())
  2111. {
  2112. if(count < rand)
  2113. {
  2114. count++;
  2115. continue;
  2116. }
  2117. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead()|| obj == getAttackTarget() || obj == actor)
  2118. continue;
  2119. try
  2120. {
  2121. _actor.setTarget(getAttackTarget());
  2122. }
  2123. catch (NullPointerException e)
  2124. {
  2125. continue;
  2126. }
  2127. if(MostHate!=null)
  2128. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2129. else
  2130. actor.addDamageHate(obj,2000,2000);
  2131. _actor.setTarget(obj);
  2132. setAttackTarget(obj);
  2133. return;
  2134. }
  2135. }
  2136. if(!(_actor instanceof L2GuardInstance))
  2137. {
  2138. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  2139. for (L2Object target : objs)
  2140. {
  2141. L2Character obj = null;
  2142. if(target instanceof L2Character)
  2143. obj = (L2Character)target;
  2144. else
  2145. continue;
  2146. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead() || obj != MostHate || obj == _actor)
  2147. continue;
  2148. if(obj instanceof L2PcInstance)
  2149. {
  2150. if(MostHate!=null || !MostHate.isDead())
  2151. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2152. else
  2153. actor.addDamageHate(obj,2000,2000);
  2154. _actor.setTarget(obj);
  2155. setAttackTarget(obj);
  2156. }
  2157. else if(obj instanceof L2Attackable)
  2158. {
  2159. if(((L2Attackable)_actor).getEnemyClan() != null && (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan())) && !"none".equals(((L2Attackable)_actor).getEnemyClan()))
  2160. {
  2161. if(MostHate != null)
  2162. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2163. else
  2164. actor.addDamageHate(obj,2000,2000);
  2165. _actor.setTarget(obj);
  2166. }
  2167. if (((L2Attackable)_actor).getIsChaos() != 0)
  2168. {
  2169. if(((L2Attackable)obj).getFactionId() != null && ((L2Attackable)obj).getFactionId().equals(((L2Attackable)_actor).getFactionId()))
  2170. continue;
  2171. else
  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. setAttackTarget(obj);
  2179. }
  2180. }
  2181. }
  2182. else if(obj instanceof L2Summon)
  2183. {
  2184. if(MostHate != null)
  2185. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2186. else
  2187. actor.addDamageHate(obj,2000,2000);
  2188. _actor.setTarget(obj);
  2189. setAttackTarget(obj);
  2190. }
  2191. }
  2192. }
  2193. }
  2194. private void LSkillRender()
  2195. {
  2196. if(_skillrender._Lrangeskills == null)
  2197. _skillrender._Lrangeskills = ((L2Npc)_actor).getLrangeSkill();
  2198. }
  2199. private void SSkillRender()
  2200. {
  2201. if(_skillrender._Srangeskills == null)
  2202. _skillrender._Srangeskills = ((L2Npc)_actor).getSrangeSkill();
  2203. }
  2204. /**
  2205. * Manage AI thinking actions of a L2Attackable.<BR><BR>
  2206. */
  2207. @Override
  2208. protected void onEvtThink()
  2209. {
  2210. // Check if the actor can't use skills and if a thinking action isn't already in progress
  2211. if (_thinking || _actor.isAllSkillsDisabled()) return;
  2212. // Start thinking action
  2213. _thinking = true;
  2214. try
  2215. {
  2216. // Manage AI thinks of a L2Attackable
  2217. if (getIntention() == AI_INTENTION_ACTIVE) thinkActive();
  2218. else if (getIntention() == AI_INTENTION_ATTACK) thinkAttack();
  2219. }
  2220. finally
  2221. {
  2222. // Stop thinking action
  2223. _thinking = false;
  2224. }
  2225. }
  2226. /**
  2227. * Launch actions corresponding to the Event Attacked.<BR><BR>
  2228. *
  2229. * <B><U> Actions</U> :</B><BR><BR>
  2230. * <li>Init the attack : Calculate the attack timeout, Set the _globalAggro to 0, Add the attacker to the actor _aggroList</li>
  2231. * <li>Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance</li>
  2232. * <li>Set the Intention to AI_INTENTION_ATTACK</li><BR><BR>
  2233. *
  2234. * @param attacker The L2Character that attacks the actor
  2235. *
  2236. */
  2237. @Override
  2238. protected void onEvtAttacked(L2Character attacker)
  2239. {
  2240. //if (_actor instanceof L2ChestInstance && !((L2ChestInstance)_actor).isInteracted())
  2241. //{
  2242. //((L2ChestInstance)_actor).deleteMe();
  2243. //((L2ChestInstance)_actor).getSpawn().startRespawn();
  2244. //return;
  2245. //}
  2246. // Calculate the attack timeout
  2247. _attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks();
  2248. // Set the _globalAggro to 0 to permit attack even just after spawn
  2249. if (_globalAggro < 0) _globalAggro = 0;
  2250. // Add the attacker to the _aggroList of the actor
  2251. ((L2Attackable) _actor).addDamageHate(attacker, 0, 1);
  2252. // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  2253. if (!_actor.isRunning()) _actor.setRunning();
  2254. // Set the Intention to AI_INTENTION_ATTACK
  2255. if (getIntention() != AI_INTENTION_ATTACK)
  2256. {
  2257. setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  2258. }
  2259. else if (((L2Attackable) _actor).getMostHated() != getAttackTarget())
  2260. {
  2261. setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  2262. }
  2263. super.onEvtAttacked(attacker);
  2264. }
  2265. /**
  2266. * Launch actions corresponding to the Event Aggression.<BR><BR>
  2267. *
  2268. * <B><U> Actions</U> :</B><BR><BR>
  2269. * <li>Add the target to the actor _aggroList or update hate if already present </li>
  2270. * <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>
  2271. *
  2272. * @param attacker The L2Character that attacks
  2273. * @param aggro The value of hate to add to the actor against the target
  2274. *
  2275. */
  2276. @Override
  2277. protected void onEvtAggression(L2Character target, int aggro)
  2278. {
  2279. L2Attackable me = (L2Attackable) _actor;
  2280. if (target != null)
  2281. {
  2282. // Add the target to the actor _aggroList or update hate if already present
  2283. me.addDamageHate(target, 0, aggro);
  2284. // Set the actor AI Intention to AI_INTENTION_ATTACK
  2285. if (getIntention() != CtrlIntention.AI_INTENTION_ATTACK)
  2286. {
  2287. // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  2288. if (!_actor.isRunning()) _actor.setRunning();
  2289. setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  2290. }
  2291. }
  2292. }
  2293. @Override
  2294. protected void onIntentionActive()
  2295. {
  2296. // Cancel attack timeout
  2297. _attackTimeout = Integer.MAX_VALUE;
  2298. super.onIntentionActive();
  2299. }
  2300. public void setGlobalAggro(int value)
  2301. {
  2302. _globalAggro = value;
  2303. }
  2304. /**
  2305. * @param clan The clan to set.
  2306. */
  2307. public void setClan(String CL)
  2308. {
  2309. this.clan = CL;
  2310. }
  2311. /**
  2312. * @return Returns the clan.
  2313. */
  2314. public String getClan()
  2315. {
  2316. return clan;
  2317. }
  2318. /**
  2319. * @param enemyClan The enemyClan to set.
  2320. */
  2321. public void setEnemyClan(String EC)
  2322. {
  2323. this.enemyClan = EC;
  2324. }
  2325. /**
  2326. * @return Returns the enemyClan.
  2327. */
  2328. public String getEnemyClan()
  2329. {
  2330. return enemyClan;
  2331. }
  2332. /**
  2333. * @param timepass The timepass to set.
  2334. */
  2335. public void setTimepass(int TP)
  2336. {
  2337. this.timepass = TP;
  2338. }
  2339. /**
  2340. * @return Returns the timepass.
  2341. */
  2342. public int getTimepass()
  2343. {
  2344. return timepass;
  2345. }
  2346. }