summaryrefslogblamecommitdiff
path: root/npc/021-4/main.txt
blob: 477dbd57d677f1db2a9bafa3bd1e5f0af282dc84 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14













                                                                                               














                                                                        
 


                                                            
                                             










                                              
                                                                                                       





                                                    
                                                                 






























                                                                                  
 
        

                                    
                                                        
                                     
                     

                                             
                                                      
                                           
                     



                                                                 
                                               

                                    
                    


                                                                                                  
                                                                                         
     












                                                                                                                                        




                                                 
 
        














                                                                                                                                  
                                     



                     
        






                                
                                      



                                                                                          

          
























                                                                                                      




                                                                                   



                                                                                                          
                                                                                                           


                                                                                       
                                                                                      





                                                            

     



                                                     

                                 
                   
                            
            
                                                            


                               



                                  


          


           
                                     




                           


                                                                                            

        







                                                                    
          
          
                
             
                 

                            




                                 
                                                                           
                                             
                 

        
            
            
                                                       
 







                                                            
                              
                                 
                                                                                                                                        
                                                                         
                                                                          
                                        
                     
            
     














                                                           

                     
















                                                                              
                              












                                                                                                    
     







                                                                                         

                                                                      
                        
                 

        

                
                                      
                                                                                   
                                                          
                     




                                 
        
 
 
// TMW2 scripts.
// Authors:
//    The Mana World Team
//    Jesusalva
// Description:
//    Cindy Cave core logic. You must flip 5 switches to free Cindy, and kill every
//    Yeti to leave the Yeti's King Throne Room. Each passing minute, a new Yeti will
//    spawn. Amount relies on how long this has been dragging on.
//    Flipping switches creates yetis on the other switches.
//    You must try flip all 5 switches at once. Once all switches are flipped, there'll
//    be various waves of Yetis. More time passing = more penalty Yetis, with a safety
//    check to abort script after a hour. If this happen, everyone inside the cave
//    will be banned for cheating. This should not be possible without @monsterignore anyway :<

// Switches
function	script	CindySwitch_Check_214	{
    .@st1=getvariableofnpc(.lifetime, "#CindySwitch_06")-gettimetick(2);
    .@st2=getvariableofnpc(.lifetime, "#CindySwitch_07")-gettimetick(2);
    .@st3=getvariableofnpc(.lifetime, "#CindySwitch_08")-gettimetick(2);
    .@st4=getvariableofnpc(.lifetime, "#CindySwitch_09")-gettimetick(2);
    .@st5=getvariableofnpc(.lifetime, "#CindySwitch_10")-gettimetick(2);
    .@i=0;
    if (.@st1 > 0) .@i++;
    if (.@st2 > 0) .@i++;
    if (.@st3 > 0) .@i++;
    if (.@st4 > 0) .@i++;
    if (.@st5 > 0) .@i++;
    return .@i;
}

// Switches
021-4,101,33,0	script	#CindySwitch_06	NPC_SWITCH_OFFLINE,{
    .@q=getq(NivalisQuest_Cindy);
    if (.@q < 3 || !countitem(TreasureKey)) {
        mesn strcharinfo(0);
        mesq l("This is a strange switch...");
        close;
    }
    if (.lifetime-gettimetick(2) <= 0) {
        mesc l("Pull the switch?");
        select
            l("Pull it"),
            l("Leave it");
        if (@menu == 1) {
            getexp rand(55, 110), rand(5, 11);
            .lifetime=gettimetick(2)+rand(110, 150)+60; // Something between 1m50s and 2m30s + 1 minute
            specialeffect(FX_SUCCESS);
            setnpcdisplay .name$, NPC_SWITCH_ONLINE;
            initnpctimer;
            .@r=rand(0,100);
            getmapxy(.@m$, .@x, .@y,0);
            if (.@r < 90)
                monster .@m$, .@x, .@y, "Yeti", Yeti, rand2(4,6);
            else
                monster .@m$, .@x, .@y, "Yeti", Yeti, 2;
            npctalk l("Automatic disarm in: @@", FuzzyTime(.lifetime));
            closedialog;
        }
        close;
    }
    npctalk l("Automatic disarm in: @@", FuzzyTime(.lifetime));
    end;

OnTimer1000:
    if (.lifetime-gettimetick(2) <= 0) {
        setnpcdisplay .name$, NPC_SWITCH_OFFLINE;
        stopnpctimer;
    } else {
        initnpctimer;
    }
    end;

OnInit:
    .sex = G_OTHER;
    .distance = 3;
    .lifetime=0;  // When will this switch turn off automatically
    end;

}

021-4,90,79,0	duplicate(#CindySwitch_06)	#CindySwitch_07	NPC_SWITCH_OFFLINE
021-4,49,65,0	duplicate(#CindySwitch_06)	#CindySwitch_08	NPC_SWITCH_OFFLINE
021-4,47,21,0	duplicate(#CindySwitch_06)	#CindySwitch_09	NPC_SWITCH_OFFLINE
021-4,80,49,0	duplicate(#CindySwitch_06)	#CindySwitch_10	NPC_SWITCH_OFFLINE

// Cindy
//    Global Variable: $@CINDY_STATE

021-4,66,49,0	script	Cindy#Outside	NPC_CINDY_CAGE,{
    if (getq(NivalisQuest_Cindy) < 4)
        goto L_Cheat;
    if ($@CINDY_STATE > 150000) goto L_Reset;
    if ($@CINDY_STATE % 2 == 0) goto L_Start;
    if (CindySwitch_Check_214() == 5 && !.canfinish) {
        // Gate is open, advance to stage 2
        .canfinish=1;
        .lifetime+=3;
        .wtime=0;
        mapannounce "021-4", "*roaaaaar*",0;
        npctalk "Take care! More Yetis! And they have friends!!";
        setnpcdisplay .name$, NPC_CINDY_UNCAGE;
        .@pl = getmapusers("021-4");
        if (.@pl == 1)
            .@pl+=1;
        .@pl+=3;
        areamonster "021-4", 20, 20, 100, 80, "Yeti", Yeti, .@pl, "Cindy#Outside::OnPetDeath";
        areamonster "021-4", 20, 20, 100, 80, "Moggun", Moggun, .@pl, "Cindy#Outside::OnPetDeath";
        areamonster "021-4", 20, 20, 100, 80, "Slime Blast", SlimeBlast, $@CINDY_STATE+1;
    }

    // If a major bug happened, do it now
    // This finishes the quest
    .@y=mobcount("021-4", "Cindy#Outside::OnPetDeath");
    if (.@y == 0 && .canfinish) {
        $@CINDY_STATE=gettimetick(2)+60*rand2(55,65)*rand2(4,36); // It is way too random to I say how long it takes (220min ~ 39 hours)
        mapannounce "021-4", "Nivalis: Cindy is now safe!",bc_all|bc_npc;
        areatimer "021-4", 20, 20, 100, 80, 10, "Cindy#Outside::OnReward";
        setnpcdisplay .name$, NPC_CINDY;
        stopnpctimer;
        end;
    }

    if (.canfinish)
        npctalk l("*scream*");
    else
        npctalk3 l("Please get me out of here!");
    end;

// Start
L_Start:
    mesn;
    mesq l("Have you came here to rescue me?");
    mes ""; mes "";
    mesc l(".:: WARNING ::."), 1;
    mesc l("Once you decide to rescue Cindy, nobody else will be able to enter or leave this room."), 1;
    mesc l("The blame of failure will be over you, but so will be the glory of success. There's no death penalty for others."), 1;
    mes "";
    select
        l("Not yet, I'm waiting for friends"),
        l("Yes. Let me try to open this."),
        l("No, I'll let you there to the Yeti's mercy.");

    if (@menu == 2 && $@CINDY_STATE % 2 == 0) {
        $@CINDY_STATE+=1;
        $@CINDY_HERO$=strcharinfo(0);
        goto L_Begin;
    }
    close;

// Begin
L_Begin:
    initnpctimer;
    enablenpc "#CindySwitch_06";
    enablenpc "#CindySwitch_07";
    enablenpc "#CindySwitch_08";
    enablenpc "#CindySwitch_09";
    enablenpc "#CindySwitch_10";
    changemusic "021-4", "misuse.ogg";

    .@pl = getmapusers("021-4");
    areamonster "021-4", 20, 20, 100, 80, "Yeti", Yeti, .@pl, "Cindy#Outside::OnPetDeath";
    monster "021-4", 66, 49, "Yeti", Yeti, 1, "Cindy#Outside::OnPetDeath";
    close;

// Special use-case
L_Reset:
    if ($@CINDY_HERO$ == strcharinfo(0)) {
        goto L_Winner;
    } else if (is_gm() && $@GM_OVERRIDE) {
        $@CINDY_STATE=0;
        npctalk l("*beeep*");
    }
    end;

// For all players finishing the quest
OnReward:
    if (ispcdead()) {
        recovery(getcharid(3));
        warp "Save", 0, 0;
        end;
    }
    if ($@CINDY_HERO$ == strcharinfo(0))
        dispbottom l("Congratulations on rescuing Cindy. You should now talk to her before leaving.");
    else
        dispbottom l("Congratulations on rescuing Cindy.");
    setq2 NivalisQuest_Cindy, getq2(NivalisQuest_Cindy)+1;
    getexp 10000, JobLevel;
    end;

// Winner Reward
L_Winner:
    mesn;
    mesq l("Thanks for saving me. I'll return home on my own, if you don't mind.");
    mesq l("Here, take this reward. Good luck. %%1");

    if ($CINDY_WINNER$ == "") {
        $CINDY_WINNER$=strcharinfo(0);
        channelmes("#world", $CINDY_WINNER$+" is the first player to finish Cindy Quest!! GG, dude! %%N");
        announce "All hail ##B"+$CINDY_WINNER$+"##b, first to complete the ##3Cindy Quest!", bc_all|bc_npc;
        getexp 0, 2000;
        getitem PrismGift, 1;
        mesc l("CONGRATULATIONS! You are the first player to finish Cindy Quest!!"), 2;
        mesc l("You just gained a Prism Gift, and 2000 Job Exp for your bravery!"), 2;
    } else {
        if (getcharid(1) > 0)
            .@v$=getpartyname(getcharid(1));
        else
            .@v$=strcharinfo(0);
        kamibroadcast("Cindy was rescued by \""+.@v$+"\".");
    }

    // Better proccess this before everything else...
    $@CINDY_HERO$="";
    setnpcdisplay .name$, NPC_ICE_CAGE;

    .@q=getq(NivalisQuest_Cindy);
    // First time
    if (.@q == 4) {
        getitem Earmuffs, 1;
    } else {
        Zeny=Zeny+rand(min(15000, 5000+BaseLevel*10),15000);
        getitem TreasureMap, 1;
        getitem TreasureKey, 1;
    }
    setq1 NivalisQuest_Cindy, 5;
    next;
    npctalk l("Cindy is gone...");
    closedialog;
    close;

// Events
OnPetDeath:
    end;

// Cast against all players on defeat
OnFail:
    percentheal -100, -100;
    heal -1, -1;
    end;

// Edge Cases
L_Cheat:
    warp "Save", 0, 0; atcommand "@jail "+strcharinfo(0); dispbottom l("Cheater detected.");
    end;

// Timeout
OnReckless:
L_Reckless:
    kamibroadcast("People failed to rescue Cindy!");
    areatimer "021-4", 20, 20, 100, 80, 10, "Cindy#Outside::OnFail";
    goto L_CleanUp;

// Event is over, clean up the mess the players left
OnCleanUp:
L_CleanUp:
    .lifetime=0;
    .wtime=0;
    .canfinish=0;
    $@CINDY_STATE+=1;
    killmonsterall("021-4");
    disablenpc "#CindySwitch_06";
    disablenpc "#CindySwitch_07";
    disablenpc "#CindySwitch_08";
    disablenpc "#CindySwitch_09";
    disablenpc "#CindySwitch_10";
    setnpcdisplay .name$, NPC_CINDY_CAGE; // We need NPC_CINDY for complete
    changemusic "021-4", "water_prelude.ogg";
    stopnpctimer;
    end;

// Main loop
OnTimer2000:
    .@y=mobcount("021-4", "Cindy#Outside::OnPetDeath");

    // Quest is complete... We might need to clean the mess.
    if ($@CINDY_STATE > gettimetick(2)) {
        .@pl = getmapusers("021-4");
        if (!.@pl)
            goto L_CleanUp;
        end;
    }

    // This finishes the quest
    if (.@y == 0 && .canfinish) {
        $@CINDY_STATE=gettimetick(2)+60*rand2(55,65)*rand2(4,36); // It is way too random to I say how long it takes (220min ~ 39 hours)
        mapannounce "021-4", "Nivalis: Cindy is now safe!",bc_all|bc_npc;
        areatimer "021-4", 20, 20, 100, 80, 10, "Cindy#Outside::OnReward";
        setnpcdisplay .name$, NPC_CINDY;
        stopnpctimer;
        end;
    }
    .wtime+=2;

    // Before 10 minutes, spawn every ~ 2 minutes
    .@bonus=rand2(110,130);
    // After 10 waves, spawn each ~ 10 minutes
    if (.lifetime >= 10)
        .@bonus+=500;

    // After 15 waves, we'll go a bit slower, but not much.
    // You are a noob and should fail the quest.
    if (.lifetime >= 15)
        .@bonus+=.lifetime*2;

    if (.wtime >= .@bonus) {
        // A new wave have passed
        .wtime=0;
        .lifetime+=1;
        .@pl = getmapusers("021-4");

        // Once the gate is open, more Yetis spawn, but not much
        if (.canfinish)
            .@pl+=1;

        // Value is given as: 1 Yeti per player
        .@value=.@pl;
        // + 1 Yeti per difficulty setting
        .@value+=($@CINDY_STATE/2);
        // +1 Yetis if you are alone because this is not a solo quest at heart
        if (.@pl == 1)
            .@value+=1;

        // To make easier, we spawn some Mogguns, too.
        // The ratio is Yeti 2:1 Moggun. (Third Yeti is replaced)
        .@mogg=.@value/3;
        .@yeti=.@value-.@mogg;
        areamonster "021-4", 20, 20, 100, 80, "Yeti", Yeti, .@yeti, "Cindy#Outside::OnPetDeath";
        areamonster "021-4", 20, 20, 100, 80, "Moggun", Moggun, .@mogg, "Cindy#Outside::OnPetDeath";
        npctalk any("Yetis!",
                    "Watch out!",
                    "More of them are coming!",
                    "Be careful! There's more!",
                    "More Yetis! Will this never end?",
                    "AAAAH! YETIS!",
                    "*shierks*",
                    "There are coming more and more!",
                    "More Yetis! We are hopeless!",
                    "Keep your guard up!",
                    "Hit and run, hit and run! More of them!");
    }

    // Regardless of Wave, Blue Slimes and Slime Blast will show up.
    // This is based difficulty setting (previous fails)
    if (.wtime % 10 == 2) {
        .@mid=any(SlimeBlast, SlimeBlast, SlimeBlast, BlueSlime, BlueSlime, AzulSlime);
        areamonster "021-4", 20, 20, 100, 80, strmobinfo(1, .@mid), .@mid, $@CINDY_STATE;
    }

    // You're taking too much time, clear the spot after the 30th wave
    if (.lifetime >= 30)
        goto L_Reckless;
    initnpctimer;
    end;

OnInit:
    .distance=5;
    .lifetime=0; // Controls Yeti Wave
    .wtime=0;    // Timer runs sort of often. WTime controls automatic Yeti advance
    .canfinish=0;// Can finish or must talk to cage first?
    $@CINDY_HERO$="";
    disablenpc "#CindySwitch_06";
    disablenpc "#CindySwitch_07";
    disablenpc "#CindySwitch_08";
    disablenpc "#CindySwitch_09";
    disablenpc "#CindySwitch_10";
    end;
}