using Content.Shared.Examine; using Content.Shared.Humanoid; using Robust.Shared.Enums; using Robust.Shared.Prototypes; namespace Content.Shared._RMC14.Marines.Roles.Ranks; public abstract class SharedRankSystem : EntitySystem { [Dependency] private readonly IPrototypeManager _prototypes = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnRankExamined); } private void OnRankExamined(Entity ent, ref ExaminedEvent args) { using (args.PushGroup(nameof(SharedRankSystem), 1)) { var user = ent.Owner; var rank = GetRankString(user, hasPaygrade: true); if (rank != null) { var finalString = Loc.GetString("rmc-rank-component-examine", ("user", user), ("rank", rank)); args.PushMarkup(finalString); } } } /// /// Sets a mob's rank from the given RankPrototype. /// public void SetRank(EntityUid uid, RankPrototype from) { SetRank(uid, from.ID); } /// /// Sets a mob's rank from the given RankPrototype. /// public void SetRank(EntityUid uid, ProtoId from) { var comp = EnsureComp(uid); comp.Rank = from; Dirty(uid, comp); } /// /// Gets the rank of a given mob. /// public RankPrototype? GetRank(EntityUid uid) { if (TryComp(uid, out var component)) return GetRank(component); return null; } /// /// Gets a RankPrototype from a RankComponent. /// public RankPrototype? GetRank(RankComponent component) { if (_prototypes.TryIndex(component.Rank, out var rankProto) && rankProto != null) return rankProto; return null; } /// /// Gets the rank name of a given mob. /// public string? GetRankString(EntityUid uid, bool isShort = false, bool hasPaygrade = false) { var rank = GetRank(uid); if (rank == null) return null; if (isShort) { if (rank.FemalePrefix == null || rank.MalePrefix == null) return rank.Prefix; if (!TryComp(uid, out var humanoidAppearance)) return rank.Prefix; var genderPrefix = humanoidAppearance.Gender switch { Gender.Female => rank.FemalePrefix, Gender.Male => rank.MalePrefix, Gender.Epicene or Gender.Neuter or _ => rank.Prefix }; return genderPrefix; } else if (hasPaygrade && rank.Paygrade != null) { return "(" + rank.Paygrade + ")" + " " + rank.Name; } else { return rank.Name; } } /// /// Gets the prefix rank name. (ex. Maj John Marine) /// public string? GetSpeakerRankName(EntityUid uid) { var rank = GetRankString(uid, true); if (rank == null) return null; return rank + " " + Name(uid); } /// /// Gets the prefix full name. (ex. Major John Marine) /// public string? GetSpeakerFullRankName(EntityUid uid) { var rank = GetRankString(uid); if (rank == null) return null; return rank + " " + Name(uid); } }