2
0

L2AttackableAI.java 81 KB

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