Przeglądaj źródła

商店数据改为分段发送

gitxsm 6 dni temu
rodzic
commit
c6231b2fee
2 zmienionych plików z 86 dodań i 40 usunięć
  1. 3 1
      script/module/shop/Proto.lua
  2. 83 39
      script/module/shop/ShopLogic.lua

+ 3 - 1
script/module/shop/Proto.lua

@@ -31,13 +31,15 @@ CG_SHOP_QUERY = {
 GC_SHOP_QUERY = {
     {"shopList",        20,    ShopInfo},   -- 商店列表
     {"shopInfo",        1,     ShopInfo},   -- 当前商店信息
-	{"list",            100,   GOODS},
+	{"list",            15,   GOODS},
 	{"refreshItem",     1,     ItemData}, -- 刷新道具ID
 	{"nextRefreshTime",	1,	   "int"}, -- 下次刷新时间
 	{"freeCnt",         1,     "int"}, -- 免费刷新次数
 	{"freeMax",         1,     "int"}, -- 免费刷新上限
 	{"costCnt",         1,     "int"}, -- 钻石刷新次数
 	{"costMax",         1,     "int"}, -- 钻石刷新次数上限
+	{"isStart",      	1,     "byte"}, -- 0-非第一段数据,1- 第一段数据
+	{"isEnd",      		1,     "byte"}, -- 0-非最后一段数据,1- 最后一段数据
 }
 
 -- 刷新物品

+ 83 - 39
script/module/shop/ShopLogic.lua

@@ -166,15 +166,15 @@ function query(human, shopType)
         end
     end
 
-	Grid.makeItem(msgRet.refreshItem,shopTypeConfig.refreshItemID,shopTypeConfig.refreshItemCnt)
+	Grid.makeItem(msgRet.refreshItem, shopTypeConfig.refreshItemID, shopTypeConfig.refreshItemCnt)
 
 	local shopConfig = ShopExcel[shopType]
 	if not shopConfig then return end
 
 	local now = os.time()
 
-    initHumanShopDB(human,shopType)
-    checkFreeCnt(human,shopType)
+    initHumanShopDB(human, shopType)
+    checkFreeCnt(human, shopType)
 
 	msgRet.nextRefreshTime = 0
 
@@ -192,48 +192,92 @@ function query(human, shopType)
 	msgRet.costCnt = getLeftCostCnt(human, shopType)
 	msgRet.costMax = getCostCntMax(human, shopType)
 
+    -- 先把所有商品数据收集到临时表
+    local allGoods = {}
+
     -- 不刷新的没有记录的 走配置
-    local cnt = 0
     if shopTypeConfig.refreshType == ShopDefine.SHOP_REFRESH_TYPE0 then
-       for index, v in pairs(shopConfig) do
-          if not human.db.shop[shopType].goods[index] then
-             local tempConfig = v
-             cnt = cnt + 1
-             Grid.makeItem(msgRet.list[cnt].itemData, tempConfig.itemID, tempConfig.cnt)
-             msgRet.list[cnt].itemIndex = index
-             Grid.makeItem(msgRet.list[cnt].needItem, tempConfig.needItemID, tempConfig.price)
-		     msgRet.list[cnt].maxCanBuy = tempConfig.limitBuyCnt
-		     msgRet.list[cnt].nowBuy = 0
-		     msgRet.list[cnt].zhekou  = tempConfig.zhekou
-		     msgRet.list[cnt].order  = tempConfig.order
-             msgRet.list[cnt].needVipLv = tempConfig.needVipLv
-             msgRet.list[cnt].rare = tempConfig.rare
-             msgRet.list[cnt].limitType = tempConfig.limitType
-             msgRet.list[cnt].bCanChose = tempConfig.isquickbuy and tempConfig.isquickbuy or 0
-             msgRet.list[cnt].bChose = 0
-          end
-       end
+        for index, v in pairs(shopConfig) do
+            if not human.db.shop[shopType].goods[index] then
+                local tempConfig = v
+                allGoods[#allGoods + 1] = {
+                    itemID      = tempConfig.itemID,
+                    itemCnt     = tempConfig.cnt,
+                    itemIndex   = index,
+                    needItemID  = tempConfig.needItemID,
+                    needItemCnt = tempConfig.price,
+                    maxCanBuy   = tempConfig.limitBuyCnt,
+                    nowBuy      = 0,
+                    zhekou      = tempConfig.zhekou,
+                    order       = tempConfig.order,
+                    needVipLv   = tempConfig.needVipLv,
+                    rare        = tempConfig.rare,
+                    limitType   = tempConfig.limitType,
+                    bCanChose   = tempConfig.isquickbuy and tempConfig.isquickbuy or 0,
+                    bChose      = 0,
+                }
+            end
+        end
     end
 
     for _, v in pairs(human.db.shop[shopType].goods) do
         local tempConfig = shopConfig[v.index]
-        cnt = cnt + 1
-        Grid.makeItem(msgRet.list[cnt].itemData, tempConfig.itemID, tempConfig.cnt)
-        msgRet.list[cnt].itemIndex = v.index
-        Grid.makeItem(msgRet.list[cnt].needItem, tempConfig.needItemID, tempConfig.price)
-		msgRet.list[cnt].maxCanBuy = tempConfig.limitBuyCnt
-		msgRet.list[cnt].nowBuy = v.nowBuy
-		msgRet.list[cnt].zhekou  = tempConfig.zhekou
-		msgRet.list[cnt].order  = tempConfig.order
-        msgRet.list[cnt].needVipLv = tempConfig.needVipLv
-        msgRet.list[cnt].rare = tempConfig.rare
-        msgRet.list[cnt].limitType = tempConfig.limitType
-        msgRet.list[cnt].bCanChose = tempConfig.isquickbuy and tempConfig.isquickbuy or 0
-        msgRet.list[cnt].bChose = ShopLogic_GetChose(human, shopType, v.index)
-    end
-
-	msgRet.list[0] = cnt
-	Msg.send(msgRet, human.fd)
+        allGoods[#allGoods + 1] = {
+            itemID      = tempConfig.itemID,
+            itemCnt     = tempConfig.cnt,
+            itemIndex   = v.index,
+            needItemID  = tempConfig.needItemID,
+            needItemCnt = tempConfig.price,
+            maxCanBuy   = tempConfig.limitBuyCnt,
+            nowBuy      = v.nowBuy,
+            zhekou      = tempConfig.zhekou,
+            order       = tempConfig.order,
+            needVipLv   = tempConfig.needVipLv,
+            rare        = tempConfig.rare,
+            limitType   = tempConfig.limitType,
+            bCanChose   = tempConfig.isquickbuy and tempConfig.isquickbuy or 0,
+            bChose      = ShopLogic_GetChose(human, shopType, v.index),
+        }
+    end
+
+    -- 分批发送,每批最多 15 条
+    local BATCH_SIZE = 15
+    local total = #allGoods
+    local totalBatches = math.max(math.ceil(total / BATCH_SIZE), 1)
+
+    for batchIdx = 1, totalBatches do
+        local startIdx = (batchIdx - 1) * BATCH_SIZE + 1
+        local endIdx   = math.min(batchIdx * BATCH_SIZE, total)
+
+        msgRet.isStart = (batchIdx == 1) and 1 or 0
+        msgRet.isEnd   = (batchIdx == totalBatches) and 1 or 0
+
+        -- 非第一批不重复发送商店列表等头部信息
+        if batchIdx > 1 then
+            msgRet.shopList[0] = 0
+        end
+
+        local cnt = 0
+        for i = startIdx, endIdx do
+            cnt = cnt + 1
+            local item = allGoods[i]
+            Grid.makeItem(msgRet.list[cnt].itemData, item.itemID, item.itemCnt)
+            msgRet.list[cnt].itemIndex  = item.itemIndex
+            Grid.makeItem(msgRet.list[cnt].needItem, item.needItemID, item.needItemCnt)
+            msgRet.list[cnt].maxCanBuy  = item.maxCanBuy
+            msgRet.list[cnt].nowBuy     = item.nowBuy
+            msgRet.list[cnt].zhekou     = item.zhekou
+            msgRet.list[cnt].order      = item.order
+            msgRet.list[cnt].needVipLv  = item.needVipLv
+            msgRet.list[cnt].rare       = item.rare
+            msgRet.list[cnt].limitType  = item.limitType
+            msgRet.list[cnt].bCanChose  = item.bCanChose
+            msgRet.list[cnt].bChose     = item.bChose
+        end
+        msgRet.list[0] = cnt
+
+        Msg.send(msgRet, human.fd)
+    end
 end
 
 -- 刷新物品