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

464 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
2023-04-06 20:07:24 -05:00
import engine.Enum;
import engine.loot.*;
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
public static void GenerateMobLoot(Mob mob, boolean fromDeath) {
2023-08-03 09:04:20 -04:00
2023-04-06 20:07:24 -05:00
//determine if mob is in hotzone
2023-08-03 09:04:20 -04:00
2023-04-06 20:07:24 -05:00
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)
RunBootySet(_bootySetMap.get(mob.getMobBase().bootySet), mob, inHotzone, fromDeath);
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)
RunBootySet(_bootySetMap.get(mob.bootySet), mob, inHotzone, fromDeath);
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
2023-08-03 09:04:20 -04:00
2023-08-04 13:25:13 -04:00
if (!fromDeath)
for (Item it : mob.getInventory()) {
2023-08-03 09:04:20 -04:00
ItemBase ib = it.getItemBase();
2023-08-03 09:04:20 -04:00
if (ib.isDiscRune() || ib.getName().toLowerCase().contains("of the gods")) {
ChatSystemMsg chatMsg = new ChatSystemMsg(null, mob.getName() + " in " + mob.getParentZone().getName() + " has found the " + ib.getName() + ". Are you tough enough to take it?");
chatMsg.setMessageType(10);
chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID());
DispatchMessage.dispatchMsgToAll(chatMsg);
}
2023-04-06 20:07:24 -05: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-05 08:47:48 -04:00
private static void RunBootySet(ArrayList<BootySetEntry> entries, Mob mob, boolean inHotzone, boolean fromDeath) {
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
if (fromDeath) {
2023-08-04 13:04:57 -04:00
GenerateEquipmentDrop(mob);
2023-08-04 12:21:22 -04:00
return;
}
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;
2023-08-08 20:37:31 -05: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
2023-08-08 20:37:31 -05:00
int itemTableRoll = 0;
int objectType = mob.getObjectType().ordinal();
if(mob.getObjectType().ordinal() == 52) { //52 = player character
itemTableRoll = ThreadLocalRandom.current().nextInt(1,320 + 1);
} else{
itemTableRoll = TableRoll(mob.level, inHotzone);
}
2023-08-07 10:16:30 -04:00
ItemTableEntry tableRow = ItemTableEntry.rollTable(itemTableId, itemTableRoll);
2023-08-03 09:04:20 -04:00
if (tableRow == null)
return null;
int itemUUID = tableRow.cacheID;
if (itemUUID == 0)
return null;
if (ItemBase.getItemBase(itemUUID).getType().ordinal() == Enum.ItemType.RESOURCE.ordinal()) {
2023-08-08 15:43:24 -05:00
int amount = ThreadLocalRandom.current().nextInt(tableRow.minSpawn, tableRow.maxSpawn + 1);
2023-08-03 09:04:20 -04:00
return new MobLoot(mob, ItemBase.getItemBase(itemUUID), amount, false);
}
outItem = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false);
Enum.ItemType outType = outItem.getItemBase().getType();
2023-08-05 19:28:53 -04:00
2023-08-04 13:25:13 -04:00
if(selectedRow.pModTable != 0){
try {
outItem = GeneratePrefix(mob, outItem, genTableID, genRoll, inHotzone);
outItem.setIsID(false);
} catch (Exception e) {
Logger.error("Failed to GeneratePrefix for item: " + outItem.getName());
}
}
if(selectedRow.sModTable != 0){
try {
outItem = GenerateSuffix(mob, outItem, genTableID, genRoll, inHotzone);
outItem.setIsID(false);
} catch (Exception e) {
Logger.error("Failed to GenerateSuffix for item: " + outItem.getName());
2023-07-15 09:23:48 -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;
2023-08-08 20:37:31 -05:00
int prefixTableRoll = 0;
if(mob.getObjectType().ordinal() == 52) {
prefixTableRoll = ThreadLocalRandom.current().nextInt(1,320 + 1);
} else{
prefixTableRoll = TableRoll(mob.level, inHotzone);
}
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
2023-08-07 10:16:30 -04:00
if (prefixMod.action.length() > 0) {
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;
2023-08-08 20:37:31 -05:00
int suffixTableRoll = 0;
if(mob.getObjectType().ordinal() == 52) {
suffixTableRoll = ThreadLocalRandom.current().nextInt(1,320 + 1);
} else{
suffixTableRoll = TableRoll(mob.level, inHotzone);
}
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
2023-08-07 10:16:30 -04:00
if (suffixMod.action.length() > 0) {
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);
if (max > 319)
max = 319;
2023-08-04 13:25:13 -04:00
int min = (int) (4.469 * mobLevel - 3.469);
if (min < 70)
2023-08-03 21:07:07 -05:00
min = 70;
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);
2023-07-30 11:43:26 -05:00
mob.getCharItemManager().addItemToInventory(goldAmount);
}
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)
2023-08-03 09:04:20 -04:00
mob.getCharItemManager().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
2023-07-30 11:43:26 -05:00
//do equipment here
2023-08-03 09:04:20 -04:00
2023-08-04 14:01:12 -04:00
if (mob.getEquip() != null)
2023-07-30 11:43:26 -05:00
for (MobEquipment me : mob.getEquip().values()) {
2023-08-03 09:04:20 -04:00
2023-07-30 11:43:26 -05:00
if (me.getDropChance() == 0)
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);
2023-07-30 11:43:26 -05:00
float dropChance = me.getDropChance() * 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
2023-08-03 19:18:05 -05:00
MobLoot ml = new MobLoot(mob, me.getItemBase(), false);
2023-08-04 13:09:09 -04:00
2023-08-03 21:07:07 -05:00
if (ml != null) {
ml.setIsID(true);
2023-08-05 19:28:53 -04:00
ml.setDurabilityCurrent((short) (ml.getDurabilityCurrent() - ThreadLocalRandom.current().nextInt(5) + 1));
2023-07-30 11:43:26 -05:00
mob.getCharItemManager().addItemToInventory(ml);
2023-08-09 08:17:53 -04:00
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
2023-08-03 19:18:05 -05:00
MobLoot lootItem = new MobLoot(mob, ItemBase.getItemBase(bse.itemBase), true);
2023-08-03 09:04:20 -04:00
2023-08-03 19:18:05 -05:00
if (lootItem != null)
mob.getCharItemManager().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) {
2023-08-09 15:50:56 -05:00
//get table ID for the itembase ID
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
if (_bootySetMap.get(gift.getItemBaseID()) != null)
2023-08-09 15:50:56 -05:00
tableID = _bootySetMap.get(gift.getItemBaseID()).get(ThreadLocalRandom.current().nextInt(_bootySetMap.get(gift.getItemBaseID()).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
CharacterItemManager itemMan = playerCharacter.getCharItemManager();
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
2023-08-09 14:48:22 -05: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
MobLoot winnings = new MobLoot(playerCharacter, ItemBase.getItemBase(selectedItem.cacheID), 1, false);
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
if (itemMan.hasRoomInventory(winnings.getItemBase().getWeight()) == 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
2023-08-09 14:48:22 -05:00
if(selectedRow.pModTable != 0){
int prefixRoll = ThreadLocalRandom.current().nextInt(220,320 + 1);
ModTableEntry prefix = ModTableEntry.rollTable(selectedRow.pModTable, prefixRoll);
2023-08-09 15:50:56 -05: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
2023-08-09 14:48:22 -05:00
if(selectedRow.sModTable != 0){
int suffixRoll = ThreadLocalRandom.current().nextInt(220,320 + 1);
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);
}
2023-08-09 15:50:56 -05:00
winnings.setIsID(true);
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
}