using Continentis.MainGame; using Continentis.MainGame.Character; 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 = null) { 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", () => roundCountSubmodule.remainingCount.ToString()) .AddParameterGetter("Target", () => target.data.displayName);//TODO: 以后增加角色的ContentSubmodule this.iconSubmodule = new IconSubmodule(this).SetTextFunctions("Count"); this.roundCountSubmodule = new CountSubmodule(this, actionCount); this.eventSubmodule = new EventSubmodule(this); } public override bool OnBuffApply(out CharacterCombatBuffBase existingBuff) { MainGameManager.Instance.basePrefabs.GenerateInfoText(contentSubmodule.displayName, attachedCharacter.characterView); if (FindExistingSameBuff(out existingBuff)) { Debug.Log("Existing same buff found."); Protecting existProtecting = existingBuff as Protecting; Debug.Log(existProtecting == null ? "Existing buff is not of type Protecting!" : "Existing Protecting buff found."); if (existProtecting.target == this.target) { existProtecting.roundCountSubmodule.AddCount(this.roundCountSubmodule.remainingCount); return false; } this.protectedBuff ??= target.combatBuffSubmodule.GetBuff(); this.protectedBuff.protectingSources.Add(this); return true; //独立处理,直接返回true } Debug.Log("No existing same buff found."); return true; } public override void OnBuffRemove() { base.OnBuffRemove(); protectedBuff.protectingSources.Remove(this); if (protectedBuff.protectingSources.Count == 0) { protectedBuff.Remove(); } } } }