1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839 |
- /*
- * Copyright (C) 2004-2013 L2J Server
- *
- * This file is part of L2J Server.
- *
- * L2J Server is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * L2J Server is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.l2jserver.gameserver.ai;
- import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
- import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
- import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.List;
- import java.util.concurrent.Future;
- import com.l2jserver.Config;
- import com.l2jserver.gameserver.GameTimeController;
- import com.l2jserver.gameserver.GeoData;
- import com.l2jserver.gameserver.ThreadPoolManager;
- import com.l2jserver.gameserver.datatables.NpcTable;
- import com.l2jserver.gameserver.datatables.TerritoryTable;
- import com.l2jserver.gameserver.instancemanager.DimensionalRiftManager;
- import com.l2jserver.gameserver.model.L2CharPosition;
- import com.l2jserver.gameserver.model.L2Object;
- import com.l2jserver.gameserver.model.actor.L2Attackable;
- import com.l2jserver.gameserver.model.actor.L2Character;
- import com.l2jserver.gameserver.model.actor.L2Npc;
- import com.l2jserver.gameserver.model.actor.L2Playable;
- import com.l2jserver.gameserver.model.actor.L2Summon;
- import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2FestivalMonsterInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2FriendlyMobInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2GuardInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2RaidBossInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2RiftInvaderInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2StaticObjectInstance;
- import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
- import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate.AIType;
- import com.l2jserver.gameserver.model.effects.L2EffectType;
- import com.l2jserver.gameserver.model.quest.Quest;
- import com.l2jserver.gameserver.model.quest.Quest.QuestEventType;
- import com.l2jserver.gameserver.model.skills.L2Skill;
- import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
- import com.l2jserver.gameserver.model.zone.ZoneId;
- import com.l2jserver.gameserver.util.Util;
- import com.l2jserver.util.Rnd;
- /**
- * This class manages AI of L2Attackable.
- */
- public class L2AttackableAI extends L2CharacterAI implements Runnable
- {
- private static final int RANDOM_WALK_RATE = 30; // confirmed
- // private static final int MAX_DRIFT_RANGE = 300;
- private static final int MAX_ATTACK_TIMEOUT = 1200; // int ticks, i.e. 2min
- /**
- * The L2Attackable AI task executed every 1s (call onEvtThink method).
- */
- private Future<?> _aiTask;
- /**
- * The delay after which the attacked is stopped.
- */
- private int _attackTimeout;
- /**
- * The L2Attackable aggro counter.
- */
- private int _globalAggro;
- /**
- * The flag used to indicate that a thinking action is in progress, to prevent recursive thinking.
- */
- private boolean _thinking;
-
- private int timepass = 0;
- private int chaostime = 0;
- private final L2NpcTemplate _skillrender;
- private List<L2Skill> shortRangeSkills = new ArrayList<>();
- private List<L2Skill> longRangeSkills = new ArrayList<>();
- int lastBuffTick;
-
- /**
- * Constructor of L2AttackableAI.
- * @param accessor The AI accessor of the L2Character
- */
- public L2AttackableAI(L2Character.AIAccessor accessor)
- {
- super(accessor);
- _skillrender = NpcTable.getInstance().getTemplate(getActiveChar().getTemplate().getNpcId());
- _attackTimeout = Integer.MAX_VALUE;
- _globalAggro = -10; // 10 seconds timeout of ATTACK after respawn
- }
-
- @Override
- public void run()
- {
- // Launch actions corresponding to the Event Think
- onEvtThink();
- }
-
- /**
- * <B><U> Actor is a L2GuardInstance</U> :</B>
- * <ul>
- * <li>The target isn't a Folk or a Door</li>
- * <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
- * <li>The target is in the actor Aggro range and is at the same height</li>
- * <li>The L2PcInstance target has karma (=PK)</li>
- * <li>The L2MonsterInstance target is aggressive</li>
- * </ul>
- * <B><U> Actor is a L2SiegeGuardInstance</U> :</B>
- * <ul>
- * <li>The target isn't a Folk or a Door</li>
- * <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
- * <li>The target is in the actor Aggro range and is at the same height</li>
- * <li>A siege is in progress</li>
- * <li>The L2PcInstance target isn't a Defender</li>
- * </ul>
- * <B><U> Actor is a L2FriendlyMobInstance</U> :</B>
- * <ul>
- * <li>The target isn't a Folk, a Door or another L2Npc</li>
- * <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
- * <li>The target is in the actor Aggro range and is at the same height</li>
- * <li>The L2PcInstance target has karma (=PK)</li>
- * </ul>
- * <B><U> Actor is a L2MonsterInstance</U> :</B>
- * <ul>
- * <li>The target isn't a Folk, a Door or another L2Npc</li>
- * <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
- * <li>The target is in the actor Aggro range and is at the same height</li>
- * <li>The actor is Aggressive</li>
- * </ul>
- * @param target The targeted L2Object
- * @return True if the target is autoattackable (depends on the actor type).
- */
- private boolean autoAttackCondition(L2Character target)
- {
- if ((target == null) || (getActiveChar() == null))
- {
- return false;
- }
- final L2Attackable me = getActiveChar();
-
- // Check if the target isn't invulnerable
- if (target.isInvul())
- {
- // However EffectInvincible requires to check GMs specially
- if ((target instanceof L2PcInstance) && ((L2PcInstance) target).isGM())
- {
- return false;
- }
- if ((target instanceof L2Summon) && ((L2Summon) target).getOwner().isGM())
- {
- return false;
- }
- }
-
- // Check if the target isn't a Folk or a Door
- if (target instanceof L2DoorInstance)
- {
- return false;
- }
-
- // Check if the target isn't dead, is in the Aggro range and is at the same height
- if (target.isAlikeDead() || ((target instanceof L2Playable) && !me.isInsideRadius(target, me.getAggroRange(), true, false)))
- {
- return false;
- }
-
- // Check if the target is a L2Playable
- if (target.isPlayable())
- {
- // Check if the AI isn't a Raid Boss, can See Silent Moving players and the target isn't in silent move mode
- if (!(me.isRaid()) && !(me.canSeeThroughSilentMove()) && ((L2Playable) target).isSilentMoving())
- {
- return false;
- }
- }
-
- // Gets the player if there is any.
- final L2PcInstance player = target.getActingPlayer();
- if (player != null)
- {
- // Don't take the aggro if the GM has the access level below or equal to GM_DONT_TAKE_AGGRO
- if (player.isGM() && !player.getAccessLevel().canTakeAggro())
- {
- return false;
- }
-
- // check if the target is within the grace period for JUST getting up from fake death
- if (player.isRecentFakeDeath())
- {
- return false;
- }
-
- if (player.isInParty() && player.getParty().isInDimensionalRift())
- {
- byte riftType = player.getParty().getDimensionalRift().getType();
- byte riftRoom = player.getParty().getDimensionalRift().getCurrentRoom();
-
- if ((me instanceof L2RiftInvaderInstance) && !DimensionalRiftManager.getInstance().getRoom(riftType, riftRoom).checkIfInZone(me.getX(), me.getY(), me.getZ()))
- {
- return false;
- }
- }
- }
-
- // Check if the actor is a L2GuardInstance
- if (me instanceof L2GuardInstance)
- {
- // Check if the L2PcInstance target has karma (=PK)
- if ((player != null) && (player.getKarma() > 0))
- {
- return GeoData.getInstance().canSeeTarget(me, player); // Los Check
- }
- // Check if the L2MonsterInstance target is aggressive
- if ((target instanceof L2MonsterInstance) && Config.GUARD_ATTACK_AGGRO_MOB)
- {
- return (((L2MonsterInstance) target).isAggressive() && GeoData.getInstance().canSeeTarget(me, target));
- }
-
- return false;
- }
- else if (me instanceof L2FriendlyMobInstance)
- {
- // Check if the target isn't another L2Npc
- if (target instanceof L2Npc)
- {
- return false;
- }
-
- // Check if the L2PcInstance target has karma (=PK)
- if ((target instanceof L2PcInstance) && (((L2PcInstance) target).getKarma() > 0))
- {
- return GeoData.getInstance().canSeeTarget(me, target); // Los Check
- }
- return false;
- }
- else
- {
- if (target instanceof L2Attackable)
- {
- if ((me.getEnemyClan() == null) || (((L2Attackable) target).getClan() == null))
- {
- return false;
- }
-
- if (!target.isAutoAttackable(me))
- {
- return false;
- }
-
- if (me.getEnemyClan().equals(((L2Attackable) target).getClan()))
- {
- if (me.isInsideRadius(target, me.getEnemyRange(), false, false))
- {
- return GeoData.getInstance().canSeeTarget(me, target);
- }
- return false;
- }
- if ((me.getIsChaos() > 0) && me.isInsideRadius(target, me.getIsChaos(), false, false))
- {
- if ((me.getFactionId() != null) && me.getFactionId().equals(((L2Attackable) target).getFactionId()))
- {
- return false;
- }
- // Los Check
- return GeoData.getInstance().canSeeTarget(me, target);
- }
- }
-
- if ((target instanceof L2Attackable) || (target instanceof L2Npc))
- {
- return false;
- }
-
- // depending on config, do not allow mobs to attack _new_ players in peacezones,
- // unless they are already following those players from outside the peacezone.
- if (!Config.ALT_MOB_AGRO_IN_PEACEZONE && target.isInsideZone(ZoneId.PEACE))
- {
- return false;
- }
-
- if (me.isChampion() && Config.L2JMOD_CHAMPION_PASSIVE)
- {
- return false;
- }
-
- // Check if the actor is Aggressive
- return (me.isAggressive() && GeoData.getInstance().canSeeTarget(me, target));
- }
- }
-
- public void startAITask()
- {
- // If not idle - create an AI task (schedule onEvtThink repeatedly)
- if (_aiTask == null)
- {
- _aiTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(this, 1000, 1000);
- }
- }
-
- @Override
- public void stopAITask()
- {
- if (_aiTask != null)
- {
- _aiTask.cancel(false);
- _aiTask = null;
- }
- super.stopAITask();
- }
-
- /**
- * Set the Intention of this L2CharacterAI and create an AI Task executed every 1s (call onEvtThink method) for this L2Attackable.<br>
- * <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>
- * @param intention The new Intention to set to the AI
- * @param arg0 The first parameter of the Intention
- * @param arg1 The second parameter of the Intention
- */
- @Override
- synchronized void changeIntention(CtrlIntention intention, Object arg0, Object arg1)
- {
- if ((intention == AI_INTENTION_IDLE) || (intention == AI_INTENTION_ACTIVE))
- {
- // Check if actor is not dead
- L2Attackable npc = getActiveChar();
- if (!npc.isAlikeDead())
- {
- // If its _knownPlayer isn't empty set the Intention to AI_INTENTION_ACTIVE
- if (!npc.getKnownList().getKnownPlayers().isEmpty())
- {
- intention = AI_INTENTION_ACTIVE;
- }
- else
- {
- if (npc.getSpawn() != null)
- {
- final int range = Config.MAX_DRIFT_RANGE;
- if (!npc.isInsideRadius(npc.getSpawn().getLocx(), npc.getSpawn().getLocy(), npc.getSpawn().getLocz(), range + range, true, false))
- {
- intention = AI_INTENTION_ACTIVE;
- }
- }
- }
- }
-
- if (intention == AI_INTENTION_IDLE)
- {
- // Set the Intention of this L2AttackableAI to AI_INTENTION_IDLE
- super.changeIntention(AI_INTENTION_IDLE, null, null);
-
- // Stop AI task and detach AI from NPC
- if (_aiTask != null)
- {
- _aiTask.cancel(true);
- _aiTask = null;
- }
-
- // Cancel the AI
- _accessor.detachAI();
-
- return;
- }
- }
-
- // Set the Intention of this L2AttackableAI to intention
- super.changeIntention(intention, arg0, arg1);
-
- // If not idle - create an AI task (schedule onEvtThink repeatedly)
- startAITask();
- }
-
- /**
- * Manage the Attack Intention : Stop current Attack (if necessary), Calculate attack timeout, Start a new Attack and Launch Think Event.
- * @param target The L2Character to attack
- */
- @Override
- protected void onIntentionAttack(L2Character target)
- {
- // Calculate the attack timeout
- _attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getInstance().getGameTicks();
-
- // self and buffs
- if ((lastBuffTick + 30) < GameTimeController.getInstance().getGameTicks())
- {
- for (L2Skill sk : _skillrender.getBuffSkills())
- {
- if (cast(sk))
- {
- break;
- }
- }
- lastBuffTick = GameTimeController.getInstance().getGameTicks();
- }
-
- // Manage the Attack Intention : Stop current Attack (if necessary), Start a new Attack and Launch Think Event
- super.onIntentionAttack(target);
- }
-
- private void thinkCast()
- {
- if (checkTargetLost(getCastTarget()))
- {
- setCastTarget(null);
- return;
- }
- if (maybeMoveToPawn(getCastTarget(), _actor.getMagicalAttackRange(_skill)))
- {
- return;
- }
- clientStopMoving(null);
- setIntention(AI_INTENTION_ACTIVE);
- _accessor.doCast(_skill);
- }
-
- /**
- * Manage AI standard thinks of a L2Attackable (called by onEvtThink). <B><U> Actions</U> :</B>
- * <ul>
- * <li>Update every 1s the _globalAggro counter to come close to 0</li>
- * <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>
- * <li>If the actor is a L2GuardInstance that can't attack, order to it to return to its home location</li>
- * <li>If the actor is a L2MonsterInstance that can't attack, order to it to random walk (1/100)</li>
- * </ul>
- */
- private void thinkActive()
- {
- L2Attackable npc = getActiveChar();
-
- // Update every 1s the _globalAggro counter to come close to 0
- if (_globalAggro != 0)
- {
- if (_globalAggro < 0)
- {
- _globalAggro++;
- }
- else
- {
- _globalAggro--;
- }
- }
-
- // Add all autoAttackable L2Character in L2Attackable Aggro Range to its _aggroList with 0 damage and 1 hate
- // A L2Attackable isn't aggressive during 10s after its spawn because _globalAggro is set to -10
- if (_globalAggro >= 0)
- {
- // Get all visible objects inside its Aggro Range
- Collection<L2Object> objs = npc.getKnownList().getKnownObjects().values();
-
- for (L2Object obj : objs)
- {
- if (!(obj instanceof L2Character) || (obj instanceof L2StaticObjectInstance))
- {
- continue;
- }
- L2Character target = (L2Character) obj;
-
- /*
- * Check to see if this is a festival mob spawn. If it is, then check to see if the aggro trigger is a festival participant...if so, move to attack it.
- */
- if ((npc instanceof L2FestivalMonsterInstance) && (obj instanceof L2PcInstance))
- {
- L2PcInstance targetPlayer = (L2PcInstance) obj;
-
- if (!(targetPlayer.isFestivalParticipant()))
- {
- continue;
- }
- }
-
- // TODO: The AI Script ought to handle aggro behaviors in onSee. Once implemented, aggro behaviors ought
- // to be removed from here. (Fulminus)
- // For each L2Character check if the target is autoattackable
- if (autoAttackCondition(target)) // check aggression
- {
- // Get the hate level of the L2Attackable against this L2Character target contained in _aggroList
- int hating = npc.getHating(target);
-
- // Add the attacker to the L2Attackable _aggroList with 0 damage and 1 hate
- if (hating == 0)
- {
- npc.addDamageHate(target, 0, 0);
- }
- }
- }
-
- // Chose a target from its aggroList
- L2Character hated;
- if (npc.isConfused())
- {
- hated = getAttackTarget(); // effect handles selection
- }
- else
- {
- hated = npc.getMostHated();
- }
-
- // Order to the L2Attackable to attack the target
- if ((hated != null) && !npc.isCoreAIDisabled())
- {
- // Get the hate level of the L2Attackable against this L2Character target contained in _aggroList
- int aggro = npc.getHating(hated);
-
- if ((aggro + _globalAggro) > 0)
- {
- // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
- if (!npc.isRunning())
- {
- npc.setRunning();
- }
-
- // Set the AI Intention to AI_INTENTION_ATTACK
- setIntention(CtrlIntention.AI_INTENTION_ATTACK, hated);
- }
-
- return;
- }
- }
-
- // Chance to forget attackers after some time
- if ((npc.getCurrentHp() == npc.getMaxHp()) && (npc.getCurrentMp() == npc.getMaxMp()) && !npc.getAttackByList().isEmpty() && (Rnd.nextInt(500) == 0))
- {
- npc.clearAggroList();
- npc.getAttackByList().clear();
- if (npc instanceof L2MonsterInstance)
- {
- if (((L2MonsterInstance) npc).hasMinions())
- {
- ((L2MonsterInstance) npc).getMinionList().deleteReusedMinions();
- }
- }
- }
-
- // Check if the actor is a L2GuardInstance
- if (npc instanceof L2GuardInstance)
- {
- // Order to the L2GuardInstance to return to its home location because there's no target to attack
- ((L2GuardInstance) npc).returnHome();
- }
-
- // If this is a festival monster, then it remains in the same location.
- if (npc instanceof L2FestivalMonsterInstance)
- {
- return;
- }
-
- // Check if the mob should not return to spawn point
- if (!npc.canReturnToSpawnPoint())
- {
- return;
- }
-
- // Minions following leader
- final L2Character leader = npc.getLeader();
- if ((leader != null) && !leader.isAlikeDead())
- {
- final int offset;
- final int minRadius = 30;
-
- if (npc.isRaidMinion())
- {
- offset = 500; // for Raids - need correction
- }
- else
- {
- offset = 200; // for normal minions - need correction :)
- }
-
- if (leader.isRunning())
- {
- npc.setRunning();
- }
- else
- {
- npc.setWalking();
- }
-
- if (npc.getPlanDistanceSq(leader) > (offset * offset))
- {
- int x1, y1, z1;
- x1 = Rnd.get(minRadius * 2, offset * 2); // x
- y1 = Rnd.get(x1, offset * 2); // distance
- y1 = (int) Math.sqrt((y1 * y1) - (x1 * x1)); // y
- if (x1 > (offset + minRadius))
- {
- x1 = (leader.getX() + x1) - offset;
- }
- else
- {
- x1 = (leader.getX() - x1) + minRadius;
- }
- if (y1 > (offset + minRadius))
- {
- y1 = (leader.getY() + y1) - offset;
- }
- else
- {
- y1 = (leader.getY() - y1) + minRadius;
- }
-
- z1 = leader.getZ();
- // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
- moveTo(x1, y1, z1);
- return;
- }
- else if (Rnd.nextInt(RANDOM_WALK_RATE) == 0)
- {
- for (L2Skill sk : _skillrender.getBuffSkills())
- {
- if (cast(sk))
- {
- return;
- }
- }
- }
- }
- // Order to the L2MonsterInstance to random walk (1/100)
- else if ((npc.getSpawn() != null) && (Rnd.nextInt(RANDOM_WALK_RATE) == 0) && !npc.isNoRndWalk())
- {
- int x1, y1, z1;
- final int range = Config.MAX_DRIFT_RANGE;
-
- for (L2Skill sk : _skillrender.getBuffSkills())
- {
- if (cast(sk))
- {
- return;
- }
- }
-
- // If NPC with random coord in territory
- if ((npc.getSpawn().getLocx() == 0) && (npc.getSpawn().getLocy() == 0))
- {
- // Calculate a destination point in the spawn area
- int p[] = TerritoryTable.getInstance().getRandomPoint(npc.getSpawn().getLocation());
- x1 = p[0];
- y1 = p[1];
- z1 = p[2];
-
- // Calculate the distance between the current position of the L2Character and the target (x,y)
- double distance2 = npc.getPlanDistanceSq(x1, y1);
-
- if (distance2 > ((range + range) * (range + range)))
- {
- npc.setisReturningToSpawnPoint(true);
- float delay = (float) Math.sqrt(distance2) / range;
- x1 = npc.getX() + (int) ((x1 - npc.getX()) / delay);
- y1 = npc.getY() + (int) ((y1 - npc.getY()) / delay);
- }
-
- // If NPC with random fixed coord, don't move (unless needs to return to spawnpoint)
- if ((TerritoryTable.getInstance().getProcMax(npc.getSpawn().getLocation()) > 0) && !npc.isReturningToSpawnPoint())
- {
- return;
- }
- }
- else
- {
- // If NPC with fixed coord
- x1 = npc.getSpawn().getLocx();
- y1 = npc.getSpawn().getLocy();
- z1 = npc.getSpawn().getLocz();
-
- if (!npc.isInsideRadius(x1, y1, range, false))
- {
- npc.setisReturningToSpawnPoint(true);
- }
- else
- {
- x1 = Rnd.nextInt(range * 2); // x
- y1 = Rnd.get(x1, range * 2); // distance
- y1 = (int) Math.sqrt((y1 * y1) - (x1 * x1)); // y
- x1 += npc.getSpawn().getLocx() - range;
- y1 += npc.getSpawn().getLocy() - range;
- z1 = npc.getZ();
- }
- }
-
- // _log.debug("Current pos ("+getX()+", "+getY()+"), moving to ("+x1+", "+y1+").");
- // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
- moveTo(x1, y1, z1);
- }
- }
-
- /**
- * Manage AI attack thinks of a L2Attackable (called by onEvtThink). <B><U> Actions</U> :</B>
- * <ul>
- * <li>Update the attack timeout if actor is running</li>
- * <li>If target is dead or timeout is expired, stop this attack and set the Intention to AI_INTENTION_ACTIVE</li>
- * <li>Call all L2Object of its Faction inside the Faction Range</li>
- * <li>Chose a target and order to attack it with magic skill or physical attack</li>
- * </ul>
- * TODO: Manage casting rules to healer mobs (like Ant Nurses)
- */
- private void thinkAttack()
- {
- final L2Attackable npc = getActiveChar();
- if (npc.isCastingNow())
- {
- return;
- }
-
- L2Character originalAttackTarget = getAttackTarget();
- // Check if target is dead or if timeout is expired to stop this attack
- if ((originalAttackTarget == null) || originalAttackTarget.isAlikeDead() || (_attackTimeout < GameTimeController.getInstance().getGameTicks()))
- {
- // Stop hating this target after the attack timeout or if target is dead
- if (originalAttackTarget != null)
- {
- npc.stopHating(originalAttackTarget);
- }
-
- // Set the AI Intention to AI_INTENTION_ACTIVE
- setIntention(AI_INTENTION_ACTIVE);
-
- npc.setWalking();
- return;
- }
-
- final int collision = npc.getTemplate().getCollisionRadius();
-
- // Handle all L2Object of its Faction inside the Faction Range
-
- String faction_id = getActiveChar().getFactionId();
- if ((faction_id != null) && !faction_id.isEmpty())
- {
- int factionRange = npc.getClanRange() + collision;
- // Go through all L2Object that belong to its faction
- Collection<L2Object> objs = npc.getKnownList().getKnownObjects().values();
-
- try
- {
- for (L2Object obj : objs)
- {
- if (obj instanceof L2Npc)
- {
- L2Npc called = (L2Npc) obj;
-
- // Handle SevenSigns mob Factions
- final String npcfaction = called.getFactionId();
- if ((npcfaction == null) || npcfaction.isEmpty())
- {
- continue;
- }
-
- boolean sevenSignFaction = false;
-
- // TODO: Unhardcode this by AI scripts (DrHouse)
- // Catacomb mobs should assist lilim and nephilim other than dungeon
- if ("c_dungeon_clan".equals(faction_id) && ("c_dungeon_lilim".equals(npcfaction) || "c_dungeon_nephi".equals(npcfaction)))
- {
- sevenSignFaction = true;
- }
- // Lilim mobs should assist other Lilim and catacomb mobs
- else if ("c_dungeon_lilim".equals(faction_id) && "c_dungeon_clan".equals(npcfaction))
- {
- sevenSignFaction = true;
- }
- // Nephilim mobs should assist other Nephilim and catacomb mobs
- else if ("c_dungeon_nephi".equals(faction_id) && "c_dungeon_clan".equals(npcfaction))
- {
- sevenSignFaction = true;
- }
-
- if (!faction_id.equals(npcfaction) && !sevenSignFaction)
- {
- continue;
- }
-
- // Check if the L2Object is inside the Faction Range of the actor
- if (npc.isInsideRadius(called, factionRange, true, false) && called.hasAI())
- {
- if ((Math.abs(originalAttackTarget.getZ() - called.getZ()) < 600) && npc.getAttackByList().contains(originalAttackTarget) && ((called.getAI()._intention == CtrlIntention.AI_INTENTION_IDLE) || (called.getAI()._intention == CtrlIntention.AI_INTENTION_ACTIVE)) && (called.getInstanceId() == npc.getInstanceId()))
- // && GeoData.getInstance().canSeeTarget(called, npc))
- {
- if (originalAttackTarget.isPlayable())
- {
- List<Quest> quests = called.getTemplate().getEventQuests(QuestEventType.ON_FACTION_CALL);
- if ((quests != null) && !quests.isEmpty())
- {
- L2PcInstance player = originalAttackTarget.getActingPlayer();
- boolean isSummon = originalAttackTarget.isSummon();
- for (Quest quest : quests)
- {
- quest.notifyFactionCall(called, getActiveChar(), player, isSummon);
- }
- }
- }
- else if ((called instanceof L2Attackable) && (getAttackTarget() != null) && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
- {
- ((L2Attackable) called).addDamageHate(getAttackTarget(), 0, npc.getHating(getAttackTarget()));
- called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, getAttackTarget());
- }
- }
- }
- }
- }
- }
- catch (NullPointerException e)
- {
- _log.warning(getClass().getSimpleName() + ": thinkAttack() faction call failed: " + e.getMessage());
- }
- }
-
- if (npc.isCoreAIDisabled())
- {
- return;
- }
-
- // Initialize data
- L2Character mostHate = npc.getMostHated();
- if (mostHate == null)
- {
- setIntention(AI_INTENTION_ACTIVE);
- return;
- }
-
- setAttackTarget(mostHate);
- npc.setTarget(mostHate);
-
- final int combinedCollision = collision + mostHate.getTemplate().getCollisionRadius();
-
- if (!_skillrender.getSuicideSkills().isEmpty() && ((int) ((npc.getCurrentHp() / npc.getMaxHp()) * 100) < 30))
- {
- final L2Skill skill = _skillrender.getSuicideSkills().get(Rnd.nextInt(_skillrender.getSuicideSkills().size()));
- if (Util.checkIfInRange(skill.getAffectRange(), getActiveChar(), mostHate, false) && (Rnd.get(100) < Rnd.get(npc.getMinSkillChance(), npc.getMaxSkillChance())))
- {
- if (cast(skill))
- {
- return;
- }
-
- for (L2Skill sk : _skillrender.getSuicideSkills())
- {
- if (cast(sk))
- {
- return;
- }
- }
- }
- }
-
- // ------------------------------------------------------
- // In case many mobs are trying to hit from same place, move a bit,
- // circling around the target
- // Note from Gnacik:
- // On l2js because of that sometimes mobs don't attack player only running
- // around player without any sense, so decrease chance for now
- if (!npc.isMovementDisabled() && (Rnd.nextInt(100) <= 3))
- {
- for (L2Object nearby : npc.getKnownList().getKnownObjects().values())
- {
- if ((nearby instanceof L2Attackable) && npc.isInsideRadius(nearby, collision, false, false) && (nearby != mostHate))
- {
- int newX = combinedCollision + Rnd.get(40);
- if (Rnd.nextBoolean())
- {
- newX = mostHate.getX() + newX;
- }
- else
- {
- newX = mostHate.getX() - newX;
- }
- int newY = combinedCollision + Rnd.get(40);
- if (Rnd.nextBoolean())
- {
- newY = mostHate.getY() + newY;
- }
- else
- {
- newY = mostHate.getY() - newY;
- }
-
- if (!npc.isInsideRadius(newX, newY, collision, false))
- {
- int newZ = npc.getZ() + 30;
- if ((Config.GEODATA == 0) || GeoData.getInstance().canMoveFromToTarget(npc.getX(), npc.getY(), npc.getZ(), newX, newY, newZ, npc.getInstanceId()))
- {
- moveTo(newX, newY, newZ);
- }
- }
- return;
- }
- }
- }
- // Dodge if its needed
- if (!npc.isMovementDisabled() && (npc.getCanDodge() > 0))
- {
- if (Rnd.get(100) <= npc.getCanDodge())
- {
- // Micht: kepping this one otherwise we should do 2 sqrt
- double distance2 = npc.getPlanDistanceSq(mostHate.getX(), mostHate.getY());
- if (Math.sqrt(distance2) <= (60 + combinedCollision))
- {
- int posX = npc.getX();
- int posY = npc.getY();
- int posZ = npc.getZ() + 30;
-
- if (originalAttackTarget.getX() < posX)
- {
- posX = posX + 300;
- }
- else
- {
- posX = posX - 300;
- }
-
- if (originalAttackTarget.getY() < posY)
- {
- posY = posY + 300;
- }
- else
- {
- posY = posY - 300;
- }
-
- if ((Config.GEODATA == 0) || GeoData.getInstance().canMoveFromToTarget(npc.getX(), npc.getY(), npc.getZ(), posX, posY, posZ, npc.getInstanceId()))
- {
- setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
- }
- return;
- }
- }
- }
-
- // ------------------------------------------------------------------------------
- // BOSS/Raid Minion Target Reconsider
- if (npc.isRaid() || npc.isRaidMinion())
- {
- chaostime++;
- if (npc instanceof L2RaidBossInstance)
- {
- if (!((L2MonsterInstance) npc).hasMinions())
- {
- if (chaostime > Config.RAID_CHAOS_TIME)
- {
- if (Rnd.get(100) <= (100 - ((npc.getCurrentHp() * 100) / npc.getMaxHp())))
- {
- aggroReconsider();
- chaostime = 0;
- return;
- }
- }
- }
- else
- {
- if (chaostime > Config.RAID_CHAOS_TIME)
- {
- if (Rnd.get(100) <= (100 - ((npc.getCurrentHp() * 200) / npc.getMaxHp())))
- {
- aggroReconsider();
- chaostime = 0;
- return;
- }
- }
- }
- }
- else if (npc instanceof L2GrandBossInstance)
- {
- if (chaostime > Config.GRAND_CHAOS_TIME)
- {
- double chaosRate = 100 - ((npc.getCurrentHp() * 300) / npc.getMaxHp());
- if (((chaosRate <= 10) && (Rnd.get(100) <= 10)) || ((chaosRate > 10) && (Rnd.get(100) <= chaosRate)))
- {
- aggroReconsider();
- chaostime = 0;
- return;
- }
- }
- }
- else
- {
- if (chaostime > Config.MINION_CHAOS_TIME)
- {
- if (Rnd.get(100) <= (100 - ((npc.getCurrentHp() * 200) / npc.getMaxHp())))
- {
- aggroReconsider();
- chaostime = 0;
- return;
- }
- }
- }
- }
-
- if (!_skillrender.getGeneralskills().isEmpty())
- {
- // -------------------------------------------------------------------------------
- // Heal Condition
- if (!_skillrender.getHealSkills().isEmpty())
- {
- double percentage = (npc.getCurrentHp() / npc.getMaxHp()) * 100;
- if (npc.isMinion())
- {
- L2Character leader = npc.getLeader();
- if ((leader != null) && !leader.isDead() && (Rnd.get(100) > ((leader.getCurrentHp() / leader.getMaxHp()) * 100)))
- {
- for (L2Skill sk : _skillrender.getHealSkills())
- {
- if (sk.getTargetType() == L2TargetType.TARGET_SELF)
- {
- continue;
- }
- if (!checkSkillCastConditions(sk))
- {
- continue;
- }
- if (!Util.checkIfInRange((sk.getCastRange() + collision + leader.getTemplate().getCollisionRadius()), npc, leader, false) && !isParty(sk) && !npc.isMovementDisabled())
- {
- moveToPawn(leader, sk.getCastRange() + collision + leader.getTemplate().getCollisionRadius());
- return;
- }
- if (GeoData.getInstance().canSeeTarget(npc, leader))
- {
- clientStopMoving(null);
- npc.setTarget(leader);
- clientStopMoving(null);
- npc.doCast(sk);
- return;
- }
- }
- }
- }
- if (Rnd.get(100) < ((100 - percentage) / 3))
- {
- for (L2Skill sk : _skillrender.getHealSkills())
- {
- if (!checkSkillCastConditions(sk))
- {
- continue;
- }
- clientStopMoving(null);
- npc.setTarget(npc);
- npc.doCast(sk);
- return;
- }
- }
- for (L2Skill sk : _skillrender.getHealSkills())
- {
- if (!checkSkillCastConditions(sk))
- {
- continue;
- }
- if (sk.getTargetType() == L2TargetType.TARGET_ONE)
- {
- for (L2Character obj : npc.getKnownList().getKnownCharactersInRadius(sk.getCastRange() + collision))
- {
- if (!(obj instanceof L2Attackable) || obj.isDead())
- {
- continue;
- }
-
- L2Attackable targets = ((L2Attackable) obj);
- if ((npc.getFactionId() != null) && !npc.getFactionId().equals(targets.getFactionId()))
- {
- continue;
- }
- percentage = (targets.getCurrentHp() / targets.getMaxHp()) * 100;
- if (Rnd.get(100) < ((100 - percentage) / 10))
- {
- if (GeoData.getInstance().canSeeTarget(npc, targets))
- {
- clientStopMoving(null);
- npc.setTarget(obj);
- npc.doCast(sk);
- return;
- }
- }
- }
- }
- if (isParty(sk))
- {
- clientStopMoving(null);
- npc.doCast(sk);
- return;
- }
- }
- }
- // -------------------------------------------------------------------------------
- // Res Skill Condition
- if (!_skillrender.getResSkills().isEmpty())
- {
- if (npc.isMinion())
- {
- L2Character leader = npc.getLeader();
- if ((leader != null) && leader.isDead())
- {
- for (L2Skill sk : _skillrender.getResSkills())
- {
- if (sk.getTargetType() == L2TargetType.TARGET_SELF)
- {
- continue;
- }
- if (!checkSkillCastConditions(sk))
- {
- continue;
- }
- if (!Util.checkIfInRange((sk.getCastRange() + collision + leader.getTemplate().getCollisionRadius()), npc, leader, false) && !isParty(sk) && !npc.isMovementDisabled())
- {
- moveToPawn(leader, sk.getCastRange() + collision + leader.getTemplate().getCollisionRadius());
- return;
- }
- if (GeoData.getInstance().canSeeTarget(npc, leader))
- {
- clientStopMoving(null);
- npc.setTarget(leader);
- npc.doCast(sk);
- return;
- }
- }
- }
- }
- for (L2Skill sk : _skillrender.getResSkills())
- {
- if (!checkSkillCastConditions(sk))
- {
- continue;
- }
- if (sk.getTargetType() == L2TargetType.TARGET_ONE)
- {
- for (L2Character obj : npc.getKnownList().getKnownCharactersInRadius(sk.getCastRange() + collision))
- {
- if (!(obj instanceof L2Attackable) || !obj.isDead())
- {
- continue;
- }
-
- L2Attackable targets = ((L2Attackable) obj);
- if ((npc.getFactionId() != null) && !npc.getFactionId().equals(targets.getFactionId()))
- {
- continue;
- }
- if (Rnd.get(100) < 10)
- {
- if (GeoData.getInstance().canSeeTarget(npc, targets))
- {
- clientStopMoving(null);
- npc.setTarget(obj);
- npc.doCast(sk);
- return;
- }
- }
- }
- }
- if (isParty(sk))
- {
- clientStopMoving(null);
- L2Object target = getAttackTarget();
- npc.setTarget(npc);
- npc.doCast(sk);
- npc.setTarget(target);
- return;
- }
- }
- }
- }
-
- double dist = Math.sqrt(npc.getPlanDistanceSq(mostHate.getX(), mostHate.getY()));
- int dist2 = (int) dist - collision;
- int range = npc.getPhysicalAttackRange() + combinedCollision;
- if (mostHate.isMoving())
- {
- range = range + 50;
- if (npc.isMoving())
- {
- range = range + 50;
- }
- }
-
- // -------------------------------------------------------------------------------
- // Immobilize Condition
- if ((npc.isMovementDisabled() && ((dist > range) || mostHate.isMoving())) || ((dist > range) && mostHate.isMoving()))
- {
- movementDisable();
- return;
- }
-
- setTimepass(0);
- // --------------------------------------------------------------------------------
- // Skill Use
- if (!_skillrender.getGeneralskills().isEmpty())
- {
- if (Rnd.get(100) < Rnd.get(npc.getMinSkillChance(), npc.getMaxSkillChance()))
- {
- L2Skill skills = _skillrender.getGeneralskills().get(Rnd.nextInt(_skillrender.getGeneralskills().size()));
- if (cast(skills))
- {
- return;
- }
- for (L2Skill sk : _skillrender.getGeneralskills())
- {
- if (cast(sk))
- {
- return;
- }
- }
- }
-
- // --------------------------------------------------------------------------------
- // Long/Short Range skill usage.
- if (npc.hasLSkill() || npc.hasSSkill())
- {
- final List<L2Skill> shortRangeSkills = shortRangeSkillRender();
- if (!shortRangeSkills.isEmpty() && npc.hasSSkill() && (dist2 <= 150) && (Rnd.get(100) <= npc.getSSkillChance()))
- {
- final L2Skill shortRangeSkill = shortRangeSkills.get(Rnd.get(shortRangeSkills.size()));
- if ((shortRangeSkill != null) && cast(shortRangeSkill))
- {
- return;
- }
- for (L2Skill sk : shortRangeSkills)
- {
- if ((sk != null) && cast(sk))
- {
- return;
- }
- }
- }
-
- final List<L2Skill> longRangeSkills = longRangeSkillRender();
- if (!longRangeSkills.isEmpty() && npc.hasLSkill() && (dist2 > 150) && (Rnd.get(100) <= npc.getLSkillChance()))
- {
- final L2Skill longRangeSkill = longRangeSkills.get(Rnd.get(longRangeSkills.size()));
- if ((longRangeSkill != null) && cast(longRangeSkill))
- {
- return;
- }
- for (L2Skill sk : longRangeSkills)
- {
- if ((sk != null) && cast(sk))
- {
- return;
- }
- }
- }
- }
- }
-
- // --------------------------------------------------------------------------------
- // Starts Melee or Primary Skill
- if ((dist2 > range) || !GeoData.getInstance().canSeeTarget(npc, mostHate))
- {
- if (npc.isMovementDisabled())
- {
- targetReconsider();
- }
- else if (getAttackTarget() != null)
- {
- if (getAttackTarget().isMoving())
- {
- range -= 100;
- }
- if (range < 5)
- {
- range = 5;
- }
- moveToPawn(getAttackTarget(), range);
- }
- return;
- }
-
- melee(npc.getPrimarySkillId());
- }
-
- private void melee(int type)
- {
- if (type != 0)
- {
- switch (type)
- {
- case -1:
- {
- if (_skillrender.getGeneralskills() != null)
- {
- for (L2Skill sk : _skillrender.getGeneralskills())
- {
- if (cast(sk))
- {
- return;
- }
- }
- }
- break;
- }
- case 1:
- {
- for (L2Skill sk : _skillrender.getAtkSkills())
- {
- if (cast(sk))
- {
- return;
- }
- }
- break;
- }
- default:
- {
- for (L2Skill sk : _skillrender.getGeneralskills())
- {
- if (sk.getId() == getActiveChar().getPrimarySkillId())
- {
- if (cast(sk))
- {
- return;
- }
- }
- }
- }
- break;
- }
- }
-
- _accessor.doAttack(getAttackTarget());
- }
-
- private boolean cast(L2Skill sk)
- {
- if (sk == null)
- {
- return false;
- }
-
- final L2Attackable caster = getActiveChar();
-
- if (caster.isCastingNow() && !sk.isSimultaneousCast())
- {
- return false;
- }
-
- if (!checkSkillCastConditions(sk))
- {
- return false;
- }
- if (getAttackTarget() == null)
- {
- if (caster.getMostHated() != null)
- {
- setAttackTarget(caster.getMostHated());
- }
- }
- L2Character attackTarget = getAttackTarget();
- if (attackTarget == null)
- {
- return false;
- }
- double dist = Math.sqrt(caster.getPlanDistanceSq(attackTarget.getX(), attackTarget.getY()));
- double dist2 = dist - attackTarget.getTemplate().getCollisionRadius();
- double range = caster.getPhysicalAttackRange() + caster.getTemplate().getCollisionRadius() + attackTarget.getTemplate().getCollisionRadius();
- double srange = sk.getCastRange() + caster.getTemplate().getCollisionRadius();
- if (attackTarget.isMoving())
- {
- dist2 = dist2 - 30;
- }
-
- switch (sk.getSkillType())
- {
- case BUFF:
- {
- if (caster.getFirstEffect(sk) == null)
- {
- clientStopMoving(null);
- // L2Object target = attackTarget;
- caster.setTarget(caster);
- caster.doCast(sk);
- // _actor.setTarget(target);
- return true;
- }
- // ----------------------------------------
- // If actor already have buff, start looking at others same faction mob to cast
- if (sk.getTargetType() == L2TargetType.TARGET_SELF)
- {
- return false;
- }
- if (sk.getTargetType() == L2TargetType.TARGET_ONE)
- {
- L2Character target = effectTargetReconsider(sk, true);
- if (target != null)
- {
- clientStopMoving(null);
- L2Object targets = attackTarget;
- caster.setTarget(target);
- caster.doCast(sk);
- caster.setTarget(targets);
- return true;
- }
- }
- if (canParty(sk))
- {
- clientStopMoving(null);
- L2Object targets = attackTarget;
- caster.setTarget(caster);
- caster.doCast(sk);
- caster.setTarget(targets);
- return true;
- }
- break;
- }
- case HEAL:
- case HEAL_PERCENT:
- {
- double percentage = (caster.getCurrentHp() / caster.getMaxHp()) * 100;
- if (caster.isMinion() && (sk.getTargetType() != L2TargetType.TARGET_SELF))
- {
- L2Character leader = caster.getLeader();
- if ((leader != null) && !leader.isDead() && (Rnd.get(100) > ((leader.getCurrentHp() / leader.getMaxHp()) * 100)))
- {
- if (!Util.checkIfInRange((sk.getCastRange() + caster.getTemplate().getCollisionRadius() + leader.getTemplate().getCollisionRadius()), caster, leader, false) && !isParty(sk) && !caster.isMovementDisabled())
- {
- moveToPawn(leader, sk.getCastRange() + caster.getTemplate().getCollisionRadius() + leader.getTemplate().getCollisionRadius());
- }
- if (GeoData.getInstance().canSeeTarget(caster, leader))
- {
- clientStopMoving(null);
- caster.setTarget(leader);
- caster.doCast(sk);
- return true;
- }
- }
- }
- if (Rnd.get(100) < ((100 - percentage) / 3))
- {
- clientStopMoving(null);
- caster.setTarget(caster);
- caster.doCast(sk);
- return true;
- }
-
- if (sk.getTargetType() == L2TargetType.TARGET_ONE)
- {
- for (L2Character obj : caster.getKnownList().getKnownCharactersInRadius(sk.getCastRange() + caster.getTemplate().getCollisionRadius()))
- {
- if (!(obj instanceof L2Attackable) || obj.isDead())
- {
- continue;
- }
-
- L2Attackable targets = ((L2Attackable) obj);
- if ((caster.getFactionId() != null) && !caster.getFactionId().equals(targets.getFactionId()))
- {
- continue;
- }
- percentage = (targets.getCurrentHp() / targets.getMaxHp()) * 100;
- if (Rnd.get(100) < ((100 - percentage) / 10))
- {
- if (GeoData.getInstance().canSeeTarget(caster, targets))
- {
- clientStopMoving(null);
- caster.setTarget(obj);
- caster.doCast(sk);
- return true;
- }
- }
- }
- }
- if (isParty(sk))
- {
- for (L2Character obj : caster.getKnownList().getKnownCharactersInRadius(sk.getAffectRange() + caster.getTemplate().getCollisionRadius()))
- {
- if (!(obj instanceof L2Attackable))
- {
- continue;
- }
- L2Npc targets = ((L2Npc) obj);
- if ((caster.getFactionId() != null) && targets.getFactionId().equals(caster.getFactionId()))
- {
- if ((obj.getCurrentHp() < obj.getMaxHp()) && (Rnd.get(100) <= 20))
- {
- clientStopMoving(null);
- caster.setTarget(caster);
- caster.doCast(sk);
- return true;
- }
- }
- }
- }
- break;
- }
- case RESURRECT:
- {
- if (!isParty(sk))
- {
- if (caster.isMinion() && (sk.getTargetType() != L2TargetType.TARGET_SELF))
- {
- L2Character leader = caster.getLeader();
- if ((leader != null) && leader.isDead())
- {
- if (!Util.checkIfInRange((sk.getCastRange() + caster.getTemplate().getCollisionRadius() + leader.getTemplate().getCollisionRadius()), caster, leader, false) && !isParty(sk) && !caster.isMovementDisabled())
- {
- moveToPawn(leader, sk.getCastRange() + caster.getTemplate().getCollisionRadius() + leader.getTemplate().getCollisionRadius());
- }
- }
- if (GeoData.getInstance().canSeeTarget(caster, leader))
- {
- clientStopMoving(null);
- caster.setTarget(leader);
- caster.doCast(sk);
- return true;
- }
- }
-
- for (L2Character obj : caster.getKnownList().getKnownCharactersInRadius(sk.getCastRange() + caster.getTemplate().getCollisionRadius()))
- {
- if (!(obj instanceof L2Attackable) || !obj.isDead())
- {
- continue;
- }
-
- L2Attackable targets = ((L2Attackable) obj);
- if ((caster.getFactionId() != null) && !caster.getFactionId().equals(targets.getFactionId()))
- {
- continue;
- }
- if (Rnd.get(100) < 10)
- {
- if (GeoData.getInstance().canSeeTarget(caster, targets))
- {
- clientStopMoving(null);
- caster.setTarget(obj);
- caster.doCast(sk);
- return true;
- }
- }
- }
- }
- else if (isParty(sk))
- {
- for (L2Character obj : caster.getKnownList().getKnownCharactersInRadius(sk.getAffectRange() + caster.getTemplate().getCollisionRadius()))
- {
- if (!(obj instanceof L2Attackable))
- {
- continue;
- }
- L2Npc targets = ((L2Npc) obj);
- if ((caster.getFactionId() != null) && caster.getFactionId().equals(targets.getFactionId()))
- {
- if ((obj.getCurrentHp() < obj.getMaxHp()) && (Rnd.get(100) <= 20))
- {
- clientStopMoving(null);
- caster.setTarget(caster);
- caster.doCast(sk);
- return true;
- }
- }
- }
- }
- break;
- }
- case DEBUFF:
- case POISON:
- case DOT:
- case MDOT:
- case BLEED:
- {
- if (GeoData.getInstance().canSeeTarget(caster, attackTarget) && !canAOE(sk) && !attackTarget.isDead() && (dist2 <= srange))
- {
- if (attackTarget.getFirstEffect(sk) == null)
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- }
- else if (canAOE(sk))
- {
- if ((sk.getTargetType() == L2TargetType.TARGET_AURA) || (sk.getTargetType() == L2TargetType.TARGET_BEHIND_AURA) || (sk.getTargetType() == L2TargetType.TARGET_FRONT_AURA) || (sk.getTargetType() == L2TargetType.TARGET_AURA_CORPSE_MOB))
- {
- clientStopMoving(null);
- // L2Object target = attackTarget;
- // _actor.setTarget(_actor);
- caster.doCast(sk);
- // _actor.setTarget(target);
- return true;
- }
- if (((sk.getTargetType() == L2TargetType.TARGET_AREA) || (sk.getTargetType() == L2TargetType.TARGET_BEHIND_AREA) || (sk.getTargetType() == L2TargetType.TARGET_FRONT_AREA)) && GeoData.getInstance().canSeeTarget(caster, attackTarget) && !attackTarget.isDead() && (dist2 <= srange))
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- }
- else if (sk.getTargetType() == L2TargetType.TARGET_ONE)
- {
- L2Character target = effectTargetReconsider(sk, false);
- if (target != null)
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- }
- break;
- }
- case SLEEP:
- {
- if (sk.getTargetType() == L2TargetType.TARGET_ONE)
- {
- if (!attackTarget.isDead() && (dist2 <= srange))
- {
- if ((dist2 > range) || attackTarget.isMoving())
- {
- if (attackTarget.getFirstEffect(sk) == null)
- {
- clientStopMoving(null);
- // _actor.setTarget(attackTarget);
- caster.doCast(sk);
- return true;
- }
- }
- }
-
- L2Character target = effectTargetReconsider(sk, false);
- if (target != null)
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- }
- else if (canAOE(sk))
- {
- if ((sk.getTargetType() == L2TargetType.TARGET_AURA) || (sk.getTargetType() == L2TargetType.TARGET_BEHIND_AURA) || (sk.getTargetType() == L2TargetType.TARGET_FRONT_AURA))
- {
- clientStopMoving(null);
- // L2Object target = attackTarget;
- // _actor.setTarget(_actor);
- caster.doCast(sk);
- // _actor.setTarget(target);
- return true;
- }
- if (((sk.getTargetType() == L2TargetType.TARGET_AREA) || (sk.getTargetType() == L2TargetType.TARGET_BEHIND_AREA) || (sk.getTargetType() == L2TargetType.TARGET_FRONT_AREA)) && GeoData.getInstance().canSeeTarget(caster, attackTarget) && !attackTarget.isDead() && (dist2 <= srange))
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- }
- break;
- }
- case ROOT:
- case STUN:
- case PARALYZE:
- {
- if (GeoData.getInstance().canSeeTarget(caster, attackTarget) && !canAOE(sk) && (dist2 <= srange))
- {
- if (attackTarget.getFirstEffect(sk) == null)
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- }
- else if (canAOE(sk))
- {
- if ((sk.getTargetType() == L2TargetType.TARGET_AURA) || (sk.getTargetType() == L2TargetType.TARGET_BEHIND_AURA) || (sk.getTargetType() == L2TargetType.TARGET_FRONT_AURA))
- {
- clientStopMoving(null);
- // L2Object target = attackTarget;
- // _actor.setTarget(_actor);
- caster.doCast(sk);
- // _actor.setTarget(target);
- return true;
- }
- else if (((sk.getTargetType() == L2TargetType.TARGET_AREA) || (sk.getTargetType() == L2TargetType.TARGET_BEHIND_AREA) || (sk.getTargetType() == L2TargetType.TARGET_FRONT_AREA)) && GeoData.getInstance().canSeeTarget(caster, attackTarget) && !attackTarget.isDead() && (dist2 <= srange))
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- }
- else if (sk.getTargetType() == L2TargetType.TARGET_ONE)
- {
- L2Character target = effectTargetReconsider(sk, false);
- if (target != null)
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- }
- break;
- }
- case MUTE:
- case FEAR:
- {
- if (GeoData.getInstance().canSeeTarget(caster, attackTarget) && !canAOE(sk) && (dist2 <= srange))
- {
- if (attackTarget.getFirstEffect(sk) == null)
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- }
- else if (canAOE(sk))
- {
- if ((sk.getTargetType() == L2TargetType.TARGET_AURA) || (sk.getTargetType() == L2TargetType.TARGET_BEHIND_AURA) || (sk.getTargetType() == L2TargetType.TARGET_FRONT_AURA))
- {
- clientStopMoving(null);
- // L2Object target = attackTarget;
- // _actor.setTarget(_actor);
- caster.doCast(sk);
- // _actor.setTarget(target);
- return true;
- }
- if (((sk.getTargetType() == L2TargetType.TARGET_AREA) || (sk.getTargetType() == L2TargetType.TARGET_BEHIND_AREA) || (sk.getTargetType() == L2TargetType.TARGET_FRONT_AREA)) && GeoData.getInstance().canSeeTarget(caster, attackTarget) && !attackTarget.isDead() && (dist2 <= srange))
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- }
- else if (sk.getTargetType() == L2TargetType.TARGET_ONE)
- {
- L2Character target = effectTargetReconsider(sk, false);
- if (target != null)
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- }
- break;
- }
- case PDAM:
- case MDAM:
- case BLOW:
- case DRAIN:
- case CHARGEDAM:
- case FATAL:
- case DEATHLINK:
- case MANADAM:
- case CPDAMPERCENT:
- {
- if (!canAura(sk))
- {
- if (GeoData.getInstance().canSeeTarget(caster, attackTarget) && !attackTarget.isDead() && (dist2 <= srange))
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
-
- L2Character target = skillTargetReconsider(sk);
- if (target != null)
- {
- clientStopMoving(null);
- L2Object targets = attackTarget;
- caster.setTarget(target);
- caster.doCast(sk);
- caster.setTarget(targets);
- return true;
- }
- }
- else
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- break;
- }
- default:
- {
- if (sk.hasEffectType(L2EffectType.CANCEL, L2EffectType.CANCEL_ALL, L2EffectType.NEGATE))
- {
- // decrease cancel probability
- if (Rnd.get(50) != 0)
- {
- return true;
- }
-
- if (sk.getTargetType() == L2TargetType.TARGET_ONE)
- {
- if ((attackTarget.getFirstEffect(L2EffectType.BUFF) != null) && GeoData.getInstance().canSeeTarget(caster, attackTarget) && !attackTarget.isDead() && (dist2 <= srange))
- {
- clientStopMoving(null);
- // L2Object target = attackTarget;
- // _actor.setTarget(_actor);
- caster.doCast(sk);
- // _actor.setTarget(target);
- return true;
- }
- L2Character target = effectTargetReconsider(sk, false);
- if (target != null)
- {
- clientStopMoving(null);
- L2Object targets = attackTarget;
- caster.setTarget(target);
- caster.doCast(sk);
- caster.setTarget(targets);
- return true;
- }
- }
- else if (canAOE(sk))
- {
- if (((sk.getTargetType() == L2TargetType.TARGET_AURA) || (sk.getTargetType() == L2TargetType.TARGET_BEHIND_AURA) || (sk.getTargetType() == L2TargetType.TARGET_FRONT_AURA)) && GeoData.getInstance().canSeeTarget(caster, attackTarget))
-
- {
- clientStopMoving(null);
- // L2Object target = attackTarget;
- // _actor.setTarget(_actor);
- caster.doCast(sk);
- // _actor.setTarget(target);
- return true;
- }
- else if (((sk.getTargetType() == L2TargetType.TARGET_AREA) || (sk.getTargetType() == L2TargetType.TARGET_BEHIND_AREA) || (sk.getTargetType() == L2TargetType.TARGET_FRONT_AREA)) && GeoData.getInstance().canSeeTarget(caster, attackTarget) && !attackTarget.isDead() && (dist2 <= srange))
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
- }
- }
- if (!canAura(sk))
- {
-
- if (GeoData.getInstance().canSeeTarget(caster, attackTarget) && !attackTarget.isDead() && (dist2 <= srange))
- {
- clientStopMoving(null);
- caster.doCast(sk);
- return true;
- }
-
- L2Character target = skillTargetReconsider(sk);
- if (target != null)
- {
- clientStopMoving(null);
- L2Object targets = attackTarget;
- caster.setTarget(target);
- caster.doCast(sk);
- caster.setTarget(targets);
- return true;
- }
- }
- else
- {
- clientStopMoving(null);
- // L2Object targets = attackTarget;
- // _actor.setTarget(_actor);
- caster.doCast(sk);
- // _actor.setTarget(targets);
- return true;
- }
- }
- break;
- }
-
- return false;
- }
-
- /**
- * This AI task will start when ACTOR cannot move and attack range larger than distance
- */
- private void movementDisable()
- {
- final L2Attackable npc = getActiveChar();
- double dist = 0;
- double dist2 = 0;
- int range = 0;
- try
- {
- if (npc.getTarget() == null)
- {
- npc.setTarget(getAttackTarget());
- }
- dist = Math.sqrt(npc.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY()));
- dist2 = dist - npc.getTemplate().getCollisionRadius();
- range = npc.getPhysicalAttackRange() + npc.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius();
- if (getAttackTarget().isMoving())
- {
- dist = dist - 30;
- if (npc.isMoving())
- {
- dist = dist - 50;
- }
- }
-
- // Check if activeChar has any skill
- if (!_skillrender.getGeneralskills().isEmpty())
- {
- // -------------------------------------------------------------
- // Try to stop the target or disable the target as priority
- int random = Rnd.get(100);
- if (!_skillrender.getImmobiliseSkills().isEmpty() && !getAttackTarget().isImmobilized() && (random < 2))
- {
- for (L2Skill sk : _skillrender.getImmobiliseSkills())
- {
- if (!checkSkillCastConditions(sk) || (((sk.getCastRange() + npc.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius()) <= dist2) && !canAura(sk)))
- {
- continue;
- }
- if (!GeoData.getInstance().canSeeTarget(npc, getAttackTarget()))
- {
- continue;
- }
- if (getAttackTarget().getFirstEffect(sk) == null)
- {
- clientStopMoving(null);
- // L2Object target = getAttackTarget();
- // _actor.setTarget(_actor);
- npc.doCast(sk);
- // _actor.setTarget(target);
- return;
- }
- }
- }
- // -------------------------------------------------------------
- // Same as Above, but with Mute/FEAR etc....
- if (!_skillrender.getCostOverTimeSkills().isEmpty() && (random < 5))
- {
- for (L2Skill sk : _skillrender.getCostOverTimeSkills())
- {
- if (!checkSkillCastConditions(sk) || (((sk.getCastRange() + npc.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius()) <= dist2) && !canAura(sk)))
- {
- continue;
- }
- if (!GeoData.getInstance().canSeeTarget(npc, getAttackTarget()))
- {
- continue;
- }
- if (getAttackTarget().getFirstEffect(sk) == null)
- {
- clientStopMoving(null);
- // L2Object target = getAttackTarget();
- // _actor.setTarget(_actor);
- npc.doCast(sk);
- // _actor.setTarget(target);
- return;
- }
- }
- }
- // -------------------------------------------------------------
- if (!_skillrender.getDebuffSkills().isEmpty() && (random < 8))
- {
- for (L2Skill sk : _skillrender.getDebuffSkills())
- {
- if (!checkSkillCastConditions(sk) || (((sk.getCastRange() + npc.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius()) <= dist2) && !canAura(sk)))
- {
- continue;
- }
- if (!GeoData.getInstance().canSeeTarget(npc, getAttackTarget()))
- {
- continue;
- }
- if (getAttackTarget().getFirstEffect(sk) == null)
- {
- clientStopMoving(null);
- // L2Object target = getAttackTarget();
- // _actor.setTarget(_actor);
- npc.doCast(sk);
- // _actor.setTarget(target);
- return;
- }
- }
- }
- // -------------------------------------------------------------
- // Some side effect skill like CANCEL or NEGATE
- if (!_skillrender.getNegativeSkills().isEmpty() && (random < 9))
- {
- for (L2Skill sk : _skillrender.getNegativeSkills())
- {
- if (!checkSkillCastConditions(sk) || (((sk.getCastRange() + npc.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius()) <= dist2) && !canAura(sk)))
- {
- continue;
- }
- if (!GeoData.getInstance().canSeeTarget(npc, getAttackTarget()))
- {
- continue;
- }
- if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
- {
- clientStopMoving(null);
- // L2Object target = getAttackTarget();
- // _actor.setTarget(_actor);
- npc.doCast(sk);
- // _actor.setTarget(target);
- return;
- }
- }
- }
- // -------------------------------------------------------------
- // Start ATK SKILL when nothing can be done
- if (!_skillrender.getAtkSkills().isEmpty() && (npc.isMovementDisabled() || (npc.getAiType() == AIType.MAGE) || (npc.getAiType() == AIType.HEALER)))
- {
- for (L2Skill sk : _skillrender.getAtkSkills())
- {
- if (!checkSkillCastConditions(sk) || (((sk.getCastRange() + npc.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius()) <= dist2) && !canAura(sk)))
- {
- continue;
- }
- if (!GeoData.getInstance().canSeeTarget(npc, getAttackTarget()))
- {
- continue;
- }
- clientStopMoving(null);
- // L2Object target = getAttackTarget();
- // _actor.setTarget(_actor);
- npc.doCast(sk);
- // _actor.setTarget(target);
- return;
- }
- }
- // -------------------------------------------------------------
- // if there is no ATK skill to use, then try Universal skill
- // @formatter:off
- /*
- for(L2Skill sk:_skillrender.getUniversalSkills())
- {
- if(sk.getMpConsume()>=_actor.getCurrentMp()
- || _actor.isSkillDisabled(sk.getId())
- ||(sk.getCastRange()+ _actor.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius() <= dist2 && !canAura(sk))
- ||(sk.isMagic()&&_actor.isMuted())
- ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
- {
- continue;
- }
- if(!GeoData.getInstance().canSeeTarget(_actor,getAttackTarget()))
- continue;
- clientStopMoving(null);
- L2Object target = getAttackTarget();
- //_actor.setTarget(_actor);
- _actor.doCast(sk);
- //_actor.setTarget(target);
- return;
- }
- */
- // @formatter:on
- }
- // timepass = timepass + 1;
- if (npc.isMovementDisabled())
- {
- // timepass = 0;
- targetReconsider();
-
- return;
- }
- // else if(timepass>=5)
- // {
- // timepass = 0;
- // AggroReconsider();
- // return;
- // }
-
- if ((dist > range) || !GeoData.getInstance().canSeeTarget(npc, getAttackTarget()))
- {
- if (getAttackTarget().isMoving())
- {
- range -= 100;
- }
- if (range < 5)
- {
- range = 5;
- }
- moveToPawn(getAttackTarget(), range);
- return;
-
- }
-
- melee(npc.getPrimarySkillId());
- }
- catch (NullPointerException e)
- {
- setIntention(AI_INTENTION_ACTIVE);
- _log.warning(getClass().getSimpleName() + ": " + this + " - failed executing movementDisable(): " + e.getMessage());
- return;
- }
- }
-
- /**
- * @param skill the skill to check.
- * @return {@code true} if the skill is available for casting {@code false} otherwise.
- */
- private boolean checkSkillCastConditions(L2Skill skill)
- {
- // Not enough MP.
- if (skill.getMpConsume() >= getActiveChar().getCurrentMp())
- {
- return false;
- }
- // Character is in "skill disabled" mode.
- if (getActiveChar().isSkillDisabled(skill))
- {
- return false;
- }
- // If is a static skill and magic skill and character is muted or is a physical skill muted and character is physically muted.
- if (!skill.isStatic() && ((skill.isMagic() && getActiveChar().isMuted()) || getActiveChar().isPhysicalMuted()))
- {
- return false;
- }
- return true;
- }
-
- private L2Character effectTargetReconsider(L2Skill sk, boolean positive)
- {
- if (sk == null)
- {
- return null;
- }
- L2Attackable actor = getActiveChar();
- if (!sk.hasEffectType(L2EffectType.CANCEL, L2EffectType.CANCEL_ALL, L2EffectType.NEGATE))
- {
- if (!positive)
- {
- double dist = 0;
- double dist2 = 0;
- int range = 0;
-
- for (L2Character obj : actor.getAttackByList())
- {
- if ((obj == null) || obj.isDead() || !GeoData.getInstance().canSeeTarget(actor, obj) || (obj == getAttackTarget()))
- {
- continue;
- }
- try
- {
- actor.setTarget(getAttackTarget());
- dist = Math.sqrt(actor.getPlanDistanceSq(obj.getX(), obj.getY()));
- dist2 = dist - actor.getTemplate().getCollisionRadius();
- range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + obj.getTemplate().getCollisionRadius();
- if (obj.isMoving())
- {
- dist2 = dist2 - 70;
- }
- }
- catch (NullPointerException e)
- {
- continue;
- }
- if (dist2 <= range)
- {
- if (getAttackTarget().getFirstEffect(sk) == null)
- {
- return obj;
- }
- }
- }
-
- // ----------------------------------------------------------------------
- // If there is nearby Target with aggro, start going on random target that is attackable
- for (L2Character obj : actor.getKnownList().getKnownCharactersInRadius(range))
- {
- if (obj.isDead() || !GeoData.getInstance().canSeeTarget(actor, obj))
- {
- continue;
- }
- try
- {
- actor.setTarget(getAttackTarget());
- dist = Math.sqrt(actor.getPlanDistanceSq(obj.getX(), obj.getY()));
- dist2 = dist;
- range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + obj.getTemplate().getCollisionRadius();
- if (obj.isMoving())
- {
- dist2 = dist2 - 70;
- }
- }
- catch (NullPointerException e)
- {
- continue;
- }
- if (obj instanceof L2Attackable)
- {
- if ((actor.getEnemyClan() != null) && actor.getEnemyClan().equals(((L2Attackable) obj).getClan()))
- {
- if (dist2 <= range)
- {
- if (getAttackTarget().getFirstEffect(sk) == null)
- {
- return obj;
- }
- }
- }
- }
- if ((obj instanceof L2PcInstance) || (obj instanceof L2Summon))
- {
- if (dist2 <= range)
- {
- if (getAttackTarget().getFirstEffect(sk) == null)
- {
- return obj;
- }
- }
- }
- }
- }
- else if (positive)
- {
- double dist = 0;
- double dist2 = 0;
- int range = 0;
- for (L2Character obj : actor.getKnownList().getKnownCharactersInRadius(range))
- {
- if (!(obj instanceof L2Attackable) || obj.isDead() || !GeoData.getInstance().canSeeTarget(actor, obj))
- {
- continue;
- }
-
- L2Attackable targets = ((L2Attackable) obj);
- if ((actor.getFactionId() != null) && !actor.getFactionId().equals(targets.getFactionId()))
- {
- continue;
- }
-
- try
- {
- actor.setTarget(getAttackTarget());
- dist = Math.sqrt(actor.getPlanDistanceSq(obj.getX(), obj.getY()));
- dist2 = dist - actor.getTemplate().getCollisionRadius();
- range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + obj.getTemplate().getCollisionRadius();
- if (obj.isMoving())
- {
- dist2 = dist2 - 70;
- }
- }
- catch (NullPointerException e)
- {
- continue;
- }
- if (dist2 <= range)
- {
- if (obj.getFirstEffect(sk) == null)
- {
- return obj;
- }
- }
- }
- }
- }
- else
- {
- double dist = 0;
- double dist2 = 0;
- int range = 0;
- range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius();
- for (L2Character obj : actor.getKnownList().getKnownCharactersInRadius(range))
- {
- if ((obj == null) || obj.isDead() || !GeoData.getInstance().canSeeTarget(actor, obj))
- {
- continue;
- }
- try
- {
- actor.setTarget(getAttackTarget());
- dist = Math.sqrt(actor.getPlanDistanceSq(obj.getX(), obj.getY()));
- dist2 = dist - actor.getTemplate().getCollisionRadius();
- range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + obj.getTemplate().getCollisionRadius();
- if (obj.isMoving())
- {
- dist2 = dist2 - 70;
- }
- }
- catch (NullPointerException e)
- {
- continue;
- }
- if (obj instanceof L2Attackable)
- {
- if ((actor.getEnemyClan() != null) && actor.getEnemyClan().equals(((L2Attackable) obj).getClan()))
- {
- if (dist2 <= range)
- {
- if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
- {
- return obj;
- }
- }
- }
- }
- if ((obj instanceof L2PcInstance) || (obj instanceof L2Summon))
- {
-
- if (dist2 <= range)
- {
- if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
- {
- return obj;
- }
- }
- }
- }
- }
- return null;
- }
-
- private L2Character skillTargetReconsider(L2Skill sk)
- {
- double dist = 0;
- double dist2 = 0;
- int range = 0;
- L2Attackable actor = getActiveChar();
- if (actor.getHateList() != null)
- {
- for (L2Character obj : actor.getHateList())
- {
- if ((obj == null) || !GeoData.getInstance().canSeeTarget(actor, obj) || obj.isDead())
- {
- continue;
- }
- try
- {
- actor.setTarget(getAttackTarget());
- dist = Math.sqrt(actor.getPlanDistanceSq(obj.getX(), obj.getY()));
- dist2 = dist - actor.getTemplate().getCollisionRadius();
- range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius();
- // if(obj.isMoving())
- // dist2 = dist2 - 40;
- }
- catch (NullPointerException e)
- {
- continue;
- }
- if (dist2 <= range)
- {
- return obj;
- }
- }
- }
-
- if (!(actor instanceof L2GuardInstance))
- {
- Collection<L2Object> objs = actor.getKnownList().getKnownObjects().values();
- for (L2Object target : objs)
- {
- try
- {
- actor.setTarget(getAttackTarget());
- dist = Math.sqrt(actor.getPlanDistanceSq(target.getX(), target.getY()));
- dist2 = dist;
- range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius();
- // if(obj.isMoving())
- // dist2 = dist2 - 40;
- }
- catch (NullPointerException e)
- {
- continue;
- }
- L2Character obj = null;
- if (target instanceof L2Character)
- {
- obj = (L2Character) target;
- }
- if ((obj == null) || !GeoData.getInstance().canSeeTarget(actor, obj) || (dist2 > range))
- {
- continue;
- }
- if (obj instanceof L2PcInstance)
- {
- return obj;
-
- }
- if (obj instanceof L2Attackable)
- {
- if ((actor.getEnemyClan() != null) && actor.getEnemyClan().equals(((L2Attackable) obj).getClan()))
- {
- return obj;
- }
- if (actor.getIsChaos() != 0)
- {
- if ((((L2Attackable) obj).getFactionId() != null) && ((L2Attackable) obj).getFactionId().equals(actor.getFactionId()))
- {
- continue;
- }
-
- return obj;
- }
- }
- if (obj instanceof L2Summon)
- {
- return obj;
- }
- }
- }
- return null;
- }
-
- private void targetReconsider()
- {
- double dist = 0;
- double dist2 = 0;
- int range = 0;
- L2Attackable actor = getActiveChar();
- L2Character MostHate = actor.getMostHated();
- if (actor.getHateList() != null)
- {
- for (L2Character obj : actor.getHateList())
- {
- if ((obj == null) || !GeoData.getInstance().canSeeTarget(actor, obj) || obj.isDead() || (obj != MostHate) || (obj == actor))
- {
- continue;
- }
- try
- {
- dist = Math.sqrt(actor.getPlanDistanceSq(obj.getX(), obj.getY()));
- dist2 = dist - actor.getTemplate().getCollisionRadius();
- range = actor.getPhysicalAttackRange() + actor.getTemplate().getCollisionRadius() + obj.getTemplate().getCollisionRadius();
- if (obj.isMoving())
- {
- dist2 = dist2 - 70;
- }
- }
- catch (NullPointerException e)
- {
- continue;
- }
-
- if (dist2 <= range)
- {
- if (MostHate != null)
- {
- actor.addDamageHate(obj, 0, actor.getHating(MostHate));
- }
- else
- {
- actor.addDamageHate(obj, 0, 2000);
- }
- actor.setTarget(obj);
- setAttackTarget(obj);
- return;
- }
- }
- }
- if (!(actor instanceof L2GuardInstance))
- {
- Collection<L2Object> objs = actor.getKnownList().getKnownObjects().values();
- for (L2Object target : objs)
- {
- L2Character obj = null;
- if (target instanceof L2Character)
- {
- obj = (L2Character) target;
- }
-
- if ((obj == null) || !GeoData.getInstance().canSeeTarget(actor, obj) || obj.isDead() || (obj != MostHate) || (obj == actor) || (obj == getAttackTarget()))
- {
- continue;
- }
- if (obj instanceof L2PcInstance)
- {
- if (MostHate != null)
- {
- actor.addDamageHate(obj, 0, actor.getHating(MostHate));
- }
- else
- {
- actor.addDamageHate(obj, 0, 2000);
- }
- actor.setTarget(obj);
- setAttackTarget(obj);
-
- }
- else if (obj instanceof L2Attackable)
- {
- if ((actor.getEnemyClan() != null) && actor.getEnemyClan().equals(((L2Attackable) obj).getClan()))
- {
- actor.addDamageHate(obj, 0, actor.getHating(MostHate));
- actor.setTarget(obj);
- }
- if (actor.getIsChaos() != 0)
- {
- if ((((L2Attackable) obj).getFactionId() != null) && ((L2Attackable) obj).getFactionId().equals(actor.getFactionId()))
- {
- continue;
- }
-
- if (MostHate != null)
- {
- actor.addDamageHate(obj, 0, actor.getHating(MostHate));
- }
- else
- {
- actor.addDamageHate(obj, 0, 2000);
- }
- actor.setTarget(obj);
- setAttackTarget(obj);
- }
- }
- else if (obj instanceof L2Summon)
- {
- if (MostHate != null)
- {
- actor.addDamageHate(obj, 0, actor.getHating(MostHate));
- }
- else
- {
- actor.addDamageHate(obj, 0, 2000);
- }
- actor.setTarget(obj);
- setAttackTarget(obj);
- }
- }
- }
- }
-
- private void aggroReconsider()
- {
- L2Attackable actor = getActiveChar();
- L2Character MostHate = actor.getMostHated();
- if (actor.getHateList() != null)
- {
-
- int rand = Rnd.get(actor.getHateList().size());
- int count = 0;
- for (L2Character obj : actor.getHateList())
- {
- if (count < rand)
- {
- count++;
- continue;
- }
-
- if ((obj == null) || !GeoData.getInstance().canSeeTarget(actor, obj) || obj.isDead() || (obj == getAttackTarget()) || (obj == actor))
- {
- continue;
- }
-
- try
- {
- actor.setTarget(getAttackTarget());
- }
- catch (NullPointerException e)
- {
- continue;
- }
- if (MostHate != null)
- {
- actor.addDamageHate(obj, 0, actor.getHating(MostHate));
- }
- else
- {
- actor.addDamageHate(obj, 0, 2000);
- }
- actor.setTarget(obj);
- setAttackTarget(obj);
- return;
- }
- }
-
- if (!(actor instanceof L2GuardInstance))
- {
- Collection<L2Object> objs = actor.getKnownList().getKnownObjects().values();
- for (L2Object target : objs)
- {
- L2Character obj = null;
- if (target instanceof L2Character)
- {
- obj = (L2Character) target;
- }
- else
- {
- continue;
- }
-
- if (!GeoData.getInstance().canSeeTarget(actor, obj) || obj.isDead() || (obj != MostHate) || (obj == actor))
- {
- continue;
- }
- if (obj instanceof L2PcInstance)
- {
- if ((MostHate != null) && !MostHate.isDead())
- {
- actor.addDamageHate(obj, 0, actor.getHating(MostHate));
- }
- else
- {
- actor.addDamageHate(obj, 0, 2000);
- }
- actor.setTarget(obj);
- setAttackTarget(obj);
- }
- else if (obj instanceof L2Attackable)
- {
- if ((actor.getEnemyClan() != null) && actor.getEnemyClan().equals(((L2Attackable) obj).getClan()))
- {
- if (MostHate != null)
- {
- actor.addDamageHate(obj, 0, actor.getHating(MostHate));
- }
- else
- {
- actor.addDamageHate(obj, 0, 2000);
- }
- actor.setTarget(obj);
- }
- if (actor.getIsChaos() != 0)
- {
- if ((((L2Attackable) obj).getFactionId() != null) && ((L2Attackable) obj).getFactionId().equals(actor.getFactionId()))
- {
- continue;
- }
-
- if (MostHate != null)
- {
- actor.addDamageHate(obj, 0, actor.getHating(MostHate));
- }
- else
- {
- actor.addDamageHate(obj, 0, 2000);
- }
- actor.setTarget(obj);
- setAttackTarget(obj);
- }
- }
- else if (obj instanceof L2Summon)
- {
- if (MostHate != null)
- {
- actor.addDamageHate(obj, 0, actor.getHating(MostHate));
- }
- else
- {
- actor.addDamageHate(obj, 0, 2000);
- }
- actor.setTarget(obj);
- setAttackTarget(obj);
- }
- }
- }
- }
-
- private List<L2Skill> longRangeSkillRender()
- {
- longRangeSkills = _skillrender.getLongRangeSkills();
- if (longRangeSkills.isEmpty())
- {
- longRangeSkills = getActiveChar().getLongRangeSkill();
- }
- return longRangeSkills;
- }
-
- private List<L2Skill> shortRangeSkillRender()
- {
- shortRangeSkills = _skillrender.getShortRangeSkills();
- if (shortRangeSkills.isEmpty())
- {
- shortRangeSkills = getActiveChar().getShortRangeSkill();
- }
- return shortRangeSkills;
- }
-
- /**
- * Manage AI thinking actions of a L2Attackable.
- */
- @Override
- protected void onEvtThink()
- {
- // Check if the actor can't use skills and if a thinking action isn't already in progress
- if (_thinking || getActiveChar().isAllSkillsDisabled())
- {
- return;
- }
-
- // Start thinking action
- _thinking = true;
-
- try
- {
- // Manage AI thinks of a L2Attackable
- switch (getIntention())
- {
- case AI_INTENTION_ACTIVE:
- thinkActive();
- break;
- case AI_INTENTION_ATTACK:
- thinkAttack();
- break;
- case AI_INTENTION_CAST:
- thinkCast();
- break;
- }
- }
- catch (Exception e)
- {
- _log.warning(getClass().getSimpleName() + ": " + this + " - onEvtThink() failed: " + e.getMessage());
- }
- finally
- {
- // Stop thinking action
- _thinking = false;
- }
- }
-
- /**
- * Launch actions corresponding to the Event Attacked.<br>
- * <B><U> Actions</U> :</B>
- * <ul>
- * <li>Init the attack : Calculate the attack timeout, Set the _globalAggro to 0, Add the attacker to the actor _aggroList</li>
- * <li>Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance</li>
- * <li>Set the Intention to AI_INTENTION_ATTACK</li>
- * </ul>
- * @param attacker The L2Character that attacks the actor
- */
- @Override
- protected void onEvtAttacked(L2Character attacker)
- {
- L2Attackable me = getActiveChar();
-
- // Calculate the attack timeout
- _attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getInstance().getGameTicks();
-
- // Set the _globalAggro to 0 to permit attack even just after spawn
- if (_globalAggro < 0)
- {
- _globalAggro = 0;
- }
-
- // Add the attacker to the _aggroList of the actor
- me.addDamageHate(attacker, 0, 1);
-
- // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
- if (!me.isRunning())
- {
- me.setRunning();
- }
-
- // Set the Intention to AI_INTENTION_ATTACK
- if (getIntention() != AI_INTENTION_ATTACK)
- {
- setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
- }
- else if (me.getMostHated() != getAttackTarget())
- {
- setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
- }
-
- if (me instanceof L2MonsterInstance)
- {
- L2MonsterInstance master = (L2MonsterInstance) me;
-
- if (master.hasMinions())
- {
- master.getMinionList().onAssist(me, attacker);
- }
-
- master = master.getLeader();
- if ((master != null) && master.hasMinions())
- {
- master.getMinionList().onAssist(me, attacker);
- }
- }
-
- super.onEvtAttacked(attacker);
- }
-
- /**
- * Launch actions corresponding to the Event Aggression.<br>
- * <B><U> Actions</U> :</B>
- * <ul>
- * <li>Add the target to the actor _aggroList or update hate if already present</li>
- * <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>
- * </ul>
- * @param aggro The value of hate to add to the actor against the target
- */
- @Override
- protected void onEvtAggression(L2Character target, int aggro)
- {
- L2Attackable me = getActiveChar();
-
- if (target != null)
- {
- // Add the target to the actor _aggroList or update hate if already present
- me.addDamageHate(target, 0, aggro);
-
- // Set the actor AI Intention to AI_INTENTION_ATTACK
- if (getIntention() != CtrlIntention.AI_INTENTION_ATTACK)
- {
- // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
- if (!me.isRunning())
- {
- me.setRunning();
- }
-
- setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
- }
-
- if (me instanceof L2MonsterInstance)
- {
- L2MonsterInstance master = (L2MonsterInstance) me;
-
- if (master.hasMinions())
- {
- master.getMinionList().onAssist(me, target);
- }
-
- master = master.getLeader();
- if ((master != null) && master.hasMinions())
- {
- master.getMinionList().onAssist(me, target);
- }
- }
- }
- }
-
- @Override
- protected void onIntentionActive()
- {
- // Cancel attack timeout
- _attackTimeout = Integer.MAX_VALUE;
- super.onIntentionActive();
- }
-
- public void setGlobalAggro(int value)
- {
- _globalAggro = value;
- }
-
- /**
- * @param TP The timepass to set.
- */
- public void setTimepass(int TP)
- {
- timepass = TP;
- }
-
- /**
- * @return Returns the timepass.
- */
- public int getTimepass()
- {
- return timepass;
- }
-
- public L2Attackable getActiveChar()
- {
- return (L2Attackable) _actor;
- }
- }
|