|
|
@@ -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
|