L2CharacterAI.java 49 KB

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