aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-10-21 20:36:08 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2017-10-21 20:36:08 -0400
commit84a72c78cd157b2649c03f8f503310883241dcdb (patch)
tree75c7d69041f0b5c14af996ce50f61b92bc8f7267
parentda81a0a23a3704dd2de3ab2249496c1ad1912d1c (diff)
downloadartery-84a72c78cd157b2649c03f8f503310883241dcdb.tar.gz
artery-84a72c78cd157b2649c03f8f503310883241dcdb.tar.bz2
artery-84a72c78cd157b2649c03f8f503310883241dcdb.zip
Added skill inventory
Added skill inventory to the inventory system New players now stsart with a skill inventory
-rw-r--r--gamemode/config/sv_newplayer.lua4
-rw-r--r--gamemode/inventorysystem/skills/cl_skills.lua115
-rw-r--r--gamemode/inventorysystem/skills/sh_skills.lua140
3 files changed, 257 insertions, 2 deletions
diff --git a/gamemode/config/sv_newplayer.lua b/gamemode/config/sv_newplayer.lua
index 931cf60..1385bf5 100644
--- a/gamemode/config/sv_newplayer.lua
+++ b/gamemode/config/sv_newplayer.lua
@@ -7,9 +7,9 @@ np.newdata = function()
inventories = {
{"Equipment", inv.CreateInventory("Equipment"):Serialize()},
{"Shaped Inventory",inv.CreateInventory("Shaped Inventory"):Serialize()},
- {"Prayers",inv.CreateInventory("Prayers"):Serialize()}
+ {"Prayers",inv.CreateInventory("Prayers"):Serialize()},
+ {"Skills",inv.CreateInventory("Skills"):Serialize()},
},
- skills = {},
quests = {},
}
end
diff --git a/gamemode/inventorysystem/skills/cl_skills.lua b/gamemode/inventorysystem/skills/cl_skills.lua
new file mode 100644
index 0000000..c324a49
--- /dev/null
+++ b/gamemode/inventorysystem/skills/cl_skills.lua
@@ -0,0 +1,115 @@
+
+local inv = {}
+--[[
+inv.allskills = {
+ ["forageing"] = {
+ "hunting",
+ "butchering",
+ "woodcutting",
+ "plant identification",
+ },
+ ["farming"] = {
+ "domestication",
+ "sowing",
+ "arboriculture",
+ "apiarism",
+ "reaping",
+ "fishing",
+ },
+ ["artisanship"] = {
+ "pottery",
+ "glass blowing",
+ "cooking",
+ "tanning",
+ "tailoring",
+ "metalworking",
+ "lockpicking",
+ "herbalism",
+ "alchemy",
+ "jewlery",
+ },
+ ["culture"] = {
+ "litteracy",
+ "writeing",
+ "speech",
+ "negotiation",
+ "painting",
+ "performing",
+ },
+ ["adventuring"] = {
+ "polearm",
+ "axeplay",
+ "swordplay",
+ "knifeing",
+ "fenceing",
+ "lockpicking",
+ "archery",
+ "throwing",
+ },
+}
+]]
+--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)
+ elements[name].label:SetText(string.format("%s : %d (%d%%)",name,lvl,frac))
+ elements[name].bar:SetFraction(frac)
+end
+
+inv.DrawOnDPanel = function(self,panel)
+ print("Drawing skills on panel")
+ local sheet = vgui.Create( "DColumnSheet", panel )
+ sheet:Dock( FILL )
+
+ for k,v in pairs(self.allskills) do
+ local spanel = vgui.Create("DPanel", sheet)
+ spanel:Dock(FILL)
+ local layout = vgui.Create("DListLayout", spanel)
+ layout:MakeDroppable("skill_layout")
+ for i,j in pairs(v) do
+ local ipanel = vgui.Create("DListLayout",layout)
+ local label = vgui.Create("DLabel",ipanel)
+ label:Dock(TOP)
+ label:SetDark(true)
+ local bar = vgui.Create("DProgress",ipanel)
+ bar:Dock(TOP)
+ elements[j] = {
+ ["label"] = label,
+ ["bar" ] = bar,
+ }
+ set_xp_of(j,self.skills[j])
+ ipanel:Add(label)
+ ipanel:Add(bar)
+ ipanel:InvalidateLayout()
+ ipanel:SizeToChildren(true,true)
+ layout:Add(ipanel)
+ end
+ layout:Dock(FILL)
+ sheet:AddSheet(k, spanel, "icon16/cross.png")
+ end
+
+ local prox = {}
+ prox.Put = function(s,position,item)
+ set_xp_of(position[1],s[position[1]])
+ end
+
+ prox.Remove = function(s,position)
+ set_xp_of(position[1],s[position[1]])
+ end
+
+ return prox
+end
+
+return inv
diff --git a/gamemode/inventorysystem/skills/sh_skills.lua b/gamemode/inventorysystem/skills/sh_skills.lua
new file mode 100644
index 0000000..27c3bad
--- /dev/null
+++ b/gamemode/inventorysystem/skills/sh_skills.lua
@@ -0,0 +1,140 @@
+--[[
+ 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 col = nrequire("config/colortheme.lua")
+local inv = {}
+if CLIENT then inv = nrequire("cl_skills.lua") end
+inv.allskills = {
+ ["forageing"] = {
+ "hunting",
+ "butchering",
+ "woodcutting",
+ "plant identification",
+ "archery",
+ },
+ ["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",
+ },
+ ["adventuring"] = {
+ "evasion",
+ "traveling",
+ "lockpicking",
+ "willpower",
+ "dexterity",
+ "sailing",
+ },
+ ["fighting"] = {
+ "polearm",
+ "axeplay",
+ "two-handed",
+ "sword & shield",
+ "light armor",
+ "heavy armor",
+ "knifeing",
+ "fenceing",
+ "throwing",
+ "archery",
+ }
+}
+
+inv.Name = "Skills"
+inv.skills = {}
+for k,v in pairs(inv.allskills) do
+ for i,j in pairs(v) do
+ inv.skills[j] = 0
+ end
+end
+
+--[[
+item should be
+{
+ name = "name",
+ ammt = 12.3,
+ isskill = True
+}
+]]
+inv.FindPlaceFor = function(self, item)
+ if item.isskill == nil then
+ return nil
+ end
+
+ if self.skills[item.name] then
+ return {item.name}
+ else
+ return nil
+ end
+end
+
+inv.CanFitIn = function(self,position,item)
+ return self.skills[position[1]] != nil
+end
+
+inv.Put = function(self,position,item)
+ self.skills[position[1]] = self.skills[position[1]] + 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(self)
+ end
+ local cpy = table.Copy(self)
+ cpy.skills = util.JSONToTable(data)
+ return cpy
+end
+
+inventory.RegisterInventory(inv)