EventDroplist.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 com.l2jserver.gameserver.datatables;
  16. import java.util.Date;
  17. import java.util.List;
  18. import com.l2jserver.gameserver.script.DateRange;
  19. import javolution.util.FastList;
  20. /**
  21. * This class manage drop of Special Events created by GM for a defined period.
  22. * During a Special Event all L2Attackable can drop extra Items.
  23. * Those extra Items are defined in the table <B>allNpcDateDrops</B>.
  24. * Each Special Event has a start and end date to stop to drop extra Items automaticaly.<BR><BR>
  25. */
  26. public class EventDroplist
  27. {
  28. //private static Logger _log = Logger.getLogger(EventDroplist.class.getName());
  29. /** The table containing all DataDrop object */
  30. private List<DateDrop> _allNpcDateDrops;
  31. public static EventDroplist getInstance()
  32. {
  33. return SingletonHolder._instance;
  34. }
  35. public class DateDrop
  36. {
  37. /** Start and end date of the Event */
  38. public DateRange dateRange;
  39. /** The table containing Item identifier that can be dropped as extra Items during the Event */
  40. public int[] items;
  41. /** The min number of Item dropped in one time during this Event */
  42. public int min;
  43. /** The max number of Item dropped in one time during this Event */
  44. public int max;
  45. /** The rate of drop for this Event */
  46. public int chance;
  47. }
  48. /**
  49. * Constructor of EventDroplist.<BR><BR>
  50. */
  51. private EventDroplist()
  52. {
  53. _allNpcDateDrops = new FastList<DateDrop>();
  54. }
  55. /**
  56. * Create and Init a new DateDrop then add it to the allNpcDateDrops of EventDroplist .<BR><BR>
  57. *
  58. * @param items The table containing all item identifier of this DateDrop
  59. * @param count The table containing min and max value of this DateDrop
  60. * @param chance The chance to obtain this drop
  61. * @param range The DateRange object to add to this DateDrop
  62. *
  63. */
  64. public void addGlobalDrop(int[] items, int[] count, int chance, DateRange range)
  65. {
  66. DateDrop date = new DateDrop();
  67. date.dateRange = range;
  68. date.items = items;
  69. date.min = count[0];
  70. date.max = count[1];
  71. date.chance = chance;
  72. _allNpcDateDrops.add(date);
  73. }
  74. /**
  75. * Return all DateDrop of EventDroplist allNpcDateDrops within the date range.<BR><BR>
  76. */
  77. public List<DateDrop> getAllDrops()
  78. {
  79. List<DateDrop> list = new FastList<DateDrop>();
  80. for (DateDrop drop : _allNpcDateDrops)
  81. {
  82. Date currentDate = new Date();
  83. //_log.info("From: "+drop.from+" To: "+drop.to+" Now: "+ currentDate);
  84. if (drop.dateRange.isWithinRange(currentDate))
  85. {
  86. list.add(drop);
  87. }
  88. }
  89. return list;
  90. }
  91. @SuppressWarnings("synthetic-access")
  92. private static class SingletonHolder
  93. {
  94. protected static final EventDroplist _instance = new EventDroplist();
  95. }
  96. }