From 6958183d11b5202e48caa425f0e9efeff8fb8957 Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 05:20:52 +0000 Subject: [PATCH] - Added ability to play cards that "Any Player May Play" - AI may not be properly using it - Added flying pestilence ability for Ifh-Biff Efreet - Added both player usage of ability for Aluren - Fixed infinite loop in Aluren (We should bring back canPlayAI code for Aluren now) --- res/cards.txt | 14 +++---- src/forge/Card.java | 9 +++++ src/forge/CardFactory.java | 3 +- src/forge/CardFactory_Creatures.java | 53 +++++++++++++++++++++++++++ src/forge/ComputerUtil.java | 12 ++++++ src/forge/InputUtil.java | 55 ++++++++++++++-------------- src/forge/SpellAbility.java | 9 +++++ 7 files changed, 118 insertions(+), 37 deletions(-) diff --git a/res/cards.txt b/res/cards.txt index 19e4541751b..cf7a6fb03a3 100644 --- a/res/cards.txt +++ b/res/cards.txt @@ -1,3 +1,10 @@ +Ifh-Biff Efreet +2 G G +Creature Efreet +no text +3/3 +Flying + Abyssal Horror 4 B B Creature Horror @@ -20997,13 +21004,6 @@ Gift of Estates Sorcery If an opponent controls more lands than you, search your library for up to three Plains cards and put them into your hand. -Ifh-Biff Efreet -2 G G -Creature Efreet -(NOTE: "G: Ifh-Biff Efreet deals 1 damage to each creature with flying and each player. Any player may activate this ability." not implemented.) -3/3 -Flying - Arashi, the Sky Asunder 3 G G Legendary Creature Spirit diff --git a/src/forge/Card.java b/src/forge/Card.java index 4d54f659a33..c30e019c008 100644 --- a/src/forge/Card.java +++ b/src/forge/Card.java @@ -235,6 +235,15 @@ public class Card extends MyObservable { return dealtCombatDmgToOppThisTurn; } + public boolean canAnyPlayerActivate() { + for(SpellAbility s : spellAbility) + { + if (s.isAnyPlayer()) + return true; + } + return false; + } + public void setDealtDmgToOppThisTurn(boolean b) { dealtDmgToOppThisTurn = b; } diff --git a/src/forge/CardFactory.java b/src/forge/CardFactory.java index aeb40d53408..f3da360b05a 100644 --- a/src/forge/CardFactory.java +++ b/src/forge/CardFactory.java @@ -15456,9 +15456,8 @@ public class CardFactory implements NewConstants { ability1.setDescription("Any player may play creature cards with converted mana cost 3 or less without paying their mana cost any time he or she could play an instant."); ability1.setStackDescription("Aluren - Play creature with converted manacost 3 or less for free."); + ability1.setAnyPlayer(true); card.addSpellAbility(ability1); - ability1.setBeforePayMana(new Input_PayManaCost(ability1)); - } //*************** END ************ END ************************** diff --git a/src/forge/CardFactory_Creatures.java b/src/forge/CardFactory_Creatures.java index 927321756a9..9ae51315363 100644 --- a/src/forge/CardFactory_Creatures.java +++ b/src/forge/CardFactory_Creatures.java @@ -20541,6 +20541,59 @@ public class CardFactory_Creatures { } //*************** END ************ END ************************** + //*************** START *********** START ************************** + else if(cardName.equals("Ifh-Biff Efreet")) { + final SpellAbility ability = new Ability(card, "G") { + + @Override + public boolean canPlayAI() { + //todo(sol) setting up some AI for next go through + CardList human = new CardList(AllZone.Human_Play.getCards()); + CardList computer = new CardList(AllZone.Computer_Play.getCards()); + + human = human.getType("Creature").getKeyword("Flying"); + computer = computer.getType("Creature").getKeyword("Flying"); + + //int compLife = AllZone.Computer_Life.getLife(); + //int humanLife = AllZone.Human_Life.getLife(); + + // if complife > humanLife && humanlife <= available green mana, try to kill human + + if (card.getController().equals(Constant.Player.Computer)){ + // needs to be careful activating ability if human has green mana available + } + else{ + // should try to kill human's flyers but spare own + return true; + } + + return false; + } + + @Override + public void resolve() { + //get all creatures + CardList list = new CardList(); + list.addAll(AllZone.Human_Play.getCards()); + list.addAll(AllZone.Computer_Play.getCards()); + list = list.getType("Creature"); + list = list.getKeyword("Flying"); + + for(int i = 0; i < list.size(); i++) { + if(CardFactoryUtil.canDamage(card, list.get(i))) list.get(i).addDamage(1, card); + } + + AllZone.Human_Life.subtractLife(1,card); + AllZone.Computer_Life.subtractLife(1,card); + }//resolve() + };//SpellAbility + ability.setDescription("G: Ifh-Bíff Efreet deals 1 damage to each creature with flying and each player. Any player may activate this ability"); + ability.setStackDescription(card + " deals 1 damage to each flying creature and each player."); + ability.setAnyPlayer(true); + card.addSpellAbility(ability); + } + //*************** END ************ END ************************** + //*************** START *********** START ************************** if (cardName.equals("Roc Egg")) { final SpellAbility ability = new Ability(card, "0") { diff --git a/src/forge/ComputerUtil.java b/src/forge/ComputerUtil.java index 8bd6e98430b..8a114458d82 100644 --- a/src/forge/ComputerUtil.java +++ b/src/forge/ComputerUtil.java @@ -119,6 +119,18 @@ public class ComputerUtil all.addAll(AllZone.Computer_Hand.getCards()); all.addAll(CardFactoryUtil.getFlashbackUnearthCards(Constant.Player.Computer).toArray()); + CardList humanPlayable = new CardList(); + humanPlayable.addAll(AllZone.Human_Play.getCards()); + humanPlayable = humanPlayable.filter(new CardListFilter() + { + public boolean addCard(Card c) + { + return (c.canAnyPlayerActivate()); + } + }); + + all.addAll(humanPlayable.toArray()); + all = all.filter(new CardListFilter() { public boolean addCard(Card c) diff --git a/src/forge/InputUtil.java b/src/forge/InputUtil.java index e1f43c44765..77d9af9bf2d 100644 --- a/src/forge/InputUtil.java +++ b/src/forge/InputUtil.java @@ -6,45 +6,44 @@ public class InputUtil //plays activated abilities and instants static public void playInstantAbility(Card card, PlayerZone zone) { - if(zone.is(Constant.Zone.Hand) || zone.is(Constant.Zone.Play, Constant.Player.Human)) + if (zone.is(Constant.Zone.Hand, Constant.Player.Human) || zone.is(Constant.Zone.Play) && + (card.getController().equals(Constant.Player.Human) || card.canAnyPlayerActivate())) AllZone.GameAction.playCard(card); } //plays activated abilities and any card including land, sorceries, and instants static public void playAnyCard(Card card, PlayerZone zone) { - if(zone.is(Constant.Zone.Hand, Constant.Player.Human) && - (card.isLand())) - { - - //hacky stuff: see if there's cycling/transmute/other hand abilities on the land: - SpellAbility[] sa = card.getSpellAbility(); - if (sa.length > 0) + if(zone.is(Constant.Zone.Hand, Constant.Player.Human)){ // activate from hand + if (card.isLand()) { - int count = 0; - for (SpellAbility s : sa) + //hacky stuff: see if there's cycling/transmute/other hand abilities on the land: + SpellAbility[] sa = card.getSpellAbility(); + if (sa.length > 0) { - if (s.canPlay() && (s instanceof Ability_Hand)) - count++; + int count = 0; + for (SpellAbility s : sa) + { + if (s.canPlay() && (s instanceof Ability_Hand)) + count++; + } + if (count > 0) + AllZone.GameAction.playCard(card); + else //play the land + GameAction.playLand(card, zone); } - if (count > 0) - AllZone.GameAction.playCard(card); else //play the land GameAction.playLand(card, zone); + } //land + else + { + AllZone.GameAction.playCard(card); } - else //play the land - GameAction.playLand(card, zone); - } //land - /** - else if(zone.is(Constant.Zone.Hand, Constant.Player.Human) && - card.getManaCost().equals("0"))//for Mox Ruby and the like - { - AllZone.Human_Hand.remove(card); - AllZone.Stack.add(card.getSpellAbility()[0]); - } - **/ - else if (zone.is(Constant.Zone.Hand, Constant.Player.Human) || zone.is(Constant.Zone.Play, Constant.Player.Human) - || (zone.is(Constant.Zone.Play, Constant.Player.Computer)) && (card.isEquipment() || card.isAura()) && card.getController().equals(Constant.Player.Human) ) - AllZone.GameAction.playCard(card); + } + // (sol) Can activate if: You control it & it's in play or if your opponent controls it and Any Player Can activate. + else if (zone.is(Constant.Zone.Play) && + (card.getController().equals(Constant.Player.Human) || card.canAnyPlayerActivate())) + AllZone.GameAction.playCard(card); }//selectCard() + } \ No newline at end of file diff --git a/src/forge/SpellAbility.java b/src/forge/SpellAbility.java index 578fc3a7efe..b8941fdf313 100644 --- a/src/forge/SpellAbility.java +++ b/src/forge/SpellAbility.java @@ -32,6 +32,7 @@ public abstract class SpellAbility { private boolean multiKicker = false; private boolean xCost = false; private boolean kickerAbility = false; + private boolean anyPlayer = false; private Input beforePayMana; private Input afterResolve; @@ -174,6 +175,14 @@ public abstract class SpellAbility { return xCost; } + public void setAnyPlayer(boolean b) { + anyPlayer = b; + } + + public boolean isAnyPlayer() { + return anyPlayer; + } + public void setSourceCard(Card c) { sourceCard = c;