NewbieCoupons.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.NewbieCoupons;
  16. import com.l2jserver.gameserver.datatables.MultiSell;
  17. import com.l2jserver.gameserver.model.actor.L2Npc;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.model.quest.Quest;
  20. import com.l2jserver.gameserver.model.quest.QuestState;
  21. /**
  22. * @authors Vice (python), Nyaran (java)
  23. * @notes Newbie Weapon/Accesories Coupons for the Hellbound opening event.
  24. * based in the Miss Queen script.
  25. */
  26. public class NewbieCoupons extends Quest
  27. {
  28. private static final String qn = "NewbieCoupons";
  29. private static final int COUPON_ONE = 7832;
  30. private static final int COUPON_TWO = 7833;
  31. private static final int[] NPCs =
  32. {
  33. 30598, 30599, 30600, 30601, 30602, 31076, 31077, 32135
  34. };
  35. private static final int WEAPON_MULTISELL = 305986001;
  36. private static final int ACCESORIES_MULTISELL = 305986002;
  37. // enable/disable coupon give
  38. private static final boolean NEWBIE_COUPONS_ENABLED = true;
  39. /*
  40. * Newbie/one time rewards section Any quest should rely on a unique bit, but it could be shared among quests that were mutually exclusive or race restricted. Bit //1 isn't used for backwards compatibility. This script uses 2 bits, one for newbie coupons and another for travelers These 2 bits happen to be the same used by the Miss Queen script
  41. */
  42. private static final int NEWBIE_WEAPON = 16;
  43. private static final int NEWBIE_ACCESORY = 32;
  44. public NewbieCoupons(int id, String name, String descr)
  45. {
  46. super(id, name, descr);
  47. for (int i : NPCs)
  48. {
  49. addStartNpc(i);
  50. addTalkId(i);
  51. }
  52. }
  53. @Override
  54. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  55. {
  56. String htmltext = event;
  57. if (!NEWBIE_COUPONS_ENABLED)
  58. return htmltext;
  59. QuestState st = player.getQuestState(qn);
  60. int newbie = player.getNewbie();
  61. int level = player.getLevel();
  62. int occupation_level = player.getClassId().level();
  63. int pkkills = player.getPkKills();
  64. if (event.equals("newbie_give_weapon_coupon"))
  65. {
  66. /*
  67. * TODO: check if this is the very first character for this account would need a bit of SQL, or a core method to determine it. This condition should be stored by the core in the account_data table upon character creation.
  68. */
  69. if (level >= 6 && level <= 39 && pkkills == 0 && occupation_level == 0)
  70. {
  71. // check the player state against this quest newbie rewarding mark.
  72. if ((newbie | NEWBIE_WEAPON) != newbie)
  73. {
  74. player.setNewbie(newbie | NEWBIE_WEAPON);
  75. st.giveItems(COUPON_ONE, 5);
  76. htmltext = "30598-2.htm"; // here's the coupon you requested
  77. }
  78. else
  79. htmltext = "30598-1.htm"; // you got a coupon already!
  80. }
  81. else
  82. htmltext = "30598-3.htm"; // you're not eligible to get a coupon (level caps, pkkills or already changed class)
  83. }
  84. else if (event.equals("newbie_give_armor_coupon"))
  85. {
  86. if (level >= 6 && level <= 39 && pkkills == 0 && occupation_level == 1)
  87. {
  88. // check the player state against this quest newbie rewarding mark.
  89. if ((newbie | NEWBIE_ACCESORY) != newbie)
  90. {
  91. player.setNewbie(newbie | NEWBIE_ACCESORY);
  92. st.giveItems(COUPON_TWO, 1);
  93. htmltext = "30598-5.htm"; // here's the coupon you requested
  94. }
  95. else
  96. htmltext = "30598-4.htm"; // you got a coupon already!
  97. }
  98. else
  99. htmltext = "30598-6.htm"; // you're not eligible to get a coupon (level caps, pkkills or didnt change class yet)
  100. }
  101. else if (event.equals("newbie_show_weapon"))
  102. {
  103. if (level >= 6 && level <= 39 && pkkills == 0 && occupation_level == 0)
  104. {
  105. MultiSell.getInstance().separateAndSend(WEAPON_MULTISELL, player, npc, false);
  106. return null;
  107. }
  108. else
  109. htmltext = "30598-7.htm"; // you're not eligible to use warehouse
  110. }
  111. else if (event.equals("newbie_show_armor"))
  112. {
  113. if (level >= 6 && level <= 39 && pkkills == 0 && occupation_level > 0)
  114. {
  115. MultiSell.getInstance().separateAndSend(ACCESORIES_MULTISELL, player, npc, false);
  116. return null;
  117. }
  118. else
  119. htmltext = "30598-8.htm"; // you're not eligible to use warehouse
  120. }
  121. return htmltext;
  122. }
  123. @Override
  124. public String onTalk(L2Npc npc, L2PcInstance player)
  125. {
  126. QuestState st = player.getQuestState(qn);
  127. if (st == null)
  128. st = this.newQuestState(player);
  129. return "30598.htm";
  130. }
  131. public static void main(String args[])
  132. {
  133. new NewbieCoupons(-1, qn, "custom");
  134. }
  135. }