It's Cow Game! Version 2.04!
This commit is contained in:
commit
a9e1ed9ddd
3148 changed files with 95332 additions and 0 deletions
74
Inventory/Inventory.gd
Normal file
74
Inventory/Inventory.gd
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
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")
|
||||
118
Inventory/InventoryManager.gd
Normal file
118
Inventory/InventoryManager.gd
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
extends Node
|
||||
|
||||
signal playerInventoryUpdated
|
||||
|
||||
var grapeScene = preload("res://Items/Foods/Fruits/Grape.gd")
|
||||
|
||||
var inventories = {}
|
||||
|
||||
func _ready():
|
||||
initialize_inventory()
|
||||
playerInventoryUpdated.emit()
|
||||
|
||||
func clear_all_inventories():
|
||||
inventories = {}
|
||||
initialize_inventory()
|
||||
playerInventoryUpdated.emit()
|
||||
|
||||
func empty_inventory(inventoryName:String = "normal"):
|
||||
inventories[inventoryName] = Inventory.new()
|
||||
|
||||
func spend_item(item:Item, quantity:int = 1, inventoryName:String = "normal"):
|
||||
if !check_if_in_inventory(item, quantity, inventoryName):
|
||||
return false
|
||||
else:
|
||||
remove_item_from_inventory(item, quantity, inventoryName)
|
||||
return true
|
||||
|
||||
func check_if_in_inventory(item:Item, quantity:int = 1, inventoryName:String = "normal"):
|
||||
var currentInventory = inventories[inventoryName]
|
||||
|
||||
var itemPos = currentInventory.find_item_position(item)
|
||||
if itemPos < 0 or currentInventory.quantities[itemPos] < quantity:
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
func get_inventory_weight(inventoryName = "normal"):
|
||||
var currentInventory = inventories[inventoryName]
|
||||
return currentInventory.get_inventory_weight()
|
||||
|
||||
func get_item_count(item, inventoryName = "normal", modifiers = false):
|
||||
var currentInventory = inventories[inventoryName]
|
||||
|
||||
var itemPos = currentInventory.find_item_position(item)
|
||||
if itemPos < 0:
|
||||
return 0
|
||||
|
||||
return currentInventory.quantities[itemPos]
|
||||
|
||||
func get_item_count_by_name(itemName, inventoryName = "normal", modifiers = false):
|
||||
var currentInventory = inventories[inventoryName]
|
||||
|
||||
for i in range(currentInventory.items.size()):
|
||||
var currentItemName = currentInventory.items[i].get_name(modifiers)
|
||||
if currentItemName == itemName:
|
||||
return currentInventory.quantities[i]
|
||||
return 0
|
||||
|
||||
func add_item_to_inventory(item:Item, quantity:int = 1, inventoryName:String = "normal", skipEmit:bool = false):
|
||||
if not inventoryName in inventories.keys():
|
||||
create_inventory(inventoryName)
|
||||
|
||||
var currentInventory = inventories[inventoryName]
|
||||
|
||||
currentInventory.add_item(item, quantity)
|
||||
if !skipEmit:
|
||||
playerInventoryUpdated.emit()
|
||||
|
||||
func remove_item_from_inventory(item:Item, quantity:int = 1, inventoryName:String = "normal"):
|
||||
var currentInventory = inventories[inventoryName]
|
||||
|
||||
currentInventory.remove_item(item, quantity)
|
||||
playerInventoryUpdated.emit()
|
||||
|
||||
func soak_player_inventory():
|
||||
var currentInventory = inventories["normal"]
|
||||
ItemSoaking.soak_inventory(currentInventory)
|
||||
playerInventoryUpdated.emit()
|
||||
|
||||
func dry_player_inventory(amount:int = 1):
|
||||
var currentInventory = inventories["normal"]
|
||||
ItemDrying.dry_inventory_items(currentInventory, amount)
|
||||
playerInventoryUpdated.emit()
|
||||
|
||||
func get_grape_count():
|
||||
var currentInventory = inventories["normal"]
|
||||
|
||||
var grape = grapeScene.new()
|
||||
for i in range(currentInventory.items.size()):
|
||||
if currentInventory.items[i].equals(grape):
|
||||
return currentInventory.quantities[i]
|
||||
return 0
|
||||
|
||||
func alter_grape_count(amount:int):
|
||||
var grape = grapeScene.new()
|
||||
|
||||
if amount > 0:
|
||||
add_item_to_inventory(grape, amount)
|
||||
elif amount < 0:
|
||||
remove_item_from_inventory(grape, -1*amount)
|
||||
|
||||
func get_all_inventories():
|
||||
return inventories
|
||||
|
||||
func create_inventory(inventoryName:String):
|
||||
if not inventoryName in inventories.keys():
|
||||
inventories[inventoryName] = Inventory.new()
|
||||
|
||||
func initialize_inventory():
|
||||
inventories["normal"] = Inventory.new()
|
||||
inventories["keyItems"] = Inventory.new()
|
||||
|
||||
func get_inventory(inventoryName:String = "normal"):
|
||||
if not inventoryName in inventories.keys():
|
||||
create_inventory(inventoryName)
|
||||
|
||||
return inventories[inventoryName]
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue