PriestOfBlessing.java 6.7 KB

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