L2CharacterAI.java 49 KB

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