summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2020-06-07 01:06:02 -0300
committerJesusaves <cpntb1@ymail.com>2020-06-07 01:06:02 -0300
commitcd1c981d5de6c599679cadbb09cc6bb07bad0908 (patch)
tree7bd05ae2ee0c17c7e3d2fc4870769c4b6379ac91 /src
parent09f8f82adc63b21ca4a2ec950c1cbddb67224b82 (diff)
downloadevol-hercules-cd1c981d5de6c599679cadbb09cc6bb07bad0908.tar.gz
evol-hercules-cd1c981d5de6c599679cadbb09cc6bb07bad0908.tar.bz2
evol-hercules-cd1c981d5de6c599679cadbb09cc6bb07bad0908.tar.xz
evol-hercules-cd1c981d5de6c599679cadbb09cc6bb07bad0908.zip
Update harm() - It now accepts element, and now uses raw damage.
Add new command: calcdmg(src, target, type). It calcs ATK or MATK. Already taking in account everything.
Diffstat (limited to 'src')
-rw-r--r--src/emap/init.c3
-rw-r--r--src/emap/script_buildins.c121
-rw-r--r--src/emap/script_buildins.h1
3 files changed, 88 insertions, 37 deletions
diff --git a/src/emap/init.c b/src/emap/init.c
index ec71882..8cfa95d 100644
--- a/src/emap/init.c
+++ b/src/emap/init.c
@@ -236,7 +236,8 @@ HPExport void plugin_init (void)
addScriptCommand("npcshopattach","s?",npcshopattach);
addScriptCommand("instanceowner", "i", InstanceOwner);
addScriptCommand("aggravate", "i", aggravate);
- addScriptCommand("harm", "ii?", harm);
+ addScriptCommand("calcdmg", "iii", calcdmg);
+ addScriptCommand("harm", "ii??", harm);
addScriptCommand("resetrng", "", resetrng);
// Overrides
diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c
index 352e614..314d01a 100644
--- a/src/emap/script_buildins.c
+++ b/src/emap/script_buildins.c
@@ -29,6 +29,7 @@
#include "map/refine.h"
#include "map/script.h"
#include "map/quest.h"
+#include "map/map.h"
#include "emap/clif.h"
#include "emap/craft.h"
@@ -3143,23 +3144,73 @@ BUILDIN(aggravate)
return true;
}
+// Returns the estimated damage (ATK or MATK)
+// Advantage over getunitdata is: Takes crit and etc. in account
+// types: 1- physical; 2- magic.
+// calcdmg(source, target, type)
+BUILDIN(calcdmg)
+{
+ struct block_list *src;
+ struct block_list *bl;
+ int attack_type;
+
+ // 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
+ 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;
+ }
+ if (bl == NULL) {
+ ShowWarning("buildin_calcdmg: Error in finding object with given GID %d!\n", script_getnum(st, 3));
+ script_pushint(st, 0);
+ return false;
+ }
+
+ // Get ATK or MATK
+ struct Damage d;
+ switch(attack_type) {
+ case BF_WEAPON: d = battle->calc_weapon_attack(src, bl, 0,0,0); break;
+ case BF_MAGIC: d = battle->calc_magic_attack(src, bl, 0,0,0); break;
+ default:
+ ShowWarning("buildin_calcdmg: Invalid attack type %d!\n", attack_type);
+ script_pushint(st, 0);
+ return false;
+ break;
+ }
+
+ script_pushint(st, d.damage);
+ return true;
+}
+
// Like heal() but works against anything (casts battle funcs)
// types: 1- physical; 2- magic.
// Any other number: misc (no calculation)
-// harm(guid, raw_damage, type)
+// harm(guid, raw_damage, {type{, element}})
BUILDIN(harm)
{
struct block_list *src;
struct block_list *bl;
+ struct status_data *tstatus;
struct map_session_data *sd = NULL;
int attack_type = BF_MISC;
+ short elemental = ELE_NEUTRAL;
// Fill data from scripts
bl = map->id2bl(script_getnum(st, 2));
int dmg = script_getnum(st, 3);
+ // Attack Type
if (script_hasdata(st,4)) {
attack_type = script_getnum(st,4);
}
+ // Attack Element
+ if (script_hasdata(st,5)) {
+ elemental = script_getnum(st,5);
+ }
// Nullity checks
if (bl == NULL) {
@@ -3183,30 +3234,53 @@ BUILDIN(harm)
src = &sd->bl;
}
- // Damage struct
- struct Damage d;
+ // Calculate defese (unaffected if not BF_WEAPON nor BF_MAGIC)
switch(attack_type) {
- case BF_WEAPON: d = battle->calc_weapon_attack(src, bl, 0,0,0); break;
- case BF_MAGIC: d = battle->calc_magic_attack(src, bl, 0,0,0); break;
- default:
- d.damage=d.damage2=dmg;
- break;
+ case BF_WEAPON: dmg = battle->calc_defense(BF_WEAPON, src, bl, 0, 0, dmg, 0, 0); break;
+ case BF_MAGIC: dmg = battle->calc_defense(BF_MAGIC, src, bl, 0, 0, dmg, 0, 0); break;
}
- // Update raw damage with real damage
- dmg = d.damage;
+ // Elemental fix
+ tstatus = status->get_status_data(bl);
+ dmg=battle->attr_fix(src, bl, dmg, elemental, tstatus->def_ele, tstatus->ele_lv);
// Apply the damage, skip any other checks or whatelse
if ( dmg ) {
if (dmg < 0)
status->heal(bl, -dmg, 0, STATUS_HEAL_DEFAULT);
else {
- // status_damage(struct block_list *src, struct block_list *target, int64 in_hp, int64 in_sp, int walkdelay, int flag)
+ // status_damage(*src, *target, in_hp, in_sp, walkdelay, flag)
status->damage(src, bl, dmg, 0, 0, 0);
clif->damage(src, bl, 0, 0, dmg, 0, BDT_ENDURE, 0);
}
}
+ script_pushint(st, dmg);
+ return true;
+}
+
+
+/*==========================================
+ * Resets RNG seed
+ *------------------------------------------*/
+BUILDIN(resetrng)
+{
+ //rnd->init();
+ unsigned int seed;
+ double tmp;
+ // Reinitialize the random number generator
+ srand(time(NULL));
+
+ // Define a new seed
+ tmp=1.0 * rand() / RAND_MAX; // Ranges from [0;1]
+ seed=tmp * UINT_MAX; // Ranges from 0 to 4294967294 (It'll never be 100%)
+ rnd->seed(seed);
+ printf("\n\nWARNING\n\nRandomness seed updated to %u\n\n", seed);
+ script_pushint(st, 0);
+ return true;
+}
+
+//////////////////////////////////////////////////////////
/*
switch (bl->type) {
case BL_MOB:
@@ -3241,28 +3315,3 @@ BUILDIN(harm)
}
*/
- script_pushint(st, dmg);
- return true;
-}
-
-
-/*==========================================
- * Resets RNG seed
- *------------------------------------------*/
-BUILDIN(resetrng)
-{
- //rnd->init();
- unsigned int seed;
- double tmp;
- // Reinitialize the random number generator
- srand(time(NULL));
-
- // Define a new seed
- tmp=1.0 * rand() / RAND_MAX; // Ranges from [0;1]
- seed=tmp * UINT_MAX; // Ranges from 0 to 4294967294 (It'll never be 100%)
- rnd->seed(seed);
- printf("\n\nWARNING\n\nRandomness seed updated to %u\n\n", seed);
- script_pushint(st, 0);
- return true;
-}
-
diff --git a/src/emap/script_buildins.h b/src/emap/script_buildins.h
index 6a9d5d6..ef10c78 100644
--- a/src/emap/script_buildins.h
+++ b/src/emap/script_buildins.h
@@ -120,6 +120,7 @@ BUILDIN(homstatus);
BUILDIN(readparam2);
BUILDIN(InstanceOwner);
BUILDIN(aggravate);
+BUILDIN(calcdmg);
BUILDIN(harm);
BUILDIN(resetrng);