View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.communication.translator.bot.state;
2   
3   import cz.cuni.amis.fsm.FSMState;
4   import cz.cuni.amis.fsm.FSMTransition;
5   import cz.cuni.amis.fsm.IFSMState;
6   import cz.cuni.amis.pogamut.base.communication.messages.InfoMessage;
7   import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldChangeEvent;
8   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
9   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerListEnd;
10  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerListStart;
11  import cz.cuni.amis.pogamut.ut2004.communication.translator.TranslatorContext;
12  import cz.cuni.amis.pogamut.ut2004.communication.translator.bot.support.BotListState;
13  import cz.cuni.amis.pogamut.ut2004.communication.translator.shared.events.InitCommandRequest;
14  import cz.cuni.amis.pogamut.ut2004.communication.translator.shared.events.PlayerListObtained;
15  
16  /**
17   * Takes care of the player list. It stores them inside a List object and when END message comes it sends
18   * them to the world view via PlayerListObtained event.
19   * <p><p>
20   * Last state of the handshake - we switch from this state to the ConfigureMessageExpectedState. 
21   * 
22   * @author Jimmy
23   */
24  @FSMState(map={@FSMTransition(
25  					state=HandshakeControllerState.class, 
26  					symbol={PlayerListEnd.class},
27  					transition={})}
28  )
29  public class PlayerListState extends BotListState<Player, TranslatorContext> {
30  
31  	public PlayerListState() {
32  		super(PlayerListStart.class, Player.class, PlayerListEnd.class);
33  	}
34  	
35  	@Override
36  	public void stateLeaving(TranslatorContext context,
37  			IFSMState<InfoMessage, TranslatorContext> toState, InfoMessage symbol) {
38  		super.stateLeaving(context, toState, symbol);
39  		long simTime = 
40  			(symbol instanceof IWorldChangeEvent ? ((IWorldChangeEvent)symbol).getSimTime() : 0);
41  		context.getEventQueue().pushEvent(new PlayerListObtained(getList(), simTime));
42  		newList();
43  	}
44  	
45  	@Override
46  	public void stateSymbol(TranslatorContext context, InfoMessage symbol) {
47  		super.stateSymbol(context, symbol);
48  		context.getEventQueue().pushEvent((Player)symbol);
49  	}
50  
51  }