Skip to content

Commit

Permalink
Merged some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
benvalkin committed Oct 9, 2024
2 parents 35363dd + 5e956ad commit 4010826
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 21 deletions.
43 changes: 34 additions & 9 deletions UncreatedWarfare/Commands/Zone/ZoneGoCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Uncreated.Warfare.FOBs.Deployment;
using System;
using System.Globalization;
using Microsoft.Extensions.DependencyInjection;
using Uncreated.Warfare.FOBs.Deployment;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Layouts.Teams;
using Uncreated.Warfare.Locations;
using Uncreated.Warfare.Logging;
using Uncreated.Warfare.Translations;
Expand Down Expand Up @@ -40,15 +44,36 @@ public UniTask ExecuteAsync(CancellationToken token)
{
Context.AssertRanByPlayer();

Zone? zone;
if (Context.TryGetRange(0, out string? zname))
zone = _zoneStore.SearchZone(zname);
else
string teamNumberStr;
Zone? zone = null;
string? zname = null;

// t1, t2, etc
if (Context.HasArgs(1)
&& (teamNumberStr = Context.Get(0) ?? string.Empty).StartsWith("t", StringComparison.OrdinalIgnoreCase)
&& uint.TryParse(teamNumberStr.AsSpan(1), NumberStyles.Number, CultureInfo.InvariantCulture, out uint teamNumber))
{
ITeamManager<Team> teamManager = Context.ServiceProvider.GetRequiredService<ITeamManager<Team>>();

Team team = teamManager.GetTeam(new CSteamID(teamNumber));
if (team.IsValid)
{
zone = _zoneStore.SearchZone(ZoneType.MainBase, team.Faction);
zname = zone?.Name;
}
}

if (zone == null)
{
Vector3 plpos = Context.Player.Position;
if (!Context.Player.IsOnline) return UniTask.CompletedTask; // player got kicked
zone = _zoneStore.FindInsideZone(plpos, false);
zname = zone?.Name;
if (Context.TryGetRange(0, out zname))
{
zone = _zoneStore.SearchZone(zname);
}
else
{
zone = _zoneStore.FindInsideZone(Context.Player.Position, false);
zname = zone?.Name;
}
}

Vector3 pos;
Expand Down
19 changes: 19 additions & 0 deletions UncreatedWarfare/Locations/GridLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,25 @@ public static bool TryParse(ReadOnlySpan<char> value, out GridLocation location)
return false;
rtnTrue:
location = new GridLocation(x, y, index);
return !Level.isInitialized || CheckSafe(x, y);
}

private static bool CheckSafe(byte x, byte y)
{
if (CartographyUtility.UsesLegacyCartography)
{
GetMapMetrics(Level.info.size, out int gridSize, out _, out _);
if (Math.Max(x, y) >= gridSize)
return false;
}
else
{
Vector2Int captureAreaSize = CartographyUtility.MapImageSize;
GetMapMetrics(captureAreaSize.x, captureAreaSize.y, out int gridSizeX, out int gridSizeY, out _, out _, out _);
if (x >= gridSizeX || y >= gridSizeY)
return false;
}

return true;
}

Expand Down
5 changes: 5 additions & 0 deletions UncreatedWarfare/Teams/FactionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,9 @@ public object Clone()
{
return IsDefaultFaction ? null : this;
}

public override string ToString()
{
return $"{FactionId} #{PrimaryKey} [{Name}]";
}
}
4 changes: 3 additions & 1 deletion UncreatedWarfare/Util/List/SingleUseTypeDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ public class SingleUseTypeDictionary<TType> where TType : notnull
public SingleUseTypeDictionary(Type[] types, TType[] values)
{
_values = values;
Type[] typeArgs = [ typeof(TType), null! ];
for (int i = 0; i < types.Length; ++i)
{
typeArgs[1] = types[i];
typeof(IndexCache<>)
.MakeGenericType(typeof(TType), types[i])
.MakeGenericType(typeArgs)
.GetField(nameof(IndexCache<object>.Index), BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)!
.SetValue(null, i);
}
Expand Down
12 changes: 1 addition & 11 deletions UncreatedWarfare/WarfareModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.FileProviders.Physical;
using SDG.Framework.Modules;
using StackCleaner;
using Stripe;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using StackCleaner;
using Uncreated.Warfare.Actions;
using Uncreated.Warfare.Buildables;
using Uncreated.Warfare.Components;
Expand Down Expand Up @@ -244,16 +244,6 @@ private void Init()

_logger = ServiceProvider.Resolve<ILogger<WarfareModule>>();

using (_logger.BeginScope("Check players"))
{
using (_logger.BeginScope(new CSteamID(76500000000000000)))
{
_logger.LogInformation("test 1");
_logger.LogInformation("test 2");
_logger.LogInformation("test 3");
}
}

GlobalLogger = ServiceProvider.Resolve<ILoggerFactory>().CreateLogger("Global");

_logger.LogInformation("Using {0} services from core and {1} plugin(s).", ServiceProvider.ComponentRegistry.Registrations.Count(), _pluginLoader.Plugins.Count);
Expand Down

0 comments on commit 4010826

Please sign in to comment.