@SuppressWarnings("unchecked") @Override public boolean handleMessage(Telegram msg) { if (msg.message == MessageType.YOU_ARE_DISMANTLED.ordinal()) { kill(); Vector3 p = Game.instance.activeIsland.pos; ItemDrop i = new ItemDrop(Island.SIZE / 2 - 5, Island.SIZE / 4 * 3 + p.y + 1, Island.SIZE / 2, Item.get("YELLOW_CRYSTAL"), 1); island.addEntity(i, false, false); return true; } if (msg.message == MessageType.STRUCTURE_BROADCAST_HANDLED.ordinal()) { requestedHumanStates.removeValue((State<Human>) msg.extraInfo, true); } return false; }
public <T extends State> GameEntity changeState(T state){ if(fsmC == null) fsmC = Mappers.fsm.get(this.entity); if(fsmC != null && fsmC.stateMachine.getCurrentState() != state){ fsmC.stateMachine.changeState(state); } return this; }
public Structure(float x, float y, float z, String model) { super(Math.round(x), Math.round(y), Math.round(z), model); nodes = new Array<StructureNode>(); workers = new Array<Human>(); int width = (int) Math.ceil(boundingBox.getDimensions().x); int depth = (int) Math.ceil(boundingBox.getDimensions().z); nodes.add(new StructureNode(NodeType.target, -1, 0, Math.round(depth / 2))); nodes.add(new StructureNode(NodeType.target, width, 0, Math.round(depth / 2))); nodes.add(new StructureNode(NodeType.target, Math.round(width / 2), 0, -1)); nodes.add(new StructureNode(NodeType.target, Math.round(width / 2), 0, depth)); nodes.add(new StructureNode(NodeType.build, 0, 0, Math.round(depth / 2))); nodes.add(new StructureNode(NodeType.build, width - 1, 0, Math.round(depth / 2))); nodes.add(new StructureNode(NodeType.build, Math.round(width / 2), 0, 0)); nodes.add(new StructureNode(NodeType.build, Math.round(width / 2), 0, depth - 1)); inventory = new Inventory(); buildInventory = new NonStackingInventory(256 /* That should be enough... */); costs = new ResourceList(); requestedHumanStates = new Array<State<Human>>(); handledHumanStates = new Array<State<Human>>(); tasks = new Array<Task>(); taskQueue = new Array<Task>(); working = true; dimensions.x++; dimensions.z++; setBuilt(false); }
public void broadcast(float delay, State<Human> requestedState, Object... params) { Array<Object> array = new Array<Object>(params); array.insert(0, this); if (!requestedHumanStates.contains(requestedState, true)) requestedHumanStates.add(requestedState); MessageDispatcher.getInstance().dispatchMessage(delay, this, null, MessageType.STRUCTURE_BROADCAST.ordinal(), new BroadcastPayload(requestedState, array.items)); }
public void changeState(State<Human> newState, Object... params) { previousStateParams.clear(); previousStateParams.addAll(stateParams); stateParams.clear(); stateParams.addAll(params); stateMachine.changeState(newState); }
public Entity(final GraphicsProcessor graphics, final PhysicsProcessor physics, final AudioProcessor audio, final State<Entity> initialState) { this.graphics = graphics; this.physics = physics; this.audio = audio; stateMachine = new DefaultStateMachine<Entity>(this, initialState); }
public State getCurrentState(){ if(fsmC == null) fsmC = Mappers.fsm.get(this.entity); return fsmC == null? null : fsmC.stateMachine.getCurrentState(); }
public void changeState (State<GameEntity> state) { stateMachine.changeState(state); }
private Tatics(State<Entity> entryState){ this.entryState = entryState; }
public void changeState (State<Entity> state) { stateMachine.changeState(state); }
public State<Human> getWorkerState() { return workerState; }
public void broadcast(State<Human> requestedState, Object... params) { broadcast(0, requestedState, params); }
public State<Human> getState() { return stateMachine.getCurrentState(); }
public SyncedStateMachine(E owner, State<E> initialState) { super(owner, initialState); }
public SyncedStateMachine(E owner, State<E> initialState, State<E> globalState) { super(owner, initialState, globalState); }
@Override public void changeState(State<E> newState) { newStateEntered = false; super.changeState(newState); newStateEntered = true; }
public BroadcastPayload(State<Human> state, Object... params) { this.state = state; this.params = params; }
/** * Sets a new {@link State} for this {@link Entity} to be performed in the next execution step * for this character. * * @see StateMachine#changeState(State) * * @param newState * The state to make the transition to. Each {@link Entity} may define its own. * */ public void changeState(final State<Entity> newState) { stateMachine.changeState(newState); }
/** * Whether this entity is performing the given state or not. * * @see StateMachine#isInState(State) * @param state * The state to test against the current actions of the entity. * @return true if this entity is executing the state; false, otherwise. */ public boolean isInState(final State<Entity> state) { return state != null && stateMachine.isInState(state); }
/** * Returns the current state of this {@link Entity}. * * @see StateMachine#getCurrentState() * @return The {@link State} this entity is currently in. */ public State<Entity> getCurrentState() { return stateMachine.getCurrentState(); }