View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages;
2    		
3    		// --- IMPORTS FROM /messages/settings/javasettings/javaimport BEGIN
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   		// --- IMPORTS FROM /messages/settings/javasettings/javaimport END
6   		
7   		
8   		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name='all'] BEGIN
9   				
10  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name='all'] END
11  		
12  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=local]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=local]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the local part of the GameBots2004 message MYINV.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		An object in the observed player's inventory.
25      
26           */
27   	public class MyInventoryLocalImpl 
28    						extends
29    						MyInventoryLocal
30  	    {
31   	
32      	
33      	
34      	/**
35      	 * Parameter-less contructor for the message.
36      	 */
37  		public MyInventoryLocalImpl()
38  		{
39  		}
40  	
41      	
42      	
43      	
44      	/**
45  		 * Creates new instance of the message MyInventory.
46  		 * 
47  		An object in the observed player's inventory.
48      
49  		 * Corresponding GameBots message
50  		 *   (local part)
51  		 *   is
52  		 *   MYINV.
53  		 * 
54   	  	 * 
55  		 *   
56  		 *     @param Id 
57  			Unique Id of the item. This Id represents the item in the inventory.
58  		
59  		 *   
60  		 * 
61  		 *   
62  		 *     @param CurrentAmmo 
63  			If this item is a weapon, this holds the amount of primary ammo.
64  		
65  		 *   
66  		 * 
67  		 *   
68  		 *     @param CurrentAltAmmo 
69  			If this item is a weapon, this holds the amount of secondary ammo.
70  		
71  		 *   
72  		 * 
73  		 *   
74  		 *     @param Amount 
75  			If this item is ammo or armor, this holds the amount of the item the player has.
76  		
77  		 *   
78  		 * 
79  		 *   
80  		 * 
81  		 *   
82  		 * 
83  		 */
84  		public MyInventoryLocalImpl(
85  			UnrealId Id,  int CurrentAmmo,  int CurrentAltAmmo,  int Amount
86  		) {
87  			
88  					this.Id = Id;
89  				
90  					this.CurrentAmmo = CurrentAmmo;
91  				
92  					this.CurrentAltAmmo = CurrentAltAmmo;
93  				
94  					this.Amount = Amount;
95  				
96  		}
97      
98      	/**
99  		 * Cloning constructor from the full message.
100 		 *
101 		 * @param original
102 		 */
103 		public MyInventoryLocalImpl(MyInventory original) {		
104 			
105 					this.Id = original.getId()
106  	;
107 				
108 					this.CurrentAmmo = original.getCurrentAmmo()
109  	;
110 				
111 					this.CurrentAltAmmo = original.getCurrentAltAmmo()
112  	;
113 				
114 					this.Amount = original.getAmount()
115  	;
116 				
117 			this.SimTime = original.getSimTime();			
118 		}
119 		
120 		/**
121 		 * Cloning constructor from the full message.
122 		 *
123 		 * @param original
124 		 */
125 		public MyInventoryLocalImpl(MyInventoryLocalImpl original) {		
126 			
127 					this.Id = original.getId()
128  	;
129 				
130 					this.CurrentAmmo = original.getCurrentAmmo()
131  	;
132 				
133 					this.CurrentAltAmmo = original.getCurrentAltAmmo()
134  	;
135 				
136 					this.Amount = original.getAmount()
137  	;
138 				
139 			this.SimTime = original.getSimTime();
140 		}
141 		
142 			/**
143 			 * Cloning constructor from the message part.
144 			 *
145 			 * @param original
146 			 */
147 			public MyInventoryLocalImpl(MyInventoryLocal original) {
148 				
149 						this.Id = original.getId()
150  	;
151 					
152 						this.CurrentAmmo = original.getCurrentAmmo()
153  	;
154 					
155 						this.CurrentAltAmmo = original.getCurrentAltAmmo()
156  	;
157 					
158 						this.Amount = original.getAmount()
159  	;
160 					
161 			}
162 		
163    				
164    				@Override
165    				public void setSimTime(long SimTime) {
166 					super.setSimTime(SimTime);
167 				}
168    			
169 	    				@Override
170 	    				public 
171 	    				MyInventoryLocalImpl clone() {
172 	    					return new 
173 	    					MyInventoryLocalImpl(this);
174 	    				}
175 	    				
176 	    				
177     	
178 	    /**
179          * 
180 			Unique Id of the item. This Id represents the item in the inventory.
181 		 
182          */
183         protected
184          UnrealId Id =
185        	null;
186 	
187  		/**
188          * 
189 			Unique Id of the item. This Id represents the item in the inventory.
190 		 
191          */
192         public  UnrealId getId()
193  	 {
194 				    					return Id;
195 				    				}
196 				    			
197     	
198 	    /**
199          * 
200 			If this item is a weapon, this holds the amount of primary ammo.
201 		 
202          */
203         protected
204          int CurrentAmmo =
205        	0;
206 	
207  		/**
208          * 
209 			If this item is a weapon, this holds the amount of primary ammo.
210 		 
211          */
212         public  int getCurrentAmmo()
213  	 {
214 				    					return CurrentAmmo;
215 				    				}
216 				    			
217     	
218 	    /**
219          * 
220 			If this item is a weapon, this holds the amount of secondary ammo.
221 		 
222          */
223         protected
224          int CurrentAltAmmo =
225        	0;
226 	
227  		/**
228          * 
229 			If this item is a weapon, this holds the amount of secondary ammo.
230 		 
231          */
232         public  int getCurrentAltAmmo()
233  	 {
234 				    					return CurrentAltAmmo;
235 				    				}
236 				    			
237     	
238 	    /**
239          * 
240 			If this item is ammo or armor, this holds the amount of the item the player has.
241 		 
242          */
243         protected
244          int Amount =
245        	0;
246 	
247  		/**
248          * 
249 			If this item is ammo or armor, this holds the amount of the item the player has.
250 		 
251          */
252         public  int getAmount()
253  	 {
254 				    					return Amount;
255 				    				}
256 				    			
257     	
258     	
259     	
260     	
261     	public MyInventoryLocalImpl getLocal() {
262 			return this;
263     	}
264 		public ISharedWorldObject getShared() {
265 		 	throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
266 		}
267 		public IStaticWorldObject getStatic() {
268 		    throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
269 		}
270  	
271 		public static class MyInventoryLocalUpdate
272      implements ILocalWorldObjectUpdatedEvent, IGBWorldObjectEvent
273 		{
274 			protected long time;
275 			
276 			protected MyInventoryLocal data = null; //contains object data for this update
277 			
278 			public MyInventoryLocalUpdate
279     (MyInventoryLocal moverLocal, long time)
280 			{
281 				this.data = moverLocal;
282 				this.time = time;
283 			}
284 			
285 			@Override
286 			public IWorldObjectUpdateResult<ILocalWorldObject> update(
287 					ILocalWorldObject object) 
288 			{
289 				if ( object == null)
290 				{
291 					data = new MyInventoryLocalImpl(data); //we always return Impl object
292 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
293 				}
294 				if ( object instanceof MyInventoryLocalImpl )
295 				{
296 					MyInventoryLocalImpl toUpdate = (MyInventoryLocalImpl)object;
297 					
298 					boolean updated = false;
299 					
300 					// UPDATING LOCAL PROPERTIES
301 					
302 				if (toUpdate.CurrentAmmo != data.getCurrentAmmo()
303  	) {
304 				    toUpdate.CurrentAmmo=data.getCurrentAmmo()
305  	;
306 					updated = true;
307 				}
308 			
309 				if (toUpdate.CurrentAltAmmo != data.getCurrentAltAmmo()
310  	) {
311 				    toUpdate.CurrentAltAmmo=data.getCurrentAltAmmo()
312  	;
313 					updated = true;
314 				}
315 			
316 				if (toUpdate.Amount != data.getAmount()
317  	) {
318 				    toUpdate.Amount=data.getAmount()
319  	;
320 					updated = true;
321 				}
322 			
323 					
324 					data = toUpdate; //the updating has finished
325 					
326 					if ( updated )
327 					{
328 						toUpdate.SimTime = this.time;
329 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, data);
330 					}
331 					
332 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
333 				}
334 				throw new PogamutException("Unsupported object type for update. Expected MyInventoryLocalImpl for object " + object.getId() +", not object of class " + object.getClass().getSimpleName() + ".", this);
335 			}
336 	
337 			/**
338 			 * Simulation time in MILLI SECONDS !!!
339 			 */
340 			@Override
341 			public long getSimTime() {
342 				return this.time;
343 			}
344 	
345 			@Override
346 			public IWorldObject getObject() {
347 				return data;
348 			}
349 	
350 			@Override
351 			public WorldObjectId getId() {
352 				return data.getId();
353 			}
354 			
355 		}	
356  	
357  		
358  	    public String toString() {
359             return
360             	super.toString() + "[" +
361             	
362 		              			"Id = " + String.valueOf(getId()
363  	) + " | " + 
364 		              		
365 		              			"CurrentAmmo = " + String.valueOf(getCurrentAmmo()
366  	) + " | " + 
367 		              		
368 		              			"CurrentAltAmmo = " + String.valueOf(getCurrentAltAmmo()
369  	) + " | " + 
370 		              		
371 		              			"Amount = " + String.valueOf(getAmount()
372  	) + " | " + 
373 		              		
374 				"]";           		
375         }
376  	
377  		
378  		public String toHtmlString() {
379  			return super.toString() + "[<br/>" +
380             	
381 		              			"<b>Id</b> = " + String.valueOf(getId()
382  	) + " <br/> " + 
383 		              		
384 		              			"<b>CurrentAmmo</b> = " + String.valueOf(getCurrentAmmo()
385  	) + " <br/> " + 
386 		              		
387 		              			"<b>CurrentAltAmmo</b> = " + String.valueOf(getCurrentAltAmmo()
388  	) + " <br/> " + 
389 		              		
390 		              			"<b>Amount</b> = " + String.valueOf(getAmount()
391  	) + " <br/> " + 
392 		              		
393 				"<br/>]";     
394 		}
395  	
396  		
397  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
398         	
399 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
400 		
401 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---
402 	        
403 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---        	            	
404  	
405 		}
406