瀏覽代碼

* Added separate character state for vending (like for buyingstore), instead of vender_id != 0 (follow up to r14682, related r14713).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@14762 54d463be-8e91-2dee-dedb-b68131a5f0ec
ai4rei 14 年之前
父節點
當前提交
bba102a818
共有 13 個文件被更改,包括 38 次插入38 次删除
  1. 1 0
      Changelog-Trunk.txt
  2. 3 3
      src/map/atcommand.c
  3. 1 1
      src/map/buyingstore.c
  4. 2 2
      src/map/chat.c
  5. 5 5
      src/map/clif.c
  6. 1 1
      src/map/mail.c
  7. 4 4
      src/map/pc.c
  8. 4 3
      src/map/pc.h
  9. 1 1
      src/map/script.c
  10. 1 1
      src/map/searchstore.c
  11. 2 2
      src/map/trade.c
  12. 2 3
      src/map/unit.c
  13. 11 12
      src/map/vending.c

+ 1 - 0
Changelog-Trunk.txt

@@ -1,6 +1,7 @@
 Date	Added
 
 2011/03/27
+	* Added separate character state for vending (like for buyingstore), instead of vender_id != 0 (follow up to r14682, related r14713). [Ai4rei]
 	* Added support for tracking state of client command /effect through packet 0x21d (CZ_LESSEFFECT). [Ai4rei]
 2011/03/25
 	* Fixed battlegrounds chat packet 0x2dc (ZC_BATTLEFIELD_CHAT) being sent with the battleground id rather than the account id of the talking player (since r13593). [Ai4rei]

+ 3 - 3
src/map/atcommand.c

@@ -1150,7 +1150,7 @@ ACMD_FUNC(storage)
 {
 	nullpo_retr(-1, sd);
 	
-	if (sd->npc_id || sd->vender_id || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag)
+	if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag)
 		return -1;
 
 	if (storage_storageopen(sd) == 1)
@@ -1177,7 +1177,7 @@ ACMD_FUNC(guildstorage)
 		return -1;
 	}
 
-	if (sd->npc_id || sd->vender_id || sd->state.buyingstore || sd->state.trading)
+	if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading)
 		return -1;
 
 	if (sd->state.storage_flag == 1) {
@@ -5945,7 +5945,7 @@ ACMD_FUNC(autotrade)
 		return -1;
 	}
 	
-	if( !sd->vender_id && !sd->state.buyingstore ) { //check if player is vending or buying
+	if( !sd->state.vending && !sd->state.buyingstore ) { //check if player is vending or buying
 		clif_displaymessage(fd, msg_txt(549)); // "You should have a shop open to use @autotrade."
 		return -1;
 	}

+ 1 - 1
src/map/buyingstore.c

@@ -46,7 +46,7 @@ static unsigned int buyingstore_getuid(void)
 
 bool buyingstore_setup(struct map_session_data* sd, unsigned char slots)
 {
-	if( !battle_config.feature_buying_store || sd->vender_id || sd->state.buyingstore || sd->state.trading || slots == 0 )
+	if( !battle_config.feature_buying_store || sd->state.vending || sd->state.buyingstore || sd->state.trading || slots == 0 )
 	{
 		return false;
 	}

+ 2 - 2
src/map/chat.c

@@ -69,7 +69,7 @@ int chat_createpcchat(struct map_session_data* sd, const char* title, const char
 	if( sd->chatID )
 		return 0; //Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex]
 
-	if( sd->vender_id || sd->state.buyingstore )
+	if( sd->state.vending || sd->state.buyingstore )
 	{// not chat, when you already have a store open
 		return 0;
 	}
@@ -113,7 +113,7 @@ int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass)
 	nullpo_ret(sd);
 	cd = (struct chat_data*)map_id2bl(chatid);
 
-	if( cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m || sd->vender_id || sd->state.buyingstore || sd->chatID || cd->users >= cd->limit )
+	if( cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m || sd->state.vending || sd->state.buyingstore || sd->chatID || cd->users >= cd->limit )
 	{
 		clif_joinchatfail(sd,0);
 		return 0;

+ 5 - 5
src/map/clif.c

@@ -3645,7 +3645,7 @@ static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_d
 			clif_dispchat(cd,sd->fd);
 	}
 
-	if(dstsd->vender_id)
+	if( dstsd->state.vending )
 		clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
 
 	if( dstsd->state.buyingstore )
@@ -4077,7 +4077,7 @@ int clif_outsight(struct block_list *bl,va_list ap)
 				if(cd->usersd[0]==sd)
 					clif_dispchat(cd,tsd->fd);
 			}
-			if(sd->vender_id)
+			if( sd->state.vending )
 				clif_closevendingboard(bl,tsd->fd);
 			if( sd->state.buyingstore )
 				clif_buyingstore_disappear_entry_single(tsd, sd);
@@ -10428,7 +10428,7 @@ void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  *------------------------------------------*/
 void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
 {
-	if(sd->vender_id)	
+	if( sd->state.vending )
 		return;
 	if (!pc_iscarton(sd))
 		return;
@@ -10445,7 +10445,7 @@ void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  *------------------------------------------*/
 void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
 {
-	if (sd->vender_id)
+	if( sd->state.vending )
 		return;
 	if (!pc_iscarton(sd))
 		return;
@@ -12860,7 +12860,7 @@ void clif_Auction_openwindow(struct map_session_data *sd)
 {
 	int fd = sd->fd;
 
-	if( sd->state.storage_flag || sd->vender_id || sd->state.buyingstore || sd->state.trading )
+	if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
 		return;
 
 	WFIFOHEAD(fd,12);

+ 1 - 1
src/map/mail.c

@@ -162,7 +162,7 @@ int mail_openmail(struct map_session_data *sd)
 {
 	nullpo_ret(sd);
 
-	if( sd->state.storage_flag || sd->vender_id || sd->state.buyingstore || sd->state.trading )
+	if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
 		return 0;
 
 	clif_Mail_window(sd->fd, 0);

+ 4 - 4
src/map/pc.c

@@ -3435,7 +3435,7 @@ int pc_dropitem(struct map_session_data *sd,int n,int amount)
 	if(sd->status.inventory[n].nameid <= 0 ||
 		sd->status.inventory[n].amount <= 0 ||
 		sd->status.inventory[n].amount < amount ||
-		sd->state.trading || sd->vender_id != 0 ||
+		sd->state.trading || sd->state.vending ||
 		!sd->inventory_data[n] //pc_delitem would fail on this case.
 		)
 		return 0;
@@ -3870,7 +3870,7 @@ int pc_putitemtocart(struct map_session_data *sd,int idx,int amount)
 	
 	item_data = &sd->status.inventory[idx];
 
-	if( item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->vender_id )
+	if( item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending )
 		return 1;
 
 	if( pc_cart_additem(sd,item_data,amount) == 0 )
@@ -3910,7 +3910,7 @@ int pc_getitemfromcart(struct map_session_data *sd,int idx,int amount)
 	
 	item_data=&sd->status.cart[idx];
 
-	if(item_data->nameid==0 || amount < 1 || item_data->amount<amount || sd->vender_id )
+	if(item_data->nameid==0 || amount < 1 || item_data->amount<amount || sd->state.vending )
 		return 1;
 	if((flag = pc_additem(sd,item_data,amount)) == 0)
 		return pc_cart_delitem(sd,idx,amount,0);
@@ -7313,7 +7313,7 @@ int pc_checkitem(struct map_session_data *sd)
 
 	nullpo_ret(sd);
 
-	if( sd->vender_id ) //Avoid reorganizing items when we are vending, as that leads to exploits (pointed out by End of Exam)
+	if( sd->state.vending ) //Avoid reorganizing items when we are vending, as that leads to exploits (pointed out by End of Exam)
 		return 0;
 
 	if( battle_config.item_check )

+ 4 - 3
src/map/pc.h

@@ -131,6 +131,7 @@ struct map_session_data {
 		unsigned debug_remove_map : 1; // temporary state to track double remove_map's [FlavioJS]
 		unsigned buyingstore : 1;
 		unsigned lesseffect : 1;
+		unsigned vending : 1;
 		unsigned short autoloot;
 		unsigned short autolootid; // [Zephyrus]
 		unsigned noks : 3; // [Zeph Kill Steal Protection]
@@ -523,9 +524,9 @@ extern int duel_count;
 #define pc_setsit(sd)         ( (sd)->state.dead_sit = (sd)->vd.dead_sit = 2 )
 #define pc_isdead(sd)         ( (sd)->state.dead_sit == 1 )
 #define pc_issit(sd)          ( (sd)->vd.dead_sit == 2 )
-#define pc_isidle(sd)         ( (sd)->chatID || (sd)->vender_id || (sd)->state.buyingstore || DIFF_TICK(last_tick, (sd)->idletime) >= battle_config.idle_no_share )
-#define pc_istrading(sd)      ( (sd)->npc_id || (sd)->vender_id || (sd)->state.buyingstore || (sd)->state.trading )
-#define pc_cant_act(sd)       ( (sd)->npc_id || (sd)->vender_id || (sd)->state.buyingstore || (sd)->chatID || (sd)->sc.opt1 || (sd)->state.trading || (sd)->state.storage_flag )
+#define pc_isidle(sd)         ( (sd)->chatID || (sd)->state.vending || (sd)->state.buyingstore || DIFF_TICK(last_tick, (sd)->idletime) >= battle_config.idle_no_share )
+#define pc_istrading(sd)      ( (sd)->npc_id || (sd)->state.vending || (sd)->state.buyingstore || (sd)->state.trading )
+#define pc_cant_act(sd)       ( (sd)->npc_id || (sd)->state.vending || (sd)->state.buyingstore || (sd)->chatID || (sd)->sc.opt1 || (sd)->state.trading || (sd)->state.storage_flag )
 #define pc_setdir(sd,b,h)     ( (sd)->ud.dir = (b) ,(sd)->head_dir = (h) )
 #define pc_setchatid(sd,n)    ( (sd)->chatID = n )
 #define pc_ishiding(sd)       ( (sd)->sc.option&(OPTION_HIDE|OPTION_CLOAK|OPTION_CHASEWALK) )

+ 1 - 1
src/map/script.c

@@ -13111,7 +13111,7 @@ BUILDIN_FUNC(checkvending) // check vending [Nab4]
 		sd = script_rid2sd(st);
 
 	if(sd)
-		script_pushint(st,(sd->vender_id != 0));
+		script_pushint(st,sd->state.vending);
 	else
 		script_pushint(st,0);
 

+ 1 - 1
src/map/searchstore.c

@@ -71,7 +71,7 @@ static bool searchstore_hasstore(struct map_session_data* sd, unsigned char type
 {
 	switch( type )
 	{
-		case SEARCHTYPE_VENDING:      return (bool)( sd->vender_id != 0 );
+		case SEARCHTYPE_VENDING:      return sd->state.vending;
 		case SEARCHTYPE_BUYING_STORE: return sd->state.buyingstore;
 	}
 	return false;

+ 2 - 2
src/map/trade.c

@@ -138,8 +138,8 @@ void trade_tradeack(struct map_session_data *sd, int type)
 	}
 
 	//Check if you can start trade.
-	if (sd->npc_id || sd->vender_id || sd->state.buyingstore || sd->state.storage_flag ||
-		tsd->npc_id || tsd->vender_id || tsd->state.buyingstore || tsd->state.storage_flag)
+	if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.storage_flag ||
+		tsd->npc_id || tsd->state.vending || tsd->state.buyingstore || tsd->state.storage_flag)
 	{	//Fail
 		clif_tradestart(sd, 2);
 		clif_tradestart(tsd, 2);

+ 2 - 3
src/map/unit.c

@@ -802,7 +802,7 @@ int unit_can_move(struct block_list *bl)
 	
 	if (sd && (
 		pc_issit(sd) ||
-		sd->vender_id ||
+		sd->state.vending ||
 		sd->state.buyingstore ||
 		sd->state.blockedmove
 	))
@@ -1871,8 +1871,7 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
 			chat_leavechat(sd,0);
 		if(sd->trade_partner)
 			trade_tradecancel(sd);
-		if(sd->vender_id)
-			vending_closevending(sd);
+		vending_closevending(sd);
 		buyingstore_close(sd);
 		searchstore_close(sd);
 		if(sd->state.storage_flag == 1)

+ 11 - 12
src/map/vending.c

@@ -19,16 +19,11 @@
 #include <stdio.h>
 #include <string.h>
 
-static int vending_nextid = 1;
+static int vending_nextid = 0;
 
 /// Returns an unique vending shop id.
 static int vending_getuid(void)
 {
-	if(!vending_nextid)
-	{// wrapped around, 0 is reserved for "not vending" state on eathena
-		vending_nextid = 1;
-	}
-
 	return vending_nextid++;
 }
 
@@ -39,8 +34,11 @@ void vending_closevending(struct map_session_data* sd)
 {
 	nullpo_retv(sd);
 
-	sd->vender_id = 0;
-	clif_closevendingboard(&sd->bl,0);
+	if( sd->state.vending )
+	{
+		sd->state.vending = false;
+		clif_closevendingboard(&sd->bl, 0);
+	}
 }
 
 /*==========================================
@@ -53,7 +51,7 @@ void vending_vendinglistreq(struct map_session_data* sd, int id)
 
 	if( (vsd = map_id2sd(id)) == NULL )
 		return;
-	if( vsd->vender_id == 0 )
+	if( !vsd->state.vending )
 		return; // not vending
 
 	if ( !pc_can_give_items(pc_isGM(sd)) || !pc_can_give_items(pc_isGM(vsd)) ) //check if both GMs are allowed to trade
@@ -78,7 +76,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui
 	struct map_session_data* vsd = map_id2sd(aid);
 
 	nullpo_retv(sd);
-	if( vsd == NULL || vsd->vender_id == 0 || vsd->bl.id == sd->bl.id )
+	if( vsd == NULL || !vsd->state.vending || vsd->bl.id == sd->bl.id )
 		return; // invalid shop
 
 	if( vsd->vender_id != uid )
@@ -309,6 +307,7 @@ void vending_openvending(struct map_session_data* sd, const char* message, bool
 		return;
 	}
 
+	sd->state.vending = true;
 	sd->vender_id = vending_getuid();
 	sd->vend_num = i;
 	safestrncpy(sd->message, message, MESSAGE_SIZE);
@@ -324,7 +323,7 @@ bool vending_search(struct map_session_data* sd, unsigned short nameid)
 {
 	int i;
 
-	if( !sd->vender_id )
+	if( !sd->state.vending )
 	{// not vending
 		return false;
 	}
@@ -347,7 +346,7 @@ bool vending_searchall(struct map_session_data* sd, const struct s_search_store_
 	unsigned int idx, cidx;
 	struct item* it;
 
-	if( !sd->vender_id )
+	if( !sd->state.vending )
 	{// not vending
 		return true;
 	}