Files
prestonbane/src/engine/gameManager/LootManager.java
T

458 lines
16 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
2023-08-03 08:27:08 -04:00
package engine.gameManager;
2022-04-30 09:41:17 -04:00
import engine.loot.*;
import engine.mbEnums;
2023-04-06 20:07:24 -05:00
import engine.net.DispatchMessage;
2023-08-09 17:52:39 -04:00
import engine.net.client.msg.ErrorPopupMsg;
2023-04-06 20:07:24 -05:00
import engine.net.client.msg.chat.ChatSystemMsg;
import engine.objects.*;
import org.pmw.tinylog.Logger;
2023-04-06 20:07:24 -05:00
import java.util.ArrayList;
2022-04-30 09:41:17 -04:00
import java.util.HashMap;
import java.util.concurrent.ThreadLocalRandom;
/**
* Class contains static methods for data from Magicbane's loot tables
*/
2023-08-03 09:04:20 -04:00
public enum LootManager {
LOOTMANAGER;
2022-04-30 09:41:17 -04:00
2023-08-06 17:44:30 -04:00
// Newer tables
2023-08-06 18:09:34 -04:00
public static HashMap<Integer, ArrayList<GenTableEntry>> _genTables = new HashMap<>();
2023-08-07 08:39:08 -04:00
public static HashMap<Integer, ArrayList<ItemTableEntry>> _itemTables = new HashMap<>();
2023-08-07 08:49:43 -04:00
public static HashMap<Integer, ArrayList<ModTableEntry>> _modTables = new HashMap<>();
2023-08-07 08:58:44 -04:00
public static HashMap<Integer, ArrayList<ModTypeTableEntry>> _modTypeTables = new HashMap<>();
2023-08-06 17:44:30 -04:00
2023-08-03 09:04:20 -04:00
// Drop Rates
public static float NORMAL_DROP_RATE;
public static float NORMAL_EXP_RATE;
public static float NORMAL_GOLD_RATE;
public static float HOTZONE_DROP_RATE;
public static float HOTZONE_EXP_RATE;
public static float HOTZONE_GOLD_RATE;
2023-08-08 18:30:21 -04:00
public static HashMap<Integer, ArrayList<BootySetEntry>> _bootySetMap = new HashMap<>();
2023-08-03 09:04:20 -04:00
// Bootstrap routine to initialize the Loot Manager
public static void init() {
2022-04-30 09:41:17 -04:00
2023-08-03 15:20:31 -04:00
// Load loot tables from database.
2023-08-07 08:22:37 -04:00
_genTables = DbManager.LootQueries.LOAD_GEN_ITEM_TABLES();
2023-08-07 08:39:08 -04:00
_itemTables = DbManager.LootQueries.LOAD_ITEM_TABLES();
2023-08-07 08:49:43 -04:00
_modTables = DbManager.LootQueries.LOAD_MOD_TABLES();
2023-08-07 08:58:44 -04:00
_modTypeTables = DbManager.LootQueries.LOAD_MOD_TYPE_TABLES();
2023-08-03 15:20:31 -04:00
// Cache drop rate values from Config manager.
2023-08-03 09:04:20 -04:00
NORMAL_DROP_RATE = Float.parseFloat(ConfigManager.MB_NORMAL_DROP_RATE.getValue());
NORMAL_EXP_RATE = Float.parseFloat(ConfigManager.MB_NORMAL_EXP_RATE.getValue());
NORMAL_GOLD_RATE = Float.parseFloat(ConfigManager.MB_NORMAL_GOLD_RATE.getValue());
HOTZONE_DROP_RATE = Float.parseFloat(ConfigManager.MB_HOTZONE_DROP_RATE.getValue());
HOTZONE_EXP_RATE = Float.parseFloat(ConfigManager.MB_HOTZONE_EXP_RATE.getValue());
HOTZONE_GOLD_RATE = Float.parseFloat(ConfigManager.MB_HOTZONE_GOLD_RATE.getValue());
2022-04-30 09:41:17 -04:00
}
2023-07-15 09:23:48 -04:00
2023-08-21 19:36:46 -05:00
public static void GenerateMobLoot(Mob mob) {
2023-08-03 09:04:20 -04:00
2023-04-06 20:07:24 -05:00
//determine if mob is in hotzone
boolean inHotzone = ZoneManager.inHotZone(mob.getLoc());
2023-08-03 09:04:20 -04:00
2023-04-06 20:07:24 -05:00
//iterate the booty sets
2023-08-03 09:04:20 -04:00
2023-08-08 18:30:21 -04:00
if (mob.getMobBase().bootySet != 0 && _bootySetMap.containsKey(mob.getMobBase().bootySet) == true)
2023-08-21 19:36:46 -05:00
RunBootySet(_bootySetMap.get(mob.getMobBase().bootySet), mob, inHotzone);
2023-08-03 09:04:20 -04:00
2023-08-08 18:30:21 -04:00
if (mob.bootySet != 0 && _bootySetMap.containsKey(mob.bootySet) == true)
2023-08-21 19:36:46 -05:00
RunBootySet(_bootySetMap.get(mob.bootySet), mob, inHotzone);
2023-08-03 09:04:20 -04:00
2023-04-07 12:22:33 -05:00
//lastly, check mobs inventory for godly or disc runes to send a server announcement
2024-04-14 12:24:53 -04:00
for (Item item : mob.getInventory()) {
2023-08-03 09:04:20 -04:00
2024-04-14 12:24:53 -04:00
if ((item.templateID > 2499 && item.templateID <= 3050) || item.template.item_base_name.toLowerCase().contains("of the gods")) {
ChatSystemMsg chatMsg = new ChatSystemMsg(null, mob.getName() + " in " + mob.getParentZone().zoneName + " has found the " + item.template.item_base_name + ". Are you tough enough to take it?");
2024-03-24 09:42:27 -04:00
chatMsg.setMessageType(10);
chatMsg.setChannel(mbEnums.ChatChannelType.SYSTEM.getChannelID());
2024-03-24 09:42:27 -04:00
DispatchMessage.dispatchMsgToAll(chatMsg);
2023-04-06 20:07:24 -05:00
}
2024-03-24 09:42:27 -04:00
}
2023-08-04 13:25:13 -04:00
2023-04-07 12:22:33 -05:00
}
2023-08-03 09:04:20 -04:00
2023-08-21 19:36:46 -05:00
private static void RunBootySet(ArrayList<BootySetEntry> entries, Mob mob, boolean inHotzone) {
2023-08-03 09:04:20 -04:00
2023-08-04 12:21:22 -04:00
boolean hotzoneWasRan = false;
float dropRate = 1.0f;
2023-08-04 12:21:22 -04:00
2023-08-04 14:01:12 -04:00
// Iterate all entries in this bootySet and process accordingly
2023-08-04 12:21:22 -04:00
for (BootySetEntry bse : entries) {
switch (bse.bootyType) {
case "GOLD":
GenerateGoldDrop(mob, bse, inHotzone);
break;
case "LOOT":
if (mob.getSafeZone() == false)
dropRate = LootManager.NORMAL_DROP_RATE;
2023-08-05 19:23:58 -04:00
if (inHotzone == true)
dropRate = LootManager.HOTZONE_DROP_RATE;
if (ThreadLocalRandom.current().nextInt(1, 100 + 1) < (bse.dropChance * dropRate))
2023-08-06 07:53:33 -04:00
GenerateLootDrop(mob, bse.genTable, false); //generate normal loot drop
2023-08-03 09:04:20 -04:00
2023-08-04 12:21:22 -04:00
// Generate hotzone loot if in hotzone
2023-08-04 13:25:13 -04:00
// Only one bite at the hotzone apple per bootyset.
2023-08-04 12:21:22 -04:00
if (inHotzone == true && hotzoneWasRan == false)
2023-08-07 10:16:30 -04:00
if (_genTables.containsKey(bse.genTable + 1) && ThreadLocalRandom.current().nextInt(1, 100 + 1) < (bse.dropChance * dropRate)) {
2023-08-06 07:53:33 -04:00
GenerateLootDrop(mob, bse.genTable + 1, true); //generate loot drop from hotzone table
2023-08-04 12:21:22 -04:00
hotzoneWasRan = true;
}
break;
case "ITEM":
2023-08-04 13:16:44 -04:00
GenerateInventoryDrop(mob, bse);
2023-08-04 12:21:22 -04:00
break;
2023-07-30 19:52:11 -05:00
}
2023-07-31 21:28:41 -05:00
}
2023-07-31 19:20:41 -05:00
}
2023-08-03 09:04:20 -04:00
public static MobLoot getGenTableItem(int genTableID, AbstractCharacter mob, Boolean inHotzone) {
2023-08-03 09:04:20 -04:00
2023-08-07 10:16:30 -04:00
if (mob == null || _genTables.containsKey(genTableID) == false)
2023-08-03 09:04:20 -04:00
return null;
MobLoot outItem;
2024-03-24 09:42:27 -04:00
int genRoll = ThreadLocalRandom.current().nextInt(1, 100 + 1);
2023-08-03 09:04:20 -04:00
GenTableEntry selectedRow = GenTableEntry.rollTable(genTableID, genRoll, 1.0f);
2023-08-04 13:25:13 -04:00
2023-08-03 09:04:20 -04:00
if (selectedRow == null)
return null;
int itemTableId = selectedRow.itemTableID;
2023-08-07 10:16:30 -04:00
if (_itemTables.containsKey(itemTableId) == false)
2023-08-03 19:18:05 -05:00
return null;
2023-08-03 09:04:20 -04:00
//gets the 1-320 roll for this mob
2024-03-30 12:44:12 -04:00
2023-08-08 20:37:31 -05:00
int itemTableRoll = 0;
2024-03-30 12:44:12 -04:00
if (mob.getObjectType().ordinal() == 52) //52 = player character
2024-03-24 09:42:27 -04:00
itemTableRoll = ThreadLocalRandom.current().nextInt(1, 320 + 1);
2024-03-30 12:44:12 -04:00
else
2023-08-08 20:37:31 -05:00
itemTableRoll = TableRoll(mob.level, inHotzone);
2024-03-30 12:44:12 -04:00
2023-08-07 10:16:30 -04:00
ItemTableEntry tableRow = ItemTableEntry.rollTable(itemTableId, itemTableRoll);
2024-03-30 12:44:12 -04:00
2023-08-03 09:04:20 -04:00
if (tableRow == null)
return null;
2024-03-22 12:37:40 -04:00
int itemUUID = tableRow.templateID;
2023-08-03 09:04:20 -04:00
if (itemUUID == 0)
return null;
if (ItemTemplate.templates.get(itemUUID).item_type.equals(mbEnums.ItemType.RESOURCE)) {
2023-08-08 15:43:24 -05:00
int amount = ThreadLocalRandom.current().nextInt(tableRow.minSpawn, tableRow.maxSpawn + 1);
2024-03-16 07:57:17 -04:00
return new MobLoot(mob, ItemTemplate.templates.get(itemUUID), amount, false);
2023-08-03 09:04:20 -04:00
}
2024-03-16 07:57:17 -04:00
outItem = new MobLoot(mob, ItemTemplate.templates.get(itemUUID), false);
2023-08-04 13:25:13 -04:00
2024-03-30 12:44:12 -04:00
if (selectedRow.pModTable != 0)
try {
outItem = GeneratePrefix(mob, outItem, genTableID, genRoll, inHotzone);
outItem.flags.remove(mbEnums.ItemFlags.Identified);
} catch (Exception e) {
Logger.error("Failed to GeneratePrefix for item: " + outItem.getName());
}
2024-03-30 12:44:12 -04:00
if (selectedRow.sModTable != 0)
try {
outItem = GenerateSuffix(mob, outItem, genTableID, genRoll, inHotzone);
outItem.flags.remove(mbEnums.ItemFlags.Identified);
} catch (Exception e) {
Logger.error("Failed to GenerateSuffix for item: " + outItem.getName());
2023-07-15 09:23:48 -04:00
}
2024-03-30 12:44:12 -04:00
2023-08-03 09:04:20 -04:00
return outItem;
2022-04-30 09:41:17 -04:00
}
2023-08-03 09:04:20 -04:00
private static MobLoot GeneratePrefix(AbstractCharacter mob, MobLoot inItem, int genTableID, int genRoll, Boolean inHotzone) {
2023-08-03 09:04:20 -04:00
GenTableEntry selectedRow = GenTableEntry.rollTable(genTableID, genRoll, 1.0f);
2023-08-04 13:25:13 -04:00
2023-08-05 19:28:53 -04:00
if (selectedRow == null)
return inItem;
2023-08-03 19:18:05 -05:00
2023-08-05 09:39:16 -04:00
int prefixroll = ThreadLocalRandom.current().nextInt(1, 100 + 1);
2023-08-03 09:04:20 -04:00
2023-08-07 10:16:30 -04:00
ModTypeTableEntry prefixTable = ModTypeTableEntry.rollTable(selectedRow.pModTable, prefixroll);
2023-08-04 13:25:13 -04:00
2023-08-07 10:16:30 -04:00
if (prefixTable == null)
return inItem;
2024-03-30 12:44:12 -04:00
2023-08-08 20:37:31 -05:00
int prefixTableRoll = 0;
2024-03-30 12:44:12 -04:00
2024-04-14 12:41:16 -04:00
if (mob.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter))
2024-03-24 09:42:27 -04:00
prefixTableRoll = ThreadLocalRandom.current().nextInt(1, 320 + 1);
2024-03-30 12:44:12 -04:00
else
2023-08-08 20:37:31 -05:00
prefixTableRoll = TableRoll(mob.level, inHotzone);
2024-03-30 12:44:12 -04:00
2023-08-08 20:37:31 -05:00
ModTableEntry prefixMod = ModTableEntry.rollTable(prefixTable.modTableID, prefixTableRoll);
2023-08-04 13:25:13 -04:00
2023-08-07 10:16:30 -04:00
if (prefixMod == null)
return inItem;
2023-08-03 09:04:20 -04:00
2024-04-14 12:41:16 -04:00
if (prefixMod.action.isEmpty() == false) {
2023-08-07 10:16:30 -04:00
inItem.setPrefix(prefixMod.action);
inItem.addPermanentEnchantment(prefixMod.action, 0, prefixMod.level, true);
2023-08-05 19:28:53 -04:00
}
2023-08-07 10:16:30 -04:00
2023-08-02 19:45:18 -05:00
return inItem;
}
2023-08-03 09:04:20 -04:00
private static MobLoot GenerateSuffix(AbstractCharacter mob, MobLoot inItem, int genTableID, int genRoll, Boolean inHotzone) {
2023-08-03 09:04:20 -04:00
GenTableEntry selectedRow = GenTableEntry.rollTable(genTableID, genRoll, 1.0f);
2023-08-04 13:25:13 -04:00
2023-08-05 19:28:53 -04:00
if (selectedRow == null)
return inItem;
2023-08-03 19:18:05 -05:00
2023-08-07 10:16:30 -04:00
int suffixRoll = ThreadLocalRandom.current().nextInt(1, 100 + 1);
2023-08-03 19:18:05 -05:00
2023-08-07 10:16:30 -04:00
ModTypeTableEntry suffixTable = ModTypeTableEntry.rollTable(selectedRow.sModTable, suffixRoll);
2023-08-04 13:25:13 -04:00
2023-08-05 19:28:53 -04:00
if (suffixTable == null)
return inItem;
2024-03-30 12:44:12 -04:00
int suffixTableRoll;
2024-04-14 12:41:16 -04:00
if (mob.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter))
2024-03-24 09:42:27 -04:00
suffixTableRoll = ThreadLocalRandom.current().nextInt(1, 320 + 1);
2024-03-30 12:44:12 -04:00
else
2023-08-08 20:37:31 -05:00
suffixTableRoll = TableRoll(mob.level, inHotzone);
2024-03-30 12:44:12 -04:00
2023-08-08 20:37:31 -05:00
ModTableEntry suffixMod = ModTableEntry.rollTable(suffixTable.modTableID, suffixTableRoll);
2023-08-04 13:25:13 -04:00
2023-08-07 10:16:30 -04:00
if (suffixMod == null)
return inItem;
2023-08-03 09:04:20 -04:00
2024-04-14 12:41:16 -04:00
if (suffixMod.action.isEmpty() == false) {
2023-08-09 07:39:10 -04:00
inItem.setSuffix(suffixMod.action);
2023-08-17 17:53:31 -04:00
inItem.addPermanentEnchantment(suffixMod.action, 0, suffixMod.level, false);
2023-08-05 19:28:53 -04:00
}
2023-08-07 10:16:30 -04:00
2023-08-02 19:45:18 -05:00
return inItem;
}
2023-08-03 09:04:20 -04:00
2023-08-07 13:53:16 -04:00
public static int TableRoll(int mobLevel, Boolean inHotzone) {
2023-08-03 09:04:20 -04:00
if (mobLevel > 65)
2023-07-30 13:55:08 -05:00
mobLevel = 65;
2023-08-03 09:04:20 -04:00
int max = (int) (4.882 * mobLevel + 127.0);
2023-08-04 13:25:13 -04:00
int min = (int) (4.469 * mobLevel - 3.469);
2024-04-14 12:41:16 -04:00
min = Math.max(min, 70);
max = Math.min(max, 319);
2023-08-04 13:25:13 -04:00
if (inHotzone)
2023-08-03 19:21:35 -05:00
min += mobLevel;
2023-08-03 19:18:05 -05:00
2023-08-08 15:43:24 -05:00
int roll = ThreadLocalRandom.current().nextInt(min, max + 1);
2023-08-03 09:04:20 -04:00
2023-07-17 22:25:54 -05:00
return roll;
}
2023-08-03 09:04:20 -04:00
public static void GenerateGoldDrop(Mob mob, BootySetEntry bse, Boolean inHotzone) {
2023-08-05 09:39:16 -04:00
int chanceRoll = ThreadLocalRandom.current().nextInt(1, 100 + 1);
2023-08-03 09:04:20 -04:00
2023-08-03 19:18:05 -05:00
//early exit, failed to hit minimum chance roll
2023-08-03 09:04:20 -04:00
if (chanceRoll > bse.dropChance)
2023-07-30 11:43:26 -05:00
return;
2023-08-03 09:04:20 -04:00
2023-07-30 11:43:26 -05:00
//determine and add gold to mob inventory
2023-08-03 09:04:20 -04:00
2023-08-02 19:45:18 -05:00
int high = bse.highGold;
int low = bse.lowGold;
2023-08-08 15:43:24 -05:00
int gold = ThreadLocalRandom.current().nextInt(low, high + 1);
2023-08-03 09:04:20 -04:00
if (inHotzone == true)
gold = (int) (gold * HOTZONE_GOLD_RATE);
else
2023-08-03 19:18:05 -05:00
gold = (int) (gold * NORMAL_GOLD_RATE);
2023-08-03 09:04:20 -04:00
2023-07-30 11:43:26 -05:00
if (gold > 0) {
2023-08-02 19:45:18 -05:00
MobLoot goldAmount = new MobLoot(mob, gold);
2024-03-18 10:01:29 -04:00
mob.charItemManager.addItemToInventory(goldAmount);
2023-07-30 11:43:26 -05:00
}
2023-08-03 09:04:20 -04:00
2023-07-30 11:43:26 -05:00
}
2023-08-03 09:04:20 -04:00
2023-08-04 14:01:12 -04:00
public static void GenerateLootDrop(Mob mob, int tableID, Boolean inHotzone) {
2023-08-03 09:04:20 -04:00
try {
2023-08-03 19:21:35 -05:00
MobLoot toAdd = getGenTableItem(tableID, mob, inHotzone);
2023-08-05 19:28:53 -04:00
2023-08-04 13:25:13 -04:00
if (toAdd != null)
2024-03-18 10:01:29 -04:00
mob.charItemManager.addItemToInventory(toAdd);
2023-08-04 13:25:13 -04:00
2023-08-03 09:04:20 -04:00
} catch (Exception e) {
2023-07-30 13:55:08 -05:00
//TODO chase down loot generation error, affects roughly 2% of drops
int i = 0;
}
2023-07-30 11:43:26 -05:00
}
2023-08-03 09:04:20 -04:00
2023-08-04 13:04:57 -04:00
public static void GenerateEquipmentDrop(Mob mob) {
2023-08-03 09:04:20 -04:00
if (mob.behaviourType.equals(mbEnums.MobBehaviourType.HamletGuard))
return; // safehold guards don't drop their equipment
2023-07-30 11:43:26 -05:00
//do equipment here
2023-08-21 19:21:50 -05:00
int dropCount = 0;
2024-03-30 12:44:12 -04:00
2024-03-18 10:01:29 -04:00
if (mob.charItemManager.equipped.isEmpty() == false)
for (Item item : mob.charItemManager.equipped.values()) {
2023-08-03 09:04:20 -04:00
2024-03-18 10:01:29 -04:00
if (item.drop_chance == 0)
2023-07-30 11:43:26 -05:00
continue;
2023-08-03 09:04:20 -04:00
2023-08-05 09:39:16 -04:00
float equipmentRoll = ThreadLocalRandom.current().nextInt(1, 100 + 1);
2024-03-18 10:01:29 -04:00
float dropChance = item.drop_chance * 100;
2023-08-03 09:04:20 -04:00
2023-08-04 13:04:57 -04:00
if (equipmentRoll > dropChance)
2023-08-03 19:18:05 -05:00
continue;
2023-08-04 13:04:57 -04:00
2024-03-18 10:01:29 -04:00
MobLoot ml = new MobLoot(mob, item.template, false);
2023-08-04 13:09:09 -04:00
2023-08-21 19:21:50 -05:00
if (ml != null && dropCount < 1) {
ml.flags.add(mbEnums.ItemFlags.Identified);
2024-03-25 05:25:09 -04:00
ml.setCombat_health_current((short) ((short) ml.combat_health_current - ThreadLocalRandom.current().nextInt(5) + 1));
2024-03-18 10:01:29 -04:00
mob.charItemManager.addItemToInventory(ml);
2023-08-21 19:21:50 -05:00
dropCount = 1;
//break; // Exit on first successful roll.
2023-08-03 21:07:07 -05:00
}
2023-07-30 11:43:26 -05:00
}
}
2023-08-03 09:04:20 -04:00
2023-08-04 13:16:44 -04:00
public static void GenerateInventoryDrop(Mob mob, BootySetEntry bse) {
2023-08-03 09:04:20 -04:00
2023-08-05 09:39:16 -04:00
int chanceRoll = ThreadLocalRandom.current().nextInt(1, 100 + 1);
2023-08-03 09:04:20 -04:00
//early exit, failed to hit minimum chance roll
2023-08-04 13:16:44 -04:00
if (chanceRoll > bse.dropChance)
2023-07-30 15:57:01 -05:00
return;
2023-08-03 09:04:20 -04:00
2024-03-16 07:57:17 -04:00
MobLoot lootItem = new MobLoot(mob, ItemTemplate.templates.get(bse.templateID), true);
2023-08-03 09:04:20 -04:00
2023-08-03 19:18:05 -05:00
if (lootItem != null)
2024-03-18 10:01:29 -04:00
mob.charItemManager.addItemToInventory(lootItem);
2023-07-30 11:43:26 -05:00
}
2023-08-09 17:52:39 -04:00
public static void peddleFate(PlayerCharacter playerCharacter, Item gift) {
2024-03-27 17:47:38 -05:00
//get table ID for the itemtemplate
2023-08-09 17:52:39 -04:00
2023-08-09 15:50:56 -05:00
int tableID = 0;
2023-08-09 17:52:39 -04:00
2024-03-30 08:26:08 -04:00
if (_bootySetMap.get(gift.templateID) != null)
tableID = _bootySetMap.get(gift.templateID).get(ThreadLocalRandom.current().nextInt(_bootySetMap.get(gift.templateID).size())).genTable;
2023-08-09 14:48:22 -05:00
2023-08-09 17:52:39 -04:00
if (tableID == 0)
2023-08-08 19:37:42 -05:00
return;
2023-08-09 14:48:22 -05:00
//get the character item manager
2023-08-09 17:52:39 -04:00
2024-03-18 10:01:29 -04:00
CharacterItemManager itemMan = playerCharacter.charItemManager;
2023-08-09 17:52:39 -04:00
if (itemMan == null)
2023-08-09 14:48:22 -05:00
return;
//check if player owns the gift he is trying to open
2023-08-09 17:52:39 -04:00
if (itemMan.doesCharOwnThisItem(gift.getObjectUUID()) == false)
2023-08-09 14:48:22 -05:00
return;
//roll 1-100 for the gen table selection
2023-08-09 17:52:39 -04:00
int genRoll = ThreadLocalRandom.current().nextInt(1, 100 + 1);
GenTableEntry selectedRow = GenTableEntry.rollTable(tableID, genRoll, LootManager.NORMAL_DROP_RATE);
2023-08-09 17:52:39 -04:00
2024-03-24 09:42:27 -04:00
if (selectedRow == null)
2023-08-09 15:50:56 -05:00
return;
2023-08-09 14:48:22 -05:00
//roll 220-320 for the item table selection
2023-08-09 17:52:39 -04:00
int itemRoll = ThreadLocalRandom.current().nextInt(220, 320 + 1);
ItemTableEntry selectedItem = ItemTableEntry.rollTable(selectedRow.itemTableID, itemRoll);
if (selectedItem == null)
2023-08-09 14:48:22 -05:00
return;
//create the item from the table, quantity is always 1
2023-08-09 17:52:39 -04:00
2024-03-22 12:37:40 -04:00
MobLoot winnings = new MobLoot(playerCharacter, ItemTemplate.templates.get(selectedItem.templateID), 1, false);
2023-08-09 17:52:39 -04:00
if (winnings == null)
2023-08-09 14:48:22 -05:00
return;
2023-08-09 15:50:56 -05:00
//early exit if the inventory of the player will not old the item
2023-08-09 17:52:39 -04:00
2024-03-03 15:06:44 -05:00
if (itemMan.hasRoomInventory(winnings.template.item_wt) == false) {
2023-08-09 17:58:11 -04:00
ErrorPopupMsg.sendErrorPopup(playerCharacter, 21);
2023-08-09 15:50:56 -05:00
return;
}
2023-08-09 14:48:22 -05:00
//determine if the winning item needs a prefix
2023-08-09 17:52:39 -04:00
2024-03-24 09:42:27 -04:00
if (selectedRow.pModTable != 0) {
int prefixRoll = ThreadLocalRandom.current().nextInt(220, 320 + 1);
2023-08-09 14:48:22 -05:00
ModTableEntry prefix = ModTableEntry.rollTable(selectedRow.pModTable, prefixRoll);
2024-03-24 09:42:27 -04:00
if (prefix != null)
2023-08-09 14:48:22 -05:00
winnings.addPermanentEnchantment(prefix.action, 0, prefix.level, true);
2023-08-08 19:37:42 -05:00
}
2023-08-09 14:48:22 -05:00
//determine if the winning item needs a suffix
2023-08-09 17:52:39 -04:00
2024-03-22 13:03:47 -04:00
if (selectedRow.sModTable != 0) {
int suffixRoll = ThreadLocalRandom.current().nextInt(220, 320 + 1);
2023-08-09 14:48:22 -05:00
ModTableEntry suffix = ModTableEntry.rollTable(selectedRow.sModTable, suffixRoll);
2023-08-09 17:52:39 -04:00
if (suffix != null)
2023-08-09 14:48:22 -05:00
winnings.addPermanentEnchantment(suffix.action, 0, suffix.level, true);
}
winnings.flags.add(mbEnums.ItemFlags.Identified);
2023-08-09 17:52:39 -04:00
2023-08-09 14:48:22 -05:00
//remove gift from inventory
2023-08-09 17:52:39 -04:00
2023-08-09 15:50:56 -05:00
itemMan.consume(gift);
2023-08-09 14:48:22 -05:00
//add winnings to player inventory
2023-08-09 17:52:39 -04:00
2023-08-12 07:46:24 -04:00
Item playerWinnings = winnings.promoteToItem(playerCharacter);
2023-08-09 14:53:05 -05:00
itemMan.addItemToInventory(playerWinnings);
2023-08-09 15:50:56 -05:00
itemMan.updateInventory();
}
2023-08-07 10:16:30 -04:00
}