Coverage Summary for Class: Sustenance (it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
| Sustenance |
100%
(1/1)
|
100%
(7/7)
|
100%
(10/10)
|
100%
(23/23)
|
package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events;
import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building1;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
import it.polimi.ingsw.gc14.Model.Player;
import java.util.ArrayList;
/**
* Represents a Sustenance event card.
*
* <p>This class defines the specific behavior of the Sustenance event.
*/
public class Sustenance extends EventCard {
/** Food units covered by each Gatherer during the Sustenance event. */
private static final int FOOD_PER_GATHERER = 3;
/**
* The prestige penalty multiplier applied for each unpaid Food unit.
*/
private final int prestigeDebt;
/**
* Returns the prestige penalty multiplier associated with this Sustenance event.
*
* @return the prestige penalty multiplier associated with this Sustenance event.
*/
public int getPrestigeDebt() {
return prestigeDebt;
}
/**
* Creates a Sustenance event card with the specified era and prestige debt value.
*
* @param Era the era of the event card.
* @param prestigeDebt the prestige penalty multiplier for unpaid Food units.
*/
public Sustenance(int Era, int prestigeDebt) {
super(Era, EventType.SUSTENANCE);
this.prestigeDebt = prestigeDebt;
}
/**
* Creates a Sustenance event card with the specified image id, era and prestige debt value.
*
* @param idIMG the image identifier of the Sustenance event card.
* @param Era the era of the event card.
* @param prestigeDebt the prestige penalty multiplier for unpaid Food units.
*/
public Sustenance(String idIMG,int Era, int prestigeDebt) {
super(idIMG,Era, EventType.SUSTENANCE);
this.prestigeDebt = prestigeDebt;
}
/**
* Activates the Sustenance event for the specified list of players.
* For each player, the required Food is computed from the total number of characters,
* reduced by the contribution of Gatherers and by any applicable character discounts
* granted by owned building cards with effect id equal to 1.
* If the resulting Food debt is positive, the player must pay it with available Food.
* If the player does not have enough Food, all remaining Food is removed and the player
* loses Prestige equal to the unpaid Food debt multiplied by {@code prestigeDebt}.
* <b>This event is intended to be executed last among event effects.</b>
*
* @param playerList the list of players affected by the event.
*/
@Override
public void activateEvent (ArrayList <Player> playerList) {
for(Player player : playerList){
int nChar = player.getTotCharacters();
int nGatherers = player.getNType(CharacterType.GATHERER);
int nCharDiscount = 0;
for(BuildingCard b : player.getBuildingCards()){
if(b.getEffectId() == 1){
CharacterType c = ((Building1)b).getIcon();
nCharDiscount += player.getNType(c);
}
}
int foodDebt = nChar - (FOOD_PER_GATHERER * nGatherers + nCharDiscount);
if(foodDebt <= 0){
continue;
}
if(player.getFoodValue() >= foodDebt){
player.removeFood(foodDebt);
}
else{
foodDebt -= player.getFoodValue();
player.removeFood(player.getFoodValue());
player.removePrestige(foodDebt * prestigeDebt);
}
}
}
/**
* Creates and returns a copy of this Sustenance event card.
*
* @return a clone of this Sustenance event card.
*/
@Override
public EventCard clone() {
return new Sustenance(getIdIMG(),getEra(), prestigeDebt);
}
/**
* Prints a string representation of this {@code TribeCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>Includes:
* <li>{@link #prestigeDebt}
* </p>
* @return {@code String} - a string representation of this {@code TribeCard}.
* @see it.polimi.ingsw.gc14.Model.Cards.TribeCard TribeCard
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override
public String toStringPlayer() {
return "SUSTENANCE";
}
@Override
public String toStringBoard() {
return "\033[38;5;180mSUSTENANCE -1\uD83C\uDF56/-" + prestigeDebt + "\uD83C\uDFC5\033[0m";
}
}