From 4e606f4e916cb1914b70e59a4c0c7081b9cd1904 Mon Sep 17 00:00:00 2001 From: Imple Lee <80144331+ImpleLee@users.noreply.github.com> Date: Wed, 22 Nov 2023 18:00:00 +0800 Subject: [PATCH] split spawn and popNext --- parts/player/init.lua | 2 +- parts/player/player.lua | 174 +++++++++++++++++++--------------------- 2 files changed, 83 insertions(+), 93 deletions(-) diff --git a/parts/player/init.lua b/parts/player/init.lua index 6a117672..1d8dc645 100644 --- a/parts/player/init.lua +++ b/parts/player/init.lua @@ -430,7 +430,7 @@ function PLY.newDemoPlayer(id) delay=6, node=100000, } - P:popNext() + P:spawn() end function PLY.newRemotePlayer(id,mini,p) local P=_newEmptyPlayer(id,mini) diff --git a/parts/player/player.lua b/parts/player/player.lua index 606d203c..5fe019ea 100644 --- a/parts/player/player.lua +++ b/parts/player/player.lua @@ -534,7 +534,7 @@ local playerActions={ if self.waiting>self.gameEnv.hurry then self.waiting=self.gameEnv.hurry if self.waiting==0 and self.falling==0 then - self:popNext() + self:spawn() end end self.keyPressing[keyID]=true @@ -1262,6 +1262,29 @@ local phyHoldKickX={ [true]={0,-1,1},-- X==?.0 tests [false]={-.5,.5},-- X==?.5 tests } +function Player:_try_physical_hold_with(H) + local C=self.cur + if not C or not H then return end + local x,y=self.curX,self.curY + x=x+(#C.bk[1]-#H.bk[1])*.5 + y=y+(#C.bk-#H.bk)*.5 + + local iki=phyHoldKickX[x==floor(x)] + for Y=floor(y),ceil(y+.5) do + for i=1,#iki do + local X=x+iki[i] + if not self:ifoverlap(H.bk,X,Y) then + return X,Y + end + end + end +end +function Player:_get_new_block(C) + local hb=self:getBlock(C.id) + hb.color=C.color + hb.name=C.name + return hb +end function Player:hold_norm(ifpre) local ENV=self.gameEnv if #self.holdQueueENV.holdCount or ENV.holdMode=='swap' and #self.holdQueue>0 then self:hold(true,true) - elseif self.nextQueue[1] then - self.cur=rem(self.nextQueue,1) - self.cur.bagLine=nil - self:newNext() - self.pieceCount=self.pieceCount+1 + return + end - local pressing=self.keyPressing + self.holdTime=min(self.holdTime+1,ENV.holdCount) - -- IHS - if not ifhold and pressing[8] and ENV.ihs and self.holdTime>0 then - self:hold(true) - pressing[8]=false - else - self:resetBlock() - end - - self.dropDelay=ENV.drop - self.lockDelay=ENV.lock - self.freshTime=ENV.freshLimit - - if self.cur then - self:_checkSuffocate() - self:freshBlock('newBlock') - end - - -- IHdS - if pressing[6] and not ifhold then - self:act_hardDrop() - pressing[6]=false - end + if self.nextQueue[1] then + self:_popNext() elseif self.holdQueue[1] then-- Force using hold + self.spinLast=false + self.ctrlCount=0 self:hold(true,true) + self:_triggerEvent('hook_spawn') else-- Next queue is empty, force lose + self.spinLast=false + self.ctrlCount=0 self:lose(true) return end +end +function Player:_popNext(ifhold)-- Pop nextQueue to hand + if not self.nextQueue[1] then return end + local ENV=self.gameEnv + self.spinLast=false + self.ctrlCount=0 + self.cur=rem(self.nextQueue,1) + self.cur.bagLine=nil + self:newNext() + self.pieceCount=self.pieceCount+1 + + local pressing=self.keyPressing + + -- IHS + if not ifhold and pressing[8] and ENV.ihs and self.holdTime>0 then + self:hold(true) + pressing[8]=false + else + self:resetBlock() + end + + self.dropDelay=ENV.drop + self.lockDelay=ENV.lock + self.freshTime=ENV.freshLimit + + if self.cur then + self:_checkSuffocate() + self:freshBlock('newBlock') + end + + -- IHdS + if pressing[6] and not ifhold then + self:act_hardDrop() + pressing[6]=false + end self:_triggerEvent('hook_spawn') end function Player:willDieWith(B) @@ -2145,7 +2135,7 @@ do self.cur=nil if self.waiting==0 and self.falling==0 then - self:popNext() + self:spawn() end end @@ -2437,7 +2427,7 @@ local function update_alive(P,dt) if P.id==1 then playReadySFX(0) end P.control=true P.timing=true - P:popNext() + P:spawn() if P.bot then P.bot:updateField() end @@ -2585,7 +2575,7 @@ local function update_alive(P,dt) P.waiting=P.waiting-1 end if P.waiting<=0 then - P:popNext() + P:spawn() end break-- goto THROW_stop end