Skip to content

Commit 3a3482a

Browse files
committed
Merge remote-tracking branch 'origin/master' into rebalance
Signed-off-by: Haru <[email protected]>
2 parents e83b97c + 484691a commit 3a3482a

File tree

10 files changed

+128
-82
lines changed

10 files changed

+128
-82
lines changed

.mailmap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Guilherme G. Menaldo <[email protected]>
3232
Guilherme G. Menaldo <[email protected]> <[email protected]>
3333
Guilherme G. Menaldo <[email protected]> <[email protected]>
3434
35+
36+
3537
3638
3739

AUTHORS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jaBote <[email protected]>
7171
7272
7373
74-
jasonch <31005928+jasonch35@users.noreply.github.com>
74+
jasonch <jasonch35@gmail.com>
7575
7676
7777
Jesusaves <[email protected]>
@@ -80,7 +80,6 @@ jmanfffreak <[email protected]>
8080
8181
Jônatas Andreta <[email protected]>
8282
Jose Luis Rivera Flores <[email protected]>
83-
8483
8584
8685
@@ -180,6 +179,7 @@ tungsinpei <[email protected]>
180179
TungSinpei <[email protected]>
181180
ultramage <[email protected]>
182181
182+
183183
184184
185185
Vincent Thibault <[email protected]>

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,17 @@ All these changes only affect Renewal. Pre-renewal is unchanged.
792792

793793
- The `is_quest` argument to `pc->gainexp()` has been changed to a `flags` bitmask enum, in order to allow expansion to different flags. (#3279)
794794

795+
## [v2024.10] `October 2024`
796+
797+
### Changed
798+
799+
- Changed the `getmobdrops()` script command to avoid the use of global temporary variables. (#3319)
800+
- The caller now specifies an array that will be filled with the requested data.
801+
- The amount of filled entries will be returned as the command's return value. The caller should only read up to that amount of entries from the array, as it may contain previous leftover values past that point.
802+
- See the script_commands documentation for further details.
803+
- Improved the output of the `@mobinfo` atcommand to include item links for the mob drops, on clients that support it. Unsupported clients will gracefully fall back to just printing the names. #3328
804+
- Improved the output of the `@iteminfo` atcommand to include item links, on clients that support it. Unsupported clients will gracefully fall back to just printing the names. #3329
805+
795806
## [v2024.09] `September 2024`
796807

797808
### Added
@@ -3940,6 +3951,7 @@ Note: everything included in this release is part of PR #3198 which consists of
39403951
- New versioning scheme and project changelogs/release notes (#1853)
39413952

39423953
[Unreleased]: https://github.com/HerculesWS/Hercules/compare/stable...master
3954+
[v2024.10]: https://github.com/HerculesWS/Hercules/compare/v2024.09...v2024.10
39433955
[v2024.09]: https://github.com/HerculesWS/Hercules/compare/v2024.08...v2024.09
39443956
[v2024.08]: https://github.com/HerculesWS/Hercules/compare/v2024.06...v2024.08
39453957
[v2024.06]: https://github.com/HerculesWS/Hercules/compare/v2024.05...v2024.06

conf/messages.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@
13231323

13241324
// @iteminfo
13251325
1276: Please enter an item name/ID (usage: @ii/@iteminfo <item name/ID>).
1326-
1277: Item: '%s'/'%s'[%d] (%d) Type: %s | Extra Effect: %s
1326+
1277: Item: '%s'/'%s' (%d) Type: %s | Extra Effect: %s
13271327
1278: None
13281328
1279: With script
13291329
1280: NPC Buy:%dz, Sell:%dz | Weight: %.1f

doc/constants_pre-re.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4880,7 +4880,7 @@
48804880
### Server defines
48814881

48824882
- `PACKETVER`: 20190530
4883-
- `HERCULES_VERSION`: 202409000
4883+
- `HERCULES_VERSION`: 202410000
48844884
- `MAX_LEVEL`: 175
48854885
- `MAX_STORAGE`: 600
48864886
- `MAX_GUILD_STORAGE`: 500

doc/constants_re.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4878,7 +4878,7 @@
48784878
### Server defines
48794879

48804880
- `PACKETVER`: 20190530
4881-
- `HERCULES_VERSION`: 202409000
4881+
- `HERCULES_VERSION`: 202410000
48824882
- `MAX_LEVEL`: 175
48834883
- `MAX_STORAGE`: 600
48844884
- `MAX_GUILD_STORAGE`: 500

doc/script_commands.txt

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4364,54 +4364,25 @@ Example:
43644364

43654365
---------------------------------------
43664366

4367-
*getmobdrops(<mob id>)
4367+
*getmobdrops(<mob_id>, <item_id_array>{, <drop_rate_array>});
43684368

4369-
This command will find all drops of the specified mob and return the item
4370-
IDs and drop percentages into arrays of temporary global variables.
4371-
getmobdrops() returns true if successful and false if the mob ID doesn't
4372-
exist.
4373-
4374-
Upon executing this,
4375-
4376-
$@MobDrop_item[] is a global temporary number array which contains the
4377-
item IDs of the monster's drops.
4378-
4379-
$@MobDrop_rate[] is a global temporary number array which contains the
4380-
drop percentages of each item. (1 = .01%)
4381-
4382-
$@MobDrop_count is the number of item drops found.
4383-
4384-
Be sure to use $@MobDrop_count to go through the arrays, and not
4385-
'getarraysize', because the temporary global arrays are not cleared
4386-
between runs of 'getmobdrops'. If a mob with 7 item drops is looked up,
4387-
the arrays would have 7 elements. But if another mob is looked up and it
4388-
only has 5 item drops, the server will not clear the arrays for you,
4389-
overwriting the values instead. So in addition to returning the 5 item
4390-
drops, the 6th and 7th elements from the last call remain, and you will
4391-
get 5+2 item drops, of which the last 2 don't belong to the new mob.
4392-
$@MobDrop_count will always contain the correct number (5), unlike
4393-
getarraysize() which would return 7 in this case.
4369+
This command will find drops information of the specified <mob_id>, copy the
4370+
item ids on to <item_id_array> and drop rate on to <drop_rate_array> if provided.
4371+
Returns the number of items found. Will return 0 if <mob_id> is invalid.
43944372

43954373
Example:
4396-
43974374
// get a Mob ID from the user
43984375
input(.@mob_id);
43994376

4400-
if (getmobdrops(.@mob_id)) { // getmobdrops() returns true on success
4401-
// immediately copy global temporary variables into scope
4402-
// variables, since we don't know when getmobdrops() will get
4403-
// called again for another mob, overwriting your global temporary
4404-
// variables.
4405-
.@count = $@MobDrop_count;
4406-
copyarray(.@item[0], $@MobDrop_item[0], .@count);
4407-
copyarray(.@rate[0], $@MobDrop_rate[0], .@count);
4408-
4377+
.@count = getmobdrops(.@mob_id, .@item, .@rate);
4378+
4379+
if (.@count == 0) {
4380+
mes("No drops found.");
4381+
} else {
44094382
mes(getmonsterinfo(.@mob_id, MOB_NAME) + " - " + .@count + " drops found:");
44104383
for (.@i = 0; .@i < .@count; ++.@i) {
44114384
mes(.@item[.@i] + " (" + getitemname(.@item[.@i]) + ") " + .@rate[.@i]/100 + ((.@rate[.@i]%100 < 10) ? ".0":".") + .@rate[.@i]%100 + "%");
44124385
}
4413-
} else {
4414-
mes("Unknown monster ID.");
44154386
}
44164387
close();
44174388

src/config/core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define CONFIG_CORE_H
2323

2424
/// Hercules version. From tag vYYYY.MM(+PPP) -> YYYYMMPPP
25-
#define HERCULES_VERSION 202409000
25+
#define HERCULES_VERSION 202410000
2626

2727
/// Max number of items on @autolootid list
2828
#define AUTOLOOTITEM_SIZE 10

src/map/atcommand.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7156,14 +7156,14 @@ ACMD(mobinfo)
71567156
unsigned char msize[3][7] = {"Small", "Medium", "Large"};
71577157
unsigned char mrace[12][11] = {"Formless", "Undead", "Beast", "Plant", "Insect", "Fish", "Demon", "Demi-Human", "Angel", "Dragon", "Boss", "Non-Boss"};
71587158
unsigned char melement[10][8] = {"Neutral", "Water", "Earth", "Fire", "Wind", "Poison", "Holy", "Dark", "Ghost", "Undead"};
7159-
char atcmd_output2[CHAT_SIZE_MAX];
7159+
StringBuf buf;
71607160
struct item_data *item_data;
71617161
struct mob_db *monster, *mob_array[MAX_SEARCH];
71627162
int count;
71637163
int i, k;
71647164

71657165
memset(atcmd_output, '\0', sizeof(atcmd_output));
7166-
memset(atcmd_output2, '\0', sizeof(atcmd_output2));
7166+
StrBuf->Init(&buf);
71677167

71687168
if (!*message) {
71697169
clif->message(fd, msg_fd(fd, MSGTBL_MOBINFO_USAGE)); // Please enter a monster name/ID (usage: @mobinfo <monster_name_or_monster_ID>).
@@ -7253,23 +7253,22 @@ ACMD(mobinfo)
72537253
}
72547254
#endif
72557255

7256-
if (item_data->slot)
7257-
snprintf(atcmd_output2, sizeof(atcmd_output2), " - %s[%d] %02.02f%%", item_data->jname, item_data->slot, (float)droprate / 100);
7258-
else
7259-
snprintf(atcmd_output2, sizeof(atcmd_output2), " - %s %02.02f%%", item_data->jname, (float)droprate / 100);
7260-
7261-
strcat(atcmd_output, atcmd_output2);
7262-
7256+
struct item link_item = { 0 };
7257+
link_item.nameid = monster->dropitem[i].nameid;
7258+
StrBuf->AppendStr(&buf, " - ");
7259+
clif->format_itemlink(&buf, &link_item);
7260+
StrBuf->Printf(&buf, " %02.02f%%", (float)droprate / 100);
72637261
if (++j % 3 == 0) {
7264-
clif->message(fd, atcmd_output);
7265-
strcpy(atcmd_output, " ");
7262+
clif->message(fd, StrBuf->Value(&buf));
7263+
StrBuf->Clear(&buf);
72667264
}
72677265
}
72687266

72697267
if (j == 0)
72707268
clif->message(fd, msg_fd(fd, MSGTBL_MOBINFO_NO_DROPS)); // This monster has no drops.
72717269
else if (j % 3 != 0)
7272-
clif->message(fd, atcmd_output);
7270+
clif->message(fd, StrBuf->Value(&buf));
7271+
StrBuf->Clear(&buf);
72737272
// mvp
72747273
if (monster->mexp) {
72757274
snprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, MSGTBL_MOBINFO_MVP_BONUS_EXP), monster->mexp); // MVP Bonus EXP:%u
@@ -7282,19 +7281,21 @@ ACMD(mobinfo)
72827281
continue;
72837282
if (monster->mvpitem[i].p > 0) {
72847283
j++;
7285-
if(item_data->slot)
7286-
snprintf(atcmd_output2, sizeof(atcmd_output2), " %s%s[%d] %02.02f%%", j != 1 ? "- " : "", item_data->jname, item_data->slot, (float)monster->mvpitem[i].p / 100);
7287-
else
7288-
snprintf(atcmd_output2, sizeof(atcmd_output2), " %s%s %02.02f%%", j != 1 ? "- " : "", item_data->jname, (float)monster->mvpitem[i].p / 100);
7289-
strcat(atcmd_output, atcmd_output2);
7284+
struct item link_item = { 0 };
7285+
link_item.nameid = monster->mvpitem[i].nameid;
7286+
StrBuf->AppendStr(&buf, j != 1 ? " - " : "");
7287+
clif->format_itemlink(&buf, &link_item);
7288+
StrBuf->Printf(&buf, " %02.02f%%", (float)monster->mvpitem[i].p / 100);
72907289
}
72917290
}
7291+
72927292
if (j == 0)
72937293
clif->message(fd, msg_fd(fd, MSGTBL_MOBINFO_NO_MVP_PRIZES)); // This monster has no MVP prizes.
72947294
else
7295-
clif->message(fd, atcmd_output);
7295+
clif->message(fd, StrBuf->Value(&buf));
72967296
}
72977297
}
7298+
StrBuf->Destroy(&buf);
72987299
return true;
72997300
}
73007301

@@ -7717,14 +7718,22 @@ ACMD(iteminfo)
77177718
clif->message(fd, atcmd_output);
77187719
count = MAX_SEARCH;
77197720
}
7721+
StringBuf buf;
7722+
StrBuf->Init(&buf);
77207723
for (i = 0; i < count; i++) {
77217724
struct item_data *item_data = item_array[i];
77227725
if (item_data != NULL) {
7723-
snprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, MSGTBL_ITEMINFO_DETAILS), // Item: '%s'/'%s'[%d] (%d) Type: %s | Extra Effect: %s
7724-
item_data->name, item_data->jname, item_data->slot, item_data->nameid,
7726+
7727+
struct item link_item = { 0 };
7728+
link_item.nameid = item_data->nameid;
7729+
clif->format_itemlink(&buf, &link_item);
7730+
7731+
snprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, MSGTBL_ITEMINFO_DETAILS), // Item: '%s'/'%s' (%d) Type: %s | Extra Effect: %s
7732+
item_data->name, StrBuf->Value(&buf), item_data->nameid,
77257733
itemdb->typename(item_data->type),
77267734
(item_data->script == NULL) ? msg_fd(fd, MSGTBL_ITEMINFO_NONE) : msg_fd(fd, MSGTBL_ITEMINFO_WITH_SCRIPT) // None / With script
77277735
);
7736+
StrBuf->Clear(&buf);
77287737
clif->message(fd, atcmd_output);
77297738

77307739
snprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, MSGTBL_ITEMINFO_NPC_DETAILS), item_data->value_buy, item_data->value_sell, item_data->weight / 10.); // NPC Buy:%dz, Sell:%dz | Weight: %.1f
@@ -7741,6 +7750,7 @@ ACMD(iteminfo)
77417750
clif->message(fd, atcmd_output);
77427751
}
77437752
}
7753+
StrBuf->Destroy(&buf);
77447754
return true;
77457755
}
77467756

src/map/script.c

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12284,36 +12284,87 @@ static BUILDIN(monster)
1228412284
*------------------------------------------*/
1228512285
static BUILDIN(getmobdrops)
1228612286
{
12287-
int class_ = script_getnum(st,2);
12288-
int i, j = 0;
12289-
struct mob_db *monster;
12287+
struct map_session_data *sd = NULL;
12288+
int mob_id = script_getnum(st, 2);
12289+
struct mob_db *monster = NULL;
12290+
struct script_data *data1 = script_getdata(st, 3);
12291+
struct script_data *data2 = NULL;
12292+
const char *varname1 = NULL;
12293+
const char *varname2 = NULL;
12294+
int varid1 = 0;
12295+
int varid2 = 0;
12296+
int num = 0;
1229012297

12291-
if( !mob->db_checkid(class_) )
12292-
{
12298+
if (!data_isreference(data1) || reference_toconstant(data1)) {
12299+
ShowError("buildin_getmobdrops: Target argument must be a variable\n");
12300+
script->reportdata(data1);
12301+
st->state = END;
12302+
return false;
12303+
}
12304+
12305+
varname1 = reference_getname(data1);
12306+
varid1 = reference_getid(data1);
12307+
12308+
if (!is_int_variable(varname1)) {
12309+
ShowError("buildin_getmobdrops: Target argument must be an integer variable\n");
12310+
script->reportdata(data1);
12311+
st->state = END;
12312+
return false;
12313+
}
12314+
12315+
if (script_hasdata(st, 4)) {
12316+
data2 = script_getdata(st, 4);
12317+
12318+
if (!data_isreference(data2) || reference_toconstant(data2)) {
12319+
ShowError("buildin_getmobdrops: Target argument must be a variable\n");
12320+
script->reportdata(data1);
12321+
st->state = END;
12322+
return false;
12323+
}
12324+
12325+
varname2 = reference_getname(data2);
12326+
varid2 = reference_getid(data2);
12327+
12328+
if (data2 == NULL || !is_int_variable(varname2)) {
12329+
ShowError("buildin_getmobdrops: 2nd target argument must be an integer variable\n");
12330+
script->reportdata(data2);
12331+
st->state = END;
12332+
return false;
12333+
}
12334+
}
12335+
12336+
if (not_server_variable(*varname1) || (data2 != NULL && not_server_variable(*varname2))) {
12337+
sd = script->rid2sd(st);
12338+
if (sd == NULL) {
12339+
script_pushint(st, 0);
12340+
return true; // player variable but no player attached
12341+
}
12342+
}
12343+
12344+
monster = mob->db(mob_id);
12345+
12346+
if (!mob->db_checkid(mob_id) || monster == NULL) {
1229312347
script_pushint(st, 0);
1229412348
return true;
1229512349
}
1229612350

12297-
monster = mob->db(class_);
12298-
12299-
for( i = 0; i < MAX_MOB_DROP; i++ )
12300-
{
12301-
if( monster->dropitem[i].nameid < 1 )
12351+
for (int i = 0; i < MAX_MOB_DROP; i++) {
12352+
if (monster->dropitem[i].nameid < 1)
1230212353
continue;
12303-
if( itemdb->exists(monster->dropitem[i].nameid) == NULL )
12354+
if (itemdb->exists(monster->dropitem[i].nameid) == NULL)
1230412355
continue;
1230512356

12306-
mapreg->setreg(reference_uid(script->add_variable("$@MobDrop_item"), j), monster->dropitem[i].nameid);
12307-
mapreg->setreg(reference_uid(script->add_variable("$@MobDrop_rate"), j), monster->dropitem[i].p);
12308-
12309-
j++;
12357+
script->set_reg(st, sd, reference_uid(varid1, num), varname1, (const void *)h64BPTRSIZE(monster->dropitem[i].nameid), reference_getref(data1));
12358+
if (data2 != NULL)
12359+
script->set_reg(st, sd, reference_uid(varid2, num), varname2, (const void *)h64BPTRSIZE(monster->dropitem[i].p), reference_getref(data2));
12360+
num++;
1231012361
}
1231112362

12312-
mapreg->setreg(script->add_variable("$@MobDrop_count"), j);
12313-
script_pushint(st, 1);
12363+
script_pushint(st, num);
1231412364

1231512365
return true;
1231612366
}
12367+
1231712368
/*==========================================
1231812369
* Same as monster but randomize location in x0,x1,y0,y1 area
1231912370
*------------------------------------------*/
@@ -29110,7 +29161,7 @@ static void script_parse_builtin(void)
2911029161
BUILDIN_DEF(produce,"i"),
2911129162
BUILDIN_DEF(cooking,"i"),
2911229163
BUILDIN_DEF(monster,"siisii???"),
29113-
BUILDIN_DEF(getmobdrops,"i"),
29164+
BUILDIN_DEF(getmobdrops,"ii?"),
2911429165
BUILDIN_DEF(areamonster,"siiiisii???"),
2911529166
BUILDIN_DEF(killmonster,"ss?"),
2911629167
BUILDIN_DEF(killmonsterall,"s?"),

0 commit comments

Comments
 (0)