From b1de033f47ac0603df55b5ce0b9e74612f99618b Mon Sep 17 00:00:00 2001 From: Sloth Date: Sat, 20 Oct 2012 10:53:10 +0000 Subject: [PATCH] - Added Multiplayer support for unless costs (but not multiple humans yet). - Added "Any Player" support to unless costs. - Added Rhystic Tutor. --- .gitattributes | 1 + res/cardsfolder/r/rhystic_tutor.txt | 11 ++++ res/cardsfolder/w/wicked_akuba.txt | 1 + .../card/abilityfactory/AbilityFactory.java | 53 +++++++++++++------ 4 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 res/cardsfolder/r/rhystic_tutor.txt diff --git a/.gitattributes b/.gitattributes index 0f841b16701..87674615ebd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7926,6 +7926,7 @@ res/cardsfolder/r/rhys_the_exiled.txt svneol=native#text/plain res/cardsfolder/r/rhys_the_redeemed.txt svneol=native#text/plain res/cardsfolder/r/rhystic_deluge.txt svneol=native#text/plain res/cardsfolder/r/rhystic_study.txt svneol=native#text/plain +res/cardsfolder/r/rhystic_tutor.txt -text res/cardsfolder/r/rib_cage_spider.txt svneol=native#text/plain res/cardsfolder/r/ribbon_snake.txt -text res/cardsfolder/r/ribbons_of_night.txt -text svneol=unset#text/plain diff --git a/res/cardsfolder/r/rhystic_tutor.txt b/res/cardsfolder/r/rhystic_tutor.txt new file mode 100644 index 00000000000..812484a53fa --- /dev/null +++ b/res/cardsfolder/r/rhystic_tutor.txt @@ -0,0 +1,11 @@ +Name:Rhystic Tutor +ManaCost:2 B +Types:Sorcery +Text:no text +A:SP$ ChangeZone | Cost$ 2 B | Origin$ Library | Destination$ Hand | ChangeType$ Card | ChangeNum$ 1 | UnlessCost$ 2 | UnlessPayer$ Player | Mandatory$ True | SpellDescription$ Unless any player pays 2, search your library for a card, put that card into your hand, then shuffle your library. +SVar:RemAIDeck:True +SVar:Rarity:Rare +SVar:Picture:http://www.wizards.com/global/images/magic/general/rhystic_tutor.jpg +SetInfo:PCY|Rare|http://magiccards.info/scans/en/pr/77.jpg +Oracle:Unless any player pays {2}, search your library for a card, put that card into your hand, then shuffle your library. +End \ No newline at end of file diff --git a/res/cardsfolder/w/wicked_akuba.txt b/res/cardsfolder/w/wicked_akuba.txt index e26fee065dc..045422f7fd3 100644 --- a/res/cardsfolder/w/wicked_akuba.txt +++ b/res/cardsfolder/w/wicked_akuba.txt @@ -7,4 +7,5 @@ A:AB$ LoseLife | Cost$ B | ValidTgts$ Player.wasDealtDamageBySourceThisTurn | Tg SVar:Rarity:Uncommon SVar:Picture:http://www.wizards.com/global/images/magic/general/wicked_akuba.jpg SetInfo:CHK|Common|http://magiccards.info/scans/en/chk/150.jpg +Oracle:{B}: Target player dealt damage by Wicked Akuba this turn loses 1 life. End \ No newline at end of file diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactory.java b/src/main/java/forge/card/abilityfactory/AbilityFactory.java index 60ff7eebde9..20f24d16a27 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactory.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactory.java @@ -2784,7 +2784,7 @@ public class AbilityFactory { // The player who has the chance to cancel the ability final String pays = params.containsKey("UnlessPayer") ? params.get("UnlessPayer") : "TargetedController"; - final Player payer = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), pays, sa).get(0); + final ArrayList payers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), pays, sa); // The cost String unlessCost = params.get("UnlessCost").trim(); @@ -2809,7 +2809,6 @@ public class AbilityFactory { // nothing to do here } }; - ability.setActivatingPlayer(payer); final Command paidCommand = new Command() { private static final long serialVersionUID = 8094833091127334678L; @@ -2820,7 +2819,7 @@ public class AbilityFactory { } }; - final Command unpaidCommand = new Command() { + Command unpaidCommand = new Command() { private static final long serialVersionUID = 8094833091127334678L; @Override @@ -2832,27 +2831,49 @@ public class AbilityFactory { AbilityFactory.resolveSubAbilities(sa, usedStack); } }; - - if (payer.isHuman()) { - GameActionUtil.payCostDuringAbilityResolve(ability, cost, paidCommand, unpaidCommand, sa); - } else { - if (ComputerUtil.canPayCost(ability, payer) && CostUtil.checkLifeCost(payer, cost, source, 4, sa) - && CostUtil.checkDamageCost(payer, cost, source, 4) - && (!source.getName().equals("Tyrannize") || payer.getCardsIn(ZoneType.Hand).size() > 2)) { - // AI was crashing because the blank ability used to pay costs - // Didn't have any of the data on the original SA to pay dependant costs - ability.setTarget(sa.getTarget()); - ComputerUtil.playNoStack(payer, ability); // Unless cost was payed - no - // resolve + boolean paid = false; + for (Player payer : payers) { + if (payer.isComputer()) { + // AI will only pay when it's not already payed and only opponents abilities + if (paid || sa.getActivatingPlayer().equals(payer)) { + continue; + } + ability.setActivatingPlayer(payer); + if (ComputerUtil.canPayCost(ability, payer) && CostUtil.checkLifeCost(payer, cost, source, 4, sa) + && CostUtil.checkDamageCost(payer, cost, source, 4) + && (!source.getName().equals("Tyrannize") || payer.getCardsIn(ZoneType.Hand).size() > 2)) { + // AI was crashing because the blank ability used to pay costs + // Didn't have any of the data on the original SA to pay dependant costs + ability.setTarget(sa.getTarget()); + ComputerUtil.playNoStack(payer, ability); // Unless cost was payed - no resolve + paid = true; + } + } + } + boolean waitForInput = false; + for (Player payer : payers) { + if (payer.isHuman()) { + // if it's paid by the AI already the human can pay, but it won't change anything + if (paid) { + unpaidCommand = paidCommand; + } + GameActionUtil.payCostDuringAbilityResolve(ability, cost, paidCommand, unpaidCommand, sa); + waitForInput = true; // wait for the human input + break; // multiple human players are not supported + } + } + if (!waitForInput) { + if (paid) { AbilityFactory.resolveSubAbilities(sa, usedStack); } else { sa.resolve(); if (params.containsKey("PowerSink")) { - GameActionUtil.doPowerSink(payer); + GameActionUtil.doPowerSink(payers.get(0)); } AbilityFactory.resolveSubAbilities(sa, usedStack); } } + } /**