diff options
author | Haru <haru@dotalux.com> | 2016-06-24 22:39:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-24 22:39:35 +0200 |
commit | 7d2e109ba82ace541ceefa4c5b1c0b6804d0cfda (patch) | |
tree | 6fb6be124718881e0e4ec1bd9d427ae4b79b5c52 | |
parent | 7952c1fe1f92b7b4907545c6b24ccfc383c87555 (diff) | |
parent | 9fde855bfad89c9842c3f7525fe431e411a713f7 (diff) | |
download | hercules-7d2e109ba82ace541ceefa4c5b1c0b6804d0cfda.tar.gz hercules-7d2e109ba82ace541ceefa4c5b1c0b6804d0cfda.tar.bz2 hercules-7d2e109ba82ace541ceefa4c5b1c0b6804d0cfda.tar.xz hercules-7d2e109ba82ace541ceefa4c5b1c0b6804d0cfda.zip |
Merge pull request #1324 from 4144/ranged
Move ammo check into separate function in battle.c
-rw-r--r-- | src/map/battle.c | 74 | ||||
-rw-r--r-- | src/map/battle.h | 2 |
2 files changed, 44 insertions, 32 deletions
diff --git a/src/map/battle.c b/src/map/battle.c index 09b99aa05..944271efa 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -6009,6 +6009,46 @@ int battle_damage_area(struct block_list *bl, va_list ap) { return 0; } + +bool battle_check_arrows(struct map_session_data *sd) +{ + int index = sd->equip_index[EQI_AMMO]; + if (index < 0) { + if (sd->weapontype1 > W_KATAR && sd->weapontype1 < W_HUUMA) + clif->skill_fail(sd, 0, USESKILL_FAIL_NEED_MORE_BULLET, 0); + else + clif->arrow_fail(sd, 0); + return false; + } + //Ammo check by Ishizu-chan + if (sd->inventory_data[index]) { + switch (sd->status.weapon) { + case W_BOW: + if (sd->inventory_data[index]->look != A_ARROW) { + clif->arrow_fail(sd, 0); + return false; + } + break; + case W_REVOLVER: + case W_RIFLE: + case W_GATLING: + case W_SHOTGUN: + if (sd->inventory_data[index]->look != A_BULLET) { + clif->skill_fail(sd, 0, USESKILL_FAIL_NEED_MORE_BULLET, 0); + return false; + } + break; + case W_GRENADE: + if (sd->inventory_data[index]->look != A_GRENADE) { + clif->skill_fail(sd, 0, USESKILL_FAIL_NEED_MORE_BULLET, 0); + return false; + } + break; + } + } + return true; +} + /*========================================== * Do a basic physical attack (call trough unit_attack_timer) *------------------------------------------*/ @@ -6046,39 +6086,8 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t sd->state.arrow_atk = (sd->status.weapon == W_BOW || (sd->status.weapon >= W_REVOLVER && sd->status.weapon <= W_GRENADE)); if (sd->state.arrow_atk) { - int index = sd->equip_index[EQI_AMMO]; - if (index<0) { - if ( sd->weapontype1 > W_KATAR && sd->weapontype1 < W_HUUMA ) - clif->skill_fail(sd, 0, USESKILL_FAIL_NEED_MORE_BULLET, 0); - else - clif->arrow_fail(sd, 0); + if (battle->check_arrows(sd) == false) return ATK_NONE; - } - //Ammo check by Ishizu-chan - if (sd->inventory_data[index]) - switch (sd->status.weapon) { - case W_BOW: - if (sd->inventory_data[index]->look != A_ARROW) { - clif->arrow_fail(sd,0); - return ATK_NONE; - } - break; - case W_REVOLVER: - case W_RIFLE: - case W_GATLING: - case W_SHOTGUN: - if (sd->inventory_data[index]->look != A_BULLET) { - clif->skill_fail(sd, 0, USESKILL_FAIL_NEED_MORE_BULLET, 0); - return ATK_NONE; - } - break; - case W_GRENADE: - if (sd->inventory_data[index]->look != A_GRENADE) { - clif->skill_fail(sd, 0, USESKILL_FAIL_NEED_MORE_BULLET, 0); - return ATK_NONE; - } - break; - } } } if (sc && sc->count) { @@ -7605,6 +7614,7 @@ void battle_defaults(void) { battle->calc_gvg_damage = battle_calc_gvg_damage; battle->calc_bg_damage = battle_calc_bg_damage; battle->weapon_attack = battle_weapon_attack; + battle->check_arrows = battle_check_arrows; battle->calc_weapon_attack = battle_calc_weapon_attack; battle->delay_damage = battle_delay_damage; battle->drain = battle_drain; diff --git a/src/map/battle.h b/src/map/battle.h index 49abdc730..6fa600ada 100644 --- a/src/map/battle.h +++ b/src/map/battle.h @@ -593,6 +593,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); + /* check is equipped ammo and this ammo allowed */ + bool (*check_arrows) (struct map_session_data *sd); /* calculate weapon attack */ struct Damage (*calc_weapon_attack) (struct block_list *src,struct block_list *target,uint16 skill_id,uint16 skill_lv,int wflag); /* delays damage or skills by a timer */ |