PDA

View Full Version : Existing function parse through Damage types, ie 2d6 heat



MadBeardMan
July 9th, 2017, 13:34
Afternoon Folks,

Been banging on with WOIN recently, trying to sign off all the loose ends, niggles and caveats.

One on my list is this.

Within the NPC section, we you add 'attack actions' you have a damage box, in that you can put in 3d6 slashing, 2d6 ion, 2d6 cold etc.

Here's a screeny of the CT with a few NPC's added.

19750

What I'm after is pulling the 'Damage Type' from the damage string, ie 'slashing', 'ion', 'cold' from my earlier examples.

I know I can iterate through the field and work this out myself, but wondering if there's an official function that does this.

Cheers
Colin

Trenloe
July 9th, 2017, 16:15
See the various functions in the UTILITY FUNCTIONS section of the 5E scripts\manager_action_damage.lua file.

MadBeardMan
July 9th, 2017, 16:21
I have, there's not one that does this, so I'm writing one myself.

Cheers

Trenloe
July 9th, 2017, 16:36
Then I'm confused what you're trying to do (and when). Can you provide more information on when (i.e. which event) you're trying to extract the damage type, and what format the data is in at that point?

MadBeardMan
July 9th, 2017, 16:42
The 'damage' string is '2d6 heat'.

All I want is the 'heat' word from that string. This is so I can populate the 'dmgtype' property with this.

So what I've done is add a new method to the ActionDamage class to do this, it's very crude as it steps through all the words and returns the last word.

Trenloe
July 9th, 2017, 16:47
So, the "when" I mentioned is when damage is being rolled - as part of the damage action?

Trenloe
July 9th, 2017, 17:03
Have a look at the 5E scripts\manager_combat2.lua file. The function parseAttackLine parses the data in the CT attack line. The section of code beginning elseif sAbility:sub(1,4) == "DMG:" and #sAbility > 4 then sets up the damage clause, which includes aClause.dmgtype

Hope that's what you're looking for.

MadBeardMan
July 9th, 2017, 17:08
That function does far more than what I need as it looks for Abilities to add bonuses etc etc.

WOiN is built right on top of CoreRPG but in places I've borrowed from 5E. I've got all the basics of combat working now I'm onto the 'awkward' bits....

Cheers for the replies chap.

Trenloe
July 9th, 2017, 17:37
That function does far more than what I need as it looks for Abilities to add bonuses etc etc.
You can ignore the stuff you don't want. There's a section that adds a clause LUA table (aClause) that has three entries: .dice (the damage dice to roll), .modifier (the modifier to apply to the damage roll) and .dmgtype (the damage types to apply to the roll - which is what you're looking for).


local aDmgType = {};
while aPowerWords[i+1] and not StringManager.isDiceString(aPowerWords[i+1]) and not StringManager.isWord(aPowerWords[i+1], {"and", "plus"}) do
table.insert(aDmgType, aPowerWords[i+1]);
i = i + 1;
end
aClause.dmgtype = table.concat(aDmgType, ",");

This strips out the dice string plus any "and" or "plus" entries in the attack string and gives the remaining damage types in the aDmgType table. The table entries are then concatenated together. In your two screenshots in post #1: 2d6+5 desiccation and 2d6 heat this would result in aClause.dmgtype being "desiccation" and "heat", respectively. You'd just need to set aPowerWords using the damage string, e.g. local aPowerWords = StringManager.parseWords(sDamage); and step through the power words - this is all in the section of code I've previously referenced.

MadBeardMan
July 9th, 2017, 17:50
Cheers for letting me know, I'm a coder who prefers nice and clean functions/methods, sometimes best to call a method that does 1 thing, but as that does more than 1 I might look into using it to parse the full string rather than like this:


local sDamage = damage.getValue();
local aDice, nMod = StringManager.convertStringToDice(sDamage);
local sDmgType = ActionDamage.getDamageType(sDamage);