In the last week or so I decided to finally redo my drop system. So I wanted to quickly go through what I have done.
I thought it would be nice to load the NPC drops that I could from a JSON on startup, so that I don't have 500 classes of NPC drops.
Code:
{
"Names": [
"6203"
],
"Worldlist": "Zamorak Boss",
"Charm Drops": {
"Charm Amount": 1,
"12163": 18,
"12160": 1,
"12159": 4,
"12159": 12
},
"Tables Used": {
"GodwarsRdt": 8,
"GodwarsGem": 2,
"BossShardTable": 1,
"ZamorakHilt": 1
},
"Drops": [
{
"itemId": 5626,
"amount": 295,
"rollAmount": 5,
"chance": 8
},
{
"itemId": 5302,
"amount": 3,
"chance": 8
},
[
8,
{
"itemId": 145,
"amount": 3
},
{
"itemId": 157,
"amount": 3
}
],
[
8,
{
"itemId": 3026,
"amount": 3
},
{
"itemId": 189,
"amount": 3
}
],
{
"itemId": 1333,
"chance": 8
},
{
"itemId": 1123,
"chance": 8
},
{
"itemId": 1079,
"chance": 7
},
{
"itemId": 5698,
"chance": 2
},
{
"itemId": 2486,
"amount": 10,
"chance": 8
},
{
"itemId": 560,
"amount": 120,
"rollAmount": 5,
"chance": 8
},
{
"itemId": 565,
"amount": 80,
"rollAmount": 10,
"chance": 8
},
{
"itemId": 11716
},
{
"itemId": 11736
},
{
"itemId": 995,
"amount": 19500,
"rollAmount": 500,
"chance": 32
}
]
},
I am going to break down each part:
Code:
"Names": [
"6203"
],
Here is a Json Array of all of the names OR npcIds that use this drop table. Since I also use this to load tables like the RDT, names such as "RareDropTable" could also go here.
Code:
"Worldlist": "Zamorak Boss",
I keep track of the players in certain areas that need to be kept track of, such as the Zamorak Godwars boss room in a Map<String, List<Player>>. This way, I can check if an NPC's drop table has a Worldlist in its object and then when the NPC dies I can then get the player list from that map and then message all the players the drop.
Although not included in K'ril's table, I can specify the amount of rolls of the drop table when the NPC dies. If it is not included the default value would be 1 roll.
Again not included in K'ril's table, I can specify the range that the drop rolls. So if it is 255, it would roll 0 - 255. This is because some drop tables may only have 128 possible drops but according to Jagex something could be 1/255, so I need to specify this. If this doesn't exist it just gets the size of the list of items and rolls that - 1.
Code:
"Charm Drops": {
"Charm Amount": 1,
"12163": 18,
"12160": 1,
"12159": 4,
"12159": 12
},
In this object I can define the drop chance out of 100 for each charm and the amount dropped. If the amount dropped is 1 I won't include it to save space. If this exists, each charm gets put into an array equal to the number of chances it has. When the NPC dies, it will roll 0 - 99 and if it hits the index / is not greater than or equal to the length of the array, it will drop the charm it lands on.
Code:
"Tables Used": {
"GodwarsRdt": 8,
"GodwarsGem": 2,
"BossShardTable": 1,
"ZamorakHilt": 1
},
Here, I list all of the drop tables the NPC can access with their name and chance. They are put into an array chance number of times along with the drops that I will explain below. When the NPC dies and rolls its drop table, if it gets a string from the Object[] of possible drops, it will then access that drop table from the Hashmap of drop tables, then pick a drop from that.
Code:
{
"itemId": 565,
"amount": 80,
"rollAmount": 10,
"chance": 8
},
Lastly, we have an item drop. It has 4 possible things:
- The itemId, which always needs to be included.
- The amount, which if 1 I don't include it as I assume the default is 1.
- The rollAmount, which is the max quantity the drop can be. So if you could get between 20-200 feathers in a drop, this would be 180. If it doesn't exist I assume -1.
- The chance, which is the amount of times the item gets put into the possible drops array. If it is 1 I don't include it and assume by default it is 1.
Code:
[
8,
{
"itemId": 145,
"amount": 3
},
{
"itemId": 157,
"amount": 3
}
],
For drops that drop two or more different items at once, I use a Json Array. The first number is the chance for this drop. Then I list each item in the drop.
I then put a new ItemDrop(itemId, amount, rollAmount) into the list chance number of times.
I put the 100% drops in the NPC Definitions Json, because not all NPCs have a drop table but do have 100% drops, so that way I don't have to make a drop table for every NPC even if it just has 100% drops.
I am somewhat new to JSONS so please stop me if I am doing something the wrong way or you think I could be doing it better.