Browse Source

Implemented @clearstorage, @cleargstorage, @clearcart, @clearinventory (alias for @itemreset) as suggested in tid:70764.
For further details read the documentation in doc/atcommands.txt

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@17029 54d463be-8e91-2dee-dedb-b68131a5f0ec

momacabu 12 years ago
parent
commit
b9e0b20eeb
6 changed files with 121 additions and 1 deletions
  1. 8 0
      conf/msg_athena.conf
  2. 13 0
      doc/atcommands.txt
  3. 1 0
      src/common/mmo.h
  4. 85 1
      src/map/atcommand.c
  5. 13 0
      src/map/storage.c
  6. 1 0
      src/map/storage.h

+ 8 - 0
conf/msg_athena.conf

@@ -1398,5 +1398,13 @@
 // atcommand.c::is_atcommand
 // atcommand.c::is_atcommand
 1393: You can't use commands while dead.
 1393: You can't use commands while dead.
 
 
+// @clearstorage
+1394: Your storage was cleaned.
+1395: Your guild storage was cleaned.
+
+// @clearcart
+1396: You do not have a cart to be cleaned.
+1397: Your cart was cleaned.
+
 //Custom translations
 //Custom translations
 import: conf/import/msg_conf.txt
 import: conf/import/msg_conf.txt

+ 13 - 0
doc/atcommands.txt

@@ -676,6 +676,19 @@ Deletes all inventory items (not equipped items).
 
 
 ---------------------------------------
 ---------------------------------------
 
 
+@clearstorage
+@cleargstorage
+
+Deletes all items in storage (or guild storage).
+
+---------------------------------------
+
+@clearcart
+
+Deletes all items in cart, but it will not remove the cart.
+
+---------------------------------------
+
 @cleanarea
 @cleanarea
 @cleanmap
 @cleanmap
 
 

+ 1 - 0
src/common/mmo.h

@@ -253,6 +253,7 @@ struct guild_storage {
 	short storage_status;
 	short storage_status;
 	short storage_amount;
 	short storage_amount;
 	struct item items[MAX_GUILD_STORAGE];
 	struct item items[MAX_GUILD_STORAGE];
+	unsigned short lock;
 };
 };
 
 
 struct s_pet {
 struct s_pet {

+ 85 - 1
src/map/atcommand.c

@@ -52,7 +52,7 @@
 
 
 #define ATCOMMAND_LENGTH 50
 #define ATCOMMAND_LENGTH 50
 #define ACMD_FUNC(x) static int atcommand_ ## x (const int fd, struct map_session_data* sd, const char* command, const char* message)
 #define ACMD_FUNC(x) static int atcommand_ ## x (const int fd, struct map_session_data* sd, const char* command, const char* message)
-#define MAX_MSG 1400
+#define MAX_MSG 1500
 
 
 
 
 typedef struct AtCommandInfo AtCommandInfo;
 typedef struct AtCommandInfo AtCommandInfo;
@@ -5258,6 +5258,86 @@ ACMD_FUNC(storeall)
 	return 0;
 	return 0;
 }
 }
 
 
+ACMD_FUNC(clearstorage)
+{
+	int i, j;
+	nullpo_retr(-1, sd);
+
+	if (sd->state.storage_flag == 1) {
+		clif_displaymessage(fd, msg_txt(250));
+		return -1;
+	}
+	
+	j = sd->status.storage.storage_amount;
+	for (i = 0; i < j; ++i) {
+		storage_delitem(sd, i, sd->status.storage.items[i].amount);
+	}
+	storage_storageclose(sd);
+	
+	clif_displaymessage(fd, msg_txt(1394)); // Your storage was cleaned.
+	return 0;
+}
+
+ACMD_FUNC(cleargstorage)
+{
+	int i, j;
+	struct guild *g;
+	struct guild_storage *gstorage;
+	nullpo_retr(-1, sd);
+	
+	g = guild_search(sd->status.guild_id);
+	
+	if (g == NULL) {
+		clif_displaymessage(fd, msg_txt(43));
+		return -1;
+	}
+	
+	if (sd->state.storage_flag == 1) {
+		clif_displaymessage(fd, msg_txt(250));
+		return -1;
+	}
+
+	if (sd->state.storage_flag == 2) {
+		clif_displaymessage(fd, msg_txt(251));
+		return -1;
+	}
+	
+	gstorage = guild2storage2(sd->status.guild_id);
+	if (gstorage == NULL) {// Doesn't have opened @gstorage yet, so we skip the deletion since *shouldn't* have any item there.
+		return -1;
+	}
+
+	j = gstorage->storage_amount;
+	gstorage->lock = 1; // Lock @gstorage: do not allow any item to be retrieved or stored from any guild member
+	for (i = 0; i < j; ++i) {
+		guild_storage_delitem(sd, gstorage, i, gstorage->items[i].amount);
+	}
+	storage_guild_storageclose(sd);
+	gstorage->lock = 0; // Cleaning done, release lock
+	
+	clif_displaymessage(fd, msg_txt(1395)); // Your guild storage was cleaned.
+	return 0;
+}
+
+ACMD_FUNC(clearcart)
+{
+	nullpo_retr(-1, sd);
+	
+	if (pc_iscarton(sd) == 0) {
+		clif_displaymessage(fd, msg_txt(1396)); // You do not have a cart to be cleaned.
+		return -1;
+	}
+	
+	if (sd->state.vending == 1) { //Somehow...
+		return -1;
+	}
+	
+	clif_clearcart(fd);
+	
+	clif_displaymessage(fd, msg_txt(1397)); // Your cart was cleaned.
+	return 0;
+}
+
 /*==========================================
 /*==========================================
  * @skillid by [MouseJstr]
  * @skillid by [MouseJstr]
  * lookup a skill by name
  * lookup a skill by name
@@ -8739,6 +8819,10 @@ void atcommand_basecommands(void) {
 		ACMD_DEF(item),
 		ACMD_DEF(item),
 		ACMD_DEF(item2),
 		ACMD_DEF(item2),
 		ACMD_DEF(itemreset),
 		ACMD_DEF(itemreset),
+		ACMD_DEF2("clearinventory", itemreset),
+		ACMD_DEF(clearstorage),
+		ACMD_DEF(cleargstorage),
+		ACMD_DEF(clearcart),
 		ACMD_DEF2("blvl", baselevelup),
 		ACMD_DEF2("blvl", baselevelup),
 		ACMD_DEF2("jlvl", joblevelup),
 		ACMD_DEF2("jlvl", joblevelup),
 		ACMD_DEF(help),
 		ACMD_DEF(help),

+ 13 - 0
src/map/storage.c

@@ -405,6 +405,9 @@ int storage_guild_storageopen(struct map_session_data* sd)
 	}
 	}
 	if(gstor->storage_status)
 	if(gstor->storage_status)
 		return 1;
 		return 1;
+		
+	if( gstor->lock )
+		return 1;
 	
 	
 	gstor->storage_status = 1;
 	gstor->storage_status = 1;
 	sd->state.storage_flag = 2;
 	sd->state.storage_flag = 2;
@@ -522,6 +525,11 @@ int storage_guild_storageadd(struct map_session_data* sd, int index, int amount)
 	
 	
 	if( amount < 1 || amount > sd->status.inventory[index].amount )
 	if( amount < 1 || amount > sd->status.inventory[index].amount )
 		return 0;
 		return 0;
+		
+	if( stor->lock ) {
+		storage_guild_storageclose(sd);
+		return 0;
+	}
 
 
 	if(guild_storage_additem(sd,stor,&sd->status.inventory[index],amount)==0)
 	if(guild_storage_additem(sd,stor,&sd->status.inventory[index],amount)==0)
 		pc_delitem(sd,index,amount,0,4,LOG_TYPE_GSTORAGE);
 		pc_delitem(sd,index,amount,0,4,LOG_TYPE_GSTORAGE);
@@ -555,6 +563,11 @@ int storage_guild_storageget(struct map_session_data* sd, int index, int amount)
 	
 	
 	if(amount < 1 || amount > stor->items[index].amount)
 	if(amount < 1 || amount > stor->items[index].amount)
 	  	return 0;
 	  	return 0;
+		
+	if( stor->lock ) {
+		storage_guild_storageclose(sd);
+		return 0;
+	}
 
 
 	if((flag = pc_additem(sd,&stor->items[index],amount,LOG_TYPE_GSTORAGE)) == 0)
 	if((flag = pc_additem(sd,&stor->items[index],amount,LOG_TYPE_GSTORAGE)) == 0)
 		guild_storage_delitem(sd,stor,index,amount);
 		guild_storage_delitem(sd,stor,index,amount);

+ 1 - 0
src/map/storage.h

@@ -24,6 +24,7 @@ void do_reconnect_storage(void);
 void storage_storage_quit(struct map_session_data *sd, int flag);
 void storage_storage_quit(struct map_session_data *sd, int flag);
 
 
 struct guild_storage* guild2storage(int guild_id);
 struct guild_storage* guild2storage(int guild_id);
+struct guild_storage *guild2storage2(int guild_id);
 int guild_storage_delete(int guild_id);
 int guild_storage_delete(int guild_id);
 int storage_guild_storageopen(struct map_session_data *sd);
 int storage_guild_storageopen(struct map_session_data *sd);
 int guild_storage_additem(struct map_session_data *sd,struct guild_storage *stor,struct item *item_data,int amount);
 int guild_storage_additem(struct map_session_data *sd,struct guild_storage *stor,struct item *item_data,int amount);