diff options
-rw-r--r-- | src/emap/battle.c | 35 | ||||
-rw-r--r-- | src/emap/battle.h | 4 | ||||
-rw-r--r-- | src/emap/data/itemd.c | 1 | ||||
-rw-r--r-- | src/emap/init.c | 1 | ||||
-rw-r--r-- | src/emap/itemdb.c | 3 | ||||
-rw-r--r-- | src/emap/struct/itemdext.h | 2 |
6 files changed, 46 insertions, 0 deletions
diff --git a/src/emap/battle.c b/src/emap/battle.c index 1404795..5a24927 100644 --- a/src/emap/battle.c +++ b/src/emap/battle.c @@ -15,6 +15,8 @@ #include "map/mob.h" #include "map/pc.h" +#include "plugins/HPMHooking.h" + #include "emap/data/itemd.h" #include "emap/data/mobd.h" #include "emap/struct/itemdext.h" @@ -61,6 +63,8 @@ bool ebattle_check_arrows_post(bool retVal, return true; const int weaponIndex = sd->equip_index[EQI_HAND_L]; + if (weaponIndex < 0) + return true; struct ItemdExt *data = itemd_get(sd->inventory_data[weaponIndex]); if (!data) @@ -119,3 +123,34 @@ struct Damage ebattle_calc_weapon_attack_post(struct Damage retVal, retVal.damage2 = apply_percentrate64(retVal.damage2, mod, 10000); return retVal; } + +enum damage_lv ebattle_weapon_attack_pre(struct block_list **srcPtr, + struct block_list **targetPtr, + int64 *tickPtr __attribute__ ((unused)), + int *flagPtr __attribute__ ((unused))) +{ + struct block_list *src = *srcPtr; + struct block_list *target = *targetPtr; + + nullpo_retr(ATK_NONE, src); + nullpo_retr(ATK_NONE, target); + + struct map_session_data *sd = BL_CAST(BL_PC, src); + if (sd == NULL) + return ATK_NONE; + + const int weaponIndex = sd->equip_index[EQI_HAND_L]; + if (weaponIndex < 0) + return ATK_NONE; + + struct ItemdExt *data = itemd_get(sd->inventory_data[weaponIndex]); + if (!data) + return ATK_NONE; + + if (distance_bl(src, target) < data->minRange) + { // if range between player and target > minRange, then dont attack + hookStop(); + return ATK_NONE; + } + return ATK_NONE; +} diff --git a/src/emap/battle.h b/src/emap/battle.h index 38ce379..17d7ba7 100644 --- a/src/emap/battle.h +++ b/src/emap/battle.h @@ -12,5 +12,9 @@ struct Damage ebattle_calc_weapon_attack_post(struct Damage retVal, uint16 skill_id, uint16 skill_lv, int wflag); +enum damage_lv ebattle_weapon_attack_pre(struct block_list **srcPtr, + struct block_list **targetPtr, + int64 *tickPtr, + int *flagPtr); #endif // EVOL_MAP_BATTLE diff --git a/src/emap/data/itemd.c b/src/emap/data/itemd.c index e516bcd..f9dde73 100644 --- a/src/emap/data/itemd.c +++ b/src/emap/data/itemd.c @@ -75,5 +75,6 @@ struct ItemdExt *itemd_create(void) VECTOR_INIT(data->allowedAmmo); data->subX = 8; data->subY = 8; + data->minRange = 0; return data; } diff --git a/src/emap/init.c b/src/emap/init.c index 23a2a88..e6a4113 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -201,6 +201,7 @@ HPExport void plugin_init (void) addHookPre(atcommand, msgfd, eatcommand_msgfd_pre); addHookPre(atcommand, msgsd, eatcommand_msgsd_pre); + addHookPre(battle, weapon_attack, ebattle_weapon_attack_pre); addHookPre(bg, team_warp, ebg_team_warp_pre); addHookPre(pc, can_Adopt, epc_can_Adopt_pre); addHookPre(pc, adoption, epc_adoption_pre); diff --git a/src/emap/itemdb.c b/src/emap/itemdb.c index 366b05d..dc4fd2f 100644 --- a/src/emap/itemdb.c +++ b/src/emap/itemdb.c @@ -184,6 +184,9 @@ void eitemdb_readdb_additional_fields_pre(int *itemid, } } + if (itemdb->lookup_const(it, "MinRange", &i32)) + data->minRange = i32; + hookStop(); } diff --git a/src/emap/struct/itemdext.h b/src/emap/struct/itemdext.h index 9a428ba..f30d94c 100644 --- a/src/emap/struct/itemdext.h +++ b/src/emap/struct/itemdext.h @@ -34,6 +34,8 @@ struct ItemdExt int unequipEffect; int unequipFailEffect; + int minRange; + VECTOR_DECL(int) allowedAmmo; VECTOR_DECL(struct ItemCardExt) allowedCards; struct script_code *dropScript; |