L2CharacterAI.java 49 KB

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