diff options
author | Jesusaves <cpntb1@ymail.com> | 2025-03-29 01:20:33 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2025-03-29 01:20:56 -0300 |
commit | 868b00768b3a94a2fb87bbcc90e9a1442e85fc0f (patch) | |
tree | 9743e4cd9a2a1ed912f89b9aeee93220fbb98caf | |
parent | b86071ad388553171aa22558baffdf5adc9df02b (diff) | |
download | evol-hercules-868b00768b3a94a2fb87bbcc90e9a1442e85fc0f.tar.gz evol-hercules-868b00768b3a94a2fb87bbcc90e9a1442e85fc0f.tar.bz2 evol-hercules-868b00768b3a94a2fb87bbcc90e9a1442e85fc0f.tar.xz evol-hercules-868b00768b3a94a2fb87bbcc90e9a1442e85fc0f.zip |
Fix some tabulation/spacing issues + additional command
-rw-r--r-- | src/emap/init.c | 1 | ||||
-rw-r--r-- | src/emap/script_buildins.c | 338 | ||||
-rw-r--r-- | src/emap/script_buildins.h | 1 |
3 files changed, 201 insertions, 139 deletions
diff --git a/src/emap/init.c b/src/emap/init.c index a9f8686..f71cca1 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -252,6 +252,7 @@ HPExport void plugin_init (void) addScriptCommand("npc_duplicate_remove", "?", npc_duplicate_remove); addScriptCommand("apicall", "is", apicall); addScriptCommand("apiasync", "ss", apiasync); + addScriptCommand("unstoreall", "i", unstoreall); // Overrides addScriptCommand("debugmes","v*",debugmes); diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c index 9acbf7c..38ab767 100644 --- a/src/emap/script_buildins.c +++ b/src/emap/script_buildins.c @@ -2987,11 +2987,11 @@ BUILDIN(homstatus) return true; // Return the status (0 - active; 1 - resting ; 2 - mission) - // BUT Dead homunculus is not active (send RESTING instead) + // BUT Dead homunculus is not active (send RESTING instead) if (!sd->hd->homunculus.vaporize && !homun_alive(sd->hd)) - script_pushint(st,1); - else - script_pushint(st,sd->hd->homunculus.vaporize); + script_pushint(st,1); + else + script_pushint(st,sd->hd->homunculus.vaporize); return true; } @@ -3023,32 +3023,32 @@ BUILDIN(sethomunclass) int base=0; struct map_session_data *sd = script->rid2sd(st); - // Player and Homunculus exist? + // Player and Homunculus exist? if (sd == NULL || sd->hd == NULL) { - script_pushint(st, -1); + script_pushint(st, -1); return true; - } + } - // Argument parsing + // Argument parsing base = script_getnum(st,2); if (base < 1) { - script_pushint(st, -3); + script_pushint(st, -3); return true; - } + } - // Is the homunculus active? + // Is the homunculus active? if (sd->hd->homunculus.vaporize || !homun_alive(sd->hd)) { - script_pushint(st, -2); + script_pushint(st, -2); return true; - } + } - // Attempt to change class + // Attempt to change class if (!homun->change_class(sd->hd, base)) { - script_pushint(st, -4); + script_pushint(st, -4); return true; - } + } - // Everything went fine! + // Everything went fine! script_pushint(st, 0); return true; } @@ -3063,22 +3063,22 @@ BUILDIN(sethomunlevel) int base=0; struct map_session_data *sd = script->rid2sd(st); - // Player and Homunculus exist? + // Player and Homunculus exist? if (sd == NULL || sd->hd == NULL) return true; - // Argument parsing + // Argument parsing base = script_getnum(st,2); if (base < 1) return true; - // Modify the level - sd->hd->homunculus.level = base; + // Modify the level + sd->hd->homunculus.level = base; - // Shuffle status afterwards - homun->shuffle(sd->hd); + // Shuffle status afterwards + homun->shuffle(sd->hd); - return true; + return true; } @@ -3091,7 +3091,7 @@ BUILDIN(readparam2) struct map_session_data *sd; int data = script_getnum(st,2); - // Account ID/Player Name is also supported + // Account ID/Player Name is also supported if (script_hasdata(st, 3)) { if (script_isstringtype(st, 3)) { sd = script->nick2sd(st, script_getstr(st, 3)); @@ -3102,48 +3102,48 @@ BUILDIN(readparam2) sd = script->rid2sd(st); } - // Error + // Error if (sd == NULL) { script_pushint(st, -1); return true; } - switch (data) { - case 13: - script_pushint(st, sd->battle_status.str); - break; - case 14: - script_pushint(st, sd->battle_status.agi); - break; - case 15: - script_pushint(st, sd->battle_status.vit); - break; - case 16: - script_pushint(st, sd->battle_status.int_); - break; - case 17: - script_pushint(st, sd->battle_status.dex); - break; - case 18: - script_pushint(st, sd->battle_status.luk); - break; - case 6: - script_pushint(st, sd->battle_status.max_hp); - break; - case 8: - script_pushint(st, sd->battle_status.max_sp); - break; - case 45: - script_pushint(st, sd->battle_status.def); - break; - case 41: - script_pushint(st, sd->battle_status.batk+sd->battle_status.rhw.atk); - break; - default: - ShowError("Wrong paramType in readparam2(%d)\nAre you sure you used bonus constants?\nSupported values: bMaxHP, bMaxSP, bStr, bAgi, bVit, bInt, bDex, bLuk, bAtk, bDef\n", data); - script_pushint(st, -1); - break; - } + switch (data) { + case 13: + script_pushint(st, sd->battle_status.str); + break; + case 14: + script_pushint(st, sd->battle_status.agi); + break; + case 15: + script_pushint(st, sd->battle_status.vit); + break; + case 16: + script_pushint(st, sd->battle_status.int_); + break; + case 17: + script_pushint(st, sd->battle_status.dex); + break; + case 18: + script_pushint(st, sd->battle_status.luk); + break; + case 6: + script_pushint(st, sd->battle_status.max_hp); + break; + case 8: + script_pushint(st, sd->battle_status.max_sp); + break; + case 45: + script_pushint(st, sd->battle_status.def); + break; + case 41: + script_pushint(st, sd->battle_status.batk+sd->battle_status.rhw.atk); + break; + default: + ShowError("Wrong paramType in readparam2(%d)\nAre you sure you used bonus constants?\nSupported values: bMaxHP, bMaxSP, bStr, bAgi, bVit, bInt, bDex, bLuk, bAtk, bDef\n", data); + script_pushint(st, -1); + break; + } return true; } @@ -3162,7 +3162,7 @@ BUILDIN(debugmes) return false; } - // FIXME: SECURITY VULNERABILITY: Must be escaped or \n might trigger HCP + // FIXME: SECURITY VULNERABILITY: Must be escaped or \n might trigger HCP ShowDebug("script debug : %d %d : %s\n", st->rid, st->oid, StrBuf->Value(&buf)); StrBuf->Destroy(&buf); script_pushint(st, 1); @@ -3183,7 +3183,7 @@ BUILDIN(consolewarn) return false; } - // FIXME: SECURITY VULNERABILITY: Must be escaped or \n might trigger HCP + // FIXME: SECURITY VULNERABILITY: Must be escaped or \n might trigger HCP ShowWarning("script warning : %d %d : %s\n", st->rid, st->oid, StrBuf->Value(&buf)); StrBuf->Destroy(&buf); script_pushint(st, 1); @@ -3204,7 +3204,7 @@ BUILDIN(consolebug) return false; } - // FIXME: SECURITY VULNERABILITY: Must be escaped or \n might trigger HCP + // FIXME: SECURITY VULNERABILITY: Must be escaped or \n might trigger HCP ShowError("script error : %d %d : %s\n", st->rid, st->oid, StrBuf->Value(&buf)); StrBuf->Destroy(&buf); script_pushint(st, 1); @@ -3225,9 +3225,9 @@ BUILDIN(consoleinfo) return false; } - // FIXME: SECURITY VULNERABILITY: Must be escaped or \n might trigger HCP + // FIXME: SECURITY VULNERABILITY: Must be escaped or \n might trigger HCP ShowDebug("script notice : %d %d : %s\n", st->rid, st->oid, StrBuf->Value(&buf)); - // FIXME: SECURITY VULNERABILITY: Must be escaped or \n might trigger HCP + // FIXME: SECURITY VULNERABILITY: Must be escaped or \n might trigger HCP ShowNotice("%s\n", StrBuf->Value(&buf)); StrBuf->Destroy(&buf); script_pushint(st, 1); @@ -3342,7 +3342,7 @@ BUILDIN(getinventorylist) if (sd == NULL) return true; - // This implementation allows empty slots to be filled + // 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); @@ -3380,19 +3380,19 @@ BUILDIN(getinventorylist) // Returns the Acc. ID of the owner of an instance BUILDIN(InstanceOwner) { - const int instance_id = script_getnum(st, 2); + const int instance_id = script_getnum(st, 2); - // Do instance exists? - if (!instance->valid(instance_id)) { - script_pushint(st, false); - return true; - } + // Do instance exists? + if (!instance->valid(instance_id)) { + script_pushint(st, false); + return true; + } - // Note: This does not returns type! - // using this against party/guilds instances not advised. - // returns 0 if either instance doesn't exists or is global - script_pushint(st, (int)instance->list[instance_id].owner_id); - return true; + // Note: This does not returns type! + // using this against party/guilds instances not advised. + // returns 0 if either instance doesn't exists or is global + script_pushint(st, (int)instance->list[instance_id].owner_id); + return true; } @@ -3405,7 +3405,7 @@ BUILDIN(aggravate) bl = map->id2bl(script_getnum(st, 2)); - // We only work with mobs + // We only work with mobs if (bl == NULL) { ShowWarning("buildin_aggravate: Error in finding object with given GID %d!\n", script_getnum(st, 2)); script_pushint(st, -1); @@ -3418,23 +3418,23 @@ BUILDIN(aggravate) return false; } - // Player must be attached + // Player must be attached sd = script->rid2sd(st); if (sd == NULL) { ShowWarning("buildin_aggravate: Ran without player attached!"); return true; - } + } - // Create monster structure + // Create monster structure struct mob_data *md = BL_UCAST(BL_MOB, bl); - // Override the provoke flag - md->state.provoke_flag = sd->status.account_id; - // We could use mob->target() - // But I want aggravate to apply without any checks - // Skipping chase checks - md->target_id = sd->status.account_id; - return true; + // Override the provoke flag + md->state.provoke_flag = sd->status.account_id; + // We could use mob->target() + // But I want aggravate to apply without any checks + // Skipping chase checks + md->target_id = sd->status.account_id; + return true; } // Returns the estimated damage (ATK or MATK) @@ -3453,41 +3453,41 @@ BUILDIN(calcdmg) bl = map->id2bl(script_getnum(st, 3)); attack_type = script_getnum(st,4); - // Nullity check for source + // 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; - damage = damage + rnd()%sd->battle_status.batk; - script_pushint(st, 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; - } - + // 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; + damage = damage + rnd()%sd->battle_status.batk; + script_pushint(st, 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) { @@ -3540,15 +3540,15 @@ BUILDIN(harm) src = map->id2bl(script_getnum(st, 6)); } else if (st->rid != 0 && map->id2sd(st->rid) != NULL) { struct map_session_data *sd = script->rid2sd(st); - // Default source to self if needed - if (sd == NULL) { - src = bl; - } else { - src = &sd->bl; - } - } else { - src = bl; - } + // Default source to self if needed + if (sd == NULL) { + src = bl; + } else { + src = &sd->bl; + } + } else { + src = bl; + } // Nullity checks if (bl == NULL) { @@ -3560,7 +3560,7 @@ BUILDIN(harm) // Nullity checks which a fallback exists if (src == NULL) { ShowWarning("buildin_harm: Invalid source!\n"); - src = bl; + src = bl; } // Overflow checks @@ -3619,15 +3619,15 @@ BUILDIN(resetrng) *------------------------------------------*/ BUILDIN(getskillname) { - int skill_id = script_getnum(st, 2); + int skill_id = script_getnum(st, 2); - if (skill_id < 0) { - script_pushstr(st, ""); - return false; - } + if (skill_id < 0) { + script_pushstr(st, ""); + return false; + } - script_pushstrcopy(st, skill->get_desc(skill_id)); - return true; + script_pushstrcopy(st, skill->get_desc(skill_id)); + return true; } BUILDIN(bgnew) @@ -3663,12 +3663,12 @@ BUILDIN(bgnew) BUILDIN(bgjoin) { - int bgId = script_getnum(st, 2); + int bgId = script_getnum(st, 2); const char* map_name = script_getstr(st, 3); int x = script_getnum(st,4); int y = script_getnum(st,5); struct map_session_data *sd; - int map_index; + int map_index; if( (map_index = script->mapindexname2id(st,map_name)) == 0 ) return true; // Invalid Map @@ -3711,7 +3711,7 @@ BUILDIN(npc_duplicate) { int txs = -1; int tys = -1; - int tdir = 0; + int tdir = 0; if (script_hasdata(st, 9)) txs = script_getnum(st, 9); @@ -3787,7 +3787,7 @@ BUILDIN(npc_duplicate) int tx = script_getnum(st, 5); int ty = script_getnum(st, 6); if (script_hasdata(st, 8)) - tdir = script_getnum(st, 8); + tdir = script_getnum(st, 8); ShowDebug("Dir %d at (%d,%d)\n", tdir, tx, ty); #if 0 @@ -3934,3 +3934,63 @@ BUILDIN(apiasync) } */ + +/*========================================== + * Moves a storage to inventory (DANGER) + *------------------------------------------*/ +BUILDIN(unstoreall) +{ + struct map_session_data *sd = script->rid2sd(st); + int storage_id = script_getnum(st, 2); + + sd->storage.access = STORAGE_ACCESS_ALL; // Default storage access for atcommands. + + struct storage_data *stor = NULL; + if ((stor = storage->ensure(sd, storage_id)) == NULL) { + ShowError("buildin_unstoreall: Error ensuring storage for player %d, storage_id %d\n", sd->bl.id, storage_id); + script_pushint(st, 0); + return false; + } + + if (sd->state.storage_flag != STORAGE_FLAG_NORMAL) { + //Open storage. + if (storage->open(sd, stor) == 1) { + ShowError("buildin_unstoreall: Failed to open storage for player %d, storage_id %d!\n", sd->bl.id, storage_id); + script_pushint(st, 0); + return false; + } + } + + if (!stor->received) { + ShowError("buildin_unstoreall: Storage wasn't yet loaded for player %d, storage_id %d!\n", sd->bl.id, storage_id); + script_pushint(st, 0); + return false; + } + + // storage->get(struct map_session_data *sd, struct storage_data *stor, int index, int amount) + // storage->sortitem(VECTOR_DATA(stor->item), VECTOR_LENGTH(stor->item)); + //struct item *it = &VECTOR_INDEX(stor->item, index); + + for (int i = 0; i < VECTOR_LENGTH(stor->item); i++) { + struct item *it = &VECTOR_INDEX(stor->item, i); + storage->get(sd, stor, i, it->amount); + } + + /* + for (int i = 0; i < sd->status.inventorySize; i++) { + if (sd->status.inventory[i].amount) { + if(sd->status.inventory[i].equip != 0) + pc->unequipitem(sd, i, PCUNEQUIPITEM_RECALC|PCUNEQUIPITEM_FORCE); + storage->add(sd, stor, i, sd->status.inventory[i].amount); + } + } + */ + + storage->close(sd); + + script_pushint(st, 1); + return true; +} + + + diff --git a/src/emap/script_buildins.h b/src/emap/script_buildins.h index 3d0fdde..4a6d936 100644 --- a/src/emap/script_buildins.h +++ b/src/emap/script_buildins.h @@ -136,6 +136,7 @@ BUILDIN(npc_duplicate); BUILDIN(npc_duplicate_remove); BUILDIN(apicall); BUILDIN(apiasync); +BUILDIN(unstoreall); // Overrides BUILDIN(countitem); |