Browse Source

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
Cydh Ramdh 7 years ago
parent
commit
32950ecead
8 changed files with 44 additions and 19 deletions
  1. 6 0
      conf/battle/items.conf
  2. 10 2
      doc/script_commands.txt
  3. 1 0
      src/map/battle.cpp
  4. 1 0
      src/map/battle.hpp
  5. 10 2
      src/map/clif.cpp
  6. 5 5
      src/map/itemdb.cpp
  7. 1 1
      src/map/itemdb.hpp
  8. 10 9
      src/map/script.cpp

+ 6 - 0
conf/battle/items.conf

@@ -121,3 +121,9 @@ allow_bound_sell: 0x0
 // no = normal refine chances in effect (official/default value)
 // no = normal refine chances in effect (official/default value)
 // yes = event refine chances in effect
 // yes = event refine chances in effect
 event_refine_chance: no
 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

+ 10 - 2
doc/script_commands.txt

@@ -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
 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
 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
 If 'sub_group' is not defined the value will be 1 (since random group is 1 ~ 5, and 0 is
 'must' item group).
 '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.
 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.
 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
 This is not working like 'getrandgroupitem' which only give 1 item for specified
 item group & sub_group.
 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.
 More info, see doc/item_group.txt.
 
 
 ---------------------------------------
 ---------------------------------------

+ 1 - 0
src/map/battle.cpp

@@ -8492,6 +8492,7 @@ static const struct _battle_data {
 	{ "allow_bound_sell",                   &battle_config.allow_bound_sell,                0,      0,      0x3,            },
 	{ "allow_bound_sell",                   &battle_config.allow_bound_sell,                0,      0,      0x3,            },
 	{ "event_refine_chance",                &battle_config.event_refine_chance,             0,      0,      1,              },
 	{ "event_refine_chance",                &battle_config.event_refine_chance,             0,      0,      1,              },
 	{ "autoloot_adjust",                    &battle_config.autoloot_adjust,                 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"
 #include "../custom/battle_config_init.inc"
 };
 };

+ 1 - 0
src/map/battle.hpp

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

+ 10 - 2
src/map/clif.cpp

@@ -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 <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)
  * 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]
  * 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) {
 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;
 	WBUFB(buf, 4) = type;
 	WBUFW(buf, 5) = nameid;
 	WBUFW(buf, 5) = nameid;
 	WBUFB(buf, 7) = NAME_LENGTH;
 	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) {
 	switch (type) {
 		case ITEMOBTAIN_TYPE_BOXITEM:
 		case ITEMOBTAIN_TYPE_BOXITEM:

+ 5 - 5
src/map/itemdb.cpp

@@ -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_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]
 * @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;
 	uint16 i, get_amt = 0;
 	struct item tmp;
 	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.nameid = data->nameid;
 	tmp.bound = data->bound;
 	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;
 	tmp.expire_time = (data->duration) ? (unsigned int)(time(NULL) + data->duration*60) : 0;
 	if (data->isNamed) {
 	if (data->isNamed) {
 		tmp.card[0] = itemdb_isequip(data->nameid) ? CARD0_FORGE : CARD0_CREATE;
 		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
 * @param nameid: The item that trigger this item group
 * @return val: 0:success, 1:no sd, 2:invalid 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;
 	uint16 i = 0;
 	struct s_item_group_db *group;
 	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) {
 	if (group->must_qty) {
 		for (i = 0; i < group->must_qty; i++)
 		for (i = 0; i < group->must_qty; i++)
 			if (&group->must[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
 	// 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;
 		rand = rnd()%group->random[i].data_qty;
 		if (!(&group->random[i].data[rand]) || !group->random[i].data[rand].nameid)
 		if (!(&group->random[i].data[rand]) || !group->random[i].data[rand].nameid)
 			continue;
 			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;
 	return 0;

+ 1 - 1
src/map/itemdb.hpp

@@ -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);
 struct s_item_group_db *itemdb_group_exists(unsigned short group_id);
 bool itemdb_group_item_exists(unsigned short group_id, unsigned short nameid);
 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);
 bool itemdb_parse_roulette_db(void);
 
 

+ 10 - 9
src/map/script.cpp

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