L2AttackableAI.java 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512
  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_IDLE;
  19. import java.util.Collection;
  20. import java.util.concurrent.Future;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.GameTimeController;
  23. import com.l2jserver.gameserver.GeoData;
  24. import com.l2jserver.gameserver.Territory;
  25. import com.l2jserver.gameserver.ThreadPoolManager;
  26. import com.l2jserver.gameserver.datatables.NpcTable;
  27. import com.l2jserver.gameserver.instancemanager.DimensionalRiftManager;
  28. import com.l2jserver.gameserver.model.L2CharPosition;
  29. import com.l2jserver.gameserver.model.L2Object;
  30. import com.l2jserver.gameserver.model.L2Skill;
  31. import com.l2jserver.gameserver.model.L2Skill.SkillTargetType;
  32. import com.l2jserver.gameserver.model.actor.L2Attackable;
  33. import com.l2jserver.gameserver.model.actor.L2Character;
  34. import com.l2jserver.gameserver.model.actor.L2Npc;
  35. import com.l2jserver.gameserver.model.actor.L2Playable;
  36. import com.l2jserver.gameserver.model.actor.L2Summon;
  37. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  38. import com.l2jserver.gameserver.model.actor.instance.L2FestivalMonsterInstance;
  39. import com.l2jserver.gameserver.model.actor.instance.L2FriendlyMobInstance;
  40. import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  41. import com.l2jserver.gameserver.model.actor.instance.L2GuardInstance;
  42. import com.l2jserver.gameserver.model.actor.instance.L2MinionInstance;
  43. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  44. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  45. import com.l2jserver.gameserver.model.actor.instance.L2RaidBossInstance;
  46. import com.l2jserver.gameserver.model.actor.instance.L2RiftInvaderInstance;
  47. import com.l2jserver.gameserver.model.quest.Quest;
  48. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  49. import com.l2jserver.gameserver.templates.skills.L2EffectType;
  50. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  51. import com.l2jserver.gameserver.util.Util;
  52. import com.l2jserver.util.Rnd;
  53. /**
  54. * This class manages AI of L2Attackable.<BR><BR>
  55. *
  56. */
  57. public class L2AttackableAI extends L2CharacterAI implements Runnable
  58. {
  59. //protected static final Logger _log = Logger.getLogger(L2AttackableAI.class.getName());
  60. private static final int RANDOM_WALK_RATE = 30; // confirmed
  61. // private static final int MAX_DRIFT_RANGE = 300;
  62. private static final int MAX_ATTACK_TIMEOUT = 300; // int ticks, i.e. 30 seconds
  63. /** The L2Attackable AI task executed every 1s (call onEvtThink method)*/
  64. private Future<?> _aiTask;
  65. /** The delay after which the attacked is stopped */
  66. private int _attackTimeout;
  67. /** The L2Attackable aggro counter */
  68. private int _globalAggro;
  69. /** The flag used to indicate that a thinking action is in progress */
  70. private boolean _thinking; // to prevent recursive thinking
  71. private int timepass = 0;
  72. private int chaostime = 0;
  73. private L2NpcTemplate _skillrender;
  74. int lastBuffTick;
  75. /**
  76. * Constructor of L2AttackableAI.<BR><BR>
  77. *
  78. * @param accessor The AI accessor of the L2Character
  79. *
  80. */
  81. public L2AttackableAI(L2Character.AIAccessor accessor)
  82. {
  83. super(accessor);
  84. _skillrender = NpcTable.getInstance().getTemplate(((L2Npc)_actor).getTemplate().npcId);
  85. //_selfAnalysis.init();
  86. _attackTimeout = Integer.MAX_VALUE;
  87. _globalAggro = -10; // 10 seconds timeout of ATTACK after respawn
  88. }
  89. public void run()
  90. {
  91. // Launch actions corresponding to the Event Think
  92. onEvtThink();
  93. }
  94. /**
  95. * Return True if the target is autoattackable (depends on the actor type).<BR><BR>
  96. *
  97. * <B><U> Actor is a L2GuardInstance</U> :</B><BR><BR>
  98. * <li>The target isn't a Folk or a Door</li>
  99. * <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
  100. * <li>The target is in the actor Aggro range and is at the same height</li>
  101. * <li>The L2PcInstance target has karma (=PK)</li>
  102. * <li>The L2MonsterInstance target is aggressive</li><BR><BR>
  103. *
  104. * <B><U> Actor is a L2SiegeGuardInstance</U> :</B><BR><BR>
  105. * <li>The target isn't a Folk or a Door</li>
  106. * <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
  107. * <li>The target is in the actor Aggro range and is at the same height</li>
  108. * <li>A siege is in progress</li>
  109. * <li>The L2PcInstance target isn't a Defender</li><BR><BR>
  110. *
  111. * <B><U> Actor is a L2FriendlyMobInstance</U> :</B><BR><BR>
  112. * <li>The target isn't a Folk, a Door or another L2Npc</li>
  113. * <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
  114. * <li>The target is in the actor Aggro range and is at the same height</li>
  115. * <li>The L2PcInstance target has karma (=PK)</li><BR><BR>
  116. *
  117. * <B><U> Actor is a L2MonsterInstance</U> :</B><BR><BR>
  118. * <li>The target isn't a Folk, a Door or another L2Npc</li>
  119. * <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
  120. * <li>The target is in the actor Aggro range and is at the same height</li>
  121. * <li>The actor is Aggressive</li><BR><BR>
  122. *
  123. * @param target The targeted L2Object
  124. *
  125. */
  126. private boolean autoAttackCondition(L2Character target)
  127. {
  128. if (target == null || _actor == null)
  129. return false;
  130. L2Attackable me = (L2Attackable) _actor;
  131. // Check if the target isn't invulnerable
  132. if (target.isInvul())
  133. {
  134. // However EffectInvincible requires to check GMs specially
  135. if (target instanceof L2PcInstance && ((L2PcInstance)target).isGM())
  136. return false;
  137. if (target instanceof L2Summon && ((L2Summon)target).getOwner().isGM())
  138. return false;
  139. }
  140. // Check if the target isn't a Folk or a Door
  141. if (target instanceof L2DoorInstance) return false;
  142. // Check if the target isn't dead, is in the Aggro range and is at the same height
  143. if (target.isAlikeDead() || (target instanceof L2Playable && !me.isInsideRadius(target, me.getAggroRange(), true, false)))
  144. return false;
  145. // Check if the target is a L2PlayableInstance
  146. if (target instanceof L2Playable)
  147. {
  148. // Check if the AI isn't a Raid Boss, can See Silent Moving players and the target isn't in silent move mode
  149. if (!(me.isRaid()) && !(me.canSeeThroughSilentMove()) && ((L2Playable)target).isSilentMoving())
  150. return false;
  151. }
  152. // Check if the target is a L2PcInstance
  153. if (target instanceof L2PcInstance)
  154. {
  155. // Don't take the aggro if the GM has the access level below or equal to GM_DONT_TAKE_AGGRO
  156. if (((L2PcInstance)target).isGM() && !((L2PcInstance)target).getAccessLevel().canTakeAggro())
  157. return false;
  158. // TODO: Ideally, autoattack condition should be called from the AI script. In that case,
  159. // it should only implement the basic behaviors while the script will add more specific
  160. // behaviors (like varka/ketra alliance, etc). Once implemented, remove specialized stuff
  161. // from this location. (Fulminus)
  162. // Check if player is an ally (comparing mem addr)
  163. if ("varka".equals(me.getFactionId()) && ((L2PcInstance) target).isAlliedWithVarka())
  164. return false;
  165. if ("ketra".equals(me.getFactionId()) && ((L2PcInstance) target).isAlliedWithKetra())
  166. return false;
  167. // check if the target is within the grace period for JUST getting up from fake death
  168. if (((L2PcInstance) target).isRecentFakeDeath())
  169. return false;
  170. if (target.isInParty() && target.getParty().isInDimensionalRift())
  171. {
  172. byte riftType = target.getParty().getDimensionalRift().getType();
  173. byte riftRoom = target.getParty().getDimensionalRift().getCurrentRoom();
  174. if (me instanceof L2RiftInvaderInstance && !DimensionalRiftManager.getInstance().getRoom(riftType, riftRoom).checkIfInZone(me.getX(), me.getY(), me.getZ()))
  175. return false;
  176. }
  177. //if (_selfAnalysis.cannotMoveOnLand && !target.isInsideZone(L2Character.ZONE_WATER))
  178. // return false;
  179. }
  180. // Check if the target is a L2Summon
  181. if (target instanceof L2Summon)
  182. {
  183. L2PcInstance owner = ((L2Summon)target).getOwner();
  184. if (owner != null)
  185. {
  186. // Don't take the aggro if the GM has the access level below or equal to GM_DONT_TAKE_AGGRO
  187. if (owner.isGM() && (owner.isInvul() || !owner.getAccessLevel().canTakeAggro()))
  188. return false;
  189. // Check if player is an ally (comparing mem addr)
  190. if ("varka".equals(me.getFactionId()) && owner.isAlliedWithVarka())
  191. return false;
  192. if ("ketra".equals(me.getFactionId()) && owner.isAlliedWithKetra())
  193. return false;
  194. }
  195. }
  196. // Check if the actor is a L2GuardInstance
  197. if (_actor instanceof L2GuardInstance)
  198. {
  199. // Check if the L2PcInstance target has karma (=PK)
  200. if (target instanceof L2PcInstance && ((L2PcInstance) target).getKarma() > 0)
  201. // Los Check
  202. return GeoData.getInstance().canSeeTarget(me, target);
  203. //if (target instanceof L2Summon)
  204. // return ((L2Summon)target).getKarma() > 0;
  205. // Check if the L2MonsterInstance target is aggressive
  206. if (target instanceof L2MonsterInstance && Config.GUARD_ATTACK_AGGRO_MOB)
  207. return (((L2MonsterInstance) target).isAggressive() && GeoData.getInstance().canSeeTarget(me, target));
  208. return false;
  209. }
  210. else if (_actor instanceof L2FriendlyMobInstance)
  211. { // the actor is a L2FriendlyMobInstance
  212. // Check if the target isn't another L2Npc
  213. if (target instanceof L2Npc)
  214. return false;
  215. // Check if the L2PcInstance target has karma (=PK)
  216. if (target instanceof L2PcInstance && ((L2PcInstance) target).getKarma() > 0)
  217. return GeoData.getInstance().canSeeTarget(me, target); // Los Check
  218. else
  219. return false;
  220. }
  221. else
  222. {
  223. if(target instanceof L2Attackable)
  224. {
  225. if (((L2Attackable)_actor).getEnemyClan() == null || ((L2Attackable)target).getClan() == null)
  226. return false;
  227. if (!target.isAutoAttackable(_actor))
  228. return false;
  229. if (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)target).getClan()))
  230. {
  231. if (_actor.isInsideRadius(target, ((L2Attackable)_actor).getEnemyRange(), false, false))
  232. {
  233. return GeoData.getInstance().canSeeTarget(_actor, target);
  234. }
  235. else return false;
  236. }
  237. if (((L2Attackable)_actor).getIsChaos() > 0 && me.isInsideRadius(target, ((L2Attackable)_actor).getIsChaos(), false, false) )
  238. {
  239. if (((L2Attackable)_actor).getFactionId() != null && ((L2Attackable)_actor).getFactionId().equals(((L2Attackable) target).getFactionId()))
  240. {
  241. return false;
  242. }
  243. // Los Check
  244. return GeoData.getInstance().canSeeTarget(me, target);
  245. }
  246. }
  247. if (target instanceof L2Attackable || target instanceof L2Npc)
  248. return false;
  249. // depending on config, do not allow mobs to attack _new_ players in peacezones,
  250. // unless they are already following those players from outside the peacezone.
  251. if (!Config.ALT_MOB_AGRO_IN_PEACEZONE && target.isInsideZone(L2Character.ZONE_PEACE))
  252. return false;
  253. if (me.isChampion() && Config.L2JMOD_CHAMPION_PASSIVE)
  254. return false;
  255. // Check if the actor is Aggressive
  256. return (me.isAggressive() && GeoData.getInstance().canSeeTarget(me, target));
  257. }
  258. }
  259. public void startAITask()
  260. {
  261. // If not idle - create an AI task (schedule onEvtThink repeatedly)
  262. if (_aiTask == null)
  263. {
  264. _aiTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(this, 1000, 1000);
  265. }
  266. }
  267. public void stopAITask()
  268. {
  269. if (_aiTask != null)
  270. {
  271. _aiTask.cancel(false);
  272. _aiTask = null;
  273. }
  274. }
  275. @Override
  276. protected void onEvtDead()
  277. {
  278. stopAITask();
  279. super.onEvtDead();
  280. }
  281. /**
  282. * Set the Intention of this L2CharacterAI and create an AI Task executed every 1s (call onEvtThink method) for this L2Attackable.<BR><BR>
  283. *
  284. * <FONT COLOR=#FF0000><B> <U>Caution</U> : If actor _knowPlayer isn't EMPTY, AI_INTENTION_IDLE will be change in AI_INTENTION_ACTIVE</B></FONT><BR><BR>
  285. *
  286. * @param intention The new Intention to set to the AI
  287. * @param arg0 The first parameter of the Intention
  288. * @param arg1 The second parameter of the Intention
  289. *
  290. */
  291. @Override
  292. synchronized void changeIntention(CtrlIntention intention, Object arg0, Object arg1)
  293. {
  294. if (intention == AI_INTENTION_IDLE || intention == AI_INTENTION_ACTIVE)
  295. {
  296. // Check if actor is not dead
  297. if (!_actor.isAlikeDead())
  298. {
  299. L2Attackable npc = (L2Attackable) _actor;
  300. // If its _knownPlayer isn't empty set the Intention to AI_INTENTION_ACTIVE
  301. if (!npc.getKnownList().getKnownPlayers().isEmpty())
  302. intention = AI_INTENTION_ACTIVE;
  303. else
  304. {
  305. if (npc.getSpawn() != null)
  306. {
  307. final int range = Config.MAX_DRIFT_RANGE;
  308. if (!npc.isInsideRadius(npc.getSpawn().getLocx(), npc.getSpawn().getLocy(), npc.getSpawn().getLocz(), range + range, true, false))
  309. intention = AI_INTENTION_ACTIVE;
  310. }
  311. }
  312. }
  313. if (intention == AI_INTENTION_IDLE)
  314. {
  315. // Set the Intention of this L2AttackableAI to AI_INTENTION_IDLE
  316. super.changeIntention(AI_INTENTION_IDLE, null, null);
  317. // Stop AI task and detach AI from NPC
  318. if (_aiTask != null)
  319. {
  320. _aiTask.cancel(true);
  321. _aiTask = null;
  322. }
  323. // Cancel the AI
  324. _accessor.detachAI();
  325. return;
  326. }
  327. }
  328. // Set the Intention of this L2AttackableAI to intention
  329. super.changeIntention(intention, arg0, arg1);
  330. // If not idle - create an AI task (schedule onEvtThink repeatedly)
  331. startAITask();
  332. }
  333. /**
  334. * Manage the Attack Intention : Stop current Attack (if necessary), Calculate attack timeout, Start a new Attack and Launch Think Event.<BR><BR>
  335. *
  336. * @param target The L2Character to attack
  337. *
  338. */
  339. @Override
  340. protected void onIntentionAttack(L2Character target)
  341. {
  342. // Calculate the attack timeout
  343. _attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks();
  344. // self and buffs
  345. if (lastBuffTick+30 < GameTimeController.getGameTicks())
  346. {
  347. if(_skillrender.hasBuffSkill())
  348. for (L2Skill sk : _skillrender._buffskills)
  349. if (Cast(sk))
  350. break;
  351. lastBuffTick = GameTimeController.getGameTicks();
  352. }
  353. // Manage the Attack Intention : Stop current Attack (if necessary), Start a new Attack and Launch Think Event
  354. super.onIntentionAttack(target);
  355. }
  356. /**
  357. * Manage AI standard thinks of a L2Attackable (called by onEvtThink).<BR><BR>
  358. *
  359. * <B><U> Actions</U> :</B><BR><BR>
  360. * <li>Update every 1s the _globalAggro counter to come close to 0</li>
  361. * <li>If the actor is Aggressive and can attack, add all autoAttackable L2Character in its Aggro Range to its _aggroList, chose a target and order to attack it</li>
  362. * <li>If the actor is a L2GuardInstance that can't attack, order to it to return to its home location</li>
  363. * <li>If the actor is a L2MonsterInstance that can't attack, order to it to random walk (1/100)</li><BR><BR>
  364. *
  365. */
  366. private void thinkActive()
  367. {
  368. L2Attackable npc = (L2Attackable) _actor;
  369. // Update every 1s the _globalAggro counter to come close to 0
  370. if (_globalAggro != 0)
  371. {
  372. if (_globalAggro < 0)
  373. _globalAggro++;
  374. else
  375. _globalAggro--;
  376. }
  377. // Add all autoAttackable L2Character in L2Attackable Aggro Range to its _aggroList with 0 damage and 1 hate
  378. // A L2Attackable isn't aggressive during 10s after its spawn because _globalAggro is set to -10
  379. if (_globalAggro >= 0)
  380. {
  381. // Get all visible objects inside its Aggro Range
  382. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  383. //synchronized (npc.getKnownList().getKnownObjects())
  384. {
  385. for (L2Object obj : objs)
  386. {
  387. if (!(obj instanceof L2Character))
  388. continue;
  389. L2Character target = (L2Character) obj;
  390. /*
  391. * Check to see if this is a festival mob spawn.
  392. * If it is, then check to see if the aggro trigger
  393. * is a festival participant...if so, move to attack it.
  394. */
  395. if ((_actor instanceof L2FestivalMonsterInstance) && obj instanceof L2PcInstance)
  396. {
  397. L2PcInstance targetPlayer = (L2PcInstance) obj;
  398. if (!(targetPlayer.isFestivalParticipant()))
  399. continue;
  400. }
  401. // TODO: The AI Script ought to handle aggro behaviors in onSee. Once implemented, aggro behaviors ought
  402. // to be removed from here. (Fulminus)
  403. // For each L2Character check if the target is autoattackable
  404. if (autoAttackCondition(target)) // check aggression
  405. {
  406. // Get the hate level of the L2Attackable against this L2Character target contained in _aggroList
  407. int hating = npc.getHating(target);
  408. // Add the attacker to the L2Attackable _aggroList with 0 damage and 1 hate
  409. if (hating == 0)
  410. npc.addDamageHate(target, 0, 0);
  411. }
  412. }
  413. }
  414. // Chose a target from its aggroList
  415. L2Character hated;
  416. if (_actor.isConfused())
  417. hated = getAttackTarget(); // effect handles selection
  418. else
  419. hated = npc.getMostHated();
  420. // Order to the L2Attackable to attack the target
  421. if (hated != null)
  422. {
  423. // Get the hate level of the L2Attackable against this L2Character target contained in _aggroList
  424. int aggro = npc.getHating(hated);
  425. if (aggro + _globalAggro > 0)
  426. {
  427. // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  428. if (!_actor.isRunning())
  429. _actor.setRunning();
  430. // Set the AI Intention to AI_INTENTION_ATTACK
  431. setIntention(CtrlIntention.AI_INTENTION_ATTACK, hated);
  432. }
  433. return;
  434. }
  435. }
  436. // Check if the actor is a L2GuardInstance
  437. if (_actor instanceof L2GuardInstance)
  438. {
  439. // Order to the L2GuardInstance to return to its home location because there's no target to attack
  440. ((L2GuardInstance) _actor).returnHome();
  441. }
  442. // If this is a festival monster, then it remains in the same location.
  443. if (_actor instanceof L2FestivalMonsterInstance)
  444. return;
  445. // Check if the mob should not return to spawn point
  446. if (!npc.canReturnToSpawnPoint())
  447. return;
  448. // Minions following leader
  449. if (_actor instanceof L2MinionInstance && ((L2MinionInstance) _actor).getLeader() != null)
  450. {
  451. int offset;
  452. if (_actor.isRaidMinion())
  453. offset = 500; // for Raids - need correction
  454. else
  455. offset = 200; // for normal minions - need correction :)
  456. if (((L2MinionInstance) _actor).getLeader().isRunning())
  457. _actor.setRunning();
  458. else
  459. _actor.setWalking();
  460. if (_actor.getPlanDistanceSq(((L2MinionInstance) _actor).getLeader()) > offset * offset)
  461. {
  462. int x1, y1, z1;
  463. x1 = ((L2MinionInstance) _actor).getLeader().getX() + Rnd.nextInt((offset - 30) * 2) - (offset - 30);
  464. y1 = ((L2MinionInstance) _actor).getLeader().getY() + Rnd.nextInt((offset - 30) * 2) - (offset - 30);
  465. z1 = ((L2MinionInstance) _actor).getLeader().getZ();
  466. // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
  467. moveTo(x1, y1, z1);
  468. return;
  469. }
  470. else if (Rnd.nextInt(RANDOM_WALK_RATE) == 0)
  471. {
  472. if(_skillrender.hasBuffSkill())
  473. for (L2Skill sk : _skillrender._buffskills)
  474. if (Cast(sk))
  475. return;
  476. }
  477. }
  478. // Order to the L2MonsterInstance to random walk (1/100)
  479. else if (npc.getSpawn() != null && Rnd.nextInt(RANDOM_WALK_RATE) == 0
  480. && !_actor.isNoRndWalk())
  481. {
  482. int x1, y1, z1;
  483. final int range = Config.MAX_DRIFT_RANGE;
  484. if(_skillrender.hasBuffSkill())
  485. for (L2Skill sk : _skillrender._buffskills)
  486. if (Cast(sk))
  487. return;
  488. // If NPC with random coord in territory
  489. if (npc.getSpawn().getLocx() == 0 && npc.getSpawn().getLocy() == 0)
  490. {
  491. // Calculate a destination point in the spawn area
  492. int p[] = Territory.getInstance().getRandomPoint(npc.getSpawn().getLocation());
  493. x1 = p[0];
  494. y1 = p[1];
  495. z1 = p[2];
  496. // Calculate the distance between the current position of the L2Character and the target (x,y)
  497. double distance2 = _actor.getPlanDistanceSq(x1, y1);
  498. if (distance2 > (range + range) * (range + range))
  499. {
  500. npc.setisReturningToSpawnPoint(true);
  501. float delay = (float) Math.sqrt(distance2) / range;
  502. x1 = _actor.getX() + (int) ((x1 - _actor.getX()) / delay);
  503. y1 = _actor.getY() + (int) ((y1 - _actor.getY()) / delay);
  504. }
  505. // If NPC with random fixed coord, don't move (unless needs to return to spawnpoint)
  506. if (Territory.getInstance().getProcMax(npc.getSpawn().getLocation()) > 0 && !npc.isReturningToSpawnPoint())
  507. return;
  508. }
  509. else
  510. {
  511. // If NPC with fixed coord
  512. x1 = npc.getSpawn().getLocx();
  513. y1 = npc.getSpawn().getLocy();
  514. z1 = npc.getSpawn().getLocz();
  515. if (!_actor.isInsideRadius(x1, y1, z1, range + range, true, false))
  516. npc.setisReturningToSpawnPoint(true);
  517. else
  518. {
  519. x1 += Rnd.nextInt(range * 2) - range;
  520. y1 += Rnd.nextInt(range * 2) - range;
  521. z1 = npc.getZ();
  522. }
  523. }
  524. //_log.config("Curent pos ("+getX()+", "+getY()+"), moving to ("+x1+", "+y1+").");
  525. // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
  526. moveTo(x1, y1, z1);
  527. }
  528. }
  529. /**
  530. * Manage AI attack thinks of a L2Attackable (called by onEvtThink).<BR><BR>
  531. *
  532. * <B><U> Actions</U> :</B><BR><BR>
  533. * <li>Update the attack timeout if actor is running</li>
  534. * <li>If target is dead or timeout is expired, stop this attack and set the Intention to AI_INTENTION_ACTIVE</li>
  535. * <li>Call all L2Object of its Faction inside the Faction Range</li>
  536. * <li>Chose a target and order to attack it with magic skill or physical attack</li><BR><BR>
  537. *
  538. * TODO: Manage casting rules to healer mobs (like Ant Nurses)
  539. *
  540. */
  541. private void thinkAttack()
  542. {
  543. if (_attackTimeout < GameTimeController.getGameTicks())
  544. {
  545. // Check if the actor is running
  546. if (_actor.isRunning())
  547. {
  548. // Set the actor movement type to walk and send Server->Client packet ChangeMoveType to all others L2PcInstance
  549. _actor.setWalking();
  550. // Calculate a new attack timeout
  551. _attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks();
  552. }
  553. }
  554. if (_actor.isCastingNow())
  555. return;
  556. L2Character originalAttackTarget = getAttackTarget();
  557. // Check if target is dead or if timeout is expired to stop this attack
  558. if (originalAttackTarget == null || originalAttackTarget.isAlikeDead()
  559. || _attackTimeout < GameTimeController.getGameTicks())
  560. {
  561. // Stop hating this target after the attack timeout or if target is dead
  562. if (originalAttackTarget != null)
  563. ((L2Attackable) _actor).stopHating(originalAttackTarget);
  564. // Set the AI Intention to AI_INTENTION_ACTIVE
  565. setIntention(AI_INTENTION_ACTIVE);
  566. _actor.setWalking();
  567. return;
  568. }
  569. // Handle all L2Object of its Faction inside the Faction Range
  570. if (((L2Npc) _actor).getFactionId() != null)
  571. {
  572. String faction_id = ((L2Npc) _actor).getFactionId();
  573. // Go through all L2Object that belong to its faction
  574. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  575. //synchronized (_actor.getKnownList().getKnownObjects())
  576. try
  577. {
  578. for (L2Object obj : objs)
  579. {
  580. if (obj instanceof L2Npc)
  581. {
  582. L2Npc npc = (L2Npc) obj;
  583. //Handle SevenSigns mob Factions
  584. String npcfaction = npc.getFactionId();
  585. boolean sevenSignFaction = false;
  586. // TODO: Unhardcode this by AI scripts (DrHouse)
  587. //Catacomb mobs should assist lilim and nephilim other than dungeon
  588. if ("c_dungeon_clan".equals(faction_id) &&
  589. ("c_dungeon_lilim".equals(npcfaction) || "c_dungeon_nephi".equals(npcfaction)))
  590. sevenSignFaction = true;
  591. //Lilim mobs should assist other Lilim and catacomb mobs
  592. else if ("c_dungeon_lilim".equals(faction_id) &&
  593. "c_dungeon_clan".equals(npcfaction))
  594. sevenSignFaction = true;
  595. //Nephilim mobs should assist other Nephilim and catacomb mobs
  596. else if ("c_dungeon_nephi".equals(faction_id) &&
  597. "c_dungeon_clan".equals(npcfaction))
  598. sevenSignFaction = true;
  599. if (!faction_id.equals(npc.getFactionId()) && !sevenSignFaction)
  600. continue;
  601. // Check if the L2Object is inside the Faction Range of
  602. // the actor
  603. if (_actor.isInsideRadius(npc, npc.getFactionRange() + npc.getTemplate().collisionRadius, true, false) && npc.getAI() != null)
  604. {
  605. if (Math.abs(originalAttackTarget.getZ() - npc.getZ()) < 600 && _actor.getAttackByList().contains(originalAttackTarget)
  606. && (npc.getAI()._intention == CtrlIntention.AI_INTENTION_IDLE || npc.getAI()._intention == CtrlIntention.AI_INTENTION_ACTIVE) && GeoData.getInstance().canSeeTarget(_actor, npc))
  607. {
  608. if ((originalAttackTarget instanceof L2PcInstance) || (originalAttackTarget instanceof L2Summon))
  609. {
  610. if (npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_FACTION_CALL) != null)
  611. {
  612. L2PcInstance player = (originalAttackTarget instanceof L2PcInstance) ? (L2PcInstance) originalAttackTarget : ((L2Summon) originalAttackTarget).getOwner();
  613. for (Quest quest : npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_FACTION_CALL))
  614. quest.notifyFactionCall(npc, (L2Npc) _actor, player, (originalAttackTarget instanceof L2Summon));
  615. }
  616. }
  617. else if (npc instanceof L2Attackable && getAttackTarget() != null && npc.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
  618. {
  619. ((L2Attackable)npc).addDamageHate(getAttackTarget(), 0, ((L2Attackable)_actor).getHating(getAttackTarget()));
  620. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK,getAttackTarget());
  621. }
  622. }
  623. }
  624. }
  625. }
  626. }
  627. catch (NullPointerException e)
  628. {
  629. _log.info("L2AttackableAI: thinkAttack() faction call failed.");
  630. if (Config.DEBUG)
  631. e.printStackTrace();
  632. }
  633. }
  634. /*
  635. if(_actor.getTarget() == null || this.getAttackTarget() == null || this.getAttackTarget().isDead() || ctarget == _actor)
  636. AggroReconsider();
  637. */
  638. //----------------------------------------------------------------
  639. //------------------------------------------------------------------------------
  640. //Initialize data
  641. double dist = 0;
  642. int dist2 = 0;
  643. int range = 0;
  644. L2Character MostHate = ((L2Attackable) _actor).getMostHated();
  645. //L2Character ctarget = (L2Character)_actor.getTarget();
  646. try
  647. {
  648. setAttackTarget(MostHate);
  649. _actor.setTarget(MostHate);
  650. dist = Math.sqrt(_actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY()));
  651. dist2= (int) dist - _actor.getTemplate().collisionRadius;
  652. range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  653. if(getAttackTarget().isMoving())
  654. {
  655. range = range + 50;
  656. if(_actor.isMoving())
  657. range = range + 50;
  658. }
  659. }
  660. catch (NullPointerException e)
  661. {
  662. setIntention(AI_INTENTION_ACTIVE);
  663. return;
  664. }
  665. //------------------------------------------------------
  666. // In case many mobs are trying to hit from same place, move a bit,
  667. // circling around the target
  668. if (!_actor.isMovementDisabled() && Rnd.nextInt(100) <= 33) // check it once per 3 seconds
  669. {
  670. int combinedCollision = _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  671. int collision = _actor.getTemplate().collisionRadius;
  672. for (L2Object nearby : _actor.getKnownList().getKnownCharactersInRadius(collision))
  673. {
  674. if (nearby instanceof L2Attackable && nearby != getAttackTarget())
  675. {
  676. int diffx = Rnd.get(combinedCollision, combinedCollision+40);
  677. if (Rnd.get(10)<5) diffx = -diffx;
  678. int diffy = Rnd.get(combinedCollision, combinedCollision+40);
  679. if (Rnd.get(10)<5) diffy = -diffy;
  680. moveTo(getAttackTarget().getX() + diffx, getAttackTarget().getY() + diffy, getAttackTarget().getZ());
  681. return;
  682. }
  683. }
  684. }
  685. //Dodge if its needed
  686. if(!_actor.isMovementDisabled() && ((L2Attackable)_actor).getCanDodge()>0)
  687. if (Rnd.get(100) <= ((L2Attackable)_actor).getCanDodge())
  688. {
  689. // Micht: kepping this one otherwise we should do 2 sqrt
  690. double distance2 = _actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY());
  691. if (Math.sqrt(distance2) <= (60+_actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius))
  692. {
  693. //Diasable the RND for increasing the performance
  694. //int chance = 60;
  695. //if (chance >= Rnd.get(100))
  696. //{
  697. int posX = _actor.getX();
  698. int posY = _actor.getY();
  699. int posZ = _actor.getZ();
  700. /*
  701. if (Rnd.get(1)>0)
  702. posX=((L2Attackable)_actor).getSpawn().getLocx()+Rnd.get(100);
  703. else
  704. posX=((L2Attackable)_actor).getSpawn().getLocx()-Rnd.get(100);
  705. if (Rnd.get(1)>0)
  706. posY=((L2Attackable)_actor).getSpawn().getLocy() + Rnd.get(100);
  707. else
  708. posY=((L2Attackable)_actor).getSpawn().getLocy()-Rnd.get(100);
  709. setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  710. */
  711. if (Rnd.get(1)>0)
  712. posX=posX+Rnd.get(100);
  713. else
  714. posX=posX-Rnd.get(100);
  715. if (Rnd.get(1)>0)
  716. posY=posY + Rnd.get(100);
  717. else
  718. posY=posY - Rnd.get(100);
  719. setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  720. return;
  721. //}
  722. }
  723. }
  724. //------------------------------------------------------------------------------
  725. // BOSS/Raid Minion Target Reconsider
  726. if (_actor.isRaid() || _actor.isRaidMinion())
  727. {
  728. chaostime++;
  729. if (_actor instanceof L2RaidBossInstance && !((L2MonsterInstance)_actor).hasMinions())
  730. {
  731. if (chaostime > Config.RAID_CHAOS_TIME)
  732. if (Rnd.get(100) <= 100-(_actor.getCurrentHp()*100/_actor.getMaxHp()))
  733. {
  734. AggroReconsider();
  735. chaostime = 0;
  736. }
  737. }
  738. else if (_actor instanceof L2RaidBossInstance && ((L2MonsterInstance)_actor).hasMinions())
  739. {
  740. if (chaostime > Config.RAID_CHAOS_TIME)
  741. if (Rnd.get(100) <= 100-(_actor.getCurrentHp()*200/_actor.getMaxHp()))
  742. {
  743. AggroReconsider();
  744. chaostime = 0;
  745. }
  746. }
  747. else if(_actor instanceof L2GrandBossInstance)
  748. {
  749. if(chaostime > Config.GRAND_CHAOS_TIME)
  750. {
  751. double chaosRate = 100 - (_actor.getCurrentHp() * 300 / _actor.getMaxHp());
  752. if ((chaosRate <= 10 && Rnd.get(100) <= 10) || (chaosRate > 10 && Rnd.get(100)<= chaosRate))
  753. {
  754. AggroReconsider();
  755. chaostime = 0;
  756. }
  757. }
  758. }
  759. else
  760. {
  761. if(chaostime > Config.MINION_CHAOS_TIME)
  762. if(Rnd.get(100)<= 100-(_actor.getCurrentHp()*200/_actor.getMaxHp()))
  763. {
  764. AggroReconsider();
  765. chaostime = 0;
  766. }
  767. }
  768. }
  769. if(_skillrender.hasSkill())
  770. {
  771. //-------------------------------------------------------------------------------
  772. //Heal Condition
  773. if(_skillrender.hasHealSkill() && _skillrender._healskills !=null)
  774. {
  775. double percentage = _actor.getCurrentHp()/_actor.getMaxHp()*100;
  776. if(_actor instanceof L2MinionInstance)
  777. {
  778. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  779. if(leader != null && !leader.isDead() && Rnd.get(100) > (leader.getCurrentHp() / leader.getMaxHp() * 100))
  780. for(L2Skill sk:_skillrender._healskills)
  781. {
  782. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF)
  783. continue;
  784. if((sk.getMpConsume()>=_actor.getCurrentMp()
  785. || _actor.isSkillDisabled(sk)
  786. ||(sk.isMagic()&&_actor.isMuted())
  787. ||(!sk.isMagic()&&_actor.isPhysicalMuted())))
  788. {
  789. continue;
  790. }
  791. if(!Util.checkIfInRange((sk.getCastRange()+_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  792. && !isParty(sk) && !_actor.isMovementDisabled())
  793. {
  794. moveToPawn(leader,sk.getCastRange() +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  795. }
  796. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  797. {
  798. clientStopMoving(null);
  799. _actor.setTarget(leader);
  800. clientStopMoving(null);
  801. _actor.doCast(sk);
  802. return;
  803. }
  804. }
  805. }
  806. if(Rnd.get(100) < (100-percentage)/3)
  807. for(L2Skill sk:_skillrender._healskills)
  808. {
  809. if((sk.getMpConsume() >= _actor.getCurrentMp()
  810. || _actor.isSkillDisabled(sk)
  811. ||(sk.isMagic() && _actor.isMuted()))
  812. ||(!sk.isMagic() && _actor.isPhysicalMuted()))
  813. {
  814. continue;
  815. }
  816. clientStopMoving(null);
  817. _actor.setTarget(_actor);
  818. _actor.doCast(sk);
  819. return;
  820. }
  821. for(L2Skill sk:_skillrender._healskills)
  822. {
  823. if((sk.getMpConsume() >= _actor.getCurrentMp()
  824. || _actor.isSkillDisabled(sk)
  825. ||(sk.isMagic() && _actor.isMuted()))
  826. ||(!sk.isMagic() && _actor.isPhysicalMuted()))
  827. {
  828. continue;
  829. }
  830. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  831. for(L2Character obj: _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange() + _actor.getTemplate().collisionRadius))
  832. {
  833. if(!(obj instanceof L2Attackable) || obj.isDead())
  834. continue;
  835. L2Attackable targets = ((L2Attackable)obj);
  836. if(((L2Attackable)_actor).getFactionId() != targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  837. continue;
  838. percentage = targets.getCurrentHp()/targets.getMaxHp()*100;
  839. if(Rnd.get(100)< (100-percentage)/10)
  840. {
  841. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  842. {
  843. clientStopMoving(null);
  844. _actor.setTarget(obj);
  845. _actor.doCast(sk);
  846. return;
  847. }
  848. }
  849. }
  850. if(isParty(sk))
  851. {
  852. clientStopMoving(null);
  853. _actor.doCast(sk);
  854. return;
  855. }
  856. }
  857. }
  858. //-------------------------------------------------------------------------------
  859. //Res Skill Condition
  860. if(_skillrender.hasResSkill())
  861. {
  862. if(_actor instanceof L2MinionInstance)
  863. {
  864. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  865. if(leader != null && leader.isDead())
  866. for(L2Skill sk:_skillrender._resskills)
  867. {
  868. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF)
  869. continue;
  870. if((sk.getMpConsume() >= _actor.getCurrentMp()
  871. || _actor.isSkillDisabled(sk)
  872. ||(sk.isMagic() && _actor.isMuted())
  873. ||(!sk.isMagic() && _actor.isPhysicalMuted())))
  874. {
  875. continue;
  876. }
  877. if(!Util.checkIfInRange((sk.getCastRange()+_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  878. && !isParty(sk) && !_actor.isMovementDisabled())
  879. {
  880. moveToPawn(leader,sk.getCastRange()
  881. +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  882. }
  883. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  884. {
  885. clientStopMoving(null);
  886. _actor.setTarget(((L2MinionInstance)_actor).getLeader());
  887. _actor.doCast(sk);
  888. return;
  889. }
  890. }
  891. }
  892. for(L2Skill sk:_skillrender._resskills)
  893. {
  894. if((sk.getMpConsume() >= _actor.getCurrentMp()
  895. || _actor.isSkillDisabled(sk)
  896. ||(sk.isMagic() && _actor.isMuted()))
  897. ||(!sk.isMagic() && _actor.isPhysicalMuted()))
  898. {
  899. continue;
  900. }
  901. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  902. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange()+_actor.getTemplate().collisionRadius))
  903. {
  904. if(!(obj instanceof L2Attackable) || !obj.isDead())
  905. continue;
  906. L2Attackable targets = ((L2Attackable)obj);
  907. if(((L2Attackable)_actor).getFactionId() != targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  908. continue;
  909. if(Rnd.get(100) < 10)
  910. {
  911. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  912. {
  913. clientStopMoving(null);
  914. _actor.setTarget(obj);
  915. _actor.doCast(sk);
  916. return;
  917. }
  918. }
  919. }
  920. if(isParty(sk))
  921. {
  922. clientStopMoving(null);
  923. L2Object target = getAttackTarget();
  924. _actor.setTarget(_actor);
  925. _actor.doCast(sk);
  926. _actor.setTarget(target);
  927. return;
  928. }
  929. }
  930. }
  931. }
  932. //-------------------------------------------------------------------------------
  933. //Immobilize Condition
  934. if((_actor.isMovementDisabled() && (dist > range || getAttackTarget().isMoving()))
  935. ||(dist > range && getAttackTarget().isMoving()))
  936. {
  937. MovementDisable();
  938. return;
  939. }
  940. setTimepass(0);
  941. //--------------------------------------------------------------------------------
  942. //Skill Use
  943. if(_skillrender.hasSkill())
  944. {
  945. if(Rnd.get(100)<=((L2Npc)_actor).getSkillChance())
  946. {
  947. L2Skill skills = _skillrender._generalskills.get(Rnd.nextInt(_skillrender._generalskills.size()));
  948. if (Cast(skills))
  949. return;
  950. for(L2Skill sk:_skillrender._generalskills)
  951. if (Cast(sk))
  952. return;
  953. }
  954. //--------------------------------------------------------------------------------
  955. //Long/Short Range skill Usage
  956. if (((L2Npc)_actor).hasLSkill() || ((L2Npc)_actor).hasSSkill())
  957. {
  958. if (((L2Npc)_actor).hasSSkill() && dist2 <= 150 && Rnd.get(100) <= ((L2Npc)_actor).getSSkillChance())
  959. {
  960. SSkillRender();
  961. if (_skillrender._Srangeskills != null)
  962. {
  963. L2Skill skills = _skillrender._Srangeskills.get(Rnd.nextInt(_skillrender._Srangeskills.size()));
  964. if (Cast(skills))
  965. return;
  966. for(L2Skill sk : _skillrender._Srangeskills)
  967. if (Cast(sk))
  968. return;
  969. }
  970. }
  971. if (((L2Npc)_actor).hasLSkill() && dist2 > 150 && Rnd.get(100) <= ((L2Npc)_actor).getSSkillChance())
  972. {
  973. LSkillRender();
  974. if(_skillrender._Lrangeskills != null)
  975. {
  976. L2Skill skills = _skillrender._Lrangeskills.get(Rnd.nextInt(_skillrender._Lrangeskills.size()));
  977. if (Cast(skills))
  978. return;
  979. for(L2Skill sk : _skillrender._Lrangeskills)
  980. if (Cast(sk))
  981. return;
  982. }
  983. }
  984. }
  985. }
  986. //--------------------------------------------------------------------------------
  987. // Starts Melee or Primary Skill
  988. if(dist2>range || !GeoData.getInstance().canSeeTarget(_actor, getAttackTarget()))
  989. {
  990. if (_actor.isMovementDisabled())
  991. {
  992. TargetReconsider();
  993. return;
  994. }
  995. else
  996. {
  997. if(getAttackTarget().isMoving())
  998. range -= 100;
  999. if(range < 5)
  1000. range = 5;
  1001. moveToPawn(getAttackTarget(), range);
  1002. return;
  1003. }
  1004. }
  1005. else
  1006. {
  1007. Melee(((L2Npc)_actor).getPrimaryAttack());
  1008. }
  1009. }
  1010. private void Melee(int type)
  1011. {
  1012. if(type!=0)
  1013. {
  1014. switch(type)
  1015. {
  1016. case -1:
  1017. {
  1018. if(_skillrender._generalskills != null)
  1019. for(L2Skill sk : _skillrender._generalskills)
  1020. if (Cast(sk))
  1021. return;
  1022. break;
  1023. }
  1024. case 1:
  1025. {
  1026. if(_skillrender.hasAtkSkill())
  1027. for(L2Skill sk : _skillrender._atkskills)
  1028. if (Cast(sk))
  1029. return;
  1030. break;
  1031. }
  1032. default:
  1033. {
  1034. if(_skillrender._generalskills != null)
  1035. for(L2Skill sk : _skillrender._generalskills)
  1036. if(sk.getId() == ((L2Npc)_actor).getPrimaryAttack())
  1037. if (Cast(sk))
  1038. return;
  1039. }
  1040. break;
  1041. }
  1042. }
  1043. _accessor.doAttack(getAttackTarget());
  1044. }
  1045. private boolean Cast(L2Skill sk)
  1046. {
  1047. if (sk == null)
  1048. return false;
  1049. if (sk.getMpConsume() >= _actor.getCurrentMp() || _actor.isSkillDisabled(sk)
  1050. || (sk.isMagic() && _actor.isMuted()) || (!sk.isMagic() && _actor.isPhysicalMuted()))
  1051. return false;
  1052. if(getAttackTarget() == null)
  1053. if(((L2Attackable)_actor).getMostHated() != null)
  1054. setAttackTarget(((L2Attackable)_actor).getMostHated());
  1055. L2Character attackTarget = getAttackTarget();
  1056. if(attackTarget == null)
  1057. return false;
  1058. double dist = Math.sqrt(_actor.getPlanDistanceSq(attackTarget.getX(), attackTarget.getY()));
  1059. double dist2= dist - attackTarget.getTemplate().collisionRadius;
  1060. double range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + attackTarget.getTemplate().collisionRadius;
  1061. double srange = sk.getCastRange() + _actor.getTemplate().collisionRadius;
  1062. if(attackTarget.isMoving())
  1063. dist2 = dist2 - 30;
  1064. switch(sk.getSkillType())
  1065. {
  1066. case BUFF:
  1067. case REFLECT:
  1068. {
  1069. if (_actor.getFirstEffect(sk) == null)
  1070. {
  1071. clientStopMoving(null);
  1072. //L2Object target = attackTarget;
  1073. _actor.setTarget(_actor);
  1074. _actor.doCast(sk);
  1075. //_actor.setTarget(target);
  1076. return true;
  1077. }
  1078. //----------------------------------------
  1079. //If actor already have buff, start looking at others same faction mob to cast
  1080. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF)
  1081. return false;
  1082. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  1083. {
  1084. L2Character target = EffectTargetReconsider(sk,true);
  1085. if (target != null)
  1086. {
  1087. clientStopMoving(null);
  1088. L2Object targets = attackTarget;
  1089. _actor.setTarget(target);
  1090. _actor.doCast(sk);
  1091. _actor.setTarget(targets);
  1092. return true;
  1093. }
  1094. }
  1095. if(canParty(sk))
  1096. {
  1097. clientStopMoving(null);
  1098. L2Object targets = attackTarget;
  1099. _actor.setTarget(_actor);
  1100. _actor.doCast(sk);
  1101. _actor.setTarget(targets);
  1102. return true;
  1103. }
  1104. break;
  1105. }
  1106. case HEAL:
  1107. case HOT:
  1108. case HEAL_PERCENT:
  1109. case HEAL_STATIC:
  1110. case BALANCE_LIFE:
  1111. {
  1112. double percentage = _actor.getCurrentHp()/_actor.getMaxHp()*100;
  1113. if(_actor instanceof L2MinionInstance && sk.getTargetType() != L2Skill.SkillTargetType.TARGET_SELF)
  1114. {
  1115. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  1116. if(leader != null && !leader.isDead() && Rnd.get(100) > (leader.getCurrentHp()/leader.getMaxHp()*100))
  1117. {
  1118. if(!Util.checkIfInRange((sk.getCastRange() + _actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  1119. && !isParty(sk) && !_actor.isMovementDisabled())
  1120. {
  1121. moveToPawn(leader,sk.getCastRange() +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  1122. }
  1123. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  1124. {
  1125. clientStopMoving(null);
  1126. _actor.setTarget(leader);
  1127. _actor.doCast(sk);
  1128. return true;
  1129. }
  1130. }
  1131. }
  1132. if(Rnd.get(100) < (100-percentage)/3)
  1133. {
  1134. clientStopMoving(null);
  1135. _actor.setTarget(_actor);
  1136. _actor.doCast(sk);
  1137. return true;
  1138. }
  1139. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  1140. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange() + _actor.getTemplate().collisionRadius))
  1141. {
  1142. if(!(obj instanceof L2Attackable) || obj.isDead())
  1143. continue;
  1144. L2Attackable targets = ((L2Attackable)obj);
  1145. if(((L2Attackable)_actor).getFactionId() != targets.getFactionId()&&((L2Attackable)_actor).getFactionId() != null)
  1146. continue;
  1147. percentage = targets.getCurrentHp()/targets.getMaxHp()*100;
  1148. if(Rnd.get(100)< (100-percentage)/10)
  1149. {
  1150. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  1151. {
  1152. clientStopMoving(null);
  1153. _actor.setTarget(obj);
  1154. _actor.doCast(sk);
  1155. return true;
  1156. }
  1157. }
  1158. }
  1159. if(isParty(sk))
  1160. {
  1161. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius() + _actor.getTemplate().collisionRadius))
  1162. {
  1163. if(!(obj instanceof L2Attackable))
  1164. {
  1165. continue;
  1166. }
  1167. L2Npc targets = ((L2Npc)obj);
  1168. L2Npc actors = ((L2Npc)_actor);
  1169. if(actors.getFactionId() != null && targets.getFactionId().equals(actors.getFactionId()))
  1170. {
  1171. if(obj.getCurrentHp() < obj.getMaxHp() && Rnd.get(100) <= 20)
  1172. {
  1173. clientStopMoving(null);
  1174. _actor.setTarget(_actor);
  1175. _actor.doCast(sk);
  1176. return true;
  1177. }
  1178. }
  1179. }
  1180. }
  1181. break;
  1182. }
  1183. case RESURRECT:
  1184. {
  1185. if(!isParty(sk))
  1186. {
  1187. if(_actor instanceof L2MinionInstance && sk.getTargetType() != L2Skill.SkillTargetType.TARGET_SELF)
  1188. {
  1189. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  1190. if(leader != null && leader.isDead())
  1191. if(!Util.checkIfInRange((sk.getCastRange() + _actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  1192. && !isParty(sk) && !_actor.isMovementDisabled())
  1193. {
  1194. moveToPawn(leader,sk.getCastRange() +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  1195. }
  1196. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  1197. {
  1198. clientStopMoving(null);
  1199. _actor.setTarget(((L2MinionInstance)_actor).getLeader());
  1200. _actor.doCast(sk);
  1201. return true;
  1202. }
  1203. }
  1204. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange()+_actor.getTemplate().collisionRadius))
  1205. {
  1206. if(!(obj instanceof L2Attackable) || !obj.isDead())
  1207. continue;
  1208. L2Attackable targets = ((L2Attackable)obj);
  1209. if(((L2Attackable)_actor).getFactionId()!= targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  1210. continue;
  1211. if(Rnd.get(100)< 10)
  1212. {
  1213. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  1214. {
  1215. clientStopMoving(null);
  1216. _actor.setTarget(obj);
  1217. _actor.doCast(sk);
  1218. return true;
  1219. }
  1220. }
  1221. }
  1222. }
  1223. else if(isParty(sk))
  1224. {
  1225. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()+_actor.getTemplate().collisionRadius))
  1226. {
  1227. if(!(obj instanceof L2Attackable))
  1228. {
  1229. continue;
  1230. }
  1231. L2Npc targets = ((L2Npc)obj);
  1232. L2Npc actors = ((L2Npc)_actor);
  1233. if(actors.getFactionId() != null && actors.getFactionId().equals(targets.getFactionId()))
  1234. {
  1235. if(obj.getCurrentHp()<obj.getMaxHp() && Rnd.get(100)<=20)
  1236. {
  1237. clientStopMoving(null);
  1238. _actor.setTarget(_actor);
  1239. _actor.doCast(sk);
  1240. return true;
  1241. }
  1242. }
  1243. }
  1244. }
  1245. break;
  1246. }
  1247. case DEBUFF:
  1248. case WEAKNESS:
  1249. case POISON:
  1250. case DOT:
  1251. case MDOT:
  1252. case BLEED:
  1253. {
  1254. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget)
  1255. && !canAOE(sk) && !attackTarget.isDead() && dist2<=srange)
  1256. {
  1257. if (attackTarget.getFirstEffect(sk) == null)
  1258. {
  1259. clientStopMoving(null);
  1260. _actor.doCast(sk);
  1261. return true;
  1262. }
  1263. }
  1264. else if(canAOE(sk))
  1265. {
  1266. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1267. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1268. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1269. {
  1270. clientStopMoving(null);
  1271. //L2Object target = attackTarget;
  1272. //_actor.setTarget(_actor);
  1273. _actor.doCast(sk);
  1274. //_actor.setTarget(target);
  1275. return true;
  1276. }
  1277. if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1278. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1279. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1280. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1281. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1282. {
  1283. clientStopMoving(null);
  1284. _actor.doCast(sk);
  1285. return true;
  1286. }
  1287. }
  1288. else if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1289. {
  1290. L2Character target = EffectTargetReconsider(sk,false);
  1291. if (target != null)
  1292. {
  1293. clientStopMoving(null);
  1294. _actor.doCast(sk);
  1295. return true;
  1296. }
  1297. }
  1298. break;
  1299. }
  1300. case SLEEP:
  1301. {
  1302. if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1303. {
  1304. if(attackTarget != null && !attackTarget.isDead() && dist2<=srange)
  1305. {
  1306. if(dist2>range || attackTarget.isMoving())
  1307. {
  1308. if (attackTarget.getFirstEffect(sk) == null)
  1309. {
  1310. clientStopMoving(null);
  1311. //_actor.setTarget(attackTarget);
  1312. _actor.doCast(sk);
  1313. return true;
  1314. }
  1315. }
  1316. }
  1317. L2Character target = EffectTargetReconsider(sk,false);
  1318. if (target != null)
  1319. {
  1320. clientStopMoving(null);
  1321. _actor.doCast(sk);
  1322. return true;
  1323. }
  1324. }
  1325. else if(canAOE(sk))
  1326. {
  1327. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1328. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1329. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1330. {
  1331. clientStopMoving(null);
  1332. //L2Object target = attackTarget;
  1333. //_actor.setTarget(_actor);
  1334. _actor.doCast(sk);
  1335. //_actor.setTarget(target);
  1336. return true;
  1337. }
  1338. if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1339. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1340. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1341. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1342. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1343. {
  1344. clientStopMoving(null);
  1345. _actor.doCast(sk);
  1346. return true;
  1347. }
  1348. }
  1349. break;
  1350. }
  1351. case ROOT:
  1352. case STUN:
  1353. case PARALYZE:
  1354. {
  1355. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !canAOE(sk) && dist2<=srange)
  1356. {
  1357. if (attackTarget.getFirstEffect(sk) == null)
  1358. {
  1359. clientStopMoving(null);
  1360. _actor.doCast(sk);
  1361. return true;
  1362. }
  1363. }
  1364. else if(canAOE(sk))
  1365. {
  1366. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1367. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1368. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1369. {
  1370. clientStopMoving(null);
  1371. //L2Object target = attackTarget;
  1372. //_actor.setTarget(_actor);
  1373. _actor.doCast(sk);
  1374. //_actor.setTarget(target);
  1375. return true;
  1376. }
  1377. else if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1378. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1379. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1380. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1381. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1382. {
  1383. clientStopMoving(null);
  1384. _actor.doCast(sk);
  1385. return true;
  1386. }
  1387. }
  1388. else if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1389. {
  1390. L2Character target = EffectTargetReconsider(sk,false);
  1391. if (target != null)
  1392. {
  1393. clientStopMoving(null);
  1394. _actor.doCast(sk);
  1395. return true;
  1396. }
  1397. }
  1398. break;
  1399. }
  1400. case MUTE:
  1401. case FEAR:
  1402. {
  1403. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !canAOE(sk) && dist2<=srange)
  1404. {
  1405. if (attackTarget.getFirstEffect(sk) == null)
  1406. {
  1407. clientStopMoving(null);
  1408. _actor.doCast(sk);
  1409. return true;
  1410. }
  1411. }
  1412. else if(canAOE(sk))
  1413. {
  1414. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1415. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1416. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1417. {
  1418. clientStopMoving(null);
  1419. //L2Object target = attackTarget;
  1420. //_actor.setTarget(_actor);
  1421. _actor.doCast(sk);
  1422. //_actor.setTarget(target);
  1423. return true;
  1424. }
  1425. if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1426. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1427. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1428. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1429. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1430. {
  1431. clientStopMoving(null);
  1432. _actor.doCast(sk);
  1433. return true;
  1434. }
  1435. }
  1436. else if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1437. {
  1438. L2Character target = EffectTargetReconsider(sk,false);
  1439. if (target != null)
  1440. {
  1441. clientStopMoving(null);
  1442. _actor.doCast(sk);
  1443. return true;
  1444. }
  1445. }
  1446. break;
  1447. }
  1448. case CANCEL:
  1449. case NEGATE:
  1450. {
  1451. if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1452. {
  1453. if(attackTarget.getFirstEffect(L2EffectType.BUFF) != null
  1454. && GeoData.getInstance().canSeeTarget(_actor,attackTarget)
  1455. && !attackTarget.isDead()
  1456. && dist2<=srange)
  1457. {
  1458. clientStopMoving(null);
  1459. //L2Object target = attackTarget;
  1460. //_actor.setTarget(_actor);
  1461. _actor.doCast(sk);
  1462. //_actor.setTarget(target);
  1463. return true;
  1464. }
  1465. L2Character target = EffectTargetReconsider(sk,false);
  1466. if (target != null)
  1467. {
  1468. clientStopMoving(null);
  1469. L2Object targets = attackTarget;
  1470. _actor.setTarget(target);
  1471. _actor.doCast(sk);
  1472. _actor.setTarget(targets);
  1473. return true;
  1474. }
  1475. }
  1476. else if(canAOE(sk))
  1477. {
  1478. if((sk.getTargetType() == SkillTargetType.TARGET_AURA
  1479. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1480. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1481. && GeoData.getInstance().canSeeTarget(_actor,attackTarget))
  1482. {
  1483. clientStopMoving(null);
  1484. //L2Object target = attackTarget;
  1485. //_actor.setTarget(_actor);
  1486. _actor.doCast(sk);
  1487. //_actor.setTarget(target);
  1488. return true;
  1489. }
  1490. else if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1491. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1492. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1493. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1494. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1495. {
  1496. clientStopMoving(null);
  1497. _actor.doCast(sk);
  1498. return true;
  1499. }
  1500. }
  1501. break;
  1502. }
  1503. case PDAM:
  1504. case MDAM:
  1505. case BLOW:
  1506. case DRAIN:
  1507. case CHARGEDAM:
  1508. case DEATHLINK:
  1509. case CPDAM:
  1510. case MANADAM:
  1511. {
  1512. if(!canAura(sk))
  1513. {
  1514. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1515. {
  1516. clientStopMoving(null);
  1517. _actor.doCast(sk);
  1518. return true;
  1519. }
  1520. else
  1521. {
  1522. L2Character target = SkillTargetReconsider(sk);
  1523. if (target != null)
  1524. {
  1525. clientStopMoving(null);
  1526. L2Object targets = attackTarget;
  1527. _actor.setTarget(target);
  1528. _actor.doCast(sk);
  1529. _actor.setTarget(targets);
  1530. return true;
  1531. }
  1532. }
  1533. }
  1534. else
  1535. {
  1536. clientStopMoving(null);
  1537. _actor.doCast(sk);
  1538. return true;
  1539. }
  1540. break;
  1541. }
  1542. default :
  1543. {
  1544. if(!canAura(sk))
  1545. {
  1546. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1547. {
  1548. clientStopMoving(null);
  1549. _actor.doCast(sk);
  1550. return true;
  1551. }
  1552. else
  1553. {
  1554. L2Character target = SkillTargetReconsider(sk);
  1555. if (target != null)
  1556. {
  1557. clientStopMoving(null);
  1558. L2Object targets = attackTarget;
  1559. _actor.setTarget(target);
  1560. _actor.doCast(sk);
  1561. _actor.setTarget(targets);
  1562. return true;
  1563. }
  1564. }
  1565. }
  1566. else
  1567. {
  1568. clientStopMoving(null);
  1569. //L2Object targets = attackTarget;
  1570. //_actor.setTarget(_actor);
  1571. _actor.doCast(sk);
  1572. //_actor.setTarget(targets);
  1573. return true;
  1574. }
  1575. }
  1576. break;
  1577. }
  1578. return false;
  1579. }
  1580. /**
  1581. * This AI task will start when ACTOR cannot move and attack range larger than distance
  1582. */
  1583. private void MovementDisable()
  1584. {
  1585. double dist = 0;
  1586. double dist2 = 0;
  1587. int range = 0;
  1588. try
  1589. {
  1590. if(_actor.getTarget() == null)
  1591. _actor.setTarget(getAttackTarget());
  1592. dist = Math.sqrt(_actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY()));
  1593. dist2= dist - _actor.getTemplate().collisionRadius;
  1594. range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1595. if(getAttackTarget().isMoving())
  1596. {
  1597. dist = dist -30;
  1598. if(_actor.isMoving())
  1599. dist = dist -50;
  1600. }
  1601. }
  1602. catch (NullPointerException e)
  1603. {
  1604. setIntention(AI_INTENTION_ACTIVE);
  1605. return;
  1606. }
  1607. //Check if activeChar has any skill
  1608. if(_skillrender.hasSkill())
  1609. {
  1610. //-------------------------------------------------------------
  1611. //Try to stop the target or disable the target as priority
  1612. int random = Rnd.get(100);
  1613. if (_skillrender.hasImmobiliseSkill() && !getAttackTarget().isImmobilized() && random < 2)
  1614. {
  1615. for(L2Skill sk : _skillrender._immobiliseskills)
  1616. {
  1617. if(sk.getMpConsume() >= _actor.getCurrentMp()
  1618. || _actor.isSkillDisabled(sk)
  1619. || (sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1620. || (sk.isMagic()&&_actor.isMuted())
  1621. || (!sk.isMagic()&&_actor.isPhysicalMuted()))
  1622. {
  1623. continue;
  1624. }
  1625. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1626. continue;
  1627. if (getAttackTarget().getFirstEffect(sk) == null)
  1628. {
  1629. clientStopMoving(null);
  1630. //L2Object target = getAttackTarget();
  1631. //_actor.setTarget(_actor);
  1632. _actor.doCast(sk);
  1633. //_actor.setTarget(target);
  1634. return;
  1635. }
  1636. }
  1637. }
  1638. //-------------------------------------------------------------
  1639. //Same as Above, but with Mute/FEAR etc....
  1640. if(_skillrender.hasCOTSkill() && random < 5)
  1641. {
  1642. for(L2Skill sk:_skillrender._cotskills)
  1643. {
  1644. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1645. || _actor.isSkillDisabled(sk)
  1646. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1647. ||(sk.isMagic()&&_actor.isMuted())
  1648. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1649. {
  1650. continue;
  1651. }
  1652. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1653. continue;
  1654. if (getAttackTarget().getFirstEffect(sk) == null)
  1655. {
  1656. clientStopMoving(null);
  1657. //L2Object target = getAttackTarget();
  1658. //_actor.setTarget(_actor);
  1659. _actor.doCast(sk);
  1660. //_actor.setTarget(target);
  1661. return;
  1662. }
  1663. }
  1664. }
  1665. //-------------------------------------------------------------
  1666. if(_skillrender.hasDebuffSkill() && random < 8)
  1667. {
  1668. for(L2Skill sk:_skillrender._debuffskills)
  1669. {
  1670. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1671. || _actor.isSkillDisabled(sk)
  1672. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1673. ||(sk.isMagic()&&_actor.isMuted())
  1674. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1675. {
  1676. continue;
  1677. }
  1678. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1679. continue;
  1680. if (getAttackTarget().getFirstEffect(sk) == null)
  1681. {
  1682. clientStopMoving(null);
  1683. //L2Object target = getAttackTarget();
  1684. //_actor.setTarget(_actor);
  1685. _actor.doCast(sk);
  1686. //_actor.setTarget(target);
  1687. return;
  1688. }
  1689. }
  1690. }
  1691. //-------------------------------------------------------------
  1692. //Some side effect skill like CANCEL or NEGATE
  1693. if(_skillrender.hasNegativeSkill() && random < 9)
  1694. {
  1695. for(L2Skill sk : _skillrender._negativeskills)
  1696. {
  1697. if(sk.getMpConsume() >= _actor.getCurrentMp()
  1698. || _actor.isSkillDisabled(sk)
  1699. ||(sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1700. ||(sk.isMagic()&&_actor.isMuted())
  1701. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1702. {
  1703. continue;
  1704. }
  1705. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1706. continue;
  1707. if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  1708. {
  1709. clientStopMoving(null);
  1710. //L2Object target = getAttackTarget();
  1711. //_actor.setTarget(_actor);
  1712. _actor.doCast(sk);
  1713. //_actor.setTarget(target);
  1714. return;
  1715. }
  1716. }
  1717. }
  1718. //-------------------------------------------------------------
  1719. //Start ATK SKILL when nothing can be done
  1720. if(_skillrender.hasAtkSkill())
  1721. {
  1722. for(L2Skill sk:_skillrender._atkskills)
  1723. {
  1724. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1725. || _actor.isSkillDisabled(sk)
  1726. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1727. ||(sk.isMagic()&&_actor.isMuted())
  1728. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1729. {
  1730. continue;
  1731. }
  1732. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1733. continue;
  1734. clientStopMoving(null);
  1735. //L2Object target = getAttackTarget();
  1736. //_actor.setTarget(_actor);
  1737. _actor.doCast(sk);
  1738. //_actor.setTarget(target);
  1739. return;
  1740. }
  1741. }
  1742. //-------------------------------------------------------------
  1743. //if there is no ATK skill to use, then try Universal skill
  1744. /*
  1745. if(_skillrender.hasUniversalSkill())
  1746. {
  1747. for(L2Skill sk:_skillrender._universalskills)
  1748. {
  1749. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1750. || _actor.isSkillDisabled(sk.getId())
  1751. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1752. ||(sk.isMagic()&&_actor.isMuted())
  1753. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1754. {
  1755. continue;
  1756. }
  1757. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1758. continue;
  1759. clientStopMoving(null);
  1760. L2Object target = getAttackTarget();
  1761. //_actor.setTarget(_actor);
  1762. _actor.doCast(sk);
  1763. //_actor.setTarget(target);
  1764. return;
  1765. }
  1766. }
  1767. */
  1768. }
  1769. //timepass = timepass + 1;
  1770. if (_actor.isMovementDisabled())
  1771. {
  1772. //timepass = 0;
  1773. TargetReconsider();
  1774. return;
  1775. }
  1776. //else if(timepass>=5)
  1777. //{
  1778. // timepass = 0;
  1779. // AggroReconsider();
  1780. // return;
  1781. //}
  1782. if(dist>range || !GeoData.getInstance().canSeeTarget(_actor, getAttackTarget()))
  1783. {
  1784. if(getAttackTarget().isMoving())
  1785. range -=100;if(range<5)range=5;
  1786. moveToPawn(getAttackTarget(), range);
  1787. return;
  1788. }
  1789. Melee(((L2Npc)_actor).getPrimaryAttack());
  1790. return;
  1791. }
  1792. private L2Character EffectTargetReconsider(L2Skill sk, boolean positive)
  1793. {
  1794. if (sk == null)
  1795. return null;
  1796. if(sk.getSkillType() != L2SkillType.NEGATE || sk.getSkillType() != L2SkillType.CANCEL )
  1797. {
  1798. if(!positive)
  1799. {
  1800. double dist = 0;
  1801. double dist2 = 0;
  1802. int range = 0;
  1803. L2Attackable actor = (L2Attackable)_actor;
  1804. if(actor.getAttackByList() != null)
  1805. for(L2Character obj: actor.getAttackByList())
  1806. {
  1807. if(obj == null || obj.isDead() || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj == getAttackTarget())
  1808. continue;
  1809. try
  1810. {
  1811. _actor.setTarget(getAttackTarget());
  1812. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1813. dist2= dist - _actor.getTemplate().collisionRadius;
  1814. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1815. if(obj.isMoving())
  1816. dist2 = dist2 - 70;
  1817. }
  1818. catch (NullPointerException e)
  1819. {
  1820. continue;
  1821. }
  1822. if(dist2<=range)
  1823. {
  1824. if (getAttackTarget().getFirstEffect(sk) == null)
  1825. return obj;
  1826. }
  1827. }
  1828. //----------------------------------------------------------------------
  1829. //If there is nearby Target with aggro, start going on random target that is attackable
  1830. for (L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(range))
  1831. {
  1832. if(obj.isDead() || obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj))
  1833. continue;
  1834. try
  1835. {
  1836. _actor.setTarget(getAttackTarget());
  1837. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1838. dist2= dist;
  1839. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1840. if(obj.isMoving())
  1841. dist2 = dist2 - 70;
  1842. }
  1843. catch (NullPointerException e)
  1844. {
  1845. continue;
  1846. }
  1847. if(obj instanceof L2Attackable)
  1848. {
  1849. if(((L2Attackable)_actor).getEnemyClan() != null && ((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan()))
  1850. {
  1851. if(dist2<=range)
  1852. {
  1853. if (getAttackTarget().getFirstEffect(sk) == null)
  1854. return obj;
  1855. }
  1856. }
  1857. }
  1858. if(obj instanceof L2PcInstance || obj instanceof L2Summon)
  1859. {
  1860. if(dist2<=range)
  1861. {
  1862. if (getAttackTarget().getFirstEffect(sk) == null)
  1863. return obj;
  1864. }
  1865. }
  1866. }
  1867. }
  1868. else if (positive)
  1869. {
  1870. double dist = 0;
  1871. double dist2 = 0;
  1872. int range = 0;
  1873. for(L2Character obj: _actor.getKnownList().getKnownCharactersInRadius(range))
  1874. {
  1875. if(!(obj instanceof L2Attackable) || obj.isDead() || obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj))
  1876. continue;
  1877. L2Attackable targets = ((L2Attackable)obj);
  1878. if(((L2Attackable)_actor).getFactionId()!= targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  1879. continue;
  1880. try
  1881. {
  1882. _actor.setTarget(getAttackTarget());
  1883. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1884. dist2= dist - _actor.getTemplate().collisionRadius;
  1885. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1886. if(obj.isMoving())
  1887. dist2 = dist2 - 70;
  1888. }
  1889. catch (NullPointerException e)
  1890. {
  1891. continue;
  1892. }
  1893. if(dist2<=range)
  1894. {
  1895. if (obj.getFirstEffect(sk) == null)
  1896. return obj;
  1897. }
  1898. }
  1899. }
  1900. return null;
  1901. }
  1902. else
  1903. {
  1904. double dist = 0;
  1905. double dist2 = 0;
  1906. int range = 0;
  1907. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1908. for (L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(range))
  1909. {
  1910. if(obj == null || obj.isDead() || !GeoData.getInstance().canSeeTarget(_actor,obj))
  1911. continue;
  1912. try
  1913. {
  1914. _actor.setTarget(getAttackTarget());
  1915. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1916. dist2= dist - _actor.getTemplate().collisionRadius;
  1917. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1918. if(obj.isMoving())
  1919. dist2 = dist2 - 70;
  1920. }
  1921. catch (NullPointerException e)
  1922. {
  1923. continue;
  1924. }
  1925. if(obj instanceof L2Attackable)
  1926. {
  1927. if(((L2Attackable)_actor).getEnemyClan() != null && ((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan()))
  1928. {
  1929. if(dist2<=range)
  1930. {
  1931. if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  1932. return obj;
  1933. }
  1934. }
  1935. }
  1936. if(obj instanceof L2PcInstance || obj instanceof L2Summon)
  1937. {
  1938. if(dist2<=range)
  1939. {
  1940. if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  1941. return obj;
  1942. }
  1943. }
  1944. }
  1945. return null;
  1946. }
  1947. }
  1948. private L2Character SkillTargetReconsider(L2Skill sk)
  1949. {
  1950. double dist = 0;
  1951. double dist2 = 0;
  1952. int range = 0;
  1953. L2Attackable actor = (L2Attackable)_actor;
  1954. if(actor.getHateList()!=null)
  1955. for(L2Character obj: actor.getHateList())
  1956. {
  1957. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead())
  1958. continue;
  1959. try
  1960. {
  1961. _actor.setTarget(getAttackTarget());
  1962. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1963. dist2= dist - _actor.getTemplate().collisionRadius;
  1964. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1965. //if(obj.isMoving())
  1966. // dist2 = dist2 - 40;
  1967. }
  1968. catch (NullPointerException e)
  1969. {
  1970. continue;
  1971. }
  1972. if(dist2<=range)
  1973. {
  1974. return obj;
  1975. }
  1976. }
  1977. if(!(_actor instanceof L2GuardInstance))
  1978. {
  1979. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  1980. for (L2Object target : objs)
  1981. {
  1982. try
  1983. {
  1984. _actor.setTarget(getAttackTarget());
  1985. dist = Math.sqrt(_actor.getPlanDistanceSq(target.getX(), target.getY()));
  1986. dist2= dist;
  1987. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1988. //if(obj.isMoving())
  1989. // dist2 = dist2 - 40;
  1990. }
  1991. catch (NullPointerException e)
  1992. {
  1993. continue;
  1994. }
  1995. L2Character obj = null;
  1996. if (target instanceof L2Character)
  1997. obj = (L2Character)target;
  1998. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || dist2 > range)
  1999. continue;
  2000. if(obj instanceof L2PcInstance)
  2001. {
  2002. return obj;
  2003. }
  2004. if(obj instanceof L2Attackable)
  2005. {
  2006. if(((L2Attackable)_actor).getEnemyClan() != null && ((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan()))
  2007. {
  2008. return obj;
  2009. }
  2010. if (((L2Attackable)_actor).getIsChaos() != 0)
  2011. {
  2012. if(((L2Attackable)obj).getFactionId() != null && ((L2Attackable)obj).getFactionId().equals(((L2Attackable)_actor).getFactionId()))
  2013. continue;
  2014. else
  2015. return obj;
  2016. }
  2017. }
  2018. if(obj instanceof L2Summon)
  2019. {
  2020. return obj;
  2021. }
  2022. }
  2023. }
  2024. return null;
  2025. }
  2026. private void TargetReconsider()
  2027. {
  2028. double dist = 0;
  2029. double dist2 = 0;
  2030. int range = 0;
  2031. L2Attackable actor = (L2Attackable)_actor;
  2032. L2Character MostHate = ((L2Attackable) _actor).getMostHated();
  2033. if(actor.getHateList()!=null)
  2034. for(L2Character obj : actor.getHateList())
  2035. {
  2036. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead() || obj!= MostHate || obj == _actor)
  2037. continue;
  2038. try
  2039. {
  2040. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  2041. dist2= dist - _actor.getTemplate().collisionRadius;
  2042. range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  2043. if(obj.isMoving())
  2044. dist2 = dist2 - 70;
  2045. }
  2046. catch (NullPointerException e)
  2047. {
  2048. continue;
  2049. }
  2050. if(dist2<=range)
  2051. {
  2052. if(MostHate!=null)
  2053. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2054. else
  2055. actor.addDamageHate(obj,2000,2000);
  2056. _actor.setTarget(obj);
  2057. setAttackTarget(obj);
  2058. return;
  2059. }
  2060. }
  2061. if(!(_actor instanceof L2GuardInstance))
  2062. {
  2063. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  2064. for (L2Object target : objs)
  2065. {
  2066. L2Character obj = null;
  2067. if (target instanceof L2Character)
  2068. obj = (L2Character)target;
  2069. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead() || obj!= MostHate || obj == _actor || obj == getAttackTarget())
  2070. continue;
  2071. if(obj instanceof L2PcInstance)
  2072. {
  2073. if(MostHate != null)
  2074. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2075. else
  2076. actor.addDamageHate(obj,2000,2000);
  2077. _actor.setTarget(obj);
  2078. setAttackTarget(obj);
  2079. }
  2080. else if(obj instanceof L2Attackable)
  2081. {
  2082. if(((L2Attackable)_actor).getEnemyClan() != null && ((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan()))
  2083. {
  2084. actor.addDamageHate(obj,0,actor.getHating(MostHate));
  2085. _actor.setTarget(obj);
  2086. }
  2087. if (((L2Attackable)_actor).getIsChaos() != 0)
  2088. {
  2089. if(((L2Attackable)obj).getFactionId() != null && ((L2Attackable)obj).getFactionId().equals(((L2Attackable)_actor).getFactionId()))
  2090. continue;
  2091. else
  2092. {
  2093. if(MostHate != null)
  2094. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2095. else
  2096. actor.addDamageHate(obj,2000,2000);
  2097. _actor.setTarget(obj);
  2098. setAttackTarget(obj);
  2099. }
  2100. }
  2101. }
  2102. else if(obj instanceof L2Summon)
  2103. {
  2104. if(MostHate != null)
  2105. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2106. else
  2107. actor.addDamageHate(obj,2000,2000);
  2108. _actor.setTarget(obj);
  2109. setAttackTarget(obj);
  2110. }
  2111. }
  2112. }
  2113. }
  2114. @SuppressWarnings("null")
  2115. private void AggroReconsider()
  2116. {
  2117. L2Attackable actor = (L2Attackable)_actor;
  2118. L2Character MostHate = ((L2Attackable) _actor).getMostHated();
  2119. if(actor.getHateList() != null)
  2120. {
  2121. int rand = Rnd.get(actor.getHateList().size());
  2122. int count = 0;
  2123. for(L2Character obj: actor.getHateList())
  2124. {
  2125. if(count < rand)
  2126. {
  2127. count++;
  2128. continue;
  2129. }
  2130. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead()|| obj == getAttackTarget() || obj == actor)
  2131. continue;
  2132. try
  2133. {
  2134. _actor.setTarget(getAttackTarget());
  2135. }
  2136. catch (NullPointerException e)
  2137. {
  2138. continue;
  2139. }
  2140. if(MostHate!=null)
  2141. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2142. else
  2143. actor.addDamageHate(obj,2000,2000);
  2144. _actor.setTarget(obj);
  2145. setAttackTarget(obj);
  2146. return;
  2147. }
  2148. }
  2149. if(!(_actor instanceof L2GuardInstance))
  2150. {
  2151. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  2152. for (L2Object target : objs)
  2153. {
  2154. L2Character obj = null;
  2155. if(target instanceof L2Character)
  2156. obj = (L2Character)target;
  2157. else
  2158. continue;
  2159. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead() || obj != MostHate || obj == _actor)
  2160. continue;
  2161. if(obj instanceof L2PcInstance)
  2162. {
  2163. if(MostHate!=null || !MostHate.isDead())
  2164. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2165. else
  2166. actor.addDamageHate(obj,2000,2000);
  2167. _actor.setTarget(obj);
  2168. setAttackTarget(obj);
  2169. }
  2170. else if(obj instanceof L2Attackable)
  2171. {
  2172. if(((L2Attackable)_actor).getEnemyClan() != null && (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan())))
  2173. {
  2174. if(MostHate != null)
  2175. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2176. else
  2177. actor.addDamageHate(obj,2000,2000);
  2178. _actor.setTarget(obj);
  2179. }
  2180. if (((L2Attackable)_actor).getIsChaos() != 0)
  2181. {
  2182. if(((L2Attackable)obj).getFactionId() != null && ((L2Attackable)obj).getFactionId().equals(((L2Attackable)_actor).getFactionId()))
  2183. continue;
  2184. else
  2185. {
  2186. if(MostHate != null)
  2187. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2188. else
  2189. actor.addDamageHate(obj,2000,2000);
  2190. _actor.setTarget(obj);
  2191. setAttackTarget(obj);
  2192. }
  2193. }
  2194. }
  2195. else if(obj instanceof L2Summon)
  2196. {
  2197. if(MostHate != null)
  2198. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2199. else
  2200. actor.addDamageHate(obj,2000,2000);
  2201. _actor.setTarget(obj);
  2202. setAttackTarget(obj);
  2203. }
  2204. }
  2205. }
  2206. }
  2207. private void LSkillRender()
  2208. {
  2209. if(_skillrender._Lrangeskills == null)
  2210. _skillrender._Lrangeskills = ((L2Npc)_actor).getLrangeSkill();
  2211. }
  2212. private void SSkillRender()
  2213. {
  2214. if(_skillrender._Srangeskills == null)
  2215. _skillrender._Srangeskills = ((L2Npc)_actor).getSrangeSkill();
  2216. }
  2217. /**
  2218. * Manage AI thinking actions of a L2Attackable.<BR><BR>
  2219. */
  2220. @Override
  2221. protected void onEvtThink()
  2222. {
  2223. // Check if the actor can't use skills and if a thinking action isn't already in progress
  2224. if (_thinking || _actor.isAllSkillsDisabled()) return;
  2225. // Start thinking action
  2226. _thinking = true;
  2227. try
  2228. {
  2229. // Manage AI thinks of a L2Attackable
  2230. if (getIntention() == AI_INTENTION_ACTIVE) thinkActive();
  2231. else if (getIntention() == AI_INTENTION_ATTACK) thinkAttack();
  2232. }
  2233. finally
  2234. {
  2235. // Stop thinking action
  2236. _thinking = false;
  2237. }
  2238. }
  2239. /**
  2240. * Launch actions corresponding to the Event Attacked.<BR><BR>
  2241. *
  2242. * <B><U> Actions</U> :</B><BR><BR>
  2243. * <li>Init the attack : Calculate the attack timeout, Set the _globalAggro to 0, Add the attacker to the actor _aggroList</li>
  2244. * <li>Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance</li>
  2245. * <li>Set the Intention to AI_INTENTION_ATTACK</li><BR><BR>
  2246. *
  2247. * @param attacker The L2Character that attacks the actor
  2248. *
  2249. */
  2250. @Override
  2251. protected void onEvtAttacked(L2Character attacker)
  2252. {
  2253. //if (_actor instanceof L2ChestInstance && !((L2ChestInstance)_actor).isInteracted())
  2254. //{
  2255. //((L2ChestInstance)_actor).deleteMe();
  2256. //((L2ChestInstance)_actor).getSpawn().startRespawn();
  2257. //return;
  2258. //}
  2259. // Calculate the attack timeout
  2260. _attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks();
  2261. // Set the _globalAggro to 0 to permit attack even just after spawn
  2262. if (_globalAggro < 0) _globalAggro = 0;
  2263. // Add the attacker to the _aggroList of the actor
  2264. ((L2Attackable) _actor).addDamageHate(attacker, 0, 1);
  2265. // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  2266. if (!_actor.isRunning()) _actor.setRunning();
  2267. // Set the Intention to AI_INTENTION_ATTACK
  2268. if (getIntention() != AI_INTENTION_ATTACK)
  2269. {
  2270. setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  2271. }
  2272. else if (((L2Attackable) _actor).getMostHated() != getAttackTarget())
  2273. {
  2274. setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  2275. }
  2276. super.onEvtAttacked(attacker);
  2277. }
  2278. /**
  2279. * Launch actions corresponding to the Event Aggression.<BR><BR>
  2280. *
  2281. * <B><U> Actions</U> :</B><BR><BR>
  2282. * <li>Add the target to the actor _aggroList or update hate if already present </li>
  2283. * <li>Set the actor Intention to AI_INTENTION_ATTACK (if actor is L2GuardInstance check if it isn't too far from its home location)</li><BR><BR>
  2284. *
  2285. * @param attacker The L2Character that attacks
  2286. * @param aggro The value of hate to add to the actor against the target
  2287. *
  2288. */
  2289. @Override
  2290. protected void onEvtAggression(L2Character target, int aggro)
  2291. {
  2292. L2Attackable me = (L2Attackable) _actor;
  2293. if (target != null)
  2294. {
  2295. // Add the target to the actor _aggroList or update hate if already present
  2296. me.addDamageHate(target, 0, aggro);
  2297. // Set the actor AI Intention to AI_INTENTION_ATTACK
  2298. if (getIntention() != CtrlIntention.AI_INTENTION_ATTACK)
  2299. {
  2300. // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  2301. if (!_actor.isRunning()) _actor.setRunning();
  2302. setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  2303. }
  2304. }
  2305. }
  2306. @Override
  2307. protected void onIntentionActive()
  2308. {
  2309. // Cancel attack timeout
  2310. _attackTimeout = Integer.MAX_VALUE;
  2311. super.onIntentionActive();
  2312. }
  2313. public void setGlobalAggro(int value)
  2314. {
  2315. _globalAggro = value;
  2316. }
  2317. /**
  2318. * @param timepass The timepass to set.
  2319. */
  2320. public void setTimepass(int TP)
  2321. {
  2322. this.timepass = TP;
  2323. }
  2324. /**
  2325. * @return Returns the timepass.
  2326. */
  2327. public int getTimepass()
  2328. {
  2329. return timepass;
  2330. }
  2331. }