From 021bed5f5de02a9262831ebcb968a627f2ddba26 Mon Sep 17 00:00:00 2001 From: Jittapan Pluemsumran Date: Sun, 21 Aug 2016 14:30:17 +0700 Subject: [PATCH 1/3] Implemented status reduction potion support * New script command `needed_status_point` added. * The items are not yet implemented. --- doc/script_commands.txt | 8 ++++++++ npc/other/CashShop_Functions.txt | 20 ++++++++++++++++++++ src/map/script.c | 17 +++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 336c1a1ea0..6d3d68eb51 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -4294,6 +4294,14 @@ This command will force a stat recalculation for the attached player. --------------------------------------- +*needed_status_point(,{,}); + +Returns the number of stat points needed to change the specified stat by . +If is negative, returns the number of stat points that would be needed to +raise the specified stat from (current value - ) to current value. + +--------------------------------------- + *get_revision() This command will return the SVN revision number that the server is currently diff --git a/npc/other/CashShop_Functions.txt b/npc/other/CashShop_Functions.txt index e1640ec1b3..2c0fa037a2 100644 --- a/npc/other/CashShop_Functions.txt +++ b/npc/other/CashShop_Functions.txt @@ -304,3 +304,23 @@ function script F_Snowball { } end; } + +// Status reduction potion +//============================================================ +// - Permanently reduces base stat by 1. +// - Returns status points equals to points needed to raise +// that stat to original value. +// - Doesn't work if base status is already 1. +// * callfunc("F_CashReduceStat",{,}); +function script F_CashReduceStat { + .@type = getarg(0); + .@itemid = getarg(1, 0); + + if(readparam(.@type) < 2) return; + + if(.@itemid) + delitem .@itemid,1; + StatusPoint += needed_status_point(.@type, -1); + statusup2 .@type,-1; + return; +} diff --git a/src/map/script.c b/src/map/script.c index eed2047318..6f1e0d0e31 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -21661,6 +21661,22 @@ BUILDIN_FUNC(setrandomoption) { return SCRIPT_CMD_FAILURE; } +/// Returns the number of stat points needed to change the specified stat by val. +/// If val is negative, returns the number of stat points that would be needed to +/// raise the specified stat from (current value - val) to current value. +/// *needed_status_point(,{,}); +/// @author [secretdataz] +BUILDIN_FUNC(needed_status_point) { + struct map_session_data *sd; + int type, val; + if (!script_charid2sd(4, sd)) + return SCRIPT_CMD_FAILURE; + type = script_getnum(st, 2); + val = script_getnum(st, 3); + + script_pushint(st, pc_need_status_point(sd, type, val)); + return SCRIPT_CMD_SUCCESS; +} #include "../custom/script.inc" // declarations that were supposed to be exported from npc_chat.c @@ -22243,6 +22259,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(getrandomoptinfo, "i"), BUILDIN_DEF(getequiprandomoption, "iii?"), BUILDIN_DEF(setrandomoption,"iiiii?"), + BUILDIN_DEF(needed_status_point,"ii?"), #include "../custom/script_def.inc" From 472b885ca83627922d2c2208b46ff6d9b8308a7d Mon Sep 17 00:00:00 2001 From: Jittapan Pluemsumran Date: Sun, 21 Aug 2016 18:06:26 +0700 Subject: [PATCH 2/3] Follow up to 021bed5f5de02a9262831ebcb968a627f2ddba26 --- npc/other/CashShop_Functions.txt | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/npc/other/CashShop_Functions.txt b/npc/other/CashShop_Functions.txt index 2c0fa037a2..2ede408917 100644 --- a/npc/other/CashShop_Functions.txt +++ b/npc/other/CashShop_Functions.txt @@ -307,20 +307,24 @@ function script F_Snowball { // Status reduction potion //============================================================ -// - Permanently reduces base stat by 1. +// - Permanently reduces base stat by . // - Returns status points equals to points needed to raise // that stat to original value. -// - Doesn't work if base status is already 1. -// * callfunc("F_CashReduceStat",{,}); +// - Doesn't work if base status would become lower than 1 after reduction. +// * callfunc("F_CashReduceStat",{,,}); function script F_CashReduceStat { .@type = getarg(0); - .@itemid = getarg(1, 0); + .@amount = getarg(1, -1); + .@itemid = getarg(2, 0); - if(readparam(.@type) < 2) return; + if((readparam(.@type) + .@amount) < 1) return; if(.@itemid) - delitem .@itemid,1; - StatusPoint += needed_status_point(.@type, -1); - statusup2 .@type,-1; + if(countitem(.@itemid)) + delitem .@itemid,1; + else + return; + StatusPoint += needed_status_point(.@type, .@amount); + statusup2 .@type,.@amount; return; } From eb8ea91f5b62181b2108d7727ce2635dc19208ef Mon Sep 17 00:00:00 2001 From: Jittapan Pluemsumran Date: Mon, 22 Aug 2016 22:44:13 +0700 Subject: [PATCH 3/3] Follow up to 472b885ca83627922d2c2208b46ff6d9b8308a7d * Added brackets after if --- npc/other/CashShop_Functions.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/npc/other/CashShop_Functions.txt b/npc/other/CashShop_Functions.txt index 2ede408917..c8ce283ae1 100644 --- a/npc/other/CashShop_Functions.txt +++ b/npc/other/CashShop_Functions.txt @@ -319,11 +319,12 @@ function script F_CashReduceStat { if((readparam(.@type) + .@amount) < 1) return; - if(.@itemid) + if(.@itemid) { if(countitem(.@itemid)) delitem .@itemid,1; else return; + } StatusPoint += needed_status_point(.@type, .@amount); statusup2 .@type,.@amount; return;