战斗同步

back_recharge
lvxinran 2020-10-29 16:36:10 +08:00
parent 845376c52c
commit 3ac886af17
17 changed files with 1990 additions and 29 deletions

View File

@ -0,0 +1,206 @@
local Effect = require("Modules/Battle/Logic/Base/Effect")
EffectCaster = {}
local effectPool = BattleObjectPool.New(function ()
return { type = 0, args = {}} -- type, {args, ...}
end)
local effectGroupPool = BattleObjectPool.New(function ()
return { chooseId = 0, effects = {}} -- chooseId, {effect1, effect2, ...}
end)
function EffectCaster:New()
local o = {}
setmetatable(o, {__index = self})
return o
end
function EffectCaster:Init(skill, effects, targets)
self.skill = skill
self.targets = targets or {}
self.effectList = {}
for i=1, #effects do
local v = effects[i]
local effectGroup = effectGroupPool:Get() -- chooseId, {effect1, effect2, ...}
effectGroup.chooseId = v[1] -- chooseId
for j=2, #v do -- effectList
local effect = effectPool:Get() -- type, {args, ...}
effect.type = v[j][1]
for k=2, #v[j] do
effect.args[k-1] = v[j][k]
end
effectGroup.effects[j-1] = effect
end
table.insert(self.effectList, effectGroup)
end
end
function EffectCaster:DoEffect(caster, target, eff, duration, skill)
local e = {type = 0, args = {}}
e.type = eff.type
for i=1, #eff.args do
e.args[i] = eff.args[i]
end
-- 检测被动技能对技能参数的影响
local function _PassiveCheck(pe)
if pe then
e = pe
end
end
caster.Event:DispatchEvent(BattleEventName.SkillEffectBefore, skill, e, _PassiveCheck)
target.Event:DispatchEvent(BattleEventName.BeSkillEffectBefore, skill, e, _PassiveCheck)
--
if Effect[e.type] then
Effect[e.type](caster, target, e.args, duration, skill)
end
end
function EffectCaster:takeEffect(caster, target, effects, effectIndex, duration, skill)
for k=1, #effects do
-- 如果不是第一个效果对列的第一个效果则判断是否命中
if k ~= 1 and effectIndex == 1 then
if self:CheckTargetIsHit(target) then
self:DoEffect(caster, target, effects[k], duration, skill)
end
else
self:DoEffect(caster, target, effects[k], duration, skill)
end
end
end
function EffectCaster:ChooseTarget()
--
self.effectTargets = {}
self.targetIsHit = {}
-- 先计算出技能的目标
for i=1, #self.effectList do
-- 是否重新选择目标
local isReTarget = true
if self.targets and self.targets[i] then
self.effectTargets[i] = self.targets[i]
-- 判断是否有有效目标
for _, role in ipairs(self.effectTargets[i]) do
if not role:IsRealDead() then
isReTarget = false
end
end
end
-- 重新选择目标
if isReTarget then
local effectGroup = self.effectList[i]
local chooseId = effectGroup.chooseId
self.effectTargets[i] = BattleUtil.ChooseTarget(self.skill.owner, chooseId)
-- 检测被动对攻击目标的影响
if i == 1 then
local function _PassiveTarget(targets)
self.effectTargets[i] = targets
end
self.skill.owner.Event:DispatchEvent(BattleEventName.SkillTargetCheck, _PassiveTarget)
end
end
end
end
-- 释放技能
-- func 技能释放完成回调
function EffectCaster:Cast()
-- 选择目标
self:ChooseTarget()
-- 对目标造成相应的效果
for i=1, #self.effectList do
local effectGroup = self.effectList[i]
local chooseId = effectGroup.chooseId
local arr = self.effectTargets[i]
if arr and #arr > 0 then
-- 效果延迟1帧生效
BattleLogic.WaitForTrigger(BattleLogic.GameDeltaTime, function()
local effects = effectGroup.effects
local weight = math.floor(chooseId % 10000 / 100)
local count = math.min(chooseId % 10, #arr)
if count == 0 then
count = #arr
end
-- 全部同时生效
for j=1, count do
if arr[j] and not arr[j]:IsRealDead() then
-- 检测是否命中
if i == 1 then
self.targetIsHit[arr[j]] = BattleUtil.CheckIsHit(self.skill.owner, arr[j])
end
self:takeEffect(self.skill.owner, arr[j], effects, i, self.skill.hitTime, self.skill)
end
end
end)
end
end
end
-- 遍历技能命中目标
function EffectCaster:ForeachTargets(func)
local targets = self:GetDirectTargets()
for _, role in ipairs(targets) do
if func then
func(role)
end
end
end
-- 获取直接选择目标Id
function EffectCaster:GetDirectChooseId()
local effectGroup = self.effectList[1]
local chooseId = effectGroup.chooseId
return chooseId
end
-- 获取技能的直接目标,和策划规定第一个效果的目标为直接效果目标,(包含miss的目标)
function EffectCaster:GetDirectTargets()
return self.effectTargets[1]
end
-- 获取直接目标不包含miss的目标可能为空
function EffectCaster: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 EffectCaster:GetMaxTargetNum()
local mainEffect = self.effectList[1]
if not mainEffect then
return 0
end
return BattleUtil.GetMaxTargetNum(mainEffect.chooseId)
end
-- 判断是否命中
function EffectCaster:CheckTargetIsHit(role)
return self.targetIsHit[role]
end
function EffectCaster:Dispose()
for _, effectGroup in ipairs(self.effectList) do
for k=1, #effectGroup.effects do
local effect = effectGroup.effects[k]
for j=1, #effect.args do
effect.args[j] = nil
end
effectPool:Put(effect)
effectGroup.effects[k] = nil
end
effectGroupPool:Put(effectGroup)
end
self.effectList = {}
end
return EffectCaster

View File

@ -4927,7 +4927,6 @@ local passivityList = {
end
role.Event:AddEvent(BattleEventName.RoleHit, OnRoleHit)
-- 释放技能时计算额外伤害
local OnSkillCast = function(skill)
if skill then

View File

@ -34,9 +34,6 @@ 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 ()
@ -69,34 +66,35 @@ function BattleLogic.Init(data, _userData, maxRound)
BattleLogic.IsEnd = false
BattleLogic.Result = -1
MonsterManager.Init()
RoleManager.Init()
SkillManager.Init()
OutDataManager.Init(fightData)
PassiveManager.Init()
BattleLogManager.Init(fightData, userData)
--监听英雄受到治疗
BattleLogic.Event:AddEvent(BattleEventName.RoleBeTreated,function (castRole, realTreat, treat)
if castRole.camp==0 then
LogBattle("我方 英雄治疗"..treat)
allHeroDamage=allHeroDamage+treat
else
LogBattle("敌方 英雄治疗"..treat)
allEnemyDamage=allEnemyDamage+treat
end
end)
-- 监听英雄受到治疗
BattleLogic.Event:AddEvent(BattleEventName.RoleBeTreated,function (castRole, realTreat, treat)
if castRole.camp==0 then
LogBattle("我方 英雄治疗"..treat)
allHeroDamage=allHeroDamage+treat
else
LogBattle("敌方 英雄治疗"..treat)
allEnemyDamage=allEnemyDamage+treat
end
end)
--监听英雄受到攻击
BattleLogic.Event:AddEvent(BattleEventName.RoleBeDamaged,function (defRole, atkRole, damage, bCrit, finalDmg, damageType, dotType)
--我方阵营总攻击
if atkRole.camp==0 then
allHeroDamage=allHeroDamage+damage
LogBattle("我方 英雄攻击"..damage)
--敌方阵营
else
allEnemyDamage=allEnemyDamage+damage
LogBattle("敌方 英雄攻击"..damage)
end
end)
--我方阵营总攻击
if atkRole.camp==0 then
allHeroDamage=allHeroDamage+damage
LogBattle("我方 英雄攻击"..damage)
--敌方阵营
else
allEnemyDamage=allEnemyDamage+damage
LogBattle("敌方 英雄攻击"..damage)
end
end)
end
-- 检测先手阵营
@ -126,17 +124,44 @@ function BattleLogic.StartOrder()
RoleManager.AddRole(enemyData[i], enemyData[i].position)
end
local playerMonsterList = fightData.playerData.monsterList
if playerMonsterList then
for i=1, #playerMonsterList do
MonsterManager.AddMonster(playerMonsterList[i])
end
end
local enemyMonsterList = fightData.enemyData[1].monsterList
if enemyMonsterList then
for i=1, #enemyMonsterList do
MonsterManager.AddMonster(enemyMonsterList[i])
end
end
else
RoleManager.ClearEnemy()
local orderList = fightData.enemyData[BattleLogic.CurOrder]
for i=1, #orderList do
RoleManager.AddRole(orderList[i], orderList[i].position)
end
MonsterManager.ClearEnemy()
local enemyMonsterList = orderList.monsterList
if enemyMonsterList then
for i=1, #enemyMonsterList do
MonsterManager.AddMonster(enemyMonsterList[i])
end
end
end
-- 检测先后手
BattleLogic.CheckFirstCamp()
-- 开始战斗,延时一帧执行,避免战斗还没开始就释放了技能
BattleLogic.TurnRoundNextFrame()
-- 战斗开始
BattleLogic.Event:DispatchEvent(BattleEventName.BattleStart)
end
-- 获取当前轮数
@ -186,6 +211,10 @@ function BattleLogic.TurnRound(debugTurn)
end
-- 第一次进入 或者 本轮结束 初始化流程状态
if CurRound == 0 or (CurSkillPos[0] == 6 and CurSkillPos[1] == 6) then
if CurRound ~= 0 then
-- 上一轮结束
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoundEnd, CurRound)
end
CurRound = CurRound + 1
CurCamp = BattleLogic.FirstCamp -- 判断先手阵营
CurSkillPos[0] = 0
@ -197,8 +226,11 @@ function BattleLogic.TurnRound(debugTurn)
)
-- 轮数变化
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoundChange, CurRound)
-- 开始
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoundStart, CurRound)
--轮数变化后延时0.2秒用于初始化监听回合数被动的初始化
BattleLogic.WaitForTrigger(0.2,function()
-- 进入新轮
BattleLogic.CheckBattleLogic()
end)
else
@ -215,7 +247,7 @@ function BattleLogic.CheckBattleLogic()
if CurRound > MaxRound then
return
end
BattleLogManager.Log(
BattleLogManager.Log(
"Camp Change",
"camp", CurCamp
)
@ -365,6 +397,9 @@ function BattleLogic.Update()
--如果有英雄有可以复活的技能,先执行技能逻辑,最后判断死亡人数 by:王振兴
-- 检测角色状态
RoleManager.Update()
-- 检测灵兽状态
MonsterManager.Update()
end
-- 战斗结束

View File

@ -5,18 +5,24 @@ local function indexAdd()
end
BattleEventName = {
BattleStart = indexAdd(),
BattleOrderChange = indexAdd(),
BattleOrderEnd = indexAdd(),
BeforeBattleEnd = indexAdd(),
BattleEnd = indexAdd(),
AddRole = indexAdd(),
AddMonster = indexAdd(),
RemoveRole = indexAdd(),
RemoveMonster = indexAdd(),
MpChanged = indexAdd(),
MpAdd = indexAdd(),
MpSub = indexAdd(),
BattleRoleDead = indexAdd(),
BattleSkillUsable = indexAdd(),
BattleRoundStart = indexAdd(),
BattleRoundChange = indexAdd(),
BattleRoundEnd = indexAdd(),
RoleBeDamaged = indexAdd(),
RoleDamage = indexAdd(),
@ -37,7 +43,6 @@ BattleEventName = {
RoleKill = indexAdd(),
RoleRevive = indexAdd(),
RolePropertyChanged = indexAdd(),
RoleCDChanged = indexAdd(),
RoleTurnStart = indexAdd(), -- 角色回合开始
RoleTurnEnd = indexAdd(), -- 角色回合结束
RoleRageGrow = indexAdd(), -- 角色怒气成长
@ -260,4 +265,9 @@ OutDataName = {
PerpleGloryItemNum = 3,
OrangeGloryItemNum = 4,
MisteryLiquidUsedTimes = 5
}
BattleUnitType = {
Role = 1,
Monster = 2
}

View File

@ -852,4 +852,26 @@ function BattleUtil.AddProp(role, prop, value, ct)
elseif ct == 4 then --乘减算(百分比属性减算)
role.data:SubPencentValue(BattlePropList[prop], value)
end
end
-- 比较值(默认返回true)
-- 0不比较返回默认true
-- 1大于
-- 2小于
-- 3等于
-- 4大于等于
-- 5小于等于
function BattleUtil.CompareValue(v1, v2, comType)
if comType == 1 then
return v1 > v2
elseif comType == 2 then
return v1 < v2
elseif comType == 3 then
return v1 == v2
elseif comType == 4 then
return v1 >= v2
elseif comType == 5 then
return v1 <= v2
end
return true
end

View File

@ -0,0 +1,48 @@
require("Modules.Battle.Logic.Monster.MonsterSkill.MSkillManager")
Monster = {}
function Monster:New()
local o = {
data=RoleData.New(),
Event = BattleEvent:New()
}
setmetatable(o, self)
self.__index = self
return o
end
-- 初始化
function Monster:Init(data)
self.type = BattleUnitType.Monster
self.camp = data.camp
self.position = data.position
self.star = data.star
self.uid= data.id
self.roleData = data
self.data:Init(self, data.property)
self.Event:ClearEvent()
self.skillGroup = MSkillManager.CreateMSkillGroup(self, data.skill)
end
function Monster:GetRoleData(property)
local tarPro = self.data:GetData(property)
return tarPro
end
function Monster:GetCamp()
return self.camp
end
function Monster:GetPosition()
return self.position
end
function Monster:GetStar()
return self.star
end
-- 数据回收
function Monster:Dispose()
end
return Monster

View File

@ -0,0 +1,47 @@
require("Modules.Battle.Logic.Monster.Monster")
MonsterManager = {}
local this = MonsterManager
function MonsterManager.Init()
this.monsterList = {}
-- 初始化灵兽技能管理
MSkillManager.Init()
end
function MonsterManager.AddMonster(data)
local index = data.camp * 6 + data.position
local monster = Monster:New()
monster:Init(data)
if not this.monsterList then
this.monsterList = {}
end
this.monsterList[index] = monster
BattleLogic.Event:DispatchEvent(BattleEventName.AddMonster, monster)
end
function MonsterManager.Update()
end
-- 切换时使用(已废弃)
function MonsterManager.ClearEnemy()
local removePos = {}
for pos, obj in pairs(this.monsterList) do
if obj.camp == 1 then
removePos[pos] = 1
BattleLogic.Event:DispatchEvent(BattleEventName.RemoveMonster, obj)
obj:Dispose()
end
end
for pos, _ in pairs(removePos) do
this.monsterList[pos] = nil
end
end
return MonsterManager

View File

@ -0,0 +1,57 @@
MCondition = {}
local this = MCondition
local _ConditionConfig = {
[0] = function(skill, condition) --0:无限制条件
return true
end,
[1] = function(skill, condition) --1我方任意神将生命百分比 【比较类型】 N万分比
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
-- 获取该技能相同阵营人物
local roleList = RoleManager.Query(function(role)
return role.camp == skill.owner.camp
end)
-- 判断
for _, role in ipairs(roleList) do
local hpf = role:GetRoleData(RoleDataName.Hp) / role:GetRoleData(RoleDataName.MaxHp)
if BattleUtil.CompareValue(hpf, comValue/10000, comType) then
return true
end
end
return false
end,
[2] = function(skill, condition) --2:回合数 【比较类型】 N
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
-- 获取当前回合
local curRound = BattleLogic.GetCurRound()
return BattleUtil.CompareValue(curRound, comValue, comType)
end,
[4] = function(skill, condition) --4:行动单位的职业设定 【比较类型】 N
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
-- 当前释放技能的单位的职业
local professionId = skill.owner.professionId
return professionId == comValue
end
}
-- 条件检测
function MCondition.CheckCondition(skill, condition)
if not condition then
return true
end
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
return _ConditionConfig[conId](skill, condition)
end
return MCondition

View File

@ -0,0 +1,145 @@
MSkill = {}
function MSkill:New()
local o = {}
setmetatable(o, self)
self.__index = self
return o
end
function MSkill:Init(owner, group, index, skillData)
LogBattle("MSkill Init")
self.owner = owner
self.group = group
self.groupIndex = index
self.skillData = skillData
self.isKill = false --是否技能击杀目标
self.isAdd = false
self.isRage = false
self.type = BattleSkillType.Monster
self.curCastCount = 0
self.maxCastCount = self.skillData.maxCount
self.curRoundCount = 0
self.maxRoundCount = self.skillData.maxRoundCount
LogError("最大释放次数"..self.maxCastCount.."最大回合次数"..self.maxRoundCount)
-- 将技能加入触发检测
MTrigger.AddSkill(self.skillData.triggerId, self.skillData.triggerCondition, self)
local effectData = self.skillData.effect
self.id = effectData[1] -- 技能ID
self.hitTime = effectData[2] -- 效果命中需要的时间
self.continueTime = effectData[3] -- 命中后伤害持续时间
self.attackCount = effectData[4] -- 伤害持续时间内伤害次数
-- 初始化
local effects = {}
for i=5, #effectData do
table.insert(effects, effectData[i])
end
self.effectCaster = EffectCaster:New()
self.effectCaster:Init(self, effects, targets)
--监听回合开始消息
BattleLogic.Event:AddEvent(BattleEventName.BattleRoundStart,function (round)
self.curRoundCount = 0
end)
end
-- 是否可以释放
function MSkill:canCastSkill()
-- 超出最大次数限制
if self.curCastCount >= self.maxCastCount then
return false
end
-- 超出轮数最大次数限制
if self.curRoundCount >= self.maxRoundCount then
return false
end
return true
end
function MSkill:Cast(func)
self.castDoneFunc = func
self.isTriggePassivity=false
self.triggerPassivityId={}
-- 技能效果生效
if self.effectCaster then
self.effectCaster:Cast()
end
-- 释放技能开始
self.owner.Event:DispatchEvent(BattleEventName.SkillCast, self)
BattleLogic.Event:DispatchEvent(BattleEventName.SkillCast, self)
-- 只对效果1的目标发送事件效果1是技能的直接伤害目标
self.effectCaster:ForeachTargets(function(role)
role.Event:DispatchEvent(BattleEventName.BeSkillCastEnd, self)
end)
--技能的施法时间计算根据当前目标id关联的持续时间取其中时间最长的一个
local duration = self.hitTime + self.continueTime
-- 结算时间向后延长0.2秒,避免在效果结算完成前就结束了技能释放
BattleLogic.WaitForTrigger(duration + 0.8, function()
self.owner.Event:DispatchEvent(BattleEventName.SkillCastEnd, self)
BattleLogic.Event:DispatchEvent(BattleEventName.SkillCastEnd, self)
-- 只对效果1的目标发送事件效果1是技能的直接伤害目标
self.effectCaster:ForeachTargets(function(role)
role.Event:DispatchEvent(BattleEventName.BeSkillCastEnd, self)
end)
-- 技能结束
self:EndSkill()
--技能消息发送完后 iskill 设置为false
self.isKill=false
end)
self.curRoundCount = self.curRoundCount+1
self.curCastCount =self.curCastCount+1
end
function MSkill:GetOwner()
return self.owner
end
function MSkill:GetGroupIndex()
return self.groupIndex
end
-- 获取直接选择目标的ID
function MSkill:GetDirectChooseId()
return self.effectCaster:GetDirectChooseId()
end
-- 获取技能的直接目标,和策划规定第一个效果的目标为直接效果目标,(包含miss的目标)
function MSkill:GetDirectTargets()
return self.effectCaster:GetDirectTargets()
end
-- 获取直接目标不包含miss的目标可能为空
function MSkill:GetDirectTargetsNoMiss()
return self.effectCaster:GetDirectTargetsNoMiss()
end
-- 获取技能目标最大人数
function MSkill:GetMaxTargetNum()
return self.effectCaster:GetMaxTargetNum()
end
-- 判断是否命中
function MSkill:CheckTargetIsHit(role)
return self.effectCaster:CheckTargetIsHit(role)
end
-- 结束技能
function MSkill:EndSkill()
-- 技能后摇
-- 技能结束后摇后结束技能释放
BattleLogic.WaitForTrigger(0.3, function()
-- 结束回调
self.isTriggePassivity=false
self.triggerPassivityId={}
if self.castDoneFunc then self.castDoneFunc() end
end)
--
self.effectTargets = {}
end
return MSkill

View File

@ -0,0 +1,31 @@
MSkillGroup = {}
function MSkillGroup:New()
local o = {}
setmetatable(o, self)
self.__index = self
return o
end
-- 初始化数据
function MSkillGroup:Init(monster, groupData)
LogBattle("MSkillGroup Init")
self.owner = monster
self.skillGroupData = groupData
-- 创建技能
self.skillList = {}
for index, data in ipairs(self.skillGroupData) do
self.skillList[index] = MSkillManager.CreateMSkill(monster, self, index, data[1])
end
end
function MSkillGroup:GetOwner()
return self.owner
end
function MSkillGroup:Run()
end
return MSkillGroup

View File

@ -0,0 +1,42 @@
require("Modules.Battle.Logic.Monster.MonsterSkill.MTrigger")
require("Modules.Battle.Logic.Monster.MonsterSkill.MSkill")
require("Modules.Battle.Logic.Monster.MonsterSkill.MSkillGroup")
MSkillManager = {}
local this = MSkillManager
function this.Init()
this.MSkillGroupList = {} -- 技能组列表
this.MSkillList = {} -- 技能列表
MTrigger.Init()
end
-- 创建一个技能组
function this.CreateMSkillGroup(monster, skillGroupData)
local index = monster:GetCamp() * 6 + monster:GetPosition()
if not this.MSkillGroupList then
this.MSkillGroupList = {}
end
if not this.MSkillGroupList[index] then
this.MSkillGroupList[index] = MSkillGroup:New()
end
this.MSkillGroupList[index]:Init(monster, skillGroupData)
end
-- 创建一个技能
function this.CreateMSkill(monster, group, index, skilldata)
local owner = group:GetOwner()
local m_index = owner:GetCamp() * 6 + owner:GetPosition()
if not this.MSkillList then
this.MSkillList = {}
end
if not this.MSkillList[m_index] then
this.MSkillList[m_index] = {}
end
if not this.MSkillList[m_index][index] then
this.MSkillList[m_index][index] = MSkill:New()
end
this.MSkillList[m_index][index]:Init(monster, group, index, skilldata)
end
return MSkillManager

View File

@ -0,0 +1,145 @@
require("Modules.Battle.Logic.Monster.MonsterSkill.MCondition")
MTrigger = {}
local this = MTrigger
local _TriggerConfig = {
[1] = { --1敌方单位行动前
event = BattleEventName.RoleTurnStart,
triggerFunc = function(skill, ...)
local args = {...}
local role = args[1]
return role.camp ~= skill.owner.camp
end
},
[2] = {--2敌方单位行动后
event = BattleEventName.RoleTurnEnd,
triggerFunc = function(skill, ...)
local args = {...}
local role = args[1]
return role.camp ~= skill.owner.camp
end
},
[3] = {--3我方单位行动前
event = BattleEventName.RoleTurnStart,
triggerFunc = function(skill, ...)
local args = {...}
local role = args[1]
return role.camp == skill.owner.camp
end
},
[4] = {--4我方单位行动后
event = BattleEventName.RoleTurnEnd,
triggerFunc = function(skill, ...)
local args = {...}
local role = args[1]
return role.camp == skill.owner.camp
end
},
[5] = {--5战前
event = BattleEventName.BattleStart,
triggerFunc = function(skill, ...)
return true
end
},
[6] = {--6奇数回合开始前
event = BattleEventName.BattleRoundStart,
triggerFunc = function(skill, ...)
local args = {...}
local curRound = args[1]
return curRound%2 == 1
end
},
[7] = {--7偶数回合开始前
event = BattleEventName.BattleRoundStart,
triggerFunc = function(skill, ...)
local args = {...}
local curRound = args[1]
return curRound%2 == 0
end
},
[8] = {--8奇数回合结束后
event = BattleEventName.BattleRoundEnd,
triggerFunc = function(skill, ...)
local args = {...}
local curRound = args[1]
return curRound%2 == 1
end
},
[9] = {--9偶数回合结束后
event = BattleEventName.BattleRoundEnd,
triggerFunc = function(skill, ...)
local args = {...}
local curRound = args[1]
return curRound%2 == 0
end
},
[10] = {--10回合开始前
event = BattleEventName.BattleRoundEnd,
triggerFunc = function(skill, ...)
return true
end
},
[11] = {--11回合结束后
event = BattleEventName.BattleRoundEnd,
triggerFunc = function(skill, ...)
return true
end
},
[12] = {--12我方单位释放技能后
event = BattleEventName.SkillCastEnd,
triggerFunc = function(skill, ...)
local args = {...}
local castSkill = args[1]
return castSkill.owner.camp == skill.owner.camp
end
},
}
function MTrigger.Init()
this.TriggerList ={}
this.InitListener()
end
-- 初始化事件监听
function this.InitListener()
for triggerId, config in pairs(_TriggerConfig) do
BattleLogic.Event:AddEvent(config.event, function(...)
-- 判断是否有需要触发的技能
local triggerSkill = this.TriggerList[triggerId]
if not triggerSkill then
return
end
for _, trigger in ipairs(triggerSkill) do
local skill = trigger.skill
local condition = trigger.condition
-- 判断技能是否可以释放
if skill:canCastSkill() then
-- 判断是否符合触发类型条件
if config.triggerFunc(skill, ... ) then
-- 检测是否符合子条件
if MCondition.CheckCondition(skill, condition) then
-- 加入技能释放对列
SkillManager.AddMonsterSkill(skill)
end
end
end
end
end)
end
end
-- 技能加入检测
function MTrigger.AddSkill(triggerId, condition, skill)
LogBattle("AddSkill "..triggerId)
if not this.TriggerList then
this.TriggerList = {}
end
if not this.TriggerList[triggerId] then
this.TriggerList[triggerId] = {}
end
table.insert(this.TriggerList[triggerId], {condition = condition, skill = skill})
end
return MTrigger

View File

@ -0,0 +1,125 @@
RoleData = {}
RoleData.__index = RoleData
local max = math.max
local floor = math.floor
local function isFactor(name)
return name > 7
end
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},
orginData={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)
return instance
end
function RoleData:Init(role, data)
self.role = role
local max = max(#data, #self.data)
for i=1, max do
self.data[i] = BattleUtil.ErrorCorrection(data[i] or 0)
self.orginData[i] = BattleUtil.ErrorCorrection(data[i] or 0)
end
end
function RoleData:GetData(name)
return self.data[name]
end
function RoleData:GetOrginData(name)
return self.orginData[name]
end
function RoleData:SetValue(name, 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)
BattleLogManager.Log(
"property change",
"camp", self.role.camp,
"position", self.role.position,
"propId", name,
"value", value)
end
end
end
function RoleData:AddValue(name, delta)
if delta < 0 or not self.data[name] then --delta必须非负
return 0
end
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] then
local delta
if isFactor(name) then
delta = BattleUtil.ErrorCorrection(self.orginData[name] * pencent)
else
delta = floor(self.orginData[name] * pencent)
end
return self:AddValue(name, delta)
end
return 0
end
function RoleData:SubDeltaValue(name, delta)
if not delta or delta < 0 or not self.data[name] then --delta必须非负
return 0
end
if self.data[name] then
self:SetValue(name, self.data[name] - delta)
end
return delta
end
function RoleData:SubValue(name, delta)
if delta < 0 or not self.data[name] then --delta必须非负
return 0
end
local orVal = self.data[name]
if orVal then
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] then
local delta
if isFactor(name) then
delta = BattleUtil.ErrorCorrection(self.orginData[name] * pencent)
else
delta = floor(self.orginData[name] * pencent)
end
return self:SubValue(name, delta)
end
return 0
end
function RoleData:CountValue(name, value, ct)
if ct == 1 then
self:AddValue(name, value)
elseif ct == 2 then
self:AddPencentValue(name, value)
elseif ct == 3 then
self:SubValue(name, value)
elseif ct == 4 then
self:SubPencentValue(name, value)
end
end
--Debug
function RoleData:Foreach(func)
for k,v in ipairs(self.data) do
func(k, v)
end
end

View File

@ -0,0 +1,550 @@
RoleLogic = {}
RoleLogic.__index = RoleLogic
--local RoleLogic = RoleLogic
--local RoleDataName = RoleDataName
--local BattleLogic = BattleLogic
local Random = Random
local floor = math.floor
local max = math.max
local min = math.min
function RoleLogic.New()
local instance = {uid=0,roleData=0,data=RoleData.New(),camp=0,name=0,aiIndex=1,position=0,sp=0,spPass=0,
shield=BattleList.New(),
exCalDmgList=BattleList.New(),
proTranList=BattleList.New(),
buffFilter=BattleList.New(),
Event = BattleEvent:New(),passiveList={},isDead=false,IsDebug=false}
setmetatable(instance, RoleLogic)
return instance
end
function RoleLogic:Init(uid, data, position)
data.star = data.star or 1
self.type = BattleUnitType.Role
self.uid = uid
self.position = position
self.roleData = data
self.roleId=data.roleId
self.data:Init(self, data.property)
self.isDead = self:GetRoleData(RoleDataName.Hp) <= 0
self.isRealDead = self.isDead
self.camp = data.camp --阵营 0我方 1敌方
self.name = data.name
self.element = data.element
self.professionId = data.professionId
self.star = data.star or 1
-- LogError("英雄uid".. self.roleId .." " .. self.star)
self.shield:Clear() --护盾列表
self.exCalDmgList:Clear() --额外计算伤害列表
self.buffFilter:Clear() --buff屏蔽列表
self.proTranList:Clear() --属性转换列表
self.Event:ClearEvent()
self.skill = data.skill
self.superSkill = data.superSkill
--首次读条时间=速度/20*(等级+10
self.sp = 0
local time = self:GetRoleData(RoleDataName.Speed)/(20*(self:GetRoleData(RoleDataName.Level)+10))
self.spPass = floor( BattleUtil.ErrorCorrection(time) * BattleLogic.GameFrameRate)
-- 初始化怒气值默认2
self.Rage = 2
self.RageGrow = 2 -- 普通技能怒气成长
self.SuperSkillRage = 4 -- 技能需要释放的怒气值默认为4
self.NoRageRate = 0 -- 不消耗怒气值的概率
--
self.passiveList = {}
if data.passivity and #data.passivity > 0 then
for i = 1, #data.passivity do
local v = data.passivity[i]
local id = v[1]
local args = {}
for j = 2, #v do
args[j-1] = v[j]
end
if BattleUtil.Passivity[id] then
BattleUtil.Passivity[id](self, args)
-- 加入被动列表
table.insert(self.passiveList, {id, args})
end
end
end
-- 初始怒气值放在被动之后计算,使被动对初始怒气的影响生效
self.Rage = self.Rage + self:GetRoleData(RoleDataName.InitRage)-- 当前怒气值
--
self.aiOrder = data.ai
self.aiIndex = 1
self.aiTempCount = 0
self.IsDebug = false
self.enemyType = EnemyType.normal
self.lockTarget = nil --嘲讽
self.ctrl_dizzy = false --眩晕 不能释放所有技能
self.ctrl_slient = false --沉默 只能1技能
self.ctrl_palsy = false --麻痹 只能2技能
self.ctrl_noheal = false --禁疗
self.ctrl_blind = false --致盲
self.deadFilter = true -- 控制死亡置为false则角色暂时无法死亡
self.reliveFilter = true -- 控制复活的标志位置为false角色将不再享受复活效果
self.reliveHPF = 1
self.IsCanAddSkill = true -- 是否可以追加技能
end
-- 添加一个被动技能
function RoleLogic:AddPassive(id, args, isRepeat)
--判断是否可以叠加
if not isRepeat then
-- 不可以叠加, 如果重复则不再加入
for _, pst in ipairs(self.passiveList) do
if pst[1] == id then
return
end
end
end
-- 被动生效
BattleUtil.Passivity[id](self, args)
-- 加入被动列表
table.insert(self.passiveList, {id, args})
end
--
function RoleLogic:CanCastSkill()
return self.sp >= self.spPass and not self.IsDebug
end
-- 废弃的方法
function RoleLogic:GetSkillCD()
return max(self.spPass - self.sp, 0)
end
-- 废弃的方法
function RoleLogic:AddSkillCD(value, type)
if value == 0 then --为0直接清CD
self.sp = self.spPass
return
end
local cdTotal = self.spPass
local delta = 0
if type == 1 then --加算
delta = floor(value * BattleLogic.GameFrameRate)
elseif type == 2 then --乘加算(百分比属性加算)
delta = floor(value * cdTotal)
elseif type == 3 then --减算
delta = -floor(value * BattleLogic.GameFrameRate)
elseif type == 4 then --乘减算(百分比属性减算)
delta = -floor(value * cdTotal)
end
if delta > 0 then --加cd加cd最大值
self.spPass = self.spPass + delta
else --减cd减cd当前值
delta = -delta
self.sp = min(self.sp + delta, self.spPass)
end
end
-- 改变怒气值
function RoleLogic:AddRage(value, type)
-- 角色身上有无敌盾,不扣除怒气 by:wangzhenxing 2020/08/10 14:56
if (type==3 or type==4) and BattleLogic.BuffMgr:HasBuff(self, BuffName.Shield, function (buff) return buff.shieldType and buff.shieldType == ShieldTypeName.AllReduce end) then
LogBattle("角色身上有无敌盾,不扣除怒气")
return
end
local delta = 0
if type == 1 then --加算
delta = value
elseif type == 2 then --乘加算(百分比属性加算)
delta = floor(value * self.SuperSkillRage)
elseif type == 3 then --减算
delta = -value
elseif type == 4 then --乘减算(百分比属性减算)
delta = -floor(value * self.SuperSkillRage)
end
--
self.Event:DispatchEvent(BattleEventName.RoleRageChange, delta)
--怒气值不可为负值
self.Rage = max(self.Rage + delta, 0)
end
function RoleLogic:GetRoleData(property)
local tarPro = self.data:GetData(property)
local item
for i=1, self.proTranList.size do
item = self.proTranList.buffer[i]
if item.proName == property then
local value
if item.changeType == 1 then --加算
value = item.tranFactor
elseif item.changeType == 2 then --乘加算(百分比属性加算)
value = BattleUtil.ErrorCorrection(self.data:GetData(item.tranProName) * item.tranFactor)
elseif item.changeType == 3 then --减算
value = -item.tranFactor
elseif item.changeType == 4 then --乘减算(百分比属性减算)
value = -BattleUtil.ErrorCorrection(self.data:GetData(item.tranProName) * item.tranFactor)
end
tarPro = tarPro + value
end
end
return tarPro
end
--proA替换的属性factor系数proB被替换的属性, duration持续时间
--读取proB属性时得到的值为proB + proA * factor
function RoleLogic:AddPropertyTransfer(proA, factor, proB, ct, duration)
local proTran = {proName = proB, tranProName = proA, tranFactor = factor, changeType = ct}
self.proTranList:Add(proTran)
local index = self.proTranList.size
if duration then
BattleLogic.WaitForTrigger(duration, function ()
self:RemovePropertyTransfer(index, proTran)
end)
end
return index, proTran
end
-- 删除临时属性
function RoleLogic:RemovePropertyTransfer(index, tran)
if index <= self.proTranList.size and tran == self.proTranList.buffer[index] then
self.proTranList:Remove(index)
end
end
-- 是否为指定id指定星级的英雄 by:王振兴 2020/07/29
function RoleLogic:IsAssignHeroAndHeroStar(id,star)
if self.roleId==id and self.star==star then
return true
end
return false
end
function RoleLogic:AddBuff(buff)
if self:IsRealDead() then
BattleLogic.BuffMgr:PutBuff(buff)
return
end
-- buff的miss率
local missF = 0
-- 检测被动对miss概率的影响
local cl = {}
local function _CallBack(v, ct)
if v then
table.insert(cl, {v, ct})
end
end
BattleLogic.Event:DispatchEvent(BattleEventName.RoleAddBuffMiss, _CallBack, self, buff)
missF = BattleUtil.CountChangeList(missF, cl)
-- 如果概率为0 或者没有miss
if missF == 0 or not BattleUtil.RandomAction(missF, function() BattleLogic.BuffMgr:PutBuff(buff) end) then
for i=1, self.buffFilter.size do
if self.buffFilter.buffer[i](buff) then
BattleLogic.BuffMgr:PutBuff(buff)
return
end
end
BattleLogic.BuffMgr:AddBuff(self, buff)
end
end
function RoleLogic:Dispose()
end
-- 判断角色是否可以释放技能
function RoleLogic:IsAvailable()
-- 眩晕 -- 死亡
if self.ctrl_dizzy or self:IsRealDead() then
return false
end
-- 沉默麻痹同时存在
if self.ctrl_palsy and self.ctrl_slient then
return false
end
-- 麻痹同时怒气不足
if self.ctrl_palsy and self.Rage < self.SuperSkillRage then
return false
end
return true
end
-- 释放技能
function RoleLogic:SkillCast(skill, func)
local _CastDone = function()
if func then
func()
end
end
-- 角色不可用直接结束技能释放
if not skill or not self:IsAvailable() then
_CastDone()
return
end
-- 没有麻痹,释放普通攻击
if skill.type == BattleSkillType.Normal and not self.ctrl_palsy then
local function _CheckRage()
-- 后成长怒气
if skill.isRage then
-- 检测被动技能对怒气成长的影响
local grow = self.RageGrow
local _RageGrowPassivity = function(finalGrow)
grow = finalGrow
end
self.Event:DispatchEvent(BattleEventName.RoleRageGrow, grow, _RageGrowPassivity)
--
self.Rage = self.Rage + grow
end
-- 释放完成
_CastDone()
end
-- 释放普技
skill:Cast(_CheckRage)
-- 没有沉默,释放大技能
elseif (skill.type == BattleSkillType.Special or skill.type==BattleSkillType.Extra or skill.type==BattleSkillType.DeadSkill) and not self.ctrl_slient then
-- 先消耗怒气
if skill.isRage then
if self.Rage < self.SuperSkillRage then
-- 怒气值不足不能释放技能
_CastDone()
return
end
-- 检测被动技能对怒气消耗的影响
local costRage = self.SuperSkillRage
local noRageRate = self.NoRageRate
local _RageCostPassivity = function(rate, cost)
noRageRate = noRageRate + rate
costRage = costRage + cost
end
self.Event:DispatchEvent(BattleEventName.RoleRageCost, costRage, noRageRate, _RageCostPassivity)
-- 计算消耗怒气的概率,并消耗怒气
local costRate = 1 - noRageRate
costRate = costRate > 1 and 1 or costRate
costRate = costRate < 0 and 0 or costRate
BattleUtil.RandomAction(costRate, function()
self.Rage = self.Rage - costRage
end)
end
-- 释放绝技
skill:Cast(_CastDone)
-- 没有符合条件的技能直接进入下一个技能检测
else
_CastDone()
end
end
-- 加入一个技能
-- type 加入的技能类型
-- targets 指定目标
-- 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
--加入额外技能,用于额外释放技能 by:王振兴
function RoleLogic:InsertExtraSkill(id,type)
local effectData=BattleUtil.GetExtraSkillbyId(id)
if effectData then
local skillType=BattleSkillType.Extra
--如果type为1则按绝技处理,不为1的话按额外技能处理额外技能因为被动判断会判断是否是绝技类型所以不会触发
if type==1 then
skillType=BattleSkillType.Special
end
--和老史,佳琦确认果 附加技能算绝技 被沉默无法释放 可以套娃 递归触发 by:王振兴
SkillManager.InsertSkill(self, effectData, skillType, nil, true, false)
BattleLogManager.Log(
"Add Skill",
"camp", self.camp,
"pos", self.position,
"type", skillType,
"isRage", tostring(false),
"isAdd", tostring(true),
"targets", targets and #targets or "0"
)
end
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
-- 正常触发技能
function RoleLogic:CastSkill(func)
-- 设置轮转方法
SkillManager.SetTurnRoundFunc(func)
-- 没有沉默
if not self.ctrl_slient and self.Rage >= self.SuperSkillRage then
-- 释放大技能
self:AddSkill(BattleSkillType.Special, true, false, nil)
return
end
-- 没有麻痹 释放普通技能
if not self.ctrl_palsy then
self:AddSkill(BattleSkillType.Normal, true, false, nil)
return
end
end
-- 强制释放技能,测试技能时使用
-- type 追加的技能类型 1=普技 2=特殊技
-- targets 追加技能的目标 nil则自动选择目标
-- func 追加技能释放完成回调
function RoleLogic:ForceCastSkill(type, targets, func)
-- 清除技能控制
self.ctrl_dizzy = false --眩晕 不能释放技能
self.ctrl_slient = false --沉默 只能1技能
self.ctrl_palsy = false --麻痹 只能2技能
-- 设置轮转方法
SkillManager.SetTurnRoundFunc(func)
-- 释放技能
if type == 1 and self.skill then
self:AddSkill(BattleSkillType.Normal, true, false, nil)
elseif type == 2 and self.superSkill then
if self.Rage < self.SuperSkillRage then
self.Rage = self.SuperSkillRage
end
self:AddSkill(BattleSkillType.Special, true, false, nil)
end
end
-- 判断是否可以去死了
function RoleLogic:IsCanDead()
-- 暂时不能死
if not self.deadFilter then
return false
end
-- 还有我的技能没有释放,不能死啊
if SkillManager.HaveMySkill(self) then
return false
end
return true
end
-- 真的去死
function RoleLogic:GoDead()
if self:IsCanDead() then
self.isRealDead = true
self.Rage = 0
BattleLogic.BuffMgr:ClearBuff(self)
self.Event:DispatchEvent(BattleEventName.RoleRealDead, self)
BattleLogic.Event:DispatchEvent(BattleEventName.RoleRealDead, self)
return true
end
return false
end
-- 设置是否可以死亡
function RoleLogic:SetDeadFilter(filter)
self.deadFilter = filter
end
-- 要死了
function RoleLogic:SetDead()
self.isDead = true
RoleManager.AddDeadRole(self)
end
-- 判断是否死亡
function RoleLogic:IsDead()
return self.isDead
end
function RoleLogic:IsRealDead()
return self.isRealDead
end
-- 是否可以复活
function RoleLogic:IsCanRelive()
if not self.reliveFilter then
return false
end
if not self.isRealDead then
return false
end
return true
end
-- 复活吧, 真的去世后才能复活
function RoleLogic:Relive()
if self:IsCanRelive() then
-- 没有指定血量则满血
self.isDead = false
self.isRealDead = false
local maxHp = self.data:GetData(RoleDataName.MaxHp)
self.data:SetValue(RoleDataName.Hp, floor(self.reliveHPF * maxHp))
-- 发送复活事件
self.Event:DispatchEvent(BattleEventName.RoleRelive, self)
BattleLogic.Event:DispatchEvent(BattleEventName.RoleRelive, self)
return true
end
return false
end
-- 设置是否可以死亡
function RoleLogic:SetReliveFilter(filter)
self.reliveFilter = filter
end
--,hpf 复活时拥有的血量的百分比
function RoleLogic:SetRelive(hpf)
-- 判断是否可以复活
if self:IsCanRelive() then
self.reliveHPF = hpf or 1
RoleManager.AddReliveRole(self)
end
return false
end
function RoleLogic:Update()
end

View File

@ -0,0 +1,341 @@
RoleManager = {}
local this = RoleManager
-- 将死之人
local _DeadRoleList = {}
-- 重生之人
local _ReliveRoleList = {}
-- 所有角色
local PosList = {}
-- 删除节点
local removeObjList = BattleList.New()
-- 角色对象池
local rolePool = BattleObjectPool.New(function ()
return RoleLogic.New()
end)
local bMyAllDead
local bEnemyAllDead
-- 初始化
function this.Init()
bMyAllDead = false
bEnemyAllDead = false
this.Clear()
end
-- 角色数据添加
local curUid
function this.AddRole(roleData, position)
if not curUid then
curUid = 0
end
curUid = curUid + 1
local role = rolePool:Get()
role:Init(curUid, roleData, position)
-- objList:Add(curUid, role)
if roleData.camp == 0 then
PosList[position] = role -- 1-6 我方英雄
else
PosList[position + 6] = role-- 7-12 敌方英雄
end
if not role:IsRealDead() then
BattleLogic.Event:DispatchEvent(BattleEventName.AddRole, role)
end
end
--
function this.Update()
bMyAllDead = true
bEnemyAllDead = true
for _, v in pairs(PosList) do
if not v:IsRealDead() then
v:Update()
if v.camp == 0 then
bMyAllDead = false
else
bEnemyAllDead = false
end
end
end
if bEnemyAllDead then
BattleLogic.Event:DispatchEvent(BattleEventName.BattleOrderEnd, BattleLogic.CurOrder)
end
end
-- 获取结果
function this.GetResult()
if bMyAllDead then
return 0
end
if bEnemyAllDead then
return 1
end
end
-- 加入将死的人
function this.AddDeadRole(role)
_DeadRoleList[role.position + role.camp * 6] = role
end
-- 检测是有人将死
function this.CheckDead()
local isDeadFrame = false
local removePos = {}
for pos, role in pairs(_DeadRoleList) do
if role:GoDead() then
isDeadFrame = true
table.insert(removePos, pos)
end
end
for _, pos in ipairs(removePos) do
_DeadRoleList[pos] = nil
end
return isDeadFrame
end
-- 加入复活之人
function this.AddReliveRole(role)
_ReliveRoleList[role.position + role.camp * 6] = role
end
-- 检测是否有人复活
function this.CheckRelive()
local isReliveFrame = false
local removePos = {}
for pos, role in pairs(_ReliveRoleList) do
if role:Relive() then
isReliveFrame = true
table.insert(removePos, pos)
end
end
for _, pos in ipairs(removePos) do
_ReliveRoleList[pos] = nil
end
return isReliveFrame
end
-- 获取角色数据
function this.GetRole(camp, pos)
return PosList[pos + camp*6]
end
-- 获取某阵营所有角色
function this.GetRoleByCamp(camp)
local list = {}
for i = 1, 6 do
list[i] = PosList[i + camp * 6]
end
return list
end
-- 查找角色
function RoleManager.Query(func, inCludeDeadRole)
local list = {}
local index = 1
if func then
for pos, v in pairs(PosList) do
if func(v) and (inCludeDeadRole or not v:IsRealDead()) then
list[index] = v
index = index + 1
end
end
end
table.sort(list, function(a, b)
return a.position < b.position
end)
return list
end
--对位规则: 1敌方相同对位 2若死亡或不存在选取相邻阵位最近且阵位索引最小的
function this.GetAggro(role)
-- 计算开始位置
local startPos = role.position
startPos = startPos > 3 and startPos - 3 or startPos
local target
local enemyCamp = role.camp == 0 and 1 or 0
-- c=0 前排 c=1 后排
for c = 0, 1 do
startPos = startPos + c*3
-- 向左
for i = startPos, c*3+1, -1 do
local pos = i + enemyCamp * 6
if PosList[pos] and not PosList[pos]:IsRealDead() then
target = PosList[pos]
break
end
end
if target then return target end
-- 向右
for i = startPos + 1, c*3+3 do
local pos = i + enemyCamp * 6
if PosList[pos] and not PosList[pos]:IsRealDead() then
target = PosList[pos]
break
end
end
if target then return target end
end
end
-- 获取没有进入死亡状态的仇恨目标
function this.GetAliveAggro(role)
-- 计算开始位置
local startPos = role.position
startPos = startPos > 3 and startPos - 3 or startPos
local target
local enemyCamp = role.camp == 0 and 1 or 0
-- c=0 前排 c=1 后排
for c = 0, 1 do
startPos = startPos + c*3
-- 向左
for i = startPos, c*3+1, -1 do
local pos = i + enemyCamp * 6
if PosList[pos] and not PosList[pos]:IsDead() then
target = PosList[pos]
break
end
end
if target then return target end
-- 向右
for i = startPos + 1, c*3+3 do
local pos = i + enemyCamp * 6
if PosList[pos] and not PosList[pos]:IsDead() then
target = PosList[pos]
break
end
end
if target then return target end
end
end
--对位规则: 1敌方相同对位 2若死亡或不存在选取相邻阵位最近且阵位索引最小的
function this.GetArrAggroList(role, arr)
-- 重构数据
local plist = {}
for _, role in ipairs(arr) do
plist[role.position] = role
end
-- 计算开始位置
local startPos = role.position
startPos = startPos > 3 and startPos - 3 or startPos
local targetList = {}
-- c=0 前排 c=1 后排
for c = 0, 1 do
startPos = startPos + c*3
-- 向左
for i = startPos, c*3+1, -1 do
local pos = i
if plist[pos] and not plist[pos]:IsRealDead() then
table.insert(targetList, plist[pos])
end
end
-- 向右
for i = startPos + 1, c*3+3 do
local pos = i
if plist[pos] and not plist[pos]:IsRealDead() then
table.insert(targetList, plist[pos])
end
end
end
table.sort(targetList, function(a, b)
return a.position < b.position
end)
return targetList
end
--对位规则: 1敌方相同对位 2若死亡或不存在选取相邻阵位最近且阵位索引最小的
function this.GetAggroHero(role,arr)
-- 计算开始位置
if not arr then
return
end
local startPos = role.position
local targetList={}
startPos = startPos > 3 and startPos - 3 or startPos
for _, v in ipairs(arr) do
local pos= v.position>3 and v.position -3 or v.position
if pos==startPos then
table.insert(targetList,v)
end
end
if #targetList==0 then
table.insert(targetList,arr[1])
end
return targetList
end
--获取对位相邻站位的人 chooseType 1 我方 2 敌方(对位的敌人受到嘲讽的影响,若对位的敌人死亡,则选取相邻最近的作为目标)
function this.GetNeighbor(role, chooseType)
local posList = {}
local target
if chooseType == 1 then
target = role
else
if role.lockTarget and not role.lockTarget:IsRealDead() then
target = role.lockTarget
else
target = this.GetAggro(role)
end
end
if target then
local list = this.Query(function (r) return r.camp == target.camp end)
for i=1, #list do
if not list[i]:IsRealDead() then
if list[i].position == target.position + 3 -- 后排的人
or list[i].position == target.position - 3 -- 前排的人
or (math.abs(target.position - list[i].position) <= 1 and math.floor((target.position-1)/3) == math.floor((list[i].position-1)/3)) then -- 旁边的人和自己
table.insert(posList, list[i])
end
end
end
end
table.sort(posList, function(a, b)
return a.position < b.position
end)
return posList
end
function this.Clear()
for _, obj in pairs(PosList) do
obj:Dispose()
removeObjList:Add(obj)
end
PosList = {}
while removeObjList.size > 0 do
rolePool:Put(removeObjList.buffer[removeObjList.size])
removeObjList:Remove(removeObjList.size)
end
_DeadRoleList = {}
_ReliveRoleList = {}
end
-- 多波
function this.ClearEnemy()
local removePos = {}
for pos, obj in pairs(PosList) do
if obj.camp == 1 then
removePos[pos] = 1
BattleLogic.Event:DispatchEvent(BattleEventName.RemoveRole, obj)
obj:Dispose()
removeObjList:Add(obj)
end
end
for pos, _ in pairs(removePos) do
PosList[pos] = nil
end
end
return this

View File

@ -0,0 +1,128 @@
require("Modules/Battle/Logic/Base/EffectCaster")
Skill = {}
function Skill:New()
local o = {cd=0, owner=0, sp=0, spPass=0, teamSkillType=0}
setmetatable(o, self)
self.__index = self
return o
end
function Skill:Init(role, effectData, type, targets, isAdd, isRage) --type 0 异妖 1 点技 2 滑技
self.type = type
--skill = {技能ID, 命中时间, 持续时间, 伤害次数, {目标id1, 效果1, 效果2, ...},{目标id2, 效果3, 效果4, ...}, ...}
--效果 = {效果类型id, 效果参数1, 效果参数2, ...}
self.owner = role
self.id = effectData[1] -- 技能ID
self.hitTime = effectData[2] -- 效果命中需要的时间
self.continueTime = effectData[3] -- 命中后伤害持续时间
self.attackCount = effectData[4] -- 伤害持续时间内伤害次数
self.isTriggePassivity = false -- 是否一个技能只触发一次被动 true每次释放技能只会触发一次
self.triggerPassivityId={}
self.isKill = false --是否技能击杀目标
self.isAdd = isAdd
self.isRage = isRage
-- 初始化
local effects = {}
for i=5, #effectData do
table.insert(effects, effectData[i])
end
self.effectCaster = EffectCaster:New()
self.effectCaster:Init(self, effects, targets)
end
function Skill:Dispose()
if self.effectCaster then
self.effectCaster:Dispose()
end
self.effectCaster = nil
end
-- 获取拥有者
function Skill:GetOwner()
return self.owner
end
-- 是否可以释放
function Skill:canCastSkill()
return true
end
-- 释放技能
-- func 技能释放完成回调
function Skill:Cast(func)
self.castDoneFunc = func
self.isTriggePassivity=false
self.triggerPassivityId={}
-- 技能效果生效
if self.effectCaster then
self.effectCaster:Cast()
end
-- 释放技能开始
self.owner.Event:DispatchEvent(BattleEventName.SkillCast, self)
BattleLogic.Event:DispatchEvent(BattleEventName.SkillCast, self)
-- 只对效果1的目标发送事件效果1是技能的直接伤害目标
self.effectCaster:ForeachTargets(function(role)
role.Event:DispatchEvent(BattleEventName.BeSkillCastEnd, self)
end)
--技能的施法时间计算根据当前目标id关联的持续时间取其中时间最长的一个
local duration = self.hitTime + self.continueTime
-- 结算时间向后延长0.2秒,避免在效果结算完成前就结束了技能释放
BattleLogic.WaitForTrigger(duration + 0.8, function()
self.owner.Event:DispatchEvent(BattleEventName.SkillCastEnd, self)
BattleLogic.Event:DispatchEvent(BattleEventName.SkillCastEnd, self)
-- 只对效果1的目标发送事件效果1是技能的直接伤害目标
self.effectCaster:ForeachTargets(function(role)
role.Event:DispatchEvent(BattleEventName.BeSkillCastEnd, self)
end)
-- 技能结束
self:EndSkill()
--技能消息发送完后 iskill 设置为false
self.isKill=false
end)
end
-- 获取直接选择目标的ID
function Skill:GetDirectChooseId()
return self.effectCaster:GetDirectChooseId()
end
-- 获取技能的直接目标,和策划规定第一个效果的目标为直接效果目标,(包含miss的目标)
function Skill:GetDirectTargets()
return self.effectCaster:GetDirectTargets()
end
-- 获取直接目标不包含miss的目标可能为空
function Skill:GetDirectTargetsNoMiss()
return self.effectCaster:GetDirectTargetsNoMiss()
end
-- 获取技能目标最大人数
function Skill:GetMaxTargetNum()
return self.effectCaster:GetMaxTargetNum()
end
-- 判断是否命中
function Skill:CheckTargetIsHit(role)
return self.effectCaster:CheckTargetIsHit(role)
end
-- 结束技能
function Skill:EndSkill()
-- 技能后摇
-- 技能结束后摇后结束技能释放
BattleLogic.WaitForTrigger(0.3, function()
-- 结束回调
self.isTriggePassivity=false
self.triggerPassivityId={}
if self.castDoneFunc then self.castDoneFunc() end
end)
--
self.effectTargets = {}
end

View File

@ -7,6 +7,7 @@ end)
--
this.DeadSkillList = {} -- 人物死亡后技能队列,死亡技能优先级最高
this.MonsterSkillList = {}
this.SkillList = {}
this.IsSkilling = false
-- 初始化
@ -14,6 +15,16 @@ function this.Init()
this.Clear()
end
--
function this.AddMonsterSkill(skill)
LogPink("灵兽技能加入"..skill.id)
if skill.type == BattleSkillType.Monster then
table.insert(this.MonsterSkillList, skill)
end
return skill
end
-- 向技能列表中追加技能
function this.AddSkill(caster, effectData, type, targets, isAdd, isRage)
local skill = skillPool:Get()
@ -61,6 +72,9 @@ function this.CheckTurnRound()
if this.IsSkilling then
return
end
if this.MonsterSkillList and #this.MonsterSkillList > 0 then
return
end
if this.DeadSkillList and #this.DeadSkillList > 0 then
return
end
@ -87,10 +101,28 @@ function this.Update()
return
end
if this.MonsterSkillList and #this.MonsterSkillList > 0 then
local skill = this.MonsterSkillList[1]
table.remove(this.MonsterSkillList, 1)
this.IsSkilling = true
if skill:canCastSkill() then
skill:Cast(function()
-- 检测一下轮转
this.IsSkilling = false
this.CheckTurnRound()
end)
else
-- 检测一下轮转
this.IsSkilling = false
this.CheckTurnRound()
end
return
end
-- 判断是否有死亡技能
-- 跟佳琦对的是角色死后只有死亡后释放的技能才能释放(DeadSkill) by:王振兴 2020/09/02 18:53
if this.DeadSkillList and #this.DeadSkillList > 0 then
local skill = this.DeadSkillList[1]
table.remove(this.DeadSkillList, 1)
this.IsSkilling = true
@ -112,7 +144,6 @@ function this.Update()
-- 判断
if this.SkillList and #this.SkillList > 0 then
local skill = this.SkillList[1]
table.remove(this.SkillList, 1)
this.IsSkilling = true
@ -129,7 +160,6 @@ function this.Update()
this.IsSkilling = false
this.CheckTurnRound()
end
return
end