1 package cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages;
2
3
4 import java.util.*;import javax.vecmath.*;import cz.cuni.amis.pogamut.base.communication.messages.*;import cz.cuni.amis.pogamut.base.communication.worldview.*;import cz.cuni.amis.pogamut.base.communication.worldview.event.*;import cz.cuni.amis.pogamut.base.communication.worldview.object.*;import cz.cuni.amis.pogamut.multi.communication.worldview.object.*;import cz.cuni.amis.pogamut.base.communication.translator.event.*;import cz.cuni.amis.pogamut.multi.communication.translator.event.*;import cz.cuni.amis.pogamut.base3d.worldview.object.*;import cz.cuni.amis.pogamut.base3d.worldview.object.event.*;import cz.cuni.amis.pogamut.ut2004.communication.messages.*;import cz.cuni.amis.pogamut.ut2004.communication.worldview.objects.*;import cz.cuni.amis.pogamut.ut2004multi.communication.worldview.objects.*;import cz.cuni.amis.pogamut.ut2004.communication.translator.itemdescriptor.*;import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Category;import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;import cz.cuni.amis.utils.exception.*;import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result;import cz.cuni.amis.utils.SafeEquals;import cz.cuni.amis.pogamut.base.agent.*;import cz.cuni.amis.pogamut.multi.agent.*;import cz.cuni.amis.pogamut.multi.communication.worldview.property.*;import cz.cuni.amis.pogamut.ut2004multi.communication.worldview.property.*;import cz.cuni.amis.utils.token.*;import cz.cuni.amis.utils.*;
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public abstract class Item
29 extends
30 InfoMessage
31 implements IWorldEvent, IWorldChangeEvent, ICompositeWorldObject
32
33 ,ILocated
34 ,IGBViewable
35 ,ItemTyped
36 {
37
38
39 public static final String PROTOTYPE =
40 "INV {Id unreal_id} {NavPointId unreal_id} {Visible False} {Location 0,0,0} {Amount 0} {Type xWeapons.FlakCannonPickup} {Dropped False} ";
41
42
43
44
45
46
47 public Item()
48 {
49 }
50
51
52
53
54 protected long SimTime;
55
56
57
58
59 @Override
60 public long getSimTime() {
61 return SimTime;
62 }
63
64
65
66
67 protected void setSimTime(long SimTime) {
68 this.SimTime = SimTime;
69 }
70
71
72
73
74
75
76
77 public abstract UnrealId getId()
78 ;
79
80
81
82
83
84
85 public abstract UnrealId getNavPointId()
86 ;
87
88
89
90
91
92
93
94 public abstract NavPoint getNavPoint()
95 ;
96
97
98
99
100
101
102 public abstract boolean isVisible()
103 ;
104
105
106
107
108 public abstract Location getLocation()
109 ;
110
111
112
113
114
115
116
117 public abstract int getAmount()
118 ;
119
120
121
122
123
124
125 public abstract ItemType getType()
126 ;
127
128
129
130
131
132
133 public abstract ItemDescriptor getDescriptor()
134 ;
135
136
137
138
139
140
141
142 public abstract boolean isDropped()
143 ;
144
145 @Override
146 public IWorldObjectUpdatedEvent createDisappearEvent() {
147 return new ObjectDisappeared(this, getSimTime());
148 }
149
150 public static class ObjectDisappeared implements IWorldObjectUpdatedEvent
151 {
152
153 public ObjectDisappeared(Item obj, long time) {
154 this.obj = obj;
155 this.time = time;
156 }
157
158 private Item obj;
159 private long time;
160
161 @Override
162 public WorldObjectId getId() {
163 return obj.getId();
164 }
165
166
167
168
169 @Override
170 public long getSimTime() {
171 return time;
172 }
173
174 @Override
175 public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject obj) {
176 if (obj == null) {
177 throw new PogamutException("Can't 'disappear' null!", this);
178 }
179 if (!(obj instanceof ItemMessage)) {
180 throw new PogamutException("Can't update different class than ItemMessage, got class " + obj.getClass().getSimpleName() + "!", this);
181 }
182 ItemMessage toUpdate = (ItemMessage)obj;
183 if (toUpdate.Visible) {
184 toUpdate.Visible = false;
185 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
186 } else {
187 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
188 }
189 }
190
191 }
192
193
194
195 public static class ItemUpdate
196 extends GBObjectUpdate implements ICompositeWorldObjectUpdatedEvent, IGBWorldObjectEvent {
197 private Item object;
198 private long time;
199 private ITeamId teamId;
200
201 public ItemUpdate
202 (Item source, long eventTime, ITeamId teamId) {
203 this.object = source;
204 this.time = eventTime;
205 this.teamId = teamId;
206 }
207
208
209
210
211 @Override
212 public long getSimTime() {
213 return time;
214 }
215
216 @Override
217 public IWorldObject getObject() {
218 return object;
219 }
220
221 @Override
222 public WorldObjectId getId() {
223 return object.getId();
224 }
225
226 @Override
227 public ILocalWorldObjectUpdatedEvent getLocalEvent() {
228 return new ItemLocalImpl.ItemLocalUpdate
229 ((ItemLocal)object.getLocal(), time);
230 }
231
232 @Override
233 public ISharedWorldObjectUpdatedEvent getSharedEvent() {
234 return new ItemSharedImpl.ItemSharedUpdate
235 ((ItemShared)object.getShared(), time, teamId);
236 }
237
238 @Override
239 public IStaticWorldObjectUpdatedEvent getStaticEvent() {
240 return new ItemStaticImpl.ItemStaticUpdate
241 ((ItemStatic)object.getStatic(), time);
242 }
243
244 }
245
246
247 public String toString() {
248 return
249 super.toString() + "[" +
250
251 "Id = " + String.valueOf(getId()
252 ) + " | " +
253
254 "NavPointId = " + String.valueOf(getNavPointId()
255 ) + " | " +
256
257 "Visible = " + String.valueOf(isVisible()
258 ) + " | " +
259
260 "Location = " + String.valueOf(getLocation()
261 ) + " | " +
262
263 "Amount = " + String.valueOf(getAmount()
264 ) + " | " +
265
266 "Type = " + String.valueOf(getType()
267 ) + " | " +
268
269 "Dropped = " + String.valueOf(isDropped()
270 ) + " | " +
271
272 "]";
273 }
274
275
276 public String toHtmlString() {
277 return super.toString() + "[<br/>" +
278
279 "<b>Id</b> = " + String.valueOf(getId()
280 ) + " <br/> " +
281
282 "<b>NavPointId</b> = " + String.valueOf(getNavPointId()
283 ) + " <br/> " +
284
285 "<b>Visible</b> = " + String.valueOf(isVisible()
286 ) + " <br/> " +
287
288 "<b>Location</b> = " + String.valueOf(getLocation()
289 ) + " <br/> " +
290
291 "<b>Amount</b> = " + String.valueOf(getAmount()
292 ) + " <br/> " +
293
294 "<b>Type</b> = " + String.valueOf(getType()
295 ) + " <br/> " +
296
297 "<b>Dropped</b> = " + String.valueOf(isDropped()
298 ) + " <br/> " +
299
300 "<br/>]";
301 }
302
303 public String toJsonLiteral() {
304 return "item( "
305 +
306 (getId()
307 == null ? "null" :
308 "\"" + getId()
309 .getStringId() + "\""
310 )
311 + ", " +
312 (getNavPointId()
313 == null ? "null" :
314 "\"" + getNavPointId()
315 .getStringId() + "\""
316 )
317 + ", " +
318 String.valueOf(isVisible()
319 )
320 + ", " +
321 (getLocation()
322 == null ? "null" :
323 "[" + getLocation()
324 .getX() + ", " + getLocation()
325 .getY() + ", " + getLocation()
326 .getZ() + "]"
327 )
328 + ", " +
329 String.valueOf(getAmount()
330 )
331 + ", " +
332 (getType()
333 == null ? "null" :
334 "\"" + getType()
335 .getName() + "\""
336 )
337 + ", " +
338 String.valueOf(isDropped()
339 )
340
341 + ")";
342 }
343
344
345
346
347
348
349
350
351
352
353 }
354