Files
BattleBane/src/engine/loot/ItemTableEntry.java
T

60 lines
2.3 KiB
Java
Raw Normal View History

2023-08-07 08:22:37 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.loot;
2023-08-07 09:42:40 -04:00
import engine.gameManager.LootManager;
2024-06-15 19:50:05 -05:00
import org.pmw.tinylog.Logger;
2023-08-07 09:42:40 -04:00
2023-08-07 08:22:37 -04:00
import java.sql.ResultSet;
import java.sql.SQLException;
2023-08-07 09:42:40 -04:00
import java.util.List;
2024-06-15 19:44:37 -05:00
import java.util.concurrent.ThreadLocalRandom;
2023-08-07 08:22:37 -04:00
public class ItemTableEntry {
public int minRoll;
public int maxRoll;
public int cacheID;
public int minSpawn;
public int maxSpawn;
public ItemTableEntry(ResultSet rs) throws SQLException {
this.minRoll = rs.getInt("minRoll");
this.maxRoll = rs.getInt("maxRoll");
this.cacheID = rs.getInt("itemBaseUUID");
this.minSpawn = rs.getInt("minSpawn");
this.maxSpawn = rs.getInt("maxSpawn");
}
2023-08-07 09:42:40 -04:00
public static ItemTableEntry rollTable(int itemTable, int roll) {
ItemTableEntry itemTableEntry = null;
List<ItemTableEntry> itemTableEntryList;
itemTableEntryList = LootManager._itemTables.get(itemTable);
for (ItemTableEntry iteration : itemTableEntryList)
if (roll >= iteration.minRoll && roll <= iteration.maxRoll)
itemTableEntry = iteration;
return itemTableEntry;
}
2024-06-15 19:44:37 -05:00
public static Integer getRandomItem(int itemTable) {
2024-06-15 19:50:05 -05:00
int id = 0;
2024-06-15 19:44:37 -05:00
List<ItemTableEntry> itemTableEntryList;
itemTableEntryList = LootManager._itemTables.get(itemTable);
if(itemTableEntryList != null && itemTableEntryList.size() > 1){
id = itemTableEntryList.get(ThreadLocalRandom.current().nextInt(0,itemTableEntryList.size() - 1)).cacheID;
2024-06-15 19:44:37 -05:00
}
2024-06-15 19:50:05 -05:00
return id;
2024-06-15 19:44:37 -05:00
}
2023-08-07 08:22:37 -04:00
}