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
|
--[[
Ease of use functions for generating quests
]]
--[[
local quest = {
q.MakeArc("TalkArc",Entity(24),"Talk to Jared The Brutal","Rats...","I JARED THE BRUTAL. YOU THINK YOU TOUGH? GO KILL 10 RATS!!!"),
q.MakeArc("KillArc","Rat",10)
q.MakeArc("TalkArc",Entity(24),"Talk to Jared The Brutal","I kill 10 rats.","HOLY SHIT, YOU KILL 10?? GOOD. YOU BRUTAL NOW. HERE IS REWARD.")
}
local reward = function(ply)
for i=1,10 do
pcall(function()
ply:GiveItem("Rat Meat")
end,function()
end)
end
ply:AddSkill("Hunting",20)
end
local Killquest = q.GenerateQuest(quest,reward)
]]
nrequire("itemsystem/quest.lua")
local itm = nrequire("item.lua")
local log = nrequire("log.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)
local q = itm.GetItemByName("Quest")
q.questname = questname
q.Arcs = arcstbl
q.reward = rewards
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")
end)
end)
concommand.Add("artery_printquestarcs",function(ply,cmd,args)
PrintTable(arcs)
end)
return q
|