简体   繁体   中英

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. I've hit a bit of a wall, however, when it comes to storing Class base stats. I've worked more extensively in Game Maker for a number of years, so my experience is more geared toward that. I'm currently working in C# with Monogame and wrapping my head around it.

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. 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.

The XML document I was designing (entirely by theory) is structured like so:

<?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! 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 :)

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.

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". Alternately, you would use LINQ.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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