75 lines
1.6 KiB
GDScript
75 lines
1.6 KiB
GDScript
extends RefCounted
|
|
|
|
class_name Inventory
|
|
|
|
var items = []
|
|
var quantities = []
|
|
|
|
func clear():
|
|
items = []
|
|
quantities = []
|
|
|
|
func get_item_quantity_pair_array():
|
|
var duplicate = duplicate()
|
|
var pairedUpArray = []
|
|
for i in range(duplicate.items.size()):
|
|
var newPair = [duplicate.items[i], duplicate.quantities[i]]
|
|
pairedUpArray.append(newPair)
|
|
|
|
return pairedUpArray
|
|
|
|
func get_inventory_weight():
|
|
var weight = 0
|
|
for i in range(items.size()):
|
|
weight += items[i].get_weight() * quantities[i]
|
|
return weight
|
|
|
|
func get_item_count():
|
|
var count = 0
|
|
|
|
for quantity in quantities:
|
|
count += quantity
|
|
|
|
return count
|
|
|
|
func add_item(item:Item, quantity = 1):
|
|
var itemPosition = find_item_position(item)
|
|
|
|
#no other same items in inventory
|
|
if itemPosition == -1:
|
|
items.append(item)
|
|
quantities.append(quantity)
|
|
else:
|
|
quantities[itemPosition] += quantity
|
|
|
|
func remove_item(item:Item, quantity = 1):
|
|
var itemPosition = find_item_position(item)
|
|
|
|
if itemPosition != -1:
|
|
quantities[itemPosition] -= quantity
|
|
|
|
if quantities[itemPosition] <= 0:
|
|
items.remove_at(itemPosition)
|
|
quantities.remove_at(itemPosition)
|
|
|
|
func find_item_position(itemToFind:Item):
|
|
for i in range(items.size()):
|
|
if items[i].equals(itemToFind):
|
|
return i
|
|
return -1
|
|
|
|
func duplicate():
|
|
var newInventory = Inventory.new()
|
|
newInventory.items = items.duplicate(true)
|
|
newInventory.quantities = quantities.duplicate(true)
|
|
|
|
return newInventory
|
|
|
|
#call this
|
|
func jaco_function():
|
|
jaco_function()
|
|
|
|
#call this if you want to I guess
|
|
func ellie_function():
|
|
print("You are beautiful and I'm proud of you")
|