Commit 7cd1354f authored by Corentin Guillevic's avatar Corentin Guillevic

Add the last tests for the SurvivalCard Powers ; Add some correction ; Rename...

Add the last tests for the SurvivalCard Powers ; Add some correction ; Rename PowerMoificator in PowerModifier
parent 8df229a8
......@@ -17,8 +17,8 @@ import fr.univnantes.alma.server.game.item.player.Player;
import fr.univnantes.alma.server.game.item.player.Traque;
import fr.univnantes.alma.server.game.item.power.Power;
import fr.univnantes.alma.server.game.item.power.PowerType;
import fr.univnantes.alma.server.game.item.power.modificator.PowerModificator;
import fr.univnantes.alma.server.game.item.power.modificator.PowerModificatorType;
import fr.univnantes.alma.server.game.item.power.modifier.PowerModifier;
import fr.univnantes.alma.server.game.item.power.modifier.PowerModifierType;
import fr.univnantes.alma.server.game.item.power.recurrent.PowerRecurrent;
import fr.univnantes.alma.server.game.utilitary.Conversion;
import fr.univnantes.alma.server.game.utilitary.Pair;
......@@ -501,7 +501,7 @@ public class Game implements GameInterface {
response = new Response(false, "You can play jeton only in Phase 2");
}
}
else if(gameRoundVariables.refugeIsActive() && placedJeton.getJeton().getType().equals(CIBLE)) {
else if(gameRoundVariables.refugeIsActive() && isJetonCibleOnThisPlace(placedJeton.getPlaces())) {
response = new Response(false, "Can't play JetonCible when Refuge is active");
}
else{
......@@ -556,7 +556,8 @@ public class Game implements GameInterface {
int cardsPerWillingness = 2 + traque.getNumberOfAdditionalCardsTakeBackPerPawnWillingnessLostWithResist();
int numberCard = Math.min(cardsPerWillingness * number, traque.defausseSize());
if(numberCard > 0) {
choosePlaceCardsAction(playerId, numberCard, traque.getDefausse());
List<PlaceCard> chosen = choosePlaceCardsAction(playerId, numberCard, traque.getDefausse());
traque.takeBackPlaceCard(chosen);
}
traque.getRights().setCanGiveUp(false);
traque.getRights().setCanResist(false);
......@@ -947,6 +948,8 @@ public class Game implements GameInterface {
List<TrackingCard> trackingCards = creature.getTrackingCardsPlayed();
boolean containsJetonCible = false;
boolean containsJetonArtemia = false;
boolean canPlaceOn6To10 = gameRoundVariables.canPlaceJetonCreatureOnPlaces6To10();
boolean placeBetween6To10 = false;
for(TrackingCard trackingCard : trackingCards) {
if(trackingCard.containsSymbol(CIBLE)){
......@@ -971,9 +974,14 @@ public class Game implements GameInterface {
return new Response(false, "JetonCreature can't be place on two adjacent places");
}
}
for(Place place : placedJeton.getPlaces()) {
if(Planet.placeToNumber(place) >= 6) {
placeBetween6To10 = true;
}
}
if( (type.equals(CIBLE) && containsJetonCible)
|| (type.equals(ARTEMIA) && (containsJetonArtemia || board.isArtemiaSquare()))
|| type.equals(JetonSymbol.CREATURE)) {
|| type.equals(JetonSymbol.CREATURE) && (canPlaceOn6To10 || !placeBetween6To10)) {
if(planet.placeJeton(placedJeton)) {
creature.playJeton(placedJeton.getJeton());
return new Response(true, "");
......@@ -1093,7 +1101,7 @@ public class Game implements GameInterface {
traque.takeBackPlayedPlaceCards();
}
else if(gameRoundVariables.ralliementIsActive() && gameRoundVariables.getPlayersWhoHasCaughtByCreature().contains(traque.getInGameId())) {
List<PlaceCard> placeCardsWhereIsJetonCreature = planet.getPlaceCardsWhereJetonIs(JetonSymbol.CREATURE);
List<PlaceCard> placeCardsWhereIsJetonCreature = planet.findPlaceCardsWhereJetonIs(JetonSymbol.CREATURE);
traque.takeBackPlaceCard(placeCardsWhereIsJetonCreature);
traque.throwAwayPlaceCard();
}
......@@ -1136,7 +1144,7 @@ public class Game implements GameInterface {
List<Power> newNextRoundPowers = new ArrayList<>();
for(Power power : nextRoundPowers) {
if(power.getType().equals(PowerType.MODIFICATOR)) {
applyModificatorPower((PowerModificator) power);
applyModificatorPower((PowerModifier) power);
}
else if(power.getType().equals(PowerType.RECURRENT)) {
PowerRecurrent powerRecurrent = (PowerRecurrent) power;
......@@ -1152,11 +1160,11 @@ public class Game implements GameInterface {
/**
* Apply a power modificator
*/
private void applyModificatorPower(PowerModificator power) {
PowerModificatorType type = power.getModificatorType();
private void applyModificatorPower(PowerModifier power) {
PowerModifierType type = power.getModificatorType();
Player player = getPlayer(power.getInGameIdPlayer());
if(player.getTeam().equals(CREATURE)) {
if(type.equals(PowerModificatorType.PLAYABLE_TRACKING_CARD)) {
if(type.equals(PowerModifierType.PLAYABLE_TRACKING_CARD)) {
creature.getRights().setMaxTrackingCardPlayable((int) power.getModifiedValue());
}
}
......@@ -1438,4 +1446,16 @@ public class Game implements GameInterface {
}
return map;
}
private boolean isJetonCibleOnThisPlace(List<Place> places) {
List<Place> jetonCiblePlaces = planet.findPlacesWhereJetonIs(CIBLE);
Iterator<Place> iterator = places.iterator();
boolean isJetonCibleOnThisPlace = false;
while (!isJetonCibleOnThisPlace && iterator.hasNext()) {
if(jetonCiblePlaces.contains(iterator.next())) {
isJetonCibleOnThisPlace = true;
}
}
return isJetonCibleOnThisPlace;
}
}
......@@ -20,7 +20,7 @@ public class Planet {
private Map<Place, List<Jeton>> mapPlaceToJetons;
private Map<Place, Boolean> blockedPlaces;
private Map<Place, SurvivalCard> placeSurvivalCardMap;
private Map<Place, List<SurvivalCard>> placeSurvivalCardMap;
private int numberMovesAllowInRound;
private PlaceDistribution placeDistribution;
private PlanetPawn planetPawn;
......@@ -64,7 +64,7 @@ public class Planet {
}
}
public List<Place> getPlacesWhereJetonIs(JetonSymbol symbol) {
public List<Place> findPlacesWhereJetonIs(JetonSymbol symbol) {
List<Place> places = new ArrayList<>();
List<Jeton> jetonsAux;
for(Place place : mapPlaceToJetons.keySet()) {
......@@ -78,7 +78,7 @@ public class Planet {
return places;
}
public List<PlaceCard> getPlaceCardsWhereJetonIs(JetonSymbol symbol) {
public List<PlaceCard> findPlaceCardsWhereJetonIs(JetonSymbol symbol) {
List<PlaceCard> placeCards = new ArrayList<>();
List<Jeton> jetonsAux;
for(Place place : mapPlaceToJetons.keySet()) {
......@@ -244,11 +244,18 @@ public class Planet {
}
public SurvivalCard takeSurvivalCardOnPlace(Place place) {
SurvivalCard survivalCard = placeSurvivalCardMap.getOrDefault(place, null);
if(survivalCard != null) {
placeSurvivalCardMap.remove(place);
List<SurvivalCard> survivalCards = placeSurvivalCardMap.getOrDefault(place, null);
SurvivalCard cardCaught = null;
if(survivalCards != null) {
if(!survivalCards.isEmpty()) {
cardCaught = survivalCards.get(0);
survivalCards.remove(cardCaught);
}
if(survivalCards.isEmpty()) {
placeSurvivalCardMap.remove(place);
}
}
return survivalCard;
return cardCaught;
}
public SurvivalCard takeSurvivalCardOnPlace(PlaceCard placeCard) {
......@@ -257,7 +264,8 @@ public class Planet {
public void putSurvivalCardOnPlace(Pair<Place, SurvivalCard> pair) {
placeSurvivalCardMap.putIfAbsent(pair.getKey(), pair.getValue());
placeSurvivalCardMap.putIfAbsent(pair.getKey(), new ArrayList<>());
placeSurvivalCardMap.get(pair.getKey()).add(pair.getValue());
}
public void putSurvivalCardOnPlace(List<Pair<Place, SurvivalCard>> pairs) {
......
package fr.univnantes.alma.server.game.item.power.modificator;
package fr.univnantes.alma.server.game.item.power.modifier;
import fr.univnantes.alma.server.game.item.power.Power;
import fr.univnantes.alma.server.game.item.power.PowerType;
public class PowerModificator extends Power {
public class PowerModifier extends Power {
private PowerModificatorType modificatorType;
private PowerModifierType modificatorType;
private Object modifiedValue;
public PowerModificator(int playerId, PowerModificatorType modificatorType, Object modifiedValue) {
public PowerModifier(int playerId, PowerModifierType modificatorType, Object modifiedValue) {
super(playerId);
this.modificatorType = modificatorType;
this.modifiedValue = modifiedValue;
}
public PowerModificatorType getModificatorType() {
public PowerModifierType getModificatorType() {
return modificatorType;
}
......
package fr.univnantes.alma.server.game.item.power.modificator;
package fr.univnantes.alma.server.game.item.power.modifier;
public enum PowerModificatorType {
public enum PowerModifierType {
CHOOSABLE_PLACE_CARD, PLAYABLE_PLACE_CARD, CHOOSABLE_VISIBLE_ADDITIONAL_PLACE_CARD, PLAYABLE_TRACKING_CARD,
USE_FJORD_IN_PREVIOUS_ROUND
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment