aboutsummaryrefslogtreecommitdiff
path: root/gamemode/inventorysystem/equipment
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/inventorysystem/equipment')
-rw-r--r--gamemode/inventorysystem/equipment/cl_equipment.lua140
-rw-r--r--gamemode/inventorysystem/equipment/sh_equipment.lua180
-rw-r--r--gamemode/inventorysystem/equipment/sv_equipment.lua5
3 files changed, 325 insertions, 0 deletions
diff --git a/gamemode/inventorysystem/equipment/cl_equipment.lua b/gamemode/inventorysystem/equipment/cl_equipment.lua
new file mode 100644
index 0000000..5ffcccc
--- /dev/null
+++ b/gamemode/inventorysystem/equipment/cl_equipment.lua
@@ -0,0 +1,140 @@
+
+local col = nrequire("colortheme.lua")
+local svg = nrequire("cl_svg.lua")
+local inv = {}
+
+local width, height = (ScrW() / 4) - 25, ScrH()
+local iconsize = width / 5
+
+local ringmat = svg.MaterialFromSVG("materials/svg/delapouite/originals/svg/000000/transparent/ring.svg")
+
+--Positions for the eqipment inventory
+local eqp = {
+ ["Head"] = {
+ x = (width / 2) - (iconsize / 2),
+ y = 0,
+ img = svg.MaterialFromSVG("materials/svg/lorc/originals/svg/000000/transparent/cracked-helm.svg"),
+ },
+ ["Shoulders"] = {
+ x = (width / 2) - (iconsize / 2),
+ y = iconsize,
+ img = svg.MaterialFromSVG("materials/svg/skoll/originals/svg/000000/transparent/pauldrons.svg")
+ },
+ ["Chest"] = {
+ x = width / 2,
+ y = iconsize * 2,
+ img = svg.MaterialFromSVG("materials/svg/willdabeast/deviations/svg/000000/transparent/chain-mail.svg")
+ },
+ ["Back"] = {
+ x = (width / 2) - iconsize,
+ y = iconsize * 2,
+ img = svg.MaterialFromSVG("materials/svg/lorc/originals/svg/000000/transparent/knapsack.svg"),
+ },
+ ["Arms"] = {
+ x = (width / 2) - (iconsize / 2),
+ y = iconsize * 3,
+ img = svg.MaterialFromSVG("materials/svg/skoll/originals/svg/000000/transparent/bracers.svg")
+ },
+ ["Belt"] = {
+ x = (width / 2) - (iconsize * 1.5),
+ y = iconsize * 3,
+ img = svg.MaterialFromSVG("materials/svg/lucasms/equipment/svg/000000/transparent/belt.svg")
+ },
+ ["Gloves"] = {
+ x = (width / 2) + (iconsize / 2),
+ y = iconsize * 3,
+ img = svg.MaterialFromSVG("materials/svg/delapouite/originals/svg/000000/transparent/gloves.svg")
+ },
+ ["Left Hand"] = {
+ x = width / 2,
+ y = iconsize * 4,
+ img = svg.MaterialFromSVG("materials/svg/sbed/originals/svg/000000/transparent/shield.svg")
+ },
+ ["Right Hand"] = {
+ x = (width / 2) - iconsize,
+ y = iconsize * 4,
+ img = svg.MaterialFromSVG("materials/svg/delapouite/originals/svg/000000/transparent/thor-hammer.svg")
+ },
+ ["Legs"] = {
+ x = (width / 2) - iconsize,
+ y = iconsize * 5,
+ img = svg.MaterialFromSVG("materials/svg/irongamer/originals/svg/000000/transparent/armored-pants.svg")
+ },
+ ["Feet"] = {
+ x = width / 2,
+ y = iconsize * 5,
+ img = svg.MaterialFromSVG("materials/svg/lorc/originals/svg/000000/transparent/boots.svg"),
+ },
+ ["Ring 1"] = {
+ x = 0,
+ y = iconsize,
+ img = ringmat
+ },
+ ["Ring 2"] = {
+ x = width - iconsize,
+ y = iconsize,
+ img = ringmat
+ },
+ ["Ring 3"] = {
+ x = 0,
+ y = iconsize * 2.5,
+ img = ringmat
+ },
+ ["Ring 4"] = {
+ x = width - iconsize,
+ y = iconsize * 2.5,
+ img = ringmat
+ },
+ ["Ring 5"] = {
+ x = 0,
+ y = iconsize * 4,
+ img = ringmat
+ },
+ ["Ring 6"] = {
+ x = width - iconsize,
+ y = iconsize * 4,
+ img = ringmat
+ },
+}
+
+inv.DrawOnDPanel = function(self,panel)
+ local prox = {}
+ for k,v in pairs(eqp) do
+ local pn = vgui.Create("DImage",panel)
+ pn:SetSize(iconsize,iconsize)
+ pn:SetPos(v.x,v.y)
+ if self.equiped[k] then
+ if self.equiped[k].OnPaint then
+ pn.Paint = self.equiped[k].OnPaint
+ else
+ pn.Paint = function(tp,w,h)
+ draw.RoundedBox( 8, 0, 0, w, h, Color( 255, 0, 0 ) )
+ end
+ end
+ else
+ if v.img and v.img.material then
+ local c = col.ui.border
+ pn.Paint = function(tp,w,h)
+ surface.SetDrawColor(c.r,c.g,c.b)
+ surface.DrawOutlinedRect(0, 0, w, h)
+ surface.SetDrawColor(255,255,255)
+ surface.SetMaterial( v.img.material )
+ surface.DrawTexturedRect( 0, 0, w, h )
+ end
+ else
+ pn.Paint = function(tp,w,h)
+ draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 0, 0 ) )
+ end
+ end
+ end
+ prox[k] = pn
+ end
+ prox.Put = function(position,item)
+ print("Put was called!")
+ end
+ prox.Remove = function(position)
+ print("Remove was called!")
+ end
+end
+
+return inv
diff --git a/gamemode/inventorysystem/equipment/sh_equipment.lua b/gamemode/inventorysystem/equipment/sh_equipment.lua
new file mode 100644
index 0000000..ca7c22d
--- /dev/null
+++ b/gamemode/inventorysystem/equipment/sh_equipment.lua
@@ -0,0 +1,180 @@
+--[[
+ A simple inventory that holds 1 item
+]]
+local itm = nrequire("item.lua")
+local ste = nrequire("utility/stream.lua")
+local inventory = nrequire("inventory/inventory.lua")
+print("Got invnetory table, it is:")
+PrintTable(inventory)
+local slots = {
+ "Head",
+ "Shoulders",
+ "Chest",
+ "Arms",
+ "Left Hand",
+ "Right Hand",
+ "Dual",
+ "Legs",
+ "Belt",
+ "Gloves",
+ "Feet",
+ "Back",
+ "Ring 1",
+ "Ring 2",
+ "Ring 3",
+ "Ring 4",
+ "Ring 5",
+ "Ring 6",
+}
+
+local inv = {}
+if SERVER then inv = nrequire("sv_equipment.lua") end
+if CLIENT then inv = nrequire("cl_equipment.lua") end
+
+inv.Name = "Equipment"
+inv.equiped = {}
+inv.FindPlaceFor = function(self, item)
+ --Make sure it's equipable
+ if not item.Equipable then return nil end
+
+ --If this is a dual weielding weapon
+ if item.Equipable == "Dual" then
+ if self.equiped["Left Hand"] == nil and self.equiped["Right Hand"] == nil then
+ return {"Dual"}
+ else
+ return nil
+ end
+ end
+
+ --If this item is a left or right handed, make sure we don't have a dual equiped
+ if item.Equipable == "Left Hand" or item.Equipable == "Right Hand" then
+ if self.equiped["Dual"] ~= nil then return nil
+ elseif self.equiped[item.Equipable] ~= nil then return nil
+ else return {item.Equipable} end
+ end
+
+ --If this item is a ring
+ if item.Equipable == "Ring" then
+ for i = 1,6 do
+ if self.equiped["Ring " .. i] == nil then
+ return {"Ring " .. i}
+ end
+ end
+ return nil
+ end
+
+ --Otherwise, just check if the slot is empty
+ if self.equiped[item.Equipable] == nil then
+ return {item.Equipable}
+ else
+ return nil
+ end
+end
+
+inv.CanFitIn = function(self,position,item)
+ return (position[1] == item.Equipable) and (self.equiped[position[1]] == nil)
+end
+
+inv.Put = function(self,position,item)
+ self.equiped[position[1]] = item
+end
+
+inv.Has = function(self,string_or_compare_func)
+ if type(string_or_compare_func) == "string" then
+ for k,v in pairs(self.equiped) do
+ if v.Name == string_or_compare_func then return k end
+ end
+ return nil
+ elseif type(string_or_compare_func) == "function" then
+ for k,v in pairs(self.equiped) do
+ if string_or_compare_func(v.Name) then return k end
+ end
+ return nil
+ end
+ error(string.format("equipment:Has() called with a %s, expected string or function.",type(string_or_compare_func)))
+end
+
+inv.Remove = function(self,position)
+ self.equiped[position[1]] = nil
+end
+
+inv.Get = function(self,position)
+ return self.equiped[position[1]]
+end
+
+inv.Serialize = function(self)
+ local tbl = {}
+ for k,v in pairs(self.equiped) do
+ tbl[k] = v:Serialize()
+ end
+ return util.TableToJSON(tbl)
+end
+
+inv.DeSerialize = function(self,data)
+ print("deserializeing, data was",data)
+ if data ~= nil and data ~= "" then
+ local tbl = util.JSONToTable(data)
+ local cpy = table.Copy(self)
+ for k,v in pairs(tbl) do
+ cpy.equiped[k] = itm.GetItemFromData(v)
+ end
+ else
+ return table.Copy(self)
+ end
+end
+
+inventory.RegisterInventory(inv)
+
+--[[
+for k,v in pairs(slots) do
+ local inv = {}
+ inv.Name = "inv_" .. v
+ inv.FindPlaceFor = function(self, item)
+ if self.item == nil then return {} else return nil end
+ end
+ inv.CanFitIn = function(self,position,item)
+ if self.item == nil then return true else return "Inventory slot occupied by a(n)" .. self.item.Name end
+ end
+ inv.Put = function(self,pos,item)
+ self.item = item
+ end
+ inv.Has = function(self,prt)
+ if type(prt) == "string" then
+ if self.item ~= nil and self.item.Name == prt then return {} else return nil end
+ elseif type(prt) == "function" then
+ if prt(self.item) then return {} else return nil end
+ end
+ error(string.format("Passed a %s to %s:Has(), expected string or function",type(prt),self.Name))
+ end
+ inv.Remove = function(self,pos)
+ self.item = nil
+ end
+ inv.Get = function(self,pos)
+ return self.item
+ end
+ inv.Serialize = function(self)
+ if self.item then
+ local data = ste.CreateStream()
+ local itemname = self.item.Name
+ local itemdata = self.item:Serialize()
+ data:WriteString(itemname)
+ data:WriteString(itemdata)
+ return data:ToString()
+ end
+ return ""
+ end
+ inv.DeSerialize = function(self,str)
+ print("data was",str)
+ if str == "" or str == nil then
+ return table.Copy(self)
+ else
+ local data = ste.CreateStream(str)
+ local itemname = data:ReadString()
+ local itemdata = data:ReadString()
+ self.item = itm.GetItemFromData(itemname,itemdata)
+ end
+ end
+ print("Attempting to register inventory with the name " .. inv.Name)
+ inventory.RegisterInventory(inv)
+end
+]]
diff --git a/gamemode/inventorysystem/equipment/sv_equipment.lua b/gamemode/inventorysystem/equipment/sv_equipment.lua
new file mode 100644
index 0000000..2189122
--- /dev/null
+++ b/gamemode/inventorysystem/equipment/sv_equipment.lua
@@ -0,0 +1,5 @@
+--[[
+ Needed so the includer dosn't freak out
+]]
+
+return {}