103 lines
3.3 KiB
Lua
103 lines
3.3 KiB
Lua
package.path = package.path ..';luafight/?.lua';
|
|
|
|
require("Modules.Battle.Logic.Misc.BattleDefine")
|
|
require("Modules.Battle.Logic.Misc.BattleUtil")
|
|
require("Modules.Battle.Logic.Misc.BattleQueue")
|
|
require("Modules.Battle.Logic.Misc.BattleDictionary")
|
|
require("Modules.Battle.Logic.Misc.BattleList")
|
|
require("Modules.Battle.Logic.Misc.BattleObjectPool")
|
|
|
|
require("Modules.Battle.Logic.Base.BattleEvent")
|
|
require("Modules.Battle.Logic.Base.Random")
|
|
|
|
require("Modules.Battle.Logic.BattleLogic")
|
|
require("Modules.Battle.Logic.RoleLogic")
|
|
|
|
require("Modules.Battle.Logic.Base.RoleData")
|
|
require("Modules.Battle.Logic.Base.Buff")
|
|
require("Modules.Battle.Logic.Base.Skill")
|
|
require("Modules.Battle.Logic.Base.Passivity")
|
|
|
|
local BattleMain = {}
|
|
local BattleLogic = BattleLogic
|
|
local Random = Random
|
|
|
|
local _fightData
|
|
local _optionData
|
|
|
|
function PrintTable(tb)
|
|
local indent_str = "{"
|
|
for k,v in pairs(tb) do
|
|
indent_str = string.format("%s%s=%s", indent_str,
|
|
type(k) == "number" and string.format("[%d]",k) or tostring(k),
|
|
type(v) == "table" and "" or tostring(v)..",")
|
|
if type(v) == "table" then
|
|
indent_str = indent_str .. PrintTable(v)
|
|
end
|
|
end
|
|
indent_str = indent_str .. "},"
|
|
return indent_str
|
|
end
|
|
|
|
--捕获异常,并输出错误日志
|
|
local function error( err )
|
|
local time = string.format("%d-%d-%d-%d-%d-%d",
|
|
os.date("%Y"),
|
|
os.date("%m"),
|
|
os.date("%d"),
|
|
os.date("%H"),
|
|
os.date("%M"),
|
|
os.date("%S"))
|
|
local file = io.open("LogError/"..time..".txt", "a")
|
|
file:write("fightData:\n"..PrintTable(_fightData).."\n")
|
|
file:write("optionData:\n"..PrintTable(_optionData).."\n")
|
|
file:write("error:\n"..debug.traceback(err).."\n")
|
|
io.close(file)
|
|
end
|
|
|
|
function BattleMain.Execute(seed, fightData, optionData)
|
|
_fightData = fightData
|
|
_optionData = optionData
|
|
|
|
--该开关用于输出战斗过程中的日志,用于验证前后端是否出现战斗不同步
|
|
BattleLogic.IsOpenBattleRecord = false
|
|
|
|
if xpcall(function ()
|
|
Random.SetSeed(seed)
|
|
BattleLogic.Init(fightData, optionData)
|
|
BattleLogic.StartOrder()
|
|
|
|
while not BattleLogic.IsEnd do
|
|
BattleLogic.Update()
|
|
end
|
|
end, error) then
|
|
local resultList = {}
|
|
if BattleLogic.Result == 1 then --胜利记录我方剩余血量
|
|
local arr = BattleLogic.Query(function (r) return r.camp == 0 end, true)
|
|
for i=1, #arr do
|
|
resultList[i] = arr[i]:GetRoleData(RoleDataName.Hp)
|
|
end
|
|
elseif BattleLogic.Result == 0 then --失败记录敌方剩余血量
|
|
local arr = BattleLogic.Query(function (r) return r.camp == 1 end, true)
|
|
for i=1, #arr do
|
|
resultList[i] = arr[i]:GetRoleData(RoleDataName.Hp)
|
|
end
|
|
end
|
|
resultList.result = BattleLogic.Result
|
|
|
|
if BattleLogic.IsOpenBattleRecord then
|
|
BattleLogic.GenerateRecordFile()
|
|
end
|
|
|
|
-- print -----------------------------------------
|
|
--for i=1, #resultList do
|
|
-- print("hp:"..resultList[i])
|
|
--end
|
|
--print("最终运行帧数:"..BattleLogic.CurFrame())
|
|
--print("result:"..BattleLogic.Result)
|
|
return resultList
|
|
end
|
|
return { result = -1 }
|
|
end
|
|
|
|
return BattleMain |