L2CharacterAI.java 49 KB

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