Action system with XML

Started by
1 comment, last by SeanMiddleditch 9 years, 5 months ago

Hi,

I want all my different character actions to be read in by XML so i can easily balance things out and modify all those actions. I would like some feedback on what I have started. I will have some basic actions like attack, move, cast, etc but most of the skills will be a combination of those (like "Dash" and "Wound" in the example below).

Q: I would also like to incorporate some kind of formula. Like a cooldown is based on (X * weapon weight) or damage is based on (skill level * weapon damage) but i am not sure how to implement this.


<?xml version="1.0" encoding="UTF-8"?>
<actions>
    <ability>
        <name>Attack</name>
        <info>A regular melee attack with your main weapon.</info>
        <coodown>10</coodown>
        <action>
            <type>damage</type>
            <sort>mainWeapon</sort>
        </action>
    </ability>
    <ability>
        <name>Dash</name>
        <info>Dash forward to a target to hit him with greater impact.</info>
        <coodown>20</coodown>
        <action>
            <type>move</type>
            <location>target</location>
        </action>
        <action>
            <type>damage</type>
            <sort>mainWeapon</sort>
        </action>
    </ability>
    <ability>
        <name>Wound</name>
        <info>Inflicts a wound to your target.</info>
        <action>
            <type>damage</type>
            <sort>mainWeapon</sort>
        </action>
        <action>
            <type>dot</type>
            <element>physical</element>
        </action>
    </ability>
</actions>

I basically check for the type value and read XML accordingly. Q: Later i want to expand on this and i'm wondering if it is ok to to have different elements/nodes below these same types? Can i filter those out with something like:


if (action.GetChildByName("childThatMayOrMayNotExist"))
{
     //Do something if it exists!
}

For those formula's i can think of something hacky like below. But i am really looking for something more flexibel and of course compatible with LibGDX/Android if you recommend a library.


<first>weaponDamage</first>
<operator>*</operator>
<second>skillLevel</second>

Like i said, i would love to have some feedback from people with more experience.

Thank you,

Advertisement

Is using a scripting language an option? Yes, you could probably build a mini expression language in XML, but it would be a lot of work to be very flexible. Some scripting languages, like Lua, were actually designed as configuration languages first, which would make them a natural fit for something like this.

If you're going to build expressions in XML, at least keep it idiomatic. Aim for something that more closely matches an AST, e.g.

<mul><var>weaponDamage</var><var>skillLevel</var></mul>
That said, there's a middle ground between hardcoding and making them data-driven. You can pre-can some common calculations and select which one to use with the data. You can also just embed small snippets of Lua or the like in the XML rather than trying to express a script via XML itself.

Sean Middleditch – Game Systems Engineer – Join my team!

This topic is closed to new replies.

Advertisement