View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.tag.server;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   import java.util.Map;
6   
7   import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
8   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
9   import cz.cuni.amis.utils.maps.LazyMap;
10  
11  public class BotTagRecord<PLAYER_CONTAINER> {
12  	
13  	private final UnrealId botId;
14  	
15  	private long initTime;
16  	
17  	private long finishTime = -1;
18  	
19  	private Map<UnrealId, List<Long>> tagGotMillis = new LazyMap<UnrealId, List<Long>>() {
20  		@Override
21  		protected List<Long> create(UnrealId key) {
22  			return new ArrayList<Long>();
23  		}
24  	};
25  	
26  	private Map<UnrealId, List<Long>> tagPassedMillis = new LazyMap<UnrealId, List<Long>>() {
27  		@Override
28  		protected List<Long> create(UnrealId key) {
29  			return new ArrayList<Long>();
30  		}
31  	};
32  	
33  	private int score = 0;
34  	
35  	private UnrealId immunity = null;
36  	
37  	private boolean hasTag = false;
38  	
39  	private boolean inGame = false;
40  	
41  	private PLAYER_CONTAINER player;
42  	
43  	public BotTagRecord(UnrealId botId) {
44  		this.botId = botId;
45  	}
46  
47  	/**
48  	 * How many times was this bot TAGGED (negative score).
49  	 * @return
50  	 */
51  	public int getScore() {
52  		return score;
53  	}
54  
55  	public void setScore(int score) {
56  		this.score = score;
57  	}
58  
59  	public UnrealId getBotId() {
60  		return botId;
61  	}
62  
63  	public UnrealId getImmunity() {
64  		return immunity;
65  	}
66  
67  	public void setImmunity(UnrealId immunity) {
68  		this.immunity = immunity;
69  	}
70  
71  	public boolean isInGame() {
72  		return inGame;
73  	}
74  
75  	public void setInGame(boolean inGame) {
76  		this.inGame = inGame;
77  	}
78  
79  	public long getInitTime() {
80  		return initTime;
81  	}
82  
83  	public void setInitTime(long initTime) {
84  		this.initTime = initTime;
85  	}
86  
87  	public long getFinishTime() {
88  		return finishTime;
89  	}
90  
91  	public void setFinishTime(long finishTime) {
92  		this.finishTime = finishTime;
93  	}
94  
95  	public Map<UnrealId, List<Long>> getTagGotMillis() {
96  		return tagGotMillis;
97  	}
98  
99  	public Map<UnrealId, List<Long>> getTagPassedMillis() {
100 		return tagPassedMillis;
101 	}
102 	
103 	public boolean isHasTag() {
104 		return hasTag;
105 	}
106 	
107 	public void setHasTag(boolean hasTag) {
108 		this.hasTag = hasTag;
109 	}
110 
111 	public void tagged(UnrealId taggedBy) {
112 		if (hasTag) return;
113 		if (taggedBy == null) taggedBy = UT2004TagServer.SERVER_UNREAL_ID;
114 		hasTag = true;
115 		if (taggedBy != UT2004TagServer.SERVER_UNREAL_ID) ++score;
116 		tagGotMillis.get(taggedBy).add(System.currentTimeMillis());
117 	}
118 	
119 	public void tagPassed(UnrealId toWhom) {
120 		if (!hasTag) return;
121 		if (toWhom == null) toWhom = UT2004TagServer.SERVER_UNREAL_ID;
122 		hasTag = false;
123 		tagPassedMillis.get(toWhom).add(System.currentTimeMillis());
124 	}
125 
126 	public void reset() {
127 		initTime = System.currentTimeMillis();
128 		finishTime = -1;
129 		tagGotMillis.clear();
130 		tagPassedMillis.clear();
131 		inGame = false;
132 		hasTag = false;
133 		score = 0;
134 		immunity = null;
135 	}
136 
137 	public PLAYER_CONTAINER getPlayer() {
138 		return player;
139 	}
140 
141 	public void setPlayer(PLAYER_CONTAINER player) {
142 		this.player = player;
143 	}
144 
145 }