Item get event
This commit is contained in:
@@ -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="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"]
|
[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://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="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="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"]
|
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_e1h75"]
|
||||||
sky_horizon_color = Color(0.59625, 0.6135, 0.6375, 1)
|
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")
|
script = ExtResource("5_cg1ph")
|
||||||
metadata/_custom_type_script = "uid://tkfc88q8m86f"
|
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)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.651626, 0.136824, -2.4978)
|
||||||
|
interactEvent = NodePath("../Events/Get Item")
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
class_name ItemOnGround extends StaticBody3D
|
class_name ItemOnGround extends StaticBody3D
|
||||||
|
|
||||||
@export var itemType:Item.ItemType = Item.ItemType.POTION;
|
@export var interactEvent:Event = null
|
||||||
@export var quantity:int = 1;
|
|
||||||
@export var inventory:Inventory = null
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
$Entity/EntityInteractable.onInteract.connect(
|
$Entity/EntityInteractable.onInteract.connect(
|
||||||
@@ -14,12 +12,16 @@ func _exit_tree() -> void:
|
|||||||
self.onEntityInteract
|
self.onEntityInteract
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func selfDispose() -> void:
|
||||||
|
get_parent().remove_child(self)
|
||||||
|
self.queue_free()
|
||||||
|
|
||||||
func onEntityInteract(
|
func onEntityInteract(
|
||||||
interactor:EntityInteractor,
|
interactor:EntityInteractor,
|
||||||
interactee:EntityInteractable
|
interactee:EntityInteractable
|
||||||
) -> void:
|
) -> void:
|
||||||
ITEM.PLAYER_INVENTORY.addItem(ITEM.ONION);
|
if interactEvent == null || (interactEvent.started && !interactEvent.isDone()):
|
||||||
|
return
|
||||||
# Dispose self
|
|
||||||
get_parent().remove_child(self)
|
interactEvent.onEntityInteract(interactor, $Entity/EntityInteractable)
|
||||||
self.queue_free()
|
self.selfDispose()
|
||||||
|
@@ -1,9 +1,5 @@
|
|||||||
class_name EventGetItem extends Event
|
class_name EventGetItem extends "res://scripts/Event/Item/EventItem.gd"
|
||||||
|
|
||||||
@export var itemType:Item.ItemType = Item.ItemType.POTION
|
|
||||||
@export var quantity:int = 1
|
|
||||||
@export var inventory:Inventory = null
|
|
||||||
|
|
||||||
func start() -> void:
|
func start() -> void:
|
||||||
super.start()
|
super.start()
|
||||||
ITEM.
|
getInventory().addItem(itemType, quantity)
|
1
scripts/Event/Item/EventGetItem.gd.uid
Normal file
1
scripts/Event/Item/EventGetItem.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://b41umpbgqfuc2
|
11
scripts/Event/Item/EventItem.gd
Normal file
11
scripts/Event/Item/EventItem.gd
Normal 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
|
1
scripts/Event/Item/EventItem.gd.uid
Normal file
1
scripts/Event/Item/EventItem.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bgd2nkg5ni2et
|
@@ -19,8 +19,8 @@ const ITEM_STACK_SIZE_MAX = 99;
|
|||||||
|
|
||||||
var contents:Array[ItemStack] = [];
|
var contents:Array[ItemStack] = [];
|
||||||
|
|
||||||
func addItem(item: Item, quantity: int = 1) -> void:
|
func addItem(item:Item.ItemType, quantity: int = 1) -> void:
|
||||||
if !item.isStackable():
|
if !Item.isStackable(item):
|
||||||
# Item cannot be stacked, add each item to inv
|
# Item cannot be stacked, add each item to inv
|
||||||
for i in range(quantity):
|
for i in range(quantity):
|
||||||
contents.append(ItemStack.new(item, 1))
|
contents.append(ItemStack.new(item, 1))
|
||||||
@@ -46,7 +46,7 @@ func addItem(item: Item, quantity: int = 1) -> void:
|
|||||||
contents.append(ItemStack.new(item, newStackQuantity));
|
contents.append(ItemStack.new(item, newStackQuantity));
|
||||||
quantity -= newStackQuantity;
|
quantity -= newStackQuantity;
|
||||||
|
|
||||||
func removeItem(item: Item, quantity: int) -> void:
|
func removeItem(item:Item.ItemType, quantity:int) -> void:
|
||||||
var totalQuantity = 0
|
var totalQuantity = 0
|
||||||
|
|
||||||
# Calculate total quantity of the item in the inventory
|
# 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:
|
func removeStack(stack: ItemStack) -> void:
|
||||||
self.removeItem(stack.item, stack.quantity);
|
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
|
var totalQuantity = 0
|
||||||
|
|
||||||
for stack in contents:
|
for stack in contents:
|
||||||
|
@@ -11,6 +11,11 @@ enum ItemCategory {
|
|||||||
INGREDIENT
|
INGREDIENT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static func isStackable(itemType:ItemType) -> bool:
|
||||||
|
match itemType:
|
||||||
|
_:
|
||||||
|
return true
|
||||||
|
|
||||||
# func getName() -> String:
|
# func getName() -> String:
|
||||||
# push_error("getName() must be overridden in derived classes");
|
# push_error("getName() must be overridden in derived classes");
|
||||||
# return "";
|
# return "";
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
class_name ItemStack
|
class_name ItemStack
|
||||||
|
|
||||||
var item:Item;
|
var item:Item.ItemType;
|
||||||
var quantity:int;
|
var quantity:int;
|
||||||
|
|
||||||
func _init(item:Item, quantity:int = 1):
|
func _init(item:Item.ItemType, quantity:int = 1):
|
||||||
self.item = item;
|
self.item = item;
|
||||||
self.quantity = quantity;
|
self.quantity = quantity;
|
||||||
|
Reference in New Issue
Block a user