From 0c20c596e0d11ee39d2e380499626aa41e857ad9 Mon Sep 17 00:00:00 2001 From: aleos Date: Sat, 11 Feb 2017 20:55:35 -0500 Subject: [PATCH] Expanded script command setbattleflag * Fixes #1945. * Adds an optional flag to reload the monster database for specific map flags that are EXP/drop related. * This resolves having to add atcommand reloadmobdb after setting the battle configs. * Adjusted atcommand setbattleflag to also have the optional parameter. * The reload should only have to be called on the final setbattleflag use. --- conf/msg_conf/map_msg.conf | 2 +- doc/atcommands.txt | 4 +++- doc/script_commands.txt | 10 ++++++-- npc/custom/etc/floating_rates.txt | 3 +-- src/map/atcommand.c | 8 +++++-- src/map/script.c | 39 +++++++++++++++++++++++++++---- 6 files changed, 54 insertions(+), 12 deletions(-) diff --git a/conf/msg_conf/map_msg.conf b/conf/msg_conf/map_msg.conf index 2fd50ed132..db72866f22 100644 --- a/conf/msg_conf/map_msg.conf +++ b/conf/msg_conf/map_msg.conf @@ -1238,7 +1238,7 @@ 1230: Please enter a player name (usage: @trade ). // @setbattleflag -1231: Usage: @setbattleflag +1231: Usage: @setbattleflag {} 1232: Unknown battle_config flag. 1233: Set battle_config as requested. diff --git a/doc/atcommands.txt b/doc/atcommands.txt index 6f69519cc6..e7b9e488f7 100644 --- a/doc/atcommands.txt +++ b/doc/atcommands.txt @@ -1374,9 +1374,11 @@ Note that the value of a string variable may be typed with or without double quo --------------------------------------- -@setbattleflag +@setbattleflag {} Changes a battle_config flag without rebooting the server. +If a value is given for reload, then the server will attempt to reload the mob database +if the config being changed is EXP/drop related. --------------------------------------- diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 01cc2df98c..5db29c74fd 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -6715,16 +6715,22 @@ The optional parameter 'type' is used in the 'skill_damage' mapflag: --------------------------------------- -*setbattleflag "",; +*setbattleflag "",{,}; *getbattleflag("") Sets or gets the value of the given battle flag. Battle flags are the flags found in the battle / *.conf files and is also used in Lupus' variable rates script. +If the reload value is given then the server will attempt to reload monster data +to properly apply the new rates. This applies to EXP/Drop type configs. The server +will only attempt to reload specific configs. Examples: -// Will set the base experience rate to 20x (2000%) +// Will set the base experience rate to 20x (2000%) - Monster data will continue to use previous rates at server start setBattleFlag "base_exp_rate",2000; + +// Will set the base experience rate to 20x (2000%) - Monster data will be reloaded to new value + setBattleFlag "base_exp_rate",2000,true; // Will return the value of the base experience rate (when used after the above example, it would print 2000). mes getBattleFlag("base_exp_rate"); diff --git a/npc/custom/etc/floating_rates.txt b/npc/custom/etc/floating_rates.txt index 96aec24f88..95ecd00259 100644 --- a/npc/custom/etc/floating_rates.txt +++ b/npc/custom/etc/floating_rates.txt @@ -34,9 +34,8 @@ OnHour18: setbattleflag("item_rate_common",$@drate); setbattleflag("item_rate_heal",$@drate); setbattleflag("item_rate_use",$@drate); - setbattleflag("item_rate_equip",$@drate); + setbattleflag("item_rate_equip",$@drate,true); // Apply new rates to configs set above //we don't change card drops rate, because these values won't change them anyway - atcommand "@reloadmobdb"; announce "Current Rune-Midgard rates are: 1."+($@brate-100)+"x 1."+($@jrate-100)+"x 1."+($@drate-100)+"x",bc_all,0xFF6060; end; diff --git a/src/map/atcommand.c b/src/map/atcommand.c index f87671b442..7406fb1b56 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -6865,10 +6865,11 @@ ACMD_FUNC(trade) ACMD_FUNC(setbattleflag) { char flag[128], value[128]; + int reload = 0; nullpo_retr(-1, sd); - if (!message || !*message || sscanf(message, "%127s %127s", flag, value) != 2) { - clif_displaymessage(fd, msg_txt(sd,1231)); // Usage: @setbattleflag + if (!message || !*message || sscanf(message, "%127s %127s %11d", flag, value, &reload) != 2) { + clif_displaymessage(fd, msg_txt(sd,1231)); // Usage: @setbattleflag {} return -1; } @@ -6880,6 +6881,9 @@ ACMD_FUNC(setbattleflag) clif_displaymessage(fd, msg_txt(sd,1233)); // Set battle_config as requested. + if (reload) + mob_reload(); + return 0; } diff --git a/src/map/script.c b/src/map/script.c index b017e0a5db..71180aa51c 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -15117,6 +15117,10 @@ BUILDIN_FUNC(autoequip) return SCRIPT_CMD_SUCCESS; } +/** + * Set the value of a given battle config + * setbattleflag "",{,}; + */ BUILDIN_FUNC(setbattleflag) { const char *flag, *value; @@ -15126,16 +15130,43 @@ BUILDIN_FUNC(setbattleflag) if (battle_set_value(flag, value) == 0) ShowWarning("buildin_setbattleflag: unknown battle_config flag '%s'\n",flag); - else + else { ShowInfo("buildin_setbattleflag: battle_config flag '%s' is now set to '%s'.\n",flag,value); + if (script_hasdata(st, 4) && script_getnum(st, 4)) { // Only attempt to reload monster data if told to + const char *expdrop_flags[] = { // Only certain flags require a reload, check for those types + "base_exp_rate", "job_exp_rate", "mvp_exp_rate", "quest_exp_rate", "heal_exp", "resurrection_exp", + "item_rate_common", "item_rate_common_boss", "item_rate_common_mvp", "item_drop_common_min", "item_drop_common_max", + "item_rate_heal", "item_rate_heal_boss", "item_rate_heal_mvp", "item_rate_heal_min", "item_rate_heal_max", + "item_rate_use", "item_rate_use_boss", "item_rate_use_mvp", "item_rate_use_min", "item_rate_use_max", + "item_rate_equip", "item_rate_equip_boss", "item_rate_equip_mvp", "item_rate_equip_min", "item_rate_equip_max", + "item_rate_card", "item_rate_card_boss", "item_rate_card_mvp", "item_rate_card_min", "item_rate_card_max", + "item_rate_mvp", "item_rate_mvp_min", "item_rate_mvp_max", "item_rate_mvp_mode", + "item_rate_treasure", "item_rate_treasure_min", "item_rate_treasure_max", + "item_logarithmic_drops", "drop_rate0item", "drop_rateincrease", + }; + uint8 i; + + for (i = 0; i < ARRAYLENGTH(expdrop_flags); i++) { + if (!strcmpi(flag, expdrop_flags[i])) { + mob_reload(); + break; + } + } + } + } + return SCRIPT_CMD_SUCCESS; } +/** + * Get the value of a given battle config + * getbattleflag("") + */ BUILDIN_FUNC(getbattleflag) { - const char *flag; - flag = script_getstr(st,2); + const char *flag = script_getstr(st,2); + script_pushint(st,battle_get_value(flag)); return SCRIPT_CMD_SUCCESS; } @@ -22551,7 +22582,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(npcshopattach,"s?"), BUILDIN_DEF(equip,"i?"), BUILDIN_DEF(autoequip,"ii"), - BUILDIN_DEF(setbattleflag,"si"), + BUILDIN_DEF(setbattleflag,"si?"), BUILDIN_DEF(getbattleflag,"s"), BUILDIN_DEF(setitemscript,"is?"), //Set NEW item bonus script. Lupus BUILDIN_DEF(disguise,"i?"), //disguise player. Lupus