开发者

Game Design: Data structures for Stackable Attributes (DFP, HP, MP, etc) in an RPG (VB.Net)

开发者 https://www.devze.com 2023-01-10 11:49 出处:网络
I\'m wrangling with issues regarding how character equipment and attributes are stored within my game.

I'm wrangling with issues regarding how character equipment and attributes are stored within my game.

My characters and equippable items 开发者_如何学Pythonhave 22 different total attributes (HP, MP, ATP, DFP). A character has their base-statistics and can equip up to four items at one time.

For example:

  • BASE ATP: 55
  • WEAPON ATP: 45
  • ARMOR1 ATP: -10
  • ARMOR2 ATP: -5
  • ARMOR3 ATP: 3

Final character ATP in this case would be 88.

I'm looking for a way to implement this in my code. Well, I already have this implemented but it isn't elegant. Right now, I have ClassA that stores these attributes in an array. Then, I have ClassB that takes five ClassA and will add up the values and return the final attribute.

However, I need to emphasize that this isn't an elegant solution.

There has to be some better way to access and manipulate these attributes, including data structures that I haven't thought of using. Any suggestions?


EDIT: I should note that there are some restrictions on these attributes that I need to be put in place. E.g., these are the baselines.

For instance, the character's own HP and MP cannot be more than the baseline and cannot be less than 0, whereas the ATP and MST can be. I also currently cannot enforce these constraints without hacking what I currently have :(


Make an enum called CharacterAttributes to hold each of STR, DEX, etc.

Make an Equipment class to represent any equippable item. This class will have a Dictionary which is a list of any stats modified by this equipment. For a sword that gives +10 damage, use Dictionary[CharacterAttributes.Damage] = 10. Magic items might influence more than one stat, so just add as many entries as you like.

The equipment class might also have an enum representing which inventory it slots to (Boots, Weapon, Helm).

Your Character class will have a List to represent current gear. It will also have a dictionary of CharacterAttributes just like the equipment class, which represents the character's base stats.

To calculate final stats, make a method in your Character class something like this:

int GetFinalAttribute(CharacterAttributes attribute)
{
    int x = baseStats[attribute];
    foreach (Equipment e in equipment)
    {
        if (e.StatModifiers[attribute] != null)
        {
            x += e.StatModifiers[attribute];
        }
    }

    // do bounds checking here, e.g. ensure non-negative numbers, max and min

    return x;
}

I know this is C# and your post was tagged VB.NET, but it should be easy to understand the method. I haven't tested this code so apologies if there's a syntax error or something.

0

精彩评论

暂无评论...
验证码 换一张
取 消