Просмотр исходного кода

提交自动购买勾选物品

SCFC 9 месяцев назад
Родитель
Сommit
8109166d26

+ 2 - 1
script/common/ProtoID.lua

@@ -1600,7 +1600,8 @@ _ENV[1615]="GC_FUWEN_HECHENG_ONECLICK"
 -- _ENV[1643]="GC_NEW_BUSTHREEACT_DICEDO"
 
 _ENV[1644]="CG_SHOP_CHOSE_ITEM"
-_ENV[1645]="CG_SHOP_ONECLICK_BUY_CHOSE"
+_ENV[1645]="CG_BUY_LIFTTIME_CARD"
+_ENV[1646]="GC_BUY_LIFTTIME_CARD"
 _ENV[1647]="CG_FUWEN_RESET_LOCK"
 
 

+ 2 - 0
script/module/present/MonthCard.lua

@@ -14,6 +14,7 @@ local HeroLogic = require("hero.HeroLogic")
 local TreasureChestLogic = require("treasurechest.TreasureChestLogic")
 local Log = require("common.Log")
 local CommonDefine = require("common.CommonDefine")
+local ShopLogic = require("shop.ShopLogic")
 
 local MONTH_CARD_STATE_0 = 0        -- 已过期
 local MONTH_CARD_STATE_1 = 1        -- 未过期
@@ -242,6 +243,7 @@ function buyMonthCard(human,id)
 
     if MONTH_CARD_FOREVER == id then
         TreasureChestLogic.TreasureChestLogic_BuyOpenAuto(human)
+        ShopLogic.GetBuyLiftTimeCard(human)
     end
 end
 

+ 11 - 3
script/module/shop/Handler.lua

@@ -17,15 +17,23 @@ end
 
 -- 查询基础商店中随机商店中记录的道具列表
 function CG_SHOP_RECORD_QUERY(human, msg)
-	ShopLogic.RecordItems_Query(human)
+	ShopLogic.RecordItems_Query(human, msg.shopType)
 end
 
 -- 记录基础商店中随机商店中记录的道具列表
 function CG_SHOP_RECORD_ITEMS(human, msg)
-	ShopLogic.RecordItems(human, msg.itemIdxStr)
+	ShopLogic.RecordItems(human, msg.itemIdxStr, msg.shopType)
 end
 
 -- 基础商店中随机商店中所有道具
 function CG_SHOP_ALL_ITEM_QUERY(human, msg)
-	ShopLogic.AllItem_Query(human)
+	ShopLogic.AllItem_Query(human, msg.shopType)
 end
+
+function CG_SHOP_CHOSE_ITEM(human, msg)
+	ShopLogic.ChoseItem(human, msg.shopType, msg.bChose, msg.itemIndex)
+end
+
+function CG_BUY_LIFTTIME_CARD(human, msg)
+	ShopLogic.GetBuyLiftTimeCard(human)
+end

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

@@ -12,6 +12,8 @@ GOODS = {
 	{"needVipLv",	   1,	  "byte"},			-- 限定达到vip指定等级才可以购买
 	{"rare",		   1,	  "byte"},          --标签 0普通 1稀有 2上新
 	{"limitType",	   1,	  "byte"},          --0 不限购,  1限购 2 日限购  3周限购  4 月限购  5 终身限购
+	{"bCanChose",	   1,	  "byte"},			-- 0 不可被选择 1 可被选择
+	{"bChose",		   1,	  "byte"},			-- 0 未选中 1选中
 }
 
 ShopInfo = {
@@ -59,6 +61,7 @@ GC_SHOP_BUY = {
 
 -- 查询基础商店中随机商店中记录的道具列表
 CG_SHOP_RECORD_QUERY = {
+	{"shopType",       1,       "byte"},
 }
 
 GC_SHOP_RECORD_QUERY = {
@@ -68,12 +71,15 @@ GC_SHOP_RECORD_QUERY = {
 
 -- 记录基础商店中随机商店的部分道具
 CG_SHOP_RECORD_ITEMS = {
+	{"shopType",       1,       "byte"},
 	{"itemIdxStr",     1,     "string"}, --商品在配置中的索引列表, 对应GOODS结构中的itemIndex
 }
 
 
 
-CG_SHOP_ALL_ITEM_QUERY = {}
+CG_SHOP_ALL_ITEM_QUERY = {
+	{"shopType",       1,       "byte"},
+}
 
 GC_SHOP_ALL_ITEM_QUERY = {
 	{"itemList",     100,     GOODS}, -- 基础商店之随机商店中的所有道具
@@ -81,3 +87,15 @@ GC_SHOP_ALL_ITEM_QUERY = {
 }
 
 
+-- 选中对应的物品
+CG_SHOP_CHOSE_ITEM = {
+	{"shopType",       1,       "byte"},
+	{"bChose",		   1,		"byte"},		-- 0 取消选中,1 选中
+	{"itemIndex",      1,     	"int"},         -- 物品下标
+}
+
+CG_BUY_LIFTTIME_CARD = {}
+
+GC_BUY_LIFTTIME_CARD = {
+	{"bBuy",			1,		"byte"},		-- 0 未购买 1购买
+}

+ 187 - 20
script/module/shop/ShopLogic.lua

@@ -39,12 +39,50 @@ end
 
 local function initGoodsDb(human, shopType, index, refreshTs)
    if not human.db.shop[shopType].goods then return end
+
+   -- 存在旧的,用旧的数据
+   local bChose = 0
+   if human.db.shop[shopType].goods[index] and human.db.shop[shopType].goods[index].bChose then
+        bChose = human.db.shop[shopType].goods[index].bChose
+   end
+
    human.db.shop[shopType].goods[index] = {}
    human.db.shop[shopType].goods[index].nowBuy = 0
+   human.db.shop[shopType].goods[index].bChose = bChose
    human.db.shop[shopType].goods[index].index = index
    human.db.shop[shopType].goods[index].refreshTs = refreshTs
 end
 
+local function ShopLogic_GetChose(human, shopType, index)
+    if not human.db.shop[shopType].goods then 
+        return 0
+    end
+
+    if not human.db.shop[shopType].goods[index] then
+        return 0
+    end
+
+    if not human.db.shop[shopType].goods[index].bChose then
+        human.db.shop[shopType].goods[index].bChose = 0
+    end
+
+    return human.db.shop[shopType].goods[index].bChose
+end
+
+local function ShopLogic_SetChose(human, shopType, index, nValue)
+    if not human.db.shop[shopType].goods or not human.db.shop[shopType].goods[index] then
+        return false
+    end
+
+    if not human.db.shop[shopType].goods[index].bChose then
+        human.db.shop[shopType].goods[index].bChose = 0
+    end
+
+    human.db.shop[shopType].goods[index].bChose = nValue
+    
+    return true
+end
+
 -- 花费刷新总次数
 function getCostCntMax(human, shopType)
     if shopType == ShopDefine.SHOP_TYPE_BLACKMARKET then
@@ -137,12 +175,8 @@ function query(human, shopType)
 
     initHumanShopDB(human,shopType)
     checkFreeCnt(human,shopType)
-	msgRet.nextRefreshTime = 0
-	msgRet.freeCnt = human.db.shop[shopType].freeCnt
-	msgRet.freeMax = shopTypeConfig.freeCnt
-	msgRet.costCnt = getLeftCostCnt(human, shopType)
-	msgRet.costMax = getCostCntMax(human, shopType)
 
+	msgRet.nextRefreshTime = 0
 
     if human.db.shop[shopType].refreshTs > now then
         msgRet.nextRefreshTime = human.db.shop[shopType].refreshTs - now
@@ -150,6 +184,14 @@ function query(human, shopType)
 
     cleanShopGoods(human, shopType)
 
+    -- 自动购买
+    AutoBuyChoseItem(human, shopType)
+
+    msgRet.freeCnt = human.db.shop[shopType].freeCnt
+	msgRet.freeMax = shopTypeConfig.freeCnt
+	msgRet.costCnt = getLeftCostCnt(human, shopType)
+	msgRet.costMax = getCostCntMax(human, shopType)
+
     -- 不刷新的没有记录的 走配置
     local cnt = 0
     if shopTypeConfig.refreshType == ShopDefine.SHOP_REFRESH_TYPE0 then
@@ -167,6 +209,8 @@ function query(human, shopType)
              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
     end
@@ -184,6 +228,8 @@ function query(human, shopType)
         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
@@ -268,8 +314,8 @@ function refresh(human, shopType)
 
 
     -- 自动购买
-    if shopType == ShopDefine.SHOP_MAIN_TYPE_1 and human.db.shop[shopType].recordList then
-        BuyItemBtAuto(human)
+    if (shopType == ShopDefine.SHOP_MAIN_TYPE_1 or shopType == ShopDefine.SHOP_TYPE_XUYUAN) and human.db.shop[shopType].recordList then
+        BuyItemBtAuto(human, shopType)
     end
 
     
@@ -729,21 +775,22 @@ end
 
 
 -- 自动购买基础商店中随机商店里被记录的商品
-function BuyItemBtAuto(human)
-    local recordList = human.db.shop[ShopDefine.SHOP_MAIN_TYPE_1] and human.db.shop[ShopDefine.SHOP_MAIN_TYPE_1].recordList
+function BuyItemBtAuto(human, shopType)
+    local recordList = human.db.shop[shopType] and human.db.shop[shopType].recordList
     if not recordList or not next(recordList) then
+        print("[BuyItemBtAuto] 不存在对应数据")
         return
     end
 
-    local shopConfig = ShopExcel[ShopDefine.SHOP_MAIN_TYPE_1]
-    local goods = human.db.shop[ShopDefine.SHOP_MAIN_TYPE_1].goods
+    local shopConfig = ShopExcel[shopType]
+    local goods = human.db.shop[shopType].goods
 
 	if not shopConfig or not goods then
+        print("[BuyItemBtAuto] 没有对应物品数据")
         return
     end
 
-    cleanShopGoods(human, ShopDefine.SHOP_MAIN_TYPE_1)
-
+    cleanShopGoods(human, shopType)
 
     local len = 0
     local itemVector = {}
@@ -779,6 +826,8 @@ function BuyItemBtAuto(human)
     if len == 0 then
         Broadcast.sendCenter(human, Lang.ITEM_BUY_DEFAULT)
     else
+        print("[BuyItemBtAuto] 开始给奖励")
+
         BagLogic.addItemList(human, itemVector, "shop_buy")
     end
 
@@ -788,9 +837,9 @@ end
 
 
 -- 查询记录基础商店中随机商店的道具Idx列表
-function RecordItems_Query(human)
+function RecordItems_Query(human, shopType)
     local shopData = human.db.shop
-    local recordList = (shopData and shopData[ShopDefine.SHOP_MAIN_TYPE_1]) and shopData[ShopDefine.SHOP_MAIN_TYPE_1].recordList
+    local recordList = (shopData and shopData[shopType]) and shopData[shopType].recordList
 
     local msgRet = Msg.gc.GC_SHOP_RECORD_QUERY
     local itemIdxList = msgRet.itemIdxList
@@ -808,7 +857,7 @@ end
 
 
 -- 记录基础商店中随机商店的道具Idx列表
-function RecordItems(human, itemIdxStr)
+function RecordItems(human, itemIdxStr, shopType)
     local isBuyCard = MonthCard.IsBuyEverlastingCard(human)
 
     if not isBuyCard then
@@ -823,16 +872,16 @@ function RecordItems(human, itemIdxStr)
     end
 
 
-    human.db.shop[ShopDefine.SHOP_MAIN_TYPE_1].recordList = itemIdxList
+    human.db.shop[shopType].recordList = itemIdxList
 
-    RecordItems_Query(human)
+    RecordItems_Query(human, shopType)
 
     Broadcast.sendCenter(human, Lang.EQUIP_WASH_SAVE_SUC)
 end
 
 -- 查询记录基础商店中随机商店的所有道具
-function AllItem_Query(human)
-	local shopConfig = ShopExcel[ShopDefine.SHOP_MAIN_TYPE_1]
+function AllItem_Query(human, shopType)
+	local shopConfig = ShopExcel[shopType]
 	if not shopConfig then return end
 
     local cnt = 0
@@ -856,8 +905,126 @@ function AllItem_Query(human)
         msgRet.itemList[cnt].needVipLv = itemInfo.needVipLv
         msgRet.itemList[cnt].rare = itemInfo.rare
         msgRet.itemList[cnt].limitType = itemInfo.limitType
+        msgRet.itemList[cnt].bCanChose = itemInfo.isquickbuy and itemInfo.isquickbuy or 0
+        msgRet.itemList[cnt].bChose = ShopLogic_GetChose(human, shopType, idx)
     end
 
 	msgRet.itemList[0] = cnt
 	Msg.send(msgRet, human.fd)
+end
+
+-- 选中物品
+function ChoseItem(human, shopType, bChose, itemIndex)
+    local isBuyCard = MonthCard.IsBuyEverlastingCard(human)
+    if not isBuyCard then
+        return Broadcast.sendErr(human, Lang.EVERLASTING_CARD_UNACTIVE)
+    end
+
+    local tempConfig = ShopExcel[shopType][itemIndex]
+	if tempConfig == nil then
+        print("[ChoseItem] 不存在对应的配置")
+		return
+	end
+
+    local nNowChose = ShopLogic_GetChose(human, shopType, itemIndex)
+    if nNowChose == bChose then
+        return
+    end
+
+    local bRet = ShopLogic_SetChose(human, shopType, itemIndex, bChose)
+    if false == bRet then
+        print("[ChoseItem] 设置失败")
+        return
+    end
+
+    --query(human, shopType)
+end
+
+-- 自动购买勾选的物品
+function AutoBuyChoseItem(human, shopType, bCanBuy)
+    local isBuyCard = MonthCard.IsBuyEverlastingCard(human)
+    if not isBuyCard then
+        return
+    end
+
+    if shopType == ShopDefine.SHOP_TYPE_XUYUAN then
+        if nil == bCanBuy or false == bCanBuy then
+            return
+        end
+    end
+
+    print("[AutoBuyChoseItem] 进入自动购买")
+
+    local tItemList = {}
+    for k,v in pairs(human.db.shop[shopType].goods) do
+        if v.bChose and 1 == v.bChose then
+            local nIndex = v.index
+            local tempConfig = ShopExcel[shopType][nIndex]
+            local nowBuy = v.nowBuy
+            if tempConfig and tempConfig.limitBuyCnt - nowBuy > 0 then
+                local nItemID = tempConfig.itemID
+                -- 装备检测数量
+                if ItemDefine.isEquip(itemID) then
+                    if not EquipLogic.checkEmptyCnt(human, buyCnt * tempConfig.cnt) then
+                        break
+                    end
+                end
+            
+                -- 符文检测数量
+                if ItemDefine.isFuwen(itemID) then
+                    if not FuwenGrid.checkEmptyCnt(human, buyCnt * tempConfig.cnt) then
+                        break
+                    end
+                end
+
+                local nBuyCnt = tempConfig.limitBuyCnt - nowBuy
+                local needItemID = tempConfig.needItemID
+                local needItemCnt = tempConfig.price * nBuyCnt
+                local nowItemCnt = BagLogic.getItemCnt(human, needItemID)
+                if nowItemCnt >= needItemCnt then
+                    v.nowBuy = v.nowBuy + nBuyCnt
+                    local refreshType = ShopExcel.shop[shopType].refreshType
+                    if refreshType == ShopDefine.SHOP_REFRESH_TYPE6
+                        or refreshType == ShopDefine.SHOP_REFRESH_TYPE7 then
+                        buyAllItemsRefresh(human,shopType)
+                    end
+
+                    -- 先删
+                    BagLogic.delItem(human, needItemID, needItemCnt, "shop_buy", nil, itemID, nBuyCnt * tempConfig.cnt)
+
+                    if not tItemList[tempConfig.itemID] then
+                        tItemList[tempConfig.itemID] = 0
+                    end
+
+                    tItemList[tempConfig.itemID] = tItemList[tempConfig.itemID] + nBuyCnt * tempConfig.cnt
+                else
+                    break
+                end
+            end
+        end
+    end
+
+    print("[AutoBuyChoseItem] 循环结束")
+    table.print_lua_table(tItemList)
+    if nil ~= _G.next(tItemList) then
+        local tGoods = {}
+        for k, v in pairs(tItemList) do
+            table.insert(tGoods, {k,v})
+        end
+
+        print("AutoBuyChoseItem [添加物品开始打印]")
+        table.print_lua_table(tGoods)
+        BagLogic.addItemList(human, tGoods, "shop_buy")
+        print("AutoBuyChoseItem [添加物品结束打印]")
+    end
+end
+
+function GetBuyLiftTimeCard(human)
+    local tMsgData = Msg.gc.GC_BUY_LIFTTIME_CARD
+    tMsgData.bBuy = 0
+    if MonthCard.IsBuyEverlastingCard(human) then
+        tMsgData.bBuy = 1
+    end
+
+    Msg.send(tMsgData, human.fd)
 end