RPG - 存储半复杂树结构的玩家数据 [英] RPG - storing player data for semi-complex tree structure

查看:101
本文介绍了RPG - 存储半复杂树结构的玩家数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在js中使用melon JS和SQL DB和PHP制作一个Web RPG。这个问题是关于如何存储每个非玩家角色(NPC)的已完成和当前任务。

I'm making a web RPG in js, using melon JS and SQL DB with PHP. This question is about how to store completed and current tasks per non-player character (NPC).

NPC对话框和任务数据:所有对话框存储在以下结构的js对象中:

NPC dialog and task data: all dialog is stored in a js object in the following structure:

var dialog = {
    quests : {
        quest1 : {  
            NPCName ("Joe"): {
                TaskName ("1 - Introductions") :  {
                     "english" : 
                      [
                          "Hello, here is some dialog",
                          "More dialog..." (stored in array so I can cycle through it)
                      ],//more items per task
                }, //more tasks per NPC
            }, //more NPCs per quest
        }, //more quests options per "quests"
    }, //more options in dialog besides "quests" if I want
};

将所有地图对话框存储在同一个文件中,因为文件会变得太混乱......所以相反:当地图发生变化时,我使用 js_require 加载一个新的 js 带有一组新对话框的文件:

I'm not storing all map dialogs in the same file because the file would get too cluttered... so instead: when the map changes, I use js_require to load in a new js file with a new set of dialog:

loadNpcDialog : function (dialogNumber) {
    require(["./dialog/npc_dialog_level_" + dialogNumber + ".js"], function(dialog) {
    });     
},

任务编号:当新的NPC是创建(类 game.NPCEntity ),我为每个NPC实例创建一个名为 taskNum 的局部变量,设置为0当他们完成任务时,我只是访问并增加NPC的任务编号:

task number: when a new NPC is created (class game.NPCEntity), I create a local variable per that instance of NPC called taskNum, set to 0. When they complete a task, I just access and increment that NPC's task number:

    game.player = me.game.getEntityByName(game.data.currNPC)[0];
    game.player.taskNum++;

对于此RPG,我想实现以下目标:


  • GTA式自由世界任务队列级别进展,任务进度和每个NPC进程的任务是线性的(完成1级转到2级等),但是对于每个Quest,都会生成一组NPC ...(你可以将它们视为子请求),每个NPC包含1到n个任务。我想建立任务队列灵活性,允许玩家以任何顺序与任何生成的NPC对话......并按线性顺序完成任务(任务1然后是2,然后是3 ......)。这就像GTA风格,因为整体游戏遵循线性进展,但通过与世界上随机的人交谈,您可以灵活地开始任何你想要的任务。

  • GTA-style free world quest queue: Level progression, Quest progression, and Task per NPC progression is linear (complete level 1 to go to level 2, etc), but for each Quest, a set of NPCs are generated... (you can think of them as subquests), each containing 1 through n tasks. I want to build in quest queue flexibility that allows the player to talk to any of the generated NPCs in any order... and complete the tasks in linear order (task 1 then 2, then 3...). This is like GTA style because the overall game follows a linear progression, but gives you the flexibility to start any quest you want by talking to random people in the world.

游戏数据游戏应该存储当前的已完成级别,每个级别的任务名称,每个任务的npc名称以及每个登录玩家ID的每个npc名称的任务。它应该加载以下树(红色=完整):

Game data: The game should store the current and completed level, quest names per level, npc names per quest, and tasks per npc name for each Logged In Player ID. It should load the following tree (red = complete):


  • 当游戏加载时,它应该记住我在上面树中提到的那些东西。我已经设置了DB以加载级别和任务信息(我只是从DB返回当前级别和任务数,然后循环显示上面显示的 NPC对话框结构 currentAndCompleteLevels currentAndCompleteQuests 数组中的值,直到循环达到当前级别并从DB获取任务数量)...以及玩家的坐标和经验...

  • When the game loads, it should remember those things I mentioned in the tree above. I've set up the DB to load level and quest information (I just return the current level and quest num from DB, then loop through the NPC dialog structure shown above storing the values in a currentAndCompleteLevels and currentAndCompleteQuests array up until the loop reaches the current level and quest num from DB)... as well as the player's coordinates and experience...

但是,因为我允许玩家开始,暂停,然后恢复任何时候任何NPC任务列表,我都无法真正添加 npc已完成num 任务已完成num 列到数据库。这是因为我无法循环遍历 NPC对话框结构并以与级别相同的方式加载任务信息,因为您完成NPC任务的顺序是非线性。不知何故,我必须跟踪每个NPC完成的任务数量。我怎样才能做到这一点?

However, since I'm allowing the player to start, pause, then resume any NPC task list at any time, I can't really add a npc completed num and tasks completed num column to the database. This is because I can't loop through the NPC dialog structure and load in the same way I do for level and quest information because the order in which you complete NPC quests is not linear. Somehow I have to track the completed task num per NPC. How can I do this?

我想创建一个新的 NPCData 表来存储游戏中的所有NPC,然后存储<$ c那个NPC的$ c>当前任务号 ...但是我必须为登录我游戏的新玩家创建一个新条目。

I was thinking of creating a new NPCData table to store all NPCs in the game, then store current task num for that NPC... but then I would have to create a new entry for any new player who logged into my game.

或者可以在 userstats 表中创建两个数据库列, currNPC currTask ,然后循环存储每个NPC的所有任务的关联数组?但是,我需要为每个完成的NPC和每个NPC完成的任务提供一个列。哦,我的头在旋转。

Or maybe create two DB columns in userstats table, currNPC and currTask, then loop through an associative array storing all tasks per NPC? But then I would need to have a column for each completed NPC and the completed tasks per NPC. Oy, my head is spinning.

当前数据库架构:

推荐答案

我认为这是用户和任务之间经典的多对多数据库关系,在这种情况下,我建议创建一个关系表 usertasks 。这里我将存储外键: id_user levelnum questnum

I suppose this is a classic many-to-many database relationship between user and task, in which case I would suggest creating a relationship table usertasks. Here I would store the foreign keys: id_user, levelnum, questnum.

我还要补充:


  • npcnum 这是该任务的NPC ID和

  • tasknum 这是任务的数量完成。

  • npcnum which is the NPC id for that quest and
  • tasknum which is the number of tasks complete.

所以subquest实际上会被 levelnum 识别出来, questnum npcnum 我们可以将其与 id_user

So a "subquest", would actually be identified by levelnum,questnum and npcnum and we can relate that to a user with id_user.

因此,您可以为加入 levelnum questnum 来自userstats,为当前时间点为用户完成每项任务的完成任务。

So you can load tasks done for a quest joining the levelnum and questnum from userstats to get the tasks done for each task for the current point in time for a user.

这是一个提出的SQL小提示关系表。

Here's an SQLfiddle of the proposed relationship table.

http:// sqlfiddle .com /#!2 / edea9 / 1

假设你只需要在内存中拥有当前的子请求,我们就可以了假设 levelnum questnum 将始终是当前的数字,从而得到一系列数字的进展。

Assuming you only need to have the current subquests in memory, we can store the progress with an array of numbers with the assumption that levelnum and questnum will always be the "current" one.

var tasks=[];
function progress_task(npcNum){
  tasks[npcNum] = tasks[npcNum] ? tasks[npcNum]+1 : 1;
}
function get_task(npcNum){
  return tasks[npcNum] || 0;
}

var currNPC=1;
progress_task(currNpc);   

使用usertasks的注意事项是你将拥有旧任务和关卡的条目,你就会结束您担心具有 NPCData 类型表,其中包含子请求*用户行数。如果这感觉很麻烦,那么另一个选择可能只是将javscript变量 tasks 转换为JSON并存储它,当你加载 userstats时再次加载它这可能是更简单的路线。

Caveats for having a usertasks is that you will have entries for the older quests and levels and you do end up with your worry of having an NPCData type table with subquests*users number of rows. If this feels messy, than another option perhaps is just to convert the javscript variable tasks to JSON and store that, loading it back again when you load userstats which perhaps is the simpler route.

这篇关于RPG - 存储半复杂树结构的玩家数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆