mercredi 10 août 2016

Writing a game: Dynamic attack logic in classes

I'm writing an RPG in C#, I have the character classes initialising nicely but I'm struggling with the attack classes.

Each attack will have its unique damage calculation formulas based off of multiple stats and eventually decorators.

Is there a way to dynamically create/append these damage formulas and decorators, or should I create a unique class for each attack that extends a generic attack class?

Here is some Pseudocode for what I'm after:

public class Attack
{
    public string Name {get; set;}
    List<Decorators> DamageCalc;

    public Attack(string[] data, List<Decorators> decorators)
    {
        Name = data[DataList.Name]; //I'm using constants to keep my indexes readable
        DamageCalc = data[DataList.Damage]; //i.e. strength * 10 + agility
        Decorators = decorators
        ApplyDecorators(Decorators)
    }

    public double DamageCalculation(Character attacker)
    {
        double strength = attacker.Strength;
        double agility = attacker.Agility;

        return DamageCalc; //Using the DamageCalc field and the above stats
    }

    ...

}

Flexibility to add new features and behaviours is of particular interest to me.

Many thanks for your input!

EDIT Where I to use JSON, would there be any simple way to relate JSON fields to my Character class's stat variables or do I need write custom code to interoperate it?

Off hand I can't think of a tidy way to use a JSON field, or any field for that matter, that can dynamically collect information from my Character class.

Aucun commentaire:

Enregistrer un commentaire