Files
DungeonsOfKharadum/src/scripts/item.gd
2026-01-24 02:25:41 +01:00

130 lines
3.1 KiB
GDScript

class_name Item
func _init(iDic: Dictionary = {}):
if iDic != {}:
self.load(iDic)
enum ItemType {
Restoration,
Equippable,
Throwable,
Bomb,
}
# only relevant for equipment
enum EquipmentType {
NONE,
MAINHAND,
OFFHAND,
HEADGEAR,
ARMOUR,
BOOTS,
ACCESSORY
}
enum WeaponType {
NONE,
AMMUNITION,
BOW,
SWORD,
AXE,
DAGGER,
STAFF,
SPEAR,
MACE,
SPELLBOOK,
BOMB
}
var use_function = null
var item_name: String = "Red Apple"
var description: String = "Restores 5 HP"
var spritePath: String = "res://assets/gfx/items_n_shit.png"
var equipmentPath: String = "res://assets/gfx/Puny-Characters/Layer 2 - Clothes/Basic Body/BasicRed.png"
var colorReplacements: Array = []
var spriteFrames:Vector2i = Vector2i(20,14)
var spriteFrame:int = 0
var modifiers: Dictionary = { "hp": +20 }
var duration: float = 0
var buy_cost: int = 10
var sell_worth: int = 3
var sellable:bool = true
var item_type: ItemType = ItemType.Restoration
var equipment_type: EquipmentType = EquipmentType.NONE
var weapon_type: WeaponType = WeaponType.NONE
var two_handed:bool = false
var quantity = 1
var can_have_multiple_of:bool = false
var weight: float = 2.0 # Item weight for encumbrance system (default 2.0 for equipment)
func save():
var json = {
"item_name": item_name,
"description": description,
"spritePath": spritePath,
"equipmentPath": equipmentPath,
"colorReplacements": colorReplacements,
"spriteFrame": spriteFrame,
"modifiers": modifiers,
"duration": duration,
"buy_cost": buy_cost,
"sell_worth": sell_worth,
"item_type": item_type,
"equipment_type": equipment_type,
"weapon_type": weapon_type,
"two_handed": two_handed,
"quantity": quantity,
"can_have_multiple_of": can_have_multiple_of,
"weight": weight
}
return json
func from_dict(iDic: Dictionary) -> Item:
self.load(iDic)
return self
func load(iDic: Dictionary):
if iDic.has("item_name"):
item_name = iDic.get("item_name")
if iDic.has("description"):
description = iDic.get("description")
if iDic.has("spritePath"):
spritePath = iDic.get("spritePath")
if iDic.has("equipmentPath"):
equipmentPath = iDic.get("equipmentPath")
#if iDic.has("spriteFrames"):
#spriteFrames = iDic.get("spriteFrames")
if iDic.has("spriteFrame"):
spriteFrame = iDic.get("spriteFrame")
if iDic.has("modifiers"):
modifiers = iDic.get("modifiers")
if iDic.has("duration"):
duration = iDic.get("duration")
if iDic.has("buy_cost"):
buy_cost = iDic.get("buy_cost")
if iDic.has("sell_worth"):
sell_worth = iDic.get("sell_worth")
if iDic.has("item_type"):
item_type = iDic.get("item_type")
if iDic.has("equipment_type"):
equipment_type = iDic.get("equipment_type")
if iDic.has("weapon_type"):
weapon_type = iDic.get("weapon_type")
if iDic.has("two_handed"):
two_handed = iDic.get("two_handed")
if iDic.has("quantity"):
quantity = iDic.get("quantity")
if iDic.has("can_have_multiple_of"):
can_have_multiple_of = iDic.get("can_have_multiple_of")
if iDic.has("weight"):
weight = iDic.get("weight")
if iDic.has("colorReplacements"):
colorReplacements = iDic.get("colorReplacements", [])
pass