Implementing a basic ability...

If you have a question about the git repository and the code, or if you have code to propose then please post in this forum.
Do not post request here.
Post Reply
GammaPaladin
Posts: 4
Joined: Tue Jan 15, 2013 12:25 pm

Implementing a basic ability...

Post by GammaPaladin » Tue Jun 02, 2015 1:03 pm

So... There's a few cards I love that I've been hoping to see implemented for ages (As in years, literally), but it hasn't happened. Sooo... Since I'd already downloaded the latest master from github to compile anyway... I started hacking through the code to try and see if I could figure out how things work.

I think I've figured parts of it out, but I've clearly missed something, because I attempted to test with something simple (Which probably isn't), getting the Rhox Faithmender working.

So, in AllAbilities.h I added the following:

Code: Select all

class ALifeMultiply: public TriggeredAbility
{
	ALifeMultiply(GameObserver* observer, int _id, MTGCardInstance * _source, int _power = 1, int _toughness = 1) :
		TriggeredAbility(observer, _id, _source)
	{
	}
		
	int triggerOnEvent(WEvent * event)
	{
		if(WEventLife* le = dynamic_cast<WEventLife*>(event))
		{
			if (le->player == source->controller())
			{
				if (source->has(Constants::LIFEMULTIPLY))
				{
					return 0;
				}
				else
				{
					source->controller()->gainLife(le->amount);
					le->amount = le->amount * 2;
					return 1;
				}
			}
		}
		else
		{
			return 0;
		}
	}
};
And I changed the enum in MTGDefinitions.h to add my ability to the basic abilities, and incremented NB_BASIC_ABILITIES. Then in MTGDefinitions.cpp I added "lifemultiply" to Constants:MTGBasicAbilities.

And then obviously I added Rhox Faithmender to mtg.txt and removed it from unsupported.txt...

Code: Select all

[card]
name=Rhox Faithmender
abilities=lifelink,lifemultiply
text=Lifelink (Damage dealt by this creature also causes you to gain that much life.) -- If you would gain life, you gain twice that much life instead.
mana={3}{W}
type=Creature
subtype=Rhino Monk
power=1
toughness=5
[/card]
It all compiled and it runs without crashing, the card is available, and can be played, and works fine as just a simple 1/5 lifelink creature, but the ability I tried to add doesn't work... When I gain life, it isn't increased any. So, what (Probably incredibly obvious) thing have I missed?

I should note that I'm totally guessing at most of this, based on a couple hours of looking through the code.

Post Reply