PinsAndPouchUnseal.java 4.1 KB

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