Skip to content
Open
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
68 changes: 68 additions & 0 deletions Content.Server/_Forge/SoulContractSystem/SoulContractSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Content.Server._NF.Bank;
using Content.Server.Store.Components;
using Content.Shared._Forge.SoulContract;
using Content.Shared.Body.Systems;
using Content.Shared.DoAfter;
using Content.Shared.Gibbing.Systems;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory;
using Content.Shared.Storage;
using static Content.Server.Power.Pow3r.PowerState;

namespace Content.Server._Forge.SoulContractSystem
{
public sealed class SoulContractSystem : EntitySystem
{
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly BankSystem _bank = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly SharedBodySystem _bodySystem = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SoulContractComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<SoulContractComponent, SoulContractDoAfterEvent>(OnDoAfter);
}

private void OnUseInHand(Entity<SoulContractComponent> entity, ref UseInHandEvent args)
{
var (uid, soulContract) = entity;

var user = args.User;

var doAfterArgs = new DoAfterArgs(EntityManager,
user,
soulContract.UseTime,
new SoulContractDoAfterEvent(),
eventTarget: uid)
{
BreakOnHandChange = false,
BreakOnMove = true,
BreakOnDamage = true,
MovementThreshold = 0.01f,
DistanceThreshold = 5,
NeedHand = true
};

_doAfterSystem.TryStartDoAfter(doAfterArgs);
}

private void OnDoAfter(Entity<SoulContractComponent> entity, ref SoulContractDoAfterEvent args)
{
if (args.Cancelled)
return;

Del(entity.Owner);
args.Handled = _bank.TryBankDeposit(args.Args.User, entity.Comp.Reward, true) && TryGib(entity, args.Args.User);
}

private bool TryGib(Entity<SoulContractComponent> entity, EntityUid user)
{
var gibHashSet = _bodySystem.GibBody(user);

return gibHashSet.Count > 0;
}
}
}
19 changes: 17 additions & 2 deletions Content.Server/_NF/Bank/BankSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared._NF.Bank.Events;
using Content.Shared.GameTicking;
using Robust.Shared.Network;
using System.Linq;

namespace Content.Server._NF.Bank;

Expand Down Expand Up @@ -102,7 +104,7 @@ public bool TryBankWithdraw(EntityUid mobUid, int amount)
/// <param name="mobUid">The UID that the bank account is connected to, typically the player controlled mob</param>
/// <param name="amount">The amount of spesos to remove from the bank account</param>
/// <returns>true if the transaction was successful, false if it was not</returns>
public bool TryBankDeposit(EntityUid mobUid, int amount)
public bool TryBankDeposit(EntityUid mobUid, int amount, bool sendToRandomCharacter = false)
{
if (amount <= 0)
{
Expand All @@ -127,8 +129,21 @@ public bool TryBankDeposit(EntityUid mobUid, int amount)
_log.Info($"TryBankDeposit: {mobUid} has no cached prefs");
return false;
}
// Forge-SoulContract
// Forge-SoulContract-start
var profile = prefs.SelectedCharacter as HumanoidCharacterProfile;

if (prefs.SelectedCharacter is not HumanoidCharacterProfile profile)
if (sendToRandomCharacter)
{
Random rnd = new Random();
int randomInt = rnd.Next(prefs.Characters.Count);
var randomProfile = (HumanoidCharacterProfile)prefs.Characters.ToList()[randomInt].Value;

profile = randomProfile;
}

if (profile is null)
// Forge-SoulContract-end
{
_log.Info($"TryBankDeposit: {mobUid} has the wrong prefs type");
return false;
Expand Down
25 changes: 25 additions & 0 deletions Content.Shared/_Forge/SoulContract/SoulContractComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Content.Shared.DoAfter;
using Robust.Shared.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Content.Shared._Forge.SoulContract
{
[RegisterComponent]
public sealed partial class SoulContractComponent: Component
{
[DataField]
public int Reward;

[DataField]
public TimeSpan UseTime = TimeSpan.FromSeconds(5);
}

[Serializable, NetSerializable]
public sealed partial class SoulContractDoAfterEvent : SimpleDoAfterEvent
{
}
}
15 changes: 15 additions & 0 deletions Content.Shared/_Forge/SoulContract/SoulContractDoAfterEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Content.Shared.DoAfter;
using Robust.Shared.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Content.Server._Forge.SoulContractSystem
{
[Serializable, NetSerializable]
public sealed partial class SoulContractDoAfterEvent: SimpleDoAfterEvent
{
}
}
11 changes: 11 additions & 0 deletions Resources/Prototypes/_Forge/SoulContract/soul_contract.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- type: entity
name: soul contract
parent: BaseItem
id: SoulContract
description: На станции, даже ваша душа имеет цену
components:
- type: Sprite
sprite: Objects/Fun/Bikehorn.rsi
state: icon
- type: SoulContract
reward: 100000