From 35f5a8257b14212b72b9ecb88b624f998a914fe9 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sun, 13 Dec 2020 02:01:49 +0400 Subject: [PATCH] Refactor: replaced sourceId by source and introduced source param in some methods (part 2); --- .../mage/cards/b/BoxOfFreerangeGoblins.java | 2 +- Mage.Sets/src/mage/cards/b/BubblingMuck.java | 2 +- .../src/mage/cards/c/CantonicaCasino.java | 4 +- Mage.Sets/src/mage/cards/c/ChaosMoon.java | 2 +- Mage.Sets/src/mage/cards/c/ChickenEgg.java | 2 +- Mage.Sets/src/mage/cards/c/ClamIAm.java | 2 +- .../src/mage/cards/e/ElvishImpersonators.java | 4 +- .../src/mage/cards/f/ForbiddenOrchard.java | 5 +- .../src/mage/cards/f/FreeRangeChicken.java | 4 +- Mage.Sets/src/mage/cards/g/GOTOJAIL.java | 4 +- .../src/mage/cards/g/GarbageElementalC.java | 4 +- .../src/mage/cards/g/GarbageElementalD.java | 2 +- .../src/mage/cards/g/GoblinBowlingTeam.java | 4 +- Mage.Sets/src/mage/cards/g/GoblinTutor.java | 2 +- Mage.Sets/src/mage/cards/g/GroundPounder.java | 2 +- Mage.Sets/src/mage/cards/g/GrowthSpurt.java | 2 +- Mage.Sets/src/mage/cards/h/HammerHelper.java | 2 +- Mage.Sets/src/mage/cards/h/HammerJammer.java | 2 +- Mage.Sets/src/mage/cards/h/Hydradoodle.java | 2 +- Mage.Sets/src/mage/cards/i/Inhumaniac.java | 2 +- Mage.Sets/src/mage/cards/j/JackInTheMox.java | 2 +- Mage.Sets/src/mage/cards/j/JumboImp.java | 6 +- Mage.Sets/src/mage/cards/k/KrazyKow.java | 2 +- Mage.Sets/src/mage/cards/l/LobeLobber.java | 2 +- .../mage/cards/m/MadScienceFairProject.java | 2 +- Mage.Sets/src/mage/cards/p/Painiac.java | 2 +- Mage.Sets/src/mage/cards/p/Poultrygeist.java | 2 +- Mage.Sets/src/mage/cards/p/PriceOfGlory.java | 6 +- Mage.Sets/src/mage/cards/r/Ricochet.java | 2 +- Mage.Sets/src/mage/cards/s/SparkFiend.java | 4 +- .../src/mage/cards/s/StrategySchmategy.java | 2 +- .../cards/s/SwordOfDungeonsAndDragons.java | 4 +- .../src/mage/cards/t/TempOfTheDamned.java | 2 +- Mage.Sets/src/mage/cards/t/TheBigIdea.java | 4 +- Mage.Sets/src/mage/cards/t/TimeOut.java | 2 +- .../src/mage/cards/t/TreasureNabber.java | 6 +- .../mage/cards/u/UrzasScienceFairProject.java | 2 +- Mage.Sets/src/mage/cards/z/ZhurTaaDruid.java | 6 +- .../java/org/mage/test/player/TestPlayer.java | 19 ++-- .../java/org/mage/test/stub/PlayerStub.java | 15 ++-- .../java/org/mage/test/utils/RandomTest.java | 4 +- .../effects/common/RollDiceEffect.java | 2 +- .../effects/common/RollPlanarDieEffect.java | 2 +- .../mana/DelayedTriggeredManaAbility.java | 1 - Mage/src/main/java/mage/game/GameImpl.java | 2 +- .../main/java/mage/game/combat/Combat.java | 8 +- .../mage/game/permanent/PermanentImpl.java | 6 +- Mage/src/main/java/mage/players/Player.java | 13 +-- .../main/java/mage/players/PlayerImpl.java | 89 +++++++++++-------- Mage/src/main/java/mage/util/CardUtil.java | 33 ++++++- 50 files changed, 189 insertions(+), 118 deletions(-) diff --git a/Mage.Sets/src/mage/cards/b/BoxOfFreerangeGoblins.java b/Mage.Sets/src/mage/cards/b/BoxOfFreerangeGoblins.java index 60c7de54e8..c668a79bba 100644 --- a/Mage.Sets/src/mage/cards/b/BoxOfFreerangeGoblins.java +++ b/Mage.Sets/src/mage/cards/b/BoxOfFreerangeGoblins.java @@ -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; diff --git a/Mage.Sets/src/mage/cards/b/BubblingMuck.java b/Mage.Sets/src/mage/cards/b/BubblingMuck.java index ab7cd4cca8..38280e3352 100644 --- a/Mage.Sets/src/mage/cards/b/BubblingMuck.java +++ b/Mage.Sets/src/mage/cards/b/BubblingMuck.java @@ -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())); } diff --git a/Mage.Sets/src/mage/cards/c/CantonicaCasino.java b/Mage.Sets/src/mage/cards/c/CantonicaCasino.java index 0ae543d0ca..97d77800f0 100644 --- a/Mage.Sets/src/mage/cards/c/CantonicaCasino.java +++ b/Mage.Sets/src/mage/cards/c/CantonicaCasino.java @@ -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 diff --git a/Mage.Sets/src/mage/cards/c/ChaosMoon.java b/Mage.Sets/src/mage/cards/c/ChaosMoon.java index 3fd62f95bd..763bde414b 100644 --- a/Mage.Sets/src/mage/cards/c/ChaosMoon.java +++ b/Mage.Sets/src/mage/cards/c/ChaosMoon.java @@ -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())); } diff --git a/Mage.Sets/src/mage/cards/c/ChickenEgg.java b/Mage.Sets/src/mage/cards/c/ChickenEgg.java index 87018138c1..16b6dc2d81 100644 --- a/Mage.Sets/src/mage/cards/c/ChickenEgg.java +++ b/Mage.Sets/src/mage/cards/c/ChickenEgg.java @@ -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); diff --git a/Mage.Sets/src/mage/cards/c/ClamIAm.java b/Mage.Sets/src/mage/cards/c/ClamIAm.java index 5ac727a7c2..3986ab377e 100644 --- a/Mage.Sets/src/mage/cards/c/ClamIAm.java +++ b/Mage.Sets/src/mage/cards/c/ClamIAm.java @@ -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)); } } } diff --git a/Mage.Sets/src/mage/cards/e/ElvishImpersonators.java b/Mage.Sets/src/mage/cards/e/ElvishImpersonators.java index 484db9ede3..54a4ba63d4 100644 --- a/Mage.Sets/src/mage/cards/e/ElvishImpersonators.java +++ b/Mage.Sets/src/mage/cards/e/ElvishImpersonators.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/f/ForbiddenOrchard.java b/Mage.Sets/src/mage/cards/f/ForbiddenOrchard.java index 65895bb145..970cd7d492 100644 --- a/Mage.Sets/src/mage/cards/f/ForbiddenOrchard.java +++ b/Mage.Sets/src/mage/cards/f/ForbiddenOrchard.java @@ -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 diff --git a/Mage.Sets/src/mage/cards/f/FreeRangeChicken.java b/Mage.Sets/src/mage/cards/f/FreeRangeChicken.java index 74311e467a..fb56e2cfd6 100644 --- a/Mage.Sets/src/mage/cards/f/FreeRangeChicken.java +++ b/Mage.Sets/src/mage/cards/f/FreeRangeChicken.java @@ -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); } diff --git a/Mage.Sets/src/mage/cards/g/GOTOJAIL.java b/Mage.Sets/src/mage/cards/g/GOTOJAIL.java index c0d36ef64b..4ac0aafdc1 100644 --- a/Mage.Sets/src/mage/cards/g/GOTOJAIL.java +++ b/Mage.Sets/src/mage/cards/g/GOTOJAIL.java @@ -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); } diff --git a/Mage.Sets/src/mage/cards/g/GarbageElementalC.java b/Mage.Sets/src/mage/cards/g/GarbageElementalC.java index 08005ab0d0..ebf853683a 100644 --- a/Mage.Sets/src/mage/cards/g/GarbageElementalC.java +++ b/Mage.Sets/src/mage/cards/g/GarbageElementalC.java @@ -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()); diff --git a/Mage.Sets/src/mage/cards/g/GarbageElementalD.java b/Mage.Sets/src/mage/cards/g/GarbageElementalD.java index 3b784050c2..9eae2804d6 100644 --- a/Mage.Sets/src/mage/cards/g/GarbageElementalD.java +++ b/Mage.Sets/src/mage/cards/g/GarbageElementalD.java @@ -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; diff --git a/Mage.Sets/src/mage/cards/g/GoblinBowlingTeam.java b/Mage.Sets/src/mage/cards/g/GoblinBowlingTeam.java index aec2968f46..3c442308d7 100644 --- a/Mage.Sets/src/mage/cards/g/GoblinBowlingTeam.java +++ b/Mage.Sets/src/mage/cards/g/GoblinBowlingTeam.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/g/GoblinTutor.java b/Mage.Sets/src/mage/cards/g/GoblinTutor.java index 9a01d83b64..18848a2878 100644 --- a/Mage.Sets/src/mage/cards/g/GoblinTutor.java +++ b/Mage.Sets/src/mage/cards/g/GoblinTutor.java @@ -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 diff --git a/Mage.Sets/src/mage/cards/g/GroundPounder.java b/Mage.Sets/src/mage/cards/g/GroundPounder.java index c2dd585259..41942f9f8c 100644 --- a/Mage.Sets/src/mage/cards/g/GroundPounder.java +++ b/Mage.Sets/src/mage/cards/g/GroundPounder.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/g/GrowthSpurt.java b/Mage.Sets/src/mage/cards/g/GrowthSpurt.java index 54c8f2ec5f..773b69c56b 100644 --- a/Mage.Sets/src/mage/cards/g/GrowthSpurt.java +++ b/Mage.Sets/src/mage/cards/g/GrowthSpurt.java @@ -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); diff --git a/Mage.Sets/src/mage/cards/h/HammerHelper.java b/Mage.Sets/src/mage/cards/h/HammerHelper.java index 297b74c5da..91ab70d28b 100644 --- a/Mage.Sets/src/mage/cards/h/HammerHelper.java +++ b/Mage.Sets/src/mage/cards/h/HammerHelper.java @@ -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; diff --git a/Mage.Sets/src/mage/cards/h/HammerJammer.java b/Mage.Sets/src/mage/cards/h/HammerJammer.java index 04c776f35e..1a0a581cdb 100644 --- a/Mage.Sets/src/mage/cards/h/HammerJammer.java +++ b/Mage.Sets/src/mage/cards/h/HammerJammer.java @@ -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 appliedEffects = (ArrayList) 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); diff --git a/Mage.Sets/src/mage/cards/h/Hydradoodle.java b/Mage.Sets/src/mage/cards/h/Hydradoodle.java index d39d1a41e7..651d4f3ec5 100644 --- a/Mage.Sets/src/mage/cards/h/Hydradoodle.java +++ b/Mage.Sets/src/mage/cards/h/Hydradoodle.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/i/Inhumaniac.java b/Mage.Sets/src/mage/cards/i/Inhumaniac.java index f260d1cca6..439d088c48 100644 --- a/Mage.Sets/src/mage/cards/i/Inhumaniac.java +++ b/Mage.Sets/src/mage/cards/i/Inhumaniac.java @@ -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) { diff --git a/Mage.Sets/src/mage/cards/j/JackInTheMox.java b/Mage.Sets/src/mage/cards/j/JackInTheMox.java index 193b4fc027..37d14cc0a8 100644 --- a/Mage.Sets/src/mage/cards/j/JackInTheMox.java +++ b/Mage.Sets/src/mage/cards/j/JackInTheMox.java @@ -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); diff --git a/Mage.Sets/src/mage/cards/j/JumboImp.java b/Mage.Sets/src/mage/cards/j/JumboImp.java index b9c6046343..59d75dfbb6 100644 --- a/Mage.Sets/src/mage/cards/j/JumboImp.java +++ b/Mage.Sets/src/mage/cards/j/JumboImp.java @@ -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 appliedEffects = (ArrayList) 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; } diff --git a/Mage.Sets/src/mage/cards/k/KrazyKow.java b/Mage.Sets/src/mage/cards/k/KrazyKow.java index 6b6cb07195..02ecdb87f7 100644 --- a/Mage.Sets/src/mage/cards/k/KrazyKow.java +++ b/Mage.Sets/src/mage/cards/k/KrazyKow.java @@ -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); diff --git a/Mage.Sets/src/mage/cards/l/LobeLobber.java b/Mage.Sets/src/mage/cards/l/LobeLobber.java index 3571a7d4d0..e376e2225d 100644 --- a/Mage.Sets/src/mage/cards/l/LobeLobber.java +++ b/Mage.Sets/src/mage/cards/l/LobeLobber.java @@ -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); } diff --git a/Mage.Sets/src/mage/cards/m/MadScienceFairProject.java b/Mage.Sets/src/mage/cards/m/MadScienceFairProject.java index 4a3e9d28ea..842640c849 100644 --- a/Mage.Sets/src/mage/cards/m/MadScienceFairProject.java +++ b/Mage.Sets/src/mage/cards/m/MadScienceFairProject.java @@ -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 { diff --git a/Mage.Sets/src/mage/cards/p/Painiac.java b/Mage.Sets/src/mage/cards/p/Painiac.java index c23713f2df..731e6d95c2 100644 --- a/Mage.Sets/src/mage/cards/p/Painiac.java +++ b/Mage.Sets/src/mage/cards/p/Painiac.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/p/Poultrygeist.java b/Mage.Sets/src/mage/cards/p/Poultrygeist.java index aa3ed530ad..d14a4ca1bb 100644 --- a/Mage.Sets/src/mage/cards/p/Poultrygeist.java +++ b/Mage.Sets/src/mage/cards/p/Poultrygeist.java @@ -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) { diff --git a/Mage.Sets/src/mage/cards/p/PriceOfGlory.java b/Mage.Sets/src/mage/cards/p/PriceOfGlory.java index 525d295d35..7c6e6cc020 100644 --- a/Mage.Sets/src/mage/cards/p/PriceOfGlory.java +++ b/Mage.Sets/src/mage/cards/p/PriceOfGlory.java @@ -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 diff --git a/Mage.Sets/src/mage/cards/r/Ricochet.java b/Mage.Sets/src/mage/cards/r/Ricochet.java index f52a37caad..de42487820 100644 --- a/Mage.Sets/src/mage/cards/r/Ricochet.java +++ b/Mage.Sets/src/mage/cards/r/Ricochet.java @@ -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 mapEntry : new HashSet<>(playerRolls.entrySet())) { diff --git a/Mage.Sets/src/mage/cards/s/SparkFiend.java b/Mage.Sets/src/mage/cards/s/SparkFiend.java index 61a8ac8ed1..283f95a783 100644 --- a/Mage.Sets/src/mage/cards/s/SparkFiend.java +++ b/Mage.Sets/src/mage/cards/s/SparkFiend.java @@ -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; diff --git a/Mage.Sets/src/mage/cards/s/StrategySchmategy.java b/Mage.Sets/src/mage/cards/s/StrategySchmategy.java index 9c706e273d..5ea0285ceb 100644 --- a/Mage.Sets/src/mage/cards/s/StrategySchmategy.java +++ b/Mage.Sets/src/mage/cards/s/StrategySchmategy.java @@ -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 artifactPermanents = game.getBattlefield().getActivePermanents(new FilterArtifactPermanent(), controller.getId(), game); diff --git a/Mage.Sets/src/mage/cards/s/SwordOfDungeonsAndDragons.java b/Mage.Sets/src/mage/cards/s/SwordOfDungeonsAndDragons.java index 253233be3b..c1a61ffd4b 100644 --- a/Mage.Sets/src/mage/cards/s/SwordOfDungeonsAndDragons.java +++ b/Mage.Sets/src/mage/cards/s/SwordOfDungeonsAndDragons.java @@ -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); } diff --git a/Mage.Sets/src/mage/cards/t/TempOfTheDamned.java b/Mage.Sets/src/mage/cards/t/TempOfTheDamned.java index a723edfb9a..9e032a8246 100644 --- a/Mage.Sets/src/mage/cards/t/TempOfTheDamned.java +++ b/Mage.Sets/src/mage/cards/t/TempOfTheDamned.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/t/TheBigIdea.java b/Mage.Sets/src/mage/cards/t/TheBigIdea.java index 8a3a85ea19..28ab1d3145 100644 --- a/Mage.Sets/src/mage/cards/t/TheBigIdea.java +++ b/Mage.Sets/src/mage/cards/t/TheBigIdea.java @@ -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; diff --git a/Mage.Sets/src/mage/cards/t/TimeOut.java b/Mage.Sets/src/mage/cards/t/TimeOut.java index 430b5556f6..69fcb8068e 100644 --- a/Mage.Sets/src/mage/cards/t/TimeOut.java +++ b/Mage.Sets/src/mage/cards/t/TimeOut.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/t/TreasureNabber.java b/Mage.Sets/src/mage/cards/t/TreasureNabber.java index 747c9b9459..a67d6e6c42 100644 --- a/Mage.Sets/src/mage/cards/t/TreasureNabber.java +++ b/Mage.Sets/src/mage/cards/t/TreasureNabber.java @@ -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 diff --git a/Mage.Sets/src/mage/cards/u/UrzasScienceFairProject.java b/Mage.Sets/src/mage/cards/u/UrzasScienceFairProject.java index 9355a70cbd..0afa942853 100644 --- a/Mage.Sets/src/mage/cards/u/UrzasScienceFairProject.java +++ b/Mage.Sets/src/mage/cards/u/UrzasScienceFairProject.java @@ -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. diff --git a/Mage.Sets/src/mage/cards/z/ZhurTaaDruid.java b/Mage.Sets/src/mage/cards/z/ZhurTaaDruid.java index 719384a555..ffeae4d28e 100644 --- a/Mage.Sets/src/mage/cards/z/ZhurTaaDruid.java +++ b/Mage.Sets/src/mage/cards/z/ZhurTaaDruid.java @@ -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 diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index 44a39c940e..d025829913 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -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 appliedEffects, int numSides) { - return computerPlayer.rollDice(game, appliedEffects, numSides); + public int rollDice(Ability source, Game game, List 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 appliedEffects) { + public PlanarDieRoll rollPlanarDie(Ability source, Game game, List appliedEffects) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override - public PlanarDieRoll rollPlanarDie(Game game, List appliedEffects, int numberChaosSides, int numberPlanarSides) { + public PlanarDieRoll rollPlanarDie(Ability source, Game game, List appliedEffects, int numberChaosSides, int numberPlanarSides) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } diff --git a/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java b/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java index cc4d8cadd4..82e3aed0d9 100644 --- a/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java +++ b/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java @@ -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 appliedEffects, int numSides) { + public int rollDice(Ability source, Game game, List 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 appliedEffects) { + public PlanarDieRoll rollPlanarDie(Ability source, Game game, List appliedEffects) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override - public PlanarDieRoll rollPlanarDie(Game game, List appliedEffects, int numberChaosSides, int numberPlanarSides) { + public PlanarDieRoll rollPlanarDie(Ability source, Game game, List appliedEffects, int numberChaosSides, int numberPlanarSides) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } diff --git a/Mage.Tests/src/test/java/org/mage/test/utils/RandomTest.java b/Mage.Tests/src/test/java/org/mage/test/utils/RandomTest.java index 0f98b73aa0..733b539c42 100644 --- a/Mage.Tests/src/test/java/org/mage/test/utils/RandomTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/utils/RandomTest.java @@ -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, diff --git a/Mage/src/main/java/mage/abilities/effects/common/RollDiceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/RollDiceEffect.java index a57afb3540..62c1fe6a6d 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/RollDiceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/RollDiceEffect.java @@ -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; diff --git a/Mage/src/main/java/mage/abilities/effects/common/RollPlanarDieEffect.java b/Mage/src/main/java/mage/abilities/effects/common/RollPlanarDieEffect.java index b864e0d969..45a4d9df39 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/RollPlanarDieEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/RollPlanarDieEffect.java @@ -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); diff --git a/Mage/src/main/java/mage/abilities/mana/DelayedTriggeredManaAbility.java b/Mage/src/main/java/mage/abilities/mana/DelayedTriggeredManaAbility.java index c257ee0410..c17c642877 100644 --- a/Mage/src/main/java/mage/abilities/mana/DelayedTriggeredManaAbility.java +++ b/Mage/src/main/java/mage/abilities/mana/DelayedTriggeredManaAbility.java @@ -1,4 +1,3 @@ - package mage.abilities.mana; diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index 91184c7e15..3b24c52b99 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -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()) { diff --git a/Mage/src/main/java/mage/game/combat/Combat.java b/Mage/src/main/java/mage/game/combat/Combat.java index d372800dc2..3784ff1c72 100644 --- a/Mage/src/main/java/mage/game/combat/Combat.java +++ b/Mage/src/main/java/mage/game/combat/Combat.java @@ -290,7 +290,11 @@ public class Combat implements Serializable, Copyable { 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 { * 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) { diff --git a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java index 19c882d2a1..87aee9ad46 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java @@ -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; diff --git a/Mage/src/main/java/mage/players/Player.java b/Mage/src/main/java/mage/players/Player.java index e696acd3e5..6f25b84903 100644 --- a/Mage/src/main/java/mage/players/Player.java +++ b/Mage/src/main/java/mage/players/Player.java @@ -86,8 +86,11 @@ public interface Player extends MageItem, Copyable { * @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 { boolean flipCoin(Ability source, Game game, boolean winnable, List appliedEffects); - int rollDice(Game game, int numSides); + int rollDice(Ability source, Game game, int numSides); - int rollDice(Game game, List appliedEffects, int numSides); + int rollDice(Ability source, Game game, List appliedEffects, int numSides); - PlanarDieRoll rollPlanarDie(Game game); + PlanarDieRoll rollPlanarDie(Ability source, Game game); - PlanarDieRoll rollPlanarDie(Game game, List appliedEffects); + PlanarDieRoll rollPlanarDie(Ability source, Game game, List appliedEffects); - PlanarDieRoll rollPlanarDie(Game game, List appliedEffects, int numberChaosSides, int numberPlanarSides); + PlanarDieRoll rollPlanarDie(Ability source, Game game, List appliedEffects, int numberChaosSides, int numberPlanarSides); Card discardOne(boolean random, boolean payForCost, Ability source, Game game); diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 55fff0b555..d9b58fa51e 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -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 appliedEffects, int numSides) { + public int rollDice(Ability source, Game game, List 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 appliedEffects) { - return rollPlanarDie(game, appliedEffects, 2, 2); + public PlanarDieRoll rollPlanarDie(Ability source, Game game, List 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 appliedEffects, int numberChaosSides, int numberPlanarSides) { + public PlanarDieRoll rollPlanarDie(Ability source, Game game, List 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()) { diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 6d359cddf9..40c0f9d86c 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -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, ")", ""); + } }