2022-11-03 22:58:19 -04:00
|
|
|
using System.Linq;
|
2023-08-28 16:53:24 -07:00
|
|
|
using Content.Server.GameTicking.Rules;
|
2023-08-30 21:46:11 -07:00
|
|
|
using Content.Shared.Mind;
|
|
|
|
|
using Content.Shared.Objectives.Interfaces;
|
|
|
|
|
using Content.Shared.Roles.Jobs;
|
2022-01-13 09:53:50 -05:00
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Objectives.Conditions
|
|
|
|
|
{
|
|
|
|
|
[DataDefinition]
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class RandomTraitorAliveCondition : IObjectiveCondition
|
2022-01-13 09:53:50 -05:00
|
|
|
{
|
2023-08-28 23:23:19 -07:00
|
|
|
private EntityUid? _targetMind;
|
2022-01-13 09:53:50 -05:00
|
|
|
|
2023-08-28 16:53:24 -07:00
|
|
|
public IObjectiveCondition GetAssigned(EntityUid mindId, MindComponent mind)
|
2022-01-13 09:53:50 -05:00
|
|
|
{
|
|
|
|
|
var entityMgr = IoCManager.Resolve<IEntityManager>();
|
2023-04-24 16:21:05 +10:00
|
|
|
|
2023-08-30 21:46:11 -07:00
|
|
|
var traitors = Enumerable.ToList<(EntityUid Id, MindComponent Mind)>(entityMgr.System<TraitorRuleSystem>().GetOtherTraitorMindsAliveAndConnected(mind));
|
2023-08-28 16:53:24 -07:00
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
if (traitors.Count == 0)
|
|
|
|
|
return new EscapeShuttleCondition(); //You were made a traitor by admins, and are the first/only.
|
2023-08-28 23:23:19 -07:00
|
|
|
return new RandomTraitorAliveCondition { _targetMind = IoCManager.Resolve<IRobustRandom>().Pick(traitors).Id };
|
2022-01-13 09:53:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Title
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var targetName = string.Empty;
|
2023-08-28 16:53:24 -07:00
|
|
|
var ents = IoCManager.Resolve<IEntityManager>();
|
2023-08-30 21:46:11 -07:00
|
|
|
var jobs = ents.System<SharedJobSystem>();
|
2023-08-28 23:23:19 -07:00
|
|
|
var jobName = jobs.MindTryGetJobName(_targetMind);
|
2022-01-13 09:53:50 -05:00
|
|
|
|
2023-08-28 23:23:19 -07:00
|
|
|
if (_targetMind == null)
|
2022-02-06 21:25:04 -05:00
|
|
|
return Loc.GetString("objective-condition-other-traitor-alive-title", ("targetName", targetName), ("job", jobName));
|
2022-01-13 09:53:50 -05:00
|
|
|
|
2023-08-28 23:23:19 -07:00
|
|
|
if (ents.TryGetComponent(_targetMind, out MindComponent? mind) &&
|
|
|
|
|
mind.OwnedEntity is {Valid: true} owned)
|
2023-08-28 16:53:24 -07:00
|
|
|
{
|
|
|
|
|
targetName = ents.GetComponent<MetaDataComponent>(owned).EntityName;
|
|
|
|
|
}
|
2022-01-13 09:53:50 -05:00
|
|
|
|
2022-02-06 21:25:04 -05:00
|
|
|
return Loc.GetString("objective-condition-other-traitor-alive-title", ("targetName", targetName), ("job", jobName));
|
2022-01-13 09:53:50 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Description => Loc.GetString("objective-condition-other-traitor-alive-description");
|
|
|
|
|
|
2023-04-20 20:16:01 +10:00
|
|
|
public SpriteSpecifier Icon => new SpriteSpecifier.Rsi(new ("Objects/Misc/bureaucracy.rsi"), "folder-white");
|
2022-01-13 09:53:50 -05:00
|
|
|
|
2023-06-18 11:33:19 -07:00
|
|
|
public float Progress
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var entityManager = IoCManager.Resolve<EntityManager>();
|
2023-08-30 21:46:11 -07:00
|
|
|
var mindSystem = entityManager.System<SharedMindSystem>();
|
2023-08-28 23:23:19 -07:00
|
|
|
return !entityManager.TryGetComponent(_targetMind, out MindComponent? mind) ||
|
2023-08-28 16:53:24 -07:00
|
|
|
!mindSystem.IsCharacterDeadIc(mind)
|
|
|
|
|
? 1f
|
|
|
|
|
: 0f;
|
2023-06-18 11:33:19 -07:00
|
|
|
}
|
|
|
|
|
}
|
2022-01-13 09:53:50 -05:00
|
|
|
|
|
|
|
|
public float Difficulty => 1.75f;
|
|
|
|
|
|
|
|
|
|
public bool Equals(IObjectiveCondition? other)
|
|
|
|
|
{
|
2023-08-28 23:23:19 -07:00
|
|
|
return other is RandomTraitorAliveCondition kpc && Equals(_targetMind, kpc._targetMind);
|
2022-01-13 09:53:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
|
{
|
|
|
|
|
if (ReferenceEquals(null, obj)) return false;
|
|
|
|
|
if (ReferenceEquals(this, obj)) return true;
|
|
|
|
|
return obj is RandomTraitorAliveCondition alive && alive.Equals(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2023-08-28 23:23:19 -07:00
|
|
|
return _targetMind?.GetHashCode() ?? 0;
|
2022-01-13 09:53:50 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|