Explorar el Código

Prevent opening vending UI multiple times (#6430)

Prevent opening vending UI multiple times in one vending session.
Discard cart modification packet when the player is in a 'can't act' state.

Fixes #3408

Co-authored-by: Lemongrass3110 <lemongrass@kstp.at>
Jittapan Pluemsumran hace 2 años
padre
commit
857a34832f
Se han modificado 4 ficheros con 16 adiciones y 7 borrados
  1. 2 4
      src/map/clif.cpp
  2. 5 1
      src/map/intif.cpp
  3. 1 0
      src/map/pc.hpp
  4. 8 2
      src/map/skill.cpp

+ 2 - 4
src/map/clif.cpp

@@ -12466,9 +12466,7 @@ void clif_parse_StopAttack(int fd,map_session_data *sd)
 /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
 /// 0126 <index>.W <amount>.L
 void clif_parse_PutItemToCart( int fd, map_session_data *sd ){
-	if (pc_istrading(sd))
-		return;
-	if (!pc_iscarton(sd))
+	if (pc_istrading(sd) || !pc_iscarton(sd) || pc_cant_act2(sd))
 		return;
 	if (map_getmapflag(sd->bl.m, MF_NOUSECART))
 		return;
@@ -12484,7 +12482,7 @@ void clif_parse_PutItemToCart( int fd, map_session_data *sd ){
 void clif_parse_GetItemFromCart(int fd,map_session_data *sd)
 {
 	struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
-	if (!pc_iscarton(sd))
+	if (!pc_iscarton(sd) || pc_cant_act2(sd))
 		return;
 	if (map_getmapflag(sd->bl.m, MF_NOUSECART))
 		return;

+ 5 - 1
src/map/intif.cpp

@@ -3514,7 +3514,11 @@ static bool intif_parse_StorageReceived(int fd)
 			}else if( sd->state.prevend ){
 				clif_clearcart(sd->fd);
 				clif_cartlist(sd);
-				clif_openvendingreq(sd, sd->vend_skill_lv+2);
+				// Only open the vending UI, if it has not been opened already
+				if (sd->state.pending_vending_ui) {
+					clif_openvendingreq(sd, sd->vend_skill_lv + 2);
+					sd->state.pending_vending_ui = false;
+				}
 			}
 			break;
 

+ 1 - 0
src/map/pc.hpp

@@ -425,6 +425,7 @@ public:
 		unsigned int autolooting : 1; //performance-saver, autolooting state for @alootid
 		unsigned int gmaster_flag : 1;
 		unsigned int prevend : 1;//used to flag wheather you've spent 40sp to open the vending or not.
+		bool pending_vending_ui; // flag whether the vending packet should still be sent to this player or not
 		unsigned int warping : 1;//states whether you're in the middle of a warp processing
 		unsigned int permanent_speed : 1; // When 1, speed cannot be changed through status_calc_pc().
 		bool hold_recalc;

+ 8 - 2
src/map/skill.cpp

@@ -9019,10 +9019,16 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 				sd->state.workinprogress = WIP_DISABLE_ALL;
 				sd->vend_skill_lv = skill_lv;
 				ARR_FIND(0, MAX_CART, i, sd->cart.u.items_cart[i].nameid && sd->cart.u.items_cart[i].id == 0);
-				if (i < MAX_CART)
+				if (i < MAX_CART) {
+					// Save the cart before opening the vending UI
+					sd->state.pending_vending_ui = true;
 					intif_storage_save(sd, &sd->cart);
-				else
+				}
+				else{
+					// Instantly open the vending UI
+					sd->state.pending_vending_ui = false;
 					clif_openvendingreq(sd,2+skill_lv);
+				}
 			}
 		}
 		break;