Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed dual wielding not applying ice pick to offhand #7

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 21 additions & 24 deletions src/map/battle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1397,11 +1397,11 @@ static int64 battle_calc_cardfix(int attack_type, struct block_list *src, struct
* Calculates defense reduction. [malufett]
* flag:
* &1 - idef/imdef(Ignore defense)
* &2 - pdef(Pierce defense)
* &2 - rdef(Reverses defense / defense increases damage)
* &4 - tdef(Total defense reduction)
*------------------------------------------*/
// TODO: Add an enum for flag
static int64 battle_calc_defense(int attack_type, struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, int64 damage, int flag, int pdef)
static int64 battle_calc_defense(int attack_type, struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, int64 damage, int flag, int rdef)
{
struct status_data *sstatus, *tstatus;
struct map_session_data *sd, *tsd;
Expand Down Expand Up @@ -1537,14 +1537,16 @@ static int64 battle_calc_defense(int attack_type, struct block_list *src, struct
damage = (int)((100.0f - def1 / (def1 + 400.0f) * 90.0f) / 100.0f * damage - vit_def);
}
#else
if( def1 > 100 ) def1 = 100;
if( !(flag&1) ){
if( flag&2 )
damage = damage * pdef * (def1+vit_def) / 100;
if (def1 > 100)
def1 = 100;

if (!(flag & 1)) {
if (flag & 2)
damage = damage * rdef * (def1 + vit_def) / 100;
else
damage = damage * (100-def1) / 100;
damage = damage * (100 - def1) / 100;
}
if( !(flag&1 || flag&2) )
if (!(flag&1 || flag&2))
damage -= vit_def;
#endif
}
Expand Down Expand Up @@ -4622,8 +4624,7 @@ static struct Damage battle_calc_weapon_attack(struct block_list *src, struct bl
unsigned cri : 1; ///< Critical hit
unsigned idef : 1; ///< Ignore defense
unsigned idef2 : 1; ///< Ignore defense (left weapon)
unsigned pdef : 2; ///< Pierces defense (Investigate/Ice Pick)
unsigned pdef2 : 2; ///< 1: Use def+def2/100, 2: Use def+def2/50
unsigned rdef : 2; ///< Reverses defense in damage calculation (Investigate/Ice Pick)
unsigned infdef : 1; ///< Infinite defense (plants)
unsigned arrow : 1; ///< Attack is arrow-based
unsigned rh : 1; ///< Attack considers right hand (wd.damage)
Expand Down Expand Up @@ -4756,7 +4757,7 @@ static struct Damage battle_calc_weapon_attack(struct block_list *src, struct bl

case MO_INVESTIGATE:
case RL_MASS_SPIRAL:
flag.pdef = flag.pdef2 = 2;
flag.rdef = 2;
break;

case RA_AIMEDBOLT:
Expand Down Expand Up @@ -5669,17 +5670,13 @@ static struct Damage battle_calc_weapon_attack(struct block_list *src, struct bl
|| sd->right_weapon.def_ratio_atk_race & map->race_id2mask(tstatus->race)
|| sd->right_weapon.def_ratio_atk_race & map->race_id2mask(is_boss(target) ? RC_BOSS : RC_NONBOSS)
)
flag.pdef = 1;
flag.rdef = 1;

if (sd->left_weapon.def_ratio_atk_ele & (1<<tstatus->def_ele)
|| sd->left_weapon.def_ratio_atk_race & map->race_id2mask(tstatus->race)
|| sd->left_weapon.def_ratio_atk_race & map->race_id2mask(is_boss(target) ? RC_BOSS : RC_NONBOSS)
) {
//Pass effect onto right hand if configured so. [Skotlex]
if (battle_config.left_cardfix_to_right && flag.rh)
flag.pdef = 1;
else
flag.pdef2 = 1;
flag.rdef = 1;
}
}

Expand All @@ -5697,7 +5694,7 @@ static struct Damage battle_calc_weapon_attack(struct block_list *src, struct bl
sd->left_weapon.ignore_def_race & map->race_id2mask(tstatus->race) ||
sd->left_weapon.ignore_def_race & map->race_id2mask(is_boss(target) ? RC_BOSS : RC_NONBOSS)
)) {
if(battle_config.left_cardfix_to_right && flag.rh) //Move effect to right hand. [Skotlex]
if (battle_config.left_cardfix_to_right && flag.rh) //Move effect to right hand. [Skotlex]
flag.idef = 1;
else
flag.idef2 = 1;
Expand All @@ -5714,18 +5711,18 @@ static struct Damage battle_calc_weapon_attack(struct block_list *src, struct bl
#endif
) { //Defense reduction
wd.damage = battle->calc_defense(BF_WEAPON, src, target, skill_id, skill_lv, wd.damage,
(flag.idef?1:0)|(flag.pdef?2:0)
(flag.idef ? 1 : 0) | (flag.rdef ? 2 : 0)
#ifdef RENEWAL
|(flag.tdef?4:0)
#endif
, flag.pdef);
, flag.rdef);
if( wd.damage2 )
wd.damage2 = battle->calc_defense(BF_WEAPON, src, target, skill_id, skill_lv, wd.damage2,
(flag.idef2?1:0)|(flag.pdef2?2:0)
(flag.idef2 ? 1 : 0) | (flag.rdef ? 2 : 0)
#ifdef RENEWAL
|(flag.tdef?4:0)
#endif
, flag.pdef2);
, flag.rdef);
}

#ifdef RENEWAL
Expand Down Expand Up @@ -5801,7 +5798,7 @@ static struct Damage battle_calc_weapon_attack(struct block_list *src, struct bl

#ifndef RENEWAL
wd.damage = battle->calc_masteryfix(src, target, skill_id, skill_lv, wd.damage, wd.div_, 0, flag.weapon);
if( flag.lh )
if (flag.lh)
wd.damage2 = battle->calc_masteryfix(src, target, skill_id, skill_lv, wd.damage2, wd.div_, 1, flag.weapon);
#else
if( sd && flag.cri )
Expand Down Expand Up @@ -5856,7 +5853,7 @@ static struct Damage battle_calc_weapon_attack(struct block_list *src, struct bl
//Card Fix, sd side

wd.damage = battle->calc_cardfix(BF_WEAPON, src, target, nk, s_ele, s_ele_, wd.damage, 2, wd.flag);
if( flag.lh )
if (flag.lh && (!flag.rh || !battle_config.left_cardfix_to_right)) // Cards don't affect offhand when dual-wielding
wd.damage2 = battle->calc_cardfix(BF_WEAPON, src, target, nk, s_ele, s_ele_, wd.damage2, 3, wd.flag);

if( skill_id == CR_SHIELDBOOMERANG || skill_id == PA_SHIELDCHAIN )
Expand Down
2 changes: 1 addition & 1 deletion src/map/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ struct battle_interface {
/* get weapon damage */
int64 (*calc_weapon_damage) (struct block_list *src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, struct weapon_atk *watk, int nk, bool n_ele, short s_ele, short s_ele_, int size, int type, int flag, int flag2);
/* applies defense reductions */
int64 (*calc_defense) (int attack_type, struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, int64 damage, int flag, int pdef);
int64 (*calc_defense) (int attack_type, struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, int64 damage, int flag, int rdef);
/* get master (who does this unit respond to?) */
struct block_list *(*get_master) (struct block_list *src);
/* returns a random unit who is targeting this unit */
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/HPMHooking/HPMHooking.Defs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ typedef int64 (*HPMHOOK_pre_battle_calc_sizefix) (struct map_session_data **sd,
typedef int64 (*HPMHOOK_post_battle_calc_sizefix) (int64 retVal___, struct map_session_data *sd, int64 damage, int type, int size, bool ignore);
typedef int64 (*HPMHOOK_pre_battle_calc_weapon_damage) (struct block_list **src, struct block_list **bl, uint16 *skill_id, uint16 *skill_lv, struct weapon_atk **watk, int *nk, bool *n_ele, short *s_ele, short *s_ele_, int *size, int *type, int *flag, int *flag2);
typedef int64 (*HPMHOOK_post_battle_calc_weapon_damage) (int64 retVal___, struct block_list *src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, struct weapon_atk *watk, int nk, bool n_ele, short s_ele, short s_ele_, int size, int type, int flag, int flag2);
typedef int64 (*HPMHOOK_pre_battle_calc_defense) (int *attack_type, struct block_list **src, struct block_list **target, uint16 *skill_id, uint16 *skill_lv, int64 *damage, int *flag, int *pdef);
typedef int64 (*HPMHOOK_post_battle_calc_defense) (int64 retVal___, int attack_type, struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, int64 damage, int flag, int pdef);
typedef int64 (*HPMHOOK_pre_battle_calc_defense) (int *attack_type, struct block_list **src, struct block_list **target, uint16 *skill_id, uint16 *skill_lv, int64 *damage, int *flag, int *rdef);
typedef int64 (*HPMHOOK_post_battle_calc_defense) (int64 retVal___, int attack_type, struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, int64 damage, int flag, int rdef);
typedef struct block_list* (*HPMHOOK_pre_battle_get_master) (struct block_list **src);
typedef struct block_list* (*HPMHOOK_post_battle_get_master) (struct block_list* retVal___, struct block_list *src);
typedef struct block_list* (*HPMHOOK_pre_battle_get_targeted) (struct block_list **target);
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3236,29 +3236,29 @@ int64 HP_battle_calc_weapon_damage(struct block_list *src, struct block_list *bl
}
return retVal___;
}
int64 HP_battle_calc_defense(int attack_type, struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, int64 damage, int flag, int pdef) {
int64 HP_battle_calc_defense(int attack_type, struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, int64 damage, int flag, int rdef) {
int hIndex = 0;
int64 retVal___ = 0;
if (HPMHooks.count.HP_battle_calc_defense_pre > 0) {
int64 (*preHookFunc) (int *attack_type, struct block_list **src, struct block_list **target, uint16 *skill_id, uint16 *skill_lv, int64 *damage, int *flag, int *pdef);
int64 (*preHookFunc) (int *attack_type, struct block_list **src, struct block_list **target, uint16 *skill_id, uint16 *skill_lv, int64 *damage, int *flag, int *rdef);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_battle_calc_defense_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_battle_calc_defense_pre[hIndex].func;
retVal___ = preHookFunc(&attack_type, &src, &target, &skill_id, &skill_lv, &damage, &flag, &pdef);
retVal___ = preHookFunc(&attack_type, &src, &target, &skill_id, &skill_lv, &damage, &flag, &rdef);
}
if (*HPMforce_return) {
*HPMforce_return = false;
return retVal___;
}
}
{
retVal___ = HPMHooks.source.battle.calc_defense(attack_type, src, target, skill_id, skill_lv, damage, flag, pdef);
retVal___ = HPMHooks.source.battle.calc_defense(attack_type, src, target, skill_id, skill_lv, damage, flag, rdef);
}
if (HPMHooks.count.HP_battle_calc_defense_post > 0) {
int64 (*postHookFunc) (int64 retVal___, int attack_type, struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, int64 damage, int flag, int pdef);
int64 (*postHookFunc) (int64 retVal___, int attack_type, struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, int64 damage, int flag, int rdef);
for (hIndex = 0; hIndex < HPMHooks.count.HP_battle_calc_defense_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_battle_calc_defense_post[hIndex].func;
retVal___ = postHookFunc(retVal___, attack_type, src, target, skill_id, skill_lv, damage, flag, pdef);
retVal___ = postHookFunc(retVal___, attack_type, src, target, skill_id, skill_lv, damage, flag, rdef);
}
}
return retVal___;
Expand Down
Loading