Doing some more quest stuff
This commit is contained in:
@@ -19,11 +19,15 @@ const ITEM_STACK_SIZE_MAX = 99;
|
||||
|
||||
var contents:Array[ItemStack] = [];
|
||||
|
||||
func addItem(item:Item.ItemType, quantity: int = 1) -> void:
|
||||
func isPlayerInventory() -> bool:
|
||||
return self == ITEM.PLAYER_INVENTORY
|
||||
|
||||
func addItem(item:Item.Type, quantity: int = 1) -> void:
|
||||
if !Item.isStackable(item):
|
||||
# Item cannot be stacked, add each item to inv
|
||||
for i in range(quantity):
|
||||
contents.append(ItemStack.new(item, 1))
|
||||
_contentsUpdated()
|
||||
return
|
||||
|
||||
# Check for existing stacks
|
||||
@@ -35,6 +39,7 @@ func addItem(item:Item.ItemType, quantity: int = 1) -> void:
|
||||
|
||||
if quantity <= spaceAvailable:
|
||||
stack.quantity += quantity;
|
||||
_contentsUpdated()
|
||||
return
|
||||
|
||||
stack.quantity = ITEM_STACK_SIZE_MAX;
|
||||
@@ -45,8 +50,9 @@ func addItem(item:Item.ItemType, quantity: int = 1) -> void:
|
||||
var newStackQuantity = min(quantity, ITEM_STACK_SIZE_MAX);
|
||||
contents.append(ItemStack.new(item, newStackQuantity));
|
||||
quantity -= newStackQuantity;
|
||||
_contentsUpdated()
|
||||
|
||||
func removeItem(item:Item.ItemType, quantity:int) -> void:
|
||||
func removeItem(item:Item.Type, quantity:int) -> void:
|
||||
var totalQuantity = 0
|
||||
|
||||
# Calculate total quantity of the item in the inventory
|
||||
@@ -73,12 +79,13 @@ func removeItem(item:Item.ItemType, quantity:int) -> void:
|
||||
contents.erase(stack)
|
||||
|
||||
if quantity == 0:
|
||||
self._contentsUpdated()
|
||||
return
|
||||
|
||||
func removeStack(stack: ItemStack) -> void:
|
||||
self.removeItem(stack.item, stack.quantity);
|
||||
|
||||
func hasItem(item:Item.ItemType, quantity: int = 1) -> bool:
|
||||
func hasItem(item:Item.Type, quantity: int = 1) -> bool:
|
||||
var totalQuantity = 0
|
||||
|
||||
for stack in contents:
|
||||
@@ -99,4 +106,8 @@ func sortBy(by:ItemSortType) -> void:
|
||||
ItemSortType.TYPE:
|
||||
contents.sort_custom(ItemStackTypeComparator._sort)
|
||||
_:
|
||||
assert(false, "Invalid sort type: %s" % by)
|
||||
assert(false, "Invalid sort type: %s" % by)
|
||||
|
||||
func _contentsUpdated() -> void:
|
||||
if isPlayerInventory():
|
||||
QUEST.playerInventoryUpdated.emit()
|
||||
|
@@ -1,17 +1,17 @@
|
||||
class_name Item
|
||||
|
||||
enum ItemType {
|
||||
enum Type {
|
||||
POTION,
|
||||
ONION
|
||||
};
|
||||
|
||||
enum ItemCategory {
|
||||
enum Category {
|
||||
MEDICINE,
|
||||
KEY_ITEM,
|
||||
INGREDIENT
|
||||
};
|
||||
|
||||
static func isStackable(itemType:ItemType) -> bool:
|
||||
static func isStackable(itemType:Type) -> bool:
|
||||
match itemType:
|
||||
_:
|
||||
return true
|
||||
|
@@ -1,8 +1,8 @@
|
||||
class_name ItemStack
|
||||
|
||||
var item:Item.ItemType;
|
||||
var item:Item.Type;
|
||||
var quantity:int;
|
||||
|
||||
func _init(item:Item.ItemType, quantity:int = 1):
|
||||
func _init(item:Item.Type, quantity:int = 1):
|
||||
self.item = item;
|
||||
self.quantity = quantity;
|
||||
|
Reference in New Issue
Block a user