Пример #1
0
  /**
   * Updates the CatanModel to reflect the acceptance by a player of a trade
   *
   * @return CatanModel, return the updated Catan model
   */
  @Override
  public Object execute() {
    CatanModel cm = null;
    try {
      cm = facade.getGameModel(authToken);

      if (((AcceptTradeJSON) body).isWillAccept()) {
        cm.resourceManager.acceptPlayerTrade(((AcceptTradeJSON) body).getPlayerIndex());
        cm.chatManager.logAction(
            cm.playerManager.getPlayerName(((AcceptTradeJSON) body).getPlayerIndex())
                + " accepted a trade.",
            cm.playerManager.getPlayerName(((AcceptTradeJSON) body).getPlayerIndex()));
      } else {
        cm.resourceManager.declineTrade(((AcceptTradeJSON) body).getPlayerIndex());
        cm.chatManager.logAction(
            cm.playerManager.getPlayerName(((AcceptTradeJSON) body).getPlayerIndex())
                + " declined trade.",
            cm.playerManager.getPlayerName(((AcceptTradeJSON) body).getPlayerIndex()));
      }
      cm.playerManager.setTurnStatus(TurnType.PLAYING);

    } catch (ServerException
        | NotEnoughPlayerResourcesException
        | InvalidPlayerIndexException
        | TradeOfferNullException e) {
      e.printStackTrace();
    }
    return cm;
  }
Пример #2
0
  /**
   * Updates the CatanModel to reflect desired exchange of resources by a player
   *
   * @return CatanModel, return the updated Catan model
   */
  @Override
  public Object execute() {
    CatanModel cm = null;
    try {
      cm = facade.getGameModel(authToken);

      ResourceList rs = new ResourceList();
      rs.addResource(ResourceType.toEnum(((MaritimeTradeJSON) body).getOutputResource()), 1);
      rs.removeResource(
          ResourceType.toEnum(((MaritimeTradeJSON) body).getInputResource()),
          ((MaritimeTradeJSON) body).getRatio());

      cm.resourceManager.tradeWithBank(rs, ((MaritimeTradeJSON) body).getPlayerIndex());

    } catch (ServerException
        | NotEnoughBankResourcesException
        | NotEnoughPlayerResourcesException e) {
      e.printStackTrace();
    }
    return cm;
  }