Sustenance Event Added
This commit is contained in:
@@ -1,18 +1,57 @@
|
|||||||
package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events;
|
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.Character;
|
||||||
|
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.EventType;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
|
||||||
import it.polimi.ingsw.gc14.Model.Player;
|
import it.polimi.ingsw.gc14.Model.Player;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Sustenance extends EventCard {
|
public class Sustenance extends EventCard {
|
||||||
public Sustenance(int Era) {
|
int PrestigeDebt;
|
||||||
|
|
||||||
|
public Sustenance(int Era, int PrestigeDebt) {
|
||||||
super(Era, EventType.SUSTENANCE);
|
super(Era, EventType.SUSTENANCE);
|
||||||
|
this.PrestigeDebt = PrestigeDebt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
@Override
|
@Override
|
||||||
public void activateEvent (ArrayList <Player> playerList) {
|
public void activateEvent (ArrayList <Player> playerList) {
|
||||||
|
for(Player player : playerList){
|
||||||
|
int NChar = player.getCharacterCards().size();
|
||||||
|
int NGatherers =
|
||||||
|
(int) player.getCharacterCards().stream().filter(x -> x.getType().equals(CharacterType.GATHERERS)).count();
|
||||||
|
|
||||||
|
int NCharDiscount = 0;
|
||||||
|
for(Player p : playerList){
|
||||||
|
ArrayList<Character> characters = player.getCharacterCards();
|
||||||
|
for(BuildingCard b : player.getBuildingCards()){
|
||||||
|
if(b instanceof Building1 b1){
|
||||||
|
NCharDiscount += (int) characters.stream().filter(x -> x.getType().equals(b1.getIcon())).count();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int FoodDebt = NChar - (3 * NGatherers + NCharDiscount);
|
||||||
|
|
||||||
|
if(FoodDebt <= 0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(player.getFoodValue() >= FoodDebt){
|
||||||
|
player.removeFood(FoodDebt);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
while(player.getFoodValue() > 0 && FoodDebt > 0){
|
||||||
|
player.removeFood(1);
|
||||||
|
FoodDebt--;
|
||||||
|
}
|
||||||
|
if(FoodDebt > 0){
|
||||||
|
player.removePrestige(FoodDebt * PrestigeDebt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user