L2CharacterAI.java 48 KB

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