L2CharacterAI.java 46 KB

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