Skip to content

Commit

Permalink
进一步重构琼晶消除结算流程
Browse files Browse the repository at this point in the history
  • Loading branch information
MrZ626 committed May 9, 2024
1 parent 01c1065 commit 7038100
Showing 1 changed file with 58 additions and 58 deletions.
116 changes: 58 additions & 58 deletions assets/game/gelaPlayer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -661,19 +661,20 @@ function GP:gelaDropped() -- Drop & lock gela, and trigger a lot of things
self:finish('CE')
end

-- Trimmed self:updField()
if self:canFall() then
self.fallTimer=self.settings.fallDelay
else
self:checkClear()
end
-- Update field
self:updField()

-- Discard hand
self.hand=false
if self.finished then return end

-- Fresh hand
if self.settings.spawnDelay<=0 then
-- TODO
-- Trigger garbage
if self.chain<=0 or not self.settings.clearStuck then
self:checkGarbage()
end
if self.fallTimer<=0 and self.clearTimer<=0 then
self:popNext()
end
Expand Down Expand Up @@ -749,26 +750,23 @@ function GP:checkPosition(x,y)
self:getGroup(x,y,cell,set)
end

-- Record the group, mark cells, trigger clearing (or later)
-- Record the group, mark cells
if TABLE.getSize(set)>=self.settings.clearGroupSize then
ins(self.clearingGroups,set)
self:checkDig(set)
for k in next,set do k.clearing=true end
if self.settings.clearDelay<=0 then
self:clearField()
self:updField()
else
self.clearTimer=self.settings.clearDelay
end
end
end
function GP:updField()
---@param byTimer? boolean Only true when called by P:update, trigger falling, otherwise only start the falling timer but not do fall
function GP:updField(byTimer)
if self:canFall() then
if self.settings.fallDelay<=0 then
while self:fieldFall() do end
while self:doFall() do end
self:checkClear()
else
self:fieldFall()
if byTimer then
self:doFall()
end
self.fallTimer=self.settings.fallDelay
end
else
Expand All @@ -785,7 +783,7 @@ function GP:canFall()
end end
end
end
function GP:fieldFall()
function GP:doFall()
local F=self.field
local fallen=false
for x=1,self.settings.fieldW do
Expand All @@ -808,34 +806,6 @@ function GP:fieldFall()
end
return fallen
end
function GP:checkGarbage()
local i=1
while true do
l=self.garbageBuffer[i]
if not l then break end
if l._time==l.time then
self:dropGarbage(l.power*2)
rem(self.garbageBuffer,i)
i=i-1 -- Avoid index error
elseif l.mode==1 then
l._time=l._time+1
end
i=i+1
end
end
function GP:dropGarbage(count)
local F=self.field
local w=self.settings.fieldW
for _=1,count do
local x=self:random(w)
local y=self.settings.spawnH+1
while F:getCell(x,y) do y=y+1 end
F:setCell({
color=555,
diggable=true,
},x,y)
end
end
function GP:checkClear()
local F=self.field
for y=1,F:getHeight() do for x=1,self.settings.fieldW do
Expand All @@ -846,23 +816,25 @@ function GP:checkClear()
end end
if #self.clearingGroups>0 then
self:playSound('desuffocate')
end
if self.clearTimer<=0 then
-- Attack
local atk=GAME.initAtk(self:atkEvent('clear'))
if atk then
GAME.send(self,atk)
if self.settings.clearDelay<=0 then
self:doClear()
self:updField()
else
self.clearTimer=self.settings.clearDelay
end
end
if self.clearTimer<=0 or not self.settings.clearStuck then
self:checkGarbage()
end
end
function GP:clearField()
function GP:doClear()
self.chain=self.chain+1
self:playSound('chain',self.chain)
self:playSound('clear',#self.clearingGroups)

-- Attack
local atk=GAME.initAtk(self:atkEvent('clear'))
if atk then
GAME.send(self,atk)
end

local F=self.field
for i=1,#self.clearingGroups do
local set=self.clearingGroups[i]
Expand All @@ -880,6 +852,34 @@ function GP:clearField()
end
self.clearingGroups={}
end
function GP:checkGarbage()
local i=1
while true do
l=self.garbageBuffer[i]
if not l then break end
if l._time==l.time then
self:dropGarbage(l.power*2)
rem(self.garbageBuffer,i)
i=i-1 -- Avoid index error
elseif l.mode==1 then
l._time=l._time+1
end
i=i+1
end
end
function GP:dropGarbage(count)
local F=self.field
local w=self.settings.fieldW
for _=1,count do
local x=self:random(w)
local y=self.settings.spawnH+1
while F:getCell(x,y) do y=y+1 end
F:setCell({
color=555,
diggable=true,
},x,y)
end
end
function GP:changeFieldWidth(w,origPos)
if w>0 and w%1==0 then
if not origPos then origPos=1 end
Expand Down Expand Up @@ -1024,14 +1024,14 @@ function GP:updateFrame()
if self.fallTimer>0 then
self.fallTimer=self.fallTimer-1
if self.fallTimer<=0 then
self:updField()
self:updField(true)
end
break
end
if self.clearTimer>0 then
self.clearTimer=self.clearTimer-1
if self.clearTimer<=0 then
self:clearField()
self:doClear()
self:updField()

self:triggerEvent('afterClear')
Expand Down Expand Up @@ -1342,7 +1342,7 @@ local baseEnv={
maxFreshTime=6200,

-- Attack
atkSys='none',
atkSys='classic',
allowCancel=true,
clearStuck=true,

Expand Down

0 comments on commit 7038100

Please sign in to comment.