Quest.java 58 KB

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