2025-10-03 00:02:43 -04:00
using System.Collections.Generic ;
using System.Linq ;
2025-10-23 00:49:44 -04:00
using Continentis.MainGame.Card ;
using SLSFramework.General ;
2025-10-03 00:02:43 -04:00
using UnityEngine ;
namespace Continentis.MainGame.Character
{
public partial class CombatBuffSubmodule : SubmoduleBase < CharacterBase >
{
2025-10-24 09:11:22 -04:00
public List < CharacterCombatBuffBase > buffList ;
2025-10-03 00:02:43 -04:00
public CombatBuffSubmodule ( CharacterBase character ) : base ( character )
{
2025-10-24 09:11:22 -04:00
buffList = new List < CharacterCombatBuffBase > ( ) ;
2025-10-03 00:02:43 -04:00
}
}
public partial class CombatBuffSubmodule
{
2025-10-24 09:11:22 -04:00
public T GetBuff < T > ( ) where T : CharacterCombatBuffBase
2025-10-03 00:02:43 -04:00
{
return ( T ) buffList . Find ( x = > x . GetType ( ) = = typeof ( T ) ) ;
}
2025-10-25 07:49:39 -04:00
public T GetBuff < T > ( string identification ) where T : CharacterCombatBuffBase
{
return ( T ) buffList . FindAll ( x = > x . GetType ( ) = = typeof ( T ) ) . Find ( x = > x . identification = = identification ) ;
}
2025-10-31 10:02:30 -04:00
public bool TryGetBuff < T > ( out T buff ) where T : CharacterCombatBuffBase
{
buff = GetBuff < T > ( ) ;
return buff ! = null ;
}
public bool TryGetBuffs < T > ( out List < T > buffs ) where T : CharacterCombatBuffBase
{
List < CharacterCombatBuffBase > foundBuffs = buffList . FindAll ( x = > x . GetType ( ) = = typeof ( T ) ) ;
buffs = foundBuffs . Cast < T > ( ) . ToList ( ) ;
return buffs . Count > 0 ;
}
2025-10-03 00:02:43 -04:00
2025-10-24 09:11:22 -04:00
public bool HasBuff < T > ( ) where T : CharacterCombatBuffBase
2025-10-03 00:02:43 -04:00
{
return buffList . Exists ( x = > x . GetType ( ) = = typeof ( T ) ) ;
}
2025-11-01 06:13:58 -04:00
public List < CharacterCombatBuffBase > Dispel ( BuffDispelLevel dispelLevel , CharacterBase dispelSource )
{
List < CharacterCombatBuffBase > dispelledBuffs = buffList
. Where ( buff = > buff . dispelThreshold < = dispelLevel & &
buff . buffType = = ( owner . IsAlly ( dispelSource ) ? BuffType . Negative : BuffType . Positive ) )
. ToList ( ) ;
dispelledBuffs . For ( buff = > buff . Remove ( ) ) ;
return dispelledBuffs ;
}
2025-10-03 00:02:43 -04:00
}
public partial class CombatBuffSubmodule
{
2026-04-01 12:23:27 -04:00
public void CombatStart ( )
{
buffList . For ( buff = > buff . eventSubmodule ? . onCombatStart ? . Invoke ( ) ) ;
}
public void CombatEnd ( )
{
buffList . For ( buff = > buff . eventSubmodule ? . onCombatEnd ? . Invoke ( ) ) ;
}
2025-10-03 00:02:43 -04:00
public void RoundStart ( )
{
2025-10-30 04:21:28 -04:00
buffList . For ( buff = > buff . roundCountSubmodule ? . Update ( ) ) ;
2025-10-23 00:49:44 -04:00
buffList . For ( buff = > buff . eventSubmodule ? . onRoundStart ? . Invoke ( ) ) ;
2025-10-03 00:02:43 -04:00
}
public void RoundEnd ( )
{
2025-10-23 00:49:44 -04:00
buffList . For ( buff = > buff . eventSubmodule ? . onRoundEnd ? . Invoke ( ) ) ;
2025-10-03 00:02:43 -04:00
}
public void ActionStart ( )
{
2026-04-01 12:23:27 -04:00
//Debug.Log($"{owner.data.displayName} is starting an action. Current action count this round: {owner.actionCountThisRound}");
2025-10-30 04:21:28 -04:00
if ( owner . actionCountThisRound = = 0 )
{
2026-04-01 12:23:27 -04:00
//Debug.Log($"{owner.data.displayName} is starting their first action this round. Buff count of {buffList.Count} will update their round first action counts.");
2025-12-13 23:28:23 -05:00
buffList . For ( buff = >
{
2026-04-01 12:23:27 -04:00
//Debug.Log($"Updating round first action count for buff: {buff.contentSubmodule.displayName}");
2025-12-13 23:28:23 -05:00
buff . roundFirstActionCountSubmodule ? . Update ( ) ;
} ) ;
2025-10-30 04:21:28 -04:00
}
2025-10-23 00:49:44 -04:00
buffList . For ( buff = > buff . actionCountSubmodule ? . Update ( ) ) ;
buffList . For ( buff = > buff . eventSubmodule ? . onActionStart ? . Invoke ( ) ) ;
2025-10-03 00:02:43 -04:00
}
public void ActionEnd ( )
{
2025-10-23 00:49:44 -04:00
buffList . For ( buff = > buff . eventSubmodule ? . onActionEnd ? . Invoke ( ) ) ;
2025-10-03 00:02:43 -04:00
}
}
public partial class CombatBuffSubmodule
{
public void GetGeneralAttributeChange ( string attributeName , out float numericChange ,
out float percentageChangeOfAccumulation , out float percentChangeOfMultiplication )
{
numericChange = buffList . Where ( buff = > buff . generalAttributeSubmodule ! = null )
. SelectMany ( buff = > buff . generalAttributeSubmodule . numericChange )
. Where ( change = > change . Key = = attributeName )
. Sum ( change = > change . Value ) ;
percentageChangeOfAccumulation = buffList . Where ( buff = > buff . generalAttributeSubmodule ! = null )
. SelectMany ( buff = > buff . generalAttributeSubmodule . percentageChangeOfAccumulation )
. Where ( change = > change . Key = = attributeName )
. Sum ( change = > change . Value ) ;
percentChangeOfMultiplication = buffList . Where ( buff = > buff . generalAttributeSubmodule ! = null )
. SelectMany ( buff = > buff . generalAttributeSubmodule . percentageChangeOfMultiplication )
. Where ( change = > change . Key = = attributeName )
. Aggregate < KeyValuePair < string , float > , float > ( 1 , ( current , change ) = > current * change . Value ) ;
}
}
}