neo vor 2 Jahren
Ursprung
Commit
be65c20916

+ 0 - 21
common/core/nodeMgr.lua

@@ -143,28 +143,6 @@ function root.get_type_node_list(nodeType)
143 143
 	return nodes
144 144
 end
145 145
 
146
-function root.dispatch_battle_node_and_agent()
147
-	local ok, server = root.call("battlemaster", ".srvNodeMgr", "dispatch_battle_node")
148
-	if not ok or server == nil then
149
-		return
150
-	end
151
-	if is_empty(server.battleNode) or server.battleId == nil then
152
-		log.error(string.format("分配对战服失败, newBattleId=%s", server.battleId))
153
-		return
154
-	end
155
-
156
-	local ok, handle = root.call(server.battleNode, ".BattleMgr", "getBattleAgent")
157
-	if not ok or handle == nil then
158
-		return
159
-	end
160
-	local info = {}
161
-	info.nodeName = server.battleNode
162
-	info.agent = handle
163
-	info.battleId = server.battleId
164
-	return info
165
-end
166
-
167 146
 -- 节点信息是否合法
168 147
 function root.is_node_info_valid(nodeInfo)
169 148
 	if nodeInfo == nil then

+ 0 - 43
dev/utils/util_user.lua

@@ -128,22 +128,6 @@ function root:user_dispatch_game(uid)
128 128
     end
129 129
     return {nodeName = node.nodename, agent = gameAgent}
130 130
 end
131
-function root:user_dispatch_match_node(uid, conf)
132
-    local ok, matchNode = nodeMgr.call("battlemaster", ".srvNodeMgr", "dispatch_match_node", uid, conf)
133
-    if not ok or is_empty(matchNode) then
134
-        return
135
-    end
136
-
137
-    local ok, matchAgent = nodeMgr.call(matchNode, ".BattleMatch", "dispatch_match_agent", conf.battleType)
138
-    if not ok then
139
-        return
140
-    end
141
-    local nodeInfo = {}
142
-    nodeInfo.nodeName = matchNode
143
-    nodeInfo.agent = matchAgent
144
-    return nodeInfo
145
-end
146 131
 
147 132
 local MODULE_SESSION = "session"
148 133
 -- 玩家节点信息
@@ -208,33 +192,4 @@ function root:master_user_logout(uid, ...)
208 192
     return nodeMgr.call("master", ".srvNodeMgr", "userLogout", clusterName, nodename, uid, ...)
209 193
 end
210 194
 
211
-----------------------------------------
212
-----------------------------------------
213
-function root:user_call_2_battle(uid, cmd, ...)
214
-    if uid == nil or cmd == nil then
215
-        return code.PARAMTER_ERROR
216
-    end
217
-    local nodeInfo = self:user_get_cluster_info(uid, "battle")
218
-    if not nodeMgr.is_node_info_valid(nodeInfo) or nodeInfo.battleId == nil then
219
-        return code.BATTLE.NOT_EXIST
220
-    end
221
-    local ok, ret = nodeMgr.call_with_node_info(nodeInfo, "forward", nodeInfo.battleId, cmd, ...)
222
-    if not ok or ret == nil then
223
-        return code.BATTLE.NOT_EXIST
224
-    end
225
-    return ret.code, ret
226
-end
227
-
228
-function root:user_send_2_battle(uid, cmd, ...)
229
-    if uid == nil or cmd == nil then
230
-        return code.PARAMTER_ERROR
231
-    end
232
-    local nodeInfo = self:user_get_cluster_info(uid, "battle")
233
-    if not nodeMgr.is_node_info_valid(nodeInfo) or nodeInfo.battleId == nil then
234
-        return code.BATTLE.NOT_EXIST
235
-    end
236
-    nodeMgr.send_with_node_info(nodeInfo, "forward", nodeInfo.battleId, cmd, ...)
237
-end
238
-
239 195
 return root

+ 0 - 369
nodes/battle/lib/battle.lua

@@ -1,378 +0,0 @@
1
-local skynet = require "skynet"
2
-local battleCore = require "battle.battleCore"
3
-local battleLog = require "battle.battleLog"
4
-local battleCode = require "battle.battleCode"
5
-local battleDefine = require "battle.battleDefine"
6
-local nodeMgr = require "nodeMgr"
7
-local httpc = require "http.httpc"
8
-local md5 = require "md5"
9
-local machine = require "machine"
10
-local code = require "code"
11
-local util_user = require "utils.util_user"
12
-local gameConst = require("const.gameConst")
13
-local battleAdapt = require "adapt.battleAdapt"
14
-
15
-local sessionData = require("data.session")
16
-local battleData = require("data.battle")
17
-
18
-local nodename = skynet.getenv("nodeName")
19
-
20
-local root = class("Battle")
21
-
22
-function root:ctor(matchInfo, battleParams, settleNodeInfo)
23
-    self.matchNodeInfo = {}
24
-    self.matchNodeInfo.nodeName = matchInfo.matchNode
25
-    self.matchNodeInfo.agent = matchInfo.matchAgent
26
-
27
-    self.roomId = matchInfo.roomId
28
-    self.matchId = matchInfo.matchId
29
-    self.battleId = matchInfo.battleId
30
-    self.isMatchSettle = matchInfo.isMatchSettle -- 结算经过业务服
31
-
32
-    self.settleNodeInfo = settleNodeInfo -- 结算节点
33
-
34
-    self.battleParams = battleParams
35
-    local w = battleParams.w
36
-    local h = battleParams.h
37
-    local debugJsonObj = battleParams.debugJsonObj
38
-    self.core = battleCore.new(self, matchInfo.battleReal, matchInfo.battleType, w, h, debugJsonObj)
39
-
40
-    self.record = {}
41
-    self.isActive = true
42
-end
43
-
44
-function root:get_core_id()
45
-    return string.format("%s:%s:%s", self.matchNodeInfo.nodeName, self.matchId, self.battleId)
46
-end
47
-
48
-function root:enableRecord()
49
-    return true
50
-end
51
-
52
-function root:addRecord(protoName, msg)
53
-    if self:enableRecord() then
54
-        table.insert(self.record, {proto = protoName, data = msg})
55
-    end
56
-end
57
-
58
-local protos = {
59
-    "on_battle_qipan_info",
60
-    "on_battle_operate_info",
61
-    "on_battle_start",
62
-    "on_battle_finish",
63
-    "on_battle_attack",
64
-    "on_battle_attack_finish",
65
-    "on_battle_create_info"
66
-}
67
-
68
-function root:notifyPlayer(uid, protoName, msg)
69
-    if uid == nil or is_robot(uid) or is_empty(protoName) then
70
-        return
71
-    end
72
-
73
-    local uidList = self.core:get_real_uid_list()
74
-    if uidList[1] == uid and table.include(protos, protoName) then
75
-        self:addRecord(protoName, msg)
76
-    end
77
-
78
-    util_user:user_proto_notify(uid, protoName, msg)
79
-end
80
-
81
-function root:game_player_settle(uid, msg)
82
-    -- 机器人
83
-    if uid == nil or is_robot(uid) then
84
-        return
85
-    end
86
-    -- 玩家不在线
87
-    local nodeInfo = util_user:user_get_cluster_info(uid, "game")
88
-    if not nodeMgr.is_node_info_valid(nodeInfo) then
89
-        nodeMgr.send("game1_1", ".settleSrv", "offline_settle", uid, msg)
90
-        return
91
-    end
92
-    util_user:user_send_game_agent(uid, "battle.settleBattle", msg)
93
-end
94
-
95
-function root:notifyClientLog(uid, logStr)
96
-    if uid == nil or is_robot(uid) or is_empty(logStr) then
97
-        return
98
-    end
99
-    battleLog:logClient(logStr)
100
-
101
-    -- TODO: Debug 测试代码,上线前修改过来.
102
-    util_user:user_notify_client_log(uid, logStr)
103
-end
104
-
105
-function root:recordOpenLog(...)
106
-    local logUtil = require "utils.serverLogUtil"
107
-    logUtil.logOpen(...)
108
-end
109
-
110
-function root:logEvent(...)
111
-    util_user:log_event(...)
112
-end
113
-
114
-function root:getBattleNode()
115
-    return nodename
116
-end
117
-
118
-function root:getBattleId()
119
-    return self.battleId
120
-end
121
-
122
-function root:getBattleParams()
123
-    return self.battleParams
124
-end
125
-
126
-local GAME_SALT_MD5 = "0bdb9a5863c8c9063a42f38a9d5166fe" -- 游戏服加盐 md5
127
-
128
-local function sendRecord(battleNode, battleStartTime, battleId, version, record)
129
-    local server = machine.get("record_server")
130
-    if is_nil(server) then
131
-        return
132
-    end
133
-    local url = "/record/add?sign="
134
-    local head = {["Content-Type"] = "application/json"}
135
-    local body =
136
-        cjson_encode(
137
-        {
138
-            node = tostring(battleNode),
139
-            startTime = tonumber(battleStartTime),
140
-            id = tonumber(battleId),
141
-            version = tostring(version),
142
-            record = cjson_encode(record)
143
-        }
144
-    )
145
-    url = url .. md5.sumhexa(body .. GAME_SALT_MD5)
146
-    local ok, errCode, response = pcall(httpc.request, "POST", server, url, nil, head, body)
147
-    if not ok then
148
-        battleLog:logError(
149
-            string.format(
150
-                "添加录像失败 battleNode=%s battleStartTime=%s battleId=%s version=%s",
151
-                battleNode,
152
-                battleStartTime,
153
-                battleId,
154
-                version
155
-            )
156
-        )
157
-    end
158
-    if errCode ~= 200 then
159
-        battleLog:logError(
160
-            string.format(
161
-                "添加录像失败 battleNode=%s battleStartTime=%s battleId=%s version=%s response=%s",
162
-                battleNode,
163
-                battleStartTime,
164
-                battleId,
165
-                version,
166
-                tostring(response and cjson_decode(response))
167
-            )
168
-        )
169
-    end
170
-end
171
-
172
-function root:startBattle(playerList, viewerList)
173
-    local battleInfo = {
174
-        matchId = self.matchId,
175
-        battleId = self.battleId,
176
-        nodeName = nodename,
177
-        agent = skynet.self()
178
-    }
179
-    for _, v in ipairs(playerList) do
180
-        if not is_robot(v.uid) then
181
-            sessionData:user_update_cluster_info(v.uid, "battle", battleInfo)
182
-        end
183
-    end
184
-    self.core:startBattle(playerList, viewerList)
185
-end
186
-
187
-function root:settleBattle(result)
188
-    -- 测试战斗类型
189
-    if battleAdapt:isAiTestBattle(self.core.battleType) then
190
-        log.warning(
191
-            "settleBattle battleId[%s] settleNodeInfo[%s]",
192
-            tostring(self.battleId),
193
-            tostring(self.settleNodeInfo)
194
-        )
195
-        if nodeMgr.is_node_info_valid(self.settleNodeInfo) then
196
-            nodeMgr.send_with_node_info(self.settleNodeInfo, "settle", result)
197
-        else
198
-            nodeMgr.send("test", ".aiSrv", "settle", result)
199
-        end
200
-        return
201
-    end
202
-    -- 组队
203
-    -- 业务服结算
204
-    if self.isMatchSettle then
205
-        nodeMgr.send_with_node_info(self.matchNodeInfo, "match_settle", self.roomId, result)
206
-        return
207
-    end
208
-
209
-    for _, v in ipairs(self.core:getAllPlayer()) do
210
-        self:game_player_settle(v.uid, result)
211
-    end
212
-end
213
-
214
-function root:dismissBattle(reason)
215
-    self.isActive = false
216
-    battleLog:logWarning(string.format("开始销毁对战服务并退出 battleId=%s reason=%s", self.battleId, reason))
217
-    nodeMgr.send_with_node_info(self.matchNodeInfo, "destory_battle", self.roomId)
218
-    local uidList = self.core:get_real_uid_list()
219
-    for _, v in ipairs(uidList) do
220
-        -- 清除玩家战斗节点信息
221
-        battleData:user_clear_battle_info(v)
222
-
223
-        self:notifyPlayer(v, "on_battle_finish", {code = battleCode.OK})
224
-    end
225
-    if self:enableRecord() then
226
-        sendRecord(self:getBattleNode(), self.core.battleStartTime, self:getBattleId(), 1.0, self.record)
227
-    end
228
-
229
-    skynet.call(".BattleMgr", "lua", "battleLeave", self.battleId, skynet.self())
230
-end
231
-
232
-function root:loginBattle(uid)
233
-    battleLog:logInfo(string.format("玩家%d登入对战", uid))
234
-    local playerData = self.core:getPlayer(uid)
235
-    if not playerData then
236
-        -- 围观进入
237
-        self.core:viewerLoginBattle(uid)
238
-        return
239
-    end
240
-    self.core:loginBattle(playerData)
241
-    -- self:playFinish(uid, self.core:getCurRound())
242
-end
243
-
244
-function root:logoutBattle(uid)
245
-    battleLog:logInfo(string.format("玩家%d登出对战", uid))
246
-    local playerData = self.core:getPlayer(uid)
247
-    if not playerData then
248
-        return
249
-    end
250
-    self.core:logoutBattle(playerData)
251
-    -- self.core:dismissBattle("force")
252
-end
253
-
254
-function root:is_user_in_battle(uid)
255
-    local playerData = self.core:getPlayer(uid)
256
-    if playerData then
257
-        return true
258
-    end
259
-    return false
260
-end
261
-
262
-function root:operate(uid, ids, exSkillGridId)
263
-    if not ids or #ids < battleDefine.MIN_LINK_BLOCK then
264
-        return {code = battleCode.BATTLE_COUNT_LESS}
265
-    end
266
-    local playerData = self.core:getPlayer(uid)
267
-    if not playerData then
268
-        return {code = battleCode.BATTLE_PLAYER_NOT_EXIST}
269
-    end
270
-    if self.core:getNextLinkUid() ~= uid then
271
-        return {code = battleCode.BATTLE_ROUND_ERR}
272
-    end
273
-    if self.core:isPlayerOperated(playerData) then
274
-        return {code = battleCode.BATTLE_OPERATED}
275
-    end
276
-    if not self.core:operate(playerData, ids, exSkillGridId) then
277
-        if IS_TEST then
278
-            self.core:sendTestGrids(playerData)
279
-        end
280
-        return {code = battleCode.BATTLE_CANNOT_LINK}
281
-    end
282
-    return {code = battleCode.OK}
283
-end
284
-
285
-function root:playFinish(uid, round)
286
-    local playerData = self.core:getPlayer(uid)
287
-    if not playerData then
288
-        return {code = battleCode.BATTLE_PLAYER_NOT_EXIST}
289
-    end
290
-    if self.core:getCurRound() ~= round then
291
-        return {code = battleCode.BATTLE_ROUND_EXPIRED}
292
-    end
293
-    self.core:playFinish(playerData, uid, round)
294
-    return {code = battleCode.OK}
295
-end
296
-function root:auto_link(uid, isAuto)
297
-    local playerData = self.core:getPlayer(uid)
298
-    if not playerData then
299
-        return {code = battleCode.BATTLE_PLAYER_NOT_EXIST}
300
-    end
301
-
302
-    self.core:updateAutoLink(playerData, isAuto)
303
-
304
-    return {code = code.OK}
305
-end
306
-
307
-function root:info(uid)
308
-    local playerData = self.core:getPlayer(uid)
309
-    if not playerData then
310
-        return {code = battleCode.BATTLE_PLAYER_NOT_EXIST}
311
-    end
312
-    self.core:info(playerData)
313
-    return {code = battleCode.OK}
314
-end
315
-
316
-function root:debug(uid, debugType, debugArgs)
317
-    local playerData = self.core:getPlayer(uid)
318
-    if not playerData then
319
-        return {code = battleCode.BATTLE_PLAYER_NOT_EXIST}
320
-    end
321
-    local errorMsg
322
-    if IS_TEST then
323
-        errorMsg = self.core:debug(playerData, debugType, debugArgs)
324
-    end
325
-    return {code = battleCode.OK, errorMsg = errorMsg}
326
-end
327
-
328
-function root:chat(uid, id, text)
329
-    local playerData = self.core:getPlayer(uid)
330
-    if not playerData then
331
-        return {code = battleCode.BATTLE_PLAYER_NOT_EXIST}
332
-    end
333
-    self.core:chat(playerData, id, text)
334
-    return {code = battleCode.OK}
335
-end
336
-
337
-function root:getOverview(uid)
338
-    local playerData = self.core:getPlayer(uid)
339
-    if not playerData then
340
-        return {code = battleCode.BATTLE_PLAYER_NOT_EXIST}
341
-    end
342
-    local msg = self.core:getOverview(playerData)
343
-    msg.code = battleCode.OK
344
-    return msg
345
-end
346
-
347
-function root:addViewers(uid)
348
-    self.core:addViewers(uid)
349
-end
350
-
351
-function root:deleteViewers(uid)
352
-    self.core:deleteViewers(uid)
353
-end
354
-
355
-function root:ping(uid)
356
-    local playerData = self.core:getPlayer(uid)
357
-    return playerData and true or false
358
-end
359
-
360
-function root:fastSettle(uid)
361
-    log.info("battle fastSettle uid = %s", tostring(uid))
362
-    self.core:settleBattle(2, nil, uid)
363
-end
364
-
365
-function root:isServerBattleAiOpen()
366
-    return true
367
-end
368
-
369
-return root

+ 0 - 622
nodes/battle/lib/battleAiAssistSkillEvaluate.lua

@@ -1,735 +0,0 @@
1
---[[
2
- * File name: battleAiAssistSkillEvaluate.lua
3
- * Version:
4
- * Author: sky
5
- * Date time: 2023-06-27 10:29:27
6
- * Copyright (C) 2023.
7
- * Description: 辅助技能AI评分
8
---]]
9
-local battleAdapt = require "adapt.battleAdapt"
10
-local battleLog = require "battle.battleLog"
11
-local battleConst = require "battle.battleConst"
12
-
13
-----------------------------------------
14
-local _StAiAssistSkillMatching = {}
15
-local AiAssistSkillMatching =
16
-    setmetatable(
17
-    _StAiAssistSkillMatching,
18
-    {
19
-        __index = function(self, key)
20
-            -- print(tostring(self))
21
-            local funcName = string.format("getAiAssiSkillEvaluate%s", key)
22
-
23
-            local func = self.funcs[funcName]
24
-            if func then
25
-                return func
26
-            else
27
-                return self.funcs.getAiAssiSkillEvaluateCommon
28
-            end
29
-        end
30
-    }
31
-)
32
-
33
-------------------------------------------------------------
34
-local funcs = {}
35
-_StAiAssistSkillMatching.funcs = funcs
36
-
37
-------------------------------------------------------------
38
-
39
-local root = {}
40
-
41
-function root:getAiAssistSkillConfig(core, skillInfo)
42
-    local skillConfig = battleAdapt:getSkillByID(skillInfo.skillId or 0)
43
-    if skillConfig and skillConfig and #skillConfig.effectGroup > 0 then
44
-        for _, effectId in ipairs(skillConfig.effectGroup) do
45
-            local assistSkillConfig = battleAdapt:getAssistByEffectID(effectId)
46
-            if assistSkillConfig and (assistSkillConfig.params1 and not assistSkillConfig.params1.buffId) then
47
-                return assistSkillConfig
48
-            end
49
-        end
50
-    end
51
-end
52
-
53
-function root:getAiAssistSkillEvaluate(core, actionCastle, skillInfo, params)
54
-    local assistSkillLevel = skillInfo.newHeroAssistSkillLevel
55
-    if not assistSkillLevel or assistSkillLevel <= 0 then
56
-        return 0
57
-    end
58
-
59
-    local assistSkillConfig = self:getAiAssistSkillConfig(core, skillInfo)
60
-    if not assistSkillConfig then
61
-        return 0
62
-    end
63
-
64
-    return AiAssistSkillMatching[(skillInfo or {}).skillId or 0](
65
-        _StAiAssistSkillMatching.funcs,
66
-        core,
67
-        skillInfo,
68
-        params,
69
-        assistSkillConfig
70
-    )
71
-end
72
-
73
-------------------------------------------------------------
74
-
75
-function funcs:getAiAssiSkillEvaluateCommon(core, skillInfo, params, assistSkillConfig)
76
-    local newHeroAttack = params.newHeroAttack
77
-    return newHeroAttack * 0.65
78
-end
79
-
80
-function funcs:getAiAssiSkillEvaluate2221(core, skillInfo, params, assistSkillConfig)
81
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
82
-    -- params1 = {ex={damageNums=0.25}},
83
-    local enemyHeroCount = params.enemyHeroCount -- 敌方英雄个数;
84
-    if enemyHeroCount > 0 then
85
-        local skillBase = skillInfo.skillBase
86
-        return math.floor(assistSkillConfig[parValue].ex.damageNums * skillBase * 0.75)
87
-    end
88
-    return 0
89
-end
90
-
91
-function funcs:getAiAssiSkillEvaluate1221(core, skillInfo, params, assistSkillConfig)
92
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
93
-    -- params1 = {ex={upNums=0.25}},
94
-    local enemyHeroCount = params.enemyHeroCount -- 敌方英雄个数;
95
-
96
-    if enemyHeroCount > 0 then
97
-        local skillBase = skillInfo.skillBase
98
-        return math.floor(assistSkillConfig[parValue].ex.upNums * skillBase * 0.75)
99
-    end
100
-    return 0
101
-end
102
-
103
-function funcs:getAiAssiSkillEvaluate4221(core, skillInfo, params, assistSkillConfig)
104
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
105
-    -- params1 = {defendPercent=10},
106
-
107
-    local selfHeroTotalEv = params.selfHeroTotalEv
108
-    return math.floor(assistSkillConfig[parValue].defendPercent * selfHeroTotalEv * 0.25 * 0.5)
109
-end
110
-
111
-function funcs:getAiAssiSkillEvaluate3221(core, skillInfo, params, assistSkillConfig)
112
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
113
-    -- params1 = {defendPercent=55},
114
-
115
-    local newHeroAttack = params.newHeroAttack
116
-    return math.floor(assistSkillConfig[parValue].defendPercent * newHeroAttack * 0.05)
117
-end
118
-
119
-function funcs:getAiAssiSkillEvaluate2231(core, skillInfo, params, assistSkillConfig)
120
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
121
-    -- params1 = {ex={damageNums=0.25}},
122
-
123
-    local enemyHeroCount = params.enemyHeroCount
124
-    if enemyHeroCount > 0 then
125
-        local skillBase = skillInfo.skillBase
126
-        return math.floor(assistSkillConfig[parValue].ex.damageNums * skillBase * 0.75)
127
-    end
128
-    return 0
129
-end
130
-
131
-function funcs:getAiAssiSkillEvaluate1231(core, skillInfo, params, assistSkillConfig)
132
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
133
-    -- params1 = {upNums=1.25},
134
-
135
-    local skillBase = skillInfo.skillBase
136
-    return math.floor(assistSkillConfig[parValue].upNums * skillBase * 1)
137
-end
138
-
139
-function funcs:getAiAssiSkillEvaluate4231(core, skillInfo, params, assistSkillConfig)
140
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
141
-    -- params1 = {upNums=1.25},
142
-
143
-    local skillBase = skillInfo.skillBase
144
-    return math.floor(assistSkillConfig[parValue].upNums * skillBase * 1)
145
-end
146
-
147
-function funcs:getAiAssiSkillEvaluate3231(core, skillInfo, params, assistSkillConfig)
148
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
149
-    -- params1 = {ex={damagePercent=20}},
150
-
151
-    -- 最弱的敌人
152
-    local enemyHeroList = params.enemyHeroList
153
-    local selfHeroLowestEv = 0
154
-    if #enemyHeroList > 0 and enemyHeroList[1] then
155
-        selfHeroLowestEv = self:getHeroEvaluate(core, enemyHeroList[1]) or 0
156
-    end
157
-
158
-    return math.floor(assistSkillConfig[parValue].ex.damagePercent * selfHeroLowestEv * 0.01 * 0.75)
159
-end
160
-
161
-function funcs:getAiAssiSkillEvaluate2241(core, skillInfo, params, assistSkillConfig)
162
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
163
-    -- params1 = {damageNums=1},
164
-
165
-    local skillBase = skillInfo.skillBase
166
-    return math.floor(assistSkillConfig[parValue].damageNums * 3 * skillBase * 0.5)
167
-end
168
-
169
-function funcs:getAiAssiSkillEvaluate1241(core, skillInfo, params, assistSkillConfig)
170
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
171
-    -- params1 = {ex={damagePercent=63}},
172
-    local enemyHeroCount = params.enemyHeroCount
173
-    if enemyHeroCount == 1 then
174
-        local enemyHeroTotalEv = params.enemyHeroTotalEv
175
-        return math.floor(assistSkillConfig[parValue].ex.damagePercent * 0.01 * enemyHeroTotalEv * 0.5)
176
-    end
177
-    return 0
178
-end
179
-
180
-function funcs:getAiAssiSkillEvaluate4241(core, skillInfo, params, assistSkillConfig)
181
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
182
-    -- params1 = {heroLiveNums=1.2},
183
-
184
-    local skillBase = skillInfo.skillBase
185
-    return math.floor(assistSkillConfig[parValue].heroLiveNums * skillBase * 3 * 0.2)
186
-end
187
-
188
-function funcs:getAiAssiSkillEvaluate3241(core, skillInfo, params, assistSkillConfig)
189
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
190
-    -- params1 = {damageNums=0.1},
191
-
192
-    local skillBase = skillInfo.skillBase
193
-    return math.floor(assistSkillConfig[parValue].damageNums * 13 * skillBase * 0.5)
194
-end
195
-
196
-function funcs:getAiAssiSkillEvaluate2251(core, skillInfo, params, assistSkillConfig)
197
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
198
-    -- params1 = {damagePercent=55},
199
-    local newHeroAttack = params.newHeroAttack
200
-
201
-    return math.floor(
202
-        (assistSkillConfig[parValue].damagePercent * newHeroAttack * 0.75) +
203
-            (assistSkillConfig[parValue].damagePercent * newHeroAttack * 0.75)
204
-    )
205
-end
206
-
207
-function funcs:getAiAssiSkillEvaluate1251(core, skillInfo, params, assistSkillConfig)
208
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
209
-    -- params1 = {ex={damagePercent=50,upX=1.5}},
210
-    local enemyHeroTotalEv = params.enemyHeroTotalEv
211
-    local selfHeroTotalEv = params.selfHeroTotalEv
212
-    return math.floor(
213
-        max(enemyHeroTotalEv - selfHeroTotalEv, 0) * (assistSkillConfig[parValue].ex.upX * 0.5 - 0.5) * 0.5
214
-    )
215
-end
216
-
217
-function funcs:getAiAssiSkillEvaluate4251(core, skillInfo, params, assistSkillConfig)
218
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
219
-    -- params1 = {damageNums = 1},
220
-
221
-    local skillBase = skillInfo.skillBase
222
-    return math.floor(assistSkillConfig[parValue].damageNums * skillBase * 0.75)
223
-end
224
-
225
-function funcs:getAiAssiSkillEvaluate3251(core, skillInfo, params, assistSkillConfig)
226
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
227
-    -- params1 = {percent=20},
228
-    local enemyHeroTotalEv = params.enemyHeroTotalEv
229
-    local selfHeroTotalEv = params.selfHeroTotalEv
230
-    local enemyAverageBaseAttack = params.enemyAverageBaseAttack
231
-
232
-    local ve = (max(enemyHeroTotalEv - selfHeroTotalEv, 0) + 5 * enemyAverageBaseAttack) - selfHeroTotalEv
233
-
234
-    if ve > 0 then
235
-        return math.floor(assistSkillConfig[parValue].percent * 0.01 * ve * 0.5)
236
-    end
237
-
238
-    return 0
239
-end
240
-
241
-function funcs:getAiAssiSkillEvaluate2261(core, skillInfo, params, assistSkillConfig)
242
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
243
-    -- params1 = {ex={damagePercent=40}},
244
-    local enemyHeroTotalEv = params.enemyHeroTotalEv
245
-    return math.floor((50 - assistSkillConfig[parValue].ex.damagePercent) * enemyHeroTotalEv * 0.01)
246
-end
247
-
248
-function funcs:getAiAssiSkillEvaluate1261(core, skillInfo, params, assistSkillConfig)
249
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
250
-    -- params1 = {heroLiveNums=1.5},
251
-
252
-    local skillBase = skillInfo.skillBase
253
-    return math.floor(assistSkillConfig[parValue].heroLiveNums * skillBase * 1)
254
-end
255
-
256
-function funcs:getAiAssiSkillEvaluate4261(core, skillInfo, params, assistSkillConfig)
257
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
258
-    -- params1 = {defendPercent=55},
259
-    local enemyAverageBaseAttack = params.enemyAverageBaseAttack
260
-
261
-    return math.floor(5 * assistSkillConfig[parValue].defendPercent * 0.01 * enemyAverageBaseAttack * 0.5)
262
-end
263
-
264
-function funcs:getAiAssiSkillEvaluate3261(core, skillInfo, params, assistSkillConfig)
265
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
266
-    -- params1 = {ex={damagePercent=20}},
267
-    local baseAttack = params.baseAttack
268
-
269
-    return math.floor(assistSkillConfig[parValue].ex.damagePercent * 0.01 * baseAttack * 0.5)
270
-end
271
-
272
-function funcs:getAiAssiSkillEvaluate2351(core, skillInfo, params, assistSkillConfig)
273
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
274
-    -- params1 = {num=1},
275
-    local baseAttack = params.baseAttack
276
-    local skillBase = skillInfo.skillBase
277
-    return math.floor(assistSkillConfig[parValue].num * baseAttack * 0.5)
278
-end
279
-
280
-function funcs:getAiAssiSkillEvaluate1351(core, skillInfo, params, assistSkillConfig)
281
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
282
-    -- params1 = {defendPercent=-12.5},
283
-    -- params1 = {ex={damagePercent=112.5}},
284
-    local paramsValue = 0
285
-    if assistSkillConfig[parValue].ex then
286
-        paramsValue = assistSkillConfig[parValue].ex.damagePercent
287
-    else
288
-        paramsValue = assistSkillConfig[parValue].defendPercent
289
-    end
290
-
291
-    local newHeroAttack = params.newHeroAttack
292
-    return math.floor(paramsValue * newHeroAttack * 0.75)
293
-end
294
-
295
-function funcs:getAiAssiSkillEvaluate4351(core, skillInfo, params, assistSkillConfig)
296
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
297
-    -- params1 = {ex={damagePercent=20,upX=1.1}},
298
-    -- 最弱的敌人
299
-    local enemyHeroList = params.enemyHeroList
300
-    local enemyHeroLowestEv = 0
301
-    if #enemyHeroList > 0 and enemyHeroList[1] then
302
-        enemyHeroLowestEv = self:getHeroEvaluate(core, enemyHeroList[1]) or 0
303
-    end
304
-
305
-    -- 最弱的自己人
306
-    local selfHeroList = params.selfHeroList
307
-    local selfHeroLowestEv = 0
308
-    if #selfHeroList > 0 and selfHeroList[1] then
309
-        selfHeroLowestEv = self:getHeroEvaluate(core, selfHeroList[1]) or 0
310
-    end
311
-    local newHeroAttack = params.newHeroAttack
312
-    if selfHeroLowestEv == newHeroAttack then
313
-        if #selfHeroList > 1 and selfHeroList[2] then
314
-            selfHeroLowestEv = self:getHeroEvaluate(core, selfHeroList[2]) or 0
315
-        end
316
-    end
317
-
318
-    local minHero = min(enemyHeroLowestEv, selfHeroLowestEv)
319
-
320
-    return math.floor(
321
-        (assistSkillConfig[parValue].ex.upX * assistSkillConfig[parValue].ex.damagePercent -
322
-            assistSkillConfig[parValue].ex.damagePercent) *
323
-            minHero *
324
-            1
325
-    )
326
-end
327
-
328
-function funcs:getAiAssiSkillEvaluate3351(core, skillInfo, params, assistSkillConfig)
329
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
330
-    -- params1 = {ex={upPercent=20}},
331
-
332
-    local newHeroAttack = params.newHeroAttack
333
-    local selfHeroTotalEv = params.selfHeroTotalEv
334
-    local ev = max(selfHeroTotalEv - newHeroAttack, 0)
335
-    return math.floor(assistSkillConfig[parValue].ex.upPercent * 0.01 * ev * 1)
336
-end
337
-
338
-function funcs:getAiAssiSkillEvaluate2361(core, skillInfo, params, assistSkillConfig)
339
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
340
-    -- params1 = {ex={percent=20}},
341
-    local selfHeroList = params.selfHeroList
342
-    local selfHeroLowestEv = 0
343
-    if #selfHeroList > 0 and selfHeroList[1] then
344
-        selfHeroLowestEv = self:getHeroEvaluate(core, selfHeroList[1]) or 0
345
-    end
346
-
347
-    return math.floor(assistSkillConfig[parValue].ex.percent * 0, 01 * selfHeroLowestEv * 1)
348
-end
349
-
350
-function funcs:getAiAssiSkillEvaluate1361(core, skillInfo, params, assistSkillConfig)
351
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
352
-    -- params1 = {upNums=0.1},
353
-    local baseAttack = params.baseAttack
354
-    return math.floor(10 * assistSkillConfig[parValue].upNums * baseAttack * 0.5)
355
-end
356
-
357
-function funcs:getAiAssiSkillEvaluate4361(core, skillInfo, params, assistSkillConfig)
358
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
359
-    -- params1 = {num=2},
360
-    local newHeroAttack = params.newHeroAttack
361
-    return math.floor(assistSkillConfig[parValue].ex.damageNums * 0.1 * newHeroAttack * 0.75)
362
-end
363
-
364
-function funcs:getAiAssiSkillEvaluate3361(core, skillInfo, params, assistSkillConfig)
365
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
366
-    -- params1 = {heroLiveNums=1.4},
367
-    local averageBaseAttack = params.averageBaseAttack
368
-    local averageBaseAttack = skillInfo.skillBase
369
-    return math.floor(3 * assistSkillConfig[parValue].heroLiveNums * averageBaseAttack * 0.65)
370
-end
371
-
372
-function funcs:getAiAssiSkillEvaluate2281(core, skillInfo, params, assistSkillConfig)
373
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
374
-    -- params1 = {upNums=0.5},
375
-    local enemyHeroCount = params.enemyHeroCount
376
-    local baseAttack = params.baseAttack
377
-    return math.floor(enemyHeroCount * assistSkillConfig[parValue].upNums * baseAttack * 1)
378
-end
379
-
380
-function funcs:getAiAssiSkillEvaluate1281(core, skillInfo, params, assistSkillConfig)
381
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
382
-    -- params1 = {num=1},
383
-    local baseAttack = params.baseAttack
384
-    return math.floor(assistSkillConfig[parValue].num * baseAttack * 1)
385
-end
386
-
387
-function funcs:getAiAssiSkillEvaluate4281(core, skillInfo, params, assistSkillConfig)
388
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
389
-    -- params1 = {upNums=0.5},
390
-    local enemyHeroCount = params.enemyHeroCount
391
-    local baseAttack = params.baseAttack
392
-
393
-    return math.floor(enemyHeroCount * assistSkillConfig[parValue].upNums * baseAttack * 1)
394
-end
395
-
396
-function funcs:getAiAssiSkillEvaluate3281(core, skillInfo, params, assistSkillConfig)
397
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
398
-    -- params1 = {ex={upPercent=10}},
399
-    local averageBaseAttack = params.averageBaseAttack
400
-    return math.floor(assistSkillConfig[parValue].ex.upPercent * averageBaseAttack * 0.01)
401
-end
402
-
403
-function funcs:getAiAssiSkillEvaluate2291(core, skillInfo, params, assistSkillConfig)
404
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
405
-    -- params1 = {ex={percent=90}},
406
-    local newHeroAttack = params.newHeroAttack
407
-    return math.floor(assistSkillConfig[parValue].ex.damageNums * 0.01 * newHeroAttack * 1)
408
-end
409
-
410
-function funcs:getAiAssiSkillEvaluate1291(core, skillInfo, params, assistSkillConfig)
411
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
412
-    -- params1 = {upPercent=30},
413
-    local selfHeroTotalEv = params.selfHeroTotalEv
414
-    return math.floor((assistSkillConfig[parValue].upPercent - 25) * 0.01 * selfHeroTotalEv * 1)
415
-end
416
-
417
-function funcs:getAiAssiSkillEvaluate4291(core, skillInfo, params, assistSkillConfig)
418
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
419
-    -- params1 = {ex={upNums=1}},
420
-    local selfHeroList = params.selfHeroList
421
-    local newBlockXYMap = params.newBlockXYMap
422
-    local baseAttack = params.baseAttack
423
-
424
-    local count = 0
425
-    for _, hero in ipairs(selfHeroList) do
426
-        if newBlockXYMap[hero.bindBlock.id].y > 0 then
427
-            count = count + 1
428
-        end
429
-    end
430
-
431
-    return math.floor(assistSkillConfig[parValue].ex.upNums * count * baseAttack)
432
-end
433
-
434
-function funcs:getAiAssiSkillEvaluate3291(core, skillInfo, params, assistSkillConfig)
435
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
436
-    -- params1 = {assistSkillLevel=1},
437
-    local baseAttack = params.baseAttack
438
-    return math.floor(assistSkillConfig[parValue].assistSkillLevel * baseAttack)
439
-end
440
-
441
-function funcs:getAiAssiSkillEvaluate2311(core, skillInfo, params, assistSkillConfig)
442
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
443
-    -- params1 = {upNums=0.5},
444
-    local baseAttack = params.baseAttack
445
-    return math.floor(assistSkillConfig[parValue].upNums * baseAttack)
446
-end
447
-
448
-function funcs:getAiAssiSkillEvaluate1311(core, skillInfo, params, assistSkillConfig)
449
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
450
-    -- params1 = {ex={percent=10}},
451
-    local newHeroAttack = params.newHeroAttack
452
-    return math.floor(assistSkillConfig[parValue].ex.percent * 0.01 * newHeroAttack * 1)
453
-end
454
-
455
-function funcs:getAiAssiSkillEvaluate4311(core, skillInfo, params, assistSkillConfig)
456
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
457
-    -- params1 = {damagePercent=110},
458
-
459
-    local skillBase = skillInfo.skillBase
460
-    return math.floor(4 * (assistSkillConfig[parValue].damagePercent - 100) * 0.01 * skillBase * 0.5)
461
-end
462
-
463
-function funcs:getAiAssiSkillEvaluate3311(core, skillInfo, params, assistSkillConfig)
464
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
465
-    -- params1 = {defendPercent=-50},
466
-    local enemyHeroTotalEv = params.enemyHeroTotalEv
467
-    local selfHeroTotalEv = params.selfHeroTotalEv
468
-    local defendPercent = math.abs(assistSkillConfig[parValue].defendPercent)
469
-
470
-    if enemyHeroTotalEv > (1.5 * selfHeroTotalEv) then
471
-        return math.floor(defendPercent * 0.01 * selfHeroTotalEv * 0.75)
472
-    else
473
-        return math.floor(defendPercent * 0.01 * enemyHeroTotalEv * 0.75)
474
-    end
475
-end
476
-
477
-function funcs:getAiAssiSkillEvaluate2321(core, skillInfo, params, assistSkillConfig)
478
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
479
-    -- params1 = {ex={damagePercent={30, 30, 30, 30}}},
480
-    local defendPercent = (assistSkillConfig[parValue].ex.damagePercent or {})[1] or 0
481
-
482
-    local newHeroAttack = params.newHeroAttack
483
-    return math.floor((defendPercent - 25) * newHeroAttack * 0.75)
484
-end
485
-
486
-function funcs:getAiAssiSkillEvaluate1321(core, skillInfo, params, assistSkillConfig)
487
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
488
-    -- params1 = {upNums=1},
489
-    local defendPercent = assistSkillConfig[parValue].upNums
490
-
491
-    local baseAttack = params.baseAttack
492
-    return math.floor(defendPercent * baseAttack * 0.5)
493
-end
494
-
495
-function funcs:getAiAssiSkillEvaluate4321(core, skillInfo, params, assistSkillConfig)
496
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
497
-    -- params1 = {defendPercent=10},
498
-    local defendPercent = assistSkillConfig[parValue].defendPercent
499
-    local baseAttack = params.baseAttack
500
-
501
-    return math.floor(defendPercent * baseAttack * 0.1)
502
-end
503
-
504
-function funcs:getAiAssiSkillEvaluate3321(core, skillInfo, params, assistSkillConfig)
505
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
506
-    -- params1 = {ex={damagePercent=60}},
507
-    local damagePercent = assistSkillConfig[parValue].ex.damagePercent
508
-    local newHeroAttack = params.newHeroAttack
509
-
510
-    return math.floor((damagePercent - 50) * newHeroAttack * 0.75)
511
-end
512
-
513
-function funcs:getAiAssiSkillEvaluate2331(core, skillInfo, params, assistSkillConfig)
514
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
515
-    -- params1 = {ex={percent=60}},
516
-    local percent = assistSkillConfig[parValue].ex.percent
517
-
518
-    -- 最弱的自己人
519
-    local selfHeroList = params.selfHeroList
520
-    local selfHeroLowestEv = 0
521
-    if #selfHeroList > 0 and selfHeroList[1] then
522
-        selfHeroLowestEv = self:getHeroEvaluate(core, selfHeroList[1]) or 0
523
-    end
524
-
525
-    return math.floor(percent * selfHeroLowestEv * 0.01)
526
-end
527
-
528
-function funcs:getAiAssiSkillEvaluate1331(core, skillInfo, params, assistSkillConfig)
529
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
530
-    -- params1 = {ex={upNums=1}},
531
-    local upNums = assistSkillConfig[parValue].ex.upNums
532
-
533
-    local enemyHeroCount = params.enemyHeroCount
534
-    local baseAttack = params.baseAttack
535
-
536
-    return math.floor(upNums * baseAttack * 1)
537
-end
538
-
539
-function funcs:getAiAssiSkillEvaluate4331(core, skillInfo, params, assistSkillConfig)
540
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
541
-    -- params1 = {ex={percent=10}},
542
-    local percent = assistSkillConfig[parValue].ex.percent
543
-
544
-    local enemyHeroTotalEv = params.enemyHeroTotalEv
545
-    local selfHeroTotalEv = params.selfHeroTotalEv
546
-    local enemyAverageBaseAttack = params.enemyAverageBaseAttack
547
-
548
-    local ev = (max((enemyHeroTotalEv - selfHeroTotalEv), 0) + 5 * enemyAverageBaseAttack) * 0.5 * percent * 0.5 * 0.01
549
-    return math.floor(ev)
550
-end
551
-
552
-function funcs:getAiAssiSkillEvaluate3331(core, skillInfo, params, assistSkillConfig)
553
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
554
-    -- params1 = {ex={percent=50}},
555
-    local percent = assistSkillConfig[parValue].ex.percent
556
-    -- TODO: Debug 测试代码,上线前修改过来.
557
-
558
-    local selfHeroCount = params.selfHeroCount
559
-    local averageBaseAttack = params.averageBaseAttack
560
-
561
-    return math.floor(percent * selfHeroCount * averageBaseAttack * 0.5)
562
-end
563
-
564
-function funcs:getAiAssiSkillEvaluate2341(core, skillInfo, params, assistSkillConfig)
565
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
566
-    -- params1 = {ex={percent=10}},
567
-    local percent = assistSkillConfig[parValue].ex.percent
568
-
569
-    local selfHeroTotalEv = params.selfHeroTotalEv
570
-    return math.floor(percent * 0.01 * selfHeroTotalEv * 0.5 * 0.65)
571
-end
572
-
573
-function funcs:getAiAssiSkillEvaluate1341(core, skillInfo, params, assistSkillConfig)
574
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
575
-    -- params1 = {ex={percent=10}},
576
-    local percent = assistSkillConfig[parValue].ex.percent
577
-
578
-    local selfHeroTotalEv = params.selfHeroTotalEv
579
-    return math.floor(percent * 0.01 * selfHeroTotalEv * 0.5 * 0.65)
580
-end
581
-
582
-function funcs:getAiAssiSkillEvaluate4341(core, skillInfo, params, assistSkillConfig)
583
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
584
-    -- params1 = {ex={percent=50}},
585
-    local percent = assistSkillConfig[parValue].ex.percent
586
-
587
-    local baseAttack = params.baseAttack
588
-
589
-    return math.floor(3 * percent * 0.01 * baseAttack * 0.5)
590
-end
591
-
592
-function funcs:getAiAssiSkillEvaluate3341(core, skillInfo, params, assistSkillConfig)
593
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
594
-    -- params1 = {ex={damagePercent=55}},
595
-    local damagePercent = assistSkillConfig[parValue].ex.damagePercent
596
-
597
-    local enemyHeroCount = params.enemyHeroCount
598
-    local baseAttack = params.baseAttack
599
-
600
-    return math.floor((damagePercent - 50) * enemyHeroCount * baseAttack * 0.75)
601
-end
602
-
603
-function funcs:getAiAssiSkillEvaluate1002(core, skillInfo, params, assistSkillConfig)
604
-    local parValue = string.format("params%s", skillInfo.newHeroAssistSkillLevel)
605
-    --
606
-    local damagePercent = assistSkillConfig[parValue].ex.damagePercent
607
-    local enemyHeroCount = params.enemyHeroCount
608
-    local skillBase = skillInfo.skillBase
609
-    return math.floor(damagePercent * skillBase * 0.75)
610
-end
611
-
612
-function funcs:getHeroEvaluate(core, hero)
613
-    -- local buffs = hero:getBuffByType(battleConst.BUFF_TYPE.VALUE_SHIELD)
614
-    -- local shield = 0
615
-    -- for _, buff in ipairs(buffs) do
616
-    --     shield = shield + (buff.hp or 0)
617
-    -- end
618
-    -- return hero:getHp() + shield * 0.5
619
-    return hero:getHp()
620
-end
621
-
622
-return root

+ 0 - 602
nodes/battle/lib/battleAiLogic.lua

@@ -1,611 +0,0 @@
1
-local skynet = require "skynet"
2
-local battleConst = require "battle.battleConst"
3
-local battleLog = require "battle.battleLog"
4
-local battleUtils = require "battle.battleUtils"
5
-local battleAdapt = require "adapt.battleAdapt"
6
-local battleDefine = require "battle.battleDefine"
7
-local battleAiUtils = require "battleAiUtils"
8
-local utils_bt_supply = require "utils_bt_supply"
9
-
10
-local root = {}
11
-
12
-local Total_Weight = {2, 8, 11, 9, 7, 3}
13
-local Grid_Color_Weights = {
14
-    {num = 7, colors = {{p1 = 4, p2 = 3}, {p1 = 3, p2 = 4}}},
15
-    {num = 8, colors = {{p1 = 4, p2 = 4}}},
16
-    {num = 9, colors = {{p1 = 5, p2 = 4}, {p1 = 4, p2 = 5}}},
17
-    {num = 10, colors = {{p1 = 5, p2 = 5}}},
18
-    {num = 11, colors = {{p1 = 5, p2 = 6}, {p1 = 6, p2 = 5}, {p1 = 7, p2 = 4}, {p1 = 4, p2 = 7}}},
19
-    {num = 12, colors = {{p1 = 6, p2 = 6}, {p1 = 7, p2 = 5}, {p1 = 5, p2 = 7}}},
20
-    {num = 13, colors = {{p1 = 7, p2 = 6}, {p1 = 6, p2 = 7}, {p1 = 8, p2 = 5}, {p1 = 5, p2 = 8}}},
21
-    {num = 14, colors = {{p1 = 7, p2 = 7}, {p1 = 8, p2 = 6}, {p1 = 6, p2 = 8}}},
22
-    {num = 15, colors = {{p1 = 8, p2 = 7}, {p1 = 7, p2 = 8}, {p1 = 9, p2 = 6}, {p1 = 6, p2 = 9}}},
23
-    {num = 16, colors = {{p1 = 8, p2 = 8}, {p1 = 9, p2 = 7}, {p1 = 7, p2 = 9}}},
24
-    {num = 17, colors = {{p1 = 9, p2 = 8}}},
25
-    {num = 18, colors = {{p1 = 9, p2 = 9}}},
26
-    {num = 19, colors = {{p1 = 10, p2 = 9}}},
27
-    {num = 20, colors = {{p1 = 10, p2 = 10}}}
28
-}
29
------------------------------------------------
30
-------------------色块生成逻辑------------------
31
---[[ 生成50个色块
32
-]]
33
-function root:initGrid(core)
34
-    self:printToConsole("-->initGrid...")
35
-
36
-    local needColorData1, needColorData2 = self:getGridTotalColorNum(core)
37
-
38
-    local grids1 = self:createGridColor(core, 0, needColorData1) or {}
39
-    local grids2 = self:createGridColor(core, 1, needColorData2) or {}
40
-
41
-    self:printToConsole(string.format("结果1:%s", table.concat(grids1, ", ")))
42
-    self:printToConsole(string.format("结果2:%s", table.concat(grids2, ", ")))
43
-    return self:tableConcat(grids1, grids2)
44
-    -- {3, 2, 3, 2, 4, 1, 4, 3, 2, 4, 2, 1, 4, 1, 1, 2, 3, 2, 3, 2, 3, 3, 2, 3, 3, 3, 2, 3, 2, 4, 1, 4, 3, 2, 4, 2, 1, 4, 1, 1, 2, 3, 2, 3, 2, 3, 3, 2, 3, 3}
45
-end
46
-
47
-function root:getGridTotalColorNum(core)
48
-    local totalWeight = Total_Weight
49
-    local totalStartIndex = 9
50
-    local gridColorWeights = Grid_Color_Weights
51
-
52
-    local totalRedIndex = self:randomWeightToIndex(totalWeight)
53
-    local totalRed = totalStartIndex + totalRedIndex
54
-
55
-    local totalGreenIndex = self:randomWeightToIndex(totalWeight)
56
-    local totalGreen = totalStartIndex + totalGreenIndex
57
-
58
-    local totalBlueIndex = self:randomWeightToIndex(totalWeight)
59
-    local totalBlue = totalStartIndex + totalBlueIndex
60
-
61
-    local total = core.areaW * core.areaH * 2
62
-    local totalYellow = total - totalRed - totalGreen - totalBlue
63
-    -- self:printToConsole( string.format("totalRed=%d, totalGreen=%d, totalBlue=%d, totalYellow=%d", totalRed, totalGreen, totalBlue, totalYellow) )
64
-
65
-    local needColorData1 = {red = 0, green = 0, blue = 0, yellow = 0}
66
-    local needColorData2 = {red = 0, green = 0, blue = 0, yellow = 0}
67
-    local colorNum = self:getGridColorNumByColor(gridColorWeights, totalRed)
68
-    needColorData1.red = colorNum.p1
69
-    needColorData2.red = colorNum.p2
70
-    colorNum = self:getGridColorNumByColor(gridColorWeights, totalGreen)
71
-    needColorData1.green = colorNum.p1
72
-    needColorData2.green = colorNum.p2
73
-    colorNum = self:getGridColorNumByColor(gridColorWeights, totalBlue)
74
-    needColorData1.blue = colorNum.p1
75
-    needColorData2.blue = colorNum.p2
76
-    colorNum = self:getGridColorNumByColor(gridColorWeights, totalYellow)
77
-    needColorData1.yellow = colorNum.p1
78
-    needColorData2.yellow = colorNum.p2
79
-
80
-    -- self:printToConsole( string.format("needColorData1=%d,%d,%d,%d", needColorData1.red, needColorData1.yellow, needColorData1.green, needColorData1.blue) );
81
-    -- self:printToConsole( string.format("needColorData2=%d,%d,%d,%d", needColorData2.red, needColorData2.yellow, needColorData2.green, needColorData2.blue) );
82
-
83
-    return needColorData1, needColorData2
84
-end
85
-
86
-function root:getGridColorNumByColor(gridColorWeights, totalNum)
87
-    for i, v in ipairs(gridColorWeights) do
88
-        if v.num == totalNum then
89
-            local randomIndex = math.random(1, #v.colors)
90
-            local colorObj = v.colors[randomIndex]
91
-            return colorObj
92
-        end
93
-    end
94
-    return {p1 = 0, p2 = 0}
95
-end
96
-
97
-function root:createGridColor(core, castleIndex, needColorData)
98
-    local gridColorList = {}
99
-    local printGridCount = {0, 0, 0, 0}
100
-    local colorWeights = {10, 10, 10, 10}
101
-    local isCanLink = false
102
-    local total = core.areaW * core.areaH
103
-    for i = 1, total do
104
-        colorWeights[1] = needColorData.red > 0 and 10 or 0
105
-        colorWeights[2] = needColorData.yellow > 0 and 10 or 0
106
-        colorWeights[3] = needColorData.green > 0 and 10 or 0
107
-        colorWeights[4] = needColorData.blue > 0 and 10 or 0
108
-
109
-        local tempColorWeights
110
-        if not isCanLink and i >= total - 2 then
111
-            colorWeights = {10, 0, 0, 0}
112
-            if i == total then
113
-                self:printToConsole("-------- 强制生成三块红色 --------")
114
-            end
115
-        else
116
-            tempColorWeights = self:checkNearGridColor(gridColorList, colorWeights)
117
-        end
118
-
119
-        if colorWeights[1] == 0 and colorWeights[2] == 0 and colorWeights[3] == 0 and colorWeights[4] == 0 then
120
-            -- self:printToConsole("重新初始化权重")
121
-            colorWeights = {10, 10, 10, 10}
122
-            if
123
-                tempColorWeights[1].w == 0 and tempColorWeights[2].w == 0 and tempColorWeights[3].w == 0 and
124
-                    tempColorWeights[4].w == 0
125
-             then
126
-                -- self:printToConsole('### 相邻色块都超过5 ###')
127
-            else
128
-                for j = 1, 4 do
129
-                    if tempColorWeights[j].w == 0 then
130
-                        colorWeights[j] = 0
131
-                    end
132
-                end
133
-            end
134
-        end
135
-
136
-        local colorType = self:randomWeightToIndex(colorWeights)
137
-        table.insert(gridColorList, colorType)
138
-        printGridCount[colorType] = printGridCount[colorType] + 1
139
-
140
-        if colorType == 1 then
141
-            needColorData.red = needColorData.red - 1
142
-        elseif colorType == 2 then
143
-            needColorData.yellow = needColorData.yellow - 1
144
-        elseif colorType == 3 then
145
-            needColorData.green = needColorData.green - 1
146
-        elseif colorType == 4 then
147
-            needColorData.blue = needColorData.blue - 1
148
-        end
149
-
150
-        if tempColorWeights and tempColorWeights[colorType].n >= 3 then
151
-            isCanLink = true
152
-        end
153
-    end
154
-
155
-    -- self:printToConsole( string.format("玩家%d:红-%d, 黄-%d,绿-%d, 蓝-%d", castleIndex, printGridCount[1], printGridCount[2], printGridCount[3], printGridCount[4]) )
156
-    return gridColorList
157
-end
158
-
159
-function root:checkNearGridColor(gridColorList, colorWeights)
160
-    local tempColorWeights = {{w = 10, n = 0}, {w = 10, n = 0}, {w = 10, n = 0}, {w = 10, n = 0}}
161
-    if #gridColorList < 4 then
162
-        return tempColorWeights
163
-    end
164
-    for i = 1, 4 do
165
-        local nearGridColorCount = self:getNearGridColorCount(gridColorList, i)
166
-        if nearGridColorCount > 5 then
167
-            colorWeights[i] = 0
168
-            tempColorWeights[i].w = 0
169
-        -- self:printToConsole( string.format("   %d 相邻色块超过5,把权重调0", #gridColorList) )
170
-        end
171
-        tempColorWeights[i].n = nearGridColorCount
172
-    end
173
-    return tempColorWeights
174
-end
175
-
176
-function root:getNearGridColorCount(gridColorList, color, index)
177
-    local gridIndex = index ~= nil and index or #gridColorList
178
-    local list = {gridIndex}
179
-    local index = 1
180
-    while index <= #list do
181
-        local checkIndex = list[index]
182
-        index = index + 1
183
-        local gridX = checkIndex % 5
184
-        local gridY = math.floor(checkIndex / 5)
185
-        for i = -1, 1 do
186
-            for j = -1, 1 do
187
-                if (i ~= 0 or j ~= 0) and (gridX + i) >= 0 and (gridY + j) >= 0 and (gridX + i < 5) and (gridY + j < 5) then
188
-                    local tempIndex = self:getGridIndexByXY(gridX + i, gridY + j)
189
-                    local tempColor = gridColorList[tempIndex + 1]
190
-                    if
191
-                        tempColor and self:checkIsSameColor(tempColor, color) and
192
-                            self:findGridIndex(list, tempIndex) <= 0
193
-                     then
194
-                        table.insert(list, tempIndex)
195
-                        if color == battleConst.COLOR_TYPE.ALL then
196
-                            color = tempColor
197
-                        end
198
-                    end
199
-                end
200
-            end
201
-        end
202
-    end
203
-    -- self:printToConsole( string.format("[%d] color=%d, data=%s, list=%s", gridIndex, color, table.concat(gridColorList, "," ), table.concat(list, "," )) )
204
-    return #list
205
-end
206
-
207
-function root:checkIsSameColor(tempColor, color)
208
-    return tempColor == battleConst.COLOR_TYPE.ALL or color == battleConst.COLOR_TYPE.ALL or tempColor == color
209
-end
210
-
211
-function root:findGridIndex(list, tempIndex)
212
-    for i, v in ipairs(list) do
213
-        if tempIndex == v then
214
-            return i
215
-        end
216
-    end
217
-    return 0
218
-end
219
-
220
-function root:getGridIndexByXY(gridX, gridY)
221
-    return gridY * 5 + gridX
222
-end
223
-
224
-local function log2Client(core, logStr)
225
-    if not logStr then
226
-        return
227
-    end
228
-    battleLog:logClient(logStr)
229
-
230
-    core:notifyClientLog(logStr)
231
-end
232
-
233
------------------------------------------------
234
-------------------色块补充逻辑------------------
235
-function root:supplyGrids(core, actionCastle)
236
-    local grids = core.map
237
-    local curRound = core:getCurRound()
238
-
239
-    -- 将需要补充的色块,重置颜色为0
240
-    for _, block in ipairs(grids) do
241
-        if block.status == battleConst.BLOCK_STATUS.NEEDUPDATE then
242
-            block.color = battleConst.COLOR_TYPE.INVAILD
243
-            block:clear()
244
-        end
245
-    end
246
-
247
-    local enemyCastle = core:getEnemyCastle(actionCastle)
248
-    local supplyRound = enemyCastle.supplyRound
249
-    local supplyWeight1 = enemyCastle.supplyWeight1
250
-    local supplyWeight2 = enemyCastle.supplyWeight2
251
-    local supplyWeight = curRound <= supplyRound and supplyWeight1 or supplyWeight2
252
-    local supplyType = getRandomWithWeight(supplyWeight)
253
-
254
-    supplyType = "A57"
255
-
256
-    local seat = actionCastle.seat
257
-    local is2v2 = core.is2v2
258
-    utils_bt_supply:supply_grids(core, seat, grids, supplyType, is2v2)
259
-end
260
-
261
-function root:randomWeightToIndex(list)
262
-    if list == nil or #list == 0 then
263
-        return 1
264
-    end
265
-    local sum = 0
266
-    for i, weight in ipairs(list) do
267
-        sum = sum + weight
268
-    end
269
-
270
-    if sum <= 0 then
271
-        return 1
272
-    end
273
-
274
-    local ret = 1
275
-    local r = math.random(1, sum)
276
-    local didSum = 0
277
-    for index, q in ipairs(list) do
278
-        didSum = didSum + q
279
-        if r <= didSum then
280
-            ret = index
281
-            break
282
-        end
283
-    end
284
-    return ret
285
-end
286
-
287
-local function getOptionLinks(core, actionCastle)
288
-    local allLinks = battleUtils:getAllLinkBlocks2(core, core.map, actionCastle.seat)
289
-    table.sort(
290
-        allLinks,
291
-        function(a, b)
292
-            return #a.linkIds > #b.linkIds
293
-        end
294
-    )
295
-    for i = #allLinks, 1, -1 do
296
-        for j = 1, i - 1 do
297
-            local member = true
298
-            for _, v in ipairs(allLinks[i].linkIds) do
299
-                if not table.member(allLinks[j].linkIds, v) then
300
-                    member = false
301
-                    break
302
-                end
303
-            end
304
-            if member then
305
-                table.remove(allLinks, i)
306
-                break
307
-            end
308
-        end
309
-    end
310
-    return allLinks
311
-end
312
-
313
-local link = class("link")
314
-
315
-function link:ctor()
316
-    self.ids = {}
317
-    self.size = 0
318
-    self.lastY = 0
319
-end
320
-
321
-local function createLink(core, actionCastle, linkIds, isFool)
322
-    local l = link.new()
323
-    l.ids = battleUtils:reverse(core.map, actionCastle.seat, linkIds, isFool)
324
-    l.size = #linkIds
325
-    local lastBlock = battleUtils:getColorBlockByID(core.map, l.ids[l.size])
326
-    l.lastY = lastBlock.y
327
-
328
-    return l
329
-end
330
-
331
-local function findGridSuppressRoute(core, actionCastle)
332
-    local nowTime = skynet.time()
333
-    local allLinks = getOptionLinks(core, actionCastle)
334
-    if table.empty(allLinks) then
335
-        battleLog:logInfo(string.format("findGridSuppressRoute empty links error, uid %s", actionCastle.uid))
336
-        return
337
-    end
338
-
339
-    local result = {}
340
-    local exceptLinks = {}
341
-    local enableExSkill = core:getEnableExSkill(actionCastle)
342
-    for _, v in ipairs(allLinks) do
343
-        local ret, exSkillGridId, except =
344
-            battleAiUtils:getLongEvaluate(core, actionCastle, v.linkIds, v.color, false, enableExSkill)
345
-        if ret >= 1000000 then
346
-            battleLog:logInfo(string.format("findGridSuppressRoute time cost %s", skynet.time() - nowTime))
347
-            return v.linkIds, exSkillGridId
348
-        end
349
-        if except then
350
-            table.link(
351
-                exceptLinks,
352
-                battleUtils:getLinkBlocksWithoutExceptBlocks(
353
-                    core,
354
-                    core.map,
355
-                    actionCastle.seat,
356
-                    except.blocks,
357
-                    except.exceptBlocks
358
-                )
359
-            )
360
-        end
361
-        table.insert(result, {ids = v.linkIds, size = #v.linkIds, allPower = ret, exSkillGridId = exSkillGridId})
362
-
363
-        local linkIds = table.reverse(v.linkIds)
364
-        ret, exSkillGridId = battleAiUtils:getLongEvaluate(core, actionCastle, linkIds, v.color, true, enableExSkill)
365
-        if ret >= 1000000 then
366
-            battleLog:logInfo(string.format("findGridSuppressRoute time cost %s", skynet.time() - nowTime))
367
-            return linkIds, exSkillGridId
368
-        end
369
-        table.insert(result, {ids = linkIds, size = #linkIds, allPower = ret, exSkillGridId = exSkillGridId})
370
-    end
371
-    for _, v in ipairs(exceptLinks) do
372
-        local ret, exSkillGridId =
373
-            battleAiUtils:getLongEvaluate(core, actionCastle, v.linkIds, v.color, true, enableExSkill)
374
-        if ret >= 1000000 then
375
-            battleLog:logInfo(string.format("findGridSuppressRoute time cost %s", skynet.time() - nowTime))
376
-            return v.linkIds, exSkillGridId
377
-        end
378
-        table.insert(result, {ids = v.linkIds, size = #v.linkIds, allPower = ret, exSkillGridId = exSkillGridId})
379
-
380
-        local linkIds = table.reverse(v.linkIds)
381
-        ret, exSkillGridId = battleAiUtils:getLongEvaluate(core, actionCastle, linkIds, v.color, true, enableExSkill)
382
-        if ret >= 1000000 then
383
-            battleLog:logInfo(string.format("findGridSuppressRoute time cost %s", skynet.time() - nowTime))
384
-            return linkIds, exSkillGridId
385
-        end
386
-        table.insert(result, {ids = linkIds, size = #linkIds, allPower = ret, exSkillGridId = exSkillGridId})
387
-    end
388
-
389
-    table.sort(
390
-        result,
391
-        function(a, b)
392
-            if a.allPower ~= b.allPower then
393
-                return a.allPower > b.allPower
394
-            end
395
-            return a.size > b.size
396
-        end
397
-    )
398
-
399
-    battleLog:logInfo(string.format("findGridSuppressRoute time cost %s", skynet.time() - nowTime))
400
-    return result[1].ids, result[1].exSkillGridId
401
-end
402
-
403
-local function findGridCommonRoute(core, actionCastle)
404
-    local nowTime = skynet.time()
405
-    local allLinks = getOptionLinks(core, actionCastle)
406
-    if table.empty(allLinks) then
407
-        battleLog:logInfo(string.format("findGridCommonRoute empty links error, uid %s", actionCastle.uid))
408
-        return
409
-    end
410
-
411
-    local result = {}
412
-    for _, v in ipairs(allLinks) do
413
-        table.insert(result, createLink(core, actionCastle, v.linkIds, false))
414
-    end
415
-
416
-    table.sort(
417
-        result,
418
-        function(a, b)
419
-            if a.size ~= b.size then
420
-                return a.size > b.size
421
-            end
422
-            if actionCastle.seat == battleConst.BATTLE_SEAT.DOWN then
423
-                return a.lastY < b.lastY
424
-            else
425
-                return a.lastY > b.lastY
426
-            end
427
-        end
428
-    )
429
-
430
-    local ids = result[1].ids
431
-    local exSkillGridId
432
-
433
-    local enableExSkill = core:getEnableExSkill(actionCastle)
434
-    if enableExSkill then
435
-        exSkillGridId = battleAiUtils:getNormatlExSkillGridId(core, actionCastle, ids)
436
-    end
437
-
438
-    battleLog:logInfo(string.format("findGridCommonRoute time cost %s", skynet.time() - nowTime))
439
-    return ids, exSkillGridId
440
-end
441
-
442
-local function findGridFoolRoute(core, actionCastle)
443
-    local nowTime = skynet.time()
444
-
445
-    -- 获取全部连线
446
-    local allLinks = getOptionLinks(core, actionCastle)
447
-    if table.empty(allLinks) then
448
-        battleLog:logInfo(string.format("findGridFoolRoute empty links error, uid %s", actionCastle.uid))
449
-        return
450
-    end
451
-
452
-    -- 愚蠢取落点低的规则:对手(真人)游戏局数小于5局,或者30%概率
453
-    local enemyCastle = core:getEnemyCastle(actionCastle)
454
-    local mainPlayer = enemyCastle:getMainPlayer()
455
-    local isFool = false
456
-    if mainPlayer.battleCount < 5 then
457
-        isFool = true
458
-    else
459
-        isFool = math.random(100) <= 30
460
-    end
461
-
462
-    -- 全部连线结构化
463
-    local result = {}
464
-    for _, v in ipairs(allLinks) do
465
-        table.insert(result, createLink(core, actionCastle, v.linkIds, isFool))
466
-    end
467
-
468
-    -- 连线排序:优先长度,其次落点
469
-    table.sort(
470
-        result,
471
-        function(a, b)
472
-            if a.size ~= b.size then
473
-                return a.size > b.size
474
-            end
475
-
476
-            if isFool then
477
-                if actionCastle.seat == battleConst.BATTLE_SEAT.UP then
478
-                    return a.lastY < b.lastY
479
-                else
480
-                    return a.lastY > b.lastY
481
-                end
482
-            else
483
-                if actionCastle.seat == battleConst.BATTLE_SEAT.UP then
484
-                    return a.lastY > b.lastY
485
-                else
486
-                    return a.lastY < b.lastY
487
-                end
488
-            end
489
-        end
490
-    )
491
-
492
-    -- 获取长度最长的连线
493
-    local linkIds = result[1].ids
494
-
495
-    -- 10%的概率漏连。漏连数量在 BattleCommonConfig 配置
496
-    if math.random(100) <= 10 then
497
-        local lessWeights = battleAdapt:getLessLinkWeights()
498
-        local lessCount = RandomWithWeight(lessWeights)
499
-        for i = 1, lessCount do
500
-            if #linkIds == battleDefine.MIN_LINK_BLOCK then
501
-                break
502
-            end
503
-            table.remove(linkIds, 1)
504
-        end
505
-    end
506
-
507
-    local ids = linkIds
508
-    local exSkillGridId
509
-
510
-    local enableExSkill = core:getEnableExSkill(actionCastle)
511
-    if enableExSkill then
512
-        exSkillGridId = battleAiUtils:getNormatlExSkillGridId(core, actionCastle, ids)
513
-    end
514
-
515
-    battleLog:logInfo(string.format("findGridFoolRoute time cost %s", skynet.time() - nowTime))
516
-    return ids, exSkillGridId
517
-end
518
-
519
-local function findGridStupidRoute(core, actionCastle)
520
-    local nowTime = skynet.time()
521
-
522
-    -- 获取全部连线
523
-    local allLinks = getOptionLinks(core, actionCastle)
524
-    if table.empty(allLinks) then
525
-        battleLog:logInfo(string.format("findGridStupidRoute empty links error, uid %s", actionCastle.uid))
526
-        return
527
-    end
528
-
529
-    local isFool = true
530
-
531
-    -- 全部连线结构化
532
-    local result = {}
533
-    for _, v in ipairs(allLinks) do
534
-        table.insert(result, createLink(core, actionCastle, v.linkIds, isFool))
535
-    end
536
-
537
-    local ids
538
-    local exSkillGridId = nil
539
-
540
-    -- 随机一条连线
541
-    local linkIds = result[math.random(#result)].ids
542
-    if #linkIds > 3 then
543
-        ids = {}
544
-        for i = 1, 3 do
545
-            table.insert(ids, linkIds[i])
546
-        end
547
-    else
548
-        ids = linkIds
549
-    end
550
-
551
-    battleLog:logInfo(string.format("findGridStupidRoute time cost %s", skynet.time() - nowTime))
552
-    return ids, exSkillGridId
553
-end
554
-
555
------------------------------------------------
556
-------------------色块寻路逻辑------------------
557
---[[寻找最长的路线
558
-]]
559
-function root:findGridLongRoute(core, actionCastle, aiLinkType)
560
-    if not aiLinkType then
561
-        log.error("findGridLongRoute aiLinkType is nil")
562
-        return
563
-    end
564
-
565
-    -- if aiLinkType == "W" and math.random(100) <= 20 then
566
-    --     aiLinkType = "R"
567
-    -- elseif aiLinkType == "R" and math.random(100) <= 20 then
568
-    --     aiLinkType = "W"
569
-    -- end
570
-
571
-    -- aiLinkType = "R"
572
-
573
-    log2Client(core, string.format("当前回合%s aiLinkType=%s", core:getCurRound(), aiLinkType))
574
-
575
-    if aiLinkType == "W" then
576
-        return findGridSuppressRoute(core, actionCastle)
577
-    elseif aiLinkType == "R" then
578
-        return findGridCommonRoute(core, actionCastle)
579
-    elseif aiLinkType == "L" then
580
-        return findGridFoolRoute(core, actionCastle)
581
-    elseif aiLinkType == "S" then
582
-        return findGridStupidRoute(core, actionCastle)
583
-    end
584
-    battleLog:logInfo(string.format("findGridLongRoute error aiLinkType = %s", aiLinkType))
585
-end
586
-
587
-function root:tableConcat(dest, src)
588
-    local begin = #dest + 1
589
-
590
-    local len = #src
591
-    for i = 0, len - 1 do
592
-        dest[i + begin] = src[i + 1]
593
-    end
594
-    return dest
595
-end
596
-
597
--------------------------
598
-function root:printToConsole(str)
599
-    battleLog:logInfo(str)
600
-end
601
-
602
-return root

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 3292
nodes/battle/lib/battleAiUtils.lua


+ 0 - 619
nodes/battle/lib/utils_bt_grid.lua

@@ -1,646 +0,0 @@
1
---[[
2
-    方形之路,格子相关算法处理
3
-]]
4
-local root = {}
5
-
6
-local printf = print
7
-
8
-local MIN_LONG_SIZE = 3
9
-
10
-function root:grids_to_color_map(grids)
11
-    local ret = {}
12
-
13
-    for _, v in ipairs(grids) do
14
-        local x, y = v.x + 1, v.y + 1
15
-        if not ret[y] then
16
-            ret[y] = {}
17
-        end
18
-        if v:cantLink() then
19
-            ret[y][x] = -1
20
-        else
21
-            ret[y][x] = v.color
22
-        end
23
-    end
24
-
25
-    return ret
26
-end
27
-
28
-function root:grids_to_id_map(grids)
29
-    local ret = {}
30
-
31
-    for _, v in ipairs(grids) do
32
-        local x, y = v.x + 1, v.y + 1
33
-        if not ret[y] then
34
-            ret[y] = {}
35
-        end
36
-        ret[y][x] = v.id
37
-    end
38
-
39
-    return ret
40
-end
41
-
42
-function root:random_map()
43
-    local w, h = 5, 10
44
-
45
-    local ret = {}
46
-    for y = 1, h do
47
-        local oneRow = {}
48
-        for x = 1, w do
49
-            local color = math.random(1, 4)
50
-            table.insert(oneRow, color)
51
-        end
52
-        table.insert(ret, oneRow)
53
-    end
54
-
55
-    -- 随机3~4次万能色块。注意:可能4次都是同一个格子
56
-    local allColorCount = math.random(3, 4)
57
-    for i = 1, allColorCount do
58
-        local y = math.random(h)
59
-        local x = math.random(w)
60
-        ret[y][x] = 5
61
-    end
62
-
63
-    -- local ret = {
64
-    --     {3, 2, 3, 1, 2},
65
-    --     {4, 3, 5, 2, 1},
66
-    --     {3, 3, 3, 2, 3},
67
-    --     {2, 4, 1, 2, 5},
68
-    --     {1, 4, 4, 2, 1},
69
-    --     {5, 1, 4, 2, 4},
70
-    --     {2, 4, 1, 4, 1},
71
-    --     {3, 4, 3, 4, 1},
72
-    --     {3, 3, 4, 2, 4},
73
-    --     {5, 3, 3, 2, 1}
74
-    -- }
75
-
76
-    return ret
77
-end
78
-
79
-function root:get_half_map(seat, map)
80
-    local maxH = #map
81
-    local minY, maxY
82
-    if seat == 1 then
83
-        minY, maxY = 1, maxH / 2
84
-    else
85
-        minY, maxY = maxH / 2 + 1, maxH
86
-    end
87
-
88
-    local ret = {}
89
-    for y, v in ipairs(map) do
90
-        ret[y] = {}
91
-        for x, vv in ipairs(v) do
92
-            if y >= minY and y <= maxY then
93
-                ret[y][x] = vv
94
-            else
95
-                ret[y][x] = 0
96
-            end
97
-        end
98
-    end
99
-    return ret
100
-end
101
-
102
-function root:get_all_long(halfMap)
103
-    local h = #halfMap
104
-    local w = #halfMap[1]
105
-
106
-    -- 将地图分块
107
-    local longList = self:split_map(halfMap)
108
-
109
-    return longList
110
-end
111
-
112
-function root:split_map(map)
113
-    local ret = {}
114
-
115
-    local h = #map
116
-    local w = #map[1]
117
-
118
-    -- 同色地图字典
119
-    local sameColorMapDict = {
120
-        [1] = self:new_zero_map(w, h),
121
-        [2] = self:new_zero_map(w, h),
122
-        [3] = self:new_zero_map(w, h),
123
-        [4] = self:new_zero_map(w, h)
124
-    }
125
-    for y, oneRow in ipairs(map) do
126
-        for x, color in ipairs(oneRow) do
127
-            if color >= 1 and color <= 4 then
128
-                local sameColorMap = sameColorMapDict[color]
129
-                sameColorMap[y][x] = color
130
-            elseif color == 5 then
131
-                for _, sameColorMap in ipairs(sameColorMapDict) do
132
-                    sameColorMap[y][x] = color
133
-                end
134
-            end
135
-        end
136
-    end
137
-
138
-    -- 每种颜色进行分割
139
-    for _, sameColorMap in ipairs(sameColorMapDict) do
140
-        local list = self:split_same_color_map(sameColorMap)
141
-        self:array_merge(ret, list)
142
-    end
143
-
144
-    return ret
145
-end
146
-
147
-function root:split_same_color_map(sameColorMap)
148
-    local ret = {}
149
-
150
-    for y, oneRow in ipairs(sameColorMap) do
151
-        for x, color in ipairs(oneRow) do
152
-            if color >= 1 and color <= 4 then
153
-                sameColorMap[y][x] = 0
154
-
155
-                local pos = {x = x, y = y, color = color}
156
-                local oneLong = {pos}
157
-
158
-                self:pickup_one_long(oneLong, sameColorMap, pos)
159
-                if #oneLong >= MIN_LONG_SIZE then
160
-                    table.insert(ret, oneLong)
161
-                end
162
-            end
163
-        end
164
-    end
165
-
166
-    return ret
167
-end
168
-
169
-function root:pickup_one_long(oneLong, sameColorMap, pos)
170
-    local x1 = pos.x
171
-    local y1 = pos.y
172
-    local nextPosList = {}
173
-    -- 九宫格示例
174
-    -- 1 2 3
175
-    -- 4 x 6
176
-    -- 7 8 9
177
-    local deltaList = {
178
-        {dx = -1, dy = 1},
179
-        {dx = 0, dy = 1},
180
-        {dx = 1, dy = 1},
181
-        {dx = -1, dy = 0},
182
-        {dx = 1, dy = 0},
183
-        {dx = -1, dy = -1},
184
-        {dx = 0, dy = -1},
185
-        {dx = 1, dy = -1}
186
-    }
187
-    for _, v in ipairs(deltaList) do
188
-        local x2 = x1 + v.dx
189
-        local y2 = y1 + v.dy
190
-        if sameColorMap[y2] and sameColorMap[y2][x2] and sameColorMap[y2][x2] > 0 then
191
-            local newPos = {x = x2, y = y2, color = sameColorMap[y2][x2]}
192
-            table.insert(nextPosList, newPos)
193
-            table.insert(oneLong, newPos)
194
-            sameColorMap[y2][x2] = 0
195
-        end
196
-    end
197
-
198
-    for _, v in ipairs(nextPosList) do
199
-        self:pickup_one_long(oneLong, sameColorMap, v)
200
-    end
201
-end
202
-
203
-function root:get_map_all_long(seat, map)
204
-    local halfMap = self:get_half_map(seat, map)
205
-    -- 要求是长度满足的龙
206
-    local longList = self:get_all_long(halfMap)
207
-
208
-    return longList
209
-end
210
-
211
-function root:get_map_all_link(seat, map)
212
-    local halfMap = self:get_half_map(seat, map)
213
-    local h = #halfMap
214
-    local w = #halfMap[1]
215
-    local longList = self:get_all_long(halfMap)
216
-
217
-    local ret = {}
218
-    for _, v in ipairs(longList) do
219
-        local linkList = self:get_long_all_link(v, w, h)
220
-        self:array_merge(ret, linkList)
221
-    end
222
-    return ret
223
-end
224
-
225
-function root:get_long_all_link(long, w, h)
226
-    local map = self:long_to_map(long, w, h)
227
-
228
-    local ret = {}
229
-    local maxLen = 0
230
-    for y, oneRow in ipairs(map) do
231
-        for x, color in ipairs(oneRow) do
232
-            if color > 0 then
233
-                local result = {}
234
-                local links = {}
235
-                local pos = {x = x, y = y, color = color}
236
-                self:dfs(result, links, map, pos)
237
-
238
-                if #result == maxLen then
239
-                    if not self:is_same_link(result, ret) then
240
-                        table.insert(ret, result)
241
-                    end
242
-                elseif #result > maxLen and #result >= MIN_LONG_SIZE then
243
-                    ret = {result}
244
-                    maxLen = #result
245
-                end
246
-            end
247
-        end
248
-    end
249
-
250
-    return ret
251
-end
252
-
253
-function root:get_map_max_link(seat, map)
254
-    local halfMap = self:get_half_map(seat, map)
255
-    local h = #halfMap
256
-    local w = #halfMap[1]
257
-    local longList = self:get_all_long(halfMap)
258
-
259
-    table.sort(
260
-        longList,
261
-        function(a, b)
262
-            return #a > #b
263
-        end
264
-    )
265
-
266
-    local maxLink = {}
267
-    for _, v in ipairs(longList) do
268
-        if #maxLink >= #v then
269
-            break
270
-        end
271
-
272
-        local link = self:get_long_max_link(v, w, h)
273
-        if #link > #maxLink then
274
-            maxLink = link
275
-        end
276
-    end
277
-    return maxLink
278
-end
279
-
280
-function root:get_map_max_link_list(seat, map)
281
-    local halfMap = self:get_half_map(seat, map)
282
-    local h = #halfMap
283
-    local w = #halfMap[1]
284
-    local longList = self:get_all_long(halfMap)
285
-
286
-    local maxLinkList = {}
287
-    for _, v in ipairs(longList) do
288
-        local link = self:get_long_max_link(v, w, h)
289
-        table.insert(maxLinkList, link)
290
-    end
291
-    return maxLinkList
292
-end
293
-
294
-function root:get_long_max_link(long, w, h)
295
-    local map = self:long_to_map(long, w, h)
296
-
297
-    local ret = {}
298
-    local maxLen = 0
299
-    for y, oneRow in ipairs(map) do
300
-        for x, color in ipairs(oneRow) do
301
-            if color > 0 then
302
-                local result = {}
303
-                local links = {}
304
-                local pos = {x = x, y = y, color = color}
305
-                self:dfs(result, links, map, pos)
306
-
307
-                if #result > maxLen and #result >= MIN_LONG_SIZE then
308
-                    ret = result
309
-                    maxLen = #result
310
-
311
-                    if #ret == #long then
312
-                        return ret
313
-                    end
314
-                end
315
-            end
316
-        end
317
-    end
318
-
319
-    return ret
320
-end
321
-
322
-function root:dfs(result, links, map, pos, nearCountMap)
323
-    local x, y, tempColor = pos.x, pos.y, pos.color
324
-    map[y][x] = 0
325
-    table.insert(links, pos)
326
-
327
-    local nearMap = {
328
-        {x = -1, y = -1},
329
-        {x = -1, y = 0},
330
-        {x = -1, y = 1},
331
-        {x = 0, y = -1},
332
-        {x = 0, y = 1},
333
-        {x = 1, y = -1},
334
-        {x = 1, y = 0},
335
-        {x = 1, y = 1}
336
-    }
337
-    for _, v in ipairs(nearMap) do
338
-        local x1 = x + v.x
339
-        local y1 = y + v.y
340
-        if map[y1] and map[y1][x1] and map[y1][x1] > 0 then
341
-            local color1 = map[y1][x1]
342
-            local pos1 = {x = x1, y = y1, color = color1}
343
-            self:dfs(result, links, map, pos1)
344
-        end
345
-    end
346
-
347
-    if #links > #result then
348
-        for ii, vv in ipairs(links) do
349
-            result[ii] = vv
350
-        end
351
-    elseif nearCountMap and #links == #result then
352
-        local pos1 = links[#links]
353
-        local pos2 = result[#result]
354
-        if nearCountMap[pos2.y][pos2.x] < nearCountMap[pos1.y][pos1.x] then
355
-            for ii, vv in ipairs(links) do
356
-                result[ii] = vv
357
-            end
358
-        end
359
-    end
360
-
361
-    table.remove(links)
362
-    map[y][x] = tempColor
363
-end
364
-
365
------------------------------- 工具方法 ------------------------------
366
-
367
-function root:new_zero_map(w, h)
368
-    local ret = {}
369
-
370
-    for y = 1, h do
371
-        local oneRow = {}
372
-        for x = 1, w do
373
-            table.insert(oneRow, 0)
374
-        end
375
-        table.insert(ret, oneRow)
376
-    end
377
-
378
-    return ret
379
-end
380
-
381
-function root:array_merge(dest, src)
382
-    for _, v in ipairs(src) do
383
-        table.insert(dest, v)
384
-    end
385
-end
386
-
387
-function root:long_to_map(long, w, h)
388
-    local map = self:new_zero_map(w, h)
389
-
390
-    for _, v in ipairs(long) do
391
-        map[v.y][v.x] = v.color
392
-    end
393
-
394
-    return map
395
-end
396
-
397
-function root:map_to_long(map)
398
-    local long = {}
399
-
400
-    for y, oneRow in ipairs(map) do
401
-        for x, color in ipairs(oneRow) do
402
-            if color > 0 then
403
-                table.insert(long, {x = x, y = y, color = color})
404
-            end
405
-        end
406
-    end
407
-
408
-    return long
409
-end
410
-
411
---[[ 判断是否同一条连线
412
-条件1:数量一样
413
-条件2:首尾一样或相反(落点一样)
414
-条件3:都是一样的格子
415
-]]
416
-function root:is_same_link(link, list)
417
-    local oneLink = list[1]
418
-    if #link ~= #oneLink then
419
-        -- 不是 数量一样
420
-        return false
421
-    end
422
-
423
-    local linkX1, linkY1 = link[1].x, link[1].y
424
-    local linkXN, linkYN = link[#link].x, link[#link].y
425
-    local linkKey = self:get_link_key(link)
426
-    for _, v in ipairs(list) do
427
-        local x1, y1 = v[1].x, v[1].y
428
-        local xN, yN = v[#v].x, v[#v].y
429
-        if
430
-            (linkX1 == x1 and linkY1 == y1 and linkXN == xN and linkYN == yN) or
431
-                (linkX1 == xN and linkY1 == yN and linkXN == x1 and linkYN == y1)
432
-         then
433
-            -- 条件2:首尾一样或相反(落点一样)
434
-            if linkKey == self:get_link_key(link) then
435
-                -- 条件3:都是一样的格子
436
-                return true
437
-            end
438
-        end
439
-    end
440
-
441
-    return false
442
-end
443
-
444
-function root:get_link_key(link)
445
-    local list = {}
446
-    for _, v in ipairs(link) do
447
-        local x, y = v.x, v.y
448
-        local flag = y * 10 + x
449
-        table.insert(list, flag)
450
-    end
451
-    table.sort(list)
452
-
453
-    return table.concat(list, "")
454
-end
455
-
456
-function root:get_near_pos_count(map, pos)
457
-    local ret = 0
458
-
459
-    local x, y = pos.x, pos.y
460
-    local nearMap = {
461
-        {x = -1, y = -1},
462
-        {x = -1, y = 0},
463
-        {x = -1, y = 1},
464
-        {x = 0, y = -1},
465
-        {x = 0, y = 1},
466
-        {x = 1, y = -1},
467
-        {x = 1, y = 0},
468
-        {x = 1, y = 1}
469
-    }
470
-    for _, v in ipairs(nearMap) do
471
-        local x1 = x + v.x
472
-        local y1 = y + v.y
473
-        if map[y1] and map[y1][x1] and map[y1][x1] > 0 then
474
-            ret = ret + 1
475
-        end
476
-    end
477
-
478
-    return ret
479
-end
480
-
481
-function root:print_long(formatStr, long, w, h)
482
-    local map = self:long_to_map(long, w, h)
483
-    self:print_map(formatStr, map)
484
-end
485
-
486
-function root:print_map(formatStr, map)
487
-    local middleRow = #map / 2
488
-
489
-    local rows = {}
490
-
491
-    -- insert 在前面的原因:第一行输出在最后,即下面
492
-    for y, oneRow in ipairs(map) do
493
-        local str = string.format("| %s |", table.concat(oneRow, " "))
494
-        table.insert(rows, 1, str)
495
-        if y == middleRow then
496
-            table.insert(rows, 1, "| - - - - - |")
497
-        end
498
-    end
499
-
500
-    table.insert(rows, 1, "| - - - - - |")
501
-    table.insert(rows, "| - - - - - |")
502
-
503
-    local msg = table.concat(rows, "\n")
504
-    printf(string.format(formatStr, msg))
505
-end
506
-
507
-function root:print_map_list(formatStr, mapList)
508
-    local height = #mapList[1]
509
-    local middleRow = height / 2
510
-
511
-    local rows = {}
512
-    for i = 1, height + 3 do
513
-        table.insert(rows, "")
514
-    end
515
-
516
-    local rowMap = {}
517
-    -- y: 01 02 03 04 05 | 06 07 08 09 10
518
-    -- r: 12 11 10 09 08 | 06 05 04 03 02
519
-    for i = 1, height do
520
-        if i <= middleRow then
521
-            rowMap[i] = height - i + 3 -- 10 - 1 + 3
522
-        else
523
-            rowMap[i] = height - i + 2 -- 10 - 6 + 2
524
-        end
525
-    end
526
-
527
-    for _, v in ipairs(mapList) do
528
-        for y, oneRow in ipairs(v) do
529
-            local row = rowMap[y]
530
-            local str = string.format(" | %s |", table.concat(oneRow, " "))
531
-            rows[row] = rows[row] .. str
532
-        end
533
-
534
-        rows[1] = rows[1] .. " | - - - - - |"
535
-        rows[middleRow + 2] = rows[middleRow + 2] .. " | - - - - - |"
536
-        rows[height + 3] = rows[height + 3] .. " | - - - - - |"
537
-    end
538
-
539
-    local msg = table.concat(rows, "\n")
540
-    printf(string.format(formatStr, msg))
541
-end
542
-
543
-function root:test()
544
-    math.randomseed(os.time())
545
-
546
-    local map = self:random_map()
547
-    -- local list = {{1, 1}, {1, 2}, {2, 2}, {3, 2}, {1, 3}, {1, 4}}
548
-    -- for _, v in ipairs(list) do
549
-    --     map[v[1]][v[2]] = 0
550
-    -- end
551
-    self:print_map("随机一个地图:\n%s", map)
552
-    printf("")
553
-
554
-    local map1 = self:get_half_map(1, map)
555
-    self:print_map("获取下半部分地图:\n%s", map1)
556
-    printf("")
557
-
558
-    local map2 = self:get_half_map(2, map)
559
-    self:print_map("获取上半部分地图:\n%s", map2)
560
-    printf("")
561
-
562
-    printf("获取上半部分地图的所有龙:")
563
-    local map2 = self:get_half_map(2, map)
564
-    local h = #map2
565
-    local w = #map2[1]
566
-    local longList = self:get_all_long(map2)
567
-    for i, v in ipairs(longList) do
568
-        local formatStr = "龙" .. i .. ":\n%s"
569
-        self:print_long(formatStr, v, w, h)
570
-    end
571
-    printf("")
572
-
573
-    printf("获取上半部分地图的所有最长连线:")
574
-    local linkList = self:get_map_all_link(2, map)
575
-    for i, v in ipairs(linkList) do
576
-        local formatStr = "连线" .. i .. ":\n%s"
577
-        self:print_long(formatStr, v, w, h)
578
-    end
579
-    printf("")
580
-
581
-    printf("获取上半部分地图的最长连线:")
582
-    local link = self:get_map_max_link(2, map)
583
-    local formatStr = "最长连线:\n%s"
584
-    self:print_long(formatStr, link, w, h)
585
-    printf("")
586
-
587
-    printf("获取上半部分地图的最长连线列表:")
588
-    local linkList = self:get_map_max_link_list(2, map)
589
-    for i, v in ipairs(linkList) do
590
-        local formatStr = "最长连线" .. i .. ":\n%s"
591
-        self:print_long(formatStr, v, w, h)
592
-    end
593
-    printf("")
594
-end
595
-
596
-function root:test_time(count)
597
-    math.randomseed(os.time())
598
-
599
-    local errorCount = 0
600
-    for i = 1, count do
601
-        local map = self:random_map()
602
-
603
-        -- local map2 = self:get_half_map(2, map)
604
-        -- self:get_all_long(map2)
605
-
606
-        local linkList = self:get_map_all_link(2, map)
607
-        -- local maxLink1 = {}
608
-        -- for _, v in ipairs(linkList) do
609
-        --     if #v > #maxLink1 then
610
-        --         maxLink1 = v
611
-        --     end
612
-        -- end
613
-    end
614
-
615
-    printf("error count " .. errorCount)
616
-end
617
-
618
-
619
-return root

+ 0 - 494
nodes/battle/lib/utils_bt_supply.lua

@@ -1,503 +0,0 @@
1
-local utils_bt_grid = require("utils_bt_grid")
2
-local battleAdapt = require "adapt.battleAdapt"
3
-local battleConst = require "battle.battleConst"
4
-
5
-local root = {}
6
-
7
-local function log2Client(core, logStr)
8
-    if not core then
9
-        print(logStr)
10
-        return
11
-    end
12
-    core:notifyClientLog(logStr)
13
-end
14
-
15
-function root:supply_grids(core, seat, grids, supplyType, is2v2)
16
-    -- 每个颜色的数量
17
-    local colorCountMap = {0, 0, 0, 0}
18
-    local hasUpdate = false
19
-    for _, v in ipairs(grids) do
20
-        local color = v.color
21
-        if color >= 1 and color <= 4 then
22
-            colorCountMap[color] = colorCountMap[color] + 1
23
-        elseif color == 0 then
24
-            hasUpdate = true
25
-        end
26
-    end
27
-
28
-    if not hasUpdate then
29
-        -- 无需色块补充
30
-        return
31
-    end
32
-
33
-    self:_drop(seat, grids)
34
-
35
-    local colorMap = utils_bt_grid:grids_to_color_map(grids)
36
-
37
-    -- 判断A类和B类是否启用,不启动的话,需要替换成L类
38
-    if string.find(supplyType, "A") == 1 or string.find(supplyType, "B") == 1 then
39
-        local linkInfo5 = self:_get_link_len_info(seat, colorMap, 5)
40
-        local more5, count5 = linkInfo5.moreLen, linkInfo5.countLen
41
-        local msg = string.format("色块补充日志:补充前状态 连线长度为5的数量: %d, 是否有长度超过5的连线: %s", count5, more5)
42
-        log2Client(core, msg)
43
-
44
-        if string.find(supplyType, "A") == 1 then
45
-            if not (more5 or count5 >= 2) then
46
-                -- A类色块补充,替换为L类色块补充
47
-                supplyType = string.gsub(supplyType, "A", "L")
48
-            else
49
-                supplyType = "A"
50
-            end
51
-        else
52
-            if not (more5 or count5 >= 1) then
53
-                -- B类色块补充,替换为L类色块补充
54
-                supplyType = string.gsub(supplyType, "B", "L")
55
-            else
56
-                supplyType = "B"
57
-            end
58
-        end
59
-    end
60
-    log2Client(core, string.format("色块补充日志:色块补充方案: %s", supplyType))
61
-
62
-    -- updateList里,x:1~5,y:1~10
63
-    local updateList
64
-    if supplyType == "A" or supplyType == "B" then
65
-        updateList = self:_supply_ab(core, seat, colorMap, colorCountMap, supplyType)
66
-    elseif string.find(supplyType, "L") == 1 then
67
-        updateList = self:_supply_l(core, seat, colorMap, colorCountMap, supplyType)
68
-    elseif string.find(supplyType, "W") == 1 or string.find(supplyType, "R") == 1 then
69
-        updateList = self:_supply_wr(core, seat, colorMap, colorCountMap, supplyType)
70
-    else
71
-        print("ERROR: 非法色块补充方案")
72
-    end
73
-
74
-    if updateList and #updateList > 0 then
75
-        for _, v in ipairs(updateList) do
76
-            local x, y = v.x - 1, v.y - 1
77
-            self:_set_color(grids, x, y, v.color)
78
-        end
79
-
80
-        -- 补充万能色块的逻辑
81
-        local colorMap2 = utils_bt_grid:grids_to_color_map(grids)
82
-        local linkInfo4 = self:_get_link_len_info(seat, colorMap2, 4)
83
-        local more4, count4 = linkInfo4.moreLen, linkInfo4.countLen
84
-        local msg = string.format("色块补充日志:补充后状态 连线长度为4的数量: %d, 是否有长度超过4的连线: %s", count4, more4)
85
-        log2Client(core, msg)
86
-        local maxCount4 = is2v2 and 2 or 1
87
-        if count4 <= maxCount4 and not more4 then
88
-            local pos = updateList[math.random(#updateList)]
89
-            local x, y = pos.x - 1, pos.y - 1
90
-            self:_set_color(grids, x, y, battleConst.COLOR_TYPE.ALL)
91
-
92
-            local msg = string.format("色块补充日志:符合变万能色块逻辑 (%d, %d) 变为万能色块", x, y)
93
-            log2Client(core, msg)
94
-        end
95
-    end
96
-end
97
-
98
-function root:_drop(seat, grids)
99
-    --[[
100
-        seat: 当前回合操作的座位
101
-            1:下方操作,色块往下掉落,该列非空色块的y -1
102
-            2:上方操作,色块往上掉落,该列非空色块的y +1
103
-    ]]
104
-    local tempGridMap = {}
105
-    local maxX = 0
106
-    local maxY = 0
107
-    for _, v in ipairs(grids) do
108
-        local row, col = v.y + 1, v.x + 1
109
-        if not tempGridMap[row] then
110
-            tempGridMap[row] = {}
111
-        end
112
-        tempGridMap[row][col] = v
113
-
114
-        maxX = math.max(maxX, col)
115
-        maxY = math.max(maxY, row)
116
-    end
117
-    local w, h = maxX, maxY
118
-
119
-    local startY, endY, stepY
120
-    if seat == 1 then
121
-        startY, endY, stepY = 1, h, 1
122
-    else
123
-        startY, endY, stepY = h, 1, -1
124
-    end
125
-
126
-    for col = 1, w do
127
-        local emptyCount = 0
128
-        for row = startY, endY, stepY do
129
-            local grid = tempGridMap[row][col]
130
-            if grid.color == 0 then
131
-                emptyCount = emptyCount + 1
132
-
133
-                -- 例如:第2格空的,补充到倒数第2行。y=10-1*(2-1)
134
-                grid.y = endY - stepY * (emptyCount - 1) - 1
135
-            else
136
-                -- 例如:第9行往下掉2格。y=9-1*2
137
-                grid.y = grid.y - stepY * emptyCount
138
-            end
139
-        end
140
-    end
141
-end
142
-
143
---[[ 判断“当前操作的敌方”可连线长度的情况
144
-    moreLen: 连线长度为 len 的数量
145
-    countLen: 是否有长度超过 len 的连线
146
-]]
147
-function root:_get_link_len_info(seat, colorMap, len)
148
-    local otherSeat = seat == 1 and 2 or 1
149
-    local links = utils_bt_grid:get_map_max_link_list(otherSeat, colorMap)
150
-
151
-    local countLen = 0
152
-    local moreLen = false
153
-    for _, v in ipairs(links) do
154
-        if #v > len then
155
-            moreLen = true
156
-            break
157
-        elseif #v == len then
158
-            countLen = countLen + 1
159
-        end
160
-    end
161
-
162
-    return {countLen = countLen, moreLen = moreLen}
163
-end
164
-
165
-function root:_supply_l(core, seat, colorMap, colorCountMap, supplyType)
166
-    local ret = {}
167
-
168
-    -- 特殊补充色块一方:当前操作的我方。随机补充
169
-    local supplyPosList2 = self:_get_supply_pos_list(seat, colorMap)
170
-    for _, v in ipairs(supplyPosList2) do
171
-        local color = math.random(1, 4)
172
-        table.insert(ret, {x = v.x, y = v.y, color = color})
173
-    end
174
-
175
-    -- 正常补充色块一方:当前操作的敌方。按方案补充
176
-    local otherSeat = seat == 1 and 2 or 1
177
-    local halfMap = utils_bt_grid:get_half_map(otherSeat, colorMap)
178
-    local supplyPosList1 = self:_get_supply_pos_list(otherSeat, colorMap)
179
-
180
-    -- 半场每个颜色的数量记录
181
-    local halfCountMap = {0, 0, 0, 0}
182
-    for _, v in ipairs(halfMap) do
183
-        for _, vv in ipairs(v) do
184
-            if vv >= 1 and vv <= 4 then
185
-                halfCountMap[vv] = halfCountMap[vv] + 1
186
-            end
187
-        end
188
-    end
189
-
190
-    -- 排序一下
191
-    table.sort(
192
-        supplyPosList1,
193
-        function(a, b)
194
-            if a.y ~= b.y then
195
-                if otherSeat == 1 then
196
-                    return a.y > b.y
197
-                else
198
-                    return a.y < b.y
199
-                end
200
-            else
201
-                return a.x < b.x
202
-            end
203
-        end
204
-    )
205
-
206
-    for _, v in ipairs(supplyPosList1) do
207
-        local x, y = v.x, v.y
208
-
209
-        local okColorList = {1, 2, 3, 4}
210
-        local okColorWeightList = {}
211
-        for _, v in ipairs(okColorList) do
212
-            local allCount = halfCountMap[v]
213
-            local weight = battleAdapt:getColorWeight(allCount, supplyType)
214
-            table.insert(okColorWeightList, {v, weight})
215
-        end
216
-        local tempColor = self:random_with_weight(okColorWeightList)
217
-        local msg = string.format("色块补充日志:L类色块补充权重: %s, 色块补充颜色: %s", tostring(okColorWeightList), tempColor)
218
-        log2Client(core, msg)
219
-
220
-        halfCountMap[tempColor] = halfCountMap[tempColor] + 1
221
-        halfMap[y][x] = tempColor
222
-        table.insert(ret, {x = x, y = y, color = tempColor})
223
-    end
224
-
225
-    return ret
226
-end
227
-
228
-function root:_supply_wr(core, seat, colorMap, colorCountMap, supplyType)
229
-    local ret = {}
230
-
231
-    -- 每个颜色补充的数量记录
232
-    local suppleCountMap = {0, 0, 0, 0}
233
-
234
-    -- 特殊补充色块一方:当前操作的我方。随机补充
235
-    local supplyPosList2 = self:_get_supply_pos_list(seat, colorMap)
236
-    for _, v in ipairs(supplyPosList2) do
237
-        local color = math.random(1, 4)
238
-        table.insert(ret, {x = v.x, y = v.y, color = color})
239
-
240
-        suppleCountMap[color] = suppleCountMap[color] + 1
241
-    end
242
-
243
-    -- 正常补充色块一方:当前操作的敌方。按方案补充
244
-    local otherSeat = seat == 1 and 2 or 1
245
-    local halfMap = utils_bt_grid:get_half_map(otherSeat, colorMap)
246
-    local supplyPosList1 = self:_get_supply_pos_list(otherSeat, colorMap)
247
-
248
-    -- 排序一下
249
-    table.sort(
250
-        supplyPosList1,
251
-        function(a, b)
252
-            if a.y ~= b.y then
253
-                if otherSeat == 1 then
254
-                    return a.y > b.y
255
-                else
256
-                    return a.y < b.y
257
-                end
258
-            else
259
-                return a.x < b.x
260
-            end
261
-        end
262
-    )
263
-
264
-    for _, v in ipairs(supplyPosList1) do
265
-        local x, y = v.x, v.y
266
-
267
-        local okColorList = {1, 2, 3, 4}
268
-        local okColorWeightList = {}
269
-        for _, v in ipairs(okColorList) do
270
-            local allCount = colorCountMap[v] + suppleCountMap[v]
271
-            local weight = battleAdapt:getColorWeight(allCount, supplyType)
272
-            table.insert(okColorWeightList, {v, weight})
273
-        end
274
-        local tempColor = self:random_with_weight(okColorWeightList)
275
-        local msg = string.format("色块补充日志:WR类色块补充权重: %s, 色块补充颜色: %s", tostring(okColorWeightList), tempColor)
276
-        log2Client(core, msg)
277
-
278
-        suppleCountMap[tempColor] = suppleCountMap[tempColor] + 1
279
-        halfMap[y][x] = tempColor
280
-        table.insert(ret, {x = x, y = y, color = tempColor})
281
-    end
282
-
283
-    return ret
284
-end
285
-
286
-function root:_supply_ab(core, seat, colorMap, colorCountMap, supplyType)
287
-    local ret = {}
288
-
289
-    -- 每个颜色补充的数量记录
290
-    local suppleCountMap = {0, 0, 0, 0}
291
-
292
-    -- 特殊补充色块一方:当前操作的我方。随机补充
293
-    local supplyPosList2 = self:_get_supply_pos_list(seat, colorMap)
294
-    for _, v in ipairs(supplyPosList2) do
295
-        local color = math.random(1, 4)
296
-        table.insert(ret, {x = v.x, y = v.y, color = color})
297
-
298
-        suppleCountMap[color] = suppleCountMap[color] + 1
299
-    end
300
-
301
-    -- 正常补充色块一方:当前操作的敌方。按方案补充
302
-    local otherSeat = seat == 1 and 2 or 1
303
-    local halfMap = utils_bt_grid:get_half_map(otherSeat, colorMap)
304
-    local supplyPosList1 = self:_get_supply_pos_list(otherSeat, colorMap)
305
-
306
-    -- 排序一下
307
-    table.sort(
308
-        supplyPosList1,
309
-        function(a, b)
310
-            if a.y ~= b.y then
311
-                if otherSeat == 1 then
312
-                    return a.y > b.y
313
-                else
314
-                    return a.y < b.y
315
-                end
316
-            else
317
-                return a.x < b.x
318
-            end
319
-        end
320
-    )
321
-
322
-    for _, v in ipairs(supplyPosList1) do
323
-        local x, y = v.x, v.y
324
-
325
-        local okColorList = {}
326
-        local maxLen = 4
327
-        for color = 1, 4 do
328
-            halfMap[y][x] = color
329
-
330
-            local sameList = {}
331
-            local nextPos = {x = x, y = y}
332
-            self:_find_same_color_list(halfMap, sameList, nextPos, color)
333
-            if #sameList <= maxLen then
334
-                table.insert(okColorList, color)
335
-            end
336
-        end
337
-
338
-        if #okColorList == 0 then
339
-            okColorList = {1, 2, 3, 4}
340
-        end
341
-
342
-        local okColorWeightList = {}
343
-        for _, v in ipairs(okColorList) do
344
-            local allCount = colorCountMap[v] + suppleCountMap[v]
345
-            local weight = battleAdapt:getColorWeight(allCount, supplyType)
346
-            table.insert(okColorWeightList, {v, weight})
347
-        end
348
-        local tempColor = self:random_with_weight(okColorWeightList)
349
-        local msg = string.format("色块补充日志:AB类色块补充权重: %s, 色块补充颜色: %s", tostring(okColorWeightList), tempColor)
350
-        log2Client(core, msg)
351
-
352
-        suppleCountMap[tempColor] = suppleCountMap[tempColor] + 1
353
-        halfMap[y][x] = tempColor
354
-        table.insert(ret, {x = x, y = y, color = tempColor})
355
-    end
356
-
357
-    return ret
358
-end
359
-
360
-function root:_get_supply_pos_list(seat, colorMap)
361
-    local maxH = #colorMap
362
-    local minY, maxY
363
-    if seat == 1 then
364
-        minY, maxY = 1, maxH / 2
365
-    else
366
-        minY, maxY = maxH / 2 + 1, maxH
367
-    end
368
-
369
-    local ret = {}
370
-    for y = minY, maxY do
371
-        local oneRow = colorMap[y]
372
-        for x, color in ipairs(oneRow) do
373
-            if color == 0 then
374
-                table.insert(ret, {x = x, y = y})
375
-            end
376
-        end
377
-    end
378
-
379
-    return ret
380
-end
381
-
382
-function root:_find_same_color_list(map, sameList, nextPos, color)
383
-    local x1 = nextPos.x
384
-    local y1 = nextPos.y
385
-
386
-    for _, v in ipairs(sameList) do
387
-        if v.x == x1 and v.y == y1 then
388
-            -- 已经添加过了,跳过
389
-            return
390
-        end
391
-    end
392
-
393
-    table.insert(sameList, nextPos)
394
-
395
-    -- 九宫格示例
396
-    -- 1 2 3
397
-    -- 4 x 6
398
-    -- 7 8 9
399
-    local deltaList = {
400
-        {dx = -1, dy = 1},
401
-        {dx = 0, dy = 1},
402
-        {dx = 1, dy = 1},
403
-        {dx = -1, dy = 0},
404
-        {dx = 1, dy = 0},
405
-        {dx = -1, dy = -1},
406
-        {dx = 0, dy = -1},
407
-        {dx = 1, dy = -1}
408
-    }
409
-    for _, v in ipairs(deltaList) do
410
-        local x2 = x1 + v.dx
411
-        local y2 = y1 + v.dy
412
-        if map[y2] and map[y2][x2] and (map[y2][x2] == color or map[y2][x2] == 5) then
413
-            self:_find_same_color_list(map, sameList, {x = x2, y = y2}, color)
414
-        end
415
-    end
416
-end
417
-
418
-function root:_set_color(grids, x, y, color)
419
-    for _, v in ipairs(grids) do
420
-        if x == v.x and y == v.y then
421
-            v.color = color
422
-            break
423
-        end
424
-    end
425
-end
426
-
427
-function root:_get_weight(count, supplyType)
428
-    if count > 15 then
429
-        return 0
430
-    else
431
-        return 15 - count
432
-    end
433
-end
434
-
435
-function root:random_index_with_weights(list)
436
-    local sum = 0
437
-    for _, v in ipairs(list) do
438
-        sum = sum + v
439
-    end
440
-
441
-    local ret = 1
442
-    if sum > 0 then
443
-        local r = math.random(1, sum)
444
-
445
-        local didSum = 0
446
-        for i, v in ipairs(list) do
447
-            didSum = didSum + v
448
-            if r <= didSum then
449
-                ret = i
450
-                break
451
-            end
452
-        end
453
-    end
454
-
455
-    return ret
456
-end
457
-
458
-function root:random_with_weight(data)
459
-    local weights = {}
460
-    for _, v in ipairs(data) do
461
-        table.insert(weights, v[2])
462
-    end
463
-
464
-    local index = self:random_index_with_weights(weights)
465
-    return data[index][1]
466
-end
467
-
468
-function root:test()
469
-    local seat = 1
470
-    local grids = {}
471
-    local supplyType = "A"
472
-
473
-    for x = 0, 4 do
474
-        for y = 0, 9 do
475
-            table.insert(grids, {x = x, y = y, color = math.random(1, 5)})
476
-        end
477
-    end
478
-
479
-    local list = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
480
-    for _, v in ipairs(list) do
481
-        grids[v].color = 0
482
-    end
483
-
484
-    local colorMap = utils_bt_grid:grids_to_color_map(grids)
485
-    utils_bt_grid:print_map("===1 %s", colorMap)
486
-
487
-    self:supply_grids(nil, seat, grids, supplyType, false)
488
-
489
-    local colorMap = utils_bt_grid:grids_to_color_map(grids)
490
-    utils_bt_grid:print_map("===2 %s", colorMap)
491
-end
492
-
493
-
494
-return root

+ 0 - 35
nodes/battle/main.lua

@@ -1,35 +0,0 @@
1
---[[
2
-Author: neo
3
-Date: 2021-05-31 11:12:16
4
-LastEditTime: 2021-06-01 10:49:54
5
-LastEditors: Please set LastEditors
6
-Description: 游戏战斗服
7
---]]
8
-local skynet = require "skynet"
9
-require "skynet.manager"
10
-local init_nodes = require("init_nodes")
11
-
12
-skynet.start(
13
-    function()
14
-        -- 初始化控制台
15
-        init_nodes:init_console()
16
-
17
-        -- 日志
18
-        init_nodes:init_logger()
19
-        -- 数据库
20
-        init_nodes:init_mysql()
21
-        -- redis
22
-        init_nodes:init_redis()
23
-        -- 配置
24
-        init_nodes:init_config()
25
-
26
-        skynet.uniqueservice("srvBattleMgr")
27
-
28
-        -- 集群
29
-        init_nodes:init_cluster()
30
-
31
-        skynet.send(".steward", "lua", "node_hb_to_master", "battlemaster")
32
-
33
-        skynet.exit()
34
-    end
35
-)

+ 0 - 109
nodes/battle/service/srvBattle.lua

@@ -1,113 +0,0 @@
1
---[[
2
-Author: neo
3
-Date: 2021-05-31 14:40:54
4
-LastEditTime: 2021-06-28 20:56:43
5
-LastEditors: Please set LastEditors
6
-Description: battle agent
7
---]]
8
-local skynet = require "skynet"
9
-local battle = require "battle"
10
-local baseService = require("baseService")
11
-local battleCode = require "battle.battleCode"
12
-
13
-local root = {}
14
-
15
-local mapBattleObj = {} -- string.format("%s:%s:%s", matchNode, matchId, battleId) -> battleObj
16
-
17
-function root.start_battle(matchInfo, playerList, viewerList, battleParams, settleNodeInfo)
18
-    local objBattle = battle.new(matchInfo, battleParams, settleNodeInfo)
19
-    mapBattleObj[matchInfo.battleId] = objBattle
20
-    objBattle:startBattle(playerList, viewerList)
21
-    root.start_tick_timer()
22
-    -- 通知 battleMgr
23
-    skynet.call(".BattleMgr", "lua", "battleEnter", matchInfo.battleId, skynet.self())
24
-    return true
25
-end
26
-
27
-function root.is_user_in_battle(uid, battleId)
28
-    if uid == nil or battleId == nil then
29
-        return false
30
-    end
31
-    local objBattle = mapBattleObj[battleId]
32
-    if objBattle == nil then
33
-        return false
34
-    end
35
-    if objBattle:is_user_in_battle(uid) then
36
-        return true
37
-    end
38
-    return false
39
-end
40
-
41
-function root.start_tick_timer()
42
-    if root.timer then
43
-        return
44
-    end
45
-    root.timer =
46
-        create_timeout(
47
-        100,
48
-        function()
49
-            root.tick_time_out()
50
-        end
51
-    )
52
-end
53
-
54
-function root.tick_time_out()
55
-    if root.timer then
56
-        root.timer.delete()
57
-        root.timer = nil
58
-    end
59
-
60
-    local unactiveList = nil
61
-    for k, v in pairs(mapBattleObj) do
62
-        if v.isActive then
63
-            v.core:do_tick()
64
-        else
65
-            if unactiveList == nil then
66
-                unactiveList = {}
67
-            end
68
-            table.insert(unactiveList, k)
69
-        end
70
-    end
71
-    -- 清除非活跃战斗
72
-    if unactiveList then
73
-        for _, v in ipairs(unactiveList) do
74
-            log.info("tick_time_out 释放战斗[%s]", tostring(v))
75
-            mapBattleObj[v] = nil
76
-        end
77
-    end
78
-
79
-    root.start_tick_timer()
80
-end
81
-
82
-function root.forward(battleId, cmd, ...)
83
-    if battleId == nil or is_empty(cmd) then
84
-        log.error("battle error: battleId[%s] cmd[%s]", tostring(battleId), tostring(cmd))
85
-        error("battle session error")
86
-    end
87
-    local objBattle = mapBattleObj[battleId]
88
-    -- 已销毁/非活跃战斗
89
-    if not objBattle or not objBattle.isActive then
90
-        log.error("battle obj not exists, battleId = %s, cmd = %s", battleId, tostring(cmd))
91
-        -- error("battle obj not exists")
92
-        return {code = battleCode.BATTLE_NOT_EXIST}
93
-    end
94
-    local func = battle[cmd]
95
-    if not func then
96
-        error("battle func error")
97
-    end
98
-    return func(objBattle, ...)
99
-end
100
-
101
-function root.onStart()
102
-    math.randomseed(tostring(os.time()) .. skynet.self())
103
-end
104
-
105
-function root.recycle()
106
-    skynet.exit()
107
-end
108
-
109
-baseService.start(root)

+ 0 - 42
nodes/battle/service/srvBattleMgr.lua

@@ -1,45 +0,0 @@
1
---[[
2
-Author: neo
3
-Date: 2021-05-31 14:14:53
4
-LastEditTime: 2021-06-01 11:00:59
5
-LastEditors: Please set LastEditors
6
-Description: battle agent 管理服务
7
---]]
8
-local const = require "const.const"
9
-local skynet = require "skynet"
10
-
11
-local agentPool = require "agentPool"
12
-local baseService = require("baseService")
13
-
14
-local pool
15
-
16
-local CMD = {}
17
-
18
-function CMD.getBattleAgent()
19
-    return pool:alloc_agent_srv()
20
-end
21
-
22
-function CMD.battleEnter(id, battleAgent)
23
-    pool:bind_agent(id, battleAgent)
24
-end
25
-
26
-function CMD.battleLeave(id, battleAgent)
27
-    pool:unbind_agent(id, battleAgent)
28
-end
29
-
30
-function CMD.is_user_in_battle(uid, battleId, battleAgent)
31
-    if battleAgent == nil or not pool:get_agent_info_by_addr(battleAgent) then
32
-        return false
33
-    end
34
-    local ok = skynet.call(battleAgent, "lua", "is_user_in_battle", uid, battleId)
35
-    return ok
36
-end
37
-
38
-function CMD.onStart()
39
-    pool = agentPool.new("srvBattle", const.INIT_AGENT_COUNT)
40
-end
41
-
42
-baseService.start(CMD, ".BattleMgr", true)

+ 0 - 33
nodes/battlemaster/main.lua

@@ -1,33 +0,0 @@
1
---[[
2
-Author: neo
3
-Date: 2021-05-27 11:56:14
4
-LastEditTime: 2021-05-27 19:20:29
5
-LastEditors: Please set LastEditors
6
-Description: 游戏业务节点分配服
7
---]]
8
-local skynet = require "skynet"
9
-require "skynet.manager"
10
-local init_nodes = require("init_nodes")
11
-
12
-skynet.start(
13
-    function()
14
-        -- 初始化控制台
15
-        init_nodes:init_console()
16
-
17
-        -- 日志
18
-        init_nodes:init_logger()
19
-        -- 数据库
20
-        init_nodes:init_mysql()
21
-        -- redis
22
-        init_nodes:init_redis()
23
-        -- 配置
24
-        init_nodes:init_config()
25
-
26
-        skynet.uniqueservice("srvNodeMgr")
27
-
28
-        -- 集群
29
-        init_nodes:init_cluster()
30
-
31
-        skynet.exit()
32
-    end
33
-)

+ 0 - 283
nodes/battlemaster/service/srvNodeMgr.lua

@@ -1,300 +0,0 @@
1
---[[
2
-Author: neo
3
-Date: 2021-05-27 14:43:17
4
-LastEditTime: 2021-05-31 20:52:30
5
-LastEditors: Please set LastEditors
6
-Description: 游戏业务节点分配服务
7
---]]
8
-local baseService = require("baseService")
9
-local nodeMgr = require("nodeMgr")
10
-local util_node = require("utils.util_node")
11
-local lib_game_redis = require("lib_game_redis")
12
-
13
-local root = {}
14
-
15
-
16
-function root.start_timer_heart_beat()
17
-    root.timerHeatBeat =
18
-        create_timeout(
19
-        500,
20
-        function()
21
-            root.timer_out_heart_beat()
22
-        end
23
-    )
24
-end
25
-function root.timer_out_heart_beat()
26
-    root.timerHeatBeat.delete()
27
-    root.timerHeatBeat = nil
28
-
29
-    root.start_timer_heart_beat()
30
-
31
-    if root.mapCluster == nil then
32
-        return
33
-    end
34
-
35
-    local currTime = skynet_time()
36
-    for k, v in pairs(root.mapCluster) do
37
-        local isUpdate = false
38
-        for _k, _v in pairs(v) do
39
-            if _v.isAlive and currTime >= _v.updateTime + 20 then
40
-                _v.isAlive = false
41
-                log.warning("节点[%s]已失效", tostring(_v.nodeName))
42
-                isUpdate = true
43
-            end
44
-        end
45
-        if isUpdate then
46
-            root.update_weight(k)
47
-        end
48
-    end
49
-end
50
-
51
-function root.node_heart_beat(nodeInfo)
52
-    if is_empty(nodeInfo) or is_empty(nodeInfo.clusterName) or is_empty(nodeInfo.nodeName) then
53
-        return false
54
-    end
55
-    local clusterName = nodeInfo.clusterName
56
-    local nodeName = nodeInfo.nodeName
57
-    if root.mapCluster == nil then
58
-        root.mapCluster = {}
59
-    end
60
-    if root.mapCluster[clusterName] == nil then
61
-        root.mapCluster[clusterName] = {}
62
-    end
63
-    nodeInfo.updateTime = skynet_time()
64
-    nodeInfo.isAlive = true
65
-
66
-    -- 是否更新权重
67
-    local nInfo = root.get_cluster_node_info(clusterName, nodeName)
68
-    -- 重新加入节点
69
-    if nInfo == nil or not nInfo.isAlive then
70
-        util_node:node_load_init_grains(nodeName)
71
-    end
72
-    local isUpdateWeight = false
73
-    if nInfo == nil or not nInfo.isAlive or nInfo.weight ~= nodeInfo.weight then
74
-        isUpdateWeight = true
75
-    end
76
-    root.mapCluster[clusterName][nodeName] = nodeInfo
77
-
78
-    -- 更新权重
79
-    if isUpdateWeight then
80
-        root.update_weight(clusterName)
81
-    end
82
-
83
-    return true
84
-end
85
-function root.node_stop(clusterName, nodeName)
86
-    if is_empty(clusterName) or is_empty(nodeName) then
87
-        return false
88
-    end
89
-    if root.mapCluster[clusterName] == nil then
90
-        return false
91
-    end
92
-    if root.mapCluster[clusterName][nodeName] == nil then
93
-        return false
94
-    end
95
-    root.mapCluster[clusterName][nodeName].isAlive = false
96
-
97
-    -- 更新权重
98
-    root.update_weight(clusterName)
99
-    return true
100
-end
101
-function root.update_weight(clusterName)
102
-    if root.mapClusterWeight == nil then
103
-        root.mapClusterWeight = {}
104
-    end
105
-    local weightInfo = {}
106
-    weightInfo.total = 0
107
-    weightInfo.list = {}
108
-    for k, v in pairs(root.mapCluster[clusterName]) do
109
-        if v.isAlive then
110
-            local info = {}
111
-            info.nodeName = v.nodeName
112
-            info.min = weightInfo.total + 1
113
-            weightInfo.total = weightInfo.total + (v.weight or 0)
114
-            info.max = weightInfo.total
115
-            table.insert(weightInfo.list, info)
116
-        end
117
-    end
118
-    root.mapClusterWeight[clusterName] = weightInfo
119
-end
120
-
121
-function root.get_cluster_node_info(clusterName, nodeName)
122
-    if is_empty(clusterName) or is_empty(nodeName) then
123
-        return
124
-    end
125
-    if root.mapCluster == nil or root.mapCluster[clusterName] == nil then
126
-        return
127
-    end
128
-    return root.mapCluster[clusterName][nodeName]
129
-end
130
-function root.user_band_node(uid, clusterName, nodeName)
131
-    if uid == nil then
132
-        return false
133
-    end
134
-    if root.mapUid2NodeInfo == nil then
135
-        root.mapUid2NodeInfo = {}
136
-    end
137
-    if root.mapUid2NodeInfo[uid] == nil then
138
-        root.mapUid2NodeInfo[uid] = {}
139
-    end
140
-    root.mapUid2NodeInfo[uid][clusterName] = nodeName
141
-    return true
142
-end
143
-function root.dispatch_match_node(uid, conf)
144
-    -- TODO:根据match节点下匹配队列人数分配
145
-    -- 本地管理匹配队列玩家列表?
146
-    local clusterName = "match"
147
-    -- 按照负载集中分配
148
-    local nodeName = root.user_dispatch_node_by_grain(uid, clusterName)
149
-    if is_empty(nodeName) then
150
-        -- 按照权重分配
151
-        nodeName = root.user_dispatch_node_by_weight(uid, clusterName)
152
-    end
153
-    if not is_empty(nodeName) then
154
-        root.user_band_node(uid, clusterName, nodeName)
155
-        return nodeName
156
-    end
157
-end
158
-function root.dispatch_battle_node(uid)
159
-    -- 按照权重做负载均衡
160
-    local clusterName = "battle"
161
-    local nodeName = root.user_dispatch_node_by_weight(uid, clusterName)
162
-    root.user_band_node(uid, clusterName, nodeName)
163
-    if is_empty(nodeName) then
164
-        return
165
-    end
166
-
167
-    -- 全服 - 战斗ID
168
-    local battleId = lib_game_redis:hincrby("battle", "id", 1)
169
-    if battleId >= 1000000000 then
170
-        battleId = 1
171
-        lib_game_redis:hset("battle", "id", battleId)
172
-    end
173
-
174
-    local ret = {}
175
-    ret.battleNode = nodeName
176
-    ret.battleId = battleId
177
-    return ret
178
-end
179
-
180
-function root.get_total_battle_count()
181
-    if root.mapCluster == nil or root.mapCluster["match"] == nil then
182
-        return 0
183
-    end
184
-    local count = 0
185
-    for k, v in pairs(root.mapCluster["match"]) do
186
-        local ok, battleCount = nodeMgr.call(v.nodeName, ".BattleMatch", "getBattleCount")
187
-        if ok and battleCount then
188
-            count = count + battleCount
189
-        end
190
-    end
191
-    return count
192
-end
193
-
194
-function root.get_cluster_node_list(clusterName)
195
-    if is_empty(clusterName) then
196
-        return
197
-    end
198
-    if root.mapCluster == nil or root.mapCluster[clusterName] == nil then
199
-        return
200
-    end
201
-    local nodeList = {}
202
-    for k, v in pairs(root.mapCluster[clusterName]) do
203
-        if v.isAlive then
204
-            table.insert(nodeList, v.nodeName)
205
-        end
206
-    end
207
-    return nodeList
208
-end
209
-
210
-----------------------------------------
211
-----------------------------------------
212
-function root.user_dispatch_node_by_weight(uid, clusterName)
213
-    if is_empty(clusterName) then
214
-        return
215
-    end
216
-    if root.mapCluster == nil then
217
-        return
218
-    end
219
-    if root.mapCluster[clusterName] == nil then
220
-        return
221
-    end
222
-    -- 已分配
223
-    if uid and root.mapUid2NodeInfo and root.mapUid2NodeInfo[uid] and root.mapUid2NodeInfo[uid][clusterName] then
224
-        local nodeName = root.mapUid2NodeInfo[uid][clusterName]
225
-        local nodeInfo = root.get_cluster_node_info(clusterName, nodeName)
226
-        if nodeInfo and nodeInfo.isAlive then
227
-            return nodeName
228
-        end
229
-    end
230
-    local rand = math.random(1, root.mapClusterWeight[clusterName].total)
231
-    for k, v in ipairs(root.mapClusterWeight[clusterName].list) do
232
-        if v.min <= rand and rand <= v.max then
233
-            log.info("user_dispatch_node_by_weight uid[%s] nodeName[%s]", tostring(uid), tostring(v.nodeName))
234
-            return v.nodeName
235
-        end
236
-    end
237
-end
238
-function root.user_dispatch_node_by_grain(uid, clusterName)
239
-    if is_empty(clusterName) or root.mapCluster == nil or root.mapCluster[clusterName] == nil then
240
-        return
241
-    end
242
-    -- 已分配
243
-    if uid and root.mapUid2NodeInfo and root.mapUid2NodeInfo[uid] and root.mapUid2NodeInfo[uid][clusterName] then
244
-        local nodeName = root.mapUid2NodeInfo[uid][clusterName]
245
-        local nodeInfo = root.get_cluster_node_info(clusterName, nodeName)
246
-        if nodeInfo and nodeInfo.isAlive then
247
-            return nodeName
248
-        end
249
-    end
250
-    -- 按顺序分配
251
-    local firstNode = nil
252
-    for k, v in pairs(root.mapCluster[clusterName]) do
253
-        -- 首个节点
254
-        if firstNode == nil then
255
-            firstNode = v.nodeName
256
-        end
257
-        -- 该节点当前负载
258
-        local grains = util_node:node_load_get_grains(k)
259
-        if grains < v.weight * 10 then
260
-            log.info(
261
-                "user_dispatch_node_by_grain clusterName[%s] uid[%s] nodeName[%s]",
262
-                tostring(clusterName),
263
-                tostring(uid),
264
-                tostring(v.nodeName)
265
-            )
266
-            return v.nodeName
267
-        end
268
-    end
269
-    -- 找不到节点,返回首个节点
270
-    log.info(
271
-        "user_dispatch_node_by_grain clusterName[%s] uid[%s] firstNode[%s]",
272
-        tostring(clusterName),
273
-        tostring(uid),
274
-        tostring(firstNode)
275
-    )
276
-    return firstNode
277
-end
278
-
279
-function root.onStart()
280
-    root.start_timer_heart_beat()
281
-end
282
-
283
-baseService.start(root, ".srvNodeMgr", true)

+ 0 - 2
nodes/global/service/mailSrv.lua

@@ -28,7 +28,6 @@ local function l_del_expire_mail()
28 28
 		tostring(currTime)
29 29
 	)
30 30
 	local ret = lib_game_mysql:query(sql)
31
-	log.info("l_del_expire_mail sql[%s] ret[%s]", tostring(sql), tostring(ret))
32 31
 
33 32
 	-- 删除保留邮件
34 33
 	local expireTime = currTime - 3600 * 24 * 30
@@ -45,7 +44,6 @@ local function l_expire_items_mail()
45 44
 		"SELECT * FROM `mdl_mail` WHERE expireTime < %s and JSON_LENGTH(items) > 0 limit 100;",
46 45
 		tostring(currTime)
47 46
 	)
48
-	log.info("l_expire_items_mail sql[%s]", tostring(sql))
49 47
 
50 48
 	local ret = lib_game_mysql:query(sql)
51 49
 	if ret.errno and ret.errno > 0 then

+ 0 - 15
run/common/battle.conf

@@ -1,18 +0,0 @@
1
-include "public.conf"
2
-
3
-clusterName = "battle"
4
-nodeName = "battle"
5
-
6
-lroot = root.."nodes/"..clusterName.."/"
7
-luaservice = luaservice..lroot.."service/?.lua;"..lroot.."?.lua;"
8
-lua_path = lua_path..lroot.."?.lua;"..lroot.."service/?.lua;"..lroot.."lib/?.lua;"
9
-snax = luaservice
10
-
11
-start = "main"
12
-
13
-if system == "linux" then
14
-daemon = "./skynet_"..nodeName..".pid"
15
-end

+ 0 - 2
run/common/clustername.lua

@@ -4,5 +4,3 @@ global = "127.0.0.1:3002"
4 4
 login = "127.0.0.1:3003"
5 5
 gate1_1 = "127.0.0.1:3004"
6 6
 game1_1 = "127.0.0.1:3005"
7
-battlemaster = "127.0.0.1:3006"
8
-battle1_1 = "127.0.0.1:3007"