miduo_client/Assets/ManagedResources/~Lua/Modules/Battle/View/Unit/EnemyView.lua

570 lines
21 KiB
Lua
Raw Normal View History


2020-11-01 15:46:48 +08:00
local RoleConfig = ConfigManager.GetConfig(ConfigName.RoleConfig)
local HeroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
local SkillLogicConfig = ConfigManager.GetConfig(ConfigName.SkillLogicConfig)
local healEffect = "c_xy_0012_skeff_tapsk_healeff"
local rageEffect = "s_jieling_hs_3006_skeff_casting_buff_nuqi"
EnemyView = BattleUnit.New()
function EnemyView.New(go, role, position, root)
local o = BattleUnit.New(go, role, position, root)
setmetatable(o, EnemyView)
EnemyView.__index = EnemyView
o:ctor(go, role, position, root)
return o
end
function EnemyView:onCreate(go, role, position, root)
self.RootPanel = root
self.GameObject = go
self.role = role
self.camp = role.camp
-- 创建技能播放器
self.castingEfectNode = self.RootPanel.enemySkillCast
self.castingNameNode = Util.GetGameObject(self.castingEfectNode, "TongYong_Casting_Shang/DongHua/MingZi")
self.hpSlider = Util.GetGameObject(go, "hpProgress/hp"):GetComponent("Image")
self.hpPassSlider = Util.GetGameObject(go, "hpProgress/hpPass"):GetComponent("Image")
self.nameText = Util.GetGameObject(go, "Name/Text"):GetComponent("Text")
self.level = Util.GetGameObject(go, "lv/Text"):GetComponent("Text")
self.elementImg = Util.GetGameObject(go, "Pro/Image"):GetComponent("Image")
--
2020-11-06 10:12:24 +08:00
local roleId=role.roleData.roleId
local live=HeroConfig[role.roleData.roleId].Live
--如果英雄装备皮肤
if role.roleData.skinId and role.roleData.skinId>0 then
roleId=role.roleData.skinId
local skin=ConfigManager.GetConfigDataByKey(ConfigName.HeroSkin,"Type",roleId)
if skin then
live=skin.Live
end
end
if not role.roleData.skinId then
self.skinId=0
else
self.skinId=roleId
end
2020-11-01 15:46:48 +08:00
self.hpCache = self.role:GetRoleData(RoleDataName.Hp) / self.role:GetRoleData(RoleDataName.MaxHp)
self.hpSlider.fillAmount = self.hpCache
self.hpPassSlider.fillAmount = self.hpCache
2020-11-06 10:12:24 +08:00
self.livePath = GetResourcePath(live)
self.play_liveScale = RoleConfig[roleId].play_liveScale
self.enemy_liveScale = RoleConfig[roleId].enemy_liveScale
self.offset = RoleConfig[roleId].offset
self.outOffset = RoleConfig[roleId].enemy_offset
self.spAtkTime = RoleConfig[roleId].CastingSkills/1000
self.atkSoundTime = RoleConfig[roleId].CastingAudio/1000
self.attackSound = RoleConfig[roleId].sond
self.readingName = HeroConfig[role.roleData.roleId].ReadingName
2020-11-01 15:46:48 +08:00
--
self.nameText.text = self.readingName
self.level.text = role:GetRoleData(RoleDataName.Level)
self.elementImg.sprite = Util.LoadSprite(GetProStrImageByProNum(role.roleData.element))
--
self.RoleLiveGO = poolManager:LoadLive(self.livePath, go.transform.parent, Vector3.one, Vector3.zero)
self.RoleLiveGOGraphic = self.RoleLiveGO:GetComponent("SkeletonGraphic")
self.RoleLiveGOTran = self.RoleLiveGO:GetComponent("RectTransform")
self.RoleLiveGOGraphic.AnimationState:SetAnimation(0, "idle", true)
self.RoleLiveGOTran.sizeDelta = Vector2.New(1000, 1000)
self.RoleLiveGO.transform:SetParent(Util.GetTransform(self.RootPanel.EnemyPanel, "live_"..position))
self.RoleLiveGO:GetComponent("RectTransform").anchoredPosition = Vector2.New(self.outOffset[1], self.outOffset[2])-- * 0.5
self.RoleLiveGO.transform.localScale = Vector3.one * self.enemy_liveScale --* 0.75
self.RoleLiveGO:SetActive(true)
-- casting技能立绘
self.RoleLiveGO2 = poolManager:LoadLive(self.livePath, go.transform.parent, Vector3.one, Vector3.zero)
self.RoleLiveGOGraphic2 = self.RoleLiveGO2:GetComponent("SkeletonGraphic")
self.RoleLiveGOTran2 = self.RoleLiveGO2:GetComponent("RectTransform")
self.RoleLiveGOGraphic2.AnimationState:SetAnimation(0, "idle", true)
self.RoleLiveGOTran2.sizeDelta = Vector2.New(1000, 1000)
self.RoleLiveGO2.transform:SetParent(self.RootPanel.enemySkillCastRoot.transform)
self.RoleLiveGO2:GetComponent("RectTransform").anchoredPosition = Vector2.New(self.outOffset[1], self.outOffset[2] + 400)
self.RoleLiveGO2.transform.localScale = Vector3.one * self.enemy_liveScale --* 2
self.RoleLiveGO2:SetActive(false)
-- 阴影
self.shadow = Util.GetGameObject(self.RootPanel.EnemyPanel, "live_"..position.."/shadow")
self.shadow:SetActive(true)
-- 死亡特凶啊
self.effect_dead = Util.GetGameObject(go, "effect_Dead")
self.deadIconGO = Util.GetGameObject(go, "buttom/dead")
self.effect_dead:SetActive(false)
self.deadIconGO:SetActive(false)
-- 测试用
Util.GetGameObject(go, "buttom/pos"):GetComponent("Image").sprite = Util.LoadSprite("r_zhandou_difangweizhi_0"..role.position)
self.rageCache = nil
self.rageSlider = Util.GetGameObject(go, "rageProgress/rage"):GetComponent("Image")
self.rageText = Util.GetGameObject(go, "rageProgress/Text"):GetComponent("Text")
self.effect_rage = Util.GetGameObject(go, "rageProgress/effect")
self.effect_rage:SetActive(self.role.Rage >= 4)
self.rageSlider.fillAmount = self.role.Rage / 4
self.rageText.gameObject:SetActive(false)
self.rageText.text = ""
-- 伤害文字显示
self.LastBuffFloatingTime = Time.realtimeSinceStartup
self.BuffFloatingCount = 0
-- 飘字管理
self.Floater = FloatNode.New(self, self.RootPanel, self.GameObject)
-- buff管理
self.BuffCtrl = BuffCtrl.New(self, Util.GetGameObject(go, "buff"))
-- 创建技能播放器
self.SkillCaster = SkillCaster.New(self, self.spAtkTime, self.atkSoundTime, self.attackSound, self.castingEfectNode, self.castingNameNode)
role.Event:AddEvent(BattleEventName.BeHitMiss, self.OnBeHitMiss, self)
role.Event:AddEvent(BattleEventName.RoleBeDamaged, self.OnDamaged, self)
role.Event:AddEvent(BattleEventName.RoleBeTreated, self.OnTreated, self)
role.Event:AddEvent(BattleEventName.RoleBeHealed, self.OnHealed, self)
role.Event:AddEvent(BattleEventName.RoleDead, self.OnDead, self)
role.Event:AddEvent(BattleEventName.RoleRealDead, self.OnRealDead, self)
role.Event:AddEvent(BattleEventName.RoleRageChange, self.RoleRageChange, self)
role.Event:AddEvent(BattleEventName.RoleRelive, self.onRoleRelive, self)
role.Event:AddEvent(BattleEventName.AOE, self.OnAOE, self)
role.Event:AddEvent(BattleEventName.BeSeckill, self.onBeSecKill, self)
role.Event:AddEvent(BattleEventName.ShildTrigger, self.OnShieldTrigger, self)
role.Event:AddEvent(BattleEventName.ShowHintText,self.OnShowHintText,self)
if IsOpenBattleDebug then
local URoleProperty = go:GetComponent(typeof(RoleProperty))
if not URoleProperty then
URoleProperty = go:AddComponent(typeof(RoleProperty))
end
self.URoleProperty = URoleProperty
self.URoleProperty.uid = role.uid
role.data:Foreach(function (name, value)
self.URoleProperty:AddProperty(name, value)
end)
end
end
--
function EnemyView:OnSortingOrderChange(battleSorting)
end
-- 改变卡牌层级
function EnemyView:ChangeCardSorting(sortingOrder)
if not self.oSortingOrder then
self.oSortingOrder = BattleManager.GetBattleSorting()
end
self.GameObject:GetComponent("Canvas").sortingOrder = sortingOrder
self.effect_rage:GetComponent("Canvas").sortingOrder = sortingOrder
self.effect_dead:GetComponent("Canvas").sortingOrder = sortingOrder
Util.AddParticleSortLayer(self.effect_rage, sortingOrder - self.oSortingOrder)
Util.AddParticleSortLayer(self.effect_dead, sortingOrder - self.oSortingOrder)
self.oSortingOrder = sortingOrder
end
function EnemyView:Update()
if self.role:IsRealDead() then
return
end
local hp = self.role:GetRoleData(RoleDataName.Hp) / self.role:GetRoleData(RoleDataName.MaxHp)
if self.hpCache ~= hp then
local f1 = self.hpCache
local f2 = hp
if f1 > f2 then
if self.hpTween then
self.hpTween:Kill()
end
self.hpSlider.fillAmount = hp
self.hpTween = DoTween.To(DG.Tweening.Core.DOGetter_float( function () return f1 end),
DG.Tweening.Core.DOSetter_float(function (progress)
self.hpPassSlider.fillAmount = progress
end), f2, 0.5):SetEase(Ease.Linear)
else
if self.hpPassTween then
self.hpPassTween:Kill()
end
self.hpPassSlider.fillAmount = hp
self.hpPassTween = DoTween.To(DG.Tweening.Core.DOGetter_float( function () return f1 end),
DG.Tweening.Core.DOSetter_float(function (progress)
self.hpSlider.fillAmount = progress
end), f2, 0.5):SetEase(Ease.Linear)
end
self.hpCache = hp
end
local rage = self.role.Rage / 4
if self.rageCache ~= rage then
-- 判断是否播放满怒动画
if (not self.rageCache or self.rageCache < 1) and rage >= 1 then
local go = BattleManager.LoadAsset(rageEffect)
go.transform:SetParent(self.GameObject.transform)
go.transform.localScale = Vector3.one
go.transform.localPosition = Vector3.zero
go:SetActive(true)
BattleManager.AddDelayRecycleRes(rageEffect, go, 3)
end
self.effect_rage:SetActive(rage >= 1)
self.rageCache = rage
self.rageSlider.fillAmount = self.rageCache
self.rageText.gameObject:SetActive(self.rageCache >= 1)
self.rageText.text = self.role.Rage
end
if self.BuffCtrl and self.BuffCtrl.Update then
self.BuffCtrl:Update()
end
if IsOpenBattleDebug then
self.role.data:Foreach(function (name, value)
self.URoleProperty:SetValue(name, value)
end)
end
end
-- 缩放
function EnemyView:DoScale(scale, dur, func)
if self.dsTween then
self.dsTween:Kill()
end
self.dsTween = self.GameObject.transform.parent:DOScale(Vector3.one * scale, dur)
:OnComplete(function ()
-- Log("DoScale = "..scale)
if func then
func()
end
end)
if self.dsTween2 then
self.dsTween2:Kill()
end
local liveScale = self.role.position <= 3 and 0.6 or 0.5
self.dsTween2 = self.RoleLiveGO.transform.parent:DOScale(Vector3.one * liveScale * scale, dur)
end
-- 设置高亮
function EnemyView:SetHighLight(isLight, eScale, dur, func)
-- 设置变灰
if self.isDead then
Util.SetGray(self.GameObject, true)
Util.SetSpineGray(self.RoleLiveGOGraphic, true)
Util.SetGray(self.deadIconGO, false)
local color = Color.New(75, 75, 75, 255)/255
Util.SetColor(self.GameObject, color)
Util.SetColor(self.RoleLiveGOGraphic, color)
Util.SetColor(self.deadIconGO, Color.New(1, 1, 1, 1))
self:DoScale(0.8, dur, func)
return
end
self:DoScale(eScale, dur, func)
-- 颜色变灰
local sc = isLight and 0.3 or 1
local ec = isLight and 1 or 0.3
if self.hlTween3 then
self.hlTween3:Kill()
end
self.hlTween3 = DoTween.To(DG.Tweening.Core.DOGetter_float( function () return sc end),
DG.Tweening.Core.DOSetter_float(function (progress)
local color = Color.New(progress, progress, progress, 1)
Util.SetColor(self.GameObject, color)
Util.SetColor(self.RoleLiveGOGraphic, color)
end), ec, dur):SetEase(Ease.Linear)
end
-- 播放动画
function EnemyView:PlaySpineAnim(gog, time, name, isLoop)
if isLoop then
gog.AnimationState:SetAnimation(time, name, isLoop)
else
local _complete = nil
_complete = function(state)
gog.AnimationState.Complete = gog.AnimationState.Complete - _complete
gog.AnimationState:SetAnimation(0, "idle", true)
end
gog.AnimationState:ClearTracks() -- 清除上一个动画的影响(修复概率攻击动画播放错误的问题)
gog.AnimationState:SetAnimation(time, name, isLoop)
gog.AnimationState.Complete = gog.AnimationState.Complete + _complete
end
end
--单纯显示提示文字
function EnemyView:OnShowHintText(_ArtFontType)
local config = BattleManager.GetArtFontConfig(_ArtFontType)
if config then
self.Floater:TextBuffFloating(config.type, config.content)
end
end
2020-11-01 15:46:48 +08:00
function EnemyView:OnSkillPlay()
self:PlaySpineAnim(self.RoleLiveGOGraphic, 0, "attack", false)
end
function EnemyView:OnSkillEnd()
end
function EnemyView:OnSkillCastingStart()
-- 提前进入下一阶段
self.RoleLiveGO2:SetActive(true)
self:PlaySpineAnim(self.RoleLiveGOGraphic2, 0, "touch", false)
end
function EnemyView:OnSkillCastingEnd()
self.RoleLiveGO2:SetActive(false)
end
-- 治疗
function EnemyView:OnTreated(castRole, realTreat, treat)
self.Floater:ArtFloating(ArtFloatingType.Treat, ArtFloatingColor.Green, treat)
local sortingOrder = nil
local go = BattleManager.LoadAsset(healEffect, sortingOrder)
go.transform:SetParent(self.GameObject.transform)
go.transform.localScale = Vector3.one
go.transform.localPosition = Vector3.zero--self.GameObject.transform.localPosition
go:SetActive(true)
BattleManager.AddDelayRecycleRes(healEffect, go, 3)
end
-- 盾效果触发
function EnemyView:OnShieldTrigger(shield,isImmuneAllReduceShield)
2020-11-01 15:46:48 +08:00
if shield.shieldType == ShieldTypeName.AllReduce then
if atkRole and not isImmuneAllReduceShield then
self.Floater:ImageBuffFloating("z_zhandou_wudizi")
end
2020-11-01 15:46:48 +08:00
else
2021-01-26 11:05:27 +08:00
self.Floater:TextBuffFloating(TextFloatingColor.Blue, Language[10275])
2020-11-01 15:46:48 +08:00
end
end
-- 哈哈,没打着
function EnemyView:OnBeHitMiss(atkRole, skill)
2021-01-26 11:05:27 +08:00
self.Floater:TextBuffFloating(TextFloatingColor.Blue, Language[12218])
2020-11-01 15:46:48 +08:00
end
local DotTypeTip = {
2021-01-26 11:05:27 +08:00
[0] = Language[10276],
[1] = Language[10277],
[2] = Language[10278],
[3] = Language[10279],
2020-11-01 15:46:48 +08:00
}
--
function EnemyView:OnDamaged(atkRole, dmg, bCrit, finalDmg, damageType, dotType, skill)
if skill and skill.continueTime > 0 and skill.attackCount > 1 then
local space = skill.continueTime / skill.attackCount
local count = skill.attackCount
local d = math.floor(dmg/count)
-- 如果平均伤害小于0 则
if d == 0 then
d = dmg
count = 1
end
if BattleManager.IsBattleTestPanel() then
LogYellow(string.format("目标阵营:%s, 位置:%s, 总伤害:%s, 伤害段数:%s每段伤害%s", self.camp, self.role.position, dmg, count, d))
end
2020-11-01 15:46:48 +08:00
if count ~= 1 then
-- 后续伤害延迟打出
self:LoopFunc(space, count - 1, function()
self:OnceDamaged(atkRole, d, bCrit, finalDmg, damageType, dotType, skill)
end)
-- 立刻打出第一次伤害
local fd = dmg - d *(count - 1)
self:OnceDamaged(atkRole, fd, bCrit, finalDmg, damageType, dotType, skill)
else
self:OnceDamaged(atkRole, dmg, bCrit, finalDmg, damageType, dotType, skill)
end
else
if BattleManager.IsBattleTestPanel() then
LogYellow(string.format("目标阵营:%s, 位置:%s, 总伤害:%s", self.camp, self.role.position, dmg))
end
2020-11-01 15:46:48 +08:00
self:OnceDamaged(atkRole, dmg, bCrit, finalDmg, damageType, dotType, skill)
end
end
--
function EnemyView:OnceDamaged(atkRole, dmg, bCrit, finalDmg, damageType, dotType, skill)
--王振兴注释,为了解决英雄死亡多段伤害显示不完整 2020/8/17
--if self.isDead then return end
if dotType then
if dotType == DotType.Poison then
self.Floater:ArtFloating(ArtFloatingType.PoisonDamage, ArtFloatingColor.Poison, dmg)
elseif dotType == DotType.Burn then
self.Floater:ArtFloating(ArtFloatingType.FireDamage, ArtFloatingColor.Fire, dmg)
else
self.Floater:TextBuffFloating(2, DotTypeTip[dotType]..dmg)
end
else
if bCrit then -- 暴击红色并显示暴击
self.Floater:ArtFloating(ArtFloatingType.CritDamage, ArtFloatingColor.Red, dmg)
else
if atkRole.isTeam then -- 异妖紫色
self.Floater:ArtFloating(ArtFloatingType.Damage, ArtFloatingColor.Purple, dmg)
else
if skill and skill.type == BattleSkillType.Special then -- 技能黄色
self.Floater:ArtFloating(ArtFloatingType.Damage, ArtFloatingColor.Yellow, dmg)
else -- 普攻白色
self.Floater:ArtFloating(ArtFloatingType.Damage, ArtFloatingColor.White, dmg)
end
end
end
end
self.RoleLiveGOTran:DOShakeAnchorPos(0.3, Vector2.New(200, 100), 100, 50, false, true):OnComplete(function ()
self.RoleLiveGO.transform.anchoredPosition = Vector2.New(self.outOffset[1], self.outOffset[2] )
end)
self.RoleLiveGOGraphic:DOColor(Color.New(1,0,0,1), 0.3):OnComplete(function ()
self.RoleLiveGOGraphic:DOColor(Color.New(1,1,1,1), 0.1)
end)
-- 受击放大1.2倍
self:DoScale(1.2, 0.3, function()
self:DoScale(1, 0.1)
end)
-- 播放受击动画
self:PlaySpineAnim(self.RoleLiveGOGraphic, 0, "hit", false)
-- bo
if skill then
local combatId = BattleManager.GetCombatIdBySkin(skill.id, atkRole.roleData.skinId)
local combat = BattleManager.GetSkillCombat(combatId)
2020-11-01 15:46:48 +08:00
self.SkillCaster:CheckSkillHitEffect("hit", combat, skill)
end
end
function EnemyView:OnHealed(castRole)
local sortingOrder = nil
local go = BattleManager.LoadAsset(healEffect, sortingOrder)
go.transform:SetParent(self.GameObject.transform)
go.transform.localScale = Vector3.one
go.transform.localPosition = Vector3.zero--self.GameObject.transform.localPosition
go:SetActive(true)
BattleManager.AddDelayRecycleRes(healEffect, go, 3)
end
-- 怒气值改变
function EnemyView:RoleRageChange(deltaRage)
if self.role:IsRealDead() then
return
end
2020-11-01 15:46:48 +08:00
if deltaRage ~= 0 then
if deltaRage > 0 then
self.Floater:ImageBuffFloating("z_zhandou_nuqijia", nil, deltaRage)
else
2021-01-26 11:05:27 +08:00
self.Floater:TextBuffFloating(1, Language[10283]..tostring(deltaRage))
2020-11-01 15:46:48 +08:00
end
end
end
function EnemyView:OnDead()
if self.hpTween then
self.hpTween:Kill()
end
if self.hpPassTween then
self.hpPassTween:Kill()
end
self.hpSlider.fillAmount = 0
self.hpPassSlider.fillAmount = 0
self.rageSlider.fillAmount = 0
self.rageText.text = ""
end
-- 暴毙
function EnemyView:onBeSecKill()
2021-01-26 11:05:27 +08:00
self.Floater:TextBuffFloating(TextFloatingColor.Red, Language[10284])
2020-11-01 15:46:48 +08:00
end
function EnemyView:OnRealDead()
self.effect_rage:SetActive(false)
self.effect_dead:SetActive(true)
self.RoleLiveGO:SetActive(true)
local order = BattleLogic.CurOrder
BattleManager.PauseBattle()
self.RoleLiveGOGraphic:DOFade(1, 0):OnComplete(function ()
self.RoleLiveGOGraphic:DOFade(0, 1):OnComplete(function ()
BattleManager.ResumeBattle()
self.RoleLiveGOGraphic.color = Color.New(1,1,1,1)
if order ~= BattleLogic.CurOrder then return end
self.GameObject:SetActive(false)
self.RoleLiveGO:SetActive(false)
self.effect_dead:SetActive(false)
if self.shadow then
self.shadow:SetActive(false)
end
end)
end)
self.deadIconGO:SetActive(true)
local color = Color.New(75, 75, 75, 255)/255
Util.SetColor(self.GameObject, color)
Util.SetColor(self.RoleLiveGOGraphic, color)
Util.SetGray(self.deadIconGO, false)
self.BuffCtrl:Dispose()
self.RoleLiveGOGraphic.freeze = true
self.RoleLiveGOGraphic2.freeze = true
self.isDead = true
end
function EnemyView:onRoleRelive()
self.effect_dead:SetActive(false)
self.GameObject:SetActive(true)
self.RoleLiveGO:SetActive(true)
if self.shadow then
self.shadow:SetActive(true)
end
self.deadIconGO:SetActive(false)
local color = Color.New(1, 1, 1, 1)
Util.SetColor(self.GameObject, color)
Util.SetColor(self.RoleLiveGOGraphic, color)
Util.SetGray(self.GameObject, false)
Util.SetSpineGray(self.RoleLiveGOGraphic, false)
self:DoScale(1, 0)
self.RoleLiveGOGraphic.freeze = false
self.RoleLiveGOGraphic2.freeze = false
self.isDead = false
self.hpSlider.fillAmount=self.role:GetRoleData(RoleDataName.Hp) / self.role:GetRoleData(RoleDataName.MaxHp)
2020-11-01 15:46:48 +08:00
--
2021-01-26 11:05:27 +08:00
self.Floater:TextBuffFloating(4, Language[10285])
2020-11-01 15:46:48 +08:00
end
function EnemyView:onDispose()
self.GameObject.transform.parent.localScale = Vector3.one
self.BuffCtrl:Dispose()
--
Util.SetSpineGray(self.RoleLiveGOGraphic, false)
Util.SetSpineGray(self.RoleLiveGOGraphic2, false)
Util.SetColor(self.RoleLiveGOGraphic, Color.New(1, 1, 1, 1))
Util.SetColor(self.RoleLiveGOGraphic2, Color.New(1, 1, 1, 1))
self.RoleLiveGOGraphic.freeze = false
self.RoleLiveGOGraphic2.freeze = false
poolManager:UnLoadLive(self.livePath, self.RoleLiveGO)
poolManager:UnLoadLive(self.livePath, self.RoleLiveGO2)
-- 回收本节点
BattlePool.RecycleItem(self.GameObject, BATTLE_POOL_TYPE.ENEMY_ROLE)
end