Creating a Per-Character Level/XP System for Dynasty Warriors Style Game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CFR_Godot

Hi everyone!

I’m trying to put together an open source 2D Action Platformer framework titled OpenWarriors inspired by the gameplay of the Musou/Warriors games - idea being it provides a basis for others to make their own characters/levels for the framework and have them be loaded in and used together within the compiled releases through resource packs, much like MUGEN.

As the Dynasty Warriors games feature a per-character level/XP system I’m looking to try to put something like that in OpenWarriors but I’m not sure where to start or if it’d even be possible - my current theory is something like this:

Have a global Array variable called CharacterXP, which itself hosts a set of Arrays with the following format:

[CharacterName:String,Level:Int,CurrentXP:Int,DamageBonus:float,DefenceBonus:float]

Whenever we need to get any of these values, we check CharacterXP for a value that contains the character’s name and nab the appropriate value from there, creating a new entry in CharacterXP with appropriate starter values, e.g. [“character2”,1,0,1.0,1.0] if it doesn’t exist and returning the needed value if it does.

I understand there would be a lot involved in making this happen, there would need to be some way for each character to store which value in CharacterXP their stats are at to stop us having to do a costly search through the array every time we need their stats - I was just wondering if anyone knows if this would work or if there’s any better way of doing something like this?

:bust_in_silhouette: Reply From: Inces

This sounds like a very correct and optimal way of doing it.
I don’t understand what is supposed to be “costly” here ?
You don’t search dictionaries ( You mean dictionaries, not arrays, don’t You ? ) with find, but provide multiple hints and directions to get your value. I am using this kind of structure a lot and it is not slow.

You will propably need 2 kinds of dictionaries. One in autoloaded script, containing stable data, which is not supposed to change - like default stats values, stat growth per level per character, max stats.
Second one will be structured similarily, but contain dynamic data - current stats per current level. Every time your character will level up, you will use character name as key for both dictionaries, and add stats to 2nd dictionary by the values of 1st dictionary. Does that sound complicated ?

Ah, interesting!

I actually did mean Arrays, but I think that’s only because I didn’t know Dictionaries could be useful for this task - from reading the docs on it I got the impression Dictionaries could only assign words as being pseudonyms for values but now I feel I completely misinterpreted things.

I’ll have to look into this more - how would you personally lay out those two dictionaries you suggested in code?

Thanks a lot for your response! :smiley:

CFR_Godot | 2022-07-24 19:20

I see !
Dictionaries are perfect for task like these, because You can insert data in pairs of identifier : info. Identifier ( key ) can be any variable type, not just String. Also, dictionaries support other dictionaries as keys and values, enabling creation of huge data formats.

For example :

var stabledata = {
     {"Zangief" : 
          {"maxstats" : { "might" : 10.0, "speed" : 0.1,"jumpheight" : 2.0}},
          {"statsgrowthperlvl" : {"might" : 0.3,"speed":0.01,"jumpheight" :0,25}}
          {"startingstats" : { "might" : 2.0", "speed" : 0,1, "jumpheight" : 0.5}}
                      },
     {"Blanka" : 
          {"maxstats ....................
                      }
                                    }
var currentdata = {
        {"Zangief" : {"currentlevel" : 3, "might" : 2.9,"speed" : 0.13,"jumpheight" : 2.0},
        {"Blanka" : ................. 

And if You level character up You can make something like this :

on_character_levelup(charactername) :
        currentdata[charactername]["currentlevel"] += 1
       currentdata[charactername]["might"] += stabledata[charactername]["statsgrowthperlvl"]["might"]

       
       

Inces | 2022-07-24 20:21

Ooooh wow! This is a great starter for me, thanks a lot!

CFR_Godot | 2022-07-24 22:15