2
0

L2CharacterAI.java 48 KB

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