Skip to content

Commit

Permalink
Further cleanup to mapflags (#3332)
Browse files Browse the repository at this point in the history
* Follow up to a942853.
* Removed ADJUST_SKILL_DAMAGE define so that the mapflag is always enabled.
* Cleaned up atcommand mapinfo and skill_damage mapflag interaction.
* Cleaned up atcommand mapflag to not allow setting of special mapflags that require extra arguments (Please use script command setmapflag).
* Using script command setmapflag for MF_NOSAVE will default to SavePoint.
* Using script command setmapflag for MF_PVP_NIGHTMAREDROP will default to normal official drop values.
* Exported constants for skill_damage mapflag types.
Thanks to @ecdarreola, @cydh, and @Lemongrass3110!
  • Loading branch information
aleos89 committed Jul 23, 2018
1 parent 1d88575 commit 9313922
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 121 deletions.
4 changes: 0 additions & 4 deletions doc/mapflags.txt
Expand Up @@ -319,10 +319,6 @@ This mapflag can also be used to adjust the damage of one skill by a percentage:
SKILLDMG_BOSS = against boss monster
SKILLDMG_OTHER = against other (homunculus, mercenary, pet, elemental)

Notes:
- You MUST enable ADJUST_SKILL_DAMAGE in 'src/config/core.hpp' for this mapflag to take effect.
- Each map can contain up to UINT16_MAX adjustments.

---------------------------------------

==================
Expand Down
23 changes: 15 additions & 8 deletions doc/script_commands.txt
Expand Up @@ -7001,7 +7001,7 @@ specified.
*setmapflag "<map name>",<flag>{,<zone>{,<type>}};

This command marks a specified map with the given map flag, which will alter the
behavior of the map. A full list of mapflags is located in 'src/map/script_constants.h' with
behavior of the map. A full list of mapflags is located in 'src/map/script_constants.hpp' with
the 'mf_' prefix, and documentation can be found in 'doc/mapflags.txt'.

The map flags alter the behavior of the map regarding teleporting (mf_nomemo,
Expand All @@ -7013,7 +7013,14 @@ skills or open up trade deals (mf_notrade, mf_novending, mf_noskill, mf_noicewal
current weather effects (mf_snow, mf_fog, mf_sakura, mf_leaves, mf_rain, mf_clouds,
mf_fireworks) and whether night will be in effect on this map (mf_nightenabled).

The optional parameter 'zone' is used to set the zone for restricted mapflags.
The optional parameter <zone> is used to set the zone for 'restricted' mapflags,
GM level bypass for 'nocommand', base/job experience for 'bexp'/'jexp', and
flag for 'battleground'.

For 'skill_damage' mapflag:
- Setting the flag here will adjust the global (all skills) damage on the map.
- <zone> is the -100 to 100000 damage adjustment value of the skills.
- See 'getmapflag' for the different <type> values.

---------------------------------------

Expand All @@ -7032,12 +7039,12 @@ This command checks the status of a given mapflag and returns the mapflag's stat
0 means OFF, and 1 means ON. See 'setmapflag' for a list of mapflags.

The optional parameter 'type' is used in the 'skill_damage' mapflag:
0: if mapflag is set (default)
1: damage against players
2: damage against mobs
3: damage against bosses
4: damage against other
5: caster type
SKILLDMG_MAX: if mapflag is set (default)
SKILLDMG_PC: damage against players
SKILLDMG_MOB: damage against mobs
SKILLDMG_BOSS: damage against bosses
SKILLDMG_OTHER: damage against other
SKILLDMG_CASTER: caster type

---------------------------------------

Expand Down
3 changes: 0 additions & 3 deletions npc/mapflag/skill_damage.txt
Expand Up @@ -11,9 +11,6 @@
//= skill_damage_db.txt for 'Map' type 16 will be applied.
//= See the mapflag documentation for details about extra
//= parameters.
//=
//= You MUST enable ADJUST_SKILL_DAMAGE in 'src/config/core.hpp'
//= for this mapflag to take effect.
//===== Additional Comments: =================================
//= 1.0 Initial script. [Cydh]
//============================================================
Expand Down
5 changes: 0 additions & 5 deletions src/config/core.hpp
Expand Up @@ -43,11 +43,6 @@
/// Uncomment to enable real-time server stats (in and out data and ram usage).
//#define SHOW_SERVER_STATS

/// Uncomment to enable skills damage adjustments
/// By enabling this, db/skill_damage_db.txt and the skill_damage mapflag will adjust the
/// damage rate of specified skills.
//#define ADJUST_SKILL_DAMAGE

/// Uncomment to enable the job base HP/SP table (job_basehpsp_db.txt)
#define HP_SP_TABLES

Expand Down
56 changes: 35 additions & 21 deletions src/map/atcommand.cpp
Expand Up @@ -4054,15 +4054,17 @@ ACMD_FUNC(mapinfo) {
}

/* Skill damage adjustment info [Cydh] */
#ifdef ADJUST_SKILL_DAMAGE
if (map_getmapflag(m_id, MF_SKILL_DAMAGE)) {
union u_mapflag_args args = {};

args.flag_val = SKILLDMG_MAX; // Check if it's enabled first
if (map_getmapflag_sub(m_id, MF_SKILL_DAMAGE, &args)) {
clif_displaymessage(fd,msg_txt(sd,1052)); // Skill Damage Adjustments:
sprintf(atcmd_output," > [Map] %d%%, %d%%, %d%%, %d%% | Caster:%d"
,map[m_id].damage_adjust.rate[SKILLDMG_PC]
,map[m_id].damage_adjust.rate[SKILLDMG_MOB]
,map[m_id].damage_adjust.rate[SKILLDMG_BOSS]
,map[m_id].damage_adjust.rate[SKILLDMG_OTHER]
,map[m_id].damage_adjust.caster);
,(args.flag_val = SKILLDMG_PC && map_getmapflag_sub(m_id, MF_SKILL_DAMAGE, &args))
,(args.flag_val = SKILLDMG_MOB && map_getmapflag_sub(m_id, MF_SKILL_DAMAGE, &args))
,(args.flag_val = SKILLDMG_BOSS && map_getmapflag_sub(m_id, MF_SKILL_DAMAGE, &args))
,(args.flag_val = SKILLDMG_OTHER && map_getmapflag_sub(m_id, MF_SKILL_DAMAGE, &args))
,(args.flag_val = SKILLDMG_CASTER && map_getmapflag_sub(m_id, MF_SKILL_DAMAGE, &args)));
clif_displaymessage(fd, atcmd_output);
if (map[m_id].skill_damage.size()) {
clif_displaymessage(fd," > [Map Skill] Name : Player, Monster, Boss Monster, Other | Caster");
Expand All @@ -4079,7 +4081,6 @@ ACMD_FUNC(mapinfo) {
}
}
}
#endif

strcpy(atcmd_output,msg_txt(sd,1046)); // PvP Flags:
if (map_getmapflag(m_id, MF_PVP))
Expand Down Expand Up @@ -8147,7 +8148,7 @@ ACMD_FUNC(fakename)
ACMD_FUNC(mapflag) {
char flag_name[CHAT_SIZE_MAX];
short flag = 0, i, j;
StringBuf buf;
std::string buf;

nullpo_retr(-1, sd);

Expand All @@ -8157,7 +8158,9 @@ ACMD_FUNC(mapflag) {
clif_displaymessage(sd->fd,msg_txt(sd,1311)); // Enabled Mapflags in this map:
clif_displaymessage(sd->fd,"----------------------------------");
for( i = MF_MIN; i < MF_MAX; i++ ){
if( map_getmapflag_name(static_cast<e_mapflag>(i), flag_name) && map_getmapflag( sd->bl.m, static_cast<e_mapflag>(i) ) ){
union u_mapflag_args args = {};

if( map_getmapflag_name(static_cast<e_mapflag>(i), flag_name) && map_getmapflag_sub( sd->bl.m, static_cast<e_mapflag>(i), &args ) ){
clif_displaymessage(sd->fd, flag_name);
}
}
Expand All @@ -8175,9 +8178,23 @@ ACMD_FUNC(mapflag) {
enum e_mapflag mapflag = map_getmapflag_by_name(flag_name);

if( mapflag != MF_INVALID ){
map_setmapflag(sd->bl.m, static_cast<e_mapflag>(mapflag), flag != 0);
sprintf(atcmd_output,"[ @mapflag ] %s flag has been set to %s value = %hd",flag_name,flag?"On":"Off",flag);
clif_displaymessage(sd->fd,atcmd_output);
std::vector<e_mapflag> disabled_mf = { MF_NOSAVE,
MF_PVP_NIGHTMAREDROP,
MF_RESTRICTED,
MF_NOCOMMAND,
MF_BEXP,
MF_JEXP,
MF_BATTLEGROUND,
MF_SKILL_DAMAGE };

if (flag && std::find(disabled_mf.begin(), disabled_mf.end(), mapflag) != disabled_mf.end()) {
sprintf(atcmd_output,"[ @mapflag ] %s flag cannot be enabled as it requires unique values.", flag_name);
clif_displaymessage(sd->fd,atcmd_output);
} else {
map_setmapflag(sd->bl.m, mapflag, flag != 0);
sprintf(atcmd_output,"[ @mapflag ] %s flag has been set to %s value = %hd",flag_name,flag?"On":"Off",flag);
clif_displaymessage(sd->fd,atcmd_output);
}
return 0;
}else{
clif_displaymessage(sd->fd, msg_txt(sd, 1314)); // Invalid flag name or flag.
Expand All @@ -8188,25 +8205,22 @@ ACMD_FUNC(mapflag) {

clif_displaymessage(sd->fd,msg_txt(sd,1315)); // Available Flags:
clif_displaymessage(sd->fd,"----------------------------------");
StringBuf_Init(&buf);
for( i = MF_MIN, j = 0; i < MF_MAX; i++ ){
if( map_getmapflag_name( static_cast<e_mapflag>(i), flag_name ) ){
StringBuf_AppendStr( &buf, flag_name );
buf.append(flag_name);

if( (i + 1) < MF_MAX ){
StringBuf_AppendStr( &buf, ", " );
}
if( (i + 1) < MF_MAX )
buf.append(", ");

j++;
}

if( i > MF_MIN && ( j == 6 || ( i + 1 ) == MF_MAX ) ){
clif_displaymessage(sd->fd, StringBuf_Value(&buf) );
StringBuf_Clear(&buf);
clif_displaymessage(sd->fd, buf.c_str() );
buf.clear();
j = 0;
}
}
StringBuf_Destroy(&buf);
clif_displaymessage(sd->fd, msg_txt(sd, 1312)); // Usage: "@mapflag monster_noteleport 1" (0=Off | 1=On)

return 0;
Expand Down
28 changes: 9 additions & 19 deletions src/map/battle.cpp
Expand Up @@ -2156,7 +2156,6 @@ static int battle_blewcount_bonus(struct map_session_data *sd, uint16 skill_id)
return 0;
}

#ifdef ADJUST_SKILL_DAMAGE
static enum e_skill_damage_type battle_skill_damage_type( struct block_list* bl ){
switch( bl->type ){
case BL_PC:
Expand Down Expand Up @@ -2192,11 +2191,14 @@ static int battle_skill_damage_skill(struct block_list *src, struct block_list *
if (!(damage->caster&src->type))
return 0;

if ((damage->map&1 && (!map_getmapflag(m, MF_PVP) && !map_flag_gvg2(m) && !map_getmapflag(m, MF_BATTLEGROUND) && !map_getmapflag(m, MF_SKILL_DAMAGE) && !map_getmapflag(m, MF_RESTRICTED))) ||
union u_mapflag_args args = {};

args.flag_val = SKILLDMG_MAX; // Check if it's enabled first
if ((damage->map&1 && (!map_getmapflag(m, MF_PVP) && !map_flag_gvg2(m) && !map_getmapflag(m, MF_BATTLEGROUND) && !map_getmapflag_sub(m, MF_SKILL_DAMAGE, &args) && !map_getmapflag(m, MF_RESTRICTED))) ||
(damage->map&2 && map_getmapflag(m, MF_PVP)) ||
(damage->map&4 && map_flag_gvg2(m)) ||
(damage->map&8 && map_getmapflag(m, MF_BATTLEGROUND)) ||
(damage->map&16 && map_getmapflag(m, MF_SKILL_DAMAGE)) ||
(damage->map&16 && map_getmapflag_sub(m, MF_SKILL_DAMAGE, &args)) ||
(map_getmapflag(m, MF_RESTRICTED) && damage->map&(8*map[m].zone)))
{
return damage->rate[battle_skill_damage_type(target)];
Expand All @@ -2215,8 +2217,10 @@ static int battle_skill_damage_skill(struct block_list *src, struct block_list *
static int battle_skill_damage_map(struct block_list *src, struct block_list *target, uint16 skill_id) {
int rate = 0;
struct map_data *mapd = &map[src->m];
union u_mapflag_args args = {};

if (!mapd || !map_getmapflag(src->m, MF_SKILL_DAMAGE))
args.flag_val = SKILLDMG_MAX; // Check if it's enabled first
if (!mapd || !map_getmapflag_sub(src->m, MF_SKILL_DAMAGE, &args))
return 0;

// Damage rate for all skills at this map
Expand Down Expand Up @@ -2248,7 +2252,6 @@ static int battle_skill_damage(struct block_list *src, struct block_list *target
skill_id = skill_dummy2skill_id(skill_id);
return battle_skill_damage_skill(src, target, skill_id) + battle_skill_damage_map(src, target, skill_id);
}
#endif

/**
* Calculates Minstrel/Wanderer bonus for Chorus skills.
Expand Down Expand Up @@ -5103,9 +5106,7 @@ struct Damage battle_calc_weapon_final_atk_modifiers(struct Damage wd, struct bl
struct status_change *tsc = status_get_sc(target);
struct status_data *sstatus = status_get_status_data(src);
struct status_data *tstatus = status_get_status_data(target);
#ifdef ADJUST_SKILL_DAMAGE
int skill_damage = 0;
#endif

//Reject Sword bugreport:4493 by Daegaladh
if(wd.damage && tsc && tsc->data[SC_REJECTSWORD] &&
Expand Down Expand Up @@ -5187,10 +5188,8 @@ struct Damage battle_calc_weapon_final_atk_modifiers(struct Damage wd, struct bl
}

// Skill damage adjustment
#ifdef ADJUST_SKILL_DAMAGE
if ((skill_damage = battle_skill_damage(src, target, skill_id)) != 0)
ATK_ADDRATE(wd.damage, wd.damage2, skill_damage);
#endif
return wd;
}

Expand Down Expand Up @@ -5679,10 +5678,7 @@ static struct Damage battle_calc_weapon_attack(struct block_list *src, struct bl
*/
struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list *target,uint16 skill_id,uint16 skill_lv,int mflag)
{
int i, nk;
#ifdef ADJUST_SKILL_DAMAGE
int skill_damage = 0;
#endif
int i, nk, skill_damage = 0;
short s_ele = 0;

TBL_PC *sd;
Expand Down Expand Up @@ -6396,10 +6392,8 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list
ad.damage = battle_calc_bg_damage(src,target,ad.damage,skill_id,ad.flag);

// Skill damage adjustment
#ifdef ADJUST_SKILL_DAMAGE
if ((skill_damage = battle_skill_damage(src,target,skill_id)) != 0)
MATK_ADDRATE(skill_damage);
#endif

battle_absorb_damage(target, &ad);

Expand All @@ -6416,9 +6410,7 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list
*/
struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list *target,uint16 skill_id,uint16 skill_lv,int mflag)
{
#ifdef ADJUST_SKILL_DAMAGE
int skill_damage = 0;
#endif
short i, nk;
short s_ele;

Expand Down Expand Up @@ -6792,10 +6784,8 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list *
md.damage = battle_calc_bg_damage(src,target,md.damage,skill_id,md.flag);

// Skill damage adjustment
#ifdef ADJUST_SKILL_DAMAGE
if ((skill_damage = battle_skill_damage(src,target,skill_id)) != 0)
md.damage += (int64)md.damage * skill_damage / 100;
#endif

battle_absorb_damage(target, &md);

Expand Down

0 comments on commit 9313922

Please sign in to comment.