战斗同步

back_recharge
duhui 2021-04-06 16:46:38 +08:00
parent bce07ebf64
commit 7cfd951ce5
11 changed files with 74 additions and 1299 deletions

View File

@ -227,6 +227,13 @@ function BuffManager:ClearBuff(target, func)
while idx <= list.size do
local buff = list.buffer[idx]
if buff.target == target and (not func or (func and buff.clear and func(buff))) then
if func and func(buff) then
if buff.type== BuffName.Shield then
buff.target.Event:DispatchEvent(BattleEventName.ShowHintText, BattleArtFontType.Shield)
elseif buff.type== BuffName.DOT or buff.type==BuffName.Control or buff.type==BuffName.Immune then
buff.target.Event:DispatchEvent(BattleEventName.ShowHintText, BattleArtFontType.clear)
end
end
buff:OnEnd()
buff.target.Event:DispatchEvent(BattleEventName.BuffEnd, buff)
putBuff(buff)

View File

@ -3458,12 +3458,26 @@ local passivityList = {
BattleUtil.SortByHpFactor(list, 1)
local index = 0
for i = 1, #list do
if not list[i]:IsRealDead() and index < 2 then
if not list[i]:IsRealDead() and index < 2 and not BattleLogic.BuffMgr:HasBuff(list[i], BuffName.Shield, function (buff) return buff.shieldType == ShieldTypeName.AllReduce and buff.shieldValue~=0 end) then
index = index + 1
-- 吸血率%25 策划说写死
list[i]:AddBuff(Buff.Create(role, BuffName.Shield, i1, ShieldTypeName.AllReduce, 0.25, 0))
end
end
--如果只有一个人,这个人第一次上无敌盾就返回
if index==1 and #list==1 then
return
end
--如果场上能加无敌盾的不足两个,就给上过无敌盾的在上一个无敌盾 by: wangzhenxing 2021/3/30
if index<2 then
for i = 1,2-index do
if list[i] and not list[i]:IsRealDead() then
-- 吸血率%25 策划说写死
list[i]:AddBuff(Buff.Create(role, BuffName.Shield, i1, ShieldTypeName.AllReduce, 0.25, 0))
end
end
end
end
end
role.Event:AddEvent(BattleEventName.SkillCastEnd, onSkillEnd)
@ -5141,7 +5155,7 @@ local passivityList = {
if skill and BattleUtil.ChecklistIsContainValue(skill.triggerPassivityId,id) then
return
end
if skill and not skill.isAdd and defRole:IsDead() and not BattleUtil.CheckIsNoDead(defRole) then
if skill and defRole:IsDead() and not BattleUtil.CheckIsNoDead(defRole) then
BattleUtil.CalRage(role, role, i1, CountTypeName.Add)
if skill then
-- skill.isTriggePassivity=true
@ -5663,7 +5677,11 @@ local passivityList = {
if defRole and defRole.camp~=role.camp and skill.owner==role and (skill.type==BattleSkillType.Special or skill.type==BattleSkillType.Extra) then
BattleUtil.RandomAction(pro, function()
BattleLogic.BuffMgr:ClearBuff(defRole, function(buff)
return buff.type == BuffName.Immune and (buff.immuneType == 4 or buff.immuneType == 2)
if buff.type == BuffName.Immune and (buff.immuneType == 4 or buff.immuneType == 2) then
-- buff.target.Event:DispatchEvent(BattleEventName.ShowHintText, BattleArtFontType.clear)
return true
end
return false
end)
end)
end
@ -6080,7 +6098,7 @@ local passivityList = {
local v1=args[2]
local OnBuffEnd=function(buff)
if buff and not buff.target:IsDead() and buff.caster==role and buff.type==BuffName.Shield then
local val = floor(BattleUtil.FP_Mul(v1, role:GetRoleData(BattlePropList[pro])))
local val = floor(BattleUtil.FP_Mul(v1, buff.target:GetRoleData(BattlePropList[pro])))
BattleUtil.CalTreat(role,buff.target, val)
end
end

View File

@ -1,125 +0,0 @@
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

@ -1,272 +0,0 @@
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 effectPool = BattleObjectPool.New(function ()
return { type = 0, args = {}} -- type, {args, ...}
end)
local effectGroupPool = BattleObjectPool.New(function ()
return { chooseId = 0, effects = {}} -- chooseId, {effect1, effect2, ...}
end)
Skill = {}
function Skill:New()
local o = {cd=0,effectList = BattleList.New(),owner=0,sp=0,spPass=0,isTeamSkill=false,teamSkillType=0 }
setmetatable(o, self)
self.__index = self
return o
end
function Skill:Init(role, effectData, type, targets, isAdd, isRage) --type 0 异妖 1 点技 2 滑技
local isTeamSkill = type == 0
self.type = type
--skill = {技能ID, 命中时间, 持续时间, 伤害次数, {目标id1, 效果1, 效果2, ...},{目标id2, 效果3, 效果4, ...}, ...}
--效果 = {效果类型id, 效果参数1, 效果参数2, ...}
self.effectList:Clear()
self.owner = role
self.isTeamSkill = isTeamSkill
self.teamSkillType = isTeamSkill and floor(effectData[1] / 100) or 0
self.id = effectData[1] -- 技能ID
self.hitTime = effectData[2] -- 效果命中需要的时间
self.continueTime = effectData[3] -- 命中后伤害持续时间
self.attackCount = effectData[4] -- 伤害持续时间内伤害次数
self.isTriggePassivity = false -- 是否一个技能只触发一次被动 true每次释放技能只会触发一次
self.triggerPassivityId={}
self.targets = targets or {}
self.isAdd = isAdd
self.isRage = isRage
self.isKill = false --是否技能击杀目标
for i=5, #effectData do
local v = effectData[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
self.effectList:Add(effectGroup)
end
end
function Skill:Dispose()
while self.effectList.size > 0 do
local effectGroup = self.effectList.buffer[self.effectList.size]
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)
self.effectList:Remove(self.effectList.size)
end
end
local function 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)
BattleLogManager.Log(
"Take Effect",
"tcamp", target.camp,
"tpos", target.position,
"type", e.type
)
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
-- 释放技能
-- func 技能释放完成回调
function Skill:Cast(func)
self.castDoneFunc = func
self.effectTargets = {}
self.targetIsHit = {}
self.isTriggePassivity=false
self.triggerPassivityId={}
-- 先计算出技能的目标
for i=1, self.effectList.size 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
-- 重新选择目标a
if isReTarget then
local effectGroup = self.effectList.buffer[i]
local chooseId = effectGroup.chooseId
self.effectTargets[i] = BattleUtil.ChooseTarget(self.owner, chooseId)
-- 检测被动对攻击目标的影响
if i == 1 then
local function _PassiveTarget(targets)
self.effectTargets[i] = targets
end
self.owner.Event:DispatchEvent(BattleEventName.SkillTargetCheck, _PassiveTarget)
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
local effectGroup = self.effectList.buffer[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 = floor(chooseId % 10000 / 100)
local count = 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.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
if self.isTeamSkill then
self.owner.curSkill = self
end
-- 释放技能开始
self.owner.Event:DispatchEvent(BattleEventName.SkillCast, self)
BattleLogic.Event:DispatchEvent(BattleEventName.SkillCast, self)
-- 只对效果1的目标发送事件效果1是技能的直接伤害目标
for _, tr in ipairs(self.effectTargets[1]) do
tr.Event:DispatchEvent(BattleEventName.BeSkillCast, 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是技能的直接伤害目标
for _, tr in ipairs(self.effectTargets[1]) do
tr.Event:DispatchEvent(BattleEventName.BeSkillCastEnd, self)
end
-- 技能结束
self:EndSkill()
--技能消息发送完后 iskill 设置为false
self.isKill=false
end)
end
-- 获取技能的直接目标,和策划规定第一个效果的目标为直接效果目标,(包含miss的目标)
function Skill:GetDirectTargets()
return self.effectTargets[1]
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()
local mainEffect = self.effectList.buffer[1]
if not mainEffect then
return 0
end
return BattleUtil.GetMaxTargetNum(mainEffect.chooseId)
end
-- 判断是否命中
function Skill:CheckTargetIsHit(role)
return self.targetIsHit[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

@ -40,6 +40,10 @@ end
--效果结束时调用一次
function Control:OnEnd()
--如果还有同类型的控制效果,就返回
if BattleLogic.BuffMgr:HasBuff(self.target, BuffName.Control, function (buff) return buff~=self and buff.ctrlType == self.ctrlType end) then
return
end
if self.ctrlType == 1 then --眩晕
self.target.ctrl_dizzy = false
elseif self.ctrlType == 2 then --沉默

View File

@ -328,4 +328,6 @@ BattleRoleElementType = {
BattleArtFontType = {
Immune = 1, -- 免疫文字
Shield = 2, --破盾文字
clear = 3, --清除文字
}

View File

@ -84,6 +84,7 @@ function RoleLogic:Init(uid, data, position)
self.type = BattleUnitType.Role
self.passiveList = {}
if data.passivity and #data.passivity > 0 then
table.sort(data.passivity,function(a,b)return a[1] < b[1] end)
for i = 1, #data.passivity do
local v = data.passivity[i]
local passivityId=v[1]
@ -96,7 +97,7 @@ function RoleLogic:Init(uid, data, position)
if BattleUtil.Passivity[id] then
BattleUtil.Passivity[id](self, args,passivityId,judge)
-- 加入被动列表
table.insert(self.passiveList, {id, args})
table.insert(self.passiveList, {id, args,passivityId})
end
end
end

View File

@ -294,14 +294,45 @@ function this.GetAggroHero(role,arr)
local startPos = role.position
local targetList={}
startPos = startPos > 3 and startPos - 3 or startPos
local smallRole=nil
local smallPos=0
local bigRole=nil
local bigPos=0
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)
break
elseif pos<startPos then
if smallRole then
if pos>smallPos then
smallRole=v
smallPos=pos
end
else
smallRole=v
smallPos=pos
end
elseif pos>startPos then
if bigRole then
if pos<bigPos then
bigRole=v
bigPos=pos
end
else
bigRole=v
bigPos=pos
end
end
end
if #targetList==0 then
table.insert(targetList,arr[1])
if smallRole then
table.insert(targetList,smallRole)
else
if bigRole then
table.insert(targetList,bigRole)
end
end
end
return targetList
end

View File

@ -1,554 +0,0 @@
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
local skillPool = BattleObjectPool.New(function ()
return Skill:New()
end)
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.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)
self.Event:DispatchEvent(BattleEventName.RoleCDChanged)
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

@ -1,341 +0,0 @@
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

@ -1,4 +1,8 @@
v1.0.22
v1.0.25
1、选择单个对位目标修改
v1.0.24
1、同步大闹天宫新增英雄专属圣物的代码逻辑修改
v1.0.23
1、被动249修改
v1.0.22