diff options
Diffstat (limited to 'gamemode/core/quests')
| -rw-r--r-- | gamemode/core/quests/arcs.lua | 52 | ||||
| -rw-r--r-- | gamemode/core/quests/quest.lua | 81 |
2 files changed, 84 insertions, 49 deletions
diff --git a/gamemode/core/quests/arcs.lua b/gamemode/core/quests/arcs.lua new file mode 100644 index 0000000..26c60ab --- /dev/null +++ b/gamemode/core/quests/arcs.lua @@ -0,0 +1,52 @@ + +local log = nrequire("log.lua") +local fun = nrequire("fn.lua") +local a = {} + +local arcs = {} +local arc_required_fields = { + "Name", + "Init", + "Serialize", + "DeSerialize" +} + +function a.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 + log.debug("Registered new arc type:" .. tbl.Name) +end + +local function MakeArcBase(name) + log.debug("Making arc:" .. name) + assert(arcs[name] ~= nil, "Attempted to make an unknown arc type:\"" .. name .. "\". Known arc types are:" .. table.concat(table.GetKeys(arcs),"\n\t")) + local arc_m = { + __index = arcs[name] + } + arcbase = {} + setmetatable(arcbase,arc_m) + return arcbase +end + +function a.MakeArc(name, ...) + local arc = MakeArcBase(name) + arc:Init(...) + return arc +end + +function a.MakeArcWithData(name,data) + local arc = MakeArcBase(name) + arc:DeSerialize(data) + return arc +end + +concommand.Add("artery_printquestarcs",function(ply,cmd,args) + PrintTable(arcs) +end) + +return a 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 |
