From cf4437bdbd9c998cd48adc91c6f654977f814d15 Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 12:57:32 +0000 Subject: [PATCH] - Removed the unused variable dealtCombatDmgToOppThisTurn of the card class. - Fixed dealtDmgToOppThisTurn to be used in the proper place. - Added some basic AI for AF sacrifice if Defined = Each. --- src/forge/AbilityFactory_Sacrifice.java | 32 +++++++++++++++------- src/forge/Card.java | 8 +++--- src/forge/CardFactory_Creatures.java | 36 ++----------------------- src/forge/GameActionUtil.java | 13 +++++---- src/forge/Player.java | 2 -- 5 files changed, 36 insertions(+), 55 deletions(-) diff --git a/src/forge/AbilityFactory_Sacrifice.java b/src/forge/AbilityFactory_Sacrifice.java index a73d595fdf7..a78e6cb81ff 100644 --- a/src/forge/AbilityFactory_Sacrifice.java +++ b/src/forge/AbilityFactory_Sacrifice.java @@ -5,7 +5,7 @@ import java.util.HashMap; public class AbilityFactory_Sacrifice { //************************************************************** - // ****************************** FOG ************************** + // *************************** Sacrifice *********************** //************************************************************** public static SpellAbility createAbilitySacrifice(final AbilityFactory AF){ @@ -114,14 +114,15 @@ public class AbilityFactory_Sacrifice { } public static boolean sacrificeCanPlayAI(final AbilityFactory af, SpellAbility sa){ - // AI should only activate this during Human's Declare Blockers phase + + HashMap params = af.getMapParams(); boolean chance = sacrificeTgtAI(af, sa); // Some additional checks based on what is being sacrificed, and who is sacrificing Target tgt = af.getAbTgt(); if (tgt != null){ - String valid = af.getMapParams().get("SacValid"); - String num = af.getMapParams().get("Amount"); + String valid = params.get("SacValid"); + String num = params.get("Amount"); num = (num == null) ? "1" : num; int amount = AbilityFactory.calculateAmount(sa.getSourceCard(), num, sa); @@ -136,8 +137,6 @@ public class AbilityFactory_Sacrifice { // If the Human has at least half rounded up of the amount to be sacrificed, cast the spell if (list.size() < half) return false; - - return true; } Ability_Sub subAb = sa.getSubAbility(); @@ -161,7 +160,11 @@ public class AbilityFactory_Sacrifice { } public static boolean sacrificeTgtAI(AbilityFactory af, SpellAbility sa){ + + HashMap params = af.getMapParams(); + Card card = sa.getSourceCard(); Target tgt = af.getAbTgt(); + if (tgt != null){ tgt.resetTargets(); if (AllZone.HumanPlayer.canTarget(sa.getSourceCard())) @@ -170,15 +173,24 @@ public class AbilityFactory_Sacrifice { return false; } else{ - String defined = af.getMapParams().get("Defined"); + String defined = params.get("Defined"); if (defined == null){ // Self Sacrifice. } else if (defined.equals("Each")){ // If Sacrifice hits both players: - // Don't cast it if Human doesn't have any of valid - // Definitely cast it if AI doesn't have any of Valid - // Cast if the type is favorable: my "worst" valid is worse than his "worst" valid + // Only cast it if Human has the full amount of valid + // Only cast it if AI doesn't have the full amount of Valid + // TODO: Cast if the type is favorable: my "worst" valid is worse than his "worst" valid + String valid = params.get("SacValid"); + String num = params.containsKey("Amount") ? params.get("Amount") : "1"; + int amount = AbilityFactory.calculateAmount(card, num, sa); + CardList humanList = AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer); + humanList = humanList.getValidCards(valid.split(","), sa.getActivatingPlayer(), sa.getSourceCard()); + CardList computerList = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer); + computerList = computerList.getValidCards(valid.split(","), sa.getActivatingPlayer(), sa.getSourceCard()); + + if(humanList.size() < amount || computerList.size() >= amount ) return false; } } diff --git a/src/forge/Card.java b/src/forge/Card.java index 1a2c1a086b6..e817dd8094a 100644 --- a/src/forge/Card.java +++ b/src/forge/Card.java @@ -53,11 +53,11 @@ public class Card extends MyObservable { private boolean copiedSpell = false; private boolean SpellwithChoices = false; private boolean SpellCopyingCard = false; - private boolean creatureAttackedThisTurn = false; + private boolean creatureAttackedThisTurn = false; private boolean creatureAttackedThisCombat = false; private boolean creatureBlockedThisCombat = false; private boolean creatureGotBlockedThisCombat = false; - private boolean dealtCombatDmgToOppThisTurn = false; + //private boolean dealtCombatDmgToOppThisTurn = false; private boolean dealtDmgToOppThisTurn = false; private boolean sirenAttackOrDestroy = false; private boolean exaltedBonus = false; @@ -253,14 +253,14 @@ public class Card extends MyObservable { public boolean getCreatureGotBlockedThisCombat() { return creatureGotBlockedThisCombat; } - + /* public void setDealtCombatDmgToOppThisTurn(boolean b) { dealtCombatDmgToOppThisTurn = b; } public boolean getDealtCombatDmgToOppThisTurn() { return dealtCombatDmgToOppThisTurn; - } + }*/ public boolean canAnyPlayerActivate() { for(SpellAbility s : spellAbility) diff --git a/src/forge/CardFactory_Creatures.java b/src/forge/CardFactory_Creatures.java index c331f8693a9..96c520d254b 100644 --- a/src/forge/CardFactory_Creatures.java +++ b/src/forge/CardFactory_Creatures.java @@ -5818,25 +5818,6 @@ public class CardFactory_Creatures { ability.setStackDescription(sb.toString()); }//*************** END ************ END ************************** - /* - - String player = card2.getController(); - CardList creatures; - if(player.equals(AllZone.HumanPlayer)) { - creatures = new CardList(AllZone.Human_Play.getCards()); - } else { - creatures = new CardList(AllZone.Computer_Play.getCards()); - } - - creatures = creatures.getType("Creature"); - - for(int i = 0; i < creatures.size(); i++) { - Card card = creatures.get(i); - card.addCounter(Counters.P1P1, 1); - card.addExtrinsicKeyword("Vigilance"); - } - - */ //*************** START *********** START ************************** else if(cardName.equals("Giltspire Avenger")) { @@ -5848,22 +5829,12 @@ public class CardFactory_Creatures { return false; } - @Override - public boolean canPlay() { - Log.debug("Giltspire Avenger","phase =" + AllZone.Phase.getPhase()); - if((AllZone.Phase.getPhase().equals(Constant.Phase.Main2) || AllZone.Phase.getPhase().equals( - Constant.Phase.End_Of_Turn)) - && !card.hasSickness() && card.isUntapped() && super.canPlay()) return true; - else return false; - - } - @Override public void resolve() { Card c = getTargetCard(); if(AllZone.GameAction.isCardInPlay(c) - && (c.getDealtCombatDmgToOppThisTurn() || c.getDealtDmgToOppThisTurn()) + && c.getDealtDmgToOppThisTurn() && CardFactoryUtil.canTarget(card, c)) { AllZone.GameAction.destroy(c); } @@ -5888,10 +5859,7 @@ public class CardFactory_Creatures { public void selectCard(Card c, PlayerZone zone) { if(!CardFactoryUtil.canTarget(card, c)) { AllZone.Display.showMessage("Cannot target this card (Shroud? Protection?)."); - } else if(c.isCreature() && zone.is(Constant.Zone.Play) - && (c.getDealtCombatDmgToOppThisTurn() || c.getDealtDmgToOppThisTurn())) { - //tap ability - card.tap(); + } else if(c.isCreature() && zone.is(Constant.Zone.Play) && c.getDealtDmgToOppThisTurn()) { ability.setTargetCard(c); AllZone.Stack.add(ability); diff --git a/src/forge/GameActionUtil.java b/src/forge/GameActionUtil.java index 732614cebe5..15f3aee0aa9 100644 --- a/src/forge/GameActionUtil.java +++ b/src/forge/GameActionUtil.java @@ -3130,8 +3130,8 @@ public class GameActionUtil { for(int i = 0; i < list.size(); i++) { Card c = list.get(i); - if(c.getDealtCombatDmgToOppThisTurn()) c.setDealtCombatDmgToOppThisTurn(false); - if(c.getDealtDmgToOppThisTurn()) c.setDealtDmgToOppThisTurn(false); + //c.setDealtCombatDmgToOppThisTurn(false); + c.setDealtDmgToOppThisTurn(false); } } @@ -5874,7 +5874,9 @@ public class GameActionUtil { else if(c.getName().equals("Thieving Magpie")|| c.getName().equals("Lu Xun, Scholar General")) playerCombatDamage_Shadowmage_Infiltrator(c); else if(c.getName().equals("Warren Instigator")) playerCombatDamage_Warren_Instigator(c); else if(c.getName().equals("Whirling Dervish") || c.getName().equals("Dunerider Outlaw")) - playerCombatDamage_Whirling_Dervish(c); + playerCombatDamage_Whirling_Dervish(c); + + if (!c.getController().isPlayer(player)) c.setDealtDmgToOppThisTurn(true); } } //restricted to combat damage, restricted to players @@ -5979,8 +5981,9 @@ public class GameActionUtil { else if(c.getName().equals("Treva, the Renewer")) playerCombatDamage_Treva(c); else if(c.getName().equals("Rith, the Awakener")) playerCombatDamage_Rith(c); else if(c.getName().equals("Vorosh, the Hunter")) playerCombatDamage_Vorosh(c); - - if(c.getNetAttack() > 0) c.setDealtCombatDmgToOppThisTurn(true); + + //Unused variable + //c.setDealtCombatDmgToOppThisTurn(true); } diff --git a/src/forge/Player.java b/src/forge/Player.java index 7a508b85898..ee72bc31ffb 100644 --- a/src/forge/Player.java +++ b/src/forge/Player.java @@ -221,7 +221,6 @@ public abstract class Player extends MyObservable{ } GameActionUtil.executeDamageDealingEffects(source, damageToDo); - GameActionUtil.executeDamageToPlayerEffects(this, source, damageToDo); } @@ -329,7 +328,6 @@ public abstract class Player extends MyObservable{ //GameActionUtil.executePlayerDamageEffects(player, source, damage, true); GameActionUtil.executeCombatDamageToPlayerEffects(source, damageToDo); GameActionUtil.executeCombatDamageEffects(source, damageToDo); - source.setDealtCombatDmgToOppThisTurn(true); } //////////////////////////