如何对多个“用途”进行建模(例如武器)用于关系数据库中的可用库存/对象/物品(例如武士刀)
因此,我正在努力扩展 www.ninjawars.net 上的物品的用途,但我并不完全是这样确定如何在我们使用的关系数据库中灵活地表示它们。
我可能找错了方向,所以请随意在其他方向提出建议,但目前我认为每个项目都应该有相关的“标签”。
例如,Katana 当前是“items”数据库中的一行。为了将其变成武器和可握持的东西,我想我应该有一个“特征”数据库,以及一个连接两者的 item_traits 表。
// 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
我不太确定如何对产生的额外数据进行建模(例如剑会造成的伤害、damage_type 等)。
我也不是特别高兴整个项目将存储在多个地方,例如为了创建具有不同名称的项目的副本,例如“短剑”,我必须从多个表来创建重复项。
有没有更好的方法来放置我所缺少的这些东西?
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 create 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,不同种类的武器可以有共同的功绩。
例如,“锋利”武器可以包括长剑、短剑、匕首和武士刀;它们都可以共享相似的基础伤害,再加上一些与实际武器单独相关的额外特殊内容。
同样,“钝”武器可以包括锤子、狼牙棒和连枷。
所以我认为你应该引入“武器类型”的概念,这样你就不必为每种武器类型复制东西。
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.