It is currently 23 Apr 2024, 11:35
   
Text Size

Help implementing Haakon, Stromgald Scourge

Moderators: North, BetaSteward, noxx, jeffwadsworth, JayDi, TheElk801, LevelX, CCGHQ Admins

Help implementing Haakon, Stromgald Scourge

Postby Mainiack11 » 21 Jan 2015, 17:22

I've recently decided to try my hand at implementing cards, and decided to start with a card I want to test for a modern deck.

Haakon makes knight cards castable from the graveyard. I've looked at the code for Crucible of Worlds to try and get a reference for how to do it, but Crucible of Worlds is coded in a way that is unique to lands.

I also have not been able to find a card with the same restriction Haakon has to being cast. Haakon can only be cast from your graveyard. He has a CMC, but can't be cast from your hand.

Some guidance on where to look would be appreciated.
Mainiack11
 
Posts: 28
Joined: 12 Aug 2014, 05:01
Has thanked: 2 times
Been thanked: 1 time

Re: Help implementing Haakon, Stromgald Scourge

Postby LevelX » 21 Jan 2015, 18:12

Of course, not a easy card to start with. :-)

The first should be a ConinuousRuleChangingEffect looking for the CAST_SPELL event and prevent to be able to cast source from a zone != GRAVEYARD.
Look at first ability of Yawgmoth's Agenda for example.

The second a PLAY_FROM_NON_HAND_ZONE AsThoughEffect I guess.
Search for "play % from your graveyard" in rules filter field on http://ct-magefree.rhcloud.com/cards for more examples.

The third ability should be easy to implement.

For complicated cards it's often neccessary to start and test and if it's not working the first way you thought to change the way of implementation or also change or advance framework classes.

So better start with some more "normal" cards. This is maybe headscratcher to implement correctly.
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Help implementing Haakon, Stromgald Scourge

Postby Mainiack11 » 22 Jan 2015, 03:26

so, I've got the card partially implemented. You aren't able to cast him from the hand, and he is castable from the graveyard.

I've not been able to make it so Knight cards are castable from the graveyard.

I've also noticed a weird bug that seems to stem from Haakon, that I haven't been able to lock down. If the host of the lobby has more than one card with dredge in the graveyard, and the opponent has Haakon in play, the replacement effect selection dialog rapidly closes and opens.

I've attached the java file as txt and pasted the code below, if anyone wouldn't mind taking a look.

Code: Select all
package mage.sets.coldsnap;

import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.common.DiesTriggeredAbility;
import mage.constants.Layer;
import mage.constants.SubLayer;
import mage.abilities.effects.ContinuousRuleModifiyingEffectImpl;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.AsThoughEffectType;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.abilities.effects.common.LoseLifeSourceControllerEffect;
import mage.players.Player;

/**
 *
 * @author Mainiack11
 */
public class HaakonStromgaldScourge extends CardImpl {

    public HaakonStromgaldScourge(UUID ownerId) {
        super(ownerId, 61, "Haakon, Stromgald Scourge", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{1}{B}{B}");
        this.expansionSetCode = "CSP";
        this.supertype.add("Legendary");
        this.subtype.add("Zombie");
        this.subtype.add("Knight");
       
        this.color.setBlack(true);
        this.power = new MageInt(3);
        this.toughness = new MageInt(3);

        this.addAbility(new SimpleStaticAbility(Zone.GRAVEYARD, new HaakonStromgaldScourgePlayEffect()));
        this.addAbility(new SimpleStaticAbility(Zone.ALL, new HaakonStromgaldScourgePlayEffect2()));
        this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new HaakonStromgaldScourgeCanPlayKnightsFromGraveyardEffect()));
        this.addAbility(new DiesTriggeredAbility(new LoseLifeSourceControllerEffect(2)));
       
    }

    public HaakonStromgaldScourge(final HaakonStromgaldScourge card) {
        super(card);
    }

    @Override
    public HaakonStromgaldScourge copy() {
        return new HaakonStromgaldScourge(this);
    }

}

class HaakonStromgaldScourgePlayEffect extends AsThoughEffectImpl {
   
    public HaakonStromgaldScourgePlayEffect() {
        super(AsThoughEffectType.PLAY_FROM_NON_HAND_ZONE, Duration.EndOfGame, Outcome.Benefit);
        staticText = "You may cast Haakon, Stromgald Scourge from your graveyard, but not from anywhere else.";
    }
   
    public HaakonStromgaldScourgePlayEffect(final HaakonStromgaldScourgePlayEffect effect) {
        super(effect);
    }
   
    @Override
    public boolean apply(Game game, Ability source) {
        return true;
    }
   
    @Override
    public HaakonStromgaldScourgePlayEffect copy() {
        return new HaakonStromgaldScourgePlayEffect(this);
    }
   
    @Override
    public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
        if (sourceId.equals(source.getSourceId())) {
            Card card = game.getCard(source.getSourceId());
            if (card != null && card.getOwnerId().equals(source.getControllerId()) && game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) {
                return true;
            }
        }
        return false;
    }
}

class HaakonStromgaldScourgePlayEffect2 extends ContinuousRuleModifiyingEffectImpl {
   
    public HaakonStromgaldScourgePlayEffect2() {
        super(Duration.EndOfGame, Outcome.Detriment);
        staticText = "You may cast Haakon, Stromgald Scourge from your graveyard, but not from anywhere else.";
    }
   
    public HaakonStromgaldScourgePlayEffect2 (final HaakonStromgaldScourgePlayEffect2 effect) {
        super(effect);
    }
   
    @Override
    public HaakonStromgaldScourgePlayEffect2 copy() {
        return new HaakonStromgaldScourgePlayEffect2(this);
    }
   
    @Override
    public boolean apply(Game game, Ability source) {
        return true;
    }
   
    @Override
    public boolean applies(GameEvent event, Ability source, Game game) {
        if(event.getType() == GameEvent.EventType.CAST_SPELL) {
            Card card = game.getCard(event.getSourceId());
            if (card != null && card.getName().equals("Haakon, Stromgald Scourge")) {
                Zone zone = game.getState().getZone(card.getId());
                if (zone != null && (zone != Zone.GRAVEYARD)) {
                    return true;
                }
            }
        }
        return false;
    }
}

class HaakonStromgaldScourgeCanPlayKnightsFromGraveyardEffect extends ContinuousEffectImpl {
   
    public HaakonStromgaldScourgeCanPlayKnightsFromGraveyardEffect() {
        super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
        this.staticText = "As long as Haakon, Stromgald Scourge is on the battlefield, you may play Knight cards from your graveyard.";
    }

    public HaakonStromgaldScourgeCanPlayKnightsFromGraveyardEffect(final HaakonStromgaldScourgeCanPlayKnightsFromGraveyardEffect effect) {
        super(effect);
    }
   
    @Override
    public HaakonStromgaldScourgeCanPlayKnightsFromGraveyardEffect copy() {
        return new HaakonStromgaldScourgeCanPlayKnightsFromGraveyardEffect(this);
    }
   
    @Override
    public boolean apply(Game game, Ability source) {
        Player player = game.getPlayer(source.getControllerId());
        if (player != null) {
            for (UUID cardId: player.getGraveyard()) {
                Card card = game.getCard(cardId);
                if(card != null && card.getSubtype().contains("Knight")) {
                    SimpleStaticAbility ability = new SimpleStaticAbility(Zone.GRAVEYARD, new PlayKnightsFromGraveyardAbility());
                    ability.setSourceId(cardId);
                    ability.setControllerId(card.getOwnerId());
                    game.getState().addOtherAbility(cardId, ability);
                }
            }
            return true;
        }
        return false;
    }
}

class PlayKnightsFromGraveyardAbility extends AsThoughEffectImpl {
   
    public PlayKnightsFromGraveyardAbility () {
        super(AsThoughEffectType.PLAY_FROM_NON_HAND_ZONE, Duration.WhileInGraveyard, Outcome.Benefit);
        staticText = "As long as Haakon is on the battlefield, you may play Knight cards from your graveyard.";
    }
   
    public PlayKnightsFromGraveyardAbility(final PlayKnightsFromGraveyardAbility effect) {
        super(effect);
    }
   
    @Override
    public boolean apply(Game game, Ability source) {
        return true;
    }
   
    @Override
    public PlayKnightsFromGraveyardAbility copy() {
        return new PlayKnightsFromGraveyardAbility(this);
    }
   
    @Override
    public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
        if (sourceId.equals(source.getSourceId())) {
            Card card = game.getCard(source.getSourceId());
            if (card != null && card.getOwnerId().equals(source.getControllerId()) && game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) {
                return true;
            }
        }
        return false;
    }
}
Attachments
HaakonStromgaldScourge.txt
(8.57 KiB) Downloaded 217 times
Mainiack11
 
Posts: 28
Joined: 12 Aug 2014, 05:01
Has thanked: 2 times
Been thanked: 1 time

Re: Help implementing Haakon, Stromgald Scourge

Postby LevelX » 22 Jan 2015, 10:36

Did not test it, but after this changes it should work.

Code: Select all
/*
 *  Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without modification, are
 *  permitted provided that the following conditions are met:
 *
 *     1. Redistributions of source code must retain the above copyright notice, this list of
 *        conditions and the following disclaimer.
 *
 *     2. Redistributions in binary form must reproduce the above copyright notice, this list
 *        of conditions and the following disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 *  THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 *  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
 *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 *  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *  The views and conclusions contained in the software and documentation are those of the
 *  authors and should not be interpreted as representing official policies, either expressed
 *  or implied, of BetaSteward_at_googlemail.com.
 */

package mage.sets.coldsnap;

import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.common.DiesTriggeredAbility;
import mage.abilities.effects.ContinuousRuleModifiyingEffectImpl;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.AsThoughEffectType;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.abilities.effects.common.LoseLifeSourceControllerEffect;

/**
 *
 * @author Mainiack11
 */
public class HaakonStromgaldScourge extends CardImpl {

    public HaakonStromgaldScourge(UUID ownerId) {
        super(ownerId, 61, "Haakon, Stromgald Scourge", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{1}{B}{B}");
        this.expansionSetCode = "CSP";
        this.supertype.add("Legendary");
        this.subtype.add("Zombie");
        this.subtype.add("Knight");
       
        this.color.setBlack(true);
        this.power = new MageInt(3);
        this.toughness = new MageInt(3);

        // You may cast Haakon, Stromgald Scourge from your graveyard, but not from anywhere else.
        Ability ability = new SimpleStaticAbility(Zone.ALL, new HaakonStromgaldScourgePlayEffect());
        ability.addEffect(new HaakonStromgaldScourgePlayEffect2());
        this.addAbility(ability);
       
        // As long as Haakon is on the battlefield, you may play Knight cards from your graveyard.
        this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new HaakonPlayKnightsFromGraveyardEffect()));
       
        // When Haakon dies, you lose 2 life.
        this.addAbility(new DiesTriggeredAbility(new LoseLifeSourceControllerEffect(2)));
       
    }

    public HaakonStromgaldScourge(final HaakonStromgaldScourge card) {
        super(card);
    }

    @Override
    public HaakonStromgaldScourge copy() {
        return new HaakonStromgaldScourge(this);
    }

}

class HaakonStromgaldScourgePlayEffect extends AsThoughEffectImpl {
   
    public HaakonStromgaldScourgePlayEffect() {
        super(AsThoughEffectType.PLAY_FROM_NON_HAND_ZONE, Duration.EndOfGame, Outcome.Benefit);
        staticText = "You may cast {this} from your graveyard";
    }
   
    public HaakonStromgaldScourgePlayEffect(final HaakonStromgaldScourgePlayEffect effect) {
        super(effect);
    }
   
    @Override
    public boolean apply(Game game, Ability source) {
        return true;
    }
   
    @Override
    public HaakonStromgaldScourgePlayEffect copy() {
        return new HaakonStromgaldScourgePlayEffect(this);
    }
   
    @Override
    public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
        if (objectId.equals(source.getSourceId()) &&
                affectedControllerId.equals(source.getControllerId())) {
            Card card = game.getCard(source.getSourceId());
            if (card != null && game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) {
                return true;
            }
        }
        return false;
    }
}

class HaakonStromgaldScourgePlayEffect2 extends ContinuousRuleModifiyingEffectImpl {
   
    public HaakonStromgaldScourgePlayEffect2() {
        super(Duration.EndOfGame, Outcome.Detriment);
        staticText = ", but not from anywhere else";
    }
   
    public HaakonStromgaldScourgePlayEffect2 (final HaakonStromgaldScourgePlayEffect2 effect) {
        super(effect);
    }
   
    @Override
    public HaakonStromgaldScourgePlayEffect2 copy() {
        return new HaakonStromgaldScourgePlayEffect2(this);
    }
   
    @Override
    public boolean apply(Game game, Ability source) {
        return true;
    }
   
    @Override
    public boolean applies(GameEvent event, Ability source, Game game) {
        if(event.getType() == GameEvent.EventType.CAST_SPELL) {
            Card card = game.getCard(event.getSourceId());
            if (card != null && card.getId().equals(source.getSourceId())) {
                Zone zone = game.getState().getZone(card.getId());
                if (zone != null && (zone != Zone.GRAVEYARD)) {
                    return true;
                }
            }
        }
        return false;
    }
}

class HaakonPlayKnightsFromGraveyardEffect extends AsThoughEffectImpl {
   
    public HaakonPlayKnightsFromGraveyardEffect () {
        super(AsThoughEffectType.PLAY_FROM_NON_HAND_ZONE, Duration.WhileOnBattlefield, Outcome.Benefit);
        staticText = "As long as {this} is on the battlefield, you may play Knight cards from your graveyard";
    }
   
    public HaakonPlayKnightsFromGraveyardEffect(final HaakonPlayKnightsFromGraveyardEffect effect) {
        super(effect);
    }
   
    @Override
    public boolean apply(Game game, Ability source) {
        return true;
    }
   
    @Override
    public HaakonPlayKnightsFromGraveyardEffect copy() {
        return new HaakonPlayKnightsFromGraveyardEffect(this);
    }
   
    @Override
    public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {       
        if (affectedControllerId.equals(source.getControllerId())) {
            Card knightToCast = game.getCard(objectId);
            if (knightToCast != null
                    && knightToCast.hasSubtype("Knight")
                    && knightToCast.getOwnerId().equals(source.getControllerId())
                    && game.getState().getZone(objectId) == Zone.GRAVEYARD) {
                return true;
            }
        }
        return false;
    }
}
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Help implementing Haakon, Stromgald Scourge

Postby Mainiack11 » 23 Jan 2015, 01:50

I've tested the code you posted, and it seems to all be working correctly. How do I got about getting it added to the project? I didn't fork mage when I started, so I'm not sure how to make a pull request on github.

EDIT: I figured out how to make a pull request on Github.
Mainiack11
 
Posts: 28
Joined: 12 Aug 2014, 05:01
Has thanked: 2 times
Been thanked: 1 time


Return to Developers Talk

Who is online

Users browsing this forum: No registered users and 5 guests


Who is online

In total there are 5 users online :: 0 registered, 0 hidden and 5 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 5 guests

Login Form