From 7888d7144db4c4e71542b786eb7e143dbd066230 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Thu, 2 Jul 2020 04:16:29 +0200 Subject: Add bSubDefEle item bonus --- src/map/battle.c | 14 ++++++++++++++ src/map/map.h | 1 + src/map/pc.c | 23 +++++++++++++++++++++++ src/map/pc.h | 4 ++++ 4 files changed, 42 insertions(+) (limited to 'src') diff --git a/src/map/battle.c b/src/map/battle.c index 689622cf4..12d85993f 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -1234,6 +1234,20 @@ static int64 battle_calc_cardfix(int attack_type, struct block_list *src, struct } cardfix = cardfix * (100 - ele_fix_lh) / 100; } + + // Apply bSubDefEle damage reduction. + switch (src->type) { + case BL_MOB: + ele_fix = tsd->sub_def_ele[status_get_element(src)].rate_mob; + break; + case BL_PC: + ele_fix = tsd->sub_def_ele[status_get_element(src)].rate_pc; + break; + default: + break; + } + + cardfix = cardfix * (100 - ele_fix) / 100; } cardfix = cardfix * (100-tsd->subsize[sstatus->size]) / 100; cardfix = cardfix * (100-tsd->subrace2[s_race2]) / 100; diff --git a/src/map/map.h b/src/map/map.h index 17f210bc3..f57bb0278 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -557,6 +557,7 @@ enum status_point_types { //we better clean up this enum and change it name [Hem SP_SKILL_USE_SP,SP_MAGIC_ATK_ELE, SP_ADD_FIXEDCAST, SP_ADD_VARIABLECAST, //2055-2058 SP_SET_DEF_RACE,SP_SET_MDEF_RACE, //2059-2060 SP_RACE_TOLERANCE,SP_ADDMAXWEIGHT, //2061-2062 + SP_SUB_DEF_ELE, // 2063 /* must be the last, plugins add bonuses from this value onwards */ SP_LAST_KNOWN, diff --git a/src/map/pc.c b/src/map/pc.c index 64e52848f..2d3115d68 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -4031,6 +4031,29 @@ static int pc_bonus3(struct map_session_data *sd, int type, int type2, int type3 sd->bonus.sp_vanish_trigger = val; } break; + case SP_SUB_DEF_ELE: + if ((type2 >= ELE_MAX && type2 != ELE_ALL) || type2 < ELE_NEUTRAL) { + ShowError("pc_bonus3: SP_SUB_DEF_ELE: Invalid element %d\n", type2); + break; + } + + if (type2 == ELE_ALL) { + for (int j = ELE_NEUTRAL; j < ELE_MAX; j++) { + if ((val & 1) != 0) + sd->sub_def_ele[j].rate_mob += type3; + + if ((val & 2) != 0) + sd->sub_def_ele[j].rate_pc += type3; + } + } else { + if ((val & 1) != 0) + sd->sub_def_ele[type2].rate_mob += type3; + + if ((val & 2) != 0) + sd->sub_def_ele[type2].rate_pc += type3; + } + + break; default: ShowWarning("pc_bonus3: unknown type %d %d %d %d!\n",type,type2,type3,val); diff --git a/src/map/pc.h b/src/map/pc.h index e8e591b09..a0c3bf955 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -395,6 +395,10 @@ BEGIN_ZEROED_BLOCK; // this block will be globally zeroed at the beginning of st int value; int rate, tick; } def_set_race[RC_MAX], mdef_set_race[RC_MAX]; + struct { + int rate_mob; //!< Physical damage reduction against monster's defense element. + int rate_pc; //!< Physical damage reduction against player's defense element. + } sub_def_ele[ELE_MAX]; //!< Bonus bSubDefEle data structure. struct { int atk_rate; int arrow_atk,arrow_ele,arrow_cri,arrow_hit; -- cgit v1.2.3-70-g09d2 From 98064d23a7231816d2c04e1e95c90b18d5636b30 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Thu, 2 Jul 2020 04:26:09 +0200 Subject: Add bMagicSubDefEle item bonus --- db/constants.conf | 1 + doc/item_bonus.md | 1 + src/map/battle.c | 13 +++++++++++++ src/map/map.h | 2 +- src/map/pc.c | 23 +++++++++++++++++++++++ src/map/pc.h | 4 ++++ 6 files changed, 43 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/db/constants.conf b/db/constants.conf index 46a1bdca8..8237fed67 100644 --- a/db/constants.conf +++ b/db/constants.conf @@ -653,6 +653,7 @@ constants_db: { bAddRaceTolerance: 2061 bAddMaxWeight: 2062 bSubDefEle: 2063 + bMagicSubDefEle: 2064 comment__: "Equip index" /* reference to script.c::script_defaults():equip[] array used for easy-conversion */ diff --git a/doc/item_bonus.md b/doc/item_bonus.md index b699c56c2..f1c8edc81 100644 --- a/doc/item_bonus.md +++ b/doc/item_bonus.md @@ -275,6 +275,7 @@ bonus3 bAddEle,`e`,`n`,`bf`; | +n% physical damage against element `e` bonus2 bSubEle,`e`,`n`; | +n% Damage reduction against element `e` bonus3 bSubEle,`e`,`n`,`bf`; | +n% Damage reduction against element `e`. bonus3 bSubDefEle,`e`,`n`,`i`; | +n% Physical damage reduction against defense element `e`.
i:
Flags (bitfield)
&1: Reduce damage from monsters.
&2: Reduce damage from players. +bonus3 bMagicSubDefEle,`e`,`n`,`i`; | +n% Magical damage reduction against defense element `e`.
i:
Flags (bitfield)
&1: Reduce damage from monsters.
&2: Reduce damage from players. bonus2 bAddDamageClass,`c`,`x`; | +n% extra physical damage against monsters of class `c` bonus2 bAddMagicDamageClass,`c`,`x`; | +n% extra magical damage against monsters of class `c` bonus2 bAddDefClass,`c`,`x`; | +n% physical damage reduction against monsters of class `c` diff --git a/src/map/battle.c b/src/map/battle.c index 12d85993f..956cc4a49 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -1068,6 +1068,19 @@ static int64 battle_calc_cardfix(int attack_type, struct block_list *src, struct continue; ele_fix += tsd->subele2[i].rate; } + + // Apply bMagicSubDefEle damage reduction. + switch (src->type) { + case BL_MOB: + ele_fix += tsd->magic_sub_def_ele[status_get_element(src)].rate_mob; + break; + case BL_PC: + ele_fix += tsd->magic_sub_def_ele[status_get_element(src)].rate_pc; + break; + default: + break; + } + cardfix = cardfix * (100 - ele_fix) / 100; } cardfix = cardfix * (100 - tsd->subsize[sstatus->size]) / 100; diff --git a/src/map/map.h b/src/map/map.h index f57bb0278..9f17ae439 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -557,7 +557,7 @@ enum status_point_types { //we better clean up this enum and change it name [Hem SP_SKILL_USE_SP,SP_MAGIC_ATK_ELE, SP_ADD_FIXEDCAST, SP_ADD_VARIABLECAST, //2055-2058 SP_SET_DEF_RACE,SP_SET_MDEF_RACE, //2059-2060 SP_RACE_TOLERANCE,SP_ADDMAXWEIGHT, //2061-2062 - SP_SUB_DEF_ELE, // 2063 + SP_SUB_DEF_ELE, SP_MAGIC_SUB_DEF_ELE, // 2063-2064 /* must be the last, plugins add bonuses from this value onwards */ SP_LAST_KNOWN, diff --git a/src/map/pc.c b/src/map/pc.c index 2d3115d68..242c43ba3 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -4053,6 +4053,29 @@ static int pc_bonus3(struct map_session_data *sd, int type, int type2, int type3 sd->sub_def_ele[type2].rate_pc += type3; } + break; + case SP_MAGIC_SUB_DEF_ELE: + if ((type2 >= ELE_MAX && type2 != ELE_ALL) || type2 < ELE_NEUTRAL) { + ShowError("pc_bonus3: SP_MAGIC_SUB_DEF_ELE: Invalid element %d\n", type2); + break; + } + + if (type2 == ELE_ALL) { + for (int j = ELE_NEUTRAL; j < ELE_MAX; j++) { + if ((val & 1) != 0) + sd->magic_sub_def_ele[j].rate_mob += type3; + + if ((val & 2) != 0) + sd->magic_sub_def_ele[j].rate_pc += type3; + } + } else { + if ((val & 1) != 0) + sd->magic_sub_def_ele[type2].rate_mob += type3; + + if ((val & 2) != 0) + sd->magic_sub_def_ele[type2].rate_pc += type3; + } + break; default: diff --git a/src/map/pc.h b/src/map/pc.h index a0c3bf955..3f8f88444 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -399,6 +399,10 @@ BEGIN_ZEROED_BLOCK; // this block will be globally zeroed at the beginning of st int rate_mob; //!< Physical damage reduction against monster's defense element. int rate_pc; //!< Physical damage reduction against player's defense element. } sub_def_ele[ELE_MAX]; //!< Bonus bSubDefEle data structure. + struct { + int rate_mob; //!< Magical damage reduction against monster's defense element. + int rate_pc; //!< Magical damage reduction against player's defense element. + } magic_sub_def_ele[ELE_MAX]; //!< Bonus bMagicSubDefEle data structure. struct { int atk_rate; int arrow_atk,arrow_ele,arrow_cri,arrow_hit; -- cgit v1.2.3-70-g09d2 From 2eff14f905ad2a9493dcf879b16a4d4a0c5b8508 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Sat, 4 Jul 2020 00:06:34 +0200 Subject: Don't define separate structs for bSubDefEle and bMagicSubDefEle --- src/map/pc.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/map/pc.h b/src/map/pc.h index 3f8f88444..7afb35be2 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -396,13 +396,9 @@ BEGIN_ZEROED_BLOCK; // this block will be globally zeroed at the beginning of st int rate, tick; } def_set_race[RC_MAX], mdef_set_race[RC_MAX]; struct { - int rate_mob; //!< Physical damage reduction against monster's defense element. - int rate_pc; //!< Physical damage reduction against player's defense element. - } sub_def_ele[ELE_MAX]; //!< Bonus bSubDefEle data structure. - struct { - int rate_mob; //!< Magical damage reduction against monster's defense element. - int rate_pc; //!< Magical damage reduction against player's defense element. - } magic_sub_def_ele[ELE_MAX]; //!< Bonus bMagicSubDefEle data structure. + int rate_mob; //!< Damage reduction rate against monster's defense element. + int rate_pc; //!< Damage reduction rate against player's defense element. + } sub_def_ele[ELE_MAX], magic_sub_def_ele[ELE_MAX]; //!< Bonus bSubDefEle/bMagicSubDefEle data structure. struct { int atk_rate; int arrow_atk,arrow_ele,arrow_cri,arrow_hit; -- cgit v1.2.3-70-g09d2 From 69c777b219a8da1d6004be6c5bda8f590283318e Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Sat, 4 Jul 2020 00:16:30 +0200 Subject: Validate return value of status_get_element(src) before using it as array index --- src/map/battle.c | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/map/battle.c b/src/map/battle.c index 956cc4a49..98569f436 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -1070,15 +1070,20 @@ static int64 battle_calc_cardfix(int attack_type, struct block_list *src, struct } // Apply bMagicSubDefEle damage reduction. - switch (src->type) { - case BL_MOB: - ele_fix += tsd->magic_sub_def_ele[status_get_element(src)].rate_mob; - break; - case BL_PC: - ele_fix += tsd->magic_sub_def_ele[status_get_element(src)].rate_pc; - break; - default: - break; + enum elements def_ele = status_get_element(src); + + if ((src->type == BL_MOB || src->type == BL_PC) + && !Assert_chk(def_ele >= ELE_NEUTRAL && def_ele < ELE_MAX)) { + switch (src->type) { + case BL_MOB: + ele_fix += tsd->magic_sub_def_ele[def_ele].rate_mob; + break; + case BL_PC: + ele_fix += tsd->magic_sub_def_ele[def_ele].rate_pc; + break; + default: + break; + } } cardfix = cardfix * (100 - ele_fix) / 100; @@ -1249,18 +1254,23 @@ static int64 battle_calc_cardfix(int attack_type, struct block_list *src, struct } // Apply bSubDefEle damage reduction. - switch (src->type) { - case BL_MOB: - ele_fix = tsd->sub_def_ele[status_get_element(src)].rate_mob; - break; - case BL_PC: - ele_fix = tsd->sub_def_ele[status_get_element(src)].rate_pc; - break; - default: - break; - } + enum elements def_ele = status_get_element(src); - cardfix = cardfix * (100 - ele_fix) / 100; + if ((src->type == BL_MOB || src->type == BL_PC) + && !Assert_chk(def_ele >= ELE_NEUTRAL && def_ele < ELE_MAX)) { + switch (src->type) { + case BL_MOB: + ele_fix = tsd->sub_def_ele[def_ele].rate_mob; + break; + case BL_PC: + ele_fix = tsd->sub_def_ele[def_ele].rate_pc; + break; + default: + break; + } + + cardfix = cardfix * (100 - ele_fix) / 100; + } } cardfix = cardfix * (100-tsd->subsize[sstatus->size]) / 100; cardfix = cardfix * (100-tsd->subrace2[s_race2]) / 100; -- cgit v1.2.3-70-g09d2 From d3311cd34169008f0ba67a11c2f3353ab565c343 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Sat, 4 Jul 2020 06:12:48 +0200 Subject: Use sstatus->def_ele instead of status_get_element(src) --- src/map/battle.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/map/battle.c b/src/map/battle.c index 98569f436..efc82c27f 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -1070,16 +1070,14 @@ static int64 battle_calc_cardfix(int attack_type, struct block_list *src, struct } // Apply bMagicSubDefEle damage reduction. - enum elements def_ele = status_get_element(src); - if ((src->type == BL_MOB || src->type == BL_PC) - && !Assert_chk(def_ele >= ELE_NEUTRAL && def_ele < ELE_MAX)) { + && !Assert_chk(sstatus->def_ele >= ELE_NEUTRAL && sstatus->def_ele < ELE_MAX)) { switch (src->type) { case BL_MOB: - ele_fix += tsd->magic_sub_def_ele[def_ele].rate_mob; + ele_fix += tsd->magic_sub_def_ele[sstatus->def_ele].rate_mob; break; case BL_PC: - ele_fix += tsd->magic_sub_def_ele[def_ele].rate_pc; + ele_fix += tsd->magic_sub_def_ele[sstatus->def_ele].rate_pc; break; default: break; @@ -1254,16 +1252,14 @@ static int64 battle_calc_cardfix(int attack_type, struct block_list *src, struct } // Apply bSubDefEle damage reduction. - enum elements def_ele = status_get_element(src); - if ((src->type == BL_MOB || src->type == BL_PC) - && !Assert_chk(def_ele >= ELE_NEUTRAL && def_ele < ELE_MAX)) { + && !Assert_chk(sstatus->def_ele >= ELE_NEUTRAL && sstatus->def_ele < ELE_MAX)) { switch (src->type) { case BL_MOB: - ele_fix = tsd->sub_def_ele[def_ele].rate_mob; + ele_fix = tsd->sub_def_ele[sstatus->def_ele].rate_mob; break; case BL_PC: - ele_fix = tsd->sub_def_ele[def_ele].rate_pc; + ele_fix = tsd->sub_def_ele[sstatus->def_ele].rate_pc; break; default: break; -- cgit v1.2.3-70-g09d2 From 9f39a74248de7908955cb876fa2fb936babd2546 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Sat, 4 Jul 2020 11:23:03 +0200 Subject: Cast sstatus->def_ele to int --- src/map/battle.c | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/map/battle.c b/src/map/battle.c index efc82c27f..a0140d32b 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -1070,17 +1070,20 @@ static int64 battle_calc_cardfix(int attack_type, struct block_list *src, struct } // Apply bMagicSubDefEle damage reduction. - if ((src->type == BL_MOB || src->type == BL_PC) - && !Assert_chk(sstatus->def_ele >= ELE_NEUTRAL && sstatus->def_ele < ELE_MAX)) { - switch (src->type) { - case BL_MOB: - ele_fix += tsd->magic_sub_def_ele[sstatus->def_ele].rate_mob; - break; - case BL_PC: - ele_fix += tsd->magic_sub_def_ele[sstatus->def_ele].rate_pc; - break; - default: - break; + if (src->type == BL_MOB || src->type == BL_PC) { + int ele = (int)sstatus->def_ele; + + if (!Assert_chk(ele >= ELE_NEUTRAL && ele < ELE_MAX)) { + switch (src->type) { + case BL_MOB: + ele_fix += tsd->magic_sub_def_ele[ele].rate_mob; + break; + case BL_PC: + ele_fix += tsd->magic_sub_def_ele[ele].rate_pc; + break; + default: + break; + } } } @@ -1252,20 +1255,23 @@ static int64 battle_calc_cardfix(int attack_type, struct block_list *src, struct } // Apply bSubDefEle damage reduction. - if ((src->type == BL_MOB || src->type == BL_PC) - && !Assert_chk(sstatus->def_ele >= ELE_NEUTRAL && sstatus->def_ele < ELE_MAX)) { - switch (src->type) { - case BL_MOB: - ele_fix = tsd->sub_def_ele[sstatus->def_ele].rate_mob; - break; - case BL_PC: - ele_fix = tsd->sub_def_ele[sstatus->def_ele].rate_pc; - break; - default: - break; - } + if (src->type == BL_MOB || src->type == BL_PC) { + int ele = (int)sstatus->def_ele; + + if (!Assert_chk(ele >= ELE_NEUTRAL && ele < ELE_MAX)) { + switch (src->type) { + case BL_MOB: + ele_fix = tsd->sub_def_ele[ele].rate_mob; + break; + case BL_PC: + ele_fix = tsd->sub_def_ele[ele].rate_pc; + break; + default: + break; + } - cardfix = cardfix * (100 - ele_fix) / 100; + cardfix = cardfix * (100 - ele_fix) / 100; + } } } cardfix = cardfix * (100-tsd->subsize[sstatus->size]) / 100; -- cgit v1.2.3-70-g09d2