From c2e673150488957ed4db79d0d8c41216777cd242 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Wed, 29 Jul 2020 06:31:52 -0300 Subject: Allow calcdmg() to be called without a target (MUST be ID 0 or lower) NOT TESTED --- src/emap/script_buildins.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c index 467ccf2..877fac1 100644 --- a/src/emap/script_buildins.c +++ b/src/emap/script_buildins.c @@ -3153,19 +3153,50 @@ BUILDIN(calcdmg) { struct block_list *src; struct block_list *bl; - int attack_type; + int attack_type, range, damage; + struct map_session_data *sd; // Fill data from scripts src = map->id2bl(script_getnum(st, 2)); bl = map->id2bl(script_getnum(st, 3)); attack_type = script_getnum(st,4); - // Nullity checks + // Nullity check for source if (src == NULL) { ShowWarning("buildin_calcdmg: Error in finding object with given GID %d!\n", script_getnum(st, 2)); script_pushint(st, 0); return false; } + + // Maybe we don't want a target? + if (script_getnum(st, 3) <= 0) { + sd = BL_CAST(BL_PC, src); + switch(attack_type) { + case BF_WEAPON: + range = sd->battle_status.rhw.atk2-sd->battle_status.rhw.atk; + if (range <= 1) + damage = sd->battle_status.rhw.atk; + else + damage = rnd()%range + sd->battle_status.rhw.atk; + script_pushint(st, sd->battle_status.batk+damage); + break; + case BF_MAGIC: + range = sd->battle_status.matk_max-sd->battle_status.matk_min; + if (range <= 1) + script_pushint(st, sd->battle_status.matk_min); + else + script_pushint(st, rnd()%range + sd->battle_status.matk_min); + break; + default: + ShowWarning("buildin_calcdmg: Invalid attack type %d!\n", attack_type); + script_pushint(st, 0); + return false; + } + + return true; + } + + // Nullity check for target if (bl == NULL) { ShowWarning("buildin_calcdmg: Error in finding object with given GID %d!\n", script_getnum(st, 3)); script_pushint(st, 0); -- cgit v1.2.3-60-g2f50