diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2018-07-15 19:57:27 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2018-07-15 19:57:27 -0400 |
| commit | 534103be54a129d8255988fc1e75a21a63c6021f (patch) | |
| tree | c172b0884b4ca26452c5a74f5033b3b1526b6e3a /gamemode | |
| parent | 34d9ae7c4f4176fa9a943e9c2776afc32a867163 (diff) | |
| download | artery-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')
| -rw-r--r-- | gamemode/core/combat/sv_weaponswing.lua | 4 | ||||
| -rw-r--r-- | gamemode/core/database/sv_queries.lua | 16 | ||||
| -rw-r--r-- | gamemode/core/database/sv_setup.lua | 13 | ||||
| -rw-r--r-- | gamemode/core/inventory/inventory.lua | 4 | ||||
| -rw-r--r-- | gamemode/core/inventory/sv_invtracker.lua | 22 | ||||
| -rw-r--r-- | gamemode/core/npc/sv_npcsystem.lua | 4 | ||||
| -rw-r--r-- | gamemode/core/pac/sv_pac.lua | 2 | ||||
| -rw-r--r-- | gamemode/core/quests/arcs.lua | 52 | ||||
| -rw-r--r-- | gamemode/core/quests/quest.lua | 81 | ||||
| -rw-r--r-- | gamemode/inventorysystem/quests/cl_quests.lua | 84 | ||||
| -rw-r--r-- | gamemode/inventorysystem/quests/sh_quests.lua | 9 | ||||
| -rw-r--r-- | gamemode/itemsystem/quest.lua | 68 | ||||
| -rw-r--r-- | gamemode/nrequire.lua | 32 | ||||
| -rw-r--r-- | gamemode/questsystem/component_gather.lua | 71 | ||||
| -rw-r--r-- | gamemode/utility/type.lua | 11 |
15 files changed, 340 insertions, 133 deletions
diff --git a/gamemode/core/combat/sv_weaponswing.lua b/gamemode/core/combat/sv_weaponswing.lua index 7cac43a..69bfab4 100644 --- a/gamemode/core/combat/sv_weaponswing.lua +++ b/gamemode/core/combat/sv_weaponswing.lua @@ -107,7 +107,7 @@ function ws.doSwing(weapon,ply,callback) end ---Records animations for swingables. --- Records the player doing swings  +-- Records the player doing swings --@concommand artery_Recordanimations concommand.Add("artery_recordanimations",function(ply,cmd,args) if not ply:IsAdmin() then return end @@ -199,7 +199,7 @@ concommand.Add("artery_checkSwingable",function(ply,cmd,args) end) ---Clears the swingable cache, usefull for developers. --- Clears the list of items the gamemode knows about that are swingable  +-- Clears the list of items the gamemode knows about that are swingable --@concommand artery_clearswingable concommand.Add("artery_clearswingable",function(ply,cmd,args) if not ply:IsAdmin() then return end diff --git a/gamemode/core/database/sv_queries.lua b/gamemode/core/database/sv_queries.lua index 96908d4..887711a 100644 --- a/gamemode/core/database/sv_queries.lua +++ b/gamemode/core/database/sv_queries.lua @@ -40,9 +40,23 @@ function q.deserialize_player(ply,str) local tbl = util.JSONToTable(str) if not tbl then log.error("Failed to deserialize player " .. ply:Nick() .. "\n" .. str) + else + log.debug("Got player data:") + for k,v in pairs(tbl) do + log.debug("\t" .. tostring(k) .. " : " .. tostring(v)) + if k ~= "credits" then + for i,j in pairs(v) do + log.debug("\t\t" .. tostring(i) .. " : " .. tostring(j)) + for k,l in pairs(j) do + log.debug("\t\t\t" .. tostring(k) .. " : " .. tostring(l)) + end + end + end + end end local invs = tbl.inventories for k,v in pairs(invs) do + log.debug("Telling track to give inventory " .. tostring(v[1])) track.GiveInventoryWithData(ply,v[1],v[2]) end ply.data.skills = tbl.skills or {} @@ -52,7 +66,7 @@ function q.deserialize_player(ply,str) end ---Formats for an sql query. --- Kind of like string.format, but arguments are pasesd through SQL sanitization  +-- Kind of like string.format, but arguments are pasesd through SQL sanitization --@tparam string fmt The string.format function --@tparam varargs ... The parameters to format the string with function q.s_fmt(fmt,...) diff --git a/gamemode/core/database/sv_setup.lua b/gamemode/core/database/sv_setup.lua index becdcf5..4aba3db 100644 --- a/gamemode/core/database/sv_setup.lua +++ b/gamemode/core/database/sv_setup.lua @@ -100,7 +100,7 @@ function sql.GetPlayerData(ply) local s64 = ply:SteamID64() local q_str = q.s_fmt(fetch_player_query,s64) local q_suc = function(res,li) - log.debug("Loading player, res is" .. tostring(res)) + log.debug("Loading player, res is " .. tostring(res)) if res == nil then log.debug("Creating new player") sql.CreatePlayerTable(ply) @@ -120,7 +120,12 @@ function sql.GetPlayerData(ply) local vec = {x,y,z} for k,v in pairs(vec) do vec[k] = tonumber(v) end ply:SetPos(Vector(unpack(vec))) - q.deserialize_player(ply,plyd) + xpcall(function() + q.deserialize_player(ply,plyd) + end,function(err) + log.error("Failed to load:" .. ply:Nick() .. ":" .. err) + log.error(debug.traceback()) + end) end end --print("doing query",q_str) @@ -128,7 +133,7 @@ function sql.GetPlayerData(ply) end ---Manually loads data for the caller. --- Forefully loads a player's data.  +-- Forefully loads a player's data. --@concommand artery_loadplayer concommand.Add("artery_loadplayer",function(ply,cmd,args) if not ply:IsAdmin() then return end @@ -183,7 +188,7 @@ function sql.SendPlayerToInstance(ply,ls,ll) end ---Do queries related to the player creation. --- Create the caller's data, Reload the coller's data, or Send the caller to another instance  +-- Create the caller's data, Reload the coller's data, or Send the caller to another instance --@usage artery_DoQuery (create|get|send <server> <location>) --@concommand artery_DoQuery concommand.Add("artery_DoQuery",function(ply,cmd,args) diff --git a/gamemode/core/inventory/inventory.lua b/gamemode/core/inventory/inventory.lua index 52443a8..c7cdc9a 100644 --- a/gamemode/core/inventory/inventory.lua +++ b/gamemode/core/inventory/inventory.lua @@ -183,6 +183,10 @@ function inv.CreateInventoryFromData(name,data,owner) return ret end +--- Prints all inventories +-- Prints all inventories known to the game +--@usage artery_printinventories +--@concommand artery_printinventories concommand.Add("artery_printinventories", function(ply,cmd,args) PrintTable(inventories) end) diff --git a/gamemode/core/inventory/sv_invtracker.lua b/gamemode/core/inventory/sv_invtracker.lua index 8795d2a..ed5da4a 100644 --- a/gamemode/core/inventory/sv_invtracker.lua +++ b/gamemode/core/inventory/sv_invtracker.lua @@ -187,6 +187,7 @@ end --@tparam string data The data to deserialize the inventory with --@tparam table|nil higharchy The spot in the higharchy to place the inventory. function track.GiveInventoryWithData(ply,name,data,higharchy) + log.debug(string.format("Giving %s a %q inventory with data: %s",ply:Nick(),name,data)) local hi = higharchy or {} local i = inv.CreateInventoryFromData(name,data,ply) local nid = #ply.data.inventories + 1 @@ -234,15 +235,27 @@ function plymeta:RemoveItem(tbl) return item end +---Places an item in a player's inventory +-- Puts an item in a specific position in a specific inventory for a player +--@metamethod player:PutItem(location,item) +--@tparam table loc The location to put the item (returned by plymeta:HasItem()) +function plymeta:PutItem(loc,item) + local nid = loc[1] + local pos = loc[2] + self.data.inventories[nid]:Put(pos,item) +end + ---A shortcut for giving an item to a player. -- Gives an item to a player --@metamethod player:GiveItem(tbl) --@param itemtbl tbl The item to give the player --@raises "Uanble to find place to put item" Raises an exception if we cannot find a location to put the item. function plymeta:GiveItem(tbl) + assert(type(tbl) == "table", "Attempted to give a player an item that was not a table:" .. tostring(tbl)) for k,v in pairs(self.data.inventories) do local p = v:FindPlaceFor(tbl) if type(p) == "table" then + log.debug("Found inventory that would take item:" .. v.Name) v:Put(p,tbl) return else @@ -294,17 +307,19 @@ function(ply,cmd,args) end) ---Gives an inventory to a player. --- Gives a new inventory to a player  +-- Gives a new inventory to a player --@usage artery_AddInventory <inventory name> --@concommand artery_AddInventory --@reqadmin +--@tparam string invname The name of the inventory +--@see @{inventory.artery_printinventories} concommand.Add("artery_AddInventory",function(ply,cmd,args) if not ply:IsAdmin() then return end track.GiveInventoryTo(ply,args[1]) end) ---Gives an item to the player. --- Gives a new item to the player  +-- Gives a new item to the player --@usage artery_GiveItem <item name> --@concommand artery_GiveItem --@reqadmin @@ -313,7 +328,8 @@ concommand.Add("artery_GiveItem",function(ply,cmd,args) xpcall(function() ply:GiveItem(itm.GetItemByName(args[1])) end,function(err) - print("Could not give that item!:", err) + log.debug("Could not give that item!:" .. err) + log.debug(debug.traceback()) end) end) diff --git a/gamemode/core/npc/sv_npcsystem.lua b/gamemode/core/npc/sv_npcsystem.lua index 7c75f90..eb149f2 100644 --- a/gamemode/core/npc/sv_npcsystem.lua +++ b/gamemode/core/npc/sv_npcsystem.lua @@ -122,7 +122,7 @@ hook.Add("InitPostEntity", "artery_spawnmapnpcs", function() end) ---Reloads the entities on the map. --- Removes and then reload all of the entities on the level  +-- Removes and then reload all of the entities on the level --@concommand artery_reloadmap concommand.Add("artery_reloadmap", function(ply,cmd,args) if not ply:IsAdmin() then return end @@ -138,7 +138,7 @@ concommand.Add("artery_reloadmap", function(ply,cmd,args) end) ---Create a new npc. --- Creates a new npc a the point the player is looking  +-- Creates a new npc a the point the player is looking --@usage artery_makenpc <npc_name> --@concommand artery_makenpc concommand.Add("artery_makenpc", function(ply, cmd, args) diff --git a/gamemode/core/pac/sv_pac.lua b/gamemode/core/pac/sv_pac.lua index 6c9a731..daadef9 100644 --- a/gamemode/core/pac/sv_pac.lua +++ b/gamemode/core/pac/sv_pac.lua @@ -83,7 +83,7 @@ end loadhashes() ---Reloads the hashes. --- Run this if you changed a pac and want to reload it.  +-- Run this if you changed a pac and want to reload it. --@concommand artery_reload_pac_hashes concommand.Add("artery_reload_pac_hashes",function(ply,cmd,args) if not ply:IsAdmin() then return end 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 diff --git a/gamemode/inventorysystem/quests/cl_quests.lua b/gamemode/inventorysystem/quests/cl_quests.lua index 2052e19..9ad8eb1 100644 --- a/gamemode/inventorysystem/quests/cl_quests.lua +++ b/gamemode/inventorysystem/quests/cl_quests.lua @@ -1,59 +1,71 @@ +local log = nrequire("log.lua") local inv = {} --the gui elements local elements = {} local questlist = nil local questlog = nil -local function add_quest(panel,quest) - -end +local function add_quest(panel,quest,position) + local questbutton = vgui.Create("DButton",questlist) + questbutton:SetText(quest.QuestName) + questbutton.DoClick = function() + log.debug("Setting quest text to:" .. quest:GetText()) + questlog:SetText(quest:GetText()) + end + log.debug("questlist: " .. tostring(questlist) .. "\tquestbutton: " .. tostring(questbutton)) + questlist:AddItem(questbutton) + elements[position] = questbutton +end +local scrw, scrh = ScrW(), ScrH() -- Assume screen size dosn't change +local hh = (scrh - 100) / 2 inv.DrawOnDPanel = function(self,panel) local spanel = vgui.Create("DPanel", panel) spanel:Dock(FILL) - local halfs = vgui.Create("DVerticalDivider",spanel) - questlist = vgui.Create("DListLayout", spanel) - questlog = vgui.Create("DLabel",spanel) - halfs:SetBottom(questlist) - halfs:SetTop(questlog) - questlist:Dock(FILL) + function spanel:Paint(w,h) + draw.RoundedBox( 8, 0, 0, w, h, Color( 255, 0, 0 ) ) + end + local qls = vgui.Create("DScrollPanel", spanel) + function qls:Paint(w,h) + draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 255, 0 ) ) + end + qls:SetSize((scrw/4) - 40, hh) + inv.qls = qls + local sls = vgui.Create("DScrollPanel", spanel) + function sls:Paint(w,h) + draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 0, 255 ) ) + end + sls:SetSize((scrw/4) - 40, hh) + sls:SetPos(0,hh) + inv.sls = sls + questlist = vgui.Create("DGrid", qls) + questlist:SetCols(4) + questlist:SetColWide(((scrw/4) - 40) /4) + questlist:SetSize((scrw/4) - 50, hh) + function questlist:Paint(w,h) + draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 255, 255 ) ) + end + inv.questlist = questlist + inv.questlog = questlog + questlog = vgui.Create("DLabel", sls) questlog:Dock(FILL) + questlog:SetDark(true) + questlog:SetText("Quest Log") + -- questlist:Dock(TOP) + -- questlog:Dock(BOTTOM) for k,v in pairs(self.track) do - local questbutton = vgui.Create("DButton",questlist) - questbutton:SetText(v.QuestName) - questbutton.DoClick = function() - questlog:SetText(v:GetText()) - end - for i,j in pairs(v) do - local ipanel = vgui.Create("DListLayout",layout) - local label = vgui.Create("DLabel",ipanel) - label:Dock(TOP) - label:SetDark(true) - local bar = vgui.Create("DProgress",ipanel) - bar:Dock(TOP) - elements[j] = { - ["label"] = label, - ["bar" ] = bar, - } - set_xp_of(j,self.skills[j] or 0) - ipanel:Add(label) - ipanel:Add(bar) - ipanel:InvalidateLayout() - ipanel:SizeToChildren(true,true) - layout:Add(ipanel) - end - layout:Dock(FILL) - sheet:AddSheet(k, spanel, "icon16/cross.png") + add_quest(panel,v,k) end local prox = {} prox.Put = function(s,position,item) - --Observer might be called before our put() + add_quest(panel,item,position[1]) end prox.Remove = function(s,position) - -- + questlist:RemoveItem(elements[position[1]]) + -- log.error("Atempted to remove a quest") end return prox diff --git a/gamemode/inventorysystem/quests/sh_quests.lua b/gamemode/inventorysystem/quests/sh_quests.lua index 3515d61..fc651fc 100644 --- a/gamemode/inventorysystem/quests/sh_quests.lua +++ b/gamemode/inventorysystem/quests/sh_quests.lua @@ -13,12 +13,12 @@ inv.Name = "Quests" inv.track = {} function inv:FindPlaceFor(item) if item.Arcs ~= nil then - return {#self.track} + return {#self.track + 1} end return nil end function inv:CanFitIn(pos,item) - return pos[1] == #self.track + return pos[1] == #self.track + 1 end function inv:Put(pos,item) print("Added a quest:") @@ -57,10 +57,9 @@ function inv:DeSerialize(str) self.track = {} local tbl = util.JSONToTable(str) tbl = tbl or {} - local i = 1 for k,v in pairs(tbl) do - local this_prayer = itm.GetItemByName(k):DeSerialize(v) - self:Put({i},this_prayer) + local quest = itm.GetItemByName(k):DeSerialize(v) + self.track[#self.track + 1] = quest end return self end diff --git a/gamemode/itemsystem/quest.lua b/gamemode/itemsystem/quest.lua index d75c42c..bf0ef2b 100644 --- a/gamemode/itemsystem/quest.lua +++ b/gamemode/itemsystem/quest.lua @@ -2,6 +2,8 @@ Generic item for creating quests ]] +local a = nrequire("core/quests/arcs.lua") +local log = nrequire("log.lua") local item = {} local strikethoughmap = { a = "a̶", @@ -40,22 +42,76 @@ item.Arcs = {} item.ArcsCompleted = 0 function item:GetText() + log.debug("Calling quest item's GetText()") local text = {} for i=1,self.ArcsCompleted do local thisarctxt = self.Arcs[i]:GetText() - for k,v in pairs(strikethoughmap) do - print("Trying to strike though:",v) + local tas = {} + for j = 0,#thisarctxt+1 do + tas[#tas + 1] = strikethoughmap[thisarctxt[j]] end + text[#text + 1] = table.concat(tas) end - + if self.Arcs[self.ArcsCompleted + 1] then + text[#text + 1] = self.Arcs[self.ArcsCompleted + 1]:GetText() + end + return table.concat(text,"\n") end function item:Serialize() - + local s = { + completed = self.ArcsCompleted, + questname = self.QuestName, + rewards = self.Rewards, + } + assert(type(self.Arcs) == "table", "self.Arcs was not a table, it was a" .. type(self.Arcs)) + for k,v in pairs(self.Arcs) do + s[#s + 1] = {v.Name, v:Serialize()} + end + return util.TableToJSON(s) +end + +function item:UpdateCompleted() + --Remove ourselves + local qstloc = self.Owner:HasItem(function(tbl) return tbl == self end) + self.Owner:RemoveItem(qstloc) + + log.debug("Quest item's UpdateCompleted() called") + log.debug(string.format("Looking at %s arc:", self.Arcs[self.ArcsCompleted + 1].Name)) + if self.Arcs[self.ArcsCompleted + 1]:Complete() then + log.debug("Completed!") + self.ArcsCompleted = self.ArcsCompleted + 1 + end + if #self.Arcs == self.ArcsCompleted then + log.debug("Completed Quest! : " .. self.QuestName) + end + + --Re-add ourselves + self.Owner:GiveItem(self) +end + +function item:Complete() + if #self.Arcs == self.ArcsCompleted then + return true + elseif #self.Arcs < self.ArcsCompleted then + log.error(string.format("Finished %d arcs of %d arcs in quest %s",self.ArcsCompleted, #self.Arcs, self.QuestName)) + else + return false + end end -function item:DeSerialize() - +function item:DeSerialize(data) + local t = util.JSONToTable(data) + self.ArcsCompleted = t.completed + self.QuestName = t.questname + self.Rewards = t.rewards + self.Arcs = {} + for k,v in ipairs(t) do + local arcname,arcdata = unpack(v) + local arc = a.MakeArcWithData(arcname,arcdata) + arc.Quest = self + self.Arcs[k] = arc + end end local itm = nrequire("item.lua") diff --git a/gamemode/nrequire.lua b/gamemode/nrequire.lua index 94f7215..af066f0 100644 --- a/gamemode/nrequire.lua +++ b/gamemode/nrequire.lua @@ -36,14 +36,14 @@ local function BuildIncludeTable(tbl) local pathparts = {} for part in filepath:gmatch("/?[%w_]+/") do local foldername = part:gsub("/$",""):gsub("^/","") - pathparts[#pathparts+1] = foldername + pathparts[#pathparts + 1] = foldername end local filename = filepath:gfind("[%w_%.]+%.[%w_]+$")() if output[filename] == nil then output[filename] = {} end local cursor = output[filename] - for folder= #pathparts, 2, -1 do + for folder = #pathparts, 2, -1 do if cursor[pathparts[folder]] == nil then cursor[pathparts[folder]] = {} end @@ -151,11 +151,12 @@ function nrequire(req,...) return end local filetime = file.Time(tpath[1],tpath[2]) + local skip_compile = true if lastcall[tpath[1]] and lastcall[tpath[1]] < filetime then - goto cleanup + skip_compile = false end - - do -- Needed to follow the scoping rules of lua in regards to goto + + if skip_compile then -- Needed to follow the scoping rules of lua in regards to goto local filefunc = CompileString(filetxt,tpath[1],false) if type(filefunc) ~= "function" then error(filefunc) @@ -171,12 +172,11 @@ function nrequire(req,...) end) end end - - ::cleanup:: + pathstack[#pathstack] = nil - + return reqtbl[tpath[1]] - + end if SERVER then @@ -270,7 +270,7 @@ local function doincludes() reqtbl = reqtbl or {} for k,v in pairs(paths) do local filename = v[1] - MsgN("Filename:",filename) + -- MsgN("Filename:",filename) if filename == "gamemodes/artery/gamemode/init.lua" then continue end @@ -306,11 +306,11 @@ local function redoincludes() print("redoing includes") paths = {} -- Defined above somewhere for k,v in pairs(searchpaths) do - print("Searching path:") - PrintTable(v) + -- print("Searching path:") + -- PrintTable(v) TraverseFolder(v,function(n) - print("found file:") - PrintTable(n) + -- print("found file:") + -- PrintTable(n) paths[#paths + 1] = n end) end @@ -404,7 +404,7 @@ else coroutine.resume(routine) end) end) - + net.Receive("art_respondfile",function(ln,pl) local tbl = net.ReadTable() print("Received response file:",tbl.name) @@ -414,7 +414,7 @@ else print("Writing to ", fullpath) file.Write(fullpath,tbl.text) end) - + net.Receive("artery_downloadfile",function(ln,pl) print("Asked to download file") local clientfiles = net.ReadTable() diff --git a/gamemode/questsystem/component_gather.lua b/gamemode/questsystem/component_gather.lua index fccb32a..5647f42 100644 --- a/gamemode/questsystem/component_gather.lua +++ b/gamemode/questsystem/component_gather.lua @@ -1,25 +1,80 @@ +if SERVER then + inv = nrequire("sv_invtracker.lua") +end +local log = nrequire("log.lua") + +local quests = {} local comp = {} comp.Name = "Quest Component Gather" +function comp:Update() + if SERVER then + local items = {} + self.items = 0 + log.debug("in comp:Update, self.ItemNumber is" .. tostring(self.ItemNumber)) + for i = 1, self.ItemNumber do + local loc = self.Owner:HasItem(self.ItemName) + if loc then + items[loc] = self.Owner:RemoveItem(loc) + self.items = i + else + break + end + end + log.debug("Update called, self.items is now" .. tostring(self.items)) + for k,v in pairs(items) do + self.Owner:PutItem(k,v) + end + end + self.Quest:UpdateCompleted() +end + +function comp:Complete() + if self.items >= self.ItemNumber then + log.debug("Completed a gather arc of a quest!") + end + return self.items >= self.ItemNumber +end + +function comp:Init(ply,itemname,itemnumber) + if not ply or not itemname or not itemnumber then return end + self.ItemName = itemname + self.ItemNumber = itemnumber + self.Items = 0 + if CLIENT then return end + self.Owner = ply + -- self:Update() + quests[#quests + 1] = self + log.debug("After initalizing quest, found " .. tostring(self.items) .. " items") +end -function comp:Init(itemname,itemnumber) - self.itemname = itemname - self.itemnumber = itemnumber +if SERVER then + local plymeta = FindMetaTable("Player") + local det = plymeta.GiveItem + function plymeta:GiveItem(tbl) + det(self,tbl) + log.debug("Calling component_gather's GiveItem()") + for k,v in pairs(quests) do + if v.ItemName == tbl.Name then + v:Update() + end + end + end end function comp:GetText() - return string.format("Gather %s %s",self.itemnumber,self.itiemname) + return string.format("Gather %s %s",self.ItemNumber,self.ItemName) end function comp:Serialize() - return util.TableToJSON({itemname,itemnumber}) + return util.TableToJSON({self.ItemName,self.ItemNumber}) end function comp:DeSerialize(data) local tbl = util.JSONToTable(data) - self.itemname = tbl[1] - self.itemnumber = tbl[2] + self.ItemName = tbl[1] + self.ItemNumber = tbl[2] end -nrequire("core/quests/quest.lua").RegisterArc(comp) +nrequire("core/quests/arcs.lua").RegisterArc(comp) diff --git a/gamemode/utility/type.lua b/gamemode/utility/type.lua new file mode 100644 index 0000000..61f1a8b --- /dev/null +++ b/gamemode/utility/type.lua @@ -0,0 +1,11 @@ + +local t = {} + +t.checktypes = function(...) + local args = {...} + for i = 1, #args, 2 do + assert(type(args[i]) == args[i + 1], string.format("Bad argument #%d, was %s, expected %s",(i + 1) / 2,type(args[i]),args[i + 1])) + end +end + +return t |
