first commit

This commit is contained in:
2025-07-06 00:23:46 +02:00
commit 38f50c8819
1788 changed files with 112878 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
#if NETFRAMEWORK
namespace System.Runtime.CompilerServices;
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
internal sealed class CallerArgumentExpressionAttribute : Attribute
{
public CallerArgumentExpressionAttribute(string parameterName)
{
ParameterName = parameterName;
}
public string ParameterName { get; }
}
#endif

View File

@@ -0,0 +1,12 @@
namespace NitroxModel.Constants
{
/// <summary>
/// Shared values across LANDiscoveryClient, in NitroxClient project and LANDiscoveryServer in NitroxServer project.
/// </summary>
public static class LANDiscoveryConstants
{
public static readonly int[] BROADCAST_PORTS = { 1467, 8710, 16723, 3813, 9704 }; // Randomly generated
public const string BROADCAST_REQUEST_STRING = "NitroxLANRequest";
public const string BROADCAST_RESPONSE_STRING = "NitroxLANResponse";
}
}

View File

@@ -0,0 +1,12 @@
using Autofac;
namespace NitroxModel.Core
{
/// <summary>
/// Nitrox projects should inherit from this interface and register their services into the DI container using the builder method.
/// </summary>
public interface IAutoFacRegistrar
{
void RegisterDependencies(ContainerBuilder containerBuilder);
}
}

View File

@@ -0,0 +1,60 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
namespace NitroxModel.Helper
{
/// <summary>
/// Environment helper for getting meta data about where and how Nitrox is running.
/// </summary>
public static class NitroxEnvironment
{
public static string ReleasePhase => IsReleaseMode ? "Alpha" : "InDev";
public static Version Version => Assembly.GetExecutingAssembly().GetName().Version;
public static DateTime BuildDate => File.GetCreationTimeUtc(Assembly.GetExecutingAssembly().Location);
public static Types Type { get; private set; } = Types.NORMAL;
public static bool IsTesting => Type == Types.TESTING;
public static bool IsNormal => Type == Types.NORMAL;
public static int CurrentProcessId
{
get
{
using Process process = Process.GetCurrentProcess();
return process.Id;
}
}
public static bool IsReleaseMode
{
get
{
#if RELEASE
return true;
#else
return false;
#endif
}
}
private static bool hasSet;
public static void Set(Types value)
{
if (hasSet)
{
throw new Exception("Environment type can only be set once");
}
Type = value;
hasSet = true;
}
public enum Types
{
NORMAL,
TESTING
}
}
}

View File

@@ -0,0 +1,159 @@
using System;
using Autofac;
using Autofac.Builder;
using NitroxModel.DataStructures.Util;
namespace NitroxModel.Core;
/// <summary>
/// Dependency Injection (DI) class for resolving types as defined in the DI registrar, implementing <see cref="IAutoFacRegistrar" />.
/// </summary>
public static class NitroxServiceLocator
{
private static IContainer DependencyContainer { get; set; }
private static ILifetimeScope CurrentLifetimeScope { get; set; }
public static event EventHandler LifetimeScopeEnded;
public static void InitializeDependencyContainer(params IAutoFacRegistrar[] registrars)
{
ContainerBuilder builder = new();
foreach (IAutoFacRegistrar registrar in registrars)
{
registrar.RegisterDependencies(builder);
}
// IgnoreStartableComponents - Prevents "phantom" executions of the Start() method
// on a MonoBehaviour because someone accidentally did something funky with a DI registration.
DependencyContainer = builder.Build(ContainerBuildOptions.IgnoreStartableComponents);
}
/// <summary>
/// Starts a new life time scope. A single instance per registered service will be returned while this scope is active.
/// Services can scoped to this life time using <see cref="IRegistrationBuilder{TLimit,TActivatorData,TRegistrationStyle}.InstancePerLifetimeScope" />.
/// </summary>
/// <remarks>
/// A life time scope should be created when the game leaves the main menu and loads a level with multiplayer.
/// It should end when the game process unloads the level (e.g. player returns to the main menu).
/// </remarks>
public static void BeginNewLifetimeScope()
{
if (DependencyContainer == null)
{
throw new InvalidOperationException("You must install an Autofac container before initializing a new lifetime scope.");
}
CurrentLifetimeScope?.Dispose();
CurrentLifetimeScope = DependencyContainer.BeginLifetimeScope();
}
/// <summary>
/// Ends the life time scoped services that were registered using <see cref="IRegistrationBuilder{TLimit,TActivatorData,TRegistrationStyle}.InstancePerLifetimeScope" />.
/// </summary>
public static void EndCurrentLifetimeScope()
{
CurrentLifetimeScope?.Dispose();
OnLifetimeScopeEnded();
}
/// <summary>
/// Only locates the service in the container, pre-lifetime scope.
/// </summary>
public static T LocateServicePreLifetime<T>()
{
return DependencyContainer.Resolve<T>();
}
/// <summary>
/// Retrieves a service which was registered into the DI container. Creates a new instance if required.<br />
/// </summary>
/// <remarks>
/// This method should not be used if the constructor is available for defining a parameter where its type is the service to inject.
/// For Unity monobehaviours the constructor is used by Unity and cannot be used to inject services. In this case, use this method.
/// </remarks>
public static T LocateService<T>()
where T : class
{
CheckServiceResolutionViability();
return CurrentLifetimeScope.Resolve<T>();
}
/// <summary>
/// Non-generic alternative to <see cref="LocateService{T}" />.
/// </summary>
public static object LocateService(Type serviceType)
{
CheckServiceResolutionViability();
return CurrentLifetimeScope.Resolve(serviceType);
}
/// <summary>
/// Tries to locate the service if it exists. Can return an <see cref="Optional{T}" /> without a value.
/// </summary>
/// <typeparam name="T">Type of service to try to locate.</typeparam>
/// <returns>Optional that might or might not hold the service instance.</returns>
public static Optional<T> LocateOptionalService<T>() where T : class
{
CheckServiceResolutionViability();
return Optional.OfNullable(CurrentLifetimeScope.ResolveOptional<T>());
}
/// <summary>
/// Tries to locate the service if it exists. Can return an <see cref="Optional{T}" /> without a value.
/// </summary>
/// <param name="serviceType">Type of service to try to locate.</param>
/// <returns>Optional that might or might not hold the service instance.</returns>
public static Optional<object> LocateOptionalService(Type serviceType)
{
CheckServiceResolutionViability();
return Optional.OfNullable(CurrentLifetimeScope.ResolveOptional(serviceType));
}
/// <summary>
/// Throws if a service is asked for but without a proper life time scope.
/// </summary>
private static void CheckServiceResolutionViability()
{
if (DependencyContainer == null)
{
throw new InvalidOperationException("You must install an Autofac container before resolving dependencies.");
}
if (CurrentLifetimeScope == null)
{
throw new InvalidOperationException("You must begin a new lifetime scope before resolving dependencies.");
}
}
private static void OnLifetimeScopeEnded() => LifetimeScopeEnded?.Invoke(null, EventArgs.Empty);
/// <summary>
/// Generic static class to cache type with very fast lookups. Only use for singleton types.
/// </summary>
/// <typeparam name="T">Type in the cache, should be singleton.</typeparam>
public static class Cache<T> where T : class
{
private static T value;
public static T Value => value ??= LocateServiceAndRegister();
public static T ValuePreLifetime => value ??= LocateServicePreLifetimeAndRegister();
private static T LocateServiceAndRegister()
{
LifetimeScopeEnded += Invalidate;
return LocateService<T>();
}
private static T LocateServicePreLifetimeAndRegister()
{
LifetimeScopeEnded += Invalidate;
return LocateServicePreLifetime<T>();
}
/// <summary>
/// Invalidates the cache for type <see cref="T" />. The next <see cref="Value" /> access will request from <see cref="NitroxServiceLocator" /> again.
/// </summary>
private static void Invalidate(object _, EventArgs __)
{
value = null;
LifetimeScopeEnded -= Invalidate;
}
}
}

View File

@@ -0,0 +1,110 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace NitroxModel.DataStructures;
/// <summary>
/// Given a fixed size, fills to capacity and then overwrites earliest item.
/// </summary>
public class CircularBuffer<T> : IList<T>
{
private readonly List<T> data;
private readonly int maxSize;
/// <summary>
/// Returns the index last changed. If <see cref="CircularBuffer{T}" /> is empty, returns -1.
/// </summary>
public int LastChangedIndex { get; protected set; } = -1;
/// <summary>
/// Gets the item at the index, wrapping around the buffer if out-of-range.
/// </summary>
public T this[int index]
{
// Proper modulus operator which C# doesn't have. % = remainder operator and doesn't work in reverse for negative numbers.
get => data[Math.Abs((index % data.Count + data.Count) % data.Count)];
set => throw new NotSupportedException();
}
public int Count => data.Count;
public bool IsReadOnly => false;
public CircularBuffer(int maxSize, int initialCapacity = 0)
{
if (maxSize < 0) throw new ArgumentOutOfRangeException(nameof(maxSize), "Max size must be larger than -1");
this.maxSize = maxSize;
data = new List<T>(Math.Max(0, Math.Min(initialCapacity, maxSize)));
}
public int IndexOf(T item)
{
return data.IndexOf(item);
}
public void Insert(int index, T item)
{
throw new NotImplementedException();
}
public void RemoveAt(int index)
{
data.RemoveAt(index);
}
public bool Remove(T item)
{
return data.Remove(item);
}
public void Add(T item)
{
if (maxSize == 0) return;
if (data.Count < maxSize)
{
data.Add(item);
LastChangedIndex++;
return;
}
LastChangedIndex = (LastChangedIndex + 1) % maxSize;
data[LastChangedIndex] = item;
}
public void AddRange(IEnumerable<T> items)
{
foreach (T item in items) Add(item);
}
public void AddRange(params T[] items)
{
foreach (T item in items) Add(item);
}
public void Clear()
{
data.Clear();
LastChangedIndex = -1;
}
public bool Contains(T item)
{
return data.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
data.CopyTo(array, arrayIndex);
}
public IEnumerator<T> GetEnumerator()
{
return data.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}

View File

@@ -0,0 +1,144 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.Core;
using NitroxModel.DataStructures.Unity;
using NitroxModel.Helper;
namespace NitroxModel.DataStructures.GameLogic;
[Serializable]
[DataContract]
public class AbsoluteEntityCell
{
[DataMember(Order = 1)]
public NitroxInt3 BatchId { get; }
[DataMember(Order = 2)]
public NitroxInt3 CellId { get; }
[DataMember(Order = 3)]
public int Level { get; }
private static readonly Lazy<IMap> map = new(NitroxServiceLocator.LocateService<IMap>);
private NitroxInt3 BatchPosition => BatchId * map.Value.BatchSize - map.Value.BatchDimensionCenter;
public NitroxInt3 Position => BatchPosition + CellId * GetCellSize();
public NitroxInt3 Center
{
get
{
NitroxInt3 cellSize = GetCellSize();
return BatchPosition + CellId * cellSize + (cellSize >> 1);
}
}
[IgnoreConstructor]
protected AbsoluteEntityCell()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public AbsoluteEntityCell(NitroxInt3 batchId, NitroxInt3 cellId, int level)
{
BatchId = batchId;
CellId = cellId;
Level = level;
}
public AbsoluteEntityCell(NitroxVector3 worldSpace, int level)
{
Level = level;
NitroxVector3 localPosition = (worldSpace + map.Value.BatchDimensionCenter) / map.Value.BatchSize;
BatchId = NitroxInt3.Floor(localPosition);
NitroxVector3 cell = (localPosition - BatchId) * GetCellsPerBlock();
CellId = NitroxInt3.Floor(cell.X + 0.0001f, cell.Y + 0.0001f, cell.Z + 0.0001f);
}
public static bool operator ==(AbsoluteEntityCell left, AbsoluteEntityCell right)
{
return Equals(left, right);
}
public static bool operator !=(AbsoluteEntityCell left, AbsoluteEntityCell right)
{
return !Equals(left, right);
}
public static NitroxInt3 GetCellSize(int level, NitroxInt3 blocksPerBatch)
{
// Our own implementation for BatchCells.GetCellSize, that works on the server and client.
return blocksPerBatch / GetCellsPerBlock(level);
}
public static int GetCellsPerBlock(int level)
{
switch (level)
{
case 0:
return 10;
case 1:
case 2:
case 3:
return 5;
default:
throw new Exception($"Given level '{level}' does not have any defined cells.");
}
}
public override string ToString()
{
return $"[AbsoluteEntityCell Position: {Position} BatchId: {BatchId} CellId: {CellId} Level: {Level} ]";
}
public override bool Equals(object obj)
{
if (obj is null)
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((AbsoluteEntityCell)obj);
}
public override int GetHashCode()
{
unchecked
{
int hash = BatchId != default ? BatchId.GetHashCode() : 0;
hash = (hash * 397) ^ (CellId != default ? CellId.GetHashCode() : 0);
hash = (hash * 397) ^ Level;
return hash;
}
}
public NitroxInt3 GetCellSize()
{
return GetCellSize(map.Value.BatchDimensions);
}
public NitroxInt3 GetCellSize(NitroxInt3 blocksPerBatch)
{
return GetCellSize(Level, blocksPerBatch);
}
public int GetCellsPerBlock()
{
return GetCellsPerBlock(Level);
}
protected bool Equals(AbsoluteEntityCell other)
{
return Equals(BatchId, other.BatchId) && Equals(CellId, other.CellId) && Level == other.Level;
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic;
/// <summary>
/// Aurora events data
/// </summary>
[Serializable, DataContract]
public class AuroraEventData
{
/// <summary>
/// In-game time in seconds at which Aurora's countdown happens
/// </summary>
[DataMember(Order = 1)]
public float TimeToStartCountdown;
/// <summary>
/// In-game time in seconds at which Aurora's warning messages start
/// </summary>
[DataMember(Order = 2)]
public float TimeToStartWarning;
/// <summary>
/// Real time in seconds at which Aurora's considered exploded
/// </summary>
[DataMember(Order = 3)]
public float AuroraRealExplosionTime;
[IgnoreConstructor]
protected AuroraEventData()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public AuroraEventData(float timeToStartCountdown, float timeToStartWarning, float auroraRealExplosionTime)
{
TimeToStartCountdown = timeToStartCountdown;
TimeToStartWarning = timeToStartWarning;
AuroraRealExplosionTime = auroraRealExplosionTime;
}
[NonSerialized]
public static readonly IReadOnlyCollection<string> GoalNames = new[] { "Story_AuroraWarning1", "Story_AuroraWarning2", "Story_AuroraWarning3", "Story_AuroraWarning4", "Story_AuroraExplosion" };
}

View File

@@ -0,0 +1,84 @@
using System;
using System.Linq;
using System.Runtime.Serialization;
namespace NitroxModel.DataStructures.GameLogic.Bases;
[DataContract]
public class BaseData : IEquatable<BaseData>
{
[DataMember(Order = 1)]
public NitroxInt3 BaseShape;
[DataMember(Order = 2)]
public NitroxInt3 CellOffset;
[DataMember(Order = 3)]
public NitroxInt3 Anchor;
[DataMember(Order = 4)]
public int PreCompressionSize;
[DataMember(Order = 5)]
public byte[] Faces;
[DataMember(Order = 6)]
public byte[] Cells;
[DataMember(Order = 7)]
public byte[] Links;
[DataMember(Order = 8)]
public byte[] Masks;
[DataMember(Order = 9)]
public byte[] IsGlass;
public bool Equals(BaseData other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return BaseShape.Equals(other.BaseShape) &&
CellOffset.Equals(other.CellOffset) &&
Anchor.Equals(other.Anchor) &&
PreCompressionSize == other.PreCompressionSize &&
Faces.SequenceEqual(other.Faces) &&
Cells.SequenceEqual(other.Cells) &&
Links.SequenceEqual(other.Links) &&
Masks.SequenceEqualOrBothNull(other.Masks) &&
IsGlass.SequenceEqual(other.IsGlass);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((BaseData)obj);
}
public override int GetHashCode()
{
unchecked
{
int hashCode = BaseShape.GetHashCode();
hashCode = (hashCode * 397) ^ CellOffset.GetHashCode();
hashCode = (hashCode * 397) ^ Anchor.GetHashCode();
hashCode = (hashCode * 397) ^ PreCompressionSize;
hashCode = (hashCode * 397) ^ (Faces != null ? Faces.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Cells != null ? Cells.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Links != null ? Links.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Masks != null ? Masks.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (IsGlass != null ? IsGlass.GetHashCode() : 0);
return hashCode;
}
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Runtime.Serialization;
namespace NitroxModel.DataStructures.GameLogic.Bases;
[Serializable, DataContract]
public record struct BuildPieceIdentifier(NitroxTechType Recipe, NitroxBaseFace? BaseFace, NitroxInt3 BaseCell, NitroxInt3 PiecePoint)
{
[DataMember(Order = 1)]
public NitroxTechType Recipe = Recipe;
[DataMember(Order = 2)]
public NitroxBaseFace? BaseFace = BaseFace;
[DataMember(Order = 3)]
public NitroxInt3 BaseCell = BaseCell;
[DataMember(Order = 4)]
public NitroxInt3 PiecePoint = PiecePoint;
public override readonly string ToString()
{
return $"BuildPieceIdentifier (Recipe: {Recipe}, BaseFace: {BaseFace}, BaseCell: {BaseCell}, PiecePoint: {PiecePoint})";
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Runtime.Serialization;
namespace NitroxModel.DataStructures.GameLogic.Bases;
[Serializable, DataContract]
public record struct NitroxBaseFace(NitroxInt3 Cell, int Direction)
{
[DataMember(Order = 1)]
public NitroxInt3 Cell = Cell;
[DataMember(Order = 2)]
public int Direction = Direction;
public override readonly string ToString()
{
return $"NitroxBaseFace ({Cell}) {Direction}";
}
}

View File

@@ -0,0 +1,21 @@
using System;
using NitroxModel.DataStructures.Unity;
using NitroxModel.DataStructures.Util;
namespace NitroxModel.DataStructures.GameLogic
{
[Serializable]
public class DamageTakenData
{
public NitroxVector3 Position { get; set; }
public ushort DamageType { get; set; }
public Optional<NitroxId> DealerId { get; set; }
public override string ToString()
{
return $"DamageTakenData: Position: {Position}, DamageType: {DamageType}, DealerId: {DealerId}";
}
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
namespace NitroxModel.DataStructures.GameLogic.Entities.Bases;
[Serializable, DataContract]
public class BaseLeakEntity : Entity
{
[DataMember(Order = 1)]
public float Health { get; set; }
[DataMember(Order = 2)]
public NitroxInt3 RelativeCell { get; set; }
[IgnoreConstructor]
protected BaseLeakEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public BaseLeakEntity(float health, NitroxInt3 relativeCell, NitroxId leakId, NitroxId parentId)
{
Health = health;
RelativeCell = relativeCell;
Id = leakId;
ParentId = parentId;
}
/// <remarks>Used for deserialization</remarks>
public BaseLeakEntity(float health, NitroxInt3 relativeCell, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities)
{
Health = health;
RelativeCell = relativeCell;
Id = id;
TechType = techType;
Metadata = metadata;
ParentId = parentId;
ChildEntities = childEntities;
}
public override string ToString()
{
return $"[BaseLeakEntity Health: {Health}, RelativeCell: {RelativeCell}]";
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Bases;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities.Bases;
[Serializable, DataContract]
public class BuildEntity : GlobalRootEntity
{
[DataMember(Order = 1)]
public BaseData BaseData { get; set; }
[IgnoredMember]
public int OperationId;
[IgnoreConstructor]
protected BuildEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public static BuildEntity MakeEmpty()
{
return new BuildEntity();
}
/// <remarks>
/// Used for deserialization.
/// <see cref="WorldEntity.SpawnedByServer"/> is set to true because this entity is meant to receive simulation locks
/// </remarks>
public BuildEntity(BaseData baseData, NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, true, id, techType, metadata, parentId, childEntities)
{
BaseData = baseData;
}
public override string ToString()
{
return $"[BuildEntity Id: {Id}]";
}
}

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Bases;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities.Bases;
[Serializable, DataContract]
public class GhostEntity : ModuleEntity
{
[DataMember(Order = 1)]
public NitroxBaseFace BaseFace { get; set; }
[DataMember(Order = 2)]
public BaseData BaseData { get; set; }
[IgnoreConstructor]
protected GhostEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public new static GhostEntity MakeEmpty()
{
return new GhostEntity();
}
/// <remarks>Used for deserialization</remarks>
public GhostEntity(NitroxBaseFace baseFace, BaseData baseData, float constructedAmount, bool isInside, NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(constructedAmount, isInside, transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
BaseFace = baseFace;
BaseData = baseData;
}
public override string ToString()
{
return $"[GhostEntity Id: {Id}, ParentId: {ParentId}, ClassId: {ClassId}, Metadata: {Metadata}, ConstructedAmount: {ConstructedAmount}, IsInside: {IsInside}, BaseFace: [{BaseFace}], BaseData: {BaseData}]";
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Bases;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities.Bases;
[Serializable, DataContract]
public class InteriorPieceEntity : GlobalRootEntity
{
[DataMember(Order = 1)]
public NitroxBaseFace BaseFace;
[IgnoreDataMember]
public bool IsWaterPark => ClassId is "31662630-7cba-4583-8456-2fa1c4cc31aa" or "c2a91864-0f0f-4d8a-99b8-9867571763dd"; // classIds for WaterPark.prefab and WaterParkLarge.prefab
[IgnoreConstructor]
protected InteriorPieceEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public static InteriorPieceEntity MakeEmpty()
{
return new InteriorPieceEntity();
}
/// <remarks>
/// Used for deserialization.
/// <see cref="WorldEntity.SpawnedByServer"/> is set to true because this entity is meant to receive simulation locks
/// </remarks>
public InteriorPieceEntity(NitroxBaseFace baseFace, NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, true, id, techType, metadata, parentId, childEntities)
{
BaseFace = baseFace;
}
public override string ToString()
{
return $"[InteriorPieceEntity Id: {Id}, ParentId: {ParentId}, BaseFace: {BaseFace}, {base.ToString()}]";
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities.Bases;
[Serializable, DataContract]
public class MapRoomEntity : GlobalRootEntity
{
[DataMember(Order = 1)]
public NitroxInt3 Cell { get; set; }
[IgnoreConstructor]
protected MapRoomEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public MapRoomEntity(NitroxId id, NitroxId parentId, NitroxInt3 cell)
{
Id = id;
ParentId = parentId;
Cell = cell;
Transform = new();
}
/// <remarks>
/// Used for deserialization.
/// <see cref="WorldEntity.SpawnedByServer"/> is set to true because this entity is meant to receive simulation locks
/// </remarks>
public MapRoomEntity(NitroxInt3 cell, NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, true, id, techType, metadata, parentId, childEntities)
{
Cell = cell;
}
public override string ToString()
{
return $"[MapRoomEntity Id: {Id}, Cell: {Cell}]";
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
using ProtoBufNet;
namespace NitroxModel.DataStructures.GameLogic.Entities.Bases;
[Serializable, DataContract]
[ProtoInclude(50, typeof(GhostEntity))]
public class ModuleEntity : GlobalRootEntity
{
[DataMember(Order = 1)]
public float ConstructedAmount { get; set; }
[DataMember(Order = 2)]
public bool IsInside { get; set; }
[IgnoreConstructor]
protected ModuleEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public static ModuleEntity MakeEmpty()
{
return new ModuleEntity();
}
/// <remarks>
/// Used for deserialization.
/// <see cref="WorldEntity.SpawnedByServer"/> is set to true because this entity is meant to receive simulation locks
/// </remarks>
public ModuleEntity(float constructedAmount, bool isInside, NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, true, id, techType, metadata, parentId, childEntities)
{
ConstructedAmount = constructedAmount;
IsInside = isInside;
}
public override string ToString()
{
return $"[ModuleEntity Id: {Id}, ParentId: {ParentId}, ClassId: {ClassId}, ConstructedAmount: {ConstructedAmount}, IsInside: {IsInside}]";
}
}

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities.Bases;
[Serializable, DataContract]
public class MoonpoolEntity : GlobalRootEntity
{
[DataMember(Order = 1)]
public NitroxInt3 Cell { get; set; }
[IgnoreConstructor]
protected MoonpoolEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public MoonpoolEntity(NitroxId id, NitroxId parentId, NitroxInt3 cell)
{
Id = id;
ParentId = parentId;
Cell = cell;
}
/// <remarks>
/// Used for deserialization.
/// <see cref="WorldEntity.SpawnedByServer"/> is set to true because this entity is meant to receive simulation locks
/// </remarks>
public MoonpoolEntity(NitroxInt3 cell, NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, true, id, techType, metadata, parentId, childEntities)
{
Cell = cell;
}
public override string ToString()
{
return $"[MoonpoolEntity Id: {Id}, Cell: {Cell}]";
}
}

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable]
[DataContract]
public class CellRootEntity : WorldEntity
{
public static readonly string CLASS_ID = "55d7ab35-de97-4d95-af6c-ac8d03bb54ca";
[IgnoreConstructor]
protected CellRootEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public CellRootEntity(NitroxVector3 localPosition, NitroxQuaternion localRotation, NitroxVector3 scale, NitroxTechType techType, int level, string classId, bool spawnedByServer, NitroxId id)
{
Transform = new NitroxTransform(localPosition, localRotation, scale);
TechType = techType;
Id = id;
Level = level;
ClassId = classId;
SpawnedByServer = spawnedByServer;
}
/// <remarks>Used for deserialization</remarks>
public CellRootEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities)
{
Id = id;
TechType = techType;
Metadata = metadata;
ParentId = parentId;
Transform = transform;
ChildEntities = childEntities;
Level = level;
ClassId = classId;
SpawnedByServer = spawnedByServer;
}
public override string ToString()
{
return $"[CellRootEntity {base.ToString()}]";
}
}

View File

@@ -0,0 +1,41 @@
using System;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using System.Collections.Generic;
using BinaryPack.Attributes;
using System.Runtime.Serialization;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable, DataContract]
public class CreatureRespawnEntity : WorldEntity
{
[DataMember(Order = 1)]
public float SpawnTime { get; set; }
[DataMember(Order = 2)]
public NitroxTechType RespawnTechType { get; set; }
[DataMember(Order = 3)]
public List<string> AddComponents { get; set; } = [];
[IgnoreConstructor]
protected CreatureRespawnEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
/// <remarks>Used for deserialization</remarks>
public CreatureRespawnEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities, float spawnTime, NitroxTechType respawnTechType, List<string> addComponents) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
SpawnTime = spawnTime;
RespawnTechType = respawnTechType;
AddComponents = addComponents;
}
public override string ToString()
{
return $"[{nameof(CreatureRespawnEntity)} SpawnTime: {SpawnTime}, RespawnTechType: {RespawnTechType}, AddComponents: [{string.Join(", ", AddComponents)}] {base.ToString()}]";
}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable]
[DataContract]
public class EscapePodWorldEntity : GlobalRootEntity
{
[DataMember(Order = 1)]
public List<ushort> Players { get; set; } = [];
[IgnoreConstructor]
protected EscapePodWorldEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public EscapePodWorldEntity(NitroxVector3 position, NitroxId id, EntityMetadata metadata)
{
Transform = new NitroxTransform(position, NitroxQuaternion.Identity, NitroxVector3.One);
Id = id;
Metadata = metadata;
Players = [];
Level = 0;
TechType = new NitroxTechType("EscapePod");
SpawnedByServer = true;
ChildEntities = [];
}
/// <remarks>Used for deserialization</remarks>
public EscapePodWorldEntity(List<ushort> players, NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
Players = players;
}
public override string ToString()
{
return $"[EscapePodWorldEntity Players: [{string.Join(", ", Players)}] {base.ToString()}]";
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable, DataContract]
public class GeyserWorldEntity : WorldEntity
{
[DataMember(Order = 1)]
public float RandomIntervalVarianceMultiplier { get; set; }
[DataMember(Order = 2)]
public float StartEruptTime { get; set; }
[IgnoreConstructor]
protected GeyserWorldEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
/// <remarks>Used for deserialization</remarks>
public GeyserWorldEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities, float randomIntervalVarianceMultiplier, float startEruptTime) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
RandomIntervalVarianceMultiplier = randomIntervalVarianceMultiplier;
StartEruptTime = startEruptTime;
}
public override string ToString()
{
return $"[{nameof(GeyserWorldEntity)} RandomIntervalVarianceMultiplier: {RandomIntervalVarianceMultiplier}, StartEruptTime: {StartEruptTime} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Bases;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
using ProtoBufNet;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable, DataContract]
[ProtoInclude(50, typeof(BuildEntity))]
[ProtoInclude(51, typeof(EscapePodWorldEntity))]
[ProtoInclude(52, typeof(InteriorPieceEntity))]
[ProtoInclude(53, typeof(MapRoomEntity))]
[ProtoInclude(54, typeof(ModuleEntity))]
[ProtoInclude(55, typeof(MoonpoolEntity))]
[ProtoInclude(56, typeof(PlanterEntity))]
[ProtoInclude(57, typeof(PlayerWorldEntity))]
[ProtoInclude(58, typeof(VehicleWorldEntity))]
[ProtoInclude(59, typeof(RadiationLeakEntity))]
public class GlobalRootEntity : WorldEntity
{
[IgnoreConstructor]
protected GlobalRootEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
/// <remarks>Used for deserialization</remarks>
public GlobalRootEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{ }
}

View File

@@ -0,0 +1,8 @@
using System.Collections.Generic;
namespace NitroxModel.DataStructures.GameLogic.Entities;
public interface IUwePrefabFactory
{
public bool TryGetPossiblePrefabs(string biomeType, out List<UwePrefab> prefabs);
}

View File

@@ -0,0 +1,6 @@
namespace NitroxModel.DataStructures.GameLogic.Entities;
public interface IUweWorldEntityFactory
{
public bool TryFind(string classId, out UweWorldEntity uweWorldEntity);
}

View File

@@ -0,0 +1,33 @@
using System;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable]
[DataContract]
public class InstalledBatteryEntity : Entity
{
[IgnoreConstructor]
protected InstalledBatteryEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
/// <remarks>Used for deserialization</remarks>
public InstalledBatteryEntity(NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities)
{
Id = id;
TechType = techType;
Metadata = metadata;
ParentId = parentId;
ChildEntities = childEntities;
}
public override string ToString()
{
return $"[InstalledBatteryEntity {base.ToString()}]";
}
}

View File

@@ -0,0 +1,41 @@
using System;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using System.Collections.Generic;
using BinaryPack.Attributes;
using System.Runtime.Serialization;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable]
[DataContract]
public class InstalledModuleEntity : Entity
{
[DataMember(Order = 1)]
public string Slot { get; set; }
[DataMember(Order = 2)]
public string ClassId { get; set; }
[IgnoreConstructor]
protected InstalledModuleEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
/// <remarks>Used for deserialization</remarks>
public InstalledModuleEntity(string slot, string classId, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities)
{
Slot = slot;
ClassId = classId;
Id = id;
TechType = techType;
Metadata = metadata;
ParentId = parentId;
ChildEntities = childEntities;
}
public override string ToString()
{
return $"[InstalledModuleEntity Slot: {Slot} ClassId: {ClassId} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,40 @@
using System;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using System.Collections.Generic;
using BinaryPack.Attributes;
using System.Runtime.Serialization;
namespace NitroxModel.DataStructures.GameLogic.Entities;
/// <summary>
/// Represents an object that can hold InventoryItemEntity, such as the locker in the escape pod.
/// </summary>
[Serializable]
[DataContract]
public class InventoryEntity : Entity
{
[DataMember(Order = 1)]
public int ComponentIndex { get; set; }
[IgnoreConstructor]
protected InventoryEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
/// <remarks>Used for deserialization</remarks>
public InventoryEntity(int componentIndex, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities)
{
ComponentIndex = componentIndex;
Id = id;
TechType = techType;
Metadata = metadata;
ParentId = parentId;
ChildEntities = childEntities;
}
public override string ToString()
{
return $"[InventoryEntity {base.ToString()}]";
}
}

View File

@@ -0,0 +1,37 @@
using System;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using System.Collections.Generic;
using BinaryPack.Attributes;
using System.Runtime.Serialization;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable]
[DataContract]
public class InventoryItemEntity : Entity
{
[DataMember(Order = 1)]
public string ClassId { get; set; }
[IgnoreConstructor]
protected InventoryItemEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
/// <remarks>Used for deserialization</remarks>
public InventoryItemEntity(NitroxId id, string classId, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities)
{
ClassId = classId;
Id = id;
TechType = techType;
Metadata = metadata;
ParentId = parentId;
ChildEntities = childEntities;
}
public override string ToString()
{
return $"[InventoryItemEntity ClassId: {ClassId} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata.Bases;
[Serializable, DataContract]
public class BaseAnchoredCellGhostMetadata : GhostMetadata
{
[DataMember(Order = 1)]
public NitroxInt3? AnchoredCell { get; set; }
[IgnoreConstructor]
public BaseAnchoredCellGhostMetadata()
{
// Constructor for ProtoBuf deserialization.
}
/// <remarks>Used for json deserialization</remarks>
public BaseAnchoredCellGhostMetadata(NitroxInt3? anchoredCell, NitroxInt3 targetOffset) : base(targetOffset)
{
AnchoredCell = anchoredCell;
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Bases;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata.Bases;
[Serializable, DataContract]
public class BaseAnchoredFaceGhostMetadata : GhostMetadata
{
[DataMember(Order = 1)]
public NitroxBaseFace? AnchoredFace { get; set; }
[IgnoreConstructor]
public BaseAnchoredFaceGhostMetadata()
{
// Constructor for ProtoBuf deserialization.
}
/// <remarks>Used for json deserialization</remarks>
public BaseAnchoredFaceGhostMetadata(NitroxBaseFace? anchoredFace, NitroxInt3 targetOffset) : base(targetOffset)
{
AnchoredFace = anchoredFace;
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Bases;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata.Bases;
[Serializable, DataContract]
public class BaseDeconstructableGhostMetadata : GhostMetadata
{
[DataMember(Order = 1)]
public NitroxBaseFace? ModuleFace { get; set; }
[DataMember(Order = 2)]
public string ClassId { get; set; }
[IgnoreConstructor]
public BaseDeconstructableGhostMetadata()
{
// Constructor for ProtoBuf deserialization.
}
/// <remarks>Used for json deserialization</remarks>
public BaseDeconstructableGhostMetadata(NitroxBaseFace? moduleFace, string classId, NitroxInt3 targetOffset) : base(targetOffset)
{
ModuleFace = moduleFace;
ClassId = classId;
}
public override string ToString()
{
return $"[BaseDeconstructableGhostMetadata TargetOffset: {TargetOffset}, ModuleFace: {ModuleFace}, ClassId: {ClassId}]";
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using ProtoBufNet;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata.Bases;
[Serializable, DataContract]
[ProtoInclude(50, typeof(BaseDeconstructableGhostMetadata))]
[ProtoInclude(51, typeof(BaseAnchoredFaceGhostMetadata))]
[ProtoInclude(52, typeof(BaseAnchoredCellGhostMetadata))]
public class GhostMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public NitroxInt3 TargetOffset { get; set; }
[IgnoreConstructor]
public GhostMetadata()
{
// Constructor for ProtoBuf deserialization.
}
/// <remarks>Used for json deserialization</remarks>
public GhostMetadata(NitroxInt3 targetOffset)
{
TargetOffset = targetOffset;
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class BatteryMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public float Charge { get; }
[IgnoreConstructor]
protected BatteryMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public BatteryMetadata(float charge)
{
Charge = charge;
}
public override string ToString()
{
return $"[BatteryMetadata Charge: {Charge}]";
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class BeaconMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public string Label { get; }
[IgnoreConstructor]
protected BeaconMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public BeaconMetadata(string label)
{
Label = label;
}
public override string ToString()
{
return $"[BeaconMetadata Label: {Label}]";
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class ConstructorMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool Deployed { get; }
[IgnoreConstructor]
protected ConstructorMetadata()
{
//Constructor for serialization. Has to be "protected" for json serialization.
}
public ConstructorMetadata(bool deployed)
{
Deployed = deployed;
}
public override string ToString()
{
return $"[ConstructorMetadata Deployed: {Deployed}]";
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class CrafterMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public NitroxTechType TechType { get; }
[DataMember(Order = 2)]
public float StartTime { get; }
[DataMember(Order = 3)]
public float Duration { get; }
[IgnoreConstructor]
protected CrafterMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public CrafterMetadata(NitroxTechType techType, float startTime, float duration)
{
TechType = techType;
StartTime = startTime;
Duration = duration;
}
public override string ToString()
{
return $"[CrafterMetadata TechType: {TechType} StartTime: {StartTime} Duration: {Duration} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable, DataContract]
public class CrashHomeMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public float SpawnTime { get; }
[IgnoreConstructor]
protected CrashHomeMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public CrashHomeMetadata(float spawnTime)
{
SpawnTime = spawnTime;
}
public override string ToString()
{
return $"[CrashHomeMetadata SpawnTime: {SpawnTime}]";
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class CyclopsLightingMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool FloodLightsOn { get; set; }
[DataMember(Order = 2)]
public bool InternalLightsOn { get; set; }
[IgnoreConstructor]
protected CyclopsLightingMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public CyclopsLightingMetadata(bool floodLightsOn, bool internalLightsOn)
{
FloodLightsOn = floodLightsOn;
InternalLightsOn = internalLightsOn;
}
public override string ToString()
{
return $"[CyclopsLightningMetadata FloodLightsOn: {FloodLightsOn}, InternalLightsOn: {InternalLightsOn}]";
}
}

View File

@@ -0,0 +1,53 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class CyclopsMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool SilentRunningOn { get; set; }
[DataMember(Order = 2)]
public bool ShieldOn { get; set; }
[DataMember(Order = 3)]
public bool SonarOn { get; set; }
[DataMember(Order = 4)]
public bool EngineOn { get; set; }
[DataMember(Order = 5)]
public int EngineMode { get; set; }
[DataMember(Order = 6)]
public float Health { get; set; }
[DataMember(Order = 7)]
public bool IsDestroyed { get; set; }
[IgnoreConstructor]
protected CyclopsMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public CyclopsMetadata(bool silentRunningOn, bool shieldOn, bool sonarOn, bool engineOn, int engineMode, float health, bool isDestroyed)
{
SilentRunningOn = silentRunningOn;
ShieldOn = shieldOn;
SonarOn = sonarOn;
EngineOn = engineOn;
EngineMode = engineMode;
Health = health;
IsDestroyed = isDestroyed;
}
public override string ToString()
{
return $"[CyclopsMetadata SilentRunningOn: {SilentRunningOn}, ShieldOn: {ShieldOn}, SonarOn: {SonarOn}, EngineOn: {EngineOn}, EngineMode: {EngineMode}, Health: {Health}, IsDestroyed: {IsDestroyed}]";
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class EatableMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public float TimeDecayStart { get; }
[IgnoreConstructor]
protected EatableMetadata()
{
//Constructor for serialization. Has to be "protected" for json serialization.
}
public EatableMetadata(float timeDecayStart)
{
TimeDecayStart = timeDecayStart;
}
public override string ToString()
{
return $"[{nameof(EatableMetadata)} TimeDecayStart: {TimeDecayStart}]";
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class EggMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public float TimeStartHatching { get; }
[DataMember(Order = 2)]
public float Progress { get; }
[IgnoreConstructor]
protected EggMetadata()
{
//Constructor for serialization. Has to be "protected" for json serialization.
}
public EggMetadata(float timeStartHatching, float progress)
{
TimeStartHatching = timeStartHatching;
Progress = progress;
}
public override string ToString()
{
return $"[{nameof(EggMetadata)} TimeStartHatching: {TimeStartHatching}, Progress: {Progress}]";
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Runtime.Serialization;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata.Bases;
using ProtoBufNet;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
{
[Serializable]
[DataContract]
[ProtoInclude(50, typeof(KeypadMetadata))]
[ProtoInclude(51, typeof(SealedDoorMetadata))]
[ProtoInclude(52, typeof(PrecursorDoorwayMetadata))]
[ProtoInclude(53, typeof(PrecursorTeleporterMetadata))]
[ProtoInclude(54, typeof(PrecursorKeyTerminalMetadata))]
[ProtoInclude(55, typeof(PrecursorTeleporterActivationTerminalMetadata))]
[ProtoInclude(56, typeof(StarshipDoorMetadata))]
[ProtoInclude(57, typeof(WeldableWallPanelGenericMetadata))]
[ProtoInclude(58, typeof(IncubatorMetadata))]
[ProtoInclude(59, typeof(EntitySignMetadata))]
[ProtoInclude(60, typeof(ConstructorMetadata))]
[ProtoInclude(61, typeof(FlashlightMetadata))]
[ProtoInclude(62, typeof(BatteryMetadata))]
[ProtoInclude(63, typeof(EscapePodMetadata))]
[ProtoInclude(64, typeof(CrafterMetadata))]
[ProtoInclude(65, typeof(PlantableMetadata))]
[ProtoInclude(66, typeof(CyclopsMetadata))]
[ProtoInclude(67, typeof(RocketMetadata))]
[ProtoInclude(68, typeof(CyclopsLightingMetadata))]
[ProtoInclude(69, typeof(FireExtinguisherHolderMetadata))]
[ProtoInclude(70, typeof(PlayerMetadata))]
[ProtoInclude(71, typeof(GhostMetadata))]
[ProtoInclude(72, typeof(WaterParkCreatureMetadata))]
[ProtoInclude(73, typeof(NamedColoredMetadata))]
[ProtoInclude(74, typeof(BeaconMetadata))]
[ProtoInclude(75, typeof(FlareMetadata))]
[ProtoInclude(76, typeof(RadiationMetadata))]
[ProtoInclude(77, typeof(CrashHomeMetadata))]
[ProtoInclude(78, typeof(EatableMetadata))]
[ProtoInclude(79, typeof(SeaTreaderMetadata))]
[ProtoInclude(80, typeof(StayAtLeashPositionMetadata))]
[ProtoInclude(81, typeof(EggMetadata))]
[ProtoInclude(82, typeof(PlantableMetadata))]
[ProtoInclude(83, typeof(FruitPlantMetadata))]
public abstract class EntityMetadata
{
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class EntitySignMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public string Text { get; }
[DataMember(Order = 2)]
public int ColorIndex { get; }
[DataMember(Order = 3)]
public int ScaleIndex { get; }
[DataMember(Order = 4)]
public bool[] Elements { get; } = [];
[DataMember(Order = 5)]
public bool Background { get; }
[IgnoreConstructor]
protected EntitySignMetadata()
{
//Constructor for serialization. Has to be "protected" for json serialization.
}
public EntitySignMetadata(string text, int colorIndex, int scaleIndex, bool[] elements, bool background)
{
Text = text;
ColorIndex = colorIndex;
ScaleIndex = scaleIndex;
Elements = elements;
Background = background;
}
public override string ToString()
{
return $"[EntitySignMetadata - Text: {Text}, ColorIndex: {ColorIndex}, ScaleIndex: {ScaleIndex}, Elements: {Elements}, Background: {Background}]";
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class EscapePodMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool PodRepaired { get; }
[DataMember(Order = 2)]
public bool RadioRepaired { get; }
[IgnoreConstructor]
protected EscapePodMetadata()
{
//Constructor for serialization. Has to be "protected" for json serialization.
}
public EscapePodMetadata(bool podRepaired, bool radioRepaired)
{
PodRepaired = podRepaired;
RadioRepaired = radioRepaired;
}
public override string ToString()
{
return $"[{nameof(EscapePodMetadata)} - PodRepaired: {PodRepaired}, RadioRepaired: {RadioRepaired}]";
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable, DataContract]
public class ExosuitMetadata : VehicleMetadata
{
[IgnoreConstructor]
protected ExosuitMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public ExosuitMetadata(float health, string name, NitroxVector3[] colors) : base(health, name, colors)
{ }
public override string ToString()
{
return $"[{nameof(ExosuitMetadata)} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class FireExtinguisherHolderMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool HasExtinguisher { get; }
[DataMember(Order = 2)]
public float Fuel { get; }
[IgnoreConstructor]
protected FireExtinguisherHolderMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public FireExtinguisherHolderMetadata(bool hasExtinguisher, float fuel)
{
HasExtinguisher = hasExtinguisher;
Fuel = fuel;
}
public override string ToString()
{
return $"[FireExtinguisherHolderMetadata HasExtinguisher: {HasExtinguisher}, Fuel: {Fuel}]";
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable, DataContract]
public class FlareMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public float EnergyLeft { get; }
[DataMember(Order = 2)]
public bool HasBeenThrown { get; }
[DataMember(Order = 3)]
public float? FlareActivateTime { get; }
[IgnoreConstructor]
protected FlareMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public FlareMetadata(float energyLeft, bool hasBeenThrown, float? flareActivateTime)
{
EnergyLeft = energyLeft;
HasBeenThrown = hasBeenThrown;
FlareActivateTime = flareActivateTime;
}
public override string ToString()
{
return $"[FlareMetadata EnergyLeft: {EnergyLeft}, HasBeenThrown: {HasBeenThrown}, FlareActivateTime: {FlareActivateTime}]";
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class FlashlightMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool On { get; }
[IgnoreConstructor]
protected FlashlightMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public FlashlightMetadata(bool on)
{
On = on;
}
public override string ToString()
{
return $"[FlashlightMetadata On: {On}]";
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class FruitPlantMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool[] PickedStates { get; } = [];
[DataMember(Order = 2)]
public float TimeNextFruit { get; }
[IgnoreConstructor]
protected FruitPlantMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public FruitPlantMetadata(bool[] pickedStates, float timeNextFruit)
{
PickedStates = pickedStates;
TimeNextFruit = timeNextFruit;
}
public override string ToString()
{
return $"[{nameof(FruitPlantMetadata)} PickedStates: [{string.Join(", ", PickedStates)}], TimeNextFruit: {TimeNextFruit}]";
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
{
[Serializable]
[DataContract]
public class IncubatorMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool Powered { get; }
[DataMember(Order = 2)]
public bool Hatched { get; }
[IgnoreConstructor]
protected IncubatorMetadata()
{
//Constructor for serialization. Has to be "protected" for json serialization.
}
public IncubatorMetadata(bool powered, bool hatched)
{
Powered = powered;
Hatched = hatched;
}
public override string ToString()
{
return $"[IncubatorMetadata Powered: {Powered} Hatched: {Hatched}]";
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
{
[Serializable]
[DataContract]
public class KeypadMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool Unlocked { get; }
[IgnoreConstructor]
protected KeypadMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public KeypadMetadata(bool unlocked)
{
Unlocked = unlocked;
}
public override string ToString()
{
return $"[KeypadMetadata isOpen: {Unlocked}]";
}
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.Unity;
using ProtoBufNet;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable, DataContract]
[ProtoInclude(50, typeof(VehicleMetadata))]
[ProtoInclude(51, typeof(SubNameInputMetadata))]
public abstract class NamedColoredMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public string Name { get; init; }
[DataMember(Order = 2)]
public NitroxVector3[] Colors { get; init; } = [];
[IgnoreConstructor]
protected NamedColoredMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public NamedColoredMetadata(string name, NitroxVector3[] colors) : base()
{
Name = name;
Colors = colors;
}
public override string ToString()
{
return $"[{nameof(NamedColoredMetadata)} Name: {Name}, Colors: {string.Join(";", Colors)} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,44 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class PlantableMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public float TimeStartGrowth { get; set; }
[DataMember(Order = 2)]
public int SlotID { get; set; }
// TODO: When the metadata system is reworked and we can have multiple metadatas on one entity, this won't be required anymore
[DataMember(Order = 3)]
public FruitPlantMetadata FruitPlantMetadata { get; set; }
[IgnoreConstructor]
protected PlantableMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public PlantableMetadata(float timeStartGrowth, int slotID)
{
TimeStartGrowth = timeStartGrowth;
SlotID = slotID;
}
public PlantableMetadata(float timeStartGrowth, int slotID, FruitPlantMetadata fruitPlantMetadata)
{
TimeStartGrowth = timeStartGrowth;
SlotID = slotID;
FruitPlantMetadata = fruitPlantMetadata;
}
public override string ToString()
{
return $"[{nameof(PlantableMetadata)} TimeStartGrowth: {TimeStartGrowth}, SlotID: {SlotID}, FruitPlantMetadata: {FruitPlantMetadata}]";
}
}

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class PlayerMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public List<EquippedItem> EquippedItems { get; }
[IgnoreConstructor]
protected PlayerMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public PlayerMetadata(List<EquippedItem> equippedItems)
{
EquippedItems = equippedItems;
}
public override string ToString()
{
return $"[PlayerMetadata EquippedItems: {string.Join(",", EquippedItems)}]";
}
[Serializable]
[DataContract]
public class EquippedItem
{
[DataMember(Order = 1)]
public NitroxId Id { get; }
[DataMember(Order = 2)]
public string Slot { get; }
[DataMember(Order = 3)]
public NitroxTechType TechType { get; }
[IgnoreConstructor]
protected EquippedItem()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public EquippedItem(NitroxId id, string slot, NitroxTechType techType)
{
Id = id;
Slot = slot;
TechType = techType;
}
public override string ToString()
{
return $"[EquippedItem Id: {Id} Slot: {Slot} TechType: {TechType}]";
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
{
[Serializable]
[DataContract]
public class PrecursorDoorwayMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool IsOpen { get; }
[IgnoreConstructor]
protected PrecursorDoorwayMetadata()
{
//Constructor for serialization. Has to be "protected" for json serialization.
}
public PrecursorDoorwayMetadata(bool isOpen)
{
IsOpen = isOpen;
}
public override string ToString()
{
return $"[PrecursorDoorwayMetadata isOpen: {IsOpen}]";
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
{
[Serializable]
[DataContract]
public class PrecursorKeyTerminalMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool Slotted { get; }
[IgnoreConstructor]
protected PrecursorKeyTerminalMetadata()
{
//Constructor for serialization. Has to be "protected" for json serialization.
}
public PrecursorKeyTerminalMetadata(bool slotted)
{
Slotted = slotted;
}
public override string ToString()
{
return $"[PrecursorKeyTerminalMetadata Slotted: {Slotted}]";
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
{
[Serializable]
[DataContract]
public class PrecursorTeleporterActivationTerminalMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool Unlocked { get; }
[IgnoreConstructor]
protected PrecursorTeleporterActivationTerminalMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public PrecursorTeleporterActivationTerminalMetadata(bool unlocked)
{
Unlocked = unlocked;
}
public override string ToString()
{
return $"[PrecursorTeleporterActivationTerminalMetadata Unlocked: {Unlocked}]";
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
{
[Serializable]
[DataContract]
public class PrecursorTeleporterMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool IsOpen { get; }
[IgnoreConstructor]
protected PrecursorTeleporterMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public PrecursorTeleporterMetadata(bool isOpen)
{
IsOpen = isOpen;
}
public override string ToString()
{
return $"[PrecursorTeleporterMetadata isOpen: {IsOpen}]";
}
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable, DataContract]
public class RadiationMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public float Health { get; set; }
[DataMember(Order = 2)]
public float FixRealTime { get; set; }
[IgnoreConstructor]
protected RadiationMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public RadiationMetadata(float health, float fixRealTime = -1)
{
Health = health;
FixRealTime = fixRealTime;
}
public override string ToString()
{
return $"[{nameof(RadiationMetadata)} Health: {Health}, FixRealTime: {FixRealTime}]";
}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class RocketMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public int CurrentStage { get; set; }
[DataMember(Order = 2)]
public float LastStageTransitionTime { get; set; }
[DataMember(Order = 3)]
public int ElevatorState { get; set; }
[DataMember(Order = 4)]
public float ElevatorPosition { get; set; }
[DataMember(Order = 5)]
public List<int> PreflightChecks { get; set; } = [];
[IgnoreConstructor]
protected RocketMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public RocketMetadata(int currentStage, float lastStageTransitionTime, int elevatorState, float elevatorPosition, List<int> preflightChecks)
{
CurrentStage = currentStage;
LastStageTransitionTime = lastStageTransitionTime;
ElevatorState = elevatorState;
ElevatorPosition = elevatorPosition;
PreflightChecks = preflightChecks;
}
public override string ToString()
{
return $"[{nameof(RocketMetadata)} CurrentStage: {CurrentStage}, LastStageTransitionTime: {LastStageTransitionTime}, ElevatorState: {ElevatorState}, ElevatorPosition: {ElevatorPosition}, PreflightChecks: {string.Join(",", PreflightChecks)}]";
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class SeaTreaderMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool ReverseDirection { get; }
[DataMember(Order = 2)]
public float GrazingEndTime { get; }
[DataMember(Order = 3)]
public NitroxVector3 LeashPosition { get; }
[IgnoreConstructor]
protected SeaTreaderMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public SeaTreaderMetadata(bool reverseDirection, float grazingEndTime, NitroxVector3 leashPosition)
{
ReverseDirection = reverseDirection;
GrazingEndTime = grazingEndTime;
LeashPosition = leashPosition;
}
public override string ToString()
{
return $"[{nameof(SeaTreaderMetadata)} ReverseDirection: {ReverseDirection}, GrazingEndTime: {GrazingEndTime}, LeashPosition: {LeashPosition}]";
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
{
[Serializable]
[DataContract]
public class SealedDoorMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool Sealed { get; }
[DataMember(Order = 2)]
public float OpenedAmount { get; }
[IgnoreConstructor]
protected SealedDoorMetadata()
{
//Constructor for serialization. Has to be "protected" for json serialization.
}
public SealedDoorMetadata(bool Sealed, float OpenedAmount)
{
this.Sealed = Sealed;
this.OpenedAmount = OpenedAmount;
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class SeamothMetadata : VehicleMetadata
{
[DataMember(Order = 1)]
public bool LightsOn { get; }
[IgnoreConstructor]
protected SeamothMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public SeamothMetadata(bool lightsOn, float health, string name, NitroxVector3[] colors) : base(health, name, colors)
{
LightsOn = lightsOn;
}
public override string ToString()
{
return $"[{nameof(SeamothMetadata)} LightsOn: {LightsOn} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
{
[Serializable]
[DataContract]
public class StarshipDoorMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool DoorLocked { get; }
[DataMember(Order = 2)]
public bool DoorOpen { get; }
[IgnoreConstructor]
protected StarshipDoorMetadata()
{
//Constructor for serialization. Has to be "protected" for json serialization.
}
public StarshipDoorMetadata(bool doorLocked, bool doorOpen)
{
DoorLocked = doorLocked;
DoorOpen = doorOpen;
}
public override string ToString()
{
return $"[StarshipDoorMetadata DoorLocked: {DoorLocked} DoorOpen: {DoorOpen}]";
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable, DataContract]
public class StayAtLeashPositionMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public NitroxVector3 LeashPosition { get; }
[IgnoreConstructor]
protected StayAtLeashPositionMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public StayAtLeashPositionMetadata(NitroxVector3 leashPosition)
{
LeashPosition = leashPosition;
}
public override string ToString()
{
return $"[{nameof(StayAtLeashPositionMetadata)} LeashPosition: {LeashPosition}]";
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable]
[DataContract]
public class SubNameInputMetadata : NamedColoredMetadata
{
[DataMember(Order = 1)]
public int SelectedColorIndex { get; }
[IgnoreConstructor]
protected SubNameInputMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public SubNameInputMetadata(int selectedColorIndex, string name, NitroxVector3[] colors) : base(name, colors)
{
SelectedColorIndex = selectedColorIndex;
}
public override string ToString()
{
return $"[{nameof(SubNameInputMetadata)} SelectedColorIndex: {SelectedColorIndex} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.Unity;
using ProtoBufNet;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable, DataContract]
[ProtoInclude(50, typeof(SeamothMetadata))]
[ProtoInclude(60, typeof(ExosuitMetadata))]
public abstract class VehicleMetadata : NamedColoredMetadata
{
[DataMember(Order = 1)]
public float Health { get; init; }
[IgnoreConstructor]
protected VehicleMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public VehicleMetadata(float health, string name, NitroxVector3[] colors) : base(name, colors)
{
Health = health;
}
public override string ToString()
{
return $"[{nameof(VehicleMetadata)} Health: {Health} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,40 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;
[Serializable, DataContract]
public class WaterParkCreatureMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public float Age { get; init; }
[DataMember(Order = 2)]
public double MatureTime { get; init; }
[DataMember(Order = 3)]
public float TimeNextBreed { get; init; }
[DataMember(Order = 4)]
public bool BornInside { get; init; }
[IgnoreConstructor]
protected WaterParkCreatureMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public WaterParkCreatureMetadata(float age, double matureTime, float timeNextBreed, bool bornInside)
{
Age = age;
MatureTime = matureTime;
TimeNextBreed = timeNextBreed;
BornInside = bornInside;
}
public override string ToString()
{
return $"[WaterParkCreatureMetadata Age: {Age}, MatureTime: {MatureTime}, TimeNextBreed: {TimeNextBreed}, BornInside: {BornInside}]";
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
{
[Serializable]
[DataContract]
public class WeldableWallPanelGenericMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public float LiveMixInHealth { get; }
[IgnoreConstructor]
protected WeldableWallPanelGenericMetadata()
{
//Constructor for serialization. Has to be "protected" for json serialization.
}
public WeldableWallPanelGenericMetadata(float liveMixInHealth)
{
LiveMixInHealth = liveMixInHealth;
}
public override string ToString()
{
return $"[WeldableWallPanelGenericMetadata LiveMixInHealth: {LiveMixInHealth}]";
}
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable, DataContract]
public class OxygenPipeEntity : WorldEntity
{
[DataMember(Order = 1)]
public NitroxId ParentPipeId { get; set; }
[DataMember(Order = 2)]
public NitroxId RootPipeId { get; set; }
[DataMember(Order = 3)]
public NitroxVector3 ParentPosition { get; set; }
[IgnoreConstructor]
protected OxygenPipeEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
/// <remarks>Used for deserialization</remarks>
public OxygenPipeEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities, NitroxId parentPipeId, NitroxId rootPipeId, NitroxVector3 parentPosition) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
ParentPipeId = parentPipeId;
RootPipeId = rootPipeId;
ParentPosition = parentPosition;
}
}

View File

@@ -0,0 +1,37 @@
using System;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable]
[DataContract]
public class PathBasedChildEntity : Entity
{
[DataMember(Order = 1)]
public string Path { get; set; }
[IgnoreConstructor]
protected PathBasedChildEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
/// <remarks>Used for deserialization</remarks>
public PathBasedChildEntity(string path, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities)
{
Path = path;
Id = id;
TechType = techType;
Metadata = metadata;
ParentId = parentId;
ChildEntities = childEntities;
}
public override string ToString()
{
return $"[PathBasedChildEntity Path: {Path} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable, DataContract]
public class PlacedWorldEntity : WorldEntity
{
[IgnoreConstructor]
protected PlacedWorldEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
/// <remarks>Used for deserialization</remarks>
public PlacedWorldEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities) { }
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable, DataContract]
public class PlaceholderGroupWorldEntity : WorldEntity
{
[DataMember(Order = 1)]
public int ComponentIndex { get; set; }
[IgnoreConstructor]
protected PlaceholderGroupWorldEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public PlaceholderGroupWorldEntity(WorldEntity worldEntity, int componentIndex = 0)
{
Id = worldEntity.Id;
TechType = worldEntity.TechType;
Metadata = worldEntity.Metadata;
ParentId = worldEntity.ParentId;
Transform = worldEntity.Transform;
Level = worldEntity.Level;
ClassId = worldEntity.ClassId;
SpawnedByServer = worldEntity.SpawnedByServer;
ChildEntities = worldEntity.ChildEntities;
ComponentIndex = componentIndex;
}
/// <remarks>Used for deserialization</remarks>
public PlaceholderGroupWorldEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities, int componentIndex) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
ComponentIndex = componentIndex;
}
public override string ToString()
{
return $"[PlaceholderGroupWorldEntity ComponentIndex: {ComponentIndex} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable, DataContract]
public class PlanterEntity : GlobalRootEntity
{
[IgnoreConstructor]
protected PlanterEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public PlanterEntity(NitroxId id, NitroxId parentId)
{
Id = id;
ParentId = parentId;
}
/// <remarks>
/// Used for deserialization.
/// <see cref="WorldEntity.SpawnedByServer"/> is set to true because this entity is meant to receive simulation locks
/// </remarks>
public PlanterEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, true, id, techType, metadata, parentId, childEntities) {}
public override string ToString()
{
return $"[PlanterEntity {base.ToString()}]";
}
}

View File

@@ -0,0 +1,31 @@
using System;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using System.Collections.Generic;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.Unity;
using System.Runtime.Serialization;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable]
[DataContract]
public class PlayerWorldEntity : GlobalRootEntity
{
[IgnoreConstructor]
protected PlayerWorldEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
/// <remarks>
/// Used for deserialization.
/// <see cref="WorldEntity.SpawnedByServer"/> is set to true because this entity is meant to receive simulation locks
/// </remarks>
public PlayerWorldEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, true, id, techType, metadata, parentId, childEntities) {}
public override string ToString()
{
return $"[PlayerEntity {base.ToString()}]";
}
}

View File

@@ -0,0 +1,59 @@
using System;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic.Entities
{
/*
* A PrefabChildEntity is a gameobject that resides inside of a spawned prefab. Although the server knows about these,
* it is too cost prohibitive for it to send spawn data for all of these. Instead, we let the game spawn them and tag
* the entity after the fact. An example of this is a keypad in the aurora; there is an overarching Door prefab with
* the keypad baked in - we simply update the id of the keypad on spawn. Each PrefabChildEntity will always bubble up
* to a root WorldEntity.
*/
[Serializable]
[DataContract]
public class PrefabChildEntity : Entity
{
[DataMember(Order = 1)]
public int ComponentIndex { get; set; }
[DataMember(Order = 2)]
public string ClassId { get; set; }
[IgnoreConstructor]
protected PrefabChildEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public PrefabChildEntity(NitroxId id, string classId, NitroxTechType techType, int componentIndex, EntityMetadata metadata, NitroxId parentId)
{
Id = id;
TechType = techType;
ComponentIndex = componentIndex;
ParentId = parentId;
ClassId = classId;
Metadata = metadata;
}
/// <remarks>Used for deserialization</remarks>
public PrefabChildEntity(int componentIndex, string classId, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities)
{
ComponentIndex = componentIndex;
ClassId = classId;
Id = id;
TechType = techType;
Metadata = metadata;
ParentId = parentId;
ChildEntities = childEntities;
}
public override string ToString()
{
return $"[PrefabChildEntity ComponentIndex: {ComponentIndex} ClassId: {ClassId} {base.ToString()}]";
}
}
}

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
/// <summary>
/// Represents a Placeholder GameObject located under a PrefabPlaceholdersGroup
/// </summary>
[Serializable, DataContract]
public class PrefabPlaceholderEntity : WorldEntity
{
[DataMember(Order = 1)]
public int ComponentIndex { get; set; }
[IgnoreConstructor]
protected PrefabPlaceholderEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public PrefabPlaceholderEntity(WorldEntity worldEntity, int componentIndex = 0)
{
Id = worldEntity.Id;
TechType = worldEntity.TechType;
Metadata = worldEntity.Metadata;
ParentId = worldEntity.ParentId;
Transform = worldEntity.Transform;
Level = worldEntity.Level;
ClassId = worldEntity.ClassId;
SpawnedByServer = worldEntity.SpawnedByServer;
ChildEntities = worldEntity.ChildEntities;
ComponentIndex = componentIndex;
}
/// <remarks>Used for deserialization</remarks>
public PrefabPlaceholderEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities, int componentIndex) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
ComponentIndex = componentIndex;
}
public override string ToString()
{
return $"[PrefabPlaceholderEntity ComponentIndex: {ComponentIndex} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable, DataContract]
public class RadiationLeakEntity : GlobalRootEntity
{
[DataMember(Order = 1)]
public int ObjectIndex { get; set; }
[IgnoreConstructor]
protected RadiationLeakEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public RadiationLeakEntity(NitroxId id, int objectIndex, RadiationMetadata metadata)
{
Id = id;
ObjectIndex = objectIndex;
Metadata = metadata;
Transform = new();
}
/// <remarks>Used for deserialization</remarks>
public RadiationLeakEntity(int objectIndex, NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
ObjectIndex = objectIndex;
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable, DataContract]
public class ReefbackChildEntity : WorldEntity
{
[DataMember(Order = 1)]
public ReefbackChildType Type { get; set; }
[IgnoreConstructor]
protected ReefbackChildEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public ReefbackChildEntity(NitroxVector3 localPosition, NitroxQuaternion localRotation, NitroxVector3 scale, NitroxTechType techType, int level, string classId, bool spawnedByServer, NitroxId id, ReefbackEntity parentEntity, ReefbackChildType type) :
base(localPosition, localRotation, scale, techType, level, classId, spawnedByServer, id, null)
{
Type = type;
// Manually set ParentId instead of providing parentEntity to the base constructor to avoid having the Transform being parented
ParentId = parentEntity.Id;
}
/// <remarks>Used for deserialization</remarks>
public ReefbackChildEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities, ReefbackChildType type) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
Type = type;
}
public override string ToString()
{
return $"[{nameof(ReefbackChildEntity)} Type: {Type} {base.ToString()}]";
}
public enum ReefbackChildType
{
CREATURE,
PLANT
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable, DataContract]
public class ReefbackEntity : WorldEntity
{
[DataMember(Order = 1)]
public int GrassIndex { get; set; }
[DataMember(Order = 2)]
public NitroxVector3 OriginalPosition { get; set; }
[IgnoreConstructor]
protected ReefbackEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
/// <remarks>Used for deserialization</remarks>
public ReefbackEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities, int grassIndex, NitroxVector3 originalPosition) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
GrassIndex = grassIndex;
OriginalPosition = originalPosition;
}
public override string ToString()
{
return $"[{nameof(ReefbackEntity)} GrassIndex: {GrassIndex}, OriginalPosition: {OriginalPosition} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
/// <summary>
/// An implementation for GameObjects marked as CreateEmptyObject in the protobuf serializer.
/// They seem to represent unique (which is why they don't exist as a prefab) statically created objects which are part of the decor but can't be interacted with.
/// </summary>
/// <remarks>
/// The associated GameObjects are mostly alone in their own EntityCell.
/// To avoid creating an EntityCell entity for each of them we give it a global position and its actual cell reference.
/// It is safe to give a static cell because those objects don't move.
/// </remarks>
[Serializable]
[DataContract]
public class SerializedWorldEntity : WorldEntity
{
public override AbsoluteEntityCell AbsoluteEntityCell => new(BatchId, CellId, Level);
[DataMember(Order = 1)]
public List<SerializedComponent> Components { get; set; } = [];
[DataMember(Order = 2)]
public int Layer { get; set; }
/// <summary>
/// This entity is not parented so it doesn't have info for the cell containing it,
/// therefore we need to serialize it instead of generating it from a local position (which would make no sense)
/// </summary>
[DataMember(Order = 3)]
public NitroxInt3 BatchId { get; set; }
/// <inheritdoc cref="BatchId"/>
[DataMember(Order = 4)]
public NitroxInt3 CellId { get; set; }
[IgnoreConstructor]
protected SerializedWorldEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public SerializedWorldEntity(List<SerializedComponent> components, int layer, NitroxTransform transform, NitroxId id, NitroxId parentId, AbsoluteEntityCell cell)
{
Components = components;
Layer = layer;
Transform = transform;
Id = id;
ParentId = parentId;
Level = cell.Level;
BatchId = cell.BatchId;
CellId = cell.CellId;
}
/// <remarks>Used for deserialization</remarks>
public SerializedWorldEntity(List<SerializedComponent> components, int layer, NitroxInt3 batchId, NitroxInt3 cellId, NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
Components = components;
Layer = layer;
BatchId = batchId;
CellId = cellId;
}
public override string ToString()
{
return $"[{nameof(SerializedWorldEntity)} Components: {Components.Count}, Layer: {Layer}, BatchId: {BatchId}, CellId: {CellId} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,3 @@
namespace NitroxModel.DataStructures.GameLogic.Entities;
public readonly record struct UwePrefab(string ClassId, int Count, float Probability, bool IsFragment);

View File

@@ -0,0 +1,23 @@
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic.Entities;
public class UweWorldEntity
{
public string ClassId { get; }
public NitroxTechType TechType { get; }
public string SlotType { get; }
public bool PrefabZUp { get; }
public int CellLevel { get; }
public NitroxVector3 LocalScale { get; }
public UweWorldEntity(string classId, NitroxTechType techType, string slotType, bool prefabZUp, int cellLevel, NitroxVector3 localScale)
{
ClassId = classId;
TechType = techType;
SlotType = slotType;
PrefabZUp = prefabZUp;
CellLevel = cellLevel;
LocalScale = localScale;
}
}

View File

@@ -0,0 +1,45 @@
using System;
using BinaryPack.Attributes;
using System.Runtime.Serialization;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
using System.Collections.Generic;
namespace NitroxModel.DataStructures.GameLogic.Entities;
[Serializable]
[DataContract]
public class VehicleWorldEntity : GlobalRootEntity
{
[DataMember(Order = 1)]
public NitroxId SpawnerId { get; set; }
[DataMember(Order = 2)]
public float ConstructionTime { get; set; }
[IgnoreConstructor]
protected VehicleWorldEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public VehicleWorldEntity(NitroxId spawnerId, float constructionTime, NitroxTransform transform, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata) :
base(transform, 0, classId, spawnedByServer, id, techType, metadata, null, new List<Entity>())
{
SpawnerId = spawnerId;
ConstructionTime = constructionTime;
}
/// <remarks>Used for deserialization</remarks>
public VehicleWorldEntity(NitroxId spawnerId, float constructionTime, NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
SpawnerId = spawnerId;
ConstructionTime = constructionTime;
}
public override string ToString()
{
return $"[VehicleEntity SpawnerId:{SpawnerId} ConstructionTime:{ConstructionTime} {base.ToString()}]";
}
}

View File

@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.DataStructures.Unity;
using ProtoBufNet;
namespace NitroxModel.DataStructures.GameLogic.Entities
{
/*
* A world entity is an object physically in the world with a transform. It is either a global root entity
* or something that phases out with the clip map manager.
*/
[Serializable]
[DataContract]
[ProtoInclude(50, typeof(PlaceholderGroupWorldEntity))]
[ProtoInclude(51, typeof(CellRootEntity))]
[ProtoInclude(52, typeof(GlobalRootEntity))]
[ProtoInclude(53, typeof(OxygenPipeEntity))]
[ProtoInclude(54, typeof(PlacedWorldEntity))]
[ProtoInclude(55, typeof(SerializedWorldEntity))]
[ProtoInclude(56, typeof(PrefabPlaceholderEntity))]
[ProtoInclude(57, typeof(GeyserWorldEntity))]
[ProtoInclude(58, typeof(ReefbackEntity))]
[ProtoInclude(59, typeof(ReefbackChildEntity))]
[ProtoInclude(60, typeof(CreatureRespawnEntity))]
public class WorldEntity : Entity
{
public virtual AbsoluteEntityCell AbsoluteEntityCell => new(Transform.Position, Level);
[DataMember(Order = 1)]
public NitroxTransform Transform { get; set; }
[DataMember(Order = 2)]
public int Level { get; set; }
/// <summary>
/// Gets the prefab class id assigned by Unity Engine. This is a unique <see cref="Guid"/>.
/// </summary>
/// <remarks>
/// <a href="https://docs.unity3d.com/Manual/Prefabs.html">What is a prefab?</a>
/// </remarks>
[DataMember(Order = 3)]
public string ClassId { get; set; }
/// <summary>
/// Keeps track if an entity was spawned by the server or a player
/// Server-spawned entities need to be techType white-listed to be simulated
/// </summary>
[DataMember(Order = 4)]
public bool SpawnedByServer;
[IgnoreConstructor]
protected WorldEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public WorldEntity(NitroxVector3 localPosition, NitroxQuaternion localRotation, NitroxVector3 scale, NitroxTechType techType, int level, string classId, bool spawnedByServer, NitroxId id, Entity parentEntity)
{
Transform = new NitroxTransform(localPosition, localRotation, scale);
TechType = techType;
Id = id;
Level = level;
ClassId = classId;
SpawnedByServer = spawnedByServer;
if (parentEntity != null)
{
ParentId = parentEntity.Id;
if (parentEntity is WorldEntity weParent)
{
Transform.SetParent(weParent.Transform, false);
}
}
}
/// <remarks>Used for deserialization</remarks>
public WorldEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities)
{
Id = id;
TechType = techType;
Metadata = metadata;
ParentId = parentId;
Transform = transform;
ChildEntities = childEntities;
Level = level;
ClassId = classId;
SpawnedByServer = spawnedByServer;
}
public override string ToString()
{
return $"[{GetType().Name} Transform: {Transform} Level: {Level} ClassId: {ClassId} SpawnedByServer: {SpawnedByServer} {base.ToString()}]";
}
}
}

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.DataStructures.GameLogic.Entities;
using NitroxModel.DataStructures.GameLogic.Entities.Bases;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using ProtoBufNet;
namespace NitroxModel.DataStructures.GameLogic
{
[Serializable]
[DataContract]
[ProtoInclude(50, typeof(PrefabChildEntity))]
[ProtoInclude(51, typeof(InventoryEntity))]
[ProtoInclude(52, typeof(InventoryItemEntity))]
[ProtoInclude(53, typeof(PathBasedChildEntity))]
[ProtoInclude(54, typeof(InstalledBatteryEntity))]
[ProtoInclude(55, typeof(InstalledModuleEntity))]
[ProtoInclude(56, typeof(WorldEntity))]
[ProtoInclude(57, typeof(BaseLeakEntity))]
public abstract class Entity
{
[DataMember(Order = 1)]
public NitroxId Id { get; set; }
[DataMember(Order = 2)]
public NitroxTechType TechType { get; set; }
[DataMember(Order = 3)]
public EntityMetadata Metadata { get; set; }
[DataMember(Order = 4)]
public NitroxId ParentId { get; set; }
[DataMember(Order = 5)]
public List<Entity> ChildEntities { get; set; } = [];
[IgnoreConstructor]
protected Entity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public override string ToString()
{
return $"[Entity id: {Id} techType: {TechType} Metadata: {Metadata} ParentId: {ParentId} ChildEntities: {string.Join(",\n ", ChildEntities)}]";
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic
{
[Serializable]
public class InitialPDAData
{
public List<NitroxTechType> KnownTechTypes { get; set; }
public List<NitroxTechType> AnalyzedTechTypes { get; set; }
public List<PDALogEntry> PDALogEntries { get; set; }
public List<string> EncyclopediaEntries { get; set; }
// PDA Scanner data
public List<NitroxId> ScannerFragments { get; set; }
public List<PDAEntry> ScannerPartial { get; set; }
public List<NitroxTechType> ScannerComplete { get; set; }
[IgnoreConstructor]
protected InitialPDAData()
{
//Constructor for serialization. Has to be "protected" for json serialization.
}
public InitialPDAData(List<NitroxTechType> knownTechTypes, List<NitroxTechType> analyzedTechTypes, List<PDALogEntry> pDALogEntries, List<string> encyclopediaEntries, List<NitroxId> scannerFragments, List<PDAEntry> scannerPartial, List<NitroxTechType> scannerComplete)
{
KnownTechTypes = knownTechTypes;
AnalyzedTechTypes = analyzedTechTypes;
PDALogEntries = pDALogEntries;
EncyclopediaEntries = encyclopediaEntries;
ScannerFragments = scannerFragments;
ScannerPartial = scannerPartial;
ScannerComplete = scannerComplete;
}
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic
{
[Serializable]
public class InitialStoryGoalData
{
public List<string> CompletedGoals { get; set; }
public List<string> RadioQueue { get; set; }
public List<NitroxScheduledGoal> ScheduledGoals { get; set; }
/// <remarks>
/// This is the only field in this class that is very personal to the player this will be sent to.
/// The other ones are shared by everyone and are related to overall story progress.
/// </remarks>
public Dictionary<string, float> PersonalCompletedGoalsWithTimestamp { get; set; }
[IgnoreConstructor]
protected InitialStoryGoalData()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public InitialStoryGoalData(List<string> completedGoals, List<string> radioQueue, List<NitroxScheduledGoal> scheduledGoals, Dictionary<string, float> personalCompletedGoalsWithTimestamp)
{
CompletedGoals = completedGoals;
RadioQueue = radioQueue;
ScheduledGoals = scheduledGoals;
PersonalCompletedGoalsWithTimestamp = personalCompletedGoalsWithTimestamp;
}
}
}

View File

@@ -0,0 +1,12 @@
namespace NitroxModel.DataStructures.GameLogic;
public enum IntroCinematicMode : byte
{
NONE,
LOADING,
WAITING,
START,
PLAYING,
SINGLEPLAYER,
COMPLETED
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic;
[Serializable, DataContract]
public class NitroxScheduledGoal
{
[DataMember(Order = 1)]
public float TimeExecute { get; set; }
[DataMember(Order = 2)]
public string GoalKey { get; set; }
[DataMember(Order = 3)]
public int GoalType { get; set; }
[IgnoreConstructor]
protected NitroxScheduledGoal()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public NitroxScheduledGoal(float timeExecute, string goalKey, int goalType)
{
TimeExecute = timeExecute;
GoalKey = goalKey;
GoalType = goalType;
}
public static NitroxScheduledGoal From(float timeExecute, string goalKey, int goalType)
{
return new NitroxScheduledGoal(timeExecute, goalKey, goalType);
}
public override string ToString()
{
return $"[NitroxScheduledGoal: TimeExecute: {TimeExecute}, GoalKey: {GoalKey}, GoalType: {GoalType}]";
}
}

View File

@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic;
/// <summary>
/// TechType is the enum used in Subnautica for defining all the spawnable objects in the world. This includes food, enemies and bases.
/// </summary>
/// <remarks>
/// Shim tech type model to bridge the gap between original subnautica and BZ.
/// </remarks>
[Serializable]
[DataContract]
public class NitroxTechType : IEquatable<NitroxTechType>
{
[DataMember(Order = 1)]
public string Name { get; }
[IgnoreConstructor]
protected NitroxTechType()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public NitroxTechType(string name)
{
Name = name;
}
public static NitroxTechType None { get; } = new NitroxTechType("None");
public override string ToString()
{
return Name;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != this.GetType())
{
return false;
}
return Equals((NitroxTechType)obj);
}
public bool Equals(NitroxTechType other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Name == other.Name;
}
public override int GetHashCode()
{
return 539060726 + EqualityComparer<string>.Default.GetHashCode(Name);
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic;
[Serializable, DataContract]
public class PDAEntry
{
[DataMember(Order = 1)]
public NitroxTechType TechType { get; set; }
[DataMember(Order = 2)]
public int Unlocked { get; set; }
[IgnoreConstructor]
protected PDAEntry()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public PDAEntry(NitroxTechType techType, int unlocked)
{
TechType = techType;
Unlocked = unlocked;
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic
{
[Serializable]
[DataContract]
public class PDALogEntry
{
[DataMember(Order = 1)]
public string Key;
[DataMember(Order = 2)]
public float Timestamp;
[IgnoreConstructor]
protected PDALogEntry()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public PDALogEntry(string key, float timestamp)
{
Key = key;
Timestamp = timestamp;
}
public override string ToString()
{
return $"{nameof(Key)}: {Key}, {nameof(Timestamp)}: {Timestamp}";
}
}
}

View File

@@ -0,0 +1,20 @@
using System;
namespace NitroxModel.DataStructures.GameLogic
{
public enum Perms : byte
{
NONE,
PLAYER,
MODERATOR,
ADMIN,
CONSOLE
}
[Flags]
public enum PermsFlag : byte
{
NONE = 0x0,
NO_CONSOLE = 0x1
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic;
[Serializable]
[DataContract]
public class PingInstancePreference
{
[DataMember(Order = 1)]
public int Color { get; set; }
[DataMember(Order = 2)]
public bool Visible { get; set; }
[IgnoreConstructor]
protected PingInstancePreference()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public PingInstancePreference(int color, bool visible)
{
Color = color;
Visible = visible;
}
}

View File

@@ -0,0 +1,49 @@
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
namespace NitroxModel.DataStructures.GameLogic
{
[Serializable]
[DataContract]
public class PlayerStatsData
{
[DataMember(Order = 1)]
public float Oxygen { get; }
[DataMember(Order = 2)]
public float MaxOxygen { get; }
[DataMember(Order = 3)]
public float Health { get; }
[DataMember(Order = 4)]
public float Food { get; }
[DataMember(Order = 5)]
public float Water { get; }
[DataMember(Order = 6)]
public float InfectionAmount { get; }
[IgnoreConstructor]
protected PlayerStatsData()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
public PlayerStatsData(float oxygen, float maxOxygen, float health, float food, float water, float infectionAmount)
{
Oxygen = oxygen;
MaxOxygen = maxOxygen;
Health = health;
Food = food;
Water = water;
InfectionAmount = infectionAmount;
}
public override string ToString()
{
return $"[Oxygen: {Oxygen} MaxOxygen: {MaxOxygen} Health: {Health} Food: {Food} Water: {Water} InfectionAmount: {InfectionAmount} ]";
}
}
}

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using NitroxModel.DataStructures.Unity;
namespace NitroxModel.DataStructures.GameLogic;
public class RandomStartGenerator
{
private readonly IPixelProvider pixelProvider;
public RandomStartGenerator(IPixelProvider pixelProvider)
{
this.pixelProvider = pixelProvider;
}
public NitroxVector3 GenerateRandomStartPosition(Random rnd)
{
for (int i = 0; i < 1000; i++)
{
float normalizedX = (float)rnd.NextDouble();
float normalizedZ = (float)rnd.NextDouble();
if (IsStartPointValid(normalizedX, normalizedZ))
{
float x = 4096f * normalizedX - 2048f; // normalizedX = (x + 2048) / 4096
float z = 4096f * normalizedZ - 2048f;
return new NitroxVector3(x, 0, z);
}
}
return NitroxVector3.Zero;
}
public List<NitroxVector3> GenerateRandomStartPositions(string seed)
{
Random rnd = new(seed.GetHashCode());
List<NitroxVector3> list = new();
for (int i = 0; i < 1000; i++)
{
float normalizedX = (float)rnd.NextDouble();
float normalizedZ = (float)rnd.NextDouble();
if (IsStartPointValid(normalizedX, normalizedZ))
{
float x = 4096f * normalizedX - 2048f; // normalizedX = (x + 2048) / 4096
float z = 4096f * normalizedZ - 2048f;
list.Add(new NitroxVector3(x, 0, z));
}
}
return list;
}
private bool IsStartPointValid(float normalizedX, float normalizedZ)
{
int textureX = (int)(normalizedX * 512);
int textureZ = (int)(normalizedZ * 512);
return pixelProvider.GetGreen(textureX, textureZ) > 127;
}
/// <summary>
/// API for getting pixels from an underlying texture.
/// </summary>
public interface IPixelProvider
{
byte GetRed(int x, int y);
byte GetGreen(int x, int y);
byte GetBlue(int x, int y);
}
}

View File

@@ -0,0 +1,13 @@
using System;
namespace NitroxModel.DataStructures.GameLogic;
/// <summary>
/// States that are temporary for one session so we don't need to persist them
/// </summary>
[Serializable]
public class SessionSettings
{
public bool FastHatch;
public bool FastGrow;
}

Some files were not shown because too many files have changed in this diff Show More