From 1efd3bd58d639d5620aa17e8dd77e7652da7ab81 Mon Sep 17 00:00:00 2001 From: wangyuan Date: Thu, 9 May 2019 17:50:38 +0800 Subject: [PATCH] fight --- luafight/BattleMain.lua | 8 +- .../Modules/Battle/Logic/Base/Passivity.lua | 103 ++++++++++++++++-- luafight/Modules/Battle/Logic/Base/Skill.lua | 4 +- luafight/Modules/Battle/Logic/BattleLogic.lua | 8 +- .../Modules/Battle/Logic/Misc/BattleUtil.lua | 24 ++-- luafight/Modules/Battle/Logic/RoleLogic.lua | 15 ++- 6 files changed, 128 insertions(+), 34 deletions(-) diff --git a/luafight/BattleMain.lua b/luafight/BattleMain.lua index a0808ca23..f857802da 100644 --- a/luafight/BattleMain.lua +++ b/luafight/BattleMain.lua @@ -119,17 +119,17 @@ local function generateRecordFile() io.close(file) end -function BattleMain.Execute(seed, fightData, optionData) +function BattleMain.Execute(args, fightData, optionData) _fightData = fightData _optionData = optionData - --print(PrintTable(fightData)) + print(PrintTable(fightData)) --该开关用于输出战斗过程中的日志,用于验证前后端是否出现战斗不同步 BattleLogic.IsOpenBattleRecord = false if xpcall(function () - Random.SetSeed(seed) - BattleLogic.Init(fightData, optionData) + Random.SetSeed(args.seed) + BattleLogic.Init(args.maxTime, fightData, optionData) BattleLogic.StartOrder() while not BattleLogic.IsEnd do diff --git a/luafight/Modules/Battle/Logic/Base/Passivity.lua b/luafight/Modules/Battle/Logic/Base/Passivity.lua index 792925ab5..6d6a123c5 100644 --- a/luafight/Modules/Battle/Logic/Base/Passivity.lua +++ b/luafight/Modules/Battle/Logic/Base/Passivity.lua @@ -145,17 +145,20 @@ local passivityList = { role.Event:AddEvent(BattleEventName.SkillCastEnd, OnSkillCastEnd) end, - --发动技能后,使仇恨目标受到治疗效果降低[a],持续[b] - --a[float],b[int] + --发动技能后,[c]使仇恨目标受到治疗效果降低[a],持续[b] + --a[float],b[int],c[float] [3] = function(role, args) local f1 = args[1] local f2 = args[2] + local f3 = args[3] local OnSkillCastEnd = function(skill) - local arr = chooseTarget(role, 40000) - if arr[1] then - BattleUtil.CalDamage(role, arr[1], dt, f2) - end + BattleUtil.RandomAction(f3, function () + local arr = chooseTarget(role, 40000) + if arr[1] then + arr[1]:AddBuff(Buff.Create(role, BuffName.PropertyChange, f2, RoleDataName.CureFacter, f1, 3)) + end + end) end role.Event:AddEvent(BattleEventName.SkillCastEnd, OnSkillCastEnd) end, @@ -414,7 +417,7 @@ local passivityList = { role.Event:AddEvent(BattleEventName.SkillCastEnd, OnSkillCastEnd) end, - --发动技能后,[d]改变自身[a]属性[b],持续[c]秒 + --发动技能后,[d]改变仇恨目标[a]属性[b],持续[c]秒 --a[属性],b[int],c[int],d[改变类型] [17] = function(role, args) local pro1 = args[1] @@ -423,9 +426,10 @@ local passivityList = { local ct = args[4] local OnSkillCastEnd = function(skill) - BattleUtil.RandomAction(f1, function () - role:AddBuff(Buff.Create(role, BuffName.PropertyChange, f2, propertyList[pro1], f1, ct)) - end) + local arr = chooseTarget(role, 40000) + if arr[1] then + arr[1]:AddBuff(Buff.Create(role, BuffName.PropertyChange, f2, propertyList[pro1], f1, ct)) + end end role.Event:AddEvent(BattleEventName.SkillCastEnd, OnSkillCastEnd) end, @@ -451,6 +455,8 @@ local passivityList = { --a[float] [19] = function(role, args) local f1 = args[1] + + role.data:AddValue(RoleDataName.CureFacter, f1) end, --[b]造成的持续伤害时间延长[a]。 @@ -650,7 +656,7 @@ local passivityList = { role.Event:AddEvent(BattleEventName.RoleDamageBefore, OnRoleDamageBefore) end, - --发动技能后,[d]改变己方全体[a]属性[b],持续[c]秒 + --发动技能后,[d]改变敌方全体[a]属性[b],持续[c]秒 --a[属性],b[float],c[int],d[改变类型] [30] = function(role, args) local pro = args[1] @@ -659,7 +665,7 @@ local passivityList = { local ct = args[4] local OnSkillCastEnd = function(skill) - local arr = chooseTarget(role, 10000) + local arr = chooseTarget(role, 20000) for i=1, #arr do arr[i]:AddBuff(Buff.Create(role, BuffName.PropertyChange, f2, propertyList[pro], f1, ct)) end @@ -838,5 +844,78 @@ local passivityList = { end role.Event:AddEvent(BattleEventName.PassiveCriting, OnPassiveCriting) end, + + --发动技能后,[d]改变仇恨目标[a]属性[b],持续整场战斗,属性最多可改变[c] + --a[属性],b[float],c[float],d[改变类型] + [43] = function(role, args) + local pro = args[1] + local f1 = args[2] + local i1 = args[3] + local ct = args[4] + + local OnSkillCastEnd = function(skill) + local arr = chooseTarget(role, 40000) + if arr[1] then + local buff = Buff.Create(role, BuffName.PropertyChange, 0, propertyList[pro], f1, ct) + buff.cover = true + buff.maxLayer = i1 + arr[1]:AddBuff(buff) + end + end + role.Event:AddEvent(BattleEventName.SkillCastEnd, OnSkillCastEnd) + end, + + --发动技能后,[a]的概率[e]改变自身[b]属性[c],持续[d]秒。 + --a[float],b[属性],c[float],d[int],e[改变类型] + [44] = function(role, args) + local f1 = args[1] + local pro = args[2] + local f2 = args[3] + local f3 = args[4] + local ct = args[5] + + local OnSkillCastEnd = function(skill) + BattleUtil.RandomAction(f1, function () + role:AddBuff(Buff.Create(role, BuffName.PropertyChange, f3, propertyList[pro], f2, ct)) + end) + end + role.Event:AddEvent(BattleEventName.SkillCastEnd, OnSkillCastEnd) + end, + + --免疫[a]控制状态。 + --a[控制类型] + [45] = function(role, args) + local ct = args[1] + role.buffFilter:Add(function(buff) + return buff.type == BuffName.Control and (ct == 0 or buff.ctrlType == ct) + end) + end, + + --免疫[a]持续伤害状态。 + --a[持续伤害类型] + [46] = function(role, args) + local dt = args[1] + role.buffFilter:Add(function(buff) + return buff.type == BuffName.DOT and (dt == 0 or buff.damageType == dt) + end) + end, + + --战斗中,[c]改变[a]属性[b]。 + --a[属性],b[float],c[改变类型] + [47] = function(role, args) + local pro = args[1] + local f1 = args[2] + local ct = args[3] + + if ct == 1 then --加算 + role.data:AddValue(propertyList[pro], f1) + elseif ct == 2 then --乘加算(百分比属性加算) + role.data:AddPencentValue(propertyList[pro], f1) + elseif ct == 3 then --减算 + role.data:SubValue(propertyList[pro], f1) + elseif ct == 4 then --乘减算(百分比属性减算) + role.data:SubPencentValue(propertyList[pro], f1) + end + end, } return passivityList \ No newline at end of file diff --git a/luafight/Modules/Battle/Logic/Base/Skill.lua b/luafight/Modules/Battle/Logic/Base/Skill.lua index e96b5dcaa..6d0f3a98f 100644 --- a/luafight/Modules/Battle/Logic/Base/Skill.lua +++ b/luafight/Modules/Battle/Logic/Base/Skill.lua @@ -268,12 +268,12 @@ function Skill:Cast() BattleLogic.AddMP(self.owner.camp, 10) if self.owner.skill then local skill = self.owner.skill - local time = max(6-self.owner:GetRoleData(RoleDataName.Speed)/(8*(self.owner:GetRoleData(RoleDataName.Level)+10)), 1.5) + local time = max(8-self.owner:GetRoleData(RoleDataName.Speed)/(8*(self.owner:GetRoleData(RoleDataName.Level)+10)), 1.5) skill.sp = 0 skill.spPass = floor(time * BattleLogic.GameFrameRate) end else - local time = max(6-self.owner:GetRoleData(RoleDataName.Speed)/(8*(self.owner:GetRoleData(RoleDataName.Level)+10)), 1.5) + local time = max(8-self.owner:GetRoleData(RoleDataName.Speed)/(8*(self.owner:GetRoleData(RoleDataName.Level)+10)), 1.5) self.sp = 0 self.spPass = floor(time * BattleLogic.GameFrameRate) BattleLogic.AddMP(self.owner.camp, 8) diff --git a/luafight/Modules/Battle/Logic/BattleLogic.lua b/luafight/Modules/Battle/Logic/BattleLogic.lua index 465af8434..44c1e3844 100644 --- a/luafight/Modules/Battle/Logic/BattleLogic.lua +++ b/luafight/Modules/Battle/Logic/BattleLogic.lua @@ -26,7 +26,7 @@ BattleLogic.Event = BattleEvent.New() BattleLogic.BuffMgr = BuffManager.New() local playerTeamDummyRole = {camp = 0, Event = BattleLogic.Event, isTeam = true} -local enemyTeamDummyRole = {camp = 0, Event = BattleLogic.Event, isTeam = true} +local enemyTeamDummyRole = {camp = 1, Event = BattleLogic.Event, isTeam = true} local playerTeamSkillList = {} local enemyTeamSkillList = {} local playerTeamSkillIndex @@ -46,8 +46,7 @@ BattleLogic.TotalOrder = 0 --当前波次 BattleLogic.CurOrder = 0 -local maxFrame = BattleLogic.GameFrameRate * 300 --战斗最大用时5分钟,超时判负 - +local maxFrame --战斗最大用时,超时判负 local actionPool = BattleObjectPool.New(function () return { 0, 0 } end) @@ -60,11 +59,12 @@ local rolePool = BattleObjectPool.New(function () return RoleLogic.New() end) -function BattleLogic.Init(data, optionData) +function BattleLogic.Init(maxTime, data, optionData) if BattleLogic.IsOpenBattleRecord then record = {} end + maxFrame = BattleLogic.GameFrameRate * maxTime fightData = data if optionData then optionRecord = optionData diff --git a/luafight/Modules/Battle/Logic/Misc/BattleUtil.lua b/luafight/Modules/Battle/Logic/Misc/BattleUtil.lua index 36c2305b0..80343117b 100644 --- a/luafight/Modules/Battle/Logic/Misc/BattleUtil.lua +++ b/luafight/Modules/Battle/Logic/Misc/BattleUtil.lua @@ -62,7 +62,16 @@ end function BattleUtil.ApplyDamage(atkRole, defRole, damage, bCrit, damageType) bCrit = bCrit or false damageType = damageType or 0 - damage = floor(damage + 0.5) + + if atkRole.isTeam then + --max(技能基础伤害*(1+已方异妖伤害加成-目标异妖伤害减免),30%×技能基础伤害) + local arr = BattleLogic.Query(function (r) return r.camp == atkRole.camp end) + local n = 0 + for i=1, #arr do + n = n + arr[i]:GetRoleData(RoleDataName.TeamDamageBocusFactor) + end + damage = floor(max(damage * (1 + n / #arr - defRole:GetRoleData(RoleDataName.TeamDamageReduceFactor)), 0.3 * damage)) + end --加入被动效果 local damagingFunc = function(dmgDeduction) damage = damage - dmgDeduction end @@ -111,7 +120,7 @@ function BattleUtil.CalDamage(atkRole, defRole, damageType, baseFactor, ignoreDe local bCrit = false local baseDamage ignoreDef = 1 - (ignoreDef or 0) - bCrit = Random.Range01() <= clamp(atkRole:GetRoleData(RoleDataName.Crit), 0, 1) + bCrit = Random.Range01() <= clamp(atkRole:GetRoleData(RoleDataName.Crit)-defRole:GetRoleData(RoleDataName.Tenacity), 0, 1) local defence = 0 if damageType == 1 then --1 物理 2 魔法 defence = defRole:GetRoleData(RoleDataName.PhysicalDefence) @@ -135,7 +144,7 @@ function BattleUtil.CalDamage(atkRole, defRole, damageType, baseFactor, ignoreDe baseDamage = max(attack - 0.5 * defence * ignoreDef, 0) end --伤害 =(基础伤害*(1+己伤害加成-目标伤害减免)*(1+己方属性伤害加成-目标属性伤害减免),10%*己攻) - local element = 1 + local exFactor = 1 + atkRole:GetRoleData(RoleDataName.DamageBocusFactor) - defRole:GetRoleData(RoleDataName.DamageReduceFactor) local elementDamageReduceFactor = RoleDataName.FireDamageReduceFactor if atkRole.element == 1 then elementDamageReduceFactor = RoleDataName.FireDamageReduceFactor @@ -150,9 +159,9 @@ function BattleUtil.CalDamage(atkRole, defRole, damageType, baseFactor, ignoreDe elseif atkRole.element == 6 then elementDamageReduceFactor = RoleDataName.DarkDamageReduceFactor end - element = (1 + atkRole:GetRoleData(RoleDataName.ElementDamageBocusFactor)) * max(1 - defRole:GetRoleData(elementDamageReduceFactor), 0) + exFactor = exFactor * (1 + atkRole:GetRoleData(RoleDataName.ElementDamageBocusFactor) - defRole:GetRoleData(elementDamageReduceFactor)) - baseDamage = baseDamage * baseFactor * element + baseDamage = baseDamage * baseFactor * exFactor baseDamage = floor(max(baseDamage, 0.1 * attack)) local func @@ -181,8 +190,9 @@ function BattleUtil.ApplyTreat(castRole, targetRole, value, baseFactor) baseFactor = baseFactor or 1 local maxHp = targetRole:GetRoleData(RoleDataName.MaxHp) local hp = targetRole:GetRoleData(RoleDataName.Hp) - local factor = castRole:GetRoleData(RoleDataName.TreatFacter) - local baseTreat = floor(value * baseFactor * (factor + 1) + 0.5) + local factor = castRole:GetRoleData(RoleDataName.TreatFacter) + 1 + local factor2 = targetRole:GetRoleData(RoleDataName.CureFacter) + 1 + local baseTreat = floor(value * baseFactor * factor * factor2 + 0.5) --加入被动效果 local treatingFunc = function(exFactor) baseTreat = floor(baseTreat * (exFactor + 1) + 0.5) end diff --git a/luafight/Modules/Battle/Logic/RoleLogic.lua b/luafight/Modules/Battle/Logic/RoleLogic.lua index 73f7ed2a2..18750f0da 100644 --- a/luafight/Modules/Battle/Logic/RoleLogic.lua +++ b/luafight/Modules/Battle/Logic/RoleLogic.lua @@ -54,11 +54,16 @@ function RoleLogic:Init(uid, data) self.superSkill.spPass = floor(self.superSkill.cd * BattleLogic.GameFrameRate) self.superSkill.sp = self.superSkill.spPass end - for i = 1, #data.passivity do - local v = data.passivity[i] - local id = v[1] - local args = v[2] - Passivity[id](self, args) + 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 + Passivity[id](self, args) + end end self.isDead = self:GetRoleData(RoleDataName.Hp) <= 0