RandyKnapp / ValheimMods

179 stars 137 forks source link

[BUG] DropTables calculation error #263

Closed dony22 closed 3 years ago

dony22 commented 3 years ago

Hello, while editing the Droptables to only drop epic and legendaries i noticed that something was wrong.. So for example sake:

"Object": "Tier5Mob", "LeveledLoot": [ { "Level": 1, "Drops": [ [0, 75], [1, 24], [2, 1] ], "Loot": [ { "Item": "Tier4Everything", "Weight": 1, "Rarity": [ 0, 0, 10, 1 ] } ] }"

 In My mind this would make 10% chance to drop a epic and 1% to drop a ledendary.. but happend is that they started to drop alot more legendary and epics. so i dig into the code and found this:

 ` float total = dropTable.Sum(x => x.Value);
            if (total > 0)
            {
                t.AppendLine($"> | Drops (lvl {level}) | Weight (Chance) |");
                t.AppendLine($"> | -- | -- |");
                foreach (var drop in dropTable)
                {
                    var count = drop.Key;
                    var value = drop.Value;
                    var percent = (value / total) * 100;
                    t.AppendLine($"> | {count} | {value} ({percent:0.#}%) |");
                }
            }
            t.AppendLine();

`

With this in mind if we apply the formula:

(total = 11) Epic chance =~91% Legendary chance =~ 9%

In summary the total count should have base 100 imo:

float total = dropTable.Sum(x => x.Value) > 100 ? dropTable.Sum(x => x.Value) : 100;

ZekeDP commented 3 years ago

Hi, if you want to drop it to 1% you need to make sure sum of all of the rarity value is 100 example: "Rarity": [ 0, 0, 99, 1 ]

this will drop to 99% epic, 1% legendary.

in your case the reason you get more legendary now is because 1/11 * 100 =9.09% chance of dropping now.

dony22 commented 3 years ago

i understand that, but.. what if. i want 0% magic 0% rares 10% epics and 1% legendary?

The idea behind this is to drop less bloat and more cool stuff. Drop less but when it drops ppl will get more satisfied. Thats why i say the calculations wrongly made.

ZekeDP commented 3 years ago

that doesn't make any sense.. all i can say if you want less drop.

just make it drop less in "Drops" field? you could do something like this: "Drops": [ [0, 25], [1, 40], [2, 20], [3, 10], [4, 5]],

then the rarity will do the if it's epic or legendary or whatnot.

dony22 commented 3 years ago

Thank you for your reply, i cant seem to find documentation regarding that "Drops": [ [0, 25], [1, 40], [2, 20], [3, 10], [4, 5]],

Can you explain to me what is 0, 25.. 1,40.. Is it 25% chance to drop 0 item?

ZekeDP commented 3 years ago

yes exactly like what you've said.

another example: [2,20] - means 2 item drop for 20% chance.

just make sure the total of chance is equal to 100% to make it accurate to 20% just like the rarity one.

dony22 commented 3 years ago

So if i use:

"Object": "Tier5Mob", "LeveledLoot": [ { "Level": 1, "Drops": [ [0, 90], [1, 10], ], "Loot": [ { "Item": "Tier4Everything", "Weight": 1, "Rarity": [ 0, 0, 90, 10 ] } ] }"

this would be 10% chance to drop 1 item, when it drops 9 out of 10 would be a epic and 1 out of 10 would be a legendary correct?

ZekeDP commented 3 years ago

Yes that is correct. 👍🏼

dony22 commented 3 years ago

Ok thank you so much for your help! Im going to close this as theres a work around but i still would belive that the line of code that i suggested would make sense to avoid further mistakes. as we are always talking about percebtage the total would always have a minimum of 100.

float total = dropTable.Sum(x => x.Value) >= 100 ? dropTable.Sum(x => x.Value) : 100;

dony22 commented 3 years ago

Im sorry but i must be doing something wrong.. I used the following settings:

// Tier 5 Mobs (Goblin, Deathsquito, Lox, Fenring, Stone Golem, Serpent) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// { "Object": "Tier5Mob", "LeveledLoot": [ { "Level": 1, "Drops": [ [0, 99], [1, 1] ], "Loot": [ { "Item": "Tier4Everything", "Weight": 1, "Rarity": [ 0, 0, 95, 5 ] } ] }, { "Level": 2, "Drops": [ [0, 95], [1, 5] ], "Loot": [ { "Item": "Tier4Everything", "Weight": 5, "Rarity": [ 0, 0, 90, 10 ] }, { "Item": "Tier5Everything", "Weight": 1, "Rarity": [ 0, 0, 90, 10 ] } ] }, { "Level": 3, "Drops": [ [0, 90], [1, 10] ], "Loot": [ { "Item": "Tier4Everything", "Weight": 3, "Rarity": [ 0, 0, 85, 15 ] }, { "Item": "Tier5Everything", "Weight": 1, "Rarity": [ 0, 0, 85, 15 ] } ] }, { "Level": 4, "Drops": [ [0, 87], [1, 12], [2, 1] ], "Loot": [ { "Item": "Tier4Everything", "Weight": 1, "Rarity": [ 0, 0, 85, 15 ] }, { "Item": "Tier5Everything", "Weight": 1, "Rarity": [ 0, 0, 85, 15 ] } ] }, { "Level": 5, "Drops": [ [0, 83], [1, 15], [2, 2] ], "Loot": [ { "Item": "Tier4Everything", "Weight": 1, "Rarity": [ 0, 0, 80, 20 ] }, { "Item": "Tier5Everything", "Weight": 5, "Rarity": [ 0, 0, 80, 20 ] } ] }, { "Level": 6, "Drops": [ [0, 80], [1, 17], [2, 3] ], "Loot": [ { "Item": "Tier4Everything", "Weight": 1, "Rarity": [ 0, 0, 75, 25 ] }, { "Item": "Tier5Everything", "Weight": 10, "Rarity": [ 0, 0, 75, 25 ] } ] } ] },

Went ahead and killed a camp of Fulings (about 30 mobs) and dropped about 20 epics and 4 legendaries..

So i believe the "Drops": [ [0, 95], [1, 5] ], either is not working properly or its not what we tought!

please advise.

RandyKnapp commented 3 years ago

To answer some previous questions, they are weights, not percentages. I do not require them to add up to 100.

I will look into why you're getting so many drops.

dony22 commented 3 years ago

Thanks please let me know, and share any toughts that we might debug together.

RandyKnapp commented 3 years ago

Can you please enable logging for the mod? Then reproduce the issue and send me your player log?

On Sun, Jun 13, 2021, 8:28 AM dony22 @.***> wrote:

Thanks please let me know, and share any toughts that we might debug together.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/RandyKnapp/ValheimMods/issues/263#issuecomment-860229011, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZNL4IX5N2TBOYADB45XLDTSTFBVANCNFSM46TUDS5Q .

dony22 commented 3 years ago

yes, ofcourse i can, if you want i can also stream on discord. Just made another test with the settings above devcommands god spawn Goblin 50 killall

Result: 10 epics 1 legendary

EDIT: Found de logging setting. will post soon.

dony22 commented 3 years ago

Here are the log with the same commands above

https://pastebin.com/3t6SXbjK

total of 14 drops.

here is the loottables.json https://pastebin.com/TPkVjZeY

RandyKnapp commented 3 years ago

Looking at the log, there were 70 goblins killed with no drops, and 30 killed with 1 drop. How close is that to the drops you set for level 1 goblins?

dony22 commented 3 years ago

hum?? ? for the 50 goblins i see all this drops in the logs

thats way more than 1

dony22 commented 3 years ago

if your using Ctrl + F and find "Rolling on loot table: Goblin (lvl 1), spawned 0 items at drop poin" = 70 hits (but in reallity is 35 due to duplicated log on raw)

if your using Ctrl + F and find "Rolling on loot table: Goblin (lvl 1), spawned 1 items at drop poin" = 30 hits (but in reallity is 15 due to duplicated log on raw)

so.. out of 50 goblins there was 15 drops.

RandyKnapp commented 3 years ago

I'm sorry, but if I do this locally, it looks correct:

      "Object": "Tier5Mob",
      "LeveledLoot": [
        {
          "Level": 1,
          "Drops": [ [0, 99], [1, 1], [2, 0] ],
          "Loot": [
            { "Item": "Tier4Everything", "Weight": 1, "Rarity": [ 0, 50, 49, 4 ] }
          ]
        },

And out of 100 goblins, it spawned one item: image

dony22 commented 3 years ago

Well, you must be doing something right that im missing and not having to do with the loottable perhaps. We could be here "it happens on my machine but not on your" type of thing. but you have facts and so do i :P I belive your a very busy man but if you could spare 5 min time hit me on discord: MagicPT#1092

Thank you for your time not only on this issue but on your mods that bring a new life to the game.

dony22 commented 3 years ago

So im making further testing, and without attaching to the process is dificuld for me.. but im lacking a bunch of dependencies... However.. it seems its not even working i changed to the following>

"Object": "Tier5Mob", "LeveledLoot": [ { "Level": 1, "Drops": [ [0, 9999], [1, 1] ], "Loot": [ { "Item": "Tier4Everything", "Weight": 1, "Rarity": [ 0, 0, 0, 100 ] } ] }

and i still have the same number of drops on the floor.. this time all legendary.

Because im from portugal i thought it could be something to do with decimal place, since i belive the code is not taking into considerarion InvariantCulture, but i changed to US Decimal place with no success.

dony22 commented 3 years ago

Got it! i found the problem!

Changed this: "Object": "Goblin", "LeveledLoot": [ { "Level": 1, "Drops": [ [0, 75], [1, 24], [2, 1] ], "Loot": [ { "Item": "Tier5Mob.1" } ] },

to this:

"Object": "Goblin", "LeveledLoot": [ { "Level": 1, "Drops": [ [0, 99], [1, 1] ], "Loot": [ { "Item": "Tier5Mob.1" } ] },

It worked.

So my question is: When and why is he using this drop by Goblin and not by :

"Object": "Tier5Mob", "LeveledLoot": [ { "Level": 1, "Drops": [ [0, 9999], [1, 1] ], "Loot": [ { "Item": "Tier4Everything", "Weight": 1, "Rarity": [ 0, 0, 95, 1 ] } ] },

is there a setting to change to which should it be using?