Refactor: replaced sourceId by source and introduced source param in some methods;

This commit is contained in:
Oleg Agafonov 2020-12-12 20:23:19 +04:00
parent 2bb472607b
commit db239a1055
3205 changed files with 7080 additions and 6795 deletions

View file

@ -19,12 +19,12 @@ public enum AttachedPermanentToughnessValue implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability source, Effect effect) {
public int calculate(Game game, Ability sourceAbility, Effect effect) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
Permanent enchantment = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
enchantment = game.getPermanentOrLKIBattlefield(sourceAbility.getSourceId());
}
if (enchantment == null) {
return 0;

View file

@ -31,9 +31,9 @@ public class AuraAttachedCount implements DynamicValue {
}
@Override
public int calculate(Game game, Ability source, Effect effect) {
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int count = 0;
Permanent p = game.getPermanent(source.getSourceId());
Permanent p = game.getPermanent(sourceAbility.getSourceId());
if (p != null) {
List<UUID> attachments = p.getAttachments();
for (UUID attachmentId : attachments) {

View file

@ -32,11 +32,11 @@ public class ColorsOfManaSpentToCastCount implements DynamicValue {
}
@Override
public int calculate(Game game, Ability source, Effect effect) {
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int count = 0;
Spell spell = game.getStack().getSpell(source.getSourceId());
Spell spell = game.getStack().getSpell(sourceAbility.getSourceId());
if (spell == null) {
MageObject mageObject = game.getLastKnownInformation(source.getSourceId(), Zone.STACK);
MageObject mageObject = game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.STACK);
if (mageObject instanceof Spell) {
spell = (Spell) mageObject;
}

View file

@ -13,9 +13,9 @@ public enum CommanderCastCountValue implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability source, Effect effect) {
public int calculate(Game game, Ability sourceAbility, Effect effect) {
CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
return watcher != null ? watcher.getPlayerCount(source.getControllerId()) : 0;
return watcher != null ? watcher.getPlayerCount(sourceAbility.getControllerId()) : 0;
}
@Override

View file

@ -24,7 +24,7 @@ public class EffectKeyValue implements DynamicValue {
}
@Override
public int calculate(Game game, Ability source, Effect effect) {
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return (Integer)effect.getValue(key);
}

View file

@ -32,9 +32,9 @@ public class EquipmentAttachedCount implements DynamicValue {
}
@Override
public int calculate(Game game, Ability source, Effect effect) {
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int count = 0;
Permanent permanent = game.getPermanent(source.getSourceId()); // don't change this - may affect other cards
Permanent permanent = game.getPermanent(sourceAbility.getSourceId()); // don't change this - may affect other cards
if (permanent != null) {
List<UUID> attachments = permanent.getAttachments();
for (UUID attachmentId : attachments) {

View file

@ -16,7 +16,7 @@ public enum GetKickerXValue implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability source, Effect effect) {
public int calculate(Game game, Ability sourceAbility, Effect effect) {
// calcs only kicker with X values
// kicker adds additional costs to spell ability
@ -24,7 +24,7 @@ public enum GetKickerXValue implements DynamicValue {
// kicker can be calls multiple times (use getKickedCounter)
int finalValue = 0;
Spell spell = game.getSpellOrLKIStack(source.getSourceId());
Spell spell = game.getSpellOrLKIStack(sourceAbility.getSourceId());
if (spell != null && spell.getSpellAbility() != null) {
int xValue = spell.getSpellAbility().getManaCostsToPay().getX();
for (Ability ability : spell.getAbilities()) {
@ -38,7 +38,7 @@ public enum GetKickerXValue implements DynamicValue {
if (haveVarCost) {
int kickedCount = ((KickerAbility) ability).getKickedCounter(game, source);
int kickedCount = ((KickerAbility) ability).getKickedCounter(game, sourceAbility);
if (kickedCount > 0) {
finalValue += kickedCount * xValue;
}

View file

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

View file

@ -16,10 +16,10 @@ public enum ManaSpentToCastCount implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability source, Effect effect) {
Spell spell = game.getStack().getSpell(source.getSourceId());
public int calculate(Game game, Ability sourceAbility, Effect effect) {
Spell spell = game.getStack().getSpell(sourceAbility.getSourceId());
if (spell == null) {
MageObject mageObject = game.getLastKnownInformation(source.getSourceId(), Zone.STACK);
MageObject mageObject = game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.STACK);
if (mageObject instanceof Spell) {
spell = (Spell) mageObject;
}

View file

@ -15,13 +15,13 @@ public enum MultikickerCount implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability source, Effect effect) {
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int count = 0;
Card card = game.getCard(source.getSourceId());
Card card = game.getCard(sourceAbility.getSourceId());
if (card != null) {
for (Ability ability : card.getAbilities()) {
for (Ability ability : card.getAbilities(game)) {
if (ability instanceof KickerAbility) {
count += ((KickerAbility) ability).getKickedCounter(game, source);
count += ((KickerAbility) ability).getKickedCounter(game, sourceAbility);
}
}
}

View file

@ -33,7 +33,7 @@ public class NumericSetToEffectValues implements DynamicValue {
}
@Override
public int calculate(Game game, Ability source, Effect effect) {
public int calculate(Game game, Ability sourceAbility, Effect effect) {
Object object = effect.getValue(valueKey);
if (object instanceof Integer) {
return (Integer) object;

View file

@ -16,11 +16,11 @@ public enum SunburstCount implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability source, Effect effect) {
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int count = 0;
if (!game.getStack().isEmpty()) {
StackObject spell = game.getStack().getFirst();
if (spell instanceof Spell && ((Spell) spell).getSourceId().equals(source.getSourceId())) {
if (spell instanceof Spell && ((Spell) spell).getSourceId().equals(sourceAbility.getSourceId())) {
Mana mana = ((Spell) spell).getSpellAbility().getManaCostsToPay().getPayment();
if (mana.getBlack() > 0) {
count++;

View file

@ -19,8 +19,9 @@ public class SweepNumber implements DynamicValue {
}
@Override
public int calculate(Game game, Ability source, Effect effect) {
Integer sweepNumber = (Integer) game.getState().getValue("sweep" + source.getSourceId() + game.getState().getZoneChangeCounter(source.getSourceId()));
public int calculate(Game game, Ability sourceAbility, Effect effect) {
Integer sweepNumber = (Integer) game.getState().getValue("sweep"
+ sourceAbility.getSourceId() + game.getState().getZoneChangeCounter(sourceAbility.getSourceId()));
return sweepNumber != null ? sweepNumber : 0;
}

View file

@ -14,8 +14,8 @@ public enum TargetConvertedManaCost implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability source, Effect effect) {
Card card = game.getCard(source.getFirstTarget());
public int calculate(Game game, Ability sourceAbility, Effect effect) {
Card card = game.getCard(sourceAbility.getFirstTarget());
if (card != null) {
return card.getConvertedManaCost();
}