战斗同步

lvxinran 2020-06-26 00:42:16 +08:00
parent dec66f3ee5
commit fe32e26bfc
11 changed files with 270 additions and 108 deletions

View File

@ -1557,12 +1557,12 @@ local passivityList = {
[92] = function(role, args)
local i1 = args[1]
local OnRoleHit = function(defRole)
local OnRoleHit = function(defRole, damage, bCrit, finalDmg, damageType, skill)
-- local buff = Buff.Create(role, BuffName.PropertyChange, 0, BattlePropList[pro], i1, 1)
-- buff.cover = true -- 可以叠加
-- buff.clear = false -- 不可驱散
-- role:AddBuff(buff)
if defRole:IsDead() then
if skill and not skill.isAdd and defRole:IsDead() then
role:AddRage(i1, CountTypeName.Add)
end
end
@ -2088,7 +2088,7 @@ local passivityList = {
local af = 0
local onSkillCast = function(skill)
if skill.type == BattleSkillType.Normal then
if skill.type == BattleSkillType.Normal and not skill.isAdd then
af = 0
elseif skill.type == BattleSkillType.Special then
af = af + f1
@ -3109,7 +3109,7 @@ local passivityList = {
local f1 = args[1]
local ct = args[2]
local f2 = args[3]
local ct2 = args[4]
local ct2 = args[4] -- 废物参数
-- 释放技能后
local onPassiveDamaging = function(damagingFunc, defRole, damage, skill)
@ -4363,7 +4363,7 @@ local passivityList = {
-- 我方武将造成伤害时,[a]概率附加[b]效果,每回合造成攻击[c]%的伤害,持续[d]秒。
-- 普攻时,[a]概率附加[b]效果,每回合造成攻击[c]%的伤害,持续[d]秒。
-- a[float],b[持续伤害效果],c[float],d[int]
[223] = function(role, args)
local rand = args[1]
@ -4371,11 +4371,13 @@ local passivityList = {
local f1 = args[3]
local i1 = args[3]
local function _OnRoleHit(target)
local function _OnRoleHit(target, damage, _, finalDmg, _, skill)
-- BattleUtil.RandomDot(rand, dot, role, target, i1, 1, )
BattleUtil.RandomAction(rand, function()
target:AddBuff(Buff.Create(role, BuffName.DOT, i1, 1, dot, 2, f1))
end)
if skill and skill.type == BattleSkillType.Normal then
BattleUtil.RandomAction(rand, function()
target:AddBuff(Buff.Create(role, BuffName.DOT, i1, 1, dot, 2, f1))
end)
end
end
role.Event:AddEvent(BattleEventName.RoleHit, _OnRoleHit)
end,
@ -4395,6 +4397,10 @@ local passivityList = {
role.Event:AddEvent(BattleEventName.RoleHit, _OnRoleHit)
end,
--
[225] = function()
end,
-- 斩杀生命低于[a]的敌人
-- a[float]

View File

@ -38,9 +38,9 @@ end
--随机0-1
function Random.Range01()
local var = random() / 2147483647
if BattleLogic.IsOpenBattleRecord then
BattleLogic.RecordSeed(seed)
end
BattleLogManager.Log(
"random",
"seed", seed)
return var
end

View File

@ -37,9 +37,12 @@ function RoleData:SetValue(name, value)
delta = value - delta
if delta ~= 0 then
self.role.Event:DispatchEvent(BattleEventName.RolePropertyChanged, name, value, delta)
if BattleLogic.IsOpenBattleRecord then
BattleLogic.RecordRoleProperty(self.role.uid, self.role.camp, name, value, delta)
end
BattleLogManager.Log(
"property change",
"camp", self.role.camp,
"position", self.role.position,
"propId", name,
"value", value)
end
end
end

View File

@ -91,9 +91,13 @@ local function takeEffect(caster, target, effects, duration, skill)
--
if effect[e.type] then
effect[e.type](caster, target, e.args, duration, skill)
if BattleLogic.IsOpenBattleRecord then
BattleLogic.RecordEffect(caster, target, e.type, e.args, duration)
end
BattleLogManager.Log(
"Take Effect",
"tcamp", target.camp,
"tpos", target.position,
"type", e.type
)
end
end
end
@ -131,6 +135,15 @@ function Skill:Cast(func)
end
end
end
--
BattleLogManager.Log(
"Cast Skill",
"camp", self.owner.camp,
"pos", self.owner.position,
"type", self.type,
"isRage", tostring(self.isRage),
"isAdd", tostring(self.isAdd)
)
-- 对目标造成相应的效果
for i=1, self.effectList.size do

View File

@ -0,0 +1,133 @@
BattleLogManager = {}
local this = BattleLogManager
local isLog = true
local function pairsByKeys(t)
local a = {}
for n in pairs(t) do
if n then
a[#a+1] = n
end
end
table.sort(a, function( op1, op2 )
local type1, type2 = type(op1), type(op2)
local num1, num2 = tonumber(op1), tonumber(op2)
if ( num1 ~= nil) and (num2 ~= nil) then
return num1 < num2
elseif type1 ~= type2 then
return type1 < type2
elseif type1 == "string" then
return op1 < op2
elseif type1 == "boolean" then
return op1
-- 以上处理: number, string, boolean
else -- 处理剩下的: function, table, thread, userdata
return tostring(op1) < tostring(op2) -- tostring后比较字符串
end
end)
local i = 0
return function()
i = i + 1
return a[i], t[a[i]]
end
end
function this.PrintBattleTable(tb)
local indent_str = "{"
local count = 0
for k,v in pairs(tb) do
count = count + 1
end
for k=1, #tb do
local v = tb[k]
if type(v) == "table" then
indent_str = indent_str .. this.PrintBattleTable(v)
elseif type(v) == "string" then
indent_str = indent_str .. "\""..tostring(v) .. "\""
else
indent_str = indent_str .. tostring(v)
end
if k < count then
indent_str = indent_str..","
end
end
local index = 0
for k,v in pairsByKeys(tb) do
index = index + 1
if type(k) ~= "number" then
if type(v) == "table" then
indent_str = string.format("%s%s=%s", indent_str, tostring(k), this.PrintBattleTable(v))
elseif type(v) == "string" then
indent_str = string.format("%s%s=\"%s\"", indent_str, tostring(k), tostring(v))
else
indent_str = string.format("%s%s=%s", indent_str, tostring(k), tostring(v))
end
if index < count then
indent_str = indent_str .. ","
end
end
end
indent_str = indent_str .. "}"
return indent_str
end
--
function this.Init(fightdata)
this.timestamp = Random.GetSeed()
this.fightdata = fightdata
this.logList = {}
end
function this.Log(...)
if not isLog then return end
local args = {...}
local log = args[1] .. ":\n"
log = log .. string.format("%s = %s, ", "frame", BattleLogic.CurFrame())
for i = 2, #args, 2 do
local key = args[i]
local value = args[i + 1]
log = log .. string.format("%s = %s, ", key, value)
end
table.insert(this.logList, log)
end
function this.WriteFile()
if not isLog then return end
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
local platform
-- linux
if not file then
file = io.open("../luafight/BattleRecord/log-"..time..".txt", "a")
platform = "Linux"
end
-- local window server
if not file then
file = io.open("luafight/BattleRecord/log-"..time..".txt", "a")
platform = "Local Windows Server"
end
-- local
if not file then
file = io.open("BattleRecord/log-"..time..".txt", "a")
platform = "Local"
end
file:write(platform..":\n\n\n")
for i = 1, #this.logList do
file:write(this.logList[i].."\n")
end
file:write("\n\n\n\n\n")
file:write("fightData:\n")
file:write(this.PrintBattleTable(this.fightdata))
file:write("\n\n")
file:write("timeStamp: " .. this.timestamp)
io.close(file)
end
return BattleLogManager

View File

@ -1,10 +1,3 @@
require("Modules.Battle.Logic.SkillManager")
require("Modules.Battle.Logic.RoleManager")
require("Modules.Battle.Logic.OutDataManager")
BattleLogic = {}
local floor = math.floor
@ -88,6 +81,7 @@ function BattleLogic.Init(data, optionData, maxRound)
SkillManager.Init()
OutDataManager.Init(fightData)
PassiveManager.Init()
BattleLogManager.Init(fightData)
end
function BattleLogic.StartOrder()
@ -165,6 +159,11 @@ function BattleLogic.TurnRound(debugTurn)
CurCamp = 0
CurSkillPos[0] = 0
CurSkillPos[1] = 0
--
BattleLogManager.Log(
"Round Change",
"round", CurRound
)
-- 轮数变化
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoundChange, CurRound)
else
@ -172,6 +171,11 @@ function BattleLogic.TurnRound(debugTurn)
CurCamp = (CurCamp + 1) % 2
end
--
BattleLogManager.Log(
"Camp Change",
"camp", CurCamp
)
-- 当前阵营下一释放技能的位置
local cpos = CurSkillPos[CurCamp] + 1
-- 找到下一个释放技能的人
@ -195,10 +199,16 @@ function BattleLogic.TurnRound(debugTurn)
end
-- 如果找不到下一个人,直接交换阵营
if not SkillRole then
BattleLogManager.Log( "No Skill Position" )
BattleLogic.TurnRoundNextFrame()
return
end
--
BattleLogManager.Log(
"Position Change",
"position", CurSkillPos[CurCamp]
)
-- 如果角色无法释放技能
if not SkillRole:IsAvailable() then
@ -239,9 +249,6 @@ function BattleLogic.WaitForTrigger(delayTime, action)
item[1] = curFrame + delayFrame
item[2] = action
tbActionList:Add(item)
if BattleLogic.IsOpenBattleRecord then
BattleLogic.RecordDelayTrigger(delayTime, curFrame + delayFrame)
end
end
@ -308,11 +315,14 @@ end
function BattleLogic.BattleEnd(result)
--
BattleLogic.Event:DispatchEvent(BattleEventName.BeforeBattleEnd, result)
--
BattleLogic.IsEnd = true
BattleLogic.Result = result
BattleLogic.Event:DispatchEvent(BattleEventName.BattleEnd, result)
-- 战斗日志写入
if not BattleLogic.GetIsDebug() then
BattleLogManager.WriteFile()
end
end
--
function BattleLogic.Clear()
@ -324,75 +334,3 @@ function BattleLogic.Clear()
tbActionList:Remove(tbActionList.size)
end
end
-------++++++++++++++++++++++++++++ 战斗记录相关
--Record专用
function BattleLogic.GetRecord()
return record
end
--Record专用
function BattleLogic.RecordSeed(seed)
table.insert(record, string.format("frame:%d, seed:%d", curFrame, seed))
end
--Record专用
function BattleLogic.RecordRoleProperty(uid, camp, name, value, delta)
table.insert(record, string.format("frame:%d, uid:%d, camp:%d, name:%s, value:%d, delta:%d", curFrame, uid, camp, name, value, delta))
end
--Record专用
function BattleLogic.RecordMul(args)
local str = ""
for i=1, #args do
str = str..tostring(args[i]) .. (i == #args and "" or "#")
end
table.insert(record, string.format("frame:%d, mulArgs:%s", curFrame, str))
end
--Record专用
function BattleLogic.RecordEffect(caster, target, type, args, interval)
local cUid = tostring(caster.uid) or "cTeam"
local tUid = tostring(target.uid) or "tTeam"
local str = ""
for i=1, #args do
str = str..tostring(args[i]) .. (i == #args and "" or "#")
end
table.insert(record, string.format("frame:%d, caster:%s, target:%s, effectType:%d, args:%s, interval:%d", curFrame, cUid, tUid, type, str, interval))
end
--Record专用
function BattleLogic.RecordDelayTrigger(delayFrame, triggerFrame)
table.insert(record, string.format("frame:%d, delayTime:%f, triggerFrame:%d", curFrame, delayFrame, triggerFrame))
end
--Record专用
function BattleLogic.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("BattleRecord/"..time..".txt", "a")
for i=1, #record do
file:write(record[i].."\n")
end
io.close(file)
end

View File

@ -25,6 +25,8 @@ function NoDead:OnStart()
self.target:SetDeadFilter(false)
self.target:SetReliveFilter(self.isCanRelive)
self.target:SetIsCanAddSkill(false)
end
--间隔N帧触发返回true时表示继续触发返回false立刻触发OnEnd
@ -36,6 +38,8 @@ end
function NoDead:OnEnd()
self.target.Event:AddEvent(BattleEventName.PassiveDamaging, self.onPassiveDamaging, self)
self.target:SetDeadFilter(true)
-- self.target:SetIsCanAddSkill(false)
end
--只有当cover字段为true时触发返回true则被新效果覆盖

View File

@ -27,9 +27,6 @@ function BattleUtil.FP_Mul(...)
for i, v in ipairs{...} do
f = floor(f * v * 100000 + 0.5) / 100000
end
if BattleLogic.IsOpenBattleRecord then
BattleLogic.RecordMul({...})
end
return f
end
@ -227,6 +224,11 @@ function BattleUtil.ChooseTarget(role, chooseId)
end
end
end
-- table.sort(finalArr, function(a, b)
-- return a.position < b.position
-- end)
return finalArr
end
@ -363,6 +365,18 @@ function BattleUtil.FinalDamage(skill, atkRole, defRole, damage, bCrit, damageTy
defRole.Event:DispatchEvent(BattleEventName.RoleBeHit, atkRole, damage, bCrit, finalDmg, damageType, skill)
end
end
--
BattleLogManager.Log(
"Final Damage",
"acamp", atkRole.camp,
"apos", atkRole.position,
"tcamp", defRole.camp,
"tpos", defRole.position,
"damage", damage,
"dotType", tostring(dotType)
)
return finalDmg
end
@ -438,6 +452,10 @@ function BattleUtil.CalDamage(skill, atkRole, defRole, damageType, baseFactor, i
atkRole.Event:DispatchEvent(BattleEventName.RoleDamageAfter, defRole, damageFunc, fixDamage)
defRole.Event:DispatchEvent(BattleEventName.RoleBeDamagedAfter, atkRole, damageFunc, fixDamage)
fixDamage = max(floor(attack * 0.1), fixDamage)
local finalDmg = 0 --计算实际造成的扣血
if not defRole:IsRealDead() then
finalDmg = BattleUtil.ApplyDamage(skill, atkRole, defRole, fixDamage, bCrit, damageType, dotType)
@ -494,6 +512,16 @@ function BattleUtil.ApplyTreat(castRole, targetRole, value, baseFactor)
end
castRole.Event:DispatchEvent(BattleEventName.RoleTreat, targetRole, treat, baseTreat)
targetRole.Event:DispatchEvent(BattleEventName.RoleBeTreated, castRole, treat, baseTreat)
--
BattleLogManager.Log(
"Final Damage",
"acamp", castRole.camp,
"apos", castRole.position,
"tcamp", targetRole.camp,
"tpos", targetRole.position,
"value", value
)
end
@ -713,9 +741,9 @@ end
-- 根据位置类型获取数据
function BattleUtil.GetRoleListByPosType(camp, posType)
if posType == 1 then
return RoleManager.Query(function (r) return r.camp ~= camp and r.position <= 3 end)
return RoleManager.Query(function (r) return r.camp == camp and r.position <= 3 end)
elseif posType == 2 then
return RoleManager.Query(function (r) return r.camp ~= camp and r.position > 3 end)
return RoleManager.Query(function (r) return r.camp == camp and r.position > 3 end)
end
end

View File

@ -1,7 +1,6 @@
--战斗外数据管理、
OutDataManager = {}
local this = OutDataManager
--
local function _Split(input, delimiter)
input = tostring(input)

View File

@ -18,7 +18,7 @@ function RoleLogic.New()
exCalDmgList=BattleList.New(),
proTranList=BattleList.New(),
buffFilter=BattleList.New(),
Event=BattleEvent:New(),passiveList={},isDead=false,IsDebug=false}
Event = BattleEvent:New(),passiveList={},isDead=false,IsDebug=false}
setmetatable(instance, RoleLogic)
return instance
end
@ -36,6 +36,7 @@ function RoleLogic:Init(uid, data, position)
self.name = data.name
self.element = data.element
self.professionId = data.professionId
self.star = data.star or 1
self.shield:Clear() --护盾列表
self.exCalDmgList:Clear() --额外计算伤害列表
@ -100,6 +101,8 @@ function RoleLogic:Init(uid, data, position)
self.reliveFilter = true -- 控制复活的标志位置为false角色将不再享受复活效果
self.reliveHPF = 1
self.IsCanAddSkill = true -- 是否可以追加技能
end
-- 添加一个被动技能
@ -350,13 +353,39 @@ end
-- isAdd 是否是追加技能
-- isRage 是否正常操作怒气值
function RoleLogic:AddSkill(type, isRage, isAdd, targets)
if not self.IsCanAddSkill and isAdd then return end
local effectData = type == BattleSkillType.Normal and self.skill or self.superSkill
SkillManager.AddSkill(self, effectData, type, targets, isAdd, isRage)
--
BattleLogManager.Log(
"Add Skill",
"camp", self.camp,
"pos", self.position,
"type", type,
"isRage", tostring(isRage),
"isAdd", tostring(isAdd),
"targets", targets and #targets or "0"
)
end
-- 插入一个技能
function RoleLogic:InsertSkill(type, isRage, isAdd, targets)
if not self.IsCanAddSkill and isAdd then return end
local effectData = type == BattleSkillType.Normal and self.skill or self.superSkill
SkillManager.InsertSkill(self, effectData, type, targets, isAdd, isRage)
--
BattleLogManager.Log(
"Insert Skill",
"camp", self.camp,
"pos", self.position,
"type", type,
"isRage", tostring(isRage),
"isAdd", tostring(isAdd),
"targets", targets and #targets or "0"
)
end
-- 设置是否可以追加技能
function RoleLogic:SetIsCanAddSkill(isCan)
self.IsCanAddSkill = isCan
end

View File

@ -149,6 +149,9 @@ function RoleManager.Query(func, inCludeDeadRole)
end
end
end
table.sort(list, function(a, b)
return a.position < b.position
end)
return list
end
@ -245,6 +248,9 @@ function this.GetArrAggroList(role, arr)
end
end
end
table.sort(targetList, function(a, b)
return a.position < b.position
end)
return targetList
end
--获取对位相邻站位的人 chooseType 1 我方 2 敌方(对位的敌人受到嘲讽的影响,若对位的敌人死亡,则选取相邻最近的作为目标)
@ -272,6 +278,9 @@ function this.GetNeighbor(role, chooseType)
end
end
end
table.sort(posList, function(a, b)
return a.position < b.position
end)
return posList
end