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

333 lines
15 KiB
Lua

local RoleConfig = ConfigManager.GetConfig(ConfigName.RoleConfig)
local SpiritAnimal = ConfigManager.GetConfig(ConfigName.SpiritAnimal)
local SkillLogicConfig = ConfigManager.GetConfig(ConfigName.SkillLogicConfig)
local healEffect = "c_xy_0012_skeff_tapsk_healeff"
local rageEffect = "s_jieling_hs_3006_skeff_casting_buff_nuqi"
MonsterView = BattleUnit.New()
function MonsterView.New(go, role, position, root)
local o = BattleUnit.New(go, role, position, root)
setmetatable(o, MonsterView)
MonsterView.__index = MonsterView
o:ctor(go, role, position, root)
return o
end
function MonsterView:onCreate(go, role, position, root)
self.spLoader = SpriteLoader.New()
self.RootPanel = root
self.GameObject = go
self.role = role
self.camp = role.camp
-- 创建技能播放器
self.castingEfectNode = role.camp == 0 and self.RootPanel.lingshouCastDown or self.RootPanel.lingshouCastUp
self.castingNameNode = Util.GetGameObject(self.castingEfectNode, role.camp == 0 and "EFFECT_Casting_LingShou_Xia/DongHua/MingZi" or "EFFECT_Casting_LingShou_Shang/DongHua/MingZi")
self.skillCastRoot = role.camp == 0 and self.RootPanel.lingshouCastDownRoot or self.RootPanel.lingshouCastUpRoot
self.liveRoot = role.camp == 0 and Util.GetGameObject(self.RootPanel.gameObject, "playerMonster/live") or Util.GetGameObject(self.RootPanel.gameObject, "enemyMonster/live")
self.icon = Util.GetGameObject(go, "icon"):GetComponent("Image")
self.turnEffect=role.camp == 0 and self.RootPanel.lingshouDownEffect or self.RootPanel.lingshouUpEffect
-- 获取数据
self.livePath = nil
if position==100 then
if not role.roleData.id or role.roleData.id == 0 then
role.roleData.id = 20100
end
if role.roleData.id == 20100 then
if role.sex == ROLE_SEX.BOY then
self.livePath = "live2d_caomaolufei"
else
self.livePath = "live2d_namei"
end
-- 确定是主角
self.isMainPlayer = true
end
end
-- 配置表数据
self.config = SpiritAnimal[role.roleData.id]
-- 如果不是男女主角
if not self.livePath then
self.livePath = GetResourcePath(self.config.Live)
self.icon.sprite = self.spLoader:LoadSprite(GetResourcePath(self.config.Icon))
end
self.play_liveScale = self.config.play_liveScale
self.enemy_liveScale = self.config.enemy_liveScale
self.offset = self.config.offset
self.outOffset = self.config.enemy_offset
self.spAtkTime = self.config.CastingSkills/1000
self.atkSoundTime = self.config.CastingAudio/1000
self.attackSound = self.config.sond
-- 人物立绘
self.RoleLiveGO = poolManager:LoadLive(self.livePath, self.skillCastRoot.transform.parent, Vector3.one, Vector3.zero)
self.RoleLiveGO.transform:SetParent(self.liveRoot.transform)
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(false)
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)
--
-- local combatId = BattleManager.GetCombatIdBySkin(self.role.skill[1],self.skinId)
-- self.combat = BattleManager.GetSkillCombat(combatId)
-- self.SkillAttackDisplaceoffset=self.combat.AttackDisplaceoffset
-- if self.combat.CloseRangeHit~=nil and self.combat.CloseRangeHit~="" then
-- self.RoleSkillLiveGo=poolManager:LoadLive(self.combat.CloseRangeHit, go.transform.parent, Vector3.one, Vector3.zero)
-- self.RoleSkillLiveGoTran = self.RoleSkillLiveGo:GetComponent("RectTransform")
-- self.RoleSkillLiveGoTran:SetParent(self.RoleLiveGO.transform)
-- self.RoleSkillLiveGoTran.anchoredPosition = Vector2.New(self.outOffset[1], self.outOffset[2])-- * 0.5
-- self.RoleSkillLiveGoTran.localScale = Vector3.one
-- self.RoleSkillLiveGoTran.sizeDelta = Vector2.New(1000, 1000)
-- self.RoleSkillLiveGoGraphic = self.RoleSkillLiveGo:GetComponent("SkeletonGraphic")
-- self.RoleSkillLiveGoGraphic.AnimationState:SetAnimation(0, "idle", true)
-- end
-- local combatId2 = BattleManager.GetCombatIdBySkin(self.role.superSkill[1],self.skinId)
-- self.combat2 = BattleManager.GetSkillCombat(combatId2)
-- if self.combat2.CloseRangeHit~=nil and self.combat2.CloseRangeHit~="" then
-- self.superSkillAttackDisplaceoffset=self.combat2.AttackDisplaceoffset
-- self.RoleSkillLiveGo2=poolManager:LoadLive(self.combat2.CloseRangeHit, go.transform.parent, Vector3.one, Vector3.zero)
-- self.RoleSkillLiveGoTran2 = self.RoleSkillLiveGo2:GetComponent("RectTransform")
-- self.RoleSkillLiveGoTran2:SetParent(self.RoleLiveGO.transform)
-- -- self.RoleSkillLiveGoTran2.anchoredPosition = Vector2.New(self.outOffset[1], self.outOffset[2])-- * 0.5
-- self.RoleSkillLiveGoTran2.localPosition = Vector2.New(self.combat2.CloseRangeHitOffset[1], self.combat2.CloseRangeHitOffset[2])-- * 0.5
-- self.RoleSkillLiveGoTran2.localScale = Vector3.one
-- self.RoleSkillLiveGoTran2.sizeDelta = Vector2.New(1000, 1000)
-- self.RoleSkillLiveGoGraphic2 = self.RoleSkillLiveGo2:GetComponent("SkeletonGraphic")
-- -- local t= self.RoleLiveGOGraphic.SkeletonData.animations
-- self.RoleSkillLiveGoGraphic2.AnimationState:SetAnimation(0, "idle", true)
-- self.RoleSkillLiveGo2:SetActive(true)
-- end
-- casting技能立绘
self.RoleLiveGO2=nil
-- self.livePath2=GetResourcePath(HeroConfig[role.roleData.roleId].Painting)
self.RoleLiveGO2 = poolManager:LoadLive(self.livePath, self.skillCastRoot.gameObject.transform.parent, Vector3.one, Vector3.zero)
self.RoleLiveGO2.transform:SetParent(self.skillCastRoot.gameObject.transform)
local offset = self.camp == 0 and self.offset or self.outOffset
self.RoleLiveGO2:GetComponent("RectTransform").anchoredPosition = Vector2.New(offset[1], offset[2])
if self.camp==1 then
self.RoleLiveGO2.transform.rotation=Vector3.New(0,180,0)
end
local scale = self.camp == 0 and self.play_liveScale or self.enemy_liveScale
self.RoleLiveGO2.transform.localScale = Vector3.one * scale --* 2
self.RoleLiveGO2:SetActive(false)
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.SkillCaster = SkillCaster.New(self, self.spAtkTime, self.atkSoundTime, self.attackSound, self.castingEfectNode, self.castingNameNode)
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
self.combat=nil
end
--
function MonsterView:OnSortingOrderChange(battleSorting)
end
function MonsterView:Update()
if IsOpenBattleDebug then
self.role.data:Foreach(function (name, value)
--self.URoleProperty:SetValue(name, value)
end)
end
end
-- 缩放
function MonsterView:DoScale(scale, dur, func)
if func then
func()
end
end
-- 设置高亮
function MonsterView:SetHighLight(isLight, eScale, dur, func)
if func then
func()
end
end
-- 播放动画
function MonsterView: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
local heroConfig=nil
function MonsterView:OnSkillCastStart(skill)
-- self.RoleLiveGO:SetActive(true)
local name=nil
local roleConfig=nil
if skill and skill.id and skill.id~=0 then
local aaa=SkillLogicConfig[skill.id].Hero
if aaa and aaa~=0 then
heroConfig=ConfigManager.GetConfigData(ConfigName.HeroConfig,aaa)
local liveId=heroConfig.Live
roleConfig=ConfigManager.GetConfigData(ConfigName.RoleConfig,aaa)
if liveId then
name=ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig,liveId).Name
end
end
end
local offset = self.camp == 0 and self.offset or self.outOffset
self.RoleLiveGO2:GetComponent("RectTransform").anchoredPosition = Vector2.New(offset[1], offset[2])
if name then
self.RoleLiveGO3=nil
local aaa1=Util.GetGameObject(self.skillCastRoot.gameObject.transform.parent,name)
if aaa1 then
self.RoleLiveGO3=aaa1
else
self.RoleLiveGO3 = poolManager:LoadLive(name, self.skillCastRoot.gameObject.transform.parent, Vector3.one, Vector3.zero)
end
self.RoleLiveGO3.transform:SetParent(self.skillCastRoot.gameObject.transform)
self.RoleLiveGO3.transform:SetSiblingIndex(0)
--self.RoleLiveGO3.transform.position=Vector3.zero
local offset = self.camp == 0 and self.config.offset or self.config.enemy_offset
local add=roleConfig.enemy_offset
if self.camp==1 then
self.RoleLiveGO3.transform.rotation=Vector3.New(0,180,0)
self.RoleLiveGO3:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, offset[2]+add[2]+180)
else
self.RoleLiveGO2:GetComponent("RectTransform").anchoredPosition = Vector2.New(offset[1], offset[2]+300)
self.RoleLiveGO3:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, offset[2]+add[2]+480)
end
local scale = roleConfig.enemy_liveScale
self.RoleLiveGO3.transform.localScale = Vector3.one * scale --* 2
self.RoleLiveGO3:SetActive(false)
self.RoleLiveGOGraphic3 = self.RoleLiveGO3:GetComponent("SkeletonGraphic")
self.RoleLiveGOTran3 = self.RoleLiveGO3:GetComponent("RectTransform")
self.RoleLiveGOGraphic3.AnimationState:SetAnimation(0, "attack", true)
self.RoleLiveGOTran3.sizeDelta = Vector2.New(1000, 1000)
self.castingNameNode:GetComponent("Text").text = "身外化身"
local eid = BattleManager.GetCombatIdBySkin(skill.id, skill.owner.skinId)
self.combat = BattleManager.GetSkillCombat(eid)
else
self.RoleLiveGO3=nil
end
end
--
function MonsterView:OnSkillPlay()
--self:PlaySpineAnim(self.RoleLiveGOGraphic, 0, "attack", false)
end
--
function MonsterView:OnSkillEnd()
-- self.RoleLiveGO:SetActive(false)
end
function MonsterView:OnSkillCastingStart(skill)
if self.RoleLiveGO2 then
-- 提前进入下一阶段
self.turnEffect:SetActive(false)
self.RoleLiveGO2:SetActive(true)
self.RoleLiveGO2:GetComponent("RectTransform").rotation = Quaternion.Euler(Vector3.New(0, 0, 0))
if self.RoleLiveGO3 then
if (self.camp==0 and heroConfig and heroConfig.Toward==1) or (self.camp==1 and heroConfig and heroConfig.Toward==2) then
self.RoleLiveGO3:GetComponent("RectTransform").rotation = Quaternion.Euler(Vector3.New(0, 90, 0))
else
self.RoleLiveGO3:GetComponent("RectTransform").rotation = Quaternion.Euler(Vector3.New(0, -90, 0))
end
coroutine.start(function()
coroutine.wait(0.7)
-- self.RoleLiveGO2.transform:DOLocalMoveY(0, 0.2, false):OnComplete(function()
-- rightList[i].transform:DOLocalMoveX(10, 0.3, false)
self.RoleLiveGO2.transform:DORotate(Vector3.New(0, 90, 0),0.5):OnComplete(function()
self.RoleLiveGO2.gameObject:SetActive(false)
self.RoleLiveGO3.gameObject:SetActive(true)
if (self.camp==0 and heroConfig and heroConfig.Toward==1) or (self.camp==1 and heroConfig and heroConfig.Toward==2) then
self.RoleLiveGO3.transform:DORotate(Vector3.New(0,180, 0),0.5)
else
self.RoleLiveGO3.transform:DORotate(Vector3.New(0,0, 0),0.5)
end
if self.combat.skillname then
self.castingNameNode:SetActive(true)
self.castingNameNode:GetComponent("Image").sprite = self.spLoader:LoadSprite(self.combat.skillname)
else
self.castingNameNode:SetActive(false)
end
self:PlaySpineAnim(self.RoleLiveGOGraphic3, 0, "attack" , false)
-- coroutine.wait(1.5)
--self.turnEffect:SetActive(false)
end)
coroutine.wait(0.1)
self.turnEffect:SetActive(true)
end)
-- 延长Casting时间
return 0.6
else
if self.isMainPlayer then
self:PlaySpineAnim(self.RoleLiveGOGraphic2, 0, "idle" , false)
else
self:PlaySpineAnim(self.RoleLiveGOGraphic2, 0, "attack" , false)
end
end
end
end
function MonsterView:OnSkillCastingEnd()
if self.RoleLiveGO2 then
self.RoleLiveGO2:SetActive(false)
end
if self.RoleLiveGO3 then
self.RoleLiveGO3:SetActive(false)
end
end
function MonsterView:onDispose()
self.spLoader:Destroy()
--
Util.SetSpineGray(self.RoleLiveGOGraphic2, false)
Util.SetColor(self.RoleLiveGOGraphic2, Color.New(1, 1, 1, 1))
self.RoleLiveGOGraphic2.freeze = false
--poolManager:UnLoadLive(self.livePath2, self.RoleLiveGO2)
poolManager:UnLoadLive(self.livePath, self.RoleLiveGO)
-- poolManager:UnLoadLive(self.combat2.CloseRangeHit, self.RoleSkillLiveGo2)
-- poolManager:UnLoadLive(self.combat.CloseRangeHit, self.RoleSkillLiveGo)
GameObject.DestroyImmediate(self.RoleLiveGO2)
self.RoleLiveGO2 = nil
heroConfig=nil
-- 回收本节点
BattlePool.RecycleItem(self.GameObject, BATTLE_POOL_TYPE.ENEMY_ROLE)
end