Пример #1
0
 /**
  * Gets the Assets this Card would yield the given Player, if played, before optional choices
  *
  * @param player the player that would play this card
  * @return the Assets
  */
 public AssetMap getAssets(Player player) {
   AssetMap result = new AssetMap();
   if (!isChoice) {
     int multiplier = 1;
     if (!multiplierAssets.isEmpty()) {
       multiplier = 0;
       if (multiplierTargets.isEmpty()) {
         multiplierTargets.add(PLAYER_SELF);
       }
       for (String target : multiplierTargets) {
         Player targetPlayer;
         if (target.equals(PLAYER_LEFT)) {
           targetPlayer = player.getPlayerLeft();
         } else if (target.equals(PLAYER_RIGHT)) {
           targetPlayer = player.getPlayerRight();
         } else { // self
           targetPlayer = player;
         }
         Map<String, Integer> targetPlayerAssets = targetPlayer.getConcreteAssets();
         for (String multiplierAsset : multiplierAssets) {
           multiplier += targetPlayerAssets.get(multiplierAsset);
         }
       }
     }
     for (String asset : baseAssets.keySet()) {
       result.put(asset, baseAssets.get(asset) * multiplier);
     }
   }
   return result;
 }
Пример #2
0
 /**
  * Gets the optional Assets this Card would yield the given Player, if played
  *
  * @param player the player that would play this card
  * @return the Assets
  */
 public AssetSet getAssetsOptional(Player player) {
   AssetSet result = new AssetSet();
   if (isChoice) {
     for (String asset : baseAssets.keySet()) {
       result.add(asset);
     }
   }
   return result;
 }
Пример #3
0
  /**
   * Determines whether the given Player can afford this Card, if they perform the purchases stated
   * in the command
   *
   * @param player the Player that would play the Card
   * @param command the command that would play the Card
   * @return whether the Player can afford this Card
   */
  public boolean canAfford(Player player, PlayerCommand command) {
    AssetMap costLessBase = new AssetMap();
    AssetMap playerAssets = player.getAssets();

    costLessBase.add(getCost(player));
    costLessBase.subtract(playerAssets);
    costLessBase.subtract(command.leftPurchases);
    costLessBase.subtract(command.rightPurchases);

    return costLessBase.isEmpty()
        || costLessBase.existsValidChoices(player.getOptionalAssetsComplete());
  }