L2CharacterAI.java 49 KB

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