aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/quests/quest.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2018-07-15 19:57:27 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2018-07-15 19:57:27 -0400
commit534103be54a129d8255988fc1e75a21a63c6021f (patch)
treec172b0884b4ca26452c5a74f5033b3b1526b6e3a /gamemode/core/quests/quest.lua
parent34d9ae7c4f4176fa9a943e9c2776afc32a867163 (diff)
downloadartery-534103be54a129d8255988fc1e75a21a63c6021f.tar.gz
artery-534103be54a129d8255988fc1e75a21a63c6021f.tar.bz2
artery-534103be54a129d8255988fc1e75a21a63c6021f.zip
Finished gather quest arcs
Finished base quest system, and added "Gather" arcs, where players gather a certain number of a certain item.
Diffstat (limited to 'gamemode/core/quests/quest.lua')
-rw-r--r--gamemode/core/quests/quest.lua81
1 files changed, 32 insertions, 49 deletions
diff --git a/gamemode/core/quests/quest.lua b/gamemode/core/quests/quest.lua
index 5560745..ed5ec57 100644
--- a/gamemode/core/quests/quest.lua
+++ b/gamemode/core/quests/quest.lua
@@ -13,7 +13,7 @@
pcall(function()
ply:GiveItem("Rat Meat")
end,function()
-
+
end)
end
ply:AddSkill("Hunting",20)
@@ -24,62 +24,45 @@
nrequire("itemsystem/quest.lua")
local itm = nrequire("item.lua")
local log = nrequire("log.lua")
-
+local arc = nrequire("arcs.lua")
+local typ = nrequire("type.lua")
local q = {}
-local arcs = {}
-local arc_required_fields = {
- "Name",
- "Init",
- "Serialize",
- "DeSerialize"
-}
-
-function q.RegisterArc(tbl)
- for k,v in pairs(arc_required_fields) do
- assert(tbl[v],"Attempted to register an arc, which didn't have a required field:" .. v)
- end
- if arcs[tbl.Name] ~= nil then
- log.warn("Attempted to register and arc named " .. tbl.Name .. " when another arc by that name already exists. Overwriteing...")
- end
- arcs[tbl.Name] = tbl
-end
-
-function q.MakeArc(name,...)
- assert(arcs[name] ~= nil, "Attempted to make an unknown arc type:\"" .. name .. "\". Known arc types are:" + table.concat(table.GetKeys(items),"\n\t"))
- local arc_m = {
- __index = arcs[name]
- }
- arcbase = {}
- setmetatable(arcbase,arc_m)
- return arcbase
-end
-- Generates an item that represents a quest
function q.GenerateQuest(questname,arcstbl,rewards)
+ typ.checktypes(
+ questname,"string",
+ arcstbl,"table",
+ rewards,"table"
+ )
local q = itm.GetItemByName("Quest")
- q.questname = questname
+ q.QuestName = questname
q.Arcs = arcstbl
- q.reward = rewards
+ for k,v in pairs(arcstbl) do
+ v.Quest = q
+ end
+ q.Reward = rewards
+ return q
end
-concommand.Add("artery_gen_test_quest",function(ply,cmd,args)
- print("Generating a test quest")
- local qu = {
- q.MakeArc("Quest Component Gather","Test item", 3)
- }
- local reward = function(ply)
- print("Sucessfully finished quest for", ply)
- end
- local kq = q.GenerateQuest(qu,reward)
- xpcall(function()
- ply:GiveItem(kq)
- end,function()
- print("FAiled to add quest")
+if SERVER then
+ concommand.Add("artery_gen_test_quest",function(ply,cmd,args)
+ print("Generating a test quest")
+ local qu = {
+ arc.MakeArc("Quest Component Gather",ply,"Test item", 3)
+ }
+ local reward = {
+ {"Test item", 1}
+ }
+ local kq = q.GenerateQuest("My test quest",qu,reward)
+ kq.Owner = ply
+ xpcall(function()
+ ply:GiveItem(kq)
+ end,function(err)
+ log.error("Failed to add quest:" .. err)
+ log.error(debug.traceback())
+ end)
end)
-end)
-
-concommand.Add("artery_printquestarcs",function(ply,cmd,args)
- PrintTable(arcs)
-end)
+end
return q