Board index Programs with AI or Rules Enforcement Magic: The Gathering - Duels of the Planeswalkers Programming Talk
Embermaw Hellion Difficulties
Moderator: CCGHQ Admins
Embermaw Hellion Difficulties
by Xander9009 » 23 Aug 2015, 08:38
So, I've encountered another card that just doesn't seem to be nearly as simple as it should be. Embermaw Hellion is simply supposed to add 1 damage to any damage another red source you control would deal. However, thanks to a lack of any function to modify damage except to prevent it or multiply it, I first tried this:
2: (2+1)/2 = 3/2 = 1.5 -> 2*1.5 = 3
It continues to work like it should and I was hopeful. However, the Multiply function apparently only accepts integers, not floats, even if the resulting damage amount would still be an integer. So, it only works for 1 original damage (where it gets multiplied by 2). Any more damage and the multiplier is between 1 and 2. So, that method wouldn't work.
I decided to go with the code that seemed to work, and sure enough, in most situations, it does. It multiplies by the smallest number needed to ensure that at least enough damage is being dealt, and then it prevents any extra.
Cast Lightning Bolt with 4 Hellions, and it'll multiply by 3, and then it'll prevent 2, for a total of 7 damage (correct). If you have 1 Embermaw Hellion, it'll multiply by 2 and prevent 2, for the correct result of 4.
However, there's a flaw with this: some damage can't be prevented. An Embermaw Hellion and a Wild Slash results in 4 damage being dealt, not 3. Arrow Storm after attacking results in 10 rather than 6.
So, my friend thought of making it so that right before a source that can deal unpreventable damage deals any damage, it runs a function to check for any cards that add to the damage first and modifies the damage before dealing it. Anything that adds damage will exclude anything that has the ability to deal unpreventable damage.
My question is this: is there an easier or better way to do this so that Flaring Pain doesn't double all damage dealt when you have an Embermaw Hellion? There are 15 cards than can deal unpreventable damage (including Flaring Pain) and 4 that add to the amount of damage things deal. Embermaw Hellion is staying as it is for now, but I'd like to eventually fix this.
- Code: Select all
local Amount = Damage():GetAmount()
Damage():Multiply( (Amount+1)/Amount )
2: (2+1)/2 = 3/2 = 1.5 -> 2*1.5 = 3
It continues to work like it should and I was hopeful. However, the Multiply function apparently only accepts integers, not floats, even if the resulting damage amount would still be an integer. So, it only works for 1 original damage (where it gets multiplied by 2). Any more damage and the multiplier is between 1 and 2. So, that method wouldn't work.
I decided to go with the code that seemed to work, and sure enough, in most situations, it does. It multiplies by the smallest number needed to ensure that at least enough damage is being dealt, and then it prevents any extra.
Cast Lightning Bolt with 4 Hellions, and it'll multiply by 3, and then it'll prevent 2, for a total of 7 damage (correct). If you have 1 Embermaw Hellion, it'll multiply by 2 and prevent 2, for the correct result of 4.
However, there's a flaw with this: some damage can't be prevented. An Embermaw Hellion and a Wild Slash results in 4 damage being dealt, not 3. Arrow Storm after attacking results in 10 rather than 6.
So, my friend thought of making it so that right before a source that can deal unpreventable damage deals any damage, it runs a function to check for any cards that add to the damage first and modifies the damage before dealing it. Anything that adds damage will exclude anything that has the ability to deal unpreventable damage.
My question is this: is there an easier or better way to do this so that Flaring Pain doesn't double all damage dealt when you have an Embermaw Hellion? There are 15 cards than can deal unpreventable damage (including Flaring Pain) and 4 that add to the amount of damage things deal. Embermaw Hellion is staying as it is for now, but I'd like to eventually fix this.
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
-
Xander9009 - Programmer
- Posts: 2905
- Joined: 29 Jun 2013, 07:44
- Location: Indiana, United States
- Has thanked: 121 times
- Been thanked: 445 times
Re: Embermaw Hellion Difficulties
by RiiakShiNal » 23 Aug 2015, 23:43
There is not an easier way, but there is a better way. My recommendation would be to take the easier method in this case (meaning you can ignore the rest of this post unless you are curious).
- Better way | Open
- Unfortunately, the absolute best way to handle this would be to write a new damage dealing system then to have all cards use that system for dealing and/or modifying damage (preventing would remain the same), but this would essentially entail modifying all cards that deal damage (except through combat).
For example you write a new function:- Code: Select all
New_DealDamageTo = function(amount, target, source)
-- First standard checks to make sure things are valid:
if ((target == nil) or (source == nil) or (amount == nil) or (amount <= 0))
return
-- Here we check for any modifications to the amount such as with Embermaw Hellion
amount = New_CheckForDamageMods(amount)
-- Check to see that we still have damage to deal.
if (amount > 0) then
-- Now if we still have damage to do we will actually do the damage.
source:DealDamageTo(amount, target)
end
end
For example:- Code: Select all
EffectSourceLKI():DealDamageTo(1, player)
- Code: Select all
New_DealDamageTo(1, player, EffectSourceLKI())
Just getting started: Xander9009's DotP 2014 Community Wad
Need a deck builder: DotP 2014 Deck Builder
Problems Modding: DotP 2014 Frequent Modding Mistakes
Need a deck builder: DotP 2014 Deck Builder
Problems Modding: DotP 2014 Frequent Modding Mistakes
- RiiakShiNal
- Programmer
- Posts: 2185
- Joined: 16 May 2011, 21:37
- Has thanked: 75 times
- Been thanked: 497 times
Re: Embermaw Hellion Difficulties
by Xander9009 » 24 Aug 2015, 00:08
Alright. Then for now, I'll stick with the easier method. One hypothetical day in the future when my ambition overcomes my reason, I may attempt the better method.
_______________________________
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
Community Wad - Community Wad Website - How to Help and Report Bugs
Discord: discord.gg/4AXvHzW
-
Xander9009 - Programmer
- Posts: 2905
- Joined: 29 Jun 2013, 07:44
- Location: Indiana, United States
- Has thanked: 121 times
- Been thanked: 445 times
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 26 guests