Skip to content

Commit

Permalink
Merged lots of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
benvalkin committed Dec 3, 2024
2 parents cf91859 + d7f33b5 commit 2b5d01e
Show file tree
Hide file tree
Showing 115 changed files with 4,124 additions and 2,617 deletions.
2 changes: 1 addition & 1 deletion UncreatedWarfare/Actions/ActionMenuUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ public class ActionMenuUI : UnturnedUI
public readonly UnturnedUIElement SquadSection = new UnturnedUIElement("AC_DefaultMenu/AC_SquadLeader");
public readonly UnturnedUIElement LogiSection = new UnturnedUIElement("AC_DefaultMenu/AC_Logi");

public ActionMenuUI(AssetConfiguration assetConfig, ILoggerFactory loggerFactory) : base(loggerFactory, assetConfig.GetAssetLink<EffectAsset>("UI:ActionMenu")) { }
public ActionMenuUI(AssetConfiguration assetConfig, ILoggerFactory loggerFactory) : base(loggerFactory, assetConfig.GetAssetLink<EffectAsset>("UI:ActionMenu"), staticKey: true) { }
}
40 changes: 14 additions & 26 deletions UncreatedWarfare/Commands/Kit/KitFavoriteCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using Uncreated.Framework.UI;
using System.Collections.Generic;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Kits;
using Uncreated.Warfare.Models.Kits;
Expand All @@ -15,19 +13,19 @@ internal class KitFavoriteCommand : IExecutableCommand
private readonly SignInstancer _signs;
private readonly KitCommandTranslations _translations;
private readonly KitManager _kitManager;
private readonly IServiceProvider _serviceProvider;
public CommandContext Context { get; set; }

public KitFavoriteCommand(TranslationInjection<KitCommandTranslations> translations, SignInstancer signs, KitManager kitManager, IServiceProvider serviceProvider)
public KitFavoriteCommand(TranslationInjection<KitCommandTranslations> translations, SignInstancer signs, KitManager kitManager)
{
_signs = signs;
_kitManager = kitManager;
_translations = translations.Value;
_serviceProvider = serviceProvider;
}

public async UniTask ExecuteAsync(CancellationToken token)
{
// ReSharper disable InconsistentlySynchronizedField

Context.AssertRanByPlayer();

string? kitId = null;
Expand Down Expand Up @@ -64,33 +62,23 @@ public async UniTask ExecuteAsync(CancellationToken token)
throw Context.Reply(_translations.KitNotFound, kitId);
}

await Context.Player.PurchaseSync.WaitAsync(token).ConfigureAwait(false);
try
await UniTask.SwitchToMainThread(token);

KitPlayerComponent comp = Context.Player.Component<KitPlayerComponent>();
lock (comp)
{
await UniTask.SwitchToMainThread(token);

if (_kitManager.IsFavoritedQuick(kit.PrimaryKey, Context.Player))
if (comp.FavoritedKits != null && comp.FavoritedKits.Contains(kit.PrimaryKey))
{
throw Context.Reply(_translations.KitFavoriteAlreadyFavorited, kit);
}

KitMenuUIData? data = UnturnedUIDataSource.GetData<KitMenuUIData>(Context.CallerId, _kitManager.MenuUI.Parent);
if (data == null)
{
data = new KitMenuUIData(_kitManager.MenuUI, _kitManager.MenuUI.Parent, Context.Player, _serviceProvider);
UnturnedUIDataSource.AddData(data);
}
(comp.FavoritedKits ??= new List<uint>(8)).Add(kit.PrimaryKey);
comp.FavoritesDirty = true;
}

(data.FavoriteKits ??= new List<uint>(8)).Add(kit.PrimaryKey);
data.FavoritesDirty = true;
Context.Reply(_translations.KitFavorited, kit);

await _kitManager.SaveFavorites(Context.Player, data.FavoriteKits, token).ConfigureAwait(false);

Context.Reply(_translations.KitFavorited, kit);
}
finally
{
Context.Player.PurchaseSync.Release();
}
// ReSharper restore InconsistentlySynchronizedField
}
}
34 changes: 16 additions & 18 deletions UncreatedWarfare/Commands/Kit/KitUnfavoriteCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Uncreated.Framework.UI;
using System.Collections.Generic;
using Uncreated.Framework.UI;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Kits;
using Uncreated.Warfare.Models.Kits;
Expand All @@ -24,6 +25,8 @@ public KitUnfavoriteCommand(TranslationInjection<KitCommandTranslations> transla

public async UniTask ExecuteAsync(CancellationToken token)
{
// ReSharper disable InconsistentlySynchronizedField

Context.AssertRanByPlayer();

string? kitId = null;
Expand Down Expand Up @@ -60,28 +63,23 @@ public async UniTask ExecuteAsync(CancellationToken token)
throw Context.Reply(_translations.KitNotFound, kitId);
}

await Context.Player.PurchaseSync.WaitAsync(token).ConfigureAwait(false);
try
await UniTask.SwitchToMainThread(token);

KitPlayerComponent comp = Context.Player.Component<KitPlayerComponent>();
lock (comp)
{
await UniTask.SwitchToMainThread(token);

if (!_kitManager.IsFavoritedQuick(kit.PrimaryKey, Context.Player))
if (comp.FavoritedKits == null || !comp.FavoritedKits.Contains(kit.PrimaryKey))
{
throw Context.Reply(_translations.KitFavoriteAlreadyUnfavorited, kit);
}

KitMenuUIData? data = UnturnedUIDataSource.GetData<KitMenuUIData>(Context.CallerId, _kitManager.MenuUI.Parent);
if (data?.FavoriteKits?.Remove(kit.PrimaryKey) ?? false)
{
data.FavoritesDirty = true;
await _kitManager.SaveFavorites(Context.Player, data.FavoriteKits, token).ConfigureAwait(false);
}

Context.Reply(_translations.KitUnfavorited, kit);
}
finally
{
Context.Player.PurchaseSync.Release();
comp.FavoritedKits.Remove(kit.PrimaryKey);
comp.FavoritesDirty = true;
}

Context.Reply(_translations.KitUnfavorited, kit);


// ReSharper restore InconsistentlySynchronizedField
}
}
67 changes: 0 additions & 67 deletions UncreatedWarfare/Commands/KitsCommand.cs

This file was deleted.

129 changes: 0 additions & 129 deletions UncreatedWarfare/Commands/Vanilla/HelpCommand.cs

This file was deleted.

46 changes: 46 additions & 0 deletions UncreatedWarfare/Commands/WarfareDev/DebugQuickWinCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using DanielWillett.ReflectionTools;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Layouts;
using Uncreated.Warfare.Layouts.Teams;
using Uncreated.Warfare.Players;

namespace Uncreated.Warfare.Commands;

[Command("quickwin", "nextphase"), SubCommandOf(typeof(WarfareDevCommand))]
internal class DebugQuickWinCommand : IExecutableCommand
{
private readonly Layout _layout;
public CommandContext Context { get; set; }

public DebugQuickWinCommand(Layout layout)
{
_layout = layout;
}

public async UniTask ExecuteAsync(CancellationToken token)
{
Team? winner = (Context.Caller as WarfarePlayer)?.Team;
if (winner == null || !winner.IsValid || Context.HasArgs(1))
{
if (Context.TryGetRange(0, out string? teamLookup))
{
winner = _layout.TeamManager.FindTeam(teamLookup);
}

if (winner == null || !winner.IsValid)
throw Context.ReplyString("Winning team not found.");
}

_layout.Data[KnownLayoutDataKeys.WinnerTeam] = winner;

if (_layout.IsActive)
{
await _layout.MoveToNextPhase(token);
Context.ReplyString($"Moved to next phase: {(_layout.ActivePhase?.GetType() is { } t ? Accessor.ExceptionFormatter.Format(t) : "null")}");
}
else
{
Context.ReplyString("Not active.");
}
}
}
1 change: 0 additions & 1 deletion UncreatedWarfare/Components/HeatSeekingMissileComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public void Initialize(GameObject projectile, Player firer, IServiceProvider ser
}
}
}
// TODO: add support for non-vehicle controller

_projectile = projectile;
_maxTurnDegrees = responsiveness;
Expand Down
Loading

0 comments on commit 2b5d01e

Please sign in to comment.