L2AttackableAI.java 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527
  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. // Chance to forget attackers after some time
  437. if (_actor.getCurrentHp() == _actor.getMaxHp()
  438. && _actor.getCurrentMp() == _actor.getMaxMp()
  439. && !_actor.getAttackByList().isEmpty()
  440. && Rnd.nextInt(500) == 0)
  441. {
  442. ((L2Attackable)_actor).clearAggroList();
  443. _actor.getAttackByList().clear();
  444. }
  445. // Check if the actor is a L2GuardInstance
  446. if (_actor instanceof L2GuardInstance)
  447. {
  448. // Order to the L2GuardInstance to return to its home location because there's no target to attack
  449. ((L2GuardInstance) _actor).returnHome();
  450. }
  451. // If this is a festival monster, then it remains in the same location.
  452. if (_actor instanceof L2FestivalMonsterInstance)
  453. return;
  454. // Check if the mob should not return to spawn point
  455. if (!npc.canReturnToSpawnPoint())
  456. return;
  457. // Minions following leader
  458. if (_actor instanceof L2MinionInstance && ((L2MinionInstance) _actor).getLeader() != null)
  459. {
  460. final int offset;
  461. final int minRadius = 30;
  462. if (_actor.isRaidMinion())
  463. offset = 500; // for Raids - need correction
  464. else
  465. offset = 200; // for normal minions - need correction :)
  466. if (((L2MinionInstance) _actor).getLeader().isRunning())
  467. _actor.setRunning();
  468. else
  469. _actor.setWalking();
  470. if (_actor.getPlanDistanceSq(((L2MinionInstance) _actor).getLeader()) > offset * offset)
  471. {
  472. int x1, y1, z1;
  473. x1 = Rnd.get(minRadius * 2, offset * 2); // x
  474. y1 = Rnd.get(x1, offset * 2); // distance
  475. y1 = (int)Math.sqrt(y1*y1 - x1*x1); // y
  476. if (x1 > offset + minRadius)
  477. x1 = ((L2MinionInstance) _actor).getLeader().getX() + x1 - offset;
  478. else
  479. x1 = ((L2MinionInstance) _actor).getLeader().getX() - x1 + minRadius;
  480. if (y1 > offset + minRadius)
  481. y1 = ((L2MinionInstance) _actor).getLeader().getY() + y1 - offset;
  482. else
  483. y1 = ((L2MinionInstance) _actor).getLeader().getY() - y1 + minRadius;
  484. z1 = ((L2MinionInstance) _actor).getLeader().getZ();
  485. // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
  486. moveTo(x1, y1, z1);
  487. return;
  488. }
  489. else if (Rnd.nextInt(RANDOM_WALK_RATE) == 0)
  490. {
  491. if(_skillrender.hasBuffSkill())
  492. for (L2Skill sk : _skillrender._buffskills)
  493. if (Cast(sk))
  494. return;
  495. }
  496. }
  497. // Order to the L2MonsterInstance to random walk (1/100)
  498. else if (npc.getSpawn() != null && Rnd.nextInt(RANDOM_WALK_RATE) == 0
  499. && !_actor.isNoRndWalk())
  500. {
  501. int x1, y1, z1;
  502. final int range = Config.MAX_DRIFT_RANGE;
  503. if(_skillrender.hasBuffSkill())
  504. for (L2Skill sk : _skillrender._buffskills)
  505. if (Cast(sk))
  506. return;
  507. // If NPC with random coord in territory
  508. if (npc.getSpawn().getLocx() == 0 && npc.getSpawn().getLocy() == 0)
  509. {
  510. // Calculate a destination point in the spawn area
  511. int p[] = Territory.getInstance().getRandomPoint(npc.getSpawn().getLocation());
  512. x1 = p[0];
  513. y1 = p[1];
  514. z1 = p[2];
  515. // Calculate the distance between the current position of the L2Character and the target (x,y)
  516. double distance2 = _actor.getPlanDistanceSq(x1, y1);
  517. if (distance2 > (range + range) * (range + range))
  518. {
  519. npc.setisReturningToSpawnPoint(true);
  520. float delay = (float) Math.sqrt(distance2) / range;
  521. x1 = _actor.getX() + (int) ((x1 - _actor.getX()) / delay);
  522. y1 = _actor.getY() + (int) ((y1 - _actor.getY()) / delay);
  523. }
  524. // If NPC with random fixed coord, don't move (unless needs to return to spawnpoint)
  525. if (Territory.getInstance().getProcMax(npc.getSpawn().getLocation()) > 0 && !npc.isReturningToSpawnPoint())
  526. return;
  527. }
  528. else
  529. {
  530. // If NPC with fixed coord
  531. x1 = npc.getSpawn().getLocx();
  532. y1 = npc.getSpawn().getLocy();
  533. z1 = npc.getSpawn().getLocz();
  534. if (!_actor.isInsideRadius(x1, y1, range, false))
  535. npc.setisReturningToSpawnPoint(true);
  536. else
  537. {
  538. x1 = Rnd.nextInt(range * 2); // x
  539. y1 = Rnd.get(x1, range * 2); // distance
  540. y1 = (int)Math.sqrt(y1*y1 - x1*x1); // y
  541. x1 += npc.getSpawn().getLocx() - range;
  542. y1 += npc.getSpawn().getLocy() - range;
  543. z1 = npc.getZ();
  544. }
  545. }
  546. //_log.config("Curent pos ("+getX()+", "+getY()+"), moving to ("+x1+", "+y1+").");
  547. // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
  548. moveTo(x1, y1, z1);
  549. }
  550. }
  551. /**
  552. * Manage AI attack thinks of a L2Attackable (called by onEvtThink).<BR><BR>
  553. *
  554. * <B><U> Actions</U> :</B><BR><BR>
  555. * <li>Update the attack timeout if actor is running</li>
  556. * <li>If target is dead or timeout is expired, stop this attack and set the Intention to AI_INTENTION_ACTIVE</li>
  557. * <li>Call all L2Object of its Faction inside the Faction Range</li>
  558. * <li>Chose a target and order to attack it with magic skill or physical attack</li><BR><BR>
  559. *
  560. * TODO: Manage casting rules to healer mobs (like Ant Nurses)
  561. *
  562. */
  563. private void thinkAttack()
  564. {
  565. if (_attackTimeout < GameTimeController.getGameTicks())
  566. {
  567. // Check if the actor is running
  568. if (_actor.isRunning())
  569. {
  570. // Set the actor movement type to walk and send Server->Client packet ChangeMoveType to all others L2PcInstance
  571. _actor.setWalking();
  572. // Calculate a new attack timeout
  573. _attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks();
  574. }
  575. }
  576. if (_actor.isCastingNow())
  577. return;
  578. L2Character originalAttackTarget = getAttackTarget();
  579. // Check if target is dead or if timeout is expired to stop this attack
  580. if (originalAttackTarget == null || originalAttackTarget.isAlikeDead()
  581. || _attackTimeout < GameTimeController.getGameTicks())
  582. {
  583. // Stop hating this target after the attack timeout or if target is dead
  584. if (originalAttackTarget != null)
  585. ((L2Attackable) _actor).stopHating(originalAttackTarget);
  586. // Set the AI Intention to AI_INTENTION_ACTIVE
  587. setIntention(AI_INTENTION_ACTIVE);
  588. _actor.setWalking();
  589. return;
  590. }
  591. // Handle all L2Object of its Faction inside the Faction Range
  592. if (((L2Npc) _actor).getFactionId() != null)
  593. {
  594. String faction_id = ((L2Npc) _actor).getFactionId();
  595. // Go through all L2Object that belong to its faction
  596. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  597. //synchronized (_actor.getKnownList().getKnownObjects())
  598. try
  599. {
  600. for (L2Object obj : objs)
  601. {
  602. if (obj instanceof L2Npc)
  603. {
  604. L2Npc npc = (L2Npc) obj;
  605. //Handle SevenSigns mob Factions
  606. String npcfaction = npc.getFactionId();
  607. boolean sevenSignFaction = false;
  608. // TODO: Unhardcode this by AI scripts (DrHouse)
  609. //Catacomb mobs should assist lilim and nephilim other than dungeon
  610. if ("c_dungeon_clan".equals(faction_id) &&
  611. ("c_dungeon_lilim".equals(npcfaction) || "c_dungeon_nephi".equals(npcfaction)))
  612. sevenSignFaction = true;
  613. //Lilim mobs should assist other Lilim and catacomb mobs
  614. else if ("c_dungeon_lilim".equals(faction_id) &&
  615. "c_dungeon_clan".equals(npcfaction))
  616. sevenSignFaction = true;
  617. //Nephilim mobs should assist other Nephilim and catacomb mobs
  618. else if ("c_dungeon_nephi".equals(faction_id) &&
  619. "c_dungeon_clan".equals(npcfaction))
  620. sevenSignFaction = true;
  621. if (!faction_id.equals(npc.getFactionId()) && !sevenSignFaction)
  622. continue;
  623. // Check if the L2Object is inside the Faction Range of
  624. // the actor
  625. if (_actor.isInsideRadius(npc, npc.getFactionRange() + npc.getTemplate().collisionRadius, true, false) && npc.getAI() != null)
  626. {
  627. if (Math.abs(originalAttackTarget.getZ() - npc.getZ()) < 600 && _actor.getAttackByList().contains(originalAttackTarget)
  628. && (npc.getAI()._intention == CtrlIntention.AI_INTENTION_IDLE || npc.getAI()._intention == CtrlIntention.AI_INTENTION_ACTIVE) && GeoData.getInstance().canSeeTarget(_actor, npc))
  629. {
  630. if ((originalAttackTarget instanceof L2PcInstance) || (originalAttackTarget instanceof L2Summon))
  631. {
  632. if (npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_FACTION_CALL) != null)
  633. {
  634. L2PcInstance player = (originalAttackTarget instanceof L2PcInstance) ? (L2PcInstance) originalAttackTarget : ((L2Summon) originalAttackTarget).getOwner();
  635. for (Quest quest : npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_FACTION_CALL))
  636. quest.notifyFactionCall(npc, (L2Npc) _actor, player, (originalAttackTarget instanceof L2Summon));
  637. }
  638. }
  639. else if (npc instanceof L2Attackable && getAttackTarget() != null && npc.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
  640. {
  641. ((L2Attackable)npc).addDamageHate(getAttackTarget(), 0, ((L2Attackable)_actor).getHating(getAttackTarget()));
  642. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK,getAttackTarget());
  643. }
  644. }
  645. }
  646. }
  647. }
  648. }
  649. catch (NullPointerException e)
  650. {
  651. _log.info("L2AttackableAI: thinkAttack() faction call failed.");
  652. if (Config.DEBUG)
  653. e.printStackTrace();
  654. }
  655. }
  656. /*
  657. if(_actor.getTarget() == null || this.getAttackTarget() == null || this.getAttackTarget().isDead() || ctarget == _actor)
  658. AggroReconsider();
  659. */
  660. //----------------------------------------------------------------
  661. //------------------------------------------------------------------------------
  662. //Initialize data
  663. double dist = 0;
  664. int dist2 = 0;
  665. int range = 0;
  666. L2Character mostHate = ((L2Attackable) _actor).getMostHated();
  667. if (mostHate == null)
  668. {
  669. setIntention(AI_INTENTION_ACTIVE);
  670. return;
  671. }
  672. setAttackTarget(mostHate);
  673. _actor.setTarget(mostHate);
  674. dist = Math.sqrt(_actor.getPlanDistanceSq(mostHate.getX(), mostHate.getY()));
  675. dist2= (int) dist - _actor.getTemplate().collisionRadius;
  676. range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + mostHate.getTemplate().collisionRadius;
  677. if(mostHate.isMoving())
  678. {
  679. range = range + 50;
  680. if(_actor.isMoving())
  681. range = range + 50;
  682. }
  683. //------------------------------------------------------
  684. // In case many mobs are trying to hit from same place, move a bit,
  685. // circling around the target
  686. if (!_actor.isMovementDisabled() && Rnd.nextInt(100) <= 33) // check it once per 3 seconds
  687. {
  688. int combinedCollision = _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  689. int collision = _actor.getTemplate().collisionRadius;
  690. for (L2Object nearby : _actor.getKnownList().getKnownCharactersInRadius(collision))
  691. {
  692. if (nearby instanceof L2Attackable && nearby != getAttackTarget())
  693. {
  694. int diffx = Rnd.get(combinedCollision, combinedCollision+40);
  695. if (Rnd.get(10)<5) diffx = -diffx;
  696. int diffy = Rnd.get(combinedCollision, combinedCollision+40);
  697. if (Rnd.get(10)<5) diffy = -diffy;
  698. moveTo(getAttackTarget().getX() + diffx, getAttackTarget().getY() + diffy, getAttackTarget().getZ());
  699. return;
  700. }
  701. }
  702. }
  703. //Dodge if its needed
  704. if(!_actor.isMovementDisabled() && ((L2Attackable)_actor).getCanDodge()>0)
  705. if (Rnd.get(100) <= ((L2Attackable)_actor).getCanDodge())
  706. {
  707. // Micht: kepping this one otherwise we should do 2 sqrt
  708. double distance2 = _actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY());
  709. if (Math.sqrt(distance2) <= (60+_actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius))
  710. {
  711. //Diasable the RND for increasing the performance
  712. //int chance = 60;
  713. //if (chance >= Rnd.get(100))
  714. //{
  715. int posX = _actor.getX();
  716. int posY = _actor.getY();
  717. int posZ = _actor.getZ();
  718. /*
  719. if (Rnd.get(1)>0)
  720. posX=((L2Attackable)_actor).getSpawn().getLocx()+Rnd.get(100);
  721. else
  722. posX=((L2Attackable)_actor).getSpawn().getLocx()-Rnd.get(100);
  723. if (Rnd.get(1)>0)
  724. posY=((L2Attackable)_actor).getSpawn().getLocy() + Rnd.get(100);
  725. else
  726. posY=((L2Attackable)_actor).getSpawn().getLocy()-Rnd.get(100);
  727. setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  728. */
  729. if (Rnd.get(1)>0)
  730. posX=posX+Rnd.get(100);
  731. else
  732. posX=posX-Rnd.get(100);
  733. if (Rnd.get(1)>0)
  734. posY=posY + Rnd.get(100);
  735. else
  736. posY=posY - Rnd.get(100);
  737. if (Config.GEODATA == 0 || GeoData.getInstance().canMoveFromToTarget(_actor.getX(), _actor.getY(), posZ, posX, posY, posZ, _actor.getInstanceId()))
  738. setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  739. return;
  740. //}
  741. }
  742. }
  743. //------------------------------------------------------------------------------
  744. // BOSS/Raid Minion Target Reconsider
  745. if (_actor.isRaid() || _actor.isRaidMinion())
  746. {
  747. chaostime++;
  748. if (_actor instanceof L2RaidBossInstance && !((L2MonsterInstance)_actor).hasMinions())
  749. {
  750. if (chaostime > Config.RAID_CHAOS_TIME)
  751. if (Rnd.get(100) <= 100-(_actor.getCurrentHp()*100/_actor.getMaxHp()))
  752. {
  753. AggroReconsider();
  754. chaostime = 0;
  755. }
  756. }
  757. else if (_actor instanceof L2RaidBossInstance && ((L2MonsterInstance)_actor).hasMinions())
  758. {
  759. if (chaostime > Config.RAID_CHAOS_TIME)
  760. if (Rnd.get(100) <= 100-(_actor.getCurrentHp()*200/_actor.getMaxHp()))
  761. {
  762. AggroReconsider();
  763. chaostime = 0;
  764. }
  765. }
  766. else if(_actor instanceof L2GrandBossInstance)
  767. {
  768. if(chaostime > Config.GRAND_CHAOS_TIME)
  769. {
  770. double chaosRate = 100 - (_actor.getCurrentHp() * 300 / _actor.getMaxHp());
  771. if ((chaosRate <= 10 && Rnd.get(100) <= 10) || (chaosRate > 10 && Rnd.get(100)<= chaosRate))
  772. {
  773. AggroReconsider();
  774. chaostime = 0;
  775. }
  776. }
  777. }
  778. else
  779. {
  780. if(chaostime > Config.MINION_CHAOS_TIME)
  781. if(Rnd.get(100)<= 100-(_actor.getCurrentHp()*200/_actor.getMaxHp()))
  782. {
  783. AggroReconsider();
  784. chaostime = 0;
  785. }
  786. }
  787. }
  788. if(_skillrender.hasSkill())
  789. {
  790. //-------------------------------------------------------------------------------
  791. //Heal Condition
  792. if(_skillrender.hasHealSkill() && _skillrender._healskills !=null)
  793. {
  794. double percentage = _actor.getCurrentHp()/_actor.getMaxHp()*100;
  795. if(_actor instanceof L2MinionInstance)
  796. {
  797. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  798. if(leader != null && !leader.isDead() && Rnd.get(100) > (leader.getCurrentHp() / leader.getMaxHp() * 100))
  799. for(L2Skill sk:_skillrender._healskills)
  800. {
  801. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF)
  802. continue;
  803. if((sk.getMpConsume()>=_actor.getCurrentMp()
  804. || _actor.isSkillDisabled(sk)
  805. ||(sk.isMagic()&&_actor.isMuted())
  806. ||(!sk.isMagic()&&_actor.isPhysicalMuted())))
  807. {
  808. continue;
  809. }
  810. if(!Util.checkIfInRange((sk.getCastRange()+_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  811. && !isParty(sk) && !_actor.isMovementDisabled())
  812. {
  813. moveToPawn(leader,sk.getCastRange() +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  814. }
  815. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  816. {
  817. clientStopMoving(null);
  818. _actor.setTarget(leader);
  819. clientStopMoving(null);
  820. _actor.doCast(sk);
  821. return;
  822. }
  823. }
  824. }
  825. if(Rnd.get(100) < (100-percentage)/3)
  826. for(L2Skill sk:_skillrender._healskills)
  827. {
  828. if((sk.getMpConsume() >= _actor.getCurrentMp()
  829. || _actor.isSkillDisabled(sk)
  830. ||(sk.isMagic() && _actor.isMuted()))
  831. ||(!sk.isMagic() && _actor.isPhysicalMuted()))
  832. {
  833. continue;
  834. }
  835. clientStopMoving(null);
  836. _actor.setTarget(_actor);
  837. _actor.doCast(sk);
  838. return;
  839. }
  840. for(L2Skill sk:_skillrender._healskills)
  841. {
  842. if((sk.getMpConsume() >= _actor.getCurrentMp()
  843. || _actor.isSkillDisabled(sk)
  844. ||(sk.isMagic() && _actor.isMuted()))
  845. ||(!sk.isMagic() && _actor.isPhysicalMuted()))
  846. {
  847. continue;
  848. }
  849. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  850. for(L2Character obj: _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange() + _actor.getTemplate().collisionRadius))
  851. {
  852. if(!(obj instanceof L2Attackable) || obj.isDead())
  853. continue;
  854. L2Attackable targets = ((L2Attackable)obj);
  855. if(((L2Attackable)_actor).getFactionId() != targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  856. continue;
  857. percentage = targets.getCurrentHp()/targets.getMaxHp()*100;
  858. if(Rnd.get(100)< (100-percentage)/10)
  859. {
  860. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  861. {
  862. clientStopMoving(null);
  863. _actor.setTarget(obj);
  864. _actor.doCast(sk);
  865. return;
  866. }
  867. }
  868. }
  869. if(isParty(sk))
  870. {
  871. clientStopMoving(null);
  872. _actor.doCast(sk);
  873. return;
  874. }
  875. }
  876. }
  877. //-------------------------------------------------------------------------------
  878. //Res Skill Condition
  879. if(_skillrender.hasResSkill())
  880. {
  881. if(_actor instanceof L2MinionInstance)
  882. {
  883. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  884. if(leader != null && leader.isDead())
  885. for(L2Skill sk:_skillrender._resskills)
  886. {
  887. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF)
  888. continue;
  889. if((sk.getMpConsume() >= _actor.getCurrentMp()
  890. || _actor.isSkillDisabled(sk)
  891. ||(sk.isMagic() && _actor.isMuted())
  892. ||(!sk.isMagic() && _actor.isPhysicalMuted())))
  893. {
  894. continue;
  895. }
  896. if(!Util.checkIfInRange((sk.getCastRange()+_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  897. && !isParty(sk) && !_actor.isMovementDisabled())
  898. {
  899. moveToPawn(leader,sk.getCastRange()
  900. +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  901. }
  902. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  903. {
  904. clientStopMoving(null);
  905. _actor.setTarget(((L2MinionInstance)_actor).getLeader());
  906. _actor.doCast(sk);
  907. return;
  908. }
  909. }
  910. }
  911. for(L2Skill sk:_skillrender._resskills)
  912. {
  913. if((sk.getMpConsume() >= _actor.getCurrentMp()
  914. || _actor.isSkillDisabled(sk)
  915. ||(sk.isMagic() && _actor.isMuted()))
  916. ||(!sk.isMagic() && _actor.isPhysicalMuted()))
  917. {
  918. continue;
  919. }
  920. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  921. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange()+_actor.getTemplate().collisionRadius))
  922. {
  923. if(!(obj instanceof L2Attackable) || !obj.isDead())
  924. continue;
  925. L2Attackable targets = ((L2Attackable)obj);
  926. if(((L2Attackable)_actor).getFactionId() != targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  927. continue;
  928. if(Rnd.get(100) < 10)
  929. {
  930. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  931. {
  932. clientStopMoving(null);
  933. _actor.setTarget(obj);
  934. _actor.doCast(sk);
  935. return;
  936. }
  937. }
  938. }
  939. if(isParty(sk))
  940. {
  941. clientStopMoving(null);
  942. L2Object target = getAttackTarget();
  943. _actor.setTarget(_actor);
  944. _actor.doCast(sk);
  945. _actor.setTarget(target);
  946. return;
  947. }
  948. }
  949. }
  950. }
  951. //-------------------------------------------------------------------------------
  952. //Immobilize Condition
  953. if((_actor.isMovementDisabled() && (dist > range || getAttackTarget().isMoving()))
  954. ||(dist > range && getAttackTarget().isMoving()))
  955. {
  956. MovementDisable();
  957. return;
  958. }
  959. setTimepass(0);
  960. //--------------------------------------------------------------------------------
  961. //Skill Use
  962. if(_skillrender.hasSkill())
  963. {
  964. if(Rnd.get(100)<=((L2Npc)_actor).getSkillChance())
  965. {
  966. L2Skill skills = _skillrender._generalskills.get(Rnd.nextInt(_skillrender._generalskills.size()));
  967. if (Cast(skills))
  968. return;
  969. for(L2Skill sk:_skillrender._generalskills)
  970. if (Cast(sk))
  971. return;
  972. }
  973. //--------------------------------------------------------------------------------
  974. //Long/Short Range skill Usage
  975. if (((L2Npc)_actor).hasLSkill() || ((L2Npc)_actor).hasSSkill())
  976. {
  977. if (((L2Npc)_actor).hasSSkill() && dist2 <= 150 && Rnd.get(100) <= ((L2Npc)_actor).getSSkillChance())
  978. {
  979. SSkillRender();
  980. if (_skillrender._Srangeskills != null)
  981. {
  982. L2Skill skills = _skillrender._Srangeskills.get(Rnd.nextInt(_skillrender._Srangeskills.size()));
  983. if (Cast(skills))
  984. return;
  985. for(L2Skill sk : _skillrender._Srangeskills)
  986. if (Cast(sk))
  987. return;
  988. }
  989. }
  990. if (((L2Npc)_actor).hasLSkill() && dist2 > 150 && Rnd.get(100) <= ((L2Npc)_actor).getSSkillChance())
  991. {
  992. LSkillRender();
  993. if(_skillrender._Lrangeskills != null)
  994. {
  995. L2Skill skills = _skillrender._Lrangeskills.get(Rnd.nextInt(_skillrender._Lrangeskills.size()));
  996. if (Cast(skills))
  997. return;
  998. for(L2Skill sk : _skillrender._Lrangeskills)
  999. if (Cast(sk))
  1000. return;
  1001. }
  1002. }
  1003. }
  1004. }
  1005. //--------------------------------------------------------------------------------
  1006. // Starts Melee or Primary Skill
  1007. if(dist2>range || !GeoData.getInstance().canSeeTarget(_actor, getAttackTarget()))
  1008. {
  1009. if (_actor.isMovementDisabled())
  1010. {
  1011. TargetReconsider();
  1012. return;
  1013. }
  1014. else
  1015. {
  1016. if(getAttackTarget().isMoving())
  1017. range -= 100;
  1018. if(range < 5)
  1019. range = 5;
  1020. moveToPawn(getAttackTarget(), range);
  1021. return;
  1022. }
  1023. }
  1024. else
  1025. {
  1026. Melee(((L2Npc)_actor).getPrimaryAttack());
  1027. }
  1028. }
  1029. private void Melee(int type)
  1030. {
  1031. if(type!=0)
  1032. {
  1033. switch(type)
  1034. {
  1035. case -1:
  1036. {
  1037. if(_skillrender._generalskills != null)
  1038. for(L2Skill sk : _skillrender._generalskills)
  1039. if (Cast(sk))
  1040. return;
  1041. break;
  1042. }
  1043. case 1:
  1044. {
  1045. if(_skillrender.hasAtkSkill())
  1046. for(L2Skill sk : _skillrender._atkskills)
  1047. if (Cast(sk))
  1048. return;
  1049. break;
  1050. }
  1051. default:
  1052. {
  1053. if(_skillrender._generalskills != null)
  1054. for(L2Skill sk : _skillrender._generalskills)
  1055. if(sk.getId() == ((L2Npc)_actor).getPrimaryAttack())
  1056. if (Cast(sk))
  1057. return;
  1058. }
  1059. break;
  1060. }
  1061. }
  1062. _accessor.doAttack(getAttackTarget());
  1063. }
  1064. private boolean Cast(L2Skill sk)
  1065. {
  1066. if (sk == null)
  1067. return false;
  1068. if (sk.getMpConsume() >= _actor.getCurrentMp() || _actor.isSkillDisabled(sk)
  1069. || (sk.isMagic() && _actor.isMuted()) || (!sk.isMagic() && _actor.isPhysicalMuted()))
  1070. return false;
  1071. if(getAttackTarget() == null)
  1072. if(((L2Attackable)_actor).getMostHated() != null)
  1073. setAttackTarget(((L2Attackable)_actor).getMostHated());
  1074. L2Character attackTarget = getAttackTarget();
  1075. if(attackTarget == null)
  1076. return false;
  1077. double dist = Math.sqrt(_actor.getPlanDistanceSq(attackTarget.getX(), attackTarget.getY()));
  1078. double dist2= dist - attackTarget.getTemplate().collisionRadius;
  1079. double range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + attackTarget.getTemplate().collisionRadius;
  1080. double srange = sk.getCastRange() + _actor.getTemplate().collisionRadius;
  1081. if(attackTarget.isMoving())
  1082. dist2 = dist2 - 30;
  1083. switch(sk.getSkillType())
  1084. {
  1085. case BUFF:
  1086. case REFLECT:
  1087. {
  1088. if (_actor.getFirstEffect(sk) == null)
  1089. {
  1090. clientStopMoving(null);
  1091. //L2Object target = attackTarget;
  1092. _actor.setTarget(_actor);
  1093. _actor.doCast(sk);
  1094. //_actor.setTarget(target);
  1095. return true;
  1096. }
  1097. //----------------------------------------
  1098. //If actor already have buff, start looking at others same faction mob to cast
  1099. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF)
  1100. return false;
  1101. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  1102. {
  1103. L2Character target = EffectTargetReconsider(sk,true);
  1104. if (target != null)
  1105. {
  1106. clientStopMoving(null);
  1107. L2Object targets = attackTarget;
  1108. _actor.setTarget(target);
  1109. _actor.doCast(sk);
  1110. _actor.setTarget(targets);
  1111. return true;
  1112. }
  1113. }
  1114. if(canParty(sk))
  1115. {
  1116. clientStopMoving(null);
  1117. L2Object targets = attackTarget;
  1118. _actor.setTarget(_actor);
  1119. _actor.doCast(sk);
  1120. _actor.setTarget(targets);
  1121. return true;
  1122. }
  1123. break;
  1124. }
  1125. case HEAL:
  1126. case HOT:
  1127. case HEAL_PERCENT:
  1128. case HEAL_STATIC:
  1129. case BALANCE_LIFE:
  1130. {
  1131. double percentage = _actor.getCurrentHp()/_actor.getMaxHp()*100;
  1132. if(_actor instanceof L2MinionInstance && sk.getTargetType() != L2Skill.SkillTargetType.TARGET_SELF)
  1133. {
  1134. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  1135. if(leader != null && !leader.isDead() && Rnd.get(100) > (leader.getCurrentHp()/leader.getMaxHp()*100))
  1136. {
  1137. if(!Util.checkIfInRange((sk.getCastRange() + _actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  1138. && !isParty(sk) && !_actor.isMovementDisabled())
  1139. {
  1140. moveToPawn(leader,sk.getCastRange() +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  1141. }
  1142. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  1143. {
  1144. clientStopMoving(null);
  1145. _actor.setTarget(leader);
  1146. _actor.doCast(sk);
  1147. return true;
  1148. }
  1149. }
  1150. }
  1151. if(Rnd.get(100) < (100-percentage)/3)
  1152. {
  1153. clientStopMoving(null);
  1154. _actor.setTarget(_actor);
  1155. _actor.doCast(sk);
  1156. return true;
  1157. }
  1158. if(sk.getTargetType() == L2Skill.SkillTargetType.TARGET_ONE)
  1159. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange() + _actor.getTemplate().collisionRadius))
  1160. {
  1161. if(!(obj instanceof L2Attackable) || obj.isDead())
  1162. continue;
  1163. L2Attackable targets = ((L2Attackable)obj);
  1164. if(((L2Attackable)_actor).getFactionId() != targets.getFactionId()&&((L2Attackable)_actor).getFactionId() != null)
  1165. continue;
  1166. percentage = targets.getCurrentHp()/targets.getMaxHp()*100;
  1167. if(Rnd.get(100)< (100-percentage)/10)
  1168. {
  1169. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  1170. {
  1171. clientStopMoving(null);
  1172. _actor.setTarget(obj);
  1173. _actor.doCast(sk);
  1174. return true;
  1175. }
  1176. }
  1177. }
  1178. if(isParty(sk))
  1179. {
  1180. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius() + _actor.getTemplate().collisionRadius))
  1181. {
  1182. if(!(obj instanceof L2Attackable))
  1183. {
  1184. continue;
  1185. }
  1186. L2Npc targets = ((L2Npc)obj);
  1187. L2Npc actors = ((L2Npc)_actor);
  1188. if(actors.getFactionId() != null && targets.getFactionId().equals(actors.getFactionId()))
  1189. {
  1190. if(obj.getCurrentHp() < obj.getMaxHp() && Rnd.get(100) <= 20)
  1191. {
  1192. clientStopMoving(null);
  1193. _actor.setTarget(_actor);
  1194. _actor.doCast(sk);
  1195. return true;
  1196. }
  1197. }
  1198. }
  1199. }
  1200. break;
  1201. }
  1202. case RESURRECT:
  1203. {
  1204. if(!isParty(sk))
  1205. {
  1206. if(_actor instanceof L2MinionInstance && sk.getTargetType() != L2Skill.SkillTargetType.TARGET_SELF)
  1207. {
  1208. L2Character leader = ((L2MinionInstance)_actor).getLeader();
  1209. if(leader != null && leader.isDead())
  1210. if(!Util.checkIfInRange((sk.getCastRange() + _actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius),_actor,leader,false)
  1211. && !isParty(sk) && !_actor.isMovementDisabled())
  1212. {
  1213. moveToPawn(leader,sk.getCastRange() +_actor.getTemplate().collisionRadius + leader.getTemplate().collisionRadius);
  1214. }
  1215. if(GeoData.getInstance().canSeeTarget(_actor,leader))
  1216. {
  1217. clientStopMoving(null);
  1218. _actor.setTarget(((L2MinionInstance)_actor).getLeader());
  1219. _actor.doCast(sk);
  1220. return true;
  1221. }
  1222. }
  1223. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getCastRange()+_actor.getTemplate().collisionRadius))
  1224. {
  1225. if(!(obj instanceof L2Attackable) || !obj.isDead())
  1226. continue;
  1227. L2Attackable targets = ((L2Attackable)obj);
  1228. if(((L2Attackable)_actor).getFactionId()!= targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  1229. continue;
  1230. if(Rnd.get(100)< 10)
  1231. {
  1232. if(GeoData.getInstance().canSeeTarget(_actor,targets))
  1233. {
  1234. clientStopMoving(null);
  1235. _actor.setTarget(obj);
  1236. _actor.doCast(sk);
  1237. return true;
  1238. }
  1239. }
  1240. }
  1241. }
  1242. else if(isParty(sk))
  1243. {
  1244. for(L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(sk.getSkillRadius()+_actor.getTemplate().collisionRadius))
  1245. {
  1246. if(!(obj instanceof L2Attackable))
  1247. {
  1248. continue;
  1249. }
  1250. L2Npc targets = ((L2Npc)obj);
  1251. L2Npc actors = ((L2Npc)_actor);
  1252. if(actors.getFactionId() != null && actors.getFactionId().equals(targets.getFactionId()))
  1253. {
  1254. if(obj.getCurrentHp()<obj.getMaxHp() && Rnd.get(100)<=20)
  1255. {
  1256. clientStopMoving(null);
  1257. _actor.setTarget(_actor);
  1258. _actor.doCast(sk);
  1259. return true;
  1260. }
  1261. }
  1262. }
  1263. }
  1264. break;
  1265. }
  1266. case DEBUFF:
  1267. case WEAKNESS:
  1268. case POISON:
  1269. case DOT:
  1270. case MDOT:
  1271. case BLEED:
  1272. {
  1273. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget)
  1274. && !canAOE(sk) && !attackTarget.isDead() && dist2<=srange)
  1275. {
  1276. if (attackTarget.getFirstEffect(sk) == null)
  1277. {
  1278. clientStopMoving(null);
  1279. _actor.doCast(sk);
  1280. return true;
  1281. }
  1282. }
  1283. else if(canAOE(sk))
  1284. {
  1285. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1286. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1287. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1288. {
  1289. clientStopMoving(null);
  1290. //L2Object target = attackTarget;
  1291. //_actor.setTarget(_actor);
  1292. _actor.doCast(sk);
  1293. //_actor.setTarget(target);
  1294. return true;
  1295. }
  1296. if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1297. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1298. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1299. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1300. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1301. {
  1302. clientStopMoving(null);
  1303. _actor.doCast(sk);
  1304. return true;
  1305. }
  1306. }
  1307. else if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1308. {
  1309. L2Character target = EffectTargetReconsider(sk,false);
  1310. if (target != null)
  1311. {
  1312. clientStopMoving(null);
  1313. _actor.doCast(sk);
  1314. return true;
  1315. }
  1316. }
  1317. break;
  1318. }
  1319. case SLEEP:
  1320. {
  1321. if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1322. {
  1323. if(!attackTarget.isDead() && dist2 <= srange)
  1324. {
  1325. if(dist2 > range || attackTarget.isMoving())
  1326. {
  1327. if (attackTarget.getFirstEffect(sk) == null)
  1328. {
  1329. clientStopMoving(null);
  1330. //_actor.setTarget(attackTarget);
  1331. _actor.doCast(sk);
  1332. return true;
  1333. }
  1334. }
  1335. }
  1336. L2Character target = EffectTargetReconsider(sk,false);
  1337. if (target != null)
  1338. {
  1339. clientStopMoving(null);
  1340. _actor.doCast(sk);
  1341. return true;
  1342. }
  1343. }
  1344. else if(canAOE(sk))
  1345. {
  1346. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1347. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1348. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1349. {
  1350. clientStopMoving(null);
  1351. //L2Object target = attackTarget;
  1352. //_actor.setTarget(_actor);
  1353. _actor.doCast(sk);
  1354. //_actor.setTarget(target);
  1355. return true;
  1356. }
  1357. if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1358. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1359. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1360. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1361. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1362. {
  1363. clientStopMoving(null);
  1364. _actor.doCast(sk);
  1365. return true;
  1366. }
  1367. }
  1368. break;
  1369. }
  1370. case ROOT:
  1371. case STUN:
  1372. case PARALYZE:
  1373. {
  1374. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !canAOE(sk) && dist2<=srange)
  1375. {
  1376. if (attackTarget.getFirstEffect(sk) == null)
  1377. {
  1378. clientStopMoving(null);
  1379. _actor.doCast(sk);
  1380. return true;
  1381. }
  1382. }
  1383. else if(canAOE(sk))
  1384. {
  1385. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1386. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1387. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1388. {
  1389. clientStopMoving(null);
  1390. //L2Object target = attackTarget;
  1391. //_actor.setTarget(_actor);
  1392. _actor.doCast(sk);
  1393. //_actor.setTarget(target);
  1394. return true;
  1395. }
  1396. else if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1397. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1398. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1399. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1400. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1401. {
  1402. clientStopMoving(null);
  1403. _actor.doCast(sk);
  1404. return true;
  1405. }
  1406. }
  1407. else if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1408. {
  1409. L2Character target = EffectTargetReconsider(sk,false);
  1410. if (target != null)
  1411. {
  1412. clientStopMoving(null);
  1413. _actor.doCast(sk);
  1414. return true;
  1415. }
  1416. }
  1417. break;
  1418. }
  1419. case MUTE:
  1420. case FEAR:
  1421. {
  1422. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !canAOE(sk) && dist2<=srange)
  1423. {
  1424. if (attackTarget.getFirstEffect(sk) == null)
  1425. {
  1426. clientStopMoving(null);
  1427. _actor.doCast(sk);
  1428. return true;
  1429. }
  1430. }
  1431. else if(canAOE(sk))
  1432. {
  1433. if(sk.getTargetType() == SkillTargetType.TARGET_AURA
  1434. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1435. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1436. {
  1437. clientStopMoving(null);
  1438. //L2Object target = attackTarget;
  1439. //_actor.setTarget(_actor);
  1440. _actor.doCast(sk);
  1441. //_actor.setTarget(target);
  1442. return true;
  1443. }
  1444. if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1445. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1446. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1447. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1448. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1449. {
  1450. clientStopMoving(null);
  1451. _actor.doCast(sk);
  1452. return true;
  1453. }
  1454. }
  1455. else if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1456. {
  1457. L2Character target = EffectTargetReconsider(sk,false);
  1458. if (target != null)
  1459. {
  1460. clientStopMoving(null);
  1461. _actor.doCast(sk);
  1462. return true;
  1463. }
  1464. }
  1465. break;
  1466. }
  1467. case CANCEL:
  1468. case NEGATE:
  1469. {
  1470. if(sk.getTargetType() == SkillTargetType.TARGET_ONE)
  1471. {
  1472. if(attackTarget.getFirstEffect(L2EffectType.BUFF) != null
  1473. && GeoData.getInstance().canSeeTarget(_actor,attackTarget)
  1474. && !attackTarget.isDead()
  1475. && dist2<=srange)
  1476. {
  1477. clientStopMoving(null);
  1478. //L2Object target = attackTarget;
  1479. //_actor.setTarget(_actor);
  1480. _actor.doCast(sk);
  1481. //_actor.setTarget(target);
  1482. return true;
  1483. }
  1484. L2Character target = EffectTargetReconsider(sk,false);
  1485. if (target != null)
  1486. {
  1487. clientStopMoving(null);
  1488. L2Object targets = attackTarget;
  1489. _actor.setTarget(target);
  1490. _actor.doCast(sk);
  1491. _actor.setTarget(targets);
  1492. return true;
  1493. }
  1494. }
  1495. else if(canAOE(sk))
  1496. {
  1497. if((sk.getTargetType() == SkillTargetType.TARGET_AURA
  1498. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1499. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AURA)
  1500. && GeoData.getInstance().canSeeTarget(_actor,attackTarget))
  1501. {
  1502. clientStopMoving(null);
  1503. //L2Object target = attackTarget;
  1504. //_actor.setTarget(_actor);
  1505. _actor.doCast(sk);
  1506. //_actor.setTarget(target);
  1507. return true;
  1508. }
  1509. else if((sk.getTargetType() == SkillTargetType.TARGET_AREA
  1510. || sk.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  1511. || sk.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  1512. || sk.getTargetType() == SkillTargetType.TARGET_MULTIFACE)
  1513. && GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1514. {
  1515. clientStopMoving(null);
  1516. _actor.doCast(sk);
  1517. return true;
  1518. }
  1519. }
  1520. break;
  1521. }
  1522. case PDAM:
  1523. case MDAM:
  1524. case BLOW:
  1525. case DRAIN:
  1526. case CHARGEDAM:
  1527. case DEATHLINK:
  1528. case CPDAM:
  1529. case MANADAM:
  1530. {
  1531. if(!canAura(sk))
  1532. {
  1533. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1534. {
  1535. clientStopMoving(null);
  1536. _actor.doCast(sk);
  1537. return true;
  1538. }
  1539. else
  1540. {
  1541. L2Character target = SkillTargetReconsider(sk);
  1542. if (target != null)
  1543. {
  1544. clientStopMoving(null);
  1545. L2Object targets = attackTarget;
  1546. _actor.setTarget(target);
  1547. _actor.doCast(sk);
  1548. _actor.setTarget(targets);
  1549. return true;
  1550. }
  1551. }
  1552. }
  1553. else
  1554. {
  1555. clientStopMoving(null);
  1556. _actor.doCast(sk);
  1557. return true;
  1558. }
  1559. break;
  1560. }
  1561. default :
  1562. {
  1563. if(!canAura(sk))
  1564. {
  1565. if(GeoData.getInstance().canSeeTarget(_actor,attackTarget) && !attackTarget.isDead() && dist2<=srange)
  1566. {
  1567. clientStopMoving(null);
  1568. _actor.doCast(sk);
  1569. return true;
  1570. }
  1571. else
  1572. {
  1573. L2Character target = SkillTargetReconsider(sk);
  1574. if (target != null)
  1575. {
  1576. clientStopMoving(null);
  1577. L2Object targets = attackTarget;
  1578. _actor.setTarget(target);
  1579. _actor.doCast(sk);
  1580. _actor.setTarget(targets);
  1581. return true;
  1582. }
  1583. }
  1584. }
  1585. else
  1586. {
  1587. clientStopMoving(null);
  1588. //L2Object targets = attackTarget;
  1589. //_actor.setTarget(_actor);
  1590. _actor.doCast(sk);
  1591. //_actor.setTarget(targets);
  1592. return true;
  1593. }
  1594. }
  1595. break;
  1596. }
  1597. return false;
  1598. }
  1599. /**
  1600. * This AI task will start when ACTOR cannot move and attack range larger than distance
  1601. */
  1602. private void MovementDisable()
  1603. {
  1604. double dist = 0;
  1605. double dist2 = 0;
  1606. int range = 0;
  1607. try
  1608. {
  1609. if(_actor.getTarget() == null)
  1610. _actor.setTarget(getAttackTarget());
  1611. dist = Math.sqrt(_actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY()));
  1612. dist2= dist - _actor.getTemplate().collisionRadius;
  1613. range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1614. if(getAttackTarget().isMoving())
  1615. {
  1616. dist = dist -30;
  1617. if(_actor.isMoving())
  1618. dist = dist -50;
  1619. }
  1620. }
  1621. catch (NullPointerException e)
  1622. {
  1623. setIntention(AI_INTENTION_ACTIVE);
  1624. return;
  1625. }
  1626. //Check if activeChar has any skill
  1627. if(_skillrender.hasSkill())
  1628. {
  1629. //-------------------------------------------------------------
  1630. //Try to stop the target or disable the target as priority
  1631. int random = Rnd.get(100);
  1632. if (_skillrender.hasImmobiliseSkill() && !getAttackTarget().isImmobilized() && random < 2)
  1633. {
  1634. for(L2Skill sk : _skillrender._immobiliseskills)
  1635. {
  1636. if(sk.getMpConsume() >= _actor.getCurrentMp()
  1637. || _actor.isSkillDisabled(sk)
  1638. || (sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1639. || (sk.isMagic()&&_actor.isMuted())
  1640. || (!sk.isMagic()&&_actor.isPhysicalMuted()))
  1641. {
  1642. continue;
  1643. }
  1644. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1645. continue;
  1646. if (getAttackTarget().getFirstEffect(sk) == null)
  1647. {
  1648. clientStopMoving(null);
  1649. //L2Object target = getAttackTarget();
  1650. //_actor.setTarget(_actor);
  1651. _actor.doCast(sk);
  1652. //_actor.setTarget(target);
  1653. return;
  1654. }
  1655. }
  1656. }
  1657. //-------------------------------------------------------------
  1658. //Same as Above, but with Mute/FEAR etc....
  1659. if(_skillrender.hasCOTSkill() && random < 5)
  1660. {
  1661. for(L2Skill sk:_skillrender._cotskills)
  1662. {
  1663. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1664. || _actor.isSkillDisabled(sk)
  1665. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1666. ||(sk.isMagic()&&_actor.isMuted())
  1667. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1668. {
  1669. continue;
  1670. }
  1671. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1672. continue;
  1673. if (getAttackTarget().getFirstEffect(sk) == null)
  1674. {
  1675. clientStopMoving(null);
  1676. //L2Object target = getAttackTarget();
  1677. //_actor.setTarget(_actor);
  1678. _actor.doCast(sk);
  1679. //_actor.setTarget(target);
  1680. return;
  1681. }
  1682. }
  1683. }
  1684. //-------------------------------------------------------------
  1685. if(_skillrender.hasDebuffSkill() && random < 8)
  1686. {
  1687. for(L2Skill sk:_skillrender._debuffskills)
  1688. {
  1689. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1690. || _actor.isSkillDisabled(sk)
  1691. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1692. ||(sk.isMagic()&&_actor.isMuted())
  1693. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1694. {
  1695. continue;
  1696. }
  1697. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1698. continue;
  1699. if (getAttackTarget().getFirstEffect(sk) == null)
  1700. {
  1701. clientStopMoving(null);
  1702. //L2Object target = getAttackTarget();
  1703. //_actor.setTarget(_actor);
  1704. _actor.doCast(sk);
  1705. //_actor.setTarget(target);
  1706. return;
  1707. }
  1708. }
  1709. }
  1710. //-------------------------------------------------------------
  1711. //Some side effect skill like CANCEL or NEGATE
  1712. if(_skillrender.hasNegativeSkill() && random < 9)
  1713. {
  1714. for(L2Skill sk : _skillrender._negativeskills)
  1715. {
  1716. if(sk.getMpConsume() >= _actor.getCurrentMp()
  1717. || _actor.isSkillDisabled(sk)
  1718. ||(sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1719. ||(sk.isMagic()&&_actor.isMuted())
  1720. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1721. {
  1722. continue;
  1723. }
  1724. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1725. continue;
  1726. if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  1727. {
  1728. clientStopMoving(null);
  1729. //L2Object target = getAttackTarget();
  1730. //_actor.setTarget(_actor);
  1731. _actor.doCast(sk);
  1732. //_actor.setTarget(target);
  1733. return;
  1734. }
  1735. }
  1736. }
  1737. //-------------------------------------------------------------
  1738. //Start ATK SKILL when nothing can be done
  1739. if(_skillrender.hasAtkSkill())
  1740. {
  1741. for(L2Skill sk:_skillrender._atkskills)
  1742. {
  1743. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1744. || _actor.isSkillDisabled(sk)
  1745. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1746. ||(sk.isMagic()&&_actor.isMuted())
  1747. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1748. {
  1749. continue;
  1750. }
  1751. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1752. continue;
  1753. clientStopMoving(null);
  1754. //L2Object target = getAttackTarget();
  1755. //_actor.setTarget(_actor);
  1756. _actor.doCast(sk);
  1757. //_actor.setTarget(target);
  1758. return;
  1759. }
  1760. }
  1761. //-------------------------------------------------------------
  1762. //if there is no ATK skill to use, then try Universal skill
  1763. /*
  1764. if(_skillrender.hasUniversalSkill())
  1765. {
  1766. for(L2Skill sk:_skillrender._universalskills)
  1767. {
  1768. if(sk.getMpConsume()>=_actor.getCurrentMp()
  1769. || _actor.isSkillDisabled(sk.getId())
  1770. ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  1771. ||(sk.isMagic()&&_actor.isMuted())
  1772. ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  1773. {
  1774. continue;
  1775. }
  1776. if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
  1777. continue;
  1778. clientStopMoving(null);
  1779. L2Object target = getAttackTarget();
  1780. //_actor.setTarget(_actor);
  1781. _actor.doCast(sk);
  1782. //_actor.setTarget(target);
  1783. return;
  1784. }
  1785. }
  1786. */
  1787. }
  1788. //timepass = timepass + 1;
  1789. if (_actor.isMovementDisabled())
  1790. {
  1791. //timepass = 0;
  1792. TargetReconsider();
  1793. return;
  1794. }
  1795. //else if(timepass>=5)
  1796. //{
  1797. // timepass = 0;
  1798. // AggroReconsider();
  1799. // return;
  1800. //}
  1801. if(dist>range || !GeoData.getInstance().canSeeTarget(_actor, getAttackTarget()))
  1802. {
  1803. if(getAttackTarget().isMoving())
  1804. range -=100;if(range<5)range=5;
  1805. moveToPawn(getAttackTarget(), range);
  1806. return;
  1807. }
  1808. Melee(((L2Npc)_actor).getPrimaryAttack());
  1809. return;
  1810. }
  1811. private L2Character EffectTargetReconsider(L2Skill sk, boolean positive)
  1812. {
  1813. if (sk == null)
  1814. return null;
  1815. if(sk.getSkillType() != L2SkillType.NEGATE || sk.getSkillType() != L2SkillType.CANCEL )
  1816. {
  1817. if(!positive)
  1818. {
  1819. double dist = 0;
  1820. double dist2 = 0;
  1821. int range = 0;
  1822. L2Attackable actor = (L2Attackable)_actor;
  1823. for(L2Character obj: actor.getAttackByList())
  1824. {
  1825. if(obj == null || obj.isDead() || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj == getAttackTarget())
  1826. continue;
  1827. try
  1828. {
  1829. _actor.setTarget(getAttackTarget());
  1830. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1831. dist2= dist - _actor.getTemplate().collisionRadius;
  1832. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1833. if(obj.isMoving())
  1834. dist2 = dist2 - 70;
  1835. }
  1836. catch (NullPointerException e)
  1837. {
  1838. continue;
  1839. }
  1840. if(dist2<=range)
  1841. {
  1842. if (getAttackTarget().getFirstEffect(sk) == null)
  1843. return obj;
  1844. }
  1845. }
  1846. //----------------------------------------------------------------------
  1847. //If there is nearby Target with aggro, start going on random target that is attackable
  1848. for (L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(range))
  1849. {
  1850. if(obj.isDead() || !GeoData.getInstance().canSeeTarget(_actor,obj))
  1851. continue;
  1852. try
  1853. {
  1854. _actor.setTarget(getAttackTarget());
  1855. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1856. dist2= dist;
  1857. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1858. if(obj.isMoving())
  1859. dist2 = dist2 - 70;
  1860. }
  1861. catch (NullPointerException e)
  1862. {
  1863. continue;
  1864. }
  1865. if(obj instanceof L2Attackable)
  1866. {
  1867. if(((L2Attackable)_actor).getEnemyClan() != null && ((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan()))
  1868. {
  1869. if(dist2<=range)
  1870. {
  1871. if (getAttackTarget().getFirstEffect(sk) == null)
  1872. return obj;
  1873. }
  1874. }
  1875. }
  1876. if(obj instanceof L2PcInstance || obj instanceof L2Summon)
  1877. {
  1878. if(dist2<=range)
  1879. {
  1880. if (getAttackTarget().getFirstEffect(sk) == null)
  1881. return obj;
  1882. }
  1883. }
  1884. }
  1885. }
  1886. else if (positive)
  1887. {
  1888. double dist = 0;
  1889. double dist2 = 0;
  1890. int range = 0;
  1891. for(L2Character obj: _actor.getKnownList().getKnownCharactersInRadius(range))
  1892. {
  1893. if(!(obj instanceof L2Attackable) || obj.isDead() || !GeoData.getInstance().canSeeTarget(_actor,obj))
  1894. continue;
  1895. L2Attackable targets = ((L2Attackable)obj);
  1896. if(((L2Attackable)_actor).getFactionId()!= targets.getFactionId() && ((L2Attackable)_actor).getFactionId()!=null)
  1897. continue;
  1898. try
  1899. {
  1900. _actor.setTarget(getAttackTarget());
  1901. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1902. dist2= dist - _actor.getTemplate().collisionRadius;
  1903. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1904. if(obj.isMoving())
  1905. dist2 = dist2 - 70;
  1906. }
  1907. catch (NullPointerException e)
  1908. {
  1909. continue;
  1910. }
  1911. if(dist2<=range)
  1912. {
  1913. if (obj.getFirstEffect(sk) == null)
  1914. return obj;
  1915. }
  1916. }
  1917. }
  1918. return null;
  1919. }
  1920. else
  1921. {
  1922. double dist = 0;
  1923. double dist2 = 0;
  1924. int range = 0;
  1925. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1926. for (L2Character obj : _actor.getKnownList().getKnownCharactersInRadius(range))
  1927. {
  1928. if(obj == null || obj.isDead() || !GeoData.getInstance().canSeeTarget(_actor,obj))
  1929. continue;
  1930. try
  1931. {
  1932. _actor.setTarget(getAttackTarget());
  1933. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1934. dist2= dist - _actor.getTemplate().collisionRadius;
  1935. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  1936. if(obj.isMoving())
  1937. dist2 = dist2 - 70;
  1938. }
  1939. catch (NullPointerException e)
  1940. {
  1941. continue;
  1942. }
  1943. if(obj instanceof L2Attackable)
  1944. {
  1945. if(((L2Attackable)_actor).getEnemyClan() != null && ((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan()))
  1946. {
  1947. if(dist2<=range)
  1948. {
  1949. if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  1950. return obj;
  1951. }
  1952. }
  1953. }
  1954. if(obj instanceof L2PcInstance || obj instanceof L2Summon)
  1955. {
  1956. if(dist2<=range)
  1957. {
  1958. if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  1959. return obj;
  1960. }
  1961. }
  1962. }
  1963. return null;
  1964. }
  1965. }
  1966. private L2Character SkillTargetReconsider(L2Skill sk)
  1967. {
  1968. double dist = 0;
  1969. double dist2 = 0;
  1970. int range = 0;
  1971. L2Attackable actor = (L2Attackable)_actor;
  1972. if(actor.getHateList()!=null)
  1973. for(L2Character obj: actor.getHateList())
  1974. {
  1975. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead())
  1976. continue;
  1977. try
  1978. {
  1979. _actor.setTarget(getAttackTarget());
  1980. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  1981. dist2= dist - _actor.getTemplate().collisionRadius;
  1982. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  1983. //if(obj.isMoving())
  1984. // dist2 = dist2 - 40;
  1985. }
  1986. catch (NullPointerException e)
  1987. {
  1988. continue;
  1989. }
  1990. if(dist2<=range)
  1991. {
  1992. return obj;
  1993. }
  1994. }
  1995. if(!(_actor instanceof L2GuardInstance))
  1996. {
  1997. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  1998. for (L2Object target : objs)
  1999. {
  2000. try
  2001. {
  2002. _actor.setTarget(getAttackTarget());
  2003. dist = Math.sqrt(_actor.getPlanDistanceSq(target.getX(), target.getY()));
  2004. dist2= dist;
  2005. range = sk.getCastRange() + _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  2006. //if(obj.isMoving())
  2007. // dist2 = dist2 - 40;
  2008. }
  2009. catch (NullPointerException e)
  2010. {
  2011. continue;
  2012. }
  2013. L2Character obj = null;
  2014. if (target instanceof L2Character)
  2015. obj = (L2Character)target;
  2016. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || dist2 > range)
  2017. continue;
  2018. if(obj instanceof L2PcInstance)
  2019. {
  2020. return obj;
  2021. }
  2022. if(obj instanceof L2Attackable)
  2023. {
  2024. if(((L2Attackable)_actor).getEnemyClan() != null && ((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan()))
  2025. {
  2026. return obj;
  2027. }
  2028. if (((L2Attackable)_actor).getIsChaos() != 0)
  2029. {
  2030. if(((L2Attackable)obj).getFactionId() != null && ((L2Attackable)obj).getFactionId().equals(((L2Attackable)_actor).getFactionId()))
  2031. continue;
  2032. else
  2033. return obj;
  2034. }
  2035. }
  2036. if(obj instanceof L2Summon)
  2037. {
  2038. return obj;
  2039. }
  2040. }
  2041. }
  2042. return null;
  2043. }
  2044. private void TargetReconsider()
  2045. {
  2046. double dist = 0;
  2047. double dist2 = 0;
  2048. int range = 0;
  2049. L2Attackable actor = (L2Attackable)_actor;
  2050. L2Character MostHate = ((L2Attackable) _actor).getMostHated();
  2051. if(actor.getHateList()!=null)
  2052. for(L2Character obj : actor.getHateList())
  2053. {
  2054. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead() || obj!= MostHate || obj == _actor)
  2055. continue;
  2056. try
  2057. {
  2058. dist = Math.sqrt(_actor.getPlanDistanceSq(obj.getX(), obj.getY()));
  2059. dist2= dist - _actor.getTemplate().collisionRadius;
  2060. range = _actor.getPhysicalAttackRange() + _actor.getTemplate().collisionRadius + obj.getTemplate().collisionRadius;
  2061. if(obj.isMoving())
  2062. dist2 = dist2 - 70;
  2063. }
  2064. catch (NullPointerException e)
  2065. {
  2066. continue;
  2067. }
  2068. if(dist2<=range)
  2069. {
  2070. if(MostHate!=null)
  2071. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2072. else
  2073. actor.addDamageHate(obj,2000,2000);
  2074. _actor.setTarget(obj);
  2075. setAttackTarget(obj);
  2076. return;
  2077. }
  2078. }
  2079. if(!(_actor instanceof L2GuardInstance))
  2080. {
  2081. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  2082. for (L2Object target : objs)
  2083. {
  2084. L2Character obj = null;
  2085. if (target instanceof L2Character)
  2086. obj = (L2Character)target;
  2087. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead() || obj!= MostHate || obj == _actor || obj == getAttackTarget())
  2088. continue;
  2089. if(obj instanceof L2PcInstance)
  2090. {
  2091. if(MostHate != null)
  2092. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2093. else
  2094. actor.addDamageHate(obj,2000,2000);
  2095. _actor.setTarget(obj);
  2096. setAttackTarget(obj);
  2097. }
  2098. else if(obj instanceof L2Attackable)
  2099. {
  2100. if(((L2Attackable)_actor).getEnemyClan() != null && ((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan()))
  2101. {
  2102. actor.addDamageHate(obj,0,actor.getHating(MostHate));
  2103. _actor.setTarget(obj);
  2104. }
  2105. if (((L2Attackable)_actor).getIsChaos() != 0)
  2106. {
  2107. if(((L2Attackable)obj).getFactionId() != null && ((L2Attackable)obj).getFactionId().equals(((L2Attackable)_actor).getFactionId()))
  2108. continue;
  2109. else
  2110. {
  2111. if(MostHate != null)
  2112. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2113. else
  2114. actor.addDamageHate(obj,2000,2000);
  2115. _actor.setTarget(obj);
  2116. setAttackTarget(obj);
  2117. }
  2118. }
  2119. }
  2120. else if(obj instanceof L2Summon)
  2121. {
  2122. if(MostHate != null)
  2123. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2124. else
  2125. actor.addDamageHate(obj,2000,2000);
  2126. _actor.setTarget(obj);
  2127. setAttackTarget(obj);
  2128. }
  2129. }
  2130. }
  2131. }
  2132. @SuppressWarnings("null")
  2133. private void AggroReconsider()
  2134. {
  2135. L2Attackable actor = (L2Attackable)_actor;
  2136. L2Character MostHate = ((L2Attackable) _actor).getMostHated();
  2137. if(actor.getHateList() != null)
  2138. {
  2139. int rand = Rnd.get(actor.getHateList().size());
  2140. int count = 0;
  2141. for(L2Character obj: actor.getHateList())
  2142. {
  2143. if(count < rand)
  2144. {
  2145. count++;
  2146. continue;
  2147. }
  2148. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead()|| obj == getAttackTarget() || obj == actor)
  2149. continue;
  2150. try
  2151. {
  2152. _actor.setTarget(getAttackTarget());
  2153. }
  2154. catch (NullPointerException e)
  2155. {
  2156. continue;
  2157. }
  2158. if(MostHate!=null)
  2159. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2160. else
  2161. actor.addDamageHate(obj,2000,2000);
  2162. _actor.setTarget(obj);
  2163. setAttackTarget(obj);
  2164. return;
  2165. }
  2166. }
  2167. if(!(_actor instanceof L2GuardInstance))
  2168. {
  2169. Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
  2170. for (L2Object target : objs)
  2171. {
  2172. L2Character obj = null;
  2173. if(target instanceof L2Character)
  2174. obj = (L2Character)target;
  2175. else
  2176. continue;
  2177. if(obj == null || !GeoData.getInstance().canSeeTarget(_actor,obj) || obj.isDead() || obj != MostHate || obj == _actor)
  2178. continue;
  2179. if(obj instanceof L2PcInstance)
  2180. {
  2181. if(MostHate!=null || !MostHate.isDead())
  2182. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2183. else
  2184. actor.addDamageHate(obj,2000,2000);
  2185. _actor.setTarget(obj);
  2186. setAttackTarget(obj);
  2187. }
  2188. else if(obj instanceof L2Attackable)
  2189. {
  2190. if(((L2Attackable)_actor).getEnemyClan() != null && (((L2Attackable)_actor).getEnemyClan().equals(((L2Attackable)obj).getClan())))
  2191. {
  2192. if(MostHate != null)
  2193. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2194. else
  2195. actor.addDamageHate(obj,2000,2000);
  2196. _actor.setTarget(obj);
  2197. }
  2198. if (((L2Attackable)_actor).getIsChaos() != 0)
  2199. {
  2200. if(((L2Attackable)obj).getFactionId() != null && ((L2Attackable)obj).getFactionId().equals(((L2Attackable)_actor).getFactionId()))
  2201. continue;
  2202. else
  2203. {
  2204. if(MostHate != null)
  2205. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2206. else
  2207. actor.addDamageHate(obj,2000,2000);
  2208. _actor.setTarget(obj);
  2209. setAttackTarget(obj);
  2210. }
  2211. }
  2212. }
  2213. else if(obj instanceof L2Summon)
  2214. {
  2215. if(MostHate != null)
  2216. actor.addDamageHate(obj,actor.getHating(MostHate),actor.getHating(MostHate));
  2217. else
  2218. actor.addDamageHate(obj,2000,2000);
  2219. _actor.setTarget(obj);
  2220. setAttackTarget(obj);
  2221. }
  2222. }
  2223. }
  2224. }
  2225. private void LSkillRender()
  2226. {
  2227. if(_skillrender._Lrangeskills == null)
  2228. _skillrender._Lrangeskills = ((L2Npc)_actor).getLrangeSkill();
  2229. }
  2230. private void SSkillRender()
  2231. {
  2232. if(_skillrender._Srangeskills == null)
  2233. _skillrender._Srangeskills = ((L2Npc)_actor).getSrangeSkill();
  2234. }
  2235. /**
  2236. * Manage AI thinking actions of a L2Attackable.<BR><BR>
  2237. */
  2238. @Override
  2239. protected void onEvtThink()
  2240. {
  2241. // Check if the actor can't use skills and if a thinking action isn't already in progress
  2242. if (_thinking || _actor.isAllSkillsDisabled()) return;
  2243. // Start thinking action
  2244. _thinking = true;
  2245. try
  2246. {
  2247. // Manage AI thinks of a L2Attackable
  2248. if (getIntention() == AI_INTENTION_ACTIVE) thinkActive();
  2249. else if (getIntention() == AI_INTENTION_ATTACK) thinkAttack();
  2250. }
  2251. finally
  2252. {
  2253. // Stop thinking action
  2254. _thinking = false;
  2255. }
  2256. }
  2257. /**
  2258. * Launch actions corresponding to the Event Attacked.<BR><BR>
  2259. *
  2260. * <B><U> Actions</U> :</B><BR><BR>
  2261. * <li>Init the attack : Calculate the attack timeout, Set the _globalAggro to 0, Add the attacker to the actor _aggroList</li>
  2262. * <li>Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance</li>
  2263. * <li>Set the Intention to AI_INTENTION_ATTACK</li><BR><BR>
  2264. *
  2265. * @param attacker The L2Character that attacks the actor
  2266. *
  2267. */
  2268. @Override
  2269. protected void onEvtAttacked(L2Character attacker)
  2270. {
  2271. //if (_actor instanceof L2ChestInstance && !((L2ChestInstance)_actor).isInteracted())
  2272. //{
  2273. //((L2ChestInstance)_actor).deleteMe();
  2274. //((L2ChestInstance)_actor).getSpawn().startRespawn();
  2275. //return;
  2276. //}
  2277. // Calculate the attack timeout
  2278. _attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks();
  2279. // Set the _globalAggro to 0 to permit attack even just after spawn
  2280. if (_globalAggro < 0) _globalAggro = 0;
  2281. // Add the attacker to the _aggroList of the actor
  2282. ((L2Attackable) _actor).addDamageHate(attacker, 0, 1);
  2283. // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  2284. if (!_actor.isRunning()) _actor.setRunning();
  2285. // Set the Intention to AI_INTENTION_ATTACK
  2286. if (getIntention() != AI_INTENTION_ATTACK)
  2287. {
  2288. setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  2289. }
  2290. else if (((L2Attackable) _actor).getMostHated() != getAttackTarget())
  2291. {
  2292. setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  2293. }
  2294. super.onEvtAttacked(attacker);
  2295. }
  2296. /**
  2297. * Launch actions corresponding to the Event Aggression.<BR><BR>
  2298. *
  2299. * <B><U> Actions</U> :</B><BR><BR>
  2300. * <li>Add the target to the actor _aggroList or update hate if already present </li>
  2301. * <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>
  2302. *
  2303. * @param attacker The L2Character that attacks
  2304. * @param aggro The value of hate to add to the actor against the target
  2305. *
  2306. */
  2307. @Override
  2308. protected void onEvtAggression(L2Character target, int aggro)
  2309. {
  2310. L2Attackable me = (L2Attackable) _actor;
  2311. if (target != null)
  2312. {
  2313. // Add the target to the actor _aggroList or update hate if already present
  2314. me.addDamageHate(target, 0, aggro);
  2315. // Set the actor AI Intention to AI_INTENTION_ATTACK
  2316. if (getIntention() != CtrlIntention.AI_INTENTION_ATTACK)
  2317. {
  2318. // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
  2319. if (!_actor.isRunning()) _actor.setRunning();
  2320. setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  2321. }
  2322. }
  2323. }
  2324. @Override
  2325. protected void onIntentionActive()
  2326. {
  2327. // Cancel attack timeout
  2328. _attackTimeout = Integer.MAX_VALUE;
  2329. super.onIntentionActive();
  2330. }
  2331. public void setGlobalAggro(int value)
  2332. {
  2333. _globalAggro = value;
  2334. }
  2335. /**
  2336. * @param timepass The timepass to set.
  2337. */
  2338. public void setTimepass(int TP)
  2339. {
  2340. this.timepass = TP;
  2341. }
  2342. /**
  2343. * @return Returns the timepass.
  2344. */
  2345. public int getTimepass()
  2346. {
  2347. return timepass;
  2348. }
  2349. }