first commit
This commit is contained in:
178
NitroxModel-Subnautica/DataStructures/DataExtensions.cs
Normal file
178
NitroxModel-Subnautica/DataStructures/DataExtensions.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.DataStructures.GameLogic;
|
||||
using NitroxModel.DataStructures.GameLogic.Bases;
|
||||
using NitroxModel.DataStructures.Unity;
|
||||
using NitroxModel.Packets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxModel_Subnautica.DataStructures;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for converting Unity types to Nitrox types and vice versa.
|
||||
/// This is necessary to allow the server to work without a dependency on game models while still being able to represent game models.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The abbreviation "DTO" means Data Transfer Object which is a common term used in REST APIs.
|
||||
/// Its purpose is to be a serializable type and to transfer the least amount of data necessary per request (e.g. API call).
|
||||
/// </remarks>
|
||||
public static class DataExtensions
|
||||
{
|
||||
public static Int3 ToUnity(this NitroxInt3 v)
|
||||
{
|
||||
return new Int3(v.X, v.Y, v.Z);
|
||||
}
|
||||
|
||||
public static NitroxInt3 ToDto(this Int3 v)
|
||||
{
|
||||
return new NitroxInt3(v.x, v.y, v.z);
|
||||
}
|
||||
|
||||
public static NitroxVector3 ToDto(this Vector3 v)
|
||||
{
|
||||
return new NitroxVector3(v.x, v.y, v.z);
|
||||
}
|
||||
|
||||
public static Vector3 ToUnity(this NitroxVector3 v)
|
||||
{
|
||||
return new Vector3(v.X, v.Y, v.Z);
|
||||
}
|
||||
|
||||
public static NitroxVector4 ToDto(this Vector4 v)
|
||||
{
|
||||
return new NitroxVector4(v.x, v.y, v.z, v.w);
|
||||
}
|
||||
|
||||
public static Vector4 ToUnity(this NitroxVector4 v)
|
||||
{
|
||||
return new Vector4(v.X, v.Y, v.Z, v.W);
|
||||
}
|
||||
|
||||
public static NitroxTechType ToDto(this TechType v)
|
||||
{
|
||||
return new NitroxTechType(v.ToString());
|
||||
}
|
||||
|
||||
public static TechType ToUnity(this NitroxTechType v)
|
||||
{
|
||||
return (TechType)Enum.Parse(typeof(TechType), v.Name);
|
||||
}
|
||||
|
||||
public static Quaternion ToUnity(this NitroxQuaternion v)
|
||||
{
|
||||
return new Quaternion(v.X, v.Y, v.Z, v.W);
|
||||
}
|
||||
|
||||
public static NitroxQuaternion ToDto(this Quaternion v)
|
||||
{
|
||||
return new NitroxQuaternion(v.x, v.y, v.z, v.w);
|
||||
}
|
||||
|
||||
public static NitroxColor ToDto(this Color v)
|
||||
{
|
||||
return new NitroxColor(v.r, v.g, v.b, v.a);
|
||||
}
|
||||
|
||||
public static Color ToUnity(this NitroxColor v)
|
||||
{
|
||||
return new Color(v.R, v.G, v.B, v.A);
|
||||
}
|
||||
|
||||
public static NitroxTransform ToLocalDto(this Transform transform)
|
||||
{
|
||||
return new NitroxTransform(transform.localPosition.ToDto(),
|
||||
transform.localRotation.ToDto(),
|
||||
transform.localScale.ToDto());
|
||||
}
|
||||
|
||||
public static NitroxTransform ToWorldDto(this Transform transform)
|
||||
{
|
||||
return new NitroxTransform(transform.position.ToDto(),
|
||||
transform.rotation.ToDto(),
|
||||
transform.localScale.ToDto());
|
||||
}
|
||||
|
||||
public static NitroxColor[] ToDto(this Color[] v)
|
||||
{
|
||||
NitroxColor[] result = new NitroxColor[v.Length];
|
||||
for (int i = 0; i < v.Length; i++)
|
||||
{
|
||||
result[i] = v[i].ToDto();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static NitroxVector3[] ToDto(this Vector3[] v)
|
||||
{
|
||||
if (v == null)
|
||||
{
|
||||
return Array.Empty<NitroxVector3>();
|
||||
}
|
||||
|
||||
NitroxVector3[] result = new NitroxVector3[v.Length];
|
||||
for (int i = 0; i < v.Length; i++)
|
||||
{
|
||||
result[i] = v[i].ToDto();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Vector3[] ToUnity(this NitroxVector3[] v)
|
||||
{
|
||||
if (v == null)
|
||||
{
|
||||
return Array.Empty<Vector3>();
|
||||
}
|
||||
|
||||
Vector3[] result = new Vector3[v.Length];
|
||||
for (int i = 0; i < v.Length; i++)
|
||||
{
|
||||
result[i] = v[i].ToUnity();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static StoryGoalExecuted.EventType ToDto(this Story.GoalType goalType)
|
||||
{
|
||||
return goalType switch
|
||||
{
|
||||
Story.GoalType.PDA => StoryGoalExecuted.EventType.PDA,
|
||||
Story.GoalType.Radio => StoryGoalExecuted.EventType.RADIO,
|
||||
Story.GoalType.Encyclopedia => StoryGoalExecuted.EventType.ENCYCLOPEDIA,
|
||||
Story.GoalType.Story => StoryGoalExecuted.EventType.STORY,
|
||||
_ => throw new ArgumentException("The provided Story.GoalType doesn't correspond to a StoryEventSend.EventType"),
|
||||
};
|
||||
}
|
||||
|
||||
public static Story.GoalType ToUnity(this StoryGoalExecuted.EventType eventType)
|
||||
{
|
||||
return eventType switch
|
||||
{
|
||||
StoryGoalExecuted.EventType.PDA => Story.GoalType.PDA,
|
||||
StoryGoalExecuted.EventType.RADIO => Story.GoalType.Radio,
|
||||
StoryGoalExecuted.EventType.ENCYCLOPEDIA => Story.GoalType.Encyclopedia,
|
||||
StoryGoalExecuted.EventType.STORY => Story.GoalType.Story,
|
||||
_ => throw new ArgumentException("The provided StoryEventSend.EventType doesn't correspond to a Story.GoalType")
|
||||
};
|
||||
}
|
||||
|
||||
public static PDAEntry ToDto(this PDAScanner.Entry entry)
|
||||
{
|
||||
return new(entry.techType.ToDto(), entry.unlocked);
|
||||
}
|
||||
|
||||
public static PDAScanner.Entry ToUnity(this PDAEntry entry)
|
||||
{
|
||||
return new() { techType = entry.TechType.ToUnity(), unlocked = entry.Unlocked };
|
||||
}
|
||||
|
||||
public static Base.Face ToUnity(this NitroxBaseFace baseFace)
|
||||
{
|
||||
return new(baseFace.Cell.ToUnity(), (Base.Direction)baseFace.Direction);
|
||||
}
|
||||
|
||||
public static NitroxBaseFace ToDto(this Base.Face face)
|
||||
{
|
||||
return new(face.cell.ToDto(), (int)face.direction);
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxModel_Subnautica.DataStructures.GameLogic.Creatures.Actions
|
||||
{
|
||||
public interface SerializableCreatureAction
|
||||
{
|
||||
CreatureAction GetCreatureAction(GameObject gameObject);
|
||||
}
|
||||
|
||||
// SerializableCreatureAction is not implemented yet but test require that at least one class inherits it
|
||||
[Serializable]
|
||||
public class EmptyCreatureAction: SerializableCreatureAction
|
||||
{
|
||||
public CreatureAction GetCreatureAction(GameObject gameObject) => null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.DataStructures.Unity;
|
||||
using NitroxModel.DataStructures.Util;
|
||||
|
||||
namespace NitroxModel_Subnautica.DataStructures.GameLogic
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class CyclopsDamageInfoData
|
||||
{
|
||||
[DataMember(Order = 1)]
|
||||
public NitroxId ReceiverId { get; set; }
|
||||
|
||||
[DataMember(Order = 2)]
|
||||
public Optional<NitroxId> DealerId { get; set; }
|
||||
|
||||
[DataMember(Order = 3)]
|
||||
public float OriginalDamage { get; set; }
|
||||
|
||||
[DataMember(Order = 4)]
|
||||
public float Damage { get; set; }
|
||||
|
||||
[DataMember(Order = 5)]
|
||||
public NitroxVector3 Position { get; set; }
|
||||
|
||||
[DataMember(Order = 6)]
|
||||
public DamageType Type { get; set; }
|
||||
|
||||
protected CyclopsDamageInfoData()
|
||||
{
|
||||
// Constructor for serialization. Has to be "protected" for json serialization.
|
||||
}
|
||||
|
||||
public CyclopsDamageInfoData(NitroxId receiverId, Optional<NitroxId> dealerId, float originalDamage, float damage, NitroxVector3 position, DamageType type)
|
||||
{
|
||||
ReceiverId = receiverId;
|
||||
DealerId = dealerId;
|
||||
OriginalDamage = originalDamage;
|
||||
Damage = damage;
|
||||
Position = position;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[CyclopsDamageInfoData - ReceiverId: {ReceiverId} DealerId:{DealerId} OriginalDamage: {OriginalDamage} Damage: {Damage} Position: {Position} Type: {Type}}}]";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using NitroxModel.DataStructures;
|
||||
|
||||
namespace NitroxModel_Subnautica.DataStructures.GameLogic
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class CyclopsFireData
|
||||
{
|
||||
[DataMember(Order = 1)]
|
||||
public NitroxId FireId { get; set; }
|
||||
|
||||
[DataMember(Order = 2)]
|
||||
public NitroxId CyclopsId { get; set; }
|
||||
|
||||
[DataMember(Order = 3)]
|
||||
public CyclopsRooms Room { get; set; }
|
||||
|
||||
[DataMember(Order = 4)]
|
||||
public int NodeIndex { get; set; }
|
||||
|
||||
protected CyclopsFireData()
|
||||
{
|
||||
// Constructor for serialization. Has to be "protected" for json serialization.
|
||||
}
|
||||
|
||||
public CyclopsFireData(NitroxId fireId, NitroxId cyclopsId, CyclopsRooms room, int nodeIndex)
|
||||
{
|
||||
FireId = fireId;
|
||||
CyclopsId = cyclopsId;
|
||||
Room = room;
|
||||
NodeIndex = nodeIndex;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[CyclopsFireData - FireId: {FireId}, CyclopsId: {CyclopsId}, Room: {Room}, FireNodeIndex: {NodeIndex}]";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LitJson;
|
||||
using NitroxModel.DataStructures.GameLogic.Entities;
|
||||
using NitroxModel.Helper;
|
||||
using static LootDistributionData;
|
||||
|
||||
namespace NitroxModel_Subnautica.DataStructures.GameLogic.Entities;
|
||||
|
||||
public class SubnauticaUwePrefabFactory : IUwePrefabFactory
|
||||
{
|
||||
private readonly LootDistributionData lootDistributionData;
|
||||
private readonly Dictionary<string, List<UwePrefab>> cache = new();
|
||||
|
||||
public SubnauticaUwePrefabFactory(string lootDistributionJson)
|
||||
{
|
||||
lootDistributionData = GetLootDistributionData(lootDistributionJson);
|
||||
}
|
||||
|
||||
public bool TryGetPossiblePrefabs(string biome, out List<UwePrefab> prefabs)
|
||||
{
|
||||
if (biome == null)
|
||||
{
|
||||
prefabs = null;
|
||||
return false;
|
||||
}
|
||||
if (cache.TryGetValue(biome, out prefabs))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
prefabs = new();
|
||||
BiomeType biomeType = (BiomeType)Enum.Parse(typeof(BiomeType), biome);
|
||||
if (lootDistributionData.GetBiomeLoot(biomeType, out DstData dstData))
|
||||
{
|
||||
foreach (PrefabData prefabData in dstData.prefabs)
|
||||
{
|
||||
if (lootDistributionData.srcDistribution.TryGetValue(prefabData.classId, out SrcData srcData))
|
||||
{
|
||||
// Manually went through the list of those to make this "filter"
|
||||
// You can verify this by looping through all of SrcData (e.g in LootDistributionData.Initialize)
|
||||
// print the prefabPath and check the TechType related to the provided classId (WorldEntityDatabase.TryGetInfo) with PDAScanner.IsFragment
|
||||
bool isFragment = srcData.prefabPath.Contains("Fragment") || srcData.prefabPath.Contains("BaseGlassDome");
|
||||
prefabs.Add(new(prefabData.classId, prefabData.count, prefabData.probability, isFragment));
|
||||
}
|
||||
}
|
||||
}
|
||||
cache[biome] = prefabs;
|
||||
return true;
|
||||
}
|
||||
|
||||
private LootDistributionData GetLootDistributionData(string lootDistributionJson)
|
||||
{
|
||||
// LitJson uses the computer's local CultureInfo when parsing the JSON files.
|
||||
// However, these json files were saved in en_US. Ensure that this is done for the current thread.
|
||||
CultureManager.ConfigureCultureInfo();
|
||||
|
||||
JsonMapper.RegisterImporter((double value) => Convert.ToSingle(value));
|
||||
|
||||
Dictionary<string, LootDistributionData.SrcData> result = JsonMapper.ToObject<Dictionary<string, LootDistributionData.SrcData>>(lootDistributionJson);
|
||||
|
||||
LootDistributionData lootDistributionData = new LootDistributionData();
|
||||
lootDistributionData.Initialize(result);
|
||||
|
||||
return lootDistributionData;
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using NitroxModel.DataStructures.GameLogic.Entities;
|
||||
using UWE;
|
||||
|
||||
namespace NitroxModel_Subnautica.DataStructures.GameLogic.Entities;
|
||||
|
||||
public class SubnauticaUweWorldEntityFactory : IUweWorldEntityFactory
|
||||
{
|
||||
private readonly Dictionary<string, WorldEntityInfo> worldEntitiesByClassId;
|
||||
|
||||
public SubnauticaUweWorldEntityFactory(Dictionary<string, WorldEntityInfo> worldEntitiesByClassId)
|
||||
{
|
||||
this.worldEntitiesByClassId = worldEntitiesByClassId;
|
||||
}
|
||||
|
||||
public bool TryFind(string classId, out UweWorldEntity uweWorldEntity)
|
||||
{
|
||||
if (worldEntitiesByClassId.TryGetValue(classId, out WorldEntityInfo worldEntityInfo))
|
||||
{
|
||||
uweWorldEntity = new(worldEntityInfo.classId,
|
||||
worldEntityInfo.techType.ToDto(),
|
||||
worldEntityInfo.slotType.ToString(),
|
||||
worldEntityInfo.prefabZUp,
|
||||
(int)worldEntityInfo.cellLevel,
|
||||
worldEntityInfo.localScale.ToDto());
|
||||
|
||||
return true;
|
||||
}
|
||||
uweWorldEntity = null;
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
using System.Runtime.Serialization;
|
||||
using NitroxModel.DataStructures.Surrogates;
|
||||
using NitroxModel.DataStructures.Unity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxModel_Subnautica.DataStructures.Surrogates
|
||||
{
|
||||
[DataContract]
|
||||
public class QuaternionSurrogate : SerializationSurrogate<Quaternion>
|
||||
{
|
||||
[DataMember(Order = 1)]
|
||||
public float X { get; private set; }
|
||||
|
||||
[DataMember(Order = 2)]
|
||||
public float Y { get; private set; }
|
||||
|
||||
[DataMember(Order = 3)]
|
||||
public float Z { get; private set; }
|
||||
|
||||
[DataMember(Order = 4)]
|
||||
public float W { get; private set; }
|
||||
|
||||
protected override void GetObjectData(Quaternion quaternion, SerializationInfo info)
|
||||
{
|
||||
info.AddValue("w", quaternion.w);
|
||||
info.AddValue("x", quaternion.x);
|
||||
info.AddValue("y", quaternion.y);
|
||||
info.AddValue("z", quaternion.z);
|
||||
}
|
||||
|
||||
protected override Quaternion SetObjectData(Quaternion quaternion, SerializationInfo info)
|
||||
{
|
||||
quaternion.w = info.GetSingle("w");
|
||||
quaternion.x = info.GetSingle("x");
|
||||
quaternion.y = info.GetSingle("y");
|
||||
quaternion.z = info.GetSingle("z");
|
||||
return quaternion;
|
||||
}
|
||||
|
||||
public static implicit operator QuaternionSurrogate(Quaternion v)
|
||||
{
|
||||
return new QuaternionSurrogate
|
||||
{
|
||||
X = v.x,
|
||||
Y = v.y,
|
||||
W = v.w,
|
||||
Z = v.z
|
||||
};
|
||||
}
|
||||
|
||||
public static implicit operator Quaternion(QuaternionSurrogate surrogate)
|
||||
{
|
||||
return new Quaternion(surrogate.X, surrogate.Y, surrogate.Z, surrogate.W);
|
||||
}
|
||||
|
||||
public static implicit operator QuaternionSurrogate(NitroxQuaternion v)
|
||||
{
|
||||
return new QuaternionSurrogate
|
||||
{
|
||||
X = v.X,
|
||||
Y = v.Y,
|
||||
W = v.W,
|
||||
Z = v.Z
|
||||
};
|
||||
}
|
||||
|
||||
public static implicit operator NitroxQuaternion(QuaternionSurrogate surrogate)
|
||||
{
|
||||
return new NitroxQuaternion(surrogate.X, surrogate.Y, surrogate.Z, surrogate.W);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
using System.Runtime.Serialization;
|
||||
using NitroxModel.DataStructures.Surrogates;
|
||||
using NitroxModel.DataStructures.Unity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxModel_Subnautica.DataStructures.Surrogates
|
||||
{
|
||||
[DataContract]
|
||||
public class Vector3Surrogate : SerializationSurrogate<Vector3>
|
||||
{
|
||||
[DataMember(Order = 1)]
|
||||
public float X { get; private set; }
|
||||
|
||||
[DataMember(Order = 2)]
|
||||
public float Y { get; private set; }
|
||||
|
||||
[DataMember(Order = 3)]
|
||||
public float Z { get; private set; }
|
||||
|
||||
protected override void GetObjectData(Vector3 vector3, SerializationInfo info)
|
||||
{
|
||||
info.AddValue("x", vector3.x);
|
||||
info.AddValue("y", vector3.y);
|
||||
info.AddValue("z", vector3.z);
|
||||
}
|
||||
|
||||
protected override Vector3 SetObjectData(Vector3 vector3, SerializationInfo info)
|
||||
{
|
||||
vector3.x = info.GetSingle("x");
|
||||
vector3.y = info.GetSingle("y");
|
||||
vector3.z = info.GetSingle("z");
|
||||
return vector3;
|
||||
}
|
||||
|
||||
public static implicit operator Vector3Surrogate(NitroxVector3 v)
|
||||
{
|
||||
return new Vector3Surrogate
|
||||
{
|
||||
X = v.X,
|
||||
Y = v.Y,
|
||||
Z = v.Z
|
||||
};
|
||||
}
|
||||
|
||||
public static implicit operator NitroxVector3(Vector3Surrogate surrogate)
|
||||
{
|
||||
return new NitroxVector3(surrogate.X, surrogate.Y, surrogate.Z);
|
||||
}
|
||||
|
||||
public static implicit operator Vector3Surrogate(Vector3 v)
|
||||
{
|
||||
return new Vector3Surrogate
|
||||
{
|
||||
X = v.x,
|
||||
Y = v.y,
|
||||
Z = v.z
|
||||
};
|
||||
}
|
||||
|
||||
public static implicit operator Vector3(Vector3Surrogate surrogate)
|
||||
{
|
||||
return new Vector3(surrogate.X, surrogate.Y, surrogate.Z);
|
||||
}
|
||||
}
|
||||
}
|
6
NitroxModel-Subnautica/Helper/SubnauticaConstants.cs
Normal file
6
NitroxModel-Subnautica/Helper/SubnauticaConstants.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace NitroxModel_Subnautica.Helper;
|
||||
|
||||
public static class SubnauticaConstants
|
||||
{
|
||||
public const string LIGHTMAPPED_PREFAB_NAME = "__LIGHTMAPPED_PREFAB__";
|
||||
}
|
40
NitroxModel-Subnautica/Helper/SubnauticaMap.cs
Normal file
40
NitroxModel-Subnautica/Helper/SubnauticaMap.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.DataStructures.GameLogic;
|
||||
using NitroxModel.Helper;
|
||||
|
||||
namespace NitroxModel_Subnautica.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// Static information about the game world loaded by Subnautica that isn't (and shouldn't) be retrievable from the game directly.
|
||||
/// </summary>
|
||||
public class SubnauticaMap : IMap
|
||||
{
|
||||
private const int BATCH_SIZE = 160;
|
||||
private const int SKYBOX_METERS_ABOVE_WATER = 160;
|
||||
|
||||
/// <summary>
|
||||
/// TechType can't be introspected at runtime in RELEASE mode because its reflection info is elided.
|
||||
/// </summary>
|
||||
public static readonly List<NitroxTechType> GLOBAL_ROOT_TECH_TYPES = new List<NitroxTechType>
|
||||
{
|
||||
new NitroxTechType(nameof(TechType.Pipe)),
|
||||
new NitroxTechType(nameof(TechType.Constructor)),
|
||||
new NitroxTechType(nameof(TechType.Flare)),
|
||||
new NitroxTechType(nameof(TechType.Gravsphere)),
|
||||
new NitroxTechType(nameof(TechType.PipeSurfaceFloater)),
|
||||
new NitroxTechType(nameof(TechType.SmallStorage)),
|
||||
new NitroxTechType(nameof(TechType.CyclopsDecoy)),
|
||||
new NitroxTechType(nameof(TechType.LEDLight)),
|
||||
new NitroxTechType(nameof(TechType.Beacon))
|
||||
};
|
||||
|
||||
public int ItemLevelOfDetail => 3;
|
||||
public int BatchSize => 160;
|
||||
public NitroxInt3 BatchDimensions => new NitroxInt3(BatchSize, BatchSize, BatchSize);
|
||||
public NitroxInt3 DimensionsInMeters => new NitroxInt3(4096, 3200, 4096);
|
||||
public NitroxInt3 DimensionsInBatches => NitroxInt3.Ceil(DimensionsInMeters / BATCH_SIZE);
|
||||
public NitroxInt3 BatchDimensionCenter => new NitroxInt3(DimensionsInMeters.X / 2, DimensionsInMeters.Y - SKYBOX_METERS_ABOVE_WATER, DimensionsInMeters.Z / 2);
|
||||
public List<NitroxTechType> GlobalRootTechTypes { get; } = GLOBAL_ROOT_TECH_TYPES;
|
||||
}
|
||||
}
|
32
NitroxModel-Subnautica/Helper/TextureScaler.cs
Normal file
32
NitroxModel-Subnautica/Helper/TextureScaler.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxModel_Subnautica.Helper
|
||||
{
|
||||
public static class TextureScaler
|
||||
{
|
||||
public static void Scale(Texture2D tex, int width, int height, FilterMode mode = FilterMode.Trilinear)
|
||||
{
|
||||
Rect texR = new Rect(0, 0, width, height);
|
||||
GpuScale(tex, width, height, mode);
|
||||
|
||||
tex.Resize(width, height);
|
||||
tex.ReadPixels(texR, 0, 0, true);
|
||||
tex.Apply(true);
|
||||
}
|
||||
|
||||
internal static void GpuScale(Texture2D src, int width, int height, FilterMode fmode)
|
||||
{
|
||||
src.filterMode = fmode;
|
||||
src.Apply(true);
|
||||
|
||||
RenderTexture rtt = new RenderTexture(width, height, 32);
|
||||
|
||||
Graphics.SetRenderTarget(rtt);
|
||||
|
||||
GL.LoadPixelMatrix(0, 1, 1, 0);
|
||||
|
||||
GL.Clear(true, true, new Color(0, 0, 0, 0));
|
||||
Graphics.DrawTexture(new Rect(0, 0, 1, 1), src);
|
||||
}
|
||||
}
|
||||
}
|
65
NitroxModel-Subnautica/Helper/VehicleHelper.cs
Normal file
65
NitroxModel-Subnautica/Helper/VehicleHelper.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using NitroxModel.DataStructures.Unity;
|
||||
|
||||
namespace NitroxModel_Subnautica.Helper
|
||||
{
|
||||
public static class VehicleHelper
|
||||
{
|
||||
public static NitroxVector3[] GetDefaultColours(TechType techType)
|
||||
{
|
||||
switch (techType)
|
||||
{
|
||||
case TechType.Seamoth:
|
||||
return new[] {
|
||||
new NitroxVector3(0f, 0f, 1f),
|
||||
new NitroxVector3(0f, 0f, 0f),
|
||||
new NitroxVector3(0f, 0f, 1f),
|
||||
new NitroxVector3(0.577f, 0.447f, 0.604f),
|
||||
new NitroxVector3(0.114f, 0.729f, 0.965f)
|
||||
};
|
||||
case TechType.Exosuit:
|
||||
return new[] {
|
||||
new NitroxVector3(0f, 0f, 1f), //_Color
|
||||
new NitroxVector3(0f, 0f, 0f), //_Tint
|
||||
new NitroxVector3(0f, 0f, 1f), //_Color
|
||||
new NitroxVector3(0.577f, 0.447f, 0.604f),//_Color2
|
||||
new NitroxVector3(0.114f, 0.729f, 0.965f) //_Color3
|
||||
};
|
||||
|
||||
case TechType.Cyclops:
|
||||
return new[]
|
||||
{
|
||||
new NitroxVector3(1f, 0f, 1f),
|
||||
new NitroxVector3(0.6f, 0.4f, 0.4f),
|
||||
new NitroxVector3(0.1f, 0.8f, 1f),
|
||||
new NitroxVector3(0f, 0f, 0f)
|
||||
};
|
||||
|
||||
default:
|
||||
return GetPrimalDefaultColours();
|
||||
}
|
||||
}
|
||||
|
||||
public static NitroxVector3[] GetPrimalDefaultColours()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
new NitroxVector3(0f, 0f, 1f)
|
||||
};
|
||||
}
|
||||
|
||||
public static bool IsVehicle(TechType techtype)
|
||||
{
|
||||
switch (techtype)
|
||||
{
|
||||
case TechType.Seamoth:
|
||||
case TechType.Exosuit:
|
||||
case TechType.Cyclops:
|
||||
case TechType.RocketBase:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
22
NitroxModel-Subnautica/Logger/SubnauticaInGameLogger.cs
Normal file
22
NitroxModel-Subnautica/Logger/SubnauticaInGameLogger.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using NitroxModel.Logger;
|
||||
|
||||
namespace NitroxModel_Subnautica.Logger
|
||||
{
|
||||
/// <summary>
|
||||
/// Log handler for logging and showing information to the player.
|
||||
/// The log is also written to the log file.
|
||||
/// </summary>
|
||||
public class SubnauticaInGameLogger : InGameLogger
|
||||
{
|
||||
public void Log(object message) => Log(message?.ToString());
|
||||
public void Log(string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Logs to the top-left of the screen using UWE code.
|
||||
ErrorMessage.AddMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
16
NitroxModel-Subnautica/NitroxModel-Subnautica.csproj
Normal file
16
NitroxModel-Subnautica/NitroxModel-Subnautica.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net472;net9.0</TargetFrameworks>
|
||||
<RootNamespace>NitroxModel_Subnautica</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NitroxModel\NitroxModel.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LitJson" Version="0.19.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
49
NitroxModel-Subnautica/Packets/CyclopsDamage.cs
Normal file
49
NitroxModel-Subnautica/Packets/CyclopsDamage.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.Packets;
|
||||
using NitroxModel_Subnautica.DataStructures.GameLogic;
|
||||
|
||||
namespace NitroxModel_Subnautica.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// A state update packet for the Cyclops that could be sent due to a <see cref="CyclopsDamagePoint"/> create/repair, <see cref="SubFire"/> create/extinguish,
|
||||
/// or a general Cyclops health change. A health change to 0 means the Cyclops has been destroyed.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class CyclopsDamage : Packet
|
||||
{
|
||||
public NitroxId Id { get; }
|
||||
public float SubHealth { get; }
|
||||
public float DamageManagerHealth { get; }
|
||||
public float SubFireHealth { get; }
|
||||
public int[] DamagePointIndexes { get; }
|
||||
public CyclopsFireData[] RoomFires { get; }
|
||||
public CyclopsDamageInfoData DamageInfo { get; }
|
||||
|
||||
/// <param name="id"><see cref="SubRoot"/> Id.</param>
|
||||
/// <param name="subHealth"><see cref="SubRoot.liveMixin.health"/>.</param>
|
||||
/// <param name="damageManagerHealth"><see cref="CyclopsExternalDamageManager.subLiveMixin.health"/>.</param>
|
||||
/// <param name="subFireHealth"><see cref="SubFire.liveMixin.health"/>.</param>
|
||||
/// <param name="damagePointIndexes"><see cref="CyclopsExternalDamageManager.damagePoints"/> where <see cref="GameObject.activeSelf"/>.
|
||||
/// Null if only a Cyclops health change.</param>
|
||||
/// <param name="roomFires"><see cref="SubFire.RoomFire.spawnNodes"/> where <see cref="Transform.childCount"/> > 0.
|
||||
/// Null if only a Cyclops health change.</param>
|
||||
/// <param name="damageInfo">Null if a repair or extinguish.</param>
|
||||
public CyclopsDamage(NitroxId id, float subHealth, float damageManagerHealth, float subFireHealth, int[] damagePointIndexes, CyclopsFireData[] roomFires, CyclopsDamageInfoData damageInfo = null)
|
||||
{
|
||||
Id = id;
|
||||
SubHealth = subHealth;
|
||||
DamageManagerHealth = damageManagerHealth;
|
||||
SubFireHealth = subFireHealth;
|
||||
DamagePointIndexes = damagePointIndexes;
|
||||
RoomFires = roomFires;
|
||||
DamageInfo = damageInfo;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[CyclopsDamage - Id: {Id}, SubHealth: {SubHealth}, DamageManagerHealth: {DamageManagerHealth}, SubFireHealth: {SubFireHealth}{(DamagePointIndexes == null ? "" : $" DamagePointIndexes: {string.Join(", ", DamagePointIndexes.Select(x => x.ToString()).ToArray())}")}{(RoomFires == null ? "" : $" RoomFires: {string.Join(", ", RoomFires.Select(x => x.ToString()).ToArray())}")}{(DamageInfo == null ? "" : $" DamageInfo: DealerId: {DamageInfo?.DealerId}")}";
|
||||
}
|
||||
}
|
||||
}
|
28
NitroxModel-Subnautica/Packets/CyclopsDamagePointRepaired.cs
Normal file
28
NitroxModel-Subnautica/Packets/CyclopsDamagePointRepaired.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.Packets;
|
||||
|
||||
namespace NitroxModel_Subnautica.Packets
|
||||
{
|
||||
[Serializable]
|
||||
public class CyclopsDamagePointRepaired : Packet
|
||||
{
|
||||
public NitroxId Id { get; }
|
||||
public int DamagePointIndex { get; }
|
||||
public float RepairAmount { get; }
|
||||
|
||||
/// <param name="id">The Cyclops id</param>
|
||||
/// <param name="repairAmount">The amount to repair the damage by. A large repair amount is passed if the point is meant to be fully repaired</param>
|
||||
public CyclopsDamagePointRepaired(NitroxId id, int damagePointIndex, float repairAmount)
|
||||
{
|
||||
Id = id;
|
||||
DamagePointIndex = damagePointIndex;
|
||||
RepairAmount = repairAmount;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[CyclopsDamagePointRepaired - Id: {Id}, DamagePointIndex: {DamagePointIndex}, RepairAmount: {RepairAmount}]";
|
||||
}
|
||||
}
|
||||
}
|
22
NitroxModel-Subnautica/Packets/CyclopsDecoyLaunch.cs
Normal file
22
NitroxModel-Subnautica/Packets/CyclopsDecoyLaunch.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.Packets;
|
||||
|
||||
namespace NitroxModel_Subnautica.Packets
|
||||
{
|
||||
[Serializable]
|
||||
public class CyclopsDecoyLaunch : Packet
|
||||
{
|
||||
public NitroxId Id { get; }
|
||||
|
||||
public CyclopsDecoyLaunch(NitroxId id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[CyclopsDecoyLaunch - Id: {Id}]";
|
||||
}
|
||||
}
|
||||
}
|
32
NitroxModel-Subnautica/Packets/CyclopsFireCreated.cs
Normal file
32
NitroxModel-Subnautica/Packets/CyclopsFireCreated.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.Packets;
|
||||
using NitroxModel_Subnautica.DataStructures.GameLogic;
|
||||
|
||||
namespace NitroxModel_Subnautica.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Triggered when a fire has been created in <see cref="SubFire.CreateFire(SubFire.RoomFire)"/>
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class CyclopsFireCreated : Packet
|
||||
{
|
||||
public CyclopsFireData FireCreatedData { get; }
|
||||
|
||||
public CyclopsFireCreated(NitroxId id, NitroxId cyclopsId, CyclopsRooms room, int nodeIndex)
|
||||
{
|
||||
FireCreatedData = new CyclopsFireData(id, cyclopsId, room, nodeIndex);
|
||||
}
|
||||
|
||||
/// <remarks>Used for deserialization</remarks>
|
||||
public CyclopsFireCreated(CyclopsFireData fireCreatedData)
|
||||
{
|
||||
FireCreatedData = fireCreatedData;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[CyclopsFireCreated - {FireCreatedData}]";
|
||||
}
|
||||
}
|
||||
}
|
23
NitroxModel-Subnautica/Packets/CyclopsFireSuppression.cs
Normal file
23
NitroxModel-Subnautica/Packets/CyclopsFireSuppression.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.Packets;
|
||||
|
||||
namespace NitroxModel_Subnautica.Packets
|
||||
{
|
||||
[Serializable]
|
||||
public class CyclopsFireSuppression : Packet
|
||||
{
|
||||
public NitroxId Id { get; }
|
||||
|
||||
public CyclopsFireSuppression(NitroxId id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[CyclopsFireSuppressionSystem - Id: {Id}]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
39
NitroxModel-Subnautica/Packets/ExosuitArmActionPacket.cs
Normal file
39
NitroxModel-Subnautica/Packets/ExosuitArmActionPacket.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.DataStructures.Unity;
|
||||
using NitroxModel.Packets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxModel_Subnautica.Packets
|
||||
{
|
||||
[Serializable]
|
||||
public class ExosuitArmActionPacket : Packet
|
||||
{
|
||||
public TechType TechType { get; }
|
||||
public NitroxId ArmId { get; }
|
||||
public ExosuitArmAction ArmAction { get; }
|
||||
public NitroxVector3? OpVector { get; }
|
||||
public NitroxQuaternion? OpRotation { get; }
|
||||
|
||||
public ExosuitArmActionPacket(TechType techType, NitroxId armId, ExosuitArmAction armAction, NitroxVector3? opVector, NitroxQuaternion? opRotation)
|
||||
{
|
||||
TechType = techType;
|
||||
ArmId = armId;
|
||||
ArmAction = armAction;
|
||||
OpVector = opVector;
|
||||
OpRotation = opRotation;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[ExosuitArmAction - TechType: {TechType}, ArmId:{ArmId}, ArmAction: {ArmAction}, Vector: {OpVector}, Rotation: {OpRotation}]";
|
||||
}
|
||||
}
|
||||
|
||||
public enum ExosuitArmAction
|
||||
{
|
||||
START_USE_TOOL,
|
||||
END_USE_TOOL,
|
||||
ALT_HIT
|
||||
}
|
||||
}
|
16
NitroxModel-Subnautica/Packets/RocketLaunch.cs
Normal file
16
NitroxModel-Subnautica/Packets/RocketLaunch.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.Packets;
|
||||
|
||||
namespace NitroxModel_Subnautica.Packets;
|
||||
|
||||
[Serializable]
|
||||
public class RocketLaunch : Packet
|
||||
{
|
||||
public NitroxId RocketId { get; }
|
||||
|
||||
public RocketLaunch(NitroxId rocketId)
|
||||
{
|
||||
RocketId = rocketId;
|
||||
}
|
||||
}
|
19
NitroxModel-Subnautica/Packets/RocketResync.cs
Normal file
19
NitroxModel-Subnautica/Packets/RocketResync.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.Packets;
|
||||
|
||||
namespace NitroxModel_Subnautica.Packets;
|
||||
|
||||
[Serializable]
|
||||
public class RocketResync : Packet
|
||||
{
|
||||
public NitroxId RocketId { get; }
|
||||
public List<PreflightCheck> PreflightChecks { get; }
|
||||
|
||||
public RocketResync(NitroxId rocketId, List<PreflightCheck> preflightChecks)
|
||||
{
|
||||
RocketId = rocketId;
|
||||
PreflightChecks = preflightChecks;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user