From b0af22677aab9c91a054d98e6b78c4da8ee59443 Mon Sep 17 00:00:00 2001 From: L_J Date: Sun, 26 Aug 2018 20:33:23 +0000 Subject: [PATCH 1/3] Implemented Mages' Contest --- Mage.Sets/src/mage/cards/m/MagesContest.java | 102 +++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/m/MagesContest.java diff --git a/Mage.Sets/src/mage/cards/m/MagesContest.java b/Mage.Sets/src/mage/cards/m/MagesContest.java new file mode 100644 index 00000000000..56b1a0d7a02 --- /dev/null +++ b/Mage.Sets/src/mage/cards/m/MagesContest.java @@ -0,0 +1,102 @@ + +package mage.cards.m; + +import java.util.Objects; +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.game.Game; +import mage.game.stack.Spell; +import mage.players.Player; +import mage.target.TargetSpell; +import mage.util.RandomUtil; + +/** + * + * @author Quercitron & L_J + */ +public final class MagesContest extends CardImpl { + + public MagesContest(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{R}{R}"); + + // You and target spell's controller bid life. You start the bidding with a bid of 1. In turn order, each player may top the high bid. The bidding ends if the high bid stands. The high bidder loses life equal to the high bid. If you win the bidding, counter that spell. + this.getSpellAbility().addEffect(new MagesContestEffect()); + this.getSpellAbility().addTarget(new TargetSpell()); + + } + + public MagesContest(final MagesContest card) { + super(card); + } + + @Override + public MagesContest copy() { + return new MagesContest(this); + } +} + +class MagesContestEffect extends OneShotEffect { + + public MagesContestEffect() { + super(Outcome.Detriment); + this.staticText = "You and target spell's controller bid life. You start the bidding with a bid of 1. In turn order, each player may top the high bid. The bidding ends if the high bid stands. The high bidder loses life equal to the high bid. If you win the bidding, counter that spell"; + } + + public MagesContestEffect(final MagesContestEffect effect) { + super(effect); + } + + @Override + public MagesContestEffect copy() { + return new MagesContestEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source)); + if (spell != null) { + Player you = game.getPlayer(source.getControllerId()); + Player spellController = game.getPlayer(spell.getControllerId()); + if (you != null && spellController != null) { + int highBid = 1; + game.informPlayers(you.getLogName() + " has bet " + highBid + " life"); + Player winner = you; + Player currentPlayer = spellController; + do { + if (currentPlayer != null && currentPlayer.canRespond()) { + int newBid = 0; + if (!currentPlayer.isHuman()) { + // make AI evaluate value of the spell to decide on bidding, should be reworked + int maxBid = Math.min(RandomUtil.nextInt(currentPlayer.getLife()) + RandomUtil.nextInt(spell.getConvertedManaCost()), currentPlayer.getLife()); + if (highBid + 1 < maxBid) { + newBid = highBid + 1; + } + } else if (currentPlayer.chooseUse(Outcome.Benefit, winner.getLogName() + " has bet " + highBid + " life. Top the bid?", source, game)) { + newBid = currentPlayer.getAmount(highBid + 1, Integer.MAX_VALUE, "Choose bid", game); + } + if (newBid > highBid) { + highBid = newBid; + winner = currentPlayer; + game.informPlayers(currentPlayer.getLogName() + " has bet " + newBid + " life"); + currentPlayer = (winner == you ? spellController : you); + } else { + break; + } + } + } while (!Objects.equals(currentPlayer, winner)); + game.informPlayers(winner.getLogName() + " has won the contest with a high bid of " + highBid + " life"); + winner.loseLife(highBid, game, false); + if (winner == you) { + game.getStack().counter(spell.getId(), source.getSourceId(), game); + } + return true; + } + } + return false; + } +} From a45c7dd22f5b746ca51282fa41ac3888a257abf7 Mon Sep 17 00:00:00 2001 From: L_J Date: Sun, 26 Aug 2018 20:34:31 +0000 Subject: [PATCH 2/3] Implemented Mages' Contest --- Mage.Sets/src/mage/sets/Invasion.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Mage.Sets/src/mage/sets/Invasion.java b/Mage.Sets/src/mage/sets/Invasion.java index f5fb547f149..7aef568c5aa 100644 --- a/Mage.Sets/src/mage/sets/Invasion.java +++ b/Mage.Sets/src/mage/sets/Invasion.java @@ -165,6 +165,7 @@ public final class Invasion extends ExpansionSet { cards.add(new SetCardInfo("Loafing Giant", 153, Rarity.RARE, mage.cards.l.LoafingGiant.class)); cards.add(new SetCardInfo("Lobotomy", 255, Rarity.UNCOMMON, mage.cards.l.Lobotomy.class)); cards.add(new SetCardInfo("Lotus Guardian", 305, Rarity.RARE, mage.cards.l.LotusGuardian.class)); + cards.add(new SetCardInfo("Mages' Contest", 154, Rarity.RARE, mage.cards.m.MagesContest.class)); cards.add(new SetCardInfo("Mana Maze", 59, Rarity.RARE, mage.cards.m.ManaMaze.class)); cards.add(new SetCardInfo("Maniacal Rage", 155, Rarity.COMMON, mage.cards.m.ManiacalRage.class)); cards.add(new SetCardInfo("Manipulate Fate", 60, Rarity.UNCOMMON, mage.cards.m.ManipulateFate.class)); From dca2ec174b053ffc0a0b72371b7480e1b7b92105 Mon Sep 17 00:00:00 2001 From: L_J Date: Tue, 28 Aug 2018 15:08:05 +0000 Subject: [PATCH 3/3] Modified bidding evaluation for AI (Mages' Contest) --- Mage.Sets/src/mage/cards/m/MagesContest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage.Sets/src/mage/cards/m/MagesContest.java b/Mage.Sets/src/mage/cards/m/MagesContest.java index 56b1a0d7a02..bf7b44a7c1a 100644 --- a/Mage.Sets/src/mage/cards/m/MagesContest.java +++ b/Mage.Sets/src/mage/cards/m/MagesContest.java @@ -72,7 +72,7 @@ class MagesContestEffect extends OneShotEffect { int newBid = 0; if (!currentPlayer.isHuman()) { // make AI evaluate value of the spell to decide on bidding, should be reworked - int maxBid = Math.min(RandomUtil.nextInt(currentPlayer.getLife()) + RandomUtil.nextInt(spell.getConvertedManaCost()), currentPlayer.getLife()); + int maxBid = Math.min(RandomUtil.nextInt(Math.max(currentPlayer.getLife(), 0)) + RandomUtil.nextInt(spell.getConvertedManaCost()), currentPlayer.getLife()); if (highBid + 1 < maxBid) { newBid = highBid + 1; }