Triggered Abilities in Ability Factory
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins
23 posts
• Page 2 of 2 • 1, 2
Re: Triggered Abilities in Ability Factory
by friarsol » 15 Nov 2010, 22:02
To ease Rob's curiosity here's the code I put together to get this to work.Rob Cashwalker wrote:I'm curious how exactly the triggered ability you made worked... Is it like the Whenever keyword sort of triggered ability? If so, what triggers it?
Two key pieces missing from this code block are AbilityFactory's API call into the Trigger (which will return a null for the SA) and in CardFactory, before anything is done to the SA, checking if it's null and continue-ing the loop if so. Both of these are needed to prevent Null Pointer Errors.
Now onto the fun:
- Code: Select all
public static SpellAbility createTriggerGainLife(final AbilityFactory AF){
if (!AF.getMapParams().containsKey("Trigger"))
return null;
String sTrigger = AF.getMapParams().get("Trigger");
final Card host = AF.getHostCard();
final SpellAbility trGainLife = new Ability(host, "0"){
private static final long serialVersionUID = 6631124959690157874L;
final AbilityFactory af = AF;
final HashMap<String,String> params = af.getMapParams();
@Override
public String getStackDescription(){
// when getStackDesc is called, just build exactly what is happening
StringBuilder sb = new StringBuilder();
String name = host.getName();
int amount = calculateAmount(host, params.get("LifeAmount"), this);
String player = "You gain ";
if (af.getAbTgt() != null)
player = getTargetPlayer() + " gains ";
sb.append(name).append(" - ").append(player).append(amount).append(" life.");
return sb.toString();
}
@Override
public void resolve() {
int amount = calculateAmount(host, params.get("LifeAmount"), this);
gainLifeResolve(af, this, amount);
}
};
Command trAbility = new Command() {
private static final long serialVersionUID = -1537994957313929513L;
public void execute() {
trGainLife.setActivatingPlayer(host.getController());
AllZone.Stack.add(trGainLife);
}
};
if (sTrigger.equals("EntersBattlefield"))
host.addComesIntoPlayCommand(trAbility);
return null;
}
- Code: Select all
Name:Radiant's Dragoons
ManaCost:3 W
Types:Creature Human Soldier
Text:When Radiant's Dragoons enters the battlefield, you gain 5 life.
PT:2/5
K:Echo:3 W
A:TR$GainLife|Trigger$EntersBattlefield|LifeAmount$5
SVar:Rarity:Uncommon
SVar:Picture:http://www.wizards.com/global/images/magic/general/radiants_dragoons.jpg
End
It wouldn't be as global as some of things that Whenever does "When <type> enters the battlefield" but it can handle many of the simpler methods that take up space in CardFactories.
I can put the Python script back into my list of things to do. I've mostly been flagging down bugs from Phase and Targeting work, but it'd be good to stop looking at the same pieces of code for a bit.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Triggered Abilities in Ability Factory
by Sloth » 15 Nov 2010, 22:16
Well, EntersBattlefield alone would enable about a hundred new cards and all etb keywords as well as some whenever keyword cards could be converted. It would be quite an improvement.friarsol wrote:It wouldn't be as global as some of things that Whenever does "When <type> enters the battlefield" but it can handle many of the simpler methods that take up space in CardFactories.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Triggered Abilities in Ability Factory
by Sloth » 15 Nov 2010, 22:20
I'm not a native speaker, but I suggest "Deploy" for these abilities (like in Surprise Deployment).friarsol wrote:Cheat (or whatever other name we want to use) this would be for cards in your hand that are cheated into play. This is for cards like Sneak Attack or Elvish Piper.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Triggered Abilities in Ability Factory
by Chris H. » 15 Nov 2010, 22:59
`Sloth wrote:Well, EntersBattlefield alone would enable about a hundred new cards and all etb keywords as well as some whenever keyword cards could be converted. It would be quite an improvement.friarsol wrote:It wouldn't be as global as some of things that Whenever does "When <type> enters the battlefield" but it can handle many of the simpler methods that take up space in CardFactories.
This is starting to look very interesting. It would be nice to add the etb and ltb variants to the new AF's.
-

Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: Triggered Abilities in Ability Factory
by slapshot5 » 15 Nov 2010, 23:04
I think that's as good a name as any.Sloth wrote:I'm not a native speaker, but I suggest "Deploy" for these abilities (like in Surprise Deployment).
-slapshot5
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: Triggered Abilities in Ability Factory
by Rob Cashwalker » 15 Nov 2010, 23:28
I don't think handling "EntersTheBattlefield" or "LeavesTheBattlefield" individually for each AF is a good idea. I see "TriggeredAbility" as the base keyword, which then gets the actual Command from the AF, sorta like my theory of the SubAbility...This way of handling limits the trigger for things the card does. "When this enters the battlefield" "When this leaves the battlefield" for however many of these CommandLists we have or can create.
It wouldn't be as global as some of things that Whenever does "When <type> enters the battlefield" but it can handle many of the simpler methods that take up space in CardFactories.
The Force will be with you, Always.
-

Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: Triggered Abilities in Ability Factory
by friarsol » 16 Nov 2010, 00:09
.Rob Cashwalker wrote:I don't think handling "EntersTheBattlefield" or "LeavesTheBattlefield" individually for each AF is a good idea. I see "TriggeredAbility" as the base keyword, which then gets the actual Command from the AF, sorta like my theory of the SubAbility...This way of handling limits the trigger for things the card does. "When this enters the battlefield" "When this leaves the battlefield" for however many of these CommandLists we have or can create.
It wouldn't be as global as some of things that Whenever does "When <type> enters the battlefield" but it can handle many of the simpler methods that take up space in CardFactories.
I have strongly stated we should not do this now. This was mostly an experiment to see if I could do it and what it would take. There wasn't any major foresight, just experimentation. Once SubAbility is ready it probably would be easier to handle Triggers as a SubAbility.
I think we shouldn't try to rush every interesting idea through and make sure it makes sense before we get there. Another reason why I didn't want this done yet, was Ability_Trigger currently is a command, where it should be inheriting from Ability. I have this listed as an Issue for me right now, but I don't know when I'll be able to get around to it.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Triggered Abilities in Ability Factory
by zerker2000 » 17 Nov 2010, 20:26
Is SubAbility is intended to be an implementation of "effects"(MTG rules sense)?
If so, shouldn't they be called such?
If so, shouldn't they be called such?
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.
--Eladamri, the Seed of Freyalise
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.
--Eladamri, the Seed of Freyalise
- zerker2000
- Programmer
- Posts: 569
- Joined: 09 May 2009, 21:40
- Location: South Pasadena, CA
- Has thanked: 0 time
- Been thanked: 0 time
23 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 13 guests