It is currently 27 Apr 2024, 17:00
   
Text Size

Help implementing a card

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

Re: Help implementing a card

Postby Doctor Weird » 01 Mar 2016, 13:51

escplan9 wrote:So perhaps I misunderstand the "then" clause. As DoctorWeird mentioned, I should be able to react after the first part of the effect is done, before the "then" clause. For instance, I'll try to use an activated ability of Nantuko Husk after Scion creates a token, but before the then clause of populating. I'm unable to and am forced to choose a token to populate.
Just having a quick look at your posts and I should mention that you're getting what I said wrong. Go back and read what I said one more time. Basically, when a card says "do X and then Y" it's still all part of one effect and ability, with no pause in between.

Doctor Weird wrote:
| Open
And you absolutely do want to make sure the ability is done correctly, as in not making it two different effects going separately on the stack. Not only because that is how the rules demand it ("then" in card's rule texts means you do the next action after the previous but never with any other thing happening in between)

To put it in other terms, Cacodemon's ability should be only one instance showing up on the stack, not two separate ones for destroying and then tapping. No player should be able to play or respond in any way between the destroying and the tapping. Let's say the Cacodemon destroyed creatures that have abilities that trigger on death, like Abyssal Gatekeeper; The Gatekeeper's ability would only show up on the stack after the Cacodemon had already tapped the creatures too. The ability is all done in one go.

Think of it the same way as cards that let you search your library for something, they all say "(...)put it into your hand. Then shuffle your library." This simply means you shuffle after searching (obviously), but it doesn't mean that anything can be played in between searching and shuffling, right? Otherwise why wouldn't people search for a card with a Demonic Tutor and then use an Ancestral Recall to draw three cards they left on top of their deck before being forced to shuffle?

To recap:
  • Cast Dread Cacodemon
  • Dread Cacodemon successfully resolves and enters the battlefield
  • Dread Cacodemon's ETB ability triggers and goes on the stack (one single instance on the stack, not two) IF it was cast from hand. If it was not then the ability will not even trigger at all.
  • "When Dread Cacodemon enters the battlefield, if you cast it from your hand, destroy all creatures your opponents control, then tap all other creatures you control." is now on the stack and the active player receives priority to play spells or abilities, followed by the other players, as normal.
  • Once anything that might have been played in response to the ETB trigger resolves the Cacodemon's ability is now finally going to happen and all creatures you don't control die and the ones you do control that are not the Dread Cacodemon that triggered this ability are tapped, no breaks here.
Doctor Weird
 
Posts: 180
Joined: 25 May 2015, 01:33
Has thanked: 7 times
Been thanked: 52 times

Re: Help implementing a card

Postby escplan9 » 01 Mar 2016, 14:02

Thanks for clarifying DoctorWeird. I originally misunderstood you when you gave the example of a situation where someone could respond to the triggers - I thought you meant that was how the card was supposed to work, not that I should make sure the card is programmed correctly to avoid such a situation. I later realized my folly.

The card as is now is programmed to have the effects be immediate - both effects occur immediately one after the other without allowing a response (when cast from hand of course).
escplan9
 
Posts: 257
Joined: 10 Aug 2015, 22:38
Has thanked: 26 times
Been thanked: 40 times

Re: Help implementing a card

Postby LevelX » 01 Mar 2016, 14:51

I fixed Scion of Vitu-Ghazi to work now as intended.

Dread Cacodemon shoul be coded basically as I suggested (like Scion of Vitu-Ghazi is coded now) because as already pointed out it has an intervening if-clause. If there are other cards with an intervening if-clause that check the condition on effect level, then they are not implemented correctly and have to be corrected.

If it should not work that way, there are probably problems with other classes (e.g. the condition) that we have to look into then.
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Help implementing a card

Postby escplan9 » 01 Mar 2016, 22:43

Thanks for all the help everyone. I created a separate pull request for the new implementation using the proper function ConditionalTriggeredAbility. Tested fine - does not even trigger when not cast from hand. Only triggers on cast from hand as expected now. I might have my first contribution done! :shock:
escplan9
 
Posts: 257
Joined: 10 Aug 2015, 22:38
Has thanked: 26 times
Been thanked: 40 times

Re: Help implementing a card

Postby escplan9 » 02 Mar 2016, 16:13

I might try to work on the card Standard Bearer next (I sometimes play Pauper, and this is a staple in W/x tokens decks there). It'll probably be a big headache to figure out. Anyone know of other cards with somewhat similar effects? When it is on the battlefield it needs to be able to catch whenever the opponent casts a spell or activates an ability than can target Standard Bearer. I can't think of any cards off the top of my head with a similar effect for a starting point.
escplan9
 
Posts: 257
Joined: 10 Aug 2015, 22:38
Has thanked: 26 times
Been thanked: 40 times

Re: Help implementing a card

Postby LevelX » 02 Mar 2016, 16:26

escplan9 wrote:I might try to work on the card Standard Bearer next (I sometimes play Pauper, and this is a staple in W/x tokens decks there). It'll probably be a big headache to figure out. Anyone know of other cards with somewhat similar effects? When it is on the battlefield it needs to be able to catch whenever the opponent casts a spell or activates an ability than can target Standard Bearer. I can't think of any cards off the top of my head with a similar effect for a starting point.
Not that simple.

Hmm I would probably implement it as an continuous rule changing effect (not sure if that would be correct) that sets some general target rules to the State (or Game) class that have to be checked and if needed -executed- by all target actions the rules fit to.
A complete new mechanism.

So maybe it's helpful for you to get some more practice by doing first some simpler cards to get more experience with all the existing main framework classes and different existing structures and more quick wins. :D
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Help implementing a card

Postby escplan9 » 02 Mar 2016, 16:38

:lol: I was thinking it probably would be too much of a huge jump. Can I have access to the Card Tracking Tool by the way?
escplan9
 
Posts: 257
Joined: 10 Aug 2015, 22:38
Has thanked: 26 times
Been thanked: 40 times

Re: Help implementing a card

Postby djbrez » 03 Mar 2016, 05:19

I just started working on one of my old favorites, 'Uncle Istvan'. I've been combing through implemented cards, trying to find a class that does his effect, but it's a subtle twist, where damage is prevented only to this card when dealt by creatures.

I got it somewhat working by using a Protection effect and filtering creature, but I don't think that actually captures what his effect does correctly.

any suggestions on how to properly extend one of the existing DamageToSource classes that will filter by cardtype/creature? I am still learning Java, and I think someone more versed than me could do this in seconds :)

I'm having a blast going through cards and making them work...

thanks!
Don
djbrez
 
Posts: 3
Joined: 14 Feb 2016, 20:57
Has thanked: 0 time
Been thanked: 1 time

Re: Help implementing a card

Postby escplan9 » 04 Mar 2016, 10:36

djbrez wrote:I just started working on one of my old favorites, 'Uncle Istvan'. I've been combing through implemented cards, trying to find a class that does his effect, but it's a subtle twist, where damage is prevented only to this card when dealt by creatures.

I got it somewhat working by using a Protection effect and filtering creature, but I don't think that actually captures what his effect does correctly.

any suggestions on how to properly extend one of the existing DamageToSource classes that will filter by cardtype/creature? I am still learning Java, and I think someone more versed than me could do this in seconds :)

I'm having a blast going through cards and making them work...

thanks!
Don
What I like to do is use gatherer.wizards.com advanced search to find similar cards. For instance I put in rules text to search for "prevent all damage" "by creatures" and results are at link below:

Code: Select all
http://gatherer.wizards.com/Pages/Search/Default.aspx?action=advanced&text=+[%22prevent%20all%20damage%22]+[%22by%20creatures%22]
Uncle Istvan is amongst those cards as you'll see. Check out the other similar cards there and how they are implemented in XMage.

For instance, Ethereal Haze uses this for a similar effect:
Code: Select all
this.getSpellAbility().addEffect(new PreventAllDamageByAllEffect(new FilterCreaturePermanent("creatures"), Duration.EndOfTurn, false));
escplan9
 
Posts: 257
Joined: 10 Aug 2015, 22:38
Has thanked: 26 times
Been thanked: 40 times

Re: Help implementing a card

Postby LevelX » 04 Mar 2016, 11:52

escplan9 wrote:What I like to do is use gatherer.wizards.com advanced search to find similar cards. For instance I put in rules text to search for "prevent all damage" "by creatures"
You can do that also on http://ct-magefree.rhcloud.com/ with the advantage of only getting the in xmage implemented cards.
Enter e.g. simply "prevent all damage % by creatures" into the "Rules Text" filter settings.
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Help implementing a card

Postby escplan9 » 04 Mar 2016, 13:20

Good to know, thanks. I'll have to use it that way more often.

In other news...

So I was starting to work on the card Drake Familiar as recently requested. I looked up similar cards such as Glint Hawk and Faerie Impostor and was able to code it to work similarly. However, I double checked the rulings since none of these cards allowed the option of NOT selecting the permanent requested to simply sacrifice the creature. I created a bug report for those two cards.

I wanted to add tests for these conditions on Glint Hawk and Faerie Impostor, but I'm not sure if I can even test these scenarios (the option to not select anything) with the cards as they are currently programmed. Here is what I was thinking for test to not select anything:

Code: Select all
        addCard(Zone.BATTLEFIELD, playerA, "Plains", 2);
        addCard(Zone.HAND, playerA, "Glint Hawk");
        addCard(Zone.BATTLEFIELD, playerA, "Relic of Progenitus");

        castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Glint Hawk");
        addTarget(playerA, ""); // do not select anything

        setStopAt(1, PhaseStep.BEGIN_COMBAT);
        execute();

        assertPermanentCount(playerA, "Glint Hawk", 0);
        assertGraveyardCount(playerA, "Glint Hawk", 1);
        assertHandCount(playerA, "Relic of Progenitus", 0);
        assertPermanentCount(playerA, "Relic of Progenitus", 1);
Not sure on if I can use addTarget and not select anything. Should be I using something different in place of addTarget for this test? Or a different parameter?
escplan9
 
Posts: 257
Joined: 10 Aug 2015, 22:38
Has thanked: 26 times
Been thanked: 40 times

Re: Help implementing a card

Postby escplan9 » 04 Mar 2016, 13:40

Also, can someone clarify what the Outcome enum's purpose is? Does it matter what option I select for it? Or is it just for descriptive purposes?

Like in terms of Faerie Impostor , I see:
Code: Select all
    FaerieImpostorEffect() {
        super(Outcome.ReturnToHand);
        staticText = effectText;
    }
and later

Code: Select all
     if (target.canChoose(controller.getId(), game)) {
             controller.choose(Outcome.ReturnToHand, target, source.getSourceId(), game);
             ...
Would it matter if say this was Outcome.Neutral instead? (And what is Outcome.Neutral anyways? Outcome.Benefit, etc as well) Or any of the other Outcome enumerations? I'm not seeing where anything in the code really cares about what the Outcome is, but I see it as parameters often.
escplan9
 
Posts: 257
Joined: 10 Aug 2015, 22:38
Has thanked: 26 times
Been thanked: 40 times

Re: Help implementing a card

Postby LevelX » 04 Mar 2016, 14:18

escplan9 wrote:Also, can someone clarify what the Outcome enum's purpose is? Does it matter what option I
It's used by the AI to decide if an effect should be used or not used and what should be targeted with the effect (own or opponents objects). So it does play some role.

I guess is was at some point in the past planed to use more than the good/bad categorization of the outcome attribute. But as fas as I know that's all what's used until today.
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Help implementing a card

Postby LevelX » 04 Mar 2016, 14:20

escplan9 wrote:Not sure on if I can use addTarget and not select anything. Should be I using something different in place of addTarget for this test? Or a different parameter?
This won't work.

We have to fix the cards so the user gets an request if he likes to pay the cost. So you can set the choice for the test script.
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Help implementing a card

Postby escplan9 » 04 Mar 2016, 15:06

To fix those cards... looks like all that may be needed is one parameter change:

Code: Select all
    public boolean apply(Game game, Ability source) {
     ...
            TargetPermanent target = new TargetPermanent(1, 1, filter, true);
Previously was (1,1,filter,false) for
Code: Select all
public TargetPermanent(int minNumTargets, int maxNumTargets, FilterPermanent filter, boolean notTarget)
Although I see many other cards (like Plant Elemental - Portal) are programmed using "SacrificeSourceUnlessPaysEffect" instead of overriding the apply function like Glint Hawk and Faerie Impostor does so perhaps that's the way to go for simplification and consistency.

edit:

I see another area that's different. Compare Quickling to Glint Hawk and you'll also see
Code: Select all
if (target.canChoose(controller.getId(), game) && controller.chooseUse(outcome, "Return another creature you control to its owner's hand?", source, game))
escplan9
 
Posts: 257
Joined: 10 Aug 2015, 22:38
Has thanked: 26 times
Been thanked: 40 times

PreviousNext

Return to Developers Talk

Who is online

Users browsing this forum: No registered users and 8 guests


Who is online

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

Login Form