MobGroupTable.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.model;
  16. import java.util.Map;
  17. import javolution.util.FastMap;
  18. import com.l2jserver.gameserver.model.actor.instance.L2ControllableMobInstance;
  19. /**
  20. * @author littlecrow
  21. *
  22. */
  23. public class MobGroupTable
  24. {
  25. private Map<Integer, MobGroup> _groupMap;
  26. public static final int FOLLOW_RANGE = 300;
  27. public static final int RANDOM_RANGE = 300;
  28. private MobGroupTable()
  29. {
  30. _groupMap = new FastMap<Integer, MobGroup>();
  31. }
  32. public static MobGroupTable getInstance()
  33. {
  34. return SingletonHolder._instance;
  35. }
  36. public void addGroup(int groupKey, MobGroup group)
  37. {
  38. _groupMap.put(groupKey, group);
  39. }
  40. public MobGroup getGroup(int groupKey)
  41. {
  42. return _groupMap.get(groupKey);
  43. }
  44. public int getGroupCount()
  45. {
  46. return _groupMap.size();
  47. }
  48. public MobGroup getGroupForMob(L2ControllableMobInstance mobInst)
  49. {
  50. for (MobGroup mobGroup : _groupMap.values())
  51. if (mobGroup.isGroupMember(mobInst))
  52. return mobGroup;
  53. return null;
  54. }
  55. public MobGroup[] getGroups()
  56. {
  57. return _groupMap.values().toArray(new MobGroup[getGroupCount()]);
  58. }
  59. public boolean removeGroup(int groupKey)
  60. {
  61. return (_groupMap.remove(groupKey) != null);
  62. }
  63. @SuppressWarnings("synthetic-access")
  64. private static class SingletonHolder
  65. {
  66. protected static final MobGroupTable _instance = new MobGroupTable();
  67. }
  68. }