L2CharacterAI.java 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342
  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 net.sf.l2j.gameserver.ai;
  16. import static net.sf.l2j.gameserver.ai.CtrlIntention.*;
  17. import java.util.List;
  18. import javolution.util.FastList;
  19. import net.sf.l2j.Config;
  20. import net.sf.l2j.gameserver.Universe;
  21. import net.sf.l2j.gameserver.model.L2Attackable;
  22. import net.sf.l2j.gameserver.model.L2CharPosition;
  23. import net.sf.l2j.gameserver.model.L2Character;
  24. import net.sf.l2j.gameserver.model.L2ItemInstance;
  25. import net.sf.l2j.gameserver.model.L2Object;
  26. import net.sf.l2j.gameserver.model.L2Skill;
  27. import net.sf.l2j.gameserver.model.L2ItemInstance.ItemLocation;
  28. import net.sf.l2j.gameserver.model.actor.instance.L2BoatInstance;
  29. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  30. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  31. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  32. import net.sf.l2j.gameserver.network.serverpackets.AutoAttackStop;
  33. import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager;
  34. import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
  35. import net.sf.l2j.gameserver.templates.item.L2Weapon;
  36. import net.sf.l2j.gameserver.templates.item.L2WeaponType;
  37. import net.sf.l2j.util.Point3D;
  38. import net.sf.l2j.util.Rnd;
  39. /**
  40. * This class manages AI of L2Character.<BR><BR>
  41. *
  42. * L2CharacterAI :<BR><BR>
  43. * <li>L2AttackableAI</li>
  44. * <li>L2DoorAI</li>
  45. * <li>L2PlayerAI</li>
  46. * <li>L2SummonAI</li><BR><BR>
  47. *
  48. */
  49. public class L2CharacterAI extends AbstractAI
  50. {
  51. class IntentionCommand
  52. {
  53. protected CtrlIntention _crtlIntention;
  54. protected Object _arg0, _arg1;
  55. protected IntentionCommand(CtrlIntention pIntention, Object pArg0, Object pArg1)
  56. {
  57. _crtlIntention = pIntention;
  58. _arg0 = pArg0;
  59. _arg1 = pArg1;
  60. }
  61. }
  62. /**
  63. * Constructor of L2CharacterAI.<BR><BR>
  64. *
  65. * @param accessor The AI accessor of the L2Character
  66. *
  67. */
  68. public L2CharacterAI(L2Character.AIAccessor accessor)
  69. {
  70. super(accessor);
  71. }
  72. public IntentionCommand getNextIntention()
  73. {
  74. return null;
  75. }
  76. @Override
  77. protected void onEvtAttacked(L2Character attacker)
  78. {
  79. if (attacker instanceof L2Attackable && !((L2Attackable) attacker).isCoreAIDisabled())
  80. clientStartAutoAttack();
  81. }
  82. /**
  83. * Manage the Idle Intention : Stop Attack, Movement and Stand Up the actor.<BR><BR>
  84. *
  85. * <B><U> Actions</U> :</B><BR><BR>
  86. * <li>Set the AI Intention to AI_INTENTION_IDLE </li>
  87. * <li>Init cast and attack target </li>
  88. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  89. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast) </li>
  90. * <li>Stand up the actor server side AND client side by sending Server->Client packet ChangeWaitType (broadcast) </li><BR><BR>
  91. *
  92. */
  93. @Override
  94. protected void onIntentionIdle()
  95. {
  96. // Set the AI Intention to AI_INTENTION_IDLE
  97. changeIntention(AI_INTENTION_IDLE, null, null);
  98. // Init cast and attack target
  99. setCastTarget(null);
  100. setAttackTarget(null);
  101. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  102. clientStopMoving(null);
  103. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  104. clientStopAutoAttack();
  105. }
  106. /**
  107. * Manage the Active Intention : Stop Attack, Movement and Launch Think Event.<BR><BR>
  108. *
  109. * <B><U> Actions</U> : <I>if the Intention is not already Active</I></B><BR><BR>
  110. * <li>Set the AI Intention to AI_INTENTION_ACTIVE </li>
  111. * <li>Init cast and attack target </li>
  112. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  113. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast) </li>
  114. * <li>Launch the Think Event </li><BR><BR>
  115. *
  116. */
  117. @Override
  118. protected void onIntentionActive()
  119. {
  120. // Check if the Intention is not already Active
  121. if (getIntention() != AI_INTENTION_ACTIVE)
  122. {
  123. // Set the AI Intention to AI_INTENTION_ACTIVE
  124. changeIntention(AI_INTENTION_ACTIVE, null, null);
  125. // Init cast and attack target
  126. setCastTarget(null);
  127. setAttackTarget(null);
  128. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  129. clientStopMoving(null);
  130. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  131. clientStopAutoAttack();
  132. // Also enable random animations for this L2Character if allowed
  133. // This is only for mobs - town npcs are handled in their constructor
  134. if (_actor instanceof L2Attackable)
  135. ((L2NpcInstance) _actor).startRandomAnimationTimer();
  136. // Launch the Think Event
  137. onEvtThink();
  138. }
  139. }
  140. /**
  141. * Manage the Rest Intention.<BR><BR>
  142. *
  143. * <B><U> Actions</U> : </B><BR><BR>
  144. * <li>Set the AI Intention to AI_INTENTION_IDLE </li><BR><BR>
  145. *
  146. */
  147. @Override
  148. protected void onIntentionRest()
  149. {
  150. // Set the AI Intention to AI_INTENTION_IDLE
  151. setIntention(AI_INTENTION_IDLE);
  152. }
  153. /**
  154. * Manage the Attack Intention : Stop current Attack (if necessary), Start a new Attack and Launch Think Event.<BR><BR>
  155. *
  156. * <B><U> Actions</U> : </B><BR><BR>
  157. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  158. * <li>Set the Intention of this AI to AI_INTENTION_ATTACK </li>
  159. * <li>Set or change the AI attack target </li>
  160. * <li>Start the actor Auto Attack client side by sending Server->Client packet AutoAttackStart (broadcast) </li>
  161. * <li>Launch the Think Event </li><BR><BR>
  162. *
  163. *
  164. * <B><U> Overridden in</U> :</B><BR><BR>
  165. * <li>L2AttackableAI : Calculate attack timeout</li><BR><BR>
  166. *
  167. */
  168. @Override
  169. protected void onIntentionAttack(L2Character target)
  170. {
  171. if (target == null)
  172. {
  173. clientActionFailed();
  174. return;
  175. }
  176. if (getIntention() == AI_INTENTION_REST)
  177. {
  178. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  179. clientActionFailed();
  180. return;
  181. }
  182. if (_actor.isAllSkillsDisabled() || _actor.isCastingNow() || _actor.isAfraid())
  183. {
  184. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  185. clientActionFailed();
  186. return;
  187. }
  188. // Check if the Intention is already AI_INTENTION_ATTACK
  189. if (getIntention() == AI_INTENTION_ATTACK)
  190. {
  191. // Check if the AI already targets the L2Character
  192. if (getAttackTarget() != target)
  193. {
  194. // Set the AI attack target (change target)
  195. setAttackTarget(target);
  196. stopFollow();
  197. // Launch the Think Event
  198. notifyEvent(CtrlEvent.EVT_THINK, null);
  199. }
  200. else
  201. clientActionFailed(); // else client freezes until cancel target
  202. }
  203. else
  204. {
  205. // Set the Intention of this AbstractAI to AI_INTENTION_ATTACK
  206. changeIntention(AI_INTENTION_ATTACK, target, null);
  207. // Set the AI attack target
  208. setAttackTarget(target);
  209. stopFollow();
  210. // Launch the Think Event
  211. notifyEvent(CtrlEvent.EVT_THINK, null);
  212. }
  213. }
  214. /**
  215. * Manage the Cast Intention : Stop current Attack, Init the AI in order to cast and Launch Think Event.<BR><BR>
  216. *
  217. * <B><U> Actions</U> : </B><BR><BR>
  218. * <li>Set the AI cast target </li>
  219. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  220. * <li>Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor </li>
  221. * <li>Set the AI skill used by INTENTION_CAST </li>
  222. * <li>Set the Intention of this AI to AI_INTENTION_CAST </li>
  223. * <li>Launch the Think Event </li><BR><BR>
  224. *
  225. */
  226. @Override
  227. protected void onIntentionCast(L2Skill skill, L2Object target)
  228. {
  229. if (getIntention() == AI_INTENTION_REST && skill.isMagic())
  230. {
  231. clientActionFailed();
  232. _actor.setIsCastingNow(false);
  233. return;
  234. }
  235. // Set the AI cast target
  236. setCastTarget((L2Character) target);
  237. // Stop actions client-side to cast the skill
  238. if (skill.getHitTime() > 50)
  239. {
  240. // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  241. _actor.abortAttack();
  242. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  243. // no need for second ActionFailed packet, abortAttack() already sent it
  244. //clientActionFailed();
  245. }
  246. // Set the AI skill used by INTENTION_CAST
  247. _skill = skill;
  248. // Change the Intention of this AbstractAI to AI_INTENTION_CAST
  249. changeIntention(AI_INTENTION_CAST, skill, target);
  250. // Launch the Think Event
  251. notifyEvent(CtrlEvent.EVT_THINK, null);
  252. }
  253. /**
  254. * Manage the Move To Intention : Stop current Attack and Launch a Move to Location Task.<BR><BR>
  255. *
  256. * <B><U> Actions</U> : </B><BR><BR>
  257. * <li>Stop the actor auto-attack server side AND client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  258. * <li>Set the Intention of this AI to AI_INTENTION_MOVE_TO </li>
  259. * <li>Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast) </li><BR><BR>
  260. *
  261. */
  262. @Override
  263. protected void onIntentionMoveTo(L2CharPosition pos)
  264. {
  265. if (getIntention() == AI_INTENTION_REST)
  266. {
  267. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  268. clientActionFailed();
  269. return;
  270. }
  271. if (_actor.isAllSkillsDisabled() || _actor.isCastingNow())
  272. {
  273. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  274. clientActionFailed();
  275. return;
  276. }
  277. // Set the Intention of this AbstractAI to AI_INTENTION_MOVE_TO
  278. changeIntention(AI_INTENTION_MOVE_TO, pos, null);
  279. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  280. clientStopAutoAttack();
  281. // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  282. _actor.abortAttack();
  283. // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
  284. moveTo(pos.x, pos.y, pos.z);
  285. }
  286. /* (non-Javadoc)
  287. * @see net.sf.l2j.gameserver.ai.AbstractAI#onIntentionMoveToInABoat(net.sf.l2j.gameserver.model.L2CharPosition, net.sf.l2j.gameserver.model.L2CharPosition)
  288. */
  289. @Override
  290. protected void onIntentionMoveToInABoat(L2CharPosition destination, L2CharPosition origin)
  291. {
  292. if (getIntention() == AI_INTENTION_REST)
  293. {
  294. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  295. clientActionFailed();
  296. return;
  297. }
  298. if (_actor.isAllSkillsDisabled() || _actor.isCastingNow())
  299. {
  300. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  301. clientActionFailed();
  302. return;
  303. }
  304. // Set the Intention of this AbstractAI to AI_INTENTION_MOVE_TO
  305. //
  306. //changeIntention(AI_INTENTION_MOVE_TO, new L2CharPosition(((L2PcInstance)_actor).getBoat().getX() - destination.x, ((L2PcInstance)_actor).getBoat().getY() - destination.y, ((L2PcInstance)_actor).getBoat().getZ() - destination.z, 0) , null);
  307. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  308. clientStopAutoAttack();
  309. // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  310. _actor.abortAttack();
  311. // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
  312. moveToInABoat(destination, origin);
  313. }
  314. /**
  315. * Manage the Follow Intention : Stop current Attack and Launch a Follow Task.<BR><BR>
  316. *
  317. * <B><U> Actions</U> : </B><BR><BR>
  318. * <li>Stop the actor auto-attack server side AND client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  319. * <li>Set the Intention of this AI to AI_INTENTION_FOLLOW </li>
  320. * <li>Create and Launch an AI Follow Task to execute every 1s </li><BR><BR>
  321. *
  322. */
  323. @Override
  324. protected void onIntentionFollow(L2Character target)
  325. {
  326. if (getIntention() == AI_INTENTION_REST)
  327. {
  328. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  329. clientActionFailed();
  330. return;
  331. }
  332. if (_actor.isAllSkillsDisabled() || _actor.isCastingNow())
  333. {
  334. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  335. clientActionFailed();
  336. return;
  337. }
  338. if (_actor.isImmobilized() || _actor.isRooted())
  339. {
  340. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  341. clientActionFailed();
  342. return;
  343. }
  344. // Dead actors can`t follow
  345. if (_actor.isDead())
  346. {
  347. clientActionFailed();
  348. return;
  349. }
  350. // do not follow yourself
  351. if (_actor == target)
  352. {
  353. clientActionFailed();
  354. return;
  355. }
  356. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  357. clientStopAutoAttack();
  358. // Set the Intention of this AbstractAI to AI_INTENTION_FOLLOW
  359. changeIntention(AI_INTENTION_FOLLOW, target, null);
  360. // Create and Launch an AI Follow Task to execute every 1s
  361. startFollow(target);
  362. }
  363. /**
  364. * Manage the PickUp Intention : Set the pick up target and Launch a Move To Pawn Task (offset=20).<BR><BR>
  365. *
  366. * <B><U> Actions</U> : </B><BR><BR>
  367. * <li>Set the AI pick up target </li>
  368. * <li>Set the Intention of this AI to AI_INTENTION_PICK_UP </li>
  369. * <li>Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast) </li><BR><BR>
  370. *
  371. */
  372. @Override
  373. protected void onIntentionPickUp(L2Object object)
  374. {
  375. if (getIntention() == AI_INTENTION_REST)
  376. {
  377. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  378. clientActionFailed();
  379. return;
  380. }
  381. if (_actor.isAllSkillsDisabled() || _actor.isCastingNow())
  382. {
  383. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  384. clientActionFailed();
  385. return;
  386. }
  387. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  388. clientStopAutoAttack();
  389. if (object instanceof L2ItemInstance && ((L2ItemInstance)object).getLocation() != ItemLocation.VOID)
  390. return;
  391. // Set the Intention of this AbstractAI to AI_INTENTION_PICK_UP
  392. changeIntention(AI_INTENTION_PICK_UP, object, null);
  393. // Set the AI pick up target
  394. setTarget(object);
  395. if (object.getX() == 0 && object.getY() == 0) // TODO: Find the drop&spawn bug
  396. {
  397. _log.warning("Object in coords 0,0 - using a temporary fix");
  398. object.setXYZ(getActor().getX(), getActor().getY(), getActor().getZ() + 5);
  399. }
  400. // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast)
  401. moveToPawn(object, 20);
  402. }
  403. /**
  404. * Manage the Interact Intention : Set the interact target and Launch a Move To Pawn Task (offset=60).<BR><BR>
  405. *
  406. * <B><U> Actions</U> : </B><BR><BR>
  407. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  408. * <li>Set the AI interact target </li>
  409. * <li>Set the Intention of this AI to AI_INTENTION_INTERACT </li>
  410. * <li>Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast) </li><BR><BR>
  411. *
  412. */
  413. @Override
  414. protected void onIntentionInteract(L2Object object)
  415. {
  416. if (getIntention() == AI_INTENTION_REST)
  417. {
  418. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  419. clientActionFailed();
  420. return;
  421. }
  422. if (_actor.isAllSkillsDisabled() || _actor.isCastingNow())
  423. {
  424. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  425. clientActionFailed();
  426. return;
  427. }
  428. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  429. clientStopAutoAttack();
  430. if (getIntention() != AI_INTENTION_INTERACT)
  431. {
  432. // Set the Intention of this AbstractAI to AI_INTENTION_INTERACT
  433. changeIntention(AI_INTENTION_INTERACT, object, null);
  434. // Set the AI interact target
  435. setTarget(object);
  436. // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast)
  437. moveToPawn(object, 60);
  438. }
  439. }
  440. /**
  441. * Do nothing.<BR><BR>
  442. */
  443. @Override
  444. protected void onEvtThink()
  445. {
  446. // do nothing
  447. }
  448. /**
  449. * Do nothing.<BR><BR>
  450. */
  451. @Override
  452. protected void onEvtAggression(L2Character target, int aggro)
  453. {
  454. // do nothing
  455. }
  456. /**
  457. * Launch actions corresponding to the Event Stunned then onAttacked Event.<BR><BR>
  458. *
  459. * <B><U> Actions</U> :</B><BR><BR>
  460. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
  461. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  462. * <li>Break an attack and send Server->Client ActionFailed packet and a System Message to the L2Character </li>
  463. * <li>Break a cast and send Server->Client ActionFailed packet and a System Message to the L2Character </li>
  464. * <li>Launch actions corresponding to the Event onAttacked (only for L2AttackableAI after the stunning periode) </li><BR><BR>
  465. *
  466. */
  467. @Override
  468. protected void onEvtStunned(L2Character attacker)
  469. {
  470. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  471. _actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId()));
  472. if (AttackStanceTaskManager.getInstance().getAttackStanceTask(_actor))
  473. AttackStanceTaskManager.getInstance().removeAttackStanceTask(_actor);
  474. // Stop Server AutoAttack also
  475. setAutoAttacking(false);
  476. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  477. clientStopMoving(null);
  478. // Launch actions corresponding to the Event onAttacked (only for L2AttackableAI after the stunning periode)
  479. onEvtAttacked(attacker);
  480. }
  481. @Override
  482. protected void onEvtParalyzed(L2Character attacker)
  483. {
  484. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  485. _actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId()));
  486. if (AttackStanceTaskManager.getInstance().getAttackStanceTask(_actor))
  487. AttackStanceTaskManager.getInstance().removeAttackStanceTask(_actor);
  488. // Stop Server AutoAttack also
  489. setAutoAttacking(false);
  490. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  491. clientStopMoving(null);
  492. // Launch actions corresponding to the Event onAttacked (only for L2AttackableAI after the stunning periode)
  493. onEvtAttacked(attacker);
  494. }
  495. /**
  496. * Launch actions corresponding to the Event Sleeping.<BR><BR>
  497. *
  498. * <B><U> Actions</U> :</B><BR><BR>
  499. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
  500. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  501. * <li>Break an attack and send Server->Client ActionFailed packet and a System Message to the L2Character </li>
  502. * <li>Break a cast and send Server->Client ActionFailed packet and a System Message to the L2Character </li><BR><BR>
  503. *
  504. */
  505. @Override
  506. protected void onEvtSleeping(L2Character attacker)
  507. {
  508. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  509. _actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId()));
  510. if (AttackStanceTaskManager.getInstance().getAttackStanceTask(_actor))
  511. AttackStanceTaskManager.getInstance().removeAttackStanceTask(_actor);
  512. // stop Server AutoAttack also
  513. setAutoAttacking(false);
  514. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  515. clientStopMoving(null);
  516. }
  517. /**
  518. * Launch actions corresponding to the Event Rooted.<BR><BR>
  519. *
  520. * <B><U> Actions</U> :</B><BR><BR>
  521. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  522. * <li>Launch actions corresponding to the Event onAttacked</li><BR><BR>
  523. *
  524. */
  525. @Override
  526. protected void onEvtRooted(L2Character attacker)
  527. {
  528. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  529. //_actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId()));
  530. //if (AttackStanceTaskManager.getInstance().getAttackStanceTask(_actor))
  531. // AttackStanceTaskManager.getInstance().removeAttackStanceTask(_actor);
  532. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  533. clientStopMoving(null);
  534. // Launch actions corresponding to the Event onAttacked
  535. onEvtAttacked(attacker);
  536. }
  537. /**
  538. * Launch actions corresponding to the Event Confused.<BR><BR>
  539. *
  540. * <B><U> Actions</U> :</B><BR><BR>
  541. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  542. * <li>Launch actions corresponding to the Event onAttacked</li><BR><BR>
  543. *
  544. */
  545. @Override
  546. protected void onEvtConfused(L2Character attacker)
  547. {
  548. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  549. clientStopMoving(null);
  550. // Launch actions corresponding to the Event onAttacked
  551. onEvtAttacked(attacker);
  552. }
  553. /**
  554. * Launch actions corresponding to the Event Muted.<BR><BR>
  555. *
  556. * <B><U> Actions</U> :</B><BR><BR>
  557. * <li>Break a cast and send Server->Client ActionFailed packet and a System Message to the L2Character </li><BR><BR>
  558. *
  559. */
  560. @Override
  561. protected void onEvtMuted(L2Character attacker)
  562. {
  563. // Break a cast and send Server->Client ActionFailed packet and a System Message to the L2Character
  564. onEvtAttacked(attacker);
  565. }
  566. /**
  567. * Launch actions corresponding to the Event ReadyToAct.<BR><BR>
  568. *
  569. * <B><U> Actions</U> :</B><BR><BR>
  570. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  571. *
  572. */
  573. @Override
  574. protected void onEvtReadyToAct()
  575. {
  576. // Launch actions corresponding to the Event Think
  577. onEvtThink();
  578. }
  579. /**
  580. * Do nothing.<BR><BR>
  581. */
  582. @Override
  583. protected void onEvtUserCmd(Object arg0, Object arg1)
  584. {
  585. // do nothing
  586. }
  587. /**
  588. * Launch actions corresponding to the Event Arrived.<BR><BR>
  589. *
  590. * <B><U> Actions</U> :</B><BR><BR>
  591. * <li>If the Intention was AI_INTENTION_MOVE_TO, set the Intention to AI_INTENTION_ACTIVE</li>
  592. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  593. *
  594. */
  595. @Override
  596. protected void onEvtArrived()
  597. {
  598. // Launch an explore task if necessary
  599. if (Config.ACTIVATE_POSITION_RECORDER && _accessor.getActor() instanceof L2PcInstance)
  600. {
  601. ((L2PcInstance) _accessor.getActor()).explore();
  602. }
  603. _accessor.getActor().revalidateZone(true);
  604. if (_accessor.getActor().moveToNextRoutePoint())
  605. return;
  606. if (_accessor.getActor() instanceof L2Attackable)
  607. {
  608. ((L2Attackable) _accessor.getActor()).setisReturningToSpawnPoint(false);
  609. }
  610. clientStoppedMoving();
  611. // If the Intention was AI_INTENTION_MOVE_TO, set the Intention to AI_INTENTION_ACTIVE
  612. if (getIntention() == AI_INTENTION_MOVE_TO)
  613. setIntention(AI_INTENTION_ACTIVE);
  614. // Launch actions corresponding to the Event Think
  615. onEvtThink();
  616. if (_actor instanceof L2BoatInstance)
  617. {
  618. ((L2BoatInstance) _actor).evtArrived();
  619. }
  620. }
  621. /**
  622. * Launch actions corresponding to the Event ArrivedRevalidate.<BR><BR>
  623. *
  624. * <B><U> Actions</U> :</B><BR><BR>
  625. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  626. *
  627. */
  628. @Override
  629. protected void onEvtArrivedRevalidate()
  630. {
  631. // Launch actions corresponding to the Event Think
  632. onEvtThink();
  633. }
  634. /**
  635. * Launch actions corresponding to the Event ArrivedBlocked.<BR><BR>
  636. *
  637. * <B><U> Actions</U> :</B><BR><BR>
  638. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  639. * <li>If the Intention was AI_INTENTION_MOVE_TO, set the Intention to AI_INTENTION_ACTIVE</li>
  640. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  641. *
  642. */
  643. @Override
  644. protected void onEvtArrivedBlocked(L2CharPosition blocked_at_pos)
  645. {
  646. // If the Intention was AI_INTENTION_MOVE_TO, set the Intention to AI_INTENTION_ACTIVE
  647. if (getIntention() == AI_INTENTION_MOVE_TO || getIntention() == AI_INTENTION_CAST)
  648. setIntention(AI_INTENTION_ACTIVE);
  649. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  650. clientStopMoving(blocked_at_pos);
  651. if (Config.ACTIVATE_POSITION_RECORDER && Universe.getInstance().shouldLog(_accessor.getActor().getObjectId()))
  652. {
  653. if (!_accessor.getActor().isFlying())
  654. Universe.getInstance().registerObstacle(blocked_at_pos.x, blocked_at_pos.y, blocked_at_pos.z);
  655. if (_accessor.getActor() instanceof L2PcInstance)
  656. ((L2PcInstance) _accessor.getActor()).explore();
  657. }
  658. // Launch actions corresponding to the Event Think
  659. onEvtThink();
  660. }
  661. /**
  662. * Launch actions corresponding to the Event ForgetObject.<BR><BR>
  663. *
  664. * <B><U> Actions</U> :</B><BR><BR>
  665. * <li>If the object was targeted and the Intention was AI_INTENTION_INTERACT or AI_INTENTION_PICK_UP, set the Intention to AI_INTENTION_ACTIVE</li>
  666. * <li>If the object was targeted to attack, stop the auto-attack, cancel target and set the Intention to AI_INTENTION_ACTIVE</li>
  667. * <li>If the object was targeted to cast, cancel target and set the Intention to AI_INTENTION_ACTIVE</li>
  668. * <li>If the object was targeted to follow, stop the movement, cancel AI Follow Task and set the Intention to AI_INTENTION_ACTIVE</li>
  669. * <li>If the targeted object was the actor , cancel AI target, stop AI Follow Task, stop the movement and set the Intention to AI_INTENTION_IDLE </li><BR><BR>
  670. *
  671. */
  672. @Override
  673. protected void onEvtForgetObject(L2Object object)
  674. {
  675. // If the object was targeted and the Intention was AI_INTENTION_INTERACT or AI_INTENTION_PICK_UP, set the Intention to AI_INTENTION_ACTIVE
  676. if (getTarget() == object)
  677. {
  678. setTarget(null);
  679. if (getIntention() == AI_INTENTION_INTERACT)
  680. setIntention(AI_INTENTION_ACTIVE);
  681. else if (getIntention() == AI_INTENTION_PICK_UP)
  682. setIntention(AI_INTENTION_ACTIVE);
  683. }
  684. // Check if the object was targeted to attack
  685. if (getAttackTarget() == object)
  686. {
  687. // Cancel attack target
  688. setAttackTarget(null);
  689. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  690. setIntention(AI_INTENTION_ACTIVE);
  691. }
  692. // Check if the object was targeted to cast
  693. if (getCastTarget() == object)
  694. {
  695. // Cancel cast target
  696. setCastTarget(null);
  697. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  698. setIntention(AI_INTENTION_ACTIVE);
  699. }
  700. // Check if the object was targeted to follow
  701. if (getFollowTarget() == object)
  702. {
  703. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  704. clientStopMoving(null);
  705. // Stop an AI Follow Task
  706. stopFollow();
  707. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  708. setIntention(AI_INTENTION_ACTIVE);
  709. }
  710. // Check if the targeted object was the actor
  711. if (_actor == object)
  712. {
  713. // Cancel AI target
  714. setTarget(null);
  715. setAttackTarget(null);
  716. setCastTarget(null);
  717. // Stop an AI Follow Task
  718. stopFollow();
  719. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  720. clientStopMoving(null);
  721. // Set the Intention of this AbstractAI to AI_INTENTION_IDLE
  722. changeIntention(AI_INTENTION_IDLE, null, null);
  723. }
  724. }
  725. /**
  726. * Launch actions corresponding to the Event Cancel.<BR><BR>
  727. *
  728. * <B><U> Actions</U> :</B><BR><BR>
  729. * <li>Stop an AI Follow Task</li>
  730. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  731. *
  732. */
  733. @Override
  734. protected void onEvtCancel()
  735. {
  736. _actor.abortCast();
  737. // Stop an AI Follow Task
  738. stopFollow();
  739. if (!AttackStanceTaskManager.getInstance().getAttackStanceTask(_actor))
  740. _actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId()));
  741. // Launch actions corresponding to the Event Think
  742. onEvtThink();
  743. }
  744. /**
  745. * Launch actions corresponding to the Event Dead.<BR><BR>
  746. *
  747. * <B><U> Actions</U> :</B><BR><BR>
  748. * <li>Stop an AI Follow Task</li>
  749. * <li>Kill the actor client side by sending Server->Client packet AutoAttackStop, StopMove/StopRotation, Die (broadcast)</li><BR><BR>
  750. *
  751. */
  752. @Override
  753. protected void onEvtDead()
  754. {
  755. // Stop an AI Follow Task
  756. stopFollow();
  757. // Kill the actor client side by sending Server->Client packet AutoAttackStop, StopMove/StopRotation, Die (broadcast)
  758. clientNotifyDead();
  759. if (!(_actor instanceof L2PcInstance))
  760. _actor.setWalking();
  761. }
  762. /**
  763. * Launch actions corresponding to the Event Fake Death.<BR><BR>
  764. *
  765. * <B><U> Actions</U> :</B><BR><BR>
  766. * <li>Stop an AI Follow Task</li>
  767. *
  768. */
  769. @Override
  770. protected void onEvtFakeDeath()
  771. {
  772. // Stop an AI Follow Task
  773. stopFollow();
  774. // Stop the actor movement and send Server->Client packet StopMove/StopRotation (broadcast)
  775. clientStopMoving(null);
  776. // Init AI
  777. _intention = AI_INTENTION_IDLE;
  778. setTarget(null);
  779. setCastTarget(null);
  780. setAttackTarget(null);
  781. }
  782. /**
  783. * Do nothing.<BR><BR>
  784. */
  785. @Override
  786. protected void onEvtFinishCasting()
  787. {
  788. // do nothing
  789. }
  790. protected boolean maybeMoveToPosition(Point3D worldPosition, int offset)
  791. {
  792. if (worldPosition == null)
  793. {
  794. _log.warning("maybeMoveToPosition: worldPosition == NULL!");
  795. return false;
  796. }
  797. if (offset < 0)
  798. return false; // skill radius -1
  799. if (!_actor.isInsideRadius(worldPosition.getX(), worldPosition.getY(), offset + _actor.getTemplate().collisionRadius, false))
  800. {
  801. if (_actor.isMovementDisabled())
  802. return true;
  803. if (!_actor.isRunning() && !(this instanceof L2PlayerAI))
  804. _actor.setRunning();
  805. stopFollow();
  806. int x = _actor.getX();
  807. int y = _actor.getY();
  808. double dx = worldPosition.getX() - x;
  809. double dy = worldPosition.getY() - y;
  810. double dist = Math.sqrt(dx * dx + dy * dy);
  811. double sin = dy / dist;
  812. double cos = dx / dist;
  813. dist -= offset - 5;
  814. x += (int) (dist * cos);
  815. y += (int) (dist * sin);
  816. moveTo(x, y, worldPosition.getZ());
  817. return true;
  818. }
  819. if (getFollowTarget() != null)
  820. stopFollow();
  821. return false;
  822. }
  823. /**
  824. * Manage the Move to Pawn action in function of the distance and of the Interact area.<BR><BR>
  825. *
  826. * <B><U> Actions</U> :</B><BR><BR>
  827. * <li>Get the distance between the current position of the L2Character and the target (x,y)</li>
  828. * <li>If the distance > offset+20, move the actor (by running) to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast)</li>
  829. * <li>If the distance <= offset+20, Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li><BR><BR>
  830. *
  831. * <B><U> Example of use </U> :</B><BR><BR>
  832. * <li> L2PLayerAI, L2SummonAI</li><BR><BR>
  833. *
  834. * @param target The targeted L2Object
  835. * @param offset The Interact area radius
  836. *
  837. * @return True if a movement must be done
  838. *
  839. */
  840. protected boolean maybeMoveToPawn(L2Object target, int offset)
  841. {
  842. // Get the distance between the current position of the L2Character and the target (x,y)
  843. if (target == null)
  844. {
  845. _log.warning("maybeMoveToPawn: target == NULL!");
  846. return false;
  847. }
  848. if (offset < 0)
  849. return false; // skill radius -1
  850. offset += _actor.getTemplate().collisionRadius;
  851. if (target instanceof L2Character)
  852. offset += ((L2Character) target).getTemplate().collisionRadius;
  853. if (!_actor.isInsideRadius(target, offset, false, false))
  854. {
  855. // Caller should be L2Playable and thinkAttack/thinkCast/thinkInteract/thinkPickUp
  856. if (getFollowTarget() != null)
  857. {
  858. // allow larger hit range when the target is moving (check is run only once per second)
  859. if (!_actor.isInsideRadius(target, offset + 100, false, false))
  860. return true;
  861. stopFollow();
  862. return false;
  863. }
  864. if (_actor.isMovementDisabled())
  865. return true;
  866. // If not running, set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  867. if (!_actor.isRunning() && !(this instanceof L2PlayerAI))
  868. _actor.setRunning();
  869. stopFollow();
  870. if ((target instanceof L2Character) && !(target instanceof L2DoorInstance))
  871. {
  872. if (((L2Character) target).isMoving())
  873. offset -= 100;
  874. if (offset < 5)
  875. offset = 5;
  876. startFollow((L2Character) target, offset);
  877. }
  878. else
  879. {
  880. // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast)
  881. moveToPawn(target, offset);
  882. }
  883. return true;
  884. }
  885. if (getFollowTarget() != null)
  886. stopFollow();
  887. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  888. // clientStopMoving(null);
  889. return false;
  890. }
  891. /**
  892. * Modify current Intention and actions if the target is lost or dead.<BR><BR>
  893. *
  894. * <B><U> Actions</U> : <I>If the target is lost or dead</I></B><BR><BR>
  895. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
  896. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  897. * <li>Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE</li><BR><BR>
  898. *
  899. * <B><U> Example of use </U> :</B><BR><BR>
  900. * <li> L2PLayerAI, L2SummonAI</li><BR><BR>
  901. *
  902. * @param target The targeted L2Object
  903. *
  904. * @return True if the target is lost or dead (false if fakedeath)
  905. *
  906. */
  907. protected boolean checkTargetLostOrDead(L2Character target)
  908. {
  909. if (target == null || target.isAlikeDead())
  910. {
  911. //check if player is fakedeath
  912. if (target instanceof L2PcInstance && ((L2PcInstance)target).isFakeDeath())
  913. {
  914. target.stopFakeDeath(null);
  915. return false;
  916. }
  917. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  918. setIntention(AI_INTENTION_ACTIVE);
  919. return true;
  920. }
  921. return false;
  922. }
  923. /**
  924. * Modify current Intention and actions if the target is lost.<BR><BR>
  925. *
  926. * <B><U> Actions</U> : <I>If the target is lost</I></B><BR><BR>
  927. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
  928. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  929. * <li>Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE</li><BR><BR>
  930. *
  931. * <B><U> Example of use </U> :</B><BR><BR>
  932. * <li> L2PLayerAI, L2SummonAI</li><BR><BR>
  933. *
  934. * @param target The targeted L2Object
  935. *
  936. * @return True if the target is lost
  937. *
  938. */
  939. protected boolean checkTargetLost(L2Object target)
  940. {
  941. // check if player is fakedeath
  942. if (target instanceof L2PcInstance)
  943. {
  944. L2PcInstance target2 = (L2PcInstance) target; //convert object to chara
  945. if (target2.isFakeDeath())
  946. {
  947. target2.stopFakeDeath(null);
  948. return false;
  949. }
  950. }
  951. if (target == null)
  952. {
  953. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  954. setIntention(AI_INTENTION_ACTIVE);
  955. return true;
  956. }
  957. return false;
  958. }
  959. protected class SelfAnalysis
  960. {
  961. public boolean isMage = false;
  962. public boolean isBalanced;
  963. public boolean isArcher = false;
  964. public boolean isHealer = false;
  965. public boolean isFighter = false;
  966. public boolean cannotMoveOnLand = false;
  967. public List<L2Skill> generalSkills = new FastList<L2Skill>();
  968. public List<L2Skill> buffSkills = new FastList<L2Skill>();
  969. public int lastBuffTick = 0;
  970. public List<L2Skill> debuffSkills = new FastList<L2Skill>();
  971. public int lastDebuffTick = 0;
  972. public List<L2Skill> cancelSkills = new FastList<L2Skill>();
  973. public List<L2Skill> healSkills = new FastList<L2Skill>();
  974. //public List<L2Skill> trickSkills = new FastList<L2Skill>();
  975. public List<L2Skill> generalDisablers = new FastList<L2Skill>();
  976. public List<L2Skill> sleepSkills = new FastList<L2Skill>();
  977. public List<L2Skill> rootSkills = new FastList<L2Skill>();
  978. public List<L2Skill> muteSkills = new FastList<L2Skill>();
  979. public List<L2Skill> resurrectSkills = new FastList<L2Skill>();
  980. public boolean hasHealOrResurrect = false;
  981. public boolean hasLongRangeSkills = false;
  982. public boolean hasLongRangeDamageSkills = false;
  983. public int maxCastRange = 0;
  984. public SelfAnalysis()
  985. {
  986. }
  987. public void init()
  988. {
  989. switch (((L2NpcTemplate) _actor.getTemplate()).AI)
  990. {
  991. case FIGHTER:
  992. isFighter = true;
  993. break;
  994. case MAGE:
  995. isMage = true;
  996. break;
  997. case BALANCED:
  998. isBalanced = true;
  999. break;
  1000. case ARCHER:
  1001. isArcher = true;
  1002. break;
  1003. case HEALER:
  1004. isHealer = true;
  1005. break;
  1006. default:
  1007. isFighter = true;
  1008. break;
  1009. }
  1010. // water movement analysis
  1011. if (_actor instanceof L2NpcInstance)
  1012. {
  1013. int npcId = ((L2NpcInstance) _actor).getNpcId();
  1014. switch (npcId)
  1015. {
  1016. case 20314: // great white shark
  1017. case 20849: // Light Worm
  1018. cannotMoveOnLand = true;
  1019. break;
  1020. default:
  1021. cannotMoveOnLand = false;
  1022. break;
  1023. }
  1024. }
  1025. // skill analysis
  1026. for (L2Skill sk : _actor.getAllSkills())
  1027. {
  1028. if (sk.isPassive())
  1029. continue;
  1030. int castRange = sk.getCastRange();
  1031. boolean hasLongRangeDamageSkill = false;
  1032. switch (sk.getSkillType())
  1033. {
  1034. case HEAL:
  1035. case HEAL_PERCENT:
  1036. case HEAL_STATIC:
  1037. case BALANCE_LIFE:
  1038. case HOT:
  1039. healSkills.add(sk);
  1040. hasHealOrResurrect = true;
  1041. continue; // won't be considered something for fighting
  1042. case BUFF:
  1043. buffSkills.add(sk);
  1044. continue; // won't be considered something for fighting
  1045. case PARALYZE:
  1046. case STUN:
  1047. // hardcoding petrification until improvements are made to
  1048. // EffectTemplate... petrification is totally different for
  1049. // AI than paralyze
  1050. switch (sk.getId())
  1051. {
  1052. case 367:
  1053. case 4111:
  1054. case 4383:
  1055. case 4616:
  1056. case 4578:
  1057. sleepSkills.add(sk);
  1058. break;
  1059. default:
  1060. generalDisablers.add(sk);
  1061. break;
  1062. }
  1063. break;
  1064. case MUTE:
  1065. muteSkills.add(sk);
  1066. break;
  1067. case SLEEP:
  1068. sleepSkills.add(sk);
  1069. break;
  1070. case ROOT:
  1071. rootSkills.add(sk);
  1072. break;
  1073. case FEAR: // could be used as an alternative for healing?
  1074. case CONFUSION:
  1075. // trickSkills.add(sk);
  1076. case DEBUFF:
  1077. debuffSkills.add(sk);
  1078. break;
  1079. case CANCEL:
  1080. case MAGE_BANE:
  1081. case WARRIOR_BANE:
  1082. case NEGATE:
  1083. cancelSkills.add(sk);
  1084. break;
  1085. case RESURRECT:
  1086. resurrectSkills.add(sk);
  1087. hasHealOrResurrect = true;
  1088. break;
  1089. case NOTDONE:
  1090. case COREDONE:
  1091. continue; // won't be considered something for fighting
  1092. default:
  1093. generalSkills.add(sk);
  1094. hasLongRangeDamageSkill = true;
  1095. break;
  1096. }
  1097. if (castRange > 70)
  1098. {
  1099. hasLongRangeSkills = true;
  1100. if (hasLongRangeDamageSkill)
  1101. hasLongRangeDamageSkills = true;
  1102. }
  1103. if (castRange > maxCastRange)
  1104. maxCastRange = castRange;
  1105. }
  1106. // Because of missing skills, some mages/balanced cannot play like mages
  1107. if (!hasLongRangeDamageSkills && isMage)
  1108. {
  1109. isBalanced = true;
  1110. isMage = false;
  1111. isFighter = false;
  1112. }
  1113. if (!hasLongRangeSkills && (isMage || isBalanced))
  1114. {
  1115. isBalanced = false;
  1116. isMage = false;
  1117. isFighter = true;
  1118. }
  1119. if (generalSkills.isEmpty() && isMage)
  1120. {
  1121. isBalanced = true;
  1122. isMage = false;
  1123. }
  1124. }
  1125. }
  1126. protected class TargetAnalysis
  1127. {
  1128. public L2Character character;
  1129. public boolean isMage;
  1130. public boolean isBalanced;
  1131. public boolean isArcher;
  1132. public boolean isFighter;
  1133. public boolean isCanceled;
  1134. public boolean isSlower;
  1135. public boolean isMagicResistant;
  1136. public TargetAnalysis()
  1137. {
  1138. }
  1139. public void update(L2Character target)
  1140. {
  1141. // update status once in 4 seconds
  1142. if (target == character && Rnd.nextInt(100) > 25)
  1143. return;
  1144. character = target;
  1145. if (target == null)
  1146. return;
  1147. isMage = false;
  1148. isBalanced = false;
  1149. isArcher = false;
  1150. isFighter = false;
  1151. isCanceled = false;
  1152. if (target.getMAtk(null, null) > 1.5 * target.getPAtk(null))
  1153. isMage = true;
  1154. else if (target.getPAtk(null) * 0.8 < target.getMAtk(null, null) || target.getMAtk(null, null) * 0.8 > target.getPAtk(null))
  1155. {
  1156. isBalanced = true;
  1157. }
  1158. else
  1159. {
  1160. L2Weapon weapon = target.getActiveWeaponItem();
  1161. if (weapon != null && (weapon.getItemType() == L2WeaponType.BOW || weapon.getItemType() == L2WeaponType.CROSSBOW))
  1162. isArcher = true;
  1163. else
  1164. isFighter = true;
  1165. }
  1166. if (target.getRunSpeed() < _actor.getRunSpeed() - 3)
  1167. isSlower = true;
  1168. else
  1169. isSlower = false;
  1170. if (target.getMDef(null, null) * 1.2 > _actor.getMAtk(null, null))
  1171. isMagicResistant = true;
  1172. else
  1173. isMagicResistant = false;
  1174. if (target.getBuffCount() < 4)
  1175. isCanceled = true;
  1176. }
  1177. }
  1178. }