--[[ A simple inventory that holds 1 item ]] --local itm = nrequire("item.lua") --local ste = nrequire("utility/stream.lua") local inventory = nrequire("inventory/inventory.lua") local log = nrequire("log.lua") --local col = nrequire("config/colortheme.lua") local sc = nrequire("skills/sh_skillcommon.lua") local inv = {} if CLIENT then inv = nrequire("cl_skills.lua") end --TODO: uncomment these as their minigames are implemented inv.allskills = {} --[[ ["forageing"] = { -- "Hunting", -- "Butchering", -- "Woodcutting", -- "plant identification", -- "archery", -- "fishing", -- "Mineing", }, ["farming"] = { -- "domestication", -- "sowing", -- "arboriculture", -- "apiarism", -- "reaping", }, ["artisanship"] = { "pottery", "glass blowing", "cooking", "tanning", "tailoring", "metalworking", "lockpicking", "herbalism", "alchemy", "jewlery", "fletching", "carpentry", }, ["culture"] = { "litteracy", "writeing", "speech", "negotiation", "painting", "performing", "faith", "engraving", "architect", }, ["adventuring"] = { "evasion", "traveling", "lockpicking", "willpower", "dexterity", "swimming", "sailing", }, ["fighting"] = { "polearm", "axeplay", "two-handed", "sword & shield", "light armor", "heavy armor", "knifeing", "fenceing", "throwing", "archery", } } ]] inv.Name = "Skills" inv.skills = {} local function calculate_skills() for k,v in pairs(sc.SkillList()) do for i,j in pairs(v) do print("settings inv's skills' ", j, " to 0") inv.skills[j] = 0 end end print("After calculating skills, inv was") PrintTable(inv) end calculate_skills() --[[ item should be { name = "name", ammt = 12.3, isskill = True } ]] inv.FindPlaceFor = function(self, item) print("finding place for ") PrintTable(item) if not item.isskill then return nil end print("Skill inventory trying to find place for, looking in ") PrintTable(inv.skills) print("for") print(item.name) if inv.skills[item.name] then return {item.name} else return nil end end inv.CanFitIn = function(self,position,item) return sc.SkillList()[position[1]] != nil end inv.Put = function(self,position,item) print("item is") PrintTable(item) self.skills[position[1]] = (self.skills[position[1]] or 0) + item.ammt end inv.Has = function(self,string_or_compare_func) local socf = string_or_compare_func if type(socf) == "string" and self.skills[socf] then return self.skills[socf] elseif type(socf) == "function" then for k,v in pairs(self.skills) do if socf(v) then return k end end else return nil end end inv.Remove = function(self,position) error("Tried to call remove on skill inventory") end inv.Get = function(self,position) return self.skills[position[1]] end inv.Serialize = function(self) return util.TableToJSON(self.skills) end inv.DeSerialize = function(self,data) if data == nil or data == '' then return table.Copy(inv) end calculate_skills() print("At the time we deserialized, sc.skilllist was") PrintTable(sc.SkillList()) print("Before making a copy of, inv is") PrintTable(inv) local cpy = table.Copy(self) local gen = util.JSONToTable(data) for k,v in pairs(gen) do cpy.skills[k] = v end print("AFter deserializing inventory, it is") PrintTable(cpy) return cpy end inventory.RegisterInventory(inv)