Biased Random Enchantment?

Discussion in 'Plugin Development' started by Burnout Ben, Feb 2, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    Burnout Ben

    I'm trying to make a plugin where you can pay to enchant items. It will have a price cap at 100k and I want to make it so the more money you pay, the more likely you are to get a better enchant (because of the money cap I can turn it into a percentage with (moneyPaid / 100000) * 100)

    How can I make it more likely to get say Efficiency 4 or 5 (just better enchantments overall) over Efficiency 1 if I pay more money?

    I want it to be like the Minecraft enchants (the higher the level you enchant, the better enchants that you get) but instead of using levels I'm going to use the Vault API to use money instead.

    I was thinking about making a dictionary type thing where I list all enchantments there and ranges for them. So if the money percentage is say between 5 and 25 you get a list of all enchantments in that range from the dict then I just get a random one of those but I'm sure there is a better method.
    Any ideas?
     
  2. Offline

    Chr0mosom3

    @Burnout Ben, I don't fully understand what you are trying to do but I will try my best to help you.

    Since there is a money cap this makes this much easier.

    An idea that popped into my head is that you get the highest enchant that you can get, for example, if efficiency 5 then you get the money cap, for example, 100 and divide the money cap by the highest enchant (100 / 5 = 20). Then divide that number by the highest enchant (20 / 5 = 4). Since 4 * 5 is 20 you list all of the numbers in that sequence, like this: 4, 8, 12, 16, 20. Then you add them all up (You get 60). Then you get a random number from 1 to 60. If it lands on 4 it's efficiency 1, If it lands on 4 to (4 + 8) 12 then it's efficiency 2. If it lands on 12 to 24 it's efficiency 3, if it lands on 24 to 40 then it's efficiency 4, if it lands on 40 to 60 it's efficiency 5.

    I am sorry if this is confusing. If you can't understand it please reply and I will try to rephrase it in a clearer way. If this solved your issue then please mark this post as resolved.
     
Thread Status:
Not open for further replies.

Share This Page