简体   繁体   English

如何将XML用于RPG Stat / Leveling系统

[英]How to use XML for an RPG Stat/Leveling system

I'm looking at developing an RPG engine mostly for development experience, not really aiming for anything commercial. 我正在寻找开发RPG引擎主要是为了开发经验,而不是真正针对任何商业。 I've hit a bit of a wall, however, when it comes to storing Class base stats. 然而,当涉及到存储Class base stats时,我已经碰到了一点墙。 I've worked more extensively in Game Maker for a number of years, so my experience is more geared toward that. 我在Game Maker工作了很多年,所以我的经验更适合那个。 I'm currently working in C# with Monogame and wrapping my head around it. 我目前正在使用Monogame在C#中工作,并绕着它缠绕我的脑袋。

I believe a good method of storing the information I need will require external files, from what I have read. 我相信一种存储我需要的信息的好方法将需要外部文件,从我读过的内容。 I am used to calling and using INI files from GM, but have not had as much being able to wrap my head around XML. 我习惯于调用和使用GM的INI文件,但是没有那么多能够绕过XML。 I have a public pastebin of the setup I'm hoping to achieve, and was curious on your guys' take if such a setup is viable or if I'm trying to do this in some awful fashion. 我有一个我希望实现的设置的公共pastebin,并且如果这样的设置可行或者我想以某种可怕的方式尝试这样做,那么你很好奇。

The XML document I was designing (entirely by theory) is structured like so: 我正在设计的XML文档(完全通过理论)的结构如下:

<?xml version="1.0" encoding="utf-8" ?>
<BaseClass>
  <Class Class="Barbarian">
    <Level Level="1">
      <baseAtk>1</baseAtk>
      <baseFort>2</baseFort>
      <baseRef>0</baseRef>
      <baseWill>0</baseWill>
      <classSkillCt>2</classSkillCt>
      <classSkill0>ID_CS_BARB_FASTMOVE</classSkill0>
      <classSkill1>ID_CS_BARB_RAGE</classSkill1>
    </Level>
    <Level Level="2">
      <baseAtk>2</baseAtk>
      <baseFort>3</baseFort>
      <baseRef>0</baseRef>
      <baseWill>0</baseWill>
      <classSkillCt>2</classSkillCt>
      <classSkill0>ID_CS_BARB_UNCDODGE</classSkill0>
      <classSkill1>ID_CS_BARB_RAGEPWR1</classSkill1>
    </Level>
    <Level Level="3">
      <baseAtk>3</baseAtk>
      <baseFort>3</baseFort>
      <baseRef>1</baseRef>
      <baseWill>1</baseWill>
      <classSkillCt>1</classSkillCt>
      <classSkill0>ID_CS_BARB_TRAPSENSE1</classSkill0>
    </Level>
    <Level Level="4">
      <baseAtk>4</baseAtk>
      <baseFort>4</baseFort>
      <baseRef>1</baseRef>
      <baseWill>1</baseWill>
      <classSkillCt>1</classSkillCt>
      <classSkill0>ID_CS_BARB_RAGEPWR2</classSkill0>
    </Level>
    <Level Level="5">
      <baseAtk>5</baseAtk>
      <baseFort>4</baseFort>
      <baseRef>1</baseRef>
      <baseWill>1</baseWill>
      <classSkillCt>1</classSkillCt>
      <classSkill0>ID_CS_BARB_IMPUNCDODGE</classSkill0>
    </Level>
  </Class>
  <Class Class="Bard">
    <Level Level="1">
      <baseAtk>2</baseAtk>
      <baseFort>1</baseFort>
      <baseRef>3</baseRef>
      <baseWill>3</baseWill>
      <spellDay0>4</spellDay0>
      <spellDay1>1</spellDay1>
      <spellDay2>0</spellDay2>
      <spellDay3>0</spellDay3>
      <spellDay4>0</spellDay4>
      <spellDay5>0</spellDay5>
      <spellDay6>0</spellDay6>
      <spellDay7>0</spellDay7>
      <spellDay8>0</spellDay8>
      <spellDay9>0</spellDay9>
      <spellKnw0>6</spellKnw0>
      <spellKnw1>4</spellKnw1>
      <spellKnw2>0</spellKnw2>
      <spellKnw3>0</spellKnw3>
      <spellKnw4>0</spellKnw4>
      <spellKnw5>0</spellKnw5>
      <spellKnw6>0</spellKnw6>
      <spellKnw7>0</spellKnw7>
      <spellKnw8>0</spellKnw8>
      <spellKnw9>0</spellKnw9>
      <classSkillCt>6</classSkillCt>
      <classSkill0>ID_CL_SKILL_BRD_BRDKNOWLEDGE</classSkill0>
      <classSkill1>ID_CL_SKILL_BRD_BRDPERFORM</classSkill1>
      <classSkill2>ID_CL_SKILL_BRD_COUNTERSONG</classSkill2>
      <classSkill3>ID_CL_SKILL_BRD_DISTRACTION</classSkill3>
      <classSkill4>ID_CL_SKILL_BRD_FASCINATE</classSkill4>
      <classSkill5>ID_CL_SKILL_BRD_INSPCOURAGE1</classSkill5>
    </Level>
  </Class>
</BaseClass>

If this is not how XML documents work, please let me know so I'm not screwing the pooch on this one! 如果这不是XML文档的工作原理,请告诉我,所以我不会把这个狗搞砸! I'm not looking for anyone to write the code for me, just for open suggestions on what would be the best way to achieve what I'm looking for. 我不是在寻找任何人为我编写代码,只是为了获得有关实现我正在寻找的最佳方法的公开建议。 I'd like to be able to somehow get the base stats of any class at any level I request. 我希望能够以某种方式获得我要求的任何级别的任何级别的基本统计数据。 So if I were to request (Barbarian,2) or something of that nature, I'd get the information for a level 2 barbarian :) 所以如果我要求(野蛮人,2)或那种性质的东西,我会获得2级野蛮人的信息:)

I've tried to follow a number of tutorials online, but have not yet found one that has really explained the best way to utilize any external files in a way that makes sense. 我曾尝试在线跟踪一些教程,但还没有找到一个真正解释了以有意义的方式利用任何外部文件的最佳方法的教程。 If anyone has suggested materials on this kind of information, please let me know! 如果有人就这类信息提供了材料,请告诉我!

Your XML is fine, though maybe the BaseClass element should be plural and should agree with its content elements ("Classes") which are just Class. 你的XML很好,虽然BaseClass元素可能是复数,并且应该与它的内容元素(“Classes”)一致,它们只是Class。

For extracting, for instance, the base attack bonus for a level 2 barbarian you would use an XPath expression of the form "./BaseClass/Class[@Class='Barbarian']/Level[@Level='2']/baseAtk". 例如,为了提取2级野蛮人的基本攻击加值,您将使用“./BaseClass/Class[@Class='Barbarian']/Level[@Level='2']/baseAtk”形式的XPath表达式。 ”。 Alternately, you would use LINQ. 或者,您将使用LINQ。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM