基本完成中途加入的观战
修复从联网游戏房间退出不会把GAME.playing置false checkWarning的玩家改成输入而不是自动获取 整理代码
This commit is contained in:
@@ -800,13 +800,12 @@ do-- function resetGameData(args)
|
|||||||
collectgarbage()
|
collectgarbage()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
do-- function checkWarning()
|
do-- function checkWarning(P,dt)
|
||||||
local max=math.max
|
local max=math.max
|
||||||
function checkWarning(dt)
|
function checkWarning(P,dt)
|
||||||
local P1=PLAYERS[1]
|
if P.alive then
|
||||||
if P1.alive then
|
if P.frameRun%26==0 then
|
||||||
if P1.frameRun%26==0 then
|
local F=P.field
|
||||||
local F=P1.field
|
|
||||||
local height=0-- Max height of row 4~7
|
local height=0-- Max height of row 4~7
|
||||||
for x=4,7 do
|
for x=4,7 do
|
||||||
for y=#F,1,-1 do
|
for y=#F,1,-1 do
|
||||||
@@ -818,7 +817,7 @@ do-- function checkWarning()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
GAME.warnLVL0=math.log(height-(P1.gameEnv.fieldH-5)+P1.atkBufferSum*.8)
|
GAME.warnLVL0=math.log(height-(P.gameEnv.fieldH-5)+P.atkBufferSum*.8)
|
||||||
end
|
end
|
||||||
local _=GAME.warnLVL
|
local _=GAME.warnLVL
|
||||||
if _<GAME.warnLVL0 then
|
if _<GAME.warnLVL0 then
|
||||||
@@ -827,7 +826,7 @@ do-- function checkWarning()
|
|||||||
_=max(_-.026,0)
|
_=max(_-.026,0)
|
||||||
end
|
end
|
||||||
GAME.warnLVL=_
|
GAME.warnLVL=_
|
||||||
if GAME.warnLVL>1.126 and P1.frameRun%30==0 then
|
if GAME.warnLVL>1.126 and P.frameRun%30==0 then
|
||||||
SFX.fplay('warn_beep',SETTING.sfx_warn)
|
SFX.fplay('warn_beep',SETTING.sfx_warn)
|
||||||
end
|
end
|
||||||
elseif GAME.warnLVL>0 then
|
elseif GAME.warnLVL>0 then
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ local WS=WS
|
|||||||
local NET={
|
local NET={
|
||||||
uid=false,
|
uid=false,
|
||||||
uid_sid={},
|
uid_sid={},
|
||||||
storedStream={},
|
storedStream=false,
|
||||||
|
|
||||||
roomState={-- A copy of room structure on server
|
roomState={-- A copy of room structure on server
|
||||||
info={
|
info={
|
||||||
@@ -440,19 +440,19 @@ end
|
|||||||
|
|
||||||
--Remove player when leave
|
--Remove player when leave
|
||||||
local function _playerLeaveRoom(uid)
|
local function _playerLeaveRoom(uid)
|
||||||
if SCN.cur=='net_game' then
|
if SCN.cur~='net_game' then return end
|
||||||
for i=1,#PLAYERS do if PLAYERS[i].uid==uid then table.remove(PLAYERS,i) break end end
|
for i=1,#PLAYERS do if PLAYERS[i].uid==uid then table.remove(PLAYERS,i) break end end
|
||||||
for i=1,#PLY_ALIVE do if PLY_ALIVE[i].uid==uid then table.remove(PLY_ALIVE,i) break end end
|
for i=1,#PLY_ALIVE do if PLY_ALIVE[i].uid==uid then table.remove(PLY_ALIVE,i) break end end
|
||||||
if uid==USER.uid then
|
if uid==USER.uid then
|
||||||
|
GAME.playing=false
|
||||||
SCN.backTo('net_menu')
|
SCN.backTo('net_menu')
|
||||||
else
|
else
|
||||||
NETPLY.remove(uid)
|
NETPLY.remove(uid)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--Push stream data to players
|
--Push stream data to players
|
||||||
local function _pumpStream(d)
|
function NET.pumpStream(d)
|
||||||
if d.playerId==USER.uid then return end
|
if d.playerId==USER.uid then return end
|
||||||
for _,P in next,PLAYERS do
|
for _,P in next,PLAYERS do
|
||||||
if P.uid==d.playerId then
|
if P.uid==d.playerId then
|
||||||
@@ -586,14 +586,13 @@ function NET.wsCallBack.global_getOnlineCount(body)
|
|||||||
NET.onlineCount=tonumber(body.data) or "_"
|
NET.onlineCount=tonumber(body.data) or "_"
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.room_chat(body)
|
function NET.wsCallBack.room_chat(body)
|
||||||
if SCN.cur=='net_game' then
|
if SCN.cur~='net_game' then return end
|
||||||
TASK.unlock('receiveMessage')
|
TASK.unlock('receiveMessage')
|
||||||
TASK.lock('receiveMessage',1)
|
TASK.lock('receiveMessage',1)
|
||||||
NET.textBox:push{
|
NET.textBox:push{
|
||||||
COLOR.Z,_getFullName(body.data.playerId),
|
COLOR.Z,_getFullName(body.data.playerId),
|
||||||
COLOR.N,body.data.message,
|
COLOR.N,body.data.message,
|
||||||
}
|
}
|
||||||
end
|
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.room_create(body)
|
function NET.wsCallBack.room_create(body)
|
||||||
MES.new('check',text.createRoomSuccessed)
|
MES.new('check',text.createRoomSuccessed)
|
||||||
@@ -625,7 +624,6 @@ function NET.wsCallBack.room_enter(body)
|
|||||||
NET.roomState=body.data
|
NET.roomState=body.data
|
||||||
NETPLY.clear()
|
NETPLY.clear()
|
||||||
destroyPlayers()
|
destroyPlayers()
|
||||||
TABLE.cut(NET.storedStream)
|
|
||||||
loadGame('netBattle',true,true)
|
loadGame('netBattle',true,true)
|
||||||
for _,p in next,body.data.players do
|
for _,p in next,body.data.players do
|
||||||
NETPLY.add{
|
NETPLY.add{
|
||||||
@@ -638,6 +636,7 @@ function NET.wsCallBack.room_enter(body)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
if NET.roomState.state=='Playing' then
|
if NET.roomState.state=='Playing' then
|
||||||
|
NET.storedStream={}
|
||||||
for _,p in next,body.data.players do
|
for _,p in next,body.data.players do
|
||||||
table.insert(NET.storedStream,{
|
table.insert(NET.storedStream,{
|
||||||
playerId=p.playerId,
|
playerId=p.playerId,
|
||||||
@@ -660,7 +659,7 @@ function NET.wsCallBack.room_enter(body)
|
|||||||
config=p.config,
|
config=p.config,
|
||||||
}
|
}
|
||||||
NET.textBox:push{COLOR.Y,text.joinRoom:repD(_getFullName(p.playerId))}
|
NET.textBox:push{COLOR.Y,text.joinRoom:repD(_getFullName(p.playerId))}
|
||||||
if not GAME.playing then
|
if not TASK.getLock('netPlaying') then
|
||||||
SFX.play('connected')
|
SFX.play('connected')
|
||||||
NET.freshRoomAllReady()
|
NET.freshRoomAllReady()
|
||||||
end
|
end
|
||||||
@@ -723,7 +722,7 @@ function NET.wsCallBack.player_setState(body)-- not used
|
|||||||
end
|
end
|
||||||
function NET.wsCallBack.player_stream(body)
|
function NET.wsCallBack.player_stream(body)
|
||||||
if SCN.cur~='net_game' then return end
|
if SCN.cur~='net_game' then return end
|
||||||
_pumpStream(body.data)
|
NET.pumpStream(body.data)
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_setPlayMode(body)
|
function NET.wsCallBack.player_setPlayMode(body)
|
||||||
if SCN.cur~='net_game' then return end
|
if SCN.cur~='net_game' then return end
|
||||||
@@ -773,6 +772,7 @@ function NET.ws_update()
|
|||||||
TEST.yieldT(1/26)
|
TEST.yieldT(1/26)
|
||||||
if WS.status('game')=='dead' then
|
if WS.status('game')=='dead' then
|
||||||
TEST.yieldUntilNextScene()
|
TEST.yieldUntilNextScene()
|
||||||
|
GAME.playing=false
|
||||||
SCN.backTo('main')
|
SCN.backTo('main')
|
||||||
return
|
return
|
||||||
elseif WS.status('game')=='running' then
|
elseif WS.status('game')=='running' then
|
||||||
@@ -791,6 +791,7 @@ function NET.ws_update()
|
|||||||
USER.uid=res.data
|
USER.uid=res.data
|
||||||
else
|
else
|
||||||
TEST.yieldUntilNextScene()
|
TEST.yieldUntilNextScene()
|
||||||
|
GAME.playing=false
|
||||||
SCN.backTo('main')
|
SCN.backTo('main')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -806,6 +807,7 @@ function NET.ws_update()
|
|||||||
|
|
||||||
if WS.status('game')=='dead' then
|
if WS.status('game')=='dead' then
|
||||||
TEST.yieldUntilNextScene()
|
TEST.yieldUntilNextScene()
|
||||||
|
GAME.playing=false
|
||||||
SCN.backTo('main')
|
SCN.backTo('main')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -824,12 +826,13 @@ function NET.ws_update()
|
|||||||
if msg and msg.message then LOG(msg.message) end
|
if msg and msg.message then LOG(msg.message) end
|
||||||
end
|
end
|
||||||
TEST.yieldUntilNextScene()
|
TEST.yieldUntilNextScene()
|
||||||
|
GAME.playing=false
|
||||||
SCN.backTo('main')
|
SCN.backTo('main')
|
||||||
return
|
return
|
||||||
elseif msg then
|
elseif msg then
|
||||||
msg=JSON.decode(msg)
|
msg=JSON.decode(msg)
|
||||||
-- print(("Recv: <-- $1 err:$2"):repD(msg.action,msg.errno))
|
-- print(("Recv: <-- $1 err:$2"):repD(msg.action,msg.errno))
|
||||||
print(("Recv: <-- $1 err:$2"):repD(msg.action,msg.errno)) print(TABLE.dump(msg),"\n")
|
-- print(("Recv: <-- $1 err:$2"):repD(msg.action,msg.errno)) print(TABLE.dump(msg),"\n")
|
||||||
if msg.errno~=0 then
|
if msg.errno~=0 then
|
||||||
parseError(msg.message~=nil and msg.message or msg)
|
parseError(msg.message~=nil and msg.message or msg)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ local function _update_common(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Warning check
|
-- Warning check
|
||||||
checkWarning(dt)
|
checkWarning(PLAYERS[1],dt)
|
||||||
end
|
end
|
||||||
function scene.update(dt)
|
function scene.update(dt)
|
||||||
trigGameRate=trigGameRate+gameRate
|
trigGameRate=trigGameRate+gameRate
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ end
|
|||||||
local function _quit()
|
local function _quit()
|
||||||
if tryBack() then
|
if tryBack() then
|
||||||
NET.room_leave()
|
NET.room_leave()
|
||||||
|
GAME.playing=false
|
||||||
SCN.back()
|
SCN.back()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -218,16 +219,17 @@ function scene.update(dt)
|
|||||||
NET.freshRoomAllReady()
|
NET.freshRoomAllReady()
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
local P1=PLAYERS[1]
|
|
||||||
|
|
||||||
touchMoveLastFrame=false
|
touchMoveLastFrame=false
|
||||||
VK.update(dt)
|
VK.update(dt)
|
||||||
|
|
||||||
|
if #PLAYERS>0 then
|
||||||
-- Update players
|
-- Update players
|
||||||
for p=1,#PLAYERS do PLAYERS[p]:update(dt) end
|
for p=1,#PLAYERS do PLAYERS[p]:update(dt) end
|
||||||
|
|
||||||
|
local P1=PLAYERS[1]
|
||||||
|
|
||||||
-- Warning check
|
-- Warning check
|
||||||
checkWarning(dt)
|
checkWarning(P1,dt)
|
||||||
|
|
||||||
-- Upload stream
|
-- Upload stream
|
||||||
if not NET.spectate and P1.frameRun-lastUpstreamTime>8 then
|
if not NET.spectate and P1.frameRun-lastUpstreamTime>8 then
|
||||||
@@ -246,6 +248,7 @@ function scene.update(dt)
|
|||||||
lastUpstreamTime=PLAYERS[1].alive and P1.frameRun or 1e99
|
lastUpstreamTime=PLAYERS[1].alive and P1.frameRun or 1e99
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
if not TASK.getLock('netPlaying') then
|
if not TASK.getLock('netPlaying') then
|
||||||
NETPLY.update(dt)
|
NETPLY.update(dt)
|
||||||
@@ -256,10 +259,17 @@ function scene.update(dt)
|
|||||||
upstreamProgress=1
|
upstreamProgress=1
|
||||||
resetGameData('n',NET.seed)
|
resetGameData('n',NET.seed)
|
||||||
NETPLY.mouseMove(0,0)
|
NETPLY.mouseMove(0,0)
|
||||||
|
|
||||||
for i=1,#NETPLY.list do
|
for i=1,#NETPLY.list do
|
||||||
NETPLY.list[i].readyMode='Playing'
|
NETPLY.list[i].readyMode='Playing'
|
||||||
end
|
end
|
||||||
NET.spectate=PLAYERS[1].uid~=USER.uid
|
NET.spectate=PLAYERS[1].uid~=USER.uid
|
||||||
|
if NET.storedStream then
|
||||||
|
for i=1,#NET.storedStream do
|
||||||
|
NET.pumpStream(NET.storedStream[i])
|
||||||
|
end
|
||||||
|
NET.storedStream=false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user