function E0090()
    InitRoom()FAI(0)
end
function E0091()
    InitRoom()FAI(1)
end
function E0092()
    InitRoom()FAI(2)
end
function E0093()
    InitRoom()FAI(3)
end
function E0094()
    InitRoom()FAI(4)
end

function InitRoom()
    MNA()
    if(FLJ("KingBack")) then
        CMU("CS_Kodou")
    else
        CMU("CS_Mura")
    end
end

--去外面
function Door_GoVillage()
    if(FLJ("Night")) then
        PRI()MM0()SOU("CS_011_door")ANP("Door_GoVillage",0,1)FAO(2)TRA("CS_village_night","E0090",23,14)
    else
        PRI()MM0()SOU("CS_011_door")ANP("Door_GoVillage",0,1)FAO(2)TRA("CS_village","E0090",23,14)
    end
end


--和杰克对话
function Jack1()
    if(FLJ("ThreeDaysLater")) then
        KEY()
        FAC("jack_normal")
        MS3("Come back soon!")NOD()
        CAT("\nPlease!")NOD()CLR()
    elseif(FLJ("AskedJack")) then
        KEY()
        FAC("jack_normal")
        MS3("It's getting late.")NOD()
        CAT("\nKanpachi, you should head back")
        CAT("\nand rest too.")NOD()CLR()
    else
        KEY()
        FAC("jack_normal")MS3("King has gone out on business")
        CAT("\nfor the past few days,")NOD()
        CAT("\nso I'll be managing the village") 
        CAT("\nfor now as the No. 2.")NOD()CLR()
        CAT("What?")NOD()
        CAT("\nSomeone went missing on my")
        CAT("\nfirst day in charge?")NOD()CLR()
        CAT("Ah... Mahin...")NOD()
        CAT("\nDon't worry about him.")NOD()
        CAT("\nIf he can't find food outside,")NOD()
        CAT("\nhe'll come back on his own.")NOD()
        CAT("\nJust wait another day or two...")NOD()CLR()
        FLP("AskedJack")
        if(FLJ("AskedToroko")) then
            MSR("AskEveryoneAboutMahin","GoHomeSleep")
            FLP("Night")
        end
    end
end

function ThreeDaysLater()
    KEY()
    FLS("AskedJack")
    FLS("Night")
    CMU("CS_Kodou")WAI(64)
    LIP(1000)
    MS2("Three days have passed since then.")
        CAT("\nMahin still hasn't returned...")NOD()CLO()
    WAI(64)
    AMC(0,1,PLY())
    FAI(2)
    WAI(32)
    FAC("jack_normal")MS4("I see,")NOD()
    CAT("\nHe's still not back.")NOD()CLR()
    CAT("You want to go look for him,") 
    CAT("\ndon't you?")NOD()
    CAT("\nLet me give you something useful.")NOD()CLO()
    ANP("Jack1",1,0)
    WAI(2*16)
    ANP("Jack1",0,0)
    GIT("Spikes")
    ITP("Spikes")
    SOU("CS_038_get_item")
    AMC(204,"CS_mychar_kanpa")
    MS4("\nGot =SPIKED BOOTS=.")WAI(30)NOD()GIT()CLR()
    FAC("jack_normal")CAT("With these boots, ")NOD()
    CAT("\nyou'll be more agile while moving,")NOD()
    CAT("\nand you can stomp on enemies")
    CAT("\nfrom above.")NOD()CLR()
    CAT("King cautioned me")
    CAT("\nnot to let anyone leave")
    CAT("\nthe village during this time,")NOD()
    CAT("\nbut now we have no choice.")NOD()CLR()
    CAT("Kanpachi, come back")
    CAT("\nas soon as you can,")NOD()
    CAT("\nand try not to let others")
    CAT("\nsee you leaving.")NOD()
    CAT("\nI'm counting on you!")NOD()
    FLP("ThreeDaysLater")
    MSR("GoHomeSleep","SearchForMahin")
end

function JackWaitKanpa()
    KEY()
    CMU("CS_Kodou")
    MNP("Jack1",22,15,0)
    ANP("Jack1","wander")
    FAI(0)
    WAI(120)
    ANP("Jack1","normal")
    WAI(32)
    FAC("jack_><")MS3("It's so late now,")NOD()
    CAT("\nwhy hasn't Kanpachi returned yet...")NOD()CLR()CLO()
    WAI(32)
    ANP("Jack1","normal",1)
    WAI(16)
    ANP("Jack1","normal",0)
    WAI(32)
    FAC("jack_normal")MS3("I'm getting worried.")NOD()
    CAT("\nI'd better see if the others")
    CAT("\nhave gone to bed...")NOD()CLO()
    ANP("Jack1","walk",0)
    WAI(64)
    FAO(3)
    TRA("CS_bar","Party",28,14)
end

function KnockTheDoor()
    for i=0,2,1 do
        SOU("CS_023_thud")
        SNP("CS_pe_gunshothit",14,15,0,"mainLayer","null")
        WAI(16)
    end
end

function ChakoWakeJackUp()
    KEY()
    CMU("XXXX")
    --杰克还在睡觉
    DNP("FirePlace1")
    ANP("Jack1","sleep")
    FAI(2)
    WAI(32)
    --怡可敲门
    KnockTheDoor()
    WAI(64)
    MS3("Santa...")NOD()
    CAT("\nLet me sleep a little longer...")NOD()CLO()
    WAI(32)
    KnockTheDoor()
    WAI(32)
    FAC("jack_><")MS3("\nWhat is it...")NOD()CLO()
    WAI(32)
    KnockTheDoor()
    WAI(32)
    FAC("jack_><")MS3("Stop knocking...")NOD()
    CAT("\nI'm coming now...")NOD()CLO()
    WAI(32)
    ANP("Jack1","normal",0)
    WAI(32)
    ANP("Jack1","walk",0)
    WAI(32)
    KnockTheDoor()
    WAI(60)
    ANP("Jack1","normal",0)
    WAI(16)
    SOU("CS_011_door")ANP("Door_GoVillage",0,1)
    WAI(32)
    --怡可出现
    SNP("CS_chako_animate",14,15,0,"mainLayer","Chako1")--怡可
    WAI(16)
    ANP("Chako1","walk",1)
    WAI(8)
    ANP("Jack1","normal",1)
    WAI(8)
    ANP("Chako1","normal",0)
    WAI(32)
    FAC("jack_normal")MS3("Oh, it's Chako...")NOD()
    CAT("\nWhat do you need...")CLR()
    ANP("Chako1","jump")
    SNP("CS_exclamation",15,13,0,"mainLayer","null")--感叹号
    FAC("chako_sigh")CAT("Toroko and the others have been")
    CAT("\ncaptured by monsters!!")NOD()CLR()
    FAC("jack_normal")CAT("What!")NOD()
    CAT("\nToroko's been captured?!")NOD()
    CAT("\nI need to tell King right away!")
    for i=0,6,1 do
        CAT(".")
        WAI(16)
    end
    CLR()
    ANP("Jack1","normal",0)
    FAC("jack_><")CAT("\nUgh, he's not here these days...")NOD()CLR()
    CAT("(If anything happens to Toroko, ")NOD()
    CAT("\nKing will tear me to pieces...)")NOD()CLO()
    WAI(64)
    FAC("chako_normal")MS3("\nSo you have to go rescue them!")ANP("Jack1","normal",1)NOD()CLO()
    WAI(16)
    SNP("CS_santa_animate",14,15,0,"mainLayer","Santa1")--桑塔
    ANP("Santa1","walk")
    WAI(16)
    ANP("Santa1","normal",1)
    FAC("chako_happy")MS3("\nSanta will go with you too.")NOD()CLR()
    FAC("jack_normal")CAT("\nColons are counting on you!")NOD()CLR()
    FAC("chako_happy")CAT("Defeat the Dark Lord")
    CAT("\nand come back soon~")NOD()CLO()
    FAO(2)
    WAI(32)
    TRA("CS_king_house","JackAndSantaReadyToGo",20,15)
end

function JackAndSantaReadyToGo()
    KEY()
    CMU("CS_Mura")
    --切换杰克（玩家） 加入 玩家2加入桑塔
    MOV(20,15,0)
    SLR(1,0)
    MOV(22,15,1)
    SLR(0,1)
    SWC(0,"CS_mychar_jack","CS_mychar_jack_p1")
    SWC(1,"CS_mychar_santa","CS_mychar_santa_p2")
    FLP("JackSantaGo")
    FLP("ColonLeave")
    FLP("Colon1GiveExp")
    FLP("Colon2GiveExp")
    FLP("Colon3GiveExp")
    FLP("Colon4GiveExp")
    FLP("ChakoGiveExp")
    FLP("SueGiveExp")
    FLP("TorokoGiveExp")
    FLP("TorokoNecklace")
    FLS("PowerOn")
    DNP("Jack1")
    --让指令先执行
    WAI(1)
   
    FLP("HideHomeJack")
    FLS("Night")
    FAI(0)
    WAI(32)
    --显示枪
    SOU("CS_004_switchweapon")
    AMC("show_gun",1,0)
    FAC("jack_normal")MS3("\nGot your weapon?")NOD()CLO()
    WAI(32)
    AMC("show_gun")
    SOU("CS_004_switchweapon")
    WAI(32)
    MS3("\nYes, I have it.")NOD()CLR()
    FAC("jack_normal")CAT("\nThen let's move out!")NOD()CLR()
    FAC()MS2("In multi-character scenarios,")NOD()
    CAT("\npress ["..KEN(0,13).."] key to switch") 
    CAT("\ncontrol between the 2 playable characters.")NOD()
    CAT("\nPlayer 2 can press ["..KEN(1,13).."] key") 
    CAT("\nto control the 2nd playable character,")
    CAT("\npress again to let AI control it.")NOD()CLO()
    --如果只有1个玩家
    if(GOP() == 1) then
        --玩家2由AI控制
        AGP("CS_mychar_santa_p2",true)
    end
    P2A(true)--允许玩家2使用AI切换
    --设置地图系统在岔路口捡到
    if(ITJ("MapSystem")) then
        FLP("KanpaMapSystemDrop")
    end
    --清空所有物品
    ITS()
    --带上枪
    ITP("Bubbler")
    ITP("Fireball")
    --移除所有任务
    MSD()
    --增加现在的任务
    MSA("SaveToroko")
end

function PuuSearch()
    KEY()
    ANP("Door_GoVillage",0,1)
    DNP("FirePlace1")
    SNP("CS_puu_animate",19,15,0,"mainLayer","Puu1")
    ANP("Puu1","walk",1)
    FAI(0)
    WAI(64)
    ANP("Puu1","normal",1)
    WAI(32)
    ANP("Puu1","normal",0)
    WAI(32)
    ANP("Puu1","normal",1)
    WAI(64)
    ANP("Puu1","walk",0)
    WAI(128)
    WAI(32)
    ANP("Puu1","normal",0)
    WAI(32)
    DNP("Puu1")
    WAI(32)
    SOU("CS_011_door")ANP("Door_GoVillage",0,0)
    WAI(32)
    FAO(2)TRA("CS_village","SoapSearch",0,0)
end

function ChakoHidden()
    KEY()
    SNP("CS_chako_animate",16,15,1,"mainLayer","Chako1")
    ANP("Chako1","back",1)
    ANP("Blackboard1",0,1)
    DNP("FirePlace1")
    FAI(0)
    WAI(16)
    FAC("chako_sad")MS3("At this point,")NOD()
    CAT("\nI have no choice but to go all out,")NOD()
    CAT("\nThe best I can do now is leave behind")
    CAT("\nclues about the monster's appearance.")NOD()CLO()
    ANP("Chako1","normal",1)
    WAI(32)
    GIT("ChakoLipstick")
    MS3("\n*Drops lipstick on the ground.")NOD()CLO()
    GIT()
    SNP("CS_sparkitem",17,15,0,"mainLayer","Chako1")
    WAI(32)
    FAC("chako_sad")MS3("\nThis will have to do...")NOD()CLO()
    KnockTheDoor()
    ANP("Chako1","normal",0)
    WAI(16)
    MS3("Are you there? Little beauty,")NOD()
    CAT("\nStop hiding and come out now...")NOD()CLR()
    CAT("Unless you want me to use")
    CAT("\na more forceful approach.")NOD()CLO()
    FLP("ChakoClue")
    WAI(32)
    ANP("Chako1","walk",0)
    WAI(32)
    ANP("Chako1","back",0)
    WAI(16)
    FAC("chako_sad")MS3("The monsters aren't")
    CAT("\nwhat's frightening...")NOD()
    CAT("\nWhat's truly terrifying is,")NOD()
    CAT("\nif the Colons are exposed,")NOD()
    CAT("\nonce they've captured all")
    CAT("\nseven of us,")NOD()
    CAT("\nhanding us over to the Gaudis would")
    CAT("\nbe the worst fate.")NOD()CLO()
    ANP("Chako1","normal",0)
    WAI(32)
    KnockTheDoor()
    MS3("\nLittle beauty, don't keep me waiting too long~")NOD()CLO()
    WAI(64)
    FAC("chako_happy")MS3("\nChako, please summon your courage!")NOD()CLO()
    ANP("Chako1","back",0)
    WAI(64)
    SOU("CS_011_door")ANP("Door_GoVillage",0,1)
    WAI(16)
    DNP("Chako1")
    WAI(16)
    SOU("CS_011_door")ANP("Door_GoVillage",0,0)
    WAI(16)
    FAO(2)TRA("CS_village","ChakoGetCaught",0,0)
end

function GetChakoLipstick()
    KEY()
    FAC("king_normal")MS3("Let's leave the scene as it is.")NOD()
    CAT("\nI'll leave this clue for")
    CAT("\nQuote and Curly as well.")NOD()
end

function Blackboard1()
    PRI()
    MS4("\nNothing noteworthy up there.")NOD()
end

function ChakoClue()
    KEY()
    FAC("king_normal")MS3("This is what the monster looks like.")NOD()
    CAT("\nIt appears to be one of those")
    CAT("\nStatue Fiend living beneath")
    CAT("\nthe caves.")NOD()
end

function KingBack()
    KEY()
    --CMU("CS_Kodou")
    HMC(0)
    SLR(1,0)
    FAI(2)
    WAI(16)
    SOU("CS_011_door")ANP("Door_GoVillage",0,1)
    WAI(16)
    SMC(0)
    WAI(16)
    SOU("CS_011_door")ANP("Door_GoVillage",0,0)
    WAI(32)
    FAC("king_normal")MS3("Jack?")NOD()
    CAT("\nJack's not here either...")NOD()CLO()
    WAI(32)
    AMC("walk")
    WAI(32)
    AMC("normal")
    WAI(32)
    GIT("ChakoLipstick")
    FAC("king_normal")MS3("This is Chako's lipstick...")NOD()
    CAT("\nWhy is it here?")NOD()CLO()
    GIT()
    WAI(32)
    AMC("back")
    WAI(32)
    FAC("king_normal")MS3("What's this red pattern drawn on it?")NOD()
    CAT("\nLooks like it was drawn")
    CAT("\nwith lipstick...")NOD()
    CAT("\nCould everyone be in danger?!")NOD()CLR()
    AMC("normal")
    CAT("\nI must check on them right away!!")NOD()CLO()
    WAI(16)
    FAO(0)
    TRA("CS_santa_house","KingBack",18,14)
end

function KingReadyToGo()
    KEY()
    AMC("back",1)
    FAI(2)
    WAI(32)
    FAC("king_normal")MS3("This must be the clue Chako left")
    CAT("\nabout the monster's appearance.")NOD()
    CAT("\nI have some idea where the")
    CAT("\nmonster might be.")NOD()CLO()
    AMC("normal",1)
    WAI(32)
    FAC("king_normal")MS3("Though I wanted to wait for")
    CAT("\nQuote and Curly")
    CAT("\nto return before taking action,")NOD()
    CAT("\nmy instincts tell me")
    CAT("\ntime is running out.")NOD()CLR()
    CAT("\nI need to leave immediately!")NOD()
    ---[[
    --如果是双玩家模式
    if(GOP() == 2) then
        --再加入一个金让玩家2控制
        CGP("CS_mychar_king_p1","CS_mychar_king_p2")
        SPL(1,"CS_mychar_king_p2")
        P2A(false)--禁止玩家2使用AI切换
    else
        --玩家2置为NULL
        SGP("null",73,27,0,"CS_mychar_null_p2")
        SPL(1,"CS_mychar_null_p2")
    end
    --]]
    MSD()
    MSA("SaveEveryoneKing")
end