TvTEventTeam.java 4.1 KB

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