Item get event

This commit is contained in:
2025-05-19 07:10:17 -05:00
parent dd783174e8
commit f625415939
9 changed files with 44 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=14 format=3 uid="uid://dx6fv8n4jl5ku"]
[gd_scene load_steps=15 format=3 uid="uid://dx6fv8n4jl5ku"]
[ext_resource type="PackedScene" uid="uid://yhtpoum3eek7" path="res://scenes/Entities/Rosa.tscn" id="1_7b7hx"]
[ext_resource type="Script" uid="uid://c37crdel0m5mw" path="res://scripts/Map/Map.gd" id="1_ru75d"]
@@ -10,6 +10,7 @@
[ext_resource type="Script" uid="uid://y7ckj1tn5cro" path="res://scripts/Event/EventTextbox.gd" id="6_gxq5o"]
[ext_resource type="Script" uid="uid://c4d7nithqnx5y" path="res://scripts/Event/Quest/EventStartQuest.gd" id="7_brp0k"]
[ext_resource type="PackedScene" uid="uid://bkj630bhmnvsi" path="res://scenes/Entities/Sign.tscn" id="9_xfqoe"]
[ext_resource type="Script" uid="uid://b41umpbgqfuc2" path="res://scripts/Event/Item/EventGetItem.gd" id="10_avybc"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_e1h75"]
sky_horizon_color = Color(0.59625, 0.6135, 0.6375, 1)
@@ -85,5 +86,10 @@ text = "Thanks for closing the quest menu"
script = ExtResource("5_cg1ph")
metadata/_custom_type_script = "uid://tkfc88q8m86f"
[node name="ItemOnGround" parent="." instance=ExtResource("4_ejcqv")]
[node name="Get Item" type="Node" parent="Events"]
script = ExtResource("10_avybc")
metadata/_custom_type_script = "uid://b41umpbgqfuc2"
[node name="ItemOnGround" parent="." node_paths=PackedStringArray("interactEvent") instance=ExtResource("4_ejcqv")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.651626, 0.136824, -2.4978)
interactEvent = NodePath("../Events/Get Item")

View File

@@ -1,8 +1,6 @@
class_name ItemOnGround extends StaticBody3D
@export var itemType:Item.ItemType = Item.ItemType.POTION;
@export var quantity:int = 1;
@export var inventory:Inventory = null
@export var interactEvent:Event = null
func _ready() -> void:
$Entity/EntityInteractable.onInteract.connect(
@@ -14,12 +12,16 @@ func _exit_tree() -> void:
self.onEntityInteract
)
func selfDispose() -> void:
get_parent().remove_child(self)
self.queue_free()
func onEntityInteract(
interactor:EntityInteractor,
interactee:EntityInteractable
) -> void:
ITEM.PLAYER_INVENTORY.addItem(ITEM.ONION);
# Dispose self
get_parent().remove_child(self)
self.queue_free()
if interactEvent == null || (interactEvent.started && !interactEvent.isDone()):
return
interactEvent.onEntityInteract(interactor, $Entity/EntityInteractable)
self.selfDispose()

View File

@@ -1,9 +1,5 @@
class_name EventGetItem extends Event
@export var itemType:Item.ItemType = Item.ItemType.POTION
@export var quantity:int = 1
@export var inventory:Inventory = null
class_name EventGetItem extends "res://scripts/Event/Item/EventItem.gd"
func start() -> void:
super.start()
ITEM.
getInventory().addItem(itemType, quantity)

View File

@@ -0,0 +1 @@
uid://b41umpbgqfuc2

View File

@@ -0,0 +1,11 @@
class_name EventItem extends Event
const Inventory = preload("res://scripts/Item/Inventory.gd")
@export var itemType:Item.ItemType = Item.ItemType.POTION
@export var quantity:int = 1
var inventory:Inventory = null
func getInventory() -> Inventory:
if inventory == null:
inventory = ITEM.PLAYER_INVENTORY
return inventory

View File

@@ -0,0 +1 @@
uid://bgd2nkg5ni2et

View File

@@ -19,8 +19,8 @@ const ITEM_STACK_SIZE_MAX = 99;
var contents:Array[ItemStack] = [];
func addItem(item: Item, quantity: int = 1) -> void:
if !item.isStackable():
func addItem(item:Item.ItemType, quantity: int = 1) -> void:
if !Item.isStackable(item):
# Item cannot be stacked, add each item to inv
for i in range(quantity):
contents.append(ItemStack.new(item, 1))
@@ -46,7 +46,7 @@ func addItem(item: Item, quantity: int = 1) -> void:
contents.append(ItemStack.new(item, newStackQuantity));
quantity -= newStackQuantity;
func removeItem(item: Item, quantity: int) -> void:
func removeItem(item:Item.ItemType, quantity:int) -> void:
var totalQuantity = 0
# Calculate total quantity of the item in the inventory
@@ -78,7 +78,7 @@ func removeItem(item: Item, quantity: int) -> void:
func removeStack(stack: ItemStack) -> void:
self.removeItem(stack.item, stack.quantity);
func hasItem(item: Item, quantity: int = 1) -> bool:
func hasItem(item:Item.ItemType, quantity: int = 1) -> bool:
var totalQuantity = 0
for stack in contents:

View File

@@ -11,6 +11,11 @@ enum ItemCategory {
INGREDIENT
};
static func isStackable(itemType:ItemType) -> bool:
match itemType:
_:
return true
# func getName() -> String:
# push_error("getName() must be overridden in derived classes");
# return "";

View File

@@ -1,8 +1,8 @@
class_name ItemStack
var item:Item;
var item:Item.ItemType;
var quantity:int;
func _init(item:Item, quantity:int = 1):
func _init(item:Item.ItemType, quantity:int = 1):
self.item = item;
self.quantity = quantity;