L2AttackableAI.java 81 KB

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