TvTEventTeam.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Copyright (C) 2004-2014 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.entity;
  20. import java.util.Map;
  21. import javolution.util.FastMap;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. /**
  24. * @author FBIagent
  25. */
  26. public class TvTEventTeam
  27. {
  28. /** The name of the team<br> */
  29. private final String _name;
  30. /** The team spot coordinated<br> */
  31. private int[] _coordinates = new int[3];
  32. /** The points of the team<br> */
  33. private short _points;
  34. /** Name and instance of all participated players in FastMap<br> */
  35. private Map<Integer, L2PcInstance> _participatedPlayers = new FastMap<>();
  36. /**
  37. * C'tor initialize the team<br>
  38. * <br>
  39. * @param name as String<br>
  40. * @param coordinates as int[]<br>
  41. */
  42. public TvTEventTeam(String name, int[] coordinates)
  43. {
  44. _name = name;
  45. _coordinates = coordinates;
  46. _points = 0;
  47. }
  48. /**
  49. * Adds a player to the team<br>
  50. * <br>
  51. * @param playerInstance as L2PcInstance<br>
  52. * @return boolean: true if success, otherwise false<br>
  53. */
  54. public boolean addPlayer(L2PcInstance playerInstance)
  55. {
  56. if (playerInstance == null)
  57. {
  58. return false;
  59. }
  60. synchronized (_participatedPlayers)
  61. {
  62. _participatedPlayers.put(playerInstance.getObjectId(), playerInstance);
  63. }
  64. return true;
  65. }
  66. /**
  67. * Removes a player from the team
  68. * @param playerObjectId
  69. */
  70. public void removePlayer(int playerObjectId)
  71. {
  72. synchronized (_participatedPlayers)
  73. {
  74. _participatedPlayers.remove(playerObjectId);
  75. }
  76. }
  77. /**
  78. * Increases the points of the team<br>
  79. */
  80. public void increasePoints()
  81. {
  82. ++_points;
  83. }
  84. /**
  85. * Cleanup the team and make it ready for adding players again<br>
  86. */
  87. public void cleanMe()
  88. {
  89. _participatedPlayers.clear();
  90. _participatedPlayers = new FastMap<>();
  91. _points = 0;
  92. }
  93. /**
  94. * Is given player in this team?
  95. * @param playerObjectId
  96. * @return boolean: true if player is in this team, otherwise false
  97. */
  98. public boolean containsPlayer(int playerObjectId)
  99. {
  100. boolean containsPlayer;
  101. synchronized (_participatedPlayers)
  102. {
  103. containsPlayer = _participatedPlayers.containsKey(playerObjectId);
  104. }
  105. return containsPlayer;
  106. }
  107. /**
  108. * Returns the name of the team<br>
  109. * <br>
  110. * @return String: name of the team<br>
  111. */
  112. public String getName()
  113. {
  114. return _name;
  115. }
  116. /**
  117. * Returns the coordinates of the team spot<br>
  118. * <br>
  119. * @return int[]: team coordinates<br>
  120. */
  121. public int[] getCoordinates()
  122. {
  123. return _coordinates;
  124. }
  125. /**
  126. * Returns the points of the team<br>
  127. * <br>
  128. * @return short: team points<br>
  129. */
  130. public short getPoints()
  131. {
  132. return _points;
  133. }
  134. /**
  135. * Returns name and instance of all participated players in FastMap<br>
  136. * <br>
  137. * @return Map<String, L2PcInstance>: map of players in this team<br>
  138. */
  139. public Map<Integer, L2PcInstance> getParticipatedPlayers()
  140. {
  141. Map<Integer, L2PcInstance> participatedPlayers = null;
  142. synchronized (_participatedPlayers)
  143. {
  144. participatedPlayers = _participatedPlayers;
  145. }
  146. return participatedPlayers;
  147. }
  148. /**
  149. * Returns player count of this team<br>
  150. * <br>
  151. * @return int: number of players in team<br>
  152. */
  153. public int getParticipatedPlayerCount()
  154. {
  155. int participatedPlayerCount;
  156. synchronized (_participatedPlayers)
  157. {
  158. participatedPlayerCount = _participatedPlayers.size();
  159. }
  160. return participatedPlayerCount;
  161. }
  162. }