L2CharacterAI.java 49 KB

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