ThemsAllTook
|
|
« Reply #1 on: February 09, 2022, 08:18:34 AM » |
|
I designed a system like this a little while ago. It's gone through a few iterations and might not be 100% done yet, but where I've landed right now is a data structure for each item that has these properties:
- Display info (name, icon, description, etc.) - List of required stats to be able to use (minimum strength value for a heavy weapon, etc.; can be an empty list) - Valid slots to equip ("hand" for a sword, "chest" for a tunic, "item" for a potion, etc.; can have multiple valid slots like "hand 1", "hand 2", and only one piece of equipment can be in each slot) - Stat bonuses granted while equipped (+ attack power for weapon, + defense for armor, empty list for a consumable) - Combat abilities granted while equipped, with a maximum use count for each (a weapon might grant an unlimited-use special attack; a potion might have 3 charges of invoking a healing ability before being depleted)
A separate data structure describes the abilities that are granted by having something equipped (or in the case of my game, may be innately usable by a character or granted through other means):
- Display info (name, visual/sound effects, etc.) - Resource cost (3 mana to cast a heal spell, etc.; can be an empty list) - Valid targets (self, ally, enemy, single/multiple) - Effect on target. This is where it gets interesting. Each ability can be of type "change resource", "apply status", "remove status", or "compound", which is a list of one or more of the other three types for items that do multiple things at the same time.
Most abilities are of type "change resource", which identifies a target resource type (health, mana, stamina, etc.) and a formula for how to change it. Can be a positive or negative change. I built a pretty robust pseudo-scripting system that can describe stuff like "take the actor's strength stat, subtract the target's defense stat, clamp that to a value of zero or above, and subtract it from the target's health resource". A formula evaluator takes the ability's effect description and the actor and target data structures, reads the relevant values from them, and applies a change to the target's state described by the evaluated outcome of the formula.
It works pretty well, and I haven't found it too cumbersome to work with in my scenario editor. There are some unusual things about how my system works; for example, I have no true consumables, so if you own a potion and use it in combat, you'll end up with the same potion recharged and able to be used again in the next encounter. I also designed the formula system so that it could automatically print out a human-readable description of exactly what each thing does, so the player has complete information about the algorithms used.
|