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