Files
OldThink/Content.Server/TraitorDeathMatch/TraitorDeathMatchRedemptionSystem.cs

109 lines
4.4 KiB
C#
Raw Normal View History

2022-08-17 00:34:25 -04:00
using Content.Server.Mind.Components;
2022-07-14 04:34:20 -07:00
using Content.Server.TraitorDeathMatch.Components;
2022-08-17 00:34:25 -04:00
using Content.Server.Store.Components;
using Content.Server.Store.Systems;
using Content.Server.Traitor.Uplink;
using Content.Shared.FixedPoint;
2022-07-14 04:34:20 -07:00
using Content.Shared.Interaction;
using Content.Shared.Inventory;
using Content.Shared.Popups;
namespace Content.Server.TraitorDeathMatch;
public sealed class TraitorDeathMatchRedemptionSystem : EntitySystem
{
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
2022-08-17 00:34:25 -04:00
[Dependency] private readonly UplinkSystem _uplink = default!;
[Dependency] private readonly StoreSystem _store = default!;
2022-07-14 04:34:20 -07:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<TraitorDeathMatchRedemptionComponent, InteractUsingEvent>(OnInteractUsing);
}
private void OnInteractUsing(EntityUid uid, TraitorDeathMatchRedemptionComponent component, InteractUsingEvent args)
{
if (!EntityManager.TryGetComponent<MindComponent>(args.User, out var userMindComponent))
{
_popup.PopupEntity(Loc.GetString(
"traitor-death-match-redemption-component-interact-using-main-message",
("secondMessage",
Loc.GetString("traitor-death-match-redemption-component-interact-using-no-mind-message"))), uid, args.User);
2022-07-14 04:34:20 -07:00
return;
}
var userMind = userMindComponent.Mind;
if (userMind == null)
{
_popup.PopupEntity(Loc.GetString(
"traitor-death-match-redemption-component-interact-using-main-message",
("secondMessage",
Loc.GetString("traitor-death-match-redemption-component-interact-using-no-user-mind-message"))), uid, args.User);
2022-07-14 04:34:20 -07:00
return;
}
2022-08-17 00:34:25 -04:00
if (!EntityManager.TryGetComponent<StoreComponent>(args.Used, out var victimUplink))
2022-07-14 04:34:20 -07:00
{
_popup.PopupEntity(Loc.GetString(
"traitor-death-match-redemption-component-interact-using-main-message",
("secondMessage",
Loc.GetString("traitor-death-match-redemption-component-interact-using-no-pda-message"))), uid, args.User);
2022-07-14 04:34:20 -07:00
return;
}
if (!EntityManager.TryGetComponent<TraitorDeathMatchReliableOwnerTagComponent>(args.Used,
out var victimPDAuid))
{
_popup.PopupEntity(Loc.GetString(
"traitor-death-match-redemption-component-interact-using-main-message",
("secondMessage",
Loc.GetString("traitor-death-match-redemption-component-interact-using-no-pda-owner-message"))), uid, args.User);
2022-07-14 04:34:20 -07:00
return;
}
if (victimPDAuid.UserId == userMind.UserId)
{
_popup.PopupEntity(Loc.GetString(
"traitor-death-match-redemption-component-interact-using-main-message",
("secondMessage",
Loc.GetString(
"traitor-death-match-redemption-component-interact-using-pda-different-user-message"))), uid, args.User);
2022-07-14 04:34:20 -07:00
return;
}
2022-08-17 00:34:25 -04:00
StoreComponent? userUplink = null;
2022-07-14 04:34:20 -07:00
if (_inventory.TryGetSlotEntity(args.User, "id", out var pdaUid) &&
2022-08-17 00:34:25 -04:00
EntityManager.TryGetComponent<StoreComponent>(pdaUid, out var userUplinkComponent))
2022-07-14 04:34:20 -07:00
userUplink = userUplinkComponent;
if (userUplink == null)
{
_popup.PopupEntity(Loc.GetString(
"traitor-death-match-redemption-component-interact-using-main-message",
("secondMessage",
Loc.GetString(
"traitor-death-match-redemption-component-interact-using-no-pda-in-pocket-message"))), uid, args.User);
2022-07-14 04:34:20 -07:00
return;
}
2022-08-17 00:34:25 -04:00
// We have finally determined both PDA components. FINALLY.
2022-07-14 04:34:20 -07:00
2022-08-17 00:34:25 -04:00
// 4 is the per-PDA bonus amount
var transferAmount = _uplink.GetTCBalance(victimUplink) + 4;
victimUplink.Balance.Clear();
2023-02-12 07:39:14 -05:00
_store.TryAddCurrency(new Dictionary<string, FixedPoint2>() { {"Telecrystal", FixedPoint2.New(transferAmount)}}, userUplink.Owner, userUplink);
2022-07-14 04:34:20 -07:00
EntityManager.DeleteEntity(victimUplink.Owner);
_popup.PopupEntity(Loc.GetString("traitor-death-match-redemption-component-interact-using-success-message",
("tcAmount", transferAmount)), uid, args.User);
2022-07-14 04:34:20 -07:00
args.Handled = true;
}
}