Source code for gacha system with entirely customizable drop rate for each item.
- Create a variable that list your items' data and drop rate.
You could see the template on theindex.js
file (itemList
variable).
Make sure you assign the drop rate on therate
property and the item data on thedata
property. - Call the function
gacha
with the item list on the first parameter.
It should look something like:gacha(itemList)
.
It will return one random itemdata
based on the assigned drop rate. - If you need to list the item drop rate, you could use
rateListing
.
It should look something like:rateListing(itemList, 3)
.
Where3
is the number of digit after the comma (example: 44.950%
).
If the drop rate is less or more than 100, the system will calculate it automatically. So you don't have to worry if the gacha result will return nothing.