战斗验证

back_recharge
mashiyu 2019-03-21 14:33:56 +08:00
parent 5ed6302f7e
commit e56acaea56
23 changed files with 1323 additions and 764 deletions

View File

@ -4,19 +4,26 @@ 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")
require("Modules.Battle.Logic.BattleLogic")
require("Modules.Battle.Logic.RoleLogic")
--捕获异常,并输出错误日志
local function error( err )
print("error....")
local time = string.format("%d-%d-%d-%d-%d-%d",
os.date("%Y"),
os.date("%m"),
@ -24,320 +31,466 @@ local function error( err )
os.date("%H"),
os.date("%M"),
os.date("%S"))
local file = io.open("LogError/"..time..".txt", "a")
local file = io.open("luafight/LogError/"..time..".txt", "a")
file:write(debug.traceback(err))
io.close(file)
end
--测试战斗数据
local test_fight_data={
playerData = {
[1] = {
--角色id
roleId = 10001,
--职业id 0 无职业 1 秘法;2 天罚 3 武卫;4 玄策 5 生花
professionId = 4,
--角色类型 1人形 2亡灵 3动物 4魔人
local test_fight_data= {
playerData =
{
[1] =
{
professionId = 5,
passivity =
{
},
type = 1,
--品质 1普通 2精英 3首领 4史诗
quality = 1,
--camp 0我方, 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,
--skill = {cd, {目标id1, 效果时间, 效果1, 效果2, ...},{目标id2, 效果时间, 效果3, 效果4, ...}, ...}
--效果 = {效果类型id, 效果参数1, 效果参数2, ...}
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
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,
},
--同skill
superSkill = { 0.5, {20011, 0.7, {1, 0.1, 1}}
},
--passivity = {被动1, 被动2, ...}
--被动 = {被动类型id1, 被动参数1, 被动参数2, ...}
passivity = {},
--属性 {等级,生命,最大生命,攻击力,护甲,魔抗,速度,伤害加成系数(%,伤害减免系数(%),命中率(%),闪避率(%),暴击率(%),暴击伤害系数(%),治疗加成系数(%)
-- ,火系伤害加成系数(%),火系伤害减免系数(%),冰系伤害加成系数(%),冰系伤害减免系数(%),雷系伤害加成系数(%),雷系伤害减免系数(%),风系伤害加成系数(%)
-- ,风系伤害减免系数(%),地系伤害加成系数(%),地系伤害减免系数(%),暗系伤害加成系数(%),暗系伤害减免系数(%)}
property = {1, 2390, 2390, 169, 271, 95, 176, 0, 0, 0.3, 0.15, 0.3, 1.5, 1, 0.05, 0, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0},
},
[2] = {
roleId = 10001,
professionId = 4,
type = 1,
quality = 1,
camp = 0, --阵营 0我方 1敌方
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
superSkill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
passivity = {
--{201011, {30, 1, 0.2, 24, 0}},
--passivity = {被动1, 被动2, ...}
--被动 = {被动id, 被动参数1, 被动参数2, ...}
},
property = {1, 10000, 10000, 169, 271, 95, 176, 0, 0, 0.3, 0.15, 0.3, 1.5, 1, 0.05, 0, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0},
},
[3] = {
roleId = 10001,
professionId = 4,
[2] =
{
professionId = 1,
passivity =
{
},
type = 1,
quality = 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,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
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,
},
superSkill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
passivity = {
--{201011, {30, 1, 0.2, 24, 0}},
},
property = {1, 10000, 10000, 169, 271, 95, 176, 0, 0, 0.3, 0.15, 0.3, 1.5, 1, 0.05, 0, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0},
},
[4] = {
roleId = 10001,
professionId = 4,
type = 1,
quality = 1,
camp = 0,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
superSkill = {
0.5, {20011, 0.7,{1, 0.1, 1}}
},
passivity = {
--{201011, {30, 1, 0.2, 24, 0}},
},
property = {1, 10000, 10000, 169, 271, 95, 176, 0, 0, 0.3, 0.15, 0.3, 1.5, 1, 0.05, 0, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0},
},
[5] = {
roleId = 10001,
[3] =
{
professionId = 4,
passivity =
{
},
type = 1,
quality = 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,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
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,
},
superSkill = {0.5, {20011, 0.7,{1, 0.1, 1}}
},
passivity = {
--{201011, {30, 1, 0.2, 24, 0}},
},
property = {1, 10000, 10000, 169, 271, 95, 176, 0, 0, 0.3, 0.15, 0.3, 1.5, 1, 0.05, 0, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0},
quality = 1,
},
teamSkill =
{
},
},
enemyData = {
[1] = {
[1] = {
roleId = 1,
professionId = 2,
type = 1,
quality = 1,
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,
skill = { 0.5, {20011, 0.7,{1, 0.1, 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,
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {1, 144, 144, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
quality = 1,
},
[2] = {
[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,
professionId = 2,
type = 1,
quality = 1,
camp = 1,
skill = { 0.5, {20011, 0.7,{1, 0.1, 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,
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {9, 144, 144, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
quality = 1,
},
[3] = {
roleId = 1,
professionId = 2,
type = 1,
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,
skill = { 0.5, {20011, 0.7,{1, 0.1, 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,
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {7, 144, 144, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
quality = 1,
},
[4] = {
roleId = 1,
professionId = 2,
type = 1,
quality = 1,
camp = 1,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {5, 144, 144, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
},
[5] = {
roleId = 1,
professionId = 2,
type = 1,
quality = 1,
camp = 1,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {3, 144, 144, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
teamSkill =
{
},
},
[2] = {
[1] = {
roleId = 1,
professionId = 2,
type = 1,
quality = 1,
camp = 1,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {1, 144, 144, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
},
[2] = {
roleId = 1,
professionId = 2,
type = 1,
quality = 1,
camp = 1,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {9, 144, 144, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
},
[3] = {
roleId = 1,
professionId = 2,
type = 1,
quality = 1,
camp = 1,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {7, 144, 144, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
},
[4] = {
roleId = 1,
professionId = 2,
type = 1,
quality = 1,
camp = 1,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {9, 144, 144, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
},
[5] = {
roleId = 1,
professionId = 2,
type = 1,
quality = 1,
camp = 1,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {7, 144, 144, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
},
},
[3] = {
[1] = {
roleId = 1,
professionId = 2,
type = 1,
quality = 1,
camp = 1,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {1, 1044, 1044, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
},
[2] = {
roleId = 1,
professionId = 2,
type = 1,
quality = 1,
camp = 1,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {9, 144, 144, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
},
[3] = {
roleId = 1,
professionId = 2,
type = 1,
quality = 1,
camp = 1,
skill = { 0.5, {20011, 0.7,{1, 0.1, 1}}
},
superSkill = {
},
passivity = {
--{206021, {1,1}},
},
property = {7, 144, 144, 285, 152, 53, 154, 0, 0, 0.7, 0.35, 0.3, 1.5, 1, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0.05, 0},
},
}
}
},
}
local optionData = {
{14,1,0}, --{第几帧,操作类型,操作参数}
@ -352,61 +505,151 @@ local optionData = {
}
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 = true
BattleLogic.IsOpenBattleRecord = false
--PrintTable(fightData)
Random.SetSeed(seed)
BattleLogic.Init(fightData, optionData)
BattleLogic.StartOrder()
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
-- 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)
]]
while not BattleLogic.IsEnd do
BattleLogic.Update()
end
return { result = -1 }
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
--BattleMain.Execute(932590676, test_fight_data, optionData)
--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

View File

@ -1,6 +1,12 @@
BattleEvent={}
BattleEvent.__index = BattleEvent
local listPool = BattleObjectPool.New(function ()
return BattleList.New()
end)
local itemPool = BattleObjectPool.New(function ()
return { func = 0, obj = 0, once = false }
end)
function BattleEvent.New()
local instance = {}
setmetatable(instance, BattleEvent)
@ -9,34 +15,39 @@ function BattleEvent.New()
end
function BattleEvent:AddEvent(sEventName, fListener, pObj, bOnce)
if self.m_listeners[sEventName] == nil then
self.m_listeners[sEventName] = {}
if not self.m_listeners[sEventName] then
self.m_listeners[sEventName] = listPool:Get()
end
table.insert(self.m_listeners[sEventName],{ func = fListener, obj = pObj, once = bOnce } )
local item = itemPool:Get()
item.func = fListener
item.obj = pObj
item.once = bOnce
self.m_listeners[sEventName]:Add(item)
end
function BattleEvent:RemoveEvent(sEventName, fListener)
if self.m_listeners[sEventName] == nil then
if not self.m_listeners[sEventName] then
return
end
local v
for i=1, #self.m_listeners[sEventName] do
v = self.m_listeners[sEventName][i]
for i=1, self.m_listeners[sEventName].size do
v = self.m_listeners[sEventName].buffer[i]
if v.func == fListener then
table.remove(self.m_listeners[sEventName], i)
itemPool:Put(v)
self.m_listeners[sEventName]:Remove(i)
break
end
end
end
function BattleEvent:DispatchEvent(sEventName,...)
if self.m_listeners[sEventName] == nil then
function BattleEvent:DispatchEvent(sEventName, ...)
if not self.m_listeners[sEventName] then
return
end
local v
for i=1, #self.m_listeners[sEventName] do
v = self.m_listeners[sEventName][i]
if nil == v.obj then
for i=1, self.m_listeners[sEventName].size do
v = self.m_listeners[sEventName].buffer[i]
if not v.obj then
v.func(...)
else
v.func(v.obj, ...)
@ -47,5 +58,12 @@ function BattleEvent:DispatchEvent(sEventName,...)
end
end
function BattleEvent:ClearEvent()
self.m_listeners={}
for k, v in pairs(self.m_listeners) do
for i=1, v.size do
itemPool:Put(v.buffer[i])
end
v:Clear()
listPool:Put(v)
self.m_listeners[k]=nil
end
end

View File

@ -1,6 +1,23 @@
Buff = {}
local floor = math.floor
local buffPoolList = {}
local getBuff = function(type)
if not buffPoolList[type] then
buffPoolList[type] = BattleObjectPool.New(function (type)
return require("Modules/Battle/Logic/Buff/"..type):New()
end)
end
return buffPoolList[type]:Get(type)
end
local putBuff = function(buff)
if buffPoolList[buff.type] then
buffPoolList[buff.type]:Put(buff)
end
end
function Buff:New()
local o = {}
setmetatable(o, self)
@ -9,37 +26,49 @@ function Buff:New()
end
function Buff.Create(caster, type, duration, ...)
local instance = require("Modules/Battle/Logic/Buff/"..type):New()
local buff = getBuff(type)
buff.type = type
buff.id = BattleLogic.GenerateBuffId()
buff.caster = caster
buff.disperse = false
buff.cover = false
instance.type = type
instance.id = BattleLogic.GenerateBuffId()
instance.caster = caster
instance.disperse = false
instance.cover = false
buff.duration = duration --持续时间为0时buff永久存在
buff.interval = -1 --间隔帧为0时每帧触发,小于0不触发 默认不触发OnTrigger
buff.maxCount = 0 --限定效果最大数量
buff.framePass = 0
instance.duration = duration --持续时间为0时buff永久存在
instance.interval = -1 --间隔帧为0时每帧触发,小于0不触发 默认不触发OnTrigger
instance.maxCount = 0 --限定效果最大数量
instance.framePass = 0
instance:SetData(...)
return instance
buff:SetData(...)
return buff
end
local queuePool = BattleObjectPool.New(function ()
return BattleQueue.New()
end)
local dicPool = BattleObjectPool.New(function ()
return BattleDictionary.New()
end)
BuffManager = {}
BuffManager.__index = BuffManager
function BuffManager.New(owner)
local instance = {}
instance.owner = owner
instance.buffQueue = BattleQueue.New()
instance.buffList = BattleDictionary.New()
function BuffManager.New()
local instance = {owner=0, buffQueue = queuePool:Get(), buffList = dicPool:Get()}
setmetatable(instance, BuffManager)
return instance
end
function BuffManager:Init(owner)
self.owner = owner
end
function BuffManager:Dispose(owner)
self.buffQueue:Clear()
self.buffList:Clear()
queuePool:Put(self.buffQueue)
dicPool:Put(self.buffList)
self.owner = owner
end
function BuffManager:AddBuff(buff)
self.buffQueue:Enqueue(buff)
if not buff.exCtrlTime then
@ -63,8 +92,8 @@ function BuffManager:HasBuff(type, checkFunc)
local v
for i=1, self.buffList:Count() do
v = self.buffList.vList[i]
if #v > 0 then
if v[1].type == type and (not checkFunc or (checkFunc and checkFunc(v[1]))) then
if v.size > 0 then
if v.buffer[1].type == type and (not checkFunc or (checkFunc and checkFunc(v.buffer[1]))) then
return true
end
end
@ -76,21 +105,20 @@ function BuffManager:ClearBuff(func)
for i = 1, self.buffList.size do
local k = self.buffList.kList[i]
local v = self.buffList.vList[i]
local count = #v
if count > 0 then
if v.size > 0 then
local removeCount = 0
local idx = 1
while idx <= count do
if func(v[idx]) then
table.remove(v, idx)
count = count - 1
while idx <= v.size do
if func(v.buffer[idx]) then
putBuff:Put(v.buffer[idx])
v:Remove(idx)
removeCount = removeCount + 1
else
idx = idx + 1
end
end
if removeCount > 0 then
self.owner.Event:DispatchEvent(BattleEventName.BuffCountChange, k, count)
self.owner.Event:DispatchEvent(BattleEventName.BuffCountChange, k, v.size)
end
end
end
@ -98,7 +126,7 @@ end
function BuffManager:GetBuffCount(id)
if self.buffList[id] then
return self.buffList[id]:Count()
return self.buffList[id].size
end
return 0
end
@ -112,17 +140,17 @@ function BuffManager:Update()
end
local buffList
if not self.buffList.kvList[buff.id] then
buffList = {}
buffList = BattleList.New()
self.buffList:Add(buff.id, buffList)
else
buffList = self.buffList.kvList[buff.id]
end
local count = #buffList
local count = buffList.size
if buff.cover and count > 0 then
if buffList[1]:OnCover(buff) then --判定该效果能否被覆盖
buffList[1]:OnEnd(self.owner)
self.owner.Event:DispatchEvent(BattleEventName.BuffEnd, buffList[1])
buffList[1] = buff
if buffList.buffer[1]:OnCover(buff) then --判定该效果能否被覆盖
buffList.buffer[1]:OnEnd(self.owner)
self.owner.Event:DispatchEvent(BattleEventName.BuffEnd, buffList.buffer[1])
buffList.buffer[1] = buff
buff.target = self.owner
buff:OnStart()
self.owner.Event:DispatchEvent(BattleEventName.BuffStart, buff)
@ -130,8 +158,7 @@ function BuffManager:Update()
end
else
if buff.maxCount == 0 or count < buff.maxCount then --限制相同效果的数量,为0则不限制
count = count + 1
buffList[count] = buff
buffList:Add(buff)
buff.target = self.owner
buff:OnStart()
self.owner.Event:DispatchEvent(BattleEventName.BuffStart, buff)
@ -142,13 +169,12 @@ function BuffManager:Update()
for i = 1, self.buffList.size do
local k = self.buffList.kList[i]
local v = self.buffList.vList[i]
local count = #v
if count > 0 then
if v.size > 0 then
local removeCount = 0
local idx = 1
local buff
while idx <= count do
buff = v[idx]
while idx <= v.size do
buff = v.buffer[idx]
--印记类型的buff不处理更新逻辑
if buff.frameDuration == 0 and buff.frameInterval < 0 then
else
@ -180,15 +206,15 @@ function BuffManager:Update()
if buff.disperse then
buff:OnEnd()
buff.target.Event:DispatchEvent(BattleEventName.BuffEnd, buff)
table.remove(v, idx)
count = count - 1
putBuff(v.buffer[idx])
v:Remove(idx)
removeCount = removeCount + 1
else
idx = idx + 1
end
end
if removeCount > 0 then
self.owner.Event:DispatchEvent(BattleEventName.BuffCountChange, k, count)
self.owner.Event:DispatchEvent(BattleEventName.BuffCountChange, k, v.size)
end
end
end

View File

@ -16,6 +16,8 @@ local propertyList = {
RoleDataName.Crit,
RoleDataName.CritDamageFactor,
RoleDataName.TreatFacter,
RoleDataName.MaxHp,
RoleDataName.MaxHp,
}
--效果表
@ -72,6 +74,7 @@ local effectList = {
local f1 = args[2]
local f2 = args[3]
BattleLogic.WaitForTrigger(interval, function ()
target.Event:DispatchEvent(BattleEventName.RoleBeHealed, caster)
target:AddBuff(Buff.Create(caster, BuffName.HOT, f2, 1, floor(caster:GetRoleData(propertyList[pro1]) * f1)))
end)
end,
@ -214,10 +217,10 @@ local effectList = {
local f2 = args[3] * (1 + caster:GetRoleData(RoleDataName.Hit) / (1 + target:GetRoleData(RoleDataName.Dodge)))
local rid = args[4]
local f3 = args[5]
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, interval)
if caster.camp == 0 and target.camp == 1 then
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomChange, target, interval)
end
--caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, interval)
--if caster.camp == 0 and target.camp == 1 then
-- BattleLogic.Event:DispatchEvent(BattleEventName.ZoomChange, target, interval)
--end
BattleLogic.WaitForTrigger(interval, function ()
local layer
if target.BuffMgr:HasBuff(BuffName.Brand, function (buff)
@ -426,6 +429,63 @@ local effectList = {
BattleUtil.CalDamage(caster, target, dt, f1)
end)
end,
--瞬间恢复[a]*[b]%生命
--a[属性],b[float]
[24] = function(caster, target, args, interval)
local pro1 = args[1]
local f1 = args[2]
BattleLogic.WaitForTrigger(interval, function ()
target.Event:DispatchEvent(BattleEventName.RoleBeHealed, caster)
BattleUtil.ApplyTreat(caster, target, floor(caster:GetRoleData(propertyList[pro1]) * f1))
end)
end,
--对[a]的伤害[b]%,持续[c]秒
--a[持续伤害状态],b[float],c[int]
[25] = function(caster, target, args, interval)
local dot = args[1]
local f1 = args[2]
local f2 = args[3]
BattleLogic.WaitForTrigger(interval, function ()
local func = function(damage)
if target.BuffMgr:HasBuff(BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
damage = damage + floor(damage * f1)
end
return damage
end
target.exCalDmgList:Add(func)
if f2 > 0 then
BattleLogic.WaitForTrigger(f2, function ()
for i=1, target.exCalDmgList.size do
if target.exCalDmgList.buffer[i] == func then
target.exCalDmgList:Remove(i)
break
end
end
end)
end
end)
end,
--造成[a]的伤害【AOE】(真实伤害)
--a[int]
[26] = function(caster, target, args, interval)
local d = args[1]
BattleLogic.WaitForTrigger(interval, function ()
if not target.isDead then
BattleUtil.ApplyDamage(caster, target, d)
end
end)
end,
--每秒造成[d]的伤害,持续[f]秒【AOE】(真实伤害)
--d[float],f[int]
[27] = function(caster, target, args, interval)
local d1 = args[1]
local d2 = args[2]
BattleLogic.WaitForTrigger(interval, function ()
target:AddBuff(Buff.Create(caster, BuffName.DOT, d2, 1, 0, d1, 1))
end)
end,
}
return effectList

View File

@ -2,24 +2,58 @@ RoleData = {}
RoleData.__index = RoleData
local max = math.max
function RoleData.New(role, data)
local instance = {}
local dataOrder = {
RoleDataName.Level,
RoleDataName.Hp,
RoleDataName.MaxHp,
RoleDataName.Attack,
RoleDataName.PhysicalDefence,
RoleDataName.MagicDefence,
RoleDataName.Speed,
RoleDataName.DamageBocusFactor,
RoleDataName.DamageReduceFactor,
RoleDataName.Hit,
RoleDataName.Dodge,
RoleDataName.Crit,
RoleDataName.CritDamageFactor,
RoleDataName.TreatFacter,
RoleDataName.FireDamageBocusFactor,
RoleDataName.IceDamageBocusFactor,
RoleDataName.LightDamageBocusFactor,
RoleDataName.WindDamageBocusFactor,
RoleDataName.LandDamageBocusFactor,
RoleDataName.DarkDamageBocusFactor,
RoleDataName.FireDamageReduceFactor,
RoleDataName.IceDamageReduceFactor,
RoleDataName.LightDamageReduceFactor,
RoleDataName.WindDamageReduceFactor,
RoleDataName.LandDamageReduceFactor,
RoleDataName.DarkDamageReduceFactor,
}
function RoleData.New()
local instance = {role=0, data={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}
setmetatable(instance, RoleData)
instance.role = role
instance.data = data
return instance
end
function RoleData:Init(role, data)
self.role = role
for i=1, #data do
self.data[dataOrder[i]] = data[i]
end
end
function RoleData:GetData(name)
if self.data[name] then
return self.data[name][1]
return self.data[name]
end
end
function RoleData:SetValue(name, value)
if self.data[name][1] then
local delta = self.data[name][1]
self.data[name][1] = value
if self.data[name] then
local delta = self.data[name]
self.data[name] = value
delta = value - delta
if delta ~= 0 then
self.role.Event:DispatchEvent(BattleEventName.RolePropertyChanged, name, value, delta)
@ -34,26 +68,25 @@ function RoleData:AddValue(name, delta)
if delta < 0 or not self.data[name] then --delta必须非负
return 0
end
if self.data[name][1] then
self:SetValue(name, self.data[name][1] + delta)
if self.data[name] then
self:SetValue(name, self.data[name] + delta)
end
return delta
end
function RoleData:AddPencentValue(name, pencent)
if self.data[name][1] and not self.data[name][2] then
return self:AddValue(name, self.data[name][1] * pencent)
else
return self:AddValue(name, pencent)
if self.data[name] then
return self:AddValue(name, self.data[name] * pencent)
end
return 0
end
function RoleData:SubDeltaValue(name, delta)
if delta < 0 or not self.data[name] then --delta必须非负
return 0
end
if self.data[name][1] then
self:SetValue(name, self.data[name][1] - delta)
if self.data[name] then
self:SetValue(name, self.data[name] - delta)
end
return delta
end
@ -62,29 +95,24 @@ function RoleData:SubValue(name, delta)
if delta < 0 or not self.data[name] then --delta必须非负
return 0
end
local orVal = self.data[name][1]
local orVal = self.data[name]
if orVal then
if self.data[name][2] then
self:SetValue(name, self.data[name][1] * (1 - delta))
else
self:SetValue(name, max(self.data[name][1] - delta, 0))
end
orVal = orVal - self.data[name][1]
self:SetValue(name, max(self.data[name] - delta, 0))
orVal = orVal - self.data[name]
end
return orVal
end
function RoleData:SubPencentValue(name, pencent)
if self.data[name][1] and not self.data[name][2] then
return self:SubValue(name, self.data[name][1] * pencent)
else
return self:SubValue(name, pencent)
if self.data[name] then
return self:SubValue(name, self.data[name] * pencent)
end
return 0
end
--Debug
function RoleData:Foreach(func)
for k,v in ipairs(self.data) do
func(k, v[1])
func(k, v)
end
end

View File

@ -1,28 +1,12 @@
local effect = require("Modules/Battle/Logic/Base/Effect")
local floor = math.floor
local max = math.max
local min = math.min
--local BattleConst = BattleConst
--local RoleDataName = RoleDataName
--local BattleEventName = BattleEventName
local function queryExceptList(r, exceptList)
if not exceptList then return true end
for i=1, #exceptList do
if r.uid == exceptList[i].uid then
return false
end
end
return true
end
local function queryAllies(role, exceptList)
return function (r) return r.camp == role.camp and queryExceptList(r, exceptList) end
end
local function queryAlliesExceptSelf(role, exceptList)
return function (r) return r.camp == role.camp and r.uid ~= role.uid and queryExceptList(r, exceptList) end
end
local function queryEnemy(role, exceptList)
return function (r) return r.camp ~= role.camp and queryExceptList(r, exceptList) end
end
local chooseList = {}
local function chooseTarget(role, chooseId, exceptList)
local chooseType = floor(chooseId / 10000) % 10
local chooseWeight = floor(chooseId / 100) % 10
@ -30,16 +14,32 @@ local function chooseTarget(role, chooseId, exceptList)
local exceptNum = #exceptList
local num = chooseId % 10
local arr = {}
local arr = BattleLogic.Query()
if chooseType == 1 then
arr = BattleLogic.Query(queryAllies(role, exceptList))
arr = BattleLogic.Query(function (r)
for i=1, exceptList.size do
if r.uid == exceptList.buffer[i].uid then
return false
end
end
return r.camp == role.camp
end)
elseif chooseType == 2 then
if role.lockTarget and num == 1 then
return {role.lockTarget}
arr[1] = role.lockTarget
return arr
end
arr = BattleLogic.Query(queryEnemy(role, exceptList))
arr = BattleLogic.Query(function (r)
for i=1, exceptList.size do
if r.uid == exceptList.buffer[i].uid then
return false
end
end
return r.camp ~= role.camp
end)
elseif chooseType == 3 then
return {role}
arr[1] = role
return arr
elseif chooseType == 4 then
return {BattleLogic.GetAggro(role.camp)}
end
@ -90,88 +90,115 @@ local function chooseTarget(role, chooseId, exceptList)
end)
end
local arr2 = {}
for i=1, #chooseList do
chooseList[i] = nil
end
--local chooseList = {}
for i=1, exceptNum do
arr2[i] = exceptList[i]
chooseList[i] = exceptList[i]
end
if #arr >= num then
for i=1+exceptNum, num == 0 and #arr or num do
arr2[i] = arr[i]
end
for i=1+exceptNum, num == 0 and #arr or min(#arr, num) do
chooseList[i] = arr[i]
end
arr = arr2
arr = chooseList
return arr
end
local effectPool = BattleObjectPool.New(function ()
return {0, {}} -- type, {args, ...}
end)
local effectGroupPool = BattleObjectPool.New(function ()
return { 0, 0, {}} -- chooseId, duration, {effect1, effect2, ...}
end)
Skill = {}
function Skill:New(role, effectData)
local o = {}
o.cd = effectData[1]
function Skill:New()
local o = {cd=0,effectList = BattleList.New(),owner=0,sp=0,spPass = 0,choosedList = BattleList.New(),isTeamSkill=false }
setmetatable(o, self)
self.__index = self
return o
end
function Skill:Init(role, effectData)
self.cd = effectData[1]
--skill = {cd, {目标id1, 效果时间, 效果1, 效果2, ...},{目标id2, 效果时间, 效果3, 效果4, ...}, ...}
--效果 = {效果类型id, 效果参数1, 效果参数2, ...}
o.effectList = {}
o.owner = role
o.sp = 0
o.spPass = 0
o.choosedList = {}
self.effectList:Clear()
self.owner = role
self.sp = 0
self.spPass = 0
self.choosedList:Clear()
self.isTeamSkill = false
local v
for i=2, #effectData do
v = effectData[i]
local effectGroup = { 0, 0, {}} -- chooseId, duration, {effect1, effect2, ...}
local effectGroup = effectGroupPool:Get() -- chooseId, duration, {effect1, effect2, ...}
effectGroup[1] = v[1] --chooseId
effectGroup[2] = v[2] --duration
for j=3, #v do --effectList
local effect = {0, {}} -- type, {args, ...}
local effect = effectPool:Get() -- type, {args, ...}
effect[1] = v[j][1]
for k=2, #v[j] do
effect[2][k-1] = v[j][k]
end
effectGroup[3][j-2] = effect
end
o.effectList[i-1] = effectGroup
self.effectList:Add(effectGroup)
end
setmetatable(o, self)
self.__index = self
end
return o
function Skill:Dispose()
local effectGroup
for i=1, self.effectList.size do
effectGroup = self.effectList.buffer[i]
for k=1, #effectGroup[3] do
effectPool:Put(effectGroup[3][k])
effectGroup[3][k] = nil
end
effectGroupPool:Put(effectGroup)
end
end
function Skill:ResetCD()
if self.owner.superSkill == self then
if BattleLogic.SkillUsable then
if not self.isTeamSkill then
if self.owner.superSkill == self then
self.sp = 0
self.spPass = floor(self.cd * BattleLogic.GameFrameRate)
self.owner.Event:DispatchEvent(BattleEventName.SkillCast, self)
BattleLogic.SkillUsable = false
BattleLogic.WaitForTrigger(self.cd, function()
BattleLogic.SkillUsable = true
end)
BattleLogic.AddMP(self.owner.camp, 8)
BattleLogic.AddMP(self.owner.camp, 10)
if self.owner.skill then
local skill = self.owner.skill
local time = max(6-self.owner:GetRoleData(RoleDataName.Speed)/(8*(self.owner:GetRoleData(RoleDataName.Level)+10)), 1.5)
skill.sp = 0
skill.spPass = floor(skill.cd * BattleLogic.GameFrameRate)
skill.spPass = floor(time * BattleLogic.GameFrameRate)
end
else
local time = max(6-self.owner:GetRoleData(RoleDataName.Speed)/(8*(self.owner:GetRoleData(RoleDataName.Level)+10)), 1.5)
self.sp = 0
self.spPass = floor(time * BattleLogic.GameFrameRate)
BattleLogic.AddMP(self.owner.camp, 8)
self.owner.Event:DispatchEvent(BattleEventName.SkillCast, self)
end
else
local time = max(6-self.owner:GetRoleData(RoleDataName.Speed)/(8*(self.owner:GetRoleData(RoleDataName.Level)+10)), 1.5)
self.sp = 0
self.spPass = floor(time * BattleLogic.GameFrameRate)
BattleLogic.AddMP(self.owner.camp, 4)
self.owner.Event:DispatchEvent(BattleEventName.SkillCast, self)
BattleLogic.Event:DispatchEvent(BattleEventName.SkillCast, self.cd) --队伍技能结构和其他相同,只是cd项为对应异妖类型
end
local duration = 0
for i=1, self.effectList.size do
duration = max(duration, self.effectList.buffer[i][2])
end
BattleLogic.SetSkillUsable(self.owner.camp, false)
BattleLogic.WaitForTrigger(duration, function()
BattleLogic.SetSkillUsable(self.owner.camp, true)
end)
BattleLogic.SetAggro(self.owner, 0)
end
function Skill:Cast()
if self.owner.superSkill == self and not BattleLogic.SkillUsable then
return
end
for i=1, #self.effectList do
local effectGroup = self.effectList[i]
for i=1, self.effectList.size do
local effectGroup = self.effectList.buffer[i]
local chooseId = effectGroup[1]
local duration = effectGroup[2]
local arr = chooseTarget(self.owner, chooseId, self.choosedList)
@ -201,7 +228,7 @@ function Skill:Cast()
effect[v[1]](self.owner, arr[j], v[2], duration)
end
end
elseif nn == 1 then
elseif nn == 1 or nn == 3 then
for j=1, #arr do
for k=1, #effectGroup[3] do
local v = effectGroup[3][k]
@ -209,13 +236,14 @@ function Skill:Cast()
end
end
else
local d = duration / (#arr + 1) --分割多人目标施加效果的时间,按照(1+1+..+2)的时间权重占比分配
for j=1, #arr do
local count = chooseId % 10
local d = duration / (count + 1) --分割多人目标施加效果的时间,按照(1+1+..+2)的时间权重占比分配
for j=1, count do
local index = j
local cd = j == #arr and d * 2 or d
local cd = j == count and d * 2 or d
BattleLogic.WaitForTrigger(d * (j-1), function()
local r = arr[index]
if r.isDead then --当被选取的目标已经死亡,则重新选取,若重新选取的目标也死亡,则从之前的目标中选取第一个不死亡的
if not r or r.isDead then --当被选取的目标已经死亡或者没有,则重新选取,若重新选取的目标也死亡或者没有,则从之前的目标中选取第一个不死亡的
arr = chooseTarget(self.owner, chooseId, self.choosedList)
r = arr[index]
if not r then --当没有新增的被选取目标时,可能为空
@ -234,7 +262,7 @@ function Skill:Cast()
end
end
end
table.insert(self.choosedList, r)
self.choosedList:Add(r)
for k=1, #effectGroup[3] do
local v = effectGroup[3][k]
effect[v[1]](self.owner, r, v[2], cd)
@ -242,18 +270,17 @@ function Skill:Cast()
end)
end
BattleLogic.WaitForTrigger(duration, function()
self.choosedList = {}
self.choosedList:Clear()
end)
end
end)
end
end
BattleLogic.SetAggro(self.owner, 0)
self:ResetCD()
end
--表现层调用
function Skill:CanManualCast()
return not self.owner.IsDebug and self.owner.camp == 0 and not self.owner.Auto and self.sp >= self.spPass and BattleLogic.SkillUsable
return not self.owner.IsDebug and self.owner.camp == 0 and not self.owner.Auto and self.sp >= self.spPass and BattleLogic.GetSkillUsable(self.owner.camp)
end
--表现层调用
function Skill:ManualCast()

View File

@ -1,9 +1,10 @@
BattleLogic = {}
local floor = math.floor
local tbObjList
local tbActionList
local tbActionListCount = 0
local objList = BattleDictionary.New()
local skillList
local curUid
local curBuffId
local curFrame
@ -16,24 +17,46 @@ local enemyAggro
local playerAggroChangable
local enemyAggroChangable
local playerSkillUsable
local enemySkillUsable
BattleLogic.IsEnd = false
BattleLogic.Result = -1
BattleLogic.Event = BattleEvent.New()
local playerTeamDummyRole = {camp = 0, Event = BattleLogic.Event, isTeam = true}
local enemyTeamDummyRole = {camp = 0, Event = BattleLogic.Event, isTeam = true}
local playerTeamSkillList = {}
local enemyTeamSkillList = {}
local playerTeamSkillIndex
local enemyTeamSkillIndex
local fightData
local record
local optionRecord
BattleLogic.IsEnd = false
BattleLogic.Result = -1
BattleLogic.Event = BattleEvent:New()
--是否开启战斗日志
BattleLogic.IsOpenBattleRecord = false
--逻辑帧频
BattleLogic.GameFrameRate = 30
BattleLogic.GameDeltaTime = 1 / BattleLogic.GameFrameRate
BattleLogic.SkillUsable = true
--总波次
BattleLogic.TotalOrder = 0
--当前波次
BattleLogic.CurOrder = 0
local actionPool = BattleObjectPool.New(function ()
return { 0, 0 }
end)
local skillPool = BattleObjectPool.New(function ()
return Skill:New()
end)
local tbActionList = BattleList.New()
local rolePool = BattleObjectPool.New(function ()
return RoleLogic.New()
end)
function BattleLogic.Init(data, optionData)
if BattleLogic.IsOpenBattleRecord then
record = {}
@ -49,20 +72,29 @@ function BattleLogic.Init(data, optionData)
BattleLogic.CurOrder = 0
BattleLogic.TotalOrder = #data.enemyData
tbObjList = BattleDictionary.New()
tbActionList = {}
tbActionListCount = 0
BattleLogic.Clear()
skillList = {}
curUid = 0
curBuffId = 0
curFrame = 0
playerMP = 0
enemyMP = 0
playerTeamSkillIndex = 1
enemyTeamSkillIndex = 1
playerAggroChangable = true
enemyAggroChangable = true
playerSkillUsable = true
enemySkillUsable = true
BattleLogic.Event:ClearEvent()
BattleLogic.IsEnd = false
BattleLogic.Result = -1
BattleLogic.SkillUsable = true
end
function BattleLogic.StartOrder()
@ -74,11 +106,41 @@ function BattleLogic.StartOrder()
for i=1, #fightData.enemyData[BattleLogic.CurOrder] do
BattleLogic.AddRole(fightData.enemyData[BattleLogic.CurOrder][i])
end
for i=1, #playerTeamSkillList do
skillPool:Put(playerTeamSkillList[i])
playerTeamSkillList[i]=nil
end
for i=1, #fightData.playerData.teamSkill do
playerTeamSkillList[i] = skillPool:Get()
playerTeamSkillList[i]:Init(playerTeamDummyRole, fightData.playerData.teamSkill[i])
playerTeamSkillList[i].isTeamSkill = true
end
for i=1, #enemyTeamSkillList do
skillPool:Put(enemyTeamSkillList[i])
enemyTeamSkillList[i]=nil
end
for i=1, #fightData.enemyData[BattleLogic.CurOrder].teamSkill do
enemyTeamSkillList[i] = skillPool:Get()
enemyTeamSkillList[i]:Init(enemyTeamDummyRole, fightData.enemyData[BattleLogic.CurOrder].teamSkill[i])
enemyTeamSkillList[i].isTeamSkill = true
end
else
BattleLogic.ClearOrder()
for i=1, #fightData.enemyData[BattleLogic.CurOrder] do
BattleLogic.AddRole(fightData.enemyData[BattleLogic.CurOrder][i])
end
for i=1, #enemyTeamSkillList do
skillPool:Put(enemyTeamSkillList[i])
enemyTeamSkillList[i]=nil
end
for i=1, #fightData.enemyData[BattleLogic.CurOrder].teamSkill do
enemyTeamSkillList[i] = skillPool:Get()
enemyTeamSkillList[i]:Init(enemyTeamDummyRole, fightData.enemyData[BattleLogic.CurOrder].teamSkill[i])
enemyTeamSkillList[i].isTeamSkill = true
end
end
BattleLogic.InitAggro()
end
@ -102,21 +164,23 @@ end
function BattleLogic.AddRole(roleData)
curUid = curUid + 1
local data = RoleLogic.New(curUid, roleData)
tbObjList:Add(curUid, data)
local data = rolePool:Get()
--rolePool:Get(curUid, roleData)
data:Init(curUid, roleData)
objList:Add(curUid, data)
BattleLogic.Event:DispatchEvent(BattleEventName.AddRole, data)
end
function BattleLogic.InitAggro()
for i=1, tbObjList.size do
if tbObjList.vList[i].camp == 1 then
playerAggro = tbObjList.vList[i]
for i=1, objList.size do
if objList.vList[i].camp == 1 then
playerAggro = objList.vList[i]
break
end
end
for i=1, tbObjList.size do
if tbObjList.vList[i].camp == 0 then
enemyAggro = tbObjList.vList[i]
for i=1, objList.size do
if objList.vList[i].camp == 0 then
enemyAggro = objList.vList[i]
break
end
end
@ -126,7 +190,9 @@ function BattleLogic.SetAggro(role, duration)
if role.camp == 1 then
if playerAggroChangable then
playerAggro = role
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomChange, role, math.max(duration, 0.3))
if enemySkillUsable then
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomChange, role, math.max(duration/2, 0.3))
end
playerAggroChangable = false
BattleLogic.WaitForTrigger(duration-BattleLogic.GameDeltaTime, function () --减去一帧避免卡点
playerAggroChangable = true
@ -146,9 +212,9 @@ end
function BattleLogic.GetAggro(camp)
if camp == 0 then
if not playerAggro or playerAggro.isDead then
for i=1, tbObjList.size do
if tbObjList.vList[i].camp == 1 and not tbObjList.vList[i].isDead then
playerAggro = tbObjList.vList[i]
for i=1, objList.size do
if objList.vList[i].camp == 1 and not objList.vList[i].isDead then
playerAggro = objList.vList[i]
BattleLogic.SetAggro(playerAggro, 0)
break
end
@ -157,9 +223,9 @@ function BattleLogic.GetAggro(camp)
return playerAggro
else
if not enemyAggro or enemyAggro.isDead then
for i=1, tbObjList.size do
if tbObjList.vList[i].camp == 0 and not tbObjList.vList[i].isDead then
enemyAggro = tbObjList.vList[i]
for i=1, objList.size do
if objList.vList[i].camp == 0 and not objList.vList[i].isDead then
enemyAggro = objList.vList[i]
BattleLogic.SetAggro(enemyAggro, 0)
break
end
@ -169,9 +235,27 @@ function BattleLogic.GetAggro(camp)
end
end
function BattleLogic.SetSkillUsable(camp, value)
if camp == 0 then
playerSkillUsable = value
else
enemySkillUsable = value
end
end
function BattleLogic.GetSkillUsable(camp)
if camp == 0 then
return playerSkillUsable
else
return enemySkillUsable
end
end
function BattleLogic.WaitForTrigger(delayTime, action)
tbActionListCount = tbActionListCount + 1
tbActionList[tbActionListCount] = { curFrame + floor(delayTime * BattleLogic.GameFrameRate + 0.5), action }
local item = actionPool:Get()
item[1] = curFrame + floor(delayTime * BattleLogic.GameFrameRate + 0.5)
item[2] = action
tbActionList:Add(item)
end
function BattleLogic.AddOption(opType, opArg)
@ -183,14 +267,16 @@ function BattleLogic.GetOption()
end
function BattleLogic.HasObj(obj)
return obj and tbObjList.kvList[obj.uid]
return obj and objList.kvList[obj.uid]
end
function BattleLogic.RemoveObj(uid)
local role = tbObjList.kvList[uid]
local role = objList.kvList[uid]
if role then
BattleLogic.Event:DispatchEvent(BattleEventName.RemoveRole, role)
tbObjList:Remove(uid)
role:Dispose()
rolePool:Put(role)
objList:Remove(uid)
end
end
@ -198,12 +284,16 @@ function BattleLogic.CurFrame()
return curFrame
end
local list = {}
function BattleLogic.Query(func, inCludeDeadRole)
local list = {}
for i=1, #list do
list[i] = nil
end
--local list = {}
local index = 1
if func then
for i=1, tbObjList.size do
local v = tbObjList.vList[i]
for i=1, objList.size do
local v = objList.vList[i]
if func(v) and (inCludeDeadRole or not v.isDead) then
list[index] = v
index = index + 1
@ -213,12 +303,30 @@ function BattleLogic.Query(func, inCludeDeadRole)
return list
end
function BattleLogic.BattleEnd(result)
BattleLogic.IsEnd = true
BattleLogic.Result = result
BattleLogic.Event:DispatchEvent(BattleEventName.BattleEnd, result)
end
function BattleLogic.Clear()
local index = 1
while index <= objList.size do
BattleLogic.RemoveObj(objList.vList[index].uid)
end
index = 1
while index <= tbActionList.size do
actionPool:Put(tbActionList.buffer[index])
tbActionList:Remove(index)
end
end
function BattleLogic.ClearOrder()
local index = 1
local count = tbObjList.size
local count = objList.size
while index <= count do
if tbObjList.vList[index].camp == 1 then
BattleLogic.RemoveObj(tbObjList.vList[index].uid)
if objList.vList[index].camp == 1 then
BattleLogic.RemoveObj(objList.vList[index].uid)
count = count - 1
else
index = index + 1
@ -236,19 +344,19 @@ function BattleLogic.Update()
local opType = optionRecord[i][2]
local opArg = optionRecord[i][3]
if opType == 1 then --自动手动
for i=1, tbObjList.size do
tmpObj = tbObjList.vList[i]
for i=1, objList.size do
tmpObj = objList.vList[i]
if tmpObj.camp == 0 then
tmpObj.Auto = opArg == 1
end
end
elseif opType == 2 then --释放skill
local role = tbObjList.kvList[opArg]
local role = objList.kvList[opArg]
if role and role.skill then
role.skill:Cast()
end
elseif opType == 3 then --释放superSkill
local role = tbObjList.kvList[opArg]
local role = objList.kvList[opArg]
if role and role.superSkill then
role.superSkill:Cast()
end
@ -257,57 +365,45 @@ function BattleLogic.Update()
end
index = 1
while index <= tbActionListCount do
if tbActionList[index][1] <= curFrame then
if tbActionList[index][2] then
tbActionList[index][2]()
while index <= tbActionList.size do
if tbActionList.buffer[index][1] <= curFrame then
if tbActionList.buffer[index][2] then
tbActionList.buffer[index][2]()
end
table.remove(tbActionList, index)
tbActionListCount = tbActionListCount - 1
actionPool:Put(tbActionList.buffer[index])
tbActionList:Remove(index)
else
index = index + 1
end
end
if playerMP == 100 then
if Random.Range01() < 0.5 then
local roleArr = BattleLogic.Query(function (r) return r.camp == 0 end)
BattleLogic.Event:DispatchEvent(BattleEventName.AOE, 0)
--延迟1帧释放效果
BattleLogic.WaitForTrigger(BattleLogic.GameDeltaTime, function ()
for i = 1, #roleArr do
local role = roleArr[i]
BattleLogic.WaitForTrigger(0.3, function ()
BattleUtil.ApplyTreat(role, role, 50)
end)
end
end)
else
local roleArr = BattleLogic.Query(function (r) return r.camp == 1 end)
BattleLogic.Event:DispatchEvent(BattleEventName.AOE, 1)
--延迟1帧释放效果
BattleLogic.WaitForTrigger(BattleLogic.GameDeltaTime, function ()
for i = 1, #roleArr do
local role = roleArr[i]
for j=1, 4 do
BattleLogic.WaitForTrigger(0.1 * (j-1), function ()
BattleUtil.ApplyDamage(nil, role, 5)
end)
end
end
end)
if playerMP == 100 and playerSkillUsable then
local teamSkill = playerTeamSkillList[playerTeamSkillIndex]
if teamSkill then
teamSkill:Cast()
playerTeamSkillIndex = playerTeamSkillIndex + 1
if playerTeamSkillIndex > #playerTeamSkillList then
playerTeamSkillIndex = 1
end
end
playerMP = 0
BattleLogic.SkillUsable = false
BattleLogic.WaitForTrigger(2, function ()
BattleLogic.SkillUsable = true
end)
end
if enemyMP == 100 and enemySkillUsable then
local teamSkill = enemyTeamSkillList[enemyTeamSkillIndex]
if teamSkill then
teamSkill:Cast()
enemyTeamSkillIndex = enemyTeamSkillIndex + 1
if enemyTeamSkillIndex > #enemyTeamSkillList then
enemyTeamSkillIndex = 1
end
end
enemyMP = 0
end
bMyAllDead = true
bEnemyAllDead = true
for i=1, tbObjList.size do
tmpObj = tbObjList.vList[i]
for i=1, objList.size do
tmpObj = objList.vList[i]
if not tmpObj.isDead then
tmpObj:Update()
if tmpObj.camp == 0 then
@ -318,32 +414,13 @@ function BattleLogic.Update()
end
end
if bMyAllDead then
BattleLogic.IsEnd = true
BattleLogic.Result = 0
BattleLogic.Event:DispatchEvent(BattleEventName.BattleEnd, 0)
BattleLogic.BattleEnd(0)
end
if bEnemyAllDead then
if BattleLogic.CurOrder == BattleLogic.TotalOrder then
BattleLogic.IsEnd = true
BattleLogic.Result = 1
BattleLogic.Event:DispatchEvent(BattleEventName.BattleEnd, 1)
BattleLogic.BattleEnd(1)
else
BattleLogic.CurOrder = BattleLogic.CurOrder + 1
--for i=1, tbObjList.size do --切波次重置技能冷却时间
-- tmpObj = tbObjList.vList[i]
-- if tmpObj.camp == 0 then
-- if tmpObj.skill then
-- tmpObj.skill.sp = 0
-- end
-- if tmpObj.superSkill then
-- tmpObj.superSkill.sp = 0
-- end
-- end
--end
--playerMP = 0
--tbActionList = {}
--tbActionListCount = 0
BattleLogic.SkillUsable = true
BattleLogic.Event:DispatchEvent(BattleEventName.BattleOrderChange, BattleLogic.CurOrder)
BattleLogic.StartOrder()
end
@ -353,23 +430,23 @@ end
--Debug专用
function BattleLogic.SetDebug()
local v
for i=1, tbObjList.size do
v = tbObjList.vList[i]
for i=1, objList.size do
v = objList.vList[i]
v.IsDebug = not v.IsDebug
end
end
--Debug专用
function BattleLogic.SetRoleValue(uid, name, value)
if tbObjList.kvList[uid] then
tbObjList.kvList[uid].data:SetValue(name, value)
if objList.kvList[uid] then
objList.kvList[uid].data:SetValue(name, value)
end
end
--Debug专用
function BattleLogic.SetRoleDebug(uid, isDebug)
if tbObjList.kvList[uid] then
tbObjList.kvList[uid].IsDebug = isDebug
if objList.kvList[uid] then
objList.kvList[uid].IsDebug = isDebug
end
end

View File

@ -13,11 +13,7 @@ end
--初始化后调用一次
function Shield:OnStart()
--log("Shield:OnStart")
if not self.target.shield then
self.target.shield = {}
end
table.insert(self.target.shield, self)
self.target.Event:DispatchEvent(BattleEventName.ShieldAdd, self)
self.target.shield:Add(self)
end
--间隔N帧触发,返回true时表示继续触发,返回false立刻触发OnEnd
@ -29,14 +25,11 @@ end
--效果结束时调用一次
function Shield:OnEnd()
--log("Shield:OnEnd")
if self.target.shield then
for i = 1, #self.target.shield do
if self.target.shield[i] == self then
table.remove(self.target.shield, i)
BattleUtil.ApplyDamage(self.caster, self.target, math.floor(self.dmgReboundFactor * self.damageSum))
self.target.Event:DispatchEvent(BattleEventName.ShieldEnd, self)
break
end
for i = 1, self.target.shield.size do
if self.target.shield.buffer[i] == self then
BattleUtil.ApplyDamage(self.caster, self.target, math.floor(self.dmgReboundFactor * self.damageSum))
self.target.shield:Remove(i)
break
end
end
end

View File

@ -13,11 +13,13 @@ BattleEventName = {
MpAdd = indexAdd(),
MpSub = indexAdd(),
BattleRoleDead = indexAdd(),
BattleSkillUsable = indexAdd(),
RoleBeDamaged = indexAdd(),
RoleDamage = indexAdd(),
RoleBeTreated = indexAdd(),
RoleTreat = indexAdd(),
RoleBeHealed = indexAdd(),
RoleBeCrit = indexAdd(),
RoleCrit = indexAdd(),
RoleDodge = indexAdd(),
@ -41,9 +43,6 @@ BattleEventName = {
BuffEnd = indexAdd(),
BuffCountChange = indexAdd(),
BuffCover = indexAdd(),
ShieldAdd = indexAdd(),
ShieldEnd = indexAdd(),
}
index = 0

View File

@ -3,8 +3,10 @@ function BattleDictionary.New()
local o = {}
setmetatable(o, BattleDictionary)
BattleDictionary.__index = BattleDictionary
o.kList = {}
o.vList = {}
o.kL = BattleList.New()
o.vL = BattleList.New()
o.kList = o.kL.buffer
o.vList = o.vL.buffer
o.kvList = {}
o.size = 0
return o
@ -14,8 +16,8 @@ function BattleDictionary:Add(k,v)
if not self.kvList[k] then
self.size = self.size + 1
self.kvList[k] = v
self.kList[self.size] = k
self.vList[self.size] = v
self.kL:Add(k)
self.vL:Add(v)
end
end
@ -24,8 +26,8 @@ function BattleDictionary:Remove(k)
for i=1, self.size do
if self.vList[i] == self.kvList[k] then
self.size = self.size - 1
table.remove(self.kList, i)
table.remove(self.vList, i)
self.kL:Remove(i)
self.vL:Remove(i)
self.kvList[k] = nil
break
end
@ -39,8 +41,8 @@ function BattleDictionary:Set(k,v)
end
function BattleDictionary:Clear()
self.kList = {}
self.vList = {}
self.kL:Clear()
self.vL:Clear()
self.kvList = {}
self.size = 0
end

View File

@ -0,0 +1,30 @@
BattleList = {}
function BattleList.New()
local o = {}
setmetatable(o, BattleList)
BattleList.__index = BattleList
o.buffer = {}
o.size = 0
return o
end
function BattleList:Add(v)
self.size = self.size + 1
self.buffer[self.size] = v
end
function BattleList:Remove(index)
self.size = self.size - 1
for i=index, self.size do
self.buffer[i] = self.buffer[i+1]
end
end
function BattleList:Clear()
--self.buffer = {}
self.size = 0
end
function BattleList:Count()
return self.size
end

View File

@ -0,0 +1,24 @@
BattleObjectPool = {}
function BattleObjectPool.New(onCreate)
local o = {}
setmetatable(o, BattleObjectPool)
BattleObjectPool.__index = BattleObjectPool
o.buffer = {}
o.size = 0
o.onCreate = onCreate
return o
end
function BattleObjectPool:Get(...)
local e = self.buffer[self.size]
if not e then
return self.onCreate(...)
end
self.size = self.size - 1
return e
end
function BattleObjectPool:Put(item)
self.size = self.size + 1
self.buffer[self.size] = item
end

View File

@ -34,7 +34,7 @@ function BattleQueue:Dequeue()
end
function BattleQueue:Clear()
self.list = {}
--self.list = {}
self.size = 0
self.head = -1
self.rear = -1

View File

@ -94,20 +94,18 @@ function BattleUtil.CalCrit(atkRole, defRole)
end
function BattleUtil.CalShield(atkRole, defRole, damage)
if defRole.shield then
local buff
for i=1, #defRole.shield do
buff = defRole.shield[i]
if damage < buff.shieldValue then
buff.shieldValue = buff.shieldValue - damage
buff.damageSum = buff.damageSum + damage
return 0
else
buff.damageSum = buff.damageSum + buff.shieldValue
damage = damage - buff.shieldValue
buff.shieldValue = 0
buff.disperse = true
end
local buff
for i=1, defRole.shield.size do
buff = defRole.shield.buffer[i]
if damage < buff.shieldValue then
buff.shieldValue = buff.shieldValue - damage
buff.damageSum = buff.damageSum + damage
return 0
else
buff.damageSum = buff.damageSum + buff.shieldValue
damage = damage - buff.shieldValue
buff.shieldValue = 0
buff.disperse = true
end
end
return damage
@ -134,6 +132,9 @@ end
--执行完整的命中,伤害,暴击计算,返回命中,暴击
function BattleUtil.CalDamage(atkRole, defRole, damageType, baseFactor)
if atkRole.isTeam and not defRole.isDead then
return BattleUtil.ApplyDamage(atkRole, defRole, damageType), false
end
local bCrit = false
local baseDamage
bCrit = BattleUtil.CalCrit(atkRole, defRole)
@ -158,6 +159,13 @@ function BattleUtil.CalDamage(atkRole, defRole, damageType, baseFactor)
end
baseDamage = BattleUtil.CalBaseDamage(atkRole, defRole, baseDamage, baseFactor)
baseDamage = max(baseDamage, 0.1 * attack)
local func
for i=1, atkRole.exCalDmgList.size do
func = atkRole.exCalDmgList.buffer[i]
baseDamage = func(baseDamage)
end
baseDamage = BattleUtil.CalShield(atkRole, defRole, baseDamage)
local finalDmg = 0 --计算实际造成的扣血
if not defRole.isDead then

View File

@ -7,84 +7,72 @@ local Random = Random
local floor = math.floor
local max = math.max
local Passivity = require("Modules/Battle/Logic/Base/Passivity")
local function InitData(property)
--初始化属性
local index = 1
local getData = function(property)
local p = property[index]
index = index + 1
return p
end
return {
[RoleDataName.Level] = {getData(property), false},
[RoleDataName.Hp] = {getData(property), false},
[RoleDataName.MaxHp] = {getData(property), false},
[RoleDataName.Attack] = {getData(property), false},
[RoleDataName.PhysicalDefence] = {getData(property), false},
[RoleDataName.MagicDefence] = {getData(property), false},
[RoleDataName.Speed] = {getData(property), false},
[RoleDataName.DamageBocusFactor] = {getData(property), true},
[RoleDataName.DamageReduceFactor] = {getData(property), true},
[RoleDataName.Hit] = {getData(property), true},
[RoleDataName.Dodge] = {getData(property), true},
[RoleDataName.Crit] = {getData(property), true},
[RoleDataName.CritDamageFactor] = {getData(property), true},
[RoleDataName.TreatFacter] = {getData(property), true},
[RoleDataName.FireDamageBocusFactor] = {getData(property), true},
[RoleDataName.IceDamageBocusFactor] = {getData(property), true},
[RoleDataName.LightDamageBocusFactor] = { getData(property), true},
[RoleDataName.WindDamageBocusFactor] = {getData(property), true},
[RoleDataName.LandDamageBocusFactor] = {getData(property), true},
[RoleDataName.DarkDamageBocusFactor] = {getData(property), true},
[RoleDataName.FireDamageReduceFactor] = {getData(property), true},
[RoleDataName.IceDamageReduceFactor] = {getData(property), true},
[RoleDataName.LightDamageReduceFactor] = { getData(property), true},
[RoleDataName.WindDamageReduceFactor] = {getData(property), true},
[RoleDataName.LandDamageReduceFactor] = {getData(property), true},
[RoleDataName.DarkDamageReduceFactor] = {getData(property), true},
}
local skillPool = BattleObjectPool.New(function ()
return Skill:New()
end)
local buffPool = BattleObjectPool.New(function ()
return BuffManager.New()
end)
local eventPool = BattleObjectPool.New(function ()
return BattleEvent:New()
end)
local dataPool = BattleObjectPool.New(function ()
return RoleData.New()
end)
function RoleLogic.New()
local instance = {uid=0,roleData=0,data=0,camp=0,name=0,roleType=0,shield=BattleList.New(),exCalDmgList=BattleList.New(),
BuffMgr=0,Event=0,passiveList=0,isDead=false,Auto=false,IsDebug=false,enable=false}
setmetatable(instance, RoleLogic)
return instance
end
function RoleLogic.New(uid, data)
local instance = {}
setmetatable(instance, RoleLogic)
function RoleLogic:Init(uid, data)
self.uid = uid
self.roleData = data
instance.uid = uid
instance.roleData = data
instance.data = RoleData.New(instance, InitData(data.property))
self.data = dataPool:Get()
self.data:Init(self, data.property)
instance.camp = data.camp --阵营 0:我方 1:敌方
instance.name = data.name
instance.roleType = 1 --阵营 1:普通 2:Boss 3:召唤物
self.camp = data.camp --阵营 0:我方 1:敌方
self.name = data.name
self.roleType = 1 --阵营 1:普通 2:Boss 3:召唤物
instance.BuffMgr = BuffManager.New(instance)
instance.Event = BattleEvent:New()
self.shield:Clear() --护盾列表
self.exCalDmgList:Clear() --额外计算伤害列表
instance.passiveList = {}
self.BuffMgr = buffPool:Get()
self.BuffMgr:Init(self)
self.Event = eventPool:Get()
self.Event:ClearEvent()
self.passiveList = {}
if data.skill and #data.skill > 0 then
instance.skill = Skill:New(instance, data.skill)
instance.skill.sp = 0
local time = max(6-instance:GetRoleData(RoleDataName.Speed)/(8*(instance:GetRoleData(RoleDataName.Level)+10)), 1.5)
instance.skill.spPass = floor( time * BattleLogic.GameFrameRate)
self.skill = skillPool:Get()
self.skill:Init(self, data.skill)
self.skill.sp = 0
local time = max(6-self:GetRoleData(RoleDataName.Speed)/(8*(self:GetRoleData(RoleDataName.Level)+10)), 1.5)
self.skill.spPass = floor( time * BattleLogic.GameFrameRate)
end
if data.superSkill and #data.superSkill > 0 then
instance.superSkill = Skill:New(instance, data.superSkill)
instance.superSkill.spPass = floor(instance.superSkill.cd * BattleLogic.GameFrameRate)
instance.superSkill.sp = instance.superSkill.spPass
self.superSkill = skillPool:Get()
self.superSkill:Init(self, data.superSkill)
self.superSkill.spPass = floor(self.superSkill.cd * BattleLogic.GameFrameRate)
self.superSkill.sp = self.superSkill.spPass
end
for i = 1, #data.passivity do
local v = data.passivity[i]
local id = v[1]
local args = v[2]
Passivity[id](instance, args)
Passivity[id](self, args)
end
instance.isDead = false
instance.Auto = true
instance.IsDebug = false
instance.enable = true
return instance
self.isDead = false
self.Auto = true
self.IsDebug = false
self.enable = true
end
function RoleLogic:GetRoleData(property)
@ -95,6 +83,22 @@ function RoleLogic:AddBuff(buff)
self.BuffMgr:AddBuff(buff)
end
function RoleLogic:Dispose()
eventPool:Put(self.Event)
dataPool:Put(self.data)
buffPool:Put(self.BuffMgr)
if self.skill then
self.skill:Dispose()
skillPool:Put(self.skill)
self.skill = nil
end
if self.superSkill then
self.superSkill:Dispose()
skillPool:Put(self.superSkill)
self.superSkill = nil
end
end
function RoleLogic:Update()
self.BuffMgr:Update()
if not self.enable then
@ -104,7 +108,7 @@ function RoleLogic:Update()
if self.superSkill.sp >= self.superSkill.spPass then
if self.skill then
if self.skill.sp >= self.skill.spPass then
if self.Auto and not self.IsDebug then
if self.Auto and not self.IsDebug and BattleLogic.GetSkillUsable(self.camp) then
if Random.Range01() <= 0.75 then
self.skill:Cast()
else
@ -115,7 +119,7 @@ function RoleLogic:Update()
self.skill.sp = self.skill.sp + 1
end
else
if self.Auto and not self.IsDebug then
if self.Auto and not self.IsDebug and BattleLogic.GetSkillUsable(self.camp) then
self.superSkill:Cast()
end
end
@ -125,7 +129,7 @@ function RoleLogic:Update()
else
if self.skill then
if self.skill.sp >= self.skill.spPass then
if self.Auto and not self.IsDebug then
if self.Auto and not self.IsDebug and BattleLogic.GetSkillUsable(self.camp) then
self.skill:Cast()
end
else

View File

@ -81,7 +81,7 @@ public class GameApplication {
MapLogic.getInstance().init(configurableApplicationContext);
// 加载lua文件
// CheckFight.getInstance().init("luafight\\BattleMain.lua");
CheckFight.getInstance().init("luafight\\BattleMain.lua");
final NettyServerAutoConfiguration netServerConfig = configurableApplicationContext.getBean(NettyServerAutoConfiguration.class);
NettyProperties properties = netServerConfig.getNettyProperties();

View File

@ -89,9 +89,7 @@ public class MapLogic {
LOGGER.info("enterMap() uid=>{} team pos is wrong ", uid, teamId);
return;
}
List<String> heroFightInfo = HeroLogic.getInstance().getHeroFightInfo(user, teamId);
// TODO to redis
// heroFightInfo
mapManager.setTeamId(teamId);
mapManager.setTotalStep(totalStep + 5);
}
@ -684,6 +682,7 @@ public class MapLogic {
User user = UserManager.getUser(uid);
String key = RedisKey.getKey(RedisKey.FIGHT, user.getId() , false);
Map<Object , Object> valueMap = RedisUtil.getInstence().hmget(key);
RedisUtil.getInstence().del(key);
if (valueMap == null || valueMap.isEmpty()) {
LOGGER.info("endFight() uid=>{} not start fight", uid);
MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
@ -708,20 +707,40 @@ public class MapLogic {
return;
}
frames = "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";
// frames = "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";
frames ="";
LuaValue getFightData = FightDataUtil.getFinalFightData(fightTeamInfo,monsterTeamList);
// LuaValue getFightData = FightDataUtil.getTestFightData();
LuaValue getOptionData = FightDataUtil.getOptionData(frames);
// int[] checkResult = CheckFight.getInstance().checkFight(seed, getFightData, getOptionData);
int[] checkResult = CheckFight.getInstance().checkFight(seed, getFightData, getOptionData);
int resultCode = checkResult[0];
if (resultCode!=-1){
MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "战斗失败!");
return;
}
int teamId = user.getMapManager().getTeamId();
List<TeamPosHeroInfo> team = user.getTeamPosManager().getTeamPosForHero().get(teamId);
for (TeamPosHeroInfo teamPosHeroInfo : team){
Hero hero = user.getHeroManager().getHero(teamPosHeroInfo.getHeroId());
hero.setCurHp(checkResult[teamPosHeroInfo.getPosition()]);
}
List<Integer> remainHp = new ArrayList<>();
for (int i = 1; i < checkResult.length; i++) {
remainHp.set(i,checkResult[i]);
}
CommonProto.Drop.Builder drop = ItemUtil.drop(user, sMonsterGroup.getRewardgroup(), 1, 1);
FightInfoProto.FightEndResponse fightEndResponse = FightInfoProto.FightEndResponse
.newBuilder()
.setDrop(drop)
.addAllRemainHpList(remainHp)
.build();
MessageUtil.sendMessage(session, 1, messageType.getNumber(), fightEndResponse, true);
RedisUtil.getInstence().del(key);
}
/**

View File

@ -121,7 +121,7 @@ public class BehaviorUtil {
//monster
List<CommonProto.FightUnitInfo> monsterByGroup = MonsterUtil.getMonsterByGroup(groupId);
String monsterTeamSkill = MonsterUtil.getMonsterTeamSkillByGroup(groupId).trim();
String monsterTeamSkill = MonsterUtil.getMonsterTeamSkillByGroup(groupId);
List<CommonProto.FightTeamInfo> monsterGroupList = new ArrayList<>();
CommonProto.FightTeamInfo monsterTeamInfo = CommonProto.FightTeamInfo
.newBuilder()

View File

@ -82,7 +82,7 @@ public class CheckFight {
if (status==1){
for (int i = 1; i <= result.length(); i++) {
resultCache[i] = result.rawget(i).toint();
// LOGGER.info(i+" --> 单位剩余血量 : "+ resultCache[i]);
LOGGER.info(i+" --> 单位剩余血量 : "+ resultCache[i]);
}
}
return resultCache;

View File

@ -642,21 +642,21 @@ public class HeroLogic {
return result;
}
public List<String> getHeroFightInfo(User user,int teamId){
List<String> result = new ArrayList<>(5);
List<TeamPosHeroInfo> teamPosHeroInfoList = user.getTeamPosManager().getTeamPosForHero().get(teamId);
Collections.sort(teamPosHeroInfoList);
Map<String, Hero> heroMap = user.getHeroManager().getHeroMap();
for(TeamPosHeroInfo teamPosHeroInfo : teamPosHeroInfoList){
String heroId = teamPosHeroInfo.getHeroId();
Hero hero = heroMap.get(heroId);
StringBuilder sb = new StringBuilder(hero.getTemplateId()).append(DIVISION);
getHeroSkills(hero,sb);
getHeroProperty(user,hero,sb);
result.add(sb.toString());
}
return result;
}
// public List<String> getHeroFightInfo(User user,int teamId){
// List<String> result = new ArrayList<>(5);
// List<TeamPosHeroInfo> teamPosHeroInfoList = user.getTeamPosManager().getTeamPosForHero().get(teamId);
// Collections.sort(teamPosHeroInfoList);
// Map<String, Hero> heroMap = user.getHeroManager().getHeroMap();
// for(TeamPosHeroInfo teamPosHeroInfo : teamPosHeroInfoList){
// String heroId = teamPosHeroInfo.getHeroId();
// Hero hero = heroMap.get(heroId);
// StringBuilder sb = new StringBuilder(hero.getTemplateId()).append(DIVISION);
// getHeroSkills(hero,sb);
// getHeroProperty(user,hero,sb);
// result.add(sb.toString());
// }
// return result;
// }
public StringBuilder getHeroSkills(Hero hero, StringBuilder sb){
for (Integer skillId : hero.getSkillList()) {
@ -734,6 +734,7 @@ public class HeroLogic {
//食物buffer加成
Map<Integer, Integer> foodAddMap = CombatLogic.getInstance().attributeByEatFood(user,GlobalsDef.FOOD_ADDITION_EXPLORE_TYPE, GlobalsDef.FOOD_EAT_AFFECT_TEAM);
combinedAttribute(foodAddMap,heroAllAttribute);
heroAllAttribute.put(HeroAttributeEnum.CurHP.getPropertyId(),(int)hero.getCurHp());
return heroAllAttribute;
}

View File

@ -157,7 +157,7 @@ public class CBean2Proto {
monsterPropertyList.append((int)(sMonsterConfig.getHit() * 10000)).append("#"); //命中率
monsterPropertyList.append((int)(sMonsterConfig.getDodge() * 10000)).append("#"); //闪避率
monsterPropertyList.append((int)(sMonsterConfig.getCritDamageFactor() * 10000)).append("#"); //暴击伤害系数
monsterPropertyList.append(-1).append("#"); //治疗加成系数
monsterPropertyList.append(1).append("#"); //治疗加成系数
monsterPropertyList.append(damageBonusFactor[0]).append("#"); //火系伤害加成系数
monsterPropertyList.append(damageReduceFactor[0]).append("#"); //火系伤害减免系数
monsterPropertyList.append(damageBonusFactor[1]).append("#"); //冰系伤害加成系数

View File

@ -22,6 +22,9 @@ public class FightDataUtil {
* @return
*/
public static LuaValue getOptionData(String data) {
if (data.equals("") || data==null){
return new LuaTable();
}
String[] tempData1 = data.split("\\|");
LuaValue tableA = new LuaTable();
for (int i = 0; i < tempData1.length; i++) {
@ -59,7 +62,7 @@ public class FightDataUtil {
CommonProto.FightUnitInfo unitInfo = data.getFightUnitList(i);
String[] unitSkill = data.getTeamSkillList().trim().split("#");
String[] unitSkill = unitInfo.getUnitSkillIds().trim().split("#");
SMonsterConfig sMonster = SMonsterConfig.getsMonsterConfigMap().get(Integer.parseInt(unitInfo.getUnitId()));
@ -84,7 +87,7 @@ public class FightDataUtil {
enemyData.rawset(i+1, unitData);
}
enemyData.rawset("teamSkill", getTeamSkill(data.getTeamSkillList().trim()));
enemyData.set("teamSkill", getTeamSkill(data.getTeamSkillList().trim()));
return enemyData;
}
@ -129,42 +132,12 @@ public class FightDataUtil {
}
public static LuaValue getEnemyListData(List<LuaValue> enemyList) {
LuaValue enemyDataList = new LuaTable();
for (LuaValue unitData : enemyList) {
enemyDataList.add(unitData);
}
return enemyDataList;
}
public static LuaValue getTestFightData() {
LuaValue LuaTable = new LuaTable();
LuaTable.set("playerData", getTestPlayerData());
LuaTable.set("enemyData", getTestEnemyData());
return LuaTable;
}
private static LuaValue getTestEnemyData() {
LuaValue playerDataMap = new LuaTable();
LuaValue playerData = new LuaTable();
for (int i = 1; i <= 5; i++) {
playerData.rawset(i, getTestFightUnit(false));
}
// for (int i = 1; i <= 3; i++) {
// }
playerDataMap.rawset(1, playerData);
return playerDataMap;
}
public static LuaValue getPlayerData(CommonProto.FightTeamInfo heroTeam) {
LuaValue playerData = new LuaTable();
for (int i = 1; i <= heroTeam.getFightUnitListCount(); i++) {
playerData.rawset(i, getHeroFightUnit(heroTeam.getFightUnitList(i - 1)));
}
playerData.rawset("teamSkill", getTeamSkill(heroTeam.getTeamSkillList()));
playerData.set("teamSkill", getTeamSkill(heroTeam.getTeamSkillList()));
return playerData;
}
@ -175,8 +148,9 @@ public class FightDataUtil {
}
String[] skills = pokemonSkill.trim().split("#");
for (int i = 0; i < skills.length; i++) {
teamSkill.rawset(i + 1, getSkill(skills[i]));
if (Integer.parseInt(skills[i])>0){
teamSkill.rawset(i + 1, getSkill(skills[i]));
}
}
return teamSkill;
}
@ -204,8 +178,8 @@ public class FightDataUtil {
private static LuaValue getProperty(String dataList) {
String[] propertyArr = dataList.trim().split("#");
LuaValue property = new LuaTable();
for (int i = 3; i <= propertyArr.length - 1; i++) {
property.rawset(i, LuaValue.valueOf(propertyArr[i]));
for (int i = 1; i <= propertyArr.length; i++) {
property.rawset(i, LuaValue.valueOf(Double.parseDouble(propertyArr[i-1])));
}
return property;
}
@ -263,6 +237,28 @@ public class FightDataUtil {
return effectValueList;
}
//==================================test data =================================
public static LuaValue getTestFightData() {
LuaValue LuaTable = new LuaTable();
LuaTable.set("playerData", getTestPlayerData());
LuaTable.set("enemyData", getTestEnemyData());
return LuaTable;
}
private static LuaValue getTestEnemyData() {
LuaValue playerDataMap = new LuaTable();
LuaValue playerData = new LuaTable();
for (int i = 1; i <= 5; i++) {
playerData.rawset(i, getTestFightUnit(false));
}
playerData.set("teamSkill", new LuaTable());
for (int i = 1; i <= 3; i++) {
playerDataMap.rawset(i, playerData);
}
return playerDataMap;
}
private static LuaValue getTestFightUnit(boolean b) {
LuaValue unitData = new LuaTable();
@ -345,6 +341,7 @@ public class FightDataUtil {
for (int i = 1; i <= 5; i++) {
playerData.rawset(i, getTestFightUnit(true));
}
playerData.set("teamSkill", new LuaTable());
return playerData;
}

View File

@ -35,6 +35,9 @@ public class MonsterUtil {
}
public static String getMonsterTeamSkillByGroup(int groupId) {
return SMonsterGroup.getsMonsterGroupMap().get(groupId).getSkill();
if (SMonsterGroup.getsMonsterGroupMap().get(groupId).getSkill()!=null){
return SMonsterGroup.getsMonsterGroupMap().get(groupId).getSkill();
}
return "";
}
}