被动
This commit is contained in:
parent
fd4e6d88c4
commit
281d220052
@ -16,6 +16,7 @@ BattleConst.SIDE_DEF = 2
|
|||||||
BattleConst.SKILL_TYPE_ACTIVE = 1
|
BattleConst.SKILL_TYPE_ACTIVE = 1
|
||||||
BattleConst.SKILL_TYPE_NORMAL = 2
|
BattleConst.SKILL_TYPE_NORMAL = 2
|
||||||
BattleConst.SKILL_TYPE_ASSISTING = 3
|
BattleConst.SKILL_TYPE_ASSISTING = 3
|
||||||
|
BattleConst.SKILL_TYPE_PASSIVE = 4
|
||||||
BattleConst.SKILL_SELECT_COUNT = 3
|
BattleConst.SKILL_SELECT_COUNT = 3
|
||||||
BattleConst.DEFAULT_FACTOR = 10000
|
BattleConst.DEFAULT_FACTOR = 10000
|
||||||
BattleConst.INIT_POS_X = 200 -- 战斗单位初始化的坐标
|
BattleConst.INIT_POS_X = 200 -- 战斗单位初始化的坐标
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
local BattleConst = require "app/module/battle/battle_const"
|
local BattleConst = require "app/module/battle/battle_const"
|
||||||
local BattleHelper = require "app/module/battle/helper/battle_helper"
|
local BattleHelper = require "app/module/battle/helper/battle_helper"
|
||||||
local BattleBuffHandle = require "app/module/battle/helper/battle_buff_handle"
|
local BattleBuffHandle = require "app/module/battle/helper/battle_buff_handle"
|
||||||
|
local BattlePassive = require "app/module/battle/helper/battle_passive"
|
||||||
|
|
||||||
local BattleUnitComp = class("BattleUnitComp", LuaComponent)
|
local BattleUnitComp = class("BattleUnitComp", LuaComponent)
|
||||||
|
|
||||||
@ -77,9 +78,96 @@ function BattleUnitComp:initWithEntity(modelId, entity, battleController, target
|
|||||||
self.side = entity:getSide()
|
self.side = entity:getSide()
|
||||||
self:_initBase()
|
self:_initBase()
|
||||||
self:initPosition()
|
self:initPosition()
|
||||||
|
self:initPassiveSkills()
|
||||||
self:playBorn()
|
self:playBorn()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BattleUnitComp:initPassiveSkills()
|
||||||
|
local pasSkills = self.unitEntity:getPassiveSkills()
|
||||||
|
if pasSkills and #pasSkills > 0 then
|
||||||
|
if self.passiveSkills == nil then
|
||||||
|
self.passiveSkills = {}
|
||||||
|
else
|
||||||
|
self:removeAllPassiveSkills()
|
||||||
|
end
|
||||||
|
for k, skill in ipairs(pasSkills) do
|
||||||
|
local id = skill:getPassiveTriggerId()
|
||||||
|
if id then
|
||||||
|
skill:clearRecordData()
|
||||||
|
local skills = self.passiveSkills[id]
|
||||||
|
if skills == nil then
|
||||||
|
skills = {}
|
||||||
|
self.passiveSkills[id] = skills
|
||||||
|
end
|
||||||
|
table.insert(skills, skill)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleUnitComp:addPassiveSkill(pasSkill)
|
||||||
|
pasSkill:clearRecordData()
|
||||||
|
if self.passiveSkills == nil then
|
||||||
|
self.passiveSkills = {}
|
||||||
|
end
|
||||||
|
local id = pasSkill:getPassiveTriggerId()
|
||||||
|
if id then
|
||||||
|
local skills = self.passiveSkills[id]
|
||||||
|
if skills == nil then
|
||||||
|
skills = {}
|
||||||
|
self.passiveSkills[id] = skills
|
||||||
|
end
|
||||||
|
table.insert(skills, pasSkill)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleUnitComp:removePassiveSkill(skill)
|
||||||
|
if self.passiveSkills == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local id = skill:getPassiveTriggerId()
|
||||||
|
if id then
|
||||||
|
local skills = self.passiveSkills[id]
|
||||||
|
if skills then
|
||||||
|
for k, v in ipairs(skills) do
|
||||||
|
if v == skill then
|
||||||
|
table.remove(skills, k)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleUnitComp:removeAllPassiveSkills()
|
||||||
|
if self.passiveSkills then
|
||||||
|
for _, skills in pairs(self.passiveSkills) do
|
||||||
|
local count = #skills
|
||||||
|
for i = 1, count do
|
||||||
|
table.remove(skills)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleUnitComp:addSkill(skillId)
|
||||||
|
local skillEntity = self.unitEntity:addSkill(skillId)
|
||||||
|
if skillEntity then
|
||||||
|
if skillEntity:getIsPassiveType() then -- 添加被动
|
||||||
|
self:addPassiveSkill(skillEntity)
|
||||||
|
end
|
||||||
|
return skillEntity:getSid()
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleUnitComp:removeSkill(skillId, sid)
|
||||||
|
local skillEntity = self.unitEntity:removeSkill(skillId, sid)
|
||||||
|
if skillEntity and skillEntity:getIsPassiveType() then
|
||||||
|
self:removePassiveSkill(skillEntity)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function BattleUnitComp:hideOutsideScreen()
|
function BattleUnitComp:hideOutsideScreen()
|
||||||
if self.unitEntity:getSide() == SIDE_ATK then
|
if self.unitEntity:getSide() == SIDE_ATK then
|
||||||
self.baseObject:setLocalPosition(-GConst.UI_SCREEN_WIDTH/2 - BattleConst.UNIT_BODY_WIDTH, 0, 0)
|
self.baseObject:setLocalPosition(-GConst.UI_SCREEN_WIDTH/2 - BattleConst.UNIT_BODY_WIDTH, 0, 0)
|
||||||
@ -807,6 +895,30 @@ function BattleUnitComp:tick(dt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BattleUnitComp:checkPassiveEvent(eventId, targetComp, ...)
|
||||||
|
if self.passiveSkills == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local skills = self.passiveSkills[eventId]
|
||||||
|
if skills and #skills > 0 then
|
||||||
|
local func = BattlePassive.checkTrigger[eventId]
|
||||||
|
if func then
|
||||||
|
for _, skill in ipairs(skills) do
|
||||||
|
local count = func(self, skill, targetComp, ...)
|
||||||
|
if count > 0 and skill:getIsAvailable() then
|
||||||
|
for i = 1, count do
|
||||||
|
self:usePassiveSkill(skill)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleUnitComp:usePassiveSkill(skill)
|
||||||
|
self:onSkillTakeEffect(skill)
|
||||||
|
end
|
||||||
|
|
||||||
function BattleUnitComp:getIsClear()
|
function BattleUnitComp:getIsClear()
|
||||||
return self.isClear
|
return self.isClear
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
local BattleHelper = require "app/module/battle/helper/battle_helper"
|
local BattleHelper = require "app/module/battle/helper/battle_helper"
|
||||||
local BattleScheduler = require "app/module/battle/helper/battle_scheduler"
|
local BattleScheduler = require "app/module/battle/helper/battle_scheduler"
|
||||||
local BattleTeam = require "app/module/battle/team/battle_team"
|
local BattleTeam = require "app/module/battle/team/battle_team"
|
||||||
|
local BattlePassive = require "app/module/battle/helper/battle_passive"
|
||||||
|
|
||||||
local BattleController = class("BattleController")
|
local BattleController = class("BattleController")
|
||||||
|
|
||||||
@ -139,6 +140,7 @@ function BattleController:init(params)
|
|||||||
self.battleData:init()
|
self.battleData:init()
|
||||||
BattleScheduler:init()
|
BattleScheduler:init()
|
||||||
BattleHelper:init()
|
BattleHelper:init()
|
||||||
|
BattlePassive:init()
|
||||||
self:initBattleTeam()
|
self:initBattleTeam()
|
||||||
self:initOther()
|
self:initOther()
|
||||||
self:prepareFight()
|
self:prepareFight()
|
||||||
@ -1214,6 +1216,7 @@ function BattleController:clear()
|
|||||||
end
|
end
|
||||||
BattleScheduler:clear()
|
BattleScheduler:clear()
|
||||||
BattleHelper:clear()
|
BattleHelper:clear()
|
||||||
|
BattlePassive:clear()
|
||||||
end
|
end
|
||||||
|
|
||||||
function BattleController:endBattleAndExit()
|
function BattleController:endBattleAndExit()
|
||||||
|
|||||||
@ -6,11 +6,13 @@ local BUFF_NAME = BattleConst.BUFF_NAME
|
|||||||
local ATTR_NAME = BattleConst.ATTR_NAM
|
local ATTR_NAME = BattleConst.ATTR_NAM
|
||||||
|
|
||||||
local function _addSkillOn(unitComp, buff, target, buffEffect)
|
local function _addSkillOn(unitComp, buff, target, buffEffect)
|
||||||
return 1
|
return target:addSkill(buff:getEffectNum())
|
||||||
end
|
end
|
||||||
|
|
||||||
local function _addSkillOff(buffSender, target, buff, buffEffect)
|
local function _addSkillOff(buffSender, target, buff, buffEffect)
|
||||||
return 1
|
if buffEffect and buffEffect.result > 0 then
|
||||||
|
target:removeSkill(buff:getEffectNum(), buffEffect.result)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function _skillFireTimesOn(unitComp, buff, target, buffEffect)
|
local function _skillFireTimesOn(unitComp, buff, target, buffEffect)
|
||||||
|
|||||||
20
lua/app/module/battle/helper/battle_passive.lua
Normal file
20
lua/app/module/battle/helper/battle_passive.lua
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
local BattleConst = require "app/module/battle/battle_const"
|
||||||
|
|
||||||
|
local BattlePassive = {
|
||||||
|
passiveSkills = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
local PASSIVE_EVENT = BattleConst.PASSIVE_EVENT
|
||||||
|
local SKILL_RECORD_DATA_NAME = BattleConst.SKILL_RECORD_DATA_NAME
|
||||||
|
local DEFAULT_FACTOR = BattleConst.DEFAULT_FACTOR
|
||||||
|
|
||||||
|
function BattlePassive:init()
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattlePassive:clear()
|
||||||
|
end
|
||||||
|
|
||||||
|
BattlePassive.checkTrigger = {
|
||||||
|
}
|
||||||
|
|
||||||
|
return BattlePassive
|
||||||
10
lua/app/module/battle/helper/battle_passive.lua.meta
Normal file
10
lua/app/module/battle/helper/battle_passive.lua.meta
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b44646ca9b5bf8240a4af4b9d2edd001
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
local BattleTeamEntity = require "app/userdata/battle/team/battle_team_entity"
|
local BattleTeamEntity = require "app/userdata/battle/team/battle_team_entity"
|
||||||
|
local BattleSkillEntity = require "app/userdata/battle/skill/battle_skill_entity"
|
||||||
|
|
||||||
local BattleData = class("BattleData", BaseData)
|
local BattleData = class("BattleData", BaseData)
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ function BattleData:init()
|
|||||||
self.needBattleExp = self:getLvNeedExp()
|
self.needBattleExp = self:getLvNeedExp()
|
||||||
self.addLvCount = 0
|
self.addLvCount = 0
|
||||||
self.data.lvDirty = false
|
self.data.lvDirty = false
|
||||||
|
BattleSkillEntity.sid = 0
|
||||||
self.atkTeam = self:initTeam(BattleConst.SIDE_ATK)
|
self.atkTeam = self:initTeam(BattleConst.SIDE_ATK)
|
||||||
self.defTeam = self:initTeam(BattleConst.SIDE_DEF)
|
self.defTeam = self:initTeam(BattleConst.SIDE_DEF)
|
||||||
self:initRogueSkills()
|
self:initRogueSkills()
|
||||||
|
|||||||
@ -2,10 +2,14 @@ local BattleBuffEntity = require "app/userdata/battle/skill/battle_buff_entity"
|
|||||||
|
|
||||||
local BattleSkillEntity = class("BattleSkillEntity", BaseData)
|
local BattleSkillEntity = class("BattleSkillEntity", BaseData)
|
||||||
|
|
||||||
|
BattleSkillEntity.sid = 0
|
||||||
|
|
||||||
function BattleSkillEntity:ctor(skillId, skillType, owner)
|
function BattleSkillEntity:ctor(skillId, skillType, owner)
|
||||||
self.skillType = skillType
|
self.skillType = skillType
|
||||||
self.skillId = skillId
|
self.skillId = skillId
|
||||||
self.owner = owner
|
self.owner = owner
|
||||||
|
BattleSkillEntity.sid = BattleSkillEntity.sid + 1
|
||||||
|
self.sid = BattleSkillEntity.sid
|
||||||
self:init()
|
self:init()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -99,6 +103,10 @@ function BattleSkillEntity:getSkillid()
|
|||||||
return self.skillId
|
return self.skillId
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BattleSkillEntity:getIsPassiveType()
|
||||||
|
return self.skillType == GConst.BattleConst.SKILL_TYPE_PASSIVE
|
||||||
|
end
|
||||||
|
|
||||||
function BattleSkillEntity:changeSkillId(skillId)
|
function BattleSkillEntity:changeSkillId(skillId)
|
||||||
self.skillId = skillId
|
self.skillId = skillId
|
||||||
self:init()
|
self:init()
|
||||||
@ -139,4 +147,34 @@ function BattleSkillEntity:getTargetType()
|
|||||||
return self.skillInfo.obj
|
return self.skillInfo.obj
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BattleSkillEntity:getSid()
|
||||||
|
return self.sid
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleSkillEntity:getPassiveTriggerId()
|
||||||
|
return self.skillInfo.trigger
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleSkillEntity:getRecordData(name)
|
||||||
|
if self.recordData == nil then
|
||||||
|
self.recordData = {}
|
||||||
|
end
|
||||||
|
return self.recordData[name]
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleSkillEntity:setRecordData(name, value)
|
||||||
|
if self.recordData == nil then
|
||||||
|
self.recordData = {}
|
||||||
|
end
|
||||||
|
self.recordData[name] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleSkillEntity:clearRecordData()
|
||||||
|
if self.recordData then
|
||||||
|
for k, v in pairs(self.recordData) do
|
||||||
|
self.recordData[k] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return BattleSkillEntity
|
return BattleSkillEntity
|
||||||
@ -28,6 +28,49 @@ function BattleUnitEntity:initSkill()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BattleUnitEntity:addSkill(skillId)
|
||||||
|
local skillInfo = ConfigManager:getConfig("skill")[skillId]
|
||||||
|
if skillInfo == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
if skillInfo.effect_type == 1 then -- 主动技能
|
||||||
|
local skill = BattleSkillEntity:create(skillId, GConst.BattleConst.SKILL_TYPE_ACTIVE, self)
|
||||||
|
table.insert(self.activeSkills, skill)
|
||||||
|
return skill
|
||||||
|
else -- 被动技能
|
||||||
|
if self.passiveSkills == nil then
|
||||||
|
self.passiveSkills = {}
|
||||||
|
end
|
||||||
|
local skill = BattleSkillEntity:create(skillId, GConst.BattleConst.SKILL_TYPE_PASSIVE, self)
|
||||||
|
table.insert(self.passiveSkills, skill)
|
||||||
|
return skill
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleUnitEntity:removeSkill(skillId, sid)
|
||||||
|
local skillInfo = ConfigManager:getConfig("skill")[skillId]
|
||||||
|
if skillInfo == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
if skillInfo.effect_type == 1 then -- 主动技能
|
||||||
|
for k, v in ipairs(self.activeSkills) do
|
||||||
|
if v:getSid() == sid then
|
||||||
|
return table.remove(self.activeSkills, k)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else -- 被动技能
|
||||||
|
if self.passiveSkills then
|
||||||
|
for k, v in ipairs(self.passiveSkills) do
|
||||||
|
if v:getSid() == sid then
|
||||||
|
return table.remove(self.passiveSkills, k)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
function BattleUnitEntity:addAttr(name, num, isPercent)
|
function BattleUnitEntity:addAttr(name, num, isPercent)
|
||||||
return self.team:addAttr(name, num, isPercent)
|
return self.team:addAttr(name, num, isPercent)
|
||||||
end
|
end
|
||||||
@ -91,6 +134,10 @@ function BattleUnitEntity:getNormalSkillNameList()
|
|||||||
return self.normalSkillNameList, count
|
return self.normalSkillNameList, count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BattleUnitEntity:getPassiveSkills()
|
||||||
|
return self.passiveSkills
|
||||||
|
end
|
||||||
|
|
||||||
function BattleUnitEntity:changeActiveSkillId(originSkillId, tartgetSkillId)
|
function BattleUnitEntity:changeActiveSkillId(originSkillId, tartgetSkillId)
|
||||||
for _, skillEntity in ipairs(self.activeSkills) do
|
for _, skillEntity in ipairs(self.activeSkills) do
|
||||||
if skillEntity:getSkillid() == originSkillId then
|
if skillEntity:getSkillid() == originSkillId then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user