Quest.java 57 KB

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