Updated Item Group features (#2692)

* Added config to hide last chars of player's name `broadcast_hide_name` and its default value is 2.
* Fixed `getgroupitem` that should give unidentified item for equipment types.
* Added optional param for `getgroupitem` and `getrandgroupitem` to always give player identified item, ignores the `itemdb_isidentified`'s check.
* Thanks to @aleos89 @Lemongrass3110
This commit is contained in:
Cydh Ramdh 2018-01-02 12:55:52 +07:00 committed by GitHub
parent fb966a12e0
commit 32950ecead
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 19 deletions

View File

@ -121,3 +121,9 @@ allow_bound_sell: 0x0
// no = normal refine chances in effect (official/default value)
// yes = event refine chances in effect
event_refine_chance: no
// Hide n last characters of player's name with asterisk (*) when the player
// obtained an item with special broadcast flag.
// Note: Players with short names can be fully converted to asterisks if this
// config value is set high.
broadcast_hide_name: 2

View File

@ -4864,7 +4864,7 @@ More info, see doc/item_group.txt.
---------------------------------------
*getrandgroupitem <group_id>{,<quantity>{,<sub_group>}};
*getrandgroupitem <group_id>{,<quantity>{,<sub_group>{,<identify>{,<char_id>}}}};
Similar to the above example, this command allows players to obtain the specified
quantity of a random item from the group "<group id>". The different groups and
@ -4875,16 +4875,24 @@ If 'quantity' is not defined or 0, it will uses defined amount from Item Group l
If 'sub_group' is not defined the value will be 1 (since random group is 1 ~ 5, and 0 is
'must' item group).
For item with type IT_WEAPON, IT_ARMOR, IT_PETARMOR, and IT_SHADOWGEAR will be given
as unidentified item (as defined by itemdb_isidentified in src/map/itemdb.cpp) except
if 'identify' is defined with value 1.
More info, see doc/item_group.txt.
---------------------------------------
*getgroupitem <group_id>{,<char_id>};
*getgroupitem <group_id>{,<identify>{,<char_id>}};
Gives item(s) to the attached player based on item group contents.
This is not working like 'getrandgroupitem' which only give 1 item for specified
item group & sub_group.
For item with type IT_WEAPON, IT_ARMOR, IT_PETARMOR, and IT_SHADOWGEAR will be given
as unidentified item (as defined by itemdb_isidentified in src/map/itemdb.cpp) except
if 'identify' is defined with value 1.
More info, see doc/item_group.txt.
---------------------------------------

View File

@ -8492,6 +8492,7 @@ static const struct _battle_data {
{ "allow_bound_sell", &battle_config.allow_bound_sell, 0, 0, 0x3, },
{ "event_refine_chance", &battle_config.event_refine_chance, 0, 0, 1, },
{ "autoloot_adjust", &battle_config.autoloot_adjust, 0, 0, 1, },
{ "broadcast_hide_name", &battle_config.broadcast_hide_name, 2, 0, NAME_LENGTH, },
#include "../custom/battle_config_init.inc"
};

View File

@ -637,6 +637,7 @@ struct Battle_Config
int allow_bound_sell;
int event_refine_chance;
int autoloot_adjust;
int broadcast_hide_name;
#include "../custom/battle_config_struct.inc"
};

View File

@ -19521,7 +19521,7 @@ void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
/**
* 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
* 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
* type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [surcename] ... [itemname]" -> MsgStringTable[1629]
* type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
* type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
**/
void clif_broadcast_obtain_special_item(const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type, const char *srcname) {
@ -19539,7 +19539,15 @@ void clif_broadcast_obtain_special_item(const char *char_name, unsigned short na
WBUFB(buf, 4) = type;
WBUFW(buf, 5) = nameid;
WBUFB(buf, 7) = NAME_LENGTH;
safestrncpy(WBUFCP(buf, 8), char_name, NAME_LENGTH);
if (battle_config.broadcast_hide_name) {
std::string dispname = std::string(char_name);
int hide = min(battle_config.broadcast_hide_name, dispname.length() - 1);
dispname.replace(dispname.length() - hide, hide, hide, '*');
safestrncpy(WBUFCP(buf, 8), dispname.c_str(), NAME_LENGTH);
}
else
safestrncpy(WBUFCP(buf, 8), char_name, NAME_LENGTH);
switch (type) {
case ITEMOBTAIN_TYPE_BOXITEM:

View File

@ -201,7 +201,7 @@ unsigned short itemdb_searchrandomid(uint16 group_id, uint8 sub_group) {
* @param group_id: The group ID of item that obtained by player
* @param *group: struct s_item_group from itemgroup_db[group_id].random[idx] or itemgroup_db[group_id].must[sub_group][idx]
*/
static void itemdb_pc_get_itemgroup_sub(struct map_session_data *sd, struct s_item_group_entry *data) {
static void itemdb_pc_get_itemgroup_sub(struct map_session_data *sd, bool identify, struct s_item_group_entry *data) {
uint16 i, get_amt = 0;
struct item tmp;
@ -211,7 +211,7 @@ static void itemdb_pc_get_itemgroup_sub(struct map_session_data *sd, struct s_it
tmp.nameid = data->nameid;
tmp.bound = data->bound;
tmp.identify = 1;
tmp.identify = identify ? identify : itemdb_isidentified(data->nameid);
tmp.expire_time = (data->duration) ? (unsigned int)(time(NULL) + data->duration*60) : 0;
if (data->isNamed) {
tmp.card[0] = itemdb_isequip(data->nameid) ? CARD0_FORGE : CARD0_CREATE;
@ -245,7 +245,7 @@ static void itemdb_pc_get_itemgroup_sub(struct map_session_data *sd, struct s_it
* @param nameid: The item that trigger this item group
* @return val: 0:success, 1:no sd, 2:invalid item group
*/
char itemdb_pc_get_itemgroup(uint16 group_id, struct map_session_data *sd) {
char itemdb_pc_get_itemgroup(uint16 group_id, bool identify, struct map_session_data *sd) {
uint16 i = 0;
struct s_item_group_db *group;
@ -260,7 +260,7 @@ char itemdb_pc_get_itemgroup(uint16 group_id, struct map_session_data *sd) {
if (group->must_qty) {
for (i = 0; i < group->must_qty; i++)
if (&group->must[i])
itemdb_pc_get_itemgroup_sub(sd,&group->must[i]);
itemdb_pc_get_itemgroup_sub(sd, identify, &group->must[i]);
}
// Get the 'random' item each random group
@ -271,7 +271,7 @@ char itemdb_pc_get_itemgroup(uint16 group_id, struct map_session_data *sd) {
rand = rnd()%group->random[i].data_qty;
if (!(&group->random[i].data[rand]) || !group->random[i].data[rand].nameid)
continue;
itemdb_pc_get_itemgroup_sub(sd,&group->random[i].data[rand]);
itemdb_pc_get_itemgroup_sub(sd, identify, &group->random[i].data[rand]);
}
return 0;

View File

@ -948,7 +948,7 @@ struct item_combo *itemdb_combo_exists(unsigned short combo_id);
struct s_item_group_db *itemdb_group_exists(unsigned short group_id);
bool itemdb_group_item_exists(unsigned short group_id, unsigned short nameid);
char itemdb_pc_get_itemgroup(uint16 group_id, struct map_session_data *sd);
char itemdb_pc_get_itemgroup(uint16 group_id, bool identify, struct map_session_data *sd);
bool itemdb_parse_roulette_db(void);

View File

@ -20993,16 +20993,16 @@ BUILDIN_FUNC(checkre)
return SCRIPT_CMD_SUCCESS;
}
/* getrandgroupitem <group_id>{,<quantity>{,<sub_group>}} */
/* getrandgroupitem <group_id>{,<quantity>{,<sub_group>{,<identify>{,<char_id>}}}} */
BUILDIN_FUNC(getrandgroupitem) {
TBL_PC* sd;
int i, get_count = 0;
int i, get_count = 0, identify = 0;
uint16 group, qty = 0;
uint8 sub_group = 1;
struct item item_tmp;
struct s_item_group_entry *entry = NULL;
if (!script_rid2sd(sd))
if (!script_charid2sd(6, sd))
return SCRIPT_CMD_SUCCESS;
group = script_getnum(st,2);
@ -21014,6 +21014,7 @@ BUILDIN_FUNC(getrandgroupitem) {
FETCH(3, qty);
FETCH(4, sub_group);
FETCH(5, identify);
entry = itemdb_get_randgroupitem(group,sub_group);
if (!entry)
@ -21021,7 +21022,7 @@ BUILDIN_FUNC(getrandgroupitem) {
memset(&item_tmp,0,sizeof(item_tmp));
item_tmp.nameid = entry->nameid;
item_tmp.identify = itemdb_isidentified(entry->nameid);
item_tmp.identify = identify ? 1 : itemdb_isidentified(entry->nameid);
if (!qty)
qty = entry->amount;
@ -21051,17 +21052,17 @@ BUILDIN_FUNC(getrandgroupitem) {
return SCRIPT_CMD_SUCCESS;
}
/* getgroupitem <group_id>{,<char_id>};
/* getgroupitem <group_id>{,<identify>{,<char_id>}};
* Gives item(s) to the attached player based on item group contents
*/
BUILDIN_FUNC(getgroupitem) {
TBL_PC *sd;
int group_id = script_getnum(st,2);
if (!script_charid2sd(3,sd))
if (!script_charid2sd(4,sd))
return SCRIPT_CMD_SUCCESS;
if (itemdb_pc_get_itemgroup(group_id,sd)) {
if (itemdb_pc_get_itemgroup(group_id, (script_hasdata(st, 3) ? script_getnum(st, 3) != 0 : false), sd)) {
ShowError("buildin_getgroupitem: Invalid group id '%d' specified.\n",group_id);
return SCRIPT_CMD_FAILURE;
}
@ -24223,7 +24224,7 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(get_revision,""),
BUILDIN_DEF(get_githash,""),
BUILDIN_DEF(freeloop,"?"),
BUILDIN_DEF(getrandgroupitem,"i??"),
BUILDIN_DEF(getrandgroupitem,"i????"),
BUILDIN_DEF(cleanmap,"s"),
BUILDIN_DEF2(cleanmap,"cleanarea","siiii"),
BUILDIN_DEF(npcskill,"viii"),
@ -24270,7 +24271,7 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(vip_time,"i?"),
BUILDIN_DEF(bonus_script,"si????"),
BUILDIN_DEF(bonus_script_clear,"??"),
BUILDIN_DEF(getgroupitem,"i?"),
BUILDIN_DEF(getgroupitem,"i??"),
BUILDIN_DEF(enable_command,""),
BUILDIN_DEF(disable_command,""),
BUILDIN_DEF(getguildmember,"i??"),