From a5d162f398905ca370c39f7c449e0df53db32251 Mon Sep 17 00:00:00 2001 From: Tran Hai Nam Date: Tue, 5 May 2026 17:47:39 +0700 Subject: [PATCH] modify some code of channel act --- Assets/PerfectWorld/Scripts/Move/CECPlayer.cs | 16 ++++++++-------- Assets/PerfectWorld/Scripts/NPC/CECModel.cs | 18 ++++++++++++++---- Assets/Scripts/PlayerVisual.cs | 17 +++++++++++------ 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/Move/CECPlayer.cs b/Assets/PerfectWorld/Scripts/Move/CECPlayer.cs index 297406e0d2..181c2f5356 100644 --- a/Assets/PerfectWorld/Scripts/Move/CECPlayer.cs +++ b/Assets/PerfectWorld/Scripts/Move/CECPlayer.cs @@ -4058,7 +4058,7 @@ namespace BrewMonster public bool IsForceStopPrevious; public bool IsLoop; public CECAttackEvent AttackEvent; - public byte Channel; + public int Rank; public PlayActionEvent(string animationName, int iTransTime, bool isForceStopPrevious = false, CECAttackEvent attackEvent = null, bool isLoop = false) { this.ChannelAct = null; @@ -4067,9 +4067,9 @@ namespace BrewMonster IsForceStopPrevious = isForceStopPrevious; AttackEvent = attackEvent; IsLoop = isLoop; - Channel = 0; + Rank = 0; } - public PlayActionEvent(ref ChannelAct channelAct, string animationName, int iTransTime, bool isForceStopPrevious = false, CECAttackEvent attackEvent = null, bool isLoop = false, byte channel = 0) + public PlayActionEvent(ref ChannelAct channelAct, string animationName, int iTransTime, bool isForceStopPrevious = false, CECAttackEvent attackEvent = null, bool isLoop = false, int rank = 0) { this.ChannelAct = channelAct; this.AnimationName = animationName; @@ -4077,7 +4077,7 @@ namespace BrewMonster IsForceStopPrevious = isForceStopPrevious; AttackEvent = attackEvent; IsLoop = isLoop; - Channel = channel; + Rank = rank; } } public struct PLAYER_ACTION @@ -4095,7 +4095,7 @@ namespace BrewMonster public bool IsHitAnim; public bool IsForceStopPrevious; public bool IsLoop; - public byte Channel; + public int Rank; public QueueActionEvent(string animationName, Action setFlag, bool isHitAnim, CECAttackEvent attackEvent, int iTransTime, bool isForceStopPrevious = false, bool isLoop = false) { @@ -4107,10 +4107,10 @@ namespace BrewMonster ITransTime = iTransTime; IsForceStopPrevious = isForceStopPrevious; IsLoop = isLoop; - Channel = 0; + Rank = 0; } public QueueActionEvent(ref ChannelAct channelAct, string animationName, Action setFlag, bool isHitAnim, - CECAttackEvent attackEvent, int iTransTime, bool isForceStopPrevious = false, bool isLoop = false, byte channel = 0) + CECAttackEvent attackEvent, int iTransTime, bool isForceStopPrevious = false, bool isLoop = false, int rank = 0) { this.ChannelAct = channelAct; this.AnimationName = animationName; @@ -4120,7 +4120,7 @@ namespace BrewMonster ITransTime = iTransTime; IsForceStopPrevious = isForceStopPrevious; IsLoop = isLoop; - Channel = channel; + Rank = rank; } public void SetData(string shapeName, string animationName, Action setFlag, bool isHitAnim, diff --git a/Assets/PerfectWorld/Scripts/NPC/CECModel.cs b/Assets/PerfectWorld/Scripts/NPC/CECModel.cs index c321e2cef8..f3db65e1b6 100644 --- a/Assets/PerfectWorld/Scripts/NPC/CECModel.cs +++ b/Assets/PerfectWorld/Scripts/NPC/CECModel.cs @@ -55,9 +55,10 @@ public enum ActionChannel public class A3DCombActDynData { public A3DCombinedAction combinedAction; - public float fTime; public int nChannel; public int m_dwUserData; + public bool IsAllActionFinished => m_EventNames.Count == 0; + public List m_EventNames = new List(); public void SetUserData(int dwUserData) { m_dwUserData = dwUserData; } public int GetUserData() { return m_dwUserData; } } @@ -790,17 +791,24 @@ public class CECModel node = new ChannelActNode { m_Rank = 0 }; m_ChannelActs[nChannel].m_RankNodes.Add(node); } - node.m_pActive = new A3DCombActDynData + var actData = new A3DCombActDynData { combinedAction = combinedAction, nChannel = nChannel, m_dwUserData = (int)dwUserData }; EventBus.PublishChannel(m_nId, new PlayActionEvent(ref m_ChannelActs[nChannel], actionInfos[0].m_strName, nTransTime, bForceStop, attackEvent, isLoop, node.m_Rank)); + actData.m_EventNames.Add(actionInfos[0].m_strName); + for(int i = 1; i < actionInfos.Count; i++) { EventBus.PublishChannelClass(m_nId, new QueueActionEvent(ref m_ChannelActs[nChannel], actionInfos[i].m_strName, null, false, attackEvent, nTransTime, false, isLoop, node.m_Rank)); + actData.m_EventNames.Add(actionInfos[i].m_strName); } + + node.m_pActive = actData; + + //Todo: should move those event logic to channel act because their control the animation life span. var eventInfoList = combinedAction.m_EventInfoLst; if(eventInfoList != null && eventInfoList.Count > 0) { @@ -848,7 +856,7 @@ public class CECModel var isLoop = combinedAction.m_nLoops == 1; var node = new ChannelActNode { m_Rank = (byte)m_ChannelActs[nChannel].m_RankNodes.Count}; m_ChannelActs[nChannel].m_RankNodes.Add(node); - node.m_pActive = new A3DCombActDynData + var actData = new A3DCombActDynData { // combinedAction = combinedAction, // not needed now nChannel = nChannel, @@ -857,9 +865,11 @@ public class CECModel EventBus.PublishChannelClass(m_nId, new QueueActionEvent(ref m_ChannelActs[nChannel], actionInfos[0].m_strName, null, false, attackEvent, nTransTime, bForceStopPrevAct, isLoop, node.m_Rank)); for(int i = 1; i < actionInfos.Count; i++) { - EventBus.PublishChannelClass(m_nId, new QueueActionEvent(ref m_ChannelActs[nChannel], actionInfos[i].m_strName, null, false, attackEvent, nTransTime, false, isLoop, node.m_Rank)); + actData.m_EventNames.Add(actionInfos[i].m_strName); } + node.m_pActive = actData; + //todo: should add sfx and gfx logic to channel act. currently we dont have logic for queue action. only available for play action. return true; } public bool ClearComActFlagAllRankNodes(bool bSignalCurrent) diff --git a/Assets/Scripts/PlayerVisual.cs b/Assets/Scripts/PlayerVisual.cs index 47c4bf363d..e79b9b083e 100644 --- a/Assets/Scripts/PlayerVisual.cs +++ b/Assets/Scripts/PlayerVisual.cs @@ -15,7 +15,7 @@ namespace BrewMonster public CECAttackEvent AttackEvent; public bool IsLoop; public ChannelAct ChannelAct; - public byte Channel; + public int Rank; } public class PlayerVisual : MonoBehaviour { @@ -52,14 +52,14 @@ namespace BrewMonster IsForceStopPrevious = @event.IsForceStopPrevious, AttackEvent = @event.AttackEvent, ChannelAct = @event.ChannelAct, - Channel = @event.Channel + Rank = @event.Rank }); _animationList = _animationQueue.Select(q => q.AnimationName).ToList(); return; } previousAnimationName = @event.AnimationName; InternalPlayAnimation(@event.AnimationName, @event.ITransTime, FadeMode, @event.IsLoop); - ApplyAnimationEndCallbacks(@event.AttackEvent, @event.ChannelAct, @event.Channel); + ApplyAnimationEndCallbacks(@event.AttackEvent, @event.ChannelAct, @event.Rank); } public void InitPlayerEventDoneHandler() { @@ -162,7 +162,7 @@ namespace BrewMonster AttackEvent = @event.AttackEvent, IsLoop = @event.IsLoop, ChannelAct = @event.ChannelAct, - Channel = @event.Channel + Rank = @event.Rank }); _animationList = _animationQueue.Select(q => q.AnimationName).ToList(); if (!isHit) @@ -228,16 +228,21 @@ namespace BrewMonster _animationList = _animationQueue.Select(q => q.AnimationName).ToList(); previousAnimationName = animationQueue.AnimationName; InternalPlayAnimation(animationQueue.AnimationName, animationQueue.ITransTime, FadeMode, animationQueue.IsLoop); - ApplyAnimationEndCallbacks(animationQueue.AttackEvent, animationQueue.ChannelAct, animationQueue.Channel); + ApplyAnimationEndCallbacks(animationQueue.AttackEvent, animationQueue.ChannelAct, animationQueue.Rank); } - private void ApplyAnimationEndCallbacks(CECAttackEvent attackEvent, ChannelAct channelAct, byte channel) + private void ApplyAnimationEndCallbacks(CECAttackEvent attackEvent, ChannelAct channelAct, int rank) { if (_currentState == null) return; _currentState.Events.OnEnd = () => { if (attackEvent != null) attackEvent.m_bSignaled = true; + channelAct.GetNodeByRank((byte)rank).m_pActive.m_EventNames.Remove(_currentAnimationName); + if(channelAct.GetNodeByRank((byte)rank).m_pActive.IsAllActionFinished) + { + //channelAct.RemoveNodeByRank((byte)rank); + } }; } void ApplyDamage()