mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 21:42:07 -08:00
Add a limit to how many tokens are made (#7469)
* added a simple token limit * updated implementation of token limit * added token limit test
This commit is contained in:
parent
9d84a22412
commit
3a4b0159a9
3 changed files with 74 additions and 0 deletions
|
|
@ -372,4 +372,14 @@ public class Battlefield implements Serializable {
|
|||
return controlChanged;
|
||||
}
|
||||
|
||||
public int countTokens(UUID controllerId) {
|
||||
return field
|
||||
.values()
|
||||
.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(PermanentToken.class::isInstance)
|
||||
.map(permanent -> permanent.isControlledBy(controllerId))
|
||||
.mapToInt(x -> x ? 1 : 0)
|
||||
.sum();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
|
|||
private String tokenDescriptor;
|
||||
private boolean expansionSetCodeChecked;
|
||||
private Card copySourceCard; // the card the Token is a copy from
|
||||
private static final int MAX_TOKENS_PER_GAME = 500;
|
||||
|
||||
// list of set codes token images are available for
|
||||
protected List<String> availableImageSetCodes = new ArrayList<>();
|
||||
|
|
@ -174,6 +175,15 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
|
|||
|
||||
CreateTokenEvent event = new CreateTokenEvent(source, controllerId, amount, this);
|
||||
if (!created || !game.replaceEvent(event)) {
|
||||
int currentTokens = game.getBattlefield().countTokens(event.getPlayerId());
|
||||
int tokenSlots = Math.max(MAX_TOKENS_PER_GAME - currentTokens, 0);
|
||||
if (event.getAmount() > tokenSlots) {
|
||||
game.informPlayers(
|
||||
"The token limit per player is " + MAX_TOKENS_PER_GAME + ", " + controller.getName()
|
||||
+ " will only create " + tokenSlots + " tokens."
|
||||
);
|
||||
}
|
||||
event.setAmount(Math.min(event.getAmount(), tokenSlots));
|
||||
putOntoBattlefieldHelper(event, game, source, tapped, attacking, attackedPlayer, created);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue