I'm trying to fix Funeral Charm
 Posted: 17 Apr 2010, 23:43
Posted: 17 Apr 2010, 23:43I tried to fix this card some time ago and ran out of steam. I recently found my code additions/modifications. So I thought that I would try again. I have the third SpellAbility included in the code object. It works reasonably well for the human.
The AI will cause the human to discard a card but it will not choose either of the two pump abilities to buff it's attacking creature. I will post my code in the hopes that someone will see something that I must have missed.
			The AI will cause the human to discard a card but it will not choose either of the two pump abilities to buff it's attacking creature. I will post my code in the hopes that someone will see something that I must have missed.
- Code: Select all
- //*************** START *********** START **************************
 else if (cardName.equals("Funeral Charm")) {
 
 //discard
 final SpellAbility spell_one = new Spell(card) {
 private static final long serialVersionUID = 8273875515630095127L;
 
 @Override
 public boolean canPlayAI() {
 CardList computerCreatures = new CardList(AllZone.Computer_Play.getCards());
 computerCreatures = computerCreatures.filter(new CardListFilter() {
 public boolean addCard(Card c) {
 return c.isCreature() && CardFactoryUtil.canTarget(card, c) &&
 !c.getKeyword().contains("Defender") && 1 < c.getNetDefense();
 }
 });
 
 setTargetPlayer(Constant.Player.Human);
 PlayerZone humanHand = AllZone.getZone(Constant.Zone.Hand, Constant.Player.Human);
 
 return (humanHand.size() >= 1 && computerCreatures.size() < 1 &&
 (MyRandom.random.nextBoolean() || MyRandom.random.nextBoolean())) ||
 (humanHand.size() >= 1 && computerCreatures.size() > 0 && MyRandom.random.nextBoolean());
 }
 
 @Override
 public void resolve() {
 if (Constant.Player.Computer.equals(getTargetPlayer())) AllZone.GameAction.discardRandom(getTargetPlayer());
 else AllZone.InputControl.setInput(CardFactoryUtil.input_discard());
 }//resolve()
 };//SpellAbility
 
 spell_one.setDescription("Target player discards a card.");
 spell_one.setBeforePayMana(CardFactoryUtil.input_targetPlayer(spell_one));
 //creature gets +2/-1
 final SpellAbility spell_two = new Spell(card) {
 private static final long serialVersionUID = -4554812851052322555L;
 
 @Override
 public boolean canPlayAI() {
 CardList list = new CardList(ComputerUtil.getAttackers().getAttackers());
 list = list.filter(new CardListFilter() {
 public boolean addCard(Card c) {
 return c.getNetDefense() > 1 && CardFactoryUtil.canTarget(card, c) &&
 (!c.hasSickness() || (c.hasSickness() && c.getKeyword().contains("Haste")));
 }
 });
 
 //put biggest attack creatures first
 if (list.size() > 0) {
 CardListUtil.sortAttack(list);
 setTargetCard(list.get(0));
 }
 
 return list.size() > 0 && MyRandom.random.nextBoolean();
 }
 
 @Override
 public void resolve() {
 final Card c = getTargetCard();
 
 if (AllZone.GameAction.isCardInPlay(c) && CardFactoryUtil.canTarget(card, c)) {
 c.addTempAttackBoost(2);
 c.addTempDefenseBoost(-1);
 
 Command until = new Command() {
 private static final long serialVersionUID = 4674846621452044251L;
 
 public void execute() {
 c.addTempAttackBoost(-2);
 c.addTempDefenseBoost(1);
 }
 };//Command
 AllZone.EndOfTurn.addUntil(until);
 }//if card in play?
 }//resolve()
 };//SpellAbility
 spell_two.setDescription("Target creature gets +2/-1 until end of turn.");
 spell_two.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell_two));
 
 //creature gets swampwalk
 final SpellAbility spell_three = new Spell(card) {
 private static final long serialVersionUID = -8455677074284271852L;
 @Override
 public boolean canPlayAI() {
 CardList creatures = new CardList(ComputerUtil.getAttackers().getAttackers());
 creatures = creatures.filter(new CardListFilter() {
 public boolean addCard(Card c) {
 return CardFactoryUtil.canTarget(card, c) && !c.getKeyword().contains("Swampwalk") &&
 (!c.hasSickness() || (c.hasSickness() && c.getKeyword().contains("Haste")));
 }
 });
 
 //put biggest attack creatures first
 if (creatures.size() > 0) {
 CardListUtil.sortAttack(creatures);
 setTargetCard(creatures.get(0));
 }
 
 CardList humanSwamp = new CardList(AllZone.Human_Play.getCards());
 humanSwamp = humanSwamp.getType("Swamp");
 
 return creatures.size() > 0 && humanSwamp.size() > 0 && MyRandom.random.nextBoolean();
 }
 
 @Override
 public void resolve() {
 final Card c = getTargetCard();
 
 if (AllZone.GameAction.isCardInPlay(c) && CardFactoryUtil.canTarget(card, c) && !c.getKeyword().contains("Swampwalk")) {
 c.addExtrinsicKeyword("Swampwalk");
 
 Command until = new Command() {
 private static final long serialVersionUID = 1452395016805444249L;
 public void execute() {
 if (AllZone.GameAction.isCardInPlay(c)) {
 c.removeExtrinsicKeyword("Swampwalk");
 }
 }
 };//Command
 AllZone.EndOfTurn.addUntil(until);
 }//if card in play?
 }//resolve()
 };//SpellAbility
 spell_three.setDescription("Target creature gains swampwalk until end of turn.");
 spell_three.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell_three));
 
 card.clearSpellAbility();
 card.addSpellAbility(spell_one);
 card.addSpellAbility(spell_two);
 card.addSpellAbility(spell_three);
 }//*************** END ************ END **************************

