View Javadoc

1   package cz.cuni.amis.pogamut.emohawk.agent.module.sensomotoric;
2   
3   
4   import cz.cuni.amis.pogamut.base.agent.module.SensomotoricModule;
5   import cz.cuni.amis.pogamut.base.communication.worldview.event.IWorldEventListener;
6   import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
7   
8   import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
9   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.GiveItem;
10  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Pick;
11  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.PutDownItem;
12  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GiveItemResult;
13  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
14  
15  
16  /**
17   * Module helping us handle items in UnrealEngine2Runtime.
18   * @author knight
19   */
20  public class Inventory extends SensomotoricModule<UT2004Bot> {
21      
22      GiveItemResult lastGiveItemResult = null;
23  
24      /**
25       * Listener for responses for giveItem command.
26       */
27      IWorldEventListener<GiveItemResult> giveItemResultListener = new IWorldEventListener<GiveItemResult>() {
28          @Override
29          public void notify(GiveItemResult event) {
30              lastGiveItemResult = event;
31          }    
32      };
33  
34      /**
35       * Returns last result of give item command.
36       * @return
37       */
38      public GiveItemResult getLastGiveItemResult() {
39          return lastGiveItemResult;
40      }
41  
42      /**
43       * Gives item to input bot. Bot has to within reach (200 ut units ~ 200 cm)!
44       * @param pl
45       * @param item
46       */
47      public void giveItem(Player pl, ItemTypeUE2 item) {
48          act.act(new GiveItem().setId(pl.getId()).setType(item.getUnrealName()));
49      }
50  
51      /**
52       * Gives item to input bot. Bot has to within reach (200 ut units ~ 200 cm)!
53       * @param id
54       * @param item
55       */
56      public void giveItem(UnrealId id, ItemTypeUE2 item) {
57          act.act(new GiveItem().setId(id).setType(item.getUnrealName()));
58      }
59      
60      /**
61       * Puts item down at the location of the bot.
62       * @param item
63       */
64      public void putDownItem(ItemTypeUE2 item) {
65          act.act(new PutDownItem().setType(item.getUnrealName()));
66      }
67  
68      /**
69       * Picks item at the location of the bot - bot has to be touching the item.
70       * @param id
71       */
72      public void pickItem(UnrealId id) {
73          act.act(new Pick().setId(id));
74      }
75  
76      /**
77       * Default constructor.
78       * @param agent
79       */
80      public Inventory(UT2004Bot agent) {
81          super(agent);
82          agent.getWorldView().addEventListener(GiveItemResult.class, giveItemResultListener);
83      }
84  }