diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2018-03-23 20:20:40 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2018-03-23 20:20:40 -0400 |
| commit | e2428796b9afe019ae6ca45e07fbe1aaa6963917 (patch) | |
| tree | b6514bbf349a99ebd3e999a3811ab6f0fa52851b /gamemode/core/quests | |
| parent | c132bf1fa77a0b01b18a848db91879383a8210a8 (diff) | |
| download | artery-e2428796b9afe019ae6ca45e07fbe1aaa6963917.tar.gz artery-e2428796b9afe019ae6ca45e07fbe1aaa6963917.tar.bz2 artery-e2428796b9afe019ae6ca45e07fbe1aaa6963917.zip | |
Started working on quest inventory
Diffstat (limited to 'gamemode/core/quests')
| -rw-r--r-- | gamemode/core/quests/quest.lua | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/gamemode/core/quests/quest.lua b/gamemode/core/quests/quest.lua new file mode 100644 index 0000000..5560745 --- /dev/null +++ b/gamemode/core/quests/quest.lua @@ -0,0 +1,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 |
