661 lines
17 KiB
Lua
661 lines
17 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 function error( err )
|
||
print("error....")
|
||
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/LogError/"..time..".txt", "a")
|
||
file:write(debug.traceback(err))
|
||
io.close(file)
|
||
end
|
||
|
||
--测试战斗数据
|
||
local test_fight_data= {
|
||
playerData =
|
||
{
|
||
[1] =
|
||
{
|
||
professionId = 5,
|
||
passivity =
|
||
{
|
||
},
|
||
type = 1,
|
||
skill =
|
||
{
|
||
[1] = 0,
|
||
[2] =
|
||
{
|
||
[1] = 40001,
|
||
[2] = 0.7,
|
||
[3] =
|
||
{
|
||
[1] = 11,
|
||
[2] = 0.93,
|
||
[3] = 2,
|
||
[4] = 2,
|
||
[5] = 0.2,
|
||
},
|
||
},
|
||
},
|
||
superSkill =
|
||
{
|
||
[1] = 3,
|
||
[2] =
|
||
{
|
||
[1] = 20000,
|
||
[2] = 0.7,
|
||
[3] =
|
||
{
|
||
[1] = 2,
|
||
[2] = 1.06,
|
||
[3] = 2,
|
||
},
|
||
[4] =
|
||
{
|
||
[1] = 3,
|
||
[2] = 0.6,
|
||
[3] = 1,
|
||
[4] = 4,
|
||
},
|
||
},
|
||
},
|
||
roleId = 10008,
|
||
camp = 0,
|
||
property =
|
||
{
|
||
[1] = 1,
|
||
[2] = 2206,
|
||
[3] = 2206,
|
||
[4] = 217,
|
||
[5] = 193,
|
||
[6] = 232,
|
||
[7] = 130,
|
||
[8] = 0,
|
||
[9] = 0,
|
||
[10] = 0,
|
||
[11] = 0,
|
||
[12] = 0,
|
||
[13] = 0,
|
||
[14] = 0,
|
||
[15] = 0,
|
||
[16] = 0,
|
||
[17] = 0,
|
||
[18] = 0,
|
||
[19] = 0,
|
||
[20] = 0,
|
||
[21] = 0,
|
||
[22] = 0,
|
||
[23] = 0,
|
||
[24] = 0,
|
||
[25] = 0,
|
||
[26] = 0,
|
||
},
|
||
quality = 1,
|
||
},
|
||
[2] =
|
||
{
|
||
professionId = 1,
|
||
passivity =
|
||
{
|
||
},
|
||
type = 1,
|
||
skill =
|
||
{
|
||
[1] = 0,
|
||
[2] =
|
||
{
|
||
[1] = 40001,
|
||
[2] = 0.7,
|
||
[3] =
|
||
{
|
||
[1] = 1,
|
||
[2] = 1,
|
||
[3] = 1,
|
||
},
|
||
},
|
||
[3] =
|
||
{
|
||
[1] = 30011,
|
||
[2] = 0.7,
|
||
[3] =
|
||
{
|
||
[1] = 4,
|
||
[2] = 9,
|
||
[3] = 0.1,
|
||
[4] = 5,
|
||
[5] = 1,
|
||
},
|
||
[4] =
|
||
{
|
||
[1] = 4,
|
||
[2] = 10,
|
||
[3] = 0.1,
|
||
[4] = 5,
|
||
[5] = 1,
|
||
},
|
||
},
|
||
},
|
||
superSkill =
|
||
{
|
||
[1] = 2.3,
|
||
[2] =
|
||
{
|
||
[1] = 20312,
|
||
[2] = 0.7,
|
||
[3] =
|
||
{
|
||
[1] = 19,
|
||
[2] = 1.35,
|
||
[3] = 1,
|
||
[4] = 0.5,
|
||
[5] = 5,
|
||
},
|
||
},
|
||
},
|
||
roleId = 10013,
|
||
camp = 0,
|
||
property =
|
||
{
|
||
[1] = 1,
|
||
[2] = 1678,
|
||
[3] = 1678,
|
||
[4] = 242,
|
||
[5] = 194,
|
||
[6] = 162,
|
||
[7] = 163,
|
||
[8] = 0,
|
||
[9] = 0,
|
||
[10] = 0,
|
||
[11] = 0,
|
||
[12] = 0,
|
||
[13] = 0,
|
||
[14] = 0,
|
||
[15] = 0,
|
||
[16] = 0,
|
||
[17] = 0,
|
||
[18] = 0,
|
||
[19] = 0,
|
||
[20] = 0,
|
||
[21] = 0,
|
||
[22] = 0,
|
||
[23] = 0,
|
||
[24] = 0,
|
||
[25] = 0,
|
||
[26] = 0,
|
||
},
|
||
quality = 1,
|
||
},
|
||
[3] =
|
||
{
|
||
professionId = 4,
|
||
passivity =
|
||
{
|
||
},
|
||
type = 1,
|
||
skill =
|
||
{
|
||
[1] = 0,
|
||
[2] =
|
||
{
|
||
[1] = 40001,
|
||
[2] = 0.7,
|
||
[3] =
|
||
{
|
||
[1] = 1,
|
||
[2] = 1.35,
|
||
[3] = 2,
|
||
},
|
||
},
|
||
[3] =
|
||
{
|
||
[1] = 30011,
|
||
[2] = 0.7,
|
||
[3] =
|
||
{
|
||
[1] = 3,
|
||
[2] = 0,
|
||
[3] = 0,
|
||
[4] = 5,
|
||
},
|
||
},
|
||
},
|
||
superSkill =
|
||
{
|
||
[1] = 2.5,
|
||
[2] =
|
||
{
|
||
[1] = 20000,
|
||
[2] = 0.7,
|
||
[3] =
|
||
{
|
||
[1] = 14,
|
||
[2] = 1.55,
|
||
[3] = 2,
|
||
[4] = 1,
|
||
[5] = 10023,
|
||
[6] = 0.2,
|
||
},
|
||
},
|
||
},
|
||
roleId = 10023,
|
||
camp = 0,
|
||
property =
|
||
{
|
||
[1] = 1,
|
||
[2] = 1439,
|
||
[3] = 1439,
|
||
[4] = 280,
|
||
[5] = 131,
|
||
[6] = 157,
|
||
[7] = 168,
|
||
[8] = 0,
|
||
[9] = 0,
|
||
[10] = 0,
|
||
[11] = 0,
|
||
[12] = 0,
|
||
[13] = 0,
|
||
[14] = 0,
|
||
[15] = 0,
|
||
[16] = 0,
|
||
[17] = 0,
|
||
[18] = 0,
|
||
[19] = 0,
|
||
[20] = 0,
|
||
[21] = 0,
|
||
[22] = 0,
|
||
[23] = 0,
|
||
[24] = 0,
|
||
[25] = 0,
|
||
[26] = 0,
|
||
},
|
||
quality = 1,
|
||
},
|
||
teamSkill =
|
||
{
|
||
},
|
||
},
|
||
enemyData =
|
||
{
|
||
[1] =
|
||
{
|
||
[1] =
|
||
{
|
||
professionId = 0,
|
||
passivity =
|
||
{
|
||
},
|
||
type = 2,
|
||
skill =
|
||
{
|
||
[1] = 0,
|
||
[2] =
|
||
{
|
||
[1] = 20011,
|
||
[2] = 0.7,
|
||
[3] =
|
||
{
|
||
[1] = 1,
|
||
[2] = 1,
|
||
[3] = 1,
|
||
},
|
||
[4] =
|
||
{
|
||
[1] = 3,
|
||
[2] = 0.3,
|
||
[3] = 1,
|
||
[4] = 3,
|
||
},
|
||
},
|
||
},
|
||
superSkill =
|
||
{
|
||
},
|
||
roleId = 14,
|
||
camp = 1,
|
||
property =
|
||
{
|
||
[1] = 0,
|
||
[2] = 772,
|
||
[3] = 772,
|
||
[4] = 260,
|
||
[5] = 61,
|
||
[6] = 61,
|
||
[7] = 80,
|
||
[8] = 0,
|
||
[9] = 0,
|
||
[10] = 0.3,
|
||
[11] = 0.3,
|
||
[12] = 0.2,
|
||
[13] = 1.5,
|
||
[14] = 1,
|
||
[15] = 0,
|
||
[16] = 0,
|
||
[17] = 0,
|
||
[18] = 0,
|
||
[19] = 0,
|
||
[20] = 0,
|
||
[21] = 0,
|
||
[22] = 0,
|
||
[23] = 0,
|
||
[24] = 0,
|
||
[25] = 2,
|
||
[26] = 2,
|
||
},
|
||
quality = 1,
|
||
},
|
||
[2] =
|
||
{
|
||
professionId = 0,
|
||
passivity =
|
||
{
|
||
},
|
||
type = 2,
|
||
skill =
|
||
{
|
||
[1] = 0,
|
||
[2] =
|
||
{
|
||
[1] = 20013,
|
||
[2] = 0.7,
|
||
[3] =
|
||
{
|
||
[1] = 1,
|
||
[2] = 0.45,
|
||
[3] = 1,
|
||
},
|
||
},
|
||
},
|
||
superSkill =
|
||
{
|
||
},
|
||
roleId = 1,
|
||
camp = 1,
|
||
property =
|
||
{
|
||
[1] = 0,
|
||
[2] = 483,
|
||
[3] = 483,
|
||
[4] = 260,
|
||
[5] = 61,
|
||
[6] = 61,
|
||
[7] = 240,
|
||
[8] = 0,
|
||
[9] = 0,
|
||
[10] = 0.3,
|
||
[11] = 0.3,
|
||
[12] = 0.2,
|
||
[13] = 1.5,
|
||
[14] = 1,
|
||
[15] = 0,
|
||
[16] = 0,
|
||
[17] = 0,
|
||
[18] = 0,
|
||
[19] = 0,
|
||
[20] = 0,
|
||
[21] = 0,
|
||
[22] = 0,
|
||
[23] = 0,
|
||
[24] = 0,
|
||
[25] = 0,
|
||
[26] = 0,
|
||
},
|
||
quality = 1,
|
||
},
|
||
[3] =
|
||
{
|
||
professionId = 0,
|
||
passivity =
|
||
{
|
||
},
|
||
type = 2,
|
||
skill =
|
||
{
|
||
[1] = 0,
|
||
[2] =
|
||
{
|
||
[1] = 20013,
|
||
[2] = 0.7,
|
||
[3] =
|
||
{
|
||
[1] = 1,
|
||
[2] = 0.45,
|
||
[3] = 1,
|
||
},
|
||
},
|
||
},
|
||
superSkill =
|
||
{
|
||
},
|
||
roleId = 3,
|
||
camp = 1,
|
||
property =
|
||
{
|
||
[1] = 0,
|
||
[2] = 483,
|
||
[3] = 483,
|
||
[4] = 260,
|
||
[5] = 61,
|
||
[6] = 61,
|
||
[7] = 7,
|
||
[8] = 0,
|
||
[9] = 0,
|
||
[10] = 0.3,
|
||
[11] = 0.3,
|
||
[12] = 0.2,
|
||
[13] = 1.5,
|
||
[14] = 1,
|
||
[15] = 0,
|
||
[16] = 0,
|
||
[17] = 0,
|
||
[18] = 0,
|
||
[19] = 0,
|
||
[20] = 0,
|
||
[21] = 0,
|
||
[22] = 0,
|
||
[23] = 0,
|
||
[24] = 0,
|
||
[25] = 0,
|
||
[26] = 0,
|
||
},
|
||
quality = 1,
|
||
},
|
||
teamSkill =
|
||
{
|
||
},
|
||
},
|
||
},
|
||
}
|
||
local optionData = {
|
||
{14,1,0}, --{第几帧,操作类型,操作参数}
|
||
{132,2,3},
|
||
{152,2,5},
|
||
{178,3,2},
|
||
{219,2,4},
|
||
{260,3,1},
|
||
{287,2,2},
|
||
{312,3,5},
|
||
{467,1,1},
|
||
}
|
||
|
||
local BattleMain = {}
|
||
local BattleLogic = BattleLogic
|
||
local Random = Random
|
||
|
||
function PrintItem(v)
|
||
if type(v) == "table" then
|
||
return ""
|
||
end
|
||
return tostring(v)..","
|
||
end
|
||
function PrintKey(v)
|
||
if type(v) == "number" then
|
||
return string.format("[%d]",v)
|
||
end
|
||
return tostring(v)
|
||
end
|
||
function PrintTable( tbl , level, filteDefault)
|
||
filteDefault = filteDefault or true --默认过滤关键字(DeleteMe, _class_type)
|
||
level = level or 1
|
||
local indent_str = ""
|
||
for i = 1, level do
|
||
indent_str = indent_str.."\t"
|
||
end
|
||
|
||
print(indent_str .. "{")
|
||
for k,v in pairs(tbl) do
|
||
if filteDefault then
|
||
if k ~= "_class_type" and k ~= "DeleteMe" then
|
||
local item_str = string.format("%s%s = %s", indent_str ,PrintKey(k), PrintItem(v))
|
||
print(item_str)
|
||
if type(v) == "table" then
|
||
PrintTable(v, level + 1)
|
||
end
|
||
end
|
||
else
|
||
local item_str = string.format("%s%s = %s", indent_str ,PrintKey(k), PrintItem(v))
|
||
print(item_str)
|
||
if type(v) == "table" then
|
||
PrintTable(v, level + 1)
|
||
end
|
||
end
|
||
end
|
||
print(indent_str .. "},")
|
||
end
|
||
|
||
|
||
|
||
|
||
function BattleMain.Execute(seed, fightData, optionData)
|
||
--该开关用于输出战斗过程中的日志,用于验证前后端是否出现战斗不同步
|
||
BattleLogic.IsOpenBattleRecord = false
|
||
|
||
--PrintTable(fightData)
|
||
|
||
Random.SetSeed(seed)
|
||
BattleLogic.Init(fightData, optionData)
|
||
BattleLogic.StartOrder()
|
||
|
||
while not BattleLogic.IsEnd do
|
||
BattleLogic.Update()
|
||
end
|
||
|
||
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
|
||
|
||
--if xpcall(function ()
|
||
-- 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
|
||
-- --[[ --TODO:需要导入cjson库
|
||
-- --local json = require("cjson")
|
||
-- --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("BattleRecord/"..time..".txt", "a")
|
||
-- --file:write(json.encode(test_fight_data))
|
||
-- --io.close(file)
|
||
-- ]]
|
||
--end
|
||
--return { result = -1 }
|
||
end
|
||
|
||
--local starttime = os.clock()
|
||
--
|
||
--for i=1, 100 do
|
||
-- BattleMain.Execute(932590676, test_fight_data, optionData)
|
||
--end
|
||
--
|
||
--print("cost time : %.4f", os.clock() - starttime)
|
||
|
||
return BattleMain
|
||
--> hp:2084
|
||
--> hp:9934
|
||
--> hp:9781
|
||
--> hp:9868
|
||
--> hp:9752
|
||
--> 最终运行帧数:2735
|
||
--> result:1 (1胜,0负,-1战斗异常) |