2
0

L2SiegeClan.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.List;
  17. import javolution.util.FastList;
  18. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  19. public class L2SiegeClan
  20. {
  21. // ==========================================================================================
  22. // Instance
  23. // ===============================================================
  24. // Data Field
  25. private int _clanId = 0;
  26. private List<L2NpcInstance> _flag = new FastList<L2NpcInstance>();
  27. private int _numFlagsAdded = 0;
  28. private SiegeClanType _type;
  29. public enum SiegeClanType
  30. {
  31. OWNER,
  32. DEFENDER,
  33. ATTACKER,
  34. DEFENDER_PENDING
  35. }
  36. // =========================================================
  37. // Constructor
  38. public L2SiegeClan(int clanId, SiegeClanType type)
  39. {
  40. _clanId = clanId;
  41. _type = type;
  42. }
  43. // =========================================================
  44. // Method - Public
  45. public int getNumFlags()
  46. {
  47. return _numFlagsAdded;
  48. }
  49. public void addFlag(L2NpcInstance flag)
  50. {
  51. _numFlagsAdded++;
  52. getFlag().add(flag);
  53. }
  54. public boolean removeFlag(L2NpcInstance flag)
  55. {
  56. if (flag == null) return false;
  57. boolean ret = getFlag().remove(flag);
  58. //flag.deleteMe();
  59. //check if null objects or dups remain in the list.
  60. //for some reason, this might be happenning sometimes...
  61. // delete false dupplicates: if this flag got deleted, delete its copies too.
  62. if (ret)
  63. while (getFlag().remove(flag)) ;
  64. // now delete nulls
  65. int n;
  66. boolean more = true;
  67. while (more)
  68. {
  69. more = false;
  70. n = getFlag().size();
  71. if (n>0)
  72. for(int i=0; i<n;i++)
  73. if(getFlag().get(i)==null)
  74. {
  75. getFlag().remove(i);
  76. more = true;
  77. break;
  78. }
  79. }
  80. flag.deleteMe();
  81. _numFlagsAdded--;
  82. return ret;
  83. }
  84. public void removeFlags()
  85. {
  86. for (L2NpcInstance flag: getFlag())
  87. removeFlag(flag);
  88. }
  89. // =========================================================
  90. // Proeprty
  91. public final int getClanId() { return _clanId; }
  92. public final List<L2NpcInstance> getFlag()
  93. {
  94. if (_flag == null) _flag = new FastList<L2NpcInstance>();
  95. return _flag;
  96. }
  97. public SiegeClanType getType() { return _type; }
  98. public void setType(SiegeClanType setType) { _type = setType; }
  99. }