RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
NpcDropTable.java
1package com.osroyale.game.world.entity.mob.npc.drop;
2
3import com.osroyale.game.world.entity.mob.player.Player;
4import com.osroyale.game.world.entity.mob.player.PlayerRight;
5import com.osroyale.game.world.items.ItemDefinition;
6import com.osroyale.util.RandomUtils;
7import com.osroyale.util.parser.impl.NpcDropParser;
8
9import java.util.LinkedList;
10import java.util.List;
11
45
46* The class which represents a npc drop table.
47 *
48 * @author Michael | Chex
49 */
50public final class NpcDropTable {
51
53 public final int[] npcIds;
54
56 private final boolean rareDropTable;
57
59 public final NpcDrop[] drops;
60
61 public final NpcDrop[][] table = new NpcDrop[5][];
62
63 private int maxRoll = 20_000;
64
65 // common = 1/2
66 // uncommon = 1 / 4
67 // rare = 1/75
68 // very rare = 1/100
69 private static final int[] ROLL_DATA = {
70 /* very rare roll */
71 200,
72
73 /* rare roll */
74 350,
75
76 /* uncommon roll */
77 7000,
78
79 /* common roll */
80 12500,
81
82 /* empty drop roll */
83 200
84 };
85
86 private int[] rollData;
87
89 public NpcDropTable(int[] npcIds, boolean rareDropTable, NpcDrop[] npcDrops, NpcDrop[] always, NpcDrop[] common, NpcDrop[] uncommon, NpcDrop[] rare, NpcDrop[] veryRare) {
90 this.npcIds = npcIds;
91 this.rareDropTable = rareDropTable;
92 this.drops = npcDrops;
93 rollData = ROLL_DATA;
94 table[0] = veryRare;
95 table[1] = rare;
96 table[2] = uncommon;
97 table[3] = common;
98 table[4] = always;
99 }
100
101 public List<NpcDrop> generate(Player player, boolean simulated) {
102 LinkedList<NpcDrop> items = new LinkedList<>();
103 int roll = RandomUtils.inclusive(maxRoll);
104 if (player.equipment.hasRow()) {
105 int old = roll;
106 roll = PlayerRight.dropRateIncrease(player, roll);
107
108 if (roll < rollData[0] && old >= rollData[0]) {
109 if (!simulated) {
110 player.message("Very Rare drop table accessed by ring");
111 player.playerAssistant.useROW();
112 }
113 } else if (roll < rollData[1] && old >= rollData[1]) {
114 if (!simulated) {
115 player.message("Rare drop table accessed by ring");
116 player.playerAssistant.useROW();
117 }
118 } else {
119 /* undo the ring effect since both tables weren't accessed */
120 roll = old;
121 }
122 }
123
124 for (int chance = 0, index = 0; index < rollData.length - 1; index++) {
125 chance += rollData[index];
126
127 if (rollData[index] == 0 || roll >= chance) {
128 continue;
129 }
130
131 if (table[index].length > 0) {
132 items.addFirst(RandomUtils.random(table[index]));
133 break;
134 }
135 }
136
137 for (NpcDrop drop : table[4]) {
138 items.addFirst(drop);
139 }
140
141 return items;
142 }
143
144 public void setRollData(int[] rollData) {
145 this.rollData = rollData;
146 maxRoll = 0;
147 for (int roll : rollData) {
148 maxRoll += roll;
149 }
150 }
151
152 public static void main(String[] args) {
153 int npcId = 7241;
154
155 /*
156 *
157 * DONT USE RATES LESS THAN 100!!!
158 *
159 * The ring of wealth works best with values larger than 100
160 * since 3% of 100 is 3, anything lower than 100 will fuck up ROW
161 *
162 */
163
164 int[] customRolls = {
165 /* very rare roll */
166 200,
167
168 /* rare roll */
169 350,
170
171 /* uncommon roll */
172 7000,
173
174 /* common roll */
175 12500,
176
177 /* empty drop roll */
178 200
179 };
180
181 ItemDefinition.createParser().run();
182 new NpcDropParser().run();
183
184 NpcDropTable table = NpcDropManager.NPC_DROPS.get(npcId);
185
186 System.out.println();
187 System.out.println("Table lengths (vr, r, uc, c): ");
188 for (int index = 0; index < table.table.length - 1; index++) {
189 System.out.print(table.table[index].length + " ");
190 }
191 System.out.println("\n");
192 System.out.println("--------------------------------------------------");
193 System.out.println("Current rolls: \t \t \t \t Custom rolls:");
194 printRates(table.table, table.rollData, customRolls);
195 System.out.println();
196 }
197
198 private static void printRates(NpcDrop[][] tables, int[] rollData, int[] rollData2) {
199 long maxRoll = 0, maxRoll2 = 0;
200
201 for (int index = 0; index < rollData.length; index++) {
202 maxRoll += rollData[index];
203 maxRoll2 += rollData2[index];
204 }
205
206 System.out.println("--------------------------------------------------");
207 System.out.println("Very Rare ---- " + ((long) rollData[0] * 100_00 / maxRoll) / 100.0 + "% \t\t Very Rare ---- " + ((long) rollData2[0] * 100_00 / maxRoll2) / 100.0 + "%");
208 System.out.println("Rare --------- " + ((long) rollData[1] * 100_00 / maxRoll) / 100.0 + "% \t\t Rare --------- " + ((long) rollData2[1] * 100_00 / maxRoll2) / 100.0 + "%");
209 System.out.println("Uncommon ----- " + ((long) rollData[2] * 100_00 / maxRoll) / 100.0 + "% \t\t Uncommon ----- " + ((long) rollData2[2] * 100_00 / maxRoll2) / 100.0 + "%");
210 System.out.println("Common ------- " + ((long) rollData[3] * 100_00 / maxRoll) / 100.0 + "% \t\t Common ------- " + ((long) rollData2[3] * 100_00 / maxRoll2) / 100.0 + "%");
211 System.out.println("Empty Drop --- " + ((long) rollData[4] * 100_00 / maxRoll) / 100.0 + "% \t\t Empty Drop --- " + ((long) rollData2[4] * 100_00 / maxRoll2) / 100.0 + "%");
212 System.out.println("--------------------------------------------------");
213 System.out.println("Very Rare ---- " + ((long) rollData[0] * 100_00 / maxRoll) / tables[0].length / 100.0 + "% \t\t Very Rare ---- " + ((long) rollData2[0] * 100_00 / maxRoll2) / tables[0].length / tables[0].length / 100.0 + "%");
214 System.out.println("Rare --------- " + ((long) rollData[1] * 100_00 / maxRoll) / tables[1].length / 100.0 + "% \t\t Rare --------- " + ((long) rollData2[1] * 100_00 / maxRoll2) / tables[0].length / tables[1].length / 100.0 + "%");
215 System.out.println("Uncommon ----- " + ((long) rollData[2] * 100_00 / maxRoll) / tables[2].length / 100.0 + "% \t\t Uncommon ----- " + ((long) rollData2[2] * 100_00 / maxRoll2) / tables[0].length / tables[2].length / 100.0 + "%");
216 System.out.println("Common ------- " + ((long) rollData[3] * 100_00 / maxRoll) / tables[3].length / 100.0 + "% \t\t Common ------- " + ((long) rollData2[3] * 100_00 / maxRoll2) / tables[0].length / tables[3].length / 100.0 + "%");
217 System.out.println("--------------------------------------------------");
218 }
219
220}
NpcDropTable(int[] npcIds, boolean rareDropTable, NpcDrop[] npcDrops, NpcDrop[] always, NpcDrop[] common, NpcDrop[] uncommon, NpcDrop[] rare, NpcDrop[] veryRare)