Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	SL-CustomObjects/Assets/DONT TOUCH/Scripts/Schematic.cs
#	SL-CustomObjects/Assets/DONT TOUCH/Scripts/SchematicManager/Updater.cs
  • Loading branch information
Michal78900 committed Jun 10, 2023
2 parents 059475c + dc51a60 commit bcff026
Show file tree
Hide file tree
Showing 957 changed files with 1,414 additions and 116,635 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,5 @@ FodyWeavers.xsd
/SL-CustomObjects/[Ll]ibrary/
/SL-CustomObjects/Assets/[Mm]y [Pp]rojects
/SL-CustomObjects/Assets/config.json
/SL-CustomObjects/Assets/config.json.meta
/SL-CustomObjects/Assets/config.json.meta
/MapEditorReborn/MapEditorReborn.csproj
15 changes: 7 additions & 8 deletions MapEditorReborn/API/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public static class API
/// <summary>
/// The base schematic.
/// </summary>
internal static MapSchematic MapSchematic;
internal static MapSchematic? MapSchematic;

internal static ReadOnlyCollection<RoomType> RoomTypes;
internal static ReadOnlyCollection<RoomType>? RoomTypes;

/// <summary>
/// Gets or sets currently loaded <see cref="MapSchematic"/>.
/// </summary>
public static MapSchematic CurrentLoadedMap
public static MapSchematic? CurrentLoadedMap
{
get => MapSchematic;
set => MapUtils.LoadMap(value);
Expand All @@ -61,8 +61,7 @@ public static MapSchematic CurrentLoadedMap
/// </summary>
internal static Dictionary<ushort, ObjectType> ToolGuns { get; private set; } = new();

internal static List<ushort> GravityGuns { get; private set; } = new();

internal static Dictionary<ushort, GravityGunMode> GravityGuns { get; private set; } = new();
internal static HashSet<ushort> PickupsLocked { get; private set; } = new();

internal static Dictionary<ushort, int> PickupsUsesLeft { get; private set; } = new();
Expand All @@ -80,9 +79,9 @@ public static MapSchematic CurrentLoadedMap
/// <summary>
/// Gets or sets a random <see cref="Room"/> from the <see cref="RoomType"/>.
/// </summary>
/// <param name="type">The <see cref="RoomType"/> from which the room should be choosen.</param>
/// <param name="type">The <see cref="RoomType"/> from which the room should be chosen.</param>
/// <returns>A random <see cref="Room"/> that has <see cref="Room.Type"/> of the argument.</returns>
public static Room GetRandomRoom(RoomType type)
public static Room? GetRandomRoom(RoomType type)
{
if (type == RoomType.Unknown)
return null;
Expand Down Expand Up @@ -143,4 +142,4 @@ public static bool TryGetVector(string x, string y, string z, out Vector3 vector
return true;
}
}
}
}
13 changes: 13 additions & 0 deletions MapEditorReborn/API/Enums/GravityGunMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace MapEditorReborn.API.Enums
{
using System;

[Flags]
internal enum GravityGunMode
{
Movement = 1,
Rotate = 2,
Gravity = 4,

}
}
15 changes: 15 additions & 0 deletions MapEditorReborn/API/Enums/LoadMapOnEventMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace MapEditorReborn.API.Enums
{
public enum LoadMapOnEventMode
{
/// <summary>
/// Picks a random map from the available maps.
/// </summary>
Random,

/// <summary>
/// Merges multiple maps into one and loads all of them.
/// </summary>
Merge
}
}
150 changes: 150 additions & 0 deletions MapEditorReborn/API/Extensions/BitwiseExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
namespace MapEditorReborn.API.Extensions
{
using System;
using System.Globalization;

public static class BitwiseExtensions
{
public static T IncludeAll<T>(this Enum value)
{
Type type = value.GetType();
object result = value;
string[] names = Enum.GetNames(type);
foreach (var name in names)
{
((Enum)result).Include(Enum.Parse(type, name));
}

return (T)result;
//Enum.Parse(type, result.ToString());
}

/// <summary>
/// Includes an enumerated type and returns the new value
/// </summary>
public static T Include<T>(this Enum value, T append)
{
Type type = value.GetType();

//determine the values
object result = value;
var parsed = new _Value(append, type);
if (parsed.Signed is long)
{
result = Convert.ToInt64(value) | (long)parsed.Signed;
}
else if (parsed.Unsigned is ulong)
{
result = Convert.ToUInt64(value) | (ulong)parsed.Unsigned;
}

//return the final value
return (T)Enum.Parse(type, result.ToString());
}

/// <summary>
/// Check to see if a flags enumeration has a specific flag set.
/// </summary>
/// <param name="variable">Flags enumeration to check</param>
/// <param name="value">Flag to check for</param>
/// <returns></returns>
public static bool HasFlag(this Enum variable, Enum value)
{
if (variable == null)
return false;

if (value == null)
throw new ArgumentNullException("value");

// Not as good as the .NET 4 version of this function,
// but should be good enough
if (!Enum.IsDefined(variable.GetType(), value))
{
throw new ArgumentException(string.Format(
"Enumeration type mismatch. The flag is of type '{0}', " +
"was expecting '{1}'.", value.GetType(),
variable.GetType()));
}

ulong num = Convert.ToUInt64(value);
return ((Convert.ToUInt64(variable) & num) == num);
}

public static T SetFlag<T>(this T flags, T flag, bool value) where T : struct, IComparable, IFormattable, IConvertible
{
int flagsInt = flags.ToInt32(NumberFormatInfo.CurrentInfo);
int flagInt = flag.ToInt32(NumberFormatInfo.CurrentInfo);
if (value)
{
flagsInt |= flagInt;
}
else
{
flagsInt &= ~flagInt;
}
return (T)(Object)flagsInt;
}


/// <summary>
/// Removes an enumerated type and returns the new value
/// </summary>
public static T Remove<T>(this Enum value, T remove)
{
Type type = value.GetType();

//determine the values
object result = value;
var parsed = new _Value(remove, type);
if (parsed.Signed is long)
{
result = Convert.ToInt64(value) & ~(long)parsed.Signed;
}
else if (parsed.Unsigned is ulong)
{
result = Convert.ToUInt64(value) & ~(ulong)parsed.Unsigned;
}

//return the final value
return (T)Enum.Parse(type, result.ToString());
}

//class to simplfy narrowing values between
//a ulong and long since either value should
//cover any lesser value
private class _Value
{
//cached comparisons for tye to use
private static readonly Type _UInt32 = typeof(long);
private static readonly Type _UInt64 = typeof(ulong);

public readonly long? Signed;
public readonly ulong? Unsigned;

public _Value(object value, Type type)
{
//make sure it is even an enum to work with
if (!type.IsEnum)
{
throw new ArgumentException(
"Value provided is not an enumerated type!");
}

//then check for the enumerated value
Type compare = Enum.GetUnderlyingType(type);

//if this is an unsigned long then the only
//value that can hold it would be a ulong
if (compare.Equals(_UInt32) || compare.Equals(_UInt64))
{
Unsigned = Convert.ToUInt64(value);
}
//otherwise, a long should cover anything else
else
{
Signed = Convert.ToInt64(value);
}
}
}
}
}
3 changes: 2 additions & 1 deletion MapEditorReborn/API/Extensions/CullingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static void SpawnNetworkIdentity(this Player player, NetworkIdentity netw
/// <param name="player">The target.</param>
/// <param name="networkIdentity">The network identity to destroy.</param>
public static void DestroyNetworkIdentity(this Player player, NetworkIdentity networkIdentity) =>
player.Connection.Send(new ObjectDestroyMessage() { netId = networkIdentity.netId });
player.Connection.Send(new ObjectDestroyMessage
{ netId = networkIdentity.netId });
}
}
26 changes: 16 additions & 10 deletions MapEditorReborn/API/Extensions/GenericExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ namespace MapEditorReborn.API.Extensions
using System.Globalization;
using Enums;
using Exiled.API.Enums;
using Exiled.API.Extensions;
using Exiled.API.Features.Items;
using Exiled.API.Features.Pickups;
using InventorySystem.Items.Firearms;
using InventorySystem.Items.Pickups;
using UnityEngine;
using Firearm = Exiled.API.Features.Items.Firearm;
using FirearmPickup = InventorySystem.Items.Firearms.FirearmPickup;

/// <summary>
/// The extensions class which contains a few useful methods.
Expand Down Expand Up @@ -62,31 +68,31 @@ public static SpawnableTeam ConvertToSpawnableTeam(this string spawnPointTag)
public static Pickup CreatePickup(this Item item, Vector3 position, Quaternion rotation = default, Vector3? scale = null)
{
item.Base.PickupDropModel.Info.ItemId = item.Type;
item.Base.PickupDropModel.Info.Position = position;
item.Base.PickupDropModel.Info._serverPosition = position;
item.Base.PickupDropModel.Info.Weight = item.Weight;
item.Base.PickupDropModel.Info.Rotation = new LowPrecisionQuaternion(rotation);
item.Base.PickupDropModel.Info._serverRotation = rotation;
item.Base.PickupDropModel.NetworkInfo = item.Base.PickupDropModel.Info;
item.Base.Category = ItemCategory.None;

InventorySystem.Items.Pickups.ItemPickupBase ipb = Object.Instantiate(item.Base.PickupDropModel, position, rotation);
if (ipb is InventorySystem.Items.Firearms.FirearmPickup firearmPickup)
ItemPickupBase ipb = Object.Instantiate(item.Base.PickupDropModel, position, rotation);
if (ipb is FirearmPickup firearmPickup)
{
if (item is Firearm firearm)
{
firearmPickup.Status = new InventorySystem.Items.Firearms.FirearmStatus(firearm.Ammo, InventorySystem.Items.Firearms.FirearmStatusFlags.MagazineInserted, firearmPickup.Status.Attachments);
firearmPickup.Status = new FirearmStatus(firearm.Ammo, FirearmStatusFlags.MagazineInserted, firearmPickup.Status.Attachments);
}
else
{
byte ammo = item.Base switch
{
InventorySystem.Items.Firearms.AutomaticFirearm auto => auto._baseMaxAmmo,
InventorySystem.Items.Firearms.Shotgun shotgun => shotgun._ammoCapacity,
InventorySystem.Items.Firearms.Revolver revolver => revolver.AmmoManagerModule.MaxAmmo,
AutomaticFirearm auto => auto._baseMaxAmmo,
Shotgun shotgun => shotgun._ammoCapacity,
Revolver revolver => revolver.AmmoManagerModule.MaxAmmo,
_ => 0,
};

uint code = firearmPickup.Status.Attachments;
firearmPickup.Status = new InventorySystem.Items.Firearms.FirearmStatus(ammo, InventorySystem.Items.Firearms.FirearmStatusFlags.MagazineInserted, code);
firearmPickup.Status = new FirearmStatus(ammo, FirearmStatusFlags.MagazineInserted, code);
}

firearmPickup.NetworkStatus = firearmPickup.Status;
Expand All @@ -102,7 +108,7 @@ public static Pickup CreatePickup(this Item item, Vector3 position, Quaternion r
/// <inheritdoc cref="Exiled.API.Extensions.ReflectionExtensions.CopyProperties(object, object)"/>
public static T CopyProperties<T>(this T target, object source)
{
Exiled.API.Extensions.ReflectionExtensions.CopyProperties(target, source);
ReflectionExtensions.CopyProperties(target, source);
return target;
}

Expand Down
Loading

0 comments on commit bcff026

Please sign in to comment.