LootGenerator
Inherits: NodeInventories < Node
Node that generates random loot from loot resources into target inventories.
Description
The LootGenerator node provides functionality for generating random items from weighted loot resources and placing them into target inventories. It inherits from NodeInventories and can access the inventory database for item validation. This is commonly used in survival games for treasure chests, enemy drops, and resource gathering mechanics.
The loot generation uses a unified API where a single method handles both default roll behavior (using the loot resource’s configured min/max roll range) and custom roll counts. The rolls functionality allows for Minecraft-style loot table behavior where a loot table can generate multiple items in a single call.
The loot generation uses weighted random selection where items with higher weights are more likely to be selected. Each loot item can specify minimum and maximum amounts to generate random quantities. Additionally, property ranges defined in LootItem resources allow for randomized item properties, enabling items to be generated with randomized durability, damage, enchantments, or other properties within configurable ranges.
Properties
|
||
|
|
Methods
void |
generate_loot(rolls: |
get_target_inventory() const |
Property Descriptions
String
loot_id 🔗
void set_loot_id(value:
String
)String
get_loot_id()
The ID of the Loot resource containing the weighted list of items that can be generated. This ID references a loot resource in the inventory database that defines which items can be generated and their relative probabilities.
NodePath
target_inventory_path = NodePath("")
🔗
void set_target_inventory_path(value:
NodePath
)NodePath
get_target_inventory_path()
The NodePath
to the target Inventory node where generated loot will be placed. The path should point to a valid Inventory node in the scene tree.
Method Descriptions
void generate_loot(rolls: int
= -1) 🔗
Generate random items from the assigned loot resource and add them to the target inventory. When rolls
is -1 (default), uses the loot resource’s configured roll range (min_rolls to max_rolls) with random selection. When rolls
is greater than 0, uses that specific number of rolls, overriding the configured range. Each roll represents an independent weighted selection from the loot table. The actual amount of each item is randomly determined between the min_amount and max_amount specified in the LootItem. Additionally, any property ranges defined in the LootItem will be applied to randomize item properties within the specified ranges.
Inventory get_target_inventory() const 🔗
Returns the target Inventory node found at the target_inventory_path. Returns null if the path is empty or no valid inventory is found at the specified path.