L2CharacterAI.java 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522
  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.model.L2CharPosition;
  29. import com.l2jserver.gameserver.model.L2ItemInstance;
  30. import com.l2jserver.gameserver.model.L2Object;
  31. import com.l2jserver.gameserver.model.L2Skill;
  32. import com.l2jserver.gameserver.model.L2ItemInstance.ItemLocation;
  33. import com.l2jserver.gameserver.model.actor.L2Attackable;
  34. import com.l2jserver.gameserver.model.actor.L2Character;
  35. import com.l2jserver.gameserver.model.actor.L2Npc;
  36. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  37. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  38. import com.l2jserver.gameserver.network.SystemMessageId;
  39. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  40. import com.l2jserver.gameserver.network.serverpackets.AutoAttackStop;
  41. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  42. import com.l2jserver.gameserver.taskmanager.AttackStanceTaskManager;
  43. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  44. import com.l2jserver.gameserver.templates.item.L2Weapon;
  45. import com.l2jserver.gameserver.templates.item.L2WeaponType;
  46. import com.l2jserver.util.Point3D;
  47. import com.l2jserver.util.Rnd;
  48. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  49. import com.l2jserver.gameserver.model.L2Effect;
  50. import com.l2jserver.gameserver.GeoData;
  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 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. // Launch an explore task if necessary
  595. if (Config.ACTIVATE_POSITION_RECORDER && _accessor.getActor() instanceof L2PcInstance)
  596. {
  597. ((L2PcInstance) _accessor.getActor()).explore();
  598. }
  599. _accessor.getActor().revalidateZone(true);
  600. if (_accessor.getActor().moveToNextRoutePoint())
  601. return;
  602. if (_accessor.getActor() instanceof L2Attackable)
  603. {
  604. ((L2Attackable) _accessor.getActor()).setisReturningToSpawnPoint(false);
  605. }
  606. clientStoppedMoving();
  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().getAttackStanceTask(_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 L2PcInstance))
  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().collisionRadius, 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().collisionRadius;
  843. if (target instanceof L2Character)
  844. offset += ((L2Character) target).getTemplate().collisionRadius;
  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. return true;
  858. // while flying there is no move to cast
  859. if (_actor.getAI().getIntention() == CtrlIntention.AI_INTENTION_CAST &&
  860. _actor instanceof L2PcInstance && ((L2PcInstance)_actor).isTransformed())
  861. {
  862. if (!((L2PcInstance)_actor).getTransformation().canStartFollowToCast())
  863. {
  864. ((L2PcInstance)_actor).sendPacket(new SystemMessage(SystemMessageId.DIST_TOO_FAR_CASTING_STOPPED));
  865. ((L2PcInstance)_actor).sendPacket(ActionFailed.STATIC_PACKET);
  866. return true;
  867. }
  868. }
  869. // If not running, set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  870. if (!_actor.isRunning() && !(this instanceof L2PlayerAI) && !(this instanceof L2SummonAI))
  871. _actor.setRunning();
  872. stopFollow();
  873. if ((target instanceof L2Character) && !(target instanceof L2DoorInstance))
  874. {
  875. if (((L2Character) target).isMoving())
  876. offset -= 100;
  877. if (offset < 5)
  878. offset = 5;
  879. startFollow((L2Character) target, offset);
  880. }
  881. else
  882. {
  883. // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast)
  884. moveToPawn(target, offset);
  885. }
  886. return true;
  887. }
  888. if (getFollowTarget() != null)
  889. stopFollow();
  890. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  891. // clientStopMoving(null);
  892. return false;
  893. }
  894. /**
  895. * Modify current Intention and actions if the target is lost or dead.<BR><BR>
  896. *
  897. * <B><U> Actions</U> : <I>If the target is lost or dead</I></B><BR><BR>
  898. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
  899. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  900. * <li>Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE</li><BR><BR>
  901. *
  902. * <B><U> Example of use </U> :</B><BR><BR>
  903. * <li> L2PLayerAI, L2SummonAI</li><BR><BR>
  904. *
  905. * @param target The targeted L2Object
  906. *
  907. * @return True if the target is lost or dead (false if fakedeath)
  908. *
  909. */
  910. protected boolean checkTargetLostOrDead(L2Character target)
  911. {
  912. if (target == null || target.isAlikeDead())
  913. {
  914. //check if player is fakedeath
  915. if (target instanceof L2PcInstance && ((L2PcInstance)target).isFakeDeath())
  916. {
  917. target.stopFakeDeath(null);
  918. return false;
  919. }
  920. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  921. setIntention(AI_INTENTION_ACTIVE);
  922. return true;
  923. }
  924. return false;
  925. }
  926. /**
  927. * Modify current Intention and actions if the target is lost.<BR><BR>
  928. *
  929. * <B><U> Actions</U> : <I>If the target is lost</I></B><BR><BR>
  930. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
  931. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  932. * <li>Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE</li><BR><BR>
  933. *
  934. * <B><U> Example of use </U> :</B><BR><BR>
  935. * <li> L2PLayerAI, L2SummonAI</li><BR><BR>
  936. *
  937. * @param target The targeted L2Object
  938. *
  939. * @return True if the target is lost
  940. *
  941. */
  942. protected boolean checkTargetLost(L2Object target)
  943. {
  944. // check if player is fakedeath
  945. if (target instanceof L2PcInstance)
  946. {
  947. L2PcInstance target2 = (L2PcInstance) target; //convert object to chara
  948. if (target2.isFakeDeath())
  949. {
  950. target2.stopFakeDeath(null);
  951. return false;
  952. }
  953. }
  954. if (target == null)
  955. {
  956. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  957. setIntention(AI_INTENTION_ACTIVE);
  958. return true;
  959. }
  960. return false;
  961. }
  962. protected class SelfAnalysis
  963. {
  964. public boolean isMage = false;
  965. public boolean isBalanced;
  966. public boolean isArcher = false;
  967. public boolean isHealer = false;
  968. public boolean isFighter = false;
  969. public boolean cannotMoveOnLand = false;
  970. public List<L2Skill> generalSkills = new FastList<L2Skill>();
  971. public List<L2Skill> buffSkills = new FastList<L2Skill>();
  972. public int lastBuffTick = 0;
  973. public List<L2Skill> debuffSkills = new FastList<L2Skill>();
  974. public int lastDebuffTick = 0;
  975. public List<L2Skill> cancelSkills = new FastList<L2Skill>();
  976. public List<L2Skill> healSkills = new FastList<L2Skill>();
  977. //public List<L2Skill> trickSkills = new FastList<L2Skill>();
  978. public List<L2Skill> generalDisablers = new FastList<L2Skill>();
  979. public List<L2Skill> sleepSkills = new FastList<L2Skill>();
  980. public List<L2Skill> rootSkills = new FastList<L2Skill>();
  981. public List<L2Skill> muteSkills = new FastList<L2Skill>();
  982. public List<L2Skill> resurrectSkills = new FastList<L2Skill>();
  983. public boolean hasHealOrResurrect = false;
  984. public boolean hasLongRangeSkills = false;
  985. public boolean hasLongRangeDamageSkills = false;
  986. public int maxCastRange = 0;
  987. public SelfAnalysis()
  988. {
  989. }
  990. public void init()
  991. {
  992. switch (((L2NpcTemplate) _actor.getTemplate()).getAIDataStatic().getAiType())
  993. {
  994. case FIGHTER:
  995. isFighter = true;
  996. break;
  997. case MAGE:
  998. isMage = true;
  999. break;
  1000. case CORPSE:
  1001. case BALANCED:
  1002. isBalanced = true;
  1003. break;
  1004. case ARCHER:
  1005. isArcher = true;
  1006. break;
  1007. case HEALER:
  1008. isHealer = true;
  1009. break;
  1010. default:
  1011. isFighter = true;
  1012. break;
  1013. }
  1014. // water movement analysis
  1015. if (_actor instanceof L2Npc)
  1016. {
  1017. int npcId = ((L2Npc) _actor).getNpcId();
  1018. switch (npcId)
  1019. {
  1020. case 20314: // great white shark
  1021. case 20849: // Light Worm
  1022. cannotMoveOnLand = true;
  1023. break;
  1024. default:
  1025. cannotMoveOnLand = false;
  1026. break;
  1027. }
  1028. }
  1029. // skill analysis
  1030. for (L2Skill sk : _actor.getAllSkills())
  1031. {
  1032. if (sk.isPassive())
  1033. continue;
  1034. int castRange = sk.getCastRange();
  1035. boolean hasLongRangeDamageSkill = false;
  1036. switch (sk.getSkillType())
  1037. {
  1038. case HEAL:
  1039. case HEAL_PERCENT:
  1040. case HEAL_STATIC:
  1041. case BALANCE_LIFE:
  1042. case HOT:
  1043. healSkills.add(sk);
  1044. hasHealOrResurrect = true;
  1045. continue; // won't be considered something for fighting
  1046. case BUFF:
  1047. buffSkills.add(sk);
  1048. continue; // won't be considered something for fighting
  1049. case PARALYZE:
  1050. case STUN:
  1051. // hardcoding petrification until improvements are made to
  1052. // EffectTemplate... petrification is totally different for
  1053. // AI than paralyze
  1054. switch (sk.getId())
  1055. {
  1056. case 367:
  1057. case 4111:
  1058. case 4383:
  1059. case 4616:
  1060. case 4578:
  1061. sleepSkills.add(sk);
  1062. break;
  1063. default:
  1064. generalDisablers.add(sk);
  1065. break;
  1066. }
  1067. break;
  1068. case MUTE:
  1069. muteSkills.add(sk);
  1070. break;
  1071. case SLEEP:
  1072. sleepSkills.add(sk);
  1073. break;
  1074. case ROOT:
  1075. rootSkills.add(sk);
  1076. break;
  1077. case FEAR: // could be used as an alternative for healing?
  1078. case CONFUSION:
  1079. // trickSkills.add(sk);
  1080. case DEBUFF:
  1081. debuffSkills.add(sk);
  1082. break;
  1083. case CANCEL:
  1084. case MAGE_BANE:
  1085. case WARRIOR_BANE:
  1086. case NEGATE:
  1087. cancelSkills.add(sk);
  1088. break;
  1089. case RESURRECT:
  1090. resurrectSkills.add(sk);
  1091. hasHealOrResurrect = true;
  1092. break;
  1093. case NOTDONE:
  1094. case COREDONE:
  1095. continue; // won't be considered something for fighting
  1096. default:
  1097. generalSkills.add(sk);
  1098. hasLongRangeDamageSkill = true;
  1099. break;
  1100. }
  1101. if (castRange > 70)
  1102. {
  1103. hasLongRangeSkills = true;
  1104. if (hasLongRangeDamageSkill)
  1105. hasLongRangeDamageSkills = true;
  1106. }
  1107. if (castRange > maxCastRange)
  1108. maxCastRange = castRange;
  1109. }
  1110. // Because of missing skills, some mages/balanced cannot play like mages
  1111. if (!hasLongRangeDamageSkills && isMage)
  1112. {
  1113. isBalanced = true;
  1114. isMage = false;
  1115. isFighter = false;
  1116. }
  1117. if (!hasLongRangeSkills && (isMage || isBalanced))
  1118. {
  1119. isBalanced = false;
  1120. isMage = false;
  1121. isFighter = true;
  1122. }
  1123. if (generalSkills.isEmpty() && isMage)
  1124. {
  1125. isBalanced = true;
  1126. isMage = false;
  1127. }
  1128. }
  1129. }
  1130. protected class TargetAnalysis
  1131. {
  1132. public L2Character character;
  1133. public boolean isMage;
  1134. public boolean isBalanced;
  1135. public boolean isArcher;
  1136. public boolean isFighter;
  1137. public boolean isCanceled;
  1138. public boolean isSlower;
  1139. public boolean isMagicResistant;
  1140. public TargetAnalysis()
  1141. {
  1142. }
  1143. public void update(L2Character target)
  1144. {
  1145. // update status once in 4 seconds
  1146. if (target == character && Rnd.nextInt(100) > 25)
  1147. return;
  1148. character = target;
  1149. if (target == null)
  1150. return;
  1151. isMage = false;
  1152. isBalanced = false;
  1153. isArcher = false;
  1154. isFighter = false;
  1155. isCanceled = false;
  1156. if (target.getMAtk(null, null) > 1.5 * target.getPAtk(null))
  1157. isMage = true;
  1158. else if (target.getPAtk(null) * 0.8 < target.getMAtk(null, null) || target.getMAtk(null, null) * 0.8 > target.getPAtk(null))
  1159. {
  1160. isBalanced = true;
  1161. }
  1162. else
  1163. {
  1164. L2Weapon weapon = target.getActiveWeaponItem();
  1165. if (weapon != null && (weapon.getItemType() == L2WeaponType.BOW || weapon.getItemType() == L2WeaponType.CROSSBOW))
  1166. isArcher = true;
  1167. else
  1168. isFighter = true;
  1169. }
  1170. if (target.getRunSpeed() < _actor.getRunSpeed() - 3)
  1171. isSlower = true;
  1172. else
  1173. isSlower = false;
  1174. if (target.getMDef(null, null) * 1.2 > _actor.getMAtk(null, null))
  1175. isMagicResistant = true;
  1176. else
  1177. isMagicResistant = false;
  1178. if (target.getBuffCount() < 4)
  1179. isCanceled = true;
  1180. }
  1181. }
  1182. public boolean canAura(L2Skill sk)
  1183. {
  1184. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_AURA
  1185. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_BEHIND_AURA
  1186. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_FRONT_AURA)
  1187. {
  1188. for(L2Object target:_actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()))
  1189. {
  1190. if (target == getAttackTarget())
  1191. return true;
  1192. }
  1193. }
  1194. return false;
  1195. }
  1196. public boolean canAOE(L2Skill sk)
  1197. {
  1198. if(sk.getSkillType() != L2SkillType.NEGATE || sk.getSkillType() != L2SkillType.CANCEL)
  1199. {
  1200. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_AURA
  1201. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_BEHIND_AURA
  1202. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_FRONT_AURA
  1203. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_MULTIFACE)
  1204. {
  1205. boolean cancast = true;
  1206. for(L2Character target:_actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()))
  1207. {
  1208. if(!GeoData.getInstance().canSeeTarget(_actor,target))
  1209. continue;
  1210. if(target instanceof L2Attackable)
  1211. {
  1212. L2Npc targets = ((L2Npc)target);
  1213. L2Npc actors = ((L2Npc)_actor);
  1214. if(targets.getEnemyClan() == null || actors.getClan() == null || !targets.getEnemyClan().equals(actors.getClan()) || (actors.getClan() == null && actors.getIsChaos() == 0))
  1215. continue;
  1216. }
  1217. L2Effect[] effects = target.getAllEffects();
  1218. for (int i = 0; effects != null && i < effects.length; i++)
  1219. {
  1220. L2Effect effect = effects[i];
  1221. if (effect.getSkill() == sk)
  1222. {
  1223. cancast=false;
  1224. break;
  1225. }
  1226. }
  1227. }
  1228. if(cancast)
  1229. return true;
  1230. }
  1231. else if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_AREA
  1232. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_BEHIND_AREA
  1233. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_FRONT_AREA)
  1234. {
  1235. boolean cancast = true;
  1236. for(L2Character target: getAttackTarget().getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()))
  1237. {
  1238. if(!GeoData.getInstance().canSeeTarget(_actor,target) || target == null)
  1239. continue;
  1240. if(target instanceof L2Attackable)
  1241. {
  1242. L2Npc targets = ((L2Npc)target);
  1243. L2Npc actors = ((L2Npc)_actor);
  1244. if(targets.getEnemyClan() == null || actors.getClan() == null || !targets.getEnemyClan().equals(actors.getClan()) || (actors.getClan() == null && actors.getIsChaos() == 0))
  1245. continue;
  1246. }
  1247. L2Effect[] effects = target.getAllEffects();
  1248. if (effects.length >0)
  1249. cancast = true;
  1250. }
  1251. if(cancast)
  1252. return true;
  1253. }
  1254. }
  1255. else
  1256. {
  1257. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_AURA
  1258. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_BEHIND_AURA
  1259. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_FRONT_AURA
  1260. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_MULTIFACE)
  1261. {
  1262. boolean cancast = false;
  1263. for(L2Character target:_actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()))
  1264. {
  1265. if(!GeoData.getInstance().canSeeTarget(_actor,target))
  1266. continue;
  1267. if(target instanceof L2Attackable)
  1268. {
  1269. L2Npc targets = ((L2Npc)target);
  1270. L2Npc actors = ((L2Npc)_actor);
  1271. if(targets.getEnemyClan() == null || actors.getClan() == null || !targets.getEnemyClan().equals(actors.getClan()) || (actors.getClan() == null && actors.getIsChaos() == 0))
  1272. continue;
  1273. }
  1274. L2Effect[] effects = target.getAllEffects();
  1275. if (effects.length >0)
  1276. cancast = true;
  1277. }
  1278. if(cancast)
  1279. return true;
  1280. }
  1281. else if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_AREA
  1282. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_BEHIND_AREA
  1283. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_FRONT_AREA)
  1284. {
  1285. boolean cancast = true;
  1286. for(L2Character target: getAttackTarget().getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()))
  1287. {
  1288. if(!GeoData.getInstance().canSeeTarget(_actor,target))
  1289. continue;
  1290. if(target instanceof L2Attackable)
  1291. {
  1292. L2Npc targets = ((L2Npc)target);
  1293. L2Npc actors = ((L2Npc)_actor);
  1294. if(targets.getEnemyClan() == null || actors.getClan() == null || !targets.getEnemyClan().equals(actors.getClan()) || (actors.getClan() == null && actors.getIsChaos() == 0))
  1295. continue;
  1296. }
  1297. L2Effect[] effects = target.getAllEffects();
  1298. for (int i = 0; effects != null && i < effects.length; i++)
  1299. {
  1300. L2Effect effect = effects[i];
  1301. if (effect.getSkill() == sk)
  1302. {
  1303. cancast=false;
  1304. break;
  1305. }
  1306. }
  1307. }
  1308. if(cancast)
  1309. return true;
  1310. }
  1311. }
  1312. return false;
  1313. }
  1314. public boolean canParty(L2Skill sk)
  1315. {
  1316. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY)
  1317. {
  1318. int count = 0;
  1319. int ccount = 0;
  1320. for(L2Character target:_actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()))
  1321. {
  1322. if(!(target instanceof L2Attackable) || !GeoData.getInstance().canSeeTarget(_actor,target))
  1323. {
  1324. continue;
  1325. }
  1326. L2Npc targets = ((L2Npc)target);
  1327. L2Npc actors = ((L2Npc)_actor);
  1328. if(actors.getFactionId() != null && targets.getFactionId().equals(actors.getFactionId()))
  1329. {
  1330. count++;
  1331. L2Effect[] effects = target.getAllEffects();
  1332. for (int i = 0; effects != null && i < effects.length; i++)
  1333. {
  1334. L2Effect effect = effects[i];
  1335. if (effect.getSkill() == sk)
  1336. {
  1337. ccount++;
  1338. break;
  1339. }
  1340. }
  1341. }
  1342. }
  1343. if(ccount < count)
  1344. return true;
  1345. }
  1346. return false;
  1347. }
  1348. public boolean isParty(L2Skill sk)
  1349. {
  1350. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY)
  1351. {
  1352. return true;
  1353. }
  1354. return false;
  1355. }
  1356. }