L2CharacterAI.java 43 KB

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