PinsAndPouchUnseal.java 4.3 KB

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