using System.Collections.Generic; using Continentis.MainGame; using Continentis.MainGame.Character; using SLSUtilities.General; using UnityEngine; namespace Continentis.Mods.Basic.Buffs { public class Protecting : CharacterCombatBuffBase { public CharacterBase target; public Protected protectedBuff; public Protecting(CharacterBase target, int actionCount, Protected protectedBuff) { 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) .AddParameterGetter("Count", () => roundFirstActionCountSubmodule.remainingCount.ToString()) .AddParameterGetter("Target", () => target.data.displayName);//TODO: 以后增加角色的ContentSubmodule this.iconSubmodule = new IconSubmodule(this).SetTextFunctions("Count"); this.roundFirstActionCountSubmodule = new CountSubmodule(this, actionCount); } public override bool OnBuffApply(out CharacterCombatBuffBase existingBuff) { MainGameManager.Instance.basePrefabs.GenerateInfoText(contentSubmodule.displayName, attachedCharacter.characterView); if (attachedCharacter.combatBuffSubmodule.TryGetBuff(out Protected conflictProtected)) { //如果目标已经有Protected Buff,则应当将其移除,以防止冲突. //使用移除所有保护者的方式来移除。 Debug.Log( $"Conflicted Protected buff found, with {conflictProtected.protectingSources.Count} protecting sources. Removing all."); conflictProtected.protectingSources.For(ps => ps.Remove()); } if (FindExistingSameBuffs(out List existingProtecting)) { var sameProtecting = existingProtecting.Find(ep => ep.target == this.target); if (sameProtecting != null) { existingBuff = sameProtecting; sameProtecting.roundFirstActionCountSubmodule.AddCount(this.roundFirstActionCountSubmodule.remainingCount); return false; } existingBuff = null; return true; //独立处理,直接返回true } existingBuff = null; return true; } public override void OnAfterFirstApply() { base.OnAfterFirstApply(); protectedBuff.protectingSources.Add(this); } public override void OnBuffRemove() { base.OnBuffRemove(); protectedBuff.protectingSources.Remove(this); Debug.Log($"Protecting buff removed. Remaining protecting sources: {protectedBuff.protectingSources.Count}"); if (protectedBuff.protectingSources.Count == 0) { protectedBuff.Remove(); } } } }