FreyaCelebration.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 events.FreyaCelebration;
  16. import com.l2jserver.gameserver.instancemanager.QuestManager;
  17. import com.l2jserver.gameserver.model.L2Object;
  18. import com.l2jserver.gameserver.model.L2Skill;
  19. import com.l2jserver.gameserver.model.actor.L2Npc;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.quest.Quest;
  22. import com.l2jserver.gameserver.model.quest.QuestState;
  23. import com.l2jserver.gameserver.model.quest.State;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.clientpackets.Say2;
  26. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  27. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  28. import com.l2jserver.gameserver.util.Util;
  29. import com.l2jserver.util.Rnd;
  30. /**
  31. ** @author Gnacik
  32. **
  33. ** Retail Event : 'Freya Celebration'
  34. */
  35. public class FreyaCelebration extends Quest
  36. {
  37. private static final int _freya = 13296;
  38. private static final int _freya_potion = 15440;
  39. private static final int _freya_gift = 17138;
  40. private static final int _hours = 20;
  41. private static final int[] _skills = { 9150, 9151, 9152, 9153, 9154, 9155, 9156 };
  42. private static final String[] _freya_texts =
  43. {
  44. "It has been so long since I have felt this... I almost miss it.",
  45. "I have no idea what I'm feeling right now. Are all human emotions like this?",
  46. "You humans bring me such nonsense... a gift. I have no need of such things.",
  47. "I would 'appreciate' this, however it has been far too long since I have felt appreciation for anything.",
  48. " I am Freya the Ice Queen! Feelings and emotions of Felicia are nothing but memories to me."
  49. };
  50. private static final int[][] _spawns = {
  51. { -119494, 44882, 360, 24576 },
  52. { -117239, 46842, 360, 49151 },
  53. { -84023, 243051, -3728, 4096 },
  54. { -84411, 244813, -3728, 57343 },
  55. { 46908, 50856, -2992, 8192 },
  56. { 45538, 48357, -3056, 18000 },
  57. { -45372, -114104, -240, 16384 },
  58. { -45278, -112766, -240, 0 },
  59. { 9929, 16324, -4568, 62999 },
  60. { 11546, 17599, -4584, 46900 },
  61. { 115096, -178370, -880, 0 },
  62. { -13727, 122117, -2984, 16384 },
  63. { -14129, 123869, -3112, 40959 },
  64. { -83156, 150994, -3120, 0 },
  65. { -81031, 150038, -3040, 0 },
  66. { 16111, 142850, -2696, 16000 },
  67. { 17275, 145000, -3032, 25000 },
  68. { 111004, 218928, -3536, 16384 },
  69. { 81755, 146487, -3528, 32768 },
  70. { 82145, 148609, -3464, 0 },
  71. { 83037, 149324, -3464, 44000 },
  72. { 81987, 53723, -1488, 0 },
  73. { 147200, 25614, -2008, 16384 },
  74. { 148557, 26806, -2200, 32768 },
  75. { 147421, -55435, -2728, 49151 },
  76. { 148206, -55786, -2776, 61439 },
  77. { 85584, -142490, -1336, 0 },
  78. { 86865, -142915, -1336, 26000 },
  79. { 43966, -47709, -792, 49999 },
  80. { 43165, -48461, -792, 17000 }
  81. };
  82. @Override
  83. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  84. {
  85. QuestState st = player.getQuestState(getName());
  86. Quest q = QuestManager.getInstance().getQuest(getName());
  87. if (st == null || q == null)
  88. return null;
  89. if (event.equalsIgnoreCase("give_potion"))
  90. {
  91. if (st.getQuestItemsCount(57) > 1)
  92. {
  93. long _curr_time = System.currentTimeMillis();
  94. String value = q.loadGlobalQuestVar(player.getAccountName());
  95. long _reuse_time = value == "" ? 0 : Long.parseLong(value);
  96. if (_curr_time > _reuse_time)
  97. {
  98. st.setState(State.STARTED);
  99. st.takeItems(57, 1);
  100. st.giveItems(_freya_potion, 1);
  101. q.saveGlobalQuestVar(player.getAccountName(), Long.toString(System.currentTimeMillis() + (_hours * 3600000)));
  102. }
  103. else
  104. {
  105. long remainingTime = (_reuse_time - System.currentTimeMillis()) / 1000;
  106. int hours = (int) (remainingTime / 3600);
  107. int minutes = (int) ((remainingTime % 3600) / 60);
  108. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AVAILABLE_AFTER_S1_S2_HOURS_S3_MINUTES);
  109. sm.addItemName(_freya_potion);
  110. sm.addNumber(hours);
  111. sm.addNumber(minutes);
  112. player.sendPacket(sm);
  113. }
  114. }
  115. else
  116. {
  117. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S2_UNIT_OF_THE_ITEM_S1_REQUIRED);
  118. sm.addItemName(57);
  119. sm.addNumber(1);
  120. player.sendPacket(sm);
  121. }
  122. }
  123. return null;
  124. }
  125. @Override
  126. public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  127. {
  128. if ((caster == null) || (npc == null))
  129. return null;
  130. if ((npc.getNpcId() == _freya) && Util.contains(targets, npc) && Util.contains(_skills, skill.getId()))
  131. {
  132. if (Rnd.get(100) < 5)
  133. {
  134. npc.broadcastPacket(new CreatureSay(npc.getObjectId(), Say2.ALL, npc.getName(), "Dear " + caster.getName() + "... I want to express my appreciation for the gift. Take this with you. Why are you shocked? I'm a very generous person."));
  135. caster.addItem("FreyaCelebration", _freya_gift, 1, npc, true);
  136. }
  137. else
  138. {
  139. if (Rnd.get(10) < 2)
  140. {
  141. npc.broadcastPacket(new CreatureSay(npc.getObjectId(), Say2.ALL, npc.getName(), _freya_texts[Rnd.get(_freya_texts.length - 1)]));
  142. }
  143. }
  144. }
  145. return super.onSkillSee(npc, caster, skill, targets, isPet);
  146. }
  147. @Override
  148. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  149. {
  150. QuestState st = player.getQuestState(getName());
  151. if (st == null)
  152. {
  153. Quest q = QuestManager.getInstance().getQuest(getName());
  154. st = q.newQuestState(player);
  155. }
  156. return "13296.htm";
  157. }
  158. public FreyaCelebration(int questId, String name, String descr)
  159. {
  160. super(questId, name, descr);
  161. addStartNpc(_freya);
  162. addFirstTalkId(_freya);
  163. addTalkId(_freya);
  164. addSkillSeeId(_freya);
  165. for (int[] _spawn : _spawns)
  166. {
  167. addSpawn(_freya, _spawn[0], _spawn[1], _spawn[2], _spawn[3], false, 0);
  168. }
  169. }
  170. public static void main(String[] args)
  171. {
  172. new FreyaCelebration(-1, "FreyaCelebration", "events");
  173. }
  174. }