EventDroplist.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.datatables;
  20. import java.util.ArrayList;
  21. import java.util.Date;
  22. import java.util.List;
  23. import com.l2jserver.gameserver.script.DateRange;
  24. import com.l2jserver.gameserver.script.EventDrop;
  25. /**
  26. * This class manage drop of Special Events created by GM for a defined period.<br>
  27. * During a Special Event all L2Attackable can drop extra Items.<br>
  28. * Those extra Items are defined in the table <b>allNpcDateDrops</b>.<br>
  29. * Each Special Event has a start and end date to stop to drop extra Items automatically.
  30. */
  31. public class EventDroplist
  32. {
  33. /**
  34. * The table containing all DataDrop object
  35. */
  36. private static final List<DateDrop> ALL_NPC_DATE_DROPS = new ArrayList<>();
  37. public static class DateDrop
  38. {
  39. protected final DateRange _dateRange;
  40. private final EventDrop _eventDrop;
  41. public DateDrop(DateRange dateRange, EventDrop eventDrop)
  42. {
  43. _dateRange = dateRange;
  44. _eventDrop = eventDrop;
  45. }
  46. /**
  47. * @return the _eventDrop
  48. */
  49. public EventDrop getEventDrop()
  50. {
  51. return _eventDrop;
  52. }
  53. /**
  54. * @return the _dateRange
  55. */
  56. public DateRange getDateRange()
  57. {
  58. return _dateRange;
  59. }
  60. }
  61. /**
  62. * Create and Init a new DateDrop then add it to the allNpcDateDrops of EventDroplist .
  63. * @param itemIdList The table containing all item identifier of this DateDrop
  64. * @param count The table containing min and max value of this DateDrop
  65. * @param chance The chance to obtain this drop
  66. * @param dateRange The DateRange object to add to this DateDrop
  67. */
  68. public void addGlobalDrop(int[] itemIdList, int[] count, int chance, DateRange dateRange)
  69. {
  70. ALL_NPC_DATE_DROPS.add(new DateDrop(dateRange, new EventDrop(itemIdList, count[0], count[1], chance)));
  71. }
  72. /**
  73. * @param itemId the item Id for the drop
  74. * @param min the minimum drop count
  75. * @param max the maximum drop count
  76. * @param chance the drop chance
  77. * @param dateRange the event drop rate range
  78. */
  79. public void addGlobalDrop(int itemId, long min, long max, int chance, DateRange dateRange)
  80. {
  81. ALL_NPC_DATE_DROPS.add(new DateDrop(dateRange, new EventDrop(itemId, min, max, chance)));
  82. }
  83. /**
  84. * Adds an event drop for a given date range.
  85. * @param dateRange the date range.
  86. * @param eventDrop the event drop.
  87. */
  88. public void addGlobalDrop(DateRange dateRange, EventDrop eventDrop)
  89. {
  90. ALL_NPC_DATE_DROPS.add(new DateDrop(dateRange, eventDrop));
  91. }
  92. /**
  93. * @return all DateDrop of EventDroplist allNpcDateDrops within the date range.
  94. */
  95. public List<DateDrop> getAllDrops()
  96. {
  97. final List<DateDrop> list = new ArrayList<>();
  98. final Date currentDate = new Date();
  99. for (DateDrop drop : ALL_NPC_DATE_DROPS)
  100. {
  101. if (drop._dateRange.isWithinRange(currentDate))
  102. {
  103. list.add(drop);
  104. }
  105. }
  106. return list;
  107. }
  108. public static EventDroplist getInstance()
  109. {
  110. return SingletonHolder._instance;
  111. }
  112. private static class SingletonHolder
  113. {
  114. protected static final EventDroplist _instance = new EventDroplist();
  115. }
  116. }