summaryrefslogblamecommitdiff
path: root/world/map/npc/functions/clear_vars.txt
blob: 23577434cc429f0686c436a6b96148ff5e647f23 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

                       
                              
 







                                            



                            

                      
                       
                   
                      
 
                            
 



                                              
 
                                                                
          




                                                                                                           




                                                                                                          





                                                                                                  
           
 




                                                                     




























                                                      














                                                                                                     
        

                                                   

                                           

                                                

                           







                                              


                                                
           
 

                                        
                              
                             
                  

                                          
           
 
                
                                  
                        
           
 





                                                  
 
           
                                
                           






































                                                                                      




                                                                                                            
           
 

                                                                                               

                                                                                                  
                      
                   
           
 

                                                                       

                                                                                                      
                      
                   
           
 

                                                                         

                                                                                                       
                     
                    
           
 

                                                                     

                                                                                                     
                     
                  
           
 

                                                                                             

                                                                                                        
           
 






                                                                                            
 
                


                          



                                                                             

 
                               
 
                      
 


                                                                 
                     











                                          
           
 
// Clears old variables

function|script|ClearVariables
{
    if(@login_event != 1) goto L_Deprecated;

    callsub S_Bernard_Mikhail;
    callsub S_Sarah;
    callsub S_Vincent;
    callsub S_Sandra;
    callsub S_Desert;
    callsub S_Bandit;
    callsub S_Tutorial;
    callsub S_Heathin;
    callsub S_Remove_Skills;
    callsub S_FixBank;
    callsub S_Flags;
    callsub S_Bitmask;
    callsub S_BlueSage;
    callsub S_Luca;
    callsub S_Keshlam;

    callsub S_Valentine2021;

    return; // go back to global handler

S_Return: // this is to end execution of a sub
    return;

////////////////////////////////////////////////////////////////
S_Bitmask:
    // move Scythe quest into bitmasked variable QUEST_Hurnscald
    if (QUEST_Scythe_state)
        set QUEST_Hurnscald, (QUEST_Hurnscald & ~(NIBBLE_1_MASK)) | (QUEST_Scythe_state << NIBBLE_1_SHIFT);
    set QUEST_Scythe_state, 0;

    // move Demon Mask quest into bitmasked variable QUEST_Hurnscald
    if (QUEST_demon_mines)
        set QUEST_Hurnscald, (QUEST_Hurnscald & ~(NIBBLE_2_MASK)) | (QUEST_demon_mines << NIBBLE_2_SHIFT);
    set QUEST_demon_mines, 0;

    // move Inspector quest into bitmasked variable QUEST_Hurnscald
    set @inspector, ((QUEST_Hurnscald & NIBBLE_3_MASK) >> NIBBLE_3_SHIFT);
    if (Inspector > @inspector)
        set QUEST_Hurnscald, (QUEST_Hurnscald & ~(NIBBLE_3_MASK)) | (Inspector << NIBBLE_3_SHIFT);
    set Inspector, 0;
    set @inspector, 0;
    return;

S_BlueSage:
    if (QUEST_BlueSage & (1 << 7))
        set QUEST_BlueSage, QUEST_BlueSage & ~((1<<5)|(1<<6)|(1<<7));
    return;

S_Luca:
    if (FLAGS & FLAG_LUCA_FIX) goto S_Return;
    if (FLAGS & FLAG_LUCA_6SKILLS_MAXED) goto S_Luca6;
    if (FLAGS & FLAG_LUCA_4SKILLS_MAXED) goto S_Luca4;
    if (FLAGS & FLAG_LUCA_2SKILLS_MAXED) goto S_Luca2;
    goto S_LucaX;

S_Luca6:
    if (countitem("AssassinMask") < 1) goto S_Return;
    delitem "AssassinMask", 1;
    set FLAGS, FLAGS ^ FLAG_LUCA_6SKILLS_MAXED;
    goto S_Luca4;

S_Luca4:
    if (countitem("AssassinPants") < 1) goto S_Return;
    delitem "AssassinPants", 1;
    set FLAGS, FLAGS ^ FLAG_LUCA_4SKILLS_MAXED;
    goto S_Luca2;

S_Luca2:
    if (countitem("AssassinBoots") < 1) goto S_Return;
    delitem "AssassinBoots", 1;
    set FLAGS, FLAGS ^ FLAG_LUCA_2SKILLS_MAXED;
    goto S_LucaX;

S_LucaX:
    set FLAGS, FLAGS | FLAG_LUCA_FIX;
    return;

S_Keshlam:
    if (FLAGS & FLAG_KESHLAM_REPACKED) goto S_Return;
    set KESHLAM_STATE, #BOSS_MEDALS | (#BOSS_MEDALS_AVAILABLE << BYTE_1_SHIFT);
    set #BOSS_MEDALS, 0;
    set #BOSS_MEDALS_AVAILABLE, 0;
    // old
    // FLAG_KESHLAM_FLAWEDLENS 16384  shift 14
    // FLAG_KESHLAM_RAREDROP   32768  shift 15
    // new
    // FLAG_KESHLAM_FLAWEDLENS 65536  shift 16
    // FLAG_KESHLAM_RAREDROP   131072 shift 17
    set KESHLAM_STATE, KESHLAM_STATE | ((FLAGS & 16384) >> 14) << 16 | ((FLAGS & 32768) >> 15) << 17;
    set FLAGS, FLAGS | FLAG_KESHLAM_REPACKED ^ 16384 ^ 32768;
    return;

S_Flags:
    if (Open_Underground_Palace_Barrier)
        set FLAGS, FLAGS | FLAG_OPENED_UNDERGROUND;
    set Open_Underground_Palace_Barrier, 0;

    if (Naem_Quest_Done)
        set FLAGS, FLAGS | FLAG_GOT_NAEM_GLOVES;
    set Naem_Quest_Done, 0;

    if (ChristmasQuest)
        set FLAGS, FLAGS | FLAG_SNOWMAN;
    set ChristmasQuest, 0;

    if (ChristmasQuest2)
        set FLAGS, FLAGS | FLAG_SANTAS_HELPER;
    set ChristmasQuest2, 0;

    if (ChestQuest)
        set FLAGS, FLAGS | FLAG_HURNSMINE_CHEST;
    set ChestQuest, 0;
    return;

S_FixBank:
    if(#BankAccount >= 0) goto S_Return;
    if (Zeny >= -#BankAccount)
        goto S_Fix_Bank_Full;
    // Partial fix
    set #BankAccount, #BankAccount + Zeny;
    set Zeny, 0;
    return;

S_Fix_Bank_Full:
    set Zeny, Zeny + #BankAccount;
    set #BankAccount, 0;
    return;

S_Remove_Skills:
    if(getskilllv(SKILL_TRADE) < 1) goto S_Return;
    setskill SKILL_TRADE, 0;
    setskill SKILL_PARTY, 0;
    setskill SKILL_EMOTE, 0;
    return;

S_Tutorial:
    if(!TUTORIAL) goto S_Return;
    //TUTORIAL to STARTAREA
    set @tutorial_tmp, ((TUTORIAL & NIBBLE_0_MASK) >> NIBBLE_0_SHIFT);
    // Tutorial
    // Nibble 0 (sorfina, tanisha, kaan & hasan)
    set STARTAREA, (STARTAREA & ~(NIBBLE_0_MASK) | (@tutorial_tmp << NIBBLE_0_SHIFT));
    // Nibble 1 (valon)
    set @tutorial_tmp, ((TUTORIAL & NIBBLE_2_MASK) >> NIBBLE_2_SHIFT);
    set @valon_done, (TUTORIAL & (1 << 7));
    set @valon_start, (TUTORIAL & (1 << 6));
    if (@valon_start)
        set @tutorial_tmp, (@tutorial_tmp + 2);
    if (@valon_done)
        set @tutorial_tmp, 7;
    set STARTAREA, (STARTAREA & ~(NIBBLE_1_MASK) | (@tutorial_tmp << NIBBLE_1_SHIFT));
    // Nibble 2 (Counts)
    set @tutorial_tmp, ((TUTORIAL & NIBBLE_3_MASK) >> NIBBLE_3_SHIFT);
    set STARTAREA, (STARTAREA & ~(NIBBLE_2_MASK) | (@tutorial_tmp << NIBBLE_2_SHIFT));
    // Nibble 3 (Morgan)
    set @tutorial_tmp, ((TUTORIAL & NIBBLE_6_MASK) >> NIBBLE_6_SHIFT);
    set STARTAREA, (STARTAREA & ~(NIBBLE_3_MASK) | (@tutorial_tmp << NIBBLE_3_SHIFT));
    // Nibble 4 (Zegas) Barrels shuffled
    set @zegas_done, (TUTORIAL & (1 << 23));
    set @zegas_start, (TUTORIAL & (1 << 16));
    set @zegas_met, (TUTORIAL & (1 << 30));
    set @tutorial_tmp, 0;
    if (@zegas_met)
        set @tutorial_tmp, 1;
    if (@zegas_start)
        set @tutorial_tmp, 2;
    if (@zegas_done)
        set @tutorial_tmp, 4;
    set STARTAREA, (STARTAREA & ~(NIBBLE_4_MASK) | (@tutorial_tmp << NIBBLE_4_SHIFT));
    // Nibble 5 (Barrels)
    set @tutorial_tmp, 0;
    set STARTAREA, (STARTAREA & ~(NIBBLE_5_MASK) | (@tutorial_tmp << NIBBLE_5_SHIFT));
    // Nibble 6 (Barrels)
    set STARTAREA, (STARTAREA & ~(NIBBLE_6_MASK) | (@tutorial_tmp << NIBBLE_6_SHIFT));
    set TUTORIAL, 0;
    return;


S_Heathin:
    if(!HEATHIN_QUEST) goto S_Return;
    set QUEST_NorthTulimshar, (QUEST_NorthTulimshar & ~(NIBBLE_6_MASK)) | (HEATHIN_QUEST << NIBBLE_6_SHIFT);
    set HEATHIN_QUEST, 0;
    return;

S_Desert: // move guard and miner subquest into Byte 2 (Nibble 4 and 5) of QUEST_SouthTulimshar
    if(!TMW_QUEST || TMW_QUEST > 40) goto S_Return;
    set @miners, TMW_Quest - 12;
    set QUEST_SouthTulimshar, (QUEST_SouthTulimshar & ~(BYTE_2_MASK) | (@miners << BYTE_2_SHIFT));
    set TMW_Quest, 12;
    set @miners, 0;
    return;

S_Sandra: // move Sandra subquest into Nibble 3 of QUEST_SouthTulimshar
    if(!TMW_QUEST || TMW_QUEST > 12) goto S_Return;
    set @sandra, TMW_Quest - 10;
    set QUEST_SouthTulimshar, (QUEST_SouthTulimshar & ~(NIBBLE_3_MASK) | (@sandra << NIBBLE_3_SHIFT));
    set TMW_Quest, 10;
    set @sandra, 0;
    return;

S_Vincent: // move Vincent subquest into Nibble 2 of QUEST_SouthTulimshar
    if(!TMW_QUEST || TMW_QUEST > 10) goto S_Return;
    set @vincent, TMW_Quest - 8;
    set QUEST_SouthTulimshar, (QUEST_SouthTulimshar & ~(NIBBLE_2_MASK) | (@vincent << NIBBLE_2_SHIFT));
    set TMW_Quest, 8;
    set @vincent, 0;
    return;

S_Sarah: // move Sarah subquest into Nibble 1 of QUEST_SouthTulimshar
    if(!TMW_QUEST || TMW_QUEST > 8) goto S_Return;
    set @sarah, TMW_Quest - 6;
    set QUEST_SouthTulimshar, (QUEST_SouthTulimshar & ~(NIBBLE_1_MASK) | (@sarah << NIBBLE_1_SHIFT));
    set TMW_Quest, 6;
    set @sarah, 0;
    return;

S_Bernard_Mikhail: // move Bernard and Mikhail subquest into Nibble 0 of QUEST_SouthTulimshar
    if(!TMW_QUEST || TMW_QUEST > 6) goto S_Return;
    set QUEST_SouthTulimshar, (QUEST_SouthTulimshar & ~(NIBBLE_0_MASK) | (TMW_Quest << NIBBLE_0_SHIFT));
    set TMW_Quest, 0;
    return;

S_Bandit: // move Bandit subquest into Nibble 0 of QUEST_Hurnscald
    if(!TMW_QUEST) goto S_Return;
    set @bandit, TMW_Quest - 40;
    set QUEST_Hurnscald, (QUEST_Hurnscald & ~(NIBBLE_0_MASK) | (@bandit << NIBBLE_0_SHIFT));
    set TMW_Quest, 40;
    set @bandit, 0;
    return;

S_Valentine2021:
    set #VALENTINE2021, 0;
    return;

L_Deprecated:
    debugmes "Explicitely calling ClearVariables after login is deprecated.";
    mapexit;
}


function|script|ClearGlobalVars
{
    goto L_IlliaClear;

// Clear the array which saves the teams who beat the Illia quest
L_IlliaClear:
    set $@loop, 0;
    goto L_IlliaLoop;

L_IlliaLoop:
    if ($Illia_Win_Records$[$@loop] == "")
        goto L_EventClear;

    set $Illia_Win_Records$[$@loop], "";

    set $@loop, $@loop + 1;
    goto L_IlliaLoop;

L_EventClear:
    set $@loop, 0;
    return;
}