PinsAndPouchUnseal.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 custom.PinsAndPouchUnseal;
  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.network.NpcStringId;
  21. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  22. import com.l2jserver.util.Rnd;
  23. public class PinsAndPouchUnseal extends Quest
  24. {
  25. private final static int[] NPCs =
  26. {
  27. 32610,32612
  28. };
  29. private final static int[] UNSEALPRICE = {3200,11800,26500,136600};
  30. // failed, low, mid, high, top
  31. private final static int[] CHANCES = {49,78,95,99,100};
  32. // sealdId, lowId, midId, highId, topId
  33. private final static int[][] PINS = {{13898,13902,13903,13904,13905},
  34. {13899,13906,13907,13908,13909},
  35. {13900,13910,13911,13912,13913},
  36. {13901,13914,13915,13916,13917}
  37. };
  38. // sealdId, lowId, midId, highId, topId
  39. private final static int[][] POUCHS = {{13918,13922,13923,13924,13925},
  40. {13919,13926,13927,13928,13929},
  41. {13920,13930,13931,13932,13933},
  42. {13921,13934,13935,13936,13937}
  43. };
  44. // "B,C grade" is the Magic Clip
  45. // "A,S grade" is the Magic Ornament
  46. // sealdId, lowId, midId, highId, topId
  47. private final static int[][] CLIPSORNAMENTS = {{14902,14906,14907,14908,14909},
  48. {14903,14910,14911,14912,14913},
  49. {14904,14914,14915,14916,14917},
  50. {14905,14918,14919,14920,14921}
  51. };
  52. public PinsAndPouchUnseal(int questId, String name, String descr)
  53. {
  54. super(questId, name, descr);
  55. for (int id : NPCs)
  56. {
  57. addStartNpc(id);
  58. addTalkId(id);
  59. }
  60. }
  61. @Override
  62. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  63. {
  64. String htmltext = "";
  65. QuestState st = player.getQuestState(getName());
  66. htmltext = event;
  67. if (event.contains("_grade_"))
  68. {
  69. int grade = Integer.parseInt(event.substring(0, 1));
  70. int price;
  71. int[] itemIds;
  72. if (event.endsWith("_pin"))
  73. {
  74. price = UNSEALPRICE[grade];
  75. itemIds = PINS[grade];
  76. }
  77. else if (event.endsWith("_pouch"))
  78. {
  79. price = UNSEALPRICE[grade];
  80. itemIds = POUCHS[grade];
  81. }
  82. else if (event.endsWith("_clip"))
  83. {
  84. price = UNSEALPRICE[grade];
  85. itemIds = CLIPSORNAMENTS[grade - 2];
  86. }
  87. else if (event.endsWith("_ornament"))
  88. {
  89. price = UNSEALPRICE[grade];
  90. itemIds = CLIPSORNAMENTS[grade];
  91. }
  92. else
  93. // this should not happen!
  94. return "";
  95. if (st.getQuestItemsCount(itemIds[0]) > 0)
  96. {
  97. if (st.getQuestItemsCount(57) > price)
  98. {
  99. htmltext = "";
  100. st.takeItems(57, price);
  101. st.takeItems(itemIds[0], 1);
  102. int rand = Rnd.get(100);
  103. if (rand < CHANCES[0])
  104. npc.broadcastPacket(new NpcSay(npc.getObjectId(), 0, npc.getNpcId(), NpcStringId.WHAT_A_PREDICAMENT_MY_ATTEMPTS_WERE_UNSUCCESSFUL));
  105. else if (rand < CHANCES[1])
  106. st.giveItems(itemIds[1], 1);
  107. else if (rand < CHANCES[2])
  108. st.giveItems(itemIds[2], 1);
  109. else if (rand < CHANCES[3])
  110. st.giveItems(itemIds[3], 1);
  111. else
  112. st.giveItems(itemIds[4], 1);
  113. }
  114. else
  115. htmltext = npc.getNpcId() + "-low.htm";
  116. }
  117. else
  118. htmltext = npc.getNpcId() + "-no.htm";
  119. st.exitQuest(true);
  120. }
  121. return htmltext;
  122. }
  123. @Override
  124. public String onTalk(L2Npc npc, L2PcInstance player)
  125. {
  126. String htmltext = "";
  127. htmltext = npc.getNpcId() + "-1.htm";
  128. return htmltext;
  129. }
  130. public static void main(String[] args)
  131. {
  132. new PinsAndPouchUnseal(-1, "PinsAndPouchUnseal", "custom");
  133. }
  134. }