aboutsummaryrefslogtreecommitdiff
path: root/gamemode/inventorysystem/skills/sh_skills.lua
blob: 3c212bfd49cb0927c059c1c522cb9bedd5af9e82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
--[[
	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
			inv.skills[j] = 0
		end
	end
end
calculate_skills()

--[[
item should be
{
	name = "name",
	ammt = 12.3,
	isskill = True
}
]]
inv.FindPlaceFor = function(self, item)
	if not item.isskill then
		return nil
	end
	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)
	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)
	calculate_skills()
	self.skills = {}
	local gen = util.JSONToTable(data)
	gen = gen or {}
	for k,v in pairs(gen) do
		self.skills[k] = v
	end
	return self
end

inventory.RegisterInventory(inv)