Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"maximum number of microbes has already been" message added #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
@Service
public class CardResourceService {
private final int MAXIMUM_MICROBES_ON_THE_BACTERIAL_AGGREGATES = 5;

public void addResources(Player player, Card toCard, int count) {
final Map<Class<?>, Integer> cardResourcesCount = player.getCardResourcesCount();
Expand All @@ -32,4 +33,15 @@ public void addResources(Player player, Card toCard, int count) {
}
}

public String resourceSubmissionMessage(Card inputCard, Player player) {

if (inputCard.getClass() == BacterialAggregates.class) {
if (player.getCardResourcesCount().get(BacterialAggregates.class) == MAXIMUM_MICROBES_ON_THE_BACTERIAL_AGGREGATES) {
return "The maximum number of microbes has already been reached on the selected card";
}
}

return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.terraforming.ares.validation.action;

import com.terraforming.ares.cards.blue.BacterialAggregates;
import com.terraforming.ares.cards.blue.ConservedBiome;
import com.terraforming.ares.mars.MarsGame;
import com.terraforming.ares.model.Card;
import com.terraforming.ares.model.CardCollectableResource;
import com.terraforming.ares.model.InputFlag;
import com.terraforming.ares.model.Player;
import com.terraforming.ares.services.CardResourceService;
import com.terraforming.ares.services.CardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -23,6 +25,7 @@
public class ConservedBiomeActionValidator implements ActionValidator<ConservedBiome> {
public static final String ERROR_MESSAGE = "Conserved biome expects a card to add an Animal/Microbe to";
private final CardService cardService;
private final CardResourceService cardResourceService;

@Override
public Class<ConservedBiome> getType() {
Expand Down Expand Up @@ -53,6 +56,11 @@ public String validate(MarsGame game, Player player, Map<Integer, List<Integer>>
return "You may only add resource to an Animal/Microbe card";
}

String resourceSubmissionMessage = cardResourceService.resourceSubmissionMessage(project,player);
if (resourceSubmissionMessage != null) {
return resourceSubmissionMessage;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.terraforming.ares.validation.action;

import com.terraforming.ares.cards.blue.BacterialAggregates;
import com.terraforming.ares.cards.blue.ExtremeColdFungus;
import com.terraforming.ares.mars.MarsGame;
import com.terraforming.ares.model.Card;
import com.terraforming.ares.model.CardCollectableResource;
import com.terraforming.ares.model.InputFlag;
import com.terraforming.ares.model.Player;
import com.terraforming.ares.services.CardResourceService;
import com.terraforming.ares.services.CardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -22,6 +24,7 @@
@RequiredArgsConstructor
public class ExtremeColdFungusActionValidator implements ActionValidator<ExtremeColdFungus> {
private final CardService cardService;
private final CardResourceService cardResourceService;

@Override
public Class<ExtremeColdFungus> getType() {
Expand Down Expand Up @@ -56,6 +59,10 @@ public String validate(MarsGame game, Player player, Map<Integer, List<Integer>>
if (project.getCollectableResource() != CardCollectableResource.MICROBE) {
return "You may only add resource to a Microbe card";
}
String resourceSubmissionMessage = cardResourceService.resourceSubmissionMessage(project,player);
if (resourceSubmissionMessage != null) {
return resourceSubmissionMessage;
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.terraforming.ares.validation.action;

import com.terraforming.ares.cards.blue.BacterialAggregates;
import com.terraforming.ares.cards.blue.SymbioticFungus;
import com.terraforming.ares.mars.MarsGame;
import com.terraforming.ares.model.Card;
import com.terraforming.ares.model.CardCollectableResource;
import com.terraforming.ares.model.InputFlag;
import com.terraforming.ares.model.Player;
import com.terraforming.ares.services.CardResourceService;
import com.terraforming.ares.services.CardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -23,6 +25,7 @@
public class SymbioticFungudActionValidator implements ActionValidator<SymbioticFungus> {
public static final String ERROR_MESSAGE = "SymbioticFungud requires a card to put a microbe on";
private final CardService cardService;
private final CardResourceService cardResourceService;

@Override
public Class<SymbioticFungus> getType() {
Expand Down Expand Up @@ -51,6 +54,11 @@ public String validate(MarsGame game, Player player, Map<Integer, List<Integer>>
return "SymbioticFungud may only place a microbe on a microbe collecting card";
}

String resourceSubmissionMessage = cardResourceService.resourceSubmissionMessage(card,player);
if (resourceSubmissionMessage != null) {
return resourceSubmissionMessage;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.terraforming.ares.validation.input;

import com.terraforming.ares.cards.blue.BacterialAggregates;
import com.terraforming.ares.cards.green.Astrofarm;
import com.terraforming.ares.model.Card;
import com.terraforming.ares.model.CardCollectableResource;
import com.terraforming.ares.model.InputFlag;
import com.terraforming.ares.model.Player;
import com.terraforming.ares.services.CardResourceService;
import com.terraforming.ares.services.CardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -23,6 +25,7 @@ public class AstrofarmOnBuiltEffectValidator implements OnBuiltEffectValidator<A
private static final String INCORRECT_INPUT_ERROR_MESSAGE =
"Astrofarm: requires an input with the card to put resources on";
private final CardService cardService;
private final CardResourceService cardResourceService;

@Override
public Class<Astrofarm> getType() {
Expand Down Expand Up @@ -52,6 +55,10 @@ public String validate(Card card, Player player, Map<Integer, List<Integer>> inp
return "Selected card does not collect Microbes";
}

String resourceSubmissionMessage = cardResourceService.resourceSubmissionMessage(inputCard,player);
if (resourceSubmissionMessage != null) {
return resourceSubmissionMessage;
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.terraforming.ares.validation.input;

import com.terraforming.ares.cards.blue.BacterialAggregates;
import com.terraforming.ares.cards.red.CryogenicShipment;
import com.terraforming.ares.model.Card;
import com.terraforming.ares.model.CardCollectableResource;
import com.terraforming.ares.model.InputFlag;
import com.terraforming.ares.model.Player;
import com.terraforming.ares.services.CardResourceService;
import com.terraforming.ares.services.CardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -22,6 +24,7 @@
public class CryogenicShipmentOnBuiltEffectValidator implements OnBuiltEffectValidator<CryogenicShipment> {
private final OnBuiltEffectValidationService onBuiltEffectValidationService;
private final CardService cardService;
private final CardResourceService cardResourceService;
private static final String INCORRECT_INPUT_ERROR_MESSAGE =
"Cryogenic Shipment: requires an input with choice to put resources on";

Expand Down Expand Up @@ -54,6 +57,15 @@ public String validate(Card card, Player player, Map<Integer, List<Integer>> inp
return "Selected card does not collect Animals or Microbes";
}

if (inputCard.getClass().equals(BacterialAggregates.class) && player.getCardResourcesCount().get(BacterialAggregates.class) == 5) {
return "The maximum number of microbes has already been reached on the selected card";
}

String resourceSubmissionMessage = cardResourceService.resourceSubmissionMessage(inputCard,player);
if (resourceSubmissionMessage != null) {
return resourceSubmissionMessage;
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.terraforming.ares.validation.input;

import com.terraforming.ares.cards.blue.BacterialAggregates;
import com.terraforming.ares.cards.red.ImportedHydrogen;
import com.terraforming.ares.model.*;
import com.terraforming.ares.services.CardResourceService;
import com.terraforming.ares.services.CardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -20,6 +22,7 @@ public class ImportedHydrogenOnBuiltEffectValidator implements OnBuiltEffectVali
private static final String INCORRECT_INPUT_ERROR_MESSAGE =
"ImportedHydrogen: requires an input with choise for either 3 plants or a card to put resources on";
private final CardService cardService;
private final CardResourceService cardResourceService;

@Override
public Class<ImportedHydrogen> getType() {
Expand Down Expand Up @@ -54,6 +57,10 @@ public String validate(Card card, Player player, Map<Integer, List<Integer>> inp
return "Selected card does not collect Animals or Microbes";
}

String resourceSubmissionMessage = cardResourceService.resourceSubmissionMessage(inputCard,player);
if (resourceSubmissionMessage != null) {
return resourceSubmissionMessage;
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.terraforming.ares.validation.input;

import com.terraforming.ares.cards.blue.BacterialAggregates;
import com.terraforming.ares.cards.red.ImportedNitrogen;
import com.terraforming.ares.model.Card;
import com.terraforming.ares.model.CardCollectableResource;
import com.terraforming.ares.model.InputFlag;
import com.terraforming.ares.model.Player;
import com.terraforming.ares.services.CardResourceService;
import com.terraforming.ares.services.CardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -23,6 +25,7 @@ public class ImportedNitrogenOnBuiltEffectValidator implements OnBuiltEffectVali
private static final String INCORRECT_INPUT_ERROR_MESSAGE =
"ImportedNitrogen requires input both for Animals and Microbes action";
private final CardService cardService;
private final CardResourceService cardResourceService;

@Override
public Class<ImportedNitrogen> getType() {
Expand Down Expand Up @@ -64,6 +67,11 @@ public String validate(Card card, Player player, Map<Integer, List<Integer>> inp
if (microbeCard.getCollectableResource() != CardCollectableResource.MICROBE) {
return "Selected card doesn't collect microbes";
}

String resourceSubmissionMessage = cardResourceService.resourceSubmissionMessage(microbeCard,player);
if (resourceSubmissionMessage != null) {
return resourceSubmissionMessage;
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.terraforming.ares.validation.input;

import com.terraforming.ares.cards.blue.BacterialAggregates;
import com.terraforming.ares.cards.red.LocalHeatTrapping;
import com.terraforming.ares.model.Card;
import com.terraforming.ares.model.CardCollectableResource;
import com.terraforming.ares.model.InputFlag;
import com.terraforming.ares.model.Player;
import com.terraforming.ares.services.CardResourceService;
import com.terraforming.ares.services.CardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -23,6 +25,7 @@ public class LocalHeatTrappingOnBuiltEffectValidator implements OnBuiltEffectVal
private static final String INCORRECT_INPUT_ERROR_MESSAGE =
"LocalHeatTrapping: requires an input with the card to put resources on";
private final CardService cardService;
private final CardResourceService cardResourceService;

@Override
public Class<LocalHeatTrapping> getType() {
Expand Down Expand Up @@ -57,6 +60,10 @@ public String validate(Card card, Player player, Map<Integer, List<Integer>> inp
return "Selected card does not collect Animals or Microbes";
}

String resourceSubmissionMessage = cardResourceService.resourceSubmissionMessage(inputCard,player);
if (resourceSubmissionMessage != null) {
return resourceSubmissionMessage;
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.terraforming.ares.validation.input;

import com.terraforming.ares.cards.blue.BacterialAggregates;
import com.terraforming.ares.cards.blue.ViralEnhancers;
import com.terraforming.ares.model.*;
import com.terraforming.ares.services.CardResourceService;
import com.terraforming.ares.services.CardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -21,6 +23,7 @@
@RequiredArgsConstructor
public class ViralEnhancersOnBuiltEffectValidator implements OnBuiltEffectValidator<ViralEnhancers> {
private final CardService cardService;
private final CardResourceService cardResourceService;

@Override
public Class<ViralEnhancers> getType() {
Expand Down Expand Up @@ -62,6 +65,11 @@ public String validate(Card card, Player player, Map<Integer, List<Integer>> inp
&& projectCard.getCollectableResource() != CardCollectableResource.MICROBE) {
return "Selected card can not collect any animals or resources";
}

String resourceSubmissionMessage = cardResourceService.resourceSubmissionMessage(projectCard,player);
if (resourceSubmissionMessage != null) {
return resourceSubmissionMessage;
}
}
}

Expand Down