summaryrefslogblamecommitdiff
path: root/npc/commands/rate-management.txt
blob: 24bf9d75ab8254b1a650183ffef9dd7409e1f137 (plain) (tree)
1
2
3
4
5
6
7
8
9
                           


                                       

                          
                                             
            
                                             

     


                        
                                      
            
                                      

     



                          
                                     

                                                      
                                                                                 
                        
                                                                









                                                                          
                
            




                                                                                              
                         

                                     
                                                        










                                                                                  
 



                                   


                                                                                         
                                    
                                        
                        

                                       



                                                                                                                                                             
 
                                                                                                               
                                                                                               
                                                                                         
 

                                                     
                               
                                            

                                                                                                                     
                
                                                                                                        
                                                                       


                                                                                                      
 

            


                                                                       
                                   



        
             
      


                                            
      

                                                                       

                                           
                                                   
 





                                                                        
                                                                    
               
                                  
                                

                                                           



                                   
                                                                                                




                                 
                       

        

                      
                                 






                    
                         





                                                                   
                                                                          

                                                                    
                                 

                                


                                                                    


         


                                                    
                                          
                                               
                                              

                                                                
        

                  


                                                       





                                               
 





                                                                                 

                           
                                             
            
                                             

     


                         
                                      
            
                                      

     



                          
                                     









                                                               
                                                                                                               
                        
                                                                 









                                                                          
                  












                                                                                              









                                                                       
                                    
                        

                                       
                                                                                                                                                       


                                     

                                                                                                                
                                                                                                
                                                                                          
                                                     
                               
                                              

                                                                                                                     
                
                                                                                                         
                                                                        








                                                                                                        
                                    





                      
                                 






                    
                         








                                                                                                   
                                 
                         


         



                                                     
                                           











                                                       
                                                       
        
 
// Authors: Gumi, Jesusalva
-	script	@exprate	32767,{
    end;

    function expRateReal {
        if (is_night())
            return $BCONFB_EXPR+$BCONFN_EXPR;
        else
            return $BCONFB_EXPR+$BCONFD_EXPR;
    }

    function expRecalc {
        .@val=getarg(0);
        if (is_night())
            return .@val+$BCONFN_EXPR;
        else
            return .@val+$BCONFD_EXPR;
    }

    function rateCleanUp {
        stopnpctimer;
        .hours = 0;
        .max_hours = 0;
        .current_rate = $BCONFB_EXPR;
        setbattleflag("base_exp_rate", expRateReal());
        setbattleflag("job_exp_rate", expRateReal());
        charcommand("@reloadmobdb"); // this is on purpose (callable without RID)
        SeasonReload(1);
        channelmes("#world", "The EXP Rate Bonus is now over.");
    }

    function remainingTime {
        .@total_seconds = (3600 * .max_hours);
        .@seconds_elapsed = (3600 * .hours) + (getnpctimer(0) / 1000);
        .@seconds_remaining = max(1, .@total_seconds - .@seconds_elapsed);
        return FuzzyTime(time_from_seconds(.@seconds_remaining), 2, 2);
    }

OnCall:
   if (!is_gm())
        end;

    .@special$ = strip(.@atcmd_parameters$[0]); // special value
    .@new_rate = min(atoi(.@special$), 1000); // or just a regular integer
    .@hours = min(0x7FFFFFFE, max(1, atoi(strip(.@atcmd_parameters$[1])))); // number of hours

    if (.@new_rate > 0) {
        // Overwriting previous rate?
        // Confirmation Required
        if (expRecalc(.current_rate) != expRateReal()) {
            setnpcdialogtitle("@rate-managment");
            mesc l("WARNING!"), 1;
            mesc l("A previous exp rate up event is already ongoing."), 1;
            mesc l("IF YOU CHANGE EXP RATE NOW, PREVIOUS BONUS WILL BE LOST!"), 1;
            next;
            mesc l("CONTINUE ANYWAY? [Y/N]"), 1;
            // aborted
            if (askyesno() == ASK_NO)
                close;
            closeclientdialog;
        }

        // set new exp rate
        .hours = 0;
        .max_hours = .@hours;
        .current_rate = .@new_rate;
        setbattleflag("base_exp_rate", expRecalc(.@new_rate));
        setbattleflag("job_exp_rate", expRecalc(.@new_rate)); // Should GM event do this?
        //setbattleflag("quest_exp_rate", expRecalc(.@new_rate));
        charcommand("@reloadmobdb");
        //charcommand("@reloadquestdb");
        SeasonReload(1);
        initnpctimer; // start counting

        .@msg$=strcharinfo(0)+" increased experience rate to "+str(.@new_rate)+"%. It will only last "+str(FuzzyTime(time_from_hours(.max_hours), 2, 2))+"!";

        announce .@msg$, bc_all;
        channelmes("#world", .@msg$);

        //dispbottom l("You successfully set the exp rate to @@%. It will reset to @@% (default value) in @@.",
        //            .@new_rate, expRateReal(), FuzzyTime(time_from_hours(.max_hours), 2, 2));
        dispbottom l("You can also manually stop it at any time with: @exprate default");

    } else if (.@new_rate == 0 && .@special$ == "") {

        // get current exp rate
        if (.current_rate == $BCONFB_EXPR) {
            atcommand("@rates");
            dispbottom col(l("Usage of @exprate without argument is deprecated, please use \"@rates\" instead."), 1);
        } else {
            dispbottom l("Current exp rate is set to @@%, and will reset to @@% (default value) in @@.",
                        .current_rate, expRateReal(), remainingTime());

            dispbottom l("If you meant to reset the exp rate to its default value: @exprate default");
        }

    } else {

        // reset
        rateCleanUp;
        dispbottom l("Exp rate has been reset to @@% (default value).",
                    expRateReal());
    }

    end;

OnPlayerCall:
    /*
    // GM calls take precedence at any time!
    if (.max_hours > 0 || .hours > 0)
        end;
    */
    // $@EXP_EVENT will determine the boost and should not be above 25%
    // Default duration is one hour, or whatever $@EXP_EVENT_TIME is
    $@EXP_EVENT=limit(0, $@EXP_EVENT, 100);
    $@EXP_EVENT+=.current_rate;
    $@EXP_EVENT_TIME=limit(1, $@EXP_EVENT_TIME, 6);

    // If a GM rate-up was running, we will sum the time, too.
    // It'll be rounded down. (so 1h + 30m = 1h) FIXME average is better
    if (.hours || .max_hours) {
        $@EXP_EVENT_TIME+=max(0, .max_hours-.hours-1);
    }

    // Default duration is one hour, or whatever $@EXP_EVENT_TIME is
    .hours = 0;
    .max_hours = $@EXP_EVENT_TIME;
    .current_rate = $@EXP_EVENT;
    setbattleflag("base_exp_rate", expRecalc($@EXP_EVENT));
    setbattleflag("job_exp_rate", expRecalc($@EXP_EVENT));
    charcommand("@reloadmobdb");
    SeasonReload(1);
    initnpctimer; // start counting

    .@msg$="Experience Rate was modified to "+$@EXP_EVENT+"% for "+$@EXP_EVENT_TIME+" hour(s)!";

    announce .@msg$, bc_all;
    channelmes("#world", .@msg$);

    $@EXP_EVENT=0;
    $@EXP_EVENT_TIME=0;
    end;

OnTimer3600000:
    // runs every hour
    if (++.hours == .max_hours) {
        rateCleanUp;
        end;
    }
    initnpctimer;
    end;

OnPCLoginEvent:
    if (.max_hours > 0) {
        dispbottom col(l("Exp rate is set to @@% for the next @@.",
                        .current_rate, remainingTime()), 6);
    }
    end;

OnInit:
    bindatcmd "exprate", "@exprate::OnCall", 60, 80, 1; // change exp rate

    // WARNING: using @reloadscript will change the "original" value
    .current_rate = $BCONFB_EXPR;

    // XXX: maybe in the future:
    //.original_job_rate = getbattleflag("base_job_rate");
    //.original_pk_mode = getbattleflag("pk_mode");
    //.original_death_penalty = getbattleflag("death_penalty_type");
    end;

OnReload:
    if (debug) {
        debugmes("EXP Reload refused: Test server");
    }
    .@new_rate = expRecalc(.current_rate);
    setbattleflag("base_exp_rate", .@new_rate);
    setbattleflag("job_exp_rate", .@new_rate);
    //charcommand("@reloadmobdb");
    //SeasonReload(1); // TODO FIXME: We are casting this twice.
    end;

OnInheirtedReload:
    if (debug) {
        debugmes("Nested Reload refused: Test server");
    }
    debugmes "[EXP] Inheir Reload";
    .@new_rate = expRecalc(.current_rate);
    setbattleflag("base_exp_rate", .@new_rate);
    setbattleflag("job_exp_rate", .@new_rate);
    donpcevent("@droprate::OnReload");
    end;
}


/////////////////////////////////////////////////////////////////////////////////
-	script	@droprate	32767,{
    end;

    function dropRateReal {
        if (is_night())
            return $BCONFB_DROP+$BCONFN_DROP;
        else
            return $BCONFB_DROP+$BCONFD_DROP;
    }

    function dropRecalc {
        .@val=getarg(0);
        if (is_night())
            return .@val+$BCONFN_DROP;
        else
            return .@val+$BCONFD_DROP;
    }

    function rateCleanUp {
        stopnpctimer;
        .hours = 0;
        .max_hours = 0;
        .current_rate = $BCONFB_DROP;
        setbattleflag("item_rate_common", dropRateReal());
        setbattleflag("item_rate_common_boss", dropRateReal());
        setbattleflag("item_rate_heal", dropRateReal());
        setbattleflag("item_rate_heal_boss", dropRateReal());
        setbattleflag("item_rate_use", dropRateReal());
        setbattleflag("item_rate_use_boss", dropRateReal());
        setbattleflag("item_rate_equip", dropRateReal());
        setbattleflag("item_rate_equip_boss", dropRateReal());
        setbattleflag("item_rate_card", dropRateReal());
        setbattleflag("item_rate_card_boss", dropRateReal());
        charcommand("@reloadmobdb"); // this is on purpose (callable without RID) - no idea what is the purpose
        SeasonReload(1);
        channelmes("#world", "The Drop Rate Bonus is now over.");
    }

    function remainingTime {
        .@total_seconds = (3600 * .max_hours);
        .@seconds_elapsed = (3600 * .hours) + (getnpctimer(0) / 1000);
        .@seconds_remaining = max(1, .@total_seconds - .@seconds_elapsed);
        return FuzzyTime(time_from_seconds(.@seconds_remaining), 2, 2);
    }

OnCall:
   if (!is_gm()) {
        end;
    }

    .@special$ = strip(.@atcmd_parameters$[0]); // special value
    .@new_rate = min(atoi(.@special$), 1000); // or just a regular integer
    .@hours = min(0x7FFFFFFE, max(1, atoi(strip(.@atcmd_parameters$[1])))); // number of hours

    if (.@new_rate > 0)
    {
        // set new exp rate
        .hours = 0;
        .max_hours = .@hours;
        .current_rate = .@new_rate;
        setbattleflag("item_rate_common", dropRecalc(.@new_rate));
        setbattleflag("item_rate_common_boss", dropRecalc(.@new_rate));
        setbattleflag("item_rate_heal", dropRecalc(.@new_rate));
        setbattleflag("item_rate_heal_boss", dropRecalc(.@new_rate));
        setbattleflag("item_rate_use", dropRecalc(.@new_rate));
        setbattleflag("item_rate_use_boss", dropRecalc(.@new_rate));
        setbattleflag("item_rate_equip", dropRecalc(.@new_rate));
        setbattleflag("item_rate_equip_boss", dropRecalc(.@new_rate));
        setbattleflag("item_rate_card", dropRecalc(.@new_rate));
        setbattleflag("item_rate_card_boss", dropRecalc(.@new_rate));
        charcommand("@reloadmobdb");
        SeasonReload(1);
        initnpctimer; // start counting

        .@msg$=strcharinfo(0)+" modified drop rates to "+str(.@new_rate)+"%. It will only last "+str(FuzzyTime(time_from_hours(.max_hours), 2, 2))+"!";

        announce .@msg$, bc_all;
        channelmes("#world", .@msg$);

        //dispbottom l("You successfully set the drop rate to @@%. It will reset to @@% (default value) in @@.",
        //            .@new_rate, dropRateReal(), FuzzyTime(time_from_hours(.max_hours), 2, 2));
        dispbottom l("You can also manually stop it at any time with: @droprate default");
    } else if (.@new_rate == 0 && .@special$ == "") {
        // get current exp rate
        if (.current_rate == dropRateReal()) {
            atcommand("@rates");
            dispbottom col(l("Usage of @exprate without argument is deprecated, please use \"@rates\" instead."), 1);
        } else {
            dispbottom l("Current drop rate is set to @@%, and will reset to @@% (default value) in @@.",
                        .current_rate, dropRateReal(), remainingTime());
            dispbottom l("If you meant to reset the drop rate to its default value: @droprate default");
        }
    }

    else
    {
        // reset
        rateCleanUp;
        dispbottom l("Drop rate has been reset to @@% (default value).",
                    dropRateReal());
    }

    end;

OnTimer3600000:
    // runs every hour
    if (++.hours == .max_hours) {
        rateCleanUp;
        end;
    }
    initnpctimer;
    end;

OnPCLoginEvent:
    if (.max_hours > 0) {
        dispbottom col(l("Drop rate is set to @@% for the next @@.",
                        .current_rate, remainingTime()), 6);
    }
    end;

OnInit:
    bindatcmd "droprate", "@droprate::OnCall", 80, 80, 1; // change drop rate

    // WARNING: using @reloadscript will change the "original" value, use @reloadbattleconf before!
    .current_rate = $BCONFB_DROP;
    //force_refreshall();
    end;

OnReload:
    if (debug) {
        SeasonReload(1);
        debugmes("Drop Reload refused: Test server");
    }
    .@new_rate = dropRecalc(.current_rate);
    setbattleflag("item_rate_common", .@new_rate);
    setbattleflag("item_rate_common_boss", .@new_rate);
    setbattleflag("item_rate_heal", .@new_rate);
    setbattleflag("item_rate_heal_boss", .@new_rate);
    setbattleflag("item_rate_use", .@new_rate);
    setbattleflag("item_rate_use_boss", .@new_rate);
    setbattleflag("item_rate_equip", .@new_rate);
    setbattleflag("item_rate_equip_boss", .@new_rate);
    setbattleflag("item_rate_card", .@new_rate);
    setbattleflag("item_rate_card_boss", .@new_rate);
    charcommand("@reloadmobdb");
    SeasonReload(1);
    debugmes("Drop rates were reloaded with success.");
    end;
}