169 lines
6.1 KiB
C#
169 lines
6.1 KiB
C#
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Continentis.MainGame.Card;
|
||
using Continentis.MainGame.UI;
|
||
using SLSFramework.General;
|
||
using UnityEngine;
|
||
|
||
namespace Continentis.MainGame.Character
|
||
{
|
||
public abstract partial class CharacterCombatBuffBase : CharacterBuffBase
|
||
{
|
||
public CardLogicBase sourceCard;
|
||
|
||
/// <summary>
|
||
/// 行动计数,每次行动开始时计数-1。
|
||
/// </summary>
|
||
public CountSubmodule actionCountSubmodule;
|
||
/// <summary>
|
||
/// 回合计数,每回合开始时计数-1。
|
||
/// </summary>
|
||
public CountSubmodule roundCountSubmodule;
|
||
/// <summary>
|
||
/// 首次行动计数,仅在角色本回合首次行动时计数-1。
|
||
/// </summary>
|
||
public CountSubmodule roundFirstActionCountSubmodule;
|
||
|
||
public UnitedStackSubmodule unitedStackSubmodule;
|
||
public IndependentStackSubmodule independentStackSubmodule;
|
||
public CoreAttributeSubmodule coreAttributeSubmodule;
|
||
public GeneralAttributeSubmodule generalAttributeSubmodule;
|
||
public StatusSubmodule statusSubmodule;
|
||
}
|
||
|
||
public partial class CharacterCombatBuffBase
|
||
{
|
||
public sealed override bool OnBuffApply(out BuffBase<CharacterBase> existingBuff)
|
||
{
|
||
throw new System.NotImplementedException("请使用类型约束更强的OnBuffApply方法");
|
||
}
|
||
|
||
public virtual bool OnBuffApply(out CharacterCombatBuffBase existingBuff)
|
||
{
|
||
throw new System.NotImplementedException(); //需要在子类中实现
|
||
}
|
||
|
||
public override void OnAfterFirstApply()
|
||
{
|
||
statusSubmodule?.AddStatus();
|
||
}
|
||
|
||
public override void OnBuffRemove()
|
||
{
|
||
RefreshAttributes();
|
||
statusSubmodule?.RemoveStatus();
|
||
iconSubmodule?.Remove();
|
||
}
|
||
}
|
||
|
||
public partial class CharacterCombatBuffBase
|
||
{
|
||
protected bool FindExistingSameBuff<T>(out T existingBuff) where T : CharacterBuffBase
|
||
{
|
||
return FindExistingSameBuff(out existingBuff, attachedCharacter.combatBuffSubmodule.buffList);
|
||
}
|
||
|
||
public override void Apply(CharacterBase attachedCharacter, CharacterBase sourceCharacter = null)
|
||
{
|
||
this.Apply(attachedCharacter, sourceCharacter, null);
|
||
}
|
||
|
||
public void Apply(CharacterBase attachedCharacter, CharacterBase sourceCharacter = null, CardLogicBase sourceCard = null)
|
||
{
|
||
this.attachedCharacter = attachedCharacter;
|
||
this.sourceCharacter = sourceCharacter;
|
||
this.sourceCard = sourceCard;
|
||
|
||
if (OnBuffApply(out CharacterCombatBuffBase existingBuff))
|
||
{
|
||
this.attachedCharacter.combatBuffSubmodule.buffList.AddByPriority(this);
|
||
|
||
OnAfterFirstApply();
|
||
|
||
if (iconSubmodule != null)
|
||
{
|
||
(attachedCharacter.characterView.hudContainer.enablingHUDs["CharacterBuffCollection"] as HUD_CharacterBuffCollection)
|
||
?.AddBuffIcon(this);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
existingBuff.iconSubmodule?.Update();
|
||
}
|
||
|
||
RefreshAttributes();
|
||
iconSubmodule?.Update();
|
||
attachedCharacter.deckSubmodule.GetAllCards().ForEach(card => card.cardLogic.RefreshCardAttributes());
|
||
}
|
||
|
||
public override void Remove()
|
||
{
|
||
OnBuffRemove();
|
||
this.attachedCharacter.combatBuffSubmodule.buffList.Remove(this);
|
||
attachedCharacter.deckSubmodule.GetAllCards().ForEach(card => card.cardLogic.RefreshCardAttributes());
|
||
}
|
||
|
||
public override void UntriggerRemove()
|
||
{
|
||
this.attachedCharacter.combatBuffSubmodule.buffList.Remove(this);
|
||
attachedCharacter.deckSubmodule.GetAllCards().ForEach(card => card.cardLogic.RefreshCardAttributes());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检查并处理专注类Buff的添加逻辑。
|
||
/// 如果已有相同Buff存在,则返回true,并通过out参数返回该Buff。
|
||
/// 如果没有相同Buff存在,则返回false,并在必要时移除优先级最低的专注类Buff以腾出空间。
|
||
/// </summary>
|
||
/// <param name="existingBuff"></param>
|
||
/// <returns></returns>
|
||
public bool FocusingCheck(out CharacterCombatBuffBase existingBuff)
|
||
{
|
||
if (buffType != BuffType.Focusing)
|
||
{
|
||
Debug.LogError("FocusingCheck只能用于专注类Buff");
|
||
existingBuff = null;
|
||
return false;
|
||
}
|
||
|
||
// 移除超出上限的专注类Buff
|
||
List<CharacterCombatBuffBase> focusingBuffs =
|
||
attachedCharacter.combatBuffSubmodule.buffList.Where(buff => buff.buffType == BuffType.Focusing).ToList();
|
||
focusingBuffs.Sort();
|
||
int maximumFocusingBuffAmount = attachedCharacter.GetAttribute("MaximumFocusingBuffAmount", 1);
|
||
for (int i = maximumFocusingBuffAmount; i < focusingBuffs.Count; i++)
|
||
{
|
||
focusingBuffs[i].Remove();
|
||
}
|
||
|
||
// 检查是否已有相同Buff存在
|
||
if (FindExistingSameBuff(out existingBuff))
|
||
{
|
||
return true;
|
||
}
|
||
|
||
// 如果没有相同Buff存在但已达上限,则移除优先级最低的专注类Buff(将由新Buff替代)
|
||
if(focusingBuffs.Count >= maximumFocusingBuffAmount)
|
||
{
|
||
CharacterCombatBuffBase lowestPriorityBuff = focusingBuffs[focusingBuffs.Count - 1];
|
||
lowestPriorityBuff.Remove();
|
||
}
|
||
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public partial class CharacterCombatBuffBase
|
||
{
|
||
private void RefreshAttributes()
|
||
{
|
||
if (coreAttributeSubmodule != null)
|
||
{
|
||
coreAttributeSubmodule.RefreshAllModifiedAttributes();
|
||
}
|
||
else
|
||
{
|
||
generalAttributeSubmodule?.RefreshAllModifiedAttributes();
|
||
}
|
||
}
|
||
}
|
||
} |