From 7d2ade4524b2b744d8427d5a68a9a1e4b0312a23 Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 08:22:54 +0000 Subject: [PATCH] - Created a GainLife function instead of needing two lines everywhere life gaining happened. --- src/forge/CardFactory.java | 20 ++-- src/forge/CardFactoryUtil.java | 4 +- src/forge/CardFactory_Auras.java | 4 +- src/forge/CardFactory_Creatures.java | 121 ++++++----------------- src/forge/CardFactory_Equipment.java | 4 +- src/forge/CardFactory_Instants.java | 16 ++- src/forge/CardFactory_Lands.java | 8 +- src/forge/CardFactory_Planeswalkers.java | 13 ++- src/forge/CardFactory_Sorceries.java | 30 +++--- src/forge/CombatUtil.java | 8 +- src/forge/GameAction.java | 24 ++++- src/forge/GameActionUtil.java | 118 ++++++++-------------- src/forge/PlayerLife.java | 15 ++- src/forge/QuestUtil.java | 2 +- 14 files changed, 151 insertions(+), 236 deletions(-) diff --git a/src/forge/CardFactory.java b/src/forge/CardFactory.java index 165139ca316..cc972deb12e 100644 --- a/src/forge/CardFactory.java +++ b/src/forge/CardFactory.java @@ -624,7 +624,7 @@ public class CardFactory implements NewConstants { } else if(ActionID.equals("GainLife")) { - AllZone.GameAction.getPlayerLife(Target).addLife(Integer.parseInt(SplitActionParams[0])); + AllZone.GameAction.gainLife(Target, Integer.parseInt(SplitActionParams[0])); } else { @@ -4470,7 +4470,7 @@ public class CardFactory implements NewConstants { else TgtPlayer = card.getController(); - AllZone.GameAction.getPlayerLife(TgtPlayer).addLife(nlife); + AllZone.GameAction.gainLife(TgtPlayer, nlife); if (!DrawBack[0].equals("none")) CardFactoryUtil.doDrawBack(DrawBack[0], nlife, card.getController(), AllZone.GameAction.getOpponent(card.getController()), TgtPlayer, card, null, this); @@ -4629,7 +4629,7 @@ public class CardFactory implements NewConstants { else TgtPlayer = card.getController(); - AllZone.GameAction.getPlayerLife(TgtPlayer).addLife(nlife); + AllZone.GameAction.gainLife(TgtPlayer, nlife); if (!DrawBack[0].equals("none")) CardFactoryUtil.doDrawBack(DrawBack[0], nlife, card.getController(), AllZone.GameAction.getOpponent(card.getController()), TgtPlayer, card, null, this); }//resolve() @@ -4687,7 +4687,7 @@ public class CardFactory implements NewConstants { else TgtPlayer = card.getController(); - AllZone.GameAction.getPlayerLife(TgtPlayer).addLife(nlife); + AllZone.GameAction.gainLife(TgtPlayer, nlife); if (!DrawBack[0].equals("none")) CardFactoryUtil.doDrawBack(DrawBack[0], nlife, card.getController(), AllZone.GameAction.getOpponent(card.getController()), TgtPlayer, card, null, this); @@ -7415,7 +7415,7 @@ public class CardFactory implements NewConstants { @Override public void resolve() { - AllZone.GameAction.getPlayerLife(card.getController()).addLife(5); + AllZone.GameAction.gainLife(card.getController(), 5); AllZone.GameAction.sacrifice(getSourceCard()); }//resolve() };//SpellAbility @@ -8885,7 +8885,7 @@ public class CardFactory implements NewConstants { @Override public void resolve() { - AllZone.GameAction.getPlayerLife(card.getController()).addLife(1); + AllZone.GameAction.gainLife(card.getController(), 1); } };//SpellAbility @@ -9083,8 +9083,7 @@ public class CardFactory implements NewConstants { if(AllZone.GameAction.isCardInPlay(c)) { AllZone.GameAction.sacrifice(c); makeToken(); - PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController()); - life.addLife(1); + AllZone.GameAction.gainLife(card.getController(), 1); } }//resolve @@ -9199,8 +9198,7 @@ public class CardFactory implements NewConstants { @Override public void resolve() { Card c = card; - PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController()); - life.addLife(20); + AllZone.GameAction.gainLife(c.getController(), 20); } }; @@ -9555,7 +9553,7 @@ public class CardFactory implements NewConstants { setTargetCard(target); }//chooseTargetAI() public void resolve() { - AllZone.GameAction.getPlayerLife(card.getController()).addLife(2); + AllZone.GameAction.gainLife(card.getController(), 2); AllZone.GameAction.sacrifice(getTargetCard()); } };//SpellAbility diff --git a/src/forge/CardFactoryUtil.java b/src/forge/CardFactoryUtil.java index ebca7f6e6b5..f1983a6d545 100644 --- a/src/forge/CardFactoryUtil.java +++ b/src/forge/CardFactoryUtil.java @@ -3862,8 +3862,8 @@ public class CardFactoryUtil { AllZone.GameAction.addDamage(dbPlayer, Src, X); - if(d[0].contains("GainLife")) - AllZone.GameAction.getPlayerLife(dbPlayer).addLife(X); + if(d[0].contains("GainLife")) + AllZone.GameAction.gainLife(dbPlayer, X); if(d[0].contains("LoseLife")) AllZone.GameAction.getPlayerLife(dbPlayer).subtractLife(X,Src); diff --git a/src/forge/CardFactory_Auras.java b/src/forge/CardFactory_Auras.java index 304ed0b3ddb..459ba8e0634 100644 --- a/src/forge/CardFactory_Auras.java +++ b/src/forge/CardFactory_Auras.java @@ -215,9 +215,7 @@ class CardFactory_Auras { if(AllZone.GameAction.isCardInPlay(c)) { //AllZone.getZone(c).remove(c); AllZone.GameAction.sacrifice(c); - - PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController()); - life.addLife(1); + AllZone.GameAction.gainLife(c.getController(), 1); } }//resolve diff --git a/src/forge/CardFactory_Creatures.java b/src/forge/CardFactory_Creatures.java index a888500ae90..8ed70f47904 100644 --- a/src/forge/CardFactory_Creatures.java +++ b/src/forge/CardFactory_Creatures.java @@ -1313,9 +1313,7 @@ public class CardFactory_Creatures { public void resolve() { int n = countArtifacts(); - PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController()); - life.addLife(3 * n); - + AllZone.GameAction.gainLife(card.getController(), 3 * n); } int countArtifacts() { @@ -1346,8 +1344,8 @@ public class CardFactory_Creatures { @Override public void resolve() { Card c = card; - PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController()); - life.addLife(2); + + AllZone.GameAction.gainLife(c.getController(), 2); } }; Command intoPlay = new Command() { @@ -1367,9 +1365,8 @@ public class CardFactory_Creatures { final SpellAbility ability = new Ability(card, "0") { @Override public void resolve() { - Card c = card; - PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController()); - life.addLife(5); + Card c = card; + AllZone.GameAction.gainLife(c.getController(), 5); } }; Command intoPlay = new Command() { @@ -1393,8 +1390,7 @@ public class CardFactory_Creatures { @Override public void resolve() { Card c = card; - PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController()); - life.addLife(4); + AllZone.GameAction.gainLife(c.getController(), 4); } }; Command intoPlay = new Command() { @@ -1684,8 +1680,7 @@ public class CardFactory_Creatures { //AllZone.getZone(c).remove(c); AllZone.GameAction.sacrifice(c); - PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController()); - life.addLife(1); + AllZone.GameAction.gainLife(c.getController(), 1); } }//resolve @@ -1931,8 +1926,7 @@ public class CardFactory_Creatures { @Override public void resolve() { Card c = card; - PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController()); - life.addLife(3); + AllZone.GameAction.gainLife(c.getController(), 3); } }; Command intoPlay = new Command() { @@ -2299,10 +2293,9 @@ public class CardFactory_Creatures { String opponent = AllZone.GameAction.getOpponent(card.getController()); PlayerLife opp = AllZone.GameAction.getPlayerLife(opponent); - PlayerLife my = AllZone.GameAction.getPlayerLife(card.getController()); opp.subtractLife(5,card); - my.addLife(5); + AllZone.GameAction.gainLife(card.getController(), 5); } }; Command destroy = new Command() { @@ -2462,7 +2455,7 @@ public class CardFactory_Creatures { String opponent = AllZone.GameAction.getOpponent(card.getController()); AllZone.GameAction.getPlayerLife(opponent).subtractLife(2,card); - AllZone.GameAction.getPlayerLife(card.getController()).addLife(2); + AllZone.GameAction.gainLife(card.getController(), 2); } }; Command intoPlay = new Command() { @@ -4030,7 +4023,7 @@ public class CardFactory_Creatures { };//Command card.addComesIntoPlayCommand(intoPlay); }//*************** END ************ END ************************** - + //*************** START *********** START ************************** else if(cardName.equals("Penumbra Kavu")) { @@ -5239,8 +5232,7 @@ public class CardFactory_Creatures { public void resolve() { int number = ((Integer) countZubera.execute()).intValue(); - PlayerLife life = AllZone.GameAction.getPlayerLife(getTargetPlayer()); - life.addLife(number * 2); + AllZone.GameAction.gainLife(getTargetPlayer(), number*2); }//resolve() };//SpellAbility @@ -8160,9 +8152,8 @@ public class CardFactory_Creatures { @Override public void resolve() { - PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController()); - life.addLife(3); - + AllZone.GameAction.gainLife(card.getController(), 3); + AllZone.GameAction.sacrifice(card); }//resolve() };//SpellAbility @@ -8833,8 +8824,7 @@ public class CardFactory_Creatures { public void resolve() { String opponent = AllZone.GameAction.getOpponent(card.getController()); AllZone.GameAction.getPlayerLife(opponent).subtractLife(2,card); - - AllZone.GameAction.getPlayerLife(card.getController()).addLife(2); + AllZone.GameAction.gainLife(card.getController(), 2); //computer discards here, todo: should discard when ability put on stack if(card.getController().equals(Constant.Player.Computer)) AllZone.GameAction.discardRandom(Constant.Player.Computer, this); @@ -9603,43 +9593,11 @@ public class CardFactory_Creatures { destroy.setBeforePayMana(target); destroy.setBeforePayMana(CardFactoryUtil.input_targetCreature(destroy)); }//*************** END ************ END ************************** - + //*************** START *********** START ************************** else if(cardName.equals("Ghost-Lit Redeemer")) { - final SpellAbility ability = new Ability_Tap(card, "W") { - private static final long serialVersionUID = -7119153679100849498L; - - @Override - public boolean canPlayAI() { - return AllZone.Phase.getPhase().equals(Constant.Phase.Main2); - } - - @Override - public void resolve() { - Card c = card; - PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController()); - life.addLife(2); - } - };//SpellAbility - card.addSpellAbility(ability); - ability.setDescription("W, tap: You gain 2 life"); - ability.setStackDescription("Computer gains 2 life"); - - final Command paid = new Command() { - private static final long serialVersionUID = 3649597692883194760L; - - public void execute() { - Card c = card; - c.tap(); - AllZone.Human_Play.updateObservers();//so the card will tap at the correct time - - ability.setStackDescription(c.getController() + " gains 2 life"); - AllZone.Stack.add(ability); - AllZone.InputControl.resetInput(); - } - }; - ability.setBeforePayMana(new Input_PayManaCost_Ability(ability.getManaCost(), paid, Command.Blank)); + // Does not have Channel Ability }//*************** END ************ END ************************** @@ -11313,11 +11271,8 @@ public class CardFactory_Creatures { if(!AllZone.GameAction.isCardInPlay(c)) return; if(AllZone.GameAction.isCardInPlay(c)) { - //AllZone.getZone(c).remove(c); AllZone.GameAction.sacrifice(c); - - PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController()); - life.addLife(2); + AllZone.GameAction.gainLife(c.getController(), 2); } }//resolve @@ -11670,8 +11625,7 @@ public class CardFactory_Creatures { lifeGain = CardFactoryUtil.getNumberOfPermanentsByColor(color); } - PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController()); - life.addLife(lifeGain); + AllZone.GameAction.gainLife(card.getController(), lifeGain); } @Override @@ -11766,8 +11720,7 @@ public class CardFactory_Creatures { final Ability ability = new Ability(card, "0") { @Override public void resolve() { - PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController()); - life.addLife(3); + AllZone.GameAction.gainLife(card.getController(), 3); } }; @@ -11790,8 +11743,7 @@ public class CardFactory_Creatures { final Ability ability = new Ability(card, "0") { @Override public void resolve() { - PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController()); - life.addLife(1); + AllZone.GameAction.gainLife(card.getController(), 1); } }; @@ -11814,8 +11766,7 @@ public class CardFactory_Creatures { final Ability ability = new Ability(card, "0") { @Override public void resolve() { - PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController()); - life.addLife(2); + AllZone.GameAction.gainLife(card.getController(), 2); } }; @@ -13725,8 +13676,7 @@ public class CardFactory_Creatures { private static final long serialVersionUID = 5588978023269625349L; public void execute() { - PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController()); - life.addLife(2); + AllZone.GameAction.gainLife(card.getController(), 2); } }; @@ -16300,8 +16250,7 @@ public class CardFactory_Creatures { SpellAbility ability = new Ability(card, "0") { @Override public void resolve() { - String player = abilityComes.getTargetPlayer(); - AllZone.GameAction.getPlayerLife(player).addLife(6); + AllZone.GameAction.gainLife(abilityComes.getTargetPlayer(), 6); }//resolve() };//SpellAbility @@ -16332,8 +16281,7 @@ public class CardFactory_Creatures { int drain = list.size(); AllZone.GameAction.getPlayerLife(AllZone.GameAction.getOpponent(card.getController())).subtractLife( drain,card); - AllZone.GameAction.getPlayerLife(card.getController()).addLife(drain); - + AllZone.GameAction.gainLife(card.getController(), drain); }//resolve() }; abilityComes.setStackDescription(card @@ -16955,8 +16903,7 @@ public class CardFactory_Creatures { final Ability ability = new Ability(card, "0") { @Override public void resolve() { - String player = card.getController(); - AllZone.GameAction.getPlayerLife(player).addLife(1); + AllZone.GameAction.gainLife(card.getController(), 1); } }; ability.setStackDescription(card.getName() + " - " + card.getController() + " gains 1 life."); @@ -17304,7 +17251,7 @@ public class CardFactory_Creatures { @Override public void resolve() { int lifeGain = card.getCounters(Counters.AGE) * 2; - AllZone.GameAction.getPlayerLife(card.getController()).addLife(lifeGain); + AllZone.GameAction.gainLife(card.getController(), lifeGain); } }; @@ -17612,7 +17559,7 @@ public class CardFactory_Creatures { final Ability ability = new Ability(card, "0") { @Override public void resolve() { - AllZone.GameAction.getPlayerLife(card.getController()).addLife(card.getMultiKickerMagnitude() * 2); + AllZone.GameAction.gainLife(card.getController(), card.getMultiKickerMagnitude() * 2); card.setMultiKickerMagnitude(0); } }; @@ -18167,19 +18114,16 @@ public class CardFactory_Creatures { @Override public void resolve() { - //AllZone.GameAction.drawCard(sourceCard.getController()); final String target = getTargetPlayer(); PlayerLife targetLife = AllZone.GameAction.getPlayerLife(target); - final String player = card.getController(); - PlayerLife playerLife = AllZone.GameAction.getPlayerLife(player); AllZone.GameAction.sacrifice(card); targetLife.subtractLife(1,card); - playerLife.addLife(1); + AllZone.GameAction.gainLife(card.getController(), 1); } }; - //ability.setDescription("1, Sacrifice " + cardName + ": Draw a card."); + //ability.setStackDescription(cardName + " - Target player loses 1 life and controller gains 1 life."); card.addSpellAbility(ability); ability.setBeforePayMana(CardFactoryUtil.input_targetPlayer(ability)); @@ -19341,8 +19285,7 @@ public class CardFactory_Creatures { public void resolve() { if (card.getCounters(Counters.P1P1) > 0){ card.subtractCounter(Counters.P1P1, 1); - PlayerLife life = AllZone.GameAction.getPlayerLife(getActivatingPlayer()); - life.addLife(2); + AllZone.GameAction.gainLife(getActivatingPlayer(), 2); } }//resolve @@ -19703,7 +19646,7 @@ public class CardFactory_Creatures { } public void resolve() { - AllZone.GameAction.getPlayerLife(card.getController()).addLife(4); + AllZone.GameAction.gainLife(card.getController(), 4); AllZone.GameAction.sacrifice(getTargetCard()); } };//SpellAbility diff --git a/src/forge/CardFactory_Equipment.java b/src/forge/CardFactory_Equipment.java index 6bb2930a910..18e4f117d20 100644 --- a/src/forge/CardFactory_Equipment.java +++ b/src/forge/CardFactory_Equipment.java @@ -283,9 +283,7 @@ class CardFactory_Equipment { @Override public void resolve() { card.subtractCounter(Counters.CHARGE, 1); - String player = card.getController(); - PlayerLife life = AllZone.GameAction.getPlayerLife(player); - life.addLife(2); + AllZone.GameAction.gainLife(card.getController(), 2); } @Override diff --git a/src/forge/CardFactory_Instants.java b/src/forge/CardFactory_Instants.java index 256e6f8b608..3ecf6791898 100644 --- a/src/forge/CardFactory_Instants.java +++ b/src/forge/CardFactory_Instants.java @@ -1483,8 +1483,7 @@ public class CardFactory_Instants { private static final long serialVersionUID = 7699412574052780825L; public void execute() { - PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController()); - life.addLife(2); + AllZone.GameAction.gainLife(card.getController(), 2); } }); }//*************** END ************ END ************************** @@ -1506,8 +1505,7 @@ public class CardFactory_Instants { } }); - PlayerLife life = AllZone.GameAction.getPlayerLife(getTargetPlayer()); - life.addLife(4 + (4 * count.size())); + AllZone.GameAction.gainLife(getTargetPlayer(), 4 + (4 * count.size())); } }; spell.setChooseTargetAI(CardFactoryUtil.AI_targetComputer()); @@ -2676,8 +2674,8 @@ public class CardFactory_Instants { for(int i = 0; i < Sacrificed.getNetAttack(); i++) { AllZone.GameAction.drawCard(card.getController()); } - PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController()); - life.addLife(Sacrificed.getNetDefense()); + AllZone.GameAction.gainLife(card.getController(), Sacrificed.getNetDefense()); + } } @@ -4122,7 +4120,7 @@ public class CardFactory_Instants { CardList attackers = new CardList(); attackers.addAll(AllZone.Combat.getAttackers()); attackers.addAll(AllZone.pwCombat.getAttackers()); - AllZone.GameAction.getPlayerLife(card.getController()).addLife(attackers.size()); + AllZone.GameAction.gainLife(card.getController(), attackers.size()); } } public boolean canPlayAI() @@ -4207,7 +4205,7 @@ public class CardFactory_Instants { public void resolve() { - AllZone.GameAction.getPlayerLife(card.getController()).addLife(card.getXManaCostPaid() + 3); + AllZone.GameAction.gainLife(card.getController(), card.getXManaCostPaid() + 3); card.setXManaCostPaid(0); } @@ -4741,7 +4739,7 @@ public class CardFactory_Instants { } AllZone.GameAction.getPlayerLife(tPlayer).subtractLife(X,card); - AllZone.GameAction.getPlayerLife(player).addLife(X); + AllZone.GameAction.gainLife(player, X); card.setXManaCostPaid(0); } diff --git a/src/forge/CardFactory_Lands.java b/src/forge/CardFactory_Lands.java index bf136edd4a5..ab2266fc33e 100644 --- a/src/forge/CardFactory_Lands.java +++ b/src/forge/CardFactory_Lands.java @@ -118,8 +118,7 @@ class CardFactory_Lands { @Override public void resolve() { Card c = card; - PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController()); - life.addLife(2); + AllZone.GameAction.gainLife(c.getController(), 2); } }; Command intoPlay = new Command() { @@ -486,8 +485,7 @@ class CardFactory_Lands { public void resolve() { Card c = card; //c.tap(); - PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController()); - life.addLife(1); + AllZone.GameAction.gainLife(c.getController(), 1); } }; Command intoPlay = new Command() { @@ -3436,7 +3434,7 @@ class CardFactory_Lands { if(c != null) { if(CardFactoryUtil.canTarget(card, c) && c.isCreature() ) { - AllZone.GameAction.getPlayerLife(c.getController()).addLife(c.getNetDefense()); + AllZone.GameAction.gainLife(c.getController(), c.getNetDefense()); AllZone.GameAction.sacrifice(c); } } diff --git a/src/forge/CardFactory_Planeswalkers.java b/src/forge/CardFactory_Planeswalkers.java index 91e9d9fb7ea..13bca2ccb85 100644 --- a/src/forge/CardFactory_Planeswalkers.java +++ b/src/forge/CardFactory_Planeswalkers.java @@ -299,7 +299,7 @@ class CardFactory_Planeswalkers { CardList elves = new CardList(play.getCards()); elves = elves.getType("Elf"); - AllZone.GameAction.getPlayerLife(card.getController()).addLife(2 * elves.size()); + AllZone.GameAction.gainLife(card.getController(), 2 * elves.size()); }//resolve() @@ -1006,7 +1006,7 @@ class CardFactory_Planeswalkers { turn[0] = AllZone.Phase.getTurn(); - AllZone.GameAction.getPlayerLife(card2.getController()).addLife(2); + AllZone.GameAction.gainLife(card2.getController(), 2); Log.debug("Ajani Goldmane", "current phase: " + AllZone.Phase.getPhase()); } @@ -2094,8 +2094,11 @@ class CardFactory_Planeswalkers { Card c = getTargetCard(); c.addDamage(damage, card2); } - } else AllZone.GameAction.getPlayerLife(getTargetPlayer()).subtractLife(damage,card2); - AllZone.GameAction.getPlayerLife(card2.getController()).addLife(3); + } + else + AllZone.GameAction.getPlayerLife(getTargetPlayer()).subtractLife(damage,card2); + + AllZone.GameAction.gainLife(card2.getController(), 3); } @Override @@ -3252,7 +3255,7 @@ class CardFactory_Planeswalkers { turn[0] = AllZone.Phase.getTurn(); int life = AllZoneUtil.getCreaturesInPlay(card2.getController()).size(); - AllZone.GameAction.getPlayerLife(card2.getController()).addLife(life); + AllZone.GameAction.gainLife(card2.getController(), life); Log.debug("Elspeth Tirel", "current phase: " + AllZone.Phase.getPhase()); } diff --git a/src/forge/CardFactory_Sorceries.java b/src/forge/CardFactory_Sorceries.java index 7f73b969b05..e542fc04bdc 100644 --- a/src/forge/CardFactory_Sorceries.java +++ b/src/forge/CardFactory_Sorceries.java @@ -1207,8 +1207,7 @@ public class CardFactory_Sorceries { AllZone.GameAction.drawCard(card.getController()); } // Player Gains 5 Life - PlayerLife playerlife = AllZone.GameAction.getPlayerLife(card.getController()); - playerlife.addLife(5); + AllZone.GameAction.gainLife(card.getController(), 5); } // Resolve @@ -1242,11 +1241,10 @@ public class CardFactory_Sorceries { @Override public void resolve() { - PlayerLife player = AllZone.GameAction.getPlayerLife(card.getController()); String opponent = AllZone.GameAction.getOpponent(card.getController()); PlayerLife target = AllZone.GameAction.getPlayerLife(opponent); target.subtractLife(2,card); - player.addLife(2); + AllZone.GameAction.gainLife(card.getController(), 2); } public boolean canPlayAI() { @@ -1842,7 +1840,7 @@ public class CardFactory_Sorceries { @Override public void resolve() { PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController()); - life.addLife(10); + AllZone.GameAction.gainLife(card.getController(), 10); String opponent = AllZone.GameAction.getOpponent(card.getController()); PlayerLife oppLife = AllZone.GameAction.getPlayerLife(opponent); @@ -3859,13 +3857,11 @@ public class CardFactory_Sorceries { AllZone.GameAction.discard(c2, null); if(c1.getType().contains("Land")) { - PlayerLife life = AllZone.GameAction.getPlayerLife(Constant.Player.Human); - life.addLife(3); + AllZone.GameAction.gainLife(Constant.Player.Human, 3); } if(c2.getType().contains("Land")) { - PlayerLife life = AllZone.GameAction.getPlayerLife(Constant.Player.Human); - life.addLife(3); + AllZone.GameAction.gainLife(Constant.Player.Human, 3); } @@ -3889,8 +3885,7 @@ public class CardFactory_Sorceries { AllZone.GameAction.discard(c, null); if(c.getType().contains("Land")) { - PlayerLife life = AllZone.GameAction.getPlayerLife(Constant.Player.Computer); - life.addLife(3); + AllZone.GameAction.gainLife(Constant.Player.Computer, 3); } if(list.size() > 0) { @@ -3906,8 +3901,7 @@ public class CardFactory_Sorceries { AllZone.GameAction.discard(c2, null); if(c2.getType().contains("Land")) { - PlayerLife life = AllZone.GameAction.getPlayerLife(Constant.Player.Computer); - life.addLife(3); + AllZone.GameAction.gainLife(Constant.Player.Computer, 3); } } } @@ -5854,9 +5848,7 @@ public class CardFactory_Sorceries { public void resolve() { - String player = getTargetPlayer(); - - AllZone.GameAction.getPlayerLife(player).addLife(card.getXManaCostPaid()); + AllZone.GameAction.gainLife(getTargetPlayer(), card.getXManaCostPaid()); card.setXManaCostPaid(0); } @@ -5985,7 +5977,8 @@ public class CardFactory_Sorceries { { AllZone.GameAction.mill(getTargetPlayer(),card.getXManaCostPaid()); - AllZone.GameAction.getPlayerLife(card.getController()).addLife(card.getXManaCostPaid()); + AllZone.GameAction.gainLife(card.getController(), card.getXManaCostPaid()); + card.setXManaCostPaid(0); } @@ -6983,8 +6976,7 @@ public class CardFactory_Sorceries { lib.add(tgt); //add to top if lib is empty } }//else - PlayerLife life = AllZone.GameAction.getPlayerLife(tgt.getController()); - life.addLife(3); + AllZone.GameAction.gainLife(tgt.getController(), 3); } }//if isCardInPlay() && canTarget() }//resolve() diff --git a/src/forge/CombatUtil.java b/src/forge/CombatUtil.java index 2faf87e34ff..d1cb3a7704c 100644 --- a/src/forge/CombatUtil.java +++ b/src/forge/CombatUtil.java @@ -1975,7 +1975,7 @@ public class CombatUtil { }; Card top = lib.get(0); if(top.getType().contains("Creature")) { - AllZone.GameAction.getPlayerLife(player).addLife(top.getBaseDefense()); + AllZone.GameAction.gainLife(player, top.getBaseDefense()); AllZone.GameAction.getPlayerLife(player).subtractLife(top.getBaseAttack(),c); hand.add(top); lib.remove(top); @@ -2123,7 +2123,7 @@ public class CombatUtil { { public void resolve() { - AllZone.GameAction.getPlayerLife(crd.getController()).addLife(2); + AllZone.GameAction.gainLife(crd.getController(), 2); } }; ability.setStackDescription(pcs.get(i) + " - " + c.getController() + " gains 2 life."); @@ -2367,9 +2367,9 @@ public class CombatUtil { && !a.getCreatureBlockedThisCombat()) { a.untap(); } else if (a.getName().equals("Deepwood Tantiv") && !a.getCreatureBlockedThisCombat()) { - AllZone.GameAction.getPlayerLife(a.getController()).addLife(2); + AllZone.GameAction.gainLife(a.getController(), 2); } else if (a.getName().equals("Sacred Prey") && !a.getCreatureBlockedThisCombat()) { - AllZone.GameAction.getPlayerLife(a.getController()).addLife(1); + AllZone.GameAction.gainLife(a.getController(), 1); } else if (a.getName().equals("Vedalken Ghoul") && !a.getCreatureBlockedThisCombat()) { AllZone.GameAction.getPlayerLife(b.getController()).subtractLife(4,a); } diff --git a/src/forge/GameAction.java b/src/forge/GameAction.java index c780053e422..ae1d357bd2e 100644 --- a/src/forge/GameAction.java +++ b/src/forge/GameAction.java @@ -1591,8 +1591,10 @@ public class GameAction { if(Whenever_Go(F_card,F_k) == true) if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { PlayerLife life = AllZone.GameAction.getPlayerLife(F_TargetPlayer[F_Target]); - if(F_Amount[0] > -1) life.addLife(F_Amount[0]); - else life.subtractLife(F_Amount[0] * -1,F_card); + if(F_Amount[0] > -1) + AllZone.GameAction.gainLife(F_TargetPlayer[F_Target], F_Amount[0]); + else + life.subtractLife(F_Amount[0] * -1,F_card); } } @@ -3903,6 +3905,24 @@ public class GameAction { return AllZone.Computer_PoisonCounter.getPoisonCounters(); } + public void gainLife(String player, int lifeGained){ + PlayerLife p = getPlayerLife(player); + p.addLife(lifeGained); + + Object[] Life_Whenever_Parameters = new Object[1]; + Life_Whenever_Parameters[0] = lifeGained; + AllZone.GameAction.CheckWheneverKeyword(p.getPlayerCard(), "GainLife", Life_Whenever_Parameters); + } + + public void loseLife(String player, int lifeLost){ + PlayerLife p = getPlayerLife(player); + p.payLife(lifeLost); + + Object[] Life_Whenever_Parameters = new Object[1]; + Life_Whenever_Parameters[0] = lifeLost; + AllZone.GameAction.CheckWheneverKeyword(p.getPlayerCard(), "LoseLife", Life_Whenever_Parameters); + } + public void searchLibraryLand(String type, String player, String Zone1, boolean tapLand) { searchLibraryTwoLand(type, player, Zone1, tapLand, "", false); } diff --git a/src/forge/GameActionUtil.java b/src/forge/GameActionUtil.java index 06dc30e4ef0..d512e4e915d 100644 --- a/src/forge/GameActionUtil.java +++ b/src/forge/GameActionUtil.java @@ -173,7 +173,7 @@ public class GameActionUtil { @Override public void resolve() { //Lifeblood controller (opponent in this case) gains 1 life - AllZone.GameAction.getPlayerLife(opponent).addLife(1); + AllZone.GameAction.gainLife(opponent, 1); } };//Ability ability.setStackDescription(lifeblood.getName()+" - Mountain was tapped, "+opponent+" gains 1 life."); @@ -189,7 +189,7 @@ public class GameActionUtil { @Override public void resolve() { //Lifetap controller (opponent in this case) gains 1 life - AllZone.GameAction.getPlayerLife(opponent).addLife(1); + AllZone.GameAction.gainLife(opponent, 1); } };//Ability ability.setStackDescription(lifetap.getName()+" - Forest was tapped, "+opponent+" gains 1 life."); @@ -1740,8 +1740,7 @@ public class GameActionUtil { else target = "Human"; // check for target of spell/abilities should be here } else target = "Human"; // check for target of spell/abilities should be here AllZone.GameAction.getPlayerLife(target).subtractLife(1,card); - PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController()); - life.addLife(1); + AllZone.GameAction.gainLife(card.getController(), 1); } //resolve }; //ability @@ -1903,7 +1902,8 @@ public class GameActionUtil { else if(!choice.equals("None")) target = "Human"; // check for target of spell/abilities should be here else target = "none"; } else target = "Computer"; // check for target of spell/abilities should be here - if(!target.equals("none")) AllZone.GameAction.getPlayerLife(target).addLife(converted); + if(!target.equals("none")) + AllZone.GameAction.gainLife(target, converted); } //resolve }; //ability ability2.setChooseTargetAI(CardFactoryUtil.AI_targetHuman()); @@ -2682,8 +2682,7 @@ public class GameActionUtil { Ability ability2 = new Ability(card, "0") { @Override public void resolve() { - PlayerLife life = AllZone.GameAction.getPlayerLife(controller); - life.addLife(1); + AllZone.GameAction.gainLife(controller, 1); } }; // ability2 @@ -3055,6 +3054,7 @@ public class GameActionUtil { Ability ability2 = new Ability(card, "0") { public void resolve() { + boolean bAccept = false; if (card.getController().equals("Human")) { StringBuilder title = new StringBuilder(); title.append("Kor Firewalker Ability"); @@ -3062,14 +3062,14 @@ public class GameActionUtil { message.append("Will you gain 1 life?"); int choice = JOptionPane.showConfirmDialog(null, message.toString(), title.toString(), JOptionPane.YES_NO_OPTION); - if (choice == JOptionPane.YES_OPTION) { - AllZone.GameAction.getPlayerLife(card.getController()).addLife(1); - } + bAccept = (choice == JOptionPane.YES_OPTION); }// Human - - if (card.getController().equals("Computer")) { - AllZone.GameAction.getPlayerLife(card.getController()).addLife(1); - }// Computer + else // computer always wants life + bAccept = true; + + if (bAccept) + AllZone.GameAction.gainLife(card.getController(), 1); + }// resolve() };//ability2 @@ -3874,8 +3874,7 @@ public class GameActionUtil { if (o != null) { Card c = (Card) o; int power=c.getNetAttack(); - PlayerLife life = AllZone.GameAction.getPlayerLife(player); - life.addLife(power); + AllZone.GameAction.gainLife(player, power); } } else//computer @@ -3885,8 +3884,7 @@ public class GameActionUtil { // Card c = creats.get(0); if (c != null) { int power = c.getNetAttack(); - PlayerLife life = AllZone.GameAction.getPlayerLife(player); - life.addLife(power); + AllZone.GameAction.gainLife(player, power); } } } // resolve @@ -4362,9 +4360,7 @@ public class GameActionUtil { PlayerZone play = AllZone.getZone(Constant.Zone.Play, crd.getController()); CardList allies = new CardList(play.getCards()); allies = allies.getType("Ally"); - PlayerLife life = AllZone.GameAction.getPlayerLife(crd.getController()); - life.addLife(allies.size()); - + AllZone.GameAction.gainLife(crd.getController(), allies.size()); } }; @@ -4520,9 +4516,7 @@ public class GameActionUtil { Ability ability = new Ability(c, "0") { @Override public void resolve() { - String player = crd.getController(); - PlayerLife life = AllZone.GameAction.getPlayerLife(player); - life.addLife(1); + AllZone.GameAction.gainLife(crd.getController(), 1); } }; ability.setStackDescription("Moonlit Wake - " + c.getController() + " gains 1 life."); @@ -4535,9 +4529,7 @@ public class GameActionUtil { Ability ability = new Ability(c, "0") { @Override public void resolve() { - String player = crd.getController(); - PlayerLife life = AllZone.GameAction.getPlayerLife(player); - life.addLife(crd2.getNetDefense()); + AllZone.GameAction.gainLife(crd.getController(), crd2.getNetDefense()); } }; ability.setStackDescription("Proper Burial - " + c.getController() + " gains " + destroyed.getNetDefense() @@ -5059,22 +5051,10 @@ public class GameActionUtil { }//landfall_Eternity_Vessel public static void executeLifeLinkEffects(Card c) { - final String player = c.getController(); int pwr = c.getNetAttack(); if(CombatUtil.isDoranInPlay()) pwr = c.getNetDefense(); - final int power = pwr; - - Ability ability2 = new Ability(c, "0") { - @Override - public void resolve() { - PlayerLife life = AllZone.GameAction.getPlayerLife(player); - life.addLife(power); - } - }; // ability2 - - ability2.setStackDescription(c.getName() + " (Lifelink) - " + player + " gains " + power + " life."); - AllZone.Stack.add(ability2); + executeLifeLinkEffects(c, pwr); } public static void executeLifeLinkEffects(Card c, int n) { @@ -5085,8 +5065,7 @@ public class GameActionUtil { Ability ability2 = new Ability(c, "0") { @Override public void resolve() { - PlayerLife life = AllZone.GameAction.getPlayerLife(player); - life.addLife(power); + AllZone.GameAction.gainLife(player, power); } }; // ability2 @@ -5167,7 +5146,7 @@ public class GameActionUtil { } } - AllZone.GameAction.getPlayerLife(src.getController()).addLife(3); + AllZone.GameAction.gainLife(src.getController(), 3); } }; // ability @@ -6070,8 +6049,7 @@ public class GameActionUtil { AllZone.Display.getChoiceOptional("Top card", cl.toArray()); }; Card top = lib.get(0); - AllZone.GameAction.getPlayerLife(player[0]).addLife( - CardUtil.getConvertedManaCost(top.getManaCost())); + AllZone.GameAction.gainLife(player[0], CardUtil.getConvertedManaCost(top.getManaCost())); hand.add(top); lib.remove(top); @@ -7098,7 +7076,7 @@ public class GameActionUtil { if(creatureType.contains("Giant") || creatureType.contains("Wizard") || library.get(0).getKeyword().contains("Changeling")) { - AllZone.GameAction.getPlayerLife(player).addLife(4); + AllZone.GameAction.gainLife(player, 4); } }// resolve() @@ -7942,12 +7920,13 @@ public class GameActionUtil { @Override public void resolve() { - pLife.addLife(1); + if (pLife.getLife() <= 10) + AllZone.GameAction.gainLife(player, 1); } };// Ability ability.setStackDescription("Convalescence - " + player + " gain 1 life"); - if((pLife.getLife() + i) <= 10) { + if(pLife.getLife() <= 10) { AllZone.Stack.add(ability); } }// for @@ -7956,35 +7935,29 @@ public class GameActionUtil { private static void upkeep_Convalescent_Care() { final String player = AllZone.Phase.getActivePlayer(); PlayerZone playZone = AllZone.getZone(Constant.Zone.Play, player); - PlayerLife pLife = AllZone.GameAction.getPlayerLife(player); + final PlayerLife pLife = AllZone.GameAction.getPlayerLife(player); CardList list = new CardList(playZone.getCards()); list = list.getName("Convalescent Care"); for(int i = 0; i < list.size(); i++) { - /* Ability ability = new Ability(list.get(i), "0") { public void resolve() { - - pLife.addLife(3); - AllZone.GameAction.drawCard(player); + if (pLife.getLife() <= 5){ + AllZone.GameAction.gainLife(player, 3); + AllZone.GameAction.drawCard(player); + } } };// Ability ability.setStackDescription("Convalescent Care - " + player + " gains 3 life and draws a card"); - if ((pLife.getLife() + i) <= 5) - { + if (pLife.getLife() <= 5){ AllZone.Stack.add(ability); } - */ - if((pLife.getLife()) <= 5) { - pLife.addLife(3); - AllZone.GameAction.drawCard(player); - } }// for }// upkeep_Convalescence() @@ -8008,7 +7981,7 @@ public class GameActionUtil { PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, player); int numCards = hand.getCards().length; if( numCards > 4 ) { - AllZone.GameAction.getPlayerLife(player).addLife(numCards-4); + AllZone.GameAction.gainLife(player, numCards - 4); } } };//Ability @@ -9304,9 +9277,7 @@ public class GameActionUtil { CardList hondlist = new CardList(); hondlist.addAll(Play.getCards()); hondlist = hondlist.getType("Shrine"); - for(int j = 0; j < hondlist.size(); j++) { - AllZone.GameAction.getPlayerLife(player).addLife(2); - } + AllZone.GameAction.gainLife(player, 2*hondlist.size()); } }; ability.setStackDescription(list.get(i) + " - " + list.get(i).getController() @@ -13363,13 +13334,12 @@ public class GameActionUtil { // Gain life for new Essence Wardens n[0] += newWarden.size(); - final PlayerLife life = AllZone.GameAction.getPlayerLife(wardenList.get( - outer).getController()); + final String player = wardenList.get(outer).getController(); SpellAbility ability = new Ability(new Card(), "0") { @Override public void resolve() { - life.addLife(n[0]); + AllZone.GameAction.gainLife(player, n[0]); } }; ability.setStackDescription(wardenList.get(outer).getName() @@ -13443,14 +13413,14 @@ public class GameActionUtil { // Gain life for new Soul Wardens n[0] += newWarden.size(); - final PlayerLife life = AllZone.GameAction.getPlayerLife(wardenList.get( - outer).getController()); + final String player = wardenList.get(outer).getController(); + SpellAbility ability = new Ability(new Card(), "0") { @Override public void resolve() { - life.addLife(n[0]); + AllZone.GameAction.gainLife(player, n[0]); } }; ability.setStackDescription(wardenList.get(outer).getName() @@ -13524,14 +13494,13 @@ public class GameActionUtil { // Gain life for new Soul's Attendants n[0] += newWarden.size(); - final PlayerLife life = AllZone.GameAction.getPlayerLife(wardenList.get( - outer).getController()); + final String player = wardenList.get(outer).getController(); SpellAbility ability = new Ability(new Card(), "0") { @Override public void resolve() { - life.addLife(n[0]); + AllZone.GameAction.gainLife(player, n[0]); } }; ability.setStackDescription(wardenList.get(outer).getName() @@ -13674,13 +13643,12 @@ public class GameActionUtil { } // Ability - final PlayerLife life = AllZone.GameAction.getPlayerLife(player); SpellAbility ability = new Ability(new Card(), "0") { @Override public void resolve() { - life.addLife(lifeGain[0]); + AllZone.GameAction.gainLife(player, lifeGain[0]); } }; ability.setStackDescription(angelicChorus.get(i).getName() diff --git a/src/forge/PlayerLife.java b/src/forge/PlayerLife.java index b22d7822fa7..33de55e5476 100644 --- a/src/forge/PlayerLife.java +++ b/src/forge/PlayerLife.java @@ -8,16 +8,18 @@ public class PlayerLife extends MyObservable implements java.io.Serializable private int life; private int assignedDamage;//from combat - public void setAssignedDamage(int n) {assignedDamage = n;} - public int getAssignedDamage() {return assignedDamage;} + public void setPlayerCard(Card playerCard) { this.playerCard = playerCard; } + public Card getPlayerCard() { return playerCard; } + public void setAssignedDamage(int n) { assignedDamage = n; } + public int getAssignedDamage() { return assignedDamage; } public PlayerLife(String pl) { player = pl; if (player.equals(Constant.Player.Human)) - playerCard = AllZone.CardFactory.HumanNullCard; + setPlayerCard(AllZone.CardFactory.HumanNullCard); else - playerCard = AllZone.CardFactory.ComputerNullCard; + setPlayerCard(AllZone.CardFactory.ComputerNullCard); } public int getLife() @@ -33,9 +35,6 @@ public class PlayerLife extends MyObservable implements java.io.Serializable public void addLife(int life2) { life += life2; - Object[] Life_Whenever_Parameters = new Object[1]; - Life_Whenever_Parameters[0] = life2; - AllZone.GameAction.CheckWheneverKeyword(playerCard, "GainLife", Life_Whenever_Parameters); this.updateObservers(); } public void subtractLife(int life2, Card SourceCard) @@ -51,7 +50,7 @@ public class PlayerLife extends MyObservable implements java.io.Serializable this.updateObservers(); } - public void payLife(int life2) + public void payLife(int life2) // change this to subtractLife { life -= life2; this.updateObservers(); diff --git a/src/forge/QuestUtil.java b/src/forge/QuestUtil.java index 3880c3ea8b3..eb6b4c7888f 100644 --- a/src/forge/QuestUtil.java +++ b/src/forge/QuestUtil.java @@ -149,7 +149,7 @@ public class QuestUtil { @Override public void resolve() { - AllZone.GameAction.getPlayerLife(crd.getController()).addLife(1); + AllZone.GameAction.gainLife(crd.getController(), 1); } }; c.addSpellAbility(ability);