miduo_server/luafight/BattleMain.lua

185 lines
9.3 KiB
Lua
Raw Normal View History

2019-03-21 15:32:29 +08:00
package.path = package.path ..';luafight/?.lua';
2019-03-12 14:05:45 +08:00
require("Modules.Battle.Logic.Misc.BattleDefine")
require("Modules.Battle.Logic.Misc.BattleUtil")
require("Modules.Battle.Logic.Misc.BattleQueue")
require("Modules.Battle.Logic.Misc.BattleDictionary")
2019-03-21 14:33:56 +08:00
require("Modules.Battle.Logic.Misc.BattleList")
require("Modules.Battle.Logic.Misc.BattleObjectPool")
2019-03-12 14:05:45 +08:00
require("Modules.Battle.Logic.Base.BattleEvent")
require("Modules.Battle.Logic.Base.Random")
2019-03-21 14:33:56 +08:00
2019-03-12 14:05:45 +08:00
require("Modules.Battle.Logic.Base.RoleData")
require("Modules.Battle.Logic.Base.Buff")
require("Modules.Battle.Logic.Base.Skill")
require("Modules.Battle.Logic.Base.Passivity")
2019-04-16 14:32:11 +08:00
require("Modules.Battle.Logic.BattleLogic")
require("Modules.Battle.Logic.RoleLogic")
2019-03-21 15:01:27 +08:00
local BattleMain = {}
local BattleLogic = BattleLogic
local Random = Random
2019-03-21 14:33:56 +08:00
2019-03-21 15:01:27 +08:00
local _fightData
local _optionData
2019-03-22 15:00:06 +08:00
local function newPairs(tbl, func)
if func == nil then
return pairs(tbl)
end
local ary = {}
local lastUsed = 0
for key --[[, val--]] in pairs(tbl) do
if (lastUsed == 0) then
ary[1] = key
else
local done = false
for j=1,lastUsed do -- 进行插入排序
if (func(key, ary[j]) == true) then
arrayInsert( ary, key, j )
done = true
break
end
end
if (done == false) then
ary[lastUsed + 1] = key
end
end
lastUsed = lastUsed + 1
end
-- 定义并返回迭代器
local i = 0
local iter = function ()
i = i + 1
if ary[i] == nil then
return nil
else
return ary[i], tbl[ary[i]]
end
end
return iter
end
local function PrintTable(tb)
2019-03-21 15:01:27 +08:00
local indent_str = "{"
2019-05-15 12:05:54 +08:00
local count = 0
for k,v in pairs(tb) do
count = count + 1
end
2019-03-22 15:00:06 +08:00
for k=1, #tb do
local v = tb[k]
2019-03-21 15:01:27 +08:00
if type(v) == "table" then
indent_str = indent_str .. PrintTable(v)
2019-03-22 15:00:06 +08:00
else
2019-05-15 12:05:54 +08:00
indent_str = indent_str .. tostring(v)
end
if k < count then
indent_str = indent_str..","
2019-03-22 15:00:06 +08:00
end
end
2019-05-15 12:05:54 +08:00
local index = 0
for k,v in pairs(tb) do
index = index + 1
2019-03-22 15:00:06 +08:00
if type(k) ~= "number" then
if type(v) == "table" then
indent_str = string.format("%s%s=%s", indent_str, tostring(k), PrintTable(v))
else
2019-05-15 12:05:54 +08:00
indent_str = string.format("%s%s=%s", indent_str, tostring(k), tostring(v))
end
if index < count then
indent_str = indent_str .. ","
2019-03-22 15:00:06 +08:00
end
2019-03-21 15:01:27 +08:00
end
end
2019-05-15 12:05:54 +08:00
indent_str = indent_str .. "}"
2019-03-21 15:01:27 +08:00
return indent_str
end
2019-03-12 14:05:45 +08:00
2019-05-15 12:05:54 +08:00
2019-03-12 14:05:45 +08:00
--捕获异常,并输出错误日志
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"))
2019-03-22 15:00:06 +08:00
local file = io.open("luafight/LogError/"..time..".txt", "a")
--file:write("fightData:\n"..PrintTable(_fightData).."\n")
--file:write("optionData:\n"..PrintTable(_optionData).."\n")
2019-03-21 15:01:27 +08:00
file:write("error:\n"..debug.traceback(err).."\n")
2019-03-12 14:05:45 +08:00
io.close(file)
end
2019-03-22 15:00:06 +08:00
local function generateRecordFile()
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("luafight/BattleRecord/"..time..".txt", "a")
local record = BattleLogic.GetRecord()
for i=1, #record do
file:write(record[i].."\n")
end
io.close(file)
end
2019-05-09 17:50:38 +08:00
function BattleMain.Execute(args, fightData, optionData)
2019-03-21 15:01:27 +08:00
_fightData = fightData
_optionData = optionData
2019-03-12 14:05:45 +08:00
2019-05-09 17:50:38 +08:00
print(PrintTable(fightData))
2019-03-21 15:01:27 +08:00
--该开关用于输出战斗过程中的日志,用于验证前后端是否出现战斗不同步
2019-03-26 11:45:28 +08:00
BattleLogic.IsOpenBattleRecord = false
2019-03-21 14:33:56 +08:00
2019-03-21 15:01:27 +08:00
if xpcall(function ()
2019-05-09 17:50:38 +08:00
Random.SetSeed(args.seed)
BattleLogic.Init(args.maxTime, fightData, optionData)
2019-03-21 15:01:27 +08:00
BattleLogic.StartOrder()
2019-03-21 14:33:56 +08:00
2019-03-21 15:01:27 +08:00
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)
2019-03-21 14:33:56 +08:00
end
2019-03-21 15:01:27 +08:00
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)
2019-03-21 14:33:56 +08:00
end
end
2019-03-21 15:01:27 +08:00
resultList.result = BattleLogic.Result
2019-03-12 14:05:45 +08:00
2019-03-21 15:01:27 +08:00
if BattleLogic.IsOpenBattleRecord then
2019-03-22 15:00:06 +08:00
generateRecordFile()
2019-03-12 14:05:45 +08:00
end
2019-03-21 15:01:27 +08:00
-- print -----------------------------------------
2019-03-22 18:36:24 +08:00
--for i=1, #resultList do
-- print("hp:"..resultList[i])
--end
--print("最终运行帧数:"..BattleLogic.CurFrame())
--print("result:"..BattleLogic.Result)
2019-03-22 15:00:06 +08:00
2019-03-21 15:01:27 +08:00
return resultList
2019-03-21 14:33:56 +08:00
end
2019-03-21 15:01:27 +08:00
return { result = -1 }
2019-03-12 14:05:45 +08:00
end
2019-03-22 18:36:24 +08:00
--BattleMain.Execute(1553167956, {playerData={{professionId=3,passivity={},type=1,skill={0,{40001,0.7,{1,2.3,2,},},{30011,0.7,{4,9,0.2,4,1,},{4,10,0.2,4,1,},},},superSkill={1.6,{20211,0.7,{1,3.3,2,},{15,1.98,2,1.98,},},},roleId=10022,camp=0,property={1,1676,1678,248,167,200,173,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=5,passivity={},type=1,skill={0,{40001,0.7,{11,0.93,2,2,0.2,},},},superSkill={3,{20000,0.7,{2,1.06,2,},{3,0.6,1,4,},},},roleId=10008,camp=0,property={1,2206,2208,221,193,232,130,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=4,passivity={},type=1,skill={0,{40001,0.7,{1,1.35,2,},},{30011,0.7,{3,0,0,5,},},},superSkill={2.5,{20000,0.7,{14,1.55,2,1,10023,0.2,},},},roleId=10023,camp=0,property={1,1439,1441,284,131,157,168,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=1,passivity={},type=1,skill={0,{40001,0.7,{1,1,1,},},{30011,0.7,{4,9,0.1,5,1,},{4,10,0.1,5,1,},},},superSkill={2.3,{20312,0.7,{19,1.35,1,0.5,5,},},},roleId=10013,camp=0,property={1,1678,1680,246,194,162,163,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=3,passivity={},type=1,skill={0,{40001,0.7,{1,2.3,2,},},{30011,0.7,{4,9,0.2,4,1,},{4,10,0.2,4,1,},},},superSkill={1.6,{20211,0.7,{1,3.3,2,},{15,1.98,2,1.98,},},},roleId=10022,camp=0,property={17,2732,2734,401,272,326,308,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},teamSkill={},},enemyData={{{professionId=0,passivity={},type=2,skill={0,{20013,0.7,{1,0.45,1,},},},superSkill={},roleId=1,camp=1,property={0,483,483,260,61,61,240,0,0,0.3,0.3,0.2,1.5,1,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=0,passivity={},type=2,skill={0,{20013,0.7,{1,0.45,1,},},},superSkill={},roleId=2,camp=1,property={0,483,483,260,61,61,80,0,0,0.3,0.3,0.2,1.5,1,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=0,passivity={},type=2,skill={0,{20013,0.7,{1,0.45,1,},},},superSkill={},roleId=3,camp=1,property={0,483,483,260,61,61,7,0,0,0.3,0.3,0.2,1.5,1,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},teamSkill={},},},})
--BattleMain.Execute(1553167956, {playerData={{professionId=4,passivity={},type=1,skill={0,{40001,0.7,{1,1.35,2,},},{30011,0.7,{3,0,0,5,},},},superSkill={2.5,{20000,0.7,{14,1.55,2,1,10023,0.2,},},},roleId=10023,camp=0,property={1,1439,1441,284,131,157,168,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=3,passivity={},type=1,skill={0,{40001,0.7,{1,2.3,2,},},{30011,0.7,{4,9,0.2,4,1,},{4,9,0.2,4,1,},},},superSkill={1.6,{20211,0.7,{1,3.3,2,},{15,1.98,2,1.98,},},},roleId=10022,camp=0,property={1,1676,1678,248,167,200,173,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=2,passivity={},type=1,skill={0,{40001,0.7,{1,1.05,2,},{4,4,5,5,3,},},},superSkill={2.3,{20000,0.7,{2,1.89,2,},},{20012,0.7,{3,1,5,5,},},},roleId=10021,camp=0,property={1,1920,1922,209,170,204,178,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=5,passivity={},type=1,skill={0,{40001,0.7,{11,0.93,2,2,0.2,},},},superSkill={3,{20000,0.7,{2,1.06,2,},{3,0.6,1,4,},},},roleId=10008,camp=0,property={1,2206,2208,221,193,232,130,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=1,passivity={},type=1,skill={0,{40001,0.7,{1,1,1,},},{30011,0.7,{4,9,0.1,5,1,},{4,9,0.1,5,1,},},},superSkill={2.3,{20312,0.7,{19,1.35,1,0.5,5,},},},roleId=10013,camp=0,property={1,1678,1680,246,194,162,163,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},teamSkill={{3,{20012,0.7,{26,600,},{27,100,4,},},{10014,0.7,{25,2,0.1,4,},},},},},enemyData={{{professionId=0,passivity={},type=2,skill={0,{20011,0.7,{1,1,1,},{3,0.3,1,3,},},},superSkill={},roleId=14,camp=1,property={0,772,772,260,61,61,80,0,0,0.3,0.3,0.2,1.5,1,0,0,0,0,0,0,0,0,0,0,2,2,},quality=1,},{professionId=0,passivity={},type=2,skill={0,{20013,0.7,{1,0.45,1,},},},superSkill={},roleId=1,camp=1,property={0,483,483,260,61,61,240,0,0,0.3,0.3,0.2,1.5,1,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=0,passivity={},type=2,skill={0,{20013,0.7,{1,0.45,1,},},},superSkill={},roleId=3,camp=1,property={0,483,483,260,61,61,7,0,0,0.3,0.3,0.2,1.5,1,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},teamSkill={},},},})
2019-03-12 17:01:40 +08:00
2019-03-21 15:01:27 +08:00
return BattleMain