package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events;

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;

/**
 * When activated, gives Food and Prestige Points to every player.
 *
 * @see EventCard
 */
public class Hunt extends EventCard {
    /** Food points multiplier used during the event. */
    int foodMultiplier;

    /** Prestige Points multiplier used during the event. */
    int prestigeMultiplier;

    /**
     * Creates a new Hunt event card.
     *
     * @param Era                      the era of the card
     * @param prestigeMultiplier    prestige points multiplicator used during the event
     */
    public Hunt(int Era, int prestigeMultiplier) {
        super(Era, EventType.HUNT);
        this.foodMultiplier = 1;
        this.prestigeMultiplier = prestigeMultiplier;
    }

    /**
     * Activates the event card "Hunt".
     * Each player takes 1 Food and gains Prestige Points for each Hunter in their tribe.
     *
     * Buildings influence:
     *      Building 7: you take 1 Food and 1 additional Prestige Point for each Hunter
     *
     * @param playerList contains all the players in the game
     */
    @Override
    public void activateEvent (ArrayList <Player> playerList){
        for (Player player : playerList) {
            int tmpFoodMultiplier = foodMultiplier;
            int tmpPrestigeMultiplier = prestigeMultiplier;

            ArrayList <BuildingCard> buildingList = player.buildingCards;
            int hunterCounter=player.getNType(CharacterType.HUNTER);

            for (BuildingCard buildingCard : buildingList) {
                if (buildingCard.getEffectId() == 7) {
                    tmpFoodMultiplier++;
                    tmpPrestigeMultiplier++;
                }
            }

            player.addFood(tmpFoodMultiplier * hunterCounter);
            player.addPrestige(tmpPrestigeMultiplier * hunterCounter);
        }
    }

    /**
     * Creates and returns a copy of this Hunt card.
     *
     * @return a new Hunt card with the same era and prestige multiplier
     */
    @Override
    public EventCard clone() {
        return new Hunt(getEra(), prestigeMultiplier);
    }

}
