From b6f6bac5e04918257e0bb9f67162f9aac420228e Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Tue, 2 Feb 2021 19:26:09 +0400 Subject: [PATCH] Refactor: overflow method naming --- .../src/mage/cards/a/AngrathsMarauders.java | 2 +- .../src/mage/cards/a/AnthemOfRakdos.java | 2 +- Mage.Sets/src/mage/cards/b/BitterFeud.java | 2 +- Mage.Sets/src/mage/cards/b/BlazingEffigy.java | 2 +- Mage.Sets/src/mage/cards/b/BlindFury.java | 2 +- .../src/mage/cards/b/BranchingEvolution.java | 2 +- .../mage/cards/b/BruvacTheGrandiloquent.java | 2 +- .../src/mage/cards/c/CalamityBearer.java | 2 +- .../src/mage/cards/c/ChargingTuskodon.java | 2 +- .../src/mage/cards/c/CurseOfBloodletting.java | 2 +- .../src/mage/cards/d/DesperateGambit.java | 2 +- .../mage/cards/d/DictateOfTheTwinGods.java | 5 +- Mage.Sets/src/mage/cards/d/Dracoplasm.java | 4 +- .../src/mage/cards/e/EmbermawHellion.java | 2 +- Mage.Sets/src/mage/cards/f/FarrelsMantle.java | 2 +- Mage.Sets/src/mage/cards/f/FiendishDuo.java | 2 +- .../src/mage/cards/f/FieryEmancipation.java | 4 +- Mage.Sets/src/mage/cards/f/FireServant.java | 2 +- Mage.Sets/src/mage/cards/f/FurnaceOfRath.java | 2 +- .../mage/cards/g/GiselaBladeOfGoldnight.java | 2 +- .../src/mage/cards/g/GoblinBowlingTeam.java | 5 +- Mage.Sets/src/mage/cards/g/GoblinGoliath.java | 2 +- .../src/mage/cards/g/GoldnightCastigator.java | 5 +- .../src/mage/cards/g/GratuitousViolence.java | 2 +- .../src/mage/cards/i/ImpulsiveManeuvers.java | 2 +- .../src/mage/cards/i/InquisitorsFlail.java | 2 +- Mage.Sets/src/mage/cards/i/InsultInjury.java | 2 +- .../mage/cards/j/JayaVeneratedFiremage.java | 2 +- .../src/mage/cards/j/JeskaThriceReborn.java | 4 +- .../src/mage/cards/m/ManaReflection.java | 12 +-- .../src/mage/cards/n/NyxbloomAncient.java | 12 +-- .../src/mage/cards/o/OboshThePreypiercer.java | 2 +- Mage.Sets/src/mage/cards/o/Overblaze.java | 2 +- Mage.Sets/src/mage/cards/p/Phthisis.java | 2 +- .../src/mage/cards/p/PredatorsRapport.java | 2 +- .../src/mage/cards/p/PyromancersGauntlet.java | 2 +- .../src/mage/cards/p/PyromancersSwath.java | 2 +- .../src/mage/cards/q/QuestForPureFlame.java | 3 +- Mage.Sets/src/mage/cards/s/Sentinel.java | 2 +- .../src/mage/cards/s/SulfuricVapors.java | 2 +- Mage.Sets/src/mage/cards/s/SwornDefender.java | 4 +- .../src/mage/cards/t/TheFlameOfKeld.java | 2 +- .../mage/cards/t/TorbranThaneOfRedFell.java | 2 +- .../src/mage/cards/w/WallOfTombstones.java | 2 +- Mage/src/main/java/mage/MageInt.java | 2 +- Mage/src/main/java/mage/Mana.java | 64 ++++++++-------- .../mana/AddConditionalManaEffect.java | 2 +- .../mage/game/permanent/PermanentImpl.java | 2 +- Mage/src/main/java/mage/players/ManaPool.java | 2 +- .../main/java/mage/players/PlayerImpl.java | 6 +- Mage/src/main/java/mage/util/CardUtil.java | 73 ++++++++++--------- 51 files changed, 139 insertions(+), 138 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/AngrathsMarauders.java b/Mage.Sets/src/mage/cards/a/AngrathsMarauders.java index cd6f1f2366..0d64ebd4d6 100644 --- a/Mage.Sets/src/mage/cards/a/AngrathsMarauders.java +++ b/Mage.Sets/src/mage/cards/a/AngrathsMarauders.java @@ -75,7 +75,7 @@ class AngrathsMaraudersEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/a/AnthemOfRakdos.java b/Mage.Sets/src/mage/cards/a/AnthemOfRakdos.java index 9ee6381a0a..fbc37b9938 100644 --- a/Mage.Sets/src/mage/cards/a/AnthemOfRakdos.java +++ b/Mage.Sets/src/mage/cards/a/AnthemOfRakdos.java @@ -86,7 +86,7 @@ class AnthemOfRakdosHellbentEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/b/BitterFeud.java b/Mage.Sets/src/mage/cards/b/BitterFeud.java index c5eac22d28..ff574c045c 100644 --- a/Mage.Sets/src/mage/cards/b/BitterFeud.java +++ b/Mage.Sets/src/mage/cards/b/BitterFeud.java @@ -169,7 +169,7 @@ class BitterFeudEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/b/BlazingEffigy.java b/Mage.Sets/src/mage/cards/b/BlazingEffigy.java index d429166ebe..d823666f23 100644 --- a/Mage.Sets/src/mage/cards/b/BlazingEffigy.java +++ b/Mage.Sets/src/mage/cards/b/BlazingEffigy.java @@ -60,7 +60,7 @@ enum BlazingEffigyCount implements DynamicValue { return 3; } int effigyDamage = watcher.damageDoneTo(sourceAbility.getSourceId(), sourceAbility.getSourceObjectZoneChangeCounter() - 1, game); - return CardUtil.addWithOverflowCheck(3, effigyDamage); + return CardUtil.overflowInc(3, effigyDamage); } @Override diff --git a/Mage.Sets/src/mage/cards/b/BlindFury.java b/Mage.Sets/src/mage/cards/b/BlindFury.java index 5f82b75538..d97aae48c1 100644 --- a/Mage.Sets/src/mage/cards/b/BlindFury.java +++ b/Mage.Sets/src/mage/cards/b/BlindFury.java @@ -77,7 +77,7 @@ class FurnaceOfRathEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/b/BranchingEvolution.java b/Mage.Sets/src/mage/cards/b/BranchingEvolution.java index 0e67487032..3a89869041 100644 --- a/Mage.Sets/src/mage/cards/b/BranchingEvolution.java +++ b/Mage.Sets/src/mage/cards/b/BranchingEvolution.java @@ -52,7 +52,7 @@ class BranchingEvolutionEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmountForCounters(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount()), true); + event.setAmountForCounters(CardUtil.overflowMultiply(event.getAmount(), 2), true); return false; } diff --git a/Mage.Sets/src/mage/cards/b/BruvacTheGrandiloquent.java b/Mage.Sets/src/mage/cards/b/BruvacTheGrandiloquent.java index be1371b865..e05f747908 100644 --- a/Mage.Sets/src/mage/cards/b/BruvacTheGrandiloquent.java +++ b/Mage.Sets/src/mage/cards/b/BruvacTheGrandiloquent.java @@ -74,7 +74,7 @@ class BruvacTheGrandiloquentReplacementEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/c/CalamityBearer.java b/Mage.Sets/src/mage/cards/c/CalamityBearer.java index 2e500729ab..52c5420652 100644 --- a/Mage.Sets/src/mage/cards/c/CalamityBearer.java +++ b/Mage.Sets/src/mage/cards/c/CalamityBearer.java @@ -65,7 +65,7 @@ class CalamityBearerEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } diff --git a/Mage.Sets/src/mage/cards/c/ChargingTuskodon.java b/Mage.Sets/src/mage/cards/c/ChargingTuskodon.java index abd4d4d1be..2c8b01a4b5 100644 --- a/Mage.Sets/src/mage/cards/c/ChargingTuskodon.java +++ b/Mage.Sets/src/mage/cards/c/ChargingTuskodon.java @@ -82,7 +82,7 @@ class ChargingTuskodonEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } diff --git a/Mage.Sets/src/mage/cards/c/CurseOfBloodletting.java b/Mage.Sets/src/mage/cards/c/CurseOfBloodletting.java index 7fe65e9355..05ba991974 100644 --- a/Mage.Sets/src/mage/cards/c/CurseOfBloodletting.java +++ b/Mage.Sets/src/mage/cards/c/CurseOfBloodletting.java @@ -85,7 +85,7 @@ class CurseOfBloodlettingEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } diff --git a/Mage.Sets/src/mage/cards/d/DesperateGambit.java b/Mage.Sets/src/mage/cards/d/DesperateGambit.java index 80351f9dd6..673b425089 100644 --- a/Mage.Sets/src/mage/cards/d/DesperateGambit.java +++ b/Mage.Sets/src/mage/cards/d/DesperateGambit.java @@ -106,7 +106,7 @@ class DesperateGambitEffect extends PreventionEffectImpl { if (controller != null && object != null) { if (super.applies(event, source, game) && event instanceof DamageEvent && event.getAmount() > 0) { if (wonFlip) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); this.discard(); } else { preventDamageAction(event, source, game); diff --git a/Mage.Sets/src/mage/cards/d/DictateOfTheTwinGods.java b/Mage.Sets/src/mage/cards/d/DictateOfTheTwinGods.java index 20111b82a3..907bdc0a81 100644 --- a/Mage.Sets/src/mage/cards/d/DictateOfTheTwinGods.java +++ b/Mage.Sets/src/mage/cards/d/DictateOfTheTwinGods.java @@ -15,7 +15,6 @@ import mage.constants.Zone; import mage.game.Game; import mage.game.events.DamageEvent; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.players.Player; import mage.util.CardUtil; @@ -90,13 +89,13 @@ class DictateOfTheTwinGodsEffect extends ReplacementEffectImpl { if (damageEvent.getType() == GameEvent.EventType.DAMAGE_PLAYER) { Player targetPlayer = game.getPlayer(event.getTargetId()); if (targetPlayer != null) { - targetPlayer.damage(CardUtil.addWithOverflowCheck(damageEvent.getAmount(), damageEvent.getAmount()), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects()); + targetPlayer.damage(CardUtil.overflowInc(damageEvent.getAmount(), damageEvent.getAmount()), 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(), damageEvent.getAmount()), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects()); + targetPermanent.damage(CardUtil.overflowInc(damageEvent.getAmount(), damageEvent.getAmount()), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects()); return true; } } diff --git a/Mage.Sets/src/mage/cards/d/Dracoplasm.java b/Mage.Sets/src/mage/cards/d/Dracoplasm.java index 5bd5ebbd05..c55998f816 100644 --- a/Mage.Sets/src/mage/cards/d/Dracoplasm.java +++ b/Mage.Sets/src/mage/cards/d/Dracoplasm.java @@ -106,8 +106,8 @@ class DracoplasmEffect extends ReplacementEffectImpl { for (UUID targetId : target.getTargets()) { Permanent targetCreature = game.getPermanent(targetId); if (targetCreature != null && targetCreature.sacrifice(source, game)) { - power = CardUtil.addWithOverflowCheck(power, targetCreature.getPower().getValue()); - toughness = CardUtil.addWithOverflowCheck(toughness, targetCreature.getToughness().getValue()); + power = CardUtil.overflowInc(power, targetCreature.getPower().getValue()); + toughness = CardUtil.overflowInc(toughness, targetCreature.getToughness().getValue()); } } ContinuousEffect effect = new SetPowerToughnessSourceEffect(power, toughness, Duration.Custom, SubLayer.SetPT_7b); diff --git a/Mage.Sets/src/mage/cards/e/EmbermawHellion.java b/Mage.Sets/src/mage/cards/e/EmbermawHellion.java index 9bc75994f2..331d32f10b 100644 --- a/Mage.Sets/src/mage/cards/e/EmbermawHellion.java +++ b/Mage.Sets/src/mage/cards/e/EmbermawHellion.java @@ -95,7 +95,7 @@ class EmbermawHellionEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), 1)); + event.setAmount(CardUtil.overflowInc(event.getAmount(), 1)); return false; } diff --git a/Mage.Sets/src/mage/cards/f/FarrelsMantle.java b/Mage.Sets/src/mage/cards/f/FarrelsMantle.java index bcfd264d5c..54b7ec7d99 100644 --- a/Mage.Sets/src/mage/cards/f/FarrelsMantle.java +++ b/Mage.Sets/src/mage/cards/f/FarrelsMantle.java @@ -101,7 +101,7 @@ class FarrelsMantleEffect extends OneShotEffect{ @Override public boolean apply(Game game, Ability source) { Permanent perm = game.getPermanent(source.getSourceId()); - int damage = CardUtil.addWithOverflowCheck(perm.getPower().getValue(), 2); + int damage = CardUtil.overflowInc(perm.getPower().getValue(), 2); DamageTargetEffect dmgEffect = new DamageTargetEffect(damage); return dmgEffect.apply(game, source); } diff --git a/Mage.Sets/src/mage/cards/f/FiendishDuo.java b/Mage.Sets/src/mage/cards/f/FiendishDuo.java index e8ae73d92e..94737ffb94 100644 --- a/Mage.Sets/src/mage/cards/f/FiendishDuo.java +++ b/Mage.Sets/src/mage/cards/f/FiendishDuo.java @@ -82,7 +82,7 @@ class FiendishDuoEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/f/FieryEmancipation.java b/Mage.Sets/src/mage/cards/f/FieryEmancipation.java index 0c6009ef96..0a9a0e94e6 100644 --- a/Mage.Sets/src/mage/cards/f/FieryEmancipation.java +++ b/Mage.Sets/src/mage/cards/f/FieryEmancipation.java @@ -67,8 +67,8 @@ class FieryEmancipationEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck( - CardUtil.addWithOverflowCheck( + event.setAmount(CardUtil.overflowInc( + CardUtil.overflowInc( event.getAmount(), event.getAmount() ), event.getAmount() )); diff --git a/Mage.Sets/src/mage/cards/f/FireServant.java b/Mage.Sets/src/mage/cards/f/FireServant.java index 5cd9c2c04a..d4deb897ac 100644 --- a/Mage.Sets/src/mage/cards/f/FireServant.java +++ b/Mage.Sets/src/mage/cards/f/FireServant.java @@ -86,7 +86,7 @@ class FireServantEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } diff --git a/Mage.Sets/src/mage/cards/f/FurnaceOfRath.java b/Mage.Sets/src/mage/cards/f/FurnaceOfRath.java index a7b4297ec8..f0bcf3bac5 100644 --- a/Mage.Sets/src/mage/cards/f/FurnaceOfRath.java +++ b/Mage.Sets/src/mage/cards/f/FurnaceOfRath.java @@ -75,7 +75,7 @@ class FurnaceOfRathEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/g/GiselaBladeOfGoldnight.java b/Mage.Sets/src/mage/cards/g/GiselaBladeOfGoldnight.java index 58cdb7b47a..c01ba19127 100644 --- a/Mage.Sets/src/mage/cards/g/GiselaBladeOfGoldnight.java +++ b/Mage.Sets/src/mage/cards/g/GiselaBladeOfGoldnight.java @@ -98,7 +98,7 @@ class GiselaBladeOfGoldnightDoubleDamageEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/g/GoblinBowlingTeam.java b/Mage.Sets/src/mage/cards/g/GoblinBowlingTeam.java index 3c442308d7..ba589e8347 100644 --- a/Mage.Sets/src/mage/cards/g/GoblinBowlingTeam.java +++ b/Mage.Sets/src/mage/cards/g/GoblinBowlingTeam.java @@ -16,7 +16,6 @@ import mage.constants.Zone; import mage.game.Game; import mage.game.events.DamageEvent; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.players.Player; import mage.util.CardUtil; @@ -94,13 +93,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(source, game, 6)), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects()); + targetPlayer.damage(CardUtil.overflowInc(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(source, game, 6)), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects()); + targetPermanent.damage(CardUtil.overflowInc(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/GoblinGoliath.java b/Mage.Sets/src/mage/cards/g/GoblinGoliath.java index a6a7c02f60..10df0b311a 100644 --- a/Mage.Sets/src/mage/cards/g/GoblinGoliath.java +++ b/Mage.Sets/src/mage/cards/g/GoblinGoliath.java @@ -99,7 +99,7 @@ class GoblinGoliathDamageEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/g/GoldnightCastigator.java b/Mage.Sets/src/mage/cards/g/GoldnightCastigator.java index 517c2b659f..cbddd29f3a 100644 --- a/Mage.Sets/src/mage/cards/g/GoldnightCastigator.java +++ b/Mage.Sets/src/mage/cards/g/GoldnightCastigator.java @@ -17,7 +17,6 @@ import mage.constants.Outcome; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.util.CardUtil; @@ -93,14 +92,14 @@ class GoldnightCastigatorDoubleDamageEffect extends ReplacementEffectImpl { switch (event.getType()) { case DAMAGE_PLAYER: if (event.getTargetId().equals(source.getControllerId())) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); } break; case DAMAGE_CREATURE: Permanent permanent = game.getPermanent(event.getTargetId()); if (permanent != null) { if (permanent.getId().equals(source.getSourceId())) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); } } } diff --git a/Mage.Sets/src/mage/cards/g/GratuitousViolence.java b/Mage.Sets/src/mage/cards/g/GratuitousViolence.java index b345c48d22..ecac08f250 100644 --- a/Mage.Sets/src/mage/cards/g/GratuitousViolence.java +++ b/Mage.Sets/src/mage/cards/g/GratuitousViolence.java @@ -82,7 +82,7 @@ class GratuitousViolenceReplacementEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/i/ImpulsiveManeuvers.java b/Mage.Sets/src/mage/cards/i/ImpulsiveManeuvers.java index 1e2ec98a84..d46f8e4e7d 100644 --- a/Mage.Sets/src/mage/cards/i/ImpulsiveManeuvers.java +++ b/Mage.Sets/src/mage/cards/i/ImpulsiveManeuvers.java @@ -92,7 +92,7 @@ class ImpulsiveManeuversEffect extends PreventionEffectImpl { DamageEvent damageEvent = (DamageEvent) event; if (damageEvent.isCombatDamage()) { if (wonFlip) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); this.discard(); } else { preventDamageAction(event, source, game); diff --git a/Mage.Sets/src/mage/cards/i/InquisitorsFlail.java b/Mage.Sets/src/mage/cards/i/InquisitorsFlail.java index 1d6be5af4b..7b9f76544c 100644 --- a/Mage.Sets/src/mage/cards/i/InquisitorsFlail.java +++ b/Mage.Sets/src/mage/cards/i/InquisitorsFlail.java @@ -101,7 +101,7 @@ class InquisitorsFlailEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } diff --git a/Mage.Sets/src/mage/cards/i/InsultInjury.java b/Mage.Sets/src/mage/cards/i/InsultInjury.java index 0808f17d01..fee67bae1f 100644 --- a/Mage.Sets/src/mage/cards/i/InsultInjury.java +++ b/Mage.Sets/src/mage/cards/i/InsultInjury.java @@ -89,7 +89,7 @@ class InsultDoubleDamageEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/j/JayaVeneratedFiremage.java b/Mage.Sets/src/mage/cards/j/JayaVeneratedFiremage.java index 9a38e5d761..8805450e1b 100644 --- a/Mage.Sets/src/mage/cards/j/JayaVeneratedFiremage.java +++ b/Mage.Sets/src/mage/cards/j/JayaVeneratedFiremage.java @@ -96,7 +96,7 @@ class JayaVeneratedFiremageEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), 1)); + event.setAmount(CardUtil.overflowInc(event.getAmount(), 1)); return false; } diff --git a/Mage.Sets/src/mage/cards/j/JeskaThriceReborn.java b/Mage.Sets/src/mage/cards/j/JeskaThriceReborn.java index 7a411d75ec..21b8e9330d 100644 --- a/Mage.Sets/src/mage/cards/j/JeskaThriceReborn.java +++ b/Mage.Sets/src/mage/cards/j/JeskaThriceReborn.java @@ -150,8 +150,8 @@ class JeskaThriceRebornEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { int amount = event.getAmount(); - event.setAmount(CardUtil.addWithOverflowCheck(amount, event.getAmount())); - event.setAmount(CardUtil.addWithOverflowCheck(amount, event.getAmount())); + event.setAmount(CardUtil.overflowInc(amount, event.getAmount())); + event.setAmount(CardUtil.overflowInc(amount, event.getAmount())); return false; } } diff --git a/Mage.Sets/src/mage/cards/m/ManaReflection.java b/Mage.Sets/src/mage/cards/m/ManaReflection.java index 0c5d13a83f..563b314179 100644 --- a/Mage.Sets/src/mage/cards/m/ManaReflection.java +++ b/Mage.Sets/src/mage/cards/m/ManaReflection.java @@ -56,22 +56,22 @@ class ManaReflectionReplacementEffect extends ReplacementEffectImpl { public boolean replaceEvent(GameEvent event, Ability source, Game game) { Mana mana = ((ManaEvent) event).getMana(); if (mana.getBlack() > 0) { - mana.set(ManaType.BLACK, CardUtil.multiplyWithOverflowCheck(mana.getBlack(), 2)); + mana.set(ManaType.BLACK, CardUtil.overflowMultiply(mana.getBlack(), 2)); } if (mana.getBlue() > 0) { - mana.set(ManaType.BLUE, CardUtil.multiplyWithOverflowCheck(mana.getBlue(), 2)); + mana.set(ManaType.BLUE, CardUtil.overflowMultiply(mana.getBlue(), 2)); } if (mana.getWhite() > 0) { - mana.set(ManaType.WHITE, CardUtil.multiplyWithOverflowCheck(mana.getWhite(), 2)); + mana.set(ManaType.WHITE, CardUtil.overflowMultiply(mana.getWhite(), 2)); } if (mana.getGreen() > 0) { - mana.set(ManaType.GREEN, CardUtil.multiplyWithOverflowCheck(mana.getGreen(), 2)); + mana.set(ManaType.GREEN, CardUtil.overflowMultiply(mana.getGreen(), 2)); } if (mana.getRed() > 0) { - mana.set(ManaType.RED, CardUtil.multiplyWithOverflowCheck(mana.getRed(), 2)); + mana.set(ManaType.RED, CardUtil.overflowMultiply(mana.getRed(), 2)); } if (mana.getColorless() > 0) { - mana.set(ManaType.COLORLESS, CardUtil.multiplyWithOverflowCheck(mana.getColorless(), 2)); + mana.set(ManaType.COLORLESS, CardUtil.overflowMultiply(mana.getColorless(), 2)); } return false; } diff --git a/Mage.Sets/src/mage/cards/n/NyxbloomAncient.java b/Mage.Sets/src/mage/cards/n/NyxbloomAncient.java index e7ad29c6f3..13207b0079 100644 --- a/Mage.Sets/src/mage/cards/n/NyxbloomAncient.java +++ b/Mage.Sets/src/mage/cards/n/NyxbloomAncient.java @@ -65,22 +65,22 @@ class NyxbloomAncientReplacementEffect extends ReplacementEffectImpl { public boolean replaceEvent(GameEvent event, Ability source, Game game) { Mana mana = ((ManaEvent) event).getMana(); if (mana.getBlack() > 0) { - mana.set(ManaType.BLACK, CardUtil.multiplyWithOverflowCheck(mana.getBlack(), 3)); + mana.set(ManaType.BLACK, CardUtil.overflowMultiply(mana.getBlack(), 3)); } if (mana.getBlue() > 0) { - mana.set(ManaType.BLUE, CardUtil.multiplyWithOverflowCheck(mana.getBlue(), 3)); + mana.set(ManaType.BLUE, CardUtil.overflowMultiply(mana.getBlue(), 3)); } if (mana.getWhite() > 0) { - mana.set(ManaType.WHITE, CardUtil.multiplyWithOverflowCheck(mana.getWhite(), 3)); + mana.set(ManaType.WHITE, CardUtil.overflowMultiply(mana.getWhite(), 3)); } if (mana.getGreen() > 0) { - mana.set(ManaType.GREEN, CardUtil.multiplyWithOverflowCheck(mana.getGreen(), 3)); + mana.set(ManaType.GREEN, CardUtil.overflowMultiply(mana.getGreen(), 3)); } if (mana.getRed() > 0) { - mana.set(ManaType.RED, CardUtil.multiplyWithOverflowCheck(mana.getRed(), 3)); + mana.set(ManaType.RED, CardUtil.overflowMultiply(mana.getRed(), 3)); } if (mana.getColorless() > 0) { - mana.set(ManaType.COLORLESS, CardUtil.multiplyWithOverflowCheck(mana.getColorless(), 3)); + mana.set(ManaType.COLORLESS, CardUtil.overflowMultiply(mana.getColorless(), 3)); } return false; } diff --git a/Mage.Sets/src/mage/cards/o/OboshThePreypiercer.java b/Mage.Sets/src/mage/cards/o/OboshThePreypiercer.java index 721b6159da..8383689f01 100644 --- a/Mage.Sets/src/mage/cards/o/OboshThePreypiercer.java +++ b/Mage.Sets/src/mage/cards/o/OboshThePreypiercer.java @@ -102,7 +102,7 @@ class OboshThePreypiercerEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/o/Overblaze.java b/Mage.Sets/src/mage/cards/o/Overblaze.java index 9cd3621f3f..88486a28cd 100644 --- a/Mage.Sets/src/mage/cards/o/Overblaze.java +++ b/Mage.Sets/src/mage/cards/o/Overblaze.java @@ -78,7 +78,7 @@ class OverblazeEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } diff --git a/Mage.Sets/src/mage/cards/p/Phthisis.java b/Mage.Sets/src/mage/cards/p/Phthisis.java index 1e7a599844..ce6805d4b1 100644 --- a/Mage.Sets/src/mage/cards/p/Phthisis.java +++ b/Mage.Sets/src/mage/cards/p/Phthisis.java @@ -66,7 +66,7 @@ class PhthisisEffect extends OneShotEffect { if (creature != null) { Player controller = game.getPlayer(creature.getControllerId()); if (controller != null) { - int lifeLoss = CardUtil.addWithOverflowCheck(creature.getPower().getValue(), creature.getToughness().getValue()); + int lifeLoss = CardUtil.overflowInc(creature.getPower().getValue(), creature.getToughness().getValue()); creature.destroy(source, game, false); // the life loss happens also if the creature is indestructible or regenerated (legal targets) controller.loseLife(lifeLoss, game, source, false); diff --git a/Mage.Sets/src/mage/cards/p/PredatorsRapport.java b/Mage.Sets/src/mage/cards/p/PredatorsRapport.java index 501052376f..4ab331686d 100644 --- a/Mage.Sets/src/mage/cards/p/PredatorsRapport.java +++ b/Mage.Sets/src/mage/cards/p/PredatorsRapport.java @@ -47,7 +47,7 @@ class TargetPermanentPowerPlusToughnessCount implements DynamicValue { public int calculate(Game game, Ability sourceAbility, Effect effect) { Permanent sourcePermanent = game.getPermanent(sourceAbility.getFirstTarget()); if (sourcePermanent != null) { - return CardUtil.addWithOverflowCheck(sourcePermanent.getPower().getValue(), sourcePermanent.getToughness().getValue()); + return CardUtil.overflowInc(sourcePermanent.getPower().getValue(), sourcePermanent.getToughness().getValue()); } return 0; } diff --git a/Mage.Sets/src/mage/cards/p/PyromancersGauntlet.java b/Mage.Sets/src/mage/cards/p/PyromancersGauntlet.java index 4e56c86f57..73d68e6a5c 100644 --- a/Mage.Sets/src/mage/cards/p/PyromancersGauntlet.java +++ b/Mage.Sets/src/mage/cards/p/PyromancersGauntlet.java @@ -76,7 +76,7 @@ class PyromancersGauntletReplacementEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), 2)); + event.setAmount(CardUtil.overflowInc(event.getAmount(), 2)); return false; } diff --git a/Mage.Sets/src/mage/cards/p/PyromancersSwath.java b/Mage.Sets/src/mage/cards/p/PyromancersSwath.java index 9bcae7d269..3f509960cc 100644 --- a/Mage.Sets/src/mage/cards/p/PyromancersSwath.java +++ b/Mage.Sets/src/mage/cards/p/PyromancersSwath.java @@ -81,7 +81,7 @@ class PyromancersSwathReplacementEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), 2)); + event.setAmount(CardUtil.overflowInc(event.getAmount(), 2)); return false; } diff --git a/Mage.Sets/src/mage/cards/q/QuestForPureFlame.java b/Mage.Sets/src/mage/cards/q/QuestForPureFlame.java index e11f82d588..1cfc1cf0e9 100644 --- a/Mage.Sets/src/mage/cards/q/QuestForPureFlame.java +++ b/Mage.Sets/src/mage/cards/q/QuestForPureFlame.java @@ -17,7 +17,6 @@ import mage.constants.Zone; import mage.counters.CounterType; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.util.CardUtil; import java.util.UUID; @@ -119,7 +118,7 @@ class QuestForPureFlameEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), event.getAmount())); + event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2)); return false; } } diff --git a/Mage.Sets/src/mage/cards/s/Sentinel.java b/Mage.Sets/src/mage/cards/s/Sentinel.java index 323593fc76..4b44b0fcba 100644 --- a/Mage.Sets/src/mage/cards/s/Sentinel.java +++ b/Mage.Sets/src/mage/cards/s/Sentinel.java @@ -80,7 +80,7 @@ class SentinelEffect extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); Permanent targetPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source); if (controller != null && targetPermanent != null) { - int newToughness = CardUtil.addWithOverflowCheck(targetPermanent.getPower().getValue(), 1); + int newToughness = CardUtil.overflowInc(targetPermanent.getPower().getValue(), 1); game.addEffect(new SetToughnessSourceEffect(StaticValue.get(newToughness), Duration.Custom, SubLayer.SetPT_7b), source); return true; } diff --git a/Mage.Sets/src/mage/cards/s/SulfuricVapors.java b/Mage.Sets/src/mage/cards/s/SulfuricVapors.java index 2efe5d53ba..24ce38ec62 100644 --- a/Mage.Sets/src/mage/cards/s/SulfuricVapors.java +++ b/Mage.Sets/src/mage/cards/s/SulfuricVapors.java @@ -77,7 +77,7 @@ class SulfuricVaporsEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), 1)); + event.setAmount(CardUtil.overflowInc(event.getAmount(), 1)); return false; } diff --git a/Mage.Sets/src/mage/cards/s/SwornDefender.java b/Mage.Sets/src/mage/cards/s/SwornDefender.java index 2032339f9e..bd869df8bb 100644 --- a/Mage.Sets/src/mage/cards/s/SwornDefender.java +++ b/Mage.Sets/src/mage/cards/s/SwornDefender.java @@ -74,8 +74,8 @@ class SwornDefenderEffect extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); Permanent targetPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source); if (controller != null && targetPermanent != null) { - int newPower = CardUtil.subtractWithOverflowCheck(targetPermanent.getToughness().getValue(), 1); - int newToughness = CardUtil.addWithOverflowCheck(targetPermanent.getPower().getValue(), 1); + int newPower = CardUtil.overflowDec(targetPermanent.getToughness().getValue(), 1); + int newToughness = CardUtil.overflowInc(targetPermanent.getPower().getValue(), 1); game.addEffect(new SetPowerToughnessSourceEffect(newPower, newToughness, Duration.EndOfTurn, SubLayer.SetPT_7b), source); return true; } diff --git a/Mage.Sets/src/mage/cards/t/TheFlameOfKeld.java b/Mage.Sets/src/mage/cards/t/TheFlameOfKeld.java index 1fb9383bfb..578355e355 100644 --- a/Mage.Sets/src/mage/cards/t/TheFlameOfKeld.java +++ b/Mage.Sets/src/mage/cards/t/TheFlameOfKeld.java @@ -65,7 +65,7 @@ class TheFlameOfKeldDamageEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), 2)); + event.setAmount(CardUtil.overflowInc(event.getAmount(), 2)); return false; } diff --git a/Mage.Sets/src/mage/cards/t/TorbranThaneOfRedFell.java b/Mage.Sets/src/mage/cards/t/TorbranThaneOfRedFell.java index 7f0b09a09d..418850d4f3 100644 --- a/Mage.Sets/src/mage/cards/t/TorbranThaneOfRedFell.java +++ b/Mage.Sets/src/mage/cards/t/TorbranThaneOfRedFell.java @@ -58,7 +58,7 @@ class TorbranThaneOfRedFellEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - event.setAmount(CardUtil.addWithOverflowCheck(event.getAmount(), 2)); + event.setAmount(CardUtil.overflowInc(event.getAmount(), 2)); return false; } diff --git a/Mage.Sets/src/mage/cards/w/WallOfTombstones.java b/Mage.Sets/src/mage/cards/w/WallOfTombstones.java index d1399069cd..cf3d579f77 100644 --- a/Mage.Sets/src/mage/cards/w/WallOfTombstones.java +++ b/Mage.Sets/src/mage/cards/w/WallOfTombstones.java @@ -64,7 +64,7 @@ class WallOfTombstonesEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int newToughness = CardUtil.addWithOverflowCheck(1, new CardsInControllerGraveyardCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this)); + int newToughness = CardUtil.overflowInc(1, new CardsInControllerGraveyardCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this)); game.addEffect(new SetToughnessSourceEffect(StaticValue.get(newToughness), Duration.Custom, SubLayer.SetPT_7b), source); return true; } diff --git a/Mage/src/main/java/mage/MageInt.java b/Mage/src/main/java/mage/MageInt.java index 9507918a8c..1faf335299 100644 --- a/Mage/src/main/java/mage/MageInt.java +++ b/Mage/src/main/java/mage/MageInt.java @@ -80,7 +80,7 @@ public class MageInt implements Serializable, Copyable { } public void boostValue(int amount) { - this.boostedValue = CardUtil.addWithOverflowCheck(this.boostedValue, amount); + this.boostedValue = CardUtil.overflowInc(this.boostedValue, amount); } public void resetToBaseValue() { diff --git a/Mage/src/main/java/mage/Mana.java b/Mage/src/main/java/mage/Mana.java index 8c73b6aef2..5bb92c6d1e 100644 --- a/Mage/src/main/java/mage/Mana.java +++ b/Mage/src/main/java/mage/Mana.java @@ -41,20 +41,20 @@ public class Mana implements Comparable, Serializable, Copyable { } protected void incrementAmount(ManaColor manaColor) { - this.amount = CardUtil.addWithOverflowCheck(this.amount, manaColor.amount); - this.snowAmount = CardUtil.addWithOverflowCheck(this.snowAmount, manaColor.snowAmount); + this.amount = CardUtil.overflowInc(this.amount, manaColor.amount); + this.snowAmount = CardUtil.overflowInc(this.snowAmount, manaColor.snowAmount); } protected void incrementAmount(int amount, boolean snow) { - this.amount = CardUtil.addWithOverflowCheck(this.amount, amount); + this.amount = CardUtil.overflowInc(this.amount, amount); if (snow) { - this.snowAmount = CardUtil.addWithOverflowCheck(this.snowAmount, amount); + this.snowAmount = CardUtil.overflowInc(this.snowAmount, amount); } } protected void removeAmount(ManaColor manaColor) { - this.amount = CardUtil.subtractWithOverflowCheck(this.amount, manaColor.amount); - this.snowAmount = CardUtil.subtractWithOverflowCheck(this.snowAmount, manaColor.snowAmount); + this.amount = CardUtil.overflowDec(this.amount, manaColor.amount); + this.snowAmount = CardUtil.overflowDec(this.snowAmount, manaColor.snowAmount); } protected void clear() { @@ -67,11 +67,11 @@ public class Mana implements Comparable, Serializable, Copyable { return false; } if (manaColor.getSnowAmount() > 0) { - manaColor.snowAmount = CardUtil.subtractWithOverflowCheck(manaColor.snowAmount, 1); - this.snowAmount = CardUtil.addWithOverflowCheck(this.snowAmount, 1); + manaColor.snowAmount = CardUtil.overflowDec(manaColor.snowAmount, 1); + this.snowAmount = CardUtil.overflowInc(this.snowAmount, 1); } - manaColor.amount = CardUtil.subtractWithOverflowCheck(manaColor.amount, 1); - this.amount = CardUtil.addWithOverflowCheck(this.amount, 1); + manaColor.amount = CardUtil.overflowDec(manaColor.amount, 1); + this.amount = CardUtil.overflowInc(this.amount, 1); return true; } @@ -597,25 +597,25 @@ public class Mana implements Comparable, Serializable, Copyable { } int count = 0; if (filter.isWhite()) { - count = CardUtil.addWithOverflowCheck(count, white.getAmount()); + count = CardUtil.overflowInc(count, white.getAmount()); } if (filter.isBlue()) { - count = CardUtil.addWithOverflowCheck(count, blue.getAmount()); + count = CardUtil.overflowInc(count, blue.getAmount()); } if (filter.isBlack()) { - count = CardUtil.addWithOverflowCheck(count, black.getAmount()); + count = CardUtil.overflowInc(count, black.getAmount()); } if (filter.isRed()) { - count = CardUtil.addWithOverflowCheck(count, red.getAmount()); + count = CardUtil.overflowInc(count, red.getAmount()); } if (filter.isGreen()) { - count = CardUtil.addWithOverflowCheck(count, green.getAmount()); + count = CardUtil.overflowInc(count, green.getAmount()); } if (filter.isGeneric()) { - count = CardUtil.addWithOverflowCheck(count, generic.getAmount()); + count = CardUtil.overflowInc(count, generic.getAmount()); } if (filter.isColorless()) { - count = CardUtil.addWithOverflowCheck(count, colorless.getAmount()); + count = CardUtil.overflowInc(count, colorless.getAmount()); } return count; } @@ -811,13 +811,13 @@ public class Mana implements Comparable, Serializable, Copyable { } if (compare.generic.getAmount() < 0) { int remaining = 0; - remaining = CardUtil.addWithOverflowCheck(remaining, Math.min(0, compare.white.getAmount())); - remaining = CardUtil.addWithOverflowCheck(remaining, Math.min(0, compare.blue.getAmount())); - remaining = CardUtil.addWithOverflowCheck(remaining, Math.min(0, compare.black.getAmount())); - remaining = CardUtil.addWithOverflowCheck(remaining, Math.min(0, compare.red.getAmount())); - remaining = CardUtil.addWithOverflowCheck(remaining, Math.min(0, compare.green.getAmount())); - remaining = CardUtil.addWithOverflowCheck(remaining, Math.min(0, compare.colorless.getAmount())); - remaining = CardUtil.addWithOverflowCheck(remaining, Math.min(0, compare.any.getAmount())); + remaining = CardUtil.overflowInc(remaining, Math.min(0, compare.white.getAmount())); + remaining = CardUtil.overflowInc(remaining, Math.min(0, compare.blue.getAmount())); + remaining = CardUtil.overflowInc(remaining, Math.min(0, compare.black.getAmount())); + remaining = CardUtil.overflowInc(remaining, Math.min(0, compare.red.getAmount())); + remaining = CardUtil.overflowInc(remaining, Math.min(0, compare.green.getAmount())); + remaining = CardUtil.overflowInc(remaining, Math.min(0, compare.colorless.getAmount())); + remaining = CardUtil.overflowInc(remaining, Math.min(0, compare.any.getAmount())); if (remaining > 0) { int diff = Math.min(remaining, Math.abs(compare.generic.getAmount())); compare.generic.incrementAmount(diff, false); @@ -1148,7 +1148,7 @@ public class Mana implements Comparable, Serializable, Copyable { case GREEN: return green.getAmount(); case COLORLESS: - return CardUtil.addWithOverflowCheck(generic.getAmount(), colorless.getAmount()); + return CardUtil.overflowInc(generic.getAmount(), colorless.getAmount()); } return 0; } @@ -1246,7 +1246,7 @@ public class Mana implements Comparable, Serializable, Copyable { && this.green.getAmount() >= mana.green.getAmount() && this.colorless.getAmount() >= mana.colorless.getAmount() && (this.generic.getAmount() >= mana.generic.getAmount() - || CardUtil.addWithOverflowCheck(this.countColored(), this.colorless.getAmount()) >= mana.count()); + || CardUtil.overflowInc(this.countColored(), this.colorless.getAmount()) >= mana.count()); } @@ -1282,33 +1282,33 @@ public class Mana implements Comparable, Serializable, Copyable { moreMana = mana1; lessMana = mana2; } - int anyDiff = CardUtil.subtractWithOverflowCheck(mana2.getAny(), mana1.getAny()); + int anyDiff = CardUtil.overflowDec(mana2.getAny(), mana1.getAny()); if (lessMana.getWhite() > moreMana.getWhite()) { - anyDiff = CardUtil.subtractWithOverflowCheck(anyDiff, CardUtil.subtractWithOverflowCheck(lessMana.getWhite(), moreMana.getWhite())); + anyDiff = CardUtil.overflowDec(anyDiff, CardUtil.overflowDec(lessMana.getWhite(), moreMana.getWhite())); if (anyDiff < 0) { return null; } } if (lessMana.getRed() > moreMana.getRed()) { - anyDiff = CardUtil.subtractWithOverflowCheck(anyDiff, CardUtil.subtractWithOverflowCheck(lessMana.getRed(), moreMana.getRed())); + anyDiff = CardUtil.overflowDec(anyDiff, CardUtil.overflowDec(lessMana.getRed(), moreMana.getRed())); if (anyDiff < 0) { return null; } } if (lessMana.getGreen() > moreMana.getGreen()) { - anyDiff = CardUtil.subtractWithOverflowCheck(anyDiff, CardUtil.subtractWithOverflowCheck(lessMana.getGreen(), moreMana.getGreen())); + anyDiff = CardUtil.overflowDec(anyDiff, CardUtil.overflowDec(lessMana.getGreen(), moreMana.getGreen())); if (anyDiff < 0) { return null; } } if (lessMana.getBlue() > moreMana.getBlue()) { - anyDiff = CardUtil.subtractWithOverflowCheck(anyDiff, CardUtil.subtractWithOverflowCheck(lessMana.getBlue(), moreMana.getBlue())); + anyDiff = CardUtil.overflowDec(anyDiff, CardUtil.overflowDec(lessMana.getBlue(), moreMana.getBlue())); if (anyDiff < 0) { return null; } } if (lessMana.getBlack() > moreMana.getBlack()) { - anyDiff = CardUtil.subtractWithOverflowCheck(anyDiff, CardUtil.subtractWithOverflowCheck(lessMana.getBlack(), moreMana.getBlack())); + anyDiff = CardUtil.overflowDec(anyDiff, CardUtil.overflowDec(lessMana.getBlack(), moreMana.getBlack())); if (anyDiff < 0) { return null; } diff --git a/Mage/src/main/java/mage/abilities/effects/mana/AddConditionalManaEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/AddConditionalManaEffect.java index b79d7c436b..c52e0744fb 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/AddConditionalManaEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/AddConditionalManaEffect.java @@ -58,7 +58,7 @@ public class AddConditionalManaEffect extends ManaEffect { if (amountAvailableMana > 0) { Mana calculatedMana = mana.copy(); for (ManaType manaType : ManaType.getTrueManaTypes()) { - calculatedMana.set(manaType, CardUtil.multiplyWithOverflowCheck(calculatedMana.get(manaType), amountAvailableMana)); + calculatedMana.set(manaType, CardUtil.overflowMultiply(calculatedMana.get(manaType), amountAvailableMana)); } maxAvailableMana.add(manaBuilder.setMana(calculatedMana, source, game).build()); } diff --git a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java index 4a54b96b63..7e5365d342 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java @@ -1026,7 +1026,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { addCounters(CounterType.M1M1.createInstance(actualDamage), game.getControllerId(attackerId), damageSourceAbility, game); } } else { - this.damage = CardUtil.addWithOverflowCheck(this.damage, actualDamage); + this.damage = CardUtil.overflowInc(this.damage, actualDamage); } DamagedEvent damagedEvent = new DamagedCreatureEvent(this.getId(), attackerId, this.getControllerId(), actualDamage, combat); damagedEvent.setExcess(actualDamage - lethal); diff --git a/Mage/src/main/java/mage/players/ManaPool.java b/Mage/src/main/java/mage/players/ManaPool.java index 7b27e7df8b..0d46942b27 100644 --- a/Mage/src/main/java/mage/players/ManaPool.java +++ b/Mage/src/main/java/mage/players/ManaPool.java @@ -388,7 +388,7 @@ public class ManaPool implements Serializable { private void removeConditional(ConditionalManaInfo manaInfo, Ability ability, Game game, Cost costToPay, Mana usedManaToPay) { for (ConditionalMana mana : getConditionalMana()) { if (mana.get(manaInfo.manaType) > 0 && mana.apply(ability, game, mana.getManaProducerId(), costToPay)) { - mana.set(manaInfo.manaType, CardUtil.subtractWithOverflowCheck(mana.get(manaInfo.manaType), 1)); + mana.set(manaInfo.manaType, CardUtil.overflowDec(mana.get(manaInfo.manaType), 1)); usedManaToPay.increase(manaInfo.manaType, manaInfo.sourceObject.isSnow()); GameEvent event = new ManaPaidEvent(ability, mana.getManaProducerId(), mana.getFlag(), mana.getManaProducerOriginalId()); game.fireEvent(event); diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 0cff215dfc..a7e6c65a8e 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -2004,7 +2004,7 @@ public abstract class PlayerImpl implements Player, Serializable { GameEvent event = new GameEvent(GameEvent.EventType.LOSE_LIFE, playerId, source, playerId, amount, atCombat); if (!game.replaceEvent(event)) { - this.life = CardUtil.subtractWithOverflowCheck(this.life, event.getAmount()); + this.life = CardUtil.overflowDec(this.life, event.getAmount()); if (!game.isSimulation()) { UUID needId = attackerId; if (needId == null) { @@ -2048,7 +2048,7 @@ public abstract class PlayerImpl implements Player, Serializable { // TODO: lock life at Integer.MAX_VALUE if reached, until it's set to a different amount // (https://magic.wizards.com/en/articles/archive/news/unstable-faqawaslfaqpaftidawabiajtbt-2017-12-06 - "infinite" life total stays infinite no matter how much is gained or lost) // this.life += event.getAmount(); - this.life = CardUtil.addWithOverflowCheck(this.life, event.getAmount()); + this.life = CardUtil.overflowInc(this.life, event.getAmount()); if (!game.isSimulation()) { game.informPlayers(this.getLogName() + " gains " + event.getAmount() + " life" + CardUtil.getSourceLogName(game, source)); } @@ -3244,7 +3244,7 @@ public abstract class PlayerImpl implements Player, Serializable { restVal = 0; availableLifeMana -= oldPayOption.get(manaType); } else { - restVal = CardUtil.subtractWithOverflowCheck(oldPayOption.get(manaType), availableLifeMana); + restVal = CardUtil.overflowDec(oldPayOption.get(manaType), availableLifeMana); availableLifeMana = 0; } manaCopy.set(manaType, restVal); diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index eb8346df6a..5a4894e005 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -628,44 +628,49 @@ public final class CardUtil { return "" + text + ""; } - public static boolean cardCanBePlayedNow(Card card, UUID playerId, Game game) { - if (card.isLand()) { - return game.canPlaySorcery(playerId) && game.getPlayer(playerId).canPlayLand(); + /** + * Integer operation with overflow protection + * + * @param base + * @param increment + * @return + */ + public static int overflowInc(int base, int increment) { + return overflowResult((long) base + increment); + } + + /** + * Integer operation with overflow protection + * + * @param base + * @param decrement + * @return + */ + public static int overflowDec(int base, int decrement) { + return overflowResult((long) base - decrement); + } + + /** + * Integer operation with overflow protection + * + * @param base + * @param multiply + * @return + */ + public static int overflowMultiply(int base, int multiply) { + return overflowResult((long) base * multiply); + } + + private static int overflowResult(long value) { + if (value > Integer.MAX_VALUE) { + return Integer.MAX_VALUE; + } else if (value < Integer.MIN_VALUE) { + return Integer.MIN_VALUE; } else { - return card.getSpellAbility() != null && card.getSpellAbility().spellCanBeActivatedRegularlyNow(playerId, game); + return (int) value; } } - public static int addWithOverflowCheck(int base, int increment) { - long result = ((long) base) + increment; - if (result > Integer.MAX_VALUE) { - return Integer.MAX_VALUE; - } else if (result < Integer.MIN_VALUE) { - return Integer.MIN_VALUE; - } - return base + increment; - } - - public static int subtractWithOverflowCheck(int base, int decrement) { - long result = ((long) base) - decrement; - if (result > Integer.MAX_VALUE) { - return Integer.MAX_VALUE; - } else if (result < Integer.MIN_VALUE) { - return Integer.MIN_VALUE; - } - return base - decrement; - } - - public static int multiplyWithOverflowCheck(int base, int multiply) { - long result = ((long) base) * multiply; - if (result > Integer.MAX_VALUE) { - return Integer.MAX_VALUE; - } else if (result < Integer.MIN_VALUE) { - return Integer.MIN_VALUE; - } - return base * multiply; - } - public static String createObjectRealtedWindowTitle(Ability source, Game game, String textSuffix) { String title; if (source != null) {