L2CharacterAI.java 48 KB

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