123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682 |
- /*
- * Copyright (C) 2004-2014 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.model.events;
- import java.lang.annotation.Annotation;
- import java.lang.reflect.Method;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.concurrent.ConcurrentHashMap;
- import java.util.function.Consumer;
- import java.util.function.Function;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javolution.util.FastList;
- import javolution.util.FastSet;
- import com.l2jserver.Config;
- import com.l2jserver.gameserver.GameTimeController;
- import com.l2jserver.gameserver.datatables.DoorTable;
- import com.l2jserver.gameserver.datatables.ItemTable;
- import com.l2jserver.gameserver.datatables.NpcData;
- import com.l2jserver.gameserver.enums.QuestSound;
- import com.l2jserver.gameserver.idfactory.IdFactory;
- import com.l2jserver.gameserver.instancemanager.CastleManager;
- import com.l2jserver.gameserver.instancemanager.FortManager;
- import com.l2jserver.gameserver.instancemanager.InstanceManager;
- import com.l2jserver.gameserver.instancemanager.ZoneManager;
- import com.l2jserver.gameserver.model.L2Spawn;
- import com.l2jserver.gameserver.model.Location;
- 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.instance.L2DoorInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2TrapInstance;
- import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
- import com.l2jserver.gameserver.model.entity.Castle;
- import com.l2jserver.gameserver.model.entity.Fort;
- import com.l2jserver.gameserver.model.entity.Instance;
- import com.l2jserver.gameserver.model.events.annotations.Id;
- import com.l2jserver.gameserver.model.events.annotations.Ids;
- import com.l2jserver.gameserver.model.events.annotations.NpcLevelRange;
- import com.l2jserver.gameserver.model.events.annotations.NpcLevelRanges;
- import com.l2jserver.gameserver.model.events.annotations.Priority;
- import com.l2jserver.gameserver.model.events.annotations.Range;
- import com.l2jserver.gameserver.model.events.annotations.Ranges;
- import com.l2jserver.gameserver.model.events.annotations.RegisterEvent;
- import com.l2jserver.gameserver.model.events.annotations.RegisterType;
- import com.l2jserver.gameserver.model.events.impl.IBaseEvent;
- import com.l2jserver.gameserver.model.events.impl.character.OnCreatureKill;
- import com.l2jserver.gameserver.model.events.impl.character.OnCreatureZoneEnter;
- import com.l2jserver.gameserver.model.events.impl.character.OnCreatureZoneExit;
- import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcCanBeSeen;
- import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcCreatureSee;
- import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcEventReceived;
- import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcFirstTalk;
- import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcMoveFinished;
- import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcMoveNodeArrived;
- import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcMoveRouteFinished;
- import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillFinished;
- import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillSee;
- import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSpawn;
- import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcTeleport;
- import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAggroRangeEnter;
- import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAttack;
- import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableFactionCall;
- import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableHate;
- import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableKill;
- import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerLogin;
- import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerLogout;
- import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerProfessionChange;
- import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerSkillLearn;
- import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerSummonSpawn;
- import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerSummonTalk;
- import com.l2jserver.gameserver.model.events.impl.character.trap.OnTrapAction;
- import com.l2jserver.gameserver.model.events.impl.item.OnItemBypassEvent;
- import com.l2jserver.gameserver.model.events.impl.item.OnItemTalk;
- import com.l2jserver.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
- import com.l2jserver.gameserver.model.events.impl.sieges.castle.OnCastleSiegeFinish;
- import com.l2jserver.gameserver.model.events.impl.sieges.castle.OnCastleSiegeOwnerChange;
- import com.l2jserver.gameserver.model.events.impl.sieges.castle.OnCastleSiegeStart;
- import com.l2jserver.gameserver.model.events.listeners.AbstractEventListener;
- import com.l2jserver.gameserver.model.events.listeners.AnnotationEventListener;
- import com.l2jserver.gameserver.model.events.listeners.ConsumerEventListener;
- import com.l2jserver.gameserver.model.events.listeners.DummyEventListener;
- import com.l2jserver.gameserver.model.events.listeners.FunctionEventListener;
- import com.l2jserver.gameserver.model.events.listeners.RunnableEventListener;
- import com.l2jserver.gameserver.model.events.returns.AbstractEventReturn;
- import com.l2jserver.gameserver.model.events.returns.TerminateReturn;
- import com.l2jserver.gameserver.model.holders.ItemHolder;
- import com.l2jserver.gameserver.model.interfaces.IPositionable;
- import com.l2jserver.gameserver.model.itemcontainer.Inventory;
- import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
- import com.l2jserver.gameserver.model.items.L2Item;
- import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
- import com.l2jserver.gameserver.model.olympiad.Olympiad;
- import com.l2jserver.gameserver.model.skills.Skill;
- import com.l2jserver.gameserver.model.stats.Stats;
- import com.l2jserver.gameserver.model.zone.L2ZoneType;
- import com.l2jserver.gameserver.network.NpcStringId;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;
- import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
- import com.l2jserver.gameserver.network.serverpackets.SpecialCamera;
- import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
- import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
- import com.l2jserver.gameserver.scripting.ManagedScript;
- import com.l2jserver.gameserver.util.MinionList;
- import com.l2jserver.util.Rnd;
- /**
- * @author UnAfraid
- */
- public abstract class AbstractScript extends ManagedScript
- {
- protected static final Logger _log = Logger.getLogger(AbstractScript.class.getName());
- private final Map<ListenerRegisterType, Set<Integer>> _registeredIds = new ConcurrentHashMap<>();
- private final List<AbstractEventListener> _listeners = new FastList<AbstractEventListener>().shared();
-
- public AbstractScript()
- {
- initializeAnnotationListeners();
- }
-
- private void initializeAnnotationListeners()
- {
- final List<Integer> ids = new ArrayList<>();
- for (Method method : getClass().getMethods())
- {
- if (method.isAnnotationPresent(RegisterEvent.class) && method.isAnnotationPresent(RegisterType.class))
- {
- final RegisterEvent listener = method.getAnnotation(RegisterEvent.class);
- final RegisterType regType = method.getAnnotation(RegisterType.class);
-
- final ListenerRegisterType type = regType.value();
- final EventType eventType = listener.value();
- if (method.getParameterCount() != 1)
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": Non properly defined annotation listener on method: " + method.getName() + " expected parameter count is 1 but found: " + method.getParameterCount());
- continue;
- }
- else if (!eventType.isEventClass(method.getParameterTypes()[0]))
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": Non properly defined annotation listener on method: " + method.getName() + " expected parameter to be type of: " + eventType.getEventClass().getSimpleName() + " but found: " + method.getParameterTypes()[0].getSimpleName());
- continue;
- }
- else if (!eventType.isReturnClass(method.getReturnType()))
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": Non properly defined annotation listener on method: " + method.getName() + " expected return type to be one of: " + Arrays.toString(eventType.getReturnClasses()) + " but found: " + method.getReturnType().getSimpleName());
- continue;
- }
-
- int priority = 0;
-
- // Clear the list
- ids.clear();
-
- // Scan for possible Id filters
- for (Annotation annotation : method.getAnnotations())
- {
- if (annotation instanceof Id)
- {
- final Id npc = (Id) annotation;
- for (int id : npc.value())
- {
- ids.add(id);
- }
- }
- else if (annotation instanceof Ids)
- {
- final Ids npcs = (Ids) annotation;
- for (Id npc : npcs.value())
- {
- for (int id : npc.value())
- {
- ids.add(id);
- }
- }
- }
- else if (annotation instanceof Range)
- {
- final Range range = (Range) annotation;
- if (range.from() > range.to())
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": Wrong " + annotation.getClass().getSimpleName() + " from is higher then to!");
- continue;
- }
-
- for (int id = range.from(); id <= range.to(); id++)
- {
- ids.add(id);
- }
- }
- else if (annotation instanceof Ranges)
- {
- final Ranges ranges = (Ranges) annotation;
- for (Range range : ranges.value())
- {
- if (range.from() > range.to())
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": Wrong " + annotation.getClass().getSimpleName() + " from is higher then to!");
- continue;
- }
-
- for (int id = range.from(); id <= range.to(); id++)
- {
- ids.add(id);
- }
- }
- }
- else if (annotation instanceof NpcLevelRange)
- {
- final NpcLevelRange range = (NpcLevelRange) annotation;
- if (range.from() > range.to())
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": Wrong " + annotation.getClass().getSimpleName() + " from is higher then to!");
- continue;
- }
- else if (type != ListenerRegisterType.NPC)
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": ListenerRegisterType " + type + " for " + annotation.getClass().getSimpleName() + " NPC is expected!");
- continue;
- }
-
- for (int level = range.from(); level <= range.to(); level++)
- {
- final List<L2NpcTemplate> templates = NpcData.getInstance().getAllOfLevel(level);
- templates.forEach(template -> ids.add(template.getId()));
- }
-
- }
- else if (annotation instanceof NpcLevelRanges)
- {
- final NpcLevelRanges ranges = (NpcLevelRanges) annotation;
- for (NpcLevelRange range : ranges.value())
- {
- if (range.from() > range.to())
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": Wrong " + annotation.getClass().getSimpleName() + " from is higher then to!");
- continue;
- }
- else if (type != ListenerRegisterType.NPC)
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": ListenerRegisterType " + type + " for " + annotation.getClass().getSimpleName() + " NPC is expected!");
- continue;
- }
-
- for (int level = range.from(); level <= range.to(); level++)
- {
- final List<L2NpcTemplate> templates = NpcData.getInstance().getAllOfLevel(level);
- templates.forEach(template -> ids.add(template.getId()));
- }
- }
- }
- else if (annotation instanceof Priority)
- {
- final Priority p = (Priority) annotation;
- priority = p.value();
- }
- }
-
- if (!ids.isEmpty())
- {
- if (!_registeredIds.containsKey(type))
- {
- _registeredIds.put(type, new FastSet<Integer>().shared());
- }
- _registeredIds.get(type).addAll(ids);
- }
-
- registerAnnotation(method, eventType, type, priority, ids);
- }
- }
- }
-
- /**
- * Unloads all listeners registered by this class.
- */
- @Override
- public boolean unload()
- {
- _listeners.forEach(AbstractEventListener::unregisterMe);
- _listeners.clear();
- return true;
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides delayed (Depending on {@link com.l2jserver.gameserver.model.actor.L2Attackable#getOnKillDelay()}) callback operation when L2Attackable dies from a player.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setAttackableKillId(Consumer<OnAttackableKill> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_ATTACKABLE_KILL, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides delayed (Depending on {@link com.l2jserver.gameserver.model.actor.L2Attackable#getOnKillDelay()}) callback operation when L2Attackable dies from a player.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setAttackableKillId(Consumer<OnAttackableKill> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_ATTACKABLE_KILL, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when L2Attackable dies from a player with return type.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> addCreatureKillId(Function<OnCreatureKill, ? extends AbstractEventReturn> callback, int... npcIds)
- {
- return registerFunction(callback, EventType.ON_CREATURE_KILL, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when L2Attackable dies from a player.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setCreatureKillId(Consumer<OnCreatureKill> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_CREATURE_KILL, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Attackable} dies from a {@link L2PcInstance}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setCreatureKillId(Consumer<OnCreatureKill> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_CREATURE_KILL, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc} for first time.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcFirstTalkId(Consumer<OnNpcFirstTalk> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_FIRST_TALK, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc} for first time.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcFirstTalkId(Consumer<OnNpcFirstTalk> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_FIRST_TALK, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc}.
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcTalkId(Collection<Integer> npcIds)
- {
- return registerDummy(EventType.ON_NPC_TALK, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc}.
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcTalkId(int... npcIds)
- {
- return registerDummy(EventType.ON_NPC_TALK, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when teleport {@link L2Npc}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcTeleportId(Consumer<OnNpcTeleport> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_TELEPORT, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when teleport {@link L2Npc}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcTeleportId(Consumer<OnNpcTeleport> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_TELEPORT, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc} and must receive quest state.
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcQuestStartId(int... npcIds)
- {
- return registerDummy(EventType.ON_NPC_QUEST_START, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc} and must receive quest state.
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcQuestStartId(Collection<Integer> npcIds)
- {
- return registerDummy(EventType.ON_NPC_QUEST_START, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when L2Npc sees skill from a player.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcSkillSeeId(Consumer<OnNpcSkillSee> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_SKILL_SEE, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when L2Npc sees skill from a player.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcSkillSeeId(Consumer<OnNpcSkillSee> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_SKILL_SEE, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when L2Npc casts skill on a player.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcSkillFinishedId(Consumer<OnNpcSkillFinished> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_SKILL_FINISHED, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when L2Npc casts skill on a player.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcSkillFinishedId(Consumer<OnNpcSkillFinished> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_SKILL_FINISHED, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when L2Npc is spawned.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcSpawnId(Consumer<OnNpcSpawn> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_SPAWN, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when L2Npc is spawned.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcSpawnId(Consumer<OnNpcSpawn> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_SPAWN, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2Npc} receives event from another {@link L2Npc}
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcEventReceivedId(Consumer<OnNpcEventReceived> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_EVENT_RECEIVED, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Npc} receives event from another {@link L2Npc}
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcEventReceivedId(Consumer<OnNpcEventReceived> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_EVENT_RECEIVED, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2Npc} finishes to move.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcMoveFinishedId(Consumer<OnNpcMoveFinished> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_MOVE_FINISHED, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Npc} finishes to move.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcMoveFinishedId(Consumer<OnNpcMoveFinished> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_MOVE_FINISHED, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2Npc} arrive to node of its route
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcMoveNodeArrivedId(Consumer<OnNpcMoveNodeArrived> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_MOVE_NODE_ARRIVED, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Npc} arrive to node of its route
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcMoveNodeArrivedId(Consumer<OnNpcMoveNodeArrived> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_MOVE_NODE_ARRIVED, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2Npc} finishes to move on its route.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcMoveRouteFinishedId(Consumer<OnNpcMoveRouteFinished> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_MOVE_ROUTE_FINISHED, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Npc} finishes to move on its route.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcMoveRouteFinishedId(Consumer<OnNpcMoveRouteFinished> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_MOVE_ROUTE_FINISHED, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcHateId(Consumer<OnAttackableHate> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_HATE, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcHateId(Consumer<OnAttackableHate> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_HATE, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> addNpcHateId(Function<OnAttackableHate, TerminateReturn> callback, int... npcIds)
- {
- return registerFunction(callback, EventType.ON_NPC_HATE, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> addNpcHateId(Function<OnAttackableHate, TerminateReturn> callback, Collection<Integer> npcIds)
- {
- return registerFunction(callback, EventType.ON_NPC_HATE, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcCanBeSeenId(Consumer<OnNpcCanBeSeen> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_CAN_BE_SEEN, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcCanBeSeenId(Consumer<OnNpcCanBeSeen> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_CAN_BE_SEEN, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcCanBeSeenId(Function<OnNpcCanBeSeen, TerminateReturn> callback, int... npcIds)
- {
- return registerFunction(callback, EventType.ON_NPC_CAN_BE_SEEN, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcCanBeSeenId(Function<OnNpcCanBeSeen, TerminateReturn> callback, Collection<Integer> npcIds)
- {
- return registerFunction(callback, EventType.ON_NPC_CAN_BE_SEEN, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2Npc} sees another creature.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcCreatureSeeId(Consumer<OnNpcCreatureSee> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Npc} sees another creature.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setNpcCreatureSeeId(Consumer<OnNpcCreatureSee> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when L2Attackable is under attack to other clan mates.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setAttackableFactionIdId(Consumer<OnAttackableFactionCall> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_ATTACKABLE_FACTION_CALL, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when L2Attackable is under attack to other clan mates.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setAttackableFactionIdId(Consumer<OnAttackableFactionCall> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_ATTACKABLE_FACTION_CALL, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when L2Attackable is attacked from a player.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setAttackableAttackId(Consumer<OnAttackableAttack> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_ATTACKABLE_ATTACK, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when L2Attackable is attacked from a player.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setAttackableAttackId(Consumer<OnAttackableAttack> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_ATTACKABLE_ATTACK, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} enters in {@link L2Attackable}'s aggressive range.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setAttackableAggroRangeEnterId(Consumer<OnAttackableAggroRangeEnter> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_ATTACKABLE_AGGRO_RANGE_ENTER, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} enters in {@link L2Attackable}'s aggressive range.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setAttackableAggroRangeEnterId(Consumer<OnAttackableAggroRangeEnter> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_ATTACKABLE_AGGRO_RANGE_ENTER, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} learn's a {@link Skill}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setPlayerSkillLearnId(Consumer<OnPlayerSkillLearn> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_PLAYER_SKILL_LEARN, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} learn's a {@link Skill}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setPlayerSkillLearnId(Consumer<OnPlayerSkillLearn> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_PLAYER_SKILL_LEARN, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} summons a servitor or a pet
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setPlayerSummonSpawnId(Consumer<OnPlayerSummonSpawn> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_PLAYER_SUMMON_SPAWN, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} summons a servitor or a pet
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setPlayerSummonSpawnId(Consumer<OnPlayerSummonSpawn> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_PLAYER_SUMMON_SPAWN, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} talk with a servitor or a pet
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setPlayerSummonTalkId(Consumer<OnPlayerSummonTalk> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_PLAYER_SUMMON_TALK, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} talk with a servitor or a pet
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setPlayerSummonTalkId(Consumer<OnPlayerSummonSpawn> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_PLAYER_SUMMON_TALK, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} summons a servitor or a pet
- * @param callback
- * @return
- */
- protected final List<AbstractEventListener> setPlayerLoginId(Consumer<OnPlayerLogin> callback)
- {
- return registerConsumer(callback, EventType.ON_PLAYER_LOGIN, ListenerRegisterType.GLOBAL);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} summons a servitor or a pet
- * @param callback
- * @return
- */
- protected final List<AbstractEventListener> setPlayerLogoutId(Consumer<OnPlayerLogout> callback)
- {
- return registerConsumer(callback, EventType.ON_PLAYER_LOGOUT, ListenerRegisterType.GLOBAL);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link com.l2jserver.gameserver.model.actor.L2Character} Enters on a {@link L2ZoneType}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setCreatureZoneEnterId(Consumer<OnCreatureZoneEnter> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_CREATURE_ZONE_ENTER, ListenerRegisterType.ZONE, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link com.l2jserver.gameserver.model.actor.L2Character} Enters on a {@link L2ZoneType}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setCreatureZoneEnterId(Consumer<OnCreatureZoneEnter> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_CREATURE_ZONE_ENTER, ListenerRegisterType.ZONE, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link com.l2jserver.gameserver.model.actor.L2Character} Exits on a {@link L2ZoneType}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setCreatureZoneExitId(Consumer<OnCreatureZoneExit> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_CREATURE_ZONE_EXIT, ListenerRegisterType.ZONE, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link com.l2jserver.gameserver.model.actor.L2Character} Exits on a {@link L2ZoneType}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setCreatureZoneExitId(Consumer<OnCreatureZoneExit> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_CREATURE_ZONE_EXIT, ListenerRegisterType.ZONE, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link com.l2jserver.gameserver.model.actor.instance.L2TrapInstance} acts.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setTrapActionId(Consumer<OnTrapAction> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_TRAP_ACTION, ListenerRegisterType.NPC, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link com.l2jserver.gameserver.model.actor.instance.L2TrapInstance} acts.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setTrapActionId(Consumer<OnTrapAction> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_TRAP_ACTION, ListenerRegisterType.NPC, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2Item} receives an event from {@link L2PcInstance}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setItemBypassEvenId(Consumer<OnItemBypassEvent> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_ITEM_BYPASS_EVENT, ListenerRegisterType.ITEM, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2Item} receives an event from {@link L2PcInstance}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setItemBypassEvenId(Consumer<OnItemBypassEvent> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_ITEM_BYPASS_EVENT, ListenerRegisterType.ITEM, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Item}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setItemTalkId(Consumer<OnItemTalk> callback, int... npcIds)
- {
- return registerConsumer(callback, EventType.ON_ITEM_TALK, ListenerRegisterType.ITEM, npcIds);
- }
-
- /**
- * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Item}.
- * @param callback
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> setItemTalkId(Consumer<OnItemTalk> callback, Collection<Integer> npcIds)
- {
- return registerConsumer(callback, EventType.ON_ITEM_TALK, ListenerRegisterType.ITEM, npcIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when Olympiad match finishes.
- * @param callback
- * @return
- */
- protected final List<AbstractEventListener> setOlympiadMatchResult(Consumer<OnOlympiadMatchResult> callback)
- {
- return registerConsumer(callback, EventType.ON_OLYMPIAD_MATCH_RESULT, ListenerRegisterType.OLYMPIAD);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when castle siege begins
- * @param callback
- * @param castleIds
- * @return
- */
- protected final List<AbstractEventListener> setCastleSiegeStartId(Consumer<OnCastleSiegeStart> callback, int... castleIds)
- {
- return registerConsumer(callback, EventType.ON_CASTLE_SIEGE_START, ListenerRegisterType.CASTLE, castleIds);
- }
-
- /**
- * Provides instant callback operation when castle siege begins
- * @param callback
- * @param castleIds
- * @return
- */
- protected final List<AbstractEventListener> setCastleSiegeStartId(Consumer<OnCastleSiegeStart> callback, Collection<Integer> castleIds)
- {
- return registerConsumer(callback, EventType.ON_CASTLE_SIEGE_START, ListenerRegisterType.CASTLE, castleIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when Castle owner has changed during a siege
- * @param callback
- * @param castleIds
- * @return
- */
- protected final List<AbstractEventListener> setCastleSiegeOwnerChangeId(Consumer<OnCastleSiegeOwnerChange> callback, int... castleIds)
- {
- return registerConsumer(callback, EventType.ON_CASTLE_SIEGE_OWNER_CHANGE, ListenerRegisterType.CASTLE, castleIds);
- }
-
- /**
- * Provides instant callback operation when Castle owner has changed during a siege
- * @param callback
- * @param castleIds
- * @return
- */
- protected final List<AbstractEventListener> setCastleSiegeOwnerChangeId(Consumer<OnCastleSiegeOwnerChange> callback, Collection<Integer> castleIds)
- {
- return registerConsumer(callback, EventType.ON_CASTLE_SIEGE_OWNER_CHANGE, ListenerRegisterType.CASTLE, castleIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when castle siege ends
- * @param callback
- * @param castleIds
- * @return
- */
- protected final List<AbstractEventListener> setCastleSiegeFinishId(Consumer<OnCastleSiegeFinish> callback, int... castleIds)
- {
- return registerConsumer(callback, EventType.ON_CASTLE_SIEGE_FINISH, ListenerRegisterType.CASTLE, castleIds);
- }
-
- /**
- * Provides instant callback operation when castle siege ends
- * @param callback
- * @param castleIds
- * @return
- */
- protected final List<AbstractEventListener> setCastleSiegeFinishId(Consumer<OnCastleSiegeFinish> callback, Collection<Integer> castleIds)
- {
- return registerConsumer(callback, EventType.ON_CASTLE_SIEGE_FINISH, ListenerRegisterType.CASTLE, castleIds);
- }
-
- // ---------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Provides instant callback operation when player's profession has change
- * @param callback
- * @return
- */
- protected final List<AbstractEventListener> setPlayerProfessionChangeId(Consumer<OnPlayerProfessionChange> callback)
- {
- return registerConsumer(callback, EventType.ON_PLAYER_PROFESSION_CHANGE, ListenerRegisterType.GLOBAL);
- }
-
- // --------------------------------------------------------------------------------------------------
- // --------------------------------Default listener register methods---------------------------------
- // --------------------------------------------------------------------------------------------------
-
- /**
- * Method that registers Function type of listeners (Listeners that need parameters but doesn't return objects)
- * @param callback
- * @param type
- * @param registerType
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> registerConsumer(Consumer<? extends IBaseEvent> callback, EventType type, ListenerRegisterType registerType, int... npcIds)
- {
- return registerListener((container) -> new ConsumerEventListener(container, type, callback, this), registerType, npcIds);
- }
-
- /**
- * Method that registers Function type of listeners (Listeners that need parameters but doesn't return objects)
- * @param callback
- * @param type
- * @param registerType
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> registerConsumer(Consumer<? extends IBaseEvent> callback, EventType type, ListenerRegisterType registerType, Collection<Integer> npcIds)
- {
- return registerListener((container) -> new ConsumerEventListener(container, type, callback, this), registerType, npcIds);
- }
-
- /**
- * Method that registers Function type of listeners (Listeners that need parameters and return objects)
- * @param callback
- * @param type
- * @param registerType
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> registerFunction(Function<? extends IBaseEvent, ? extends AbstractEventReturn> callback, EventType type, ListenerRegisterType registerType, int... npcIds)
- {
- return registerListener((container) -> new FunctionEventListener(container, type, callback, this), registerType, npcIds);
- }
-
- /**
- * Method that registers Function type of listeners (Listeners that need parameters and return objects)
- * @param callback
- * @param type
- * @param registerType
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> registerFunction(Function<? extends IBaseEvent, ? extends AbstractEventReturn> callback, EventType type, ListenerRegisterType registerType, Collection<Integer> npcIds)
- {
- return registerListener((container) -> new FunctionEventListener(container, type, callback, this), registerType, npcIds);
- }
-
- /**
- * Method that registers runnable type of listeners (Listeners that doesn't needs parameters or return objects)
- * @param callback
- * @param type
- * @param registerType
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> registerRunnable(Runnable callback, EventType type, ListenerRegisterType registerType, int... npcIds)
- {
- return registerListener((container) -> new RunnableEventListener(container, type, callback, this), registerType, npcIds);
- }
-
- /**
- * Method that registers runnable type of listeners (Listeners that doesn't needs parameters or return objects)
- * @param callback
- * @param type
- * @param registerType
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> registerRunnable(Runnable callback, EventType type, ListenerRegisterType registerType, Collection<Integer> npcIds)
- {
- return registerListener((container) -> new RunnableEventListener(container, type, callback, this), registerType, npcIds);
- }
-
- /**
- * Method that registers runnable type of listeners (Listeners that doesn't needs parameters or return objects)
- * @param callback
- * @param type
- * @param registerType
- * @param priority
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> registerAnnotation(Method callback, EventType type, ListenerRegisterType registerType, int priority, int... npcIds)
- {
- return registerListener((container) -> new AnnotationEventListener(container, type, callback, this, priority), registerType, npcIds);
- }
-
- /**
- * Method that registers runnable type of listeners (Listeners that doesn't needs parameters or return objects)
- * @param callback
- * @param type
- * @param registerType
- * @param priority
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> registerAnnotation(Method callback, EventType type, ListenerRegisterType registerType, int priority, Collection<Integer> npcIds)
- {
- return registerListener((container) -> new AnnotationEventListener(container, type, callback, this, priority), registerType, npcIds);
- }
-
- /**
- * Method that registers dummy type of listeners (Listeners doesn't gets notification but just used to check if their type present or not)
- * @param type
- * @param registerType
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> registerDummy(EventType type, ListenerRegisterType registerType, int... npcIds)
- {
- return registerListener((container) -> new DummyEventListener(container, type, this), registerType, npcIds);
- }
-
- /**
- * Method that registers dummy type of listeners (Listeners doesn't gets notification but just used to check if their type present or not)
- * @param type
- * @param registerType
- * @param npcIds
- * @return
- */
- protected final List<AbstractEventListener> registerDummy(EventType type, ListenerRegisterType registerType, Collection<Integer> npcIds)
- {
- return registerListener((container) -> new DummyEventListener(container, type, this), registerType, npcIds);
- }
-
- // --------------------------------------------------------------------------------------------------
- // --------------------------------------Register methods--------------------------------------------
- // --------------------------------------------------------------------------------------------------
-
- /**
- * Generic listener register method
- * @param action
- * @param registerType
- * @param ids
- * @return
- */
- protected final List<AbstractEventListener> registerListener(Function<ListenersContainer, AbstractEventListener> action, ListenerRegisterType registerType, int... ids)
- {
- final List<AbstractEventListener> listeners = new ArrayList<>(ids.length > 0 ? ids.length : 1);
- if (ids.length > 0)
- {
- for (int id : ids)
- {
- switch (registerType)
- {
- case NPC:
- {
- final L2NpcTemplate template = NpcData.getInstance().getTemplate(id);
- if (template != null)
- {
- listeners.add(template.addListener(action.apply(template)));
- }
- break;
- }
- case ZONE:
- {
- final L2ZoneType template = ZoneManager.getInstance().getZoneById(id);
- if (template != null)
- {
- listeners.add(template.addListener(action.apply(template)));
- }
- break;
- }
- case ITEM:
- {
- final L2Item template = ItemTable.getInstance().getTemplate(id);
- if (template != null)
- {
- listeners.add(template.addListener(action.apply(template)));
- }
- break;
- }
- case CASTLE:
- {
- final Castle template = CastleManager.getInstance().getCastleById(id);
- if (template != null)
- {
- listeners.add(template.addListener(action.apply(template)));
- }
- break;
- }
- case FORTRESS:
- {
- final Fort template = FortManager.getInstance().getFortById(id);
- if (template != null)
- {
- listeners.add(template.addListener(action.apply(template)));
- }
- break;
- }
- default:
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": Unhandled register type: " + registerType);
- }
- }
-
- if (!_registeredIds.containsKey(registerType))
- {
- _registeredIds.put(registerType, new FastSet<Integer>().shared());
- }
- _registeredIds.get(registerType).add(id);
- }
- }
- else
- {
- switch (registerType)
- {
- case OLYMPIAD:
- {
- final Olympiad template = Olympiad.getInstance();
- listeners.add(template.addListener(action.apply(template)));
- break;
- }
- case GLOBAL: // Global Listener
- {
- final ListenersContainer template = Containers.Global();
- listeners.add(template.addListener(action.apply(template)));
- break;
- }
- case GLOBAL_NPCS: // Global Npcs Listener
- {
- final ListenersContainer template = Containers.Npcs();
- listeners.add(template.addListener(action.apply(template)));
- break;
- }
- case GLOBAL_MONSTERS: // Global Monsters Listener
- {
- final ListenersContainer template = Containers.Monsters();
- listeners.add(template.addListener(action.apply(template)));
- break;
- }
- case GLOBAL_PLAYERS: // Global Players Listener
- {
- final ListenersContainer template = Containers.Players();
- listeners.add(template.addListener(action.apply(template)));
- break;
- }
- }
- }
-
- _listeners.addAll(listeners);
- return listeners;
- }
-
- /**
- * Generic listener register method
- * @param action
- * @param registerType
- * @param ids
- * @return
- */
- protected final List<AbstractEventListener> registerListener(Function<ListenersContainer, AbstractEventListener> action, ListenerRegisterType registerType, Collection<Integer> ids)
- {
- final List<AbstractEventListener> listeners = new ArrayList<>(!ids.isEmpty() ? ids.size() : 1);
- if (!ids.isEmpty())
- {
- for (int id : ids)
- {
- switch (registerType)
- {
- case NPC:
- {
- final L2NpcTemplate template = NpcData.getInstance().getTemplate(id);
- if (template != null)
- {
- listeners.add(template.addListener(action.apply(template)));
- }
- break;
- }
- case ZONE:
- {
- final L2ZoneType template = ZoneManager.getInstance().getZoneById(id);
- if (template != null)
- {
- listeners.add(template.addListener(action.apply(template)));
- }
- break;
- }
- case ITEM:
- {
- final L2Item template = ItemTable.getInstance().getTemplate(id);
- if (template != null)
- {
- listeners.add(template.addListener(action.apply(template)));
- }
- break;
- }
- case CASTLE:
- {
- final Castle template = CastleManager.getInstance().getCastleById(id);
- if (template != null)
- {
- listeners.add(template.addListener(action.apply(template)));
- }
- break;
- }
- case FORTRESS:
- {
- final Fort template = FortManager.getInstance().getFortById(id);
- if (template != null)
- {
- listeners.add(template.addListener(action.apply(template)));
- }
- break;
- }
- default:
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": Unhandled register type: " + registerType);
- }
- }
- }
- if (!_registeredIds.containsKey(registerType))
- {
- _registeredIds.put(registerType, new FastSet<Integer>().shared());
- }
- _registeredIds.get(registerType).addAll(ids);
- }
- else
- {
- switch (registerType)
- {
- case OLYMPIAD:
- {
- final Olympiad template = Olympiad.getInstance();
- listeners.add(template.addListener(action.apply(template)));
- break;
- }
- case GLOBAL: // Global Listener
- {
- final ListenersContainer template = Containers.Global();
- listeners.add(template.addListener(action.apply(template)));
- break;
- }
- case GLOBAL_NPCS: // Global Npcs Listener
- {
- final ListenersContainer template = Containers.Npcs();
- listeners.add(template.addListener(action.apply(template)));
- break;
- }
- case GLOBAL_MONSTERS: // Global Monsters Listener
- {
- final ListenersContainer template = Containers.Monsters();
- listeners.add(template.addListener(action.apply(template)));
- break;
- }
- case GLOBAL_PLAYERS: // Global Players Listener
- {
- final ListenersContainer template = Containers.Players();
- listeners.add(template.addListener(action.apply(template)));
- break;
- }
- }
- }
- _listeners.addAll(listeners);
- return listeners;
- }
-
- public Set<Integer> getRegisteredIds(ListenerRegisterType type)
- {
- return _registeredIds.containsKey(type) ? _registeredIds.get(type) : Collections.emptySet();
- }
-
- public List<AbstractEventListener> getListeners()
- {
- return _listeners;
- }
-
- /**
- * -------------------------------------------------------------------------------------------------------
- */
-
- /**
- * Show an on screen message to the player.
- * @param player the player to display the message to
- * @param text the message to display
- * @param time the duration of the message in milliseconds
- */
- public static void showOnScreenMsg(L2PcInstance player, String text, int time)
- {
- player.sendPacket(new ExShowScreenMessage(text, time));
- }
-
- /**
- * Show an on screen message to the player.
- * @param player the player to display the message to
- * @param npcString the NPC string to display
- * @param position the position of the message on the screen
- * @param time the duration of the message in milliseconds
- * @param params values of parameters to replace in the NPC String (like S1, C1 etc.)
- */
- public static void showOnScreenMsg(L2PcInstance player, NpcStringId npcString, int position, int time, String... params)
- {
- player.sendPacket(new ExShowScreenMessage(npcString, position, time, params));
- }
-
- /**
- * Show an on screen message to the player.
- * @param player the player to display the message to
- * @param systemMsg the system message to display
- * @param position the position of the message on the screen
- * @param time the duration of the message in milliseconds
- * @param params values of parameters to replace in the system message (like S1, C1 etc.)
- */
- public static void showOnScreenMsg(L2PcInstance player, SystemMessageId systemMsg, int position, int time, String... params)
- {
- player.sendPacket(new ExShowScreenMessage(systemMsg, position, time, params));
- }
-
- /**
- * Add a temporary spawn of the specified NPC.
- * @param npcId the ID of the NPC to spawn
- * @param pos the object containing the spawn location coordinates
- * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
- * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
- * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
- */
- public static L2Npc addSpawn(int npcId, IPositionable pos)
- {
- return addSpawn(npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), false, 0, false, 0);
- }
-
- /**
- * Add a temporary spawn of the specified NPC.
- * @param summoner the NPC that requires this spawn
- * @param npcId the ID of the NPC to spawn
- * @param pos the object containing the spawn location coordinates
- * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
- * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
- * @return the {@link L2Npc} object of the newly spawned NPC, {@code null} if the NPC doesn't exist
- */
- public static L2Npc addSpawn(L2Npc summoner, int npcId, IPositionable pos, boolean randomOffset, long despawnDelay)
- {
- return addSpawn(summoner, npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), randomOffset, despawnDelay, false, 0);
- }
-
- /**
- * Add a temporary spawn of the specified NPC.
- * @param npcId the ID of the NPC to spawn
- * @param pos the object containing the spawn location coordinates
- * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
- * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
- * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
- * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
- */
- public static L2Npc addSpawn(int npcId, IPositionable pos, boolean isSummonSpawn)
- {
- return addSpawn(npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), false, 0, isSummonSpawn, 0);
- }
-
- /**
- * Add a temporary spawn of the specified NPC.
- * @param npcId the ID of the NPC to spawn
- * @param pos the object containing the spawn location coordinates
- * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
- * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
- * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
- * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
- * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
- */
- public static L2Npc addSpawn(int npcId, IPositionable pos, boolean randomOffset, long despawnDelay)
- {
- return addSpawn(npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), randomOffset, despawnDelay, false, 0);
- }
-
- /**
- * Add a temporary spawn of the specified NPC.
- * @param npcId the ID of the NPC to spawn
- * @param pos the object containing the spawn location coordinates
- * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
- * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
- * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
- * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
- * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
- * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
- */
- public static L2Npc addSpawn(int npcId, IPositionable pos, boolean randomOffset, long despawnDelay, boolean isSummonSpawn)
- {
- return addSpawn(npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), randomOffset, despawnDelay, isSummonSpawn, 0);
- }
-
- /**
- * Add a temporary spawn of the specified NPC.
- * @param npcId the ID of the NPC to spawn
- * @param pos the object containing the spawn location coordinates
- * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
- * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
- * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
- * @param instanceId the ID of the instance to spawn the NPC in (0 - the open world)
- * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
- * @see #addSpawn(int, IPositionable)
- * @see #addSpawn(int, IPositionable, boolean)
- * @see #addSpawn(int, IPositionable, boolean, long)
- * @see #addSpawn(int, IPositionable, boolean, long, boolean)
- * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
- */
- public static L2Npc addSpawn(int npcId, IPositionable pos, boolean randomOffset, long despawnDelay, boolean isSummonSpawn, int instanceId)
- {
- return addSpawn(npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), randomOffset, despawnDelay, isSummonSpawn, instanceId);
- }
-
- /**
- * Add a temporary spawn of the specified NPC.
- * @param npcId the ID of the NPC to spawn
- * @param x the X coordinate of the spawn location
- * @param y the Y coordinate of the spawn location
- * @param z the Z coordinate (height) of the spawn location
- * @param heading the heading of the NPC
- * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
- * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
- * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
- * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
- * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
- */
- public static L2Npc addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay)
- {
- return addSpawn(npcId, x, y, z, heading, randomOffset, despawnDelay, false, 0);
- }
-
- /**
- * Add a temporary spawn of the specified NPC.
- * @param npcId the ID of the NPC to spawn
- * @param x the X coordinate of the spawn location
- * @param y the Y coordinate of the spawn location
- * @param z the Z coordinate (height) of the spawn location
- * @param heading the heading of the NPC
- * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
- * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
- * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
- * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
- * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
- * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
- */
- public static L2Npc addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay, boolean isSummonSpawn)
- {
- return addSpawn(npcId, x, y, z, heading, randomOffset, despawnDelay, isSummonSpawn, 0);
- }
-
- /**
- * Add a temporary spawn of the specified NPC.
- * @param npcId the ID of the NPC to spawn
- * @param x the X coordinate of the spawn location
- * @param y the Y coordinate of the spawn location
- * @param z the Z coordinate (height) of the spawn location
- * @param heading the heading of the NPC
- * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
- * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
- * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
- * @param instanceId the ID of the instance to spawn the NPC in (0 - the open world)
- * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
- * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
- * @see #addSpawn(int, int, int, int, int, boolean, long)
- * @see #addSpawn(int, int, int, int, int, boolean, long, boolean)
- */
- public static L2Npc addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay, boolean isSummonSpawn, int instanceId)
- {
- return addSpawn(null, npcId, x, y, z, heading, randomOffset, despawnDelay, isSummonSpawn, instanceId);
- }
-
- /**
- * Add a temporary spawn of the specified NPC.
- * @param summoner the NPC that requires this spawn
- * @param npcId the ID of the NPC to spawn
- * @param x the X coordinate of the spawn location
- * @param y the Y coordinate of the spawn location
- * @param z the Z coordinate (height) of the spawn location
- * @param heading the heading of the NPC
- * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
- * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
- * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
- * @param instanceId the ID of the instance to spawn the NPC in (0 - the open world)
- * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
- * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
- * @see #addSpawn(int, int, int, int, int, boolean, long)
- * @see #addSpawn(int, int, int, int, int, boolean, long, boolean)
- */
- public static L2Npc addSpawn(L2Npc summoner, int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay, boolean isSummonSpawn, int instanceId)
- {
- try
- {
- final L2NpcTemplate template = NpcData.getInstance().getTemplate(npcId);
- if (template == null)
- {
- _log.severe("Couldn't find NPC template for ID:" + npcId + "!");
- return null;
- }
-
- if ((x == 0) && (y == 0))
- {
- _log.log(Level.SEVERE, "addSpawn(): invalid spawn coordinates for NPC #" + npcId + "!");
- return null;
- }
-
- if (randomOffset)
- {
- int offset = Rnd.get(50, 100);
- if (Rnd.nextBoolean())
- {
- offset *= -1;
- }
- x += offset;
-
- offset = Rnd.get(50, 100);
- if (Rnd.nextBoolean())
- {
- offset *= -1;
- }
- y += offset;
- }
-
- final L2Spawn spawn = new L2Spawn(template);
- spawn.setInstanceId(instanceId);
- spawn.setHeading(heading);
- spawn.setX(x);
- spawn.setY(y);
- spawn.setZ(z);
- spawn.stopRespawn();
-
- final L2Npc npc = spawn.spawnOne(isSummonSpawn);
- if (despawnDelay > 0)
- {
- npc.scheduleDespawn(despawnDelay);
- }
-
- if (summoner != null)
- {
- summoner.addSummonedNpc(npc);
- }
- return npc;
- }
- catch (Exception e)
- {
- _log.warning("Could not spawn NPC #" + npcId + "; error: " + e.getMessage());
- }
-
- return null;
- }
-
- /**
- * @param trapId
- * @param x
- * @param y
- * @param z
- * @param heading
- * @param skill
- * @param instanceId
- * @return
- */
- public L2TrapInstance addTrap(int trapId, int x, int y, int z, int heading, Skill skill, int instanceId)
- {
- final L2NpcTemplate npcTemplate = NpcData.getInstance().getTemplate(trapId);
- L2TrapInstance trap = new L2TrapInstance(IdFactory.getInstance().getNextId(), npcTemplate, instanceId, -1);
- trap.setCurrentHp(trap.getMaxHp());
- trap.setCurrentMp(trap.getMaxMp());
- trap.setIsInvul(true);
- trap.setHeading(heading);
- trap.spawnMe(x, y, z);
- return trap;
- }
-
- /**
- * @param master
- * @param minionId
- * @return
- */
- public L2Npc addMinion(L2MonsterInstance master, int minionId)
- {
- return MinionList.spawnMinion(master, minionId);
- }
-
- /**
- * Get the amount of an item in player's inventory.
- * @param player the player whose inventory to check
- * @param itemId the ID of the item whose amount to get
- * @return the amount of the specified item in player's inventory
- */
- public static long getQuestItemsCount(L2PcInstance player, int itemId)
- {
- return player.getInventory().getInventoryItemCount(itemId, -1);
- }
-
- /**
- * Get the total amount of all specified items in player's inventory.
- * @param player the player whose inventory to check
- * @param itemIds a list of IDs of items whose amount to get
- * @return the summary amount of all listed items in player's inventory
- */
- public long getQuestItemsCount(L2PcInstance player, int... itemIds)
- {
- long count = 0;
- for (L2ItemInstance item : player.getInventory().getItems())
- {
- if (item == null)
- {
- continue;
- }
-
- for (int itemId : itemIds)
- {
- if (item.getId() == itemId)
- {
- if ((count + item.getCount()) > Long.MAX_VALUE)
- {
- return Long.MAX_VALUE;
- }
- count += item.getCount();
- }
- }
- }
- return count;
- }
-
- /**
- * Check if the player has the specified item in his inventory.
- * @param player the player whose inventory to check for the specified item
- * @param item the {@link ItemHolder} object containing the ID and count of the item to check
- * @return {@code true} if the player has the required count of the item
- */
- protected static boolean hasItem(L2PcInstance player, ItemHolder item)
- {
- return hasItem(player, item, true);
- }
-
- /**
- * Check if the player has the required count of the specified item in his inventory.
- * @param player the player whose inventory to check for the specified item
- * @param item the {@link ItemHolder} object containing the ID and count of the item to check
- * @param checkCount if {@code true}, check if each item is at least of the count specified in the ItemHolder,<br>
- * otherwise check only if the player has the item at all
- * @return {@code true} if the player has the item
- */
- protected static boolean hasItem(L2PcInstance player, ItemHolder item, boolean checkCount)
- {
- if (item == null)
- {
- return false;
- }
- if (checkCount)
- {
- return (getQuestItemsCount(player, item.getId()) >= item.getCount());
- }
- return hasQuestItems(player, item.getId());
- }
-
- /**
- * Check if the player has all the specified items in his inventory and, if necessary, if their count is also as required.
- * @param player the player whose inventory to check for the specified item
- * @param checkCount if {@code true}, check if each item is at least of the count specified in the ItemHolder,<br>
- * otherwise check only if the player has the item at all
- * @param itemList a list of {@link ItemHolder} objects containing the IDs of the items to check
- * @return {@code true} if the player has all the items from the list
- */
- protected static boolean hasAllItems(L2PcInstance player, boolean checkCount, ItemHolder... itemList)
- {
- if ((itemList == null) || (itemList.length == 0))
- {
- return false;
- }
- for (ItemHolder item : itemList)
- {
- if (!hasItem(player, item, checkCount))
- {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Check for an item in player's inventory.
- * @param player the player whose inventory to check for quest items
- * @param itemId the ID of the item to check for
- * @return {@code true} if the item exists in player's inventory, {@code false} otherwise
- */
- public static boolean hasQuestItems(L2PcInstance player, int itemId)
- {
- return (player.getInventory().getItemByItemId(itemId) != null);
- }
-
- /**
- * Check for multiple items in player's inventory.
- * @param player the player whose inventory to check for quest items
- * @param itemIds a list of item IDs to check for
- * @return {@code true} if all items exist in player's inventory, {@code false} otherwise
- */
- public static boolean hasQuestItems(L2PcInstance player, int... itemIds)
- {
- if ((itemIds == null) || (itemIds.length == 0))
- {
- return false;
- }
- final PcInventory inv = player.getInventory();
- for (int itemId : itemIds)
- {
- if (inv.getItemByItemId(itemId) == null)
- {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Check for multiple items in player's inventory.
- * @param player the player whose inventory to check for quest items
- * @param itemIds a list of item IDs to check for
- * @return {@code true} if at least one items exist in player's inventory, {@code false} otherwise
- */
- public boolean hasAtLeastOneQuestItem(L2PcInstance player, int... itemIds)
- {
- final PcInventory inv = player.getInventory();
- for (int itemId : itemIds)
- {
- if (inv.getItemByItemId(itemId) != null)
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Get the enchantment level of an item in player's inventory.
- * @param player the player whose item to check
- * @param itemId the ID of the item whose enchantment level to get
- * @return the enchantment level of the item or 0 if the item was not found
- */
- public static int getEnchantLevel(L2PcInstance player, int itemId)
- {
- final L2ItemInstance enchantedItem = player.getInventory().getItemByItemId(itemId);
- if (enchantedItem == null)
- {
- return 0;
- }
- return enchantedItem.getEnchantLevel();
- }
-
- /**
- * Give Adena to the player.
- * @param player the player to whom to give the Adena
- * @param count the amount of Adena to give
- * @param applyRates if {@code true} quest rates will be applied to the amount
- */
- public void giveAdena(L2PcInstance player, long count, boolean applyRates)
- {
- if (applyRates)
- {
- rewardItems(player, Inventory.ADENA_ID, count);
- }
- else
- {
- giveItems(player, Inventory.ADENA_ID, count);
- }
- }
-
- /**
- * Give a reward to player using multipliers.
- * @param player the player to whom to give the item
- * @param holder
- */
- public static void rewardItems(L2PcInstance player, ItemHolder holder)
- {
- rewardItems(player, holder.getId(), holder.getCount());
- }
-
- /**
- * Give a reward to player using multipliers.
- * @param player the player to whom to give the item
- * @param itemId the ID of the item to give
- * @param count the amount of items to give
- */
- public static void rewardItems(L2PcInstance player, int itemId, long count)
- {
- if (count <= 0)
- {
- return;
- }
-
- final L2ItemInstance _tmpItem = ItemTable.getInstance().createDummyItem(itemId);
- if (_tmpItem == null)
- {
- return;
- }
-
- try
- {
- if (itemId == Inventory.ADENA_ID)
- {
- count *= Config.RATE_QUEST_REWARD_ADENA;
- }
- else if (Config.RATE_QUEST_REWARD_USE_MULTIPLIERS)
- {
- if (_tmpItem.isEtcItem())
- {
- switch (_tmpItem.getEtcItem().getItemType())
- {
- case POTION:
- count *= Config.RATE_QUEST_REWARD_POTION;
- break;
- case SCRL_ENCHANT_WP:
- case SCRL_ENCHANT_AM:
- case SCROLL:
- count *= Config.RATE_QUEST_REWARD_SCROLL;
- break;
- case RECIPE:
- count *= Config.RATE_QUEST_REWARD_RECIPE;
- break;
- case MATERIAL:
- count *= Config.RATE_QUEST_REWARD_MATERIAL;
- break;
- default:
- count *= Config.RATE_QUEST_REWARD;
- }
- }
- }
- else
- {
- count *= Config.RATE_QUEST_REWARD;
- }
- }
- catch (Exception e)
- {
- count = Long.MAX_VALUE;
- }
-
- // Add items to player's inventory
- L2ItemInstance item = player.getInventory().addItem("Quest", itemId, count, player, player.getTarget());
- if (item == null)
- {
- return;
- }
-
- sendItemGetMessage(player, item, count);
- }
-
- /**
- * Send the system message and the status update packets to the player.
- * @param player the player that has got the item
- * @param item the item obtain by the player
- * @param count the item count
- */
- private static void sendItemGetMessage(L2PcInstance player, L2ItemInstance item, long count)
- {
- // If item for reward is gold, send message of gold reward to client
- if (item.getId() == Inventory.ADENA_ID)
- {
- SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S1_ADENA);
- smsg.addLong(count);
- player.sendPacket(smsg);
- }
- // Otherwise, send message of object reward to client
- else
- {
- if (count > 1)
- {
- SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S);
- smsg.addItemName(item);
- smsg.addLong(count);
- player.sendPacket(smsg);
- }
- else
- {
- SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.EARNED_ITEM_S1);
- smsg.addItemName(item);
- player.sendPacket(smsg);
- }
- }
- // send packets
- StatusUpdate su = new StatusUpdate(player);
- su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
- player.sendPacket(su);
- }
-
- /**
- * Give item/reward to the player
- * @param player
- * @param itemId
- * @param count
- */
- public static void giveItems(L2PcInstance player, int itemId, long count)
- {
- giveItems(player, itemId, count, 0);
- }
-
- /**
- * Give item/reward to the player
- * @param player
- * @param holder
- */
- protected static void giveItems(L2PcInstance player, ItemHolder holder)
- {
- giveItems(player, holder.getId(), holder.getCount());
- }
-
- /**
- * @param player
- * @param itemId
- * @param count
- * @param enchantlevel
- */
- public static void giveItems(L2PcInstance player, int itemId, long count, int enchantlevel)
- {
- if (count <= 0)
- {
- return;
- }
-
- // Add items to player's inventory
- final L2ItemInstance item = player.getInventory().addItem("Quest", itemId, count, player, player.getTarget());
- if (item == null)
- {
- return;
- }
-
- // set enchant level for item if that item is not adena
- if ((enchantlevel > 0) && (itemId != Inventory.ADENA_ID))
- {
- item.setEnchantLevel(enchantlevel);
- }
-
- sendItemGetMessage(player, item, count);
- }
-
- /**
- * @param player
- * @param itemId
- * @param count
- * @param attributeId
- * @param attributeLevel
- */
- public static void giveItems(L2PcInstance player, int itemId, long count, byte attributeId, int attributeLevel)
- {
- if (count <= 0)
- {
- return;
- }
-
- // Add items to player's inventory
- final L2ItemInstance item = player.getInventory().addItem("Quest", itemId, count, player, player.getTarget());
- if (item == null)
- {
- return;
- }
-
- // set enchant level for item if that item is not adena
- if ((attributeId >= 0) && (attributeLevel > 0))
- {
- item.setElementAttr(attributeId, attributeLevel);
- if (item.isEquipped())
- {
- item.updateElementAttrBonus(player);
- }
-
- InventoryUpdate iu = new InventoryUpdate();
- iu.addModifiedItem(item);
- player.sendPacket(iu);
- }
-
- sendItemGetMessage(player, item, count);
- }
-
- /**
- * Give the specified player a set amount of items if he is lucky enough.<br>
- * Not recommended to use this for non-stacking items.
- * @param player the player to give the item(s) to
- * @param itemId the ID of the item to give
- * @param amountToGive the amount of items to give
- * @param limit the maximum amount of items the player can have. Won't give more if this limit is reached. 0 - no limit.
- * @param dropChance the drop chance as a decimal digit from 0 to 1
- * @param playSound if true, plays ItemSound.quest_itemget when items are given and ItemSound.quest_middle when the limit is reached
- * @return {@code true} if limit > 0 and the limit was reached or if limit <= 0 and items were given; {@code false} in all other cases
- */
- public static boolean giveItemRandomly(L2PcInstance player, int itemId, long amountToGive, long limit, double dropChance, boolean playSound)
- {
- return giveItemRandomly(player, null, itemId, amountToGive, amountToGive, limit, dropChance, playSound);
- }
-
- /**
- * Give the specified player a set amount of items if he is lucky enough.<br>
- * Not recommended to use this for non-stacking items.
- * @param player the player to give the item(s) to
- * @param npc the NPC that "dropped" the item (can be null)
- * @param itemId the ID of the item to give
- * @param amountToGive the amount of items to give
- * @param limit the maximum amount of items the player can have. Won't give more if this limit is reached. 0 - no limit.
- * @param dropChance the drop chance as a decimal digit from 0 to 1
- * @param playSound if true, plays ItemSound.quest_itemget when items are given and ItemSound.quest_middle when the limit is reached
- * @return {@code true} if limit > 0 and the limit was reached or if limit <= 0 and items were given; {@code false} in all other cases
- */
- public static boolean giveItemRandomly(L2PcInstance player, L2Npc npc, int itemId, long amountToGive, long limit, double dropChance, boolean playSound)
- {
- return giveItemRandomly(player, npc, itemId, amountToGive, amountToGive, limit, dropChance, playSound);
- }
-
- /**
- * Give the specified player a random amount of items if he is lucky enough.<br>
- * Not recommended to use this for non-stacking items.
- * @param player the player to give the item(s) to
- * @param npc the NPC that "dropped" the item (can be null)
- * @param itemId the ID of the item to give
- * @param minAmount the minimum amount of items to give
- * @param maxAmount the maximum amount of items to give (will give a random amount between min/maxAmount multiplied by quest rates)
- * @param limit the maximum amount of items the player can have. Won't give more if this limit is reached. 0 - no limit.
- * @param dropChance the drop chance as a decimal digit from 0 to 1
- * @param playSound if true, plays ItemSound.quest_itemget when items are given and ItemSound.quest_middle when the limit is reached
- * @return {@code true} if limit > 0 and the limit was reached or if limit <= 0 and items were given; {@code false} in all other cases
- */
- public static boolean giveItemRandomly(L2PcInstance player, L2Npc npc, int itemId, long minAmount, long maxAmount, long limit, double dropChance, boolean playSound)
- {
- final long currentCount = getQuestItemsCount(player, itemId);
-
- if ((limit > 0) && (currentCount >= limit))
- {
- return true;
- }
-
- minAmount *= Config.RATE_QUEST_DROP;
- maxAmount *= Config.RATE_QUEST_DROP;
- dropChance *= Config.RATE_QUEST_DROP; // TODO separate configs for rate and amount
- if ((npc != null) && Config.L2JMOD_CHAMPION_ENABLE && npc.isChampion())
- {
- dropChance *= Config.L2JMOD_CHAMPION_REWARDS;
- if ((itemId == Inventory.ADENA_ID) || (itemId == Inventory.ANCIENT_ADENA_ID))
- {
- minAmount *= Config.L2JMOD_CHAMPION_ADENAS_REWARDS;
- maxAmount *= Config.L2JMOD_CHAMPION_ADENAS_REWARDS;
- }
- else
- {
- minAmount *= Config.L2JMOD_CHAMPION_REWARDS;
- maxAmount *= Config.L2JMOD_CHAMPION_REWARDS;
- }
- }
-
- long amountToGive = ((minAmount == maxAmount) ? minAmount : Rnd.get(minAmount, maxAmount));
- final double random = Rnd.nextDouble();
- // Inventory slot check (almost useless for non-stacking items)
- if ((dropChance >= random) && (amountToGive > 0) && player.getInventory().validateCapacityByItemId(itemId))
- {
- if ((limit > 0) && ((currentCount + amountToGive) > limit))
- {
- amountToGive = limit - currentCount;
- }
-
- // Give the item to player
- L2ItemInstance item = player.addItem("Quest", itemId, amountToGive, npc, true);
- if (item != null)
- {
- // limit reached (if there is no limit, this block doesn't execute)
- if ((currentCount + amountToGive) == limit)
- {
- if (playSound)
- {
- playSound(player, QuestSound.ITEMSOUND_QUEST_MIDDLE);
- }
- return true;
- }
-
- if (playSound)
- {
- playSound(player, QuestSound.ITEMSOUND_QUEST_ITEMGET);
- }
- // if there is no limit, return true every time an item is given
- if (limit <= 0)
- {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Take an amount of a specified item from player's inventory.
- * @param player the player whose item to take
- * @param itemId the ID of the item to take
- * @param amount the amount to take
- * @return {@code true} if any items were taken, {@code false} otherwise
- */
- public static boolean takeItems(L2PcInstance player, int itemId, long amount)
- {
- // Get object item from player's inventory list
- final L2ItemInstance item = player.getInventory().getItemByItemId(itemId);
- if (item == null)
- {
- return false;
- }
-
- // Tests on count value in order not to have negative value
- if ((amount < 0) || (amount > item.getCount()))
- {
- amount = item.getCount();
- }
-
- // Destroy the quantity of items wanted
- if (item.isEquipped())
- {
- final L2ItemInstance[] unequiped = player.getInventory().unEquipItemInBodySlotAndRecord(item.getItem().getBodyPart());
- InventoryUpdate iu = new InventoryUpdate();
- for (L2ItemInstance itm : unequiped)
- {
- iu.addModifiedItem(itm);
- }
- player.sendPacket(iu);
- player.broadcastUserInfo();
- }
- return player.destroyItemByItemId("Quest", itemId, amount, player, true);
- }
-
- /**
- * Take a set amount of a specified item from player's inventory.
- * @param player the player whose item to take
- * @param holder the {@link ItemHolder} object containing the ID and count of the item to take
- * @return {@code true} if the item was taken, {@code false} otherwise
- */
- protected static boolean takeItem(L2PcInstance player, ItemHolder holder)
- {
- if (holder == null)
- {
- return false;
- }
- return takeItems(player, holder.getId(), holder.getCount());
- }
-
- /**
- * Take a set amount of all specified items from player's inventory.
- * @param player the player whose items to take
- * @param itemList the list of {@link ItemHolder} objects containing the IDs and counts of the items to take
- * @return {@code true} if all items were taken, {@code false} otherwise
- */
- protected static boolean takeAllItems(L2PcInstance player, ItemHolder... itemList)
- {
- if ((itemList == null) || (itemList.length == 0))
- {
- return false;
- }
- // first check if the player has all items to avoid taking half the items from the list
- if (!hasAllItems(player, true, itemList))
- {
- return false;
- }
- for (ItemHolder item : itemList)
- {
- // this should never be false, but just in case
- if (!takeItem(player, item))
- {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Take an amount of all specified items from player's inventory.
- * @param player the player whose items to take
- * @param amount the amount to take of each item
- * @param itemIds a list or an array of IDs of the items to take
- * @return {@code true} if all items were taken, {@code false} otherwise
- */
- public static boolean takeItems(L2PcInstance player, int amount, int... itemIds)
- {
- boolean check = true;
- if (itemIds != null)
- {
- for (int item : itemIds)
- {
- check &= takeItems(player, item, amount);
- }
- }
- return check;
- }
-
- /**
- * Send a packet in order to play a sound to the player.
- * @param player the player whom to send the packet
- * @param sound the name of the sound to play
- */
- public static void playSound(L2PcInstance player, String sound)
- {
- player.sendPacket(QuestSound.getSound(sound));
- }
-
- /**
- * Send a packet in order to play a sound to the player.
- * @param player the player whom to send the packet
- * @param sound the {@link QuestSound} object of the sound to play
- */
- public static void playSound(L2PcInstance player, QuestSound sound)
- {
- player.sendPacket(sound.getPacket());
- }
-
- /**
- * Add EXP and SP as quest reward.
- * @param player the player whom to reward with the EXP/SP
- * @param exp the amount of EXP to give to the player
- * @param sp the amount of SP to give to the player
- */
- public static void addExpAndSp(L2PcInstance player, long exp, int sp)
- {
- player.addExpAndSp((long) player.calcStat(Stats.EXPSP_RATE, exp * Config.RATE_QUEST_REWARD_XP, null, null), (int) player.calcStat(Stats.EXPSP_RATE, sp * Config.RATE_QUEST_REWARD_SP, null, null));
- }
-
- /**
- * Get a random integer from 0 (inclusive) to {@code max} (exclusive).<br>
- * Use this method instead of importing {@link com.l2jserver.util.Rnd} utility.
- * @param max the maximum value for randomization
- * @return a random integer number from 0 to {@code max - 1}
- */
- public static int getRandom(int max)
- {
- return Rnd.get(max);
- }
-
- /**
- * Get a random integer from {@code min} (inclusive) to {@code max} (inclusive).<br>
- * Use this method instead of importing {@link com.l2jserver.util.Rnd} utility.
- * @param min the minimum value for randomization
- * @param max the maximum value for randomization
- * @return a random integer number from {@code min} to {@code max}
- */
- public static int getRandom(int min, int max)
- {
- return Rnd.get(min, max);
- }
-
- /**
- * Get a random boolean.<br>
- * Use this method instead of importing {@link com.l2jserver.util.Rnd} utility.
- * @return {@code true} or {@code false} randomly
- */
- public static boolean getRandomBoolean()
- {
- return Rnd.nextBoolean();
- }
-
- /**
- * Get the ID of the item equipped in the specified inventory slot of the player.
- * @param player the player whose inventory to check
- * @param slot the location in the player's inventory to check
- * @return the ID of the item equipped in the specified inventory slot or 0 if the slot is empty or item is {@code null}.
- */
- public static int getItemEquipped(L2PcInstance player, int slot)
- {
- return player.getInventory().getPaperdollItemId(slot);
- }
-
- /**
- * @return the number of ticks from the {@link com.l2jserver.gameserver.GameTimeController}.
- */
- public static int getGameTicks()
- {
- return GameTimeController.getInstance().getGameTicks();
- }
-
- /**
- * Execute a procedure for each player depending on the parameters.
- * @param player the player on which the procedure will be executed
- * @param npc the related NPC
- * @param isSummon {@code true} if the event that called this method was originated by the player's summon, {@code false} otherwise
- * @param includeParty if {@code true}, #actionForEachPlayer(L2PcInstance, L2Npc, boolean) will be called with the player's party members
- * @param includeCommandChannel if {@code true}, {@link #actionForEachPlayer(L2PcInstance, L2Npc, boolean)} will be called with the player's command channel members
- * @see #actionForEachPlayer(L2PcInstance, L2Npc, boolean)
- */
- public final void executeForEachPlayer(L2PcInstance player, final L2Npc npc, final boolean isSummon, boolean includeParty, boolean includeCommandChannel)
- {
- if ((includeParty || includeCommandChannel) && player.isInParty())
- {
- if (includeCommandChannel && player.getParty().isInCommandChannel())
- {
- player.getParty().getCommandChannel().forEachMember(member ->
- {
- actionForEachPlayer(member, npc, isSummon);
- return true;
- });
- }
- else if (includeParty)
- {
- player.getParty().forEachMember(member ->
- {
- actionForEachPlayer(member, npc, isSummon);
- return true;
- });
- }
- }
- else
- {
- actionForEachPlayer(player, npc, isSummon);
- }
- }
-
- /**
- * Overridable method called from {@link #executeForEachPlayer(L2PcInstance, L2Npc, boolean, boolean, boolean)}
- * @param player the player on which the action will be run
- * @param npc the NPC related to this action
- * @param isSummon {@code true} if the event that called this method was originated by the player's summon
- */
- public void actionForEachPlayer(L2PcInstance player, L2Npc npc, boolean isSummon)
- {
- // To be overridden in quest scripts.
- }
-
- /**
- * Open a door if it is present on the instance and its not open.
- * @param doorId the ID of the door to open
- * @param instanceId the ID of the instance the door is in (0 if the door is not not inside an instance)
- */
- public void openDoor(int doorId, int instanceId)
- {
- final L2DoorInstance door = getDoor(doorId, instanceId);
- if (door == null)
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": called openDoor(" + doorId + ", " + instanceId + "); but door wasnt found!", new NullPointerException());
- }
- else if (!door.getOpen())
- {
- door.openMe();
- }
- }
-
- /**
- * Close a door if it is present in a specified the instance and its open.
- * @param doorId the ID of the door to close
- * @param instanceId the ID of the instance the door is in (0 if the door is not not inside an instance)
- */
- public void closeDoor(int doorId, int instanceId)
- {
- final L2DoorInstance door = getDoor(doorId, instanceId);
- if (door == null)
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": called closeDoor(" + doorId + ", " + instanceId + "); but door wasnt found!", new NullPointerException());
- }
- else if (door.getOpen())
- {
- door.closeMe();
- }
- }
-
- /**
- * Retrieve a door from an instance or the real world.
- * @param doorId the ID of the door to get
- * @param instanceId the ID of the instance the door is in (0 if the door is not not inside an instance)
- * @return the found door or {@code null} if no door with that ID and instance ID was found
- */
- public L2DoorInstance getDoor(int doorId, int instanceId)
- {
- L2DoorInstance door = null;
- if (instanceId <= 0)
- {
- door = DoorTable.getInstance().getDoor(doorId);
- }
- else
- {
- final Instance inst = InstanceManager.getInstance().getInstance(instanceId);
- if (inst != null)
- {
- door = inst.getDoor(doorId);
- }
- }
- return door;
- }
-
- /**
- * Teleport a player into/out of an instance.
- * @param player the player to teleport
- * @param loc the {@link Location} object containing the destination coordinates
- * @param instanceId the ID of the instance to teleport the player to (0 to teleport out of an instance)
- */
- public void teleportPlayer(L2PcInstance player, Location loc, int instanceId)
- {
- teleportPlayer(player, loc, instanceId, true);
- }
-
- /**
- * Teleport a player into/out of an instance.
- * @param player the player to teleport
- * @param loc the {@link Location} object containing the destination coordinates
- * @param instanceId the ID of the instance to teleport the player to (0 to teleport out of an instance)
- * @param allowRandomOffset if {@code true}, will randomize the teleport coordinates by +/-Config.MAX_OFFSET_ON_TELEPORT
- */
- public void teleportPlayer(L2PcInstance player, Location loc, int instanceId, boolean allowRandomOffset)
- {
- loc.setInstanceId(instanceId);
- player.teleToLocation(loc, allowRandomOffset);
- }
-
- /**
- * Sends the special camera packet to the player.
- * @param player the player
- * @param creature the watched creature
- * @param force
- * @param angle1
- * @param angle2
- * @param time
- * @param range
- * @param duration
- * @param relYaw
- * @param relPitch
- * @param isWide
- * @param relAngle
- */
- public static final void specialCamera(L2PcInstance player, L2Character creature, int force, int angle1, int angle2, int time, int range, int duration, int relYaw, int relPitch, int isWide, int relAngle)
- {
- player.sendPacket(new SpecialCamera(creature, force, angle1, angle2, time, range, duration, relYaw, relPitch, isWide, relAngle));
- }
-
- /**
- * Sends the special camera packet to the player.
- * @param player
- * @param creature
- * @param force
- * @param angle1
- * @param angle2
- * @param time
- * @param duration
- * @param relYaw
- * @param relPitch
- * @param isWide
- * @param relAngle
- */
- public static final void specialCameraEx(L2PcInstance player, L2Character creature, int force, int angle1, int angle2, int time, int duration, int relYaw, int relPitch, int isWide, int relAngle)
- {
- player.sendPacket(new SpecialCamera(creature, player, force, angle1, angle2, time, duration, relYaw, relPitch, isWide, relAngle));
- }
-
- /**
- * Sends the special camera packet to the player.
- * @param player
- * @param creature
- * @param force
- * @param angle1
- * @param angle2
- * @param time
- * @param range
- * @param duration
- * @param relYaw
- * @param relPitch
- * @param isWide
- * @param relAngle
- * @param unk
- */
- public static final void specialCamera3(L2PcInstance player, L2Character creature, int force, int angle1, int angle2, int time, int range, int duration, int relYaw, int relPitch, int isWide, int relAngle, int unk)
- {
- player.sendPacket(new SpecialCamera(creature, force, angle1, angle2, time, range, duration, relYaw, relPitch, isWide, relAngle, unk));
- }
- }
|