Ver Fonte

Suggestion: identifyall script command (#3419)

* Implemented script command identifyall.
Thanks to @secretdataz for suggestions!
Atemo há 6 anos atrás
pai
commit
fd4f7ccd5c
5 ficheiros alterados com 62 adições e 6 exclusões
  1. 8 0
      doc/script_commands.txt
  2. 1 6
      src/map/atcommand.cpp
  3. 23 0
      src/map/pc.cpp
  4. 2 0
      src/map/pc.hpp
  5. 28 0
      src/map/script.cpp

+ 8 - 0
doc/script_commands.txt

@@ -3032,6 +3032,14 @@ If no item ID/name given, all possible items in player's inventory will be merge
 Returns true if the item in <equipment slot> is tradable.
 Returns false otherwise.
 
+---------------------------------------
+
+*identifyall({<type>{,<account_id>}});
+
+Returns the count of unidentified items in the player inventory.
+If <type> is true the command will identify all the unidentified items as well (default).
+If <type> is false the command only returns the count of unidentified items.
+
 ---------------------------------------
 //
 2,1.- End of item-related commands.

+ 1 - 6
src/map/atcommand.cpp

@@ -7091,12 +7091,7 @@ ACMD_FUNC(identifyall)
 {
 	int i;
 	nullpo_retr(-1, sd);
-	for(i=0; i<MAX_INVENTORY; i++) {
-		if (sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].identify != 1) {
-			sd->inventory.u.items_inventory[i].identify = 1;
-			clif_item_identified(sd,i,0);
-		}
-	}
+	pc_identifyall(sd, true);
 	return 0;
 }
 

+ 23 - 0
src/map/pc.cpp

@@ -4288,6 +4288,29 @@ int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip)
 	return 0;
 }
 
+/**
+ * Returns the count of unidentified items with the option to identify too.
+ * @param sd: Player data
+ * @param identify_item: Whether or not to identify any unidentified items
+ * @return Unidentified items count
+ */
+int pc_identifyall(struct map_session_data *sd, bool identify_item)
+{
+	int unidentified_count = 0;
+
+	for (int i = 0; i < MAX_INVENTORY; i++) {
+		if (sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].identify != 1) {
+			if (identify_item == true) {
+				sd->inventory.u.items_inventory[i].identify = 1;
+				clif_item_identified(sd,i,0);
+			}
+			unidentified_count++;
+		}
+	}
+
+	return unidentified_count;
+}
+
 //
 // Items
 //

+ 2 - 0
src/map/pc.hpp

@@ -1106,6 +1106,8 @@ bool pc_skill(struct map_session_data *sd, uint16 skill_id, int level, enum e_ad
 
 int pc_insert_card(struct map_session_data *sd,int idx_card,int idx_equip);
 
+int pc_identifyall(struct map_session_data *sd, bool identify_item);
+
 int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skill_lv);
 int pc_steal_coin(struct map_session_data *sd,struct block_list *bl);
 

+ 28 - 0
src/map/script.cpp

@@ -23823,6 +23823,33 @@ BUILDIN_FUNC(open_roulette){
 #endif
 }
 
+/*==========================================
+ * identifyall({<type>{,<account_id>}})
+ * <type>:
+ *	true: identify the items and returns the count of unidentified items (default)
+ *	false: returns the count of unidentified items only
+ *------------------------------------------*/
+BUILDIN_FUNC(identifyall) {
+	TBL_PC *sd;
+	bool identify_item = true;
+
+	if (script_hasdata(st, 2))
+		identify_item = script_getnum(st, 2) != 0;
+
+	if( !script_hasdata(st, 3) )
+		script_rid2sd(sd);
+	else
+		sd = map_id2sd( script_getnum(st, 3) );
+
+	if (sd == NULL) {
+		script_pushint(st, -1);
+		return SCRIPT_CMD_SUCCESS;
+	}
+	script_pushint(st, pc_identifyall(sd, identify_item));
+
+	return SCRIPT_CMD_SUCCESS;
+}
+
 #include "../custom/script.inc"
 
 // declarations that were supposed to be exported from npc_chat.c
@@ -24477,6 +24504,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(getequiptradability, "i?"),
 	BUILDIN_DEF(mail, "isss*"),
 	BUILDIN_DEF(open_roulette,"?"),
+	BUILDIN_DEF(identifyall,"??"),
 #include "../custom/script_def.inc"
 
 	{NULL,NULL,NULL},