diff options
Diffstat (limited to 'gamemode/core')
| -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 |
9 files changed, 136 insertions, 62 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 |
