Task模块全部改用协程

This commit is contained in:
MrZ626
2020-12-04 16:09:17 +08:00
parent 6f49341ba5
commit 98629be450
21 changed files with 607 additions and 474 deletions

View File

@@ -1,4 +1,6 @@
local rem=table.remove local rem=table.remove
local ct=coroutine
local assert=assert
local tasks={} local tasks={}
local TASK={ local TASK={
@@ -10,24 +12,40 @@ end
function TASK.update() function TASK.update()
for i=#tasks,1,-1 do for i=#tasks,1,-1 do
local T=tasks[i] local T=tasks[i]
if T.code(T.data)then assert(ct.resume(T.thread))
if T.data.net then if ct.status(T.thread)=="dead"then
if T.net then
TASK.netTaskCount=TASK.netTaskCount-1 TASK.netTaskCount=TASK.netTaskCount-1
end end
rem(tasks,i) rem(tasks,i)
end end
end end
end end
function TASK.new(code,data) function TASK.new(code,...)
local thread=ct.create(code)
if ...~=nil then ct.resume(thread,...)end
if ct.status(thread)~="dead"then
tasks[#tasks+1]={ tasks[#tasks+1]={
thread=thread,
code=code, code=code,
data=data,
} }
end end
end
function TASK.newNet(code,...)
local thread=ct.create(code)
if ...~=nil then ct.resume(thread,...)end
if ct.status(thread)~="dead"then
tasks[#tasks+1]={
thread=thread,
code=code,
net=true,
}
end
end
function TASK.changeCode(c1,c2) function TASK.changeCode(c1,c2)
for i=#tasks,1,-1 do for i=#tasks,1,-1 do
if tasks[i].code==c1 then if tasks[i].thread==c1 then
tasks[i].code=c2 tasks[i].thread=c2
end end
end end
end end

View File

@@ -548,13 +548,12 @@ do--httpRequest & wsConnect
client and function(tick,path,method,header,body) client and function(tick,path,method,header,body)
local task,err=client.httpraw{ local task,err=client.httpraw{
url="http://krakens.tpddns.cn:10026"..path, url="http://krakens.tpddns.cn:10026"..path,
-- url="http://127.0.0.1:10026"..path,
method=method or"GET", method=method or"GET",
header=header, header=header,
body=body, body=body,
} }
if task then if task then
TASK.new(tick,{task=task,time=0,net=true}) TASK.newNet(tick,task)
else else
LOG.print("NETlib error: "..err,"warn") LOG.print("NETlib error: "..err,"warn")
end end
@@ -569,12 +568,10 @@ do--httpRequest & wsConnect
local task,err=client.wsraw{ local task,err=client.wsraw{
url="ws://krakens.tpddns.cn:10026"..path, url="ws://krakens.tpddns.cn:10026"..path,
origin="krakens.tpddns.cn", origin="krakens.tpddns.cn",
-- url="ws://127.0.0.1:10026"..path,
-- origin="127.0.0.1",
header=header, header=header,
} }
if task then if task then
TASK.new(tick,{wsconntask=task,time=0,net=true}) TASK.newNet(tick,task)
else else
LOG.print("NETlib error: "..err,"warn") LOG.print("NETlib error: "..err,"warn")
end end

View File

@@ -487,7 +487,7 @@ function resetGameData(replaying)
STAT.game=STAT.game+1 STAT.game=STAT.game+1
FREEROW.reset(30*#PLAYERS) FREEROW.reset(30*#PLAYERS)
TASK.removeTask_code(TICK.showMods) TASK.removeTask_code(TICK.showMods)
TASK.new(TICK.showMods,{0}) TASK.new(TICK.showMods)
SFX.play("ready") SFX.play("ready")
collectgarbage() collectgarbage()
end end

View File

@@ -23,11 +23,14 @@ return{
freshLimit=15, freshLimit=15,
dropPiece=score, dropPiece=score,
task=function(P) task=function(P)
while true do
coroutine.yield()
if P.stat.frame>=53.5*60 then if P.stat.frame>=53.5*60 then
P.modeData.point=min(P.modeData.point+16,80) P.modeData.point=min(P.modeData.point+16,80)
P.modeData.event=sectionName[int(P.modeData.point*.1)+1] P.modeData.event=sectionName[int(P.modeData.point*.1)+1]
P:win("finish") P:win("finish")
return true return
end
end end
end, end,
bg="tunnel",bgm="far", bg="tunnel",bgm="far",

View File

@@ -6,8 +6,9 @@ return{
freshLimit=15, freshLimit=15,
pushSpeed=2, pushSpeed=2,
task=function(P) task=function(P)
if not(P.control and SCN.cur=="play")then return end while true do
if P.atkBuffer.sum==0 then coroutine.yield()
if P.control and SCN.cur=="play"and P.atkBuffer.sum==0 then
local p=#P.atkBuffer+1 local p=#P.atkBuffer+1
local B,D=P.atkBuffer,P.modeData local B,D=P.atkBuffer,P.modeData
local t local t
@@ -32,6 +33,7 @@ return{
end end
end end
end end
end
end, end,
bg="rainbow2",bgm="shining terminal", bg="rainbow2",bgm="shining terminal",
}, },

View File

@@ -5,8 +5,9 @@ return{
fall=8, fall=8,
freshLimit=15, freshLimit=15,
task=function(P) task=function(P)
if not(P.control and SCN.cur=="play")then return end while true do
if P.atkBuffer.sum<4 then coroutine.yield()
if P.control and SCN.cur=="play"and P.atkBuffer.sum<4 then
local p=#P.atkBuffer+1 local p=#P.atkBuffer+1
local B,D=P.atkBuffer,P.modeData local B,D=P.atkBuffer,P.modeData
local s local s
@@ -39,6 +40,7 @@ return{
end end
end end
end end
end
end, end,
bg="rainbow2",bgm="shining terminal", bg="rainbow2",bgm="shining terminal",
}, },

View File

@@ -8,7 +8,9 @@ return{
freshLimit=15, freshLimit=15,
pushSpeed=2, pushSpeed=2,
task=function(P) task=function(P)
if not(P.control and SCN.cur=="play")then return end while true do
coroutine.yield()
if P.control and SCN.cur=="play"then
P.modeData.counter=P.modeData.counter+1 P.modeData.counter=P.modeData.counter+1
local t=240-2*P.modeData.event local t=240-2*P.modeData.event
if P.modeData.counter>=t then if P.modeData.counter>=t then
@@ -36,6 +38,8 @@ return{
end end
end end
end end
end
end
end, end,
bg="rainbow2",bgm="storm", bg="rainbow2",bgm="storm",
}, },

View File

@@ -8,7 +8,9 @@ return{
freshLimit=15, freshLimit=15,
pushSpeed=1, pushSpeed=1,
task=function(P) task=function(P)
if not(P.control and SCN.cur=="play")then return end while true do
coroutine.yield()
if P.control and SCN.cur=="play"then
P.modeData.counter=P.modeData.counter+1 P.modeData.counter=P.modeData.counter+1
local t=360-P.modeData.event*2 local t=360-P.modeData.event*2
if P.modeData.counter>=t then if P.modeData.counter>=t then
@@ -36,6 +38,8 @@ return{
end end
end end
end end
end
end
end, end,
bg="rainbow2",bgm="storm", bg="rainbow2",bgm="storm",
}, },

View File

@@ -1,4 +1,3 @@
local max=math.max
return{ return{
color=COLOR.magenta, color=COLOR.magenta,
env={ env={
@@ -6,15 +5,19 @@ return{
fall=20, fall=20,
freshLimit=15, freshLimit=15,
task=function(P) task=function(P)
if not(P.control and SCN.cur=="play")then return end while true do
coroutine.yield()
if P.control and SCN.cur=="play"then
local D=P.modeData local D=P.modeData
D.counter=D.counter+1 D.counter=D.counter+1
if D.counter>=max(90,180-D.event)then if D.counter>=math.max(90,180-D.event)then
P:garbageRise(21,1,P:getHolePos()) P:garbageRise(21,1,P:getHolePos())
P.stat.recv=P.stat.recv+1 P.stat.recv=P.stat.recv+1
D.counter=0 D.counter=0
D.event=D.event+1 D.event=D.event+1
end end
end
end
end, end,
bg="bg2",bgm="down", bg="bg2",bgm="down",
}, },

View File

@@ -1,19 +1,22 @@
local max=math.max
return{ return{
color=COLOR.lYellow, color=COLOR.lYellow,
env={ env={
drop=10,lock=30, drop=10,lock=30,
freshLimit=15, freshLimit=15,
task=function(P) task=function(P)
if not(P.control and SCN.cur=="play")then return end while true do
coroutine.yield()
if P.control and SCN.cur=="play"then
local D=P.modeData local D=P.modeData
D.counter=D.counter+1 D.counter=D.counter+1
if D.counter>=max(30,80-.3*D.event)then if D.counter>=math.max(30,80-.3*D.event)then
P:garbageRise(20+D.event%5,1,P:getHolePos()) P:garbageRise(20+D.event%5,1,P:getHolePos())
P.stat.recv=P.stat.recv+1 P.stat.recv=P.stat.recv+1
D.counter=0 D.counter=0
D.event=D.event+1 D.event=D.event+1
end end
end
end
end, end,
bg="bg2",bgm="down", bg="bg2",bgm="down",
}, },

View File

@@ -7,14 +7,17 @@ local PClist=require"parts/modes/PClist"
local PCtype={[0]=1,2,3,2,3} local PCtype={[0]=1,2,3,2,3}
local function task_PC(P) local function task_PC(P)
P.modeData.counter=P.modeData.counter+1 local D=P.modeData
if P.modeData.counter==26 then while true do
local base=PCbase[P.modeData.type] coroutine.yield()
P:pushLineList(base[P:RND(#base)],P.modeData.symmetry) D.counter=D.counter+1
return true if D.counter==26 then
local base=PCbase[D.type]
P:pushLineList(base[P:RND(#base)],D.symmetry)
end end
end end
local function newPC(P) end
local function check(P)
local r=P.field local r=P.field
if r[1]then if r[1]then
r=r[#r] r=r[#r]
@@ -55,7 +58,7 @@ return{
fall=20, fall=20,
sequence="none", sequence="none",
freshLimit=15, freshLimit=15,
dropPiece=newPC, dropPiece=check,
RS="SRS", RS="SRS",
ospin=false, ospin=false,
bg="rgb",bgm="oxygen", bg="rgb",bgm="oxygen",
@@ -63,7 +66,7 @@ return{
pauseLimit=true, pauseLimit=true,
load=function() load=function()
PLY.newPlayer(1,340,15) PLY.newPlayer(1,340,15)
newPC(PLAYERS[1]) check(PLAYERS[1])
end, end,
mesDisp=function(P) mesDisp=function(P)
setFont(75) setFont(75)

View File

@@ -13,14 +13,17 @@ local PCtype={
3, 3,
} }
local function task_PC(P) local function task_PC(P)
P.modeData.counter=P.modeData.counter+1 local D=P.modeData
if P.modeData.counter==26 then while true do
local base=PCbase[P.modeData.type] D.counter=D.counter+1
P:pushLineList(base[P:RND(#base)],P.modeData.symmetry) if D.counter==26 then
return true local base=PCbase[D.type]
P:pushLineList(base[P:RND(#base)],D.symmetry)
end
coroutine.yield()
end end
end end
local function newPC(P) local function check(P)
local r=P.field local r=P.field
if r[1]then if r[1]then
r=r[#r] r=r[#r]
@@ -47,7 +50,7 @@ return{
drop=120,lock=180, drop=120,lock=180,
fall=20, fall=20,
sequence="none", sequence="none",
dropPiece=newPC, dropPiece=check,
RS="SRS", RS="SRS",
ospin=false, ospin=false,
bg="rgb",bgm="oxygen", bg="rgb",bgm="oxygen",
@@ -55,7 +58,7 @@ return{
pauseLimit=true, pauseLimit=true,
load=function() load=function()
PLY.newPlayer(1,340,15) PLY.newPlayer(1,340,15)
newPC(PLAYERS[1]) check(PLAYERS[1])
end, end,
mesDisp=function(P) mesDisp=function(P)
setFont(75) setFont(75)

View File

@@ -1,13 +1,14 @@
local max=math.max
return{ return{
color=COLOR.cyan, color=COLOR.cyan,
env={ env={
drop=30,lock=45, drop=30,lock=45,
freshLimit=10, freshLimit=10,
task=function(P) task=function(P)
if not(P.control and SCN.cur=="play")then return end while true do
coroutine.yield()
if P.control and SCN.cur=="play"then
P.modeData.counter=P.modeData.counter+1 P.modeData.counter=P.modeData.counter+1
if P.modeData.counter>=max(60,150-2*P.modeData.event)and P.atkBuffer.sum<4 then if P.modeData.counter>=math.max(60,150-2*P.modeData.event)and P.atkBuffer.sum<4 then
P.atkBuffer[#P.atkBuffer+1]={pos=P:RND(10),amount=1,countdown=30,cd0=30,time=0,sent=false,lv=1} P.atkBuffer[#P.atkBuffer+1]={pos=P:RND(10),amount=1,countdown=30,cd0=30,time=0,sent=false,lv=1}
P.atkBuffer.sum=P.atkBuffer.sum+1 P.atkBuffer.sum=P.atkBuffer.sum+1
P.stat.recv=P.stat.recv+1 P.stat.recv=P.stat.recv+1
@@ -15,6 +16,8 @@ return{
P.modeData.counter=0 P.modeData.counter=0
P.modeData.event=P.modeData.event+1 P.modeData.event=P.modeData.event+1
end end
end
end
end, end,
bg="glow",bgm="new era", bg="glow",bgm="new era",
}, },

View File

@@ -1,14 +1,15 @@
local max=math.max
return{ return{
color=COLOR.magenta, color=COLOR.magenta,
env={ env={
drop=30,lock=45, drop=30,lock=45,
freshLimit=10, freshLimit=10,
task=function(P) task=function(P)
if not(P.control and SCN.cur=="play")then return end while true do
coroutine.yield()
if P.control and SCN.cur=="play"then
P.modeData.counter=P.modeData.counter+1 P.modeData.counter=P.modeData.counter+1
local B=P.atkBuffer local B=P.atkBuffer
if P.modeData.counter>=max(60,180-2*P.modeData.event)and B.sum<15 then if P.modeData.counter>=math.max(60,180-2*P.modeData.event)and B.sum<15 then
B[#B+1]= B[#B+1]=
P.modeData.event%3<2 and P.modeData.event%3<2 and
{pos=P:RND(10),amount=1,countdown=0,cd0=0,time=0,sent=false,lv=1} {pos=P:RND(10),amount=1,countdown=0,cd0=0,time=0,sent=false,lv=1}
@@ -21,6 +22,8 @@ return{
P.modeData.counter=0 P.modeData.counter=0
P.modeData.event=P.modeData.event+1 P.modeData.event=P.modeData.event+1
end end
end
end
end, end,
bg="glow",bgm="secret7th", bg="glow",bgm="secret7th",
}, },

View File

@@ -1,14 +1,15 @@
local max=math.max
return{ return{
color=COLOR.red, color=COLOR.red,
env={ env={
drop=30,lock=45, drop=30,lock=45,
freshLimit=10, freshLimit=10,
task=function(P) task=function(P)
if not(P.control and SCN.cur=="play")then return end while true do
coroutine.yield()
if P.control and SCN.cur=="play"then
P.modeData.counter=P.modeData.counter+1 P.modeData.counter=P.modeData.counter+1
if P.modeData.counter>=max(60,150-P.modeData.event)and P.atkBuffer.sum<20 then if P.modeData.counter>=math.max(60,150-P.modeData.event)and P.atkBuffer.sum<20 then
local t=max(60,90-P.modeData.event) local t=math.max(60,90-P.modeData.event)
P.atkBuffer[#P.atkBuffer+1]={pos=P:RND(10),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=3} P.atkBuffer[#P.atkBuffer+1]={pos=P:RND(10),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=3}
P.atkBuffer.sum=P.atkBuffer.sum+4 P.atkBuffer.sum=P.atkBuffer.sum+4
P.stat.recv=P.stat.recv+4 P.stat.recv=P.stat.recv+4
@@ -16,6 +17,8 @@ return{
P.modeData.counter=0 P.modeData.counter=0
P.modeData.event=P.modeData.event+1 P.modeData.event=P.modeData.event+1
end end
end
end
end, end,
bg="glow",bgm="storm", bg="glow",bgm="storm",
}, },

View File

@@ -1,13 +1,14 @@
local max=math.max
return{ return{
color=COLOR.green, color=COLOR.green,
env={ env={
drop=30,lock=45, drop=30,lock=45,
freshLimit=10, freshLimit=10,
task=function(P) task=function(P)
if not(P.control and SCN.cur=="play")then return end while true do
coroutine.yield()
if P.control and SCN.cur=="play"then
P.modeData.counter=P.modeData.counter+1 P.modeData.counter=P.modeData.counter+1
if P.modeData.counter>=max(90,180-2*P.modeData.event)and P.atkBuffer.sum<8 then if P.modeData.counter>=math.max(90,180-2*P.modeData.event)and P.atkBuffer.sum<8 then
local d=P.modeData.event+1 local d=P.modeData.event+1
P.atkBuffer[#P.atkBuffer+1]= P.atkBuffer[#P.atkBuffer+1]=
d%4==0 and{pos=P:RND(10),amount=1,countdown=60,cd0=60,time=0,sent=false,lv=1}or d%4==0 and{pos=P:RND(10),amount=1,countdown=60,cd0=60,time=0,sent=false,lv=1}or
@@ -20,6 +21,8 @@ return{
P.modeData.counter=0 P.modeData.counter=0
P.modeData.event=d P.modeData.event=d
end end
end
end
end, end,
bg="glow",bgm="secret8th", bg="glow",bgm="secret8th",
}, },

View File

@@ -1,4 +1,3 @@
local max=math.max
return{ return{
color=COLOR.lYellow, color=COLOR.lYellow,
env={ env={
@@ -7,10 +6,12 @@ return{
freshLimit=15, freshLimit=15,
pushSpeed=2, pushSpeed=2,
task=function(P) task=function(P)
if not(P.control and SCN.cur=="play")then return end while true do
coroutine.yield()
if P.control and SCN.cur=="play"then
P.modeData.counter=P.modeData.counter+1 P.modeData.counter=P.modeData.counter+1
if P.modeData.counter>=max(300,600-10*P.modeData.event)and P.atkBuffer.sum<20 then if P.modeData.counter>=math.max(300,600-10*P.modeData.event)and P.atkBuffer.sum<20 then
local t=max(300,480-12*P.modeData.event) local t=math.max(300,480-12*P.modeData.event)
local p=#P.atkBuffer+1 local p=#P.atkBuffer+1
P.atkBuffer[p] ={pos=P:RND(10),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=2} P.atkBuffer[p] ={pos=P:RND(10),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=2}
P.atkBuffer[p+1]={pos=P:RND(10),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=3} P.atkBuffer[p+1]={pos=P:RND(10),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=3}
@@ -22,6 +23,8 @@ return{
P.modeData.counter=0 P.modeData.counter=0
P.modeData.event=P.modeData.event+1 P.modeData.event=P.modeData.event+1
end end
end
end
end, end,
bg="welcome",bgm="storm", bg="welcome",bgm="storm",
}, },

View File

@@ -8,6 +8,8 @@ return{
drop=60,lock=60, drop=60,lock=60,
fall=20, fall=20,
task=function(P) task=function(P)
while true do
coroutine.yield()
local _=P.modeData.counter+1 local _=P.modeData.counter+1
if P.stat.frame>=warnTime[_]*60 then if P.stat.frame>=warnTime[_]*60 then
if _<9 then if _<9 then
@@ -16,7 +18,8 @@ return{
else else
SFX.play("start") SFX.play("start")
P:win("finish") P:win("finish")
return true return
end
end end
end end
end, end,

View File

@@ -7,6 +7,7 @@ local Player={}--Player class
local int,ceil,rnd=math.floor,math.ceil,math.random local int,ceil,rnd=math.floor,math.ceil,math.random
local max,min=math.max,math.min local max,min=math.max,math.min
local ins,rem=table.insert,table.remove local ins,rem=table.insert,table.remove
local ct=coroutine
local kickList=require"parts/kickList" local kickList=require"parts/kickList"
local scs=spinCenters local scs=spinCenters
@@ -124,12 +125,11 @@ function Player.RND(P,a,b)
local R=P.randGen local R=P.randGen
return R:random(a,b) return R:random(a,b)
end end
function Player.newTask(P,code,data) function Player.newTask(P,code)
local L=P.tasks local L=P.tasks
ins(L,{ local thread=ct.create(code)
code=code, ct.resume(thread,P)
data=data, L[#L+1]=thread
})
end end
function Player.set20G(P,if20g,init)--Only set init=true when initialize CC, do not use it function Player.set20G(P,if20g,init)--Only set init=true when initialize CC, do not use it
@@ -1453,7 +1453,7 @@ function Player.win(P,result)
end end
if P.human then if P.human then
gameOver() gameOver()
TASK.new(TICK.autoPause,{0}) TASK.new(TICK.autoPause)
if MARKING then if MARKING then
P:showTextF(text.marking,0,-226,25,"appear",.4,.0626) P:showTextF(text.marking,0,-226,25,"appear",.4,.0626)
end end
@@ -1532,7 +1532,7 @@ function Player.lose(P,force)
end end
P.lastRecv=A P.lastRecv=A
if P.id==1 or A.id==1 then if P.id==1 or A.id==1 then
TASK.new(TICK.throwBadge,{A.ai,P,max(3,P.badge)*4}) TASK.new(TICK.throwBadge,A.ai,P,max(3,P.badge)*4)
end end
end end
else else
@@ -1561,7 +1561,7 @@ function Player.lose(P,force)
end end
gameOver() gameOver()
P:newTask(#PLAYERS>1 and TICK.lose or TICK.finish) P:newTask(#PLAYERS>1 and TICK.lose or TICK.finish)
TASK.new(TICK.autoPause,{0}) TASK.new(TICK.autoPause)
if MARKING then if MARKING then
P:showTextF(text.marking,0,-226,25,"appear",.4,.0626) P:showTextF(text.marking,0,-226,25,"appear",.4,.0626)
end end

View File

@@ -1,5 +1,7 @@
local int,max,min,abs=math.floor,math.max,math.min,math.abs local int,max,min,abs=math.floor,math.max,math.min,math.abs
local rem=table.remove local rem=table.remove
local ct=coroutine
local assert=assert
local function updateLine(P)--Attacks, line pushing, cam moving local function updateLine(P)--Attacks, line pushing, cam moving
local bf=P.atkBuffer local bf=P.atkBuffer
@@ -95,7 +97,10 @@ end
local function updateTasks(P) local function updateTasks(P)
local L=P.tasks local L=P.tasks
for i=#L,1,-1 do for i=#L,1,-1 do
if L[i].code(P,L[i].data)then rem(L,i)end assert(ct.resume(L[i]))
if ct.status(L[i])=="dead"then
rem(L,i)
end
end end
end end

View File

@@ -1,24 +1,24 @@
local function checkTimeout(data,time) local yield=coroutine.yield
data.time=data.time+1
if data.time==time then
LOG.print(text.httpTimeout,"message")
return true
end
end
local Tick={} local Tick={}
function Tick.showMods(data) function Tick.showMods()
local d=data[1]+1 local time=0
if d%20==0 then while true do
local M=GAME.mod[d/20] yield()
time=time+1
if time%20==0 then
local M=GAME.mod[time/20]
if M then if M then
TEXT.show(M.id,700+(d-20)%120*4,36,45,"spin",.5) TEXT.show(M.id,700+(time-20)%120*4,36,45,"spin",.5)
else else
return true return
end
end end
end end
data[1]=d
end end
function Tick.finish(P) function Tick.finish(P)
while true do
yield()
P.endCounter=P.endCounter+1 P.endCounter=P.endCounter+1
if P.endCounter<40 then if P.endCounter<40 then
--Make field visible --Make field visible
@@ -26,10 +26,13 @@ function Tick.finish(P)
if P.visTime[j][i]<20 then P.visTime[j][i]=P.visTime[j][i]+.5 end if P.visTime[j][i]<20 then P.visTime[j][i]=P.visTime[j][i]+.5 end
end end end end
elseif P.endCounter==60 then elseif P.endCounter==60 then
return true return
end
end end
end end
function Tick.lose(P) function Tick.lose(P)
while true do
yield()
P.endCounter=P.endCounter+1 P.endCounter=P.endCounter+1
if P.endCounter<40 then if P.endCounter<40 then
--Make field visible --Make field visible
@@ -50,7 +53,7 @@ function Tick.lose(P)
FREEROW.discard(P.visTime[_]) FREEROW.discard(P.visTime[_])
P.field[_],P.visTime[_]=nil P.field[_],P.visTime[_]=nil
end end
return true return
end end
end end
if not GAME.modeEnv.royaleMode and #PLAYERS>1 then if not GAME.modeEnv.royaleMode and #PLAYERS>1 then
@@ -58,10 +61,13 @@ function Tick.lose(P)
P.absFieldY=P.absFieldY+P.endCounter*.26 P.absFieldY=P.absFieldY+P.endCounter*.26
end end
end end
function Tick.throwBadge(data)--{ifAI,Sender,timer} end
data[3]=data[3]-1 function Tick.throwBadge(ifAI,sender,time)
if data[3]%4==0 then while true do
local S,R=data[2],data[2].lastRecv yield()
time=time-1
if time%4==0 then
local S,R=sender,sender.lastRecv
local x1,y1,x2,y2 local x1,y1,x2,y2
if S.small then if S.small then
x1,y1=S.centerX,S.centerY x1,y1=S.centerX,S.centerY
@@ -77,24 +83,31 @@ function Tick.throwBadge(data)--{ifAI,Sender,timer}
--Generate badge object --Generate badge object
SYSFX.newBadge(x1,y1,x2,y2) SYSFX.newBadge(x1,y1,x2,y2)
if not data[1]and data[3]%8==0 then if not ifAI and time%8==0 then
SFX.play("collect") SFX.play("collect")
end end
end end
if data[3]<=0 then return true end if time<=0 then return end
end end
function Tick.autoPause(data) end
data[1]=data[1]+1 function Tick.autoPause()
if SCN.cur~="play"then return true end local time=0
if data[1]==120 then while true do
if SCN.cur=="play"then yield()
time=time+1
if SCN.cur~="play"then
return
elseif time==120 then
pauseGame() pauseGame()
end return
return true
end end
end end
function Tick.httpREQ_launch(data) end
local response,request_error=client.poll(data.task) function Tick.httpREQ_launch(task)
local time=0
while true do
yield()
local response,request_error=client.poll(task)
if response then if response then
local res=json.decode(response.body) local res=json.decode(response.body)
if res then if res then
@@ -109,15 +122,23 @@ function Tick.httpREQ_launch(data)
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
end end
end end
return true return
elseif request_error then elseif request_error then
LOG.print(text.getNoticeFail..": "..request_error,"warn") LOG.print(text.getNoticeFail..": "..request_error,"warn")
return true return
end end
return checkTimeout(data,260) time=time+1
if time>360 then
LOG.print(text.httpTimeout,"message")
return
end end
function Tick.httpREQ_register(data) end
local response,request_error=client.poll(data.task) end
function Tick.httpREQ_register(task)
local time=0
while true do
yield()
local response,request_error=client.poll(task)
if response then if response then
local res=json.decode(response.body) local res=json.decode(response.body)
if res then if res then
@@ -127,15 +148,23 @@ function Tick.httpREQ_register(data)
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
end end
end end
return true return
elseif request_error then elseif request_error then
LOG.print(text.loginFailed..": "..request_error,"warn") LOG.print(text.loginFailed..": "..request_error,"warn")
return true return
end end
return checkTimeout(data,360) time=time+1
if time>360 then
LOG.print(text.httpTimeout,"message")
return
end end
function Tick.httpREQ_newLogin(data) end
local response,request_error=client.poll(data.task) end
function Tick.httpREQ_newLogin(task)
local time=0
while true do
yield()
local response,request_error=client.poll(task)
if response then if response then
local res=json.decode(response.body) local res=json.decode(response.body)
LOGIN=response.code==200 LOGIN=response.code==200
@@ -160,15 +189,23 @@ function Tick.httpREQ_newLogin(data)
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
end end
end end
return true return
elseif request_error then elseif request_error then
LOG.print(text.loginFailed..": "..request_error,"warn") LOG.print(text.loginFailed..": "..request_error,"warn")
return true return
end end
return checkTimeout(data,360) time=time+1
if time>360 then
LOG.print(text.httpTimeout,"message")
return
end end
function Tick.httpREQ_autoLogin(data) end
local response,request_error=client.poll(data.task) end
function Tick.httpREQ_autoLogin(task)
local time=0
while true do
yield()
local response,request_error=client.poll(task)
if response then if response then
if response.code==200 then if response.code==200 then
LOGIN=true LOGIN=true
@@ -183,15 +220,23 @@ function Tick.httpREQ_autoLogin(data)
LOG.print(text.loginFailed..": "..text.netErrorCode..response.code.."-"..err.message,"warn") LOG.print(text.loginFailed..": "..text.netErrorCode..response.code.."-"..err.message,"warn")
end end
end end
return true return
elseif request_error then elseif request_error then
LOG.print(text.loginFailed..": "..request_error,"warn") LOG.print(text.loginFailed..": "..request_error,"warn")
return true return
end end
return checkTimeout(data,360) time=time+1
if time>360 then
LOG.print(text.httpTimeout,"message")
return
end end
function Tick.httpREQ_checkAccessToken(data) end
local response,request_error=client.poll(data.task) end
function Tick.httpREQ_checkAccessToken(task)
local time=0
while true do
yield()
local response,request_error=client.poll(task)
if response then if response then
if response.code==200 then if response.code==200 then
LOG.print(text.accessSuccessed) LOG.print(text.accessSuccessed)
@@ -214,15 +259,23 @@ function Tick.httpREQ_checkAccessToken(data)
LOG.print(text.netErrorCode..response.code..": "..err.message,"warn") LOG.print(text.netErrorCode..response.code..": "..err.message,"warn")
end end
end end
return true return
elseif request_error then elseif request_error then
LOG.print(text.loginFailed..": "..request_error,"warn") LOG.print(text.loginFailed..": "..request_error,"warn")
return true return
end end
return checkTimeout(data,360) time=time+1
if time>360 then
LOG.print(text.httpTimeout,"message")
return
end end
function Tick.httpREQ_getAccessToken(data) end
local response,request_error=client.poll(data.task) end
function Tick.httpREQ_getAccessToken(task)
local time=0
while true do
yield()
local response,request_error=client.poll(task)
if response then if response then
if response.code==200 then if response.code==200 then
local res=json.decode(response.body) local res=json.decode(response.body)
@@ -250,28 +303,41 @@ function Tick.httpREQ_getAccessToken(data)
SCN.pop() SCN.pop()
SCN.go("main") SCN.go("main")
end end
return true return
elseif request_error then elseif request_error then
LOG.print(text.loginFailed..": "..request_error,"warn") LOG.print(text.loginFailed..": "..request_error,"warn")
return true return
end end
return checkTimeout(data,360) time=time+1
if time>360 then
LOG.print(text.httpTimeout,"message")
return
end end
function Tick.wsCONN_connect(data) end
if data.wsconntask then end
local wsconn,connErr=client.poll(data.wsconntask) function Tick.wsCONN_connect(task)
local time=0
while true do
yield()
local wsconn,connErr=client.poll(task)
if wsconn then if wsconn then
WSCONN=wsconn WSCONN=wsconn
TASK.new(Tick.wsCONN_read) TASK.new(Tick.wsCONN_read)
return true return
elseif connErr then elseif connErr then
LOG.print(text.wsFailed..": "..connErr,"warn") LOG.print(text.wsFailed..": "..connErr,"warn")
return true return
end
time=time+1
if time>360 then
LOG.print(text.httpTimeout,"message")
return
end end
end end
return checkTimeout(data,360)
end end
function Tick.wsCONN_read() function Tick.wsCONN_read()
while true do
yield()
local messages,readErr=client.read(WSCONN) local messages,readErr=client.read(WSCONN)
if messages then if messages then
if messages[1]then if messages[1]then
@@ -283,18 +349,20 @@ function Tick.wsCONN_read()
LOG.print("Socket closed!","warn") LOG.print("Socket closed!","warn")
end end
WSCONN=nil WSCONN=nil
return true return
end end
end end
-- function Tick.wsCONN_write(data) end
-- if not data.net then -- function Tick.wsCONN_write()
-- return true -- while true do
-- end -- local message=yield()
-- local writeErr=client.write(WSCONN,data.message) -- if message then
-- local writeErr=client.write(WSCONN,message)
-- if writeErr then -- if writeErr then
-- print(writeErr,"warn") -- print(writeErr,"warn")
-- end -- end
-- return true -- end
-- end
-- end -- end
return Tick return Tick