Blame view

src/models/RoleBattle.lua 13.5 KB
d4e9b817   zhouhaihai   战斗 日志
1
2
3
4
5
6
7
8
9
10
11
12
13
  local RoleBattle = {}
  
  --[[
  	100	剧情关卡类	
  	200	非剧情类普通关卡	
  	300	每日任务类、日常本类	
  	400	资源获取类关卡	
  	500	PVP关卡	
  	1000	活动期间限定类关卡	
  	2000	其他	
  ]]
  
  local BattleType = {
ca55c763   chenyueqi   引导招募必送思露德判定出了大问题
14
15
16
17
18
  	hang = 100,
  	tower = 200,
  	bonus = 300,
  	pvpc = 500,
  	pvph = 501,
66fe093a   liuzujun   元旦关卡活动
19
  	act_battle = 502,
29fbbc10   zhouhaihai   夜间打工
20
  	work = 301,
d4e9b817   zhouhaihai   战斗 日志
21
22
23
24
  }
  
  RoleBattle.bind = function (Role)
  
edf2ee12   zhouhaihai   防作弊
25
26
27
28
29
30
31
32
33
34
35
36
  local checkCheatAttrs = {
  	["hp"] = 1,
  	["atk"] = 1,
  	["def"] = 1,
  	["hit"] = 1,
  	["miss"] = 1,
  	["crit"] = 1,
  	["atkSpeed"] = 1,
  	["critHurt"] = 1,
  	-- ["vampire"] = 1,
  	-- ["pierce"] = 1,
  }
d4e9b817   zhouhaihai   战斗 日志
37
  
edf2ee12   zhouhaihai   防作弊
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  local function checkOneCheat(selfTeamClient, selfTeamServer, enemyClient, enemyServer)
  	if not selfTeamClient or type(selfTeamClient) ~= "table" then return end
  	for unitType, clientInfo in pairs(selfTeamClient) do
  		local serverInfo = selfTeamServer[unitType]
  		if not serverInfo then return end
  		for attr, pm in pairs(checkCheatAttrs) do
  			if not clientInfo[attr] then return end
  		end
  		local b1 = ((clientInfo["hp"] + clientInfo["def"] * 7 + clientInfo["miss"] * 4) * (clientInfo["atk"] * 4 + clientInfo["hit"] * 2) * (1 + clientInfo["crit"]/100 * clientInfo["critHurt"]/100) * clientInfo["atkSpeed"] / 600000) ^ 0.8
  		local b2 = ((serverInfo["hp"] + serverInfo["def"] * 7 + serverInfo["miss"] * 4) * (serverInfo["atk"] * 4 + serverInfo["hit"] * 2) * (1 + serverInfo["crit"]/100 * serverInfo["critHurt"]/100) * serverInfo["atkSpeed"] / 600000) ^ 0.8
  		if b1 >= b2 * 2 then
  			return
  		end
  	end
  	return true
d4e9b817   zhouhaihai   战斗 日志
53
54
  end
  
edf2ee12   zhouhaihai   防作弊
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  -- local function getRobotAttrs(info, strength)
  -- 	strength = strength or 10000
  -- 	local unitData = csvdb["unitCsv"][info.unitType]
  -- 	local enemy = {}
  -- 	for arr, _ in pairs(checkCheatAttrs) do
  -- 		enemy[arr] = unitData[attr] * info[attr] * strength / 10000
  -- 	end
  -- 	return enemy
  -- end
  
  -- --通过配表构建敌人队伍 通用
  -- function BattleEnter:packBattleEnemyCommon( carbonData )
  -- 	local enemys = {}
  -- 	local monsterSet = csvdb[carbonData.monster:match("/([^/]*)$") .. "Csv"]
  -- 	for phase = 1, #monsterSet do
  -- 		local allEnemys = table.values(monsterSet[phase])
  -- 		table.sort(allEnemys, function(a, b) return a.id < b.id end)
  -- 		local heros = {}
  -- 		for idx, enemy in ipairs(allEnemys) do
  -- 			local info = getRobotAttrs(enemy, carbonData.strength)
  -- 			enemys[idx] = info
  -- 		end
  -- 		break
  -- 	end
  -- 	return enemys
  -- end
d4e9b817   zhouhaihai   战斗 日志
81
  
edf2ee12   zhouhaihai   防作弊
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  --  检查战斗是否作弊 
  function Role:checkBattleCheat(battleType, params)
  	if not params.isWin then return true end
  	local clientInfo = params.info or {}
  
  	if not BattleType[battleType] then
  		print(string.format("NO find battleType: %s", battleType))
  		return true
  	end
  	local selfTeamServer = {}
  	local enemyServer = {}
  
  	local cheat = {}
  	cheat["hang"] = function()
  		local team = self:getTeamBattleInfo(self:getTeamFormatByType(TeamSystemType.Hang))
  		for slot, hero in pairs(team.heros) do
  			local temp = {}
  			for arr, _ in pairs(checkCheatAttrs) do
  				temp[arr] = hero[arr]
  			end
a33ade6c   liuzujun   rmb礼包改钻石礼包
102
103
              selfTeamServer[hero.type] = temp
              self:log_battle_hero(hero.type, "hangTeam")
edf2ee12   zhouhaihai   防作弊
104
105
106
107
108
  		end
  		-- local carbonData = csvdb["idle_battleCsv"][params.id]
  		-- enemyServer = packBattleEnemyCommon(carbonData)
  	end
  	cheat["tower"] = function()
761b3ea8   chenyueqi   再改一波电波塔整容相关信息
109
  		local team = self:getTeamBattleInfo(self:getTowerTeamFormat(params.tower))
edf2ee12   zhouhaihai   防作弊
110
111
112
113
114
115
  		for slot, hero in pairs(team.heros) do
  			local temp = {}
  			for arr, _ in pairs(checkCheatAttrs) do
  				temp[arr] = hero[arr]
  			end
  			selfTeamServer[hero.type] = temp
a33ade6c   liuzujun   rmb礼包改钻石礼包
116
              self:log_battle_hero(hero.type, "towerTeam")
edf2ee12   zhouhaihai   防作弊
117
118
119
120
121
122
123
124
125
126
127
128
  		end
  		-- local carbonData = csvdb["tower_battleCsv"][params.id]
  		-- enemyServer = packBattleEnemyCommon(carbonData)
  	end
  	cheat["bonus"] = function()
  		local team = self:getTeamBattleInfo(self:getTeamFormatByType(TeamSystemType.BonusBattle))
  		for slot, hero in pairs(team.heros) do
  			local temp = {}
  			for arr, _ in pairs(checkCheatAttrs) do
  				temp[arr] = hero[arr]
  			end
  			selfTeamServer[hero.type] = temp
a33ade6c   liuzujun   rmb礼包改钻石礼包
129
              self:log_battle_hero(hero.type, "bonusTeam")
edf2ee12   zhouhaihai   防作弊
130
131
132
133
  		end
  		-- local carbonData = csvdb["bonus_battleCsv"][params.id]
  		-- enemyServer = packBattleEnemyCommon(carbonData)
  	end
29fbbc10   zhouhaihai   夜间打工
134
135
136
137
138
139
140
141
  	cheat["work"] = function()
  		local team = self:getTeamBattleInfo(self:getTeamFormatByType(TeamSystemType.BonusBattle))
  		for slot, hero in pairs(team.heros) do
  			local temp = {}
  			for arr, _ in pairs(checkCheatAttrs) do
  				temp[arr] = hero[arr]
  			end
  			selfTeamServer[hero.type] = temp
a33ade6c   liuzujun   rmb礼包改钻石礼包
142
              self:log_battle_hero(hero.type, "workTeam")
29fbbc10   zhouhaihai   夜间打工
143
144
145
146
  		end
  		-- local carbonData = csvdb["bonus_battleCsv"][params.id]
  		-- enemyServer = packBattleEnemyCommon(carbonData)
  	end
edf2ee12   zhouhaihai   防作弊
147
148
149
150
151
152
153
154
155
  	cheat["pvpc"] = function()
  		if not params.format then return end
  		local team = self:getTeamBattleInfo(params.format)
  		for slot, hero in pairs(team.heros) do
  			local temp = {}
  			for arr, _ in pairs(checkCheatAttrs) do
  				temp[arr] = hero[arr]
  			end
  			selfTeamServer[hero.type] = temp
a33ade6c   liuzujun   rmb礼包改钻石礼包
156
              self:log_battle_hero(hero.type, "pvpcTeam")
edf2ee12   zhouhaihai   防作弊
157
158
159
160
161
162
163
164
165
  		end
  	end
  	cheat["pvph"] = cheat["pvpc"]
  	cheat["act_battle"] = cheat["pvpc"]
  
  	cheat[battleType]()
  
  	local status = checkOneCheat(clientInfo.selfAttr, selfTeamServer, clientInfo.enemyAttr, enemyServer)
  	if not status then
f82b9dc2   zhouhaihai   删除自动封号
166
167
168
  		-- local cheatCount = self:getProperty("cheatCount")
  		-- cheatCount = cheatCount + 1
  		-- self:setProperty("cheatCount", cheatCount)
edf2ee12   zhouhaihai   防作弊
169
170
  
  		local result = {clientSelf = {}, serverSelf = {}}
4083e99a   zhouhaihai   可能的报错点
171
  		for k , v in pairs(clientInfo.selfAttr or {}) do
edf2ee12   zhouhaihai   防作弊
172
173
174
175
176
177
  			result.clientSelf[tostring(k)] = v
  		end
  		for k , v in pairs(selfTeamServer) do
  			result.serverSelf[tostring(k)] = v
  		end
  		result = json.encode(result)
f82b9dc2   zhouhaihai   删除自动封号
178
179
180
181
182
183
184
185
  		self:mylog("cheat", {desc = battleType, int1 = 1, text1 = result})
  
  		-- for _, v in ipairs(globalCsv.cheat_check) do
  		-- 	if cheatCount == v[1] then
  		-- 		self:setBan(v[2] / 86400, 5)
  		-- 		break
  		-- 	end
  		-- end
edf2ee12   zhouhaihai   防作弊
186
  	end
6a59245c   zhouhaihai   结算正常
187
  	return true
edf2ee12   zhouhaihai   防作弊
188
  end
d4e9b817   zhouhaihai   战斗 日志
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
  
  function Role:checkBattle(battleType, params)
  	local clientInfo = params.info or {}
  
  	if not BattleType[battleType] then
  		print(string.format("NO find battleType: %s", battleType))
  		return
  	end
  
  	local selflist = {}
  	local heroscore = 0
  	local teamskill = {}
  	local enemylist = {}
  
  	local fixData = {
  		hang = function()
c8235ab8   zhouhaihai   battle Bug
205
  			for slot, hero in pairs(self:getProperty("hangTS").heros) do
d4e9b817   zhouhaihai   战斗 日志
206
207
208
209
210
211
212
213
214
215
216
217
218
  				selflist[slot] = hero.type
  			end
  			heroscore = self:getProperty("hangTBV")
  			for slot , one in pairs(self:getProperty("hangTB").supports) do
  				teamskill[one[1]] = one[2]
  			end
  			local carbonData = csvdb["idle_battleCsv"][params.id]
  			local monsterData = csvdb[carbonData.monster:match("/([^/]*)$") .. "Csv"]
  			for slot, one in pairs(monsterData[1]) do
  				enemylist[#enemylist + 1] = one["unitType"]
  			end
  		end,
  		tower = function()
761b3ea8   chenyueqi   再改一波电波塔整容相关信息
219
  			local towerF = self:getTowerTeamFormat(params.tower)
821e2704   zhouhaihai   heros 增加 supports
220
  			for slot, hero in pairs(self:getTeamHerosInfo(towerF).heros) do
d4e9b817   zhouhaihai   战斗 日志
221
222
223
224
225
226
227
228
229
230
231
232
233
  				selflist[slot] = hero.type
  			end
  			heroscore = self:getTeamBattleValue(towerF.heros)
  			for slot , one in pairs(self:getTeamBattleInfo(towerF).supports) do
  				teamskill[one[1]] = one[2]
  			end
  			local carbonData = csvdb["tower_battleCsv"][params.id]
  			local monsterData = csvdb[carbonData.monster:match("/([^/]*)$") .. "Csv"]
  			for slot, one in pairs(monsterData[1]) do
  				enemylist[#enemylist + 1] = one["unitType"]
  			end
  		end,
  		bonus = function()
98d32f92   liuzujun   多编队
234
  			local bTeam = self:getTeamFormatByType(TeamSystemType.BonusBattle)
821e2704   zhouhaihai   heros 增加 supports
235
  			for slot, hero in pairs(self:getTeamHerosInfo(bTeam).heros) do
d4e9b817   zhouhaihai   战斗 日志
236
237
238
239
240
241
  				selflist[slot] = hero.type
  			end
  			heroscore = self:getTeamBattleValue(bTeam.heros)
  			for slot , one in pairs(self:getTeamBattleInfo(bTeam).supports) do
  				teamskill[one[1]] = one[2]
  			end
b8c1be12   zhouhaihai   一些 bug
242
  			local carbonData = csvdb["bonus_battleCsv"][params.id]
d4e9b817   zhouhaihai   战斗 日志
243
244
245
246
247
  			local monsterData = csvdb[carbonData.monster:match("/([^/]*)$") .. "Csv"]
  			for slot, one in pairs(monsterData[1]) do
  				enemylist[#enemylist + 1] = one["unitType"]
  			end
  		end,
66fe093a   liuzujun   元旦关卡活动
248
  		act_battle = function()
821e2704   zhouhaihai   heros 增加 supports
249
  			for slot, hero in pairs(self:getTeamHerosInfo(params).heros) do
66fe093a   liuzujun   元旦关卡活动
250
251
252
253
254
255
256
257
258
259
260
261
  				selflist[slot] = hero.type
  			end
  			heroscore = self:getTeamBattleValue(params.heros)
  			for slot , one in pairs(params.supports) do
  				teamskill[one[1]] = one[2]
  			end
  			local carbonData = params.cfg
  			local monsterData = csvdb[carbonData.monster:match("/([^/]*)$") .. "Csv"]
  			for slot, one in pairs(monsterData[1]) do
  				enemylist[#enemylist + 1] = one["unitType"]
  			end
  		end,
d4e9b817   zhouhaihai   战斗 日志
262
  		pvpc = function()
55c7c172   zhouhaihai   奖励副本 新机制
263
  			for slot, hero in pairs(self:getProperty("pvpTSC").heros) do
d4e9b817   zhouhaihai   战斗 日志
264
265
266
267
268
269
270
271
272
  				selflist[slot] = hero.type
  			end
  			heroscore = self:getProperty("pvpTBVC")
  			for slot , one in pairs(self:getProperty("pvpTBC").supports) do
  				teamskill[one[1]] = one[2]
  			end
  			if params.robotId then
  				local carbonData = csvdb["pvp_robotCsv"][params.robotId]
  				local monsterData = csvdb[carbonData.monster:match("/([^/]*)$") .. "Csv"]
b8c1be12   zhouhaihai   一些 bug
273
  				for slot, one in pairs(monsterData) do
d4e9b817   zhouhaihai   战斗 日志
274
275
276
277
278
279
280
281
282
283
284
  					enemylist[#enemylist + 1] = one["unitType"]
  				end
  			else
  				for slot, one in pairs((params.enemy or {})["heros"] or {}) do
  					enemylist[slot] = one["type"]
  				end
  			end
  		end,
  		pvph = function()
  			for idx, team in pairs(self:getProperty("pvpTSH")) do
  				selflist[idx] = selflist[idx] or {}
55c7c172   zhouhaihai   奖励副本 新机制
285
  				for slot, hero in pairs(team.heros) do
d4e9b817   zhouhaihai   战斗 日志
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
  					selflist[idx][slot] = hero.type
  				end
  			end
  			for _, one in pairs(self:getProperty("pvpTBVH")) do
  				heroscore = heroscore + one
  			end
  			for idx, team in pairs(self:getProperty("pvpTBH")) do
  				for slot , one in pairs(team.supports) do
  					teamskill[one[1]] = one[2]
  				end
  			end
  
  			if params.robotId then
  				local carbonData = csvdb["pvp_robot_groupCsv"][params.robotId]
  				for idx = 1, 3 do
  					enemylist[idx] = enemylist[idx] or {}
  					local monsterData = csvdb[carbonData["monster" .. idx]:match("/([^/]*)$") .. "Csv"]
b8c1be12   zhouhaihai   一些 bug
303
  					for slot, one in pairs(monsterData) do
d4e9b817   zhouhaihai   战斗 日志
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
  						enemylist[idx][#enemylist + 1] = one["unitType"]
  					end
  				end
  			else
  				for idx, team in pairs(params.enemy or {}) do
  					enemylist[idx] = enemylist[idx] or {}
  					for slot, one in pairs(team["heros"] or {}) do
  						enemylist[idx][slot] = one["type"]
  					end
  				end
  			end
  		end
  	}
  
  	if fixData[battleType] then
  		fixData[battleType]()
  	end
  
  	-- robotId = match.t == 2 and match.id or nil,
  	-- enemy = match.t == 1 and (revenge and _pvpRecordBattleInfoCacheH[match.id] or _pvpBattleInfoCacheH[match.id]) or nil,
  	-- score = myScore,
  	-- reward = reward,
  	self:log("mission", {
  		mission_threadid = battleType == "hang" and math.floor((params.id % 100) / 100) or 0, -- 大关卡ID
  		mission_id = params.id or 0, -- 关卡ID
  		mission_type = BattleType[battleType], -- 关卡类型,见关卡类型枚举表
  		mission_herolist = selflist, -- 英雄ID,排序以玩家出战设置为准,PVP多个队伍则记录多个列表。示例:[[1,2,3],[456]]
  		mission_heroscore = heroscore, -- 编队总评分
  		mission_enemylist = enemylist, -- 地方英雄ID,排序以玩家出战设置为准,PVP多个队伍则记录多个列表。示例:[[1,2,3],[456]]
  		mission_damage = clientInfo.damage or {}, -- 英雄输出值。示例:{'heroid1':1000,'heroid2':2000,………..}
  		mission_ultskill = clientInfo.ultskill or {}, -- 大招使用情况。示例:{'heroid1':1000,'heroid2':2000,………..}
  		mission_reward = params.reward or {}, -- 获得奖励,建议使用json格式记录。示例:{ "XX": "1", "XXX": "3"}
  		mission_starttime = clientInfo.start or 0, -- 战斗开始时间,格式 unixtime 秒级
  		mission_roundtime = clientInfo.atime or 0, -- 对局时长(秒)
  		mission_result = params.isWin and 1 or 2, -- 战斗结果(0-无效,1-胜利,2-失败)
66fe093a   liuzujun   元旦关卡活动
339
  		mission_star = params.star or 0, -- 战斗完成星数,无星级的话填写0
d4e9b817   zhouhaihai   战斗 日志
340
341
342
343
344
345
346
347
348
349
350
  		mission_restriction = 0, -- 周期内参与限制(0表示没有上限)
  		mission_difficulty = 0, -- 关卡困难度,无难度区分的话填写0
  		mission_strength = 1, -- 消耗的体力或次数
  		mission_score = params.score or 0, -- 本局分数,PVP玩法记录为对战后积分,无得分的填0
  		mission_cleartype = 1, -- 1正常通关;2代理拾荒
  		mission_rank = params.rank, -- 对战后排名,适用于PVP玩法和电波塔,其他玩法留空
  		misson_monsterkill = clientInfo.kill or {}, -- 击杀怪物ID和数量,建议使用json格式记录。示例:{ "XX": "1", "XXX": "3"}
  		misson_teamskill = teamskill, -- 编队支援技能和技能等级情况,json格式记录,{"teamskill1":1,"teamskill2":2,………..}
  	})
  end
  
e572e903   zhangqijia   fix: 拾荒生存力和属性调整
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
  	local function initPlayer(player)
  		player["hp"] = player["hp"] or 0
  		player["atk"] = player["atk"] or 0
  		player["def"] = player["def"] or 0
  		player["hit"] = player["hit"] or 0
  		player["miss"] = player["miss"] or 0
  		player["crit"] = player["crit"] or 0
  		player["critHurt"] = player["critHurt"] or 0
  		player["pierce"] = player["pierce"] or 0
  		player["vampire"] = player["vampire"] or 0
  	end
  
  	function Role:checkPlayerAttr(player)
  		if next(player) == nil then return end
  		initPlayer(player)
d4e9b817   zhouhaihai   战斗 日志
366
  
e572e903   zhangqijia   fix: 拾荒生存力和属性调整
367
368
369
370
371
372
  		player["hp"] = math.floor(player["hp"]  / globalCsv.adv_battle_attr_ratio["hp"])
  		player["atk"] = math.floor(player["atk"] / globalCsv.adv_battle_attr_ratio["atk"])
  		player["def"] = math.floor(player["def"]  / globalCsv.adv_battle_attr_ratio["def"])
  		player["hit"] = math.floor((player["hit"]  + player["miss"] )/ globalCsv.adv_battle_attr_ratio["hit"])
  		player["miss"] = math.floor((player["crit"] + player["critHurt"] + player["pierce"]  + player["vampire"])/ globalCsv.adv_battle_attr_ratio["miss"])
  	end
d4e9b817   zhouhaihai   战斗 日志
373
  
e572e903   zhangqijia   fix: 拾荒生存力和属性调整
374
375
376
377
  	function Role:getSurvivability(player, heroCount)
  		if next(player) == nil then return 0 end
  		heroCount = heroCount or 1
  		initPlayer(player)
d4e9b817   zhouhaihai   战斗 日志
378
  
e572e903   zhangqijia   fix: 拾荒生存力和属性调整
379
380
381
382
383
384
385
  		local battleV = (globalCsv.adv_battle_fight_points["hp"] * player["hp"]
  				+ globalCsv.adv_battle_fight_points["atk"] * player["atk"]
  				+ globalCsv.adv_battle_fight_points["def"] * player["def"]
  				+ globalCsv.adv_battle_fight_points["hit"] * player["hit"] )
  				* (1 + (player["miss"]- heroCount * globalCsv.adv_battle_fight_points["miss"])/ 100)
  		return battleV
  	end
d4e9b817   zhouhaihai   战斗 日志
386
  
4cf5dec9   zhouhaihai   battle bug
387
388
389
390
  end
  
  
  return RoleBattle