(WIP) Replacing blocking/blocked by predicates (#8729)

* replaced blocking/blocked by predicates

* added test for knight of dusk (currently fails)

* added source parameter to filters and everything else that needs it

* some changes to various predicates

* test fix

* small changes to filter code

* merge fix

* fixed a test failure

* small change to Karn, Scion of Urza

* removed sourceId from filter methods and other similar places

* added new getobject method to fix some test failures

* a few more fixes

* fixed merge conflicts

* merge fix
This commit is contained in:
Evan Kranzler 2022-03-23 18:45:02 -04:00 committed by GitHub
parent 53877424a0
commit 80e11b2052
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1719 changed files with 3384 additions and 3325 deletions

View file

@ -966,7 +966,7 @@ public abstract class AbilityImpl implements Ability {
if (target.getTargetController() != null) {
abilityControllerId = target.getTargetController();
}
if (!target.canChoose(ability.getSourceId(), abilityControllerId, game)) {
if (!target.canChoose(abilityControllerId, ability, game)) {
validTargets = false;
break;
}

View file

@ -219,7 +219,7 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
realMaxModes = 0;
for (UUID targetPlayerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player targetPlayer = game.getPlayer(targetPlayerId);
if (((FilterPlayer) this.maxModesFilter).match(targetPlayer, source.getSourceId(), source.getControllerId(), game)) {
if (((FilterPlayer) this.maxModesFilter).match(targetPlayer, source.getControllerId(), source, game)) {
realMaxModes++;
}
}
@ -292,7 +292,7 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
}
for (Mode mode : this.values()) {
if ((!isEachModeOnlyOnce() || onceSelectedModes == null || !onceSelectedModes.contains(mode.getId()))
&& mode.getTargets().canChoose(source.getSourceId(), source.getControllerId(), game)) {
&& mode.getTargets().canChoose(source.getControllerId(), source, game)) {
this.addSelectedMode(mode.getId());
}
}
@ -309,7 +309,7 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
UUID playerId = null;
if (modeChooser == TargetController.OPPONENT) {
TargetOpponent targetOpponent = new TargetOpponent();
if (targetOpponent.choose(Outcome.Benefit, source.getControllerId(), source.getSourceId(), game)) {
if (targetOpponent.choose(Outcome.Benefit, source.getControllerId(), source.getSourceId(), source, game)) {
playerId = targetOpponent.getFirstTarget();
}
} else {

View file

@ -331,7 +331,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
}
}
if (sourceObject == null) { // source is no permanent
sourceObject = game.getObject(source.getSourceId());
sourceObject = game.getObject(source);
if (sourceObject == null || sourceObject.isPermanent(game)) {
return false; // No source object found => ability is not valid
}

View file

@ -8,7 +8,7 @@ import mage.abilities.effects.Effect;
import mage.constants.AbilityWord;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.AnotherCardPredicate;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.target.common.TargetCardInHand;
@ -26,7 +26,7 @@ public class GrandeurAbility extends ActivatedAbilityImpl {
FilterCard filter = new FilterCard("another card named " + cardName);
filter.add(new NamePredicate(cardName));
filter.add(new AnotherCardPredicate());
filter.add(AnotherPredicate.instance);
this.addCost(new DiscardTargetCost(new TargetCardInHand(filter)));
setAbilityWord(AbilityWord.GRANDEUR);
}

View file

@ -60,7 +60,7 @@ public class AttacksAllTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent permanent = game.getPermanent(event.getSourceId());
if (filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (filter.match(permanent, getControllerId(), this, game)) {
if (attacksYouOrYourPlaneswalker) {
boolean check = false;
if (event.getTargetId().equals(getControllerId())) {

View file

@ -58,7 +58,7 @@ public class AttacksAloneControlledTriggeredAbility extends TriggeredAbilityImpl
return false;
}
Permanent permanent = game.getPermanent(game.getCombat().getAttackers().get(0));
if (permanent == null || !filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (permanent == null || !filter.match(permanent, getControllerId(), this, game)) {
return false;
}
if (setTargetPointer) {

View file

@ -61,7 +61,7 @@ public class AttacksCreatureYouControlTriggeredAbility extends TriggeredAbilityI
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent sourcePermanent = game.getPermanent(event.getSourceId());
if (filter.match(sourcePermanent, sourceId, controllerId, game)) {
if (filter.match(sourcePermanent, controllerId, this, game)) {
if (setTargetPointer) {
this.getEffects().setTargetPointer(new FixedTarget(event.getSourceId(), game));
}

View file

@ -57,7 +57,7 @@ public class AttacksWithCreaturesTriggeredAbility extends TriggeredAbilityImpl {
.getAttackers()
.stream()
.map(game::getPermanent)
.filter(permanent -> filter.match(permanent, sourceId, controllerId, game))
.filter(permanent -> filter.match(permanent, controllerId, this, game))
.mapToInt(x -> 1)
.sum();
if (attackers < minAttackers) {

View file

@ -42,7 +42,7 @@ public class BecomesBlockedAllTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (filter.match(permanent, getControllerId(), this, game)) {
if (setTargetPointer) {
this.getEffects().setTargetPointer(new FixedTarget(event.getTargetId(), game));
}

View file

@ -56,7 +56,7 @@ public class BecomesTappedTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (!filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (!filter.match(permanent, getControllerId(), this, game)) {
return false;
}
if (setTargetPointer) {

View file

@ -6,7 +6,6 @@ import mage.constants.Zone;
import mage.filter.FilterStackObject;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.events.GameEvent.EventType;
import mage.game.events.GameEvent;
import mage.game.stack.StackObject;
import mage.game.permanent.Permanent;
@ -56,7 +55,7 @@ public class BecomesTargetAttachedTriggeredAbility extends TriggeredAbilityImpl
StackObject sourceObject = game.getStack().getStackObject(event.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null) {
if (event.getTargetId().equals(enchantment.getAttachedTo())
&& filter.match(sourceObject, getSourceId(), getControllerId(), game)) {
&& filter.match(sourceObject, getControllerId(), this, game)) {
return true;
}
}

View file

@ -57,7 +57,7 @@ public class BecomesTargetTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
StackObject sourceObject = game.getStack().getStackObject(event.getSourceId());
if (!event.getTargetId().equals(getSourceId())
|| !filter.match(sourceObject, getSourceId(), getControllerId(), game)) {
|| !filter.match(sourceObject, getControllerId(), this, game)) {
return false;
}
switch (setTargetPointer) {

View file

@ -69,27 +69,24 @@ public class DealsDamageToACreatureAllTriggeredAbility extends TriggeredAbilityI
return false;
}
permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (!filterPermanent.match(permanent, getSourceId(), getControllerId(), game)) {
if (!filterPermanent.match(permanent, getControllerId(), this, game)) {
return false;
}
for (Effect effect : this.getEffects()) {
effect.setValue("damage", event.getAmount());
effect.setValue("sourceId", event.getSourceId());
switch (setTargetPointer) {
case PLAYER:
effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));
break;
case PERMANENT:
effect.setTargetPointer(new FixedTarget(permanent, game));
break;
case PERMANENT_TARGET:
Permanent permanent_target = game.getPermanentOrLKIBattlefield(event.getTargetId());
if (permanent_target != null) {
effect.setTargetPointer(new FixedTarget(permanent_target, game));
}
break;
}
this.getEffects().setValue("damage", event.getAmount());
this.getEffects().setValue("sourceId", event.getSourceId());
switch (setTargetPointer) {
case PLAYER:
this.getEffects().setTargetPointer(new FixedTarget(permanent.getControllerId()));
break;
case PERMANENT:
this.getEffects().setTargetPointer(new FixedTarget(permanent, game));
break;
case PERMANENT_TARGET:
Permanent permanent_target = game.getPermanentOrLKIBattlefield(event.getTargetId());
if (permanent_target != null) {
this.getEffects().setTargetPointer(new FixedTarget(permanent_target, game));
}
break;
}
return true;
}
@ -97,6 +94,6 @@ public class DealsDamageToACreatureAllTriggeredAbility extends TriggeredAbilityI
@Override
public String getTriggerPhrase() {
return "Whenever " + filterPermanent.getMessage() + " deals "
+ (combatDamageOnly ? "combat " : "") + "damage to a creature, " ;
+ (combatDamageOnly ? "combat " : "") + "damage to a creature, ";
}
}

View file

@ -54,7 +54,7 @@ public class DealsDamageToACreatureTriggeredAbility extends TriggeredAbilityImpl
&& (!combatOnly || ((DamagedEvent) event).isCombatDamage())) {
if (filter != null) {
Permanent creature = game.getPermanentOrLKIBattlefield(event.getTargetId());
if (!filter.match(creature, getSourceId(), getControllerId(), game)) {
if (!filter.match(creature, getControllerId(), this, game)) {
return false;
}
}

View file

@ -74,7 +74,7 @@ public class DealsDamageToAPlayerAllTriggeredAbility extends TriggeredAbilityImp
return false;
}
Permanent permanent = game.getPermanent(event.getSourceId());
if (!filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (!filter.match(permanent, getControllerId(), this, game)) {
return false;
}
this.getEffects().setValue("damage", event.getAmount());

View file

@ -69,7 +69,7 @@ public class DiesCreatureTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (!zEvent.isDiesEvent() || !filter.match(zEvent.getTarget(), sourceId, controllerId, game)) {
if (!zEvent.isDiesEvent() || !filter.match(zEvent.getTarget(), controllerId, this, game)) {
return false;
}
getEffects().setValue("creatureDied", zEvent.getTarget());

View file

@ -49,7 +49,7 @@ public class DiesThisOrAnotherCreatureOrPlaneswalkerTriggeredAbility extends Tri
if (zEvent.getTarget().getId().equals(this.getSourceId())) {
return true;
} else {
if (filter.match(zEvent.getTarget(), getSourceId(), getControllerId(), game)) {
if (filter.match(zEvent.getTarget(), getControllerId(), this, game)) {
return true;
}
}

View file

@ -56,7 +56,7 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI
if (!applyFilterOnSource && zEvent.getTarget().getId().equals(this.getSourceId())) {
return true;
} else {
if (filter.match(zEvent.getTarget(), getSourceId(), getControllerId(), game)) {
if (filter.match(zEvent.getTarget(), getControllerId(), this, game)) {
return true;
}
}

View file

@ -84,7 +84,7 @@ public class EntersBattlefieldAllTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
UUID targetId = event.getTargetId();
Permanent permanent = game.getPermanent(targetId);
if (!filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (!filter.match(permanent, getControllerId(), this, game)) {
return false;
}
this.getEffects().setValue("permanentEnteringBattlefield", permanent);

View file

@ -79,7 +79,7 @@ public class EntersBattlefieldOrAttacksAllTriggeredAbility extends TriggeredAbil
public boolean checkTrigger(GameEvent event, Game game) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD
&& filter.match(permanent, getSourceId(), getControllerId(), game)) {
&& filter.match(permanent, getControllerId(), this, game)) {
if (setTargetPointer != SetTargetPointer.NONE) {
for (Effect effect : this.getEffects()) {
switch (setTargetPointer) {
@ -98,7 +98,7 @@ public class EntersBattlefieldOrAttacksAllTriggeredAbility extends TriggeredAbil
Permanent attacker = game.getPermanent(event.getSourceId());
if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED
&& filter.match(attacker, getSourceId(), getControllerId(), game)) {
&& filter.match(attacker, getControllerId(), this, game)) {
if (setTargetPointer != SetTargetPointer.NONE) {
for (Effect effect : this.getEffects()) {
switch (setTargetPointer) {

View file

@ -52,7 +52,7 @@ public class EntersBattlefieldThisOrAnotherTriggeredAbility extends EntersBattle
if (onlyControlled && !permanent.isControlledBy(this.getControllerId())) {
return false;
}
return filter.match(permanent, getSourceId(), getControllerId(), game);
return filter.match(permanent, getControllerId(), this, game);
}
@Override

View file

@ -62,7 +62,7 @@ public class LeavesBattlefieldAllTriggeredAbility extends TriggeredAbilityImpl {
if (zEvent.getFromZone() == Zone.BATTLEFIELD) {
UUID targetId = event.getTargetId();
Permanent permanent = game.getPermanentOrLKIBattlefield(targetId);
if (filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (filter.match(permanent, getControllerId(), this, game)) {
if (setTargetPointer != SetTargetPointer.NONE) {
for (Effect effect : this.getEffects()) {
switch (setTargetPointer) {

View file

@ -82,7 +82,7 @@ public class PutCardIntoGraveFromAnywhereAllTriggeredAbility extends TriggeredAb
return false;
}
Card card = game.getCard(event.getTargetId());
if (card == null || card.isCopy() || !filter.match(card, getSourceId(), getControllerId(), game)) {
if (card == null || card.isCopy() || !filter.match(card, getControllerId(), this, game)) {
return false;
}
switch (setTargetPointer) {

View file

@ -118,7 +118,7 @@ class PutIntoGraveFromAnywhereEffect extends ReplacementEffectImpl {
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (optional) {
Player controller = game.getPlayer(source.getControllerId());
MageObject object = game.getObject(source.getSourceId());
MageObject object = game.getObject(source);
if (controller == null || object == null) {
return false;
}

View file

@ -7,7 +7,6 @@ import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.target.targetpointer.FixedTarget;
@ -49,7 +48,7 @@ public class PutIntoGraveFromBattlefieldAllTriggeredAbility extends TriggeredAbi
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.isDiesEvent()) {
if (filter.match(zEvent.getTarget(), this.getSourceId(), this.getControllerId(), game)) {
if (filter.match(zEvent.getTarget(), this.getControllerId(), this, game)) {
if (onlyToControllerGraveyard && !this.isControlledBy(game.getOwnerId(zEvent.getTargetId()))) {
return false;
}

View file

@ -58,7 +58,7 @@ public class SacrificeAllTriggeredAbility extends TriggeredAbilityImpl {
break;
}
Permanent sacrificedPermanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
return sacrificed && filter.match(sacrificedPermanent, getSourceId(), getControllerId(), game);
return sacrificed && filter.match(sacrificedPermanent, getControllerId(), this, game);
}
@Override

View file

@ -57,7 +57,7 @@ public class SacrificePermanentTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
if (!isControlledBy(event.getPlayerId()) || permanent == null
|| !filter.match(permanent, getSourceId(), getControllerId(), game)) {
|| !filter.match(permanent, getControllerId(), this, game)) {
return false;
}
this.getEffects().setValue("sacrificedPermanent", permanent);

View file

@ -59,7 +59,7 @@ public class SpellCastAllTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (!filter.match(spell, getSourceId(), getControllerId(), game)) {
if (!filter.match(spell, getControllerId(), this, game)) {
return false;
}
getEffects().setValue("spellCast", spell);

View file

@ -68,7 +68,7 @@ public class SpellCastControllerTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getPlayerId().equals(this.getControllerId())) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (filter.match(spell, getSourceId(), getControllerId(), game)) {
if (filter.match(spell, getControllerId(), this, game)) {
this.getEffects().setValue("spellCast", spell);
if (rememberSource) {
if (rememberSourceAsCard) {

View file

@ -61,7 +61,7 @@ public class SpellCastOpponentTriggeredAbility extends TriggeredAbilityImpl {
return false;
}
Spell spell = game.getStack().getSpell(event.getTargetId());
if (!filter.match(spell, getSourceId(), getControllerId(), game)) {
if (!filter.match(spell, getControllerId(), this, game)) {
return false;
}
getEffects().setValue("spellCast", spell);

View file

@ -48,7 +48,7 @@ public class TapForManaAllTriggeredAbility extends TriggeredAbilityImpl {
}
TappedForManaEvent manaEvent = ((TappedForManaEvent) event);
Permanent permanent = manaEvent.getPermanent();
if (permanent == null || !filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (permanent == null || !filter.match(permanent, getControllerId(), this, game)) {
return false;
}
getEffects().setValue("mana", manaEvent.getMana());

View file

@ -42,7 +42,7 @@ public class TapForManaAllTriggeredManaAbility extends TriggeredManaAbility {
public boolean checkTrigger(GameEvent event, Game game) {
TappedForManaEvent manaEvent = ((TappedForManaEvent) event);
Permanent permanent = manaEvent.getPermanent();
if (permanent == null || !filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (permanent == null || !filter.match(permanent, getControllerId(), this, game)) {
return false;
}
getEffects().setValue("mana", manaEvent.getMana());

View file

@ -67,7 +67,7 @@ public class TurnedFaceUpAllTriggeredAbility extends TriggeredAbilityImpl {
}
}
Permanent permanent = game.getPermanent(event.getTargetId());
if (filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (filter.match(permanent, getControllerId(), this, game)) {
if (setTargetPointer) {
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId(), game));

View file

@ -60,7 +60,7 @@ public class ZoneChangeAllTriggeredAbility extends TriggeredAbilityImpl {
} else {
perm = game.getPermanent(event.getTargetId()); // LevelX2: maybe this part is not neccessary
}
if (filter.match(perm, sourceId, controllerId, game)) {
if (filter.match(perm, controllerId, this, game)) {
return true;
}
}

View file

@ -19,6 +19,6 @@ public class AnyPlayerControlsCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0;
return game.getBattlefield().count(filter, source.getControllerId(), source, game) > 0;
}
}

View file

@ -29,7 +29,7 @@ public class AttachedToMatchesFilterCondition implements Condition {
if (attachedTo == null) {
attachedTo = (Permanent) game.getLastKnownInformation(permanent.getAttachedTo(), Zone.BATTLEFIELD);
}
if (filter.match(attachedTo, attachedTo.getId(), attachedTo.getControllerId(), game)) {
if (filter.match(attachedTo, attachedTo.getControllerId(), source, game)) {
return true;
}

View file

@ -30,7 +30,7 @@ public class CardsInControllerGraveyardCondition implements Condition {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (filter != null) {
return player != null && player.getGraveyard().count(filter, source.getSourceId(), source.getControllerId(), game) >= value;
return player != null && player.getGraveyard().count(filter, source.getControllerId(), source, game) >= value;
}
return player != null && player.getGraveyard().size() >= value;
}

View file

@ -28,7 +28,7 @@ public enum ControlsCreatureGreatestPowerCondition implements Condition {
Set<UUID> controllers = new HashSet<>();
Integer maxPower = null;
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game);
for (Permanent permanent : permanents) {
if (permanent == null) {
continue;

View file

@ -27,7 +27,7 @@ public enum ControlsCreatureGreatestToughnessCondition implements Condition {
Set<UUID> controllers = new HashSet<>();
Integer maxToughness = null;
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game);
for (Permanent permanent : permanents) {
if (permanent == null) {
continue;

View file

@ -32,7 +32,7 @@ public class ControlsPermanentGreatestCMCCondition implements Condition {
Set<UUID> controllers = new HashSet<>();
Integer maxCMC = null;
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game);
for (Permanent permanent : permanents) {
int cmc = permanent.getManaCost().manaValue();
if (maxCMC == null || cmc > maxCMC) {

View file

@ -21,7 +21,7 @@ public enum CovenCondition implements Condition {
.getBattlefield()
.getActivePermanents(
StaticFilters.FILTER_CONTROLLED_CREATURE,
source.getControllerId(), source.getSourceId(), game
source.getControllerId(), source, game
)
.stream()
.filter(Objects::nonNull)

View file

@ -43,7 +43,7 @@ public class CreatureCountCondition implements Condition {
}
return true;
case ANY:
return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == creatureCount;
return game.getBattlefield().count(filter, source.getControllerId(), source, game) == creatureCount;
default:
throw new UnsupportedOperationException("Value for targetController not supported: " + targetController.toString());
}

View file

@ -30,7 +30,7 @@ public class EnchantedCreatureColorCondition implements Condition {
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null) {
Permanent creature = game.getPermanent(enchantment.getAttachedTo());
if(filter.match(creature, source.getSourceId(), enchantment.getControllerId(), game)){
if(filter.match(creature, enchantment.getControllerId(), source, game)){
return true;
}
}

View file

@ -26,7 +26,7 @@ public class EnchantedCreatureSubtypeCondition implements Condition {
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null) {
Permanent creature = game.getPermanent(enchantment.getAttachedTo());
if (filter.match(creature, source.getSourceId(), enchantment.getControllerId(), game)) {
if (filter.match(creature, enchantment.getControllerId(), source, game)) {
return true;
}

View file

@ -19,7 +19,7 @@ public enum FaceDownSourceCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
MageObject mageObject = game.getObject(source.getSourceId());
MageObject mageObject = game.getObject(source);
if (mageObject != null) {
if (mageObject instanceof Permanent) {
return ((Permanent)mageObject).isFaceDown(game);

View file

@ -32,7 +32,7 @@ public class MeldCondition implements Condition {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
filter.add(new NamePredicate(this.meldWithName));
filter.add(new OwnerIdPredicate(source.getControllerId()));
return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0;
return game.getBattlefield().count(filter, source.getControllerId(), source, game) > 0;
}
}
return false;

View file

@ -45,7 +45,7 @@ public class MostCommonColorCondition implements Condition {
i = 0;
for (ObjectColor color : ObjectColor.getAllColors()) {
colorFilters[i].add(new ColorPredicate(color));
colorCounts[i] = game.getBattlefield().count(colorFilters[i], source.getId(), source.getControllerId(), game);
colorCounts[i] = game.getBattlefield().count(colorFilters[i], source.getControllerId(), source, game);
i++;
}
int max = 0;

View file

@ -63,7 +63,7 @@ public class OathbreakerOnBattlefieldCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
// source.getSourceId() is null for commander's effects
int permanentsOnBattlefield = game.getBattlefield().count(this.filter, source.getSourceId(), playerId, game);
int permanentsOnBattlefield = game.getBattlefield().count(this.filter, playerId, source, game);
return permanentsOnBattlefield > 0;
}

View file

@ -53,7 +53,7 @@ public class OpponentControlsPermanentCondition implements Condition {
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
FilterPermanent localFilter = filter.copy();
localFilter.add(new ControllerIdPredicate(opponentId));
if (ComparisonType.compare(game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game), type, this.count)) {
if (ComparisonType.compare(game.getBattlefield().count(localFilter, source.getControllerId(), source, game), type, this.count)) {
conditionApplies = true;
break;
}

View file

@ -68,7 +68,7 @@ public class PermanentsOnTheBattlefieldCondition implements Condition {
localFilter = filter;
}
return ComparisonType.compare(game.getBattlefield().count(
localFilter, source.getSourceId(), source.getControllerId(), game
localFilter, source.getControllerId(), source, game
), type, count);
}

View file

@ -17,7 +17,7 @@ instance;
@Override
public boolean apply(Game game, Ability source) {
MageObject object = game.getObject(source.getSourceId());
MageObject object = game.getObject(source);
return object != null && !object.isLand(game);
}
}

View file

@ -29,7 +29,7 @@ public class SourceMatchesFilterCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
if (FILTER.match(permanent, permanent.getId(), permanent.getControllerId(), game)) {
if (FILTER.match(permanent, permanent.getControllerId(), source, game)) {
return true;
}

View file

@ -30,7 +30,7 @@ public class SourceTargetsPermanentCondition implements Condition {
Iterator<Target> targets = sourceSpell.getStackAbility().getTargets().iterator();
while (targets.hasNext()) {
Permanent permanent = game.getPermanentOrLKIBattlefield(targets.next().getFirstTarget());
if (filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
if (filter.match(permanent, source.getControllerId(), source, game)) {
return true;
}
}

View file

@ -117,7 +117,7 @@ public class AlternativeCostSourceAbility extends StaticAbility implements Alter
if (ability != null && AbilityType.SPELL == ability.getAbilityType()) {
if (filter != null) {
Card card = game.getCard(ability.getSourceId());
if (!filter.match(card, ability.getSourceId(), ability.getControllerId(), game)) {
if (!filter.match(card, ability.getControllerId(), ability, game)) {
return false;
}
}

View file

@ -41,7 +41,7 @@ public abstract class UseAttachedCost extends CostImpl {
public UseAttachedCost setMageObjectReference(Ability source, Game game) {
this.mageObjectReference = new MageObjectReference(source.getSourceId(), game);
MageObject object = game.getObject(source.getSourceId());
MageObject object = game.getObject(source);
if (object != null) {
this.name = object.getName();
}

View file

@ -1,39 +0,0 @@
package mage.abilities.costs.common;
import mage.abilities.Ability;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostImpl;
import mage.filter.common.FilterControlledPermanent;
import mage.game.Game;
import java.util.UUID;
public class ControlPermanentCost extends CostImpl {
private final FilterControlledPermanent filter;
public ControlPermanentCost(FilterControlledPermanent filter) {
this.filter = filter.copy();
this.text = "Activate only if you control " + filter.getMessage();
}
public ControlPermanentCost(final ControlPermanentCost cost) {
super(cost);
this.filter = cost.filter.copy();
}
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return game.getBattlefield().containsControlled(filter, source.getSourceId(), controllerId, game, 1);
}
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
this.paid = true;
return paid;
}
@Override
public ControlPermanentCost copy() {
return new ControlPermanentCost(this);
}
}

View file

@ -50,7 +50,7 @@ public class DiscardTargetCost extends CostImpl {
int amount = this.getTargets().get(0).getNumberOfTargets();
if (randomDiscard) {
this.cards.addAll(player.discard(amount, true, true, source, game).getCards(game));
} else if (targets.choose(Outcome.Discard, controllerId, source.getSourceId(), game)) {
} else if (targets.choose(Outcome.Discard, controllerId, source.getSourceId(), source, game)) {
Cards toDiscard = new CardsImpl();
toDiscard.addAll(targets.get(0).getTargets());
Cards discarded = player.discard(toDiscard, true, source, game);
@ -71,7 +71,7 @@ public class DiscardTargetCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return targets.canChoose(source.getSourceId(), controllerId, game);
return targets.canChoose(controllerId, source, game);
}
@Override

View file

@ -78,7 +78,7 @@ public class ExileFromGraveCost extends CostImpl {
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
if (targets.choose(Outcome.Exile, controllerId, source.getSourceId(), game)) {
if (targets.choose(Outcome.Exile, controllerId, source.getSourceId(), source, game)) {
for (UUID targetId : targets.get(0).getTargets()) {
Card card = game.getCard(targetId);
if (card == null
@ -106,7 +106,7 @@ public class ExileFromGraveCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return targets.canChoose(source.getSourceId(), controllerId, game);
return targets.canChoose(controllerId, source, game);
}
@Override

View file

@ -51,7 +51,7 @@ public class ExileFromHandCost extends CostImpl {
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
if (targets.choose(Outcome.Exile, controllerId, source.getSourceId(), game)) {
if (targets.choose(Outcome.Exile, controllerId, source.getSourceId(), source, game)) {
Player player = game.getPlayer(controllerId);
int cmc = 0;
for (UUID targetId : targets.get(0).getTargets()) {
@ -81,7 +81,7 @@ public class ExileFromHandCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return targets.canChoose(source.getSourceId(), controllerId, game);
return targets.canChoose(controllerId, source, game);
}
@Override

View file

@ -44,7 +44,7 @@ public class ExileTargetCost extends CostImpl {
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Player player = game.getPlayer(ability.getControllerId());
if (player == null || !targets.choose(Outcome.Exile, controllerId, source.getSourceId(), game)) {
if (player == null || !targets.choose(Outcome.Exile, controllerId, source.getSourceId(), source, game)) {
return paid;
}
Cards cards = new CardsImpl();
@ -71,7 +71,7 @@ public class ExileTargetCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return targets.canChoose(source.getSourceId(), controllerId, game);
return targets.canChoose(controllerId, source, game);
}
@Override

View file

@ -32,8 +32,8 @@ public class PutCardFromHandOnTopOfLibraryCost extends CostImpl {
TargetCardInHand targetCardInHand = new TargetCardInHand();
targetCardInHand.setRequired(false);
Card card;
if (targetCardInHand.canChoose(source.getSourceId(), controllerId, game)
&& controller.choose(Outcome.PreventDamage, targetCardInHand, source.getSourceId(), game)) {
if (targetCardInHand.canChoose(controllerId, source, game)
&& controller.choose(Outcome.PreventDamage, targetCardInHand, source, game)) {
card = game.getCard(targetCardInHand.getFirstTarget());
paid = card != null && controller.moveCardToLibraryWithInfo(card, source, game, Zone.HAND, true, true);
}

View file

@ -60,7 +60,7 @@ public class RemoveCounterCost extends CostImpl {
return paid = true;
}
target.clearChosen();
if (target.choose(Outcome.UnboostCreature, controllerId, source.getSourceId(), game)) {
if (target.choose(Outcome.UnboostCreature, controllerId, source.getSourceId(), source, game)) {
for (UUID targetId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
@ -122,7 +122,7 @@ public class RemoveCounterCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return target.canChoose(source.getSourceId(), controllerId, game);
return target.canChoose(controllerId, source, game);
}
private String setText() {

View file

@ -45,7 +45,7 @@ public class ReturnToHandChosenControlledPermanentCost extends CostImpl {
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
if (targets.choose(Outcome.ReturnToHand, controllerId, source.getSourceId(), game)) {
if (targets.choose(Outcome.ReturnToHand, controllerId, source.getSourceId(), source, game)) {
Set<Card> permanentsToReturn = new HashSet<>();
for (UUID targetId : targets.get(0).getTargets()) {
Permanent permanent = game.getPermanent(targetId);
@ -63,7 +63,7 @@ public class ReturnToHandChosenControlledPermanentCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return targets.canChoose(source.getSourceId(), controllerId, game);
return targets.canChoose(controllerId, source, game);
}
@Override

View file

@ -37,7 +37,7 @@ public class ReturnToHandFromGraveyardCost extends CostImpl {
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
if (targets.choose(Outcome.ReturnToHand, controllerId, source.getSourceId(), game)) {
if (targets.choose(Outcome.ReturnToHand, controllerId, source.getSourceId(), source, game)) {
Set<Card> cardsToMove = new LinkedHashSet<>();
for (UUID targetId : targets.get(0).getTargets()) {
mage.cards.Card targetCard = game.getCard(targetId);
@ -56,7 +56,7 @@ public class ReturnToHandFromGraveyardCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return targets.canChoose(source.getSourceId(), controllerId, game);
return targets.canChoose(controllerId, source, game);
}
@Override

View file

@ -43,7 +43,7 @@ public class RevealDragonFromHandCost extends RevealTargetFromHandCost {
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
super.pay(ability, game, source, controllerId, noMana, costToPay);
revealedOrControlled = numberCardsRevealed > 0
|| game.getBattlefield().count(filter2, source.getSourceId(), controllerId, game) > 0;
|| game.getBattlefield().count(filter2, controllerId, source, game) > 0;
return paid = true;
}

View file

@ -27,7 +27,7 @@ public class RevealHandSourceControllerCost extends CostImpl {
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Player controller = game.getPlayer(controllerId);
MageObject sourceObject = game.getObject(source.getSourceId());
MageObject sourceObject = game.getObject(source);
if (controller != null && sourceObject != null) {
controller.revealCards(sourceObject.getName(), controller.getHand(), game);
paid = true;

View file

@ -44,7 +44,7 @@ public class RevealSecretOpponentCost extends CostImpl {
ChooseSecretOpponentEffect.setSecretOwner(null, source, game); // because only once, the value is set to null
Player controller = game.getPlayer(controllerId);
Player opponent = game.getPlayer(opponentId);
MageObject sourceObject = game.getObject(source.getSourceId());
MageObject sourceObject = game.getObject(source);
if (controller != null && opponent != null && sourceObject != null) {
if (sourceObject instanceof Permanent) {
((Permanent) sourceObject).addInfo(ChooseSecretOpponentEffect.SECRET_OPPONENT, null, game);

View file

@ -40,7 +40,7 @@ public class RevealTargetFromHandCost extends CostImpl {
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
if (targets.choose(Outcome.Benefit, controllerId, source.getSourceId(), game)) {
if (targets.choose(Outcome.Benefit, controllerId, source.getSourceId(), source, game)) {
manaValues = 0;
numberCardsRevealed = 0;
Player player = game.getPlayer(controllerId);
@ -81,7 +81,7 @@ public class RevealTargetFromHandCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return targets.canChoose(source.getSourceId(), controllerId, game);
return targets.canChoose(controllerId, source, game);
}
@Override

View file

@ -53,7 +53,7 @@ public class SacrificeTargetCost extends CostImpl {
activator = ((ActivatedAbilityImpl) ability).getActivatorId();
}
// can be cancel by user
if (targets.choose(Outcome.Sacrifice, activator, source.getSourceId(), game)) {
if (targets.choose(Outcome.Sacrifice, activator, source.getSourceId(), source, game)) {
for (UUID targetId : targets.get(0).getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent == null) {

View file

@ -51,7 +51,7 @@ public class SacrificeXTargetCost extends VariableCostImpl {
@Override
public int getMaxValue(Ability source, Game game) {
return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
return game.getBattlefield().count(filter, source.getControllerId(), source, game);
}
@Override

View file

@ -37,7 +37,7 @@ public class TapTargetCost extends CostImpl {
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
List<Permanent> permanents = new ArrayList<>();
if (target.choose(Outcome.Tap, controllerId, source.getSourceId(), game)) {
if (target.choose(Outcome.Tap, controllerId, source.getSourceId(), source, game)) {
for (UUID targetId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent == null) {
@ -53,7 +53,7 @@ public class TapTargetCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return target.canChoose(source.getSourceId(), controllerId, game);
return target.canChoose(controllerId, source, game);
}
public TargetControlledPermanent getTarget() {

View file

@ -33,7 +33,7 @@ public class UntapTargetCost extends CostImpl {
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
if (target.choose(Outcome.Untap, controllerId, source.getSourceId(), game)) {
if (target.choose(Outcome.Untap, controllerId, source.getSourceId(), source, game)) {
for (UUID targetId : (List<UUID>) target.getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent == null) {
@ -47,7 +47,7 @@ public class UntapTargetCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return target.canChoose(source.getSourceId(), controllerId, game);
return target.canChoose(controllerId, source, game);
}
@Override

View file

@ -31,7 +31,7 @@ public enum LegendaryCreatureCostAdjuster implements CostAdjuster {
@Override
public void adjustCosts(Ability ability, Game game) {
int count = game.getBattlefield().count(
filter, ability.getSourceId(), ability.getControllerId(), game
filter, ability.getControllerId(), ability, game
);
if (count > 0) {
CardUtil.reduceCost(ability, count);

View file

@ -15,7 +15,7 @@ public enum ArtifactYouControlCount implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_ARTIFACT, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
return game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_ARTIFACT, sourceAbility.getControllerId(), sourceAbility, game);
}
@Override

View file

@ -48,7 +48,7 @@ public class AttackingCreatureCount implements DynamicValue {
for (UUID permId : combatGroup.getAttackers()) {
if (filter != null) {
Permanent attacker = game.getPermanent(permId);
if (filter.match(attacker, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game)) {
if (filter.match(attacker, sourceAbility.getControllerId(), sourceAbility, game)) {
count++;
}
} else {

View file

@ -38,8 +38,8 @@ public class CardsInAllGraveyardsCount implements DynamicValue {
.filter(Objects::nonNull)
.map(Player::getGraveyard)
.mapToInt(graveyard -> graveyard.count(
filter, sourceAbility.getSourceId(),
sourceAbility.getControllerId(), game
filter,
sourceAbility.getControllerId(), sourceAbility, game
)).sum();
}

View file

@ -39,7 +39,7 @@ public class CardsInControllerGraveyardCount implements DynamicValue {
Player player = game.getPlayer(sourceAbility.getControllerId());
if (player != null) {
return amount * player.getGraveyard().count(
filter, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game
filter, sourceAbility.getControllerId(), sourceAbility, game
);
}
return 0;

View file

@ -35,7 +35,7 @@ public class CardsInTargetPlayersGraveyardCount implements DynamicValue {
if (filter == null) {
return player.getGraveyard().size();
} else {
return player.getGraveyard().count(filter, sourceAbility.getControllerId(), sourceAbility.getSourceId(), game);
return player.getGraveyard().count(filter, sourceAbility.getSourceId(), sourceAbility, game);
}
}
return 0;

View file

@ -15,7 +15,7 @@ public enum CreaturesYouControlCount implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_CREATURES, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
return game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_CREATURES, sourceAbility.getControllerId(), sourceAbility, game);
}
@Override

View file

@ -38,7 +38,7 @@ public enum DomainValue implements DynamicValue {
return game.getBattlefield()
.getActivePermanents(
StaticFilters.FILTER_CONTROLLED_PERMANENT_LANDS,
targetPlayer, sourceAbility.getSourceId(), game
targetPlayer, sourceAbility, game
).stream()
.map(permanent -> SubType
.getBasicLands()

View file

@ -22,7 +22,7 @@ public enum GateYouControlCount implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return game.getBattlefield().count(filter, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
return game.getBattlefield().count(filter, sourceAbility.getControllerId(), sourceAbility, game);
}
@Override

View file

@ -26,12 +26,12 @@ public enum GreatestSharedCreatureTypeCount implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return getValue(sourceAbility.getControllerId(), sourceAbility.getSourceId(), game);
return getValue(sourceAbility.getControllerId(), sourceAbility, game);
}
public static int getValue(UUID playerId, UUID sourceId, Game game) {
public static int getValue(UUID playerId, Ability source, Game game) {
List<Permanent> permanentList = game.getBattlefield().getActivePermanents(
StaticFilters.FILTER_CONTROLLED_CREATURE, playerId, sourceId, game
StaticFilters.FILTER_CONTROLLED_CREATURE, playerId, source, game
);
permanentList.removeIf(Objects::isNull);
int changelings = permanentList

View file

@ -34,7 +34,7 @@ public class HighestCMCOfPermanentValue implements DynamicValue {
Player controller = game.getPlayer(sourceAbility.getControllerId());
if (controller != null) {
for (Permanent permanent : game.getBattlefield()
.getActivePermanents(filter, sourceAbility.getControllerId(), sourceAbility.getSourceId(), game)) {
.getActivePermanents(filter, sourceAbility.getControllerId(), sourceAbility, game)) {
if ((!onlyIfCanBeSacrificed || controller.canPaySacrificeCost(permanent, sourceAbility, sourceAbility.getControllerId(), game))
&& permanent.getManaValue() > value) {
value = permanent.getManaValue();

View file

@ -16,7 +16,7 @@ public enum LandsYouControlCount implements DynamicValue {
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return game.getBattlefield().count(
StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND,
sourceAbility.getSourceId(), sourceAbility.getControllerId(), game
sourceAbility.getControllerId(), sourceAbility, game
);
}

View file

@ -40,7 +40,7 @@ public enum PartyCount implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
Cards cards = new CardsImpl(game.getBattlefield().getActivePermanents(
filter, sourceAbility.getControllerId(), sourceAbility.getSourceId(), game
filter, sourceAbility.getControllerId(), sourceAbility, game
).stream().collect(Collectors.toSet()));
return subTypeAssigner.getRoleCount(cards, game);
}

View file

@ -41,7 +41,7 @@ public class PermanentsOnBattlefieldCount implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int value = game.getBattlefield().count(filter, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
int value = game.getBattlefield().count(filter, sourceAbility.getControllerId(), sourceAbility, game);
if (multiplier != null) {
value *= multiplier;
}

View file

@ -15,7 +15,7 @@ public enum PermanentsYouControlCount implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
return game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT, sourceAbility.getControllerId(), sourceAbility, game);
}
@Override

View file

@ -34,17 +34,17 @@ public enum UrzaTerrainValue implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
if (subType != SubType.MINE && game.getBattlefield().count(
mineFilter, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game
mineFilter, sourceAbility.getControllerId(), sourceAbility, game
) < 1) {
return 1;
}
if (subType != SubType.TOWER && game.getBattlefield().count(
towerFilter, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game
towerFilter, sourceAbility.getControllerId(), sourceAbility, game
) < 1) {
return 1;
}
if (subType != SubType.POWER_PLANT && game.getBattlefield().count(
powerPlantFilter, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game
powerPlantFilter, sourceAbility.getControllerId(), sourceAbility, game
) < 1) {
return 1;
}

View file

@ -53,7 +53,7 @@ public class AsTurnedFaceUpEffect extends ReplacementEffectImpl {
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (optional) {
Player controller = game.getPlayer(source.getControllerId());
MageObject object = game.getObject(source.getSourceId());
MageObject object = game.getObject(source);
if (controller == null || object == null) {
return false;
}

View file

@ -139,7 +139,7 @@ public class AuraReplacementEffect extends ReplacementEffectImpl {
controllingPlayer = game.getPlayer(card.getOwnerId());
}
if (target != null && controllingPlayer != null && controllingPlayer.choose(auraOutcome, target, card.getId(), game)) {
if (target != null && controllingPlayer != null && controllingPlayer.choose(auraOutcome, target, source, game)) {
targetId = target.getFirstTarget();
}
}

View file

@ -85,7 +85,7 @@ public abstract class ContinuousRuleModifyingEffectImpl extends ContinuousEffect
public String getInfoMessage(Ability source, GameEvent event, Game game) {
if (infoMessage == null) {
String message;
MageObject object = game.getObject(source.getSourceId());
MageObject object = game.getObject(source);
if (object != null) {
message = source.getRule(messageToUser ? object.getIdName() : object.getLogName());
} else {

View file

@ -98,7 +98,7 @@ public class EntersBattlefieldEffect extends ReplacementEffectImpl {
Player controller = game.getPlayer(source.getControllerId());
MageObject object = game.getPermanentEntering(source.getSourceId());
if (object == null) {
object = game.getObject(source.getSourceId());
object = game.getObject(source);
}
if (controller == null || object == null) {
return false;

View file

@ -10,7 +10,6 @@ import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.events.DamageEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.game.stack.StackObject;
import mage.players.Player;
@ -60,7 +59,7 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect {
redirectTarget.add(planeswalker.get(0).getId(), game);
}
} else {
player.choose(Outcome.Damage, redirectTarget, null, game);
player.choose(Outcome.Damage, redirectTarget, source, game);
}
if (!game.isSimulation()) {
Permanent redirectTo = game.getPermanent(redirectTarget.getFirstTarget());

View file

@ -65,7 +65,7 @@ public abstract class RedirectionEffect extends ReplacementEffectImpl {
if (damageToRedirect < 1) { // if multiple replacement effect apply, the rest damage can be 0, so the effect is not applied/replaced
return false;
}
String sourceLogName = source != null ? game.getObject(source.getSourceId()).getLogName() + ": " : "";
String sourceLogName = source != null ? game.getObject(source).getLogName() + ": " : "";
DamageEvent damageEvent = (DamageEvent) event;
int restDamage = 0;
if (damageEvent.getAmount() > amountToRedirect) {

View file

@ -34,7 +34,7 @@ public class AffinityEffect extends CostModificationEffectImpl {
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
// abilityToModify.getControllerId() works with Sen Triplets and in multiplayer games, see https://github.com/magefree/mage/issues/5931
int count = game.getBattlefield().getActivePermanents(filter, abilityToModify.getControllerId(), source.getId(), game).size();
int count = game.getBattlefield().getActivePermanents(filter, abilityToModify.getControllerId(), source, game).size();
CardUtil.reduceCost(abilityToModify, count);
return true;
}

View file

@ -116,7 +116,7 @@ public class AmplifyEffect extends ReplacementEffectImpl {
filter.add(Predicates.not(new CardIdPredicate(enteringPermanent.getId())));
}
if (controller.getHand().count(filter, source.getSourceId(), source.getControllerId(), game) <= 0) {
if (controller.getHand().count(filter, source.getControllerId(), source, game) <= 0) {
return false;
}
if (!controller.chooseUse(outcome, "Reveal cards to Amplify?", source, game)) {

View file

@ -78,7 +78,7 @@ public class BalanceEffect extends OneShotEffect {
if (lowestHandSize > 0) {
TargetCardInHand target = new TargetCardInHand(lowestHandSize, filterCardHand);
if (target.choose(Outcome.Protect, player.getId(), source.getSourceId(), game)) {
if (target.choose(Outcome.Protect, player.getId(), source.getSourceId(), source, game)) {
for (Card card : allCardsInHand) {
if (card != null && target.getTargets().contains(card.getId())) {
cardsToKeep.add(card);
@ -136,12 +136,12 @@ public class BalanceEffect extends OneShotEffect {
continue;
}
List<Permanent> allPermanentsOfType = game.getBattlefield().getActivePermanents(filterPermanent, player.getId(), source.getSourceId(), game);
List<Permanent> allPermanentsOfType = game.getBattlefield().getActivePermanents(filterPermanent, player.getId(), source, game);
List<Permanent> permanentsToKeep = new ArrayList<>();
if (lowestPermanentsCount > 0) {
TargetControlledPermanent target = new TargetControlledPermanent(lowestPermanentsCount, lowestPermanentsCount, filterPermanent, true);
if (target.choose(Outcome.Protect, player.getId(), source.getSourceId(), game)) {
if (target.choose(Outcome.Protect, player.getId(), source.getSourceId(), source, game)) {
for (Permanent permanent : allPermanentsOfType) {
if (permanent != null && target.getTargets().contains(permanent.getId())) {
permanentsToKeep.add(permanent);

View file

@ -39,7 +39,7 @@ public class BrainstormEffect extends OneShotEffect {
private boolean putOnLibrary(Player player, Ability source, Game game) {
TargetCardInHand target = new TargetCardInHand();
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
if (target.canChoose(player.getId(), source, game)) {
player.chooseTarget(Outcome.ReturnToHand, target, source, game);
Card card = player.getHand().get(target.getFirstTarget(), game);
if (card != null) {

View file

@ -59,7 +59,7 @@ public class CantBeCounteredControlledEffect extends ContinuousRuleModifyingEffe
public boolean applies(GameEvent event, Ability source, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null && spell.isControlledBy(source.getControllerId())
&& filterTarget.match(spell, source.getSourceId(), source.getControllerId(), game)) {
&& filterTarget.match(spell, source.getControllerId(), source, game)) {
if (filterSource == null) {
return true;
} else {

View file

@ -41,7 +41,7 @@ public class CantBeCounteredSourceEffect extends ContinuousRuleModifyingEffectIm
@Override
public String getInfoMessage(Ability source, GameEvent event, Game game) {
StackObject stackObject = game.getStack().getStackObject(event.getTargetId());
MageObject sourceObject = game.getObject(source.getSourceId());
MageObject sourceObject = game.getObject(source);
if (stackObject != null && sourceObject != null) {
return sourceObject.getLogName() + " can't be countered by " + stackObject.getName();
}

Some files were not shown because too many files have changed in this diff Show more