summaryrefslogtreecommitdiff
path: root/src/emap/battle.c
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-08-31 23:50:14 +0300
committerAndrei Karas <akaras@inbox.ru>2016-08-31 23:50:14 +0300
commita3158d2110a2a846d39a5ddc364adb40c212241d (patch)
tree4c057530f67be9855e1b8d270992f689bf22d3ed /src/emap/battle.c
parentd8603c474f62f62d3759b03ea317836383ba463c (diff)
downloadevol-hercules-a3158d2110a2a846d39a5ddc364adb40c212241d.tar.gz
evol-hercules-a3158d2110a2a846d39a5ddc364adb40c212241d.tar.bz2
evol-hercules-a3158d2110a2a846d39a5ddc364adb40c212241d.tar.xz
evol-hercules-a3158d2110a2a846d39a5ddc364adb40c212241d.zip
Add into mob_db weapot type attacks modifier.
New group in mob_db: WeaponAttacks Example: WeaponAttacks: { Bows: 5000 // mean bow attack do 50% of normal attack } Default value is 10000 mean 100%
Diffstat (limited to 'src/emap/battle.c')
-rw-r--r--src/emap/battle.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/emap/battle.c b/src/emap/battle.c
index 5b16244..161da3d 100644
--- a/src/emap/battle.c
+++ b/src/emap/battle.c
@@ -8,12 +8,42 @@
#include <string.h>
#include "common/HPMi.h"
+#include "common/nullpo.h"
+#include "common/utils.h"
#include "map/itemdb.h"
+#include "map/mob.h"
#include "map/pc.h"
#include "emap/data/itemd.h"
+#include "emap/data/mobd.h"
#include "emap/struct/itemdext.h"
+#include "emap/struct/mobdext.h"
+
+// copy from common/utils.c
+/**
+ * Applies a percentual rate modifier.
+ *
+ * @param value The base value.
+ * @param rate The rate modifier to apply.
+ * @param stdrate The rate modifier's divider (rate == stdrate => 100%).
+ * @return The modified value.
+ */
+int64 apply_percentrate64(int64 value, int rate, int stdrate)
+{
+ Assert_ret(stdrate > 0);
+ Assert_ret(rate >= 0);
+ if (rate == stdrate)
+ return value;
+ if (rate == 0)
+ return 0;
+ if (INT64_MAX / rate < value)
+ {
+ // Give up some precision to prevent overflows
+ return value / stdrate * rate;
+ }
+ return value * rate / stdrate;
+}
bool ebattle_check_arrows_post(bool retVal,
struct map_session_data *sd)
@@ -52,3 +82,32 @@ bool ebattle_check_arrows_post(bool retVal,
}
return false;
}
+
+struct Damage ebattle_calc_weapon_attack_post(struct Damage retVal,
+ struct block_list *src,
+ struct block_list *target __attribute__ ((unused)),
+ uint16 skill_id __attribute__ ((unused)),
+ uint16 skill_lv __attribute__ ((unused)),
+ int wflag __attribute__ ((unused)))
+{
+ if (src == NULL)
+ return retVal;
+
+ struct map_session_data *sd = BL_CAST(BL_PC, src);
+ if (sd == NULL)
+ return retVal;
+
+ struct mob_data *md = BL_CAST(BL_MOB, target);
+ if (md == NULL)
+ return retVal;
+
+ struct MobdExt *data = mobd_get_by_mob(md);
+ if (data == NULL)
+ return retVal;
+
+ const int mod = data->weaponAttacks[sd->weapontype1];
+ retVal.damage = apply_percentrate64(retVal.damage, mod, 10000);
+ retVal.damage2 = apply_percentrate64(retVal.damage2, mod, 10000);
+
+ return retVal;
+}