diff options
Diffstat (limited to 'gamemode/core')
| -rw-r--r-- | gamemode/core/combat/cl_weaponswing.lua | 57 | ||||
| -rw-r--r-- | gamemode/core/combat/sv_weaponswing.lua | 99 | ||||
| -rw-r--r-- | gamemode/core/database/sv_setup.lua | 13 | ||||
| -rw-r--r-- | gamemode/core/inventory/common/items.lua | 5 | ||||
| -rw-r--r-- | gamemode/core/inventory/sv_invtracker.lua | 36 | ||||
| -rw-r--r-- | gamemode/core/npc/sv_common.lua | 38 | ||||
| -rw-r--r-- | gamemode/core/npc/sv_huntingspawner.lua | 118 | ||||
| -rw-r--r-- | gamemode/core/npc/sv_npcsystem.lua | 40 | ||||
| -rw-r--r-- | gamemode/core/pac/cl_pac.lua | 10 | ||||
| -rw-r--r-- | gamemode/core/pac/sv_pac.lua | 6 |
10 files changed, 393 insertions, 29 deletions
diff --git a/gamemode/core/combat/cl_weaponswing.lua b/gamemode/core/combat/cl_weaponswing.lua new file mode 100644 index 0000000..8ed9637 --- /dev/null +++ b/gamemode/core/combat/cl_weaponswing.lua @@ -0,0 +1,57 @@ +local CLIENT_PAC_DIR = "artery/client/pacs" + +local ball +function finddmgpoint(name) + local filepath = string.format(CLIENT_PAC_DIR .. "/%s.txt",name) + local filetext = file.Read(filepath,"DATA") + local outfit = CompileString(string.format("return {%s}",filetext),name)() + ball = LocalPlayer():FindPACPart(outfit, "wep_point") + print("point is",ball,type(ball)) +end + +local swingtbl = {} +local tracking = false + +net.Receive("artery_doanimation",function() + local animname = net.ReadString() + local animtime = net.ReadDouble() + local wepname = net.ReadString() + local animdir = net.ReadString() + + swingtbl = {} + tracking = true + finddmgpoint(wepname) + print("Doing animation:",animname,animtime,echoname) + LocalPlayer():SetLuaAnimation(animname) + timer.Simple(animtime,function() + tracking = false + LocalPlayer():StopLuaAnimation(animname) + net.Start("artery_notifyserverofswing") + net.WriteString(wepname) + net.WriteString(animdir) + print("Seding swingtbl:") + PrintTable(swingtbl) + net.WriteTable(swingtbl) + net.SendToServer() + end) +end) + +concommand.Add("artery_startanimation",function(ply,cmd,args) + swingtbl = {} + ply:SetLuaAnimation(args[1]) + timer.Simple(args[2],function() + ply:StopLuaAnimation(args[1]) + end) +end) + +local lastpos +hook.Add("Tick","trace_weppos",function() + if not ball then return end + if lastpos == nil then lastpos = ball.Entity:GetPos() end + --`print("Distance between ", ball.Entity:GetPos(), "and", lastpos, " is" ,ball.Entity:GetPos():Distance(lastpos)) + if ball.Entity:GetPos():Distance(lastpos) > 2 and tracking then + swingtbl[#swingtbl + 1] = ball.Entity:GetPos() - LocalPlayer():GetPos() + print(ball.Entity:GetPos() - LocalPlayer():GetPos()) + end + lastpos = ball.Entity:GetPos() +end) diff --git a/gamemode/core/combat/sv_weaponswing.lua b/gamemode/core/combat/sv_weaponswing.lua new file mode 100644 index 0000000..f238497 --- /dev/null +++ b/gamemode/core/combat/sv_weaponswing.lua @@ -0,0 +1,99 @@ +--[[ + This file tells you what weapons need their swings recalculated +]] +local itm = nrequire("core/inventory/item.lua") +local ws = {} + +--Cache swing hits, if we used one once, we'll probably use it again soon +local swingcache_size = 30 +local swingcache = {} --Swing arc cache + +--A table of all the items that are swingable +local swingable = {} + +util.AddNetworkString("artery_notifyserverofswing") +util.AddNetworkString("artery_doanimation") + +net.Receive("artery_notifyserverofswing",function() + local weapon = net.ReadString() + local anim = net.ReadString() + local data = net.ReadTable() + + print("Got swing data for ",weapon,anim) + PrintTable(data) + + --Get the data that already exists for this weapon + local olddata = file.Read("artery/dynamic/swingdata/" .. weapon .. ".txt","DATA") + if olddata == nil then olddata = {} + else olddata = util.JSONToTable(util.Decompress(olddata)) end + + --Add our new data + olddata[anim] = data + + --And save back + file.Write("artery/dynamic/swingdata/" .. weapon .. ".txt",util.Compress(util.TableToJSON(olddata))) +end) + +function ws.makeSwingable(tbl) + assert(tbl.Name,"Tried to make a swingable weapon out of an item with no name!") + assert(tbl.attacks,"Tried to make a swingable weapon out of an item with no attacks! See rustyaxe.lua for example") + assert(tbl.pacname,"Tried to make a swingable weapon without a pac name! see rustyaxe.lua for example") + swingable[tbl.Name] = tbl +end + +concommand.Add("artery_recordanimations",function(ply,cmd,args) + local animqueuetime = 0 + for k,v in pairs(swingable) do + --equip the right item + print("equipable inventory:") + local eqi = ply.data.inventories[1] + print(ply.data.inventories[1]) + local itm = eqi:Get({v.Equipable}) + if itm ~= nil then + eqi:Remove({v.Equipable}) + end + eqi:Put({v.Equipable},v) + + --queue up each attack for the player to do + for i,j in pairs(v.attacks) do + timer.Simple(animqueuetime,function() + print("Doing attack:") + print(i,":",j) + net.Start("artery_doanimation") + net.WriteString(j.anim) + net.WriteDouble(j.time) + net.WriteString(v.Name) + net.WriteString(i) + net.Send(ply) + end) + animqueuetime = animqueuetime + j.time + 1 + end + + end +end) + + + +concommand.Add("artery_checkSwingable",function(ply,cmd,args) + local nitms = 0 + local noswingdata = {} + for k,v in pairs(swingable) do + --Make sure we have a weapon path for everything + if file.Exists( "artery/dynamic/swingdata/" .. k, "DATA" ) then + MsgC(Color(0,255,0),"Found data for " .. k .. "\n") + else + MsgC(Color(255,0,0),"Couldn't find data for " .. k .. "\n") + noswingdata[#noswingdata + 1] = k + end + nitms = nitms + 1 + end + + print("Scanned ",nitms,"swingable items, could not find data for:\n\t",table.concat(noswingdata,"\n\t")) +end) + +concommand.Add("artery_clearswingable",function(ply,cmd,args) + swingable = {} +end) + + +return ws diff --git a/gamemode/core/database/sv_setup.lua b/gamemode/core/database/sv_setup.lua index 2fb7ed7..2cb69d1 100644 --- a/gamemode/core/database/sv_setup.lua +++ b/gamemode/core/database/sv_setup.lua @@ -34,13 +34,18 @@ local function connect() MySQLite.initialize(config) end hook.Add("DatabaseInitialized","setup_table",function() + assert(MySQLite.isMySQL(),"Database wasn't mysqloo, something is probably wrong!") local setup_success = function(res,li) print("Set up connection to db") end print("Setup query:",setup_db) MySQLite.query(setup_db,setup_success,q_fai) end) -connect() + +hook.Add("Initialize","initalizedbconnection",function() + connect() +end) + --Retruns (PlayerData, MetaData) or nil function sql.GetPlayerData(ply) @@ -65,7 +70,7 @@ function sql.GetPlayerData(ply) return end print("We were on the right server") - --[[ + print("Before finding data in the metatable, mtbl was ") PrintTable(mtbl) print(type(mtbl.lastlocation)) @@ -74,8 +79,8 @@ function sql.GetPlayerData(ply) for k,v in pairs(vec) do vec[k] = tonumber(v) end print("setting player pos to") PrintTable(vec) - ]] - ply:SetPos(mtbl.lastlocation) + + ply:SetPos(Vector(unpack(vec))) q.deserialize_player(ply,plyd) end end diff --git a/gamemode/core/inventory/common/items.lua b/gamemode/core/inventory/common/items.lua index 03113f5..95a507c 100644 --- a/gamemode/core/inventory/common/items.lua +++ b/gamemode/core/inventory/common/items.lua @@ -14,15 +14,18 @@ local function drop_self(tbl) end +--Client requests the item be droped from the ent, invid, and inv position function items.DropItem(ent_or_tbl,invid,frompos) + --[[ if type(ent_or_tbl) == "table" then drop_self(ent_or_tbl) else drop_provided(ent_or_tbl,invid,frompos) end + ]] assert(CLIENT,"requested to drop an item when we are not the client!") net.Start("art_RequestInvDrop") - net.WriteEntity(ent) + net.WriteEntity(ent_or_tbl) net.WriteUInt(invid,32) net.WriteTable(frompos) net.SendToServer() diff --git a/gamemode/core/inventory/sv_invtracker.lua b/gamemode/core/inventory/sv_invtracker.lua index 4c1fc1b..47dd164 100644 --- a/gamemode/core/inventory/sv_invtracker.lua +++ b/gamemode/core/inventory/sv_invtracker.lua @@ -63,19 +63,47 @@ net.Receive("art_RequestInvMove",function(len,ply) toinv:Put(topos,item) end) +function track.DropItem(item,pos) + local e = ents.Create("art_droppeditem") + e.Item = {Name = item.Name, Data = item:Serialize()} + e:SetPos(pos) + e:Spawn() +end + net.Receive("art_RequestInvDrop",function(len,ply) local froment = net.ReadEntity() local frominvid = net.ReadUInt(32) local frompos = net.ReadTable() assert(not froment:IsPlayer() or froment == ply, "Player tried to drop an item that was from another players inventory") + print("Using data for drop:") + PrintTable({ + ["froment"] = froment, + ["frominvid"] = frominvid, + ["frompos"] = frompos + }) + print("Player's data is:") + PrintTable(froment.data) local frominv = froment.data.inventories[frominvid] local item = frominv:Get(frompos) frominv:Remove(frompos) - local e = ents.Create("art_droppeditem") - e.Item = {Name = item.Name, Data = item:Serialize()} - e:SetPos((ply:GetForward() * 20) + ply:GetPos()) - e:Spawn() + local placetodrop + --Find somewhere to drop this + local tr = ply:GetEyeTrace() + if tr.Hit then + if tr.HitPos:Distance(ply:GetPos()) < 200 then + placetodrop = tr.HitPos + else + local tr2 = util.TraceLine({ + start = (tr.Normal*200) + tr.StartPos, + endpos = ((tr.Normal*200) + tr.StartPos) + Vector(-2000), + }) + placetodrop = tr2.HitPos + end + else + placetodrop = ply:GetForward() * 200 + end + track.DropItem(item,placetodrop) end) function track.ClearInventories(ply) diff --git a/gamemode/core/npc/sv_common.lua b/gamemode/core/npc/sv_common.lua new file mode 100644 index 0000000..e37a5f8 --- /dev/null +++ b/gamemode/core/npc/sv_common.lua @@ -0,0 +1,38 @@ +--[[ + Some common functions that a lot of npcs use, take out here to make fixing bugs easier. +]] + +local com = {} + +com.pausefor10sec = function(npc) + npc.StartActionTime = CurTime() + 10 + npc:SetSequence(npc:LookupSequence("idle")) + npc.loco:FaceTowards(Vector(-343, 148, 565)) + local oyaw,oacc = npc.loco:GetMaxYawRate(), npc.loco:GetAcceleration() + timer.Simple(0,function() + npc.loco:SetMaxYawRate(0) + npc.loco:SetAcceleration(0) + npc.loco:SetVelocity(Vector(0,0,0)) + end) + timer.Simple(10, function() + npc.loco:SetMaxYawRate(oyaw) + npc.loco:SetAcceleration(oacc) + end) +end + +com.is10secdone = function(npc) + return npc.StartActionTime < CurTime() +end + +com.Rumors = { + "This is a rumor!", + "Here is another!", + "And yet another!", +} + +com.GetRumor = function() + local rng = math.random(#com.Rumors) + return com.Rumors[rng] +end + +return com diff --git a/gamemode/core/npc/sv_huntingspawner.lua b/gamemode/core/npc/sv_huntingspawner.lua new file mode 100644 index 0000000..283b27f --- /dev/null +++ b/gamemode/core/npc/sv_huntingspawner.lua @@ -0,0 +1,118 @@ +--[[ + This file spawns the huntable npc's in their zones. +]] +local track = nrequire("core/inventory/sv_invtracker.lua") +local itm = nrequire("core/inventory/item.lua") +local o = {} + +local huntablenodes = {} +function o.CreateSpawnNode(tbl) + huntablenodes[#huntablenodes+1] = tbl + local e = ents.Create("info_huntablespawn") + e:SetPos(tbl.Position) +end + +local function SpawnMonsterFor(ply,zone) + --Check what hunting ground we're in + print("I want to attack",ply) + if zone == nil then return end + print("I am in a zone!") + local possiblenpcs = zone.npctbl + PrintTable(possiblenpcs) + + local randnum = math.random(0,100) + print("Random num was",randnum) + local npctype + for k,v in pairs(possiblenpcs) do + randnum = randnum - v + print("Subtracting ", v , " for ",k) + if randnum < 0 then + npctype = k + break + end + end + + if npctype == nil then + print(ply,"got lucky this time...") + return + end + print("I will spawn a ",npctype,"to attack ",ply,"!") + + --Find a place for the npc to spawn that's out of sight! + local potentialspots = ents.FindInSphere( ply:GetPos(), 4000 ) + for k,v in pairs(potentialspots) do + print("Checking spot",v) + if v:GetClass() ~= "info_huntablespawn" then + print("Was not an info_huntablespawn") + potentialspots[k] = nil + else + local tr = util.TraceLine({ + start = v:GetPos() + Vector(0,0,50), + endpos = ply:GetPos() + Vector(0,0,64), + }) + if tr.Hit and tr.Entity == ply then + potentialspots[k] = nil + print("Player could see this point") + end + end + end + + local a = {} + for k,v in pairs(potentialspots) do a[#a+1] = v end + + --Choose a random spot! + local spawnpos = a[math.random(1,#a)] + + print("I want to spawn a monster at", spawnpos) + if spawnpos == nil then + print("Couldn't find a spot to spawn an NPC around",ply,"at",ply:GetPos(),"make sure there are enough info_huntablespawn entities around in little corners and stuff") + return + end + --Do a trace up to hit the skybox, + local npc = ents.Create(npctype) + npc:SetPos(spawnpos:GetPos()) + npc:SetEnemy(ply) + npc:Spawn() +end + +local lastspawned = {} +for k,v in pairs(player.GetAll()) do lastspawned[v] = CurTime() end +hook.Add("PlayerInitialSpawn","add_to_huntable_tbl",function(ply) + lastspawned[ply] = CurTime() +end) +hook.Add("Tick","occasionally_spawn_monsters",function() + for _,ply in pairs(player.GetAll()) do + local zone = ply:GetCurrentZone( "artery_huntingground" ) + if zone == nil then continue end + if CurTime() - lastspawned[ply] > zone.SpawnRate then + SpawnMonsterFor(ply,zone) + lastspawned[ply] = CurTime() + end + end +end) + +local external_drops = {} +function o.RegisterDrops(npcname,tbl) + assert(external_drops[npcname] == nil, string.format("Tried to register 2 drop tables for the npc %q",npcname)) + external_drops[npcname] = tbl +end + +hook.Add("OnNPCKilled","droplootforexnpcs",function(npc,attacker,inflictor) + local d = external_drops[npc:GetClass()] + if d == nil then return end + + for k, v in pairs(d) do + local rng = math.random(0, 100) + local itemname = v[1] + local itemchance = v[2] + local heightoffset = 10 + + if rng < itemchance then + local drop = itm.GetItemByName(itemname) + print("Createing a drop of",drop) + track.CreateDroppedItem(drop, self:GetPos()+Vector(math.random(20),math.random(20),20)) + end + end +end) + +return o diff --git a/gamemode/core/npc/sv_npcsystem.lua b/gamemode/core/npc/sv_npcsystem.lua index 1abbc67..78b041f 100644 --- a/gamemode/core/npc/sv_npcsystem.lua +++ b/gamemode/core/npc/sv_npcsystem.lua @@ -11,6 +11,7 @@ function n.RegisterNPC(npc) end function n.CreateNPCByName(npcname, pos) + assert(npcs[npcname],string.format("No npc named %q, valid names are:\n%s",npcname,table.concat(table.GetKeys(npcs),"\n"))) print("Createing a ", npcname, " at ", pos) local npctbl = npcs[npcname] local npc = ents.Create("npc_huntable") @@ -66,23 +67,32 @@ for k, v in pairs(removeents) do end end -local mapfields = {"navnodes", "npcs"} +local function ExecuteOnFolder(dir, recursive, func) + local path = "" + local fpath = table.concat({path,dir,"/*"}) + local files, directories = file.Find(fpath,"DATA") + for k,v in pairs(files) do + local callpath = table.concat({path,dir,"/",v}) + func(callpath) + end + if not recursive then return end + for k,v in pairs(directories) do + local npath = table.concat({dir,"/",v}) + ExecuteOnFolder(npath,true,func) + end +end --- "chests", local function loadMap() - for k, v in ipairs(mapfields) do - local mapname = game.GetMap() - local fpath = string.format("artery/maps/%s/%s/*", mapname, v) - local files, dirs = file.Find(fpath, "DATA") - - for i, j in pairs(files) do - if string.GetExtensionFromFilename(j) ~= "lua" then continue end - local itempath = string.format("artery/maps/%s/%s/%s", mapname, v, j) - local itemtxt = file.Read(itempath, "DATA") - assert(itemtxt ~= nil, "Found a file, but it looks like it can't be compiled:" .. itempath) - CompileString(itemtxt, itempath)() - end - end + local mapname = game.GetMap() + + local foldername = "artery/maps/" .. mapname + ExecuteOnFolder(foldername,true,function(path) + print("I want to run",path) + local filetxt = file.Read(path,"DATA") + print("File text is", filetxt) + CompileString(filetxt,path)() + print("I want to execute",path) + end) end hook.Add("InitPostEntity", "artery_spawnmapnpcs", function() diff --git a/gamemode/core/pac/cl_pac.lua b/gamemode/core/pac/cl_pac.lua index 9163d82..4f1890c 100644 --- a/gamemode/core/pac/cl_pac.lua +++ b/gamemode/core/pac/cl_pac.lua @@ -27,11 +27,13 @@ timer.Simple(0,function() net.SendToServer() end) -file.CreateDir("artery/pacs") +local CLIENT_PAC_DIR = "artery/client/pacs" + +file.CreateDir(CLIENT_PAC_DIR) local function loadpac(ent,name,hash) print("Told to apply pac", name, "to ent", ent) - local filepath = string.format("artery/pacs/%s.txt",name) + local filepath = string.format(CLIENT_PAC_DIR .. "/%s.txt",name) local filetext = file.Read(filepath,"DATA") if ent.AttachPACPart == nil then pac.SetupENT(ent) @@ -52,7 +54,7 @@ local function loadpac(ent,name,hash) end local function unloadpac(ent,name,hash) - local filepath = string.format("artery/pacs/%s.txt",name) + local filepath = string.format(CLIENT_PAC_DIR .. "/%s.txt",name) local filetext = file.Read(filepath,"DATA") local pactbl = CompileString(string.format("return {%s}",filetext),name)() ent:RemovePACPart(pactbl) @@ -62,7 +64,7 @@ net.Receive("artery_downloadpac",function() local pac_name = net.ReadString() local pac_txt = net.ReadString() local pac_hash = net.ReadUInt(32) - local filepath = string.format("artery/pacs/%s.txt",pac_name) + local filepath = string.format(CLIENT_PAC_DIR .."/%s.txt",pac_name) file.Write(filepath,pac_txt) end) diff --git a/gamemode/core/pac/sv_pac.lua b/gamemode/core/pac/sv_pac.lua index 3c5c6be..482dea6 100644 --- a/gamemode/core/pac/sv_pac.lua +++ b/gamemode/core/pac/sv_pac.lua @@ -108,12 +108,16 @@ local function cacheload(key) --If it's already in the cache, just update the time it was last used and return the pac. if pac_cache[key] ~= nil then pac_cache[key].time = CurTime() + if pac_cache[key].pac == nil then + PrintTable(pac_cache) + error("Pac was loaded, but the txt was nil!") + end return pac_cache[key].pac end --Otherwise, we need to load it. local pacpath = string.format("artery/pacs/%s.txt",key) - local pacfile = file.Read(pacpath,"LUA") + local pacfile = file.Read(pacpath,"DATA") --If we haven't reached max cache yet, just put it in if pacs_in_cache < max_pacs_in_cache then |
