mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Make the Counters API for card and permanent consistent.
This commit is contained in:
parent
277dc19fec
commit
148f633672
176 changed files with 272 additions and 277 deletions
|
|
@ -70,13 +70,13 @@ public class AttachedToCounterCondition implements Condition {
|
|||
return false;
|
||||
}
|
||||
if (from != -1) { //range compare
|
||||
int count = attachedTo.getCounters().getCount(counterType);
|
||||
int count = attachedTo.getCounters(game).getCount(counterType);
|
||||
if (to == Integer.MAX_VALUE) {
|
||||
return count >= from;
|
||||
}
|
||||
return count >= from && count <= to;
|
||||
} else { // single compare (lte)
|
||||
return attachedTo.getCounters().getCount(counterType) >= amount;
|
||||
return attachedTo.getCounters(game).getCount(counterType) >= amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class LastTimeCounterRemovedCondition implements Condition{
|
|||
permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
|
||||
}
|
||||
if (permanent != null) {
|
||||
final int timeCounters = permanent.getCounters().getCount(CounterType.TIME);
|
||||
final int timeCounters = permanent.getCounters(game).getCount(CounterType.TIME);
|
||||
return timeCounters == 0;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -67,19 +67,19 @@ public class PermanentHasCounterCondition implements Condition {
|
|||
for (Permanent permanent : permanents) {
|
||||
switch (this.type) {
|
||||
case FEWER_THAN:
|
||||
if (permanent.getCounters().getCount(this.counterType) < this.amount) {
|
||||
if (permanent.getCounters(game).getCount(this.counterType) < this.amount) {
|
||||
conditionApplies = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MORE_THAN:
|
||||
if (permanent.getCounters().getCount(this.counterType) > this.amount) {
|
||||
if (permanent.getCounters(game).getCount(this.counterType) > this.amount) {
|
||||
conditionApplies = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case EQUAL_TO:
|
||||
if (permanent.getCounters().getCount(this.counterType) == this.amount) {
|
||||
if (permanent.getCounters(game).getCount(this.counterType) == this.amount) {
|
||||
conditionApplies = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class SourceHasCounterCondition implements Condition {
|
|||
if (card != null) {
|
||||
count = card.getCounters(game).getCount(counterType);
|
||||
} else {
|
||||
count = permanent.getCounters().getCount(counterType);
|
||||
count = permanent.getCounters(game).getCount(counterType);
|
||||
}
|
||||
if (to == Integer.MAX_VALUE) {
|
||||
return count >= from;
|
||||
|
|
@ -86,7 +86,7 @@ public class SourceHasCounterCondition implements Condition {
|
|||
if (card != null) {
|
||||
return card.getCounters(game).getCount(counterType) >= amount;
|
||||
} else {
|
||||
return permanent.getCounters().getCount(counterType) >= amount;
|
||||
return permanent.getCounters(game).getCount(counterType) >= amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,15 +59,15 @@ public class PayLoyaltyCost extends CostImpl {
|
|||
@Override
|
||||
public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) {
|
||||
Permanent planeswalker = game.getPermanent(sourceId);
|
||||
return planeswalker != null && planeswalker.getCounters().getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game);
|
||||
return planeswalker != null && planeswalker.getCounters(game).getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
Permanent planeswalker = game.getPermanent(sourceId);
|
||||
if (planeswalker != null && planeswalker.getCounters().getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game)) {
|
||||
if (planeswalker != null && planeswalker.getCounters(game).getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game)) {
|
||||
if (amount > 0) {
|
||||
planeswalker.getCounters().addCounter(CounterType.LOYALTY.createInstance(amount));
|
||||
planeswalker.getCounters(game).addCounter(CounterType.LOYALTY.createInstance(amount));
|
||||
} else if (amount < 0) {
|
||||
planeswalker.removeCounters(CounterType.LOYALTY.getName(), Math.abs(amount), game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class PayVariableLoyaltyCost extends VariableCostImpl {
|
|||
int maxValue = 0;
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
maxValue = permanent.getCounters().getCount(CounterType.LOYALTY.getName());
|
||||
maxValue = permanent.getCounters(game).getCount(CounterType.LOYALTY.getName());
|
||||
}
|
||||
return maxValue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,16 +93,16 @@ public class RemoveCounterCost extends CostImpl {
|
|||
for (UUID targetId : target.getTargets()) {
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
if (permanent != null) {
|
||||
if (permanent.getCounters().size() > 0 && (counterTypeToRemove == null || permanent.getCounters().containsKey(counterTypeToRemove))) {
|
||||
if (permanent.getCounters(game).size() > 0 && (counterTypeToRemove == null || permanent.getCounters(game).containsKey(counterTypeToRemove))) {
|
||||
String counterName = null;
|
||||
|
||||
if (counterTypeToRemove != null) {
|
||||
counterName = counterTypeToRemove.getName();
|
||||
} else if (permanent.getCounters().size() > 1 && counterTypeToRemove == null) {
|
||||
} else if (permanent.getCounters(game).size() > 1 && counterTypeToRemove == null) {
|
||||
Choice choice = new ChoiceImpl(true);
|
||||
Set<String> choices = new HashSet<>();
|
||||
for (Counter counter : permanent.getCounters().values()) {
|
||||
if (permanent.getCounters().getCount(counter.getName()) > 0) {
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
if (permanent.getCounters(game).getCount(counter.getName()) > 0) {
|
||||
choices.add(counter.getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ public class RemoveCounterCost extends CostImpl {
|
|||
controller.choose(Outcome.UnboostCreature, choice, game);
|
||||
counterName = choice.getChoice();
|
||||
} else {
|
||||
for (Counter counter : permanent.getCounters().values()) {
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
if (counter.getCount() > 0) {
|
||||
counterName = counter.getName();
|
||||
}
|
||||
|
|
@ -119,16 +119,16 @@ public class RemoveCounterCost extends CostImpl {
|
|||
}
|
||||
if (counterName != null) {
|
||||
int countersLeft = countersToRemove - countersRemoved;
|
||||
int countersOnPermanent = permanent.getCounters().getCount(counterName);
|
||||
int countersOnPermanent = permanent.getCounters(game).getCount(counterName);
|
||||
int numberOfCountersSelected = 1;
|
||||
if (countersLeft > 1 && countersOnPermanent > 1) {
|
||||
numberOfCountersSelected = controller.getAmount(1, Math.min(countersLeft, countersOnPermanent),
|
||||
new StringBuilder("Remove how many counters from ").append(permanent.getIdName()).toString(), game);
|
||||
}
|
||||
permanent.removeCounters(counterName, numberOfCountersSelected, game);
|
||||
if (permanent.getCounters().getCount(counterName) == 0) {
|
||||
if (permanent.getCounters(game).getCount(counterName) == 0) {
|
||||
// this removes only the item with number = 0 from the collection
|
||||
permanent.getCounters().removeCounter(counterName);
|
||||
permanent.getCounters(game).removeCounter(counterName);
|
||||
}
|
||||
countersRemoved += numberOfCountersSelected;
|
||||
if (!game.isSimulation()) {
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class RemoveCountersSourceCost extends CostImpl {
|
|||
@Override
|
||||
public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) {
|
||||
Permanent permanent = game.getPermanent(sourceId);
|
||||
if (permanent != null && permanent.getCounters().getCount(name) >= amount) {
|
||||
if (permanent != null && permanent.getCounters(game).getCount(name) >= amount) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -73,7 +73,7 @@ public class RemoveCountersSourceCost extends CostImpl {
|
|||
@Override
|
||||
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
Permanent permanent = game.getPermanent(sourceId);
|
||||
if (permanent != null && permanent.getCounters().getCount(name) >= amount) {
|
||||
if (permanent != null && permanent.getCounters(game).getCount(name) >= amount) {
|
||||
permanent.removeCounters(name, amount, game);
|
||||
this.paid = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ public class RemoveVariableCountersSourceCost extends VariableCostImpl {
|
|||
int maxValue = 0;
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
maxValue = permanent.getCounters().getCount(counterName);
|
||||
maxValue = permanent.getCounters(game).getCount(counterName);
|
||||
}
|
||||
return maxValue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,9 +95,9 @@ public class RemoveVariableCountersTargetCost extends VariableCostImpl {
|
|||
int maxValue = 0;
|
||||
for (Permanent permanent :game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
|
||||
if (counterTypeToRemove != null) {
|
||||
maxValue += permanent.getCounters().getCount(counterTypeToRemove);
|
||||
maxValue += permanent.getCounters(game).getCount(counterTypeToRemove);
|
||||
} else {
|
||||
for(Counter counter :permanent.getCounters().values()){
|
||||
for(Counter counter :permanent.getCounters(game).values()){
|
||||
maxValue += counter.getCount();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class CountersCount implements DynamicValue {
|
|||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
int count = 0;
|
||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
|
||||
count += permanent.getCounters().getCount(counter);
|
||||
count += permanent.getCounters(game).getCount(counter);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class ApplyCountersEffect extends ContinuousEffectImpl {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
for (Permanent permanent: game.getBattlefield().getAllActivePermanents(CardType.CREATURE)) {
|
||||
for (BoostCounter counter: permanent.getCounters().getBoostCounters()) {
|
||||
for (BoostCounter counter: permanent.getCounters(game).getBoostCounters()) {
|
||||
permanent.addPower(counter.getPower() * counter.getCount());
|
||||
permanent.addToughness(counter.getToughness() * counter.getCount());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,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().getCount(counterType);
|
||||
int count = sourcePermanent.getCounters(game).getCount(counterType);
|
||||
sourcePermanent.removeCounters(counterType.getName(), count, game);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,10 +127,10 @@ public class AddCountersSourceEffect extends OneShotEffect {
|
|||
countersToAdd--;
|
||||
}
|
||||
newCounter.add(countersToAdd);
|
||||
int before = permanent.getCounters().getCount(newCounter.getName());
|
||||
int before = permanent.getCounters(game).getCount(newCounter.getName());
|
||||
permanent.addCounters(newCounter, game);
|
||||
if (informPlayers && !game.isSimulation()) {
|
||||
int amountAdded = permanent.getCounters().getCount(newCounter.getName()) - before;
|
||||
int amountAdded = permanent.getCounters(game).getCount(newCounter.getName()) - before;
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
game.informPlayers(player.getLogName() + " puts " + amountAdded + " " + newCounter.getName().toLowerCase() + " counter on " + permanent.getLogName());
|
||||
|
|
|
|||
|
|
@ -96,9 +96,9 @@ public class AddCountersTargetEffect extends OneShotEffect {
|
|||
newCounter.remove(newCounter.getCount());
|
||||
}
|
||||
newCounter.add(calculated);
|
||||
int before = permanent.getCounters().getCount(counter.getName());
|
||||
int before = permanent.getCounters(game).getCount(counter.getName());
|
||||
permanent.addCounters(newCounter, game);
|
||||
int numberAdded = permanent.getCounters().getCount(counter.getName()) - before;
|
||||
int numberAdded = permanent.getCounters(game).getCount(counter.getName()) - before;
|
||||
affectedTargets++;
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts "
|
||||
|
|
@ -114,7 +114,7 @@ public class AddCountersTargetEffect extends OneShotEffect {
|
|||
+ counter.getCount() + " " + counter.getName().toLowerCase() + " counter on " + player.getLogName());
|
||||
}
|
||||
} else if (card != null) {
|
||||
card.addCounters(counter.getName(), counter.getCount(), game);
|
||||
card.addCounters(counter, game);
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(new StringBuilder("Added ").append(counter.getCount()).append(" ").append(counter.getName())
|
||||
.append(" counter to ").append(card.getName())
|
||||
|
|
|
|||
|
|
@ -75,23 +75,25 @@ public class ProliferateEffect extends OneShotEffect {
|
|||
UUID chosen = (UUID) target.getTargets().get(idx);
|
||||
Permanent permanent = game.getPermanent(chosen);
|
||||
if (permanent != null) {
|
||||
if (permanent.getCounters().size() > 0) {
|
||||
if (permanent.getCounters().size() == 1) {
|
||||
for (Counter counter : permanent.getCounters().values()) {
|
||||
permanent.addCounters(counter.getName(), 1, game);
|
||||
if (permanent.getCounters(game).size() > 0) {
|
||||
if (permanent.getCounters(game).size() == 1) {
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
Counter newCounter = new Counter(counter.getName());
|
||||
permanent.addCounters(newCounter, game);
|
||||
}
|
||||
} else {
|
||||
Choice choice = new ChoiceImpl(true);
|
||||
Set<String> choices = new HashSet<>();
|
||||
for (Counter counter : permanent.getCounters().values()) {
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
choices.add(counter.getName());
|
||||
}
|
||||
choice.setChoices(choices);
|
||||
choice.setMessage("Choose a counter to proliferate (" + permanent.getIdName() + ")");
|
||||
controller.choose(Outcome.Benefit, choice, game);
|
||||
for (Counter counter : permanent.getCounters().values()) {
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
if (counter.getName().equals(choice.getChoice())) {
|
||||
permanent.addCounters(counter.getName(), 1, game);
|
||||
Counter newCounter = new Counter(counter.getName());
|
||||
permanent.addCounters(newCounter, game);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class RemoveCounterSourceEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent != null && permanent.getCounters().getCount(counter.getName()) >= counter.getCount()) {
|
||||
if (permanent != null && permanent.getCounters(game).getCount(counter.getName()) >= counter.getCount()) {
|
||||
permanent.removeCounters(counter.getName(), counter.getCount(), game);
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers("Removed " + counter.getCount() + " " + counter.getName() + " counter from " + permanent.getLogName());
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class RemoveCounterTargetEffect extends OneShotEffect {
|
|||
Permanent p = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
if(p != null) {
|
||||
Counter toRemove = (counter == null ? selectCounterType(game, source, p) : counter);
|
||||
if(toRemove != null && p.getCounters().getCount(toRemove.getName()) >= toRemove.getCount()) {
|
||||
if(toRemove != null && p.getCounters(game).getCount(toRemove.getName()) >= toRemove.getCount()) {
|
||||
p.removeCounters(toRemove.getName(), toRemove.getCount(), game);
|
||||
if(!game.isSimulation())
|
||||
game.informPlayers("Removed " + toRemove.getCount() + " " + toRemove.getName()
|
||||
|
|
@ -93,13 +93,13 @@ public class RemoveCounterTargetEffect extends OneShotEffect {
|
|||
|
||||
private Counter selectCounterType(Game game, Ability source, Permanent permanent) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if(controller != null && permanent.getCounters().size() > 0) {
|
||||
if(controller != null && permanent.getCounters(game).size() > 0) {
|
||||
String counterName = null;
|
||||
if(permanent.getCounters().size() > 1) {
|
||||
if(permanent.getCounters(game).size() > 1) {
|
||||
Choice choice = new ChoiceImpl(true);
|
||||
Set<String> choices = new HashSet<>();
|
||||
for(Counter counter : permanent.getCounters().values()) {
|
||||
if (permanent.getCounters().getCount(counter.getName()) > 0) {
|
||||
for(Counter counter : permanent.getCounters(game).values()) {
|
||||
if (permanent.getCounters(game).getCount(counter.getName()) > 0) {
|
||||
choices.add(counter.getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ public class RemoveCounterTargetEffect extends OneShotEffect {
|
|||
controller.choose(Outcome.Detriment, choice, game);
|
||||
counterName = choice.getChoice();
|
||||
} else {
|
||||
for(Counter counter : permanent.getCounters().values()) {
|
||||
for(Counter counter : permanent.getCounters(game).values()) {
|
||||
if(counter.getCount() > 0) {
|
||||
counterName = counter.getName();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class CumulativeUpkeepEffect extends OneShotEffect {
|
|||
Player player = game.getPlayer(source.getControllerId());
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (player != null && permanent != null) {
|
||||
int ageCounter = permanent.getCounters().getCount(CounterType.AGE);
|
||||
int ageCounter = permanent.getCounters(game).getCount(CounterType.AGE);
|
||||
if (cumulativeCost instanceof ManaCost) {
|
||||
ManaCostsImpl totalCost = new ManaCostsImpl<>();
|
||||
for (int i = 0; i < ageCounter; i++) {
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class FadingEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
int amount = permanent.getCounters().getCount(CounterType.FADE);
|
||||
int amount = permanent.getCounters(game).getCount(CounterType.FADE);
|
||||
if (amount > 0) {
|
||||
permanent.removeCounters(CounterType.FADE.createInstance(), game);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ public class GraftAbility extends TriggeredAbilityImpl {
|
|||
if (sourcePermanent != null
|
||||
&& permanent != null
|
||||
&& !sourcePermanent.getId().equals(permanent.getId())
|
||||
&& sourcePermanent.getCounters().containsKey(CounterType.P1P1)
|
||||
&& sourcePermanent.getCounters(game).containsKey(CounterType.P1P1)
|
||||
&& filter.match(permanent, game)) {
|
||||
for (Effect effect : this.getEffects()) {
|
||||
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
|
||||
|
|
@ -168,7 +168,7 @@ class GraftDistributeCounterEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
|
||||
if (sourcePermanent != null) {
|
||||
int numberOfCounters = sourcePermanent.getCounters().getCount(CounterType.P1P1);
|
||||
int numberOfCounters = sourcePermanent.getCounters(game).getCount(CounterType.P1P1);
|
||||
if (numberOfCounters > 0) {
|
||||
Permanent targetCreature = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
if (targetCreature != null) {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public class ModularAbility extends DiesTriggeredAbility {
|
|||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (super.checkTrigger(event, game)) {
|
||||
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
||||
if (zEvent.getTarget().getCounters().getCount(CounterType.P1P1) > 0) {
|
||||
if (zEvent.getTarget().getCounters(game).getCount(CounterType.P1P1) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ class ModularDistributeCounterEffect extends OneShotEffect {
|
|||
Permanent targetArtifact = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (sourcePermanent != null && targetArtifact != null && player != null) {
|
||||
int numberOfCounters = sourcePermanent.getCounters().getCount(CounterType.P1P1);
|
||||
int numberOfCounters = sourcePermanent.getCounters(game).getCount(CounterType.P1P1);
|
||||
if (numberOfCounters > 0) {
|
||||
targetArtifact.addCounters(CounterType.P1P1.createInstance(numberOfCounters), game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class PersistAbility extends DiesTriggeredAbility {
|
|||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (super.checkTrigger(event, game)) {
|
||||
Permanent permanent = ((ZoneChangeEvent) event).getTarget();
|
||||
if (permanent.getCounters().getCount(CounterType.M1M1) == 0) {
|
||||
if (permanent.getCounters(game).getCount(CounterType.M1M1) == 0) {
|
||||
FixedTarget fixedTarget = new FixedTarget(permanent.getId());
|
||||
fixedTarget.init(game, this);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class UndyingAbility extends DiesTriggeredAbility {
|
|||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (super.checkTrigger(event, game)) {
|
||||
Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
|
||||
if (!permanent.getCounters().containsKey(CounterType.P1P1) || permanent.getCounters().getCount(CounterType.P1P1) == 0) {
|
||||
if (!permanent.getCounters(game).containsKey(CounterType.P1P1) || permanent.getCounters(game).getCount(CounterType.P1P1) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ class UnleashRestrictionEffect extends RestrictionEffect {
|
|||
@Override
|
||||
public boolean applies(Permanent permanent, Ability source, Game game) {
|
||||
if (permanent != null && permanent.getId().equals(source.getSourceId())) {
|
||||
if (permanent.getCounters().getCount(CounterType.P1P1) > 0) {
|
||||
if (permanent.getCounters(game).getCount(CounterType.P1P1) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class VanishingSacrificeAbility extends TriggeredAbilityImpl {
|
|||
if (event.getData().equals("time") && event.getTargetId().equals(this.getSourceId())) {
|
||||
Permanent p = game.getPermanent(this.getSourceId());
|
||||
if (p != null) {
|
||||
return p.getCounters().getCount(CounterType.TIME) == 0;
|
||||
return p.getCounters(game).getCount(CounterType.TIME) == 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class VanishingEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Permanent p = game.getPermanent(source.getSourceId());
|
||||
if (p != null) {
|
||||
int amount = p.getCounters().getCount(CounterType.TIME);
|
||||
int amount = p.getCounters(game).getCount(CounterType.TIME);
|
||||
if (amount > 0) {
|
||||
p.removeCounters(CounterType.TIME.createInstance(), game);
|
||||
game.informPlayers("Removed a time counter from " + p.getLogName() + " (" + amount + " left)");
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import mage.constants.Zone;
|
|||
import mage.counters.Counter;
|
||||
import mage.counters.Counters;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
public interface Card extends MageObject {
|
||||
|
|
@ -152,6 +153,8 @@ public interface Card extends MageObject {
|
|||
|
||||
Counters getCounters(Game game);
|
||||
|
||||
Counters getCounters(GameState state);
|
||||
|
||||
boolean addCounters(String name, int amount, Game game);
|
||||
|
||||
boolean addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects);
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ import mage.counters.Counters;
|
|||
import mage.game.CardAttribute;
|
||||
import mage.game.CardState;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.game.command.Commander;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
|
|
@ -655,7 +656,12 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
|||
|
||||
@Override
|
||||
public Counters getCounters(Game game) {
|
||||
return game.getState().getCardState(this.objectId).getCounters();
|
||||
return getCounters(game.getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Counters getCounters(GameState state) {
|
||||
return state.getCardState(this.objectId).getCounters();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -673,7 +679,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
|||
GameEvent event = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, ownerId, name, 1);
|
||||
event.setAppliedEffects(appliedEffects);
|
||||
if (!game.replaceEvent(event)) {
|
||||
game.getState().getCardState(this.objectId).getCounters().addCounter(name, 1);
|
||||
getCounters(game).addCounter(name, 1);
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, ownerId, name, 1));
|
||||
} else {
|
||||
returnCode = false;
|
||||
|
|
@ -703,7 +709,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
|||
GameEvent event = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, ownerId, counter.getName(), 1);
|
||||
event.setAppliedEffects(appliedEffects);
|
||||
if (!game.replaceEvent(event)) {
|
||||
game.getState().getCardState(this.objectId).getCounters().addCounter(eventCounter);
|
||||
getCounters(game).addCounter(eventCounter);
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, ownerId, counter.getName(), 1));
|
||||
} else {
|
||||
returnCode = false;
|
||||
|
|
@ -718,7 +724,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
|||
@Override
|
||||
public void removeCounters(String name, int amount, Game game) {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
game.getState().getCardState(this.objectId).getCounters().removeCounter(name, 1);
|
||||
getCounters(game).removeCounter(name, 1);
|
||||
GameEvent event = GameEvent.getEvent(GameEvent.EventType.COUNTER_REMOVED, objectId, ownerId);
|
||||
event.setData(name);
|
||||
game.fireEvent(event);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class FilterPermanentOrPlayerWithCounter extends FilterPermanentOrPlayer
|
|||
return false;
|
||||
}
|
||||
} else if (o instanceof Permanent) {
|
||||
if (((Permanent)o).getCounters().size() == 0) {
|
||||
if (((Permanent)o).getCounters(game).size() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class CounterAnyPredicate implements Predicate<Permanent> {
|
|||
|
||||
@Override
|
||||
public boolean apply(Permanent input, Game game) {
|
||||
for (Counter counter: input.getCounters().values()) {
|
||||
for (Counter counter: input.getCounters(game).values()) {
|
||||
if (counter.getCount()> 0) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ public class CounterPredicate implements Predicate<Permanent> {
|
|||
@Override
|
||||
public boolean apply(Permanent input, Game game) {
|
||||
if (counter == null) {
|
||||
return !input.getCounters().keySet().isEmpty();
|
||||
return !input.getCounters(game).keySet().isEmpty();
|
||||
} else {
|
||||
return input.getCounters().containsKey(counter);
|
||||
return input.getCounters(game).containsKey(counter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1722,7 +1722,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
if (perm.getCardType().contains(CardType.PLANESWALKER)) {
|
||||
//20091005 - 704.5i
|
||||
if (perm.getCounters().getCount(CounterType.LOYALTY) == 0) {
|
||||
if (perm.getCounters(this).getCount(CounterType.LOYALTY) == 0) {
|
||||
if (movePermanentToGraveyardWithInfo(perm)) {
|
||||
somethingHappened = true;
|
||||
continue;
|
||||
|
|
@ -1860,12 +1860,12 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
|
||||
//20110501 - 704.5r
|
||||
if (perm.getCounters().containsKey(CounterType.P1P1) && perm.getCounters().containsKey(CounterType.M1M1)) {
|
||||
int p1p1 = perm.getCounters().getCount(CounterType.P1P1);
|
||||
int m1m1 = perm.getCounters().getCount(CounterType.M1M1);
|
||||
if (perm.getCounters(this).containsKey(CounterType.P1P1) && perm.getCounters(this).containsKey(CounterType.M1M1)) {
|
||||
int p1p1 = perm.getCounters(this).getCount(CounterType.P1P1);
|
||||
int m1m1 = perm.getCounters(this).getCount(CounterType.M1M1);
|
||||
int min = Math.min(p1p1, m1m1);
|
||||
perm.getCounters().removeCounter(CounterType.P1P1, min);
|
||||
perm.getCounters().removeCounter(CounterType.M1M1, min);
|
||||
perm.getCounters(this).removeCounter(CounterType.P1P1, min);
|
||||
perm.getCounters(this).removeCounter(CounterType.M1M1, min);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
|
||||
sb.append("permanents");
|
||||
for (Permanent permanent : battlefield.getAllPermanents()) {
|
||||
sb.append(permanent.getValue());
|
||||
sb.append(permanent.getValue(this));
|
||||
}
|
||||
|
||||
sb.append("spells");
|
||||
|
|
@ -305,7 +305,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
sb.append("permanents");
|
||||
List<String> perms = new ArrayList<>();
|
||||
for (Permanent permanent : battlefield.getAllPermanents()) {
|
||||
perms.add(permanent.getValue());
|
||||
perms.add(permanent.getValue(this));
|
||||
}
|
||||
Collections.sort(perms);
|
||||
sb.append(perms);
|
||||
|
|
@ -357,7 +357,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
sb.append("permanents");
|
||||
List<String> perms = new ArrayList<>();
|
||||
for (Permanent permanent : battlefield.getAllPermanents()) {
|
||||
perms.add(permanent.getValue());
|
||||
perms.add(permanent.getValue(this));
|
||||
}
|
||||
Collections.sort(perms);
|
||||
sb.append(perms);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import mage.constants.Zone;
|
|||
import mage.counters.Counters;
|
||||
import mage.game.Controllable;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
|
||||
public interface Permanent extends Card, Controllable {
|
||||
|
||||
|
|
@ -161,7 +162,7 @@ public interface Permanent extends Card, Controllable {
|
|||
|
||||
boolean entersBattlefield(UUID sourceId, Game game, Zone fromZone, boolean fireEvent);
|
||||
|
||||
String getValue();
|
||||
String getValue(GameState state);
|
||||
|
||||
@Deprecated
|
||||
void addAbility(Ability ability);
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ import mage.counters.Counter;
|
|||
import mage.counters.CounterType;
|
||||
import mage.counters.Counters;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.game.command.CommandObject;
|
||||
import mage.game.events.DamageCreatureEvent;
|
||||
import mage.game.events.DamagePlaneswalkerEvent;
|
||||
|
|
@ -219,12 +220,12 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
public String getValue(GameState state) {
|
||||
StringBuilder sb = threadLocalBuilder.get();
|
||||
sb.append(controllerId).append(name).append(tapped).append(damage);
|
||||
sb.append(subtype).append(supertype).append(power.getValue()).append(toughness.getValue());
|
||||
sb.append(abilities.getValue());
|
||||
for (Counter counter : getCounters().values()) {
|
||||
for (Counter counter : getCounters(state).values()) {
|
||||
sb.append(counter.getName()).append(counter.getCount());
|
||||
}
|
||||
return sb.toString();
|
||||
|
|
@ -333,31 +334,8 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean addCounters(String name, int amount, Game game) {
|
||||
return addCounters(name, amount, game, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects) {
|
||||
boolean returnCode = true;
|
||||
GameEvent countersEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, controllerId, name, amount);
|
||||
countersEvent.setAppliedEffects(appliedEffects);
|
||||
if (!game.replaceEvent(countersEvent)) {
|
||||
for (int i = 0; i < countersEvent.getAmount(); i++) {
|
||||
GameEvent event = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId, name, 1);
|
||||
event.setAppliedEffects(appliedEffects);
|
||||
if (!game.replaceEvent(event)) {
|
||||
counters.addCounter(name, 1);
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, controllerId, name, 1));
|
||||
} else {
|
||||
returnCode = false;
|
||||
}
|
||||
}
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTERS_ADDED, objectId, controllerId, name, amount));
|
||||
} else {
|
||||
returnCode = false;
|
||||
}
|
||||
return returnCode;
|
||||
public Counters getCounters(GameState state) {
|
||||
return counters;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -878,10 +856,10 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
int actualDamage = event.getAmount();
|
||||
if (actualDamage > 0) {
|
||||
int countersToRemove = actualDamage;
|
||||
if (countersToRemove > getCounters().getCount(CounterType.LOYALTY)) {
|
||||
countersToRemove = getCounters().getCount(CounterType.LOYALTY);
|
||||
if (countersToRemove > getCounters(game).getCount(CounterType.LOYALTY)) {
|
||||
countersToRemove = getCounters(game).getCount(CounterType.LOYALTY);
|
||||
}
|
||||
getCounters().removeCounter(CounterType.LOYALTY, countersToRemove);
|
||||
getCounters(game).removeCounter(CounterType.LOYALTY, countersToRemove);
|
||||
game.fireEvent(new DamagedPlaneswalkerEvent(objectId, sourceId, controllerId, actualDamage, combat));
|
||||
return actualDamage;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ import mage.constants.ZoneDetail;
|
|||
import mage.counters.Counter;
|
||||
import mage.counters.Counters;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
|
|
@ -825,9 +826,15 @@ public class Spell extends StackObjImpl implements Card {
|
|||
|
||||
@Override
|
||||
public Counters getCounters(Game game) {
|
||||
|
||||
return card.getCounters(game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Counters getCounters(GameState state) {
|
||||
return card.getCounters(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addCounters(String name, int amount, Game game) {
|
||||
return card.addCounters(name, amount, game);
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public class TargetPermanentOrPlayerWithCounter extends TargetPermanentOrPlayer
|
|||
public boolean canTarget(UUID id, Game game) {
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
if (permanent != null) {
|
||||
if (permanent.getCounters().size() == 0) {
|
||||
if (permanent.getCounters(game).size() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ public class TargetPermanentOrPlayerWithCounter extends TargetPermanentOrPlayer
|
|||
public boolean canTarget(UUID id, Ability source, Game game) {
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
if (permanent != null) {
|
||||
if (permanent.getCounters().size() == 0) {
|
||||
if (permanent.getCounters(game).size() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue