/** * 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; }
/** * 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()); }
/** * Gets the Asset cost of playing this card * * @return the Asset cost of playing this card */ public AssetMap getCost(Player player) { for (Card card : player.getPlayedCards()) { if (card.getName().equals(freeFor)) { return new AssetMap(); } } return cost; }
/** * Charges the given Player the cost of playing this card * * @param player the player being charged */ public void playCard(Player player) { player.changeGold(-getCost(player).get(ASSET_GOLD)); }