Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail Rework Part 1 #610

Merged
merged 10 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Content.Client/Nyanotrasen/Mail/MailSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Robust.Client.GameObjects;
using Content.Shared.Mail;
using Content.Shared.StatusIcon;
using Robust.Client.Utility;
using Robust.Shared.Prototypes;

namespace Content.Client.Mail
Expand Down Expand Up @@ -30,17 +29,20 @@ namespace Content.Client.Mail
/// </remarks>
public sealed class MailJobVisualizerSystem : VisualizerSystem<MailComponent>
{
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SpriteSystem _spriteSystem = default!;
dvir001 marked this conversation as resolved.
Show resolved Hide resolved

protected override void OnAppearanceChange(EntityUid uid, MailComponent component, ref AppearanceChangeEvent args)
{
if (args.Sprite == null)
return;

if (args.Component.TryGetData(MailVisuals.JobIcon, out string job))
{
var jobIcon = _prototype.Index<StatusIconPrototype>(job);
args.Sprite.LayerSetTexture(MailVisualLayers.JobStamp, jobIcon.Icon.Frame0());
}
args.Component.TryGetData(MailVisuals.JobIcon, out string job);

if (!_prototypeManager.TryIndex<StatusIconPrototype>(job, out var icon))
return;

args.Sprite.LayerSetTexture(MailVisualLayers.JobStamp, _spriteSystem.Frame0(icon.Icon));
}
}

Expand Down
112 changes: 67 additions & 45 deletions Content.Server/Nyanotrasen/Mail/MailSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
using Content.Server.Destructible.Thresholds.Behaviors;
using Content.Server.Destructible.Thresholds.Triggers;
using Content.Server.Fluids.Components;
using Content.Server.Item;
using Content.Server.Mail.Components;
using Content.Server.Mind;
using Content.Server.Nutrition.Components;
using Content.Server.Nutrition.EntitySystems;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Server.StationRecords.Systems;
using Content.Server.Spawners.EntitySystems;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Coordinates;
using Content.Shared.Damage;
using Content.Shared.Emag.Components;
using Content.Shared.Destructible;
Expand Down Expand Up @@ -57,15 +58,17 @@ public sealed class MailSystem : EntitySystem
[Dependency] private readonly CargoSystem _cargoSystem = default!;
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly OpenableSystem _openable = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly StationRecordsSystem _recordsSystem = default!;
[Dependency] private readonly MindSystem _mind = default!;
[Dependency] private readonly MetaDataSystem _meta = default!;
[Dependency] private readonly ItemSystem _itemSystem = default!;
[Dependency] private readonly MindSystem _mindSystem = default!;
[Dependency] private readonly MetaDataSystem _metaDataSystem = default!;

private ISawmill _sawmill = default!;

Expand All @@ -75,6 +78,8 @@ public override void Initialize()

_sawmill = Logger.GetSawmill("mail");

SubscribeLocalEvent<PlayerSpawningEvent>(OnSpawnPlayer, after: new[] { typeof(SpawnPointSystem) });

SubscribeLocalEvent<MailComponent, ComponentRemove>(OnRemove);
SubscribeLocalEvent<MailComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<MailComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
Expand Down Expand Up @@ -104,6 +109,20 @@ public override void Update(float frameTime)
}
}

/// <summary>
/// Dynamically add the MailReceiver component to appropriate entities.
/// </summary>
private void OnSpawnPlayer(PlayerSpawningEvent args)
{
if (args.SpawnResult == null ||
args.Job == null )
{
return;
}

EnsureComp<MailReceiverComponent>(args.SpawnResult.Value);
}

private void OnRemove(EntityUid uid, MailComponent component, ComponentRemove args)
{
// Make sure the priority timer doesn't run.
Expand Down Expand Up @@ -178,9 +197,15 @@ private void OnAfterInteractUsing(EntityUid uid, MailComponent component, AfterI

if (!HasComp<EmaggedComponent>(uid))
{
if (idCard.FullName != component.Recipient || idCard.JobTitle != component.RecipientJob)
//if (idCard.FullName != component.Recipient || idCard.JobTitle != component.RecipientJob)
//{
// _popupSystem.PopupEntity(Loc.GetString("mail-recipient-mismatch"), uid, args.User);
// return;
//}

if (idCard.FullName != component.Recipient) // Frontier - Only match the name
dvir001 marked this conversation as resolved.
Show resolved Hide resolved
{
_popupSystem.PopupEntity(Loc.GetString("mail-recipient-mismatch"), uid, args.User);
_popupSystem.PopupEntity(Loc.GetString("mail-recipient-mismatch-name"), uid, args.User);
return;
}

Expand All @@ -199,15 +224,15 @@ private void OnAfterInteractUsing(EntityUid uid, MailComponent component, AfterI
return;
}

_popupSystem.PopupEntity(Loc.GetString("mail-unlocked-reward", ("bounty", component.Bounty)), uid, args.User);
//_popupSystem.PopupEntity(Loc.GetString("mail-unlocked-reward", ("bounty", component.Bounty)), uid, args.User);
_popupSystem.PopupEntity(Loc.GetString("mail-unlocked-reward"), uid, args.User); // Frontier - Remove the mention of station income

component.IsProfitable = false;

var query = EntityQueryEnumerator<StationBankAccountComponent>();
while (query.MoveNext(out var oUid, out var oComp))
while (query.MoveNext(out var station, out var account))
{
// only our main station will have an account anyway so I guess we are just going to add it this way shrug.

_cargoSystem.UpdateBankAccount(oUid, oComp, component.Bounty);
_cargoSystem.UpdateBankAccount(station, account, component.Bounty);
return;
}
}
Expand Down Expand Up @@ -251,20 +276,21 @@ public void PenalizeStationFailedDelivery(EntityUid uid, MailComponent component
if (!component.IsProfitable)
return;

//_chatSystem.TrySendInGameICMessage(uid, Loc.GetString(localizationString, ("credits", component.Penalty)), InGameICChatType.Speak, false); # Dont show message.
//_audioSystem.PlayPvs(component.PenaltySound, uid); # Dont play sound.
//_chatSystem.TrySendInGameICMessage(uid, Loc.GetString(localizationString, ("credits", component.Penalty)), InGameICChatType.Speak, false); // Frontier - Dont show message.
//_audioSystem.PlayPvs(component.PenaltySound, uid); // Frontier - Dont show message. // Frontier - Dont play sound.

component.IsProfitable = false;

if (component.IsPriority)
_appearanceSystem.SetData(uid, MailVisuals.IsPriorityInactive, true);

var query = EntityQueryEnumerator<StationBankAccountComponent>();
while (query.MoveNext(out var oUid, out var oComp))
while (query.MoveNext(out var station, out var account))
{
// only our main station will have an account anyway so I guess we are just going to add it this way shrug.
//if (_stationSystem.GetOwningStation(uid) != station) // Frontier - No need for this test
// continue;

//_cargoSystem.UpdateBankAccount(oUid, oComp, component.Penalty); # Dont remove money.
//_cargoSystem.UpdateBankAccount(station, account, component.Penalty); // Frontier - Dont remove money.
return;
}
}
Expand All @@ -274,8 +300,8 @@ private void OnDestruction(EntityUid uid, MailComponent component, DestructionEv
if (component.IsLocked)
PenalizeStationFailedDelivery(uid, component, "mail-penalty-lock");

// if (component.IsEnabled)
// OpenMail(uid, component); # Dont open the mail on destruction.
// if (component.IsEnabled)
// OpenMail(uid, component); // Frontier - Dont open the mail on destruction.

UpdateAntiTamperVisuals(uid, false);
}
Expand Down Expand Up @@ -329,7 +355,8 @@ public bool IsEntityFragile(EntityUid uid, int fragileDamageThreshold)

// It can be spilled easily and has something to spill.
if (HasComp<SpillableComponent>(uid)
&& TryComp(uid, out DrinkComponent? drinkComponent)
&& TryComp<OpenableComponent>(uid, out var openable)
&& !_openable.IsClosed(uid, null, openable)
&& _solutionContainerSystem.PercentFull(uid) > 0)
return true;

Expand Down Expand Up @@ -399,21 +426,6 @@ public bool TryMatchJobTitleToPrototype(string jobTitle, [NotNullWhen(true)] out
return false;
}

public bool TryMatchJobTitleToIcon(string jobTitle, [NotNullWhen(true)] out string? jobIcon)
{
foreach (var job in _prototypeManager.EnumeratePrototypes<JobPrototype>())
{
if (job.LocalizedName == jobTitle)
{
jobIcon = job.Icon;
return true;
}
}

jobIcon = null;
return false;
}

/// <summary>
/// Handle all the gritty details particular to a new mail entity.
/// </summary>
Expand Down Expand Up @@ -449,7 +461,8 @@ public void SetupMail(EntityUid uid, MailTeleporterComponent component, MailReci

mailComp.RecipientJob = recipient.Job;
mailComp.Recipient = recipient.Name;
mailComp.RecipientStation = recipient.Ship;
mailComp.RecipientStation = recipient.Ship; // Frontier

if (mailComp.IsFragile)
{
mailComp.Bounty += component.FragileBonus;
Expand All @@ -470,10 +483,9 @@ public void SetupMail(EntityUid uid, MailTeleporterComponent component, MailReci
mailComp.priorityCancelToken.Token);
}

if (TryMatchJobTitleToIcon(recipient.Job, out string? icon))
_appearanceSystem.SetData(uid, MailVisuals.JobIcon, icon);
_appearanceSystem.SetData(uid, MailVisuals.JobIcon, recipient.JobIcon);

_meta.SetEntityName(uid, Loc.GetString("mail-item-name-addressed",
_metaDataSystem.SetEntityName(uid, Loc.GetString("mail-item-name-addressed",
("recipient", recipient.Name)));

var accessReader = EnsureComp<AccessReaderComponent>(uid);
Expand Down Expand Up @@ -541,9 +553,6 @@ public bool TryGetMailRecipientForReceiver(MailReceiverComponent receiver, [NotN
&& idCard.Comp.FullName != null
&& idCard.Comp.JobTitle != null)
{
HashSet<String> accessTags = access.Tags;

var mayReceivePriorityMail = true;
var stationUid = _stationSystem.GetOwningStation(receiver.Owner);
var stationName = string.Empty;
if (stationUid is EntityUid station
Expand All @@ -565,8 +574,13 @@ public bool TryGetMailRecipientForReceiver(MailReceiverComponent receiver, [NotN
return false;
}

var accessTags = access.Tags;

var mayReceivePriorityMail = !(_mindSystem.GetMind(receiver.Owner) == null);

recipient = new MailRecipient(idCard.Comp.FullName,
idCard.Comp.JobTitle,
idCard.Comp.JobIcon,
accessTags,
mayReceivePriorityMail,
stationName);
Expand All @@ -585,12 +599,14 @@ public List<MailRecipient> GetMailRecipientCandidates(EntityUid uid)
{
List<MailRecipient> candidateList = new();
var mailLocation = Transform(uid);

foreach (var receiver in EntityQuery<MailReceiverComponent>())
{
// mail is mapwide now, dont need to check if they are on the same station
var location = Transform(receiver.Owner); // mail is mapwide now, dont need to check if they are on the same station

//if (location.MapID != mailLocation.MapID)
//if (_stationSystem.GetOwningStation(receiver.Owner) != _stationSystem.GetOwningStation(uid))
// continue;
var location = Transform(receiver.Owner);
//continue;

if (location.MapID != mailLocation.MapID)
continue;
Expand Down Expand Up @@ -674,6 +690,8 @@ public void SpawnMail(EntityUid uid, MailTeleporterComponent? component = null)

var mail = EntityManager.SpawnEntity(chosenParcel, Transform(uid).Coordinates);
SetupMail(mail, component, candidate);

_tagSystem.AddTag(mail, "Recyclable"); // Frontier - Make it so mail can be destroyed by reclaimer
}

if (_containerSystem.TryGetContainer(uid, "queued", out var queued))
Expand Down Expand Up @@ -704,8 +722,10 @@ public void OpenMail(EntityUid uid, MailComponent? component = null, EntityUid?
_handsSystem.PickupOrDrop(user, entity);
}

_itemSystem.SetSize(uid, 1);
_tagSystem.AddTag(uid, "Trash");
_tagSystem.AddTag(uid, "Recyclable");
_tagSystem.AddTag(uid, "ClothMade"); // Frontier - Make it so moth can eat open mail.
component.IsEnabled = false;
UpdateMailTrashState(uid, true);
}
Expand All @@ -725,14 +745,16 @@ public struct MailRecipient
{
public string Name;
public string Job;
public string JobIcon;
public HashSet<String> AccessTags;
public bool MayReceivePriorityMail;
public string Ship;

public MailRecipient(string name, string job, HashSet<String> accessTags, bool mayReceivePriorityMail, string ship)
public MailRecipient(string name, string job, string jobIcon, HashSet<String> accessTags, bool mayReceivePriorityMail, string ship)
{
Name = name;
Job = job;
JobIcon = jobIcon;
AccessTags = accessTags;
MayReceivePriorityMail = mayReceivePriorityMail;
Ship = ship;
Expand Down
3 changes: 2 additions & 1 deletion Resources/Locale/en-US/_Nyano/mail.ftl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mail-recipient-mismatch = Recipient name or job does not match.
mail-recipient-mismatch-name = Recipient name does not match.
mail-invalid-access = Recipient name and job match, but access isn't as expected.
mail-locked = The anti-tamper lock hasn't been removed. Tap the recipient's ID.
mail-desc-far = A parcel of mail.
Expand All @@ -8,7 +9,7 @@ mail-desc-priority = The anti-tamper lock's [color=yellow]yellow priority tape[/
mail-desc-priority-inactive = The anti-tamper lock's [color=#886600]yellow priority tape[/color] is inactive.
mail-unlocked = Anti-tamper system unlocked.
mail-unlocked-by-emag = Anti-tamper system *BZZT*.
mail-unlocked-reward = Anti-tamper system unlocked. {$bounty} spesos have been added to station's account.
mail-unlocked-reward = Anti-tamper system unlocked.
mail-penalty-lock = ANTI-TAMPER LOCK BROKEN. STATION BANK ACCOUNT PENALIZED BY {$credits} SPESOS.
mail-penalty-fragile = INTEGRITY COMPROMISED. STATION BANK ACCOUNT PENALIZED BY {$credits} SPESOS.
mail-penalty-expired = DELIVERY PAST DUE. STATION BANK ACCOUNT PENALIZED BY {$credits} SPESOS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
- type: CameraRecoil
- type: Examiner
- type: CanHostGuardian
- type: MailReceiver
- type: NpcFactionMember
factions:
- NanoTrasen
Expand Down
1 change: 0 additions & 1 deletion Resources/Prototypes/Entities/Mobs/Player/arachnid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
damageRecovery:
types:
Asphyxiation: -0.5 # Recovery will suck without chems
- type: MailReceiver
1 change: 0 additions & 1 deletion Resources/Prototypes/Entities/Mobs/Player/diona.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
damageRecovery:
types:
Asphyxiation: -1.0
- type: MailReceiver
3 changes: 1 addition & 2 deletions Resources/Prototypes/Entities/Mobs/Player/dwarf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
name: Urist McHands The Dwarf
parent: BaseMobDwarf
id: MobDwarf
components:
- type: MailReceiver

2 changes: 0 additions & 2 deletions Resources/Prototypes/Entities/Mobs/Player/human.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
name: Urist McHands
parent: BaseMobHuman
id: MobHuman
components:
- type: MailReceiver

#Syndie
- type: entity
Expand Down
2 changes: 0 additions & 2 deletions Resources/Prototypes/Entities/Mobs/Player/moth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
name: Urist McFluff
parent: BaseMobMoth
id: MobMoth
components:
- type: MailReceiver
2 changes: 0 additions & 2 deletions Resources/Prototypes/Entities/Mobs/Player/reptilian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
name: Urisst' Mzhand
parent: BaseMobReptilian
id: MobReptilian
components:
- type: MailReceiver
#Weh
2 changes: 0 additions & 2 deletions Resources/Prototypes/Entities/Mobs/Player/slime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
save: false
parent: BaseMobSlimePerson
id: MobSlimePerson
components:
- type: MailReceiver
2 changes: 0 additions & 2 deletions Resources/Prototypes/Entities/Mobs/Player/vox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
name: Vox
parent: BaseMobVox
id: MobVox
components:
- type: MailReceiver
Loading
Loading