summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2020-05-28 19:27:45 -0300
committerJesusaves <cpntb1@ymail.com>2020-05-28 19:27:45 -0300
commit09f8f82adc63b21ca4a2ec950c1cbddb67224b82 (patch)
tree58113e8c6f61af87a4572871aedd8ca5a712f22b /src
parent70a351a62fd5ef8ef144964b1aafcb6a0b23b89f (diff)
downloadevol-hercules-09f8f82adc63b21ca4a2ec950c1cbddb67224b82.tar.gz
evol-hercules-09f8f82adc63b21ca4a2ec950c1cbddb67224b82.tar.bz2
evol-hercules-09f8f82adc63b21ca4a2ec950c1cbddb67224b82.tar.xz
evol-hercules-09f8f82adc63b21ca4a2ec950c1cbddb67224b82.zip
Theoretical fix for crafting.
getinventorylist() will now be reliable enough to determine item indexes. Be careful when looping. Hopefully, Nicholas rotten code was squashed.
Diffstat (limited to 'src')
-rw-r--r--src/emap/init.c1
-rw-r--r--src/emap/script_buildins.c72
-rw-r--r--src/emap/script_buildins.h1
3 files changed, 67 insertions, 7 deletions
diff --git a/src/emap/init.c b/src/emap/init.c
index 7ad68b9..ec71882 100644
--- a/src/emap/init.c
+++ b/src/emap/init.c
@@ -243,6 +243,7 @@ HPExport void plugin_init (void)
addScriptCommand("debugmes","v*",debugmes);
addScriptCommand("countitem","v?",countitem);
addScriptCommand("atcommand","s",atcommand);
+ addScriptCommand("getinventorylist","",getinventorylist);
do_init_langs();
diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c
index 6de1af0..352e614 100644
--- a/src/emap/script_buildins.c
+++ b/src/emap/script_buildins.c
@@ -3027,6 +3027,61 @@ BUILDIN(countitem)
return true;
}
+/*==========================================
+ * Set arrays with info of all sd inventory :
+ * @inventorylist_id, @inventorylist_amount, @inventorylist_equip,
+ * @inventorylist_refine, @inventorylist_identify, @inventorylist_attribute,
+ * @inventorylist_card(0..3),
+ * @inventorylist_opt_id(0..MAX_ITEM_OPTIONS),
+ * @inventorylist_opt_val(0..MAX_ITEM_OPTIONS),
+ * @inventorylist_opt_param(0..MAX_ITEM_OPTIONS),
+ * @inventorylist_expire, @inventorylist_bound, @inventorylist_favorite,
+ * @inventorylist_idx
+ * @inventorylist_count = scalar
+ *------------------------------------------*/
+BUILDIN(getinventorylist)
+{
+ struct map_session_data *sd = script->rid2sd(st);
+ char script_var[SCRIPT_VARNAME_LENGTH];
+ int j = 0, k = 0;
+
+ if (sd == NULL)
+ return true;
+
+ // This implementation allows empty slots to be filled
+ for (int i = 0; i < sd->status.inventorySize; i++) {
+ pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_id"), j), sd->status.inventory[i].nameid);
+ pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_amount"), j), sd->status.inventory[i].amount);
+ if (sd->status.inventory[i].equip != 0) {
+ pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_equip"), j), pc->equippoint(sd, i));
+ } else {
+ pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_equip"), j), 0);
+ }
+ pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_refine"), j), sd->status.inventory[i].refine);
+ pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_identify"), j), sd->status.inventory[i].identify);
+ pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_attribute"), j), sd->status.inventory[i].attribute);
+ for (k = 0; k < MAX_SLOTS; k++) {
+ sprintf(script_var, "@inventorylist_card%d", k + 1);
+ pc->setreg(sd, reference_uid(script->add_variable(script_var), j), sd->status.inventory[i].card[k]);
+ }
+ for (k = 0; k < MAX_ITEM_OPTIONS; k++) {
+ sprintf(script_var, "@inventorylist_opt_id%d", k + 1);
+ pc->setreg(sd, reference_uid(script->add_variable(script_var), j), sd->status.inventory[i].option[k].index);
+ sprintf(script_var, "@inventorylist_opt_val%d", k + 1);
+ pc->setreg(sd, reference_uid(script->add_variable(script_var), j), sd->status.inventory[i].option[k].value);
+ sprintf(script_var, "@inventorylist_opt_param%d", k + 1);
+ pc->setreg(sd, reference_uid(script->add_variable(script_var), j), sd->status.inventory[i].option[k].param);
+ }
+ pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_expire"), j), sd->status.inventory[i].expire_time);
+ pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_bound"), j), sd->status.inventory[i].bound);
+ pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_favorite"), j), sd->status.inventory[i].favorite);
+ pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_idx"), j), i);
+ j++;
+ }
+ pc->setreg(sd, script->add_variable("@inventorylist_count"), j);
+ return true;
+}
+
// Returns the Acc. ID of the owner of an instance
BUILDIN(InstanceOwner)
@@ -3094,16 +3149,14 @@ BUILDIN(aggravate)
// harm(guid, raw_damage, type)
BUILDIN(harm)
{
+ struct block_list *src;
struct block_list *bl;
struct map_session_data *sd = NULL;
- struct block_list *src;
+ int attack_type = BF_MISC;
- // Target and raw damage
+ // Fill data from scripts
bl = map->id2bl(script_getnum(st, 2));
int dmg = script_getnum(st, 3);
-
- // Attack type
- int attack_type = BF_MISC;
if (script_hasdata(st,4)) {
attack_type = script_getnum(st,4);
}
@@ -3114,11 +3167,16 @@ BUILDIN(harm)
script_pushint(st, 0);
return false;
}
+
+ // Overflow checks
if( dmg == INT_MIN ) dmg++;
if( dmg == INT_MAX ) dmg--;
- // Source (sd), might be null, in this case we set source to yourself
- sd = script->rid2sd(st);
+ // Source (sd), might be null
+ if(st->rid != 0 && map->id2sd(st->rid) != NULL)
+ sd = script->rid2sd(st);
+
+ // Default source to self if needed
if (sd == NULL) {
src = bl;
} else {
diff --git a/src/emap/script_buildins.h b/src/emap/script_buildins.h
index 716f332..6a9d5d6 100644
--- a/src/emap/script_buildins.h
+++ b/src/emap/script_buildins.h
@@ -127,5 +127,6 @@ BUILDIN(resetrng);
BUILDIN(countitem);
BUILDIN(debugmes);
BUILDIN(atcommand);
+BUILDIN(getinventorylist);
#endif // EVOL_MAP_SCRIPT_BUILDINS