From e4f37837c8f7448f0cec649a11f0efa92c050bec Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 10:08:50 +0000 Subject: [PATCH] consolidate code from Player and GameAction classes related to sacrifice permanents. --- src/forge/CardFactory_Creatures.java | 2 +- src/forge/CardFactory_Instants.java | 2 +- src/forge/CardFactory_Sorceries.java | 11 ++++---- src/forge/GameAction.java | 40 ---------------------------- src/forge/GameActionUtil.java | 6 ++--- src/forge/Player.java | 9 +++++++ 6 files changed, 18 insertions(+), 52 deletions(-) diff --git a/src/forge/CardFactory_Creatures.java b/src/forge/CardFactory_Creatures.java index 6e9a863b77f..c90f46cd258 100644 --- a/src/forge/CardFactory_Creatures.java +++ b/src/forge/CardFactory_Creatures.java @@ -18044,7 +18044,7 @@ public class CardFactory_Creatures { public void resolve() { if (card.getController().equals(AllZone.ComputerPlayer)) setTargetPlayer(AllZone.HumanPlayer); - AllZone.GameAction.sacrificeCreature(getTargetPlayer(), this); + getTargetPlayer().sacrificeCreature(); card.setKicked(false); } diff --git a/src/forge/CardFactory_Instants.java b/src/forge/CardFactory_Instants.java index 760fd97459c..befa3fc52ee 100644 --- a/src/forge/CardFactory_Instants.java +++ b/src/forge/CardFactory_Instants.java @@ -3346,7 +3346,7 @@ public class CardFactory_Instants { @Override public void resolve() { - AllZone.GameAction.sacrificeCreature(getTargetPlayer(), this); + getTargetPlayer().sacrificeCreature(); } @Override diff --git a/src/forge/CardFactory_Sorceries.java b/src/forge/CardFactory_Sorceries.java index 69eba0a8d5c..42f89bd16fa 100644 --- a/src/forge/CardFactory_Sorceries.java +++ b/src/forge/CardFactory_Sorceries.java @@ -4091,8 +4091,8 @@ public class CardFactory_Sorceries { @Override public void resolve() { - AllZone.GameAction.sacrificeCreature(AllZone.HumanPlayer, this); - AllZone.GameAction.sacrificeCreature(AllZone.ComputerPlayer, this); + AllZone.HumanPlayer.sacrificeCreature(); + AllZone.ComputerPlayer.sacrificeCreature(); } @Override @@ -4129,7 +4129,7 @@ public class CardFactory_Sorceries { @Override public void resolve() { - AllZone.GameAction.sacrificeCreature(getTargetPlayer(), this); + getTargetPlayer().sacrificeCreature(); } @Override @@ -4171,7 +4171,7 @@ public class CardFactory_Sorceries { PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, card.getController()); PlayerZone removed = AllZone.getZone(Constant.Zone.Removed_From_Play, card.getController()); - AllZone.GameAction.sacrificeCreature(getTargetPlayer(), this); + getTargetPlayer().sacrificeCreature(); grave.remove(card); removed.add(card); @@ -4196,8 +4196,7 @@ public class CardFactory_Sorceries { @Override public void resolve() { - AllZone.GameAction.sacrificeCreature(card.getController().getOpponent(), - this); + card.getController().getOpponent().sacrificeCreature(); } @Override diff --git a/src/forge/GameAction.java b/src/forge/GameAction.java index 9404c48a345..1012ab391d0 100644 --- a/src/forge/GameAction.java +++ b/src/forge/GameAction.java @@ -639,46 +639,6 @@ public class GameAction { if(c[i].getName().equals(name)) a.add(c[i]); } return a; - } - - public void sacrificeCreature(Player player, SpellAbility sa) { - PlayerZone play = AllZone.getZone(Constant.Zone.Play, player); - CardList list = new CardList(play.getCards()); - list = list.getType("Creature"); - - this.sacrificePermanent(player, sa, list); - } - - /* - public void sacrificePermanent(Player player, String prompt, CardList choices) { - if(choices.size() > 0) { - if(player.isHuman()) { - Input in = CardFactoryUtil.input_sacrificePermanent(choices, prompt); - AllZone.InputControl.setInput(in); - } else { - CardListUtil.sortDefense(choices); - choices.reverse(); - CardListUtil.sortAttackLowFirst(choices); - Card c = choices.get(0); - this.sacrificeDestroy(c); - } - } - } - */ - - public void sacrificePermanent(Player player, SpellAbility sa, CardList choices) { - if(choices.size() > 0) { - if(player.equals(AllZone.HumanPlayer)) { - Input in = CardFactoryUtil.input_sacrificePermanent(choices, "Select a creature to sacrifice."); - AllZone.InputControl.setInput(in); - } else { - CardListUtil.sortDefense(choices); - choices.reverse(); - CardListUtil.sortAttackLowFirst(choices); - Card c = choices.get(0); - this.sacrificeDestroy(c); - } - } } public void sacrifice(Card c) { diff --git a/src/forge/GameActionUtil.java b/src/forge/GameActionUtil.java index 354d2f7305a..9bf3fd32ca2 100644 --- a/src/forge/GameActionUtil.java +++ b/src/forge/GameActionUtil.java @@ -7054,14 +7054,12 @@ public class GameActionUtil { }; choices = choices.filter(filter); - if(choices.size() > 0) AllZone.GameAction.sacrificePermanent(AllZone.HumanPlayer, this, - choices); + if(choices.size() > 0) AllZone.HumanPlayer.sacrificeCreature(choices); CardList compCreats = new CardList(cPlay.getCards()); compCreats = compCreats.filter(filter); - if(compCreats.size() > 0) AllZone.GameAction.sacrificePermanent(AllZone.ComputerPlayer, - this, compCreats); + if(compCreats.size() > 0) AllZone.ComputerPlayer.sacrificeCreature(compCreats); } }; ability.setStackDescription("At the beginning of your upkeep, each player sacrifices a non-Vampire creature."); diff --git a/src/forge/Player.java b/src/forge/Player.java index 491b1f519a3..9201668ad63 100644 --- a/src/forge/Player.java +++ b/src/forge/Player.java @@ -501,6 +501,15 @@ public abstract class Player extends MyObservable{ //////////////////////////////// public abstract void sacrificePermanent(String prompt, CardList choices); + public void sacrificeCreature() { + CardList choices = AllZoneUtil.getCreaturesInPlay(this); + sacrificePermanent("Select a creature to sacrifice.", choices); + } + + public void sacrificeCreature(CardList choices) { + sacrificePermanent("Select a creature to sacrifice.", choices); + } + //////////////////////////////// // // generic Object overrides