Example #1
0
  @Override
  public synchronized PlayerState process(Transition action) {
    int clientID = allowedSecret(action.secret);
    if (clientID == -1) {
      return null;
    }

    Integer playerID = state.getPlayerIds().get(clientID);
    PlayerState player = state.playerStates.get(playerID);

    if (action.operator == ActionType.PlayerReady) {
      TransitionResult res = new TransitionResult(action.id);
      res.errorType = TransitionResult.TransitionError.NoError;
      player.response = res;

      printToGuiLog(player, action);
      return player;
    }

    if (!allowedPlayer(clientID)) {
      return null;
    }

    if (player.round.currentRound < state.round.currentRound) {
      player.round.currentRound = state.round.currentRound;
      player.round.startTime =
          GamePolicy.connectWaitTime
              + state.round.currentRound * GamePolicy.roundTime
              + clientID * GamePolicy.playerActionTime;
    }

    player.response = actionEngine.process(player, action);

    if (player.response.valid()) {
      logger.info("[srv]Executed action [" + action.operator.name() + "] for client: " + clientID);
    } else {
      logger.info("[srv]Failed action [" + action.operator.name() + "] for client: " + clientID);
    }

    // update the view of the player's own units after the execution of an action
    actionEngine.updatePlayerSight(state, playerID);

    // update the view of the player's own towers after the execution of an action
    actionEngine.updateTowerSight(state, playerID);

    return player;
  }