From 31cc8c5115ec6e44085a00c710d9007e425ffbbd Mon Sep 17 00:00:00 2001 From: aleos Date: Sun, 14 Jan 2024 16:08:55 -0500 Subject: [PATCH] Adds a function to assist with PK damage * Re-implement battle_calc_pk_damage to help determine when to adjust damage when PK mode is enabled. * Implement INF2_IGNOREPKREDUCTION skill flag to make skills bypass the damage adjustments. --- doc/skill_db.txt | 1 + src/map/battle.cpp | 41 +++++++++++++++++++++++++++++------- src/map/battle.hpp | 1 + src/map/script_constants.hpp | 1 + src/map/skill.hpp | 1 + 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/doc/skill_db.txt b/doc/skill_db.txt index 6b6461b975..aa389835ec 100644 --- a/doc/skill_db.txt +++ b/doc/skill_db.txt @@ -80,6 +80,7 @@ IsShadowSpell - Make skill available for SC_AUTOSHADOWSPELL. IsChorus - Chorus skill. IgnoreBgReduction - Ignore Battleground reduction. IgnoreGvgReduction - Ignore GvG reduction. +IgnorePKReduction - Ignore PK reduction. DisableNearNpc - Disable self/ground skills near NPC. In tandem with NoNearNpc node. TargetTrap - Damage traps. If TargetType is Trap. IgnoreLandProtector - Ignore SA_LANDPROTECTOR. diff --git a/src/map/battle.cpp b/src/map/battle.cpp index acf16daaad..901ac9e48b 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -1574,8 +1574,8 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam #endif case SP_SOULEXPLOSION: // Adjust these based on any possible PK damage rates. - if (battle_config.pk_mode > 0 && src->type == BL_PC && bl->type == BL_PC && damage > 0 && map_getmapflag(bl->m, MF_PVP)) - damage = battle_calc_zone_damage_rate(*bl, damage, flag); + if (battle_config.pk_mode > 0 && map_getmapflag(bl->m, MF_PVP)) + damage = battle_calc_pk_damage(*src, *bl, damage, skill_id, flag); return damage; //These skills bypass everything else. } @@ -1584,8 +1584,8 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam // So can defense sphere's but what the heck is that??? [Rytech] if (skill_id == SJ_NOVAEXPLOSING && !(tsc && (tsc->getSCE(SC_SAFETYWALL) || tsc->getSCE(SC_MILLENNIUMSHIELD)))) { // Adjust this based on any possible PK damage rates. - if (battle_config.pk_mode > 0 && src->type == BL_PC && bl->type == BL_PC && damage > 0 && map_getmapflag(bl->m, MF_PVP)) - damage = battle_calc_zone_damage_rate(*bl, damage, flag); + if (battle_config.pk_mode > 0 && map_getmapflag(bl->m, MF_PVP)) + damage = battle_calc_pk_damage(*src, *bl, damage, skill_id, flag); return damage; } @@ -1944,8 +1944,8 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam } //End of caster SC_ check //PK damage rates - if (battle_config.pk_mode > 0 && src->type == BL_PC && bl->type == BL_PC && damage > 0 && map_getmapflag(bl->m, MF_PVP)) - damage = battle_calc_zone_damage_rate(*bl, damage, flag); + if (battle_config.pk_mode > 0 && map_getmapflag(bl->m, MF_PVP)) + damage = battle_calc_pk_damage(*src, *bl, damage, skill_id, flag); if(battle_config.skill_min_damage && damage > 0 && damage < div_) { if ((flag&BF_WEAPON && battle_config.skill_min_damage&1) @@ -2098,6 +2098,31 @@ int64 battle_calc_gvg_damage(struct block_list *src,struct block_list *bl,int64 return i64max(battle_calc_zone_damage_rate(*bl, damage, flag), 1); } +/** + * Calculates PK related damage adjustments (between players only). + * @param src: Source object + * @param bl: Target object + * @param damage: Damage being done + * @param skill_id: Skill used + * @param flag: Battle flag type + * @return Modified damage + */ +int64 battle_calc_pk_damage(block_list &src, block_list &bl, int64 damage, uint16 skill_id, int flag) { + if (damage == 0) // No reductions to make. + return 0; + + if (battle_config.pk_mode == 0) // PK mode is disabled. + return damage; + + if (skill_get_inf2(skill_id, INF2_IGNOREPKREDUCTION)) //Skills with no pk damage reduction. + return damage; + + if (src.type == BL_PC && bl.type == BL_PC) + return i64max(battle_calc_zone_damage_rate(bl, damage, flag), 1); + else + return damage; +} + /** * HP/SP drain calculation * @param damage Damage inflicted to the enemy @@ -8878,8 +8903,8 @@ int64 battle_calc_return_damage(struct block_list* tbl, struct block_list *src, rdamage = battle_calc_gvg_damage(src, tbl, rdamage, skill_id, flag); else if (mapdata->getMapFlag(MF_BATTLEGROUND)) rdamage = battle_calc_bg_damage(src, tbl, rdamage, skill_id, flag); - else if (battle_config.pk_mode > 0 && src->type == BL_PC && tbl->type == BL_PC && damage > 0 && mapdata->getMapFlag(MF_PVP)) - rdamage = battle_calc_zone_damage_rate(*tbl, damage, flag); + else if (battle_config.pk_mode > 0 && mapdata->getMapFlag(MF_PVP)) + damage = battle_calc_pk_damage(*src, *tbl, damage, skill_id, flag); // Skill damage adjustment int skill_damage = battle_skill_damage(src, tbl, skill_id); diff --git a/src/map/battle.hpp b/src/map/battle.hpp index 4dffafb3ad..1fce18e24c 100644 --- a/src/map/battle.hpp +++ b/src/map/battle.hpp @@ -102,6 +102,7 @@ int battle_calc_cardfix(int attack_type, struct block_list *src, struct block_li int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Damage *d,int64 damage,uint16 skill_id,uint16 skill_lv); int64 battle_calc_gvg_damage(struct block_list *src,struct block_list *bl,int64 damage,uint16 skill_id,int flag); int64 battle_calc_bg_damage(struct block_list *src,struct block_list *bl,int64 damage,uint16 skill_id,int flag); +int64 battle_calc_pk_damage(block_list &src, block_list &bl, int64 damage, uint16 skill_id, int flag); void battle_damage(struct block_list *src, struct block_list *target, int64 damage, t_tick delay, uint16 skill_lv, uint16 skill_id, enum damage_lv dmg_lv, unsigned short attack_type, bool additional_effects, t_tick tick, bool spdamage); int battle_delay_damage (t_tick tick, int amotion, struct block_list *src, struct block_list *target, int attack_type, uint16 skill_id, uint16 skill_lv, int64 damage, enum damage_lv dmg_lv, t_tick ddelay, bool additional_effects, bool spdamage); diff --git a/src/map/script_constants.hpp b/src/map/script_constants.hpp index 79536778fd..41cfcd08c9 100644 --- a/src/map/script_constants.hpp +++ b/src/map/script_constants.hpp @@ -9837,6 +9837,7 @@ export_constant(INF2_SHOWSCALE); export_constant(INF2_IGNOREGTB); export_constant(INF2_TOGGLEABLE); + export_constant(INF2_IGNOREPKREDUCTION); /* skill no near npc flags */ export_constant(SKILL_NONEAR_WARPPORTAL); diff --git a/src/map/skill.hpp b/src/map/skill.hpp index 077fe8c959..776a12d788 100644 --- a/src/map/skill.hpp +++ b/src/map/skill.hpp @@ -110,6 +110,7 @@ enum e_skill_inf2 : uint8 { INF2_SHOWSCALE, // Skill shows AoE area while casting INF2_IGNOREGTB, // Skill ignores effect of GTB INF2_TOGGLEABLE, // Skill can be toggled on and off (won't consume HP/SP when toggled off) + INF2_IGNOREPKREDUCTION, // Skill that ignore pk reduction INF2_MAX, };