Loot/reward system by percentage

solved

(- Click for resources) #21

uhm or i don’t understand you or you don’t understand me.

i like the way .choices works so i want to keep it as is, i only want to grab the weight value out of the dict.

choices( list( chests_dict.keys() ), weight_value_from_that_key/dict_here ) 

so that i can get rid of

    chests = ['Common', 'Uncommon', 'Rare', 'Epic', 'Legendary', 'Wealthy']
    weights = [100, 50, 20, 10, 5, 3]

and purely use the data out of the dict.


(BluePrintRandom) #22

I was suggesting using a dict of dict, and storing all the data that way
also I was suggesting making all your choices in 1 shot to populate a list

this way as a choice is taken you can pop it,
this leads to the EXACT_distribution you plan

(it’s random in delivery but after 100 choices it’s exactly that rate)


(- Click for resources) #23

yes i get that, the thing you do here is just adding as much of the same item into a loot_list till it counts up to the percentage.

So 100 common, 50 uncommon, etc. then pop from the list till all loot has been given out in 150 turns.
But this is not the behavior i want/like. It needs to be random to get a chance to receive, not that after a while you are guaranteed to get it.

For actual loot out of the chest i will do this, but i don’t want it for the chest itself.


(Daedalus_MDW) #24

maybe enumerate() would help?


(edderkop) #25

you could do this.

chests = {'Common':100, 'Uncommon':50, 'Rare':20, 'Epic':10, 'Legendary':5, 'Wealthy':3}

out = Choices(list(chests.keys()),list(chests.values()))


(wkk.py) #26

I think you got to be careful with dicts, as the order is not guaranteed, I don’t even know if .keys() and .values() will spit in the same order, maybe just a matter of not having luck at one point…


(edderkop) #27

python3.6 have ordered dict so it should work.


(wkk.py) #28

https://stackoverflow.com/a/39980744/7983255

Indeed, good to know :slight_smile:

edit: @edderkop btw how one should order dicks? size?
r-edit: this was a joke as well.


(edderkop) #29

it is known as a spelling mistake.


(- Click for resources) #30

I don’t see the value in doing this, because we still have an separated dict. So i could just keep the 2 lists i have now.

I was hoping i could use it directly from within my current dict, but i can’t find a solution through google either, 1 dict deep there are, but 2 dicts deep nothing i can find.

It is also not a big deal to keep the two lists, but i thought that it would be nice to have all the chests info in one dict.

doesn’t that just add a counter to the value?


(edderkop) #31

it is to keep the 2 lists in sync.


(- Click for resources) #32

you saying that it can start at an other value then 0? list[0], etc?


(edderkop) #33

more like the length of the 2 list need to be the same, and by putting them in a dict it is guarantied, plus it is easier to tell what value goes to what item.


(- Click for resources) #34

Well i agree, it looks better in a dict and being able to directly see what value it has.


(wkk.py) #35

Does that solve your issue?


(- Click for resources) #36

Not really, the issue stays, because i can’t just put it all into one dict. If that was possible it would be great. I guess it’s not possible, so yes i can say it’s somewhat solved.


(edderkop) #37

is this what you are looking for ?

import random

chests = {'Common':{"w":100,"damage":10,"speed":5}, 'Uncommon':{"w":50,"damage":10,"speed":5}, 'Rare':{"w":20,"damage":10,"speed":5}, 'Epic':{"w":10,"damage":10,"speed":5}, 'Legendary':{"w":5,"damage":10,"speed":5}, 'Wealthy':{"w":3,"damage":10,"speed":5}}

def getloot(loottable):
    i = list(loottable)
    w = [loottable[x]["w"] for x in i]
    return random.choices(i,w)
   
loot = getloot(chests)
print(loot)

(- Click for resources) #38

You did it once again, yes that works perfectly. Thanks!

    i = list(chests)
    w = [chests[x]["weight"] for x in i]

(edderkop) #39

no problem :vulcan_salute:


(- Click for resources) #40

It really does work great!