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
29
30 public abstract class Player
31 extends
32 InfoMessage
33 implements IWorldEvent, IWorldChangeEvent, ICompositeWorldObject
34
35 ,IPerson
36 ,cz.cuni.amis.pogamut.unreal.communication.messages.gbinfomessages.IPlayer
37 ,IGBViewable
38 {
39
40
41 public static final String PROTOTYPE =
42 "PLR {Id unreal_id} {Jmx text} {Name text} {Action text} {Visible False} {Rotation 0,0,0} {Location 0,0,0} {Velocity 0,0,0} {Team 0} {Weapon text} {Crouched False} {Firing 0} {EmotLeft text} {EmotCenter text} {EmotRight text} {Bubble text} {Anim text} ";
43
44
45
46
47
48
49 public Player()
50 {
51 }
52
53
54
55
56 protected long SimTime;
57
58
59
60
61 @Override
62 public long getSimTime() {
63 return SimTime;
64 }
65
66
67
68
69 protected void setSimTime(long SimTime) {
70 this.SimTime = SimTime;
71 }
72
73
74
75
76 public abstract UnrealId getId()
77 ;
78
79
80
81
82
83
84
85 public abstract String getJmx()
86 ;
87
88
89
90
91
92
93 public abstract String getName()
94 ;
95
96
97
98
99
100
101 public abstract String getAction()
102 ;
103
104
105
106
107
108
109 public abstract boolean isVisible()
110 ;
111
112
113
114
115
116
117 public abstract Rotation getRotation()
118 ;
119
120
121
122
123
124
125 public abstract Location getLocation()
126 ;
127
128
129
130
131
132
133
134 public abstract Velocity getVelocity()
135 ;
136
137
138
139
140
141
142
143 public abstract int getTeam()
144 ;
145
146
147
148
149
150
151
152
153
154
155 public abstract String getWeapon()
156 ;
157
158
159
160
161
162
163 public abstract boolean isCrouched()
164 ;
165
166
167
168
169
170
171
172 public abstract int getFiring()
173 ;
174
175
176
177
178
179
180 public abstract String getEmotLeft()
181 ;
182
183
184
185
186
187
188 public abstract String getEmotCenter()
189 ;
190
191
192
193
194
195
196 public abstract String getEmotRight()
197 ;
198
199
200
201
202
203
204 public abstract String getBubble()
205 ;
206
207
208
209
210
211
212 public abstract String getAnim()
213 ;
214
215 @Override
216 public IWorldObjectUpdatedEvent createDisappearEvent() {
217 return new ObjectDisappeared(this, getSimTime());
218 }
219
220 public static class ObjectDisappeared implements IWorldObjectUpdatedEvent
221 {
222
223 public ObjectDisappeared(Player obj, long time) {
224 this.obj = obj;
225 this.time = time;
226 }
227
228 private Player obj;
229 private long time;
230
231 @Override
232 public WorldObjectId getId() {
233 return obj.getId();
234 }
235
236
237
238
239 @Override
240 public long getSimTime() {
241 return time;
242 }
243
244 @Override
245 public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject obj) {
246 if (obj == null) {
247 throw new PogamutException("Can't 'disappear' null!", this);
248 }
249 if (!(obj instanceof PlayerMessage)) {
250 throw new PogamutException("Can't update different class than PlayerMessage, got class " + obj.getClass().getSimpleName() + "!", this);
251 }
252 PlayerMessage toUpdate = (PlayerMessage)obj;
253 if (toUpdate.Visible) {
254 toUpdate.Visible = false;
255 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
256 } else {
257 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
258 }
259 }
260
261 }
262
263
264
265 public static class PlayerUpdate
266 extends GBObjectUpdate implements ICompositeWorldObjectUpdatedEvent, IGBWorldObjectEvent {
267 private Player object;
268 private long time;
269 private ITeamId teamId;
270
271 public PlayerUpdate
272 (Player source, long eventTime, ITeamId teamId) {
273 this.object = source;
274 this.time = eventTime;
275 this.teamId = teamId;
276 }
277
278
279
280
281 @Override
282 public long getSimTime() {
283 return time;
284 }
285
286 @Override
287 public IWorldObject getObject() {
288 return object;
289 }
290
291 @Override
292 public WorldObjectId getId() {
293 return object.getId();
294 }
295
296 @Override
297 public ILocalWorldObjectUpdatedEvent getLocalEvent() {
298 return new PlayerLocalImpl.PlayerLocalUpdate
299 ((PlayerLocal)object.getLocal(), time);
300 }
301
302 @Override
303 public ISharedWorldObjectUpdatedEvent getSharedEvent() {
304 return new PlayerSharedImpl.PlayerSharedUpdate
305 ((PlayerShared)object.getShared(), time, teamId);
306 }
307
308 @Override
309 public IStaticWorldObjectUpdatedEvent getStaticEvent() {
310 return new PlayerStaticImpl.PlayerStaticUpdate
311 ((PlayerStatic)object.getStatic(), time);
312 }
313
314 }
315
316
317 public String toString() {
318 return
319 super.toString() + "[" +
320
321 "Id = " + String.valueOf(getId()
322 ) + " | " +
323
324 "Jmx = " + String.valueOf(getJmx()
325 ) + " | " +
326
327 "Name = " + String.valueOf(getName()
328 ) + " | " +
329
330 "Action = " + String.valueOf(getAction()
331 ) + " | " +
332
333 "Visible = " + String.valueOf(isVisible()
334 ) + " | " +
335
336 "Rotation = " + String.valueOf(getRotation()
337 ) + " | " +
338
339 "Location = " + String.valueOf(getLocation()
340 ) + " | " +
341
342 "Velocity = " + String.valueOf(getVelocity()
343 ) + " | " +
344
345 "Team = " + String.valueOf(getTeam()
346 ) + " | " +
347
348 "Weapon = " + String.valueOf(getWeapon()
349 ) + " | " +
350
351 "Crouched = " + String.valueOf(isCrouched()
352 ) + " | " +
353
354 "Firing = " + String.valueOf(getFiring()
355 ) + " | " +
356
357 "EmotLeft = " + String.valueOf(getEmotLeft()
358 ) + " | " +
359
360 "EmotCenter = " + String.valueOf(getEmotCenter()
361 ) + " | " +
362
363 "EmotRight = " + String.valueOf(getEmotRight()
364 ) + " | " +
365
366 "Bubble = " + String.valueOf(getBubble()
367 ) + " | " +
368
369 "Anim = " + String.valueOf(getAnim()
370 ) + " | " +
371
372 "]";
373 }
374
375
376 public String toHtmlString() {
377 return super.toString() + "[<br/>" +
378
379 "<b>Id</b> = " + String.valueOf(getId()
380 ) + " <br/> " +
381
382 "<b>Jmx</b> = " + String.valueOf(getJmx()
383 ) + " <br/> " +
384
385 "<b>Name</b> = " + String.valueOf(getName()
386 ) + " <br/> " +
387
388 "<b>Action</b> = " + String.valueOf(getAction()
389 ) + " <br/> " +
390
391 "<b>Visible</b> = " + String.valueOf(isVisible()
392 ) + " <br/> " +
393
394 "<b>Rotation</b> = " + String.valueOf(getRotation()
395 ) + " <br/> " +
396
397 "<b>Location</b> = " + String.valueOf(getLocation()
398 ) + " <br/> " +
399
400 "<b>Velocity</b> = " + String.valueOf(getVelocity()
401 ) + " <br/> " +
402
403 "<b>Team</b> = " + String.valueOf(getTeam()
404 ) + " <br/> " +
405
406 "<b>Weapon</b> = " + String.valueOf(getWeapon()
407 ) + " <br/> " +
408
409 "<b>Crouched</b> = " + String.valueOf(isCrouched()
410 ) + " <br/> " +
411
412 "<b>Firing</b> = " + String.valueOf(getFiring()
413 ) + " <br/> " +
414
415 "<b>EmotLeft</b> = " + String.valueOf(getEmotLeft()
416 ) + " <br/> " +
417
418 "<b>EmotCenter</b> = " + String.valueOf(getEmotCenter()
419 ) + " <br/> " +
420
421 "<b>EmotRight</b> = " + String.valueOf(getEmotRight()
422 ) + " <br/> " +
423
424 "<b>Bubble</b> = " + String.valueOf(getBubble()
425 ) + " <br/> " +
426
427 "<b>Anim</b> = " + String.valueOf(getAnim()
428 ) + " <br/> " +
429
430 "<br/>]";
431 }
432
433 public String toJsonLiteral() {
434 return "Player(null, "
435
436 + ", " +
437
438 (getId()
439 == null ? "null" :
440 "\"" + getId()
441 .getStringId() + "\""
442 )
443
444 + ", " +
445
446 (getName()
447 == null ? "null" :
448 "\"" + getName()
449 + "\""
450 )
451
452 + ", " +
453
454 String.valueOf(isVisible()
455 )
456
457 + ", " +
458
459 (getLocation()
460 == null ? "null" :
461 "[" + getLocation()
462 .getX() + ", " + getLocation()
463 .getY() + ", " + getLocation()
464 .getZ() + "]"
465 )
466
467 + ", " +
468
469 String.valueOf(getTeam()
470 )
471
472 + ")";
473 }
474
475
476
477
478
479
480
481
482
483
484 }
485