* some work * equip: done unequip: todo * unequipping done & refactored events * workin * movin * reee namespaces * stun * mobstate * fixes * some work on events * removes serverside itemcomp & misc fixes * work * smol merge fix * ports template to prototype & finishes ui * moves relay & adds containerenumerator * actions & cuffs * my god what is actioncode * more fixes * im loosing my grasp on reality * more fixes * more work * explosions * yes * more work * more fixes * merge master & misc fixed because i forgot to commit before merging master * more fixes * fixes * moar * more work * moar fixes * suffixmap * more work on client * motivation low * no. no containers * mirroring client to server * fixes * move serverinvcomp * serverinventorycomponent is dead * gaming * only strippable & ai left... * only ai and richtext left * fixes ai * fixes * fixes sprite layers * more fixes * resolves optional * yes * stable™️ * fixes * moar fixes * moar * fix some tests * lmao * no comment * good to merge™️ * fixes build but for real * adresses some reviews * adresses some more reviews * nullables, yo * fixes lobbyscreen * timid refactor to differentiate actor & target * adresses more reviews * more * my god what a mess * removed the rest of duplicates * removed duplicate slotflags and renamed shoes to feet * removes another unused one * yes * fixes lobby & makes tryunequip return unequipped item * fixes * some funny renames * fixes * misc improvements to attemptevents * fixes * merge fixes Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
117 lines
6.1 KiB
C#
117 lines
6.1 KiB
C#
using System.Threading.Tasks;
|
|
using Content.Server.Mind.Components;
|
|
using Content.Server.Traitor.Uplink.Account;
|
|
using Content.Server.Traitor.Uplink.Components;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.Popups;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using InventoryComponent = Content.Shared.Inventory.InventoryComponent;
|
|
|
|
namespace Content.Server.TraitorDeathMatch.Components
|
|
{
|
|
[RegisterComponent]
|
|
public class TraitorDeathMatchRedemptionComponent : Component, IInteractUsing
|
|
{
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
|
|
/// <inheritdoc />
|
|
public override string Name => "TraitorDeathMatchRedemption";
|
|
|
|
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
|
{
|
|
if (!_entMan.TryGetComponent<MindComponent?>(eventArgs.User, out var userMindComponent))
|
|
{
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message",
|
|
("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-no-mind-message"))));
|
|
return false;
|
|
}
|
|
|
|
var userMind = userMindComponent.Mind;
|
|
if (userMind == null)
|
|
{
|
|
Owner.PopupMessage(eventArgs.User, 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"))));
|
|
return false;
|
|
}
|
|
|
|
if (!_entMan.TryGetComponent<UplinkComponent?>(eventArgs.Using, out var victimUplink))
|
|
{
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message",
|
|
("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-no-pda-message"))));
|
|
return false;
|
|
}
|
|
|
|
if (!_entMan.TryGetComponent<TraitorDeathMatchReliableOwnerTagComponent?>(eventArgs.Using, out var victimPDAOwner))
|
|
{
|
|
Owner.PopupMessage(eventArgs.User, 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"))));
|
|
return false;
|
|
}
|
|
|
|
if (victimPDAOwner.UserId == userMind.UserId)
|
|
{
|
|
Owner.PopupMessage(eventArgs.User, 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"))));
|
|
return false;
|
|
}
|
|
|
|
UplinkComponent? userUplink = null;
|
|
var invSystem = EntitySystem.Get<InventorySystem>();
|
|
|
|
if (invSystem.TryGetSlotEntity(eventArgs.User, "id", out var pdaUid) &&
|
|
_entMan.TryGetComponent<UplinkComponent>(pdaUid, out var userUplinkComponent))
|
|
{
|
|
userUplink = userUplinkComponent;
|
|
}
|
|
|
|
if (userUplink == null)
|
|
{
|
|
Owner.PopupMessage(eventArgs.User, 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"))));
|
|
return false;
|
|
}
|
|
|
|
// We have finally determined both PDA components. FINALLY.
|
|
|
|
var userAccount = userUplink.UplinkAccount;
|
|
var victimAccount = victimUplink.UplinkAccount;
|
|
|
|
if (userAccount == null)
|
|
{
|
|
// This shouldn't even BE POSSIBLE in the actual mode this is meant for.
|
|
// Advanced Syndicate anti-tampering technology.
|
|
// Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-tampering-detected"));
|
|
// if (eventArgs.User.TryGetComponent<DamagableComponent>(out var userDamagable))
|
|
// userDamagable.ChangeDamage(DamageType.Shock, 9001, true, null);
|
|
// ...So apparently, "it probably shouldn't kill people for a mistake".
|
|
// :(
|
|
// Give boring error message instead.
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message",
|
|
("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-user-no-uplink-account-message"))));
|
|
return false;
|
|
}
|
|
|
|
if (victimAccount == null)
|
|
{
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message",
|
|
("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-victim-no-uplink-account-message"))));
|
|
return false;
|
|
}
|
|
|
|
// 4 is the per-PDA bonus amount.
|
|
var accounts = _entMan.EntitySysManager.GetEntitySystem<UplinkAccountsSystem>();
|
|
var transferAmount = victimAccount.Balance + 4;
|
|
accounts.SetBalance(victimAccount, 0);
|
|
accounts.AddToBalance(userAccount, transferAmount);
|
|
|
|
_entMan.DeleteEntity(victimUplink.Owner);
|
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-success-message", ("tcAmount", transferAmount)));
|
|
return true;
|
|
}
|
|
}
|
|
}
|