MobGroupTable.java 2.1 KB

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