Introduce LootItem record and refactor loot handling logic to support material-specific max amounts
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.alttd.hunger_games.services;
|
||||
|
||||
import com.alttd.hunger_games.config.LootItems;
|
||||
import com.alttd.hunger_games.data_objects.LootItem;
|
||||
import com.alttd.hunger_games.data_objects.RARITY;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -38,15 +39,20 @@ public class LootService {
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
int slot = random.nextInt(27);
|
||||
RARITY rarity = decideRarity();
|
||||
List<Material> possibleItems = LootItems.ITEMS.get(rarity);
|
||||
List<LootItem> possibleItems = LootItems.ITEMS.get(rarity);
|
||||
|
||||
if (possibleItems == null || possibleItems.isEmpty()) {
|
||||
log.warn("No items found for rarity: {}", rarity);
|
||||
continue;
|
||||
}
|
||||
|
||||
Material material = possibleItems.get(random.nextInt(possibleItems.size()));
|
||||
inventory.setItem(slot, new ItemStack(material));
|
||||
LootItem lootItem = possibleItems.get(random.nextInt(possibleItems.size()));
|
||||
if (lootItem == null || lootItem.material() == null) {
|
||||
log.warn("LootItem or material is null for rarity: {}", rarity);
|
||||
continue;
|
||||
}
|
||||
int amount = lootItem.maxAmount() > 1 ? random.nextInt(lootItem.maxAmount()) + 1 : 1;
|
||||
inventory.setItem(slot, new ItemStack(lootItem.material(), amount));
|
||||
}
|
||||
|
||||
return inventory;
|
||||
|
||||
Reference in New Issue
Block a user