游戏中玩家与职业的数据库关系
我试图弄清楚如何对一个标准化数据库进行建模,其中玩家可能有多个类别。玩家和类对象之间是什么关系?
每个玩家都可以拥有多个职业,每个职业也将授予玩家多种技能。我熟悉规范化数据库并使用它们,但还没有从头开始设置很多数据库,尤其是我自己。
我正在使用 MySQL 社区工具集,如果有人有方便的 EER 图/屏幕截图,他们也可以给我看:)
I'm attempting to figure out how to model a normalized database where a player may have multiple classes. What is the relationship between the player and the class objects?
Each player will be able to have multiple classes and each class will then grant a player multiple skills as well. I'm familiar with normalized database and working with them, but haven't set up a lot of them from scratch, especially not for myself.
I'm working with the MySQL community toolset if anyone has a handy EER diagram/screenshot they can show me as well :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这通常使用多对多关系的链接表来处理:
通常使用 PlayerID,ClassID 为主键,PlayerID 和 ClassID 是对 Class 和 Player 表的外键引用。
通常,在许多设计中(尽管可能不是在您的设计中),这也会以其他方式索引(ClassID、PlayerID)。
您的技能表将类似地链接到一个类别:
现在这就是棘手的地方 - 如果玩家属于两个类别,每个类别都赋予相同的技能,会发生什么?它们是累加的还是合并的,或者什么?这是一个问题域问题,必须先解决该问题,然后才能将这些表简单地连接在一起并查看玩家拥有哪些技能。
This would normally be handled with a link table for a many-to-many relationship:
Usually with PlayerID, ClassID being the primary key, and PlayerID and ClassID being foreign key references to your Class and Player tables.
Typically this will be indexed the other way as well (ClassID, PlayerID) in many designs (although possibly not in yours).
Your skills table would be similarly linked to a class:
Now here's where it gets tricky - what happens if a player is in two classes which each confer the same skill? Are they additive or are they merged, or what? This is a problem domain issue which would have to be resolved before you can simply join these tables all together and see what skills a player has.
这种关系将是多对多的。通常由中间表建模:
PlayerClass 表的两个列都应该有外键约束。
请注意,数据库对于游戏来说被认为太慢。大多数游戏都使用自定义存储机制。
The relationship would be many to many. Usually modeled by an in-between table:
The PlayerClass table should have a foreign key constraint on both its columns.
Note that databases are considered too slow for games. Most games use a custom storage mechanism.