Skip to content

Commit

Permalink
添加task机制包,给有submode的模式加上submode选择条件可视化
Browse files Browse the repository at this point in the history
  • Loading branch information
MrZ626 committed Jul 19, 2024
1 parent 0aaf4c1 commit bd002d0
Show file tree
Hide file tree
Showing 9 changed files with 318 additions and 36 deletions.
144 changes: 144 additions & 0 deletions assets/game/mechanicLib/common/task.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
local pIndex=TABLE.pathIndex

local task={}

---@class Techmino.PlayerModeData.TaskObj
---@field id string
---@field title string
---@field desc string?
---@field progress string? progress text, like "1/10"
---@field value number 0-1
---@field valueShow number 0-1
---@field changing boolean
---@field achieved boolean
---@field achievedTimer integer

---@type Techmino.Event
function task.install(P)
P.modeData.task={}
P:addEvent('always',task.event_always)
P:addEvent('drawOnPlayer',task.event_drawOnPlayer)
end

---@param P Techmino.Player
---@param id string
---@param title string
---@param desc string
---@param progress? string
---@param value? number|true
function task.add(P,id,title,desc,progress,value)
table.insert(P.modeData.task,{
id=id,
title=title,
desc=desc,
value=value or 0,
valueShow=value or 0,
progress=progress,
changing=false,
achieved=value==true,
achievedTimer=0,
})
end

---@param P Techmino.Player
---@param id string
---@param value number|true
---@param progress? string
function task.set(P,id,value,progress)
---@type Techmino.PlayerModeData.TaskObj
local opt
for _,o in next,P.modeData.task do
if o.id==id then
opt=o
break
end
end
if not opt then return end
if value==true then
opt.value=1
opt.valueShow=1
opt.changing=false
opt.achieved=true
opt.achievedTimer=0
-- for _,o in next,P.modeData.task do
-- if o~=opt then
-- task.set(P,o.id,0)
-- end
-- end
else
opt.value=MATH.clamp(value,0,1)
opt.changing=opt.valueShow~=opt.value
end
if progress then
opt.progress=progress
end
end

---@type Techmino.Event
function task.event_always(P)
local L=P.modeData.task
for i=1,#L do
local opt=L[i]
if opt.changing then
opt.valueShow=MATH.expApproach(opt.valueShow,opt.value,0.0626)
if math.abs(opt.valueShow-opt.value)<.001 then
opt.valueShow=opt.value
opt.changing=false
end
end
if opt.achieved then
opt.achievedTimer=opt.achievedTimer%100+1
end
end
end

local w,dh,r=355,60,15
local gc=love.graphics
---@type Techmino.Event
function task.event_drawOnPlayer(P)
---@type Techmino.PlayerModeData.TaskObj[]
local L=P.modeData.task
local h=#L*dh
local y=-h/2
gc.push('transform')
gc.translate(-760,y)
GC.stc_reset()
GC.stc_rect(0,0,w,h,r)
gc.setColor(0,0,0,.42)
gc.rectangle('fill',0,0,w,h)
for i=1,#L do
local opt=L[i]
if opt.achieved and opt.achievedTimer<=50 then
gc.setColor(.26,.62,.7023,.7023)
else
gc.setColor(.26,.62,.7023,.872)
end
gc.rectangle('fill',0,0,w*opt.valueShow,dh)

gc.setColor(COLOR.L)
FONT.set(25,'bold')
gc.print(Text[opt.title] or opt.title,20,12)

FONT.set(20)
gc.printf(Text[opt.desc] or opt.title,10,5,w-20,'right')

if opt.progress then
FONT.set(15)
gc.printf(opt.progress,10,dh-30,w-20,'right')
end

gc.translate(0,dh)
end

gc.setColor(COLOR.L)
for i=1,#L-1 do
gc.line(0,-dh*i,w,-dh*i)
end

GC.stc_stop()
gc.setColor(COLOR.L)
gc.rectangle('line',0,-h,w,h,r)
gc.pop()
end

return task
1 change: 1 addition & 0 deletions assets/game/mechanicLib/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local require=simpRequire(function(path) return 'assets/game/mechanicLib/'..path
local mechLib={
common={
-- Tool
task=require'common/task',
timer=require'common/timer',
music=require'common/music',
characterAnim=require'common/characterAnim',
Expand Down
20 changes: 20 additions & 0 deletions assets/game/mode/brik/exterior/backfire.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,32 @@ return {
playerInit=function(P)
P.modeData.target.line=100
mechLib.common.music.set(P,{path='stat.line',s=40,e=75},'afterClear')
local T=mechLib.common.task
T.install(P)
T.add(P,'backfire_cheese','modeTask_backfire_cheese_title','modeTask_backfire_cheese_desc','(0/8)')
T.add(P,'backfire_normal','modeTask_backfire_normal_title','modeTask_backfire_normal_desc','(0/7)')
T.add(P,'backfire_amplify','modeTask_backfire_amplify_title','modeTask_backfire_amplify_desc','(0/8)')
end,
gameStart=function(P) P.timing=false end,
beforeSend=function(P,atk)
if P.modeData.subMode then return true end
P:receive(atk)
end,
beforeDiscard=function(P)
local T=mechLib.common.task
T.set(P,'backfire_cheese',P.stat.line/8,("($1/8)"):repD(P.stat.line))
if P.stat.line<=6 then
T.set(P,'backfire_normal',P.stat.line/7,("($1/7)"):repD(P.stat.atk))
else
T.set(P,'backfire_normal',0,"---")
end
if P.stat.line<=4 then
T.set(P,'backfire_amplify',P.stat.line/8,("($1/8)"):repD(P.stat.atk))
else
T.set(P,'backfire_amplify',0,"---")
end
if P.stat.atk>=8 and P.stat.line<=4 then
T.set(P,'backfire_amplify',true)
P.modeData.subMode='amplify'
P.settings.dropDelay=260
P.settings.maxFreshChance=10
Expand All @@ -32,6 +50,7 @@ return {
P:addEvent('beforeSend',mechLib.brik.survivor.backfire_easy_event_beforeSend)
playBgm('supercritical')
elseif P.stat.atk>=7 and P.stat.line<=6 then
T.set(P,'backfire_normal',true)
P.modeData.subMode='normal'
P.settings.dropDelay=620
P.settings.maxFreshChance=12
Expand All @@ -40,6 +59,7 @@ return {
P:addEvent('beforeSend',mechLib.brik.survivor.backfire_normal_event_beforeSend)
playBgm('storm')
elseif P.stat.line>=8 then
T.set(P,'backfire_cheese',true)
P.modeData.subMode='cheese'
P.settings.dropDelay=1000
P.settings.maxFreshChance=15
Expand Down
9 changes: 9 additions & 0 deletions assets/game/mode/brik/exterior/excavate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ return {
P.modeData.lineStay=0
mechLib.brik.dig.event_playerInit(P)
P:riseGarbage(math.floor(P.settings.fieldW*.5+1+P:rand(-2,2)))
local T=mechLib.common.task
T.install(P)
T.add(P,'excavate_shale', 'modeTask_excavate_shale_title', 'modeTask_excavate_shale_desc')
T.add(P,'excavate_volcanics', 'modeTask_excavate_volcanics_title', 'modeTask_excavate_volcanics_desc')
T.add(P,'excavate_checker', 'modeTask_excavate_checker_title', 'modeTask_excavate_checker_desc')
end,
gameStart=function(P) P.timing=false end,
afterClear={
Expand All @@ -31,17 +36,21 @@ return {
end
end
end
local T=mechLib.common.task
if split then
T.set(P,'excavate_checker',true)
P.modeData.digMode='checker'
P.modeData.target.lineDig=8
P.modeData.lineStay=8
mechLib.common.music.set(P,{path='.lineDig',s=2,e=6},'afterClear')
elseif clear.line<=2 then
T.set(P,'excavate_shale',true)
P.modeData.digMode='shale'
P.modeData.target.lineDig=40
P.modeData.lineStay=6
mechLib.common.music.set(P,{path='.lineDig',s=10,e=30},'afterClear')
else
T.set(P,'excavate_volcanics',true)
P.modeData.digMode='volcanics'
P.modeData.target.lineDig=20
P.modeData.lineStay=5
Expand Down
14 changes: 14 additions & 0 deletions assets/game/mode/brik/exterior/hypersonic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,31 @@ return {
P.settings.dropDelay=0
P.settings.lockDelay=1e99
P.settings.spawnDelay=260
local T=mechLib.common.task
T.install(P)
T.add(P,'hypersonic_low','modeTask_hypersonic_low_title','modeTask_hypersonic_low_desc','(0/4)')
T.add(P,'hypersonic_high','modeTask_hypersonic_high_title','modeTask_hypersonic_high_desc')
T.add(P,'hypersonic_hidden','modeTask_hypersonic_hidden_title','modeTask_hypersonic_hidden_desc')
T.add(P,'hypersonic_titanium','modeTask_hypersonic_titanium_title','modeTask_hypersonic_titanium_desc')
end,
afterClear=function(P,clear)
local initFunc
local T=mechLib.common.task
if P.stat.line<4 then
T.set(P,'hypersonic_low',P.stat.line/4,('($1/4)'):repD(P.stat.line))
end
if clear.line>=4 then

if #P.holdQueue==0 and P.gameTime<=8e3 then
-- Titanium: Techrash in 8s without hold
T.set(P,'hypersonic_titanium',true)
P.modeData.subMode='titanium'
initFunc=mechLib.brik.marathon.hypersonic_titanium_event_playerInit
playBgm('secret7th remix_hypersonic_titanium')

elseif P.gameTime<=6e3 then
-- Hidden: Techrash in 6s
T.set(P,'hypersonic_hidden',true)
P.modeData.subMode='hidden'
initFunc=mechLib.brik.marathon.hypersonic_hidden_event_playerInit
playBgm('secret7th_hypersonic_hidden')
Expand All @@ -36,6 +48,7 @@ return {

else
-- High: Techrash
T.set(P,'hypersonic_high',true)
P.modeData.subMode='high'
initFunc=mechLib.brik.marathon.hypersonic_high_event_playerInit
playBgm('secret7th')
Expand All @@ -45,6 +58,7 @@ return {
elseif P.stat.line>=4 then
-- Low: 4 Lines
P.modeData.subMode='low'
T.set(P,'hypersonic_low',true,'(4/4)')
initFunc=mechLib.brik.marathon.hypersonic_low_event_playerInit
playBgm('secret8th')
mechLib.common.music.set(P,{path='.point',s=100,e=300},'afterSpawn')
Expand Down
22 changes: 21 additions & 1 deletion assets/game/mode/brik/exterior/sequence.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,43 +72,63 @@ return {
holdSlot=0,
seqType=sequence_weird,
event={
playerInit=function(P) P.modeData.target.line=40 end,
playerInit=function(P)
P.modeData.target.line=40
local T=mechLib.common.task
T.install(P)
T.add(P,'sequence_mph', 'modeTask_sequence_mph_title', 'modeTask_sequence_mph_desc')
T.add(P,'sequence_flood', 'modeTask_sequence_flood_title', 'modeTask_sequence_flood_desc')
T.add(P,'sequence_drought', 'modeTask_sequence_drought_title', 'modeTask_sequence_drought_desc')
T.add(P,'sequence_saw', 'modeTask_sequence_saw_title', 'modeTask_sequence_saw_desc')
T.add(P,'sequence_rect', 'modeTask_sequence_rect_title', 'modeTask_sequence_rect_desc')
T.add(P,'sequence_rain', 'modeTask_sequence_rain_title', 'modeTask_sequence_rain_desc')
T.add(P,'sequence_pento', 'modeTask_sequence_pento_title', 'modeTask_sequence_pento_desc')
end,
gameStart=function(P) P.timing=false end,
afterClear={
function(P)
local T=mechLib.common.task

-- MPH
if P.stat.piece<=4 then
T.set(P,'sequence_mph',true)
P.modeData.subMode='mph'
playBgm('blox')
P:setSequenceGen('messy','-clearData')
P.settings.nextSlot=0

-- Bag
elseif P.hand.name=='S' or P.hand.name=='Z' then
T.set(P,'sequence_flood',true)
P.modeData.subMode='flood'
playBgm('reason')
P:setSequenceGen('bag7p6_flood','-clearData')
elseif P.hand.name=='J' or P.hand.name=='L' then
T.set(P,'sequence_drought',true)
P.modeData.subMode='drought'
playBgm('reason')
P:setSequenceGen('bag7p7m2_drought','-clearData')
elseif P.hand.name=='T' then
T.set(P,'sequence_saw',true)
P.modeData.subMode='saw'
playBgm('reason')
P:setSequenceGen('bag3_saw','-clearData')
elseif P.hand.name=='O' then
T.set(P,'sequence_rect',true)
P.modeData.subMode='rect'
playBgm('reason')
P:setSequenceGen('bag4_rect','-clearData')

-- ?
elseif P.hand.name=='I' then
T.set(P,'sequence_rain',true)
P.modeData.subMode='rain'
playBgm('race')
P:setSequenceGen('bag3_sea','-clearData')

-- Pento
elseif MATH.between(P.hand.id,8,25) then
T.set(P,'sequence_pento',true)
P.modeData.subMode='pento'
playBgm('beat5th')
P:setSequenceGen(sequence_pento_arc,'-clearData -clearNext')
Expand Down
14 changes: 13 additions & 1 deletion assets/game/mode/brik/exterior/survivor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ return {
atkSys='modern',
event={
playerInit={
mechLib.brik.survivor.event_playerInit,
function(P)
P.modeData.idleTime=0
P.modeData.lastPieceWave={-1,-1,-1,-1}
local T=mechLib.common.task
T.install(P)
T.add(P,'survivor_cheese','modeTask_survivor_cheese_title','modeTask_survivor_cheese_desc')
T.add(P,'survivor_power','modeTask_survivor_power_title','modeTask_survivor_power_desc')
T.add(P,'survivor_spike','modeTask_survivor_spike_title','modeTask_survivor_spike_desc')
end,
mechLib.brik.survivor.event_playerInit,
},
gameStart=function(P) P.timing=false end,
afterLock=function(P)
Expand All @@ -44,9 +49,14 @@ return {
end
end,
beforeCancel=function(P)
local T=mechLib.common.task
T.set(P,'survivor_cheese',P.stat.atk/8,("($1/8)"):repD(P.stat.atk))
T.set(P,'survivor_power',P.stat.atk/8,("($1/8)"):repD(P.stat.atk))
T.set(P,'survivor_spike',P.stat.atk/8,("($1/8)"):repD(P.stat.atk))
if P.stat.atk>=8 then
local eff=P.stat.atk/P.stat.line
if eff>=2 then
T.set(P,'survivor_spike',true)
P.modeData.subMode='spike'
P.settings.dropDelay=260
P.settings.maxFreshChance=10
Expand All @@ -56,6 +66,7 @@ return {
playBgm('there')
mechLib.common.music.set(P,{path='.wave',s=10,e=30},'afterClear')
elseif eff>=1 then
T.set(P,'survivor_power',true)
P.modeData.subMode='power'
P.settings.dropDelay=620
P.settings.maxFreshChance=12
Expand All @@ -64,6 +75,7 @@ return {
playBgm('here')
mechLib.common.music.set(P,{path='.wave',s=20,e=50},'afterClear')
else
T.set(P,'survivor_cheese',true)
P.modeData.subMode='cheese'
P.settings.dropDelay=1000
P.settings.maxFreshChance=15
Expand Down
Loading

0 comments on commit bd002d0

Please sign in to comment.