aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/combat
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/core/combat')
-rw-r--r--gamemode/core/combat/cl_weaponswing.lua57
-rw-r--r--gamemode/core/combat/sv_weaponswing.lua99
2 files changed, 156 insertions, 0 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