2
0

L2CharacterAI.java 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  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 net.sf.l2j.gameserver.ai;
  16. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
  17. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
  18. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_CAST;
  19. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_FOLLOW;
  20. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
  21. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_INTERACT;
  22. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_MOVE_TO;
  23. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_PICK_UP;
  24. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_REST;
  25. import java.util.List;
  26. import javolution.util.FastList;
  27. import net.sf.l2j.Config;
  28. import net.sf.l2j.gameserver.Universe;
  29. import net.sf.l2j.gameserver.model.L2Attackable;
  30. import net.sf.l2j.gameserver.model.L2CharPosition;
  31. import net.sf.l2j.gameserver.model.L2Character;
  32. import net.sf.l2j.gameserver.model.L2Object;
  33. import net.sf.l2j.gameserver.model.L2Skill;
  34. import net.sf.l2j.gameserver.model.actor.instance.L2BoatInstance;
  35. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  36. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  37. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  38. import net.sf.l2j.gameserver.network.serverpackets.AutoAttackStop;
  39. import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager;
  40. import net.sf.l2j.gameserver.templates.L2NpcTemplate;
  41. import net.sf.l2j.gameserver.templates.L2Weapon;
  42. import net.sf.l2j.gameserver.templates.L2WeaponType;
  43. import net.sf.l2j.util.Point3D;
  44. import net.sf.l2j.util.Rnd;
  45. /**
  46. * This class manages AI of L2Character.<BR><BR>
  47. *
  48. * L2CharacterAI :<BR><BR>
  49. * <li>L2AttackableAI</li>
  50. * <li>L2DoorAI</li>
  51. * <li>L2PlayerAI</li>
  52. * <li>L2SummonAI</li><BR><BR>
  53. *
  54. */
  55. public class L2CharacterAI extends AbstractAI
  56. {
  57. class IntentionCommand
  58. {
  59. protected CtrlIntention _crtlIntention;
  60. protected Object _arg0, _arg1;
  61. protected IntentionCommand(CtrlIntention pIntention, Object pArg0, Object pArg1)
  62. {
  63. _crtlIntention = pIntention;
  64. _arg0 = pArg0;
  65. _arg1 = pArg1;
  66. }
  67. }
  68. /**
  69. * Constructor of L2CharacterAI.<BR><BR>
  70. *
  71. * @param accessor The AI accessor of the L2Character
  72. *
  73. */
  74. public L2CharacterAI(L2Character.AIAccessor accessor)
  75. {
  76. super(accessor);
  77. }
  78. public IntentionCommand getNextIntention()
  79. {
  80. return null;
  81. }
  82. @Override
  83. protected void onEvtAttacked(L2Character attacker)
  84. {
  85. if (attacker instanceof L2Attackable && !((L2Attackable) attacker).isCoreAIDisabled())
  86. clientStartAutoAttack();
  87. }
  88. /**
  89. * Manage the Idle Intention : Stop Attack, Movement and Stand Up the actor.<BR><BR>
  90. *
  91. * <B><U> Actions</U> :</B><BR><BR>
  92. * <li>Set the AI Intention to AI_INTENTION_IDLE </li>
  93. * <li>Init cast and attack target </li>
  94. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  95. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast) </li>
  96. * <li>Stand up the actor server side AND client side by sending Server->Client packet ChangeWaitType (broadcast) </li><BR><BR>
  97. *
  98. */
  99. @Override
  100. protected void onIntentionIdle()
  101. {
  102. // Set the AI Intention to AI_INTENTION_IDLE
  103. changeIntention(AI_INTENTION_IDLE, null, null);
  104. // Init cast and attack target
  105. setCastTarget(null);
  106. setAttackTarget(null);
  107. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  108. clientStopMoving(null);
  109. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  110. clientStopAutoAttack();
  111. }
  112. /**
  113. * Manage the Active Intention : Stop Attack, Movement and Launch Think Event.<BR><BR>
  114. *
  115. * <B><U> Actions</U> : <I>if the Intention is not already Active</I></B><BR><BR>
  116. * <li>Set the AI Intention to AI_INTENTION_ACTIVE </li>
  117. * <li>Init cast and attack target </li>
  118. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  119. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast) </li>
  120. * <li>Launch the Think Event </li><BR><BR>
  121. *
  122. */
  123. @Override
  124. protected void onIntentionActive()
  125. {
  126. // Check if the Intention is not already Active
  127. if (getIntention() != AI_INTENTION_ACTIVE)
  128. {
  129. // Set the AI Intention to AI_INTENTION_ACTIVE
  130. changeIntention(AI_INTENTION_ACTIVE, null, null);
  131. // Init cast and attack target
  132. setCastTarget(null);
  133. setAttackTarget(null);
  134. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  135. clientStopMoving(null);
  136. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  137. clientStopAutoAttack();
  138. // Also enable random animations for this L2Character if allowed
  139. // This is only for mobs - town npcs are handled in their constructor
  140. if (_actor instanceof L2Attackable)
  141. ((L2NpcInstance) _actor).startRandomAnimationTimer();
  142. // Launch the Think Event
  143. onEvtThink();
  144. }
  145. }
  146. /**
  147. * Manage the Rest Intention.<BR><BR>
  148. *
  149. * <B><U> Actions</U> : </B><BR><BR>
  150. * <li>Set the AI Intention to AI_INTENTION_IDLE </li><BR><BR>
  151. *
  152. */
  153. @Override
  154. protected void onIntentionRest()
  155. {
  156. // Set the AI Intention to AI_INTENTION_IDLE
  157. setIntention(AI_INTENTION_IDLE);
  158. }
  159. /**
  160. * Manage the Attack Intention : Stop current Attack (if necessary), Start a new Attack and Launch Think Event.<BR><BR>
  161. *
  162. * <B><U> Actions</U> : </B><BR><BR>
  163. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  164. * <li>Set the Intention of this AI to AI_INTENTION_ATTACK </li>
  165. * <li>Set or change the AI attack target </li>
  166. * <li>Start the actor Auto Attack client side by sending Server->Client packet AutoAttackStart (broadcast) </li>
  167. * <li>Launch the Think Event </li><BR><BR>
  168. *
  169. *
  170. * <B><U> Overridden in</U> :</B><BR><BR>
  171. * <li>L2AttackableAI : Calculate attack timeout</li><BR><BR>
  172. *
  173. */
  174. @Override
  175. protected void onIntentionAttack(L2Character target)
  176. {
  177. if (target == null)
  178. {
  179. clientActionFailed();
  180. return;
  181. }
  182. if (getIntention() == AI_INTENTION_REST)
  183. {
  184. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  185. clientActionFailed();
  186. return;
  187. }
  188. if (_actor.isAllSkillsDisabled() || _actor.isAfraid())
  189. {
  190. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  191. clientActionFailed();
  192. return;
  193. }
  194. // Check if the Intention is already AI_INTENTION_ATTACK
  195. if (getIntention() == AI_INTENTION_ATTACK)
  196. {
  197. // Check if the AI already targets the L2Character
  198. if (getAttackTarget() != target)
  199. {
  200. // Set the AI attack target (change target)
  201. setAttackTarget(target);
  202. stopFollow();
  203. // Launch the Think Event
  204. notifyEvent(CtrlEvent.EVT_THINK, null);
  205. }
  206. else
  207. clientActionFailed(); // else client freezes until cancel target
  208. }
  209. else
  210. {
  211. // Set the Intention of this AbstractAI to AI_INTENTION_ATTACK
  212. changeIntention(AI_INTENTION_ATTACK, target, null);
  213. // Set the AI attack target
  214. setAttackTarget(target);
  215. stopFollow();
  216. // Launch the Think Event
  217. notifyEvent(CtrlEvent.EVT_THINK, null);
  218. }
  219. }
  220. /**
  221. * Manage the Cast Intention : Stop current Attack, Init the AI in order to cast and Launch Think Event.<BR><BR>
  222. *
  223. * <B><U> Actions</U> : </B><BR><BR>
  224. * <li>Set the AI cast target </li>
  225. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  226. * <li>Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor </li>
  227. * <li>Set the AI skill used by INTENTION_CAST </li>
  228. * <li>Set the Intention of this AI to AI_INTENTION_CAST </li>
  229. * <li>Launch the Think Event </li><BR><BR>
  230. *
  231. */
  232. @Override
  233. protected void onIntentionCast(L2Skill skill, L2Object target)
  234. {
  235. if (getIntention() == AI_INTENTION_REST && skill.isMagic())
  236. {
  237. clientActionFailed();
  238. return;
  239. }
  240. if (_actor.isAllSkillsDisabled())
  241. {
  242. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  243. clientActionFailed();
  244. return;
  245. }
  246. // can't cast if muted
  247. if (_actor.isMuted() && skill.isMagic())
  248. {
  249. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  250. clientActionFailed();
  251. return;
  252. }
  253. // Set the AI cast target
  254. setCastTarget((L2Character) target);
  255. // Stop actions client-side to cast the skill
  256. if (skill.getHitTime() > 50)
  257. {
  258. // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  259. _actor.abortAttack();
  260. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  261. // no need for second ActionFailed packet, abortAttack() already sent it
  262. //clientActionFailed();
  263. }
  264. // Set the AI skill used by INTENTION_CAST
  265. _skill = skill;
  266. // Change the Intention of this AbstractAI to AI_INTENTION_CAST
  267. changeIntention(AI_INTENTION_CAST, skill, target);
  268. // Launch the Think Event
  269. notifyEvent(CtrlEvent.EVT_THINK, null);
  270. }
  271. /**
  272. * Manage the Move To Intention : Stop current Attack and Launch a Move to Location Task.<BR><BR>
  273. *
  274. * <B><U> Actions</U> : </B><BR><BR>
  275. * <li>Stop the actor auto-attack server side AND client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  276. * <li>Set the Intention of this AI to AI_INTENTION_MOVE_TO </li>
  277. * <li>Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast) </li><BR><BR>
  278. *
  279. */
  280. @Override
  281. protected void onIntentionMoveTo(L2CharPosition pos)
  282. {
  283. if (getIntention() == AI_INTENTION_REST)
  284. {
  285. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  286. clientActionFailed();
  287. return;
  288. }
  289. if (_actor.isAllSkillsDisabled())
  290. {
  291. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  292. clientActionFailed();
  293. return;
  294. }
  295. // Set the Intention of this AbstractAI to AI_INTENTION_MOVE_TO
  296. changeIntention(AI_INTENTION_MOVE_TO, pos, null);
  297. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  298. clientStopAutoAttack();
  299. // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  300. _actor.abortAttack();
  301. // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
  302. moveTo(pos.x, pos.y, pos.z);
  303. }
  304. /* (non-Javadoc)
  305. * @see net.sf.l2j.gameserver.ai.AbstractAI#onIntentionMoveToInABoat(net.sf.l2j.gameserver.model.L2CharPosition, net.sf.l2j.gameserver.model.L2CharPosition)
  306. */
  307. @Override
  308. protected void onIntentionMoveToInABoat(L2CharPosition destination, L2CharPosition origin)
  309. {
  310. if (getIntention() == AI_INTENTION_REST)
  311. {
  312. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  313. clientActionFailed();
  314. return;
  315. }
  316. if (_actor.isAllSkillsDisabled())
  317. {
  318. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  319. clientActionFailed();
  320. return;
  321. }
  322. // Set the Intention of this AbstractAI to AI_INTENTION_MOVE_TO
  323. //
  324. //changeIntention(AI_INTENTION_MOVE_TO, new L2CharPosition(((L2PcInstance)_actor).getBoat().getX() - destination.x, ((L2PcInstance)_actor).getBoat().getY() - destination.y, ((L2PcInstance)_actor).getBoat().getZ() - destination.z, 0) , null);
  325. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  326. clientStopAutoAttack();
  327. // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  328. _actor.abortAttack();
  329. // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
  330. moveToInABoat(destination, origin);
  331. }
  332. /**
  333. * Manage the Follow Intention : Stop current Attack and Launch a Follow Task.<BR><BR>
  334. *
  335. * <B><U> Actions</U> : </B><BR><BR>
  336. * <li>Stop the actor auto-attack server side AND client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  337. * <li>Set the Intention of this AI to AI_INTENTION_FOLLOW </li>
  338. * <li>Create and Launch an AI Follow Task to execute every 1s </li><BR><BR>
  339. *
  340. */
  341. @Override
  342. protected void onIntentionFollow(L2Character target)
  343. {
  344. if (getIntention() == AI_INTENTION_REST)
  345. {
  346. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  347. clientActionFailed();
  348. return;
  349. }
  350. if (_actor.isAllSkillsDisabled())
  351. {
  352. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  353. clientActionFailed();
  354. return;
  355. }
  356. if (_actor.isImmobilized() || _actor.isRooted())
  357. {
  358. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  359. clientActionFailed();
  360. return;
  361. }
  362. // Dead actors can`t follow
  363. if (_actor.isDead())
  364. {
  365. clientActionFailed();
  366. return;
  367. }
  368. // do not follow yourself
  369. if (_actor == target)
  370. {
  371. clientActionFailed();
  372. return;
  373. }
  374. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  375. clientStopAutoAttack();
  376. // Set the Intention of this AbstractAI to AI_INTENTION_FOLLOW
  377. changeIntention(AI_INTENTION_FOLLOW, target, null);
  378. // Create and Launch an AI Follow Task to execute every 1s
  379. startFollow(target);
  380. }
  381. /**
  382. * Manage the PickUp Intention : Set the pick up target and Launch a Move To Pawn Task (offset=20).<BR><BR>
  383. *
  384. * <B><U> Actions</U> : </B><BR><BR>
  385. * <li>Set the AI pick up target </li>
  386. * <li>Set the Intention of this AI to AI_INTENTION_PICK_UP </li>
  387. * <li>Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast) </li><BR><BR>
  388. *
  389. */
  390. @Override
  391. protected void onIntentionPickUp(L2Object object)
  392. {
  393. if (getIntention() == AI_INTENTION_REST)
  394. {
  395. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  396. clientActionFailed();
  397. return;
  398. }
  399. if (_actor.isAllSkillsDisabled())
  400. {
  401. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  402. clientActionFailed();
  403. return;
  404. }
  405. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  406. clientStopAutoAttack();
  407. // Set the Intention of this AbstractAI to AI_INTENTION_PICK_UP
  408. changeIntention(AI_INTENTION_PICK_UP, object, null);
  409. // Set the AI pick up target
  410. setTarget(object);
  411. if (object.getX() == 0 && object.getY() == 0) // TODO: Find the drop&spawn bug
  412. {
  413. _log.warning("Object in coords 0,0 - using a temporary fix");
  414. object.setXYZ(getActor().getX(), getActor().getY(), getActor().getZ() + 5);
  415. }
  416. // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast)
  417. moveToPawn(object, 20);
  418. }
  419. /**
  420. * Manage the Interact Intention : Set the interact target and Launch a Move To Pawn Task (offset=60).<BR><BR>
  421. *
  422. * <B><U> Actions</U> : </B><BR><BR>
  423. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) </li>
  424. * <li>Set the AI interact target </li>
  425. * <li>Set the Intention of this AI to AI_INTENTION_INTERACT </li>
  426. * <li>Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast) </li><BR><BR>
  427. *
  428. */
  429. @Override
  430. protected void onIntentionInteract(L2Object object)
  431. {
  432. if (getIntention() == AI_INTENTION_REST)
  433. {
  434. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  435. clientActionFailed();
  436. return;
  437. }
  438. if (_actor.isAllSkillsDisabled())
  439. {
  440. // Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
  441. clientActionFailed();
  442. return;
  443. }
  444. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  445. clientStopAutoAttack();
  446. if (getIntention() != AI_INTENTION_INTERACT)
  447. {
  448. // Set the Intention of this AbstractAI to AI_INTENTION_INTERACT
  449. changeIntention(AI_INTENTION_INTERACT, object, null);
  450. // Set the AI interact target
  451. setTarget(object);
  452. // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast)
  453. moveToPawn(object, 60);
  454. }
  455. }
  456. /**
  457. * Do nothing.<BR><BR>
  458. */
  459. @Override
  460. protected void onEvtThink()
  461. {
  462. // do nothing
  463. }
  464. /**
  465. * Do nothing.<BR><BR>
  466. */
  467. @Override
  468. protected void onEvtAggression(L2Character target, int aggro)
  469. {
  470. // do nothing
  471. }
  472. /**
  473. * Launch actions corresponding to the Event Stunned then onAttacked Event.<BR><BR>
  474. *
  475. * <B><U> Actions</U> :</B><BR><BR>
  476. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
  477. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  478. * <li>Break an attack and send Server->Client ActionFailed packet and a System Message to the L2Character </li>
  479. * <li>Break a cast and send Server->Client ActionFailed packet and a System Message to the L2Character </li>
  480. * <li>Launch actions corresponding to the Event onAttacked (only for L2AttackableAI after the stunning periode) </li><BR><BR>
  481. *
  482. */
  483. @Override
  484. protected void onEvtStunned(L2Character attacker)
  485. {
  486. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  487. _actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId()));
  488. if (AttackStanceTaskManager.getInstance().getAttackStanceTask(_actor))
  489. AttackStanceTaskManager.getInstance().removeAttackStanceTask(_actor);
  490. // Stop Server AutoAttack also
  491. setAutoAttacking(false);
  492. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  493. clientStopMoving(null);
  494. // Launch actions corresponding to the Event onAttacked (only for L2AttackableAI after the stunning periode)
  495. onEvtAttacked(attacker);
  496. }
  497. @Override
  498. protected void onEvtParalyzed(L2Character attacker)
  499. {
  500. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  501. _actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId()));
  502. if (AttackStanceTaskManager.getInstance().getAttackStanceTask(_actor))
  503. AttackStanceTaskManager.getInstance().removeAttackStanceTask(_actor);
  504. // Stop Server AutoAttack also
  505. setAutoAttacking(false);
  506. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  507. clientStopMoving(null);
  508. // Launch actions corresponding to the Event onAttacked (only for L2AttackableAI after the stunning periode)
  509. onEvtAttacked(attacker);
  510. }
  511. /**
  512. * Launch actions corresponding to the Event Sleeping.<BR><BR>
  513. *
  514. * <B><U> Actions</U> :</B><BR><BR>
  515. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
  516. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  517. * <li>Break an attack and send Server->Client ActionFailed packet and a System Message to the L2Character </li>
  518. * <li>Break a cast and send Server->Client ActionFailed packet and a System Message to the L2Character </li><BR><BR>
  519. *
  520. */
  521. @Override
  522. protected void onEvtSleeping(L2Character attacker)
  523. {
  524. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  525. _actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId()));
  526. if (AttackStanceTaskManager.getInstance().getAttackStanceTask(_actor))
  527. AttackStanceTaskManager.getInstance().removeAttackStanceTask(_actor);
  528. // stop Server AutoAttack also
  529. setAutoAttacking(false);
  530. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  531. clientStopMoving(null);
  532. }
  533. /**
  534. * Launch actions corresponding to the Event Rooted.<BR><BR>
  535. *
  536. * <B><U> Actions</U> :</B><BR><BR>
  537. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  538. * <li>Launch actions corresponding to the Event onAttacked</li><BR><BR>
  539. *
  540. */
  541. @Override
  542. protected void onEvtRooted(L2Character attacker)
  543. {
  544. // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
  545. //_actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId()));
  546. //if (AttackStanceTaskManager.getInstance().getAttackStanceTask(_actor))
  547. // AttackStanceTaskManager.getInstance().removeAttackStanceTask(_actor);
  548. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  549. clientStopMoving(null);
  550. // Launch actions corresponding to the Event onAttacked
  551. onEvtAttacked(attacker);
  552. }
  553. /**
  554. * Launch actions corresponding to the Event Confused.<BR><BR>
  555. *
  556. * <B><U> Actions</U> :</B><BR><BR>
  557. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  558. * <li>Launch actions corresponding to the Event onAttacked</li><BR><BR>
  559. *
  560. */
  561. @Override
  562. protected void onEvtConfused(L2Character attacker)
  563. {
  564. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  565. clientStopMoving(null);
  566. // Launch actions corresponding to the Event onAttacked
  567. onEvtAttacked(attacker);
  568. }
  569. /**
  570. * Launch actions corresponding to the Event Muted.<BR><BR>
  571. *
  572. * <B><U> Actions</U> :</B><BR><BR>
  573. * <li>Break a cast and send Server->Client ActionFailed packet and a System Message to the L2Character </li><BR><BR>
  574. *
  575. */
  576. @Override
  577. protected void onEvtMuted(L2Character attacker)
  578. {
  579. // Break a cast and send Server->Client ActionFailed packet and a System Message to the L2Character
  580. onEvtAttacked(attacker);
  581. }
  582. /**
  583. * Launch actions corresponding to the Event ReadyToAct.<BR><BR>
  584. *
  585. * <B><U> Actions</U> :</B><BR><BR>
  586. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  587. *
  588. */
  589. @Override
  590. protected void onEvtReadyToAct()
  591. {
  592. // Launch actions corresponding to the Event Think
  593. onEvtThink();
  594. }
  595. /**
  596. * Do nothing.<BR><BR>
  597. */
  598. @Override
  599. protected void onEvtUserCmd(Object arg0, Object arg1)
  600. {
  601. // do nothing
  602. }
  603. /**
  604. * Launch actions corresponding to the Event Arrived.<BR><BR>
  605. *
  606. * <B><U> Actions</U> :</B><BR><BR>
  607. * <li>If the Intention was AI_INTENTION_MOVE_TO, set the Intention to AI_INTENTION_ACTIVE</li>
  608. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  609. *
  610. */
  611. @Override
  612. protected void onEvtArrived()
  613. {
  614. // Launch an explore task if necessary
  615. if (_accessor.getActor() instanceof L2PcInstance)
  616. {
  617. if (Config.ACTIVATE_POSITION_RECORDER)
  618. ((L2PcInstance) _accessor.getActor()).explore();
  619. ((L2PcInstance) _accessor.getActor()).revalidateZone(true);
  620. }
  621. else
  622. _accessor.getActor().revalidateZone();
  623. if (_accessor.getActor().moveToNextRoutePoint())
  624. return;
  625. if (_accessor.getActor() instanceof L2Attackable)
  626. {
  627. ((L2Attackable) _accessor.getActor()).setisReturningToSpawnPoint(false);
  628. }
  629. clientStoppedMoving();
  630. // If the Intention was AI_INTENTION_MOVE_TO, set the Intention to AI_INTENTION_ACTIVE
  631. if (getIntention() == AI_INTENTION_MOVE_TO)
  632. setIntention(AI_INTENTION_ACTIVE);
  633. // Launch actions corresponding to the Event Think
  634. onEvtThink();
  635. if (_actor instanceof L2BoatInstance)
  636. {
  637. ((L2BoatInstance) _actor).evtArrived();
  638. }
  639. }
  640. /**
  641. * Launch actions corresponding to the Event ArrivedRevalidate.<BR><BR>
  642. *
  643. * <B><U> Actions</U> :</B><BR><BR>
  644. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  645. *
  646. */
  647. @Override
  648. protected void onEvtArrivedRevalidate()
  649. {
  650. // Launch actions corresponding to the Event Think
  651. onEvtThink();
  652. }
  653. /**
  654. * Launch actions corresponding to the Event ArrivedBlocked.<BR><BR>
  655. *
  656. * <B><U> Actions</U> :</B><BR><BR>
  657. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  658. * <li>If the Intention was AI_INTENTION_MOVE_TO, set the Intention to AI_INTENTION_ACTIVE</li>
  659. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  660. *
  661. */
  662. @Override
  663. protected void onEvtArrivedBlocked(L2CharPosition blocked_at_pos)
  664. {
  665. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  666. clientStopMoving(blocked_at_pos);
  667. if (Config.ACTIVATE_POSITION_RECORDER && Universe.getInstance().shouldLog(_accessor.getActor().getObjectId()))
  668. {
  669. if (!_accessor.getActor().isFlying())
  670. Universe.getInstance().registerObstacle(blocked_at_pos.x, blocked_at_pos.y, blocked_at_pos.z);
  671. if (_accessor.getActor() instanceof L2PcInstance)
  672. ((L2PcInstance) _accessor.getActor()).explore();
  673. }
  674. // If the Intention was AI_INTENTION_MOVE_TO, tet the Intention to AI_INTENTION_ACTIVE
  675. if (getIntention() == AI_INTENTION_MOVE_TO)
  676. setIntention(AI_INTENTION_ACTIVE);
  677. // Launch actions corresponding to the Event Think
  678. onEvtThink();
  679. }
  680. /**
  681. * Launch actions corresponding to the Event ForgetObject.<BR><BR>
  682. *
  683. * <B><U> Actions</U> :</B><BR><BR>
  684. * <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>
  685. * <li>If the object was targeted to attack, stop the auto-attack, cancel target and set the Intention to AI_INTENTION_ACTIVE</li>
  686. * <li>If the object was targeted to cast, cancel target and set the Intention to AI_INTENTION_ACTIVE</li>
  687. * <li>If the object was targeted to follow, stop the movement, cancel AI Follow Task and set the Intention to AI_INTENTION_ACTIVE</li>
  688. * <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>
  689. *
  690. */
  691. @Override
  692. protected void onEvtForgetObject(L2Object object)
  693. {
  694. // If the object was targeted and the Intention was AI_INTENTION_INTERACT or AI_INTENTION_PICK_UP, set the Intention to AI_INTENTION_ACTIVE
  695. if (getTarget() == object)
  696. {
  697. setTarget(null);
  698. if (getIntention() == AI_INTENTION_INTERACT)
  699. setIntention(AI_INTENTION_ACTIVE);
  700. else if (getIntention() == AI_INTENTION_PICK_UP)
  701. setIntention(AI_INTENTION_ACTIVE);
  702. }
  703. // Check if the object was targeted to attack
  704. if (getAttackTarget() == object)
  705. {
  706. // Cancel attack target
  707. setAttackTarget(null);
  708. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  709. setIntention(AI_INTENTION_ACTIVE);
  710. }
  711. // Check if the object was targeted to cast
  712. if (getCastTarget() == object)
  713. {
  714. // Cancel cast target
  715. setCastTarget(null);
  716. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  717. setIntention(AI_INTENTION_ACTIVE);
  718. }
  719. // Check if the object was targeted to follow
  720. if (getFollowTarget() == object)
  721. {
  722. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  723. clientStopMoving(null);
  724. // Stop an AI Follow Task
  725. stopFollow();
  726. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  727. setIntention(AI_INTENTION_ACTIVE);
  728. }
  729. // Check if the targeted object was the actor
  730. if (_actor == object)
  731. {
  732. // Cancel AI target
  733. setTarget(null);
  734. setAttackTarget(null);
  735. setCastTarget(null);
  736. // Stop an AI Follow Task
  737. stopFollow();
  738. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  739. clientStopMoving(null);
  740. // Set the Intention of this AbstractAI to AI_INTENTION_IDLE
  741. changeIntention(AI_INTENTION_IDLE, null, null);
  742. }
  743. }
  744. /**
  745. * Launch actions corresponding to the Event Cancel.<BR><BR>
  746. *
  747. * <B><U> Actions</U> :</B><BR><BR>
  748. * <li>Stop an AI Follow Task</li>
  749. * <li>Launch actions corresponding to the Event Think</li><BR><BR>
  750. *
  751. */
  752. @Override
  753. protected void onEvtCancel()
  754. {
  755. // Stop an AI Follow Task
  756. stopFollow();
  757. if (!AttackStanceTaskManager.getInstance().getAttackStanceTask(_actor))
  758. _actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId()));
  759. // Launch actions corresponding to the Event Think
  760. onEvtThink();
  761. }
  762. /**
  763. * Launch actions corresponding to the Event Dead.<BR><BR>
  764. *
  765. * <B><U> Actions</U> :</B><BR><BR>
  766. * <li>Stop an AI Follow Task</li>
  767. * <li>Kill the actor client side by sending Server->Client packet AutoAttackStop, StopMove/StopRotation, Die (broadcast)</li><BR><BR>
  768. *
  769. */
  770. @Override
  771. protected void onEvtDead()
  772. {
  773. // Stop an AI Follow Task
  774. stopFollow();
  775. // Kill the actor client side by sending Server->Client packet AutoAttackStop, StopMove/StopRotation, Die (broadcast)
  776. clientNotifyDead();
  777. if (!(_actor instanceof L2PcInstance))
  778. _actor.setWalking();
  779. }
  780. /**
  781. * Launch actions corresponding to the Event Fake Death.<BR><BR>
  782. *
  783. * <B><U> Actions</U> :</B><BR><BR>
  784. * <li>Stop an AI Follow Task</li>
  785. *
  786. */
  787. @Override
  788. protected void onEvtFakeDeath()
  789. {
  790. // Stop an AI Follow Task
  791. stopFollow();
  792. // Stop the actor movement and send Server->Client packet StopMove/StopRotation (broadcast)
  793. clientStopMoving(null);
  794. // Init AI
  795. _intention = AI_INTENTION_IDLE;
  796. setTarget(null);
  797. setCastTarget(null);
  798. setAttackTarget(null);
  799. }
  800. /**
  801. * Do nothing.<BR><BR>
  802. */
  803. @Override
  804. protected void onEvtFinishCasting()
  805. {
  806. // do nothing
  807. }
  808. protected boolean maybeMoveToPosition(Point3D worldPosition, int offset)
  809. {
  810. if (worldPosition == null)
  811. {
  812. _log.warning("maybeMoveToPosition: worldPosition == NULL!");
  813. return false;
  814. }
  815. if (offset < 0)
  816. return false; // skill radius -1
  817. if (!_actor.isInsideRadius(worldPosition.getX(), worldPosition.getY(), offset + _actor.getTemplate().collisionRadius, false))
  818. {
  819. if (_actor.isMovementDisabled())
  820. return true;
  821. if (!_actor.isRunning() && !(this instanceof L2PlayerAI))
  822. _actor.setRunning();
  823. stopFollow();
  824. int x = _actor.getX();
  825. int y = _actor.getY();
  826. double dx = worldPosition.getX() - x;
  827. double dy = worldPosition.getY() - y;
  828. double dist = Math.sqrt(dx * dx + dy * dy);
  829. double sin = dy / dist;
  830. double cos = dx / dist;
  831. dist -= offset - 5;
  832. x += (int) (dist * cos);
  833. y += (int) (dist * sin);
  834. moveTo(x, y, worldPosition.getZ());
  835. return true;
  836. }
  837. if (getFollowTarget() != null)
  838. stopFollow();
  839. return false;
  840. }
  841. /**
  842. * Manage the Move to Pawn action in function of the distance and of the Interact area.<BR><BR>
  843. *
  844. * <B><U> Actions</U> :</B><BR><BR>
  845. * <li>Get the distance between the current position of the L2Character and the target (x,y)</li>
  846. * <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>
  847. * <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>
  848. *
  849. * <B><U> Example of use </U> :</B><BR><BR>
  850. * <li> L2PLayerAI, L2SummonAI</li><BR><BR>
  851. *
  852. * @param target The targeted L2Object
  853. * @param offset The Interact area radius
  854. *
  855. * @return True if a movement must be done
  856. *
  857. */
  858. protected boolean maybeMoveToPawn(L2Object target, int offset)
  859. {
  860. // Get the distance between the current position of the L2Character and the target (x,y)
  861. if (target == null)
  862. {
  863. _log.warning("maybeMoveToPawn: target == NULL!");
  864. return false;
  865. }
  866. if (offset < 0)
  867. return false; // skill radius -1
  868. offset += _actor.getTemplate().collisionRadius;
  869. if (target instanceof L2Character)
  870. offset += ((L2Character) target).getTemplate().collisionRadius;
  871. if (!_actor.isInsideRadius(target, offset, false, false))
  872. {
  873. // Caller should be L2Playable and thinkAttack/thinkCast/thinkInteract/thinkPickUp
  874. if (getFollowTarget() != null)
  875. {
  876. // allow larger hit range when the target is moving (check is run only once per second)
  877. if (!_actor.isInsideRadius(target, offset + 100, false, false))
  878. return true;
  879. stopFollow();
  880. return false;
  881. }
  882. if (_actor.isMovementDisabled())
  883. return true;
  884. // If not running, set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  885. if (!_actor.isRunning() && !(this instanceof L2PlayerAI))
  886. _actor.setRunning();
  887. stopFollow();
  888. if ((target instanceof L2Character) && !(target instanceof L2DoorInstance))
  889. {
  890. if (((L2Character) target).isMoving())
  891. offset -= 100;
  892. if (offset < 5)
  893. offset = 5;
  894. startFollow((L2Character) target, offset);
  895. }
  896. else
  897. {
  898. // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast)
  899. moveToPawn(target, offset);
  900. }
  901. return true;
  902. }
  903. if (getFollowTarget() != null)
  904. stopFollow();
  905. // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)
  906. // clientStopMoving(null);
  907. return false;
  908. }
  909. /**
  910. * Modify current Intention and actions if the target is lost or dead.<BR><BR>
  911. *
  912. * <B><U> Actions</U> : <I>If the target is lost or dead</I></B><BR><BR>
  913. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
  914. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  915. * <li>Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE</li><BR><BR>
  916. *
  917. * <B><U> Example of use </U> :</B><BR><BR>
  918. * <li> L2PLayerAI, L2SummonAI</li><BR><BR>
  919. *
  920. * @param target The targeted L2Object
  921. *
  922. * @return True if the target is lost or dead (false if fakedeath)
  923. *
  924. */
  925. protected boolean checkTargetLostOrDead(L2Character target)
  926. {
  927. if (target == null || target.isAlikeDead())
  928. {
  929. //check if player is fakedeath
  930. if (target != null && target.isFakeDeath())
  931. {
  932. target.stopFakeDeath(null);
  933. return false;
  934. }
  935. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  936. setIntention(AI_INTENTION_ACTIVE);
  937. return true;
  938. }
  939. return false;
  940. }
  941. /**
  942. * Modify current Intention and actions if the target is lost.<BR><BR>
  943. *
  944. * <B><U> Actions</U> : <I>If the target is lost</I></B><BR><BR>
  945. * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
  946. * <li>Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast)</li>
  947. * <li>Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE</li><BR><BR>
  948. *
  949. * <B><U> Example of use </U> :</B><BR><BR>
  950. * <li> L2PLayerAI, L2SummonAI</li><BR><BR>
  951. *
  952. * @param target The targeted L2Object
  953. *
  954. * @return True if the target is lost
  955. *
  956. */
  957. protected boolean checkTargetLost(L2Object target)
  958. {
  959. // check if player is fakedeath
  960. if (target instanceof L2PcInstance)
  961. {
  962. L2PcInstance target2 = (L2PcInstance) target; //convert object to chara
  963. if (target2.isFakeDeath())
  964. {
  965. target2.stopFakeDeath(null);
  966. return false;
  967. }
  968. }
  969. if (target == null)
  970. {
  971. // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE
  972. setIntention(AI_INTENTION_ACTIVE);
  973. return true;
  974. }
  975. return false;
  976. }
  977. protected class SelfAnalysis
  978. {
  979. public boolean isMage = false;
  980. public boolean isBalanced;
  981. public boolean isArcher = false;
  982. public boolean isFighter = false;
  983. public boolean cannotMoveOnLand = false;
  984. public List<L2Skill> generalSkills = new FastList<L2Skill>();
  985. public List<L2Skill> buffSkills = new FastList<L2Skill>();
  986. public int lastBuffTick = 0;
  987. public List<L2Skill> debuffSkills = new FastList<L2Skill>();
  988. public int lastDebuffTick = 0;
  989. public List<L2Skill> cancelSkills = new FastList<L2Skill>();
  990. public List<L2Skill> healSkills = new FastList<L2Skill>();
  991. //public List<L2Skill> trickSkills = new FastList<L2Skill>();
  992. public List<L2Skill> generalDisablers = new FastList<L2Skill>();
  993. public List<L2Skill> sleepSkills = new FastList<L2Skill>();
  994. public List<L2Skill> rootSkills = new FastList<L2Skill>();
  995. public List<L2Skill> muteSkills = new FastList<L2Skill>();
  996. public List<L2Skill> resurrectSkills = new FastList<L2Skill>();
  997. public boolean hasHealOrResurrect = false;
  998. public boolean hasLongRangeSkills = false;
  999. public boolean hasLongRangeDamageSkills = false;
  1000. public int maxCastRange = 0;
  1001. public SelfAnalysis()
  1002. {
  1003. }
  1004. public void init()
  1005. {
  1006. switch (((L2NpcTemplate) _actor.getTemplate()).AI)
  1007. {
  1008. case FIGHTER:
  1009. isFighter = true;
  1010. break;
  1011. case MAGE:
  1012. isMage = true;
  1013. break;
  1014. case BALANCED:
  1015. isBalanced = true;
  1016. break;
  1017. case ARCHER:
  1018. isArcher = true;
  1019. break;
  1020. default:
  1021. isFighter = true;
  1022. break;
  1023. }
  1024. // water movement analysis
  1025. if (_actor instanceof L2NpcInstance)
  1026. {
  1027. int npcId = ((L2NpcInstance) _actor).getNpcId();
  1028. switch (npcId)
  1029. {
  1030. case 20314: // great white shark
  1031. case 20849: // Light Worm
  1032. cannotMoveOnLand = true;
  1033. break;
  1034. default:
  1035. cannotMoveOnLand = false;
  1036. break;
  1037. }
  1038. }
  1039. // skill analysis
  1040. for (L2Skill sk : _actor.getAllSkills())
  1041. {
  1042. if (sk.isPassive())
  1043. continue;
  1044. int castRange = sk.getCastRange();
  1045. boolean hasLongRangeDamageSkill = false;
  1046. switch (sk.getSkillType())
  1047. {
  1048. case HEAL:
  1049. case HEAL_PERCENT:
  1050. case HEAL_STATIC:
  1051. case BALANCE_LIFE:
  1052. case HOT:
  1053. healSkills.add(sk);
  1054. hasHealOrResurrect = true;
  1055. continue; // won't be considered something for fighting
  1056. case BUFF:
  1057. buffSkills.add(sk);
  1058. continue; // won't be considered something for fighting
  1059. case PARALYZE:
  1060. case STUN:
  1061. // hardcoding petrification until improvements are made to
  1062. // EffectTemplate... petrification is totally different for
  1063. // AI than paralyze
  1064. switch (sk.getId())
  1065. {
  1066. case 367:
  1067. case 4111:
  1068. case 4383:
  1069. case 4616:
  1070. case 4578:
  1071. sleepSkills.add(sk);
  1072. break;
  1073. default:
  1074. generalDisablers.add(sk);
  1075. break;
  1076. }
  1077. break;
  1078. case MUTE:
  1079. muteSkills.add(sk);
  1080. break;
  1081. case SLEEP:
  1082. sleepSkills.add(sk);
  1083. break;
  1084. case ROOT:
  1085. rootSkills.add(sk);
  1086. break;
  1087. case FEAR: // could be used as an alternative for healing?
  1088. case CONFUSION:
  1089. // trickSkills.add(sk);
  1090. case DEBUFF:
  1091. debuffSkills.add(sk);
  1092. break;
  1093. case CANCEL:
  1094. case MAGE_BANE:
  1095. case WARRIOR_BANE:
  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. }