Skip to content

Commit

Permalink
Merge branch 'master' into 2024-12-28-FixYaRace
Browse files Browse the repository at this point in the history
  • Loading branch information
dvir001 authored Dec 27, 2024
2 parents e54fe22 + e84aa8a commit 0f10169
Show file tree
Hide file tree
Showing 32 changed files with 397 additions and 260 deletions.
41 changes: 41 additions & 0 deletions Content.Client/Stack/StackCustomSplitBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Cherry-picked from space-station-14#32938 courtesy of Ilya246
using JetBrains.Annotations;
using Content.Shared.Stacks;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;

namespace Content.Client.Stack
{
[UsedImplicitly]
public sealed class StackCustomSplitBoundUserInterface : BoundUserInterface
{
private IEntityManager _entManager;
private EntityUid _owner;
[ViewVariables]
private StackCustomSplitWindow? _window;

public StackCustomSplitBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_owner = owner;
_entManager = IoCManager.Resolve<IEntityManager>();
}

protected override void Open()
{
base.Open();
_window = this.CreateWindow<StackCustomSplitWindow>();

if (_entManager.TryGetComponent<StackComponent>(_owner, out var comp))
_window.SetMax(comp.Count);

_window.ApplyButton.OnPressed += _ =>
{
if (int.TryParse(_window.AmountLineEdit.Text, out var i))
{
SendMessage(new StackCustomSplitAmountMessage(i));
_window.Close();
}
};
}
}
}
15 changes: 15 additions & 0 deletions Content.Client/Stack/StackCustomSplitWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'ui-custom-stack-split-title'}"
Resizable="False">
<!--Cherry-picked from space-station-14#32938 courtesy of Ilya246-->

<BoxContainer Orientation="Vertical" SeparationOverride="4" MinSize="240 80">
<BoxContainer Orientation="Horizontal">
<LineEdit Name="AmountLineEdit" Access="Public" HorizontalExpand="True" PlaceHolder="{Loc 'ui-custom-stack-split-line-edit-placeholder'}"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Name="MaximumAmount" Access="Public" />
</BoxContainer>
<Button Name="ApplyButton" Access="Public" Text="{Loc 'ui-custom-stack-split-apply'}"/>
</BoxContainer>
</DefaultWindow>
35 changes: 35 additions & 0 deletions Content.Client/Stack/StackCustomSplitWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Cherry-picked from space-station-14#32938 courtesy of Ilya246
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.Stack
{
[GenerateTypedNameReferences]
public sealed partial class StackCustomSplitWindow : DefaultWindow
{
private int _max = Int32.MaxValue;
private int _min = 1;

public StackCustomSplitWindow()
{
RobustXamlLoader.Load(this);
AmountLineEdit.OnTextChanged += OnValueChanged;
}

public void SetMax(int max)
{
_max = max;
MaximumAmount.Text = Loc.GetString("comp-stack-split-size", ("size", _max));
}

private void OnValueChanged(LineEdit.LineEditEventArgs args)
{
if (!int.TryParse(AmountLineEdit.Text, out var amount) || amount > _max || amount < _min)
ApplyButton.Disabled = true;
else
ApplyButton.Disabled = false;
}
}
}
36 changes: 34 additions & 2 deletions Content.Server/Stack/StackSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Content.Server.Stack
public sealed class StackSystem : SharedStackSystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedUserInterfaceSystem _ui = default!; // Cherry-picked from space-station-14#32938 courtesy of Ilya246

public static readonly int[] DefaultSplitAmounts = { 1, 5, 10, 20, 50, 100, 500, 1000, 5000, 10000 };

Expand Down Expand Up @@ -170,16 +171,33 @@ private void OnStackAlternativeInteract(EntityUid uid, StackComponent stack, Get
if (!args.CanAccess || !args.CanInteract || args.Hands == null || stack.Count == 1)
return;

// Frontier: cherry-picked from ss14#32938, moved up top
var priority = 1;
if (_ui.HasUi(uid, StackCustomSplitUiKey.Key)) // Frontier: check for interface
{
AlternativeVerb custom = new()
{
Text = Loc.GetString("comp-stack-split-custom"),
Category = VerbCategory.Split,
Act = () =>
{
_ui.OpenUi(uid, StackCustomSplitUiKey.Key, args.User);
},
Priority = priority--
};
args.Verbs.Add(custom);
}
// End Frontier: cherry-picked from ss14#32938, moved up top

AlternativeVerb halve = new()
{
Text = Loc.GetString("comp-stack-split-halve"),
Category = VerbCategory.Split,
Act = () => UserSplit(uid, args.User, stack.Count / 2, stack),
Priority = 1
Priority = priority-- // Frontier: 1<priority--
};
args.Verbs.Add(halve);

var priority = 0;
foreach (var amount in DefaultSplitAmounts)
{
if (amount >= stack.Count)
Expand All @@ -200,6 +218,20 @@ private void OnStackAlternativeInteract(EntityUid uid, StackComponent stack, Get
}
}

// Cherry-picked from ss14#32938 courtesy of Ilya246
protected override void OnCustomSplitMessage(Entity<StackComponent> ent, ref StackCustomSplitAmountMessage message)
{
var (uid, comp) = ent;

// digital ghosts shouldn't be allowed to split stacks
if (!(message.Actor is { Valid: true } user))
return;

var amount = message.Amount;
UserSplit(uid, user, amount, comp);
}
// End cherry-pick from ss14#32938 courtesy of Ilya246

private void UserSplit(EntityUid uid, EntityUid userUid, int amount,
StackComponent? stack = null,
TransformComponent? userTransform = null)
Expand Down
26 changes: 26 additions & 0 deletions Content.Server/_NF/Chemistry/RandomPillSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Content.Shared.Chemistry.Components;
using Robust.Shared.Random;

namespace Content.Server._NF.Chemistry;

public sealed class RandomPillSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;

public const int MaxPillType = 21;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PillComponent, MapInitEvent>(OnMapInit);
}

private void OnMapInit(Entity<PillComponent> ent, ref MapInitEvent componentInit)
{
if (ent.Comp.Random)
{
ent.Comp.PillType = (uint)_random.Next(MaxPillType);
Dirty(ent);
}
}
}
42 changes: 26 additions & 16 deletions Content.Server/_NF/GameRule/NfAdventureRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Content.Server._NF.Bank;
using Content.Server._NF.GameRule.Components;
using Content.Server._NF.GameTicking.Events;
using Content.Shared.GameTicking.Components;
using Robust.Shared.Prototypes;
using Content.Server.Cargo.Components;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Presets;
using Content.Server.GameTicking.Rules;
using Content.Shared._NF.CCVar; // Frontier
using Robust.Shared.Configuration;
using Content.Shared._NF.Bank;
using Content.Server._NF.GameRule.Components;
using Content.Server._NF.Bank;
using Robust.Shared.Player;
using Robust.Shared.Network;
using Content.Shared._NF.CCVar;
using Content.Shared.GameTicking;
using Robust.Shared.Enums;
using Content.Shared.GameTicking.Components;
using Robust.Server.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.Network;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;

namespace Content.Server._NF.GameRule;

Expand All @@ -28,14 +29,17 @@ namespace Content.Server._NF.GameRule;
/// </summary>
public sealed class NFAdventureRuleSystem : GameRuleSystem<NFAdventureRuleComponent>
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly BankSystem _bank = default!;
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly PointOfInterestSystem _poi = default!;

private readonly HttpClient _httpClient = new();

private readonly ProtoId<GamePresetPrototype> _fallbackPresetID = "NFPirates";

public sealed class PlayerRoundBankInformation
{
// Initial balance, obtained on spawn
Expand Down Expand Up @@ -68,7 +72,7 @@ public override void Initialize()
SubscribeLocalEvent<PlayerSpawnCompleteEvent>(OnPlayerSpawningEvent);
SubscribeLocalEvent<PlayerDetachedEvent>(OnPlayerDetachedEvent);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
_playerManager.PlayerStatusChanged += PlayerManagerOnPlayerStatusChanged;
_player.PlayerStatusChanged += PlayerManagerOnPlayerStatusChanged;
}

protected override void AppendRoundEndText(EntityUid uid, NFAdventureRuleComponent component, GameRuleComponent gameRule, ref RoundEndTextAppendEvent ev)
Expand Down Expand Up @@ -196,8 +200,14 @@ protected override void Started(EntityUid uid, NFAdventureRuleComponent componen
List<PointOfInterestPrototype> optionalProtos = new();
Dictionary<string, List<PointOfInterestPrototype>> remainingUniqueProtosBySpawnGroup = new();

foreach (var location in _prototypeManager.EnumeratePrototypes<PointOfInterestPrototype>())
var currentPreset = _ticker.CurrentPreset?.ID ?? _fallbackPresetID;

foreach (var location in _proto.EnumeratePrototypes<PointOfInterestPrototype>())
{
// Check if any preset is accepted (empty) or if current preset is supported.
if (location.SpawnGamePreset.Length > 0 && !location.SpawnGamePreset.Contains(currentPreset))
continue;

if (location.SpawnGroup == "CargoDepot")
depotProtos.Add(location);
else if (location.SpawnGroup == "MarketStation")
Expand Down Expand Up @@ -228,7 +238,7 @@ protected override void Started(EntityUid uid, NFAdventureRuleComponent componen
private async Task ReportRound(string message, int color = 0x77DDE7)
{
Logger.InfoS("discord", message);
string webhookUrl = _configurationManager.GetCVar(NFCCVars.DiscordLeaderboardWebhook);
string webhookUrl = _cfg.GetCVar(NFCCVars.DiscordLeaderboardWebhook);
if (webhookUrl == string.Empty)
return;

Expand All @@ -249,7 +259,7 @@ private async Task ReportRound(string message, int color = 0x77DDE7)

private async Task ReportLedger(int color = 0xBF863F)
{
string webhookUrl = _configurationManager.GetCVar(NFCCVars.DiscordLeaderboardWebhook);
string webhookUrl = _cfg.GetCVar(NFCCVars.DiscordLeaderboardWebhook);
if (webhookUrl == string.Empty)
return;

Expand Down
1 change: 1 addition & 0 deletions Content.Server/_NF/GameRule/PointOfInterestPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public sealed partial class PointOfInterestPrototype : IPrototype

/// <summary>
/// What gamepresets ID this POI is allowed to spawn on.
/// If left empty, all presets are allowed.
/// </summary>
[DataField]
public ProtoId<GamePresetPrototype>[] SpawnGamePreset { get; private set; } = [];
Expand Down
Loading

0 comments on commit 0f10169

Please sign in to comment.