back_recharge
duhui 2023-06-06 10:31:05 +08:00
parent 41012e5528
commit 614dbffcf4
12 changed files with 1482 additions and 0 deletions

View File

@ -0,0 +1,167 @@
require("Modules.Battle.Logic.Misc.BattleDefine")
require("Modules.Battle.Logic.Misc.BattleUtil")
require("Modules.Battle.Logic.Misc.BattleQueue")
require("Modules.Battle.Logic.Misc.BattleDictionary")
require("Modules.Battle.Logic.Misc.BattleList")
require("Modules.Battle.Logic.Misc.BattleObjectPool")
require("Modules.Battle.Logic.Base.BattleEvent")
require("Modules.Battle.Logic.Base.Random")
require("Modules.Battle.Logic.Base.RoleData")
require("Modules.Battle.Logic.Base.Buff")
require("Modules.Battle.Logic.Base.Skill")
require("Modules.Battle.Logic.Base.Passivity")
require("Modules.Battle.Logic.BattleLogic")
require("Modules.Battle.Logic.RoleLogic")
local BattleMain = {}
local BattleLogic = BattleLogic
local Random = Random
local _fightData
local _optionData
local function newPairs(tbl, func)
if func == nil then
return pairs(tbl)
end
local ary = {}
local lastUsed = 0
for key --[[, val--]] in pairs(tbl) do
if (lastUsed == 0) then
ary[1] = key
else
local done = false
for j=1,lastUsed do -- 进行插入排序
if (func(key, ary[j]) == true) then
arrayInsert( ary, key, j )
done = true
break
end
end
if (done == false) then
ary[lastUsed + 1] = key
end
end
lastUsed = lastUsed + 1
end
-- 定义并返回迭代器
local i = 0
local iter = function ()
i = i + 1
if ary[i] == nil then
return nil
else
return ary[i], tbl[ary[i]]
end
end
return iter
end
local function PrintTable(tb)
local indent_str = "{"
for k=1, #tb do
local v = tb[k]
if type(v) == "table" then
indent_str = indent_str .. PrintTable(v)
else
indent_str = indent_str .. tostring(v)..","
end
end
for k,v in newPairs(tb) do
if type(k) ~= "number" then
if type(v) == "table" then
indent_str = string.format("%s%s=%s", indent_str, tostring(k), PrintTable(v))
else
indent_str = string.format("%s%s=%s", indent_str, tostring(k), tostring(v)..",")
end
end
end
indent_str = indent_str .. "},"
return indent_str
end
--捕获异常,并输出错误日志
local function error( err )
local time = string.format("%d-%d-%d-%d-%d-%d",
os.date("%Y"),
os.date("%m"),
os.date("%d"),
os.date("%H"),
os.date("%M"),
os.date("%S"))
local file = io.open("LogError/"..time..".txt", "a")
--file:write("fightData:\n"..PrintTable(_fightData).."\n")
--file:write("optionData:\n"..PrintTable(_optionData).."\n")
file:write("error:\n"..debug.traceback(err).."\n")
io.close(file)
print(debug.traceback(err))
end
local function generateRecordFile()
local time = string.format("%d-%d-%d-%d-%d-%d",
os.date("%Y"),
os.date("%m"),
os.date("%d"),
os.date("%H"),
os.date("%M"),
os.date("%S"))
local file = io.open("BattleRecord/"..time..".txt", "a")
local record = BattleLogic.GetRecord()
for i=1, #record do
file:write(record[i].."\n")
end
io.close(file)
end
function BattleMain.Execute(seed, fightData, optionData)
_fightData = fightData
_optionData = optionData
print(PrintTable(fightData))
--该开关用于输出战斗过程中的日志,用于验证前后端是否出现战斗不同步
BattleLogic.IsOpenBattleRecord = false
if xpcall(function ()
Random.SetSeed(seed)
BattleLogic.Init(fightData, optionData)
BattleLogic.StartOrder()
while not BattleLogic.IsEnd do
BattleLogic.Update()
end
end, error) then
local resultList = {}
if BattleLogic.Result == 1 then --胜利记录我方剩余血量
local arr = RoleManager.QueryIncludeExile(function (r) return r.camp == 0 end, true)
for i=1, #arr do
resultList[i] = arr[i]:GetRoleData(RoleDataName.Hp)
end
elseif BattleLogic.Result == 0 then --失败记录敌方剩余血量
local arr = BattleLogic.QueryIncludeExile(function (r) return r.camp == 1 end, true)
for i=1, #arr do
resultList[i] = arr[i]:GetRoleData(RoleDataName.Hp)
end
end
resultList.result = BattleLogic.Result
if BattleLogic.IsOpenBattleRecord then
generateRecordFile()
end
-- print -----------------------------------------
for i=1, #resultList do
print("hp:"..resultList[i])
end
print("最终运行帧数:"..BattleLogic.GetCurRound())
print("result:"..BattleLogic.Result)
return resultList
end
return { result = -1 }
end
return BattleMain

View File

@ -0,0 +1,75 @@
--不动明王印记
BuDongSign = Buff:New() --压制
--初始化Buff通过传入一些自定义参数控制成长相关的数值
function BuDongSign:SetData(...)
-- self.atkType, --1 物理 2.魔法
-- self.ct,
-- self.value1=...
self.f1=...
self.maxPro=0
-- 刷新排序等级
self.curDamage=0
self.sort = 4
end
--初始化后调用一次
function BuDongSign:OnStart()
self.curDamage = 0
--本回合最多能扣到多少比例的血条
self.maxPro=(self.target:GetRoleData(RoleDataName.Hp)/self.target:GetRoleData(RoleDataName.MaxHp))-self.f1
if self.maxPro<0 then
self.maxPro=0
end
local function onFinalBeDamage(damagingFunc, atkRole, damage, skill, dotType, bCrit, damageType,isDirect)
-- 非直接伤害不免除
if not skill and not isDirect then
return
end
--判断伤害是否能超出能扣除的最大伤害
local maxDamage =math.floor(self.target:GetRoleData(RoleDataName.Hp)-(self.target:GetRoleData(RoleDataName.MaxHp) * self.maxPro))
self.curDamage=damage
if self.curDamage > maxDamage then
-- 计算免除的伤害值
local md = self.curDamage - maxDamage
if md > damage then
md = damage
end
if damagingFunc then damagingFunc(md) end
end
end
self.target.Event:AddEvent(BattleEventName.CheckLiZhanZhiQu, onFinalBeDamage,nil,nil,self.target)
local function onRoundChange()
self.curDamage = 0
--本回合最多能扣到多少比例的血条
self.maxPro=(self.target:GetRoleData(RoleDataName.Hp)/self.target:GetRoleData(RoleDataName.MaxHp))-self.f1
if self.maxPro<0 then
self.maxPro=0
end
--LogError("本回合最多能扣到的比例=="..maxPro)
end
BattleLogic.Event:AddEvent(BattleEventName.BattleRoundChange, onRoundChange,nil,nil,self.target)
end
--间隔N帧触发返回true时表示继续触发返回false立刻触发OnEnd
function BuDongSign:OnTrigger()
return true
end
--效果结束时调用一次
function BuDongSign:OnEnd()
end
--只有当cover字段为true时触发返回true则被新效果覆盖
function BuDongSign:OnCover(newBuff)
return true
end
return BuDongSign

View File

@ -0,0 +1,60 @@
FalseNoDead = Buff:New()
--初始化Buff通过传入一些自定义参数控制成长相关的数值
function FalseNoDead:SetData(...)
self.pro,
self.time=...
--self.changePro = ... -- buff期间的增伤系数
self.cover = true --控制效果可被覆盖
-- 刷新排序等级
self.sort = 4
self.triggerTime=0
end
-- 伤害降低
function FalseNoDead:onPassiveDamaging(func,attacker, damage, skill)
if self.triggerTime>=self.time then
--LogError("22222222222222222")
return
end
BattleUtil.RandomAction(self.pro,function()
local hp=self.target:GetRoleData(RoleDataName.Hp)
if damage >= hp then
if func then
func(hp-1)
end
self.triggerTime=self.triggerTime+1
end
end)
end
--初始化后调用一次
function FalseNoDead:OnStart()
--
self.target.Event:AddEvent(BattleEventName.CheckFalseNoDead, self.onPassiveDamaging, self)
end
--间隔N帧触发返回true时表示继续触发返回false立刻触发OnEnd
function FalseNoDead:OnTrigger()
return true
end
--效果结束时调用一次
function FalseNoDead:OnEnd()
self.target.Event:RemoveEvent(BattleEventName.CheckFalseNoDead, self.onPassiveDamaging, self)
self.triggerTime=0
end
--只有当cover字段为true时触发返回true则被新效果覆盖
function FalseNoDead:OnCover(newBuff)
return true
end
-- 比较buff
function FalseNoDead:OnCompare(buff)
return true
end
return FalseNoDead

View File

@ -0,0 +1,44 @@
SuckBlood = Buff:New()
--初始化Buff通过传入一些自定义参数控制成长相关的数值
function SuckBlood:SetData(...)
self.pro=...
self.cover = true --控制效果可被覆盖
-- 刷新排序等级
self.sort = 4
self.triggerTime=0
end
-- 伤害降低
function SuckBlood:onPassiveDamaging(target, damage, bCrit, finalDmg,damageType,skill)
BattleUtil.FinalTreat(self.target, self.target, math.floor(BattleUtil.ErrorCorrection(damage * self.pro)))
end
--初始化后调用一次
function SuckBlood:OnStart()
self.target.Event:AddEvent(BattleEventName.RoleHit, self.onPassiveDamaging, self)
end
--间隔N帧触发返回true时表示继续触发返回false立刻触发OnEnd
function SuckBlood:OnTrigger()
return true
end
--效果结束时调用一次
function SuckBlood:OnEnd()
self.target.Event:RemoveEvent(BattleEventName.RoleHit, self.onPassiveDamaging, self)
end
--只有当cover字段为true时触发返回true则被新效果覆盖
function SuckBlood:OnCover(newBuff)
return true
end
-- 比较buff
function SuckBlood:OnCompare(buff)
return true
end
return SuckBlood

View File

@ -0,0 +1,123 @@
require("Modules.Battle.Logic.Monster.MonsterSkill.MSkillManager")
require("Modules.Battle.Logic.Weapon.WeaponSkillManager")
FightWeapon = {}
function FightWeapon:New()
local o = {
data=RoleData.New(),
buffFilter=BattleList.New(),
Event = BattleEvent:New()
}
setmetatable(o, self)
self.__index = self
return o
end
-- 初始化
function FightWeapon:Init(data)
self.type = BattleUnitType.Weapon
self.camp = data.camp
-- if data.position==10 then
-- self.type = BattleUnitType.Player
-- end
self.position = data.position
self.star = data.star
self.uid= data.id
self.teamDamage=data.teamDamage
self.roleData = data
self.sex=data.sex
self.addAttack=0
self.data:Init(self, data.property)
self.buffFilter:Clear() --buff屏蔽列表
self.Event:ClearEvent()
self.exileTargets={}--已经被放逐过的目标
-- self.skillGroup = MSkillManager.CreateMSkillGroup(self, data.skill)
--LogError("神兵初始化=============================")
-- self.skillList=data.skill
self.skillNum=#data.skill
self.skillGroupList = {}
--self.ownHero=RoleManager.GetRole(data.camp,data.position)
for i = 1, #data.skill do
--LogError("---------------------"..data.skill[i].skillData.effect[1])
--LogError("monster skill id=="..data.skill[i])
self.skillGroupList[i] = WeaponSkillManager.CreateMSkillGroup(self, i, data.skill[i])
end
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 = tonumber(v[1])
local judge=v[2]
local id = tonumber(v[3])
local args = {}
for j = 4, #v do
args[j-3] = v[j]
end
if BattleUtil.Passivity[id] then
BattleUtil.Passivity[id](self, args,passivityId,judge)
BattleLogManager.Log(
"Add Passive",
"id", tostring(id),
"camp", tostring(self.camp),
"pos", tostring(self.position),
"passivityId", tostring(passivityId),
"judge", tostring(judge)
)
end
end
end
end
function FightWeapon:AddBuff(buff)
-- 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 FightWeapon:GetRoleData(property)
local tarPro = self.data:GetData(property)
return tarPro
end
function FightWeapon:GetCamp()
return self.camp
end
function FightWeapon:GetPosition()
return self.position
end
function FightWeapon:GetStar()
return self.star
end
function FightWeapon:IsRealDead()
return false
end
-- 数据回收
function FightWeapon:Dispose()
end
return FightWeapon

View File

@ -0,0 +1,56 @@
require("Modules.Battle.Logic.Weapon.FightWeapon")
FightWeaponManager = {}
local this = FightWeaponManager
function FightWeaponManager.Init()
this.monsterList = {}
-- 初始化灵兽技能管理
-- if MSkillManager.isInit==false then
-- LogError("初始化 ====================mskikkmanager")
-- MSkillManager.Init()
-- end
WeaponSkillManager.Init()
end
function FightWeaponManager.AddWeapon(data)
local index = data.camp * 6 + data.position
local monster = FightWeapon:New()
monster:Init(data)
if not this.monsterList then
this.monsterList = {}
end
this.monsterList[index] = monster
BattleLogic.Event:DispatchEvent(BattleEventName.AddWeapon, monster)
end
-- 获取角色数据
function this.GetMonster(camp, pos)
local index = camp * 6 + pos
return this.monsterList[index]
end
function FightWeaponManager.Update()
end
-- 切换时使用(已废弃)
function FightWeaponManager.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 FightWeaponManager

View File

@ -0,0 +1,223 @@
WeaponCondition = {}
local this = WeaponCondition
local skillRound={}
local enSkillRound={}
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,
[3] = function(skill, condition) --2:回合数 【比较类型】 N 且 概率为 N
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
local rand = condition[4]
-- 获取当前回合
local curRound = BattleLogic.GetCurRound()
local isRoundOk = BattleUtil.CompareValue(curRound, comValue, comType)
-- 判断概率
local r = Random.Range01()
local isRandomOk = r <= rand/10000
return isRoundOk and isRandomOk
end,
[4] = function(skill, condition) --4:场上燃烧目标的数量 【比较类型】 N
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
-- 当前释放技能的单位的职业
local professionId = skill.owner.professionId
local list = RoleManager.Query(function(role)
return role.camp ~= skill.owner.camp
end)
if not list then
return false
end
local num=0
for key, value in pairs(list) do
local isHave=BattleLogic.BuffMgr:HasBuff(value, BuffName.DOT, function(buff) return buff.damageType == 1 end)
if isHave then
num=num+1
end
end
return BattleUtil.CompareValue(num, comValue, comType)
end,
[5] = function(skill, condition) --5敌方上场神将数量 且概率(万分比)
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
local rand = condition[4]
local roleList = RoleManager.Query(function(role)
return role.camp ~= skill.owner.camp
end)
local isEnough=BattleUtil.CompareValue(#roleList, comValue, comType)
local r = Random.Range01()
-- 判断概率
if isEnough then
return rand/10000>r
end
return false
end,
[6] = function(skill, condition) --6敌方任意神将生命百分比 【比较类型】 N万分比
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
local round = condition[4]
-- 获取该技能相同阵营人物
local roleList = RoleManager.Query(function(role)
return role.camp ~= skill.owner.camp
end)
-- 判断
local r = Random.Range01()
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 round/10000>r
end
end
return false
end,
[7] = function(skill, condition) --7敌方上场神将数量 且概率(万分比)(检测放逐)
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
local rand = condition[4]
local roleList = RoleManager.QueryIncludeExile(function(role)
return role.camp ~= skill.owner.camp
end)
--判断场上敌方数量是否足够
local isEnough=BattleUtil.CompareValue(#roleList, comValue, comType)
if isEnough then
local ishave=false
--是否有没被放逐的目标
local list=skill.owner.exileTargets
for key, value in pairs(roleList) do
if not BattleUtil.ChecklistIsContainValue(list,value) then
ishave=true
break
end
end
if ishave then
local r = Random.Range01()
-- 判断概率
if isEnough then
return rand/10000>r
end
end
return false
end
return false
end,
[8] = function(skill, condition) --6:回合cd数限制
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
-- 获取当前回合
local curRound = BattleLogic.GetCurRound()
--我方主角技能计算回合
if skill.owner.camp==0 then
if not skillRound[skill.id] then
skillRound[skill.id]=curRound
return true
else
if curRound==skillRound[skill.id]+comValue then
skillRound[skill.id]=curRound
return true
end
end
else
--敌方主角技能计算回合
if not enSkillRound[skill.id] then
enSkillRound[skill.id]=curRound
return true
else
if curRound==enSkillRound[skill.id]+comValue then
enSkillRound[skill.id]=curRound
return true
end
end
end
return false
end,
[9] = function(skill, condition) --6:我方道系非治疗数量
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
local list=RoleManager.Query(function(role) return role.camp==skill.owner.camp and role.element==BattleRoleElementType.DAO and role.job~=1 end)
return BattleUtil.CompareValue(#list, comValue, comType)
end,
[10] = function(skill, condition) --10神兵所属神将生命百分比 【比较类型】 N万分比
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
if skill.ownHero==nil or skill.ownHero:IsDead() then
--LogError("没有持有者")
return false
end
-- 判断
local hpf = skill.ownHero:GetRoleData(RoleDataName.Hp) / skill.ownHero:GetRoleData(RoleDataName.MaxHp)
--LogError("hpf==="..hpf)
if BattleUtil.CompareValue(hpf, comValue/10000, comType) then
--LogError("触发技能"..hpf)
return true
end
return false
end,
}
-- 条件检测
function WeaponCondition.CheckCondition(skill, condition)
if not condition then
--LogError("condition==")
return true
end
local conId = condition[1]
local comType = condition[2]
local comValue = condition[3]
--LogError("conid=="..conId.." comtype=="..comType.." comvalue=="..comValue)
return _ConditionConfig[conId](skill, condition)
end
-- 清除缓存
function WeaponCondition.ClearCache()
if skillRound then
skillRound={}
end
if enSkillRound then
enSkillRound={}
end
end
return WeaponCondition

View File

@ -0,0 +1,170 @@
WeaponSkill = {}
function WeaponSkill:New()
local o = {}
setmetatable(o, self)
self.__index = self
return o
end
function WeaponSkill:Init(owner, group, index, skillData,playerSkillIndex)
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
--后端传过来的数据最后一个是主角技能
if owner.position==100 then
if playerSkillIndex==self.owner.skillNum then
self.isPlayerSkill=true
else
self.isPlayerSkill=false
end
end
self.curCastCount = 0
self.maxCastCount = self.skillData.maxCount
-- LogError("monster skill id=="..skillData.effect[1])
self.curRoundCount = 0
self.maxRoundCount = self.skillData.maxRoundCount
--MTrigger.AddSkill(self.skillData, self.skillData.triggerCondition, self)
local effectData = self.skillData.effect
self.id = tonumber(effectData[1]) -- 技能ID
self.ownHero=RoleManager.GetRoleByCampAndPos(owner.camp,owner.position)
-- 将技能加入触发检测
WeaponTrigger.AddSkill(self.skillData.triggerId, self.skillData.triggerCondition, self)
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.BattleRoundChange,function (round)
self.curRoundCount = 0
end)
end
-- 是否可以释放
function WeaponSkill:canCastSkill()
-- 超出最大次数限制
if self.curCastCount >= self.maxCastCount then
return false
end
-- 超出轮数最大次数限制
if self.curRoundCount >= self.maxRoundCount then
return false
end
return true
end
function WeaponSkill:Cast(func)
self.castDoneFunc = func
self.isTriggePassivity=false
self.triggerPassivityId={}
-- 技能效果生效
if self.effectCaster then
--放技能前判断是否有目标,没有就不会放技能,直接执行技能回调 by 王振兴 2021/03/26
--为解决攻击目标只剩被放逐的单位导致技能播放异常
self.effectCaster:ChooseTarget()
local targets=BattleUtil.LengthOfTable(self:GetDirectTargetsNoExile())
if targets==0 and self.castDoneFunc then
self.castDoneFunc()
return
end
--end
self.effectCaster:Cast()
end
-- 释放技能开始
if self.owner.type==BattleUnitType.Weapon then
if self.ownHero then
self.ownHero.Event:DispatchEvent(BattleEventName.WeaponSkillCast, self)
end
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 WeaponSkill:GetOwner()
return self.owner
end
function WeaponSkill:GetGroupIndex()
return self.groupIndex
end
-- 获取直接选择目标的ID
function WeaponSkill:GetDirectChooseId()
return self.effectCaster:GetDirectChooseId()
end
-- 获取技能的直接目标,和策划规定第一个效果的目标为直接效果目标,(包含miss的目标)
function WeaponSkill:GetDirectTargets()
return self.effectCaster:GetDirectTargets()
end
-- 获取直接目标不包含miss的目标可能为空
function WeaponSkill:GetDirectTargetsNoMiss()
return self.effectCaster:GetDirectTargetsNoMiss()
end
-- 获取技能目标最大人数
function WeaponSkill:GetMaxTargetNum()
return self.effectCaster:GetMaxTargetNum()
end
-- 获取直接目标,不包含放逐的目标,可能为空
function WeaponSkill:GetDirectTargetsNoExile()
return self.effectCaster:GetDirectTargetsNoExile()
end
-- 判断是否命中
function WeaponSkill:CheckTargetIsHit(role)
return self.effectCaster:CheckTargetIsHit(role)
end
-- 结束技能
function WeaponSkill:EndSkill()
-- 技能后摇
-- 技能结束后摇后结束技能释放
BattleLogic.WaitForTrigger(0.3, function()
-- 结束回调
self.isTriggePassivity=false
self.triggerPassivityId={}
if self.castDoneFunc then self.castDoneFunc() end
end)
--
self.effectTargets = {}
end
return WeaponSkill

View File

@ -0,0 +1,38 @@
WeaponSkillGroup = {}
function WeaponSkillGroup:New()
local o = {}
setmetatable(o, self)
self.__index = self
return o
end
-- 初始化数据
function WeaponSkillGroup:Init(monster, groupIndex, groupData)
self.owner = monster
self.groupIndex = groupIndex
self.skillGroupData = groupData
-- 创建技能
self.skillList = {}
local num=0
-- for index, data in ipairs(self.skillGroupData) do
-- LogError("careat skill=="..index.." data=="..data.effect[1])
-- num=num+1
-- self.skillList[num] = MSkillManager.CreateMSkill(monster, self, num, data)
-- end
for i = 1, #self.skillGroupData do
self.skillList[i] = WeaponSkillManager.CreateMSkill(monster, self, i, self.skillGroupData[i],groupIndex)
end
end
function WeaponSkillGroup:GetOwner()
return self.owner
end
function WeaponSkillGroup:Run()
end
return WeaponSkillGroup

View File

@ -0,0 +1,51 @@
require("Modules.Battle.Logic.Weapon.WeaponTrigger")
require("Modules.Battle.Logic.Weapon.WeaponSkill")
require("Modules.Battle.Logic.Weapon.WeaponSkillGroup")
WeaponSkillManager = {}
local this = WeaponSkillManager
function this.Init()
this.MSkillGroupList = {} -- 技能组列表
this.MSkillList = {} -- 技能列表
WeaponTrigger.Init()
end
-- 创建一个技能组
function this.CreateMSkillGroup(monster, groupIndex, skillGroupData)
--LogError("创建神兵技能组====================")
local position = monster:GetCamp() * 6 + monster:GetPosition()
if not this.MSkillGroupList then
this.MSkillGroupList = {}
end
if not this.MSkillGroupList[position] then
this.MSkillGroupList[position] = WeaponSkillGroup:New()
end
this.MSkillGroupList[position]:Init(monster, groupIndex, skillGroupData)
return this.MSkillGroupList[position]
end
-- 创建一个技能
function this.CreateMSkill(monster, group, index, skilldata,groupIndex)
--LogError("创建神兵技能====================")
local owner = group:GetOwner()
local groupIndex = group.groupIndex
local position = owner:GetCamp() * 6 + owner:GetPosition()
if not this.MSkillList then
this.MSkillList = {}
end
if not this.MSkillList[position] then
this.MSkillList[position] = {}
end
if not this.MSkillList[position][groupIndex] then
this.MSkillList[position][groupIndex] = {}
end
if not this.MSkillList[position][groupIndex][index] then
this.MSkillList[position][groupIndex][index] = WeaponSkill:New()
end
this.MSkillList[position][groupIndex][index]:Init(monster, group, index, skilldata,groupIndex)
return this.MSkillList[position][groupIndex][index]
end
return WeaponSkillManager

View File

@ -0,0 +1,343 @@
require("Modules.Battle.Logic.Weapon.WeaponCondition")
WeaponTrigger = {}
local this = WeaponTrigger
-- 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.BattleRoundStart,
-- 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 and castSkill.owner.job==2 and (castSkill.type==BattleSkillType.DeadSkill or castSkill.type==BattleSkillType.Extra or castSkill.type==BattleSkillType.Special)
-- end
-- },
-- }
local _TriggerConfig = {
[BattleEventName.RoleTurnStart] = {
[1] = function(skill, ...) --1敌方单位行动前
local args = {...}
local role = args[1]
return role.camp ~= skill.owner.camp
end,
[3] = function(skill, ...) --3我方单位行动前
local args = {...}
local role = args[1]
return role.camp == skill.owner.camp
end
},
[BattleEventName.RoleTurnEnd] = {
[2] = function(skill, ...)--2敌方单位行动后
local args = {...}
local role = args[1]
if skill.ownHero==nil then
return
end
return role.camp ~= skill.owner.camp
end,
[4] = function(skill, ...)--4我方单位行动后
local args = {...}
local role = args[1]
if skill.ownHero==nil then
return
end
return role.camp == skill.owner.camp
end,
[13] = function(skill, ...)--13:敌方攻击最高单位行动后
local args = {...}
local caster = args[1]
local cam=skill.owner.camp
if caster.camp==cam then
return false
end
local list = RoleManager.Query(function(v) return v.camp~=cam end)
if list and #list>0 then
BattleUtil.SortByProp(list,RoleDataName.Attack,0)
if caster==list[1] then
return true
end
end
return false
end
},
[BattleEventName.BattleStart] = {
[5] = function(skill, ...)--5战前
return true
end
},
[BattleEventName.BattleRoundStart] = {
[6] = function(skill, ...)--6奇数回合开始前
local args = {...}
local curRound = args[1]
return curRound%2 == 1
end,
[7] = function(skill, ...)--7偶数回合开始前
local args = {...}
local curRound = args[1]
return curRound%2 == 0
end,
[10] = function(skill, ...)--10回合开始前
return true
end
},
[BattleEventName.BattleRoundEnd] = {
[8] = function(skill, ...)--8奇数回合结束后
local args = {...}
local curRound = args[1]
return curRound%2 == 1
end,
[9] = function(skill, ...)--9偶数回合结束后
local args = {...}
local curRound = args[1]
return curRound%2 == 0
end,
[11] = function(skill, ...)--11回合结束后
return true
end
},
[BattleEventName.SkillCastEnd] = {
[12] = function(skill, ...)--12我方单位释放技能后
local args = {...}
local castSkill = args[1]
return castSkill.owner.camp == skill.owner.camp and castSkill.owner.job==2 and (castSkill.type==BattleSkillType.DeadSkill or castSkill.type==BattleSkillType.Extra or castSkill.type==BattleSkillType.Special)
end,
[14] =function(skill,...) --14:我方金乌释放技能后
local args = {...}
local castSkill = args[1]
return castSkill.owner.camp == skill.owner.camp and castSkill.owner.type==BattleUnitType.Monster and castSkill.owner.uid==20008
end,
[16] =function(skill,...) --16:神兵所属者释放技能活普攻
local args = {...}
local castSkill = args[1]
if skill.ownHero==nil then
return
end
--LogError("castSkill.owner=="..castSkill.owner.uid.." skill.ownHero=="..skill.ownHero.uid)
return castSkill.owner == skill.ownHero and not castSkill.isAdd and (castSkill.type==BattleSkillType.Normal or castSkill.type==BattleSkillType.Special)
end,
[17] =function(skill,...) --17:神兵所属者释放普攻
local args = {...}
local castSkill = args[1]
if skill.ownHero==nil then
return
end
--LogError("============================17")
return castSkill.owner == skill.ownHero and castSkill.type==BattleSkillType.Normal
end,
[19] =function(skill,...) --19:神兵所属者释放技能(不包含追加技能)
local args = {...}
local castSkill = args[1]
if skill.ownHero==nil then
return
end
return castSkill.owner == skill.ownHero and not castSkill.isAdd and (castSkill.type==BattleSkillType.Special or castSkill.type==BattleSkillType.Extra )
end,
},
[BattleEventName.RoleIsVanish]={
[15]=function(skill, ...)
local args={...}
local role=RoleManager.GetDeadRole(skill.owner.camp)
if role and role:IsRealDead() and not BattleUtil.CheckIsNoDead(role) then
return true
end
return false
end,
},
[BattleEventName.BattleRoleDead]={
[18]=function(skill, ...)
local args={...}
local defRole=args[1]
local atkRole=args[2]
local deadSkill=args[3]
if skill.ownHero==nil then
return
end
if skill==deadSkill then
defRole:GetRoleData(RoleDataName.MaxHp)
end
end,
},
}
function WeaponTrigger.Init()
this.TriggerList ={}
this.InitListener()
end
-- 初始化事件监听
function this.InitListener()
--每次初始化时间监听前 清除下缓存数据
WeaponCondition.ClearCache()
--LogError("初始u啊神兵技能监听-------")
for event, list in pairs(_TriggerConfig) do
BattleLogic.Event:AddEvent(event, function(...)
-- 用于排序
local firstList = {}
-- 用于排序
local sortList = {}
for triggerId, triggerFunc in pairs(list) do
-- 判断是否有需要触发的技能
--LogError("判断是否有需要触发的技能")
local triggerSkill = this.TriggerList[triggerId]
if triggerSkill then
for _, trigger in ipairs(triggerSkill) do
local skill = trigger.skill
local condition = trigger.condition
--LogError("判断技能是否可以释放")
-- 判断技能是否可以释放
if skill:canCastSkill() then
-- 判断是否符合触发类型条件
--LogError("判断是否符合触发类型条件")
if triggerFunc(skill, ... ) then
-- 检测是否符合子条件
if WeaponCondition.CheckCondition(skill, condition) then
-- 加入技能排序对列
--LogError("-- 加入技能排序对列")
if skill.owner.position == 100 then
table.insert(firstList, skill)
else
table.insert(sortList, skill)
end
end
end
end
end
end
end
-- 对技能进行排序
table.sort(firstList, function(a, b)
-- 同阵营按位置排序
if a.owner.camp == b.owner.camp then
if a.owner.position == b.owner.position then
return a.id < b.id
else
return a.owner.position < b.owner.position
end
else
-- 不同阵营的根据先手阵营排序
return a.owner.camp == BattleLogic.FirstCamp
end
end)
-- 对技能进行排序
table.sort(sortList, function(a, b)
-- 同阵营按位置排序
if a.owner.camp == b.owner.camp then
if a.owner.position == b.owner.position then
return a.id < b.id
else
return a.owner.position < b.owner.position
end
else
-- 不同阵营的根据先手阵营排序
return a.owner.camp == BattleLogic.FirstCamp
end
end)
--依次加入技能管理
for _, skill in ipairs(firstList) do
SkillManager.AddMonsterSkill(skill)
end
for _, skill in ipairs(sortList) do
--LogError("添加技能到skillmanager")
SkillManager.AddMonsterSkill(skill)
end
end)
end
end
-- 技能加入检测
function WeaponTrigger.AddSkill(triggerId, condition, skill)
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,trigger= triggerId})
end
return WeaponTrigger

132
luafight/test.lua 100644

File diff suppressed because one or more lines are too long