diff options
author | gumi <mekolat@users.noreply.github.com> | 2016-12-19 15:17:10 +0100 |
---|---|---|
committer | gumi <mekolat@users.noreply.github.com> | 2017-01-17 14:04:54 -0500 |
commit | 1dfe4d358d88e1cbe87c3b5ef7e4467023db0544 (patch) | |
tree | 6930643a61eb497919e3bd9cff00a200a67b8bd2 /npc/functions/fishing.txt | |
parent | 577f233b091ee0f1c82fe970ef38ed1cb4692664 (diff) | |
download | serverdata-1dfe4d358d88e1cbe87c3b5ef7e4467023db0544.tar.gz serverdata-1dfe4d358d88e1cbe87c3b5ef7e4467023db0544.tar.bz2 serverdata-1dfe4d358d88e1cbe87c3b5ef7e4467023db0544.tar.xz serverdata-1dfe4d358d88e1cbe87c3b5ef7e4467023db0544.zip |
Completely rewrite the fishing system
Diffstat (limited to 'npc/functions/fishing.txt')
-rw-r--r-- | npc/functions/fishing.txt | 317 |
1 files changed, 216 insertions, 101 deletions
diff --git a/npc/functions/fishing.txt b/npc/functions/fishing.txt index 2f019847..6fc4d76e 100644 --- a/npc/functions/fishing.txt +++ b/npc/functions/fishing.txt @@ -1,5 +1,6 @@ // Evol functions. // Authors: +// gumi // omatt // Travolta // Description: @@ -17,163 +18,277 @@ // 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 { +function script fishing_cleanup { + .@npc$ = getarg(0, ""); + if (.@npc$ == "") end; - if (getnpcdir(getarg(0)) != DOWN && @occupy == false) + set getvariableofnpc(.char_id, .@npc$), 0; // clean acc id + set getvariableofnpc(.account_id, .@npc$), 0; // clean char id + set getvariableofnpc(.last_used, .@npc$), gettimetick(2); // set last used time + setnpcdir .@npc$, DOWN; // reset direction + return; +} + +- script global fishing handler 32767,{ + end; + +OnBite: + if (getnpcdir(@fishing_spot$) != UP) + end; + + setnpcdir @fishing_spot$, LEFT; + @fishing_tick = gettimetick(0); + misceffect getvariableofnpc(.bite_fx, @fishing_spot$); + end; + +OnCleanUp: + dispbottom l("You waited too long and lost the bait..."); + specialeffect2 getvariableofnpc(.failure_fx, @fishing_spot$), SELF; // event fail +OnPCLogoutEvent: + fishing_cleanup @fishing_spot$; + @fishing_spot$ = ""; // unbind fishing npc + end; +} + +function script fishing { + +/////////////////////////////////////////// +// Var initialization + + .@npc$ = strnpcinfo(0); // the full name of the fishing spot + + .@account_id = getvariableofnpc(.account_id, .@npc$); // the account id of the player using the fishing spot + .@char_id = getvariableofnpc(.char_id, .@npc$); // the char id of the player using the fishing spot + .@dir = getnpcdir(.@npc$); // direction of the fishing spot + .@last_used = getvariableofnpc(.last_used, .@npc$); // when this fishing spot was last used + .@baits = getvariableofnpc(.baits, .@npc$); // bait count + + .@rod = getvariableofnpc(.fishing_rod, .@npc$); // the fishing rod required for this spot + .@rod = (.@rod ? .@rod : FishingRod); + + .@regen_time = getvariableofnpc(.cooldown, .@npc$); // cooldown for the fishing spot + .@regen_time = (.@regen_time ? .@regen_time : 20); + + .@success_fx = getvariableofnpc(.success_fx, .@npc$); // effect to show on success + .@success_fx = (.@success_fx ? .@success_fx : 27); + + .@failure_fx = getvariableofnpc(.failure_fx, .@npc$); // effect to show on failure + if (.@failure_fx < 1) { - npctalkonce l("This fishing spot is already being used!"); + .@failure_fx = 28; + set getvariableofnpc(.failure_fx, .@npc$), .@failure_fx; // needed by global handler + } + + .@initial_fx = getvariableofnpc(.initial_fx, .@npc$); // effect to show when throwing the bait + .@initial_fx = (.@initial_fx ? .@initial_fx : 29); - close; + .@bite_fx = getvariableofnpc(.bite_fx, .@npc$); // effect to show when something bites + if (.@bite_fx < 1) + { + .@bite_fx = 30; + set getvariableofnpc(.bite_fx, .@npc$), .@bite_fx; // needed by global handler } - // Skip the narator when we are in fishing - if (getnpcdir(getarg(0)) == DOWN) + .@wait_time_min = getvariableofnpc(.wait_time_min, .@npc$); // min amount of time to wait for the line to sink + .@wait_time_min = (.@wait_time_min ? .@wait_time_min : 4000); + + .@wait_time_max = getvariableofnpc(.wait_time_max, .@npc$); // max amount of time to wait for the line to sink + .@wait_time_max = (.@wait_time_max ? .@wait_time_max : 18000); + + .@catch_time = getvariableofnpc(.catch_time, .@npc$); // the player must catch the fish within X ms after the line sinks + .@catch_time = (.@catch_time ? .@catch_time : 5000); + + .@pull_rand_max = getvariableofnpc(.pull_rand_max, .@npc$); + .@pull_rand_max = (.@pull_rand_max ? .@pull_rand_max : 800); + + .@fish_id = getvariableofnpc(.common_fish, .@npc$); + .@fish_id = (.@fish_id ? .@fish_id : CommonCarp); + + .@rare_id = getvariableofnpc(.rare_fish, .@npc$); + .@rare_fish = (.@rare_fish ? .@rare_fish : GrassCarp); + + .@rare_fish_chance = getvariableofnpc(.rare_fish_chance, .@npc$); + .@rare_fish_chance = (.@rare_fish_chance ? .@rare_fish_chance : 25); + + if (getvariableofnpc(.bait_ids[0], .@npc$) < 1) { - narrator 4, l("You see some fish reflecting the sun on the surface of the water."); + // default baits (bait, chance booster) + setarray getvariableofnpc(.bait_ids[0], .@npc$), + SmallTentacles, 0, + Bread, 0, + Aquada, 1, + UrchinMeat, 0, + TortugaTongue, 2, + Tentacles, 0; } - return; -} -function script fishing { + if (.@baits < 1) + { + // only count it once + .@baits = getarraysize(getvariableofnpc(.bait_ids[0], .@npc$)); + set getvariableofnpc(.baits, .@npc$), .@baits; + } - .@wait_time_min = 4000; - .@wait_time_max = 18000; - .@pull_rand_max = 800; - .@fish_id = CommonCarp; - .@rare_fish_chance = 25; - - if (countitem(FishingRod) < 1) +/////////////////////////////////////////// +// Logic below + + if (countitem(.@rod) < 1) { - narrator - l("You don't have any @@.", getitemlink(FishingRod)); + dispbottom l("You don't have any @@.", getitemlink(.@rod)); return -1; } - switch (getnpcdir(getarg(0))) + if (.@account_id > 0 && !isloggedin(.@account_id, .@char_id)) { - case UP: - @occupy = false; - setnpcdir getarg(0), DOWN; + fishing_cleanup .@npc$; // reset + .@dir = DOWN; + } - deltimer getarg(0) + "::OnBiteBait"; - deltimer getarg(0) + "::OnRemoveBait"; - narrator l("You pulled too soon and lost the bait."); + if (.@char_id != getcharid(CHAR_ID_CHAR) && .@dir != DOWN) + { + dispbottom l("This fishing spot is already being used!"); + return -2; + } - close; - case LEFT: - @occupy = false; - deltimer getarg(0) + "::OnRemoveBait"; - setnpcdir getarg(0), DOWN; + // pull too soon + if (.@dir == UP) + { + deltimer "global fishing handler::OnCleanUp"; // cancel auto cleanup + deltimer "global fishing handler::OnBite"; + specialeffect2 .@failure_fx, SELF; // event fail + fishing_cleanup .@npc$; // do it manually instead + dispbottom l("You pulled too soon and lost the bait."); + return -3; + } - getmapxy (.@mapbis$, .@xbis, .@ybis, 0); + // pull maybe on time + else if (.@dir == LEFT) + { + deltimer "global fishing handler::OnCleanUp"; // cancel auto cleanup + fishing_cleanup .@npc$; // do it manually instead - // Leave spot, lost the bait - if (.@xbis != @x || .@ybis != @y || !compare (@map$, .@mapbis$)) - { - narrator l("You left your fishing spot!"); - close; - } + getmapxy .@mapbis$, .@xbis, .@ybis, UNITTYPE_PC; // get current char location - // RNG to obtain a rare fish - .@timediff = gettimetick(0) - @tick; - if (rand(.@rare_fish_chance) == 0) - { - .@fish_id = GrassCarp; - } + // Leave spot, lost the bait + if (.@mapbis$ != @fishing_loc$[0] || .@xbis != @fishing_loc[0] || .@ybis != @fishing_loc[1] || @fishing_spot$ != .@npc$) + { + dispbottom l("You left your fishing spot!"); + return -4; + } - // RNG to obtain a fish - if (rand(.@timediff) <= .@pull_rand_max) - { - narrator l("You caught a @@!", getitemname(.@fish_id)); + // RNG to obtain a rare fish + // TODO: chance booster + if (rand(.@rare_fish_chance) == 0) + { + // TODO: rare fish array + .@fish_id = .@rare_id; + } + // TODO: else common fish array - inventoryplace .@fish_id, 1; - getitem .@fish_id, 1; - } - else + // RNG to obtain a fish + if (rand(gettimetick(0) - @fishing_tick) <= .@pull_rand_max) + { + specialeffect2 .@success_fx, SELF; // event success + + if(!checkweight(.@fish_id, 1)) { - narrator l("You pulled too late and lost a @@...", getitemname(.@fish_id)); + dispbottom l("You caught a @@ but had no room in your inventory to carry it.", getitemlink(.@fish_id)); + makeitem .@fish_id, 1, .@mapbis$, .@xbis, .@ybis; // drop on the ground + return 0; } - close; + //dispbottom l("You caught a @@!", getitemlink(.@fish_id)); <= already shows "you picked up [...]" + getitem .@fish_id, 1; + } + else + { + dispbottom l("You pulled too late and lost the bait..."); + specialeffect2 .@failure_fx, SELF; // event fail + .@fish_id = 0; + } - default: - break; + return .@fish_id; } -OnChooseBait: - if (Fishing_Tick > gettimetick(2) - 20) + + + if (gettimetick(2) - .@last_used < .@regen_time) { - narrator l("This fishing spot has just been used, give it a rest."); - close; + dispbottom l("This fishing spot has just been used, give it a rest."); + return -5; } - setarray .@bait_ids[0], SmallTentacles, Bread, Aquada, - UrchinMeat, TortugaTongue, - Tentacles; + // begin fishing + narrator 4, + l("You see some fish reflecting the sun on the surface of the water."), + l("What will be the bait for the fish?"); - .@curr_wait_times = 0; - .@sel$ = ""; - .@cnt = 0; + mes "##B" + l("Drag and drop an item from your inventory.") + "##b"; - 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."); + .@bait = requestitem(); + .@bait_c = false; - if (!.@cnt) + if (.@bait < 1) { - .@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 1, + l("You take your fishing rod and leave."); + + return -6; } - narrator 2, - l("What will be the bait for the fish?"); - .@idx = select(.@sel$); + if (countitem(.@bait) < 1) + { + return -6; + } + + for (.@i = 0; .@i < .@baits; .@i += 2) + { + if (getvariableofnpc(.bait_ids[.@i], .@npc$) == .@bait) + { + .@bait_c = true; + break; + } + } - if (.@idx == .@cnt + 1) + if (.@bait_c != true) { narrator 1, - l("You take your fishing rod and leave."); - return 0; + l("This item cannot be used as bait here."); + + return -6; } - if (@occupy == true) + if (getvariableofnpc(.char_id, .@npc$) > 0) { narrator 1, l("Somebody took your place on this spot!"), l("You take your fishing rod and leave."); - return 0; + return -8; } - @occupy = true; + + @fishing_spot$ = .@npc$; // bind player to fishing spot + set getvariableofnpc(.account_id, .@npc$), getcharid(CHAR_ID_ACCOUNT); // record account id + set getvariableofnpc(.char_id, .@npc$), getcharid(CHAR_ID_CHAR); // record char id + set getvariableofnpc(.last_used, .@npc$), gettimetick(2); + getmapxy (@fishing_loc$[0], @fishing_loc[0], @fishing_loc[1], 0); // record char pos + delitem .@bait, 1; // 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; + misceffect .@initial_fx; // throw the bait + sleep2 800; // wait 0.8s for synchronize the sound of "plop" in water with the npc dir UP. + setnpcdir .@npc$, UP; - npctalk3 l("Wait for the bait to sink underwater."); - getmapxy (@map$, @x, @y, 0); + dispbottom l("Wait for the bait to sink underwater."); .@delay = rand(.@wait_time_min, .@wait_time_max); - addtimer .@delay, getarg(0) + "::OnBiteBait"; - addtimer (.@delay + 5000), getarg(0) + "::OnRemoveBait"; + addtimer .@delay, "global fishing handler::OnBite"; // bite logic + addtimer (.@delay + .@catch_time), "global fishing handler::OnCleanUp"; // auto clean up - close; + return 0; } |