local Items = require(script.Parent.Items)
local Inventory = {}
local Inventories = {}
Inventory.__index = Inventory
function Inventory.new(userID, data)
if not userID then return end
local self = setmetatable(data or {}, Inventory)
self.MaxInventorySpace = self.MaxInventorySpace or 50
self.MaxStacks = self.MaxStacks or 1000
self.MaxExtraSpace = self.MaxExtraSpace or 25
self.ItemCount = self.ItemCount or 0
self.ExtraItemCount = self.ExtraItemCount or 0
self.Items = self.Items or {}
self.ExtraItems = self.ExtraItems or {}
Inventories[userID] = self
return self
end
function Inventory.AddItem(self, item, amount)
if type(item) ~= "table" or type(amount) ~= "number" then return end
if not Items[item.Name] or item.ID ~= Items[item.Name].ID then return end
local function sortExtraItems(item, amount) -- This function
--Worth?
end
local itemName = item.Name
local itemAmount = self.Items[itemName]
if item.Stackable and not itemAmount then -- If item is stackable and is not found in the inventory
self.ItemCount += 1
elseif not item.Stackable then -- If item is not stackable then no need to track if it needs to occupy a space
self.ItemCount += 1
end
if self.ItemCount > self.MaxInventorySpace then -- If itemCount exceeds the maximum invententory limit
self.ItemCount = self.MaxInventorySpace
-- This statement will use the sortExtraItems()
return
end
self.Items[itemName] = if itemAmount then itemAmount + amount else amount -- Finally the main purpose of this method
if self.Items[itemName] > self.MaxStacks and (self.ItemCount + 1 <= self.MaxInventorySpace) then -- If amount of stacked items exceeded the maxStacks limit
-- This statement will also use the sortExtraItems()
end
end
return Inventory
tbh I didnt think a simple add item to inventory would introduce alot of edge cases so so many ifs 😛