同步战斗

zhangshanxue 2020-07-18 21:06:17 +08:00
parent ff2593d4de
commit 1f9affbcba
6 changed files with 89 additions and 35 deletions

View File

@ -1915,7 +1915,7 @@ local passivityList = {
-- 释放技能后 -- 释放技能后
local onSkillEnd = function(skill) local onSkillEnd = function(skill)
if skill.type == BattleSkillType.Special then if skill.type == BattleSkillType.Special then
local list = skill:GetDirectTargets() local list = skill:GetDirectTargetsNoMiss()
if list then if list then
for i = 1, #list do for i = 1, #list do
list[i]:AddRage(i1, CountTypeName.Sub) list[i]:AddRage(i1, CountTypeName.Sub)
@ -2265,7 +2265,7 @@ local passivityList = {
-- 普攻后 -- 普攻后
local onSkillEnd = function(skill) local onSkillEnd = function(skill)
if skill.type == BattleSkillType.Normal then if skill.type == BattleSkillType.Normal then
local list = skill:GetDirectTargets() local list = skill:GetDirectTargetsNoMiss()
if list then if list then
for _, r in ipairs(list) do for _, r in ipairs(list) do
r:AddRage(i1, CountTypeName.Sub) r:AddRage(i1, CountTypeName.Sub)
@ -2467,7 +2467,7 @@ local passivityList = {
-- 普攻后 -- 普攻后
local onSkillEnd = function(skill) local onSkillEnd = function(skill)
if skill.type == BattleSkillType.Normal then if skill.type == BattleSkillType.Normal then
local list = skill:GetDirectTargets() local list = skill:GetDirectTargetsNoMiss()
if list then if list then
local attack = role:GetRoleData(RoleDataName.Attack) local attack = role:GetRoleData(RoleDataName.Attack)
local damage = floor(BattleUtil.ErrorCorrection(attack * 0.2)) local damage = floor(BattleUtil.ErrorCorrection(attack * 0.2))
@ -2510,7 +2510,7 @@ local passivityList = {
-- 技能后后 -- 技能后后
local onSkillEnd = function(skill) local onSkillEnd = function(skill)
if skill.type == BattleSkillType.Special then if skill.type == BattleSkillType.Special then
local list = skill:GetDirectTargets() local list = skill:GetDirectTargetsNoMiss()
if list then if list then
local tv = floor(BattleUtil.ErrorCorrection(role:GetRoleData(pro) * f1)) local tv = floor(BattleUtil.ErrorCorrection(role:GetRoleData(pro) * f1))
for _, r in ipairs(list) do for _, r in ipairs(list) do
@ -2533,7 +2533,7 @@ local passivityList = {
-- 技能后后 -- 技能后后
local onSkillEnd = function(skill) local onSkillEnd = function(skill)
if skill.type == BattleSkillType.Normal then if skill.type == BattleSkillType.Normal then
local list = skill:GetDirectTargets() local list = skill:GetDirectTargetsNoMiss()
if list then if list then
local tv = floor(BattleUtil.ErrorCorrection(role:GetRoleData(pro) * f1)) local tv = floor(BattleUtil.ErrorCorrection(role:GetRoleData(pro) * f1))
for _, r in ipairs(list) do for _, r in ipairs(list) do
@ -2871,7 +2871,7 @@ local passivityList = {
-- 技能后后 -- 技能后后
local onSkillCastEnd = function(skill) local onSkillCastEnd = function(skill)
if skill.type == BattleSkillType.Special then if skill.type == BattleSkillType.Special then
local targets = skill:GetDirectTargets() local targets = skill:GetDirectTargetsNoMiss()
if targets then if targets then
for _, r in ipairs(targets) do for _, r in ipairs(targets) do
BattleUtil.RandomControl(f1, ctrl, role, r, i1) BattleUtil.RandomControl(f1, ctrl, role, r, i1)
@ -3416,7 +3416,7 @@ local passivityList = {
local function onSkillCastEnd(skill) local function onSkillCastEnd(skill)
-- 对每个目标附加减伤盾 -- 对每个目标附加减伤盾
local targets = skill:GetDirectTargets() local targets = skill:GetDirectTargetsNoMiss()
if targets and #targets == 1 then if targets and #targets == 1 then
targets[1]:AddRage(i1, CountTypeName.Sub) targets[1]:AddRage(i1, CountTypeName.Sub)
end end
@ -3523,7 +3523,7 @@ local passivityList = {
local chooseId = effectGroup.chooseId local chooseId = effectGroup.chooseId
local chooseLimit = floor(chooseId / 10000) % 10 local chooseLimit = floor(chooseId / 10000) % 10
if chooseLimit == 3 then -- 打纵列 if chooseLimit == 3 then -- 打纵列
local targets = skill:GetDirectTargets() local targets = skill:GetDirectTargetsNoMiss()
if targets then if targets then
for _, r in ipairs(targets) do for _, r in ipairs(targets) do
r:AddRage(i1, CountTypeName.Sub) r:AddRage(i1, CountTypeName.Sub)

View File

@ -10,7 +10,7 @@ local effectPool = BattleObjectPool.New(function ()
return { type = 0, args = {}} -- type, {args, ...} return { type = 0, args = {}} -- type, {args, ...}
end) end)
local effectGroupPool = BattleObjectPool.New(function () local effectGroupPool = BattleObjectPool.New(function ()
return { chooseId = 0, duration = 0, effects = {}} -- chooseId, duration, {effect1, effect2, ...} return { chooseId = 0, effects = {}} -- chooseId, {effect1, effect2, ...}
end) end)
Skill = {} Skill = {}
@ -25,31 +25,32 @@ end
function Skill:Init(role, effectData, type, targets, isAdd, isRage) --type 0 异妖 1 点技 2 滑技 function Skill:Init(role, effectData, type, targets, isAdd, isRage) --type 0 异妖 1 点技 2 滑技
local isTeamSkill = type == 0 local isTeamSkill = type == 0
self.type = type self.type = type
--skill = {技能ID, {目标id1, 效果时间, 效果1, 效果2, ...},{目标id2, 效果时间, 效果3, 效果4, ...}, ...} --skill = {技能ID, 命中时间, 持续时间, 伤害次数, {目标id1, 效果1, 效果2, ...},{目标id2, 效果3, 效果4, ...}, ...}
--效果 = {效果类型id, 效果参数1, 效果参数2, ...} --效果 = {效果类型id, 效果参数1, 效果参数2, ...}
self.effectList:Clear() self.effectList:Clear()
self.owner = role self.owner = role
self.isTeamSkill = isTeamSkill self.isTeamSkill = isTeamSkill
self.teamSkillType = isTeamSkill and floor(effectData[1] / 100) or 0 self.teamSkillType = isTeamSkill and floor(effectData[1] / 100) or 0
self.id = effectData[1] -- 技能ID self.id = effectData[1] -- 技能ID
-- self.EffectDuration = 0 -- 效果命中需要的时间 self.hitTime = effectData[2] -- 效果命中需要的时间
self.continueTime = effectData[3] -- 命中后伤害持续时间
self.attackCount = effectData[4] -- 伤害持续时间内伤害次数
self.targets = targets or {} self.targets = targets or {}
self.isAdd = isAdd self.isAdd = isAdd
self.isRage = isRage self.isRage = isRage
for i=2, #effectData do for i=5, #effectData do
local v = effectData[i] local v = effectData[i]
local effectGroup = effectGroupPool:Get() -- chooseId, duration, {effect1, effect2, ...} local effectGroup = effectGroupPool:Get() -- chooseId, {effect1, effect2, ...}
effectGroup.chooseId = v[1] --chooseId effectGroup.chooseId = v[1] --chooseId
effectGroup.duration = v[2] --duration for j=2, #v do -- effectList
for j=3, #v do --effectList
local effect = effectPool:Get() -- type, {args, ...} local effect = effectPool:Get() -- type, {args, ...}
effect.type = v[j][1] effect.type = v[j][1]
for k=2, #v[j] do for k=2, #v[j] do
effect.args[k-1] = v[j][k] effect.args[k-1] = v[j][k]
end end
effectGroup.effects[j-2] = effect effectGroup.effects[j-1] = effect
end end
self.effectList:Add(effectGroup) self.effectList:Add(effectGroup)
end end
@ -71,12 +72,11 @@ function Skill:Dispose()
end end
end end
local function takeEffect(caster, target, effects, duration, skill) local function DoEffect(caster, target, eff, duration, skill)
for k=1, #effects do
local e = {type = 0, args = {}} local e = {type = 0, args = {}}
e.type = effects[k].type e.type = eff.type
for i=1, #effects[k].args do for i=1, #eff.args do
e.args[i] = effects[k].args[i] e.args[i] = eff.args[i]
end end
-- 检测被动技能对技能参数的影响 -- 检测被动技能对技能参数的影响
@ -100,6 +100,17 @@ local function takeEffect(caster, target, effects, duration, skill)
) )
end end
end end
function Skill:takeEffect(caster, target, effects, effectIndex, duration, skill)
for k=1, #effects do
-- 如果不是第一个效果对列的第一个效果则判断是否命中
if k ~= 1 and effectIndex == 1 then
if self:CheckTargetIsHit(target) then
DoEffect(caster, target, effects[k], duration, skill)
end
else
DoEffect(caster, target, effects[k], duration, skill)
end
end
end end
-- 释放技能 -- 释放技能
@ -107,7 +118,7 @@ end
function Skill:Cast(func) function Skill:Cast(func)
self.castDoneFunc = func self.castDoneFunc = func
self.effectTargets = {} self.effectTargets = {}
self.targetIsHit = {}
-- 先计算出技能的目标 -- 先计算出技能的目标
for i=1, self.effectList.size do for i=1, self.effectList.size do
-- 是否重新选择目标 -- 是否重新选择目标
@ -153,7 +164,6 @@ function Skill:Cast(func)
if arr and #arr > 0 then if arr and #arr > 0 then
--效果延迟1帧生效 --效果延迟1帧生效
BattleLogic.WaitForTrigger(BattleLogic.GameDeltaTime, function() BattleLogic.WaitForTrigger(BattleLogic.GameDeltaTime, function()
local duration = effectGroup.duration
local effects = effectGroup.effects local effects = effectGroup.effects
local weight = floor(chooseId % 10000 / 100) local weight = floor(chooseId % 10000 / 100)
local count = min(chooseId % 10, #arr) local count = min(chooseId % 10, #arr)
@ -163,7 +173,20 @@ function Skill:Cast(func)
-- 全部同时生效 -- 全部同时生效
for j=1, count do for j=1, count do
if arr[j] and not arr[j]:IsRealDead() then if arr[j] and not arr[j]:IsRealDead() then
takeEffect(self.owner, arr[j], effects, duration, self) -- 检测是否命中
if i == 1 then
self.targetIsHit[arr[j]] = BattleUtil.CheckIsHit(self.owner, arr[j])
end
self:takeEffect(self.owner, arr[j], effects, i, self.hitTime, self)
-- if i == 1 then
-- self.targetIsHit[arr[j]] = BattleUtil.CheckIsHit(self.owner, arr[j])
-- takeEffect(self.owner, arr[j], effects, self.hitTime, self)
-- else
-- -- 未命中的目标不会产生后续技能效果
-- if self:CheckTargetIsHit(arr[j]) then
-- takeEffect(self.owner, arr[j], effects, self.hitTime, self)
-- end
-- end
end end
end end
end) end)
@ -182,10 +205,7 @@ function Skill:Cast(func)
tr.Event:DispatchEvent(BattleEventName.BeSkillCast, self) tr.Event:DispatchEvent(BattleEventName.BeSkillCast, self)
end end
--技能的施法时间计算根据当前目标id关联的持续时间取其中时间最长的一个 --技能的施法时间计算根据当前目标id关联的持续时间取其中时间最长的一个
local duration = 0 local duration = self.hitTime + self.continueTime
for i=1, self.effectList.size do
duration = max(duration, self.effectList.buffer[i].duration)
end
-- 结算时间向后延长0.2秒,避免在效果结算完成前就结束了技能释放 -- 结算时间向后延长0.2秒,避免在效果结算完成前就结束了技能释放
BattleLogic.WaitForTrigger(duration + 0.2, function() BattleLogic.WaitForTrigger(duration + 0.2, function()
self.owner.Event:DispatchEvent(BattleEventName.SkillCastEnd, self) self.owner.Event:DispatchEvent(BattleEventName.SkillCastEnd, self)
@ -202,10 +222,20 @@ function Skill:Cast(func)
end end
-- 获取技能的直接目标,和策划规定第一个效果的目标为直接效果目标 -- 获取技能的直接目标,和策划规定第一个效果的目标为直接效果目标,(包含miss的目标)
function Skill:GetDirectTargets() function Skill:GetDirectTargets()
return self.effectTargets[1] return self.effectTargets[1]
end end
-- 获取直接目标不包含miss的目标可能为空
function Skill:GetDirectTargetsNoMiss()
local list = {}
for _, role in ipairs(self.effectTargets[1]) do
if self.CheckTargetIsHit(role) then
table.insert(list, role)
end
end
return list
end
-- 获取技能目标最大人数 -- 获取技能目标最大人数
function Skill:GetMaxTargetNum() function Skill:GetMaxTargetNum()
local mainEffect = self.effectList.buffer[1] local mainEffect = self.effectList.buffer[1]
@ -214,6 +244,10 @@ function Skill:GetMaxTargetNum()
end end
return BattleUtil.GetMaxTargetNum(mainEffect.chooseId) return BattleUtil.GetMaxTargetNum(mainEffect.chooseId)
end end
-- 判断是否命中
function Skill:CheckTargetIsHit(role)
return self.targetIsHit[role]
end
-- 结束技能 -- 结束技能
function Skill:EndSkill() function Skill:EndSkill()

View File

@ -1,6 +1,6 @@
BattleLogManager = {} BattleLogManager = {}
local this = BattleLogManager local this = BattleLogManager
local isLog = true local isLog = false
local function pairsByKeys(t) local function pairsByKeys(t)
local a = {} local a = {}

View File

@ -210,10 +210,11 @@ function BattleLogic.TurnRound(debugTurn)
"position", CurSkillPos[CurCamp] "position", CurSkillPos[CurCamp]
) )
-- buff计算
BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量
BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血)
-- 如果角色无法释放技能 -- 如果角色无法释放技能
if not SkillRole:IsAvailable() then if not SkillRole:IsAvailable() then
BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量
BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血)
BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血) BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血)
BattleLogic.BuffMgr:TurnUpdate(4) -- 计算其他buff BattleLogic.BuffMgr:TurnUpdate(4) -- 计算其他buff
BattleLogic.BuffMgr:PassUpdate() -- 计算buff轮数 BattleLogic.BuffMgr:PassUpdate() -- 计算buff轮数
@ -224,8 +225,8 @@ function BattleLogic.TurnRound(debugTurn)
-- 行动 -- 行动
SkillRole.Event:DispatchEvent(BattleEventName.RoleTurnStart, SkillRole) -- 开始行动 SkillRole.Event:DispatchEvent(BattleEventName.RoleTurnStart, SkillRole) -- 开始行动
BattleLogic.Event:DispatchEvent(BattleEventName.RoleTurnStart, SkillRole) -- 开始行动 BattleLogic.Event:DispatchEvent(BattleEventName.RoleTurnStart, SkillRole) -- 开始行动
BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量 -- BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量
BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血) -- BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血)
-- 释放技能后,递归交换阵营 -- 释放技能后,递归交换阵营
SkillRole:CastSkill(function() SkillRole:CastSkill(function()
BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血) BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血)

View File

@ -50,6 +50,8 @@ BattleEventName = {
FinalDamage = indexAdd(), FinalDamage = indexAdd(),
FinalBeDamage = indexAdd(), FinalBeDamage = indexAdd(),
HitMiss = indexAdd(),
BeHitMiss = indexAdd(),
CritDamageReduceFactor = indexAdd(), -- 暴击伤害减免系数 CritDamageReduceFactor = indexAdd(), -- 暴击伤害减免系数
SkillCast = indexAdd(), -- 技能攻击前 SkillCast = indexAdd(), -- 技能攻击前

View File

@ -383,7 +383,15 @@ end
--执行完整的命中,伤害,暴击计算,返回命中,暴击 --执行完整的命中,伤害,暴击计算,返回命中,暴击
--skill造成伤害的技能 atkRole攻击者 defRole受击者 damageType伤害类型 baseFactor伤害系数 ignoreDef无视防御参数 dotType是持续伤害类型 --skill造成伤害的技能 atkRole攻击者 defRole受击者 damageType伤害类型 baseFactor伤害系数 ignoreDef无视防御参数 dotType是持续伤害类型
function BattleUtil.CalDamage(skill, atkRole, defRole, damageType, baseFactor, ignoreDef, dotType) function BattleUtil.CalDamage(skill, atkRole, defRole, damageType, baseFactor, ignoreDef, dotType)
if atkRole.isTeam and not defRole:IsDead() then --如果是队伍技能计算真实伤害则damageType为伤害值 -- 判断是否命中
if skill and not skill:CheckTargetIsHit(defRole) then
BattleLogic.Event:DispatchEvent(BattleEventName.HitMiss, atkRole, defRole, skill)
atkRole.Event:DispatchEvent(BattleEventName.HitMiss, defRole, skill)
defRole.Event:DispatchEvent(BattleEventName.BeHitMiss, atkRole, skill)
return 0
end
-- 如果是队伍技能计算真实伤害则damageType为伤害值
if atkRole.isTeam and not defRole:IsDead() then
return BattleUtil.ApplyDamage(skill, atkRole, defRole, damageType), false return BattleUtil.ApplyDamage(skill, atkRole, defRole, damageType), false
end end
@ -526,6 +534,15 @@ end
-- 检测命中
function BattleUtil.CheckIsHit(atkRole, defRole)
-- 是否命中: 命中 = 自身命中率 - 对方闪避率
local isHit = false
local hitRandom = Random.Range01()
local hitCondition = clamp(atkRole:GetRoleData(RoleDataName.Hit) - defRole:GetRoleData(RoleDataName.Dodge), 0, 1)
isHit = hitRandom <= hitCondition
return isHit
end
function BattleUtil.RandomAction(rand, action) function BattleUtil.RandomAction(rand, action)
if Random.Range01() <= rand and action then if Random.Range01() <= rand and action then