- Added the static ability "CostChange".

This commit is contained in:
Sloth
2012-05-23 10:00:00 +00:00
parent 99df58b731
commit cb3b65351c
4 changed files with 107 additions and 0 deletions

1
.gitattributes vendored
View File

@@ -11766,6 +11766,7 @@ src/main/java/forge/card/staticability/StaticAbility.java svneol=native#text/pla
src/main/java/forge/card/staticability/StaticAbilityCantBeCast.java svneol=native#text/plain
src/main/java/forge/card/staticability/StaticAbilityCantTarget.java -text
src/main/java/forge/card/staticability/StaticAbilityContinuous.java svneol=native#text/plain
src/main/java/forge/card/staticability/StaticAbilityCostChange.java -text
src/main/java/forge/card/staticability/StaticAbilityETBTapped.java -text
src/main/java/forge/card/staticability/StaticAbilityPreventDamage.java svneol=native#text/plain
src/main/java/forge/card/staticability/package-info.java svneol=native#text/plain

View File

@@ -2408,6 +2408,13 @@ public class GameAction {
manaCost = new ManaCost(manaC);
}
} // Khalni Hydra
for (Card c : cardsInPlay) {
final ArrayList<StaticAbility> staticAbilities = c.getStaticAbilities();
for (final StaticAbility stAb : staticAbilities) {
manaCost = stAb.applyAbility("CostChange", spell, manaCost);
}
}
return manaCost;
} // GetSpellCostChange

View File

@@ -27,6 +27,7 @@ import forge.Card;
import forge.GameEntity;
import forge.Singletons;
import forge.card.abilityfactory.AbilityFactory;
import forge.card.mana.ManaCost;
import forge.card.spellability.SpellAbility;
import forge.game.phase.PhaseType;
import forge.game.player.Player;
@@ -341,6 +342,35 @@ public class StaticAbility {
return false;
}
/**
* Apply ability.
*
* @param mode
* the mode
* @param sa
* the SpellAbility
* @param originalCost
* the originalCost
* @return the modified ManaCost
*/
public final ManaCost applyAbility(final String mode, final SpellAbility sa, final ManaCost originalCost) {
// don't apply the ability if it hasn't got the right mode
if (!this.mapParams.get("Mode").equals(mode)) {
return originalCost;
}
if (this.isSuppressed() || !this.checkConditions()) {
return originalCost;
}
if (mode.equals("CostChange")) {
return StaticAbilityCostChange.applyCostChangeAbility(this, sa, originalCost);
}
return originalCost;
}
/**
* Apply ability.
*

View File

@@ -0,0 +1,69 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card.staticability;
import java.util.HashMap;
import forge.Card;
import forge.card.mana.ManaCost;
import forge.card.spellability.SpellAbility;
import forge.game.player.Player;
/**
* The Class StaticAbility_CantBeCast.
*/
public class StaticAbilityCostChange {
/**
* Applies CostChange ability.
*
* @param staticAbility
* a StaticAbility
* @param sa
* the SpellAbility
* @param originalCost
* a ManaCost
*/
public static ManaCost applyCostChangeAbility(final StaticAbility staticAbility, final SpellAbility sa
, final ManaCost originalCost) {
final HashMap<String, String> params = staticAbility.getMapParams();
final Card hostCard = staticAbility.getHostCard();
final Player activator = sa.getActivatingPlayer();
final Card card = sa.getSourceCard();
if (params.containsKey("ValidCard")
&& !card.isValid(params.get("ValidCard").split(","), hostCard.getController(), hostCard)) {
return originalCost;
}
if (params.containsKey("Activator") && ((activator == null)
|| !activator.isValid(params.get("Activator"), hostCard.getController(), hostCard))) {
return originalCost;
}
if (params.containsKey("Type") && params.get("Type").equals("Spell") && !sa.isSpell()) {
return originalCost;
}
if (params.containsKey("Type") && params.get("Type").equals("Ability") && !sa.isAbility()) {
return originalCost;
}
//modify the cost here
return originalCost;
}
}