MobGroupTable.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.model;
  20. import java.util.Map;
  21. import java.util.concurrent.ConcurrentHashMap;
  22. import com.l2jserver.gameserver.model.actor.instance.L2ControllableMobInstance;
  23. /**
  24. * @author littlecrow
  25. */
  26. public class MobGroupTable
  27. {
  28. private final Map<Integer, MobGroup> _groupMap;
  29. public static final int FOLLOW_RANGE = 300;
  30. public static final int RANDOM_RANGE = 300;
  31. protected MobGroupTable()
  32. {
  33. _groupMap = new ConcurrentHashMap<>();
  34. }
  35. public static MobGroupTable getInstance()
  36. {
  37. return SingletonHolder._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. {
  55. if (mobGroup.isGroupMember(mobInst))
  56. {
  57. return mobGroup;
  58. }
  59. }
  60. return null;
  61. }
  62. public MobGroup[] getGroups()
  63. {
  64. return _groupMap.values().toArray(new MobGroup[getGroupCount()]);
  65. }
  66. public boolean removeGroup(int groupKey)
  67. {
  68. return (_groupMap.remove(groupKey) != null);
  69. }
  70. private static class SingletonHolder
  71. {
  72. protected static final MobGroupTable _instance = new MobGroupTable();
  73. }
  74. }