From 4d1caa7fe02eb1eb2fa2a4200c295d641e682f52 Mon Sep 17 00:00:00 2001 From: MrZ_26 <1046101471@qq.com> Date: Sat, 10 Aug 2024 12:55:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=8E=A9=E5=AE=B6=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E4=BA=8B=E4=BB=B6=E7=B3=BB=E7=BB=9F=EF=BC=8C=E5=B0=9D?= =?UTF-8?q?=E8=AF=95=E6=94=AF=E6=8C=81=E5=8F=AF=E9=80=9A=E8=BF=87=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E4=BC=A0=E9=80=92=E7=9A=84=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/gameFuncs.lua | 11 +++++ parts/player/player.lua | 105 ++++++++++++++++++---------------------- 2 files changed, 57 insertions(+), 59 deletions(-) diff --git a/parts/gameFuncs.lua b/parts/gameFuncs.lua index 705f6dad..e4414aab 100644 --- a/parts/gameFuncs.lua +++ b/parts/gameFuncs.lua @@ -570,6 +570,16 @@ 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 @@ -577,6 +587,7 @@ 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 diff --git a/parts/player/player.lua b/parts/player/player.lua index c58f9365..9ee22ef1 100644 --- a/parts/player/player.lua +++ b/parts/player/player.lua @@ -701,6 +701,37 @@ function Player:_triggerEvent(eventName) return true end end +function Player:extraEvent(eventName,...) + if not (GAME.curMode.extraEvent and GAME.curMode.extraEventHandler) then return end + local list=GAME.curMode.extraEvent + local eventID + for i=1,#list do + if list[i][1]==eventName then + eventID=i + break + end + end + if not eventID then + MES.new('warn',"Extra event '"..eventName.."' doesn't exist in this mode") + return + end + + -- Write to stream + if self.type=='human' then + ins(GAME.rep,self.frameRun) + ins(GAME.rep,eventID) + 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,...) + end +end function Player:getHolePos()-- Get a good garbage-line hole position if self.garbageBeneath==0 then @@ -833,34 +864,13 @@ function Player:ifoverlap(bk,x,y) end end end -function Player:attack(R,send,time,line,fromStream) - if GAME.net then - if self.type=='human' then-- Local player attack others - ins(GAME.rep,self.frameRun) - ins(GAME.rep, - R.sid+ - send*0x100+ - time*0x10000+ - line*0x100000000+ - 0x2000000000000 - ) - self:createBeam(R,send) - end - if fromStream and R.type=='human' then-- Local player receiving lines - ins(GAME.rep,R.frameRun) - ins(GAME.rep, - self.sid+ - send*0x100+ - time*0x10000+ - line*0x100000000+ - 0x1000000000000 - ) - R:receive(self,send,time,line) - end - else - R:receive(self,send,time,line) - self:createBeam(R,send) - end +function Player:attack(R,send,time,line) + self:extraEvent('attack',R.sid,send,time,line) +end +function Player:beAttacked(P2,sid,send,time,line) + if self==P2 or self.sid~=sid then return end + self:receive(P2,send,time,line) + P2:createBeam(self,send) end function Player:receive(A,send,time,line) self.lastRecv=A @@ -2708,38 +2718,15 @@ local function update_streaming(P) P:pressKey(event) elseif event<=64 then-- Release key P:releaseKey(event-32) - elseif event>0x2000000000000 then-- Sending lines - local sid=event%0x100 - local amount=floor(event/0x100)%0x100 - local time=floor(event/0x10000)%0x10000 - local line=floor(event/0x100000000)%0x10000 - for _,p in next,PLY_ALIVE do - if p.sid==sid then - P.netAtk=P.netAtk+amount - if P.netAtk~=P.stat.send then-- He cheated or just desynchronized to death - MES.new('warn',"#"..P.uid.." desynchronized") - NET.player_finish({reason='desync'}) - P:lose(true) - return - end - P:attack(p,amount,time,line,true) - P:createBeam(p,amount) - break - end - end - elseif event>0x1000000000000 then-- Receiving lines - local sid=event%0x100 - for _,p in next,PLY_ALIVE do - if p.sid==sid then - P:receive( - p, - floor(event/0x100)%0x100,-- amount - floor(event/0x10000)%0x10000,-- time - floor(event/0x100000000)%0x10000-- line - ) - break - end + elseif event<=128 then-- Custom Event + local eventName=P.gameEnv.extraEvent[event-64][1] + local eventParamCount=P.gameEnv.extraEvent[event-64][2] + local paramList={} + for i=1,eventParamCount do + ins(paramList,P.stream[P.streamProgress+1+i]) end + P.streamProgress=P.streamProgress+eventParamCount + P:extraEvent(eventName,unpack(paramList)) end P.streamProgress=P.streamProgress+2 eventTime=P.stream[P.streamProgress]