L2CharacterAI.java 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  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. * Launch actions corresponding to the Event ReadyToAct.<BR><BR>
  556. *
  557. * <B><U> Actions</U> :</B><BR><BR>
  558. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  559. *
  560. */
  561. @Override
  562. protected void onEvtReadyToAct()
  563. {
  564. // Launch actions corresponding to the Event Think
  565. onEvtThink();
  566. }
  567. /**
  568. * Do nothing.<BR><BR>
  569. */
  570. @Override
  571. protected void onEvtUserCmd(Object arg0, Object arg1)
  572. {
  573. // do nothing
  574. }
  575. /**
  576. * Launch actions corresponding to the Event Arrived.<BR><BR>
  577. *
  578. * <B><U> Actions</U> :</B><BR><BR>
  579. * <li>If the Intention was AI_INTENTION_MOVE_TO, set the Intention to AI_INTENTION_ACTIVE</li>
  580. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  581. *
  582. */
  583. @Override
  584. protected void onEvtArrived()
  585. {
  586. // Launch an explore task if necessary
  587. if (Config.ACTIVATE_POSITION_RECORDER && _accessor.getActor() instanceof L2PcInstance)
  588. {
  589. ((L2PcInstance) _accessor.getActor()).explore();
  590. }
  591. _accessor.getActor().revalidateZone(true);
  592. if (_accessor.getActor().moveToNextRoutePoint())
  593. return;
  594. if (_accessor.getActor() instanceof L2Attackable)
  595. {
  596. ((L2Attackable) _accessor.getActor()).setisReturningToSpawnPoint(false);
  597. }
  598. clientStoppedMoving();
  599. // If the Intention was AI_INTENTION_MOVE_TO, set the Intention to AI_INTENTION_ACTIVE
  600. if (getIntention() == AI_INTENTION_MOVE_TO)
  601. setIntention(AI_INTENTION_ACTIVE);
  602. // Launch actions corresponding to the Event Think
  603. onEvtThink();
  604. }
  605. /**
  606. * Launch actions corresponding to the Event ArrivedRevalidate.<BR><BR>
  607. *
  608. * <B><U> Actions</U> :</B><BR><BR>
  609. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  610. *
  611. */
  612. @Override
  613. protected void onEvtArrivedRevalidate()
  614. {
  615. // Launch actions corresponding to the Event Think
  616. onEvtThink();
  617. }
  618. /**
  619. * Launch actions corresponding to the Event ArrivedBlocked.<BR><BR>
  620. *
  621. * <B><U> Actions</U> :</B><BR><BR>
  622. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  623. * <li>If the Intention was AI_INTENTION_MOVE_TO, set the Intention to AI_INTENTION_ACTIVE</li>
  624. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  625. *
  626. */
  627. @Override
  628. protected void onEvtArrivedBlocked(L2CharPosition blocked_at_pos)
  629. {
  630. // If the Intention was AI_INTENTION_MOVE_TO, set the Intention to AI_INTENTION_ACTIVE
  631. if (getIntention() == AI_INTENTION_MOVE_TO || getIntention() == AI_INTENTION_CAST)
  632. setIntention(AI_INTENTION_ACTIVE);
  633. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  634. clientStopMoving(blocked_at_pos);
  635. /*if (Config.ACTIVATE_POSITION_RECORDER && Universe.getInstance().shouldLog(_accessor.getActor().getObjectId()))
  636. {
  637. if (!_accessor.getActor().isFlying())
  638. Universe.getInstance().registerObstacle(blocked_at_pos.x, blocked_at_pos.y, blocked_at_pos.z);
  639. if (_accessor.getActor() instanceof L2PcInstance)
  640. ((L2PcInstance) _accessor.getActor()).explore();
  641. }*/
  642. // Launch actions corresponding to the Event Think
  643. onEvtThink();
  644. }
  645. /**
  646. * Launch actions corresponding to the Event ForgetObject.<BR><BR>
  647. *
  648. * <B><U> Actions</U> :</B><BR><BR>
  649. * <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>
  650. * <li>If the object was targeted to attack, stop the auto-attack, cancel target and set the Intention to AI_INTENTION_ACTIVE</li>
  651. * <li>If the object was targeted to cast, cancel target and set the Intention to AI_INTENTION_ACTIVE</li>
  652. * <li>If the object was targeted to follow, stop the movement, cancel AI Follow Task and set the Intention to AI_INTENTION_ACTIVE</li>
  653. * <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>
  654. *
  655. */
  656. @Override
  657. protected void onEvtForgetObject(L2Object object)
  658. {
  659. // If the object was targeted and the Intention was AI_INTENTION_INTERACT or AI_INTENTION_PICK_UP, set the Intention to AI_INTENTION_ACTIVE
  660. if (getTarget() == object)
  661. {
  662. setTarget(null);
  663. if (getIntention() == AI_INTENTION_INTERACT)
  664. setIntention(AI_INTENTION_ACTIVE);
  665. else if (getIntention() == AI_INTENTION_PICK_UP)
  666. setIntention(AI_INTENTION_ACTIVE);
  667. }
  668. // Check if the object was targeted to attack
  669. if (getAttackTarget() == object)
  670. {
  671. // Cancel attack target
  672. setAttackTarget(null);
  673. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  674. setIntention(AI_INTENTION_ACTIVE);
  675. }
  676. // Check if the object was targeted to cast
  677. if (getCastTarget() == object)
  678. {
  679. // Cancel cast target
  680. setCastTarget(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 follow
  685. if (getFollowTarget() == object)
  686. {
  687. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  688. clientStopMoving(null);
  689. // Stop an AI Follow Task
  690. stopFollow();
  691. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  692. setIntention(AI_INTENTION_ACTIVE);
  693. }
  694. // Check if the targeted object was the actor
  695. if (_actor == object)
  696. {
  697. // Cancel AI target
  698. setTarget(null);
  699. setAttackTarget(null);
  700. setCastTarget(null);
  701. // Stop an AI Follow Task
  702. stopFollow();
  703. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  704. clientStopMoving(null);
  705. // Set the Intention of this AbstractAI to AI_INTENTION_IDLE
  706. changeIntention(AI_INTENTION_IDLE, null, null);
  707. }
  708. }
  709. /**
  710. * Launch actions corresponding to the Event Cancel.<BR><BR>
  711. *
  712. * <B><U> Actions</U> :</B><BR><BR>
  713. * <li>Stop an AI Follow Task</li>
  714. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  715. *
  716. */
  717. @Override
  718. protected void onEvtCancel()
  719. {
  720. _actor.abortCast();
  721. // Stop an AI Follow Task
  722. stopFollow();
  723. if (!AttackStanceTaskManager.getInstance().getAttackStanceTask(_actor))
  724. _actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId()));
  725. // Launch actions corresponding to the Event Think
  726. onEvtThink();
  727. }
  728. /**
  729. * Launch actions corresponding to the Event Dead.<BR><BR>
  730. *
  731. * <B><U> Actions</U> :</B><BR><BR>
  732. * <li>Stop an AI Follow Task</li>
  733. * <li>Kill the actor client side by sending Server->Client packet AutoAttackStop, StopMove/StopRotation, Die (broadcast)</li><BR><BR>
  734. *
  735. */
  736. @Override
  737. protected void onEvtDead()
  738. {
  739. // Stop an AI Follow Task
  740. stopFollow();
  741. // Kill the actor client side by sending Server->Client packet AutoAttackStop, StopMove/StopRotation, Die (broadcast)
  742. clientNotifyDead();
  743. if (!(_actor instanceof L2PcInstance))
  744. _actor.setWalking();
  745. }
  746. /**
  747. * Launch actions corresponding to the Event Fake Death.<BR><BR>
  748. *
  749. * <B><U> Actions</U> :</B><BR><BR>
  750. * <li>Stop an AI Follow Task</li>
  751. *
  752. */
  753. @Override
  754. protected void onEvtFakeDeath()
  755. {
  756. // Stop an AI Follow Task
  757. stopFollow();
  758. // Stop the actor movement and send Server->Client packet StopMove/StopRotation (broadcast)
  759. clientStopMoving(null);
  760. // Init AI
  761. _intention = AI_INTENTION_IDLE;
  762. setTarget(null);
  763. setCastTarget(null);
  764. setAttackTarget(null);
  765. }
  766. /**
  767. * Do nothing.<BR><BR>
  768. */
  769. @Override
  770. protected void onEvtFinishCasting()
  771. {
  772. // do nothing
  773. }
  774. protected boolean maybeMoveToPosition(Point3D worldPosition, int offset)
  775. {
  776. if (worldPosition == null)
  777. {
  778. _log.warning("maybeMoveToPosition: worldPosition == NULL!");
  779. return false;
  780. }
  781. if (offset < 0)
  782. return false; // skill radius -1
  783. if (!_actor.isInsideRadius(worldPosition.getX(), worldPosition.getY(), offset + _actor.getTemplate().collisionRadius, false))
  784. {
  785. if (_actor.isMovementDisabled())
  786. return true;
  787. if (!_actor.isRunning() && !(this instanceof L2PlayerAI) && !(this instanceof L2SummonAI))
  788. _actor.setRunning();
  789. stopFollow();
  790. int x = _actor.getX();
  791. int y = _actor.getY();
  792. double dx = worldPosition.getX() - x;
  793. double dy = worldPosition.getY() - y;
  794. double dist = Math.sqrt(dx * dx + dy * dy);
  795. double sin = dy / dist;
  796. double cos = dx / dist;
  797. dist -= offset - 5;
  798. x += (int) (dist * cos);
  799. y += (int) (dist * sin);
  800. moveTo(x, y, worldPosition.getZ());
  801. return true;
  802. }
  803. if (getFollowTarget() != null)
  804. stopFollow();
  805. return false;
  806. }
  807. /**
  808. * Manage the Move to Pawn action in function of the distance and of the Interact area.<BR><BR>
  809. *
  810. * <B><U> Actions</U> :</B><BR><BR>
  811. * <li>Get the distance between the current position of the L2Character and the target (x,y)</li>
  812. * <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>
  813. * <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>
  814. *
  815. * <B><U> Example of use </U> :</B><BR><BR>
  816. * <li> L2PLayerAI, L2SummonAI</li><BR><BR>
  817. *
  818. * @param target The targeted L2Object
  819. * @param offset The Interact area radius
  820. *
  821. * @return True if a movement must be done
  822. *
  823. */
  824. protected boolean maybeMoveToPawn(L2Object target, int offset)
  825. {
  826. // Get the distance between the current position of the L2Character and the target (x,y)
  827. if (target == null)
  828. {
  829. _log.warning("maybeMoveToPawn: target == NULL!");
  830. return false;
  831. }
  832. if (offset < 0)
  833. return false; // skill radius -1
  834. offset += _actor.getTemplate().collisionRadius;
  835. if (target instanceof L2Character)
  836. offset += ((L2Character) target).getTemplate().collisionRadius;
  837. if (!_actor.isInsideRadius(target, offset, false, false))
  838. {
  839. // Caller should be L2Playable and thinkAttack/thinkCast/thinkInteract/thinkPickUp
  840. if (getFollowTarget() != null)
  841. {
  842. // allow larger hit range when the target is moving (check is run only once per second)
  843. if (!_actor.isInsideRadius(target, offset + 100, false, false))
  844. return true;
  845. stopFollow();
  846. return false;
  847. }
  848. if (_actor.isMovementDisabled())
  849. return true;
  850. // while flying there is no move to cast
  851. if (_actor.getAI().getIntention() == CtrlIntention.AI_INTENTION_CAST &&
  852. _actor instanceof L2PcInstance && ((L2PcInstance)_actor).isTransformed())
  853. {
  854. if (!((L2PcInstance)_actor).getTransformation().canStartFollowToCast())
  855. {
  856. ((L2PcInstance)_actor).sendPacket(new SystemMessage(SystemMessageId.DIST_TOO_FAR_CASTING_STOPPED));
  857. ((L2PcInstance)_actor).sendPacket(ActionFailed.STATIC_PACKET);
  858. return true;
  859. }
  860. }
  861. // If not running, set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  862. if (!_actor.isRunning() && !(this instanceof L2PlayerAI) && !(this instanceof L2SummonAI))
  863. _actor.setRunning();
  864. stopFollow();
  865. if ((target instanceof L2Character) && !(target instanceof L2DoorInstance))
  866. {
  867. if (((L2Character) target).isMoving())
  868. offset -= 100;
  869. if (offset < 5)
  870. offset = 5;
  871. startFollow((L2Character) target, offset);
  872. }
  873. else
  874. {
  875. // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast)
  876. moveToPawn(target, offset);
  877. }
  878. return true;
  879. }
  880. if (getFollowTarget() != null)
  881. stopFollow();
  882. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  883. // clientStopMoving(null);
  884. return false;
  885. }
  886. /**
  887. * Modify current Intention and actions if the target is lost or dead.<BR><BR>
  888. *
  889. * <B><U> Actions</U> : <I>If the target is lost or dead</I></B><BR><BR>
  890. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
  891. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  892. * <li>Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE</li><BR><BR>
  893. *
  894. * <B><U> Example of use </U> :</B><BR><BR>
  895. * <li> L2PLayerAI, L2SummonAI</li><BR><BR>
  896. *
  897. * @param target The targeted L2Object
  898. *
  899. * @return True if the target is lost or dead (false if fakedeath)
  900. *
  901. */
  902. protected boolean checkTargetLostOrDead(L2Character target)
  903. {
  904. if (target == null || target.isAlikeDead())
  905. {
  906. //check if player is fakedeath
  907. if (target instanceof L2PcInstance && ((L2PcInstance)target).isFakeDeath())
  908. {
  909. target.stopFakeDeath(null);
  910. return false;
  911. }
  912. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  913. setIntention(AI_INTENTION_ACTIVE);
  914. return true;
  915. }
  916. return false;
  917. }
  918. /**
  919. * Modify current Intention and actions if the target is lost.<BR><BR>
  920. *
  921. * <B><U> Actions</U> : <I>If the target is lost</I></B><BR><BR>
  922. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
  923. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  924. * <li>Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE</li><BR><BR>
  925. *
  926. * <B><U> Example of use </U> :</B><BR><BR>
  927. * <li> L2PLayerAI, L2SummonAI</li><BR><BR>
  928. *
  929. * @param target The targeted L2Object
  930. *
  931. * @return True if the target is lost
  932. *
  933. */
  934. protected boolean checkTargetLost(L2Object target)
  935. {
  936. // check if player is fakedeath
  937. if (target instanceof L2PcInstance)
  938. {
  939. L2PcInstance target2 = (L2PcInstance) target; //convert object to chara
  940. if (target2.isFakeDeath())
  941. {
  942. target2.stopFakeDeath(null);
  943. return false;
  944. }
  945. }
  946. if (target == null)
  947. {
  948. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  949. setIntention(AI_INTENTION_ACTIVE);
  950. return true;
  951. }
  952. return false;
  953. }
  954. protected class SelfAnalysis
  955. {
  956. public boolean isMage = false;
  957. public boolean isBalanced;
  958. public boolean isArcher = false;
  959. public boolean isHealer = false;
  960. public boolean isFighter = false;
  961. public boolean cannotMoveOnLand = false;
  962. public List<L2Skill> generalSkills = new FastList<L2Skill>();
  963. public List<L2Skill> buffSkills = new FastList<L2Skill>();
  964. public int lastBuffTick = 0;
  965. public List<L2Skill> debuffSkills = new FastList<L2Skill>();
  966. public int lastDebuffTick = 0;
  967. public List<L2Skill> cancelSkills = new FastList<L2Skill>();
  968. public List<L2Skill> healSkills = new FastList<L2Skill>();
  969. //public List<L2Skill> trickSkills = new FastList<L2Skill>();
  970. public List<L2Skill> generalDisablers = new FastList<L2Skill>();
  971. public List<L2Skill> sleepSkills = new FastList<L2Skill>();
  972. public List<L2Skill> rootSkills = new FastList<L2Skill>();
  973. public List<L2Skill> muteSkills = new FastList<L2Skill>();
  974. public List<L2Skill> resurrectSkills = new FastList<L2Skill>();
  975. public boolean hasHealOrResurrect = false;
  976. public boolean hasLongRangeSkills = false;
  977. public boolean hasLongRangeDamageSkills = false;
  978. public int maxCastRange = 0;
  979. public SelfAnalysis()
  980. {
  981. }
  982. public void init()
  983. {
  984. switch (((L2NpcTemplate) _actor.getTemplate()).getAIDataStatic().getAiType())
  985. {
  986. case FIGHTER:
  987. isFighter = true;
  988. break;
  989. case MAGE:
  990. isMage = true;
  991. break;
  992. case CORPSE:
  993. case BALANCED:
  994. isBalanced = true;
  995. break;
  996. case ARCHER:
  997. isArcher = true;
  998. break;
  999. case HEALER:
  1000. isHealer = true;
  1001. break;
  1002. default:
  1003. isFighter = true;
  1004. break;
  1005. }
  1006. // water movement analysis
  1007. if (_actor instanceof L2Npc)
  1008. {
  1009. int npcId = ((L2Npc) _actor).getNpcId();
  1010. switch (npcId)
  1011. {
  1012. case 20314: // great white shark
  1013. case 20849: // Light Worm
  1014. cannotMoveOnLand = true;
  1015. break;
  1016. default:
  1017. cannotMoveOnLand = false;
  1018. break;
  1019. }
  1020. }
  1021. // skill analysis
  1022. for (L2Skill sk : _actor.getAllSkills())
  1023. {
  1024. if (sk.isPassive())
  1025. continue;
  1026. int castRange = sk.getCastRange();
  1027. boolean hasLongRangeDamageSkill = false;
  1028. switch (sk.getSkillType())
  1029. {
  1030. case HEAL:
  1031. case HEAL_PERCENT:
  1032. case HEAL_STATIC:
  1033. case BALANCE_LIFE:
  1034. case HOT:
  1035. healSkills.add(sk);
  1036. hasHealOrResurrect = true;
  1037. continue; // won't be considered something for fighting
  1038. case BUFF:
  1039. buffSkills.add(sk);
  1040. continue; // won't be considered something for fighting
  1041. case PARALYZE:
  1042. case STUN:
  1043. // hardcoding petrification until improvements are made to
  1044. // EffectTemplate... petrification is totally different for
  1045. // AI than paralyze
  1046. switch (sk.getId())
  1047. {
  1048. case 367:
  1049. case 4111:
  1050. case 4383:
  1051. case 4616:
  1052. case 4578:
  1053. sleepSkills.add(sk);
  1054. break;
  1055. default:
  1056. generalDisablers.add(sk);
  1057. break;
  1058. }
  1059. break;
  1060. case MUTE:
  1061. muteSkills.add(sk);
  1062. break;
  1063. case SLEEP:
  1064. sleepSkills.add(sk);
  1065. break;
  1066. case ROOT:
  1067. rootSkills.add(sk);
  1068. break;
  1069. case FEAR: // could be used as an alternative for healing?
  1070. case CONFUSION:
  1071. // trickSkills.add(sk);
  1072. case DEBUFF:
  1073. debuffSkills.add(sk);
  1074. break;
  1075. case CANCEL:
  1076. case MAGE_BANE:
  1077. case WARRIOR_BANE:
  1078. case NEGATE:
  1079. cancelSkills.add(sk);
  1080. break;
  1081. case RESURRECT:
  1082. resurrectSkills.add(sk);
  1083. hasHealOrResurrect = true;
  1084. break;
  1085. case NOTDONE:
  1086. case COREDONE:
  1087. continue; // won't be considered something for fighting
  1088. default:
  1089. generalSkills.add(sk);
  1090. hasLongRangeDamageSkill = true;
  1091. break;
  1092. }
  1093. if (castRange > 70)
  1094. {
  1095. hasLongRangeSkills = true;
  1096. if (hasLongRangeDamageSkill)
  1097. hasLongRangeDamageSkills = true;
  1098. }
  1099. if (castRange > maxCastRange)
  1100. maxCastRange = castRange;
  1101. }
  1102. // Because of missing skills, some mages/balanced cannot play like mages
  1103. if (!hasLongRangeDamageSkills && isMage)
  1104. {
  1105. isBalanced = true;
  1106. isMage = false;
  1107. isFighter = false;
  1108. }
  1109. if (!hasLongRangeSkills && (isMage || isBalanced))
  1110. {
  1111. isBalanced = false;
  1112. isMage = false;
  1113. isFighter = true;
  1114. }
  1115. if (generalSkills.isEmpty() && isMage)
  1116. {
  1117. isBalanced = true;
  1118. isMage = false;
  1119. }
  1120. }
  1121. }
  1122. protected class TargetAnalysis
  1123. {
  1124. public L2Character character;
  1125. public boolean isMage;
  1126. public boolean isBalanced;
  1127. public boolean isArcher;
  1128. public boolean isFighter;
  1129. public boolean isCanceled;
  1130. public boolean isSlower;
  1131. public boolean isMagicResistant;
  1132. public TargetAnalysis()
  1133. {
  1134. }
  1135. public void update(L2Character target)
  1136. {
  1137. // update status once in 4 seconds
  1138. if (target == character && Rnd.nextInt(100) > 25)
  1139. return;
  1140. character = target;
  1141. if (target == null)
  1142. return;
  1143. isMage = false;
  1144. isBalanced = false;
  1145. isArcher = false;
  1146. isFighter = false;
  1147. isCanceled = false;
  1148. if (target.getMAtk(null, null) > 1.5 * target.getPAtk(null))
  1149. isMage = true;
  1150. else if (target.getPAtk(null) * 0.8 < target.getMAtk(null, null) || target.getMAtk(null, null) * 0.8 > target.getPAtk(null))
  1151. {
  1152. isBalanced = true;
  1153. }
  1154. else
  1155. {
  1156. L2Weapon weapon = target.getActiveWeaponItem();
  1157. if (weapon != null && (weapon.getItemType() == L2WeaponType.BOW || weapon.getItemType() == L2WeaponType.CROSSBOW))
  1158. isArcher = true;
  1159. else
  1160. isFighter = true;
  1161. }
  1162. if (target.getRunSpeed() < _actor.getRunSpeed() - 3)
  1163. isSlower = true;
  1164. else
  1165. isSlower = false;
  1166. if (target.getMDef(null, null) * 1.2 > _actor.getMAtk(null, null))
  1167. isMagicResistant = true;
  1168. else
  1169. isMagicResistant = false;
  1170. if (target.getBuffCount() < 4)
  1171. isCanceled = true;
  1172. }
  1173. }
  1174. public boolean canAura(L2Skill sk)
  1175. {
  1176. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_AURA
  1177. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_BEHIND_AURA
  1178. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_FRONT_AURA)
  1179. {
  1180. for(L2Object target:_actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()))
  1181. {
  1182. if (target == getAttackTarget())
  1183. return true;
  1184. }
  1185. }
  1186. return false;
  1187. }
  1188. public boolean canAOE(L2Skill sk)
  1189. {
  1190. if(sk.getSkillType() != L2SkillType.NEGATE || sk.getSkillType() != L2SkillType.CANCEL)
  1191. {
  1192. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_AURA
  1193. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_BEHIND_AURA
  1194. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_FRONT_AURA
  1195. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_MULTIFACE)
  1196. {
  1197. boolean cancast = true;
  1198. for(L2Character target:_actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()))
  1199. {
  1200. if(!GeoData.getInstance().canSeeTarget(_actor,target))
  1201. continue;
  1202. if(target instanceof L2Attackable)
  1203. {
  1204. L2Npc targets = ((L2Npc)target);
  1205. L2Npc actors = ((L2Npc)_actor);
  1206. if(targets.getEnemyClan() == null || actors.getClan() == null || !targets.getEnemyClan().equals(actors.getClan()) || (actors.getClan() == null && actors.getIsChaos() == 0))
  1207. continue;
  1208. }
  1209. L2Effect[] effects = target.getAllEffects();
  1210. for (int i = 0; effects != null && i < effects.length; i++)
  1211. {
  1212. L2Effect effect = effects[i];
  1213. if (effect.getSkill() == sk)
  1214. {
  1215. cancast=false;
  1216. break;
  1217. }
  1218. }
  1219. }
  1220. if(cancast)
  1221. return true;
  1222. }
  1223. else if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_AREA
  1224. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_BEHIND_AREA
  1225. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_FRONT_AREA)
  1226. {
  1227. boolean cancast = true;
  1228. for(L2Character target: getAttackTarget().getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()))
  1229. {
  1230. if(!GeoData.getInstance().canSeeTarget(_actor,target) || target == null)
  1231. continue;
  1232. if(target instanceof L2Attackable)
  1233. {
  1234. L2Npc targets = ((L2Npc)target);
  1235. L2Npc actors = ((L2Npc)_actor);
  1236. if(targets.getEnemyClan() == null || actors.getClan() == null || !targets.getEnemyClan().equals(actors.getClan()) || (actors.getClan() == null && actors.getIsChaos() == 0))
  1237. continue;
  1238. }
  1239. L2Effect[] effects = target.getAllEffects();
  1240. if (effects.length >0)
  1241. cancast = true;
  1242. }
  1243. if(cancast)
  1244. return true;
  1245. }
  1246. }
  1247. else
  1248. {
  1249. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_AURA
  1250. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_BEHIND_AURA
  1251. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_FRONT_AURA
  1252. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_MULTIFACE)
  1253. {
  1254. boolean cancast = false;
  1255. for(L2Character target:_actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()))
  1256. {
  1257. if(!GeoData.getInstance().canSeeTarget(_actor,target))
  1258. continue;
  1259. if(target instanceof L2Attackable)
  1260. {
  1261. L2Npc targets = ((L2Npc)target);
  1262. L2Npc actors = ((L2Npc)_actor);
  1263. if(targets.getEnemyClan() == null || actors.getClan() == null || !targets.getEnemyClan().equals(actors.getClan()) || (actors.getClan() == null && actors.getIsChaos() == 0))
  1264. continue;
  1265. }
  1266. L2Effect[] effects = target.getAllEffects();
  1267. if (effects.length >0)
  1268. cancast = true;
  1269. }
  1270. if(cancast)
  1271. return true;
  1272. }
  1273. else if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_AREA
  1274. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_BEHIND_AREA
  1275. || sk.getTargetType() == L2Skill.SkillTargetType.TARGET_FRONT_AREA)
  1276. {
  1277. boolean cancast = true;
  1278. for(L2Character target: getAttackTarget().getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()))
  1279. {
  1280. if(!GeoData.getInstance().canSeeTarget(_actor,target))
  1281. continue;
  1282. if(target instanceof L2Attackable)
  1283. {
  1284. L2Npc targets = ((L2Npc)target);
  1285. L2Npc actors = ((L2Npc)_actor);
  1286. if(targets.getEnemyClan() == null || actors.getClan() == null || !targets.getEnemyClan().equals(actors.getClan()) || (actors.getClan() == null && actors.getIsChaos() == 0))
  1287. continue;
  1288. }
  1289. L2Effect[] effects = target.getAllEffects();
  1290. for (int i = 0; effects != null && i < effects.length; i++)
  1291. {
  1292. L2Effect effect = effects[i];
  1293. if (effect.getSkill() == sk)
  1294. {
  1295. cancast=false;
  1296. break;
  1297. }
  1298. }
  1299. }
  1300. if(cancast)
  1301. return true;
  1302. }
  1303. }
  1304. return false;
  1305. }
  1306. public boolean canParty(L2Skill sk)
  1307. {
  1308. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY)
  1309. {
  1310. int count = 0;
  1311. int ccount = 0;
  1312. for(L2Character target:_actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()))
  1313. {
  1314. if(!(target instanceof L2Attackable) || !GeoData.getInstance().canSeeTarget(_actor,target))
  1315. {
  1316. continue;
  1317. }
  1318. L2Npc targets = ((L2Npc)target);
  1319. L2Npc actors = ((L2Npc)_actor);
  1320. if(actors.getFactionId() != null && targets.getFactionId().equals(actors.getFactionId()))
  1321. {
  1322. count++;
  1323. L2Effect[] effects = target.getAllEffects();
  1324. for (int i = 0; effects != null && i < effects.length; i++)
  1325. {
  1326. L2Effect effect = effects[i];
  1327. if (effect.getSkill() == sk)
  1328. {
  1329. ccount++;
  1330. break;
  1331. }
  1332. }
  1333. }
  1334. }
  1335. if(ccount < count)
  1336. return true;
  1337. }
  1338. return false;
  1339. }
  1340. public boolean isParty(L2Skill sk)
  1341. {
  1342. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY)
  1343. {
  1344. return true;
  1345. }
  1346. return false;
  1347. }
  1348. }