aboutsummaryrefslogtreecommitdiff
path: root/gamemode/inventorysystem
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/inventorysystem')
-rw-r--r--gamemode/inventorysystem/cl_common.lua21
-rw-r--r--gamemode/inventorysystem/equipment/cl_equipment.lua4
-rw-r--r--gamemode/inventorysystem/equipment/sh_equipment.lua6
-rw-r--r--gamemode/inventorysystem/quests/cl_quests.lua12
-rw-r--r--gamemode/inventorysystem/shapedinventory/sh_shaped.lua2
-rw-r--r--gamemode/inventorysystem/skills/cl_skills.lua13
-rw-r--r--gamemode/inventorysystem/skills/sh_skillcommon.lua17
-rw-r--r--gamemode/inventorysystem/skills/sh_skills.lua12
8 files changed, 56 insertions, 31 deletions
diff --git a/gamemode/inventorysystem/cl_common.lua b/gamemode/inventorysystem/cl_common.lua
index 559c8f0..bf9fb6f 100644
--- a/gamemode/inventorysystem/cl_common.lua
+++ b/gamemode/inventorysystem/cl_common.lua
@@ -2,6 +2,7 @@
A bunch of functions that a lot of inventories have in common, dragged out here so bugfixing is easier
]]
+local log = nrequire("log.lua")
local com = {}
--Displays a dropdown of options under the players mouse, if the option is clicked, does the function
@@ -20,6 +21,26 @@ function com.CreateMenuFor(menu, tbl)
end
end
+-- Move an item internally between two inventories
+function com.MoveItem(f,frominv,toinv)
+ local frompos = frominv:Has(f)
+ assert(frompos,string.format("Failed to find item %q in inventory %q",tostring(f),frominv.Name))
+ log.debug("Returned position:" .. frompos[1])
+ local item = frominv:Get(frompos)
+ assert(item,string.format("Failed to get item %q out of %q",tostring(f),frominv.Name))
+ local topos = toinv:FindPlaceFor(item)
+ assert(topos,string.format("Failed to find a place in %q to put a %q",toinv.Name,tostring(f)))
+
+ net.Start("art_RequestInvMove")
+ net.WriteEntity(LocalPlayer())
+ net.WriteEntity(LocalPlayer())
+ net.WriteUInt(frominv.id,32)
+ net.WriteUInt(toinv.id,32)
+ net.WriteTable(frompos)
+ net.WriteTable(topos)
+ net.SendToServer()
+end
+
function com.generatereceiver()
return function(self,panels,dropped,index,cx,cy)
if dropped then
diff --git a/gamemode/inventorysystem/equipment/cl_equipment.lua b/gamemode/inventorysystem/equipment/cl_equipment.lua
index 8d06594..58fc3f9 100644
--- a/gamemode/inventorysystem/equipment/cl_equipment.lua
+++ b/gamemode/inventorysystem/equipment/cl_equipment.lua
@@ -118,7 +118,7 @@ inv.DrawOnDPanel = function(self,panel)
if self.equiped[k].GetOptions then
pn.DoClick = function()
local dm = DermaMenu()
- com.CreateMenuFor(dm,self.equiped[k].GetOptions())
+ com.CreateMenuFor(dm,self.equiped[k]:GetOptions())
dm:Open()
end
end
@@ -153,7 +153,7 @@ inv.DrawOnDPanel = function(self,panel)
if item.GetOptions then
self[position[1]].DoClick = function()
local dm = DermaMenu()
- com.CreateMenuFor(dm,item.GetOptions())
+ com.CreateMenuFor(dm,item:GetOptions())
dm:Open()
end
end
diff --git a/gamemode/inventorysystem/equipment/sh_equipment.lua b/gamemode/inventorysystem/equipment/sh_equipment.lua
index b27dd08..a9b6f83 100644
--- a/gamemode/inventorysystem/equipment/sh_equipment.lua
+++ b/gamemode/inventorysystem/equipment/sh_equipment.lua
@@ -77,17 +77,18 @@ end
inv.Put = function(self,position,item)
self.equiped[position[1]] = item
if item.onEquip then item:onEquip(self.Owner) end
+ item.inv = self
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
+ 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
+ if string_or_compare_func(v.Name) then return {k} end
end
return nil
end
@@ -99,6 +100,7 @@ inv.Remove = function(self,position)
if not item then return end --Make sure we'r enot dragging an empty space
if item.onUnEquip then item:onUnEquip(self.Owner) end
self.equiped[position[1]] = nil
+ item.inv = nil
end
inv.Get = function(self,position)
diff --git a/gamemode/inventorysystem/quests/cl_quests.lua b/gamemode/inventorysystem/quests/cl_quests.lua
index 9ad8eb1..e485109 100644
--- a/gamemode/inventorysystem/quests/cl_quests.lua
+++ b/gamemode/inventorysystem/quests/cl_quests.lua
@@ -23,19 +23,10 @@ local hh = (scrh - 100) / 2
inv.DrawOnDPanel = function(self,panel)
local spanel = vgui.Create("DPanel", panel)
spanel:Dock(FILL)
- function spanel:Paint(w,h)
- draw.RoundedBox( 8, 0, 0, w, h, Color( 255, 0, 0 ) )
- end
local qls = vgui.Create("DScrollPanel", spanel)
- function qls:Paint(w,h)
- draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 255, 0 ) )
- end
qls:SetSize((scrw/4) - 40, hh)
inv.qls = qls
local sls = vgui.Create("DScrollPanel", spanel)
- function sls:Paint(w,h)
- draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 0, 255 ) )
- end
sls:SetSize((scrw/4) - 40, hh)
sls:SetPos(0,hh)
inv.sls = sls
@@ -43,9 +34,6 @@ inv.DrawOnDPanel = function(self,panel)
questlist:SetCols(4)
questlist:SetColWide(((scrw/4) - 40) /4)
questlist:SetSize((scrw/4) - 50, hh)
- function questlist:Paint(w,h)
- draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 255, 255 ) )
- end
inv.questlist = questlist
inv.questlog = questlog
questlog = vgui.Create("DLabel", sls)
diff --git a/gamemode/inventorysystem/shapedinventory/sh_shaped.lua b/gamemode/inventorysystem/shapedinventory/sh_shaped.lua
index 42edaa6..1e87e42 100644
--- a/gamemode/inventorysystem/shapedinventory/sh_shaped.lua
+++ b/gamemode/inventorysystem/shapedinventory/sh_shaped.lua
@@ -66,6 +66,7 @@ function inv:Put(tbl,item)
--Now set the item in the correct slot
local slot = calcposition(self.width,self.height,tbl[1],tbl[2])
self.tracker[slot] = item
+ item.inv = self
end
function inv:Has(ptr)
@@ -97,6 +98,7 @@ function inv:Remove(tbl)
end
end
end
+ item.inv = nil
return item
end
diff --git a/gamemode/inventorysystem/skills/cl_skills.lua b/gamemode/inventorysystem/skills/cl_skills.lua
index 31d4470..b5e4620 100644
--- a/gamemode/inventorysystem/skills/cl_skills.lua
+++ b/gamemode/inventorysystem/skills/cl_skills.lua
@@ -4,19 +4,8 @@ local sc = nrequire("sh_skillcommon.lua")
--the gui elements
local elements = {}
---return level, frac
-local xpmult = 1.5 --the lower, the more lvl per xp
-local levelfunc = function(val)
- local curlvl = math.log(val,xpmult)
- local prevlvlxp = xpmult ^ math.floor(curlvl)
- local nextlvlxp = xpmult ^ (math.floor(curlvl) + 1)
- local sp = nextlvlxp - prevlvlxp
- local frac = (val - prevlvlxp) / ((sp ~= 0) and sp or 1) --don't divide by 0
- return math.floor(curlvl), frac
-end
-
local set_xp_of = function(name,ammt)
- local lvl,frac = levelfunc(ammt)
+ local lvl,frac = sc.levelfunc(ammt)
elements[name].label:SetText(string.format("%s : %d (%2.5f%%)",name,lvl,frac))
elements[name].bar:SetFraction(frac)
end
diff --git a/gamemode/inventorysystem/skills/sh_skillcommon.lua b/gamemode/inventorysystem/skills/sh_skillcommon.lua
index 9c022eb..e0db95a 100644
--- a/gamemode/inventorysystem/skills/sh_skillcommon.lua
+++ b/gamemode/inventorysystem/skills/sh_skillcommon.lua
@@ -73,4 +73,21 @@ function lib.SkillList()
return skills
end
+local xpmult = 1.5 --the lower, the more lvl per xp
+function lib.levelfunc(val)
+ local curlvl = math.log(val,xpmult)
+ local prevlvlxp = xpmult ^ math.floor(curlvl)
+ local nextlvlxp = xpmult ^ (math.floor(curlvl) + 1)
+ local sp = nextlvlxp - prevlvlxp
+ local frac = (val - prevlvlxp) / ((sp ~= 0) and sp or 1) --don't divide by 0
+ return math.floor(curlvl), frac
+end
+
+function pmeta:GetSkill(name)
+ local loc = self:HasItem(name)
+ if not loc then return 0 end
+ local item = self:GetItem(loc)
+ return lib.levelfunc(item.ammt)
+end
+
return lib
diff --git a/gamemode/inventorysystem/skills/sh_skills.lua b/gamemode/inventorysystem/skills/sh_skills.lua
index 3c212bf..43137a8 100644
--- a/gamemode/inventorysystem/skills/sh_skills.lua
+++ b/gamemode/inventorysystem/skills/sh_skills.lua
@@ -117,10 +117,13 @@ 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]
+ return {socf}
elseif type(socf) == "function" then
+ local fi = {}
for k,v in pairs(self.skills) do
- if socf(v) then return k end
+ fi.name = k
+ fi.ammt = v
+ if socf(fi) then return {k} end
end
else
return nil
@@ -132,7 +135,10 @@ inv.Remove = function(self,position)
end
inv.Get = function(self,position)
- return self.skills[position[1]]
+ local fi = {}
+ fi.name = position[1]
+ fi.ammt = self.skills[position[1]]
+ return fi
end
inv.Serialize = function(self)