incremental update for AF_Animate to support removing triggers and abilities as part of the animate.

This commit is contained in:
slapshot5
2011-09-09 01:18:32 +00:00
parent 73c42b2104
commit b14dc3aae8
3 changed files with 107 additions and 45 deletions

View File

@@ -1,7 +1,20 @@
package forge.card.abilityFactory; package forge.card.abilityFactory;
import forge.*;
import forge.card.spellability.*; import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardUtil;
import forge.Command;
import forge.ComputerUtil;
import forge.Constant;
import forge.card.spellability.Ability_Activated;
import forge.card.spellability.Ability_Sub;
import forge.card.spellability.Spell;
import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target;
import forge.card.staticAbility.StaticAbility; import forge.card.staticAbility.StaticAbility;
import forge.card.trigger.Trigger; import forge.card.trigger.Trigger;
import forge.card.trigger.TriggerHandler; import forge.card.trigger.TriggerHandler;
@@ -17,7 +30,11 @@ import java.util.Map;
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class AbilityFactory_Animate { public final class AbilityFactory_Animate {
private AbilityFactory_Animate() {
throw new AssertionError();
}
//************************************************************** //**************************************************************
//************************** Animate *************************** //************************** Animate ***************************
@@ -419,7 +436,7 @@ public class AbilityFactory_Animate {
final long timestamp = timest; final long timestamp = timest;
boolean permanent = params.containsKey("Permanent") ? true : false; boolean permanent = params.containsKey("Permanent");
final ArrayList<String> types = new ArrayList<String>(); final ArrayList<String> types = new ArrayList<String>();
if (params.containsKey("Types")) { if (params.containsKey("Types")) {
@@ -498,7 +515,8 @@ public class AbilityFactory_Animate {
for (final Card c : tgts) { for (final Card c : tgts) {
final long colorTimestamp = doAnimate(c, af, power, toughness, types, removeTypes, finalDesc, keywords, timestamp); final long colorTimestamp = doAnimate(c, af, power, toughness, types,
removeTypes, finalDesc, keywords, timestamp);
//give abilities //give abilities
final ArrayList<SpellAbility> addedAbilities = new ArrayList<SpellAbility>(); final ArrayList<SpellAbility> addedAbilities = new ArrayList<SpellAbility>();
@@ -512,6 +530,17 @@ public class AbilityFactory_Animate {
} }
} }
//remove abilities
final ArrayList<SpellAbility> removedAbilities = new ArrayList<SpellAbility>();
if (params.containsKey("OverwriteAbilities")) {
for (SpellAbility ab : c.getSpellAbilities()) {
if (ab.isAbility()) {
c.removeSpellAbility(ab);
removedAbilities.add(ab);
}
}
}
//Grant triggers //Grant triggers
final ArrayList<Trigger> addedTriggers = new ArrayList<Trigger>(); final ArrayList<Trigger> addedTriggers = new ArrayList<Trigger>();
if (triggers.size() > 0) { if (triggers.size() > 0) {
@@ -523,10 +552,20 @@ public class AbilityFactory_Animate {
} }
} }
//suppress triggers from the animated card
final ArrayList<Trigger> removedTriggers = new ArrayList<Trigger>();
if (params.containsKey("OverwriteTriggers")) {
System.out.println("Suppressing triggers for: "+c);
ArrayList<Trigger> triggersToRemove = c.getTriggers();
for (Trigger trigger : triggersToRemove) {
trigger.setSuppressed(true);
}
}
//give static abilities (should only be used by cards to give itself a static ability) //give static abilities (should only be used by cards to give itself a static ability)
if (stAbs.size() > 0) { if (stAbs.size() > 0) {
for (String s : stAbs) { for (String s : stAbs) {
String actualAbility = host.getSVar(s); String actualAbility = host.getSVar(s);
c.addStaticAbility(actualAbility); c.addStaticAbility(actualAbility);
} }
} }
@@ -534,7 +573,7 @@ public class AbilityFactory_Animate {
//give sVars //give sVars
if (sVars.size() > 0) { if (sVars.size() > 0) {
for (String s : sVars) { for (String s : sVars) {
String actualsVar = host.getSVar(s); String actualsVar = host.getSVar(s);
c.setSVar(s, actualsVar); c.setSVar(s, actualsVar);
} }
} }
@@ -546,7 +585,13 @@ public class AbilityFactory_Animate {
public void execute() { public void execute() {
doUnanimate(c, af, finalDesc, keywords, addedAbilities, addedTriggers, colorTimestamp, doUnanimate(c, af, finalDesc, keywords, addedAbilities, addedTriggers, colorTimestamp,
givesStAbs, timestamp); givesStAbs, removedAbilities, timestamp);
//give back suppressed triggers
for(Trigger t : removedTriggers) {
System.out.println("Unsuppressing triggers for: "+c);
t.setSuppressed(false);
}
} }
}; };
@@ -555,7 +600,7 @@ public class AbilityFactory_Animate {
AllZone.getEndOfCombat().addUntil(unanimate); AllZone.getEndOfCombat().addUntil(unanimate);
} }
else if (params.containsKey("UntilHostLeavesPlay")) { else if (params.containsKey("UntilHostLeavesPlay")) {
host.addLeavesPlayCommand(unanimate); host.addLeavesPlayCommand(unanimate);
} }
else { else {
AllZone.getEndOfTurn().addUntil(unanimate); AllZone.getEndOfTurn().addUntil(unanimate);
@@ -577,32 +622,32 @@ public class AbilityFactory_Animate {
* @return a long. * @return a long.
*/ */
private static long doAnimate(final Card c, final AbilityFactory af, final int power, final int toughness, private static long doAnimate(final Card c, final AbilityFactory af, final int power, final int toughness,
final ArrayList<String> types, final ArrayList<String> removeTypes, final String colors, final ArrayList<String> keywords, final ArrayList<String> types, final ArrayList<String> removeTypes, final String colors,
final long timestamp) final ArrayList<String> keywords, final long timestamp)
{ {
HashMap<String, String> params = af.getMapParams(); HashMap<String, String> params = af.getMapParams();
boolean removeSuperTypes = false; boolean removeSuperTypes = false;
boolean removeCardTypes = false; boolean removeCardTypes = false;
boolean removeSubTypes = false; boolean removeSubTypes = false;
boolean removeCreatureTypes = false; boolean removeCreatureTypes = false;
if (params.containsKey("OverwriteTypes")) { if (params.containsKey("OverwriteTypes")) {
removeSuperTypes = true; removeSuperTypes = true;
removeCardTypes = true; removeCardTypes = true;
removeSubTypes = true; removeSubTypes = true;
removeCreatureTypes = true; removeCreatureTypes = true;
} }
if (params.containsKey("KeepSupertypes")) { if (params.containsKey("KeepSupertypes")) {
removeSuperTypes = false; removeSuperTypes = false;
} }
if (params.containsKey("KeepCardTypes")) { if (params.containsKey("KeepCardTypes")) {
removeCardTypes = false; removeCardTypes = false;
} }
if (params.containsKey("RemoveSuperTypes")) { if (params.containsKey("RemoveSuperTypes")) {
removeSuperTypes = true; removeSuperTypes = true;
} }
@@ -619,12 +664,12 @@ public class AbilityFactory_Animate {
} }
if (power != -1 || toughness != -1) { if (power != -1 || toughness != -1) {
c.addNewPT(power, toughness, timestamp); c.addNewPT(power, toughness, timestamp);
} }
if (!types.isEmpty() || !removeTypes.isEmpty()) { if (!types.isEmpty() || !removeTypes.isEmpty()) {
c.addChangedCardTypes(types, removeTypes, removeSuperTypes, removeCardTypes, removeSubTypes, c.addChangedCardTypes(types, removeTypes, removeSuperTypes, removeCardTypes, removeSubTypes,
removeCreatureTypes, timestamp); removeCreatureTypes, timestamp);
} }
for (String k : keywords) { for (String k : keywords) {
@@ -656,21 +701,21 @@ public class AbilityFactory_Animate {
* @param timestamp a long. * @param timestamp a long.
*/ */
private static void doUnanimate(final Card c, final AbilityFactory af, final String colorDesc, private static void doUnanimate(final Card c, final AbilityFactory af, final String colorDesc,
final ArrayList<String> originalKeywords, final ArrayList<SpellAbility> addedAbilities, final ArrayList<String> originalKeywords, final ArrayList<SpellAbility> addedAbilities,
final ArrayList<Trigger> addedTriggers, final long colorTimestamp, final ArrayList<Trigger> addedTriggers, final long colorTimestamp,
final boolean givesStAbs, final long timestamp) final boolean givesStAbs, final ArrayList<SpellAbility> removedAbilities, final long timestamp)
{ {
HashMap<String, String> params = af.getMapParams(); HashMap<String, String> params = af.getMapParams();
c.removeNewPT(timestamp); c.removeNewPT(timestamp);
//remove all static abilities //remove all static abilities
if (givesStAbs) { if (givesStAbs) {
c.setStaticAbilities(new ArrayList<StaticAbility>()); c.setStaticAbilities(new ArrayList<StaticAbility>());
} }
if (params.containsKey("Types")) { if (params.containsKey("Types")) {
c.removeChangedCardTypes(timestamp); c.removeChangedCardTypes(timestamp);
} }
c.removeColor(colorDesc, c, !params.containsKey("OverwriteColors"), colorTimestamp); c.removeColor(colorDesc, c, !params.containsKey("OverwriteColors"), colorTimestamp);
@@ -687,6 +732,10 @@ public class AbilityFactory_Animate {
c.removeSpellAbility(sa); c.removeSpellAbility(sa);
} }
for (SpellAbility sa : removedAbilities) {
c.addSpellAbility(sa);
}
for (Trigger t : addedTriggers) { for (Trigger t : addedTriggers) {
AllZone.getTriggerHandler().removeRegisteredTrigger(t); AllZone.getTriggerHandler().removeRegisteredTrigger(t);
c.removeTrigger(t); c.removeTrigger(t);
@@ -920,7 +969,7 @@ public class AbilityFactory_Animate {
final long timestamp = timest; final long timestamp = timest;
boolean permanent = params.containsKey("Permanent") ? true : false; boolean permanent = params.containsKey("Permanent");
final ArrayList<String> types = new ArrayList<String>(); final ArrayList<String> types = new ArrayList<String>();
if (params.containsKey("Types")) { if (params.containsKey("Types")) {
@@ -987,7 +1036,8 @@ public class AbilityFactory_Animate {
for (final Card c : list) { for (final Card c : list) {
final long colorTimestamp = doAnimate(c, af, power, toughness, types, removeTypes, finalDesc, keywords, timestamp); final long colorTimestamp = doAnimate(c, af, power, toughness, types,
removeTypes, finalDesc, keywords, timestamp);
//give abilities //give abilities
final ArrayList<SpellAbility> addedAbilities = new ArrayList<SpellAbility>(); final ArrayList<SpellAbility> addedAbilities = new ArrayList<SpellAbility>();
@@ -1001,6 +1051,17 @@ public class AbilityFactory_Animate {
} }
} }
//remove abilities
final ArrayList<SpellAbility> removedAbilities = new ArrayList<SpellAbility>();
if (params.containsKey("OverwriteAbilities")) {
for (SpellAbility ab : c.getSpellAbilities()) {
if (ab.isAbility()) {
c.removeSpellAbility(ab);
removedAbilities.add(ab);
}
}
}
//Grant triggers //Grant triggers
final ArrayList<Trigger> addedTriggers = new ArrayList<Trigger>(); final ArrayList<Trigger> addedTriggers = new ArrayList<Trigger>();
if (triggers.size() > 0) { if (triggers.size() > 0) {
@@ -1017,7 +1078,7 @@ public class AbilityFactory_Animate {
public void execute() { public void execute() {
doUnanimate(c, af, finalDesc, keywords, addedAbilities, addedTriggers, doUnanimate(c, af, finalDesc, keywords, addedAbilities, addedTriggers,
colorTimestamp, false, timestamp); colorTimestamp, false, removedAbilities, timestamp);
} }
}; };

View File

@@ -527,9 +527,9 @@ public abstract class Trigger {
protected boolean suppressed = false; protected boolean suppressed = false;
protected boolean temporarilySuppressed = false; protected boolean temporarilySuppressed = false;
/*public void setSuppressed(boolean supp) { public void setSuppressed(boolean supp) {
suppressed = supp; suppressed = supp;
}*/ }
public void setTemporarilySuppressed(boolean supp) { public void setTemporarilySuppressed(boolean supp) {
temporarilySuppressed = supp; temporarilySuppressed = supp;

View File

@@ -46,6 +46,7 @@ public class Trigger_Taps extends Trigger {
} }
copy.setName(name); copy.setName(name);
copy.setID(ID); copy.setID(ID);
copy.setSuppressed(suppressed);
return copy; return copy;
} }