游戏中玩家与职业的数据库关系

发布于 2024-09-07 22:38:48 字数 188 浏览 4 评论 0原文

我试图弄清楚如何对一个标准化数据库进行建模,其中玩家可能有多个类别。玩家和类对象之间是什么关系?

每个玩家都可以拥有多个职业,每个职业也将授予玩家多种技能。我熟悉规范化数据库并使用它们,但还没有从头开始设置很多数据库,尤其是我自己。

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦欢 2024-09-14 22:38:48

这通常使用多对多关系的链接表来处理:

PlayerClass:
PlayerID
ClassID

通常使用 PlayerID,ClassID 为主键,PlayerID 和 ClassID 是对 Class 和 Player 表的外键引用。

通常,在许多设计中(尽管可能不是在您的设计中),这也会以其他方式索引(ClassID、PlayerID)。

您的技能表将类似地链接到一个类别:

ClassSkills:
ClassID
SkillID

现在这就是棘手的地方 - 如果玩家属于两个类别,每个类别都赋予相同的技能,会发生什么?它们是累加的还是合并的,或者什么?这是一个问题域问题,必须先解决该问题,然后才能将这些表简单地连接在一起并查看玩家拥有哪些技能。

This would normally be handled with a link table for a many-to-many relationship:

PlayerClass:
PlayerID
ClassID

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:

ClassSkills:
ClassID
SkillID

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.

月野兔 2024-09-14 22:38:48

这种关系将是多对多的。通常由中间表建模:

table Player:       Id int, name varchar(50)
table PlayerClass:  PlayerId int, ClassId int
table Class:        Id int, name varchar(50)

PlayerClass 表的两个列都应该有外键约束。

请注意,数据库对于游戏来说被认为太慢。大多数游戏都使用自定义存储机制。

The relationship would be many to many. Usually modeled by an in-between table:

table Player:       Id int, name varchar(50)
table PlayerClass:  PlayerId int, ClassId int
table Class:        Id int, name varchar(50)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文