summaryrefslogblamecommitdiff
path: root/npc/functions/fishing.txt
blob: 2f019847ee4a1a1663f2a9c7a82ce1fdd307dea7 (plain) (tree)
1
2
3
4
5
6

                  
           


                        






                                                        


                                                                                         
                          
                                                                                                       





                                                                  
 

              
 




                                                                                           
 

           

                                 

                            
                          



                            


                                  
                                                                 

                  
 
                                 
     




                                                
                                                  




                                                                 

                                                  

                                      
                                                    

                                        

                                                                            
                                                          

                      

                                        
                                                
                                              
             
                                      
             
 

                                                    
             
                                                                       
 

                                            


                
                                                                                           
             




                  

     
             

                                           
                                                                            

              



                                                          
 
 
                          

















                                                                                
                                                         
                                                                  


                      
               




                                                 

                                                      


                 








                                                        
                                                                                        



                            
                                  


                                     
                                                        
                                
 
                                                     
 
                                                 
                                                            
 
          
 
// Evol functions.
// Authors:
//    omatt
//    Travolta
// Description:
//    Fishing functions.
// Variable
//    .dir
//         DOWN    Never try or pulled too late
//         UP      Bait dropped
//         LEFT    Fish bite bait
//
// player log on .dir is DOWN, start by choose bait menu
// player chooses bait, script addtimer in npc .dir is UP
// if player pulls before signal npc, bait is lost, set .bait to DOWN goto choose bait
// if player pulls after pull delay max, bait is lost, set .bait to DOWN goto choose bait
// npc signal .dir is LEFT
// player pulls between npc signal and pulls delay max, got the fish, set .dir to DOWN goto choose bait

function	script	fishingspot	{

    if (getnpcdir(getarg(0)) != DOWN && @occupy == false)
    {
        npctalkonce l("This fishing spot is already being used!");

        close;
    }

    // Skip the narator when we are in fishing
    if (getnpcdir(getarg(0)) == DOWN)
    {
        narrator 4, l("You see some fish reflecting the sun on the surface of the water.");
    }

    return;
}
function	script	fishing	{

    .@wait_time_min = 4000;
    .@wait_time_max = 18000;
    .@pull_rand_max = 800;
    .@fish_id = CommonCarp;
    .@rare_fish_chance = 25;

    
    if (countitem(FishingRod) < 1)
    {
        narrator
            l("You don't have any @@.", getitemlink(FishingRod));
        return -1;
    }

    switch (getnpcdir(getarg(0)))
    {
        case UP:
            @occupy = false;
            setnpcdir getarg(0), DOWN;

            deltimer getarg(0) + "::OnBiteBait";
            deltimer getarg(0) + "::OnRemoveBait";
            narrator l("You pulled too soon and lost the bait.");

            close;
        case LEFT:
            @occupy = false;
            deltimer getarg(0) + "::OnRemoveBait";

            setnpcdir getarg(0), DOWN;

            getmapxy (.@mapbis$, .@xbis, .@ybis, 0);

            // Leave spot, lost the bait
            if (.@xbis != @x || .@ybis != @y || !compare (@map$, .@mapbis$))
            {
                narrator l("You left your fishing spot!");
                close;
            }

            // RNG to obtain a rare fish
            .@timediff = gettimetick(0) - @tick;
            if (rand(.@rare_fish_chance) == 0)
            {
                .@fish_id = GrassCarp;
            }

            // RNG to obtain a fish
            if (rand(.@timediff) <= .@pull_rand_max)
            {
                narrator l("You caught a @@!", getitemname(.@fish_id));

                inventoryplace .@fish_id, 1;
                getitem .@fish_id, 1;
            }
            else
            {
                narrator l("You pulled too late and lost a @@...", getitemname(.@fish_id));
            }

            close;

        default:
            break;
    }

OnChooseBait:
    if (Fishing_Tick > gettimetick(2) - 20)
    {
        narrator l("This fishing spot has just been used, give it a rest.");
        close;
    }

    setarray .@bait_ids[0], SmallTentacles, Bread, Aquada,
                            UrchinMeat, TortugaTongue,
                            Tentacles;


    .@curr_wait_times = 0;
    .@sel$ = "";
    .@cnt = 0;

    for (.@i = 0; .@i < getarraysize(.@bait_ids); .@i++)
        if (countitem(.@bait_ids[.@i]) > 0)
        {
            setarray .@user_items[.@cnt], .@bait_ids[.@i];
            .@sel$ = .@sel$ + getitemname(.@bait_ids[.@i]) + ":";
            .@cnt += 1;
        }
    .@sel$ = .@sel$ + l("Nothing, I changed my mind.");

    if (!.@cnt)
    {
        .@bait_names$ = getitemlink(.@bait_ids[0]);
        for (.@i = 1; .@i < getarraysize(.@bait_ids); .@i++)
            .@bait_names$ = .@bait_names$ + ", " + getitemlink(.@bait_ids[.@i]);
        narrator
            l("You don't have any food to use as bait."),
            l("You need at least one of these: ") + .@bait_names$;
            return -2;
    }

    narrator 2,
        l("What will be the bait for the fish?");
    .@idx = select(.@sel$);

    if (.@idx == .@cnt + 1)
    {
        narrator 1,
            l("You take your fishing rod and leave.");
        return 0;
    }

    if (@occupy == true)
    {
        narrator 1,
            l("Somebody took your place on this spot!"),
            l("You take your fishing rod and leave.");
        return 0;
    }
    @occupy = true;

    // The player uses this spot, his bait is ready, he just has to wait for the signal.
    closedialog;

    setnpcdir getarg(0), UP;

    Fishing_Tick = gettimetick(2);
    .@bait = .@user_items[.@idx - 1];
    delitem .@bait, 1;

    npctalk3 l("Wait for the bait to sink underwater.");
    getmapxy (@map$, @x, @y, 0);

    .@delay = rand(.@wait_time_min, .@wait_time_max);

    addtimer .@delay, getarg(0) + "::OnBiteBait";
    addtimer (.@delay + 5000), getarg(0) + "::OnRemoveBait";

    close;
}