Coverage Summary for Class: ShamanicRitual (it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
| ShamanicRitual |
100%
(1/1)
|
100%
(8/8)
|
100%
(24/24)
|
100%
(29/29)
|
package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events;
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;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* When activated, rewards the player with the most shaman icons and penalizes the one with the fewest.
*
* @see EventCard
*/
public class ShamanicRitual extends EventCard {
/** Bonus shaman icons granted per Building 5 owned during this event. */
private static final int BUILDING5_BONUS_ICONS = 3;
/** Prestige points awarded to the player with the most shaman icons. */
private final int prestigeToAdd;
/**
* Returns the prestige points awarded to the player with the most shaman icons.
*
* @return prestige points to award.
*/
int getPrestigeToAdd() { return prestigeToAdd; }
/** Prestige points removed from the player with the fewest shaman icons. */
private final int prestigeToRemove;
/**
* Returns the prestige points removed from the player with the fewest shaman icons.
*
* @return prestige points to remove.
*/
int getPrestigeToRemove() { return prestigeToRemove; }
/**
* Creates a new ShamanicRitual event card.
*
* @param Era the era of the card
* @param prestigeToAdd prestige points awarded to the player with the most icons
* @param prestigeToRemove prestige points removed from the player with the fewest icons
*/
public ShamanicRitual(int Era, int prestigeToAdd, int prestigeToRemove) {
super(Era, EventType.SHAMANIC_RITUAL);
this.prestigeToAdd = prestigeToAdd;
this.prestigeToRemove = prestigeToRemove;
}
/**
* Creates a new ShamanicRitual event card.
*
* @param idIMG the image identifier of the ShamanicRitual event card.
* @param Era the era of the card.
* @param prestigeToAdd prestige points awarded to the player with the most icons.
* @param prestigeToRemove prestige points removed from the player with the fewest icons.
*/
public ShamanicRitual(String idIMG,int Era, int prestigeToAdd, int prestigeToRemove) {
super(idIMG,Era, EventType.SHAMANIC_RITUAL);
this.prestigeToAdd = prestigeToAdd;
this.prestigeToRemove = prestigeToRemove;
}
/**
* Activates the event card "Shamanic Ritual".
* The player with the most icons gains the Prestige Points indicated.
* The player with the fewest icons loses the Prestige Points indicated.
* In case of a tie, all players gain or lose the Prestige Points indicated.
* If all players have the same amount of icons, they all gain and lose Prestige Points.
* Buildings influence:
* Building 2: if you have the lowest number of icons, you don't lose Prestige Points
* Building 5: during the Shamanic Ritual, you gain 3 icons
* Building 6: if you have more icons than any other player, you gain double of Prestige Points
*
* @param playerList contains all the players in the game
*/
@Override
public void activateEvent (ArrayList <Player> playerList){
Map<Player, Integer> playerMap = new HashMap<>();
int tmpIcons;
int tmpCount;
for (Player player : playerList) {
tmpIcons = player.getShamans().stream().mapToInt(sh -> sh.getIcon()).sum();
tmpCount = (int) player.getBuildingCards().stream().filter(b -> b.getEffectId() == 5).count();
if (tmpCount >= 1) {
tmpIcons = tmpIcons+(BUILDING5_BONUS_ICONS *tmpCount);
}
playerMap.put(player, tmpIcons);
}
int maxIcon = playerMap.values().stream().mapToInt(Integer::intValue).max().orElse(0);
int minIcon = playerMap.values().stream().mapToInt(Integer::intValue).min().orElse(0);
List<Player> maxIconsPlayer = playerMap.entrySet().stream().filter(e -> e.getValue() == maxIcon).map(Map.Entry::getKey).toList();
List<Player> minIconsPlayer = playerMap.entrySet().stream().filter(e -> e.getValue() == minIcon).map(Map.Entry::getKey).toList();
for (Player player : maxIconsPlayer) {
if (player.getBuildingCards().stream().anyMatch(b -> b.getEffectId() == 6) && maxIconsPlayer.size() == 1) {
player.addPrestige(prestigeToAdd * 2);
} else {
player.addPrestige(prestigeToAdd);
}
}
for (Player player : minIconsPlayer) {
if (player.getBuildingCards().stream().noneMatch(b -> b.getEffectId() == 2)) {
player.removePrestige(prestigeToRemove);
}
}
}
/**
* Creates and returns a copy of this ShamanicRitual card.
*
* @return a new ShamanicRitual card with the same era and prestige values
*/
@Override
public EventCard clone() {
return new ShamanicRitual(getIdIMG(),getEra(), prestigeToAdd, prestigeToRemove);
}
/**
* 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 #prestigeToAdd}
* <li>{@link #prestigeToRemove}
* </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 "SHAMANIC_RITUAL";
}
@Override
public String toStringBoard() {
return "\033[38;5;180mSHAMANIC_RITUAL \uD83C\uDF1F>:" + prestigeToAdd + " \uD83C\uDF1F<:" + prestigeToRemove + "\033[0m";
}
}