prevent direct access of Player->counters ; some cleanup on counter removal effects ; implement [MH3] Izzet Generatorium (#12314)

This commit is contained in:
Susucre 2024-05-29 22:34:54 +02:00 committed by GitHub
parent 8d02ff14ff
commit 20b7a115da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
110 changed files with 895 additions and 646 deletions

View file

@ -13,6 +13,10 @@ import mage.constants.Zone;
*/
public class ActivateIfConditionActivatedAbility extends ActivatedAbilityImpl {
public ActivateIfConditionActivatedAbility(Effect effect, Cost cost, Condition condition) {
this(Zone.BATTLEFIELD, effect, cost, condition, TimingRule.INSTANT);
}
public ActivateIfConditionActivatedAbility(Zone zone, Effect effect, Cost cost, Condition condition) {
this(zone, effect, cost, condition, TimingRule.INSTANT);
}

View file

@ -11,7 +11,7 @@ import java.util.Objects;
/**
* A condition which checks whether any players being attacked are poisoned
* (have one or more poison counters on them)
*
*
* @author alexander-novo
*/
public enum AttackedPlayersPoisonedCondition implements Condition {
@ -27,7 +27,7 @@ public enum AttackedPlayersPoisonedCondition implements Condition {
.distinct()
.map(game::getPlayer)
.filter(Objects::nonNull)
.anyMatch(player -> player.getCounters().containsKey(CounterType.POISON));
.anyMatch(player -> player.getCountersCount(CounterType.POISON) > 0);
}
@Override

View file

@ -6,7 +6,6 @@ import mage.abilities.hint.ConditionHint;
import mage.abilities.hint.Hint;
import mage.counters.CounterType;
import mage.game.Game;
import mage.players.Player;
import java.util.Objects;
@ -24,8 +23,7 @@ public enum CorruptedCondition implements Condition {
.stream()
.map(game::getPlayer)
.filter(Objects::nonNull)
.map(Player::getCounters)
.anyMatch(counters -> counters.getCount(CounterType.POISON) >= 3);
.anyMatch(player -> player.getCountersCount(CounterType.POISON) >= 3);
}
@Override

View file

@ -11,6 +11,8 @@ import mage.util.CardUtil;
import java.util.UUID;
import java.util.UUID;
/**
* @author emerald000
*/
@ -31,14 +33,14 @@ public class PayEnergyCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
Player player = game.getPlayer(controllerId);
return player != null && player.getCounters().getCount(CounterType.ENERGY) >= amount;
return player != null && player.getCountersCount(CounterType.ENERGY) >= amount;
}
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Player player = game.getPlayer(controllerId);
if (player != null && player.getCounters().getCount(CounterType.ENERGY) >= amount) {
player.getCounters().removeCounter(CounterType.ENERGY, amount);
if (player != null && player.getCountersCount(CounterType.ENERGY) >= amount) {
player.loseCounters(CounterType.ENERGY.getName(), amount, source, game);
paid = true;
}
return paid;

View file

@ -38,10 +38,7 @@ public class RemoveAllCountersSourceCost extends CostImpl {
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Permanent permanent = game.getPermanent(ability.getSourceId());
if (permanent != null) {
this.removedCounters = permanent.getCounters(game).getCount(counterType);
if (this.removedCounters > 0) {
permanent.removeCounters(counterType.createInstance(this.removedCounters), source, game);
}
this.removedCounters = permanent.removeAllCounters(counterType.getName(), source, game);
}
this.paid = true;
return true;

View file

@ -20,7 +20,7 @@ public enum OpponentsPoisonCountersCount implements DynamicValue {
for (UUID playerUUID : playerList) {
Player player = game.getPlayer(playerUUID);
if (player != null) {
amount += player.getCounters().getCount(CounterType.POISON);
amount += player.getCountersCount(CounterType.POISON);
}
}
return amount;

View file

@ -32,7 +32,7 @@ public enum SourceControllerCountersCount implements DynamicValue {
int amount = 0;
Player player = game.getPlayer(sourceAbility.getControllerId());
if (player != null) {
amount = player.getCounters().getCount(counterType);
amount = player.getCountersCount(counterType);
}
return amount;
}

View file

@ -35,8 +35,7 @@ public class RemoveAllCountersSourceEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
int count = sourcePermanent.getCounters(game).getCount(counterType);
sourcePermanent.removeCounters(counterType.getName(), count, source, game);
sourcePermanent.removeAllCounters(counterType.getName(), source, game);
return true;
}
return false;

View file

@ -76,7 +76,8 @@ public class ProliferateEffect extends OneShotEffect {
if (player == null) {
continue;
}
for (Counter counter : player.getCounters().values()) {
for (Counter counter : player.getCountersAsCopy().values()) {
// TODO: this does not work with ability counters that are not explicitly in CounterType. Like the Hexproof from XXX counters from Indominus Rex, Alpha
Counter newCounter = CounterType.findByName(counter.getName()).createInstance();
if (player.addCounters(newCounter, source.getControllerId(), source, game)) {
game.informPlayers(player.getLogName() + " had " + newCounter.getDescription() + " added to them.");

View file

@ -0,0 +1,53 @@
package mage.abilities.effects.common.counter;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
* Removes all counters (optionally of a given counter type) from the target permanent.
*
* @author MTGfan
*/
public class RemoveAllCountersPermanentTargetEffect extends OneShotEffect {
private final CounterType counterType; // If not null, remove counters of that type only.
public RemoveAllCountersPermanentTargetEffect() {
this((CounterType) null);
}
public RemoveAllCountersPermanentTargetEffect(CounterType counterType) {
super(Outcome.Neutral);
this.counterType = counterType;
staticText = "remove all " + (counterType == null ? "" : counterType.getName() + " ") + "counters from it.";
}
public RemoveAllCountersPermanentTargetEffect(RemoveAllCountersPermanentTargetEffect effect) {
super(effect);
this.counterType = effect.counterType;
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null) {
if (counterType == null) {
permanent.removeAllCounters(source, game);
} else {
permanent.removeAllCounters(counterType.getName(), source, game);
}
return true;
}
return false;
}
@Override
public RemoveAllCountersPermanentTargetEffect copy() {
return new RemoveAllCountersPermanentTargetEffect(this);
}
}

View file

@ -1,45 +0,0 @@
package mage.abilities.effects.common.counter;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author MTGfan
*/
public class RemoveAllCountersTargetEffect extends OneShotEffect {
private final CounterType counterType;
public RemoveAllCountersTargetEffect(CounterType counterType) {
super(Outcome.Neutral);
this.counterType = counterType;
staticText = "remove all " + counterType.getName() + " counters from it.";
}
public RemoveAllCountersTargetEffect(RemoveAllCountersTargetEffect effect) {
super(effect);
this.counterType = effect.counterType;
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if(permanent != null) {
int count = permanent.getCounters(game).getCount(counterType);
permanent.removeCounters(counterType.getName(), count, source, game);
return true;
}
return false;
}
@Override
public RemoveAllCountersTargetEffect copy() {
return new RemoveAllCountersTargetEffect(this);
}
}