- Add CostUnattach

- Add Heartseeker
This commit is contained in:
Sol
2013-02-20 02:29:32 +00:00
parent a7f67248d4
commit d53f2b7fa8
4 changed files with 181 additions and 2 deletions

View File

@@ -232,14 +232,21 @@ public class Cost {
return new CostGainLife(splitStr[0], splitStr[1], cnt);
}
if(parse.startsWith("Unattach<")) {
// Unattach<Type/Desc>
final String[] splitStr = abCostParse(parse, 2);
final String description = splitStr.length > 1 ? splitStr[1] : null;
return new CostUnattach(splitStr[0], description);
}
if(parse.startsWith("DamageYou<")) {
// PayLife<LifeCost>
// Damage<NumDmg>
final String[] splitStr = abCostParse(parse, 1);
return new CostDamage(splitStr[0]);
}
if(parse.startsWith("Mill<")) {
// PayLife<LifeCost>
// Mill<NumCards>
final String[] splitStr = abCostParse(parse, 1);
return new CostMill(splitStr[0]);
}

View File

@@ -0,0 +1,158 @@
/*
* 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.cost;
import java.util.List;
import forge.Card;
import forge.CardLists;
import forge.card.spellability.SpellAbility;
import forge.game.GameState;
import forge.game.player.AIPlayer;
import forge.game.player.Player;
import forge.gui.GuiDialog;
/**
* The Class CostUnattach.
*/
public class CostUnattach extends CostPartWithList {
// Unattach<CARDNAME> if ability is on the Equipment
// Unattach<Card.Attached+namedHeartseeker/Equipped Heartseeker> if equipped creature has the ability
/**
* Instantiates a new cost unattach.
*/
public CostUnattach(final String type, final String desc) {
super("1", type, desc);
}
@Override
public boolean isUndoable() { return false; }
@Override
public boolean isReusable() { return false; }
/*
* (non-Javadoc)
*
* @see forge.card.cost.CostPart#toString()
*/
@Override
public final String toString() {
return String.format("Unattach %s", this.getTypeDescription());
}
/*
* (non-Javadoc)
*
* @see
* forge.card.cost.CostPart#canPay(forge.card.spellability.SpellAbility,
* forge.Card, forge.Player, forge.card.cost.Cost)
*/
@Override
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost, final GameState game) {
final String type = this.getType();
if (type.equals("CARDNAME")) {
if (source.isEquipping()) {
return true;
}
} else {
List<Card> equipped = source.getEquippedBy();
if (CardLists.getValidCards(equipped, type, activator, source).size() > 0) {
return true;
}
}
return false;
}
/*
* (non-Javadoc)
*
* @see forge.card.cost.CostPart#payAI(forge.card.spellability.SpellAbility,
* forge.Card, forge.card.cost.Cost_Payment)
*/
@Override
public final void payAI(final AIPlayer ai, final SpellAbility ability, final Card source, final CostPayment payment, final GameState game) {
Card cardToUnattach = findCardToUnattach(source, (Player)ai);
if (cardToUnattach == null) {
// We really shouldn't be able to get here if there's nothing to unattach
return;
}
Card equippingCard = cardToUnattach.getEquipping().get(0);
cardToUnattach.unEquipCard(equippingCard);
this.addToList(cardToUnattach);
}
/*
* (non-Javadoc)
*
* @see
* forge.card.cost.CostPart#payHuman(forge.card.spellability.SpellAbility,
* forge.Card, forge.card.cost.Cost_Payment)
*/
@Override
public final boolean payHuman(final SpellAbility ability, final Card source, final CostPayment payment, final GameState game) {
this.resetList();
Player activator = ability.getActivatingPlayer();
Card cardToUnattach = findCardToUnattach(source, activator);
if (cardToUnattach != null && GuiDialog.confirm(source, String.format("Unattach %s?", cardToUnattach.toString()))) {
Card equippingCard = cardToUnattach.getEquipping().get(0);
cardToUnattach.unEquipCard(equippingCard);
this.addToList(cardToUnattach);
payment.setPaidManaPart(this);
} else {
payment.setCancel(true);
payment.getRequirements().finishPaying();
return false;
}
return true;
}
private Card findCardToUnattach(final Card source, Player activator) {
if (getType().equals("CARDNAME")) {
if (source.isEquipping()) {
return source;
}
} else {
List<Card> attachees = CardLists.getValidCards(source.getEquippedBy(), this.getType(), activator, source);
if (attachees.size() > 0) {
// Just pick the first one, although maybe give a dialog
return attachees.get(0);
}
}
return null;
}
/*
* (non-Javadoc)
*
* @see
* forge.card.cost.CostPart#decideAIPayment(forge.card.spellability.SpellAbility
* , forge.Card, forge.card.cost.Cost_Payment)
*/
@Override
public final boolean decideAIPayment(final AIPlayer ai, final SpellAbility ability, final Card source, final CostPayment payment) {
this.resetList();
return true;
}
}