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

Tests for Auto spell and blade stop #9

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
15 changes: 13 additions & 2 deletions src/map/battle.c
Original file line number Diff line number Diff line change
Expand Up @@ -6496,6 +6496,17 @@ static bool battle_check_arrows(struct map_session_data *sd)
return true;
}

static bool battle_should_bladestop_attacker(struct block_list *src, struct block_list *target)
{
nullpo_retr(false, src);
nullpo_retr(false, target);

struct status_change *tsc = status->get_sc(target);
struct map_session_data *tsd = BL_CAST(BL_PC, target);

return (tsc && tsc->data[SC_BLADESTOP_WAIT] && !is_boss(src) && (src->type == BL_PC || tsd == NULL || distance_bl(src, target) <= (tsd->weapontype == W_FIST ? 1 : 2)));
}

/*==========================================
* Do a basic physical attack (call trough unit_attack_timer)
*------------------------------------------*/
Expand Down Expand Up @@ -6561,8 +6572,7 @@ static enum damage_lv battle_weapon_attack(struct block_list *src, struct block_
return ATK_BLOCK;
}
}
if( tsc && tsc->data[SC_BLADESTOP_WAIT] && !is_boss(src) && (src->type == BL_PC || tsd == NULL || distance_bl(src, target) <= (tsd->weapontype == W_FIST ? 1 : 2)) )
{
if (battle->should_bladestop_attacker(src, target)) {
uint16 skill_lv = tsc->data[SC_BLADESTOP_WAIT]->val1;
int duration = skill->get_time2(MO_BLADESTOP,skill_lv);
status_change_end(target, SC_BLADESTOP_WAIT, INVALID_TIMER);
Expand Down Expand Up @@ -8145,6 +8155,7 @@ void battle_defaults(void)
battle->calc_pc_damage = battle_calc_pc_damage;
battle->calc_gvg_damage = battle_calc_gvg_damage;
battle->calc_bg_damage = battle_calc_bg_damage;
battle->should_bladestop_attacker = battle_should_bladestop_attacker;
battle->weapon_attack = battle_weapon_attack;
battle->check_arrows = battle_check_arrows;
battle->calc_weapon_attack = battle_calc_weapon_attack;
Expand Down
2 changes: 2 additions & 0 deletions src/map/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,8 @@ struct battle_interface {
int64 (*calc_bg_damage) (struct block_list *src, struct block_list *bl, int64 damage, int div_, uint16 skill_id, uint16 skill_lv, int flag);
/* normal weapon attack */
enum damage_lv (*weapon_attack) (struct block_list *bl, struct block_list *target, int64 tick, int flag);
/* */
bool (*should_bladestop_attacker) (struct block_list *src, struct block_list *target);
/* check is equipped ammo and this ammo allowed */
bool (*check_arrows) (struct map_session_data *sd);
/* calculate weapon attack */
Expand Down
2 changes: 1 addition & 1 deletion src/map/clif.c
Original file line number Diff line number Diff line change
Expand Up @@ -14190,7 +14190,7 @@ static void clif_parse_AutoSpell(int fd, struct map_session_data *sd)
if( !skill_id )
return;

skill->autospell(sd, skill_id);
skill->autospell_spell_selected(sd, skill_id);
clif_menuskill_clear(sd);
}

Expand Down
85 changes: 47 additions & 38 deletions src/map/skill.c
Original file line number Diff line number Diff line change
Expand Up @@ -8777,42 +8777,7 @@ static int skill_castend_nodamage_id(struct block_list *src, struct block_list *
break;
case SA_AUTOSPELL:
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
if(sd){
sd->state.workinprogress = 3;
clif->autospell(sd,skill_lv);
}else {
int maxlv=1,spellid=0;
static const int spellarray[3] = { MG_COLDBOLT,MG_FIREBOLT,MG_LIGHTNINGBOLT };
if(skill_lv >= 10) {
spellid = MG_FROSTDIVER;
#if 0
if (tsc && tsc->data[SC_SOULLINK] && tsc->data[SC_SOULLINK]->val2 == SA_SAGE)
maxlv = 10;
else
#endif // 0
maxlv = skill_lv - 9;
}
else if(skill_lv >=8) {
spellid = MG_FIREBALL;
maxlv = skill_lv - 7;
}
else if(skill_lv >=5) {
spellid = MG_SOULSTRIKE;
maxlv = skill_lv - 4;
}
else if(skill_lv >=2) {
int i = rnd() % ARRAYLENGTH(spellarray);
spellid = spellarray[i];
maxlv = skill_lv - 1;
}
else if(skill_lv > 0) {
spellid = MG_NAPALMBEAT;
maxlv = 3;
}
if(spellid > 0)
sc_start4(src,src,SC_AUTOSPELL,100,skill_lv,spellid,maxlv,0,
skill->get_time(SA_AUTOSPELL, skill_lv), SA_AUTOSPELL);
}
skill->autospell_select_spell(src, skill_lv);
break;

case BS_GREED:
Expand Down Expand Up @@ -17836,7 +17801,50 @@ static void skill_weaponrefine(struct map_session_data *sd, int idx)
/*==========================================
*
*------------------------------------------*/
static int skill_autospell(struct map_session_data *sd, uint16 skill_id)
static void skill_autospell_select_spell(struct block_list *src, int skill_lv)
{
nullpo_retv(src);
struct map_session_data *sd = BL_CAST(BL_PC, src);

if(sd){
sd->state.workinprogress = 3;
clif->autospell(sd,skill_lv);
} else {
int maxlv=1,spellid=0;
static const int spellarray[3] = { MG_COLDBOLT,MG_FIREBOLT,MG_LIGHTNINGBOLT };
if(skill_lv >= 10) {
spellid = MG_FROSTDIVER;
#if 0
if (tsc && tsc->data[SC_SOULLINK] && tsc->data[SC_SOULLINK]->val2 == SA_SAGE)
maxlv = 10;
else
#endif // 0
maxlv = skill_lv - 9;
}
else if(skill_lv >=8) {
spellid = MG_FIREBALL;
maxlv = skill_lv - 7;
}
else if(skill_lv >=5) {
spellid = MG_SOULSTRIKE;
maxlv = skill_lv - 4;
}
else if(skill_lv >=2) {
int i = rnd() % ARRAYLENGTH(spellarray);
spellid = spellarray[i];
maxlv = skill_lv - 1;
}
else if(skill_lv > 0) {
spellid = MG_NAPALMBEAT;
maxlv = 3;
}
if(spellid > 0)
sc_start4(src,src,SC_AUTOSPELL,100,skill_lv,spellid,maxlv,0,
skill->get_time(SA_AUTOSPELL, skill_lv), SA_AUTOSPELL);
}
}

static int skill_autospell_spell_selected(struct map_session_data *sd, uint16 skill_id)
{
uint16 skill_lv;
int maxlv=1,lv;
Expand Down Expand Up @@ -25024,7 +25032,8 @@ void skill_defaults(void)
skill->repairweapon = skill_repairweapon;
skill->identify = skill_identify;
skill->weaponrefine = skill_weaponrefine;
skill->autospell = skill_autospell;
skill->autospell_select_spell = skill_autospell_select_spell;
skill->autospell_spell_selected = skill_autospell_spell_selected;
skill->calc_heal = skill_calc_heal;
skill->check_cloaking = skill_check_cloaking;
skill->check_cloaking_end = skill_check_cloaking_end;
Expand Down
3 changes: 2 additions & 1 deletion src/map/skill.h
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,8 @@ struct skill_interface {
void (*repairweapon) (struct map_session_data *sd, int idx);
void (*identify) (struct map_session_data *sd,int idx);
void (*weaponrefine) (struct map_session_data *sd,int idx);
int (*autospell) (struct map_session_data *md,uint16 skill_id);
void (*autospell_select_spell) (struct block_list *src, int skill_lv);
int (*autospell_spell_selected) (struct map_session_data *md,uint16 skill_id);
int (*calc_heal) (struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, bool heal);
bool (*check_cloaking) (struct block_list *bl, struct status_change_entry *sce);
int (*check_cloaking_end) (struct block_list *bl, va_list ap);
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/HPMHooking/HPMHooking.Defs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ typedef int64 (*HPMHOOK_pre_battle_calc_bg_damage) (struct block_list **src, str
typedef int64 (*HPMHOOK_post_battle_calc_bg_damage) (int64 retVal___, struct block_list *src, struct block_list *bl, int64 damage, int div_, uint16 skill_id, uint16 skill_lv, int flag);
typedef enum damage_lv (*HPMHOOK_pre_battle_weapon_attack) (struct block_list **bl, struct block_list **target, int64 *tick, int *flag);
typedef enum damage_lv (*HPMHOOK_post_battle_weapon_attack) (enum damage_lv retVal___, struct block_list *bl, struct block_list *target, int64 tick, int flag);
typedef bool (*HPMHOOK_pre_battle_should_bladestop_attacker) (struct block_list **src, struct block_list **target);
typedef bool (*HPMHOOK_post_battle_should_bladestop_attacker) (bool retVal___, struct block_list *src, struct block_list *target);
typedef bool (*HPMHOOK_pre_battle_check_arrows) (struct map_session_data **sd);
typedef bool (*HPMHOOK_post_battle_check_arrows) (bool retVal___, struct map_session_data *sd);
typedef struct Damage (*HPMHOOK_pre_battle_calc_weapon_attack) (struct block_list **src, struct block_list **target, uint16 *skill_id, uint16 *skill_lv, int *wflag);
Expand Down Expand Up @@ -8466,8 +8468,10 @@ typedef void (*HPMHOOK_pre_skill_identify) (struct map_session_data **sd, int *i
typedef void (*HPMHOOK_post_skill_identify) (struct map_session_data *sd, int idx);
typedef void (*HPMHOOK_pre_skill_weaponrefine) (struct map_session_data **sd, int *idx);
typedef void (*HPMHOOK_post_skill_weaponrefine) (struct map_session_data *sd, int idx);
typedef int (*HPMHOOK_pre_skill_autospell) (struct map_session_data **md, uint16 *skill_id);
typedef int (*HPMHOOK_post_skill_autospell) (int retVal___, struct map_session_data *md, uint16 skill_id);
typedef void (*HPMHOOK_pre_skill_autospell_select_spell) (struct block_list **src, int *skill_lv);
typedef void (*HPMHOOK_post_skill_autospell_select_spell) (struct block_list *src, int skill_lv);
typedef int (*HPMHOOK_pre_skill_autospell_spell_selected) (struct map_session_data **md, uint16 *skill_id);
typedef int (*HPMHOOK_post_skill_autospell_spell_selected) (int retVal___, struct map_session_data *md, uint16 skill_id);
typedef int (*HPMHOOK_pre_skill_calc_heal) (struct block_list **src, struct block_list **target, uint16 *skill_id, uint16 *skill_lv, bool *heal);
typedef int (*HPMHOOK_post_skill_calc_heal) (int retVal___, struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, bool heal);
typedef bool (*HPMHOOK_pre_skill_check_cloaking) (struct block_list **bl, struct status_change_entry **sce);
Expand Down
16 changes: 12 additions & 4 deletions src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ struct {
struct HPMHookPoint *HP_battle_calc_bg_damage_post;
struct HPMHookPoint *HP_battle_weapon_attack_pre;
struct HPMHookPoint *HP_battle_weapon_attack_post;
struct HPMHookPoint *HP_battle_should_bladestop_attacker_pre;
struct HPMHookPoint *HP_battle_should_bladestop_attacker_post;
struct HPMHookPoint *HP_battle_check_arrows_pre;
struct HPMHookPoint *HP_battle_check_arrows_post;
struct HPMHookPoint *HP_battle_calc_weapon_attack_pre;
Expand Down Expand Up @@ -6390,8 +6392,10 @@ struct {
struct HPMHookPoint *HP_skill_identify_post;
struct HPMHookPoint *HP_skill_weaponrefine_pre;
struct HPMHookPoint *HP_skill_weaponrefine_post;
struct HPMHookPoint *HP_skill_autospell_pre;
struct HPMHookPoint *HP_skill_autospell_post;
struct HPMHookPoint *HP_skill_autospell_select_spell_pre;
struct HPMHookPoint *HP_skill_autospell_select_spell_post;
struct HPMHookPoint *HP_skill_autospell_spell_selected_pre;
struct HPMHookPoint *HP_skill_autospell_spell_selected_post;
struct HPMHookPoint *HP_skill_calc_heal_pre;
struct HPMHookPoint *HP_skill_calc_heal_post;
struct HPMHookPoint *HP_skill_check_cloaking_pre;
Expand Down Expand Up @@ -7759,6 +7763,8 @@ struct {
int HP_battle_calc_bg_damage_post;
int HP_battle_weapon_attack_pre;
int HP_battle_weapon_attack_post;
int HP_battle_should_bladestop_attacker_pre;
int HP_battle_should_bladestop_attacker_post;
int HP_battle_check_arrows_pre;
int HP_battle_check_arrows_post;
int HP_battle_calc_weapon_attack_pre;
Expand Down Expand Up @@ -13921,8 +13927,10 @@ struct {
int HP_skill_identify_post;
int HP_skill_weaponrefine_pre;
int HP_skill_weaponrefine_post;
int HP_skill_autospell_pre;
int HP_skill_autospell_post;
int HP_skill_autospell_select_spell_pre;
int HP_skill_autospell_select_spell_post;
int HP_skill_autospell_spell_selected_pre;
int HP_skill_autospell_spell_selected_post;
int HP_skill_calc_heal_pre;
int HP_skill_calc_heal_post;
int HP_skill_check_cloaking_pre;
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(battle->calc_gvg_damage, HP_battle_calc_gvg_damage) },
{ HP_POP(battle->calc_bg_damage, HP_battle_calc_bg_damage) },
{ HP_POP(battle->weapon_attack, HP_battle_weapon_attack) },
{ HP_POP(battle->should_bladestop_attacker, HP_battle_should_bladestop_attacker) },
{ HP_POP(battle->check_arrows, HP_battle_check_arrows) },
{ HP_POP(battle->calc_weapon_attack, HP_battle_calc_weapon_attack) },
{ HP_POP(battle->delay_damage, HP_battle_delay_damage) },
Expand Down Expand Up @@ -3270,7 +3271,8 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(skill->repairweapon, HP_skill_repairweapon) },
{ HP_POP(skill->identify, HP_skill_identify) },
{ HP_POP(skill->weaponrefine, HP_skill_weaponrefine) },
{ HP_POP(skill->autospell, HP_skill_autospell) },
{ HP_POP(skill->autospell_select_spell, HP_skill_autospell_select_spell) },
{ HP_POP(skill->autospell_spell_selected, HP_skill_autospell_spell_selected) },
{ HP_POP(skill->calc_heal, HP_skill_calc_heal) },
{ HP_POP(skill->check_cloaking, HP_skill_check_cloaking) },
{ HP_POP(skill->check_cloaking_end, HP_skill_check_cloaking_end) },
Expand Down
69 changes: 61 additions & 8 deletions src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,33 @@ enum damage_lv HP_battle_weapon_attack(struct block_list *bl, struct block_list
}
return retVal___;
}
bool HP_battle_should_bladestop_attacker(struct block_list *src, struct block_list *target) {
int hIndex = 0;
bool retVal___ = false;
if (HPMHooks.count.HP_battle_should_bladestop_attacker_pre > 0) {
bool (*preHookFunc) (struct block_list **src, struct block_list **target);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_battle_should_bladestop_attacker_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_battle_should_bladestop_attacker_pre[hIndex].func;
retVal___ = preHookFunc(&src, &target);
}
if (*HPMforce_return) {
*HPMforce_return = false;
return retVal___;
}
}
{
retVal___ = HPMHooks.source.battle.should_bladestop_attacker(src, target);
}
if (HPMHooks.count.HP_battle_should_bladestop_attacker_post > 0) {
bool (*postHookFunc) (bool retVal___, struct block_list *src, struct block_list *target);
for (hIndex = 0; hIndex < HPMHooks.count.HP_battle_should_bladestop_attacker_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_battle_should_bladestop_attacker_post[hIndex].func;
retVal___ = postHookFunc(retVal___, src, target);
}
}
return retVal___;
}
bool HP_battle_check_arrows(struct map_session_data *sd) {
int hIndex = 0;
bool retVal___ = false;
Expand Down Expand Up @@ -85256,14 +85283,40 @@ void HP_skill_weaponrefine(struct map_session_data *sd, int idx) {
}
return;
}
int HP_skill_autospell(struct map_session_data *md, uint16 skill_id) {
void HP_skill_autospell_select_spell(struct block_list *src, int skill_lv) {
int hIndex = 0;
if (HPMHooks.count.HP_skill_autospell_select_spell_pre > 0) {
void (*preHookFunc) (struct block_list **src, int *skill_lv);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_autospell_select_spell_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_skill_autospell_select_spell_pre[hIndex].func;
preHookFunc(&src, &skill_lv);
}
if (*HPMforce_return) {
*HPMforce_return = false;
return;
}
}
{
HPMHooks.source.skill.autospell_select_spell(src, skill_lv);
}
if (HPMHooks.count.HP_skill_autospell_select_spell_post > 0) {
void (*postHookFunc) (struct block_list *src, int skill_lv);
for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_autospell_select_spell_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_skill_autospell_select_spell_post[hIndex].func;
postHookFunc(src, skill_lv);
}
}
return;
}
int HP_skill_autospell_spell_selected(struct map_session_data *md, uint16 skill_id) {
int hIndex = 0;
int retVal___ = 0;
if (HPMHooks.count.HP_skill_autospell_pre > 0) {
if (HPMHooks.count.HP_skill_autospell_spell_selected_pre > 0) {
int (*preHookFunc) (struct map_session_data **md, uint16 *skill_id);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_autospell_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_skill_autospell_pre[hIndex].func;
for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_autospell_spell_selected_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_skill_autospell_spell_selected_pre[hIndex].func;
retVal___ = preHookFunc(&md, &skill_id);
}
if (*HPMforce_return) {
Expand All @@ -85272,12 +85325,12 @@ int HP_skill_autospell(struct map_session_data *md, uint16 skill_id) {
}
}
{
retVal___ = HPMHooks.source.skill.autospell(md, skill_id);
retVal___ = HPMHooks.source.skill.autospell_spell_selected(md, skill_id);
}
if (HPMHooks.count.HP_skill_autospell_post > 0) {
if (HPMHooks.count.HP_skill_autospell_spell_selected_post > 0) {
int (*postHookFunc) (int retVal___, struct map_session_data *md, uint16 skill_id);
for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_autospell_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_skill_autospell_post[hIndex].func;
for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_autospell_spell_selected_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_skill_autospell_spell_selected_post[hIndex].func;
retVal___ = postHookFunc(retVal___, md, skill_id);
}
}
Expand Down
Loading