联网推进39,修改对战房间进房消息
This commit is contained in:
@@ -2,7 +2,6 @@ local Player=require"parts/player/player"
|
||||
local prepareSequence=require"parts/player/prepareSequence"
|
||||
local gameEnv0=require"parts/player/gameEnv0"
|
||||
|
||||
local mt=love.math
|
||||
local rnd,max=math.random,math.max
|
||||
local ins=table.insert
|
||||
|
||||
@@ -106,7 +105,7 @@ local function newEmptyPlayer(id,mini)
|
||||
P.keyRec=true--If calculate keySpeed
|
||||
P.draw=PLY.draw.norm
|
||||
end
|
||||
P.randGen=mt.newRandomGenerator(GAME.seed)
|
||||
P.randGen=love.math.newRandomGenerator(GAME.seed)
|
||||
|
||||
P.alive=true
|
||||
P.control=false
|
||||
@@ -219,6 +218,7 @@ local function loadGameEnv(P)--Load gameEnv
|
||||
end
|
||||
end
|
||||
local function loadRemoteEnv(P,conf)--Load gameEnv
|
||||
conf=conf and json.decode(love.data.decode("string","base64",conf))or{}
|
||||
P.gameEnv={}--Current game setting environment
|
||||
local ENV=P.gameEnv
|
||||
local GAME,SETTING=GAME,SETTING
|
||||
@@ -372,7 +372,7 @@ function PLY.newRemotePlayer(id,mini,playerData)
|
||||
P.subID=playerData.sid
|
||||
P.ready=playerData.ready
|
||||
|
||||
loadRemoteEnv(P,playerData.conf or{})
|
||||
loadRemoteEnv(P,playerData.conf)
|
||||
applyGameEnv(P)
|
||||
prepareSequence(P)
|
||||
end
|
||||
|
||||
@@ -225,6 +225,7 @@ function Player.setRS(P,RSname)
|
||||
end
|
||||
|
||||
function Player.setConf(P,conf)
|
||||
conf=json.decode(love.data.decode("string","base64",conf))
|
||||
for k,v in next,conf do
|
||||
if not GAME.modeEnv[k]then
|
||||
P.gameEnv[k]=v
|
||||
@@ -339,7 +340,6 @@ function Player.ifoverlap(P,bk,x,y)
|
||||
end
|
||||
end
|
||||
function Player.attack(P,R,send,time,line,fromStream)
|
||||
print(string.format("P%d attack P%d with %d lines, %d frames, line data:%d",P.id,R.id,send,time,line))
|
||||
if GAME.net then
|
||||
if P.type=="human"then--Local player attack others
|
||||
ins(GAME.rep,GAME.frame+1)
|
||||
@@ -367,7 +367,6 @@ function Player.attack(P,R,send,time,line,fromStream)
|
||||
end
|
||||
end
|
||||
function Player.receive(P,A,send,time,line)
|
||||
print(string.format("P%d was attacked by P%d's %d lines, %d frames, line data:%d",P.id,A.id,send,time,line))
|
||||
P.lastRecv=A
|
||||
local B=P.atkBuffer
|
||||
if B.sum<26 then
|
||||
|
||||
@@ -387,7 +387,7 @@ function update.remote_alive(P,dt)
|
||||
elseif event<=64 then--Release key
|
||||
P:releaseKey(event-32)
|
||||
elseif event>0x2000000000000 then--Sending lines
|
||||
local sid=event%0x100
|
||||
local sid=tostring(event%0x100)
|
||||
local amount=int(event/0x100)%0x100
|
||||
local time=int(event/0x10000)%0x10000
|
||||
local line=int(event/0x100000000)%0x10000
|
||||
@@ -403,7 +403,7 @@ function update.remote_alive(P,dt)
|
||||
end
|
||||
elseif event>0x1000000000000 then--Receiving lines
|
||||
local L=PLAYERS.alive
|
||||
local sid=event%0x100
|
||||
local sid=tostring(event%0x100)
|
||||
for i=1,#L do
|
||||
if L[i].subID==sid then
|
||||
P:receive(
|
||||
|
||||
@@ -32,6 +32,7 @@ local function switchChat()
|
||||
end
|
||||
|
||||
|
||||
local playerInitialized
|
||||
local playing
|
||||
local heartBeatTimer
|
||||
local lastUpstreamTime
|
||||
@@ -52,6 +53,7 @@ function scene.sceneInit()
|
||||
love.keyboard.setKeyRepeat(false)
|
||||
TASK.new(TICK_wsRead)
|
||||
hideChatBox=true
|
||||
playerInitialized=false
|
||||
textBox:clear()
|
||||
|
||||
playerData={}
|
||||
@@ -189,44 +191,51 @@ end
|
||||
function scene.socketRead(mes)
|
||||
local cmd=mes:sub(1,1)
|
||||
local args=splitStr(mes:sub(2),";")
|
||||
if cmd=="J"or cmd=="L"then
|
||||
if cmd=="J"then
|
||||
if playerInitialized then
|
||||
local L=splitStr(args[1],",")
|
||||
textBox:push{
|
||||
COLOR.lR,L[1],
|
||||
COLOR.dY,L[2].." ",
|
||||
COLOR.Y,text.joinRoom,
|
||||
}
|
||||
end
|
||||
for i=1,#args do
|
||||
local L=splitStr(args[i],",")
|
||||
L={name=L[1],id=L[2],sid=L[3],conf=L[4],ready=L[5]=="1"}
|
||||
if tostring(USER.id)~=L.id then
|
||||
ins(playerData,L)
|
||||
else
|
||||
ins(playerData,1,L)
|
||||
end
|
||||
end
|
||||
playerInitialized=true
|
||||
resetGameData("qn",playerData)
|
||||
elseif cmd=="L"then
|
||||
textBox:push{
|
||||
COLOR.lR,args[1],
|
||||
COLOR.dY,args[2].." ",
|
||||
COLOR.Y,text[cmd=="J"and"joinRoom"or"leaveRoom"]
|
||||
COLOR.Y,text.leaveRoom,
|
||||
}
|
||||
if cmd=="J"then
|
||||
for i=1,#args do
|
||||
local L=splitStr(args[i],",")
|
||||
L={name=L[1],id=L[2],sid=tonumber(L[3]),conf=L[4],ready=L[5]=="1"}
|
||||
if tostring(USER.id)~=L[2]then
|
||||
ins(playerData,L)
|
||||
else
|
||||
ins(playerData,1,L)
|
||||
end
|
||||
end
|
||||
resetGameData("qn",playerData)
|
||||
else
|
||||
for i=1,#playerData do
|
||||
if playerData[i].id==args[2]then
|
||||
rem(playerData,i)
|
||||
break
|
||||
end
|
||||
end
|
||||
for i=1,#PLAYERS do
|
||||
if PLAYERS[i].userID==args[2]then
|
||||
rem(PLAYERS,i)
|
||||
break
|
||||
end
|
||||
end
|
||||
for i=1,#PLAYERS.alive do
|
||||
if PLAYERS.alive[i].userID==args[2]then
|
||||
rem(PLAYERS.alive,i)
|
||||
initPlayerPosition(true)
|
||||
return
|
||||
end
|
||||
for i=1,#playerData do
|
||||
if playerData[i].id==args[2]then
|
||||
rem(playerData,i)
|
||||
break
|
||||
end
|
||||
end
|
||||
for i=1,#PLAYERS do
|
||||
if PLAYERS[i].userID==args[2]then
|
||||
rem(PLAYERS,i)
|
||||
break
|
||||
end
|
||||
end
|
||||
for i=1,#PLAYERS.alive do
|
||||
if PLAYERS.alive[i].userID==args[2]then
|
||||
rem(PLAYERS.alive,i)
|
||||
break
|
||||
end
|
||||
end
|
||||
initPlayerPosition(true)
|
||||
elseif cmd=="T"then
|
||||
textBox:push{
|
||||
COLOR.W,args[1],
|
||||
@@ -235,19 +244,17 @@ function scene.socketRead(mes)
|
||||
}
|
||||
elseif cmd=="C"then
|
||||
if tostring(USER.id)~=args[2]then
|
||||
local ENV=json.decode(data.decode("string","base64",args[4]))
|
||||
for i=1,#playerData do
|
||||
if playerData[i].id==args[2]then
|
||||
playerData[i].conf=ENV
|
||||
playerData[i].p:setConf(ENV)
|
||||
playerData[i].conf=args[4]
|
||||
playerData[i].p:setConf(args[4])
|
||||
return
|
||||
end
|
||||
end
|
||||
ins(playerData,{name=args[1],id=args[2],sid=tonumber(args[3]),conf=ENV})
|
||||
resetGameData("qn",playerData)
|
||||
end
|
||||
elseif cmd=="S"then
|
||||
if args[1]~=tostring(PLAYERS[1].sid)then
|
||||
if args[1]~=PLAYERS[1].subID then
|
||||
for _,P in next,PLAYERS do
|
||||
if P.subID==args[1]then
|
||||
pumpRecording(data.decode("string","base64",args[2]),P.stream)
|
||||
|
||||
Reference in New Issue
Block a user