浏览代码

修改物品消耗,绑金不足,由金币补充

huangyuhao 1 年之前
父节点
当前提交
51e5c6e614
共有 7 个文件被更改,包括 77 次插入23 次删除
  1. 37 0
      dev/data/bag.lua
  2. 11 0
      dev/modules/bag.lua
  3. 6 3
      dev/modules/pay.lua
  4. 3 3
      dev/modules/pmail.lua
  5. 8 0
      dev/modules/sharecode.lua
  6. 3 4
      dev/utils/util_box.lua
  7. 9 13
      nodes/game/interface/box.lua

+ 37 - 0
dev/data/bag.lua

@@ -95,6 +95,7 @@ end
95 95
 -- 判断资源是否足够
96 96
 function root:is_enough(uid, items)
97 97
     -- 求和
98
+    local isExchangeDiamond = false
98 99
     local tempMap = {}
99 100
     for _, v in ipairs(items) do
100 101
         if not tempMap[v.id] then
@@ -102,6 +103,9 @@ function root:is_enough(uid, items)
102 103
         else
103 104
             tempMap[v.id] = tempMap[v.id] + v.count
104 105
         end
106
+        if v.id == gameConst.ITEM_ID.DIAMOND then
107
+            isExchangeDiamond = true
108
+        end
105 109
     end
106 110
 
107 111
     local itemList = moduleData:hget_json(uid, MODULE_NAME, "itemList") or {}
@@ -114,6 +118,39 @@ function root:is_enough(uid, items)
114 118
             break
115 119
         end
116 120
     end
121
+    -- 转换绑金
122
+    if ret == false and isExchangeDiamond then
123
+        local item = table.key_find(itemList, "id", gameConst.ITEM_ID.DIAMOND)
124
+        local addGold = tempMap[gameConst.ITEM_ID.DIAMOND]
125
+        if item and not is_empty(item.count) then
126
+            addGold = addGold - item.count
127
+        end
128
+        -- 增加金币消耗
129
+        if addGold >= 0 then
130
+            tempMap[gameConst.ITEM_ID.GOLD] = (tempMap[gameConst.ITEM_ID.GOLD] or 0) + addGold
131
+
132
+            ret = true
133
+            -- 重新检查是否充足
134
+            for k, v in pairs(tempMap) do
135
+                local _item = table.key_find(itemList, "id", k)
136
+                if not _item or not _item.count or _item.count < v then
137
+                    ret = false
138
+                    break
139
+                end
140
+            end
141
+        end
142
+        if ret == true then
143
+            -- 修改消耗物品列表
144
+            local costItems = {}
145
+            for k, v in pairs(tempMap) do
146
+                table.insert(costItems, {id = k, count = v})
147
+            end
148
+            return true, costItems
149
+        end
150
+    end
151
+    if ret == true then
152
+        return true, items
153
+    end
117 154
 
118 155
     return ret
119 156
 end

+ 11 - 0
dev/modules/bag.lua

@@ -1,3 +1,14 @@
1
+--[[
2
+Descripttion:背包
3
+version:
4
+Author: Neo,Huang
5
+Date: 2023-11-15 22:34:35
6
+LastEditors: Neo,Huang
7
+LastEditTime: 2023-11-15 23:54:11
8
+--]]
9
+local code = require("code")
10
+local resAdapt = require("adapt.resAdapt")
11
+
1 12
 local bagData = require("data.bag")
2 13
 local gameConst = require("const.gameConst")
3 14
 

+ 6 - 3
dev/modules/pay.lua

@@ -1,11 +1,14 @@
1 1
 --[[
2
-Descripttion:支付订单模块
2
+Descripttion:支付统计
3 3
 version:
4 4
 Author: Neo,Huang
5
-Date: 2022-08-17 16:04:20
5
+Date: 2023-11-15 22:34:35
6 6
 LastEditors: Neo,Huang
7
-LastEditTime: 2022-09-05 10:05:30
7
+LastEditTime: 2023-11-15 23:57:03
8 8
 --]]
9
+local code = require("code")
10
+local gameConst = require("const.gameConst")
11
+local util_user = require("utils.util_user")
9 12
 local shopAdapt = require("adapt.shopAdapt")
10 13
 
11 14
 local payData = require("data.pay")

+ 3 - 3
dev/modules/pmail.lua

@@ -39,7 +39,7 @@ function root:add_read_mail(id)
39 39
 	if table.include(readIdList, id) then
40 40
 		return false
41 41
 	end
42
-	table.insetr(readIdList, id)
42
+	table.insert(readIdList, id)
43 43
 	self:redis_update_key_info("readIdList", readIdList)
44 44
 end
45 45
 -- 是否已读
@@ -63,7 +63,7 @@ function root:add_del_mail(id)
63 63
 	if table.include(delIdList, id) then
64 64
 		return false
65 65
 	end
66
-	table.insetr(delIdList, id)
66
+	table.insert(delIdList, id)
67 67
 	self:redis_update_key_info("delIdList", delIdList)
68 68
 end
69 69
 -- 是否已读
@@ -87,7 +87,7 @@ function root:add_award_mail(id)
87 87
 	if table.include(awardIdList, id) then
88 88
 		return false
89 89
 	end
90
-	table.insetr(awardIdList, id)
90
+	table.insert(awardIdList, id)
91 91
 	self:redis_update_key_info("awardIdList", awardIdList)
92 92
 	return true
93 93
 end

+ 8 - 0
dev/modules/sharecode.lua

@@ -1,4 +1,11 @@
1
+--[[
2
+Descripttion:邀请码
3
+version:
4
+Author: Neo,Huang
5
+Date: 2023-11-15 22:34:35
6
+LastEditors: Neo,Huang
7
+LastEditTime: 2023-11-15 23:58:55
8
+--]]
1 9
 local root = class("sharecode", require("base.baseModule"))
2 10
 
3 11
 function root:ctor(sharecode)

+ 3 - 4
dev/utils/util_box.lua

@@ -1,12 +1,11 @@
1 1
 --[[
2
-Descripttion:玩家事件
2
+Descripttion:开箱子
3 3
 version:
4 4
 Author: Neo,Huang
5
-Date: 2022-07-05 19:59:16
5
+Date: 2023-11-15 22:34:35
6 6
 LastEditors: Neo,Huang
7
-LastEditTime: 2022-07-05 20:08:31
7
+LastEditTime: 2023-11-15 22:41:18
8 8
 --]]
9
-local lib_game_redis = require("lib_game_redis")
10 9
 local timeUtil = require("utils.timeUtil")
11 10
 local redisUtil = require("utils.redisUtil")
12 11
 local util_player = require("utils.util_player")

+ 9 - 13
nodes/game/interface/box.lua

@@ -1,10 +1,10 @@
1 1
 --[[
2
-Descripttion:接口 - 开箱子
2
+Descripttion:开箱子
3 3
 version:
4 4
 Author: Neo,Huang
5
-Date: 2022-07-05 17:32:01
5
+Date: 2023-11-15 22:34:35
6 6
 LastEditors: Neo,Huang
7
-LastEditTime: 2022-07-05 20:29:29
7
+LastEditTime: 2023-11-15 22:42:18
8 8
 --]]
9 9
 local code = require("code")
10 10
 local util_box = require("utils.util_box")
@@ -38,21 +38,17 @@ function root:box_blind_open(role, msg)
38 38
     local items = nil
39 39
     for i = 1, count do
40 40
         -- 掉落物品
41
-        local itemId, count = util_box:get_box_drop_item_and_count(id)
42
-        if not is_empty(itemId) and not is_empty(count) then
43
-            local costItems = {{id = gameConst.ITEM_ID.DIAMOND, count = conf.diamondPrice}}
44
-            if not bagData:is_enough(uid, costItems) then
45
-                -- 绑金不足,使用金币
46
-                costItems = {{id = gameConst.ITEM_ID.GOLD, count = conf.goldPrice}}
47
-                if not bagData:is_enough(uid, costItems) then
48
-                    break
49
-                end
41
+        local itemId, itemCount = util_box:get_box_drop_item_and_count(id)
42
+        if not is_empty(itemId) and not is_empty(itemCount) then
43
+            local ok, costItems = bagData:is_enough(uid, {{id = gameConst.ITEM_ID.DIAMOND, count = conf.price}})
44
+            if not ok then
45
+                break
50 46
             end
51 47
             -- 消耗
52 48
             local eventId = string.format("box-blind-%s", tostring(id))
53 49
             bagData:consume_items(uid, costItems, eventId)
54 50
             -- 获取物品
55
-            local _items = {{id = itemId, count = count}}
51
+            local _items = {{id = itemId, count = itemCount}}
56 52
             bagData:add_items(uid, _items, eventId)
57 53
 
58 54
             items = itemUtil.items_merge(items, _items)