AbstractScript.java 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model.events;
  20. import java.lang.annotation.Annotation;
  21. import java.lang.reflect.Method;
  22. import java.util.ArrayList;
  23. import java.util.Arrays;
  24. import java.util.Collection;
  25. import java.util.Collections;
  26. import java.util.List;
  27. import java.util.Map;
  28. import java.util.Set;
  29. import java.util.concurrent.ConcurrentHashMap;
  30. import java.util.function.Consumer;
  31. import java.util.function.Function;
  32. import java.util.logging.Level;
  33. import java.util.logging.Logger;
  34. import javolution.util.FastList;
  35. import javolution.util.FastSet;
  36. import com.l2jserver.Config;
  37. import com.l2jserver.gameserver.GameTimeController;
  38. import com.l2jserver.gameserver.ai.CtrlIntention;
  39. import com.l2jserver.gameserver.datatables.DoorTable;
  40. import com.l2jserver.gameserver.datatables.ItemTable;
  41. import com.l2jserver.gameserver.datatables.NpcData;
  42. import com.l2jserver.gameserver.enums.QuestSound;
  43. import com.l2jserver.gameserver.idfactory.IdFactory;
  44. import com.l2jserver.gameserver.instancemanager.CastleManager;
  45. import com.l2jserver.gameserver.instancemanager.FortManager;
  46. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  47. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  48. import com.l2jserver.gameserver.model.L2Spawn;
  49. import com.l2jserver.gameserver.model.Location;
  50. import com.l2jserver.gameserver.model.actor.L2Attackable;
  51. import com.l2jserver.gameserver.model.actor.L2Character;
  52. import com.l2jserver.gameserver.model.actor.L2Npc;
  53. import com.l2jserver.gameserver.model.actor.L2Playable;
  54. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  55. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  56. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  57. import com.l2jserver.gameserver.model.actor.instance.L2TrapInstance;
  58. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  59. import com.l2jserver.gameserver.model.entity.Castle;
  60. import com.l2jserver.gameserver.model.entity.Fort;
  61. import com.l2jserver.gameserver.model.entity.Instance;
  62. import com.l2jserver.gameserver.model.events.annotations.Id;
  63. import com.l2jserver.gameserver.model.events.annotations.Ids;
  64. import com.l2jserver.gameserver.model.events.annotations.NpcLevelRange;
  65. import com.l2jserver.gameserver.model.events.annotations.NpcLevelRanges;
  66. import com.l2jserver.gameserver.model.events.annotations.Priority;
  67. import com.l2jserver.gameserver.model.events.annotations.Range;
  68. import com.l2jserver.gameserver.model.events.annotations.Ranges;
  69. import com.l2jserver.gameserver.model.events.annotations.RegisterEvent;
  70. import com.l2jserver.gameserver.model.events.annotations.RegisterType;
  71. import com.l2jserver.gameserver.model.events.impl.IBaseEvent;
  72. import com.l2jserver.gameserver.model.events.impl.character.OnCreatureKill;
  73. import com.l2jserver.gameserver.model.events.impl.character.OnCreatureZoneEnter;
  74. import com.l2jserver.gameserver.model.events.impl.character.OnCreatureZoneExit;
  75. import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcCanBeSeen;
  76. import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcCreatureSee;
  77. import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcEventReceived;
  78. import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcFirstTalk;
  79. import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcMoveFinished;
  80. import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcMoveNodeArrived;
  81. import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcMoveRouteFinished;
  82. import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillFinished;
  83. import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillSee;
  84. import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSpawn;
  85. import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcTeleport;
  86. import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAggroRangeEnter;
  87. import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAttack;
  88. import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableFactionCall;
  89. import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableHate;
  90. import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableKill;
  91. import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerLogin;
  92. import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerLogout;
  93. import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerProfessionChange;
  94. import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerSkillLearn;
  95. import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerSummonSpawn;
  96. import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerSummonTalk;
  97. import com.l2jserver.gameserver.model.events.impl.character.trap.OnTrapAction;
  98. import com.l2jserver.gameserver.model.events.impl.item.OnItemBypassEvent;
  99. import com.l2jserver.gameserver.model.events.impl.item.OnItemTalk;
  100. import com.l2jserver.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
  101. import com.l2jserver.gameserver.model.events.impl.sieges.castle.OnCastleSiegeFinish;
  102. import com.l2jserver.gameserver.model.events.impl.sieges.castle.OnCastleSiegeOwnerChange;
  103. import com.l2jserver.gameserver.model.events.impl.sieges.castle.OnCastleSiegeStart;
  104. import com.l2jserver.gameserver.model.events.listeners.AbstractEventListener;
  105. import com.l2jserver.gameserver.model.events.listeners.AnnotationEventListener;
  106. import com.l2jserver.gameserver.model.events.listeners.ConsumerEventListener;
  107. import com.l2jserver.gameserver.model.events.listeners.DummyEventListener;
  108. import com.l2jserver.gameserver.model.events.listeners.FunctionEventListener;
  109. import com.l2jserver.gameserver.model.events.listeners.RunnableEventListener;
  110. import com.l2jserver.gameserver.model.events.returns.AbstractEventReturn;
  111. import com.l2jserver.gameserver.model.events.returns.TerminateReturn;
  112. import com.l2jserver.gameserver.model.holders.ItemHolder;
  113. import com.l2jserver.gameserver.model.holders.SkillHolder;
  114. import com.l2jserver.gameserver.model.interfaces.IPositionable;
  115. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  116. import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
  117. import com.l2jserver.gameserver.model.items.L2Item;
  118. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  119. import com.l2jserver.gameserver.model.olympiad.Olympiad;
  120. import com.l2jserver.gameserver.model.skills.Skill;
  121. import com.l2jserver.gameserver.model.stats.Stats;
  122. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  123. import com.l2jserver.gameserver.network.NpcStringId;
  124. import com.l2jserver.gameserver.network.SystemMessageId;
  125. import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;
  126. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  127. import com.l2jserver.gameserver.network.serverpackets.SpecialCamera;
  128. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  129. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  130. import com.l2jserver.gameserver.scripting.ManagedScript;
  131. import com.l2jserver.gameserver.util.MinionList;
  132. import com.l2jserver.util.Rnd;
  133. /**
  134. * @author UnAfraid
  135. */
  136. public abstract class AbstractScript extends ManagedScript
  137. {
  138. protected static final Logger _log = Logger.getLogger(AbstractScript.class.getName());
  139. private final Map<ListenerRegisterType, Set<Integer>> _registeredIds = new ConcurrentHashMap<>();
  140. private final List<AbstractEventListener> _listeners = new FastList<AbstractEventListener>().shared();
  141. public AbstractScript()
  142. {
  143. initializeAnnotationListeners();
  144. }
  145. private void initializeAnnotationListeners()
  146. {
  147. final List<Integer> ids = new ArrayList<>();
  148. for (Method method : getClass().getMethods())
  149. {
  150. if (method.isAnnotationPresent(RegisterEvent.class) && method.isAnnotationPresent(RegisterType.class))
  151. {
  152. final RegisterEvent listener = method.getAnnotation(RegisterEvent.class);
  153. final RegisterType regType = method.getAnnotation(RegisterType.class);
  154. final ListenerRegisterType type = regType.value();
  155. final EventType eventType = listener.value();
  156. if (method.getParameterCount() != 1)
  157. {
  158. _log.log(Level.WARNING, getClass().getSimpleName() + ": Non properly defined annotation listener on method: " + method.getName() + " expected parameter count is 1 but found: " + method.getParameterCount());
  159. continue;
  160. }
  161. else if (!eventType.isEventClass(method.getParameterTypes()[0]))
  162. {
  163. _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());
  164. continue;
  165. }
  166. else if (!eventType.isReturnClass(method.getReturnType()))
  167. {
  168. _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());
  169. continue;
  170. }
  171. int priority = 0;
  172. // Clear the list
  173. ids.clear();
  174. // Scan for possible Id filters
  175. for (Annotation annotation : method.getAnnotations())
  176. {
  177. if (annotation instanceof Id)
  178. {
  179. final Id npc = (Id) annotation;
  180. for (int id : npc.value())
  181. {
  182. ids.add(id);
  183. }
  184. }
  185. else if (annotation instanceof Ids)
  186. {
  187. final Ids npcs = (Ids) annotation;
  188. for (Id npc : npcs.value())
  189. {
  190. for (int id : npc.value())
  191. {
  192. ids.add(id);
  193. }
  194. }
  195. }
  196. else if (annotation instanceof Range)
  197. {
  198. final Range range = (Range) annotation;
  199. if (range.from() > range.to())
  200. {
  201. _log.log(Level.WARNING, getClass().getSimpleName() + ": Wrong " + annotation.getClass().getSimpleName() + " from is higher then to!");
  202. continue;
  203. }
  204. for (int id = range.from(); id <= range.to(); id++)
  205. {
  206. ids.add(id);
  207. }
  208. }
  209. else if (annotation instanceof Ranges)
  210. {
  211. final Ranges ranges = (Ranges) annotation;
  212. for (Range range : ranges.value())
  213. {
  214. if (range.from() > range.to())
  215. {
  216. _log.log(Level.WARNING, getClass().getSimpleName() + ": Wrong " + annotation.getClass().getSimpleName() + " from is higher then to!");
  217. continue;
  218. }
  219. for (int id = range.from(); id <= range.to(); id++)
  220. {
  221. ids.add(id);
  222. }
  223. }
  224. }
  225. else if (annotation instanceof NpcLevelRange)
  226. {
  227. final NpcLevelRange range = (NpcLevelRange) annotation;
  228. if (range.from() > range.to())
  229. {
  230. _log.log(Level.WARNING, getClass().getSimpleName() + ": Wrong " + annotation.getClass().getSimpleName() + " from is higher then to!");
  231. continue;
  232. }
  233. else if (type != ListenerRegisterType.NPC)
  234. {
  235. _log.log(Level.WARNING, getClass().getSimpleName() + ": ListenerRegisterType " + type + " for " + annotation.getClass().getSimpleName() + " NPC is expected!");
  236. continue;
  237. }
  238. for (int level = range.from(); level <= range.to(); level++)
  239. {
  240. final List<L2NpcTemplate> templates = NpcData.getInstance().getAllOfLevel(level);
  241. templates.forEach(template -> ids.add(template.getId()));
  242. }
  243. }
  244. else if (annotation instanceof NpcLevelRanges)
  245. {
  246. final NpcLevelRanges ranges = (NpcLevelRanges) annotation;
  247. for (NpcLevelRange range : ranges.value())
  248. {
  249. if (range.from() > range.to())
  250. {
  251. _log.log(Level.WARNING, getClass().getSimpleName() + ": Wrong " + annotation.getClass().getSimpleName() + " from is higher then to!");
  252. continue;
  253. }
  254. else if (type != ListenerRegisterType.NPC)
  255. {
  256. _log.log(Level.WARNING, getClass().getSimpleName() + ": ListenerRegisterType " + type + " for " + annotation.getClass().getSimpleName() + " NPC is expected!");
  257. continue;
  258. }
  259. for (int level = range.from(); level <= range.to(); level++)
  260. {
  261. final List<L2NpcTemplate> templates = NpcData.getInstance().getAllOfLevel(level);
  262. templates.forEach(template -> ids.add(template.getId()));
  263. }
  264. }
  265. }
  266. else if (annotation instanceof Priority)
  267. {
  268. final Priority p = (Priority) annotation;
  269. priority = p.value();
  270. }
  271. }
  272. if (!ids.isEmpty())
  273. {
  274. if (!_registeredIds.containsKey(type))
  275. {
  276. _registeredIds.put(type, new FastSet<Integer>().shared());
  277. }
  278. _registeredIds.get(type).addAll(ids);
  279. }
  280. registerAnnotation(method, eventType, type, priority, ids);
  281. }
  282. }
  283. }
  284. /**
  285. * Unloads all listeners registered by this class.
  286. */
  287. @Override
  288. public boolean unload()
  289. {
  290. _listeners.forEach(AbstractEventListener::unregisterMe);
  291. _listeners.clear();
  292. return true;
  293. }
  294. // ---------------------------------------------------------------------------------------------------------------------------
  295. /**
  296. * Provides delayed (Depending on {@link com.l2jserver.gameserver.model.actor.L2Attackable#getOnKillDelay()}) callback operation when L2Attackable dies from a player.
  297. * @param callback
  298. * @param npcIds
  299. * @return
  300. */
  301. protected final List<AbstractEventListener> setAttackableKillId(Consumer<OnAttackableKill> callback, int... npcIds)
  302. {
  303. return registerConsumer(callback, EventType.ON_ATTACKABLE_KILL, ListenerRegisterType.NPC, npcIds);
  304. }
  305. /**
  306. * Provides delayed (Depending on {@link com.l2jserver.gameserver.model.actor.L2Attackable#getOnKillDelay()}) callback operation when L2Attackable dies from a player.
  307. * @param callback
  308. * @param npcIds
  309. * @return
  310. */
  311. protected final List<AbstractEventListener> setAttackableKillId(Consumer<OnAttackableKill> callback, Collection<Integer> npcIds)
  312. {
  313. return registerConsumer(callback, EventType.ON_ATTACKABLE_KILL, ListenerRegisterType.NPC, npcIds);
  314. }
  315. // ---------------------------------------------------------------------------------------------------------------------------
  316. /**
  317. * Provides instant callback operation when L2Attackable dies from a player with return type.
  318. * @param callback
  319. * @param npcIds
  320. * @return
  321. */
  322. protected final List<AbstractEventListener> addCreatureKillId(Function<OnCreatureKill, ? extends AbstractEventReturn> callback, int... npcIds)
  323. {
  324. return registerFunction(callback, EventType.ON_CREATURE_KILL, ListenerRegisterType.NPC, npcIds);
  325. }
  326. /**
  327. * Provides instant callback operation when L2Attackable dies from a player.
  328. * @param callback
  329. * @param npcIds
  330. * @return
  331. */
  332. protected final List<AbstractEventListener> setCreatureKillId(Consumer<OnCreatureKill> callback, int... npcIds)
  333. {
  334. return registerConsumer(callback, EventType.ON_CREATURE_KILL, ListenerRegisterType.NPC, npcIds);
  335. }
  336. /**
  337. * Provides instant callback operation when {@link L2Attackable} dies from a {@link L2PcInstance}.
  338. * @param callback
  339. * @param npcIds
  340. * @return
  341. */
  342. protected final List<AbstractEventListener> setCreatureKillId(Consumer<OnCreatureKill> callback, Collection<Integer> npcIds)
  343. {
  344. return registerConsumer(callback, EventType.ON_CREATURE_KILL, ListenerRegisterType.NPC, npcIds);
  345. }
  346. // ---------------------------------------------------------------------------------------------------------------------------
  347. /**
  348. * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc} for first time.
  349. * @param callback
  350. * @param npcIds
  351. * @return
  352. */
  353. protected final List<AbstractEventListener> setNpcFirstTalkId(Consumer<OnNpcFirstTalk> callback, int... npcIds)
  354. {
  355. return registerConsumer(callback, EventType.ON_NPC_FIRST_TALK, ListenerRegisterType.NPC, npcIds);
  356. }
  357. /**
  358. * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc} for first time.
  359. * @param callback
  360. * @param npcIds
  361. * @return
  362. */
  363. protected final List<AbstractEventListener> setNpcFirstTalkId(Consumer<OnNpcFirstTalk> callback, Collection<Integer> npcIds)
  364. {
  365. return registerConsumer(callback, EventType.ON_NPC_FIRST_TALK, ListenerRegisterType.NPC, npcIds);
  366. }
  367. // ---------------------------------------------------------------------------------------------------------------------------
  368. /**
  369. * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc}.
  370. * @param npcIds
  371. * @return
  372. */
  373. protected final List<AbstractEventListener> setNpcTalkId(Collection<Integer> npcIds)
  374. {
  375. return registerDummy(EventType.ON_NPC_TALK, ListenerRegisterType.NPC, npcIds);
  376. }
  377. /**
  378. * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc}.
  379. * @param npcIds
  380. * @return
  381. */
  382. protected final List<AbstractEventListener> setNpcTalkId(int... npcIds)
  383. {
  384. return registerDummy(EventType.ON_NPC_TALK, ListenerRegisterType.NPC, npcIds);
  385. }
  386. // ---------------------------------------------------------------------------------------------------------------------------
  387. /**
  388. * Provides instant callback operation when teleport {@link L2Npc}.
  389. * @param callback
  390. * @param npcIds
  391. * @return
  392. */
  393. protected final List<AbstractEventListener> setNpcTeleportId(Consumer<OnNpcTeleport> callback, Collection<Integer> npcIds)
  394. {
  395. return registerConsumer(callback, EventType.ON_NPC_TELEPORT, ListenerRegisterType.NPC, npcIds);
  396. }
  397. /**
  398. * Provides instant callback operation when teleport {@link L2Npc}.
  399. * @param callback
  400. * @param npcIds
  401. * @return
  402. */
  403. protected final List<AbstractEventListener> setNpcTeleportId(Consumer<OnNpcTeleport> callback, int... npcIds)
  404. {
  405. return registerConsumer(callback, EventType.ON_NPC_TELEPORT, ListenerRegisterType.NPC, npcIds);
  406. }
  407. // ---------------------------------------------------------------------------------------------------------------------------
  408. /**
  409. * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc} and must receive quest state.
  410. * @param npcIds
  411. * @return
  412. */
  413. protected final List<AbstractEventListener> setNpcQuestStartId(int... npcIds)
  414. {
  415. return registerDummy(EventType.ON_NPC_QUEST_START, ListenerRegisterType.NPC, npcIds);
  416. }
  417. /**
  418. * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc} and must receive quest state.
  419. * @param npcIds
  420. * @return
  421. */
  422. protected final List<AbstractEventListener> setNpcQuestStartId(Collection<Integer> npcIds)
  423. {
  424. return registerDummy(EventType.ON_NPC_QUEST_START, ListenerRegisterType.NPC, npcIds);
  425. }
  426. // ---------------------------------------------------------------------------------------------------------------------------
  427. /**
  428. * Provides instant callback operation when L2Npc sees skill from a player.
  429. * @param callback
  430. * @param npcIds
  431. * @return
  432. */
  433. protected final List<AbstractEventListener> setNpcSkillSeeId(Consumer<OnNpcSkillSee> callback, int... npcIds)
  434. {
  435. return registerConsumer(callback, EventType.ON_NPC_SKILL_SEE, ListenerRegisterType.NPC, npcIds);
  436. }
  437. /**
  438. * Provides instant callback operation when L2Npc sees skill from a player.
  439. * @param callback
  440. * @param npcIds
  441. * @return
  442. */
  443. protected final List<AbstractEventListener> setNpcSkillSeeId(Consumer<OnNpcSkillSee> callback, Collection<Integer> npcIds)
  444. {
  445. return registerConsumer(callback, EventType.ON_NPC_SKILL_SEE, ListenerRegisterType.NPC, npcIds);
  446. }
  447. // ---------------------------------------------------------------------------------------------------------------------------
  448. /**
  449. * Provides instant callback operation when L2Npc casts skill on a player.
  450. * @param callback
  451. * @param npcIds
  452. * @return
  453. */
  454. protected final List<AbstractEventListener> setNpcSkillFinishedId(Consumer<OnNpcSkillFinished> callback, int... npcIds)
  455. {
  456. return registerConsumer(callback, EventType.ON_NPC_SKILL_FINISHED, ListenerRegisterType.NPC, npcIds);
  457. }
  458. /**
  459. * Provides instant callback operation when L2Npc casts skill on a player.
  460. * @param callback
  461. * @param npcIds
  462. * @return
  463. */
  464. protected final List<AbstractEventListener> setNpcSkillFinishedId(Consumer<OnNpcSkillFinished> callback, Collection<Integer> npcIds)
  465. {
  466. return registerConsumer(callback, EventType.ON_NPC_SKILL_FINISHED, ListenerRegisterType.NPC, npcIds);
  467. }
  468. // ---------------------------------------------------------------------------------------------------------------------------
  469. /**
  470. * Provides instant callback operation when L2Npc is spawned.
  471. * @param callback
  472. * @param npcIds
  473. * @return
  474. */
  475. protected final List<AbstractEventListener> setNpcSpawnId(Consumer<OnNpcSpawn> callback, int... npcIds)
  476. {
  477. return registerConsumer(callback, EventType.ON_NPC_SPAWN, ListenerRegisterType.NPC, npcIds);
  478. }
  479. /**
  480. * Provides instant callback operation when L2Npc is spawned.
  481. * @param callback
  482. * @param npcIds
  483. * @return
  484. */
  485. protected final List<AbstractEventListener> setNpcSpawnId(Consumer<OnNpcSpawn> callback, Collection<Integer> npcIds)
  486. {
  487. return registerConsumer(callback, EventType.ON_NPC_SPAWN, ListenerRegisterType.NPC, npcIds);
  488. }
  489. // ---------------------------------------------------------------------------------------------------------------------------
  490. /**
  491. * Provides instant callback operation when {@link L2Npc} receives event from another {@link L2Npc}
  492. * @param callback
  493. * @param npcIds
  494. * @return
  495. */
  496. protected final List<AbstractEventListener> setNpcEventReceivedId(Consumer<OnNpcEventReceived> callback, int... npcIds)
  497. {
  498. return registerConsumer(callback, EventType.ON_NPC_EVENT_RECEIVED, ListenerRegisterType.NPC, npcIds);
  499. }
  500. /**
  501. * Provides instant callback operation when {@link L2Npc} receives event from another {@link L2Npc}
  502. * @param callback
  503. * @param npcIds
  504. * @return
  505. */
  506. protected final List<AbstractEventListener> setNpcEventReceivedId(Consumer<OnNpcEventReceived> callback, Collection<Integer> npcIds)
  507. {
  508. return registerConsumer(callback, EventType.ON_NPC_EVENT_RECEIVED, ListenerRegisterType.NPC, npcIds);
  509. }
  510. // ---------------------------------------------------------------------------------------------------------------------------
  511. /**
  512. * Provides instant callback operation when {@link L2Npc} finishes to move.
  513. * @param callback
  514. * @param npcIds
  515. * @return
  516. */
  517. protected final List<AbstractEventListener> setNpcMoveFinishedId(Consumer<OnNpcMoveFinished> callback, int... npcIds)
  518. {
  519. return registerConsumer(callback, EventType.ON_NPC_MOVE_FINISHED, ListenerRegisterType.NPC, npcIds);
  520. }
  521. /**
  522. * Provides instant callback operation when {@link L2Npc} finishes to move.
  523. * @param callback
  524. * @param npcIds
  525. * @return
  526. */
  527. protected final List<AbstractEventListener> setNpcMoveFinishedId(Consumer<OnNpcMoveFinished> callback, Collection<Integer> npcIds)
  528. {
  529. return registerConsumer(callback, EventType.ON_NPC_MOVE_FINISHED, ListenerRegisterType.NPC, npcIds);
  530. }
  531. // ---------------------------------------------------------------------------------------------------------------------------
  532. /**
  533. * Provides instant callback operation when {@link L2Npc} arrive to node of its route
  534. * @param callback
  535. * @param npcIds
  536. * @return
  537. */
  538. protected final List<AbstractEventListener> setNpcMoveNodeArrivedId(Consumer<OnNpcMoveNodeArrived> callback, int... npcIds)
  539. {
  540. return registerConsumer(callback, EventType.ON_NPC_MOVE_NODE_ARRIVED, ListenerRegisterType.NPC, npcIds);
  541. }
  542. /**
  543. * Provides instant callback operation when {@link L2Npc} arrive to node of its route
  544. * @param callback
  545. * @param npcIds
  546. * @return
  547. */
  548. protected final List<AbstractEventListener> setNpcMoveNodeArrivedId(Consumer<OnNpcMoveNodeArrived> callback, Collection<Integer> npcIds)
  549. {
  550. return registerConsumer(callback, EventType.ON_NPC_MOVE_NODE_ARRIVED, ListenerRegisterType.NPC, npcIds);
  551. }
  552. // ---------------------------------------------------------------------------------------------------------------------------
  553. /**
  554. * Provides instant callback operation when {@link L2Npc} finishes to move on its route.
  555. * @param callback
  556. * @param npcIds
  557. * @return
  558. */
  559. protected final List<AbstractEventListener> setNpcMoveRouteFinishedId(Consumer<OnNpcMoveRouteFinished> callback, int... npcIds)
  560. {
  561. return registerConsumer(callback, EventType.ON_NPC_MOVE_ROUTE_FINISHED, ListenerRegisterType.NPC, npcIds);
  562. }
  563. /**
  564. * Provides instant callback operation when {@link L2Npc} finishes to move on its route.
  565. * @param callback
  566. * @param npcIds
  567. * @return
  568. */
  569. protected final List<AbstractEventListener> setNpcMoveRouteFinishedId(Consumer<OnNpcMoveRouteFinished> callback, Collection<Integer> npcIds)
  570. {
  571. return registerConsumer(callback, EventType.ON_NPC_MOVE_ROUTE_FINISHED, ListenerRegisterType.NPC, npcIds);
  572. }
  573. // ---------------------------------------------------------------------------------------------------------------------------
  574. /**
  575. * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
  576. * @param callback
  577. * @param npcIds
  578. * @return
  579. */
  580. protected final List<AbstractEventListener> setNpcHateId(Consumer<OnAttackableHate> callback, int... npcIds)
  581. {
  582. return registerConsumer(callback, EventType.ON_NPC_HATE, ListenerRegisterType.NPC, npcIds);
  583. }
  584. /**
  585. * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
  586. * @param callback
  587. * @param npcIds
  588. * @return
  589. */
  590. protected final List<AbstractEventListener> setNpcHateId(Consumer<OnAttackableHate> callback, Collection<Integer> npcIds)
  591. {
  592. return registerConsumer(callback, EventType.ON_NPC_HATE, ListenerRegisterType.NPC, npcIds);
  593. }
  594. /**
  595. * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
  596. * @param callback
  597. * @param npcIds
  598. * @return
  599. */
  600. protected final List<AbstractEventListener> addNpcHateId(Function<OnAttackableHate, TerminateReturn> callback, int... npcIds)
  601. {
  602. return registerFunction(callback, EventType.ON_NPC_HATE, ListenerRegisterType.NPC, npcIds);
  603. }
  604. /**
  605. * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
  606. * @param callback
  607. * @param npcIds
  608. * @return
  609. */
  610. protected final List<AbstractEventListener> addNpcHateId(Function<OnAttackableHate, TerminateReturn> callback, Collection<Integer> npcIds)
  611. {
  612. return registerFunction(callback, EventType.ON_NPC_HATE, ListenerRegisterType.NPC, npcIds);
  613. }
  614. // ---------------------------------------------------------------------------------------------------------------------------
  615. /**
  616. * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
  617. * @param callback
  618. * @param npcIds
  619. * @return
  620. */
  621. protected final List<AbstractEventListener> setNpcCanBeSeenId(Consumer<OnNpcCanBeSeen> callback, int... npcIds)
  622. {
  623. return registerConsumer(callback, EventType.ON_NPC_CAN_BE_SEEN, ListenerRegisterType.NPC, npcIds);
  624. }
  625. /**
  626. * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
  627. * @param callback
  628. * @param npcIds
  629. * @return
  630. */
  631. protected final List<AbstractEventListener> setNpcCanBeSeenId(Consumer<OnNpcCanBeSeen> callback, Collection<Integer> npcIds)
  632. {
  633. return registerConsumer(callback, EventType.ON_NPC_CAN_BE_SEEN, ListenerRegisterType.NPC, npcIds);
  634. }
  635. /**
  636. * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
  637. * @param callback
  638. * @param npcIds
  639. * @return
  640. */
  641. protected final List<AbstractEventListener> setNpcCanBeSeenId(Function<OnNpcCanBeSeen, TerminateReturn> callback, int... npcIds)
  642. {
  643. return registerFunction(callback, EventType.ON_NPC_CAN_BE_SEEN, ListenerRegisterType.NPC, npcIds);
  644. }
  645. /**
  646. * Provides instant callback operation when {@link L2Npc} is about to hate and start attacking a creature.
  647. * @param callback
  648. * @param npcIds
  649. * @return
  650. */
  651. protected final List<AbstractEventListener> setNpcCanBeSeenId(Function<OnNpcCanBeSeen, TerminateReturn> callback, Collection<Integer> npcIds)
  652. {
  653. return registerFunction(callback, EventType.ON_NPC_CAN_BE_SEEN, ListenerRegisterType.NPC, npcIds);
  654. }
  655. // ---------------------------------------------------------------------------------------------------------------------------
  656. /**
  657. * Provides instant callback operation when {@link L2Npc} sees another creature.
  658. * @param callback
  659. * @param npcIds
  660. * @return
  661. */
  662. protected final List<AbstractEventListener> setNpcCreatureSeeId(Consumer<OnNpcCreatureSee> callback, int... npcIds)
  663. {
  664. return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
  665. }
  666. /**
  667. * Provides instant callback operation when {@link L2Npc} sees another creature.
  668. * @param callback
  669. * @param npcIds
  670. * @return
  671. */
  672. protected final List<AbstractEventListener> setNpcCreatureSeeId(Consumer<OnNpcCreatureSee> callback, Collection<Integer> npcIds)
  673. {
  674. return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
  675. }
  676. // ---------------------------------------------------------------------------------------------------------------------------
  677. /**
  678. * Provides instant callback operation when L2Attackable is under attack to other clan mates.
  679. * @param callback
  680. * @param npcIds
  681. * @return
  682. */
  683. protected final List<AbstractEventListener> setAttackableFactionIdId(Consumer<OnAttackableFactionCall> callback, int... npcIds)
  684. {
  685. return registerConsumer(callback, EventType.ON_ATTACKABLE_FACTION_CALL, ListenerRegisterType.NPC, npcIds);
  686. }
  687. /**
  688. * Provides instant callback operation when L2Attackable is under attack to other clan mates.
  689. * @param callback
  690. * @param npcIds
  691. * @return
  692. */
  693. protected final List<AbstractEventListener> setAttackableFactionIdId(Consumer<OnAttackableFactionCall> callback, Collection<Integer> npcIds)
  694. {
  695. return registerConsumer(callback, EventType.ON_ATTACKABLE_FACTION_CALL, ListenerRegisterType.NPC, npcIds);
  696. }
  697. // ---------------------------------------------------------------------------------------------------------------------------
  698. /**
  699. * Provides instant callback operation when L2Attackable is attacked from a player.
  700. * @param callback
  701. * @param npcIds
  702. * @return
  703. */
  704. protected final List<AbstractEventListener> setAttackableAttackId(Consumer<OnAttackableAttack> callback, int... npcIds)
  705. {
  706. return registerConsumer(callback, EventType.ON_ATTACKABLE_ATTACK, ListenerRegisterType.NPC, npcIds);
  707. }
  708. /**
  709. * Provides instant callback operation when L2Attackable is attacked from a player.
  710. * @param callback
  711. * @param npcIds
  712. * @return
  713. */
  714. protected final List<AbstractEventListener> setAttackableAttackId(Consumer<OnAttackableAttack> callback, Collection<Integer> npcIds)
  715. {
  716. return registerConsumer(callback, EventType.ON_ATTACKABLE_ATTACK, ListenerRegisterType.NPC, npcIds);
  717. }
  718. // ---------------------------------------------------------------------------------------------------------------------------
  719. /**
  720. * Provides instant callback operation when {@link L2PcInstance} enters in {@link L2Attackable}'s aggressive range.
  721. * @param callback
  722. * @param npcIds
  723. * @return
  724. */
  725. protected final List<AbstractEventListener> setAttackableAggroRangeEnterId(Consumer<OnAttackableAggroRangeEnter> callback, int... npcIds)
  726. {
  727. return registerConsumer(callback, EventType.ON_ATTACKABLE_AGGRO_RANGE_ENTER, ListenerRegisterType.NPC, npcIds);
  728. }
  729. /**
  730. * Provides instant callback operation when {@link L2PcInstance} enters in {@link L2Attackable}'s aggressive range.
  731. * @param callback
  732. * @param npcIds
  733. * @return
  734. */
  735. protected final List<AbstractEventListener> setAttackableAggroRangeEnterId(Consumer<OnAttackableAggroRangeEnter> callback, Collection<Integer> npcIds)
  736. {
  737. return registerConsumer(callback, EventType.ON_ATTACKABLE_AGGRO_RANGE_ENTER, ListenerRegisterType.NPC, npcIds);
  738. }
  739. // ---------------------------------------------------------------------------------------------------------------------------
  740. /**
  741. * Provides instant callback operation when {@link L2PcInstance} learn's a {@link Skill}.
  742. * @param callback
  743. * @param npcIds
  744. * @return
  745. */
  746. protected final List<AbstractEventListener> setPlayerSkillLearnId(Consumer<OnPlayerSkillLearn> callback, int... npcIds)
  747. {
  748. return registerConsumer(callback, EventType.ON_PLAYER_SKILL_LEARN, ListenerRegisterType.NPC, npcIds);
  749. }
  750. /**
  751. * Provides instant callback operation when {@link L2PcInstance} learn's a {@link Skill}.
  752. * @param callback
  753. * @param npcIds
  754. * @return
  755. */
  756. protected final List<AbstractEventListener> setPlayerSkillLearnId(Consumer<OnPlayerSkillLearn> callback, Collection<Integer> npcIds)
  757. {
  758. return registerConsumer(callback, EventType.ON_PLAYER_SKILL_LEARN, ListenerRegisterType.NPC, npcIds);
  759. }
  760. // ---------------------------------------------------------------------------------------------------------------------------
  761. /**
  762. * Provides instant callback operation when {@link L2PcInstance} summons a servitor or a pet
  763. * @param callback
  764. * @param npcIds
  765. * @return
  766. */
  767. protected final List<AbstractEventListener> setPlayerSummonSpawnId(Consumer<OnPlayerSummonSpawn> callback, int... npcIds)
  768. {
  769. return registerConsumer(callback, EventType.ON_PLAYER_SUMMON_SPAWN, ListenerRegisterType.NPC, npcIds);
  770. }
  771. /**
  772. * Provides instant callback operation when {@link L2PcInstance} summons a servitor or a pet
  773. * @param callback
  774. * @param npcIds
  775. * @return
  776. */
  777. protected final List<AbstractEventListener> setPlayerSummonSpawnId(Consumer<OnPlayerSummonSpawn> callback, Collection<Integer> npcIds)
  778. {
  779. return registerConsumer(callback, EventType.ON_PLAYER_SUMMON_SPAWN, ListenerRegisterType.NPC, npcIds);
  780. }
  781. // ---------------------------------------------------------------------------------------------------------------------------
  782. /**
  783. * Provides instant callback operation when {@link L2PcInstance} talk with a servitor or a pet
  784. * @param callback
  785. * @param npcIds
  786. * @return
  787. */
  788. protected final List<AbstractEventListener> setPlayerSummonTalkId(Consumer<OnPlayerSummonTalk> callback, int... npcIds)
  789. {
  790. return registerConsumer(callback, EventType.ON_PLAYER_SUMMON_TALK, ListenerRegisterType.NPC, npcIds);
  791. }
  792. /**
  793. * Provides instant callback operation when {@link L2PcInstance} talk with a servitor or a pet
  794. * @param callback
  795. * @param npcIds
  796. * @return
  797. */
  798. protected final List<AbstractEventListener> setPlayerSummonTalkId(Consumer<OnPlayerSummonSpawn> callback, Collection<Integer> npcIds)
  799. {
  800. return registerConsumer(callback, EventType.ON_PLAYER_SUMMON_TALK, ListenerRegisterType.NPC, npcIds);
  801. }
  802. // ---------------------------------------------------------------------------------------------------------------------------
  803. /**
  804. * Provides instant callback operation when {@link L2PcInstance} summons a servitor or a pet
  805. * @param callback
  806. * @return
  807. */
  808. protected final List<AbstractEventListener> setPlayerLoginId(Consumer<OnPlayerLogin> callback)
  809. {
  810. return registerConsumer(callback, EventType.ON_PLAYER_LOGIN, ListenerRegisterType.GLOBAL);
  811. }
  812. // ---------------------------------------------------------------------------------------------------------------------------
  813. /**
  814. * Provides instant callback operation when {@link L2PcInstance} summons a servitor or a pet
  815. * @param callback
  816. * @return
  817. */
  818. protected final List<AbstractEventListener> setPlayerLogoutId(Consumer<OnPlayerLogout> callback)
  819. {
  820. return registerConsumer(callback, EventType.ON_PLAYER_LOGOUT, ListenerRegisterType.GLOBAL);
  821. }
  822. // ---------------------------------------------------------------------------------------------------------------------------
  823. /**
  824. * Provides instant callback operation when {@link com.l2jserver.gameserver.model.actor.L2Character} Enters on a {@link L2ZoneType}.
  825. * @param callback
  826. * @param npcIds
  827. * @return
  828. */
  829. protected final List<AbstractEventListener> setCreatureZoneEnterId(Consumer<OnCreatureZoneEnter> callback, int... npcIds)
  830. {
  831. return registerConsumer(callback, EventType.ON_CREATURE_ZONE_ENTER, ListenerRegisterType.ZONE, npcIds);
  832. }
  833. /**
  834. * Provides instant callback operation when {@link com.l2jserver.gameserver.model.actor.L2Character} Enters on a {@link L2ZoneType}.
  835. * @param callback
  836. * @param npcIds
  837. * @return
  838. */
  839. protected final List<AbstractEventListener> setCreatureZoneEnterId(Consumer<OnCreatureZoneEnter> callback, Collection<Integer> npcIds)
  840. {
  841. return registerConsumer(callback, EventType.ON_CREATURE_ZONE_ENTER, ListenerRegisterType.ZONE, npcIds);
  842. }
  843. // ---------------------------------------------------------------------------------------------------------------------------
  844. /**
  845. * Provides instant callback operation when {@link com.l2jserver.gameserver.model.actor.L2Character} Exits on a {@link L2ZoneType}.
  846. * @param callback
  847. * @param npcIds
  848. * @return
  849. */
  850. protected final List<AbstractEventListener> setCreatureZoneExitId(Consumer<OnCreatureZoneExit> callback, int... npcIds)
  851. {
  852. return registerConsumer(callback, EventType.ON_CREATURE_ZONE_EXIT, ListenerRegisterType.ZONE, npcIds);
  853. }
  854. /**
  855. * Provides instant callback operation when {@link com.l2jserver.gameserver.model.actor.L2Character} Exits on a {@link L2ZoneType}.
  856. * @param callback
  857. * @param npcIds
  858. * @return
  859. */
  860. protected final List<AbstractEventListener> setCreatureZoneExitId(Consumer<OnCreatureZoneExit> callback, Collection<Integer> npcIds)
  861. {
  862. return registerConsumer(callback, EventType.ON_CREATURE_ZONE_EXIT, ListenerRegisterType.ZONE, npcIds);
  863. }
  864. // ---------------------------------------------------------------------------------------------------------------------------
  865. /**
  866. * Provides instant callback operation when {@link com.l2jserver.gameserver.model.actor.instance.L2TrapInstance} acts.
  867. * @param callback
  868. * @param npcIds
  869. * @return
  870. */
  871. protected final List<AbstractEventListener> setTrapActionId(Consumer<OnTrapAction> callback, int... npcIds)
  872. {
  873. return registerConsumer(callback, EventType.ON_TRAP_ACTION, ListenerRegisterType.NPC, npcIds);
  874. }
  875. /**
  876. * Provides instant callback operation when {@link com.l2jserver.gameserver.model.actor.instance.L2TrapInstance} acts.
  877. * @param callback
  878. * @param npcIds
  879. * @return
  880. */
  881. protected final List<AbstractEventListener> setTrapActionId(Consumer<OnTrapAction> callback, Collection<Integer> npcIds)
  882. {
  883. return registerConsumer(callback, EventType.ON_TRAP_ACTION, ListenerRegisterType.NPC, npcIds);
  884. }
  885. // ---------------------------------------------------------------------------------------------------------------------------
  886. /**
  887. * Provides instant callback operation when {@link L2Item} receives an event from {@link L2PcInstance}.
  888. * @param callback
  889. * @param npcIds
  890. * @return
  891. */
  892. protected final List<AbstractEventListener> setItemBypassEvenId(Consumer<OnItemBypassEvent> callback, int... npcIds)
  893. {
  894. return registerConsumer(callback, EventType.ON_ITEM_BYPASS_EVENT, ListenerRegisterType.ITEM, npcIds);
  895. }
  896. /**
  897. * Provides instant callback operation when {@link L2Item} receives an event from {@link L2PcInstance}.
  898. * @param callback
  899. * @param npcIds
  900. * @return
  901. */
  902. protected final List<AbstractEventListener> setItemBypassEvenId(Consumer<OnItemBypassEvent> callback, Collection<Integer> npcIds)
  903. {
  904. return registerConsumer(callback, EventType.ON_ITEM_BYPASS_EVENT, ListenerRegisterType.ITEM, npcIds);
  905. }
  906. // ---------------------------------------------------------------------------------------------------------------------------
  907. /**
  908. * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Item}.
  909. * @param callback
  910. * @param npcIds
  911. * @return
  912. */
  913. protected final List<AbstractEventListener> setItemTalkId(Consumer<OnItemTalk> callback, int... npcIds)
  914. {
  915. return registerConsumer(callback, EventType.ON_ITEM_TALK, ListenerRegisterType.ITEM, npcIds);
  916. }
  917. /**
  918. * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Item}.
  919. * @param callback
  920. * @param npcIds
  921. * @return
  922. */
  923. protected final List<AbstractEventListener> setItemTalkId(Consumer<OnItemTalk> callback, Collection<Integer> npcIds)
  924. {
  925. return registerConsumer(callback, EventType.ON_ITEM_TALK, ListenerRegisterType.ITEM, npcIds);
  926. }
  927. // ---------------------------------------------------------------------------------------------------------------------------
  928. /**
  929. * Provides instant callback operation when Olympiad match finishes.
  930. * @param callback
  931. * @return
  932. */
  933. protected final List<AbstractEventListener> setOlympiadMatchResult(Consumer<OnOlympiadMatchResult> callback)
  934. {
  935. return registerConsumer(callback, EventType.ON_OLYMPIAD_MATCH_RESULT, ListenerRegisterType.OLYMPIAD);
  936. }
  937. // ---------------------------------------------------------------------------------------------------------------------------
  938. /**
  939. * Provides instant callback operation when castle siege begins
  940. * @param callback
  941. * @param castleIds
  942. * @return
  943. */
  944. protected final List<AbstractEventListener> setCastleSiegeStartId(Consumer<OnCastleSiegeStart> callback, int... castleIds)
  945. {
  946. return registerConsumer(callback, EventType.ON_CASTLE_SIEGE_START, ListenerRegisterType.CASTLE, castleIds);
  947. }
  948. /**
  949. * Provides instant callback operation when castle siege begins
  950. * @param callback
  951. * @param castleIds
  952. * @return
  953. */
  954. protected final List<AbstractEventListener> setCastleSiegeStartId(Consumer<OnCastleSiegeStart> callback, Collection<Integer> castleIds)
  955. {
  956. return registerConsumer(callback, EventType.ON_CASTLE_SIEGE_START, ListenerRegisterType.CASTLE, castleIds);
  957. }
  958. // ---------------------------------------------------------------------------------------------------------------------------
  959. /**
  960. * Provides instant callback operation when Castle owner has changed during a siege
  961. * @param callback
  962. * @param castleIds
  963. * @return
  964. */
  965. protected final List<AbstractEventListener> setCastleSiegeOwnerChangeId(Consumer<OnCastleSiegeOwnerChange> callback, int... castleIds)
  966. {
  967. return registerConsumer(callback, EventType.ON_CASTLE_SIEGE_OWNER_CHANGE, ListenerRegisterType.CASTLE, castleIds);
  968. }
  969. /**
  970. * Provides instant callback operation when Castle owner has changed during a siege
  971. * @param callback
  972. * @param castleIds
  973. * @return
  974. */
  975. protected final List<AbstractEventListener> setCastleSiegeOwnerChangeId(Consumer<OnCastleSiegeOwnerChange> callback, Collection<Integer> castleIds)
  976. {
  977. return registerConsumer(callback, EventType.ON_CASTLE_SIEGE_OWNER_CHANGE, ListenerRegisterType.CASTLE, castleIds);
  978. }
  979. // ---------------------------------------------------------------------------------------------------------------------------
  980. /**
  981. * Provides instant callback operation when castle siege ends
  982. * @param callback
  983. * @param castleIds
  984. * @return
  985. */
  986. protected final List<AbstractEventListener> setCastleSiegeFinishId(Consumer<OnCastleSiegeFinish> callback, int... castleIds)
  987. {
  988. return registerConsumer(callback, EventType.ON_CASTLE_SIEGE_FINISH, ListenerRegisterType.CASTLE, castleIds);
  989. }
  990. /**
  991. * Provides instant callback operation when castle siege ends
  992. * @param callback
  993. * @param castleIds
  994. * @return
  995. */
  996. protected final List<AbstractEventListener> setCastleSiegeFinishId(Consumer<OnCastleSiegeFinish> callback, Collection<Integer> castleIds)
  997. {
  998. return registerConsumer(callback, EventType.ON_CASTLE_SIEGE_FINISH, ListenerRegisterType.CASTLE, castleIds);
  999. }
  1000. // ---------------------------------------------------------------------------------------------------------------------------
  1001. /**
  1002. * Provides instant callback operation when player's profession has change
  1003. * @param callback
  1004. * @return
  1005. */
  1006. protected final List<AbstractEventListener> setPlayerProfessionChangeId(Consumer<OnPlayerProfessionChange> callback)
  1007. {
  1008. return registerConsumer(callback, EventType.ON_PLAYER_PROFESSION_CHANGE, ListenerRegisterType.GLOBAL);
  1009. }
  1010. // --------------------------------------------------------------------------------------------------
  1011. // --------------------------------Default listener register methods---------------------------------
  1012. // --------------------------------------------------------------------------------------------------
  1013. /**
  1014. * Method that registers Function type of listeners (Listeners that need parameters but doesn't return objects)
  1015. * @param callback
  1016. * @param type
  1017. * @param registerType
  1018. * @param npcIds
  1019. * @return
  1020. */
  1021. protected final List<AbstractEventListener> registerConsumer(Consumer<? extends IBaseEvent> callback, EventType type, ListenerRegisterType registerType, int... npcIds)
  1022. {
  1023. return registerListener((container) -> new ConsumerEventListener(container, type, callback, this), registerType, npcIds);
  1024. }
  1025. /**
  1026. * Method that registers Function type of listeners (Listeners that need parameters but doesn't return objects)
  1027. * @param callback
  1028. * @param type
  1029. * @param registerType
  1030. * @param npcIds
  1031. * @return
  1032. */
  1033. protected final List<AbstractEventListener> registerConsumer(Consumer<? extends IBaseEvent> callback, EventType type, ListenerRegisterType registerType, Collection<Integer> npcIds)
  1034. {
  1035. return registerListener((container) -> new ConsumerEventListener(container, type, callback, this), registerType, npcIds);
  1036. }
  1037. /**
  1038. * Method that registers Function type of listeners (Listeners that need parameters and return objects)
  1039. * @param callback
  1040. * @param type
  1041. * @param registerType
  1042. * @param npcIds
  1043. * @return
  1044. */
  1045. protected final List<AbstractEventListener> registerFunction(Function<? extends IBaseEvent, ? extends AbstractEventReturn> callback, EventType type, ListenerRegisterType registerType, int... npcIds)
  1046. {
  1047. return registerListener((container) -> new FunctionEventListener(container, type, callback, this), registerType, npcIds);
  1048. }
  1049. /**
  1050. * Method that registers Function type of listeners (Listeners that need parameters and return objects)
  1051. * @param callback
  1052. * @param type
  1053. * @param registerType
  1054. * @param npcIds
  1055. * @return
  1056. */
  1057. protected final List<AbstractEventListener> registerFunction(Function<? extends IBaseEvent, ? extends AbstractEventReturn> callback, EventType type, ListenerRegisterType registerType, Collection<Integer> npcIds)
  1058. {
  1059. return registerListener((container) -> new FunctionEventListener(container, type, callback, this), registerType, npcIds);
  1060. }
  1061. /**
  1062. * Method that registers runnable type of listeners (Listeners that doesn't needs parameters or return objects)
  1063. * @param callback
  1064. * @param type
  1065. * @param registerType
  1066. * @param npcIds
  1067. * @return
  1068. */
  1069. protected final List<AbstractEventListener> registerRunnable(Runnable callback, EventType type, ListenerRegisterType registerType, int... npcIds)
  1070. {
  1071. return registerListener((container) -> new RunnableEventListener(container, type, callback, this), registerType, npcIds);
  1072. }
  1073. /**
  1074. * Method that registers runnable type of listeners (Listeners that doesn't needs parameters or return objects)
  1075. * @param callback
  1076. * @param type
  1077. * @param registerType
  1078. * @param npcIds
  1079. * @return
  1080. */
  1081. protected final List<AbstractEventListener> registerRunnable(Runnable callback, EventType type, ListenerRegisterType registerType, Collection<Integer> npcIds)
  1082. {
  1083. return registerListener((container) -> new RunnableEventListener(container, type, callback, this), registerType, npcIds);
  1084. }
  1085. /**
  1086. * Method that registers runnable type of listeners (Listeners that doesn't needs parameters or return objects)
  1087. * @param callback
  1088. * @param type
  1089. * @param registerType
  1090. * @param priority
  1091. * @param npcIds
  1092. * @return
  1093. */
  1094. protected final List<AbstractEventListener> registerAnnotation(Method callback, EventType type, ListenerRegisterType registerType, int priority, int... npcIds)
  1095. {
  1096. return registerListener((container) -> new AnnotationEventListener(container, type, callback, this, priority), registerType, npcIds);
  1097. }
  1098. /**
  1099. * Method that registers runnable type of listeners (Listeners that doesn't needs parameters or return objects)
  1100. * @param callback
  1101. * @param type
  1102. * @param registerType
  1103. * @param priority
  1104. * @param npcIds
  1105. * @return
  1106. */
  1107. protected final List<AbstractEventListener> registerAnnotation(Method callback, EventType type, ListenerRegisterType registerType, int priority, Collection<Integer> npcIds)
  1108. {
  1109. return registerListener((container) -> new AnnotationEventListener(container, type, callback, this, priority), registerType, npcIds);
  1110. }
  1111. /**
  1112. * Method that registers dummy type of listeners (Listeners doesn't gets notification but just used to check if their type present or not)
  1113. * @param type
  1114. * @param registerType
  1115. * @param npcIds
  1116. * @return
  1117. */
  1118. protected final List<AbstractEventListener> registerDummy(EventType type, ListenerRegisterType registerType, int... npcIds)
  1119. {
  1120. return registerListener((container) -> new DummyEventListener(container, type, this), registerType, npcIds);
  1121. }
  1122. /**
  1123. * Method that registers dummy type of listeners (Listeners doesn't gets notification but just used to check if their type present or not)
  1124. * @param type
  1125. * @param registerType
  1126. * @param npcIds
  1127. * @return
  1128. */
  1129. protected final List<AbstractEventListener> registerDummy(EventType type, ListenerRegisterType registerType, Collection<Integer> npcIds)
  1130. {
  1131. return registerListener((container) -> new DummyEventListener(container, type, this), registerType, npcIds);
  1132. }
  1133. // --------------------------------------------------------------------------------------------------
  1134. // --------------------------------------Register methods--------------------------------------------
  1135. // --------------------------------------------------------------------------------------------------
  1136. /**
  1137. * Generic listener register method
  1138. * @param action
  1139. * @param registerType
  1140. * @param ids
  1141. * @return
  1142. */
  1143. protected final List<AbstractEventListener> registerListener(Function<ListenersContainer, AbstractEventListener> action, ListenerRegisterType registerType, int... ids)
  1144. {
  1145. final List<AbstractEventListener> listeners = new ArrayList<>(ids.length > 0 ? ids.length : 1);
  1146. if (ids.length > 0)
  1147. {
  1148. for (int id : ids)
  1149. {
  1150. switch (registerType)
  1151. {
  1152. case NPC:
  1153. {
  1154. final L2NpcTemplate template = NpcData.getInstance().getTemplate(id);
  1155. if (template != null)
  1156. {
  1157. listeners.add(template.addListener(action.apply(template)));
  1158. }
  1159. break;
  1160. }
  1161. case ZONE:
  1162. {
  1163. final L2ZoneType template = ZoneManager.getInstance().getZoneById(id);
  1164. if (template != null)
  1165. {
  1166. listeners.add(template.addListener(action.apply(template)));
  1167. }
  1168. break;
  1169. }
  1170. case ITEM:
  1171. {
  1172. final L2Item template = ItemTable.getInstance().getTemplate(id);
  1173. if (template != null)
  1174. {
  1175. listeners.add(template.addListener(action.apply(template)));
  1176. }
  1177. break;
  1178. }
  1179. case CASTLE:
  1180. {
  1181. final Castle template = CastleManager.getInstance().getCastleById(id);
  1182. if (template != null)
  1183. {
  1184. listeners.add(template.addListener(action.apply(template)));
  1185. }
  1186. break;
  1187. }
  1188. case FORTRESS:
  1189. {
  1190. final Fort template = FortManager.getInstance().getFortById(id);
  1191. if (template != null)
  1192. {
  1193. listeners.add(template.addListener(action.apply(template)));
  1194. }
  1195. break;
  1196. }
  1197. default:
  1198. {
  1199. _log.log(Level.WARNING, getClass().getSimpleName() + ": Unhandled register type: " + registerType);
  1200. }
  1201. }
  1202. if (!_registeredIds.containsKey(registerType))
  1203. {
  1204. _registeredIds.put(registerType, new FastSet<Integer>().shared());
  1205. }
  1206. _registeredIds.get(registerType).add(id);
  1207. }
  1208. }
  1209. else
  1210. {
  1211. switch (registerType)
  1212. {
  1213. case OLYMPIAD:
  1214. {
  1215. final Olympiad template = Olympiad.getInstance();
  1216. listeners.add(template.addListener(action.apply(template)));
  1217. break;
  1218. }
  1219. case GLOBAL: // Global Listener
  1220. {
  1221. final ListenersContainer template = Containers.Global();
  1222. listeners.add(template.addListener(action.apply(template)));
  1223. break;
  1224. }
  1225. case GLOBAL_NPCS: // Global Npcs Listener
  1226. {
  1227. final ListenersContainer template = Containers.Npcs();
  1228. listeners.add(template.addListener(action.apply(template)));
  1229. break;
  1230. }
  1231. case GLOBAL_MONSTERS: // Global Monsters Listener
  1232. {
  1233. final ListenersContainer template = Containers.Monsters();
  1234. listeners.add(template.addListener(action.apply(template)));
  1235. break;
  1236. }
  1237. case GLOBAL_PLAYERS: // Global Players Listener
  1238. {
  1239. final ListenersContainer template = Containers.Players();
  1240. listeners.add(template.addListener(action.apply(template)));
  1241. break;
  1242. }
  1243. }
  1244. }
  1245. _listeners.addAll(listeners);
  1246. return listeners;
  1247. }
  1248. /**
  1249. * Generic listener register method
  1250. * @param action
  1251. * @param registerType
  1252. * @param ids
  1253. * @return
  1254. */
  1255. protected final List<AbstractEventListener> registerListener(Function<ListenersContainer, AbstractEventListener> action, ListenerRegisterType registerType, Collection<Integer> ids)
  1256. {
  1257. final List<AbstractEventListener> listeners = new ArrayList<>(!ids.isEmpty() ? ids.size() : 1);
  1258. if (!ids.isEmpty())
  1259. {
  1260. for (int id : ids)
  1261. {
  1262. switch (registerType)
  1263. {
  1264. case NPC:
  1265. {
  1266. final L2NpcTemplate template = NpcData.getInstance().getTemplate(id);
  1267. if (template != null)
  1268. {
  1269. listeners.add(template.addListener(action.apply(template)));
  1270. }
  1271. break;
  1272. }
  1273. case ZONE:
  1274. {
  1275. final L2ZoneType template = ZoneManager.getInstance().getZoneById(id);
  1276. if (template != null)
  1277. {
  1278. listeners.add(template.addListener(action.apply(template)));
  1279. }
  1280. break;
  1281. }
  1282. case ITEM:
  1283. {
  1284. final L2Item template = ItemTable.getInstance().getTemplate(id);
  1285. if (template != null)
  1286. {
  1287. listeners.add(template.addListener(action.apply(template)));
  1288. }
  1289. break;
  1290. }
  1291. case CASTLE:
  1292. {
  1293. final Castle template = CastleManager.getInstance().getCastleById(id);
  1294. if (template != null)
  1295. {
  1296. listeners.add(template.addListener(action.apply(template)));
  1297. }
  1298. break;
  1299. }
  1300. case FORTRESS:
  1301. {
  1302. final Fort template = FortManager.getInstance().getFortById(id);
  1303. if (template != null)
  1304. {
  1305. listeners.add(template.addListener(action.apply(template)));
  1306. }
  1307. break;
  1308. }
  1309. default:
  1310. {
  1311. _log.log(Level.WARNING, getClass().getSimpleName() + ": Unhandled register type: " + registerType);
  1312. }
  1313. }
  1314. }
  1315. if (!_registeredIds.containsKey(registerType))
  1316. {
  1317. _registeredIds.put(registerType, new FastSet<Integer>().shared());
  1318. }
  1319. _registeredIds.get(registerType).addAll(ids);
  1320. }
  1321. else
  1322. {
  1323. switch (registerType)
  1324. {
  1325. case OLYMPIAD:
  1326. {
  1327. final Olympiad template = Olympiad.getInstance();
  1328. listeners.add(template.addListener(action.apply(template)));
  1329. break;
  1330. }
  1331. case GLOBAL: // Global Listener
  1332. {
  1333. final ListenersContainer template = Containers.Global();
  1334. listeners.add(template.addListener(action.apply(template)));
  1335. break;
  1336. }
  1337. case GLOBAL_NPCS: // Global Npcs Listener
  1338. {
  1339. final ListenersContainer template = Containers.Npcs();
  1340. listeners.add(template.addListener(action.apply(template)));
  1341. break;
  1342. }
  1343. case GLOBAL_MONSTERS: // Global Monsters Listener
  1344. {
  1345. final ListenersContainer template = Containers.Monsters();
  1346. listeners.add(template.addListener(action.apply(template)));
  1347. break;
  1348. }
  1349. case GLOBAL_PLAYERS: // Global Players Listener
  1350. {
  1351. final ListenersContainer template = Containers.Players();
  1352. listeners.add(template.addListener(action.apply(template)));
  1353. break;
  1354. }
  1355. }
  1356. }
  1357. _listeners.addAll(listeners);
  1358. return listeners;
  1359. }
  1360. public Set<Integer> getRegisteredIds(ListenerRegisterType type)
  1361. {
  1362. return _registeredIds.containsKey(type) ? _registeredIds.get(type) : Collections.emptySet();
  1363. }
  1364. public List<AbstractEventListener> getListeners()
  1365. {
  1366. return _listeners;
  1367. }
  1368. /**
  1369. * -------------------------------------------------------------------------------------------------------
  1370. */
  1371. /**
  1372. * Show an on screen message to the player.
  1373. * @param player the player to display the message to
  1374. * @param text the message to display
  1375. * @param time the duration of the message in milliseconds
  1376. */
  1377. public static void showOnScreenMsg(L2PcInstance player, String text, int time)
  1378. {
  1379. player.sendPacket(new ExShowScreenMessage(text, time));
  1380. }
  1381. /**
  1382. * Show an on screen message to the player.
  1383. * @param player the player to display the message to
  1384. * @param npcString the NPC string to display
  1385. * @param position the position of the message on the screen
  1386. * @param time the duration of the message in milliseconds
  1387. * @param params values of parameters to replace in the NPC String (like S1, C1 etc.)
  1388. */
  1389. public static void showOnScreenMsg(L2PcInstance player, NpcStringId npcString, int position, int time, String... params)
  1390. {
  1391. player.sendPacket(new ExShowScreenMessage(npcString, position, time, params));
  1392. }
  1393. /**
  1394. * Show an on screen message to the player.
  1395. * @param player the player to display the message to
  1396. * @param systemMsg the system message to display
  1397. * @param position the position of the message on the screen
  1398. * @param time the duration of the message in milliseconds
  1399. * @param params values of parameters to replace in the system message (like S1, C1 etc.)
  1400. */
  1401. public static void showOnScreenMsg(L2PcInstance player, SystemMessageId systemMsg, int position, int time, String... params)
  1402. {
  1403. player.sendPacket(new ExShowScreenMessage(systemMsg, position, time, params));
  1404. }
  1405. /**
  1406. * Add a temporary spawn of the specified NPC.
  1407. * @param npcId the ID of the NPC to spawn
  1408. * @param pos the object containing the spawn location coordinates
  1409. * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
  1410. * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
  1411. * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
  1412. */
  1413. public static L2Npc addSpawn(int npcId, IPositionable pos)
  1414. {
  1415. return addSpawn(npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), false, 0, false, 0);
  1416. }
  1417. /**
  1418. * Add a temporary spawn of the specified NPC.
  1419. * @param summoner the NPC that requires this spawn
  1420. * @param npcId the ID of the NPC to spawn
  1421. * @param pos the object containing the spawn location coordinates
  1422. * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
  1423. * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
  1424. * @return the {@link L2Npc} object of the newly spawned NPC, {@code null} if the NPC doesn't exist
  1425. */
  1426. public static L2Npc addSpawn(L2Npc summoner, int npcId, IPositionable pos, boolean randomOffset, long despawnDelay)
  1427. {
  1428. return addSpawn(summoner, npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), randomOffset, despawnDelay, false, 0);
  1429. }
  1430. /**
  1431. * Add a temporary spawn of the specified NPC.
  1432. * @param npcId the ID of the NPC to spawn
  1433. * @param pos the object containing the spawn location coordinates
  1434. * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
  1435. * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
  1436. * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
  1437. * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
  1438. */
  1439. public static L2Npc addSpawn(int npcId, IPositionable pos, boolean isSummonSpawn)
  1440. {
  1441. return addSpawn(npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), false, 0, isSummonSpawn, 0);
  1442. }
  1443. /**
  1444. * Add a temporary spawn of the specified NPC.
  1445. * @param npcId the ID of the NPC to spawn
  1446. * @param pos the object containing the spawn location coordinates
  1447. * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
  1448. * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
  1449. * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
  1450. * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
  1451. * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
  1452. */
  1453. public static L2Npc addSpawn(int npcId, IPositionable pos, boolean randomOffset, long despawnDelay)
  1454. {
  1455. return addSpawn(npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), randomOffset, despawnDelay, false, 0);
  1456. }
  1457. /**
  1458. * Add a temporary spawn of the specified NPC.
  1459. * @param npcId the ID of the NPC to spawn
  1460. * @param pos the object containing the spawn location coordinates
  1461. * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
  1462. * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
  1463. * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
  1464. * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
  1465. * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
  1466. * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
  1467. */
  1468. public static L2Npc addSpawn(int npcId, IPositionable pos, boolean randomOffset, long despawnDelay, boolean isSummonSpawn)
  1469. {
  1470. return addSpawn(npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), randomOffset, despawnDelay, isSummonSpawn, 0);
  1471. }
  1472. /**
  1473. * Add a temporary spawn of the specified NPC.
  1474. * @param npcId the ID of the NPC to spawn
  1475. * @param pos the object containing the spawn location coordinates
  1476. * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
  1477. * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
  1478. * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
  1479. * @param instanceId the ID of the instance to spawn the NPC in (0 - the open world)
  1480. * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
  1481. * @see #addSpawn(int, IPositionable)
  1482. * @see #addSpawn(int, IPositionable, boolean)
  1483. * @see #addSpawn(int, IPositionable, boolean, long)
  1484. * @see #addSpawn(int, IPositionable, boolean, long, boolean)
  1485. * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
  1486. */
  1487. public static L2Npc addSpawn(int npcId, IPositionable pos, boolean randomOffset, long despawnDelay, boolean isSummonSpawn, int instanceId)
  1488. {
  1489. return addSpawn(npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), randomOffset, despawnDelay, isSummonSpawn, instanceId);
  1490. }
  1491. /**
  1492. * Add a temporary spawn of the specified NPC.
  1493. * @param npcId the ID of the NPC to spawn
  1494. * @param x the X coordinate of the spawn location
  1495. * @param y the Y coordinate of the spawn location
  1496. * @param z the Z coordinate (height) of the spawn location
  1497. * @param heading the heading of the NPC
  1498. * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
  1499. * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
  1500. * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
  1501. * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
  1502. * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
  1503. */
  1504. public static L2Npc addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay)
  1505. {
  1506. return addSpawn(npcId, x, y, z, heading, randomOffset, despawnDelay, false, 0);
  1507. }
  1508. /**
  1509. * Add a temporary spawn of the specified NPC.
  1510. * @param npcId the ID of the NPC to spawn
  1511. * @param x the X coordinate of the spawn location
  1512. * @param y the Y coordinate of the spawn location
  1513. * @param z the Z coordinate (height) of the spawn location
  1514. * @param heading the heading of the NPC
  1515. * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
  1516. * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
  1517. * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
  1518. * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
  1519. * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
  1520. * @see #addSpawn(int, int, int, int, int, boolean, long, boolean, int)
  1521. */
  1522. public static L2Npc addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay, boolean isSummonSpawn)
  1523. {
  1524. return addSpawn(npcId, x, y, z, heading, randomOffset, despawnDelay, isSummonSpawn, 0);
  1525. }
  1526. /**
  1527. * Add a temporary spawn of the specified NPC.
  1528. * @param npcId the ID of the NPC to spawn
  1529. * @param x the X coordinate of the spawn location
  1530. * @param y the Y coordinate of the spawn location
  1531. * @param z the Z coordinate (height) of the spawn location
  1532. * @param heading the heading of the NPC
  1533. * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
  1534. * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
  1535. * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
  1536. * @param instanceId the ID of the instance to spawn the NPC in (0 - the open world)
  1537. * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
  1538. * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
  1539. * @see #addSpawn(int, int, int, int, int, boolean, long)
  1540. * @see #addSpawn(int, int, int, int, int, boolean, long, boolean)
  1541. */
  1542. public static L2Npc addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay, boolean isSummonSpawn, int instanceId)
  1543. {
  1544. return addSpawn(null, npcId, x, y, z, heading, randomOffset, despawnDelay, isSummonSpawn, instanceId);
  1545. }
  1546. /**
  1547. * Add a temporary spawn of the specified NPC.
  1548. * @param summoner the NPC that requires this spawn
  1549. * @param npcId the ID of the NPC to spawn
  1550. * @param x the X coordinate of the spawn location
  1551. * @param y the Y coordinate of the spawn location
  1552. * @param z the Z coordinate (height) of the spawn location
  1553. * @param heading the heading of the NPC
  1554. * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
  1555. * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
  1556. * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
  1557. * @param instanceId the ID of the instance to spawn the NPC in (0 - the open world)
  1558. * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
  1559. * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
  1560. * @see #addSpawn(int, int, int, int, int, boolean, long)
  1561. * @see #addSpawn(int, int, int, int, int, boolean, long, boolean)
  1562. */
  1563. public static L2Npc addSpawn(L2Npc summoner, int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay, boolean isSummonSpawn, int instanceId)
  1564. {
  1565. try
  1566. {
  1567. final L2NpcTemplate template = NpcData.getInstance().getTemplate(npcId);
  1568. if (template == null)
  1569. {
  1570. _log.severe("Couldn't find NPC template for ID:" + npcId + "!");
  1571. return null;
  1572. }
  1573. if ((x == 0) && (y == 0))
  1574. {
  1575. _log.log(Level.SEVERE, "addSpawn(): invalid spawn coordinates for NPC #" + npcId + "!");
  1576. return null;
  1577. }
  1578. if (randomOffset)
  1579. {
  1580. int offset = Rnd.get(50, 100);
  1581. if (Rnd.nextBoolean())
  1582. {
  1583. offset *= -1;
  1584. }
  1585. x += offset;
  1586. offset = Rnd.get(50, 100);
  1587. if (Rnd.nextBoolean())
  1588. {
  1589. offset *= -1;
  1590. }
  1591. y += offset;
  1592. }
  1593. final L2Spawn spawn = new L2Spawn(template);
  1594. spawn.setInstanceId(instanceId);
  1595. spawn.setHeading(heading);
  1596. spawn.setX(x);
  1597. spawn.setY(y);
  1598. spawn.setZ(z);
  1599. spawn.stopRespawn();
  1600. final L2Npc npc = spawn.spawnOne(isSummonSpawn);
  1601. if (despawnDelay > 0)
  1602. {
  1603. npc.scheduleDespawn(despawnDelay);
  1604. }
  1605. if (summoner != null)
  1606. {
  1607. summoner.addSummonedNpc(npc);
  1608. }
  1609. return npc;
  1610. }
  1611. catch (Exception e)
  1612. {
  1613. _log.warning("Could not spawn NPC #" + npcId + "; error: " + e.getMessage());
  1614. }
  1615. return null;
  1616. }
  1617. /**
  1618. * @param trapId
  1619. * @param x
  1620. * @param y
  1621. * @param z
  1622. * @param heading
  1623. * @param skill
  1624. * @param instanceId
  1625. * @return
  1626. */
  1627. public L2TrapInstance addTrap(int trapId, int x, int y, int z, int heading, Skill skill, int instanceId)
  1628. {
  1629. final L2NpcTemplate npcTemplate = NpcData.getInstance().getTemplate(trapId);
  1630. L2TrapInstance trap = new L2TrapInstance(IdFactory.getInstance().getNextId(), npcTemplate, instanceId, -1);
  1631. trap.setCurrentHp(trap.getMaxHp());
  1632. trap.setCurrentMp(trap.getMaxMp());
  1633. trap.setIsInvul(true);
  1634. trap.setHeading(heading);
  1635. trap.spawnMe(x, y, z);
  1636. return trap;
  1637. }
  1638. /**
  1639. * @param master
  1640. * @param minionId
  1641. * @return
  1642. */
  1643. public L2Npc addMinion(L2MonsterInstance master, int minionId)
  1644. {
  1645. return MinionList.spawnMinion(master, minionId);
  1646. }
  1647. /**
  1648. * Get the amount of an item in player's inventory.
  1649. * @param player the player whose inventory to check
  1650. * @param itemId the ID of the item whose amount to get
  1651. * @return the amount of the specified item in player's inventory
  1652. */
  1653. public static long getQuestItemsCount(L2PcInstance player, int itemId)
  1654. {
  1655. return player.getInventory().getInventoryItemCount(itemId, -1);
  1656. }
  1657. /**
  1658. * Get the total amount of all specified items in player's inventory.
  1659. * @param player the player whose inventory to check
  1660. * @param itemIds a list of IDs of items whose amount to get
  1661. * @return the summary amount of all listed items in player's inventory
  1662. */
  1663. public long getQuestItemsCount(L2PcInstance player, int... itemIds)
  1664. {
  1665. long count = 0;
  1666. for (L2ItemInstance item : player.getInventory().getItems())
  1667. {
  1668. if (item == null)
  1669. {
  1670. continue;
  1671. }
  1672. for (int itemId : itemIds)
  1673. {
  1674. if (item.getId() == itemId)
  1675. {
  1676. if ((count + item.getCount()) > Long.MAX_VALUE)
  1677. {
  1678. return Long.MAX_VALUE;
  1679. }
  1680. count += item.getCount();
  1681. }
  1682. }
  1683. }
  1684. return count;
  1685. }
  1686. /**
  1687. * Check if the player has the specified item in his inventory.
  1688. * @param player the player whose inventory to check for the specified item
  1689. * @param item the {@link ItemHolder} object containing the ID and count of the item to check
  1690. * @return {@code true} if the player has the required count of the item
  1691. */
  1692. protected static boolean hasItem(L2PcInstance player, ItemHolder item)
  1693. {
  1694. return hasItem(player, item, true);
  1695. }
  1696. /**
  1697. * Check if the player has the required count of the specified item in his inventory.
  1698. * @param player the player whose inventory to check for the specified item
  1699. * @param item the {@link ItemHolder} object containing the ID and count of the item to check
  1700. * @param checkCount if {@code true}, check if each item is at least of the count specified in the ItemHolder,<br>
  1701. * otherwise check only if the player has the item at all
  1702. * @return {@code true} if the player has the item
  1703. */
  1704. protected static boolean hasItem(L2PcInstance player, ItemHolder item, boolean checkCount)
  1705. {
  1706. if (item == null)
  1707. {
  1708. return false;
  1709. }
  1710. if (checkCount)
  1711. {
  1712. return (getQuestItemsCount(player, item.getId()) >= item.getCount());
  1713. }
  1714. return hasQuestItems(player, item.getId());
  1715. }
  1716. /**
  1717. * Check if the player has all the specified items in his inventory and, if necessary, if their count is also as required.
  1718. * @param player the player whose inventory to check for the specified item
  1719. * @param checkCount if {@code true}, check if each item is at least of the count specified in the ItemHolder,<br>
  1720. * otherwise check only if the player has the item at all
  1721. * @param itemList a list of {@link ItemHolder} objects containing the IDs of the items to check
  1722. * @return {@code true} if the player has all the items from the list
  1723. */
  1724. protected static boolean hasAllItems(L2PcInstance player, boolean checkCount, ItemHolder... itemList)
  1725. {
  1726. if ((itemList == null) || (itemList.length == 0))
  1727. {
  1728. return false;
  1729. }
  1730. for (ItemHolder item : itemList)
  1731. {
  1732. if (!hasItem(player, item, checkCount))
  1733. {
  1734. return false;
  1735. }
  1736. }
  1737. return true;
  1738. }
  1739. /**
  1740. * Check for an item in player's inventory.
  1741. * @param player the player whose inventory to check for quest items
  1742. * @param itemId the ID of the item to check for
  1743. * @return {@code true} if the item exists in player's inventory, {@code false} otherwise
  1744. */
  1745. public static boolean hasQuestItems(L2PcInstance player, int itemId)
  1746. {
  1747. return (player.getInventory().getItemByItemId(itemId) != null);
  1748. }
  1749. /**
  1750. * Check for multiple items in player's inventory.
  1751. * @param player the player whose inventory to check for quest items
  1752. * @param itemIds a list of item IDs to check for
  1753. * @return {@code true} if all items exist in player's inventory, {@code false} otherwise
  1754. */
  1755. public static boolean hasQuestItems(L2PcInstance player, int... itemIds)
  1756. {
  1757. if ((itemIds == null) || (itemIds.length == 0))
  1758. {
  1759. return false;
  1760. }
  1761. final PcInventory inv = player.getInventory();
  1762. for (int itemId : itemIds)
  1763. {
  1764. if (inv.getItemByItemId(itemId) == null)
  1765. {
  1766. return false;
  1767. }
  1768. }
  1769. return true;
  1770. }
  1771. /**
  1772. * Check for multiple items in player's inventory.
  1773. * @param player the player whose inventory to check for quest items
  1774. * @param itemIds a list of item IDs to check for
  1775. * @return {@code true} if at least one items exist in player's inventory, {@code false} otherwise
  1776. */
  1777. public boolean hasAtLeastOneQuestItem(L2PcInstance player, int... itemIds)
  1778. {
  1779. final PcInventory inv = player.getInventory();
  1780. for (int itemId : itemIds)
  1781. {
  1782. if (inv.getItemByItemId(itemId) != null)
  1783. {
  1784. return true;
  1785. }
  1786. }
  1787. return false;
  1788. }
  1789. /**
  1790. * Get the enchantment level of an item in player's inventory.
  1791. * @param player the player whose item to check
  1792. * @param itemId the ID of the item whose enchantment level to get
  1793. * @return the enchantment level of the item or 0 if the item was not found
  1794. */
  1795. public static int getEnchantLevel(L2PcInstance player, int itemId)
  1796. {
  1797. final L2ItemInstance enchantedItem = player.getInventory().getItemByItemId(itemId);
  1798. if (enchantedItem == null)
  1799. {
  1800. return 0;
  1801. }
  1802. return enchantedItem.getEnchantLevel();
  1803. }
  1804. /**
  1805. * Give Adena to the player.
  1806. * @param player the player to whom to give the Adena
  1807. * @param count the amount of Adena to give
  1808. * @param applyRates if {@code true} quest rates will be applied to the amount
  1809. */
  1810. public void giveAdena(L2PcInstance player, long count, boolean applyRates)
  1811. {
  1812. if (applyRates)
  1813. {
  1814. rewardItems(player, Inventory.ADENA_ID, count);
  1815. }
  1816. else
  1817. {
  1818. giveItems(player, Inventory.ADENA_ID, count);
  1819. }
  1820. }
  1821. /**
  1822. * Give a reward to player using multipliers.
  1823. * @param player the player to whom to give the item
  1824. * @param holder
  1825. */
  1826. public static void rewardItems(L2PcInstance player, ItemHolder holder)
  1827. {
  1828. rewardItems(player, holder.getId(), holder.getCount());
  1829. }
  1830. /**
  1831. * Give a reward to player using multipliers.
  1832. * @param player the player to whom to give the item
  1833. * @param itemId the ID of the item to give
  1834. * @param count the amount of items to give
  1835. */
  1836. public static void rewardItems(L2PcInstance player, int itemId, long count)
  1837. {
  1838. if (count <= 0)
  1839. {
  1840. return;
  1841. }
  1842. final L2ItemInstance _tmpItem = ItemTable.getInstance().createDummyItem(itemId);
  1843. if (_tmpItem == null)
  1844. {
  1845. return;
  1846. }
  1847. try
  1848. {
  1849. if (itemId == Inventory.ADENA_ID)
  1850. {
  1851. count *= Config.RATE_QUEST_REWARD_ADENA;
  1852. }
  1853. else if (Config.RATE_QUEST_REWARD_USE_MULTIPLIERS)
  1854. {
  1855. if (_tmpItem.isEtcItem())
  1856. {
  1857. switch (_tmpItem.getEtcItem().getItemType())
  1858. {
  1859. case POTION:
  1860. count *= Config.RATE_QUEST_REWARD_POTION;
  1861. break;
  1862. case SCRL_ENCHANT_WP:
  1863. case SCRL_ENCHANT_AM:
  1864. case SCROLL:
  1865. count *= Config.RATE_QUEST_REWARD_SCROLL;
  1866. break;
  1867. case RECIPE:
  1868. count *= Config.RATE_QUEST_REWARD_RECIPE;
  1869. break;
  1870. case MATERIAL:
  1871. count *= Config.RATE_QUEST_REWARD_MATERIAL;
  1872. break;
  1873. default:
  1874. count *= Config.RATE_QUEST_REWARD;
  1875. }
  1876. }
  1877. }
  1878. else
  1879. {
  1880. count *= Config.RATE_QUEST_REWARD;
  1881. }
  1882. }
  1883. catch (Exception e)
  1884. {
  1885. count = Long.MAX_VALUE;
  1886. }
  1887. // Add items to player's inventory
  1888. L2ItemInstance item = player.getInventory().addItem("Quest", itemId, count, player, player.getTarget());
  1889. if (item == null)
  1890. {
  1891. return;
  1892. }
  1893. sendItemGetMessage(player, item, count);
  1894. }
  1895. /**
  1896. * Send the system message and the status update packets to the player.
  1897. * @param player the player that has got the item
  1898. * @param item the item obtain by the player
  1899. * @param count the item count
  1900. */
  1901. private static void sendItemGetMessage(L2PcInstance player, L2ItemInstance item, long count)
  1902. {
  1903. // If item for reward is gold, send message of gold reward to client
  1904. if (item.getId() == Inventory.ADENA_ID)
  1905. {
  1906. SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S1_ADENA);
  1907. smsg.addLong(count);
  1908. player.sendPacket(smsg);
  1909. }
  1910. // Otherwise, send message of object reward to client
  1911. else
  1912. {
  1913. if (count > 1)
  1914. {
  1915. SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S);
  1916. smsg.addItemName(item);
  1917. smsg.addLong(count);
  1918. player.sendPacket(smsg);
  1919. }
  1920. else
  1921. {
  1922. SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.EARNED_ITEM_S1);
  1923. smsg.addItemName(item);
  1924. player.sendPacket(smsg);
  1925. }
  1926. }
  1927. // send packets
  1928. StatusUpdate su = new StatusUpdate(player);
  1929. su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
  1930. player.sendPacket(su);
  1931. }
  1932. /**
  1933. * Give item/reward to the player
  1934. * @param player
  1935. * @param itemId
  1936. * @param count
  1937. */
  1938. public static void giveItems(L2PcInstance player, int itemId, long count)
  1939. {
  1940. giveItems(player, itemId, count, 0);
  1941. }
  1942. /**
  1943. * Give item/reward to the player
  1944. * @param player
  1945. * @param holder
  1946. */
  1947. protected static void giveItems(L2PcInstance player, ItemHolder holder)
  1948. {
  1949. giveItems(player, holder.getId(), holder.getCount());
  1950. }
  1951. /**
  1952. * @param player
  1953. * @param itemId
  1954. * @param count
  1955. * @param enchantlevel
  1956. */
  1957. public static void giveItems(L2PcInstance player, int itemId, long count, int enchantlevel)
  1958. {
  1959. if (count <= 0)
  1960. {
  1961. return;
  1962. }
  1963. // Add items to player's inventory
  1964. final L2ItemInstance item = player.getInventory().addItem("Quest", itemId, count, player, player.getTarget());
  1965. if (item == null)
  1966. {
  1967. return;
  1968. }
  1969. // set enchant level for item if that item is not adena
  1970. if ((enchantlevel > 0) && (itemId != Inventory.ADENA_ID))
  1971. {
  1972. item.setEnchantLevel(enchantlevel);
  1973. }
  1974. sendItemGetMessage(player, item, count);
  1975. }
  1976. /**
  1977. * @param player
  1978. * @param itemId
  1979. * @param count
  1980. * @param attributeId
  1981. * @param attributeLevel
  1982. */
  1983. public static void giveItems(L2PcInstance player, int itemId, long count, byte attributeId, int attributeLevel)
  1984. {
  1985. if (count <= 0)
  1986. {
  1987. return;
  1988. }
  1989. // Add items to player's inventory
  1990. final L2ItemInstance item = player.getInventory().addItem("Quest", itemId, count, player, player.getTarget());
  1991. if (item == null)
  1992. {
  1993. return;
  1994. }
  1995. // set enchant level for item if that item is not adena
  1996. if ((attributeId >= 0) && (attributeLevel > 0))
  1997. {
  1998. item.setElementAttr(attributeId, attributeLevel);
  1999. if (item.isEquipped())
  2000. {
  2001. item.updateElementAttrBonus(player);
  2002. }
  2003. InventoryUpdate iu = new InventoryUpdate();
  2004. iu.addModifiedItem(item);
  2005. player.sendPacket(iu);
  2006. }
  2007. sendItemGetMessage(player, item, count);
  2008. }
  2009. /**
  2010. * Give the specified player a set amount of items if he is lucky enough.<br>
  2011. * Not recommended to use this for non-stacking items.
  2012. * @param player the player to give the item(s) to
  2013. * @param itemId the ID of the item to give
  2014. * @param amountToGive the amount of items to give
  2015. * @param limit the maximum amount of items the player can have. Won't give more if this limit is reached. 0 - no limit.
  2016. * @param dropChance the drop chance as a decimal digit from 0 to 1
  2017. * @param playSound if true, plays ItemSound.quest_itemget when items are given and ItemSound.quest_middle when the limit is reached
  2018. * @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
  2019. */
  2020. public static boolean giveItemRandomly(L2PcInstance player, int itemId, long amountToGive, long limit, double dropChance, boolean playSound)
  2021. {
  2022. return giveItemRandomly(player, null, itemId, amountToGive, amountToGive, limit, dropChance, playSound);
  2023. }
  2024. /**
  2025. * Give the specified player a set amount of items if he is lucky enough.<br>
  2026. * Not recommended to use this for non-stacking items.
  2027. * @param player the player to give the item(s) to
  2028. * @param npc the NPC that "dropped" the item (can be null)
  2029. * @param itemId the ID of the item to give
  2030. * @param amountToGive the amount of items to give
  2031. * @param limit the maximum amount of items the player can have. Won't give more if this limit is reached. 0 - no limit.
  2032. * @param dropChance the drop chance as a decimal digit from 0 to 1
  2033. * @param playSound if true, plays ItemSound.quest_itemget when items are given and ItemSound.quest_middle when the limit is reached
  2034. * @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
  2035. */
  2036. public static boolean giveItemRandomly(L2PcInstance player, L2Npc npc, int itemId, long amountToGive, long limit, double dropChance, boolean playSound)
  2037. {
  2038. return giveItemRandomly(player, npc, itemId, amountToGive, amountToGive, limit, dropChance, playSound);
  2039. }
  2040. /**
  2041. * Give the specified player a random amount of items if he is lucky enough.<br>
  2042. * Not recommended to use this for non-stacking items.
  2043. * @param player the player to give the item(s) to
  2044. * @param npc the NPC that "dropped" the item (can be null)
  2045. * @param itemId the ID of the item to give
  2046. * @param minAmount the minimum amount of items to give
  2047. * @param maxAmount the maximum amount of items to give (will give a random amount between min/maxAmount multiplied by quest rates)
  2048. * @param limit the maximum amount of items the player can have. Won't give more if this limit is reached. 0 - no limit.
  2049. * @param dropChance the drop chance as a decimal digit from 0 to 1
  2050. * @param playSound if true, plays ItemSound.quest_itemget when items are given and ItemSound.quest_middle when the limit is reached
  2051. * @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
  2052. */
  2053. public static boolean giveItemRandomly(L2PcInstance player, L2Npc npc, int itemId, long minAmount, long maxAmount, long limit, double dropChance, boolean playSound)
  2054. {
  2055. final long currentCount = getQuestItemsCount(player, itemId);
  2056. if ((limit > 0) && (currentCount >= limit))
  2057. {
  2058. return true;
  2059. }
  2060. minAmount *= Config.RATE_QUEST_DROP;
  2061. maxAmount *= Config.RATE_QUEST_DROP;
  2062. dropChance *= Config.RATE_QUEST_DROP; // TODO separate configs for rate and amount
  2063. if ((npc != null) && Config.L2JMOD_CHAMPION_ENABLE && npc.isChampion())
  2064. {
  2065. dropChance *= Config.L2JMOD_CHAMPION_REWARDS;
  2066. if ((itemId == Inventory.ADENA_ID) || (itemId == Inventory.ANCIENT_ADENA_ID))
  2067. {
  2068. minAmount *= Config.L2JMOD_CHAMPION_ADENAS_REWARDS;
  2069. maxAmount *= Config.L2JMOD_CHAMPION_ADENAS_REWARDS;
  2070. }
  2071. else
  2072. {
  2073. minAmount *= Config.L2JMOD_CHAMPION_REWARDS;
  2074. maxAmount *= Config.L2JMOD_CHAMPION_REWARDS;
  2075. }
  2076. }
  2077. long amountToGive = ((minAmount == maxAmount) ? minAmount : Rnd.get(minAmount, maxAmount));
  2078. final double random = Rnd.nextDouble();
  2079. // Inventory slot check (almost useless for non-stacking items)
  2080. if ((dropChance >= random) && (amountToGive > 0) && player.getInventory().validateCapacityByItemId(itemId))
  2081. {
  2082. if ((limit > 0) && ((currentCount + amountToGive) > limit))
  2083. {
  2084. amountToGive = limit - currentCount;
  2085. }
  2086. // Give the item to player
  2087. L2ItemInstance item = player.addItem("Quest", itemId, amountToGive, npc, true);
  2088. if (item != null)
  2089. {
  2090. // limit reached (if there is no limit, this block doesn't execute)
  2091. if ((currentCount + amountToGive) == limit)
  2092. {
  2093. if (playSound)
  2094. {
  2095. playSound(player, QuestSound.ITEMSOUND_QUEST_MIDDLE);
  2096. }
  2097. return true;
  2098. }
  2099. if (playSound)
  2100. {
  2101. playSound(player, QuestSound.ITEMSOUND_QUEST_ITEMGET);
  2102. }
  2103. // if there is no limit, return true every time an item is given
  2104. if (limit <= 0)
  2105. {
  2106. return true;
  2107. }
  2108. }
  2109. }
  2110. return false;
  2111. }
  2112. /**
  2113. * Take an amount of a specified item from player's inventory.
  2114. * @param player the player whose item to take
  2115. * @param itemId the ID of the item to take
  2116. * @param amount the amount to take
  2117. * @return {@code true} if any items were taken, {@code false} otherwise
  2118. */
  2119. public static boolean takeItems(L2PcInstance player, int itemId, long amount)
  2120. {
  2121. // Get object item from player's inventory list
  2122. final L2ItemInstance item = player.getInventory().getItemByItemId(itemId);
  2123. if (item == null)
  2124. {
  2125. return false;
  2126. }
  2127. // Tests on count value in order not to have negative value
  2128. if ((amount < 0) || (amount > item.getCount()))
  2129. {
  2130. amount = item.getCount();
  2131. }
  2132. // Destroy the quantity of items wanted
  2133. if (item.isEquipped())
  2134. {
  2135. final L2ItemInstance[] unequiped = player.getInventory().unEquipItemInBodySlotAndRecord(item.getItem().getBodyPart());
  2136. InventoryUpdate iu = new InventoryUpdate();
  2137. for (L2ItemInstance itm : unequiped)
  2138. {
  2139. iu.addModifiedItem(itm);
  2140. }
  2141. player.sendPacket(iu);
  2142. player.broadcastUserInfo();
  2143. }
  2144. return player.destroyItemByItemId("Quest", itemId, amount, player, true);
  2145. }
  2146. /**
  2147. * Take a set amount of a specified item from player's inventory.
  2148. * @param player the player whose item to take
  2149. * @param holder the {@link ItemHolder} object containing the ID and count of the item to take
  2150. * @return {@code true} if the item was taken, {@code false} otherwise
  2151. */
  2152. protected static boolean takeItem(L2PcInstance player, ItemHolder holder)
  2153. {
  2154. if (holder == null)
  2155. {
  2156. return false;
  2157. }
  2158. return takeItems(player, holder.getId(), holder.getCount());
  2159. }
  2160. /**
  2161. * Take a set amount of all specified items from player's inventory.
  2162. * @param player the player whose items to take
  2163. * @param itemList the list of {@link ItemHolder} objects containing the IDs and counts of the items to take
  2164. * @return {@code true} if all items were taken, {@code false} otherwise
  2165. */
  2166. protected static boolean takeAllItems(L2PcInstance player, ItemHolder... itemList)
  2167. {
  2168. if ((itemList == null) || (itemList.length == 0))
  2169. {
  2170. return false;
  2171. }
  2172. // first check if the player has all items to avoid taking half the items from the list
  2173. if (!hasAllItems(player, true, itemList))
  2174. {
  2175. return false;
  2176. }
  2177. for (ItemHolder item : itemList)
  2178. {
  2179. // this should never be false, but just in case
  2180. if (!takeItem(player, item))
  2181. {
  2182. return false;
  2183. }
  2184. }
  2185. return true;
  2186. }
  2187. /**
  2188. * Take an amount of all specified items from player's inventory.
  2189. * @param player the player whose items to take
  2190. * @param amount the amount to take of each item
  2191. * @param itemIds a list or an array of IDs of the items to take
  2192. * @return {@code true} if all items were taken, {@code false} otherwise
  2193. */
  2194. public static boolean takeItems(L2PcInstance player, int amount, int... itemIds)
  2195. {
  2196. boolean check = true;
  2197. if (itemIds != null)
  2198. {
  2199. for (int item : itemIds)
  2200. {
  2201. check &= takeItems(player, item, amount);
  2202. }
  2203. }
  2204. return check;
  2205. }
  2206. /**
  2207. * Send a packet in order to play a sound to the player.
  2208. * @param player the player whom to send the packet
  2209. * @param sound the name of the sound to play
  2210. */
  2211. public static void playSound(L2PcInstance player, String sound)
  2212. {
  2213. player.sendPacket(QuestSound.getSound(sound));
  2214. }
  2215. /**
  2216. * Send a packet in order to play a sound to the player.
  2217. * @param player the player whom to send the packet
  2218. * @param sound the {@link QuestSound} object of the sound to play
  2219. */
  2220. public static void playSound(L2PcInstance player, QuestSound sound)
  2221. {
  2222. player.sendPacket(sound.getPacket());
  2223. }
  2224. /**
  2225. * Add EXP and SP as quest reward.
  2226. * @param player the player whom to reward with the EXP/SP
  2227. * @param exp the amount of EXP to give to the player
  2228. * @param sp the amount of SP to give to the player
  2229. */
  2230. public static void addExpAndSp(L2PcInstance player, long exp, int sp)
  2231. {
  2232. 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));
  2233. }
  2234. /**
  2235. * Get a random integer from 0 (inclusive) to {@code max} (exclusive).<br>
  2236. * Use this method instead of importing {@link com.l2jserver.util.Rnd} utility.
  2237. * @param max the maximum value for randomization
  2238. * @return a random integer number from 0 to {@code max - 1}
  2239. */
  2240. public static int getRandom(int max)
  2241. {
  2242. return Rnd.get(max);
  2243. }
  2244. /**
  2245. * Get a random integer from {@code min} (inclusive) to {@code max} (inclusive).<br>
  2246. * Use this method instead of importing {@link com.l2jserver.util.Rnd} utility.
  2247. * @param min the minimum value for randomization
  2248. * @param max the maximum value for randomization
  2249. * @return a random integer number from {@code min} to {@code max}
  2250. */
  2251. public static int getRandom(int min, int max)
  2252. {
  2253. return Rnd.get(min, max);
  2254. }
  2255. /**
  2256. * Get a random boolean.<br>
  2257. * Use this method instead of importing {@link com.l2jserver.util.Rnd} utility.
  2258. * @return {@code true} or {@code false} randomly
  2259. */
  2260. public static boolean getRandomBoolean()
  2261. {
  2262. return Rnd.nextBoolean();
  2263. }
  2264. /**
  2265. * Get the ID of the item equipped in the specified inventory slot of the player.
  2266. * @param player the player whose inventory to check
  2267. * @param slot the location in the player's inventory to check
  2268. * @return the ID of the item equipped in the specified inventory slot or 0 if the slot is empty or item is {@code null}.
  2269. */
  2270. public static int getItemEquipped(L2PcInstance player, int slot)
  2271. {
  2272. return player.getInventory().getPaperdollItemId(slot);
  2273. }
  2274. /**
  2275. * @return the number of ticks from the {@link com.l2jserver.gameserver.GameTimeController}.
  2276. */
  2277. public static int getGameTicks()
  2278. {
  2279. return GameTimeController.getInstance().getGameTicks();
  2280. }
  2281. /**
  2282. * Execute a procedure for each player depending on the parameters.
  2283. * @param player the player on which the procedure will be executed
  2284. * @param npc the related NPC
  2285. * @param isSummon {@code true} if the event that called this method was originated by the player's summon, {@code false} otherwise
  2286. * @param includeParty if {@code true}, #actionForEachPlayer(L2PcInstance, L2Npc, boolean) will be called with the player's party members
  2287. * @param includeCommandChannel if {@code true}, {@link #actionForEachPlayer(L2PcInstance, L2Npc, boolean)} will be called with the player's command channel members
  2288. * @see #actionForEachPlayer(L2PcInstance, L2Npc, boolean)
  2289. */
  2290. public final void executeForEachPlayer(L2PcInstance player, final L2Npc npc, final boolean isSummon, boolean includeParty, boolean includeCommandChannel)
  2291. {
  2292. if ((includeParty || includeCommandChannel) && player.isInParty())
  2293. {
  2294. if (includeCommandChannel && player.getParty().isInCommandChannel())
  2295. {
  2296. player.getParty().getCommandChannel().forEachMember(member ->
  2297. {
  2298. actionForEachPlayer(member, npc, isSummon);
  2299. return true;
  2300. });
  2301. }
  2302. else if (includeParty)
  2303. {
  2304. player.getParty().forEachMember(member ->
  2305. {
  2306. actionForEachPlayer(member, npc, isSummon);
  2307. return true;
  2308. });
  2309. }
  2310. }
  2311. else
  2312. {
  2313. actionForEachPlayer(player, npc, isSummon);
  2314. }
  2315. }
  2316. /**
  2317. * Overridable method called from {@link #executeForEachPlayer(L2PcInstance, L2Npc, boolean, boolean, boolean)}
  2318. * @param player the player on which the action will be run
  2319. * @param npc the NPC related to this action
  2320. * @param isSummon {@code true} if the event that called this method was originated by the player's summon
  2321. */
  2322. public void actionForEachPlayer(L2PcInstance player, L2Npc npc, boolean isSummon)
  2323. {
  2324. // To be overridden in quest scripts.
  2325. }
  2326. /**
  2327. * Open a door if it is present on the instance and its not open.
  2328. * @param doorId the ID of the door to open
  2329. * @param instanceId the ID of the instance the door is in (0 if the door is not not inside an instance)
  2330. */
  2331. public void openDoor(int doorId, int instanceId)
  2332. {
  2333. final L2DoorInstance door = getDoor(doorId, instanceId);
  2334. if (door == null)
  2335. {
  2336. _log.log(Level.WARNING, getClass().getSimpleName() + ": called openDoor(" + doorId + ", " + instanceId + "); but door wasnt found!", new NullPointerException());
  2337. }
  2338. else if (!door.getOpen())
  2339. {
  2340. door.openMe();
  2341. }
  2342. }
  2343. /**
  2344. * Close a door if it is present in a specified the instance and its open.
  2345. * @param doorId the ID of the door to close
  2346. * @param instanceId the ID of the instance the door is in (0 if the door is not not inside an instance)
  2347. */
  2348. public void closeDoor(int doorId, int instanceId)
  2349. {
  2350. final L2DoorInstance door = getDoor(doorId, instanceId);
  2351. if (door == null)
  2352. {
  2353. _log.log(Level.WARNING, getClass().getSimpleName() + ": called closeDoor(" + doorId + ", " + instanceId + "); but door wasnt found!", new NullPointerException());
  2354. }
  2355. else if (door.getOpen())
  2356. {
  2357. door.closeMe();
  2358. }
  2359. }
  2360. /**
  2361. * Retrieve a door from an instance or the real world.
  2362. * @param doorId the ID of the door to get
  2363. * @param instanceId the ID of the instance the door is in (0 if the door is not not inside an instance)
  2364. * @return the found door or {@code null} if no door with that ID and instance ID was found
  2365. */
  2366. public L2DoorInstance getDoor(int doorId, int instanceId)
  2367. {
  2368. L2DoorInstance door = null;
  2369. if (instanceId <= 0)
  2370. {
  2371. door = DoorTable.getInstance().getDoor(doorId);
  2372. }
  2373. else
  2374. {
  2375. final Instance inst = InstanceManager.getInstance().getInstance(instanceId);
  2376. if (inst != null)
  2377. {
  2378. door = inst.getDoor(doorId);
  2379. }
  2380. }
  2381. return door;
  2382. }
  2383. /**
  2384. * Teleport a player into/out of an instance.
  2385. * @param player the player to teleport
  2386. * @param loc the {@link Location} object containing the destination coordinates
  2387. * @param instanceId the ID of the instance to teleport the player to (0 to teleport out of an instance)
  2388. */
  2389. public void teleportPlayer(L2PcInstance player, Location loc, int instanceId)
  2390. {
  2391. teleportPlayer(player, loc, instanceId, true);
  2392. }
  2393. /**
  2394. * Teleport a player into/out of an instance.
  2395. * @param player the player to teleport
  2396. * @param loc the {@link Location} object containing the destination coordinates
  2397. * @param instanceId the ID of the instance to teleport the player to (0 to teleport out of an instance)
  2398. * @param allowRandomOffset if {@code true}, will randomize the teleport coordinates by +/-Config.MAX_OFFSET_ON_TELEPORT
  2399. */
  2400. public void teleportPlayer(L2PcInstance player, Location loc, int instanceId, boolean allowRandomOffset)
  2401. {
  2402. loc.setInstanceId(instanceId);
  2403. player.teleToLocation(loc, allowRandomOffset);
  2404. }
  2405. /**
  2406. * Monster is running and attacking the playable.
  2407. * @param npc the NPC that performs the attack
  2408. * @param playable the player
  2409. */
  2410. protected void addAttackPlayerDesire(L2Npc npc, L2Playable playable)
  2411. {
  2412. addAttackPlayerDesire(npc, playable, 999);
  2413. }
  2414. /**
  2415. * Monster is running and attacking the target.
  2416. * @param npc the NPC that performs the attack
  2417. * @param target the target of the attack
  2418. * @param desire the desire to perform the attack
  2419. */
  2420. protected void addAttackPlayerDesire(L2Npc npc, L2Playable target, int desire)
  2421. {
  2422. if (npc instanceof L2Attackable)
  2423. {
  2424. ((L2Attackable) npc).addDamageHate(target, 0, desire);
  2425. }
  2426. npc.setIsRunning(true);
  2427. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  2428. }
  2429. /**
  2430. * Instantly cast a skill upon the given target.
  2431. * @param npc the caster NPC
  2432. * @param target the target of the cast
  2433. * @param skill the skill to cast
  2434. */
  2435. protected void castSkill(L2Npc npc, L2Playable target, SkillHolder skill)
  2436. {
  2437. npc.setTarget(target);
  2438. npc.doCast(skill.getSkill());
  2439. }
  2440. /**
  2441. * Instantly cast a skill upon the given target.
  2442. * @param npc the caster NPC
  2443. * @param target the target of the cast
  2444. * @param skill the skill to cast
  2445. */
  2446. protected void castSkill(L2Npc npc, L2Playable target, Skill skill)
  2447. {
  2448. npc.setTarget(target);
  2449. npc.doCast(skill);
  2450. }
  2451. /**
  2452. * Adds the desire to cast a skill to the given NPC.
  2453. * @param npc the NPC whom cast the skill
  2454. * @param target the skill target
  2455. * @param skill the skill to cast
  2456. * @param desire the desire to cast the skill
  2457. */
  2458. protected void addSkillCastDesire(L2Npc npc, L2Character target, SkillHolder skill, int desire)
  2459. {
  2460. addSkillCastDesire(npc, target, skill.getSkill(), desire);
  2461. }
  2462. /**
  2463. * Adds the desire to cast a skill to the given NPC.
  2464. * @param npc the NPC whom cast the skill
  2465. * @param target the skill target
  2466. * @param skill the skill to cast
  2467. * @param desire the desire to cast the skill
  2468. */
  2469. protected void addSkillCastDesire(L2Npc npc, L2Character target, Skill skill, int desire)
  2470. {
  2471. if (npc instanceof L2Attackable)
  2472. {
  2473. ((L2Attackable) npc).addDamageHate(target, 0, desire);
  2474. }
  2475. npc.setTarget(target);
  2476. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_CAST, skill, target);
  2477. }
  2478. /**
  2479. * Sends the special camera packet to the player.
  2480. * @param player the player
  2481. * @param creature the watched creature
  2482. * @param force
  2483. * @param angle1
  2484. * @param angle2
  2485. * @param time
  2486. * @param range
  2487. * @param duration
  2488. * @param relYaw
  2489. * @param relPitch
  2490. * @param isWide
  2491. * @param relAngle
  2492. */
  2493. 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)
  2494. {
  2495. player.sendPacket(new SpecialCamera(creature, force, angle1, angle2, time, range, duration, relYaw, relPitch, isWide, relAngle));
  2496. }
  2497. /**
  2498. * Sends the special camera packet to the player.
  2499. * @param player
  2500. * @param creature
  2501. * @param force
  2502. * @param angle1
  2503. * @param angle2
  2504. * @param time
  2505. * @param duration
  2506. * @param relYaw
  2507. * @param relPitch
  2508. * @param isWide
  2509. * @param relAngle
  2510. */
  2511. 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)
  2512. {
  2513. player.sendPacket(new SpecialCamera(creature, player, force, angle1, angle2, time, duration, relYaw, relPitch, isWide, relAngle));
  2514. }
  2515. /**
  2516. * Sends the special camera packet to the player.
  2517. * @param player
  2518. * @param creature
  2519. * @param force
  2520. * @param angle1
  2521. * @param angle2
  2522. * @param time
  2523. * @param range
  2524. * @param duration
  2525. * @param relYaw
  2526. * @param relPitch
  2527. * @param isWide
  2528. * @param relAngle
  2529. * @param unk
  2530. */
  2531. 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)
  2532. {
  2533. player.sendPacket(new SpecialCamera(creature, force, angle1, angle2, time, range, duration, relYaw, relPitch, isWide, relAngle, unk));
  2534. }
  2535. }