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 public class MyInventoryMessage
28 extends
29 MyInventory
30 implements IWorldObjectUpdatedEvent, ICompositeWorldObjectUpdatedEvent
31
32 {
33
34
35
36
37
38
39 public MyInventoryMessage()
40 {
41 }
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 public MyInventoryMessage(
95 UnrealId Id, int CurrentAmmo, int CurrentAltAmmo, int Amount, ItemType Type, ItemDescriptor Descriptor
96 ) {
97
98 this.Id = Id;
99
100 this.CurrentAmmo = CurrentAmmo;
101
102 this.CurrentAltAmmo = CurrentAltAmmo;
103
104 this.Amount = Amount;
105
106 this.Type = Type;
107
108 this.Descriptor = Descriptor;
109
110 }
111
112
113
114
115
116
117 public MyInventoryMessage(MyInventoryMessage original) {
118
119 this.Id = original.getId()
120 ;
121
122 this.CurrentAmmo = original.getCurrentAmmo()
123 ;
124
125 this.CurrentAltAmmo = original.getCurrentAltAmmo()
126 ;
127
128 this.Amount = original.getAmount()
129 ;
130
131 this.Type = original.getType()
132 ;
133
134 this.Descriptor = original.getDescriptor()
135 ;
136
137 this.TeamId = original.getTeamId();
138
139 this.SimTime = original.getSimTime();
140 }
141
142
143 protected ITeamId TeamId;
144
145
146
147
148 protected void setTeamId(ITeamId TeamId) {
149 this.TeamId = TeamId;
150 }
151
152 public ITeamId getTeamId() {
153 return TeamId;
154 }
155
156
157
158
159
160
161
162
163
164 protected
165 UnrealId Id =
166 null;
167
168
169
170
171
172 protected boolean Id_Set = false;
173
174 @Override
175
176
177
178
179
180
181 public UnrealId getId()
182 {
183 return Id;
184 }
185
186
187
188
189
190
191
192 protected
193 int CurrentAmmo =
194 0;
195
196
197
198
199
200 protected boolean CurrentAmmo_Set = false;
201
202 @Override
203
204
205
206
207
208
209 public int getCurrentAmmo()
210 {
211 return CurrentAmmo;
212 }
213
214
215
216
217
218
219
220 protected
221 int CurrentAltAmmo =
222 0;
223
224
225
226
227
228 protected boolean CurrentAltAmmo_Set = false;
229
230 @Override
231
232
233
234
235
236
237 public int getCurrentAltAmmo()
238 {
239 return CurrentAltAmmo;
240 }
241
242
243
244
245
246
247
248 protected
249 int Amount =
250 0;
251
252
253
254
255
256 protected boolean Amount_Set = false;
257
258 @Override
259
260
261
262
263
264
265 public int getAmount()
266 {
267 return Amount;
268 }
269
270
271
272
273
274
275
276 protected
277 ItemType Type =
278 null;
279
280
281
282
283
284 protected boolean Type_Set = false;
285
286 @Override
287
288
289
290
291
292
293 public ItemType getType()
294 {
295 return Type;
296 }
297
298
299
300
301
302
303
304 protected
305 ItemDescriptor Descriptor =
306 null;
307
308
309
310
311
312 protected boolean Descriptor_Set = false;
313
314 @Override
315
316
317
318
319
320
321 public ItemDescriptor getDescriptor()
322 {
323 return Descriptor;
324 }
325
326
327 private MyInventoryLocal localPart = null;
328
329 @Override
330 public MyInventoryLocal
331 getLocal() {
332 if (localPart != null) return localPart;
333 return localPart = new
334 MyInventoryLocalMessage();
335 }
336
337 private MyInventoryShared sharedPart = null;
338
339 @Override
340 public MyInventoryShared
341 getShared() {
342 if (sharedPart != null) return sharedPart;
343 return sharedPart = new
344 MyInventorySharedMessage();
345 }
346
347 private MyInventoryStatic staticPart = null;
348
349 @Override
350 public MyInventoryStatic
351 getStatic() {
352 if (staticPart != null) return staticPart;
353 return staticPart = new
354 MyInventoryStaticMessage();
355 }
356
357
358
359
360
361
362
363
364
365
366
367
368
369 public class MyInventoryLocalMessage
370 extends
371 MyInventoryLocal
372 {
373
374 @Override
375 public
376 MyInventoryLocalMessage clone() {
377 return this;
378 }
379
380 public MyInventoryLocalMessage getLocal() {
381 return this;
382 }
383 public ISharedWorldObject getShared() {
384 throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
385 }
386 public IStaticWorldObject getStatic() {
387 throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
388 }
389
390
391
392
393
394
395 public UnrealId getId()
396 {
397 return Id;
398 }
399
400
401
402
403
404
405 public int getCurrentAmmo()
406 {
407 return CurrentAmmo;
408 }
409
410
411
412
413
414
415 public int getCurrentAltAmmo()
416 {
417 return CurrentAltAmmo;
418 }
419
420
421
422
423
424
425 public int getAmount()
426 {
427 return Amount;
428 }
429
430
431 public String toString() {
432 return
433 super.toString() + "[" +
434
435 "Id = " + String.valueOf(getId()
436 ) + " | " +
437
438 "CurrentAmmo = " + String.valueOf(getCurrentAmmo()
439 ) + " | " +
440
441 "CurrentAltAmmo = " + String.valueOf(getCurrentAltAmmo()
442 ) + " | " +
443
444 "Amount = " + String.valueOf(getAmount()
445 ) + " | " +
446
447 "]";
448 }
449
450
451 public String toHtmlString() {
452 return super.toString() + "[<br/>" +
453
454 "<b>Id</b> = " + String.valueOf(getId()
455 ) + " <br/> " +
456
457 "<b>CurrentAmmo</b> = " + String.valueOf(getCurrentAmmo()
458 ) + " <br/> " +
459
460 "<b>CurrentAltAmmo</b> = " + String.valueOf(getCurrentAltAmmo()
461 ) + " <br/> " +
462
463 "<b>Amount</b> = " + String.valueOf(getAmount()
464 ) + " <br/> " +
465
466 "<br/>]";
467 }
468
469
470
471
472
473
474
475
476
477
478 }
479
480
481
482
483
484
485
486
487
488
489
490
491
492 public class MyInventoryStaticMessage
493 extends
494 MyInventoryStatic
495 {
496
497 @Override
498 public
499 MyInventoryStaticMessage clone() {
500 return this;
501 }
502
503
504
505
506
507
508 public UnrealId getId()
509 {
510 return Id;
511 }
512
513
514
515
516
517
518 public ItemType getType()
519 {
520 return Type;
521 }
522
523
524
525
526
527
528 public ItemDescriptor getDescriptor()
529 {
530 return Descriptor;
531 }
532
533
534 @Override
535 public boolean isDifferentFrom(IStaticWorldObject other)
536 {
537 if (other == null)
538 {
539 return true;
540 }
541 else if (other == this)
542 {
543 return false;
544 }
545 else
546 {
547 MyInventoryStatic obj = (MyInventoryStatic) other;
548
549
550 if ( !(
551 AdvancedEquals.equalsOrNull(this.getId()
552 , obj.getId()
553 )
554 ) )
555 {
556 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Id on object class MyInventoryStatic");
557 return true;
558 }
559
560 if ( !(
561 AdvancedEquals.equalsOrNull(this.getType()
562 , obj.getType()
563 )
564 ) )
565 {
566 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Type on object class MyInventoryStatic");
567 return true;
568 }
569
570 if ( !(
571 AdvancedEquals.equalsOrNull(this.getDescriptor()
572 , obj.getDescriptor()
573 )
574 ) )
575 {
576 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Descriptor on object class MyInventoryStatic");
577 return true;
578 }
579
580 }
581 return false;
582 }
583
584
585 public String toString() {
586 return
587 super.toString() + "[" +
588
589 "Id = " + String.valueOf(getId()
590 ) + " | " +
591
592 "Type = " + String.valueOf(getType()
593 ) + " | " +
594
595 "]";
596 }
597
598
599 public String toHtmlString() {
600 return super.toString() + "[<br/>" +
601
602 "<b>Id</b> = " + String.valueOf(getId()
603 ) + " <br/> " +
604
605 "<b>Type</b> = " + String.valueOf(getType()
606 ) + " <br/> " +
607
608 "<br/>]";
609 }
610
611
612
613
614
615
616
617
618
619
620 }
621
622
623
624
625
626
627
628
629
630
631
632
633
634 public class MyInventorySharedMessage
635 extends
636 MyInventoryShared
637 {
638
639
640
641 public MyInventorySharedMessage()
642 {
643
644 }
645
646 @Override
647 public
648 MyInventorySharedMessage clone() {
649 return this;
650 }
651
652
653
654
655 protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
656 0
657 );
658
659 @Override
660 public ISharedProperty getProperty(PropertyId id) {
661 return propertyMap.get(id);
662 }
663
664 @Override
665 public Map<PropertyId, ISharedProperty> getProperties() {
666 return propertyMap;
667 }
668
669
670
671
672
673
674
675
676 public UnrealId getId()
677 {
678 return Id;
679 }
680
681
682 public String toString() {
683 return
684 super.toString() + "[" +
685
686 "Id = " + String.valueOf(getId()
687 ) + " | " +
688
689 "]";
690 }
691
692
693 public String toHtmlString() {
694 return super.toString() + "[<br/>" +
695
696 "<b>Id</b> = " + String.valueOf(getId()
697 ) + " <br/> " +
698
699 "<br/>]";
700 }
701
702
703
704
705
706
707
708
709
710
711 }
712
713
714
715
716 @Override
717 public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject object) {
718 if (object == null)
719 {
720 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.CREATED, this);
721 }
722 if (!( object instanceof MyInventoryMessage) ) {
723 throw new PogamutException("Can't update different class than MyInventoryMessage, got class " + object.getClass().getSimpleName() + "!", this);
724 }
725 MyInventoryMessage toUpdate = (MyInventoryMessage)object;
726
727 boolean updated = false;
728
729
730
731 if (toUpdate.CurrentAmmo != getCurrentAmmo()
732 ) {
733 toUpdate.CurrentAmmo=getCurrentAmmo()
734 ;
735 updated = true;
736 }
737
738 if (toUpdate.CurrentAltAmmo != getCurrentAltAmmo()
739 ) {
740 toUpdate.CurrentAltAmmo=getCurrentAltAmmo()
741 ;
742 updated = true;
743 }
744
745 if (toUpdate.Amount != getAmount()
746 ) {
747 toUpdate.Amount=getAmount()
748 ;
749 updated = true;
750 }
751
752
753
754
755
756
757 toUpdate.SimTime = SimTime;
758
759 if (updated) {
760 return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
761 } else {
762 return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.SAME, toUpdate);
763 }
764 }
765
766 @Override
767 public ILocalWorldObjectUpdatedEvent getLocalEvent() {
768 return new MyInventoryLocalImpl.MyInventoryLocalUpdate
769 (this.getLocal(), SimTime);
770 }
771
772 @Override
773 public ISharedWorldObjectUpdatedEvent getSharedEvent() {
774 return new MyInventorySharedImpl.MyInventorySharedUpdate
775 (this.getShared(), SimTime, this.getTeamId());
776 }
777
778 @Override
779 public IStaticWorldObjectUpdatedEvent getStaticEvent() {
780 return new MyInventoryStaticImpl.MyInventoryStaticUpdate
781 (this.getStatic(), SimTime);
782 }
783
784
785 public String toString() {
786 return
787 super.toString() + "[" +
788
789 "Id = " + String.valueOf(getId()
790 ) + " | " +
791
792 "CurrentAmmo = " + String.valueOf(getCurrentAmmo()
793 ) + " | " +
794
795 "CurrentAltAmmo = " + String.valueOf(getCurrentAltAmmo()
796 ) + " | " +
797
798 "Amount = " + String.valueOf(getAmount()
799 ) + " | " +
800
801 "Type = " + String.valueOf(getType()
802 ) + " | " +
803
804 "]";
805 }
806
807
808 public String toHtmlString() {
809 return super.toString() + "[<br/>" +
810
811 "<b>Id</b> = " + String.valueOf(getId()
812 ) + " <br/> " +
813
814 "<b>CurrentAmmo</b> = " + String.valueOf(getCurrentAmmo()
815 ) + " <br/> " +
816
817 "<b>CurrentAltAmmo</b> = " + String.valueOf(getCurrentAltAmmo()
818 ) + " <br/> " +
819
820 "<b>Amount</b> = " + String.valueOf(getAmount()
821 ) + " <br/> " +
822
823 "<b>Type</b> = " + String.valueOf(getType()
824 ) + " <br/> " +
825
826 "<br/>]";
827 }
828
829
830
831
832
833
834
835
836
837
838 }
839