Files
LuaCsForBarotraumaEP/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/CheckTraitorVoteAction.cs
T
2023-10-02 16:43:54 +03:00

40 lines
1.4 KiB
C#

#nullable enable
using Barotrauma.Networking;
using System.Linq;
namespace Barotrauma
{
/// <summary>
/// Checks whether the specific target was voted as the traitor.
/// </summary>
class CheckTraitorVoteAction : BinaryOptionAction
{
[Serialize("", IsPropertySaveable.Yes)]
public Identifier Target { get; set; }
public CheckTraitorVoteAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
if (parentEvent is not TraitorEvent)
{
DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\" - {nameof(CheckTraitorVoteAction)} can only be used in traitor events.");
}
}
protected override bool? DetermineSuccess()
{
var targetEntities = ParentEvent.GetTargets(Target);
#if SERVER
if (GameMain.Server?.TraitorManager?.GetClientAccusedAsTraitor() is Client traitorClient)
{
return targetEntities.Any(e => e is Character character && traitorClient?.Character == character);
}
#endif
return false;
}
public override string ToDebugString()
{
return $"{ToolBox.GetDebugSymbol(succeeded.HasValue)} {nameof(CheckTraitorVoteAction)} -> (TargetTag: {Target.ColorizeObject()}";
}
}
}