passport (#886)
This commit is contained in:
@@ -5,7 +5,6 @@ using Content.Shared._CP14.MagicSpell;
|
||||
using Content.Shared._CP14.MagicSpell.Components;
|
||||
using Content.Shared._CP14.MagicSpell.Events;
|
||||
using Content.Shared._CP14.MagicSpell.Spells;
|
||||
using Content.Shared.EntityEffects;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
|
||||
9
Content.Server/_CP14/Passport/CP14PassportComponent.cs
Normal file
9
Content.Server/_CP14/Passport/CP14PassportComponent.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Content.Server._CP14.Passport;
|
||||
|
||||
/// <summary>
|
||||
/// Generates a paper text confirming the identity of the player and stamps it.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class CP14PassportComponent : Component
|
||||
{
|
||||
}
|
||||
63
Content.Server/_CP14/Passport/CP14PassportSystem.cs
Normal file
63
Content.Server/_CP14/Passport/CP14PassportSystem.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Text;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Paper;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server._CP14.Passport;
|
||||
|
||||
public sealed partial class CP14PassportSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly PaperSystem _paper = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _hands = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
public readonly EntProtoId PassportProto = "CP14Passport";
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<PlayerSpawnCompleteEvent>(OnPlayerSpawning);
|
||||
}
|
||||
|
||||
private void OnPlayerSpawning(PlayerSpawnCompleteEvent ev)
|
||||
{
|
||||
var passport = Spawn(PassportProto, Transform(ev.Mob).Coordinates);
|
||||
|
||||
if (!TryComp<PaperComponent>(passport, out var paper))
|
||||
return;
|
||||
|
||||
var text = GeneratePassportText(ev);
|
||||
_paper.SetContent((passport, paper), text);
|
||||
_paper.TryStamp((passport, paper),
|
||||
new StampDisplayInfo
|
||||
{
|
||||
StampedColor = Color.FromHex("#0a332a"),
|
||||
StampedName = Loc.GetString("cp14-passport-stamp")
|
||||
},
|
||||
"");
|
||||
_hands.TryPickupAnyHand(ev.Mob, passport);
|
||||
}
|
||||
|
||||
private string GeneratePassportText(PlayerSpawnCompleteEvent ev)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
//Name
|
||||
sb.AppendLine(Loc.GetString("cp14-passport-name", ("name", ev.Profile.Name)));
|
||||
//Species
|
||||
if (_proto.TryIndex(ev.Profile.Species, out var indexedSpecies))
|
||||
sb.AppendLine(Loc.GetString("cp14-passport-species", ("species", Loc.GetString(indexedSpecies.Name))));
|
||||
//Birthday
|
||||
var birthday = $"{_random.Next(40)}.{_random.Next(12)}.{225 - ev.Profile.Age}";
|
||||
sb.AppendLine(Loc.GetString("cp14-passport-birth-date", ("birthday", birthday)));
|
||||
//Job
|
||||
if (ev.JobId is not null && _proto.TryIndex<JobPrototype>(ev.JobId, out var indexedJob))
|
||||
sb.AppendLine(Loc.GetString("cp14-passport-job", ("job", Loc.GetString(indexedJob.Name))));
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user