Refactor: replaced sourceId by source and introduced source param in some methods (part 2);

This commit is contained in:
Oleg Agafonov 2020-12-13 02:01:49 +04:00
parent db239a1055
commit 35f5a8257b
50 changed files with 189 additions and 118 deletions

View file

@ -56,7 +56,7 @@ class BoxOfFreerangeGoblinsEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
CreateTokenEffect effect = new CreateTokenEffect(new GoblinToken(), amount);
effect.apply(game, source);
return true;

View file

@ -68,7 +68,7 @@ class BubblingMuckTriggeredAbility extends DelayedTriggeredManaAbility {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent land = game.getPermanentOrLKIBattlefield(event.getTargetId());
if (land != null && filter.match(land, game)) {
if (land != null && filter.match(land, getSourceId(), getControllerId(), game)) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(land.getControllerId()));
}

View file

@ -51,8 +51,8 @@ class CantonicaCasinoEffect extends OneShotEffect {
Player you = game.getPlayer(source.getControllerId());
if (you != null) {
// Roll two six-sided dice
int dice1 = you.rollDice(game, 6);
int dice2 = you.rollDice(game, 6);
int dice1 = you.rollDice(source, game, 6);
int dice2 = you.rollDice(source, game, 6);
if (dice1 == dice2) {
// If you roll doubles, gain 10 life

View file

@ -119,7 +119,7 @@ class ChaosMoonOddTriggeredAbility extends DelayedTriggeredManaAbility {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent land = game.getPermanentOrLKIBattlefield(event.getTargetId());
if (land != null && filter.match(land, game)) {
if (land != null && filter.match(land, getSourceId(), getControllerId(), game)) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(land.getControllerId()));
}

View file

@ -60,7 +60,7 @@ class ChickenEggEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int result = controller.rollDice(game, 6);
int result = controller.rollDice(source, game, 6);
if (result == 6) {
new SacrificeSourceEffect().apply(game, source);
return (new CreateTokenEffect(new GiantBirdToken(), 1)).apply(game, source);

View file

@ -63,7 +63,7 @@ class ClamIAmEffect extends ReplacementEffectImpl {
if (numSides == 6 && event.getAmount() == 3) {
if (player.chooseUse(outcome, "Reroll the die?", source, game)) {
game.informPlayers(player.getLogName() + " chose to reroll the die.");
event.setAmount(player.rollDice(game, 6));
event.setAmount(player.rollDice(source, game, 6));
}
}
}

View file

@ -63,8 +63,8 @@ class ElvishImpersonatorsEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int firstRoll = controller.rollDice(game, 6);
int secondRoll = controller.rollDice(game, 6);
int firstRoll = controller.rollDice(source, game, 6);
int secondRoll = controller.rollDice(source, game, 6);
game.addEffect(new SetPowerToughnessSourceEffect(firstRoll, secondRoll, Duration.WhileOnBattlefield, SubLayer.SetPT_7b), source);
return true;
}

View file

@ -86,7 +86,10 @@ class ForbiddenOrchardTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
return event.getSourceId().equals(getSourceId()) && !game.inCheckPlayableState();
if (game.inCheckPlayableState()) { // Ignored - see GameEvent.TAPPED_FOR_MANA
return false;
}
return event.getSourceId().equals(getSourceId());
}
@Override

View file

@ -64,8 +64,8 @@ class FreeRangeChickenEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int firstRoll = controller.rollDice(game, 6);
int secondRoll = controller.rollDice(game, 6);
int firstRoll = controller.rollDice(source, game, 6);
int secondRoll = controller.rollDice(source, game, 6);
if (firstRoll == secondRoll) {
game.addEffect(new BoostSourceEffect(firstRoll, firstRoll, Duration.EndOfTurn), source);
}

View file

@ -153,8 +153,8 @@ class GoToJailUpkeepEffect extends OneShotEffect {
Player opponent = game.getPlayer(opponentId);
if (opponent != null) {
int thisRoll = opponent.rollDice(game, 6);
int thatRoll = opponent.rollDice(game, 6);
int thisRoll = opponent.rollDice(source, game, 6);
int thatRoll = opponent.rollDice(source, game, 6);
if (thisRoll == thatRoll) {
return permanent.sacrifice(source, game);
}

View file

@ -71,8 +71,8 @@ class GarbageElementalCEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int thisRoll = controller.rollDice(game, 6);
int thatRoll = controller.rollDice(game, 6);
int thisRoll = controller.rollDice(source, game, 6);
int thatRoll = controller.rollDice(source, game, 6);
Token token = new GoblinToken();
return token.putOntoBattlefield(Math.abs(thatRoll - thisRoll), game, source, source.getControllerId());

View file

@ -72,7 +72,7 @@ class GarbageElementalDEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (controller != null && opponent != null) {
int damage = controller.rollDice(game, 6);
int damage = controller.rollDice(source, game, 6);
return game.damagePlayerOrPlaneswalker(opponent.getId(), damage, source.getId(), source, game, false, true) > 0;
}
return false;

View file

@ -94,13 +94,13 @@ class GoblinBowlingTeamEffect extends ReplacementEffectImpl {
if (damageEvent.getType() == GameEvent.EventType.DAMAGE_PLAYER) {
Player targetPlayer = game.getPlayer(event.getTargetId());
if (targetPlayer != null) {
targetPlayer.damage(CardUtil.addWithOverflowCheck(damageEvent.getAmount(), controller.rollDice(game, 6)), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
targetPlayer.damage(CardUtil.addWithOverflowCheck(damageEvent.getAmount(), controller.rollDice(source, game, 6)), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
return true;
}
} else {
Permanent targetPermanent = game.getPermanent(event.getTargetId());
if (targetPermanent != null) {
targetPermanent.damage(CardUtil.addWithOverflowCheck(damageEvent.getAmount(), controller.rollDice(game, 6)), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
targetPermanent.damage(CardUtil.addWithOverflowCheck(damageEvent.getAmount(), controller.rollDice(source, game, 6)), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
return true;
}
}

View file

@ -66,7 +66,7 @@ class GoblinTutorEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
Effect effect = null;
// 2 - A card named Goblin Tutor

View file

@ -75,7 +75,7 @@ class GroundPounderEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
game.addEffect(new BoostSourceEffect(amount, amount, Duration.EndOfTurn), source);
return true;
}

View file

@ -56,7 +56,7 @@ class GrowthSpurtEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int result = controller.rollDice(game, 6);
int result = controller.rollDice(source, game, 6);
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
ContinuousEffect effect = new BoostTargetEffect(result, result, Duration.EndOfTurn);

View file

@ -67,7 +67,7 @@ class HammerHelperEffect extends OneShotEffect {
source.getEffects().get(0).setTargetPointer(new FixedTarget(targetCreature.getId()));
game.addEffect(new GainControlTargetEffect(Duration.EndOfTurn), source);
targetCreature.untap(game);
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
game.addEffect(new BoostTargetEffect(amount, 0, Duration.EndOfTurn), source);
game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn), source);
return true;

View file

@ -70,7 +70,7 @@ class HammerJammerEntersEffect extends EntersBattlefieldWithXCountersEffect {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanentEntering(source.getSourceId());
if (controller != null && permanent != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects"); // the basic event is the EntersBattlefieldEvent, so use already applied replacement effects from that event
permanent.addCounters(CounterType.P1P1.createInstance(amount), source, game, appliedEffects);
return super.apply(game, source);

View file

@ -93,7 +93,7 @@ class HydradoodleEffect extends OneShotEffect {
if (amount > 0) {
int total = 0;
for (int roll = 0; roll < amount; roll++) {
int thisRoll = controller.rollDice(game, 6);
int thisRoll = controller.rollDice(source, game, 6);
total += thisRoll;
}

View file

@ -64,7 +64,7 @@ class InhumaniacEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
if (amount >= 3 && amount <= 4) {
permanent.addCounters(CounterType.P1P1.createInstance(1), source, game);
} else if (amount >= 5) {

View file

@ -77,7 +77,7 @@ class JackInTheMoxManaEffect extends ManaEffect {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
switch (amount) {
case 1:
permanent.sacrifice(source, game);

View file

@ -78,7 +78,7 @@ class JumboImpEffect extends EntersBattlefieldWithXCountersEffect {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanentEntering(source.getSourceId());
if (controller != null && permanent != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects"); // the basic event is the EntersBattlefieldEvent, so use already applied replacement effects from that event
permanent.addCounters(CounterType.P1P1.createInstance(amount), source, game, appliedEffects);
return super.apply(game, source);
@ -114,7 +114,7 @@ class JumboImpAddCountersEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
permanent.addCounters(CounterType.P1P1.createInstance(amount), source, game);
return true;
}
@ -143,7 +143,7 @@ class JumboImpRemoveCountersEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
permanent.removeCounters(CounterType.P1P1.createInstance(amount), source, game);
return true;
}

View file

@ -60,7 +60,7 @@ class KrazyKowEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int result = controller.rollDice(game, 6);
int result = controller.rollDice(source, game, 6);
if (result == 1) {
new SacrificeSourceEffect().apply(game, source);
return new DamageEverythingEffect(3).apply(game, source);

View file

@ -73,7 +73,7 @@ class LobeLobberEffect extends OneShotEffect {
if (controller != null && equipment != null && player != null) {
player.damage(1, source.getSourceId(), source, game);
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
if (amount >= 5) {
new UntapSourceEffect().apply(game, source);
}

View file

@ -65,7 +65,7 @@ class MadScienceFairManaEffect extends ManaEffect {
if (game != null) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
if (amount <= 3) {
return Mana.ColorlessMana(1);
} else {

View file

@ -66,7 +66,7 @@ class PainiacEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
game.addEffect(new BoostSourceEffect(amount, 0, Duration.EndOfTurn), source);
return true;
}

View file

@ -64,7 +64,7 @@ class PoultrygeistEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int result = controller.rollDice(game, 6);
int result = controller.rollDice(source, game, 6);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (result == 1) {

View file

@ -52,8 +52,10 @@ class PriceOfGloryAbility extends TriggeredAbilityImpl {
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TAPPED_FOR_MANA
&& !game.inCheckPlayableState();
if (game.inCheckPlayableState()) {
return false;
}
return event.getType() == GameEvent.EventType.TAPPED_FOR_MANA;
}
@Override

View file

@ -116,7 +116,7 @@ class RicochetEffect extends OneShotEffect {
}
do {
for (Player player : playerRolls.keySet()) {
playerRolls.put(player, player.rollDice(game, 6));
playerRolls.put(player, player.rollDice(source, game, 6));
}
int minValueInMap = Collections.min(playerRolls.values());
for (Map.Entry<Player, Integer> mapEntry : new HashSet<>(playerRolls.entrySet())) {

View file

@ -67,7 +67,7 @@ class SparkFiendEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int roll = controller.rollDice(game, 6) + controller.rollDice(game, 6);
int roll = controller.rollDice(source, game, 6) + controller.rollDice(source, game, 6);
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject instanceof Permanent) {
Permanent sourcePermanent = (Permanent) mageObject;
@ -112,7 +112,7 @@ class SparkFiendUpkeepEffect extends OneShotEffect {
if (controller != null) {
if (game.getState().getValue("SparkFiend" + source.getSourceId().toString()) != null
&& (Integer) game.getState().getValue("SparkFiend" + source.getSourceId().toString()) != 0) {
int roll = controller.rollDice(game, 6) + controller.rollDice(game, 6);
int roll = controller.rollDice(source, game, 6) + controller.rollDice(source, game, 6);
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject instanceof Permanent) {
Permanent sourcePermanent = (Permanent) mageObject;

View file

@ -70,7 +70,7 @@ class StrategySchmategyffect extends OneShotEffect {
// 5 - Each player discards their hand and draws seven cards.
// 6 - Repeat this process two more times
while (numTimesToDo > 0) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
numTimesToDo--;
if (amount == 2) {
List<Permanent> artifactPermanents = game.getBattlefield().getActivePermanents(new FilterArtifactPermanent(), controller.getId(), game);

View file

@ -132,11 +132,11 @@ class SwordOfDungeonsAndDragonsEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int count = 1;
int amount = controller.rollDice(game, 20);
int amount = controller.rollDice(source, game, 20);
while (amount == 20) {
count += 1;
amount = controller.rollDice(game, 20);
amount = controller.rollDice(source, game, 20);
}
return new CreateTokenEffect(new DragonTokenGold(), count).apply(game, source);
}

View file

@ -68,7 +68,7 @@ class TempOfTheDamnedEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
return new AddCountersSourceEffect(CounterType.FUNK.createInstance(controller.rollDice(game, 6))).apply(game, source);
return new AddCountersSourceEffect(CounterType.FUNK.createInstance(controller.rollDice(source, game, 6))).apply(game, source);
}
return false;
}

View file

@ -97,7 +97,7 @@ class TheBigIdeaReplacementEffect extends ReplacementEffectImpl {
if (controller != null) {
discard();
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
event.setAmount(event.getAmount() + amount);
return true;
}
@ -139,7 +139,7 @@ class TheBigIdeaEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
return new CreateTokenEffect(new BrainiacToken(), amount).apply(game, source);
}
return false;

View file

@ -72,7 +72,7 @@ class TimeOutEffect extends OneShotEffect {
if (owner == null) {
return false;
}
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
controller.putCardOnTopXOfLibrary(permanent, game, source, amount, true);
return true;
}

View file

@ -56,8 +56,10 @@ class TreasureNabberAbility extends TriggeredAbilityImpl {
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TAPPED_FOR_MANA
&& !game.inCheckPlayableState();
if (game.inCheckPlayableState()) {
return false;
}
return event.getType() == GameEvent.EventType.TAPPED_FOR_MANA;
}
@Override

View file

@ -72,7 +72,7 @@ class UrzasScienceFairProjectEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int amount = controller.rollDice(game, 6);
int amount = controller.rollDice(source, game, 6);
Effect effect = null;
// 1 - -2/-2 until end of turn.

View file

@ -58,8 +58,10 @@ class ZhurTaaDruidAbility extends TriggeredAbilityImpl {
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TAPPED_FOR_MANA
&& !game.inCheckPlayableState();
if (game.inCheckPlayableState()) {
return false;
}
return event.getType() == GameEvent.EventType.TAPPED_FOR_MANA;
}
@Override

View file

@ -3043,6 +3043,11 @@ public class TestPlayer implements Player {
computerPlayer.setCanLoseLife(canLoseLife);
}
@Override
public int loseLife(int amount, Game game, Ability source, boolean atCombat, UUID attackerId) {
return computerPlayer.loseLife(amount, game, source, atCombat, attackerId);
}
@Override
public int loseLife(int amount, Game game, Ability source, boolean atCombat) {
return computerPlayer.loseLife(amount, game, source, atCombat);
@ -3300,13 +3305,13 @@ public class TestPlayer implements Player {
}
@Override
public int rollDice(Game game, int numSides) {
return computerPlayer.rollDice(game, numSides);
public int rollDice(Ability source, Game game, int numSides) {
return computerPlayer.rollDice(source, game, numSides);
}
@Override
public int rollDice(Game game, List<UUID> appliedEffects, int numSides) {
return computerPlayer.rollDice(game, appliedEffects, numSides);
public int rollDice(Ability source, Game game, List<UUID> appliedEffects, int numSides) {
return computerPlayer.rollDice(source, game, appliedEffects, numSides);
}
@Override
@ -4007,17 +4012,17 @@ public class TestPlayer implements Player {
}
@Override
public PlanarDieRoll rollPlanarDie(Game game) {
public PlanarDieRoll rollPlanarDie(Ability source, Game game) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public PlanarDieRoll rollPlanarDie(Game game, List<UUID> appliedEffects) {
public PlanarDieRoll rollPlanarDie(Ability source, Game game, List<UUID> appliedEffects) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public PlanarDieRoll rollPlanarDie(Game game, List<UUID> appliedEffects, int numberChaosSides, int numberPlanarSides) {
public PlanarDieRoll rollPlanarDie(Ability source, Game game, List<UUID> appliedEffects, int numberChaosSides, int numberPlanarSides) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

View file

@ -121,6 +121,11 @@ public class PlayerStub implements Player {
}
@Override
public int loseLife(int amount, Game game, Ability source, boolean atCombat, UUID attackerId) {
return 0;
}
@Override
public int loseLife(int amount, Game game, Ability source, boolean atCombat) {
return 0;
@ -625,12 +630,12 @@ public class PlayerStub implements Player {
}
@Override
public int rollDice(Game game, int numSides) {
public int rollDice(Ability source, Game game, int numSides) {
return 1;
}
@Override
public int rollDice(Game game, List<UUID> appliedEffects, int numSides) {
public int rollDice(Ability source, Game game, List<UUID> appliedEffects, int numSides) {
return 1;
}
@ -1330,17 +1335,17 @@ public class PlayerStub implements Player {
}
@Override
public PlanarDieRoll rollPlanarDie(Game game) {
public PlanarDieRoll rollPlanarDie(Ability source, Game game) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public PlanarDieRoll rollPlanarDie(Game game, List<UUID> appliedEffects) {
public PlanarDieRoll rollPlanarDie(Ability source, Game game, List<UUID> appliedEffects) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public PlanarDieRoll rollPlanarDie(Game game, List<UUID> appliedEffects, int numberChaosSides, int numberPlanarSides) {
public PlanarDieRoll rollPlanarDie(Ability source, Game game, List<UUID> appliedEffects, int numberChaosSides, int numberPlanarSides) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

View file

@ -101,7 +101,7 @@ public class RandomTest {
for (int x = 0; x < weight; x++) {
for (int y = 0; y < height; y++) {
// roll dice
int diceVal = player.rollDice(game, 12);
int diceVal = player.rollDice(null, game, 12);
int colorMult = Math.floorDiv(255, 12);
image.setRGB(x, y, new Color(colorMult * diceVal, colorMult * diceVal, colorMult * diceVal).getRGB());
@ -124,7 +124,7 @@ public class RandomTest {
for (int x = 0; x < weight; x++) {
for (int y = 0; y < height; y++) {
// roll planar dice
PlanarDieRoll res = player.rollPlanarDie(game);
PlanarDieRoll res = player.rollPlanarDie(null, game);
image.setRGB(x, y, new Color(
res.equals(PlanarDieRoll.CHAOS_ROLL) ? 255 : 0,
res.equals(PlanarDieRoll.PLANAR_ROLL) ? 255 : 0,

View file

@ -47,7 +47,7 @@ public class RollDiceEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && mageObject != null) {
controller.rollDice(game, numSides);
controller.rollDice(source, game, numSides);
return true;
}
return false;

View file

@ -61,7 +61,7 @@ public class RollPlanarDieEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && mageObject != null) {
PlanarDieRoll planarRoll = controller.rollPlanarDie(game);
PlanarDieRoll planarRoll = controller.rollPlanarDie(source, game);
if (planarRoll == PlanarDieRoll.CHAOS_ROLL && chaosEffects != null && chaosTargets != null) {
for (int i = 0; i < chaosTargets.size(); i++) {
Target target = chaosTargets.get(i);

View file

@ -1,4 +1,3 @@
package mage.abilities.mana;

View file

@ -2220,7 +2220,7 @@ public abstract class GameImpl implements Game, Serializable {
}
}
//20091005 - 704.5q If a creature is attached to an object or player, it becomes unattached and remains on the battlefield.
// Similarly, if a permanent that’s neither an Aura, an Equipment, nor a Fortification is attached to an object or player,
// Similarly, if a permanent that's neither an Aura, an Equipment, nor a Fortification is attached to an object or player,
// it becomes unattached and remains on the battlefield.
if (!perm.getAttachments().isEmpty()) {
for (UUID attachmentId : perm.getAttachments()) {

View file

@ -290,7 +290,11 @@ public class Combat implements Serializable, Copyable<Combat> {
if (!game.isSimulation()) {
Player player = game.getPlayer(attackingPlayerId);
if (player != null) {
game.informPlayers(player.getLogName() + " attacks with " + groups.size() + (groups.size() == 1 ? " creature" : " creatures"));
if (groups.size() > 0) {
game.informPlayers(player.getLogName() + " attacks with " + groups.size() + (groups.size() == 1 ? " creature" : " creatures"));
} else {
game.informPlayers(player.getLogName() + " skip attack");
}
}
}
}
@ -615,7 +619,7 @@ public class Combat implements Serializable, Copyable<Combat> {
* Add info about attacker blocked by blocker to the game log
*/
private void logBlockerInfo(Player defender, Game game) {
boolean shownDefendingPlayer = game.getPlayers().size() < 3; // only two players no ned to sow the attacked player
boolean shownDefendingPlayer = game.getPlayers().size() < 3; // only two players no need to saw the attacked player
for (CombatGroup group : game.getCombat().getGroups()) {
if (group.defendingPlayerId.equals(defender.getId())) {
if (!shownDefendingPlayer) {

View file

@ -1153,9 +1153,9 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
logName = this.getLogName();
}
if (this.isCreature()) {
game.informPlayers(logName + " died");
game.informPlayers(logName + " died" + CardUtil.getSourceLogName(game, " by ", source, "", ""));
} else {
game.informPlayers(logName + " was destroyed");
game.informPlayers(logName + " was destroyed" + CardUtil.getSourceLogName(game, " by ", source, "", ""));
}
}
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DESTROYED_PERMANENT, objectId, source, controllerId));
@ -1174,7 +1174,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
moveToZone(Zone.GRAVEYARD, source, game, false);
Player player = game.getPlayer(getControllerId());
if (player != null && !game.isSimulation()) {
game.informPlayers(player.getLogName() + " sacrificed " + this.getLogName());
game.informPlayers(player.getLogName() + " sacrificed " + this.getLogName() + CardUtil.getSourceLogName(game, source));
}
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.SACRIFICED_PERMANENT, objectId, source, controllerId));
return true;

View file

@ -86,8 +86,11 @@ public interface Player extends MageItem, Copyable<Player> {
* @param game
* @param source can be null for default game events like mana burn
* @param atCombat was the source combat damage
* @param attackerId id of the attacker for combat events (can be null)
* @return
*/
int loseLife(int amount, Game game, Ability source, boolean atCombat, UUID attackerId);
int loseLife(int amount, Game game, Ability source, boolean atCombat);
/**
@ -441,15 +444,15 @@ public interface Player extends MageItem, Copyable<Player> {
boolean flipCoin(Ability source, Game game, boolean winnable, List<UUID> appliedEffects);
int rollDice(Game game, int numSides);
int rollDice(Ability source, Game game, int numSides);
int rollDice(Game game, List<UUID> appliedEffects, int numSides);
int rollDice(Ability source, Game game, List<UUID> appliedEffects, int numSides);
PlanarDieRoll rollPlanarDie(Game game);
PlanarDieRoll rollPlanarDie(Ability source, Game game);
PlanarDieRoll rollPlanarDie(Game game, List<UUID> appliedEffects);
PlanarDieRoll rollPlanarDie(Ability source, Game game, List<UUID> appliedEffects);
PlanarDieRoll rollPlanarDie(Game game, List<UUID> appliedEffects, int numberChaosSides, int numberPlanarSides);
PlanarDieRoll rollPlanarDie(Ability source, Game game, List<UUID> appliedEffects, int numberChaosSides, int numberPlanarSides);
Card discardOne(boolean random, boolean payForCost, Ability source, Game game);

View file

@ -812,7 +812,7 @@ public abstract class PlayerImpl implements Player, Serializable {
}
// write info to game log first so game log infos from triggered or replacement effects follow in the game log
if (!game.isSimulation()) {
game.informPlayers(getLogName() + " discards " + card.getLogName());
game.informPlayers(getLogName() + " discards " + card.getLogName() + CardUtil.getSourceLogName(game, source));
}
/* If a card is discarded while Rest in Peace is on the battlefield, abilities that function
* when a card is discarded (such as madness) still work, even though that card never reaches
@ -962,9 +962,9 @@ public abstract class PlayerImpl implements Player, Serializable {
if (cards.isEmpty()) {
return true;
}
game.informPlayers(getLogName() + " shuffels " + CardUtil.numberToText(cards.size(), "a")
game.informPlayers(getLogName() + " shuffles " + CardUtil.numberToText(cards.size(), "a")
+ " card" + (cards.size() == 1 ? "" : "s")
+ " into their library.");
+ " into their library" + CardUtil.getSourceLogName(game, source));
boolean status = moveCards(cards, Zone.LIBRARY, source, game);
shuffleLibrary(source, game);
return status;
@ -995,7 +995,7 @@ public abstract class PlayerImpl implements Player, Serializable {
+ getLogName()
+ "'s library "
+ CardUtil.numberToOrdinalText(xFromTheTop)
+ " from the top");
+ " from the top" + CardUtil.getSourceLogName(game, source, cardInLib.getId()));
}
} else {
return false;
@ -1501,7 +1501,7 @@ public abstract class PlayerImpl implements Player, Serializable {
if ((ability.isUsesStack()
|| ability.getRuleVisible())
&& !game.isSimulation()) {
game.informPlayers(ability.getGameLogMessage(game));
game.informPlayers(getLogName() + ability.getGameLogMessage(game));
}
if (!ability.isUsesStack()) {
ability.resolve(game);
@ -1648,7 +1648,7 @@ public abstract class PlayerImpl implements Player, Serializable {
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.SHUFFLE_LIBRARY, playerId, source, playerId))) {
this.library.shuffle();
if (!game.isSimulation()) {
game.informPlayers(getLogName() + "'s library is shuffled");
game.informPlayers(getLogName() + "'s library is shuffled" + CardUtil.getSourceLogName(game, source));
}
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SHUFFLED, playerId, source, playerId));
}
@ -1694,6 +1694,7 @@ public abstract class PlayerImpl implements Player, Serializable {
sb.append(", ");
}
}
sb.append(CardUtil.getSourceLogName(game, source));
game.informPlayers(sb.toString());
}
}
@ -1991,7 +1992,7 @@ public abstract class PlayerImpl implements Player, Serializable {
}
@Override
public int loseLife(int amount, Game game, Ability source, boolean atCombat) {
public int loseLife(int amount, Game game, Ability source, boolean atCombat, UUID attackerId) {
if (!canLoseLife || !this.isInGame()) {
return 0;
}
@ -2000,7 +2001,12 @@ public abstract class PlayerImpl implements Player, Serializable {
if (!game.replaceEvent(event)) {
this.life = CardUtil.subtractWithOverflowCheck(this.life, event.getAmount());
if (!game.isSimulation()) {
game.informPlayers(this.getLogName() + " loses " + event.getAmount() + " life");
UUID needId = attackerId;
if (needId == null) {
needId = source == null ? null : source.getSourceId();
}
game.informPlayers(this.getLogName() + " loses " + event.getAmount() + " life"
+ (atCombat ? " at combat" : "") + CardUtil.getSourceLogName(game, " from ", needId, "", ""));
}
if (amount > 0) {
game.fireEvent(new GameEvent(GameEvent.EventType.LOST_LIFE,
@ -2011,6 +2017,11 @@ public abstract class PlayerImpl implements Player, Serializable {
return 0;
}
@Override
public int loseLife(int amount, Game game, Ability source, boolean atCombat) {
return loseLife(amount, game, source, atCombat, null);
}
@Override
public boolean isCanGainLife() {
return canGainLife;
@ -2034,7 +2045,7 @@ public abstract class PlayerImpl implements Player, Serializable {
// this.life += event.getAmount();
this.life = CardUtil.addWithOverflowCheck(this.life, event.getAmount());
if (!game.isSimulation()) {
game.informPlayers(this.getLogName() + " gains " + event.getAmount() + " life");
game.informPlayers(this.getLogName() + " gains " + event.getAmount() + " life" + CardUtil.getSourceLogName(game, source));
}
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.GAINED_LIFE,
playerId, source, playerId, event.getAmount()));
@ -2101,7 +2112,7 @@ public abstract class PlayerImpl implements Player, Serializable {
GameEvent damageToLifeLossEvent = new GameEvent(GameEvent.EventType.DAMAGE_CAUSES_LIFE_LOSS,
playerId, source, playerId, actualDamage, combatDamage);
if (!game.replaceEvent(damageToLifeLossEvent)) {
this.loseLife(damageToLifeLossEvent.getAmount(), game, source, combatDamage);
this.loseLife(damageToLifeLossEvent.getAmount(), game, source, combatDamage, attackerId);
}
}
if (sourceAbilities != null && sourceAbilities.containsKey(LifelinkAbility.getInstance().getId())) {
@ -2128,7 +2139,7 @@ public abstract class PlayerImpl implements Player, Serializable {
game.informPlayers(damage + " damage "
+ (sourceObject == null ? "" : "from " + sourceObject.getLogName())
+ " to " + getLogName()
+ (damage > 1 ? " were" : "was") + " prevented because of protection.");
+ (damage > 1 ? " were" : "was") + " prevented because of protection");
}
}
return 0;
@ -2592,7 +2603,7 @@ public abstract class PlayerImpl implements Player, Serializable {
}
if (!game.isSimulation()) {
game.informPlayers(searchInfo);
game.informPlayers(searchInfo + CardUtil.getSourceLogName(game, source));
}
// https://www.reddit.com/r/magicTCG/comments/jj8gh9/opposition_agent_and_panglacial_wurm_interaction/
@ -2648,7 +2659,7 @@ public abstract class PlayerImpl implements Player, Serializable {
// END SEARCH
if (takeControl) {
CardUtil.takeControlUnderPlayerEnd(game, searchingController, searchingPlayer);
game.informPlayers("Control of " + searchingPlayer.getLogName() + " is back");
game.informPlayers("Control of " + searchingPlayer.getLogName() + " is back" + CardUtil.getSourceLogName(game, source));
}
LibrarySearchedEvent searchedEvent = new LibrarySearchedEvent(targetPlayer.getId(), source, searchingPlayer.getId(), target);
@ -2745,7 +2756,8 @@ public abstract class PlayerImpl implements Player, Serializable {
FlipCoinEvent event = new FlipCoinEvent(playerId, source, result, chosen, winnable);
event.addAppliedEffects(appliedEffects);
game.replaceEvent(event);
game.informPlayers(getLogName() + " flipped " + CardUtil.booleanToFlipName(event.getResult()));
game.informPlayers(getLogName() + " flipped " + CardUtil.booleanToFlipName(event.getResult())
+ CardUtil.getSourceLogName(game, source));
if (event.getFlipCount() > 1) {
boolean canChooseHeads = event.getResult();
boolean canChooseTails = !event.getResult();
@ -2766,7 +2778,8 @@ public abstract class PlayerImpl implements Player, Serializable {
game.informPlayers(getLogName() + " chose to keep " + CardUtil.booleanToFlipName(event.getResult()));
}
if (event.isWinnable()) {
game.informPlayers(getLogName() + " " + (event.getResult() == event.getChosen() ? "won" : "lost") + " the flip");
game.informPlayers(getLogName() + " " + (event.getResult() == event.getChosen() ? "won" : "lost") + " the flip"
+ CardUtil.getSourceLogName(game, source));
}
event.setAppliedEffects(appliedEffects);
game.fireEvent(event.createFlippedEvent());
@ -2777,31 +2790,30 @@ public abstract class PlayerImpl implements Player, Serializable {
}
@Override
public int rollDice(Game game, int numSides) {
return this.rollDice(game, null, numSides);
public int rollDice(Ability source, Game game, int numSides) {
return this.rollDice(source, game, null, numSides);
}
/**
* @param source
* @param game
* @param appliedEffects
* @param numSides Number of sides the dice has
* @return the number that the player rolled
*/
@Override
public int rollDice(Game game, List<UUID> appliedEffects, int numSides) {
public int rollDice(Ability source, Game game, List<UUID> appliedEffects, int numSides) {
int result = RandomUtil.nextInt(numSides) + 1;
if (!game.isSimulation()) {
game.informPlayers("[Roll a die] " + getLogName() + " rolled a "
+ result + " on a " + numSides + " sided die");
+ result + " on a " + numSides + " sided die" + CardUtil.getSourceLogName(game, source));
}
GameEvent event = new GameEvent(GameEvent.EventType.ROLL_DICE, playerId,
null, playerId, result, true);
GameEvent event = new GameEvent(GameEvent.EventType.ROLL_DICE, playerId, source, playerId, result, true);
event.setAppliedEffects(appliedEffects);
event.setAmount(result);
event.setData(numSides + "");
if (!game.replaceEvent(event)) {
GameEvent ge = new GameEvent(GameEvent.EventType.DICE_ROLLED, playerId, null,
playerId, event.getAmount(), event.getFlag());
GameEvent ge = new GameEvent(GameEvent.EventType.DICE_ROLLED, playerId, source, playerId, event.getAmount(), event.getFlag());
ge.setData(numSides + "");
game.fireEvent(ge);
}
@ -2809,13 +2821,13 @@ public abstract class PlayerImpl implements Player, Serializable {
}
@Override
public PlanarDieRoll rollPlanarDie(Game game) {
return this.rollPlanarDie(game, null);
public PlanarDieRoll rollPlanarDie(Ability source, Game game) {
return this.rollPlanarDie(source, game, null);
}
@Override
public PlanarDieRoll rollPlanarDie(Game game, List<UUID> appliedEffects) {
return rollPlanarDie(game, appliedEffects, 2, 2);
public PlanarDieRoll rollPlanarDie(Ability source, Game game, List<UUID> appliedEffects) {
return rollPlanarDie(source, game, appliedEffects, 2, 2);
}
/**
@ -2829,7 +2841,7 @@ public abstract class PlayerImpl implements Player, Serializable {
* or NilRoll
*/
@Override
public PlanarDieRoll rollPlanarDie(Game game, List<UUID> appliedEffects, int numberChaosSides, int numberPlanarSides) {
public PlanarDieRoll rollPlanarDie(Ability source, Game game, List<UUID> appliedEffects, int numberChaosSides, int numberPlanarSides) {
int result = RandomUtil.nextInt(9) + 1;
PlanarDieRoll roll = PlanarDieRoll.NIL_ROLL;
if (numberChaosSides + numberPlanarSides > 9) {
@ -2843,15 +2855,15 @@ public abstract class PlayerImpl implements Player, Serializable {
}
if (!game.isSimulation()) {
game.informPlayers("[Roll the planar die] " + getLogName()
+ " rolled a " + roll + " on the planar die");
+ " rolled a " + roll + " on the planar die" + CardUtil.getSourceLogName(game, source));
}
GameEvent event = new GameEvent(GameEvent.EventType.ROLL_PLANAR_DIE,
playerId, null, playerId, result, true);
playerId, source, playerId, result, true);
event.setAppliedEffects(appliedEffects);
event.setData(roll + "");
if (!game.replaceEvent(event)) {
GameEvent ge = new GameEvent(GameEvent.EventType.PLANAR_DIE_ROLLED,
playerId, null, playerId, event.getAmount(), event.getFlag());
playerId, source, playerId, event.getAmount(), event.getFlag());
ge.setData(roll + "");
game.fireEvent(ge);
}
@ -4078,7 +4090,8 @@ public abstract class PlayerImpl implements Player, Serializable {
if (eventPlayer != null && fromZone != null) {
game.informPlayers(eventPlayer.getLogName() + " puts "
+ (info.faceDown ? "a card face down " : permanent.getLogName()) + " from "
+ fromZone.toString().toLowerCase(Locale.ENGLISH) + " onto the Battlefield");
+ fromZone.toString().toLowerCase(Locale.ENGLISH) + " onto the Battlefield"
+ CardUtil.getSourceLogName(game, source, permanent.getId()));
}
}
}
@ -4180,7 +4193,8 @@ public abstract class PlayerImpl implements Player, Serializable {
game.informPlayers(getLogName() + " puts "
+ (withName ? card.getLogName() : (card.isFaceDown(game) ? "a face down card" : "a card"))
+ " from " + fromZone.toString().toLowerCase(Locale.ENGLISH) + ' '
+ (card.isOwnedBy(this.getId()) ? "into their hand" : "into its owner's hand")
+ (card.isOwnedBy(this.getId()) ? "into their hand" : "into its owner's hand"
+ CardUtil.getSourceLogName(game, source, card.getId()))
);
}
result = true;
@ -4275,6 +4289,7 @@ public abstract class PlayerImpl implements Player, Serializable {
} else {
sb.append("it into its owner's graveyard");
}
sb.append(CardUtil.getSourceLogName(game, source, card.getId()));
game.informPlayers(sb.toString());
}
result = true;
@ -4307,6 +4322,7 @@ public abstract class PlayerImpl implements Player, Serializable {
sb.append(" of ").append(player.getLogName()).append("'s library");
}
}
sb.append(CardUtil.getSourceLogName(game, source, card.getId()));
game.informPlayers(sb.toString());
}
result = true;
@ -4338,6 +4354,7 @@ public abstract class PlayerImpl implements Player, Serializable {
sb.append(" to ").append(player.getLogName()).append("'s command zone");
}
}
sb.append(CardUtil.getSourceLogName(game, source, card.getId()));
game.informPlayers(sb.toString());
}
result = true;
@ -4370,7 +4387,7 @@ public abstract class PlayerImpl implements Player, Serializable {
game.informPlayers(this.getLogName() + " moves " + (withName ? card.getLogName()
+ (card.isCopy() ? " (Copy)" : "") : "a card face down") + ' '
+ (fromZone != null ? "from " + fromZone.toString().toLowerCase(Locale.ENGLISH)
+ ' ' : "") + "to the exile zone");
+ ' ' : "") + "to the exile zone" + CardUtil.getSourceLogName(game, source, card.getId()));
}
}
@ -4505,7 +4522,7 @@ public abstract class PlayerImpl implements Player, Serializable {
if (game.replaceEvent(event)) {
return false;
}
game.informPlayers(getLogName() + " scries " + event.getAmount());
game.informPlayers(getLogName() + " scries " + event.getAmount() + CardUtil.getSourceLogName(game, source));
Cards cards = new CardsImpl();
cards.addAll(getLibrary().getTopCards(game, event.getAmount()));
if (!cards.isEmpty()) {
@ -4527,7 +4544,7 @@ public abstract class PlayerImpl implements Player, Serializable {
if (game.replaceEvent(event)) {
return false;
}
game.informPlayers(getLogName() + " surveils " + event.getAmount());
game.informPlayers(getLogName() + " surveils " + event.getAmount() + CardUtil.getSourceLogName(game, source));
Cards cards = new CardsImpl();
cards.addAll(getLibrary().getTopCards(game, event.getAmount()));
if (!cards.isEmpty()) {

View file

@ -7,11 +7,9 @@ import mage.abilities.Abilities;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.SpellAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.VariableCost;
import mage.abilities.costs.mana.*;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.common.InfoEffect;
import mage.abilities.effects.common.asthought.CanPlayCardControllerEffect;
import mage.abilities.effects.common.asthought.YouMaySpendManaAsAnyColorToCastTargetEffect;
import mage.abilities.hint.Hint;
@ -1017,6 +1015,7 @@ public final class CardUtil {
/**
* Pay life in effects
*
* @param lifeToPay
* @param player
* @param source
@ -1046,4 +1045,34 @@ public final class CardUtil {
return false;
}
/**
* Generates source log name to insert into log messages
*
* @param game
* @param sourceId
* @param namePrefix if source object exists then that will be added before name
* @param namePostfix if source object exists then that will be added after name
* @param nonFoundText if source object not exists then it will be used
* @return
*/
public static String getSourceLogName(Game game, String namePrefix, UUID sourceId, String namePostfix, String nonFoundText) {
MageObject sourceObject = game.getObject(sourceId);
return (sourceObject == null ? nonFoundText : namePrefix + sourceObject.getLogName() + namePostfix);
}
public static String getSourceLogName(Game game, String namePrefix, Ability source, String namePostfix, String nonFoundText) {
return getSourceLogName(game, namePrefix, source == null ? null : source.getSourceId(), namePostfix, nonFoundText);
}
public static String getSourceLogName(Game game, Ability source) {
return CardUtil.getSourceLogName(game, " (source: ", source, ")", "");
}
public static String getSourceLogName(Game game, Ability source, UUID ignoreSourceId) {
if (ignoreSourceId != null && source != null && ignoreSourceId.equals(source.getSourceId())) {
return "";
}
return CardUtil.getSourceLogName(game, " (source: ", source, ")", "");
}
}