mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
* First Come, First Served - fixed game error with tokens usage
This commit is contained in:
parent
fe073bba0b
commit
6568f75b98
1 changed files with 13 additions and 9 deletions
|
@ -1,9 +1,5 @@
|
|||
|
||||
package mage.cards.f;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.effects.common.continuous.GainAbilityAllEffect;
|
||||
import mage.abilities.keyword.FirstStrikeAbility;
|
||||
|
@ -18,8 +14,11 @@ import mage.game.Game;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author L_J
|
||||
*/
|
||||
public final class FirstComeFirstServed extends CardImpl {
|
||||
|
@ -31,7 +30,7 @@ public final class FirstComeFirstServed extends CardImpl {
|
|||
}
|
||||
|
||||
public FirstComeFirstServed(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{W}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{W}");
|
||||
|
||||
// Each attacking or blocking creature with the lowest collector number among attacking or blocking creatures has first strike.
|
||||
GainAbilityAllEffect gainEffect = new GainAbilityAllEffect(FirstStrikeAbility.getInstance(), Duration.WhileOnBattlefield, filter, false);
|
||||
|
@ -51,14 +50,15 @@ public final class FirstComeFirstServed extends CardImpl {
|
|||
class FirstComeFirstServedPredicate implements Predicate<Permanent> {
|
||||
|
||||
private static final Pattern partNumberPattern = Pattern.compile("\\d+");
|
||||
|
||||
|
||||
@Override
|
||||
public boolean apply(Permanent input, Game game) {
|
||||
if (input instanceof PermanentCard) {
|
||||
int lowestNumber = Integer.MAX_VALUE;
|
||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterAttackingOrBlockingCreature(), game)) {
|
||||
// token don't have card number
|
||||
int number = parseCardNumber(permanent);
|
||||
if (lowestNumber > number) {
|
||||
if (number > 0 && lowestNumber > number) {
|
||||
lowestNumber = number;
|
||||
}
|
||||
}
|
||||
|
@ -66,9 +66,13 @@ class FirstComeFirstServedPredicate implements Predicate<Permanent> {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public int parseCardNumber(Permanent input) {
|
||||
String str = input.getCardNumber();
|
||||
if (str == null || str.isEmpty()) {
|
||||
// token don't have card number
|
||||
return 0;
|
||||
}
|
||||
Matcher matcher = partNumberPattern.matcher(str);
|
||||
if (matcher.find()) {
|
||||
return Integer.parseInt(matcher.group());
|
||||
|
|
Loading…
Reference in a new issue