PriestOfBlessing.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package ai.npc.PriestOfBlessing;
  20. import ai.npc.AbstractNpcAI;
  21. import com.l2jserver.gameserver.model.Location;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  27. import com.l2jserver.gameserver.util.Util;
  28. /**
  29. * Priest Of Blessing AI.
  30. * @author Gnacik
  31. */
  32. public final class PriestOfBlessing extends AbstractNpcAI
  33. {
  34. // NPC
  35. private static final int PRIEST = 32783;
  36. // Spawn state
  37. private static boolean SPAWNED = false;
  38. // Items
  39. private static final int NEVIT_VOICE = 17094;
  40. // @formatter:off
  41. private static final int[][] HOURGLASSES =
  42. {
  43. { 17095, 17096, 17097, 17098, 17099 },
  44. { 17100, 17101, 17102, 17103, 17104 },
  45. { 17105, 17106, 17107, 17108, 17109 },
  46. { 17110, 17111, 17112, 17113, 17114 },
  47. { 17115, 17116, 17117, 17118, 17119 },
  48. { 17120, 17121, 17122, 17123, 17124 },
  49. { 17125, 17126, 17127, 17128, 17129 }
  50. };
  51. // @formatter:on
  52. // Prices
  53. private static final int PRICE_VOICE = 100000;
  54. private static final int[] PRICE_HOURGLASS =
  55. {
  56. 4000,
  57. 30000,
  58. 110000,
  59. 310000,
  60. 970000,
  61. 2160000,
  62. 5000000
  63. };
  64. // Locations
  65. private static final Location[] SPAWNS =
  66. {
  67. new Location(-84139, 243145, -3704, 8473),
  68. new Location(-119702, 44557, 360, 33023),
  69. new Location(45413, 48351, -3056, 50020),
  70. new Location(115607, -177945, -896, 38058),
  71. new Location(12086, 16589, -4584, 3355),
  72. new Location(-45032, -113561, -192, 32767),
  73. new Location(-83112, 150922, -3120, 2280),
  74. new Location(-13931, 121938, -2984, 30212),
  75. new Location(87127, -141330, -1336, 49153),
  76. new Location(43520, -47590, -792, 43738),
  77. new Location(148060, -55314, -2728, 40961),
  78. new Location(82801, 149381, -3464, 53707),
  79. new Location(82433, 53285, -1488, 22942),
  80. new Location(147059, 25930, -2008, 56399),
  81. new Location(111171, 221053, -3544, 2058),
  82. new Location(15907, 142901, -2688, 14324),
  83. new Location(116972, 77255, -2688, 41951)
  84. };
  85. private PriestOfBlessing()
  86. {
  87. super(PriestOfBlessing.class.getSimpleName(), "ai/npc");
  88. addStartNpc(PRIEST);
  89. addFirstTalkId(PRIEST);
  90. addTalkId(PRIEST);
  91. if (!SPAWNED)
  92. {
  93. for (Location spawn : SPAWNS)
  94. {
  95. addSpawn(PRIEST, spawn, false, 0);
  96. }
  97. SPAWNED = true;
  98. }
  99. }
  100. @Override
  101. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  102. {
  103. String htmltext = event;
  104. if (event.equalsIgnoreCase("buy_voice"))
  105. {
  106. if (player.getAdena() >= PRICE_VOICE)
  107. {
  108. String value = loadGlobalQuestVar(player.getAccountName() + "_voice");
  109. long _reuse_time = value == "" ? 0 : Long.parseLong(value);
  110. if (System.currentTimeMillis() > _reuse_time)
  111. {
  112. takeItems(player, Inventory.ADENA_ID, PRICE_VOICE);
  113. giveItems(player, NEVIT_VOICE, 1);
  114. saveGlobalQuestVar(player.getAccountName() + "_voice", Long.toString(System.currentTimeMillis() + (20 * 3600000)));
  115. }
  116. else
  117. {
  118. long remainingTime = (_reuse_time - System.currentTimeMillis()) / 1000;
  119. int hours = (int) (remainingTime / 3600);
  120. int minutes = (int) ((remainingTime % 3600) / 60);
  121. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AVAILABLE_AFTER_S1_S2_HOURS_S3_MINUTES);
  122. sm.addItemName(NEVIT_VOICE);
  123. sm.addInt(hours);
  124. sm.addInt(minutes);
  125. player.sendPacket(sm);
  126. }
  127. return null;
  128. }
  129. htmltext = "32783-adena.htm";
  130. }
  131. else if (event.equalsIgnoreCase("buy_hourglass"))
  132. {
  133. int _index = getHGIndex(player.getLevel());
  134. int _price_hourglass = PRICE_HOURGLASS[_index];
  135. if (player.getAdena() >= _price_hourglass)
  136. {
  137. String value = loadGlobalQuestVar(player.getAccountName() + "_hg_" + _index);
  138. long _reuse_time = value == "" ? 0 : Long.parseLong(value);
  139. if (System.currentTimeMillis() > _reuse_time)
  140. {
  141. int[] _hg = HOURGLASSES[_index];
  142. int _nevit_hourglass = _hg[getRandom(0, _hg.length - 1)];
  143. takeItems(player, Inventory.ADENA_ID, _price_hourglass);
  144. giveItems(player, _nevit_hourglass, 1);
  145. saveGlobalQuestVar(player.getAccountName() + "_hg_" + _index, Long.toString(System.currentTimeMillis() + (20 * 3600000)));
  146. }
  147. else
  148. {
  149. long remainingTime = (_reuse_time - System.currentTimeMillis()) / 1000;
  150. int hours = (int) (remainingTime / 3600);
  151. int minutes = (int) ((remainingTime % 3600) / 60);
  152. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AVAILABLE_AFTER_S1_S2_HOURS_S3_MINUTES);
  153. sm.addString("Nevit's Hourglass");
  154. sm.addInt(hours);
  155. sm.addInt(minutes);
  156. player.sendPacket(sm);
  157. }
  158. return null;
  159. }
  160. htmltext = "32783-adena.htm";
  161. }
  162. return htmltext;
  163. }
  164. @Override
  165. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  166. {
  167. String content = getHtm(player.getHtmlPrefix(), "32783.htm");
  168. content = content.replace("%donate%", Util.formatAdena(PRICE_HOURGLASS[getHGIndex(player.getLevel())]));
  169. return content;
  170. }
  171. private int getHGIndex(int lvl)
  172. {
  173. int index = 0;
  174. if (lvl < 20)
  175. {
  176. index = 0;
  177. }
  178. else if (lvl < 40)
  179. {
  180. index = 1;
  181. }
  182. else if (lvl < 52)
  183. {
  184. index = 2;
  185. }
  186. else if (lvl < 61)
  187. {
  188. index = 3;
  189. }
  190. else if (lvl < 76)
  191. {
  192. index = 4;
  193. }
  194. else if (lvl < 80)
  195. {
  196. index = 5;
  197. }
  198. else if (lvl < 86)
  199. {
  200. index = 6;
  201. }
  202. return index;
  203. }
  204. public static void main(String[] args)
  205. {
  206. new PriestOfBlessing();
  207. }
  208. }