修新的事件系统问题
This commit is contained in:
@@ -256,54 +256,34 @@ end
|
||||
large value will be encoded as 1xxxxxxx(high)-1xxxxxxx-...-0xxxxxxx(low)
|
||||
|
||||
Example (decoded):
|
||||
6,1, 20,-1, 0,2, 26,-2, 872,4, ...
|
||||
26,1, 42,-1, ...
|
||||
This means:
|
||||
Press key1 at 6f
|
||||
Release key1 at 26f (6+20)
|
||||
Press key2 at the same time (26+0)
|
||||
Release key 2 after 26 frame (26+26)
|
||||
Press key 4 after 872 frame (52+872)
|
||||
Press key1 at 26f
|
||||
Release key1 at 42f
|
||||
...
|
||||
]]
|
||||
function DATA.dumpRecording(list,ptr)
|
||||
local out=""
|
||||
local buffer=""
|
||||
if not ptr then ptr=1 end
|
||||
local prevFrm=list[ptr-2] or 0
|
||||
while list[ptr] do
|
||||
-- Flush buffer
|
||||
if #buffer>10 then
|
||||
if #buffer>26 then
|
||||
out=out..buffer
|
||||
buffer=""
|
||||
end
|
||||
|
||||
-- Encode time
|
||||
local t=list[ptr]-prevFrm
|
||||
prevFrm=list[ptr]
|
||||
buffer=buffer.._encode(t)
|
||||
|
||||
-- Encode event
|
||||
buffer=buffer.._encode(list[ptr+1])
|
||||
|
||||
-- Step
|
||||
ptr=ptr+2
|
||||
buffer=buffer.._encode(list[ptr])
|
||||
ptr=ptr+1
|
||||
end
|
||||
return out..buffer,ptr
|
||||
end
|
||||
function DATA.pumpRecording(str,L)
|
||||
local len=#str
|
||||
local p=1
|
||||
local data
|
||||
|
||||
local curFrm=L[#L-1] or 0
|
||||
while p<=len do
|
||||
local code,event
|
||||
-- Read delta time
|
||||
code,p=_decode(str,p)
|
||||
curFrm=curFrm+code
|
||||
ins(L,curFrm)
|
||||
|
||||
event,p=_decode(str,p)
|
||||
ins(L,event)
|
||||
data,p=_decode(str,p)
|
||||
ins(L,data)
|
||||
end
|
||||
end
|
||||
do-- function DATA.saveReplay()
|
||||
|
||||
@@ -570,16 +570,6 @@ function applyCustomGame()-- Apply CUSTOMENV, BAG, MISSION
|
||||
GAME.modeEnv.mission=nil
|
||||
end
|
||||
end
|
||||
local defaultAttackRule={
|
||||
extraEvent={
|
||||
{'attack',4},
|
||||
},
|
||||
extraEventHandler={
|
||||
attack=function(P,P2,...)
|
||||
P:beAttacked(P2,...)
|
||||
end,
|
||||
},
|
||||
}
|
||||
function loadGame(mode,ifQuickPlay,ifNet)-- Load a mode and go to game scene
|
||||
freshDate()
|
||||
if legalGameTime() then
|
||||
@@ -587,7 +577,6 @@ function loadGame(mode,ifQuickPlay,ifNet)-- Load a mode and go to game scene
|
||||
MODES[mode]=require('parts.modes.'..mode)
|
||||
MODES[mode].name=mode
|
||||
end
|
||||
TABLE.complete(defaultAttackRule,MODES[mode])
|
||||
if MODES[mode].score then
|
||||
STAT.lastPlay=mode
|
||||
end
|
||||
|
||||
@@ -66,6 +66,15 @@ return {
|
||||
hook_drop={},
|
||||
hook_die={},
|
||||
task={},
|
||||
extraEvent={
|
||||
{'attack',4},
|
||||
},
|
||||
extraEventHandler={
|
||||
attack=function(P,P2,...)
|
||||
P:beAttacked(P2,...)
|
||||
end,
|
||||
},
|
||||
|
||||
eventSet="X",
|
||||
|
||||
bg='none',bgm='race',
|
||||
|
||||
@@ -247,6 +247,7 @@ local function _mergeFuncTable(f,L)
|
||||
return L
|
||||
end
|
||||
local hooks = {
|
||||
'task',
|
||||
'mesDisp',
|
||||
'hook_left',
|
||||
'hook_left_manual',
|
||||
@@ -259,7 +260,6 @@ local hooks = {
|
||||
'hook_spawn',
|
||||
'hook_hold',
|
||||
'hook_die',
|
||||
'task'
|
||||
}
|
||||
local function _applyGameEnv(P)-- Finish gameEnv processing
|
||||
local ENV=P.gameEnv
|
||||
|
||||
@@ -702,8 +702,8 @@ function Player:_triggerEvent(eventName)
|
||||
end
|
||||
end
|
||||
function Player:extraEvent(eventName,...)
|
||||
if not (GAME.curMode.extraEvent and GAME.curMode.extraEventHandler) then return end
|
||||
local list=GAME.curMode.extraEvent
|
||||
if not (self.gameEnv.extraEvent and self.gameEnv.extraEventHandler) then return end
|
||||
local list=self.gameEnv.extraEvent
|
||||
local eventID
|
||||
for i=1,#list do
|
||||
if list[i][1]==eventName then
|
||||
@@ -719,17 +719,19 @@ function Player:extraEvent(eventName,...)
|
||||
-- Write to stream
|
||||
if self.type=='human' then
|
||||
ins(GAME.rep,self.frameRun)
|
||||
ins(GAME.rep,eventID)
|
||||
ins(GAME.rep,64+eventID)
|
||||
ins(GAME.rep,self.sid)
|
||||
local data={...}
|
||||
for i=1,#data do
|
||||
ins(GAME.rep,data[i])
|
||||
end
|
||||
end
|
||||
|
||||
-- Trigger for everyone
|
||||
for i=1,#PLAYERS do
|
||||
local R=PLAYERS[i]
|
||||
GAME.curMode.extraEventHandler[eventName](R,self,...)
|
||||
-- Trigger for all non-remote players
|
||||
for _,p in next,PLAYERS do
|
||||
if p.type~='remote' then
|
||||
self.gameEnv.extraEventHandler[eventName](p,self,...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2718,15 +2720,31 @@ local function update_streaming(P)
|
||||
P:pressKey(event)
|
||||
elseif event<=64 then-- Release key
|
||||
P:releaseKey(event-32)
|
||||
elseif event<=128 then-- Custom Event
|
||||
elseif event<=128 then-- Extra Event
|
||||
local eventName=P.gameEnv.extraEvent[event-64][1]
|
||||
local eventParamCount=P.gameEnv.extraEvent[event-64][2]
|
||||
local sourceSid=P.stream[P.streamProgress+2]
|
||||
local paramList={}
|
||||
for i=1,eventParamCount do
|
||||
ins(paramList,P.stream[P.streamProgress+1+i])
|
||||
ins(paramList,P.stream[P.streamProgress+2+i])
|
||||
end
|
||||
P.streamProgress=P.streamProgress+eventParamCount
|
||||
P:extraEvent(eventName,unpack(paramList))
|
||||
P.streamProgress=P.streamProgress+eventParamCount+1
|
||||
|
||||
local SRC
|
||||
local SELF
|
||||
for _,p in next,PLAYERS do
|
||||
if p.sid==sourceSid then
|
||||
SRC=p
|
||||
break
|
||||
end
|
||||
end
|
||||
for _,p in next,PLAYERS do
|
||||
if p.type=='human' then
|
||||
SELF=p
|
||||
break
|
||||
end
|
||||
end
|
||||
SELF.gameEnv.extraEventHandler[eventName](SRC,SELF,unpack(paramList))
|
||||
end
|
||||
P.streamProgress=P.streamProgress+2
|
||||
eventTime=P.stream[P.streamProgress]
|
||||
|
||||
Reference in New Issue
Block a user