ContainerInteraction ​
Inherits: InteractableObjectInteraction < Interaction < Resource
Container interaction - manages inventory storage in world objects Uses InteractableObject's InventoryComponent (created if this interaction is present)
Properties ​
Dictionary | inventory | { ... } |
int | max_slots | 20 |
InventoryStyle | inventory_style | null |
int | loot_table_id | |
bool | auto_close_enabled | true |
float | auto_close_distance | 4.0 |
String | closed_animation | "closed" |
String | locked_animation | "locked" |
String | open_animation | "open" |
SFXSelection | container_open_sound | |
SFXSelection | container_close_sound | |
SFXSelection | container_locked_sound |
Variables ​
InventoryComponent | inventory_data | |
ContainerState | current_container_state | ContainerState.CLOSED_UNLOCKED |
Entity | opening_entity | null |
Timer | distance_check_timer |
Methods ​
bool | requires_inventory_component() |
void | setup_for_interactable_objects( interactable: InteractableObject ) |
Array[LootRule] | get_legacy_loot_rules() |
bool | can_interact( player: Player ) |
void | start_interaction( player: Player ) |
void | end_interaction() |
String | get_interaction_prompt() |
void | change_container_state( new_state: ContainerState, interacting_entity: Entity = null ) |
void | on_object_destroyed() |
void | refresh_after_load() |
void | on_unlocked() |
void | on_locked_reaction() |
InventoryComponent | get_inventory() |
bool | is_empty() |
void | force_open() |
void | force_close() |
Dictionary | save_state() |
void | load_state( state: Dictionary ) |
void | cleanup() |
Signals ​
container_opened( entity: Entity ) ​
Emitted when an entity opens the container.
container_closed( entity: Entity ) ​
Emitted when the container is closed.
Enumerations ​
enum ContainerState ​
The states of a container: closed and unlocked, closed and locked, open, or destroyed.
- CLOSED_UNLOCKED =
0- Container is closed and can be opened - CLOSED_LOCKED =
1- Container is closed and locked - OPEN =
2- Container is open and accessible - DESTROYED =
3- Container is destroyed and inaccessible
Property descriptions ​
Container Setup
Dictionary inventory ​
Dictionary of inventory items and currency for this container Format: { "items": { item_id: quantity }, "currency": { currency_name: amount } }
int max_slots = 20 ​
Maximum number of inventory slots
InventoryStyle inventory_style = null ​
The rules of this container's bag (space, weight). Empty = the style of the containers of the Gameplay Config. In slots mode Max slots is the number of slots
Loot Generation
int loot_table_id ​
Loot table to generate items from (overrides definition loot_table if set)
Auto-Close
bool auto_close_enabled = true ​
Whether container auto-closes when opener moves away
float auto_close_distance = 4.0 ​
Distance at which container auto-closes
Animations
String closed_animation = "closed" ​
The animation of the container when it is closed.
String locked_animation = "locked" ​
The animation of the container when it is locked.
String open_animation = "open" ​
The animation of the container when it opens.
Audio
SFXSelection container_open_sound ​
The sound of the container opening.
SFXSelection container_close_sound ​
The sound of the container closing.
SFXSelection container_locked_sound ​
The sound of trying a locked container.
Variable descriptions ​
InventoryComponent inventory_data ​
The inventory of the container: what it holds.
ContainerState current_container_state = ContainerState.CLOSED_UNLOCKED ​
The state of the container now.
Entity opening_entity = null ​
The entity that has the container open now.
Timer distance_check_timer ​
The timer that closes the container when the entity that opened it walks away.
Method descriptions ​
bool requires_inventory_component() ​
Tell InteractableObject we need an InventoryComponent
void setup_for_interactable_objects( interactable: InteractableObject ) ​
Sets the container up on its object: finds the nodes it needs and applies its starting state.
Array[LootRule] get_legacy_loot_rules() ​
The loot rules the older settings of this container make: its fixed contents and its loot table, both rolled when the container is set up
bool can_interact( player: Player ) ​
Can the player use the container now (in range, the object is not broken, the requirements are met)?
void start_interaction( player: Player ) ​
The player uses the container.
void end_interaction() ​
Does nothing: a container stays open after the interaction ends.
String get_interaction_prompt() ​
The text of the prompt above the object for its state now ("Open", "Climb" ...).
void change_container_state( new_state: ContainerState, interacting_entity: Entity = null ) ​
Puts the container in a state (opening it, locking it ...) and plays its animation and sound.
void on_object_destroyed() ​
Called when the object is destroyed. A container that still holds something stays lootable, like a corpse.
void refresh_after_load() ​
After a load: a destroyed container with loot is lootable, an empty one is destroyed for good
void on_unlocked() ​
Called when the object is unlocked.
void on_locked_reaction() ​
Called when someone tries the object while it is locked: plays the locked sound and animation.
InventoryComponent get_inventory() ​
The inventory of the container.
bool is_empty() ​
Is the container empty?
void force_open() ​
Opens the container without a player (a script or an event). Not when it is destroyed.
void force_close() ​
Closes the container without a player.
Dictionary save_state() ​
The state of the container for a save.
void load_state( state: Dictionary ) ​
Restores the state of the container from a save.
void cleanup() ​
Gives its timers back and clears what it holds (the object is going away).