开发者

How to model multiple "uses" (e.g. weapon) for usable-inventory/object/items (e.g. katana) within a relational database

So I'm working on expanding the uses of items over at www.ninjawars.net, and I'm not exactly sure how to represent them flexibly in the relational database that we use.

I may be barking up the wrong tree, so feel free to make suggestions in other directions, but currently I'm thinking that each item should have relational "tags".

For example, a Katana is currently a row in the "items" database. To make it into a weapon, and a holdable thing, I was thinking that I would have a database of "traits", and a item_traits table that connects the two.

// Objects and their basic data

item_id | item | material | etc
1 | Naginata | steel | etc


// Things that objects can do

trait_id | trait
1 | weapon
2 | holdable

// How those objects do those things, e.g. powerfully, weakly, while on fire

_item_id | _trait_id | item_trait_data
1 | 1 | damage: 5, damage_type: sharp, whatever, etc

I'm not really sure how to model the extra data that results (e.g. the damage that a sword will do, the damage_type, etc).

I'm also not especially happy that the whole of an item would be stored in more than one place, e.g. in order to cre开发者_如何学运维ate a copy of an item with a different name, like a "short sword", I would have to copy from multiple tables to create the duplicate item.

Is there a better way to lay this stuff out that I'm missing?


Well, different kinds of weapons can share common feats.
For example, "sharp" weapons can include longswords, short swords, daggers, and katanas; they all could share similar base damage, plus a few extra special things that pertain to the actual weapon individually.
Similarly, "blunt" weapons can include hammers, maces, and flails.
So I think you should introduce the concept of a "weapon type", so you don't have to copy things for each weapon type.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜