【战斗】log打印添加结果数据

dev_chengFeng
gaoxin 2021-01-22 17:45:01 +08:00
parent 745646b06e
commit cd40920949
2 changed files with 37 additions and 2 deletions

View File

@ -87,9 +87,10 @@ function this.PrintBattleTable(tb)
end end
-- --
this.logList = {} this.logList = {}
function this.Init(fightdata, userdata) function this.Init(fightdata, userdata, maxRound)
this.timestamp = Random.GetSeed() this.timestamp = Random.GetSeed()
this.fightdata = fightdata this.fightdata = fightdata
this.maxRound = maxRound
if userdata then if userdata then
this.userId = userdata.uid this.userId = userdata.uid
end end
@ -154,6 +155,8 @@ function this.WriteFightDataToFile()
file:write(this.PrintBattleTable(this.fightdata)) file:write(this.PrintBattleTable(this.fightdata))
file:write("\n\n") file:write("\n\n")
file:write("timeStamp: " .. this.timestamp) file:write("timeStamp: " .. this.timestamp)
file:write("\n")
file:write("maxRound: " .. this.maxRound)
file:write("\n\n\n\n\n") file:write("\n\n\n\n\n")
io.close(file) io.close(file)
end end

View File

@ -66,7 +66,7 @@ function BattleLogic.Init(data, _userData, maxRound)
BattleLogic.IsEnd = false BattleLogic.IsEnd = false
BattleLogic.Result = -1 BattleLogic.Result = -1
-- 日志管理放到前面初始化 -- 日志管理放到前面初始化
BattleLogManager.Init(fightData, userData) BattleLogManager.Init(fightData, userData, maxRound)
MonsterManager.Init() MonsterManager.Init()
RoleManager.Init() RoleManager.Init()
@ -436,11 +436,43 @@ function BattleLogic.BattleEnd(result)
BattleLogic.IsEnd = true BattleLogic.IsEnd = true
BattleLogic.Result = result BattleLogic.Result = result
BattleLogic.Event:DispatchEvent(BattleEventName.BattleEnd, result) BattleLogic.Event:DispatchEvent(BattleEventName.BattleEnd, result)
-- 打印结果
BattleLogic.LogResult(result)
-- 战斗日志写入 -- 战斗日志写入
if not BattleLogic.GetIsDebug() then if not BattleLogic.GetIsDebug() then
BattleLogManager.WriteLogToFile() BattleLogManager.WriteLogToFile()
end end
end end
-- 打印战斗结果
function BattleLogic.LogResult(result)
local allHeroDamage, allEnemyDamage = BattleLogic.GetAllDamage()
local heroHP = {0, 0, 0, 0, 0, 0}
local arr = RoleManager.Query(function (r) return r.camp == 0 end, true)
for i=1, #arr do
local pos = arr[i].position
heroHP[pos] = arr[i]:GetRoleData(RoleDataName.Hp)
end
local enemyHP = {0, 0, 0, 0, 0, 0}
local arr = RoleManager.Query(function (r) return r.camp == 1 end, true)
for i=1, #arr do
local pos = arr[i].position
enemyHP[pos] = arr[i]:GetRoleData(RoleDataName.Hp)
end
BattleLogManager.Log(
"Battle Over!!!!!!!",
"result", result,
"allHeroDamage", allHeroDamage,
"allEnemyDamage", allEnemyDamage,
"duration", BattleLogic.CurFrame() / BattleLogic.GameFrameRate,
"heroHP", BattleLogManager.PrintBattleTable(heroHP),
"enemyHP", BattleLogManager.PrintBattleTable(enemyHP)
)
end
-- --
function BattleLogic.Clear() function BattleLogic.Clear()
-- 清空角色 -- 清空角色