View Javadoc

1   
2               /**
3               IMPORTANT !!!
4   
5               DO NOT EDIT THIS FILE. IT IS GENERATED FROM approriate xml file in xmlresources/gbinfomessages BY
6               THE JavaClassesGenerator.xslt. MODIFY THESE FILES INSTEAD OF THIS ONE.
7   
8               IMPORTANT END !!!
9               */
10              package
11              cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages;
12  	    		import java.util.*;
13      import javax.vecmath.*;
14      import cz.cuni.amis.pogamut.base.communication.messages.*;
15      import cz.cuni.amis.pogamut.base.communication.worldview.*;
16      import cz.cuni.amis.pogamut.base.communication.worldview.event.*;
17      import cz.cuni.amis.pogamut.base.communication.worldview.object.*;
18      import cz.cuni.amis.pogamut.base.communication.translator.event.*;
19      import cz.cuni.amis.pogamut.base3d.worldview.object.*;
20      import cz.cuni.amis.pogamut.base3d.worldview.object.event.*;
21      import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
22      import cz.cuni.amis.pogamut.udk.communication.messages.*;
23      import cz.cuni.amis.pogamut.udk.communication.worldview.objects.*;
24      import cz.cuni.amis.pogamut.udk.communication.translator.itemdescriptor.*;
25      import cz.cuni.amis.pogamut.udk.communication.messages.ItemType.Category;
26      import cz.cuni.amis.utils.exception.*;
27      import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result;
28      import cz.cuni.amis.utils.SafeEquals;
29      import cz.cuni.amis.pogamut.multi.communication.worldview.object.*;
30      
31              
32              /**
33                
34  		An object in the observed player's inventory.
35      
36                            Corresponding GameBots message is
37                            MYINV.
38                        
39               */
40              
41              public class
42              MyInventory
43                      extends GBObjectUpdate
44                  
45  	            	implements IGBWorldObjectEvent, IWorldObject
46  
47              {
48              
49              /**
50                Creates new instance of command MyInventory.
51                
52  		An object in the observed player's inventory.
53      Corresponding GameBots message for this command is
54                .
55                    @param Id 
56  			Unique Id of the item. This Id represents the item in the inventory.
57  		
58                    @param CurrentAmmo 
59  			If this item is a weapon, this holds the amount of primary ammo.
60  		
61                    @param CurrentAltAmmo 
62  			If this item is a weapon, this holds the amount of secondary ammo.
63  		
64                    @param Amount 
65  			If this item is ammo or armor, this holds the amount of the item the player has.
66  		
67                    @param Type 
68  			Class of the item (e.g. LinkGun.WeaponPickup).
69  		
70                    @param Descriptor 
71  			Descriptor of the item - according the ItemType you may cast this to various XYZDescriptor.
72  		
73                */
74               public MyInventory(
75                  UnrealId Id,  int CurrentAmmo,  int CurrentAltAmmo,  int Amount,  ItemType Type,  ItemDescriptor Descriptor) {
76                      
77                      this.Id = Id;
78                  
79                      this.CurrentAmmo = CurrentAmmo;
80                  
81                      this.CurrentAltAmmo = CurrentAltAmmo;
82                  
83                      this.Amount = Amount;
84                  
85                      this.Type = Type;
86                  
87                      this.Descriptor = Descriptor;
88                  
89                  }
90  
91              
92      	/** Example how the message looks like - used during parser tests. */
93      	public static final String PROTOTYPE =
94      		"MYINV {Id unreal_id} {CurrentAmmo 0} {CurrentAltAmmo 0} {Amount 0} {Type xWeapons.FlakCannonPickup}";
95      
96  
97              /////// Properties BEGIN
98              
99          /**
100         
101 			Unique Id of the item. This Id represents the item in the inventory.
102 		 */
103         protected
104          UnrealId Id =
105         	null;
106 
107         
108         /**
109         
110 			Unique Id of the item. This Id represents the item in the inventory.
111 		 */
112         public
113         UnrealId getId() {
114             return
115          Id;
116         }
117         
118 
119         
120         /**
121         
122 			If this item is a weapon, this holds the amount of primary ammo.
123 		 */
124         protected
125          int CurrentAmmo =
126         	0;
127 
128         
129         /**
130         
131 			If this item is a weapon, this holds the amount of primary ammo.
132 		 */
133         public
134         int getCurrentAmmo() {
135             return
136          CurrentAmmo;
137         }
138         
139 
140         
141         /**
142         
143 			If this item is a weapon, this holds the amount of secondary ammo.
144 		 */
145         protected
146          int CurrentAltAmmo =
147         	0;
148 
149         
150         /**
151         
152 			If this item is a weapon, this holds the amount of secondary ammo.
153 		 */
154         public
155         int getCurrentAltAmmo() {
156             return
157          CurrentAltAmmo;
158         }
159         
160 
161         
162         /**
163         
164 			If this item is ammo or armor, this holds the amount of the item the player has.
165 		 */
166         protected
167          int Amount =
168         	0;
169 
170         
171         /**
172         
173 			If this item is ammo or armor, this holds the amount of the item the player has.
174 		 */
175         public
176         int getAmount() {
177             return
178          Amount;
179         }
180         
181 
182         
183         /**
184         
185 			Class of the item (e.g. LinkGun.WeaponPickup).
186 		 */
187         protected
188          ItemType Type =
189         	null;
190 
191         
192         /**
193         
194 			Class of the item (e.g. LinkGun.WeaponPickup).
195 		 */
196         public
197         ItemType getType() {
198             return
199          Type;
200         }
201         
202 
203         
204         /**
205         
206 			Descriptor of the item - according the ItemType you may cast this to various XYZDescriptor.
207 		 */
208         protected
209          ItemDescriptor Descriptor =
210         	null;
211 
212         
213         /**
214         
215 			Descriptor of the item - according the ItemType you may cast this to various XYZDescriptor.
216 		 */
217         public
218         ItemDescriptor getDescriptor() {
219             return
220          Descriptor;
221         }
222         
223 
224         
225             /////// Properties END
226 
227             /////// Extra Java code BEGIN
228 
229             	/////// Additional code from xslt BEGIN
230             		
231        							protected double Time = 0;
232 
233        							protected double getTime() {
234        								return Time;
235        							}
236 
237        							protected void setTime(double time) {
238        								this.Time = time;
239        							}
240 
241        							public double getLastSeenTime() {
242        								return Time;
243        							}
244        						
245        					
246        					public ILocalWorldObject getLocal() {
247        						return null;
248        					}
249        					
250        					public ISharedWorldObject getShared() {
251        						return null;
252        					}
253        					
254        					public IStaticWorldObject getStatic() {
255        						return null;
256        					}
257        					
258        					@Override
259        					public long getSimTime() {
260        						return (long)getLastSeenTime();
261        					}
262 
263        					public boolean equals(Object obj) {
264 	                      if (!(obj instanceof MyInventory)) return false;
265 	                      MyInventory cast = (MyInventory)obj;
266 	                      if (this.getId() != null) return this.getId().equals(cast.getId());
267 	                      else return cast.getId() == null;
268 	                    }
269 
270 	                    public int hashCode() {
271 	                      if (getId() != null) return getId().hashCode();
272 	                      return 0;
273 	                    }
274 
275             		
276 
277 
278             	/////// Additional code from xslt END
279 
280 	            /////// Extra Java from XML BEGIN
281             		
282             	/////// Extra Java from XML END
283 
284             /////// Extra Java code END
285 
286             
287 
288             /**
289               * Cloning constructor.
290               */
291              public MyInventory(MyInventory original) {
292                 
293                      this.Id=original.Id;
294                 
295                      this.CurrentAmmo=original.CurrentAmmo;
296                 
297                      this.CurrentAltAmmo=original.CurrentAltAmmo;
298                 
299                      this.Amount=original.Amount;
300                 
301                      this.Type=original.Type;
302                 
303                      this.Descriptor=original.Descriptor;
304                 
305              }
306 
307              
308                  /**
309                   * Used by Yylex to create empty message then to fill it's protected fields (Yylex is in the same package).
310                   */
311 	             public MyInventory() {
312 	             }
313              
314 
315 	    		/**
316 	    		 * Here we save the original object for which this object is an update.
317 	    		 */
318 	    		private IWorldObject orig = null;
319 
320 	            public IWorldObjectUpdateResult update(IWorldObject obj) {
321 		            if(obj == null) {
322 		               orig = this;
323 		               return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.CREATED, this);
324 		            }
325 		            orig = obj;
326 		            // typecast
327 		            MyInventory  o = (MyInventory)obj;
328 
329 		            boolean updated = false;
330 
331 		            
332 								o.Time = Time;
333 							
334 
335 		            if (updated) {
336 		                return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, o);
337 		            } else {
338 		            	return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, o);
339 		            }
340 		        }
341 
342 	            /**
343 	             * Returns original object (if method update() has already been called, for bot-programmer that is always true
344 	             * as the original object is updated and then the event is propagated).
345 	             */
346 		        public IWorldObject getObject() {
347 		            if (orig == null) return this;
348 		            return orig;
349 		        }
350 	        
351 
352                  
353             public String toString() {
354                 return
355                 
356                 		super.toString() + " | " +
357                 		
358 				               "Id = " +
359 				               String.valueOf(Id) + " | " +
360 				            
361 				               "CurrentAmmo = " +
362 				               String.valueOf(CurrentAmmo) + " | " +
363 				            
364 				               "CurrentAltAmmo = " +
365 				               String.valueOf(CurrentAltAmmo) + " | " +
366 				            
367 				               "Amount = " +
368 				               String.valueOf(Amount) + " | " +
369 				            
370 				               "Type = " +
371 				               String.valueOf(Type) + " | " +
372 				             "";
373                 	
374              }
375 
376              public String toHtmlString() {
377                 return super.toString() +
378             
379             "<b>Id</b> : " +
380             String.valueOf(Id) +
381             " <br/> " +
382             
383             "<b>CurrentAmmo</b> : " +
384             String.valueOf(CurrentAmmo) +
385             " <br/> " +
386             
387             "<b>CurrentAltAmmo</b> : " +
388             String.valueOf(CurrentAltAmmo) +
389             " <br/> " +
390             
391             "<b>Amount</b> : " +
392             String.valueOf(Amount) +
393             " <br/> " +
394             
395             "<b>Type</b> : " +
396             String.valueOf(Type) +
397             " <br/> " +
398             
399             "<b>Descriptor</b> : " +
400             String.valueOf(Descriptor) +
401             " <br/> " +
402              "";
403              }
404 
405              
406              
407              }
408 
409