68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
using System.Collections.Generic;
|
||
using Continentis.MainGame;
|
||
using Continentis.MainGame.Character;
|
||
using Continentis.MainGame.Combat;
|
||
using SLSFramework.General;
|
||
using UnityEngine;
|
||
|
||
namespace Continentis.Mods.Basic.Buffs
|
||
{
|
||
public class Protected : CharacterCombatBuffBase
|
||
{
|
||
public List<Protecting> protectingSources;
|
||
|
||
public Protected()
|
||
{
|
||
Initialize(BuffType.Neutral, BuffDispelLevel.DeathOnly, 100);
|
||
|
||
this.protectingSources = new List<Protecting>();
|
||
|
||
this.statusSubmodule = new StatusSubmodule(this, StatusType.Protected);
|
||
|
||
this.contentSubmodule = new ContentSubmodule(this)
|
||
.AddParameterGetter("Protector", GetProtectorNames);
|
||
|
||
this.iconSubmodule = new IconSubmodule(this).SetTextFunctions();
|
||
|
||
this.eventSubmodule = new EventSubmodule(this);
|
||
}
|
||
|
||
public override bool OnBuffApply(out CharacterCombatBuffBase existingBuff)
|
||
{
|
||
MainGameManager.Instance.basePrefabs.GenerateInfoText(contentSubmodule.displayName, attachedCharacter.characterView);
|
||
|
||
if (attachedCharacter.combatBuffSubmodule.TryGetBuffs(out List<Protecting> conflictProtectings))
|
||
{
|
||
//如果目标正在保护其他角色时,被保护,则应当将目标的所有Protecting Buff移除,以防止冲突.
|
||
Debug.Log($"Conflicted Protecting buffs found, count: {conflictProtectings.Count}. Removing all.");
|
||
conflictProtectings.For(cp => cp.Remove());
|
||
}
|
||
|
||
if (FindExistingSameBuff(out existingBuff))
|
||
{
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
private string GetProtectorNames()
|
||
{
|
||
List<string> names = new List<string>();
|
||
foreach (Protecting protector in protectingSources)
|
||
{
|
||
names.Add(protector.attachedCharacter.data.displayName);
|
||
Debug.Log($"Protector found: {protector.attachedCharacter.data.displayName}");
|
||
}
|
||
|
||
if (names.Count == 1)
|
||
{
|
||
return names[0];
|
||
}
|
||
else
|
||
{
|
||
return string.Join(", ", names);
|
||
}
|
||
}
|
||
}
|
||
} |