L2CharacterAI.java 49 KB

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