RoleBattle.lua 11.4 KB
local RoleBattle = {}

--[[
	100	剧情关卡类	
	200	非剧情类普通关卡	
	300	每日任务类、日常本类	
	400	资源获取类关卡	
	500	PVP关卡	
	1000	活动期间限定类关卡	
	2000	其他	
]]

local BattleType = {
	hang = 100,
	tower = 200,
	bonus = 300,
	pvpc = 500,
	pvph = 501,
	act_battle = 502,
}

RoleBattle.bind = function (Role)

local checkCheatAttrs = {
	["hp"] = 1,
	["atk"] = 1,
	["def"] = 1,
	["hit"] = 1,
	["miss"] = 1,
	["crit"] = 1,
	["atkSpeed"] = 1,
	["critHurt"] = 1,
	-- ["vampire"] = 1,
	-- ["pierce"] = 1,
}

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
end

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

--  检查战斗是否作弊 
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
			selfTeamServer[hero.type] = temp
		end
		-- local carbonData = csvdb["idle_battleCsv"][params.id]
		-- enemyServer = packBattleEnemyCommon(carbonData)
	end
	cheat["tower"] = function()
		local team = self:getTeamBattleInfo(self:getTeamFormatByType(TeamSystemType.Tower))
		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
		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
		end
		-- local carbonData = csvdb["bonus_battleCsv"][params.id]
		-- enemyServer = packBattleEnemyCommon(carbonData)
	end
	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
		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
		-- local cheatCount = self:getProperty("cheatCount")
		-- cheatCount = cheatCount + 1
		-- self:setProperty("cheatCount", cheatCount)

		local result = {clientSelf = {}, serverSelf = {}}
		for k , v in pairs(clientInfo.selfAttr) do
			result.clientSelf[tostring(k)] = v
		end
		for k , v in pairs(selfTeamServer) do
			result.serverSelf[tostring(k)] = v
		end
		result = json.encode(result)
		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
	end
	return true
end

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()
			for slot, hero in pairs(self:getProperty("hangTS").heros) do
				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()
			local towerF = self:getTeamFormatByType(TeamSystemType.Tower)
			for slot, hero in pairs(self:getTeamHerosInfo(towerF).heros) do
				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()
			local bTeam = self:getTeamFormatByType(TeamSystemType.BonusBattle)
			for slot, hero in pairs(self:getTeamHerosInfo(bTeam).heros) do
				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
			local carbonData = csvdb["bonus_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,
		act_battle = function()
			for slot, hero in pairs(self:getTeamHerosInfo(params).heros) do
				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,
		pvpc = function()
			for slot, hero in pairs(self:getProperty("pvpTSC").heros) do
				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"]
				for slot, one in pairs(monsterData) do
					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 {}
				for slot, hero in pairs(team.heros) do
					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"]
					for slot, one in pairs(monsterData) do
						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-失败)
		mission_star = params.star or 0, -- 战斗完成星数,无星级的话填写0
		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





end


return RoleBattle