It is currently 24 Apr 2024, 15:29
   
Text Size

need help implementing card

Moderators: ubeefx, beholder, melvin, ShawnieBoy, Lodici, CCGHQ Admins

need help implementing card

Postby Willzer » 05 Jun 2014, 15:01

hello guys, i'm new in this program, sorry if this is not the place to ask but I'd like to add the card ''Luminarch Ascension'', I'm still preety confused about the groovy code, could someone help me?
Willzer
 
Posts: 2
Joined: 05 Jun 2014, 14:53
Has thanked: 1 time
Been thanked: 0 time

Re: need help implementing card

Postby ShawnieBoy » 05 Jun 2014, 16:03

Welcome to Magarena!

Groovy code can be a bit daunting at first, but will soon make more sense (Some background in programming always helps though). Looking at other similar card's groovy should always be a best place to start.

With Luminarch Ascension, the main problem is trying to determine if you've lost life or not. At the moment, I don't think this is properly possible. It's not a simple comparison of life from the beginning of the turn to the end, as if you lost life during that turn then gained some back, it still shouldn't trigger.

Getting a copy of the repository so you can look through all the possible methods is good if you know your way around code (https://code.google.com/p/magarena/wiki/DeveloperInfo) Otherwise looking at existing cards and seeing how they work should give some ideas.

I don't mind doing a mini-tutorial, but there's something to be said for discovering and learning things yourself too :D

You can certainly put together a Luminarch-type card that doesn't have the life change requirement, ie:

At the beginning of each opponent's end step, you may put a quest counter on Willzer's Ascension.
{1} {W}: Put a 4/4 white Angel creature token with flying onto the battlefield. Activate this ability only if Willzer's Ascension has four or more quest counters on it.
Here's some cards you should look at the groovy code for, and the reasons why:

Sphinx Sovereign - End of turn trigger
Ebony Owl Netsuke - Each Opponent's
Bloodhall Ooze - You may put a counter on this
Greenhilt Trainee - Activated ability with a condition
Zektar Shrine Expedition - Quest counters and putting a token onto the battlefield

Hopefully that will give you some ideas, if not, let me know and I can go through things in more detail ;)

Good Luck!
User avatar
ShawnieBoy
Programmer
 
Posts: 601
Joined: 02 Apr 2012, 22:42
Location: UK
Has thanked: 80 times
Been thanked: 50 times

Re: need help implementing card

Postby Willzer » 05 Jun 2014, 16:12

thank you for this explanation, I'll try to make my own ascension as you said following the examples...
Willzer
 
Posts: 2
Joined: 05 Jun 2014, 14:53
Has thanked: 1 time
Been thanked: 0 time

Re: need help implementing card

Postby Lodici » 05 Jun 2014, 17:26

Willzer wrote:hello guys, i'm new in this program, sorry if this is not the place to ask but I'd like to add the card ''Luminarch Ascension'', I'm still preety confused about the groovy code, could someone help me?
Sounds like a pretty tough card to start with!

ShawnieBoy wrote:I don't mind doing a mini-tutorial, but there's something to be said for discovering and learning things yourself too :D
I think this an excellent idea. Groovy makes the scripting capabilities of Magarena very powerful and flexible but it is not exactly the most accessible of languages for someone just interested in implementing a card - I have no idea what @shawnieboy and @melvin are talking about most of the time :? and even when I look at the groovy stuff it seems a bit obscure.

How about creating a new sticky topic in this here forum which starting from the simplest groovy card, introduces a new mechanic, provides a sample card and then uses the "spoiler" feature to...
| Open
reveal the groovy answer for that card!
User avatar
Lodici
Programmer
 
Posts: 399
Joined: 13 Oct 2013, 09:44
Has thanked: 29 times
Been thanked: 71 times

Re: need help implementing card

Postby ShawnieBoy » 05 Jun 2014, 17:44

Lodici wrote:I think this an excellent idea. Groovy makes the scripting capabilities of Magarena very powerful and flexible but it is not exactly the most accessible of languages for someone just interested in implementing a card - I have no idea what @shawnieboy and @melvin are talking about most of the time :? and even when I look at the groovy stuff it seems a bit obscure.

How about creating a new sticky topic in this here forum which starting from the simplest groovy card, introduces a new mechanic, provides a sample card and then uses the "spoiler" feature to...
| Open
reveal the groovy answer for that card!
I'm all for doing that :) - with more of the cards being purely scriptable, the barrier of entry for groovy continues to climb. Sometime in the future, hopefully all the cards will be just scripts, and it's only a small step from groovy code to implementing code to the engine itself.

I'm far from being a groovy master (That'll be Melvin), but giving people a knowledge of the basics will definitely help.
User avatar
ShawnieBoy
Programmer
 
Posts: 601
Joined: 02 Apr 2012, 22:42
Location: UK
Has thanked: 80 times
Been thanked: 50 times

Re: need help implementing card

Postby ShawnieBoy » 10 Jun 2014, 13:18

First of all I apologize for the reference I gave for putting a token onto the battlefield, the reference I gave was for putting a token onto the battlefield with a play modification (like, "Sacrifice it at the end of turn").
Acorn Catapult would be a more helpful card to look at. It's acually a handy reference, it has:
    an activated ability involving tap and a mana cost,
    it deals damage to players or creatures - so you can see how to trim it down to effect only one,
    it also puts a token onto the battlefield - under someone elses control (potentially) so covers both targeting and ownership of tokens as well as...
    getting the token description for them.
All on a card that's not too busy to read.

Hopefully Willzer hasn't been put off, here's my take on Willzer's Ascension:
| Open
Code: Select all
def QUEST_4_OR_GREATER_CONDITION = new MagicCondition() {
    public boolean accept(final MagicSource source) {
        final MagicPermanent permanent = (MagicPermanent)source;
        return permanent.getCounters(MagicCounterType.Quest) >= 4;
    }
};

[
    new MagicAtEndOfTurnTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicPlayer eotPlayer) { 
            return permanent.isOpponent(eotPlayer) ?
                new MagicEvent(
                    permanent,
                    new MagicSimpleMayChoice(
                        MagicSimpleMayChoice.ADD_POS_COUNTER,
                        1,
                        MagicSimpleMayChoice.DEFAULT_YES
                    ),
                    this,
                    "PN may\$ put a quest counter on SN."
                ):
                MagicEvent.NONE;
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            if (event.isYes()){
                game.doAction(new MagicChangeCountersAction(event.getPermanent(), MagicCounterType.Quest,1,true));
            }
        }
    },
   
    new MagicPermanentActivation(
        [
            QUEST_4_OR_GREATER_CONDITION
        ],
        new MagicActivationHints(MagicTiming.Token),
        "Token"
    ) {

        @Override
        public Iterable<MagicEvent> getCostEvent(final MagicPermanent source) {
            return [new MagicPayManaCostEvent(source, "{1}{W}")];
        }

        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
            return new MagicEvent(
                source,
                this,
                "PN puts a 4/4 white Angel creature token with flying onto the battlefield."
            );
        }

        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            game.doAction(new MagicPlayTokenAction(
                    event.getPlayer(),
                    TokenCardDefinitions.get("4/4 white Angel creature token with flying")
                ));
        }
    }
]
And after including new HasGainedLife, HasLostLife player states, it's a small step to the actual card:
| Open
Code: Select all
def QUEST_4_OR_GREATER_CONDITION = new MagicCondition() {
    public boolean accept(final MagicSource source) {
        final MagicPermanent permanent = (MagicPermanent)source;
        return permanent.getCounters(MagicCounterType.Quest) >= 4;
    }
};

[
    new MagicAtEndOfTurnTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicPlayer eotPlayer) { 
            return permanent.isOpponent(eotPlayer) && !permanent.getController().hasState(MagicPlayerState.HasLostLife) ?
                new MagicEvent(
                    permanent,
                    new MagicSimpleMayChoice(
                        MagicSimpleMayChoice.ADD_POS_COUNTER,
                        1,
                        MagicSimpleMayChoice.DEFAULT_YES
                    ),
                    this,
                    "PN may\$ put a quest counter on SN."
                ):
                MagicEvent.NONE;
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            if (event.isYes()){
                game.doAction(new MagicChangeCountersAction(event.getPermanent(), MagicCounterType.Quest,1,true));
            }
        }
    },
   
    new MagicPermanentActivation(
        [
            QUEST_4_OR_GREATER_CONDITION
        ],
        new MagicActivationHints(MagicTiming.Token),
        "Token"
    ) {

        @Override
        public Iterable<MagicEvent> getCostEvent(final MagicPermanent source) {
            return [new MagicPayManaCostEvent(source, "{1}{W}")];
        }

        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
            return new MagicEvent(
                source,
                this,
                "PN puts a 4/4 white Angel creature token with flying onto the battlefield."
            );
        }

        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            game.doAction(new MagicPlayTokenAction(
                    event.getPlayer(),
                    TokenCardDefinitions.get("4/4 white Angel creature token with flying")
                ));
        }
    }
]
Bit technical for a 'my first card' though.

When I have a bit of time, I'll add some tutorials to the Wiki - it has a basic touch on groovy, but would be an easier reference than searching through a forum thread
User avatar
ShawnieBoy
Programmer
 
Posts: 601
Joined: 02 Apr 2012, 22:42
Location: UK
Has thanked: 80 times
Been thanked: 50 times


Return to Magarena

Who is online

Users browsing this forum: No registered users and 19 guests


Who is online

In total there are 19 users online :: 0 registered, 0 hidden and 19 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 19 guests

Login Form