From 1bce56231c8f6b6b6269f1ff04d69e2414431bdc Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Tue, 20 May 2025 21:34:52 -0500 Subject: [PATCH] prog --- scenes/Maps/TestMap/TestMap.tscn | 4 +- scenes/Singletons/Recipe.tscn | 18 ++++++- scripts/Cooking/Recipe.gd | 30 +++++++++-- scripts/Cooking/RecipeIngredient.gd | 4 -- scripts/Event/Item/EventGetItem.gd | 4 +- scripts/Event/Quest/EventStartQuest.gd | 3 ++ scripts/Item/Inventory.gd | 2 +- scripts/Item/Item.gd | 75 +++++++++++++++++--------- scripts/Item/ItemResource.gd | 4 ++ scripts/Item/ItemResource.gd.uid | 1 + scripts/UI/Inventory/ItemLine.gd | 2 +- 11 files changed, 107 insertions(+), 40 deletions(-) delete mode 100644 scripts/Cooking/RecipeIngredient.gd create mode 100644 scripts/Item/ItemResource.gd create mode 100644 scripts/Item/ItemResource.gd.uid diff --git a/scenes/Maps/TestMap/TestMap.tscn b/scenes/Maps/TestMap/TestMap.tscn index dda543d..283e4dc 100644 --- a/scenes/Maps/TestMap/TestMap.tscn +++ b/scenes/Maps/TestMap/TestMap.tscn @@ -46,7 +46,7 @@ interactEvent = NodePath("../../Events/TestConversation") [node name="ItemOnGround" parent="Entities" instance=ExtResource("4_ejcqv")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.546944, -0.547748, -3.46628) -itemType = 1 +itemType = 2 quantity = 2 [node name="Map" type="Node3D" parent="."] @@ -106,7 +106,7 @@ metadata/_custom_type_script = "uid://c4d7nithqnx5y" [node name="Text 1" type="Node" parent="Events/TestConversation/Before Quest STarted"] script = ExtResource("6_gxq5o") -text = "Thanks for closing the quest menu" +text = "Take this potion to help you on your way." [node name="Get Item" type="Node" parent="Events/TestConversation/Before Quest STarted"] script = ExtResource("10_avybc") diff --git a/scenes/Singletons/Recipe.tscn b/scenes/Singletons/Recipe.tscn index 51e772c..878ec96 100644 --- a/scenes/Singletons/Recipe.tscn +++ b/scenes/Singletons/Recipe.tscn @@ -1,7 +1,20 @@ -[gd_scene load_steps=3 format=3 uid="uid://1l0tymk8cfxu"] +[gd_scene load_steps=6 format=3 uid="uid://1l0tymk8cfxu"] [ext_resource type="Script" uid="uid://j87s6jrx8unn" path="res://scripts/Singleton/Recipe.gd" id="1_o4nv4"] [ext_resource type="Script" uid="uid://dipvg4uwjv6p2" path="res://scripts/Cooking/Recipe.gd" id="2_f5akq"] +[ext_resource type="Script" uid="uid://c26aptwsjs044" path="res://scripts/Item/ItemResource.gd" id="3_b8y03"] + +[sub_resource type="Resource" id="Resource_3dxl6"] +script = ExtResource("3_b8y03") +itemType = 2 +count = 1 +metadata/_custom_type_script = "uid://c26aptwsjs044" + +[sub_resource type="Resource" id="Resource_b8y03"] +script = ExtResource("3_b8y03") +itemType = 1 +count = 1 +metadata/_custom_type_script = "uid://c26aptwsjs044" [node name="RecipeSystem" type="Node"] script = ExtResource("1_o4nv4") @@ -10,4 +23,7 @@ metadata/_custom_type_script = "uid://j87s6jrx8unn" [node name="Ash-Baked Sweet Potato" type="Node" parent="."] script = ExtResource("2_f5akq") recipeName = "Ash-Baked Sweet Potato" +recipeDescription = "Tender, warm, and sweet meal, made by baking a sweet potato in campfire embers. Comforting, simple, and gently filling." +ingredients = Array[ExtResource("3_b8y03")]([SubResource("Resource_3dxl6")]) +outputs = Array[ExtResource("3_b8y03")]([SubResource("Resource_b8y03")]) metadata/_custom_type_script = "uid://dipvg4uwjv6p2" diff --git a/scripts/Cooking/Recipe.gd b/scripts/Cooking/Recipe.gd index 83d8f15..91489d7 100644 --- a/scripts/Cooking/Recipe.gd +++ b/scripts/Cooking/Recipe.gd @@ -1,8 +1,30 @@ -@tool class_name Recipe extends Node @export var recipeName:String = "" -@export var ingredients:Array[RecipeIngredient] = [] +@export var ingredients:Array[ItemResource] = [] +@export var outputs:Array[ItemResource] = [] -func test(): - print("test") \ No newline at end of file +var learned:bool = false +var timesMade:int = 0 + +func hasIngredients(inventory:Inventory = null) -> bool: + if inventory == null: + inventory = ITEM.PLAYER_INVENTORY + + for ingredient in ingredients: + if !inventory.hasItem(ingredient.type, ingredient.quantity): + return false + return true + +func make(inventory:Inventory = null) -> void: + if inventory == null: + inventory = ITEM.PLAYER_INVENTORY + + for ingredient in ingredients: + inventory.removeItem(ingredient.type, ingredient.quantity) + + for output in outputs: + inventory.addItem(output.type, output.quantity) + + + timesMade += 1 \ No newline at end of file diff --git a/scripts/Cooking/RecipeIngredient.gd b/scripts/Cooking/RecipeIngredient.gd deleted file mode 100644 index ee70d53..0000000 --- a/scripts/Cooking/RecipeIngredient.gd +++ /dev/null @@ -1,4 +0,0 @@ -class_name RecipeIngredient extends Resource - -@export var thing:int = 0 -@export var count:int = 1 \ No newline at end of file diff --git a/scripts/Event/Item/EventGetItem.gd b/scripts/Event/Item/EventGetItem.gd index b44a5eb..3db0fba 100644 --- a/scripts/Event/Item/EventGetItem.gd +++ b/scripts/Event/Item/EventGetItem.gd @@ -18,9 +18,9 @@ func start() -> void: var text:String = ""; match getType: GetType.FOUND: - text = "Found " + str(quantity) + " " + Item.getName(itemType, quantity) + "."; + text = "Found " + str(quantity) + " " + Item.getItemName(itemType, quantity) + "."; GetType.GIVEN: - text = "Received " + str(quantity) + " " + Item.getName(itemType, quantity) + "."; + text = "Received " + str(quantity) + " " + Item.getItemName(itemType, quantity) + "."; _: pass VN.getTextbox().setText(text); diff --git a/scripts/Event/Quest/EventStartQuest.gd b/scripts/Event/Quest/EventStartQuest.gd index a9de778..8b09473 100644 --- a/scripts/Event/Quest/EventStartQuest.gd +++ b/scripts/Event/Quest/EventStartQuest.gd @@ -1,5 +1,8 @@ class_name EventStartQuest extends "res://scripts/Event/Quest/EventShowQuest.gd" +@export_category("Event Start Quest") +var nothing:bool = false + func start(): assert(QUEST.quests.has(quest), "Quest not found.") QUEST.quests[quest].start() diff --git a/scripts/Item/Inventory.gd b/scripts/Item/Inventory.gd index 8da59f5..33ff9d5 100644 --- a/scripts/Item/Inventory.gd +++ b/scripts/Item/Inventory.gd @@ -7,7 +7,7 @@ enum ItemSortType { class ItemStackNameComparator: static func _sort(a, b): - return a.item.getName().to_lower() < b.item.getName().to_lower() + return Item.getItemName(a).to_lower() < Item.getItemName(b).to_lower() class ItemStackTypeComparator: static func _sort(a, b): diff --git a/scripts/Item/Item.gd b/scripts/Item/Item.gd index 99195ba..bcafd74 100644 --- a/scripts/Item/Item.gd +++ b/scripts/Item/Item.gd @@ -1,14 +1,22 @@ class_name Item enum Type { - POTION, - ONION + # Items + POTION = 1, + + # Ingredients + ONION = 2, + SWEET_POTATO = 3, + + # Recipe outputs + ASH_BAKED_SWEET_POTATO = 4, }; enum Category { MEDICINE, KEY_ITEM, - INGREDIENT + INGREDIENT, + FOOD }; static func isStackable(itemType:Type) -> bool: @@ -17,7 +25,7 @@ static func isStackable(itemType:Type) -> bool: _: return true -static func getName(itemType:Type, count:int = 1) -> String: +static func getItemName(itemType:Type, count:int = 1) -> String: match itemType: Type.POTION: if count != 1: @@ -29,35 +37,52 @@ static func getName(itemType:Type, count:int = 1) -> String: return "Onions" return "Onion" + Type.SWEET_POTATO: + if count != 1: + return "Sweet Potatoes" + return "Sweet Potato" + + Type.ASH_BAKED_SWEET_POTATO: + if count != 1: + return "Ash-Baked Sweet Potatoes" + return "Ash-Baked Sweet Potato" + _: assert(false, "Invalid item type") return "" -# func getName() -> String: -# push_error("getName() must be overridden in derived classes"); -# return ""; +static func getItemDescription(itemType:Type) -> String: + match itemType: + Type.POTION: + return "A potent healing drink, infused with magical properties. Restores health and stamina." -# func isStackable() -> bool: -# return true; + Type.ONION: + return "A common vegetable, known for its strong flavor and aroma. Can be used in cooking." -# func isDroppable() -> bool: -# return true; + Type.SWEET_POTATO: + return "A nutritious root vegetable, sweet and starchy. Can be used in cooking." -# func isSellable() -> bool: -# return true; + Type.ASH_BAKED_SWEET_POTATO: + return "Tender, warm, and sweet meal, made by baking a sweet potato in campfire embers. Comforting, simple, and gently filling." -# func getSellPrice() -> int: -# return 0; + _: + assert(false, "Invalid item type") + return "" -# func getBuyPrice() -> int: -# return 0; +static func getItemCategory(itemType:Type) -> Category: + match itemType: + Type.POTION: + return Category.MEDICINE -# func isConsumable() -> bool: -# return false; + Type.ONION: + return Category.INGREDIENT -# func consume() -> void: -# pass - -# func getCategory() -> ItemCategory: -# push_error("getCategory() must be overriden in derived class"); -# return ItemCategory.MEDICINE; \ No newline at end of file + Type.SWEET_POTATO: + return Category.INGREDIENT + + Type.ASH_BAKED_SWEET_POTATO: + return Category.FOOD + + _: + assert(false, "Invalid item type") + return Category.KEY_ITEM diff --git a/scripts/Item/ItemResource.gd b/scripts/Item/ItemResource.gd new file mode 100644 index 0000000..e32af0d --- /dev/null +++ b/scripts/Item/ItemResource.gd @@ -0,0 +1,4 @@ +class_name ItemResource extends Resource + +@export var itemType:Item.Type = Item.Type.ONION; +@export var count:int = 1; \ No newline at end of file diff --git a/scripts/Item/ItemResource.gd.uid b/scripts/Item/ItemResource.gd.uid new file mode 100644 index 0000000..45a2954 --- /dev/null +++ b/scripts/Item/ItemResource.gd.uid @@ -0,0 +1 @@ +uid://c26aptwsjs044 diff --git a/scripts/UI/Inventory/ItemLine.gd b/scripts/UI/Inventory/ItemLine.gd index d5a832a..e481b28 100644 --- a/scripts/UI/Inventory/ItemLine.gd +++ b/scripts/UI/Inventory/ItemLine.gd @@ -1,5 +1,5 @@ class_name ItemLine extends HBoxContainer func setStack(stack:ItemStack) -> void: - $ItemName.text = Item.getName(stack.type, 1) + $ItemName.text = Item.getItemName(stack.type, 1) $ItemQuantity.text = str(stack.quantity)