Files
Continentis/Assets/Mods/Basic/Characters/CombatBuffs/General/Protecting.cs

83 lines
3.2 KiB
C#
Raw Normal View History

2025-12-13 23:28:23 -05:00
using System.Collections.Generic;
2025-10-25 07:49:39 -04:00
using Continentis.MainGame;
using Continentis.MainGame.Character;
2025-10-31 10:02:30 -04:00
using SLSFramework.General;
2025-10-25 07:49:39 -04:00
using UnityEngine;
namespace Continentis.Mods.Basic.Buffs
{
public class Protecting : CharacterCombatBuffBase
{
public CharacterBase target;
public Protected protectedBuff;
2025-12-10 18:22:26 -05:00
public Protecting(CharacterBase target, int actionCount, Protected protectedBuff)
2025-10-25 07:49:39 -04:00
{
Initialize(BuffType.Neutral, BuffDispelLevel.DeathOnly, 100);
this.target = target;
this.protectedBuff = protectedBuff;
if (this.protectedBuff == null)
{
Debug.LogError("Protecting buff requires a Protected buff on the target.");
}
this.contentSubmodule = new ContentSubmodule(this)
2025-12-13 23:28:23 -05:00
.AddParameterGetter("Count", () => roundFirstActionCountSubmodule.remainingCount.ToString())
2025-10-25 07:49:39 -04:00
.AddParameterGetter("Target", () => target.data.displayName);//TODO: 以后增加角色的ContentSubmodule
this.iconSubmodule = new IconSubmodule(this).SetTextFunctions("Count");
2025-10-27 07:04:34 -04:00
2025-12-13 23:28:23 -05:00
this.roundFirstActionCountSubmodule = new CountSubmodule(this, actionCount);
2025-10-25 07:49:39 -04:00
}
2025-12-13 23:28:23 -05:00
2025-10-25 07:49:39 -04:00
public override bool OnBuffApply(out CharacterCombatBuffBase existingBuff)
{
2025-12-13 23:28:23 -05:00
MainGameManager.Instance.basePrefabs.GenerateInfoText(contentSubmodule.displayName,
attachedCharacter.characterView);
2025-10-31 10:02:30 -04:00
if (attachedCharacter.combatBuffSubmodule.TryGetBuff(out Protected conflictProtected))
{
//如果目标已经有Protected Buff则应当将其移除以防止冲突.
//使用移除所有保护者的方式来移除。
2025-12-13 23:28:23 -05:00
Debug.Log(
$"Conflicted Protected buff found, with {conflictProtected.protectingSources.Count} protecting sources. Removing all.");
2025-10-31 10:02:30 -04:00
conflictProtected.protectingSources.For(ps => ps.Remove());
}
2025-10-25 07:49:39 -04:00
2025-12-13 23:28:23 -05:00
if (FindExistingSameBuffs(out List<Protecting> existingProtecting))
2025-10-25 07:49:39 -04:00
{
2025-12-13 23:28:23 -05:00
var sameProtecting = existingProtecting.Find(ep => ep.target == this.target);
if (sameProtecting != null)
2025-10-30 12:07:59 -04:00
{
2025-12-13 23:28:23 -05:00
existingBuff = sameProtecting;
sameProtecting.roundFirstActionCountSubmodule.AddCount(this.roundFirstActionCountSubmodule.remainingCount);
2025-10-30 12:07:59 -04:00
return false;
}
2025-12-13 23:28:23 -05:00
existingBuff = null;
2025-10-25 07:49:39 -04:00
return true; //独立处理直接返回true
}
2025-12-13 23:28:23 -05:00
existingBuff = null;
2025-10-25 07:49:39 -04:00
return true;
}
2025-12-10 18:22:26 -05:00
public override void OnAfterFirstApply()
{
base.OnAfterFirstApply();
protectedBuff.protectingSources.Add(this);
}
2025-10-25 07:49:39 -04:00
public override void OnBuffRemove()
{
base.OnBuffRemove();
2025-10-30 12:07:59 -04:00
protectedBuff.protectingSources.Remove(this);
2025-12-13 23:28:23 -05:00
Debug.Log($"Protecting buff removed. Remaining protecting sources: {protectedBuff.protectingSources.Count}");
2025-10-30 12:07:59 -04:00
if (protectedBuff.protectingSources.Count == 0)
{
protectedBuff.Remove();
}
2025-10-25 07:49:39 -04:00
}
}
}