Quest.java 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model.quest;
  16. import java.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.sql.ResultSet;
  19. import java.util.Collection;
  20. import java.util.Map;
  21. import java.util.concurrent.locks.ReentrantReadWriteLock;
  22. import java.util.logging.Level;
  23. import java.util.logging.Logger;
  24. import javolution.util.FastList;
  25. import javolution.util.FastMap;
  26. import com.l2jserver.Config;
  27. import com.l2jserver.L2DatabaseFactory;
  28. import com.l2jserver.gameserver.ThreadPoolManager;
  29. import com.l2jserver.gameserver.cache.HtmCache;
  30. import com.l2jserver.gameserver.datatables.NpcTable;
  31. import com.l2jserver.gameserver.idfactory.IdFactory;
  32. import com.l2jserver.gameserver.instancemanager.QuestManager;
  33. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  34. import com.l2jserver.gameserver.model.L2Object;
  35. import com.l2jserver.gameserver.model.L2Party;
  36. import com.l2jserver.gameserver.model.L2Skill;
  37. import com.l2jserver.gameserver.model.L2Spawn;
  38. import com.l2jserver.gameserver.model.Location;
  39. import com.l2jserver.gameserver.model.actor.L2Character;
  40. import com.l2jserver.gameserver.model.actor.L2Npc;
  41. import com.l2jserver.gameserver.model.actor.L2Trap;
  42. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  43. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  44. import com.l2jserver.gameserver.model.actor.instance.L2TrapInstance;
  45. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  46. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  47. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  48. import com.l2jserver.gameserver.network.serverpackets.NpcQuestHtmlMessage;
  49. import com.l2jserver.gameserver.scripting.ManagedScript;
  50. import com.l2jserver.gameserver.scripting.ScriptManager;
  51. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  52. import com.l2jserver.gameserver.templates.item.L2Item;
  53. import com.l2jserver.gameserver.util.MinionList;
  54. import com.l2jserver.util.Rnd;
  55. import com.l2jserver.util.Util;
  56. /**
  57. * @author Luis Arias
  58. */
  59. public class Quest extends ManagedScript
  60. {
  61. protected static final Logger _log = Logger.getLogger(Quest.class.getName());
  62. /** HashMap containing events from String value of the event */
  63. private static Map<String, Quest> _allEventsS = new FastMap<String, Quest>();
  64. /** HashMap containing lists of timers from the name of the timer */
  65. private final Map<String, FastList<QuestTimer>> _allEventTimers = new FastMap<String, FastList<QuestTimer>>().shared();
  66. private final ReentrantReadWriteLock _rwLock = new ReentrantReadWriteLock();
  67. private final int _questId;
  68. private final String _name;
  69. private final String _descr;
  70. private final byte _initialState = State.CREATED;
  71. protected boolean _onEnterWorld = false;
  72. private boolean _isCustom = false;
  73. // NOTE: questItemIds will be overridden by child classes. Ideally, it should be
  74. // protected instead of public. However, quest scripts written in Jython will
  75. // have trouble with protected, as Jython only knows private and public...
  76. // In fact, protected will typically be considered private thus breaking the scripts.
  77. // Leave this as public as a workaround.
  78. public int[] questItemIds = null;
  79. private static final String DEFAULT_NO_QUEST_MSG =
  80. "<html><body>You are either not on a quest that involves this NPC, or you don't meet this NPC's minimum quest requirements.</body></html>";
  81. private static final String DEFAULT_ALREADY_COMPLETED_MSG =
  82. "<html><body>This quest has already been completed.</body></html>";
  83. /**
  84. * Return collection view of the values contains in the allEventS
  85. * @return Collection<Quest>
  86. */
  87. public static Collection<Quest> findAllEvents()
  88. {
  89. return _allEventsS.values();
  90. }
  91. /**
  92. * (Constructor)Add values to class variables and put the quest in HashMaps.
  93. * @param questId : int pointing out the ID of the quest
  94. * @param name : String corresponding to the name of the quest
  95. * @param descr : String for the description of the quest
  96. */
  97. public Quest(int questId, String name, String descr)
  98. {
  99. _questId = questId;
  100. _name = name;
  101. _descr = descr;
  102. if (questId != 0)
  103. {
  104. QuestManager.getInstance().addQuest(this);
  105. }
  106. else
  107. {
  108. _allEventsS.put(name, this);
  109. }
  110. init_LoadGlobalData();
  111. }
  112. /**
  113. * The function init_LoadGlobalData is, by default, called by the constructor of all quests.
  114. * Children of this class can implement this function in order to define what variables
  115. * to load and what structures to save them in. By default, nothing is loaded.
  116. */
  117. protected void init_LoadGlobalData()
  118. {
  119. }
  120. /**
  121. * The function saveGlobalData is, by default, called at shutdown, for all quests, by the QuestManager.
  122. * Children of this class can implement this function in order to convert their structures
  123. * into <var, value> tuples and make calls to save them to the database, if needed.
  124. * By default, nothing is saved.
  125. */
  126. public void saveGlobalData()
  127. {
  128. }
  129. public static enum TrapAction
  130. {
  131. TRAP_TRIGGERED,
  132. TRAP_DETECTED,
  133. TRAP_DISARMED
  134. }
  135. public static enum QuestEventType
  136. {
  137. ON_FIRST_TALK(false), // control the first dialog shown by NPCs when they are clicked (some quests must override the default npc action)
  138. QUEST_START(true), // onTalk action from start npcs
  139. ON_TALK(true), // onTalk action from npcs participating in a quest
  140. ON_ATTACK(true), // onAttack action triggered when a mob gets attacked by someone
  141. ON_KILL(true), // onKill action triggered when a mob gets killed.
  142. ON_SPAWN(true), // onSpawn action triggered when an NPC is spawned or respawned.
  143. ON_SKILL_SEE(true), // NPC or Mob saw a person casting a skill (regardless what the target is).
  144. ON_FACTION_CALL(true), // NPC or Mob saw a person casting a skill (regardless what the target is).
  145. ON_AGGRO_RANGE_ENTER(true), // a person came within the Npc/Mob's range
  146. ON_SPELL_FINISHED(true), // on spell finished action when npc finish casting skill
  147. ON_SKILL_LEARN(false), // control the AcquireSkill dialog from quest script
  148. ON_ENTER_ZONE(true), // on zone enter
  149. ON_EXIT_ZONE(true), // on zone exit
  150. ON_TRAP_ACTION(true), // on zone exit
  151. ON_ITEM_USE(true);
  152. // control whether this event type is allowed for the same npc template in multiple quests
  153. // or if the npc must be registered in at most one quest for the specified event
  154. private boolean _allowMultipleRegistration;
  155. QuestEventType(boolean allowMultipleRegistration)
  156. {
  157. _allowMultipleRegistration = allowMultipleRegistration;
  158. }
  159. public boolean isMultipleRegistrationAllowed()
  160. {
  161. return _allowMultipleRegistration;
  162. }
  163. }
  164. /**
  165. * Return ID of the quest
  166. * @return int
  167. */
  168. public int getQuestIntId()
  169. {
  170. return _questId;
  171. }
  172. /**
  173. * Add a new QuestState to the database and return it.
  174. * @param player
  175. * @return QuestState : QuestState created
  176. */
  177. public QuestState newQuestState(L2PcInstance player)
  178. {
  179. QuestState qs = new QuestState(this, player, getInitialState());
  180. return qs;
  181. }
  182. /**
  183. * Return initial state of the quest
  184. * @return State
  185. */
  186. public byte getInitialState()
  187. {
  188. return _initialState;
  189. }
  190. /**
  191. * Return name of the quest
  192. * @return String
  193. */
  194. public String getName()
  195. {
  196. return _name;
  197. }
  198. /**
  199. * Return description of the quest
  200. * @return String
  201. */
  202. public String getDescr()
  203. {
  204. return _descr;
  205. }
  206. /**
  207. * Add a timer to the quest, if it doesn't exist already
  208. * @param name name of the timer (also passed back as "event" in onAdvEvent)
  209. * @param time time in ms for when to fire the timer
  210. * @param npc npc associated with this timer (can be null)
  211. * @param player player associated with this timer (can be null)
  212. */
  213. public void startQuestTimer(String name, long time, L2Npc npc, L2PcInstance player)
  214. {
  215. startQuestTimer(name, time, npc, player, false);
  216. }
  217. /**
  218. * Add a timer to the quest, if it doesn't exist already. If the timer is repeatable,
  219. * it will auto-fire automatically, at a fixed rate, until explicitly canceled.
  220. * @param name name of the timer (also passed back as "event" in onAdvEvent)
  221. * @param time time in ms for when to fire the timer
  222. * @param npc npc associated with this timer (can be null)
  223. * @param player player associated with this timer (can be null)
  224. * @param repeating indicates if the timer is repeatable or one-time.
  225. */
  226. public void startQuestTimer(String name, long time, L2Npc npc, L2PcInstance player, boolean repeating)
  227. {
  228. // Add quest timer if timer doesn't already exist
  229. FastList<QuestTimer> timers = getQuestTimers(name);
  230. // no timer exists with the same name, at all
  231. if (timers == null)
  232. {
  233. timers = new FastList<QuestTimer>();
  234. timers.add(new QuestTimer(this, name, time, npc, player, repeating));
  235. _allEventTimers.put(name, timers);
  236. }
  237. // a timer with this name exists, but may not be for the same set of npc and player
  238. else
  239. {
  240. // if there exists a timer with this name, allow the timer only if the [npc, player] set is unique
  241. // nulls act as wildcards
  242. if (getQuestTimer(name, npc, player) == null)
  243. {
  244. try
  245. {
  246. _rwLock.writeLock().lock();
  247. timers.add(new QuestTimer(this, name, time, npc, player, repeating));
  248. }
  249. finally
  250. {
  251. _rwLock.writeLock().unlock();
  252. }
  253. }
  254. }
  255. }
  256. public QuestTimer getQuestTimer(String name, L2Npc npc, L2PcInstance player)
  257. {
  258. FastList<QuestTimer> qt = getQuestTimers(name);
  259. if (qt == null || qt.isEmpty())
  260. return null;
  261. try
  262. {
  263. _rwLock.readLock().lock();
  264. for (QuestTimer timer : qt)
  265. {
  266. if (timer != null)
  267. {
  268. if (timer.isMatch(this, name, npc, player))
  269. return timer;
  270. }
  271. }
  272. }
  273. finally
  274. {
  275. _rwLock.readLock().unlock();
  276. }
  277. return null;
  278. }
  279. private FastList<QuestTimer> getQuestTimers(String name)
  280. {
  281. return _allEventTimers.get(name);
  282. }
  283. public void cancelQuestTimers(String name)
  284. {
  285. FastList<QuestTimer> timers = getQuestTimers(name);
  286. if (timers == null)
  287. return;
  288. try
  289. {
  290. _rwLock.writeLock().lock();
  291. for (QuestTimer timer : timers)
  292. {
  293. if (timer != null)
  294. {
  295. timer.cancel();
  296. }
  297. }
  298. }
  299. finally
  300. {
  301. _rwLock.writeLock().unlock();
  302. }
  303. }
  304. public void cancelQuestTimer(String name, L2Npc npc, L2PcInstance player)
  305. {
  306. QuestTimer timer = getQuestTimer(name, npc, player);
  307. if (timer != null)
  308. timer.cancel();
  309. }
  310. public void removeQuestTimer(QuestTimer timer)
  311. {
  312. if (timer == null)
  313. return;
  314. FastList<QuestTimer> timers = getQuestTimers(timer.getName());
  315. if (timers == null)
  316. return;
  317. try
  318. {
  319. _rwLock.writeLock().lock();
  320. timers.remove(timer);
  321. }
  322. finally
  323. {
  324. _rwLock.writeLock().unlock();
  325. }
  326. }
  327. // these are methods to call from java
  328. public final boolean notifyAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet, L2Skill skill)
  329. {
  330. String res = null;
  331. try
  332. {
  333. res = onAttack(npc, attacker, damage, isPet, skill);
  334. }
  335. catch (Exception e)
  336. {
  337. return showError(attacker, e);
  338. }
  339. return showResult(attacker, res);
  340. }
  341. public final boolean notifyDeath(L2Character killer, L2Character victim, QuestState qs)
  342. {
  343. String res = null;
  344. try
  345. {
  346. res = onDeath(killer, victim, qs);
  347. }
  348. catch (Exception e)
  349. {
  350. return showError(qs.getPlayer(), e);
  351. }
  352. return showResult(qs.getPlayer(), res);
  353. }
  354. public final boolean notifyItemUse(L2Item item, L2PcInstance player)
  355. {
  356. String res = null;
  357. try
  358. {
  359. res = onItemUse(item, player);
  360. }
  361. catch(Exception e)
  362. {
  363. return showError(player, e);
  364. }
  365. return showResult(player, res);
  366. }
  367. public final boolean notifySpellFinished(L2Npc instance, L2PcInstance player, L2Skill skill)
  368. {
  369. String res = null;
  370. try
  371. {
  372. res = onSpellFinished(instance, player, skill);
  373. }
  374. catch (Exception e)
  375. {
  376. return showError(player, e);
  377. }
  378. return showResult(player, res);
  379. }
  380. /**
  381. * Notify quest script when something happens with a trap
  382. * @param trap the trap instance which triggers the notification
  383. * @param trigger the character which makes effect on the trap
  384. * @param action 0: trap casting its skill. 1: trigger detects the trap. 2: trigger removes the trap
  385. * @return
  386. */
  387. public final boolean notifyTrapAction(L2Trap trap, L2Character trigger, TrapAction action)
  388. {
  389. String res = null;
  390. try
  391. {
  392. res = onTrapAction(trap, trigger, action);
  393. }
  394. catch (Exception e)
  395. {
  396. if (trigger.getActingPlayer() != null)
  397. return showError(trigger.getActingPlayer(), e);
  398. _log.log(Level.WARNING, "Exception on onTrapAction() in notifyTrapAction(): " + e.getMessage(), e);
  399. return true;
  400. }
  401. if (trigger.getActingPlayer() != null)
  402. return showResult(trigger.getActingPlayer(), res);
  403. return false;
  404. }
  405. public final boolean notifySpawn(L2Npc npc)
  406. {
  407. try
  408. {
  409. onSpawn(npc);
  410. }
  411. catch (Exception e)
  412. {
  413. _log.log(Level.WARNING, "Exception on onSpawn() in notifySpawn(): " + e.getMessage(), e);
  414. return true;
  415. }
  416. return false;
  417. }
  418. public final boolean notifyEvent(String event, L2Npc npc, L2PcInstance player)
  419. {
  420. String res = null;
  421. try
  422. {
  423. res = onAdvEvent(event, npc, player);
  424. }
  425. catch (Exception e)
  426. {
  427. return showError(player, e);
  428. }
  429. return showResult(player, res);
  430. }
  431. public final boolean notifyEnterWorld(L2PcInstance player)
  432. {
  433. String res = null;
  434. try
  435. {
  436. res = onEnterWorld(player);
  437. }
  438. catch (Exception e)
  439. {
  440. return showError(player, e);
  441. }
  442. return showResult(player, res);
  443. }
  444. public final boolean notifyKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  445. {
  446. String res = null;
  447. try
  448. {
  449. res = onKill(npc, killer, isPet);
  450. }
  451. catch (Exception e)
  452. {
  453. return showError(killer, e);
  454. }
  455. return showResult(killer, res);
  456. }
  457. public final boolean notifyTalk(L2Npc npc, QuestState qs)
  458. {
  459. String res = null;
  460. try
  461. {
  462. res = onTalk(npc, qs.getPlayer());
  463. }
  464. catch (Exception e)
  465. {
  466. return showError(qs.getPlayer(), e);
  467. }
  468. qs.getPlayer().setLastQuestNpcObject(npc.getObjectId());
  469. return showResult(qs.getPlayer(), res);
  470. }
  471. // override the default NPC dialogs when a quest defines this for the given NPC
  472. public final boolean notifyFirstTalk(L2Npc npc, L2PcInstance player)
  473. {
  474. String res = null;
  475. try
  476. {
  477. res = onFirstTalk(npc, player);
  478. }
  479. catch (Exception e)
  480. {
  481. return showError(player, e);
  482. }
  483. // if the quest returns text to display, display it.
  484. if (res != null && res.length() > 0)
  485. return showResult(player, res);
  486. // else tell the player that
  487. player.sendPacket(ActionFailed.STATIC_PACKET);
  488. // note: if the default html for this npc needs to be shown, onFirstTalk should
  489. // call npc.showChatWindow(player) and then return null.
  490. return true;
  491. }
  492. public final boolean notifyAcquireSkillList(L2Npc npc, L2PcInstance player)
  493. {
  494. String res = null;
  495. try
  496. {
  497. res = onAcquireSkillList(npc, player);
  498. }
  499. catch (Exception e)
  500. {
  501. return showError(player, e);
  502. }
  503. return showResult(player, res);
  504. }
  505. public final boolean notifyAcquireSkillInfo(L2Npc npc, L2PcInstance player, L2Skill skill)
  506. {
  507. String res = null;
  508. try
  509. {
  510. res = onAcquireSkillInfo(npc, player, skill);
  511. }
  512. catch (Exception e)
  513. {
  514. return showError(player, e);
  515. }
  516. return showResult(player, res);
  517. }
  518. public final boolean notifyAcquireSkill(L2Npc npc, L2PcInstance player, L2Skill skill)
  519. {
  520. String res = null;
  521. try
  522. {
  523. res = onAcquireSkill(npc, player, skill);
  524. if (res == "true")
  525. return true;
  526. else if (res == "false")
  527. return false;
  528. }
  529. catch (Exception e)
  530. {
  531. return showError(player, e);
  532. }
  533. return showResult(player, res);
  534. }
  535. public class TmpOnSkillSee implements Runnable
  536. {
  537. private final L2Npc _npc;
  538. private final L2PcInstance _caster;
  539. private final L2Skill _skill;
  540. private final L2Object[] _targets;
  541. private final boolean _isPet;
  542. public TmpOnSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  543. {
  544. _npc = npc;
  545. _caster = caster;
  546. _skill = skill;
  547. _targets = targets;
  548. _isPet = isPet;
  549. }
  550. @Override
  551. public void run()
  552. {
  553. String res = null;
  554. try
  555. {
  556. res = onSkillSee(_npc, _caster, _skill, _targets, _isPet);
  557. }
  558. catch (Exception e)
  559. {
  560. showError(_caster, e);
  561. }
  562. showResult(_caster, res);
  563. }
  564. }
  565. public final boolean notifySkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  566. {
  567. ThreadPoolManager.getInstance().executeAi(new TmpOnSkillSee(npc, caster, skill, targets, isPet));
  568. return true;
  569. }
  570. public final boolean notifyFactionCall(L2Npc npc, L2Npc caller, L2PcInstance attacker, boolean isPet)
  571. {
  572. String res = null;
  573. try
  574. {
  575. res = onFactionCall(npc, caller, attacker, isPet);
  576. }
  577. catch (Exception e)
  578. {
  579. return showError(attacker, e);
  580. }
  581. return showResult(attacker, res);
  582. }
  583. public class TmpOnAggroEnter implements Runnable
  584. {
  585. private final L2Npc _npc;
  586. private final L2PcInstance _pc;
  587. private final boolean _isPet;
  588. public TmpOnAggroEnter(L2Npc npc, L2PcInstance pc, boolean isPet)
  589. {
  590. _npc = npc;
  591. _pc = pc;
  592. _isPet = isPet;
  593. }
  594. @Override
  595. public void run()
  596. {
  597. String res = null;
  598. try
  599. {
  600. res = onAggroRangeEnter(_npc, _pc, _isPet);
  601. }
  602. catch (Exception e)
  603. {
  604. showError(_pc, e);
  605. }
  606. showResult(_pc, res);
  607. }
  608. }
  609. public final boolean notifyAggroRangeEnter(L2Npc npc, L2PcInstance player, boolean isPet)
  610. {
  611. ThreadPoolManager.getInstance().executeAi(new TmpOnAggroEnter(npc, player, isPet));
  612. return true;
  613. }
  614. public final boolean notifyEnterZone(L2Character character, L2ZoneType zone)
  615. {
  616. L2PcInstance player = character.getActingPlayer();
  617. String res = null;
  618. try
  619. {
  620. res = this.onEnterZone(character, zone);
  621. }
  622. catch (Exception e)
  623. {
  624. if (player != null)
  625. return showError(player, e);
  626. }
  627. if (player != null)
  628. return showResult(player, res);
  629. return true;
  630. }
  631. public final boolean notifyExitZone(L2Character character, L2ZoneType zone)
  632. {
  633. L2PcInstance player = character.getActingPlayer();
  634. String res = null;
  635. try
  636. {
  637. res = this.onExitZone(character, zone);
  638. }
  639. catch (Exception e)
  640. {
  641. if (player != null)
  642. return showError(player, e);
  643. }
  644. if (player != null)
  645. return showResult(player, res);
  646. return true;
  647. }
  648. // these are methods that java calls to invoke scripts
  649. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  650. {
  651. return null;
  652. }
  653. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet, L2Skill skill)
  654. {
  655. return onAttack(npc, attacker, damage, isPet);
  656. }
  657. public String onDeath(L2Character killer, L2Character victim, QuestState qs)
  658. {
  659. if (killer instanceof L2Npc)
  660. return onAdvEvent("", (L2Npc) killer, qs.getPlayer());
  661. return onAdvEvent("", null, qs.getPlayer());
  662. }
  663. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  664. {
  665. // if not overridden by a subclass, then default to the returned value of the simpler (and older) onEvent override
  666. // if the player has a state, use it as parameter in the next call, else return null
  667. QuestState qs = player.getQuestState(getName());
  668. if (qs != null)
  669. return onEvent(event, qs);
  670. return null;
  671. }
  672. public String onEvent(String event, QuestState qs)
  673. {
  674. return null;
  675. }
  676. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  677. {
  678. return null;
  679. }
  680. public String onTalk(L2Npc npc, L2PcInstance talker)
  681. {
  682. return null;
  683. }
  684. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  685. {
  686. return null;
  687. }
  688. public String onAcquireSkillList(L2Npc npc, L2PcInstance player)
  689. {
  690. return null;
  691. }
  692. public String onAcquireSkillInfo(L2Npc npc, L2PcInstance player, L2Skill skill)
  693. {
  694. return null;
  695. }
  696. public String onAcquireSkill(L2Npc npc, L2PcInstance player, L2Skill skill)
  697. {
  698. return null;
  699. }
  700. public String onItemUse(L2Item item, L2PcInstance player)
  701. {
  702. return null;
  703. }
  704. public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  705. {
  706. return null;
  707. }
  708. public String onSpellFinished(L2Npc npc, L2PcInstance player, L2Skill skill)
  709. {
  710. return null;
  711. }
  712. public String onTrapAction(L2Trap trap, L2Character trigger, TrapAction action)
  713. {
  714. return null;
  715. }
  716. public String onSpawn(L2Npc npc)
  717. {
  718. return null;
  719. }
  720. public String onFactionCall(L2Npc npc, L2Npc caller, L2PcInstance attacker, boolean isPet)
  721. {
  722. return null;
  723. }
  724. public String onAggroRangeEnter(L2Npc npc, L2PcInstance player, boolean isPet)
  725. {
  726. return null;
  727. }
  728. public String onEnterWorld(L2PcInstance player)
  729. {
  730. return null;
  731. }
  732. public String onEnterZone(L2Character character, L2ZoneType zone)
  733. {
  734. return null;
  735. }
  736. public String onExitZone(L2Character character, L2ZoneType zone)
  737. {
  738. return null;
  739. }
  740. /**
  741. * Show message error to player who has an access level greater than 0
  742. * @param player : L2PcInstance
  743. * @param t : Throwable
  744. * @return boolean
  745. */
  746. public boolean showError(L2PcInstance player, Throwable t)
  747. {
  748. _log.log(Level.WARNING, this.getScriptFile().getAbsolutePath(), t);
  749. if (t.getMessage() == null)
  750. t.printStackTrace();
  751. if (player != null && player.getAccessLevel().isGm())
  752. {
  753. String res = "<html><body><title>Script error</title>" + Util.getStackTrace(t) + "</body></html>";
  754. return showResult(player, res);
  755. }
  756. return false;
  757. }
  758. /**
  759. * Show a message to player.<BR><BR>
  760. * <U><I>Concept : </I></U><BR>
  761. * 3 cases are managed according to the value of the parameter "res" :<BR>
  762. * <LI><U>"res" ends with string ".html" :</U> an HTML is opened in order to be shown in a dialog box</LI>
  763. * <LI><U>"res" starts with "<html>" :</U> the message hold in "res" is shown in a dialog box</LI>
  764. * <LI><U>otherwise :</U> the message held in "res" is shown in chat box</LI>
  765. * @param player the player to show the result
  766. * @param res the message to show at the player
  767. * @return boolean
  768. */
  769. public boolean showResult(L2PcInstance player, String res)
  770. {
  771. if (res == null || res.isEmpty() || player == null)
  772. return true;
  773. if (res.endsWith(".htm") || res.endsWith(".html"))
  774. {
  775. showHtmlFile(player, res);
  776. }
  777. else if (res.startsWith("<html>"))
  778. {
  779. NpcHtmlMessage npcReply = new NpcHtmlMessage(5);
  780. npcReply.setHtml(res);
  781. npcReply.replace("%playername%", player.getName());
  782. player.sendPacket(npcReply);
  783. player.sendPacket(ActionFailed.STATIC_PACKET);
  784. }
  785. else
  786. {
  787. player.sendMessage(res);
  788. }
  789. return false;
  790. }
  791. /**
  792. * Add quests to the L2PCInstance of the player.<BR><BR>
  793. * <U><I>Action : </U></I><BR>
  794. * Add state of quests, drops and variables for quests in the HashMap _quest of L2PcInstance
  795. * @param player : Player who is entering the world
  796. */
  797. public final static void playerEnter(L2PcInstance player)
  798. {
  799. Connection con = null;
  800. try
  801. {
  802. // Get list of quests owned by the player from database
  803. con = L2DatabaseFactory.getInstance().getConnection();
  804. PreparedStatement invalidQuestData = con.prepareStatement("DELETE FROM character_quests WHERE charId=? and name=?");
  805. PreparedStatement invalidQuestDataVar = con.prepareStatement("delete FROM character_quests WHERE charId=? and name=? and var=?");
  806. PreparedStatement statement = con.prepareStatement("SELECT name,value FROM character_quests WHERE charId=? AND var=?");
  807. statement.setInt(1, player.getObjectId());
  808. statement.setString(2, "<state>");
  809. ResultSet rs = statement.executeQuery();
  810. while (rs.next())
  811. {
  812. // Get ID of the quest and ID of its state
  813. String questId = rs.getString("name");
  814. String statename = rs.getString("value");
  815. // Search quest associated with the ID
  816. Quest q = QuestManager.getInstance().getQuest(questId);
  817. if (q == null)
  818. {
  819. _log.finer("Unknown quest " + questId + " for player " + player.getName());
  820. if (Config.AUTODELETE_INVALID_QUEST_DATA)
  821. {
  822. invalidQuestData.setInt(1, player.getObjectId());
  823. invalidQuestData.setString(2, questId);
  824. invalidQuestData.executeUpdate();
  825. }
  826. continue;
  827. }
  828. // Create a new QuestState for the player that will be added to the player's list of quests
  829. new QuestState(q, player, State.getStateId(statename));
  830. }
  831. rs.close();
  832. invalidQuestData.close();
  833. statement.close();
  834. // Get list of quests owned by the player from the DB in order to add variables used in the quest.
  835. statement = con.prepareStatement("SELECT name,var,value FROM character_quests WHERE charId=? AND var<>?");
  836. statement.setInt(1, player.getObjectId());
  837. statement.setString(2, "<state>");
  838. rs = statement.executeQuery();
  839. while (rs.next())
  840. {
  841. String questId = rs.getString("name");
  842. String var = rs.getString("var");
  843. String value = rs.getString("value");
  844. // Get the QuestState saved in the loop before
  845. QuestState qs = player.getQuestState(questId);
  846. if (qs == null)
  847. {
  848. _log.finer("Lost variable " + var + " in quest " + questId + " for player " + player.getName());
  849. if (Config.AUTODELETE_INVALID_QUEST_DATA)
  850. {
  851. invalidQuestDataVar.setInt(1, player.getObjectId());
  852. invalidQuestDataVar.setString(2, questId);
  853. invalidQuestDataVar.setString(3, var);
  854. invalidQuestDataVar.executeUpdate();
  855. }
  856. continue;
  857. }
  858. // Add parameter to the quest
  859. qs.setInternal(var, value);
  860. }
  861. rs.close();
  862. invalidQuestDataVar.close();
  863. statement.close();
  864. }
  865. catch (Exception e)
  866. {
  867. _log.log(Level.WARNING, "could not insert char quest:", e);
  868. }
  869. finally
  870. {
  871. L2DatabaseFactory.close(con);
  872. }
  873. // events
  874. for (String name : _allEventsS.keySet())
  875. {
  876. player.processQuestEvent(name, "enter");
  877. }
  878. }
  879. /**
  880. * Insert (or Update) in the database variables that need to stay persistant for this quest after a reboot.
  881. * This function is for storage of values that do not related to a specific player but are
  882. * global for all characters. For example, if we need to disable a quest-gatekeeper until
  883. * a certain time (as is done with some grand-boss gatekeepers), we can save that time in the DB.
  884. * @param var : String designating the name of the variable for the quest
  885. * @param value : String designating the value of the variable for the quest
  886. */
  887. public final void saveGlobalQuestVar(String var, String value)
  888. {
  889. Connection con = null;
  890. try
  891. {
  892. con = L2DatabaseFactory.getInstance().getConnection();
  893. PreparedStatement statement;
  894. statement = con.prepareStatement("REPLACE INTO quest_global_data (quest_name,var,value) VALUES (?,?,?)");
  895. statement.setString(1, getName());
  896. statement.setString(2, var);
  897. statement.setString(3, value);
  898. statement.executeUpdate();
  899. statement.close();
  900. }
  901. catch (Exception e)
  902. {
  903. _log.log(Level.WARNING, "could not insert global quest variable:", e);
  904. }
  905. finally
  906. {
  907. L2DatabaseFactory.close(con);
  908. }
  909. }
  910. /**
  911. * Read from the database a previously saved variable for this quest.
  912. * Due to performance considerations, this function should best be used only when the quest is first loaded.
  913. * Subclasses of this class can define structures into which these loaded values can be saved.
  914. * However, on-demand usage of this function throughout the script is not prohibited, only not recommended.
  915. * Values read from this function were entered by calls to "saveGlobalQuestVar"
  916. * @param var : String designating the name of the variable for the quest
  917. * @return String : String representing the loaded value for the passed var, or an empty string if the var was invalid
  918. */
  919. public final String loadGlobalQuestVar(String var)
  920. {
  921. String result = "";
  922. Connection con = null;
  923. try
  924. {
  925. con = L2DatabaseFactory.getInstance().getConnection();
  926. PreparedStatement statement;
  927. statement = con.prepareStatement("SELECT value FROM quest_global_data WHERE quest_name = ? AND var = ?");
  928. statement.setString(1, getName());
  929. statement.setString(2, var);
  930. ResultSet rs = statement.executeQuery();
  931. if (rs.first())
  932. result = rs.getString(1);
  933. rs.close();
  934. statement.close();
  935. }
  936. catch (Exception e)
  937. {
  938. _log.log(Level.WARNING, "could not load global quest variable:", e);
  939. }
  940. finally
  941. {
  942. L2DatabaseFactory.close(con);
  943. }
  944. return result;
  945. }
  946. /**
  947. * Permanently delete from the database a global quest variable that was previously saved for this quest.
  948. * @param var : String designating the name of the variable for the quest
  949. */
  950. public final void deleteGlobalQuestVar(String var)
  951. {
  952. Connection con = null;
  953. try
  954. {
  955. con = L2DatabaseFactory.getInstance().getConnection();
  956. PreparedStatement statement;
  957. statement = con.prepareStatement("DELETE FROM quest_global_data WHERE quest_name = ? AND var = ?");
  958. statement.setString(1, getName());
  959. statement.setString(2, var);
  960. statement.executeUpdate();
  961. statement.close();
  962. }
  963. catch (Exception e)
  964. {
  965. _log.log(Level.WARNING, "could not delete global quest variable:", e);
  966. }
  967. finally
  968. {
  969. L2DatabaseFactory.close(con);
  970. }
  971. }
  972. /**
  973. * Permanently delete from the database all global quest variables that was previously saved for this quest.
  974. */
  975. public final void deleteAllGlobalQuestVars()
  976. {
  977. Connection con = null;
  978. try
  979. {
  980. con = L2DatabaseFactory.getInstance().getConnection();
  981. PreparedStatement statement;
  982. statement = con.prepareStatement("DELETE FROM quest_global_data WHERE quest_name = ?");
  983. statement.setString(1, getName());
  984. statement.executeUpdate();
  985. statement.close();
  986. }
  987. catch (Exception e)
  988. {
  989. _log.log(Level.WARNING, "could not delete global quest variables:", e);
  990. }
  991. finally
  992. {
  993. L2DatabaseFactory.close(con);
  994. }
  995. }
  996. /**
  997. * Insert in the database the quest for the player.
  998. * @param qs : QuestState pointing out the state of the quest
  999. * @param var : String designating the name of the variable for the quest
  1000. * @param value : String designating the value of the variable for the quest
  1001. */
  1002. public static void createQuestVarInDb(QuestState qs, String var, String value)
  1003. {
  1004. Connection con = null;
  1005. try
  1006. {
  1007. con = L2DatabaseFactory.getInstance().getConnection();
  1008. PreparedStatement statement;
  1009. statement = con.prepareStatement("INSERT INTO character_quests (charId,name,var,value) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE value=?");
  1010. statement.setInt(1, qs.getPlayer().getObjectId());
  1011. statement.setString(2, qs.getQuestName());
  1012. statement.setString(3, var);
  1013. statement.setString(4, value);
  1014. statement.setString(5, value);
  1015. statement.executeUpdate();
  1016. statement.close();
  1017. }
  1018. catch (Exception e)
  1019. {
  1020. _log.log(Level.WARNING, "could not insert char quest:", e);
  1021. }
  1022. finally
  1023. {
  1024. L2DatabaseFactory.close(con);
  1025. }
  1026. }
  1027. /**
  1028. * Update the value of the variable "var" for the quest.<BR><BR>
  1029. * <U><I>Actions :</I></U><BR>
  1030. * The selection of the right record is made with :
  1031. * <LI>charId = qs.getPlayer().getObjectID()</LI>
  1032. * <LI>name = qs.getQuest().getName()</LI>
  1033. * <LI>var = var</LI>
  1034. * <BR><BR>
  1035. * The modification made is :
  1036. * <LI>value = parameter value</LI>
  1037. * @param qs : Quest State
  1038. * @param var : String designating the name of the variable for quest
  1039. * @param value : String designating the value of the variable for quest
  1040. */
  1041. public static void updateQuestVarInDb(QuestState qs, String var, String value)
  1042. {
  1043. Connection con = null;
  1044. try
  1045. {
  1046. con = L2DatabaseFactory.getInstance().getConnection();
  1047. PreparedStatement statement;
  1048. statement = con.prepareStatement("UPDATE character_quests SET value=? WHERE charId=? AND name=? AND var = ?");
  1049. statement.setString(1, value);
  1050. statement.setInt(2, qs.getPlayer().getObjectId());
  1051. statement.setString(3, qs.getQuestName());
  1052. statement.setString(4, var);
  1053. statement.executeUpdate();
  1054. statement.close();
  1055. }
  1056. catch (Exception e)
  1057. {
  1058. _log.log(Level.WARNING, "could not update char quest:", e);
  1059. }
  1060. finally
  1061. {
  1062. L2DatabaseFactory.close(con);
  1063. }
  1064. }
  1065. /**
  1066. * Delete a variable of player's quest from the database.
  1067. * @param qs : object QuestState pointing out the player's quest
  1068. * @param var : String designating the variable characterizing the quest
  1069. */
  1070. public static void deleteQuestVarInDb(QuestState qs, String var)
  1071. {
  1072. Connection con = null;
  1073. try
  1074. {
  1075. con = L2DatabaseFactory.getInstance().getConnection();
  1076. PreparedStatement statement;
  1077. statement = con.prepareStatement("DELETE FROM character_quests WHERE charId=? AND name=? AND var=?");
  1078. statement.setInt(1, qs.getPlayer().getObjectId());
  1079. statement.setString(2, qs.getQuestName());
  1080. statement.setString(3, var);
  1081. statement.executeUpdate();
  1082. statement.close();
  1083. }
  1084. catch (Exception e)
  1085. {
  1086. _log.log(Level.WARNING, "could not delete char quest:", e);
  1087. }
  1088. finally
  1089. {
  1090. L2DatabaseFactory.close(con);
  1091. }
  1092. }
  1093. /**
  1094. * Delete the player's quest from database.
  1095. * @param qs : QuestState pointing out the player's quest
  1096. */
  1097. public static void deleteQuestInDb(QuestState qs)
  1098. {
  1099. Connection con = null;
  1100. try
  1101. {
  1102. con = L2DatabaseFactory.getInstance().getConnection();
  1103. PreparedStatement statement;
  1104. statement = con.prepareStatement("DELETE FROM character_quests WHERE charId=? AND name=?");
  1105. statement.setInt(1, qs.getPlayer().getObjectId());
  1106. statement.setString(2, qs.getQuestName());
  1107. statement.executeUpdate();
  1108. statement.close();
  1109. }
  1110. catch (Exception e)
  1111. {
  1112. _log.log(Level.WARNING, "could not delete char quest:", e);
  1113. }
  1114. finally
  1115. {
  1116. L2DatabaseFactory.close(con);
  1117. }
  1118. }
  1119. /**
  1120. * Create a record in database for quest.<BR><BR>
  1121. * <U><I>Actions :</I></U><BR>
  1122. * Use fucntion createQuestVarInDb() with following parameters :<BR>
  1123. * <LI>QuestState : parameter sq that puts in fields of database :
  1124. * <UL type="square">
  1125. * <LI>charId : ID of the player</LI>
  1126. * <LI>name : name of the quest</LI>
  1127. * </UL>
  1128. * </LI>
  1129. * <LI>var : string "&lt;state&gt;" as the name of the variable for the quest</LI>
  1130. * <LI>val : string corresponding at the ID of the state (in fact, initial state)</LI>
  1131. * @param qs : QuestState
  1132. */
  1133. public static void createQuestInDb(QuestState qs)
  1134. {
  1135. createQuestVarInDb(qs, "<state>", State.getStateName(qs.getState()));
  1136. }
  1137. /**
  1138. * Update informations regarding quest in database.<BR>
  1139. * <U><I>Actions :</I></U><BR>
  1140. * <LI>Get ID state of the quest recorded in object qs</LI>
  1141. * <LI>Test if quest is completed. If true, add a star (*) before the ID state</LI>
  1142. * <LI>Save in database the ID state (with or without the star) for the variable called "&lt;state&gt;" of the quest</LI>
  1143. * @param qs : QuestState
  1144. */
  1145. public static void updateQuestInDb(QuestState qs)
  1146. {
  1147. String val = State.getStateName(qs.getState());
  1148. updateQuestVarInDb(qs, "<state>", val);
  1149. }
  1150. /**
  1151. * Return default html page "You are either not on a quest that involves this NPC.."
  1152. * @param player
  1153. * @return
  1154. */
  1155. public static String getNoQuestMsg(L2PcInstance player)
  1156. {
  1157. final String result = HtmCache.getInstance().getHtm(player.getHtmlPrefix(), "data/html/noquest.htm");
  1158. if (result != null && result.length() > 0)
  1159. return result;
  1160. return DEFAULT_NO_QUEST_MSG;
  1161. }
  1162. /**
  1163. * Return default html page "This quest has already been completed."
  1164. * @param player
  1165. * @return
  1166. */
  1167. public static String getAlreadyCompletedMsg(L2PcInstance player)
  1168. {
  1169. final String result = HtmCache.getInstance().getHtm(player.getHtmlPrefix(), "data/html/alreadycompleted.htm");
  1170. if (result != null && result.length() > 0)
  1171. return result;
  1172. return DEFAULT_ALREADY_COMPLETED_MSG;
  1173. }
  1174. /**
  1175. * Add this quest to the list of quests that the passed mob will respond to for the specified Event type.<BR><BR>
  1176. * @param npcId : id of the NPC to register
  1177. * @param eventType : type of event being registered
  1178. * @return L2NpcTemplate : Npc Template corresponding to the npcId, or null if the id is invalid
  1179. */
  1180. public L2NpcTemplate addEventId(int npcId, QuestEventType eventType)
  1181. {
  1182. try
  1183. {
  1184. L2NpcTemplate t = NpcTable.getInstance().getTemplate(npcId);
  1185. if (t != null)
  1186. {
  1187. t.addQuestEvent(eventType, this);
  1188. }
  1189. return t;
  1190. }
  1191. catch (Exception e)
  1192. {
  1193. _log.log(Level.WARNING, "Exception on addEventId(): " + e.getMessage(), e);
  1194. return null;
  1195. }
  1196. }
  1197. /**
  1198. * Add the quest to the NPC's startQuest
  1199. * @param npcIds
  1200. * @return L2NpcTemplate : Start NPC
  1201. */
  1202. public L2NpcTemplate[] addStartNpc(int ...npcIds)
  1203. {
  1204. L2NpcTemplate[] value = new L2NpcTemplate[npcIds.length];
  1205. int i = 0;
  1206. for (int npcId : npcIds)
  1207. value[i++] = addEventId(npcId, QuestEventType.QUEST_START);
  1208. return value;
  1209. }
  1210. public L2NpcTemplate addStartNpc(int npcId)
  1211. {
  1212. return addEventId(npcId, QuestEventType.QUEST_START);
  1213. }
  1214. /**
  1215. * Add the quest to the NPC's first-talk (default action dialog)
  1216. * @param npcIds
  1217. * @return L2NpcTemplate : Start NPC
  1218. */
  1219. public L2NpcTemplate[] addFirstTalkId(int ...npcIds)
  1220. {
  1221. L2NpcTemplate[] value = new L2NpcTemplate[npcIds.length];
  1222. int i = 0;
  1223. for (int npcId : npcIds)
  1224. value[i++] = addEventId(npcId, QuestEventType.ON_FIRST_TALK);
  1225. return value;
  1226. }
  1227. public L2NpcTemplate addFirstTalkId(int npcId)
  1228. {
  1229. return addEventId(npcId, QuestEventType.ON_FIRST_TALK);
  1230. }
  1231. /**
  1232. * Add the NPC to the AcquireSkill dialog
  1233. * @param npcIds
  1234. * @return L2NpcTemplate : NPC
  1235. */
  1236. public L2NpcTemplate[] addAcquireSkillId(int ...npcIds)
  1237. {
  1238. L2NpcTemplate[] value = new L2NpcTemplate[npcIds.length];
  1239. int i = 0;
  1240. for (int npcId : npcIds)
  1241. value[i++] = addEventId(npcId, QuestEventType.ON_SKILL_LEARN);
  1242. return value;
  1243. }
  1244. public L2NpcTemplate addAcquireSkillId(int npcId)
  1245. {
  1246. return addEventId(npcId, QuestEventType.ON_SKILL_LEARN);
  1247. }
  1248. /**
  1249. * Add this quest to the list of quests that the passed mob will respond to for Attack Events.<BR><BR>
  1250. * @param npcIds
  1251. * @return int : attackId
  1252. */
  1253. public L2NpcTemplate[] addAttackId(int ...npcIds)
  1254. {
  1255. L2NpcTemplate[] value = new L2NpcTemplate[npcIds.length];
  1256. int i = 0;
  1257. for (int npcId : npcIds)
  1258. value[i++] = addEventId(npcId, QuestEventType.ON_ATTACK);
  1259. return value;
  1260. }
  1261. public L2NpcTemplate addAttackId(int npcId)
  1262. {
  1263. return addEventId(npcId, QuestEventType.ON_ATTACK);
  1264. }
  1265. /**
  1266. * Add this quest to the list of quests that the passed mob will respond to for Kill Events.<BR><BR>
  1267. * @param killIds
  1268. * @return int : killId
  1269. */
  1270. public L2NpcTemplate[] addKillId(int ...killIds)
  1271. {
  1272. L2NpcTemplate[] value = new L2NpcTemplate[killIds.length];
  1273. int i = 0;
  1274. for (int killId : killIds)
  1275. value[i++] = addEventId(killId, QuestEventType.ON_KILL);
  1276. return value;
  1277. }
  1278. public L2NpcTemplate addKillId(int npcId)
  1279. {
  1280. return addEventId(npcId, QuestEventType.ON_KILL);
  1281. }
  1282. /**
  1283. * Add this quest to the list of quests that the passed npc will respond to for Talk Events.<BR><BR>
  1284. * @param talkIds : ID of the NPC
  1285. * @return int : ID of the NPC
  1286. */
  1287. public L2NpcTemplate[] addTalkId(int ...talkIds)
  1288. {
  1289. L2NpcTemplate[] value = new L2NpcTemplate[talkIds.length];
  1290. int i = 0;
  1291. for (int talkId : talkIds)
  1292. value[i++] = addEventId(talkId, QuestEventType.ON_TALK);
  1293. return value;
  1294. }
  1295. public L2NpcTemplate addTalkId(int npcId)
  1296. {
  1297. return addEventId(npcId, QuestEventType.ON_TALK);
  1298. }
  1299. /**
  1300. * Add this quest to the list of quests that the passed npc will respond to for Spawn Events.<BR><BR>
  1301. * @param npcIds : ID of the NPC
  1302. * @return int : ID of the NPC
  1303. */
  1304. public L2NpcTemplate[] addSpawnId(int ...npcIds)
  1305. {
  1306. L2NpcTemplate[] value = new L2NpcTemplate[npcIds.length];
  1307. int i = 0;
  1308. for (int npcId : npcIds)
  1309. value[i++] = addEventId(npcId, QuestEventType.ON_SPAWN);
  1310. return value;
  1311. }
  1312. public L2NpcTemplate addSpawnId(int npcId)
  1313. {
  1314. return addEventId(npcId, QuestEventType.ON_SPAWN);
  1315. }
  1316. /**
  1317. * Add this quest to the list of quests that the passed npc will respond to for Skill-See Events.<BR><BR>
  1318. * @param npcIds : ID of the NPC
  1319. * @return int : ID of the NPC
  1320. */
  1321. public L2NpcTemplate[] addSkillSeeId(int ...npcIds)
  1322. {
  1323. L2NpcTemplate[] value = new L2NpcTemplate[npcIds.length];
  1324. int i = 0;
  1325. for (int npcId : npcIds)
  1326. value[i++] = addEventId(npcId, QuestEventType.ON_SKILL_SEE);
  1327. return value;
  1328. }
  1329. public L2NpcTemplate addSkillSeeId(int npcId)
  1330. {
  1331. return addEventId(npcId, QuestEventType.ON_SKILL_SEE);
  1332. }
  1333. public L2NpcTemplate[] addSpellFinishedId(int ...npcIds)
  1334. {
  1335. L2NpcTemplate[] value = new L2NpcTemplate[npcIds.length];
  1336. int i = 0;
  1337. for (int npcId : npcIds)
  1338. value[i++] = addEventId(npcId, QuestEventType.ON_SPELL_FINISHED);
  1339. return value;
  1340. }
  1341. public L2NpcTemplate addSpellFinishedId(int npcId)
  1342. {
  1343. return addEventId(npcId, QuestEventType.ON_SPELL_FINISHED);
  1344. }
  1345. public L2NpcTemplate[] addTrapActionId(int ...npcIds)
  1346. {
  1347. L2NpcTemplate[] value = new L2NpcTemplate[npcIds.length];
  1348. int i = 0;
  1349. for (int npcId : npcIds)
  1350. value[i++] = addEventId(npcId, QuestEventType.ON_TRAP_ACTION);
  1351. return value;
  1352. }
  1353. public L2NpcTemplate addTrapActionId(int npcId)
  1354. {
  1355. return addEventId(npcId, QuestEventType.ON_TRAP_ACTION);
  1356. }
  1357. /**
  1358. * Add this quest to the list of quests that the passed npc will respond to for Faction Call Events.<BR><BR>
  1359. * @param npcIds : ID of the NPC
  1360. * @return int : ID of the NPC
  1361. */
  1362. public L2NpcTemplate[] addFactionCallId(int ...npcIds)
  1363. {
  1364. L2NpcTemplate[] value = new L2NpcTemplate[npcIds.length];
  1365. int i = 0;
  1366. for (int npcId : npcIds)
  1367. value[i++] = addEventId(npcId, QuestEventType.ON_FACTION_CALL);
  1368. return value;
  1369. }
  1370. public L2NpcTemplate addFactionCallId(int npcId)
  1371. {
  1372. return addEventId(npcId, QuestEventType.ON_FACTION_CALL);
  1373. }
  1374. /**
  1375. * Add this quest to the list of quests that the passed npc will respond to for Character See Events.<BR><BR>
  1376. * @param npcIds : ID of the NPC
  1377. * @return int : ID of the NPC
  1378. */
  1379. public L2NpcTemplate[] addAggroRangeEnterId(int ...npcIds)
  1380. {
  1381. L2NpcTemplate[] value = new L2NpcTemplate[npcIds.length];
  1382. int i = 0;
  1383. for (int npcId : npcIds)
  1384. value[i++] = addEventId(npcId, QuestEventType.ON_AGGRO_RANGE_ENTER);
  1385. return value;
  1386. }
  1387. public L2NpcTemplate addAggroRangeEnterId(int npcId)
  1388. {
  1389. return addEventId(npcId, QuestEventType.ON_AGGRO_RANGE_ENTER);
  1390. }
  1391. public L2ZoneType[] addEnterZoneId(int ...zoneIds)
  1392. {
  1393. L2ZoneType[] value = new L2ZoneType[zoneIds.length];
  1394. int i = 0;
  1395. for (int zoneId : zoneIds)
  1396. {
  1397. try
  1398. {
  1399. L2ZoneType zone = ZoneManager.getInstance().getZoneById(zoneId);
  1400. if (zone != null)
  1401. {
  1402. zone.addQuestEvent(Quest.QuestEventType.ON_ENTER_ZONE, this);
  1403. }
  1404. value[i++] = zone;
  1405. }
  1406. catch (Exception e)
  1407. {
  1408. _log.log(Level.WARNING, "Exception on addEnterZoneId(): " + e.getMessage(), e);
  1409. continue;
  1410. }
  1411. }
  1412. return value;
  1413. }
  1414. public L2ZoneType addEnterZoneId(int zoneId)
  1415. {
  1416. try
  1417. {
  1418. L2ZoneType zone = ZoneManager.getInstance().getZoneById(zoneId);
  1419. if (zone != null)
  1420. {
  1421. zone.addQuestEvent(Quest.QuestEventType.ON_ENTER_ZONE, this);
  1422. }
  1423. return zone;
  1424. }
  1425. catch (Exception e)
  1426. {
  1427. _log.log(Level.WARNING, "Exception on addEnterZoneId(): " + e.getMessage(), e);
  1428. return null;
  1429. }
  1430. }
  1431. public L2ZoneType[] addExitZoneId(int ...zoneIds)
  1432. {
  1433. L2ZoneType[] value = new L2ZoneType[zoneIds.length];
  1434. int i = 0;
  1435. for (int zoneId : zoneIds)
  1436. {
  1437. try
  1438. {
  1439. L2ZoneType zone = ZoneManager.getInstance().getZoneById(zoneId);
  1440. if (zone != null)
  1441. {
  1442. zone.addQuestEvent(Quest.QuestEventType.ON_EXIT_ZONE, this);
  1443. }
  1444. value[i++] = zone;
  1445. }
  1446. catch (Exception e)
  1447. {
  1448. _log.log(Level.WARNING, "Exception on addEnterZoneId(): " + e.getMessage(), e);
  1449. continue;
  1450. }
  1451. }
  1452. return value;
  1453. }
  1454. public L2ZoneType addExitZoneId(int zoneId)
  1455. {
  1456. try
  1457. {
  1458. L2ZoneType zone = ZoneManager.getInstance().getZoneById(zoneId);
  1459. if (zone != null)
  1460. {
  1461. zone.addQuestEvent(Quest.QuestEventType.ON_EXIT_ZONE, this);
  1462. }
  1463. return zone;
  1464. }
  1465. catch (Exception e)
  1466. {
  1467. _log.log(Level.WARNING, "Exception on addExitZoneId(): " + e.getMessage(), e);
  1468. return null;
  1469. }
  1470. }
  1471. // returns a random party member's L2PcInstance for the passed player's party
  1472. // returns the passed player if he has no party.
  1473. public L2PcInstance getRandomPartyMember(L2PcInstance player)
  1474. {
  1475. // NPE prevention. If the player is null, there is nothing to return
  1476. if (player == null)
  1477. return null;
  1478. if ((player.getParty() == null) || (player.getParty().getPartyMembers().isEmpty()))
  1479. return player;
  1480. L2Party party = player.getParty();
  1481. return party.getPartyMembers().get(Rnd.get(party.getPartyMembers().size()));
  1482. }
  1483. /**
  1484. * Auxilary function for party quests.
  1485. * Note: This function is only here because of how commonly it may be used by quest developers.
  1486. * For any variations on this function, the quest script can always handle things on its own
  1487. * @param player the instance of a player whose party is to be searched
  1488. * @param value the value of the "cond" variable that must be matched
  1489. * @return L2PcInstance: L2PcInstance for a random party member that matches the specified
  1490. * condition, or null if no match.
  1491. */
  1492. public L2PcInstance getRandomPartyMember(L2PcInstance player, String value)
  1493. {
  1494. return getRandomPartyMember(player, "cond", value);
  1495. }
  1496. /**
  1497. * Auxilary function for party quests.
  1498. * Note: This function is only here because of how commonly it may be used by quest developers.
  1499. * For any variations on this function, the quest script can always handle things on its own
  1500. * @param player the instance of a player whose party is to be searched
  1501. * @param var
  1502. * @param value a tuple specifying a quest condition that must be satisfied for a party member to be considered.
  1503. * @return L2PcInstance: L2PcInstance for a random party member that matches the specified
  1504. * condition, or null if no match. If the var is null, any random party
  1505. * member is returned (i.e. no condition is applied).
  1506. * The party member must be within 1500 distance from the target of the reference
  1507. * player, or if no target exists, 1500 distance from the player itself.
  1508. */
  1509. public L2PcInstance getRandomPartyMember(L2PcInstance player, String var, String value)
  1510. {
  1511. // if no valid player instance is passed, there is nothing to check...
  1512. if (player == null)
  1513. return null;
  1514. // for null var condition, return any random party member.
  1515. if (var == null)
  1516. return getRandomPartyMember(player);
  1517. // normal cases...if the player is not in a party, check the player's state
  1518. QuestState temp = null;
  1519. L2Party party = player.getParty();
  1520. // if this player is not in a party, just check if this player instance matches the conditions itself
  1521. if ((party == null) || (party.getPartyMembers().isEmpty()))
  1522. {
  1523. temp = player.getQuestState(getName());
  1524. if ((temp != null) && (temp.get(var) != null) && (temp.get(var)).equalsIgnoreCase(value))
  1525. return player; // match
  1526. return null; // no match
  1527. }
  1528. // if the player is in a party, gather a list of all matching party members (possibly
  1529. // including this player)
  1530. FastList<L2PcInstance> candidates = new FastList<L2PcInstance>();
  1531. // get the target for enforcing distance limitations.
  1532. L2Object target = player.getTarget();
  1533. if (target == null)
  1534. target = player;
  1535. for (L2PcInstance partyMember : party.getPartyMembers())
  1536. {
  1537. if (partyMember == null)
  1538. continue;
  1539. temp = partyMember.getQuestState(getName());
  1540. if ((temp != null) && (temp.get(var) != null) && (temp.get(var)).equalsIgnoreCase(value) && partyMember.isInsideRadius(target, 1500, true, false))
  1541. candidates.add(partyMember);
  1542. }
  1543. // if there was no match, return null...
  1544. if (candidates.isEmpty())
  1545. return null;
  1546. // if a match was found from the party, return one of them at random.
  1547. return candidates.get(Rnd.get(candidates.size()));
  1548. }
  1549. /**
  1550. * Auxilary function for party quests.
  1551. * Note: This function is only here because of how commonly it may be used by quest developers.
  1552. * For any variations on this function, the quest script can always handle things on its own
  1553. * @param player the instance of a player whose party is to be searched
  1554. * @param state the state in which the party member's queststate must be in order to be considered.
  1555. * @return L2PcInstance: L2PcInstance for a random party member that matches the specified
  1556. * condition, or null if no match. If the var is null, any random party
  1557. * member is returned (i.e. no condition is applied).
  1558. */
  1559. public L2PcInstance getRandomPartyMemberState(L2PcInstance player, byte state)
  1560. {
  1561. // if no valid player instance is passed, there is nothing to check...
  1562. if (player == null)
  1563. return null;
  1564. // normal cases...if the player is not in a partym check the player's state
  1565. QuestState temp = null;
  1566. L2Party party = player.getParty();
  1567. // if this player is not in a party, just check if this player instance matches the conditions itself
  1568. if ((party == null) || (party.getPartyMembers().isEmpty()))
  1569. {
  1570. temp = player.getQuestState(getName());
  1571. if ((temp != null) && (temp.getState() == state))
  1572. return player; // match
  1573. return null; // no match
  1574. }
  1575. // if the player is in a party, gather a list of all matching party members (possibly
  1576. // including this player)
  1577. FastList<L2PcInstance> candidates = new FastList<L2PcInstance>();
  1578. // get the target for enforcing distance limitations.
  1579. L2Object target = player.getTarget();
  1580. if (target == null)
  1581. target = player;
  1582. for (L2PcInstance partyMember : party.getPartyMembers())
  1583. {
  1584. if (partyMember == null)
  1585. continue;
  1586. temp = partyMember.getQuestState(getName());
  1587. if ((temp != null) && (temp.getState() == state) && partyMember.isInsideRadius(target, 1500, true, false))
  1588. candidates.add(partyMember);
  1589. }
  1590. // if there was no match, return null...
  1591. if (candidates.isEmpty())
  1592. return null;
  1593. // if a match was found from the party, return one of them at random.
  1594. return candidates.get(Rnd.get(candidates.size()));
  1595. }
  1596. /**
  1597. * Show HTML file to client
  1598. * @param player
  1599. * @param fileName
  1600. * @return String : message sent to client
  1601. */
  1602. public String showHtmlFile(L2PcInstance player, String fileName)
  1603. {
  1604. boolean questwindow = true;
  1605. if (fileName.endsWith(".html"))
  1606. questwindow = false;
  1607. int questId = getQuestIntId();
  1608. //Create handler to file linked to the quest
  1609. String content = getHtm(player.getHtmlPrefix(), fileName);
  1610. if (player.getTarget() != null)
  1611. content = content.replaceAll("%objectId%", String.valueOf(player.getTarget().getObjectId()));
  1612. //Send message to client if message not empty
  1613. if (content != null)
  1614. {
  1615. if (questwindow && questId > 0 && questId < 20000 && questId != 999)
  1616. {
  1617. NpcQuestHtmlMessage npcReply = new NpcQuestHtmlMessage(5,questId);
  1618. npcReply.setHtml(content);
  1619. npcReply.replace("%playername%", player.getName());
  1620. player.sendPacket(npcReply);
  1621. }
  1622. else
  1623. {
  1624. NpcHtmlMessage npcReply = new NpcHtmlMessage(5);
  1625. npcReply.setHtml(content);
  1626. npcReply.replace("%playername%", player.getName());
  1627. player.sendPacket(npcReply);
  1628. }
  1629. player.sendPacket(ActionFailed.STATIC_PACKET);
  1630. }
  1631. return content;
  1632. }
  1633. /**
  1634. * Return HTML file contents
  1635. * @param prefix player's language prefix.
  1636. * @param fileName the html file to be get.
  1637. * @return
  1638. */
  1639. public String getHtm(String prefix, String fileName)
  1640. {
  1641. String content = HtmCache.getInstance().getHtm(prefix, "data/scripts/" + getDescr().toLowerCase() + "/" + getName() + "/" + fileName);
  1642. if (content == null)
  1643. {
  1644. content = HtmCache.getInstance().getHtm(prefix, "data/scripts/quests/Q" + getName() + "/" + fileName);
  1645. if (content == null)
  1646. content = HtmCache.getInstance().getHtmForce(prefix, "data/scripts/quests/" + getName() + "/" + fileName);
  1647. }
  1648. return content;
  1649. }
  1650. // Method - Public
  1651. /**
  1652. * Add a temporary (quest) spawn
  1653. * @param npcId
  1654. * @param cha
  1655. * @return instance of newly spawned npc
  1656. */
  1657. public L2Npc addSpawn(int npcId, L2Character cha)
  1658. {
  1659. return addSpawn(npcId, cha.getX(), cha.getY(), cha.getZ(), cha.getHeading(), false, 0, false);
  1660. }
  1661. /**
  1662. * Add a temporary (quest) spawn
  1663. * @param npcId
  1664. * @param cha
  1665. * @param isSummonSpawn
  1666. * @return instance of newly spawned npc with summon animation
  1667. */
  1668. public L2Npc addSpawn(int npcId, L2Character cha, boolean isSummonSpawn)
  1669. {
  1670. return addSpawn(npcId, cha.getX(), cha.getY(), cha.getZ(), cha.getHeading(), false, 0, isSummonSpawn);
  1671. }
  1672. public L2Npc addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffSet, long despawnDelay)
  1673. {
  1674. return addSpawn(npcId, x, y, z, heading, randomOffSet, despawnDelay, false);
  1675. }
  1676. public L2Npc addSpawn(int npcId, Location loc, boolean randomOffSet, long despawnDelay)
  1677. {
  1678. return addSpawn(npcId, loc.getX(), loc.getY(), loc.getZ(), loc.getHeading(), randomOffSet, despawnDelay, false);
  1679. }
  1680. public L2Npc addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay, boolean isSummonSpawn)
  1681. {
  1682. return addSpawn(npcId, x, y, z, heading, randomOffset, despawnDelay, isSummonSpawn, 0);
  1683. }
  1684. public L2Npc addSpawn(int npcId, Location loc, boolean randomOffset, long despawnDelay, boolean isSummonSpawn)
  1685. {
  1686. return addSpawn(npcId, loc.getX(), loc.getY(), loc.getZ(), loc.getHeading(), randomOffset, despawnDelay, isSummonSpawn, 0);
  1687. }
  1688. public L2Npc addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay, boolean isSummonSpawn, int instanceId)
  1689. {
  1690. L2Npc result = null;
  1691. try
  1692. {
  1693. L2NpcTemplate template = NpcTable.getInstance().getTemplate(npcId);
  1694. if (template != null)
  1695. {
  1696. // Sometimes, even if the quest script specifies some xyz (for example npc.getX() etc) by the time the code
  1697. // reaches here, xyz have become 0! Also, a questdev might have purposely set xy to 0,0...however,
  1698. // the spawn code is coded such that if x=y=0, it looks into location for the spawn loc! This will NOT work
  1699. // with quest spawns! For both of the above cases, we need a fail-safe spawn. For this, we use the
  1700. // default spawn location, which is at the player's loc.
  1701. if ((x == 0) && (y == 0))
  1702. {
  1703. _log.log(Level.SEVERE, "Failed to adjust bad locks for quest spawn! Spawn aborted!");
  1704. return null;
  1705. }
  1706. if (randomOffset)
  1707. {
  1708. int offset;
  1709. offset = Rnd.get(2); // Get the direction of the offset
  1710. if (offset == 0)
  1711. {
  1712. offset = -1;
  1713. } // make offset negative
  1714. offset *= Rnd.get(50, 100);
  1715. x += offset;
  1716. offset = Rnd.get(2); // Get the direction of the offset
  1717. if (offset == 0)
  1718. {
  1719. offset = -1;
  1720. } // make offset negative
  1721. offset *= Rnd.get(50, 100);
  1722. y += offset;
  1723. }
  1724. L2Spawn spawn = new L2Spawn(template);
  1725. spawn.setInstanceId(instanceId);
  1726. spawn.setHeading(heading);
  1727. spawn.setLocx(x);
  1728. spawn.setLocy(y);
  1729. spawn.setLocz(z + 20);
  1730. spawn.stopRespawn();
  1731. result = spawn.spawnOne(isSummonSpawn);
  1732. if (despawnDelay > 0)
  1733. result.scheduleDespawn(despawnDelay);
  1734. return result;
  1735. }
  1736. }
  1737. catch (Exception e1)
  1738. {
  1739. _log.warning("Could not spawn Npc " + npcId);
  1740. }
  1741. return null;
  1742. }
  1743. public L2Trap addTrap(int trapId, int x, int y, int z, int heading, L2Skill skill, int instanceId)
  1744. {
  1745. L2NpcTemplate TrapTemplate = NpcTable.getInstance().getTemplate(trapId);
  1746. L2Trap trap = new L2TrapInstance(IdFactory.getInstance().getNextId(), TrapTemplate, instanceId, -1, skill);
  1747. trap.setCurrentHp(trap.getMaxHp());
  1748. trap.setCurrentMp(trap.getMaxMp());
  1749. trap.setIsInvul(true);
  1750. trap.setHeading(heading);
  1751. //L2World.getInstance().storeObject(trap);
  1752. trap.spawnMe(x, y, z);
  1753. return trap;
  1754. }
  1755. public L2Npc addMinion(L2MonsterInstance master, int minionId)
  1756. {
  1757. return MinionList.spawnMinion(master, minionId);
  1758. }
  1759. public int[] getRegisteredItemIds()
  1760. {
  1761. return questItemIds;
  1762. }
  1763. @Override
  1764. public String getScriptName()
  1765. {
  1766. return this.getName();
  1767. }
  1768. @Override
  1769. public void setActive(boolean status)
  1770. {
  1771. // TODO implement me
  1772. }
  1773. @Override
  1774. public boolean reload()
  1775. {
  1776. unload();
  1777. return super.reload();
  1778. }
  1779. @Override
  1780. public boolean unload()
  1781. {
  1782. return unload(true);
  1783. }
  1784. public boolean unload(boolean removeFromList)
  1785. {
  1786. this.saveGlobalData();
  1787. // cancel all pending timers before reloading.
  1788. // if timers ought to be restarted, the quest can take care of it
  1789. // with its code (example: save global data indicating what timer must
  1790. // be restarted).
  1791. for (FastList<QuestTimer> timers : _allEventTimers.values())
  1792. for (QuestTimer timer : timers)
  1793. timer.cancel();
  1794. _allEventTimers.clear();
  1795. if (removeFromList)
  1796. return QuestManager.getInstance().removeQuest(this);
  1797. return true;
  1798. }
  1799. @Override
  1800. public ScriptManager<?> getScriptManager()
  1801. {
  1802. return QuestManager.getInstance();
  1803. }
  1804. public void setOnEnterWorld(boolean val)
  1805. {
  1806. _onEnterWorld = val;
  1807. }
  1808. public boolean getOnEnterWorld()
  1809. {
  1810. return _onEnterWorld;
  1811. }
  1812. /**
  1813. * @param val if true the quest script will be set as custom quest.
  1814. */
  1815. public void setIsCustom(boolean val)
  1816. {
  1817. _isCustom = val;
  1818. }
  1819. /**
  1820. * @return true if the quest script is a custom quest.
  1821. */
  1822. public boolean isCustomQuest()
  1823. {
  1824. return _isCustom;
  1825. }
  1826. }