如何在SQL中存储目标(想想RPG Quest)

Bas*_*sic 1 sql schema database-design

今天有人问我他们应该如何在SQL数据库中存储任务目标.在这种情况下,想一下RPG.目标可能包括以下部分内容:

  • 发现[位置]
  • 杀死[MOB类型]
  • 获取[对象]的n
  • 在[技能组]中实现[技能]
  • 你在RPG中获得的所有其他东西

我能想到的最好的是:

Quest 1-* QuestStep
QuestStep 1-* MobsToKill
QuestStep 1-* PlacesToFind
QuestStep 1-* ThingsToAcquire
QuestStep 1-* etc.
Run Code Online (Sandbox Code Playgroud)

这似乎有点笨重 - 他们应该存储一些描述的查询(或公式或???)

任何建议赞赏

Dam*_*vic 9

  • 用户可以开始执行许多任务.
  • 一个任务仅属于一个用户(在此模型中).
  • 一个任务有很多目标,一个目标只属于一个任务.
  • 每个目标都是可能的目标之一.
  • 可能的目标是允许动作和动作对象的组合.
  • PossibleGoals 表列出了所有允许的操作和对象组合.
  • 目标是StepNo在任务中排序的.
  • Quantity 定义动作应该对应的对象数量(杀死5个MOB).
  • Object 是所有可能对象的超类型.
  • Location,, MOBTypeSkill是对象子类型,每个子类型具有不同的属性(列).

替代文字


Pim*_*ger 6

我会创造这样的东西。

对于 Quest 表:

| ID | Title | FirstStep (Foreign key to GuestStep table) | etc.
Run Code Online (Sandbox Code Playgroud)

QuestStep 表

| ID | Title | Goal (Foreign key to Goal table) | NextStep (ID of next QuestStep) | etc.
Run Code Online (Sandbox Code Playgroud)

当然,这就是最困难的部分开始的地方,我们如何描述目标?我会说在 Goal 表中为目标创建一条记录,并将目标的每个字段(即要杀死多少个什么类型的生物、要访问什么位置等)保存在 GoalFields 表中,因此:

目标表:

| ID | Type (type is one from an Enum of goal types) |
Run Code Online (Sandbox Code Playgroud)

目标字段表

| ID | Goal (Foreign key to goal) | Field | Value |
Run Code Online (Sandbox Code Playgroud)

我知道这可能有点模糊,所以这里是数据库中的数据的一个示例。

任务表

| 0 | "Opening quest" | 0 | ...
| 1 | "Time for a Sword" | 2 | ...
Run Code Online (Sandbox Code Playgroud)

任务步骤表

| 0 | "Go to the castle" | 0 | 1 | ...
| 1 | "Kill two fireflies" | 1 | NULL | ...
| 2 | "Get a sword" | 2 | NULL | ...
Run Code Online (Sandbox Code Playgroud)

目标表

| 0 | PlacesToFind |
| 1 | MobsToKill |
| 2 | ThingsToAcquire |
Run Code Online (Sandbox Code Playgroud)

目标字段表

| 0 | 0 | Place | "Castle" |
| 1 | 1 | Type | "firefly" |
| 2 | 1 | Amount | 2 |
| 3 | 2 | Type | "sword" |
| 4 | 2 | Amount | 1 | 
Run Code Online (Sandbox Code Playgroud)