PriestOfBlessing.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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 retail.PriestOfBlessing;
  16. import com.l2jserver.gameserver.model.actor.L2Npc;
  17. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  18. import com.l2jserver.gameserver.model.quest.Quest;
  19. import com.l2jserver.gameserver.model.quest.QuestState;
  20. import com.l2jserver.gameserver.model.quest.State;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  23. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  24. import com.l2jserver.gameserver.util.Util;
  25. /**
  26. * @author Gnacik
  27. */
  28. public class PriestOfBlessing extends Quest
  29. {
  30. // Spawn state
  31. private static boolean _spawned = false;
  32. // NPC
  33. private static final int _priest = 32783;
  34. // Prices
  35. private static final int _price_voice = 100000;
  36. //
  37. private static final int _nevit_voice = 17094;
  38. //
  39. private static final int[] _prices_hourglass =
  40. {
  41. 4000,
  42. 30000,
  43. 110000,
  44. 310000,
  45. 970000,
  46. 2160000,
  47. 5000000
  48. };
  49. //
  50. private static final int[][] _hourglasses =
  51. {
  52. {
  53. 17095,
  54. 17096,
  55. 17097,
  56. 17098,
  57. 17099
  58. },
  59. {
  60. 17100,
  61. 17101,
  62. 17102,
  63. 17103,
  64. 17104
  65. },
  66. {
  67. 17105,
  68. 17106,
  69. 17107,
  70. 17108,
  71. 17109
  72. },
  73. {
  74. 17110,
  75. 17111,
  76. 17112,
  77. 17113,
  78. 17114
  79. },
  80. {
  81. 17115,
  82. 17116,
  83. 17117,
  84. 17118,
  85. 17119
  86. },
  87. {
  88. 17120,
  89. 17121,
  90. 17122,
  91. 17123,
  92. 17124
  93. },
  94. {
  95. 17125,
  96. 17126,
  97. 17127,
  98. 17128,
  99. 17129
  100. }
  101. };
  102. // Spawns
  103. private static final int[][] _spawns =
  104. {
  105. {
  106. -84139,
  107. 243145,
  108. -3704,
  109. 8473
  110. },
  111. {
  112. -119702,
  113. 44557,
  114. 360,
  115. 33023
  116. },
  117. {
  118. 45413,
  119. 48351,
  120. -3056,
  121. 50020
  122. },
  123. {
  124. 115607,
  125. -177945,
  126. -896,
  127. 38058
  128. },
  129. {
  130. 12086,
  131. 16589,
  132. -4584,
  133. 3355
  134. },
  135. {
  136. -45032,
  137. -113561,
  138. -192,
  139. 32767
  140. },
  141. {
  142. -83112,
  143. 150922,
  144. -3120,
  145. 2280
  146. },
  147. {
  148. -13931,
  149. 121938,
  150. -2984,
  151. 30212
  152. },
  153. {
  154. 87127,
  155. -141330,
  156. -1336,
  157. 49153
  158. },
  159. {
  160. 43520,
  161. -47590,
  162. -792,
  163. 43738
  164. },
  165. {
  166. 148060,
  167. -55314,
  168. -2728,
  169. 40961
  170. },
  171. {
  172. 82801,
  173. 149381,
  174. -3464,
  175. 53707
  176. },
  177. {
  178. 82433,
  179. 53285,
  180. -1488,
  181. 22942
  182. },
  183. {
  184. 147059,
  185. 25930,
  186. -2008,
  187. 56399
  188. },
  189. {
  190. 111171,
  191. 221053,
  192. -3544,
  193. 2058
  194. },
  195. {
  196. 15907,
  197. 142901,
  198. -2688,
  199. 14324
  200. },
  201. {
  202. 116972,
  203. 77255,
  204. -2688,
  205. 41951
  206. }
  207. };
  208. @Override
  209. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  210. {
  211. String htmltext = event;
  212. QuestState st = player.getQuestState(getName());
  213. if (st == null)
  214. {
  215. return null;
  216. }
  217. if (event.equalsIgnoreCase("buy_voice"))
  218. {
  219. if (st.getQuestItemsCount(57) >= _price_voice)
  220. {
  221. String value = loadGlobalQuestVar(player.getAccountName() + "_voice");
  222. long _reuse_time = value == "" ? 0 : Long.parseLong(value);
  223. if (System.currentTimeMillis() > _reuse_time)
  224. {
  225. st.setState(State.STARTED);
  226. st.takeItems(57, _price_voice);
  227. st.giveItems(_nevit_voice, 1);
  228. saveGlobalQuestVar(player.getAccountName() + "_voice", Long.toString(System.currentTimeMillis() + (20 * 3600000)));
  229. }
  230. else
  231. {
  232. long remainingTime = (_reuse_time - System.currentTimeMillis()) / 1000;
  233. int hours = (int) (remainingTime / 3600);
  234. int minutes = (int) ((remainingTime % 3600) / 60);
  235. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AVAILABLE_AFTER_S1_S2_HOURS_S3_MINUTES);
  236. sm.addItemName(_nevit_voice);
  237. sm.addNumber(hours);
  238. sm.addNumber(minutes);
  239. player.sendPacket(sm);
  240. }
  241. return null;
  242. }
  243. htmltext = "32783-adena.htm";
  244. }
  245. else if (event.equalsIgnoreCase("buy_hourglass"))
  246. {
  247. int _index = getHGIndex(player.getLevel());
  248. int _price_hourglass = _prices_hourglass[_index];
  249. if (st.getQuestItemsCount(57) >= _price_hourglass)
  250. {
  251. String value = loadGlobalQuestVar(player.getAccountName() + "_hg_" + _index);
  252. long _reuse_time = value == "" ? 0 : Long.parseLong(value);
  253. if (System.currentTimeMillis() > _reuse_time)
  254. {
  255. int[] _hg = _hourglasses[_index];
  256. int _nevit_hourglass = _hg[getRandom(0, _hg.length - 1)];
  257. st.setState(State.STARTED);
  258. st.takeItems(57, _price_hourglass);
  259. st.giveItems(_nevit_hourglass, 1);
  260. saveGlobalQuestVar(player.getAccountName() + "_hg_" + _index, Long.toString(System.currentTimeMillis() + (20 * 3600000)));
  261. }
  262. else
  263. {
  264. long remainingTime = (_reuse_time - System.currentTimeMillis()) / 1000;
  265. int hours = (int) (remainingTime / 3600);
  266. int minutes = (int) ((remainingTime % 3600) / 60);
  267. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AVAILABLE_AFTER_S1_S2_HOURS_S3_MINUTES);
  268. sm.addString("Nevit's Hourglass");
  269. sm.addNumber(hours);
  270. sm.addNumber(minutes);
  271. player.sendPacket(sm);
  272. }
  273. return null;
  274. }
  275. htmltext = "32783-adena.htm";
  276. }
  277. return htmltext;
  278. }
  279. @Override
  280. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  281. {
  282. QuestState st = player.getQuestState(getName());
  283. if (st == null)
  284. {
  285. st = newQuestState(player);
  286. }
  287. final NpcHtmlMessage html = new NpcHtmlMessage(0);
  288. final String content = getHtm(player.getHtmlPrefix(), "32783.htm");
  289. html.setHtml(content);
  290. html.replace("%donate%", Util.formatAdena(_prices_hourglass[getHGIndex(player.getLevel())]));
  291. player.sendPacket(html);
  292. return null;
  293. }
  294. private int getHGIndex(int lvl)
  295. {
  296. int index = 0;
  297. if (lvl < 20)
  298. {
  299. index = 0;
  300. }
  301. else if (lvl < 40)
  302. {
  303. index = 1;
  304. }
  305. else if (lvl < 52)
  306. {
  307. index = 2;
  308. }
  309. else if (lvl < 61)
  310. {
  311. index = 3;
  312. }
  313. else if (lvl < 76)
  314. {
  315. index = 4;
  316. }
  317. else if (lvl < 80)
  318. {
  319. index = 5;
  320. }
  321. else if (lvl < 86)
  322. {
  323. index = 6;
  324. }
  325. return index;
  326. }
  327. public PriestOfBlessing(int questId, String name, String descr)
  328. {
  329. super(questId, name, descr);
  330. addStartNpc(_priest);
  331. addFirstTalkId(_priest);
  332. addTalkId(_priest);
  333. if (!_spawned)
  334. {
  335. for (int[] _spawn : _spawns)
  336. {
  337. addSpawn(_priest, _spawn[0], _spawn[1], _spawn[2], _spawn[3], false, 0);
  338. }
  339. _spawned = true;
  340. }
  341. }
  342. public static void main(String[] args)
  343. {
  344. new PriestOfBlessing(-1, "PriestOfBlessing", "retail");
  345. }
  346. }