With an existing item system, how can I save and load data if it was modified? (2 Questions)

Ah- my bad. I somehow completely missed your rarity comment…

I would suggest something along these lines:

For the WeaponEntry struct, I’ve made something basic that just includes damage. It includes the base damage as well as an array of the minimum and maximum modification from your rarity.


With how it’s set up, rarity -1 is base stats so even the worst weapon will still have some variation, but you can change this by adding +1 to the rarity calculations.

With the way I’ve set up the following functions, this is additive.
IE if you had a setup like the following:


You could end up with 40 (base) → 34 (rarity 0, -20/+20) → 168 (rarity 1 -300/+400)
Of course you probably wouldn’t ever want to let the player get a -280, but that’s up to you- I just added really drastic numbers to showcase it.



This is all set up with just damage. You definitely want to make this a bit more generic. I’d recommend using a map with an enum key of the stats (Damage, Crit Chance, Bullet Multiplier, etc) with a value of a custom struct that holds a float array since you can’t directly put an array in a map.
That would end up looking something like this


You can then just loop through them when saving/loading
image



For the actual implementation, I’d recommend making a function to obscure it (This is just for damage implementation, but again you’ll probably want it more generic). I’ve gone ahead and made something simple separated into two parts.

The first part goes through to make sure that the array is populated enough. If you’re at rarity 4 but only have 2 lerps decided, you’ll want to have those filled out.
You may also want to make a custom pure function to replace RandomFloat. Maybe you’ll have some lucky modifier on the player or something and want to lean higher towards 1 during that specific upgrade.
image

The second part simply iterates through the rarities, checks what our lerp happens to be for each one, calculates the added damage using the min/max values for each rarity, and tallies them up combined with base damage.



The saving and loading is extremely simple:

EDIT [Still haven’t made this generic, but I’m going with the assumption that I have]:
I just realized you don’t necessarily want every stat to be upgraded every time. You may want to add a system to randomly weigh them. Maybe something like this:


And then right before updating the stats, do this (X is what the total will be- like 1 could end up with a 0.4 lerp for ammo and a 0.6 lerp for crit chance. With how I have it set up now, it’s also possible that it would choose the same thing to upgrade twice):

Replacing the RandomFloat node with this:

1 Like