
function QuickTrap()
    KEY()
    PMU(5)
    FON("CenterCamera",0)
    MOV(42,23,MCI("CS_mychar_quote"))
    MOV(40,23,MCI("CS_mychar_curly"))
    SLR(1,0)
    SLR(0,1)
    FAI(2)
    local smallBlockIndex = math.random(0,19)
    local setX = 22;
    local setY = 6;
    for i=0,19,1 do
        if(i == smallBlockIndex) then
            SNP("CS_fortblock_small",setX,setY+1,0,"mainLayer","FortBlock1")
            SNP("CS_fortblock_small",setX,setY,0,"mainLayer","FortBlock1")
            setX = setX + 1;
        else
            SNP("CS_fortblock",setX,setY,0,"mainLayer","FortBlock1")
            setX = setX + 2;
        end
    end
    ANP("FortBlock1","adjust_pos")
    ANP("FortBlock1","set_smog")
    ANP("FortBlock1","press")
    CMU("CS_Zonbie")
    --设置事件延时计时器
    ANP("HydraulicPressCountdown","countdown",1080)
end

function HydraulicPressCountdown()
    ANP("FortBlock1","destroy")
    PMU(5)
    WAI(60)
    --放置激光武器
    local delaycount = 60;
    for i=1,39,1 do
        local eventName = "LasertrapEvent"..i;
        CNP(eventName,"CS_enemy_lasertrap",0)
        ANP(eventName,"set_smog")
        ANP(eventName,"delay",delaycount)
        delaycount = delaycount + 20;
    end
    CMU("CS_Gravity")
end

function LasertrapAllDestroy()
    --检查所有的激光是否被摧毁
    if(FLJ("Lasertrap1") and FLJ("Lasertrap2") and FLJ("Lasertrap3") and FLJ("Lasertrap4") and FLJ("Lasertrap5") and
        FLJ("Lasertrap6") and FLJ("Lasertrap7") and FLJ("Lasertrap8") and FLJ("Lasertrap9") and FLJ("Lasertrap10") and
        FLJ("Lasertrap11") and FLJ("Lasertrap12") and FLJ("Lasertrap13") and FLJ("Lasertrap14") and FLJ("Lasertrap15") and
        FLJ("Lasertrap16") and FLJ("Lasertrap17") and FLJ("Lasertrap18") and FLJ("Lasertrap19") and FLJ("Lasertrap20") and
        FLJ("Lasertrap21") and FLJ("Lasertrap22") and FLJ("Lasertrap23") and FLJ("Lasertrap24") and FLJ("Lasertrap25") and
        FLJ("Lasertrap26") and FLJ("Lasertrap27") and FLJ("Lasertrap28") and FLJ("Lasertrap29") and FLJ("Lasertrap30") and
        FLJ("Lasertrap31") and FLJ("Lasertrap32") and FLJ("Lasertrap33") and FLJ("Lasertrap34") and FLJ("Lasertrap35") and
        FLJ("Lasertrap36") and FLJ("Lasertrap37") and FLJ("Lasertrap38") and FLJ("Lasertrap39")) then
        StartWaterSpaceTrap()
    end
end

function LasertrapEvent1()FLP("Lasertrap1")LasertrapAllDestroy()end
function LasertrapEvent2()FLP("Lasertrap2")LasertrapAllDestroy()end
function LasertrapEvent3()FLP("Lasertrap3")LasertrapAllDestroy()end
function LasertrapEvent4()FLP("Lasertrap4")LasertrapAllDestroy()end
function LasertrapEvent5()FLP("Lasertrap5")LasertrapAllDestroy()end
function LasertrapEvent6()FLP("Lasertrap6")LasertrapAllDestroy()end
function LasertrapEvent7()FLP("Lasertrap7")LasertrapAllDestroy()end
function LasertrapEvent8()FLP("Lasertrap8")LasertrapAllDestroy()end
function LasertrapEvent9()FLP("Lasertrap9")LasertrapAllDestroy()end
function LasertrapEvent10()FLP("Lasertrap10")LasertrapAllDestroy()end
function LasertrapEvent11()FLP("Lasertrap11")LasertrapAllDestroy()end
function LasertrapEvent12()FLP("Lasertrap12")LasertrapAllDestroy()end
function LasertrapEvent13()FLP("Lasertrap13")LasertrapAllDestroy()end
function LasertrapEvent14()FLP("Lasertrap14")LasertrapAllDestroy()end
function LasertrapEvent15()FLP("Lasertrap15")LasertrapAllDestroy()end
function LasertrapEvent16()FLP("Lasertrap16")LasertrapAllDestroy()end
function LasertrapEvent17()FLP("Lasertrap17")LasertrapAllDestroy()end
function LasertrapEvent18()FLP("Lasertrap18")LasertrapAllDestroy()end
function LasertrapEvent19()FLP("Lasertrap19")LasertrapAllDestroy()end
function LasertrapEvent20()FLP("Lasertrap20")LasertrapAllDestroy()end
function LasertrapEvent21()FLP("Lasertrap21")LasertrapAllDestroy()end
function LasertrapEvent22()FLP("Lasertrap22")LasertrapAllDestroy()end
function LasertrapEvent23()FLP("Lasertrap23")LasertrapAllDestroy()end
function LasertrapEvent24()FLP("Lasertrap24")LasertrapAllDestroy()end
function LasertrapEvent25()FLP("Lasertrap25")LasertrapAllDestroy()end
function LasertrapEvent26()FLP("Lasertrap26")LasertrapAllDestroy()end
function LasertrapEvent27()FLP("Lasertrap27")LasertrapAllDestroy()end
function LasertrapEvent28()FLP("Lasertrap28")LasertrapAllDestroy()end
function LasertrapEvent29()FLP("Lasertrap29")LasertrapAllDestroy()end
function LasertrapEvent30()FLP("Lasertrap30")LasertrapAllDestroy()end
function LasertrapEvent31()FLP("Lasertrap31")LasertrapAllDestroy()end
function LasertrapEvent32()FLP("Lasertrap32")LasertrapAllDestroy()end
function LasertrapEvent33()FLP("Lasertrap33")LasertrapAllDestroy()end
function LasertrapEvent34()FLP("Lasertrap34")LasertrapAllDestroy()end
function LasertrapEvent35()FLP("Lasertrap35")LasertrapAllDestroy()end
function LasertrapEvent36()FLP("Lasertrap36")LasertrapAllDestroy()end
function LasertrapEvent37()FLP("Lasertrap37")LasertrapAllDestroy()end
function LasertrapEvent38()FLP("Lasertrap38")LasertrapAllDestroy()end
function LasertrapEvent39()FLP("Lasertrap39")LasertrapAllDestroy()end

function StartWaterSpaceTrap()
    PMU(5)
    WAI(60)
    SNP("CS_pe_waterfallbase",22,5,0,"mainLayer","Waterfallbase1")ANP("Waterfallbase1","set_style",0)
    SNP("CS_pe_waterfallbase",23,5,0,"mainLayer","Waterfallbase2")ANP("Waterfallbase2","set_style",1)
    SNP("CS_pe_waterfallbase",24,5,0,"mainLayer","Waterfallbase3")ANP("Waterfallbase3","set_style",2)
    SNP("CS_pe_waterfallbase",58,5,0,"mainLayer","Waterfallbase1")ANP("Waterfallbase1","set_style",0)
    SNP("CS_pe_waterfallbase",59,5,0,"mainLayer","Waterfallbase2")ANP("Waterfallbase2","set_style",1)
    SNP("CS_pe_waterfallbase",60,5,0,"mainLayer","Waterfallbase3")ANP("Waterfallbase3","set_style",2)
    SNP("CS_stream_noise",0,0,0,"mainLayer","StreamNoise1")
    WAI(120)
    ANP("Waterlevel1","up")
    WAI(60)
    for i=22,60,2 do
        SNP("CS_pe_bubble_base",i,23,0,"mainLayer","PeBubbleBase1")
    end
    WAI(200)
    ANP("Waterlevel1","stop")
    DNP("Waterfallbase1")
    DNP("Waterfallbase2")
    DNP("Waterfallbase3")
    DNP("Waterfallbase4")
    DNP("Waterfallbase5")
    DNP("Waterfallbase6")
    WAI(60)
    DNP("StreamNoise1")
    ANP("PiranhaSetter1","set_npc_type")ANP("PiranhaSetter1","CS_enemy_piranha")
    ANP("PiranhaSetter1","set_npc_num",10)
    ANP("PiranhaSetter1","set_npc_interval",60)
    ANP("PiranhaSetter1","start")
    ANP("PiranhaSetter2","set_npc_type")ANP("PiranhaSetter2","CS_enemy_piranha")
    ANP("PiranhaSetter2","set_npc_num",10)
    ANP("PiranhaSetter2","set_npc_interval",60)
    ANP("PiranhaSetter2","start")
    CMU("CS_OppressionBetaExtra")
end

function PiranhaSetter1()
    FLP("PiranhaSetter1")
    PiranhaSetterAllDestroy()
end

function PiranhaSetter2()
    FLP("PiranhaSetter2")
    PiranhaSetterAllDestroy()
end

function PiranhaSetterAllDestroy()
    if(FLJ("PiranhaSetter1") and FLJ("PiranhaSetter2")) then
        --水位下降
        PMU(5)
        ANP("Waterlevel1","down")
        WAI(200)
        DNP("PeBubbleBase1")
        WAI(60)
        ANP("Waterlevel1","stop")
        WAI(60)
        KEY()
        ANP("BombSetter1","set_npc_type")ANP("BombSetter1","CS_enemy_trackingbomb")
        ANP("BombSetter1","set_npc_num",2)
        ANP("BombSetter1","set_npc_interval",120)
        ANP("BombSetter1","start")
        ANP("BombSetter2","set_npc_type")ANP("BombSetter2","CS_enemy_trackingbomb")
        ANP("BombSetter2","set_npc_num",2)
        ANP("BombSetter2","set_npc_interval",120)
        ANP("BombSetter2","start")
        CMU("CS_ironH")
    end
end

function BombSetter1()
    FLP("BombSetter1")
    BombSetterAllDestroy()
end

function BombSetter2()
    FLP("BombSetter2")
    BombSetterAllDestroy()
end

function BombSetterAllDestroy()
    if(FLJ("BombSetter1") and FLJ("BombSetter2")) then
        WAI(300)
        FinishTrap()
    end
end

function ClearFlag()
    for i=1,39,1 do
        FLS("Lasertrap"..i)
    end
    FLS("PiranhaSetter1")
    FLS("PiranhaSetter2")
    FLS("BombSetter1")
    FLS("BombSetter2")
end

function FinishTrap()
    KEY()
    CMU("CS_Fanfale3")
    MS4("\nFinished Trap Room Challenge!")WAI(140)NOD()CLO()
    FAO(2)
    FLP("DefeatedTrap")
    ClearFlag()
    TRA("CS_bossrush_mainstage","E0090",20,83)
end

function Died()
    CMU("XXXX")WAI(30)
    FAO(2)
    ClearFlag()
    SMC(0)SMC(1)LIP(1000)MIP(1000)TRA("CS_bossrush_mainstage","E0090",20,83)
end

function DeathByMovingPlatform()
    Died()
end