Blueprints & Resources

Added the ability to associate simple commodities with resource maps
Added resource placement to zone generator
Added crafting blueprints and stat addressing system
Refactored Thrusters and Shields into Behaviors
Fixed server losing database connection
Updated icons
This commit is contained in:
hyperion51 2020-04-09 07:48:45 +01:00
commit fd92c80876
58 changed files with 1399 additions and 855 deletions

View file

@ -81,4 +81,14 @@ public class RangedIntInspectableAttribute : InspectableFieldAttribute
Min = min;
Max = max;
}
}
public class InspectableTypeAttribute : InspectableFieldAttribute
{
public readonly Type Type;
public InspectableTypeAttribute(Type type)
{
Type = type;
}
}

View file

@ -0,0 +1,55 @@
using System;
using System.Collections;
using System.Collections.Generic;
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class BlueprintData : DatabaseEntry, INamedEntry
{
[InspectableField, JsonProperty("name"), Key(1)]
public string Name;
[InspectableField, JsonProperty("ingredients"), Key(2)]
public Dictionary<Guid, int> Ingredients = new Dictionary<Guid, int>();
[InspectableDatabaseLink(typeof(CraftedItemData)), JsonProperty("item"), Key(3)]
public Guid Item;
[InspectableField, JsonProperty("quantity"), Key(4)]
public int Quantity;
[InspectableField, JsonProperty("difficulty"), Key(5)]
public int Difficulty;
[InspectableField, JsonProperty("statEffects"), Key(6)]
public List<BlueprintStatEffect> StatEffects = new List<BlueprintStatEffect>();
[IgnoreMember] public string EntryName
{
get => Name;
set => Name = value;
}
}
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class BlueprintStatEffect
{
[InspectableField, JsonProperty("ingredient"), Key(1)]
public Guid Ingredient;
[InspectableField, JsonProperty("stat"), Key(2)]
public StatReference StatReference = new StatReference();
}
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class StatReference
{
[InspectableType(typeof(IItemBehaviorData)), JsonProperty("behavior"), Key(1)]
public string Behavior;
[InspectableField, JsonProperty("stat"), Key(2)]
public string Stat;
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f2b1f367d240824408eb1e151c60bc79
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -16,51 +16,42 @@ public interface INamedEntry
string EntryName { get; set; }
}
[InspectableField]
[MessagePackObject]
[Union(0, typeof(SimpleCommodityData))]
[Union(1, typeof(CompoundCommodityData))]
[Union(2, typeof(GearData))]
[Union(3, typeof(HullData))]
[Union(4, typeof(ShieldData))]
[Union(5, typeof(ThrusterData))]
[Union(6, typeof(SimpleCommodity))]
[Union(7, typeof(CompoundCommodity))]
[Union(8, typeof(Gear))]
[Union(9, typeof(GlobalData))]
[Union(10, typeof(ZoneData))]
[Union(11, typeof(Player))]
[Union(12, typeof(Corporation))]
[Union(13, typeof(Ship))]
[Union(14, typeof(Station))]
[Union(15, typeof(OrbitData))]
[Union(16, typeof(PlanetData))]
[JsonObject(MemberSerialization.OptIn)]
[JsonConverter(typeof(JsonKnownTypesConverter<DatabaseEntry>))]
[InspectableField,
MessagePackObject,
Union(0, typeof(SimpleCommodityData)),
Union(1, typeof(CompoundCommodityData)),
Union(2, typeof(GearData)),
Union(3, typeof(HullData)),
Union(6, typeof(SimpleCommodity)),
Union(7, typeof(CompoundCommodity)),
Union(8, typeof(Gear)),
Union(9, typeof(GlobalData)),
Union(10, typeof(ZoneData)),
Union(11, typeof(Player)),
Union(12, typeof(Corporation)),
Union(13, typeof(Ship)),
Union(14, typeof(Station)),
Union(15, typeof(OrbitData)),
Union(16, typeof(PlanetData)),
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<DatabaseEntry>))]
//[Union(21, typeof(ContractData))]
//[Union(22, typeof(Station))]
public abstract class DatabaseEntry
{
[JsonProperty("id")] [Key(0)] public Guid ID = Guid.NewGuid();
[JsonProperty("id"), Key(0)] public Guid ID = Guid.NewGuid();
[IgnoreMember] public GameContext Context { get; set; }
}
[RethinkTable("Users")]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[RethinkTable("Users"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class Player : DatabaseEntry, INamedEntry
{
[JsonProperty("email")] [Key(1)]
public string Email;
[JsonProperty("password")] [Key(2)]
public string Password;
[JsonProperty("username")] [Key(3)]
public string Username;
[JsonProperty("corporation")] [Key(4)]
public Guid Corporation;
[JsonProperty("email"), Key(1)] public string Email;
[JsonProperty("password"), Key(2)] public string Password;
[JsonProperty("username"), Key(3)] public string Username;
[JsonProperty("corporation"), Key(4)] public Guid Corporation;
[IgnoreMember] public string EntryName
{
@ -69,13 +60,10 @@ public class Player : DatabaseEntry, INamedEntry
}
}
[RethinkTable("Galaxy")]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class Corporation : DatabaseEntry, INamedEntry
{
[JsonProperty("name")] [Key(1)]
public string Name;
[JsonProperty("name"), Key(1)] public string Name;
[IgnoreMember] public string EntryName
{

View file

@ -1,3 +1,5 @@
using System;
public enum LauncherCaliber
{
Micro,
@ -29,4 +31,15 @@ public enum DamageType
Thermal,
Optical,
Ionizing
}
[Flags]
public enum BodyType
{
None = 0,
Asteroid = 1 << 0,
Planetoid = 1 << 1,
Planet = 1 << 2,
GasGiant = 1 << 3,
Sun = 1 << 4
}

View file

@ -68,6 +68,8 @@ public static class Extensions
private static Random? _random;
private static Random Random => (Random) (_random ?? (_random = new Random(1337)));
public static T RandomElement<T>(this IEnumerable<T> enumerable) => enumerable.ElementAt(Random.NextInt(0, enumerable.Count()));
public static float NextUnbounded(this Random random) => 1 / (1 - random.NextFloat()) - 1;
public static float NextUnbounded(this Random random, float bias, float power) => 1 / (1 - pow(random.NextFloat(), 1 - pow(clamp(bias,0,.99f), 1 / power))) - 1;
private static Dictionary<Type,Type[]> InterfaceClasses = new Dictionary<Type, Type[]>();
public static Type[] GetAllInterfaceClasses(this Type type)

View file

@ -6,15 +6,17 @@ using static Unity.Mathematics.math;
public class GameContext
{
private Action<string> _logger;
private DatabaseCache _cache;
public GlobalData GlobalData => _cache.GetAll<GlobalData>().FirstOrDefault();
private readonly Dictionary<CraftedItemData, int> Tier = new Dictionary<CraftedItemData, int>();
// private readonly Dictionary<CraftedItemData, int> Tier = new Dictionary<CraftedItemData, int>();
public GameContext(DatabaseCache cache)
public GameContext(DatabaseCache cache, Action<string> logger)
{
_cache = cache;
_logger = logger;
var globalData = _cache.GetAll<GlobalData>().FirstOrDefault();
if (globalData == null)
{
@ -23,14 +25,14 @@ public class GameContext
}
}
public int ItemTier(CraftedItemData itemData)
{
if (Tier.ContainsKey(itemData)) return Tier[itemData];
Tier[itemData] = itemData.Ingredients.Keys.Max(ci => _cache.Get<ItemData>(ci) is CraftedItemData craftableIngredient ? ItemTier(craftableIngredient) : 0);
return Tier[itemData];
}
// public int ItemTier(CraftedItemData itemData)
// {
// if (Tier.ContainsKey(itemData)) return Tier[itemData];
//
// Tier[itemData] = itemData.Ingredients.Keys.Max(ci => _cache.Get<ItemData>(ci) is CraftedItemData craftableIngredient ? ItemTier(craftableIngredient) : 0);
//
// return Tier[itemData];
// }
public ItemData GetData(ItemInstance item)
{
@ -80,21 +82,70 @@ public class GameContext
return 0;
}
private Dictionary<BlueprintStatEffect, PerformanceStat> AffectedStats =
new Dictionary<BlueprintStatEffect, PerformanceStat>();
public PerformanceStat GetAffectedStat(BlueprintData blueprint, BlueprintStatEffect effect)
{
// We've already cached this effect's stat, return it directly
if (AffectedStats.ContainsKey(effect)) return AffectedStats[effect];
// Get the data for the item the blueprint is for, return null if not found or not equippable
var blueprintItem = _cache.Get<EquippableItemData>(blueprint.Item);
if (blueprintItem == null)
{
_logger($"Attempted to get stat effect but Blueprint {blueprint.ID} is not for an equippable item!");
return AffectedStats[effect] = null;
}
// Get the first behavior of the type specified in the blueprint stat effect, return null if not found
var effectBehavior =
blueprintItem.Behaviors.FirstOrDefault(b => b.GetType().Name == effect.StatReference.Behavior);
if (effectBehavior == null)
{
_logger($"Attempted to get stat effect for Blueprint {blueprint.ID} but stat references missing behavior \"{effect.StatReference.Behavior}\"!");
return AffectedStats[effect] = null;
}
// Get the first field in the behavior matching the name specified in the stat effect, return null if not found
var type = effectBehavior.GetType();
var field = type.GetField(effect.StatReference.Stat);
if (field == null)
{
_logger($"Attempted to get stat effect for Blueprint {blueprint.ID} but behavior {effect.StatReference.Behavior} does not have a stat named \"{effect.StatReference.Stat}\"!");
return AffectedStats[effect] = null;
}
// Finally we've confirmed the stat effect is valid, return the affected stat
return AffectedStats[effect] = field.GetValue(effectBehavior) as PerformanceStat;
}
// Determine quality of either the item itself or the specific ingredient this stat depends on
public float Quality(PerformanceStat stat, Gear item)
{
Guid? ingredientID = stat.Ingredient;
var activeEffects = item.Blueprint.StatEffects.Where(x => GetAffectedStat(item.Blueprint, x) == stat).ToArray();
float quality;
if (ingredientID == null)
if (!activeEffects.Any())
quality = item.CompoundQuality();
else
{
var ingredientInstance =
item.Ingredients.FirstOrDefault(i => i.Data == ingredientID) as CraftedItemInstance;
if (ingredientInstance == null)
throw new InvalidOperationException(
$"Item {item.ID} has invalid crafting ingredients!");
quality = ingredientInstance.CompoundQuality();
var ingredients = item.Ingredients.Where(i => activeEffects.Any(e => e.Ingredient == i.Data)).ToArray();
if(ingredients.Length != activeEffects.Length)
{
_logger($"Item {item.ID} does not have the ingredients specified by the stat effects of its blueprint!");
return 0;
}
float sum = 0;
foreach (var i in ingredients)
{
if (i is CraftedItemInstance ci)
sum += ci.CompoundQuality();
else _logger($"Blueprint stat effect for item {item.ID} specifies invalid (non crafted) ingredient!");
}
quality = sum / ingredients.Length;
}
return quality;
@ -143,7 +194,8 @@ public class GameContext
ID = Guid.NewGuid()
};
throw new InvalidOperationException("Attempted to create Simple Commodity instance using missing or incorrect item id");
_logger("Attempted to create Simple Commodity instance using missing or incorrect item id");
return null;
}
public CraftedItemInstance CreateInstance(Guid data, float quality)
@ -151,10 +203,18 @@ public class GameContext
var item = _cache.Get<CraftedItemData>(data);
if (item == null)
{
throw new InvalidOperationException("Attempted to create crafted item instance using missing or incorrect item id");
_logger("Attempted to create crafted item instance using missing or incorrect item id!");
return null;
}
var ingredients = item.Ingredients.SelectMany(ci =>
var blueprint = _cache.GetAll<BlueprintData>().FirstOrDefault(b => b.Item == data);
if (blueprint == null)
{
_logger("Attempted to create crafted item instance which has no blueprint!");
return null;
}
var ingredients = blueprint.Ingredients.SelectMany(ci =>
{
var ingredient = _cache.Get(ci.Key);
return ingredient is SimpleCommodityData

View file

@ -8,95 +8,95 @@ using static Unity.Mathematics.math;
using static Unity.Mathematics.noise;
using static NoiseFbm;
[Serializable]
[RethinkTable("Galaxy")]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[Serializable, RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class GlobalData : DatabaseEntry
{
[InspectableField] [JsonProperty("targetPersistenceDuration")] [Key(1)]
[InspectableField, JsonProperty("targetPersistenceDuration"), Key(1)]
public float TargetPersistenceDuration = 3;
[InspectableField] [JsonProperty("heatRadiationPower")] [Key(2)]
[InspectableField, JsonProperty("heatRadiationPower"), Key(2)]
public float HeatRadiationPower = 1;
[InspectableField] [JsonProperty("heatRadiationMultiplier")] [Key(3)]
[InspectableField, JsonProperty("heatRadiationMultiplier"), Key(3)]
public float HeatRadiationMultiplier = 1;
[InspectableField] [JsonProperty("galaxyArms")] [Key(13)]
[InspectableField, JsonProperty("galaxyArms"), Key(4)]
public int Arms = 4;
[InspectableField] [JsonProperty("galaxyTwist")] [Key(14)]
[InspectableField, JsonProperty("galaxyTwist"), Key(5)]
public float Twist = 10;
[InspectableField] [JsonProperty("galaxyTwistPower")] [Key(15)]
[InspectableField, JsonProperty("galaxyTwistPower"), Key(6)]
public float TwistPower = 2;
[InspectableField] [JsonProperty("radiusPower")] [Key(4)]
[InspectableField, JsonProperty("radiusPower"), Key(7)]
public float RadiusPower = 1.75f;
[InspectableField] [JsonProperty("massFloor")] [Key(5)]
[InspectableField, JsonProperty("massFloor"), Key(8)]
public float MassFloor = 1;
[InspectableField] [JsonProperty("sunMass")] [Key(6)]
[InspectableField, JsonProperty("sunMass"), Key(9)]
public float SunMass = 10000;
[InspectableField] [JsonProperty("gasGiantMass")] [Key(7)]
[InspectableField, JsonProperty("gasGiantMass"), Key(10)]
public float GasGiantMass = 2000;
[InspectableField] [JsonProperty("dockingDistance")] [Key(8)]
[InspectableField, JsonProperty("dockingDistance"), Key(11)]
public float DockingDistance = 10;
[InspectableField] [JsonProperty("satelliteCreationMassFloor")] [Key(9)]
[InspectableField, JsonProperty("satelliteCreationMassFloor"), Key(12)]
public float SatelliteCreationMassFloor = 100;
[InspectableField] [JsonProperty("satelliteCreationProbability")] [Key(10)]
[InspectableField, JsonProperty("satelliteCreationProbability"), Key(13)]
public float SatelliteCreationProbability = .25f;
[InspectableField] [JsonProperty("binaryCreationProbability")] [Key(11)]
[InspectableField, JsonProperty("binaryCreationProbability"), Key(14)]
public float BinaryCreationProbability = .25f;
[InspectableField] [JsonProperty("rosetteProbability")] [Key(12)]
[InspectableField, JsonProperty("rosetteProbability"), Key(15)]
public float RosetteProbability = .25f;
[InspectableField] [JsonProperty("mapLayers")] [Key(16)]
public Dictionary<string, Guid> MapLayers = new Dictionary<string, Guid>();
[InspectableField] [JsonProperty("zoneRadiusMin")] [Key(17)]
// [InspectableField] [JsonProperty("mapLayers")] [Key(16)]
// public Dictionary<string, Guid> MapLayers = new Dictionary<string, Guid>();
[InspectableField, JsonProperty("zoneRadiusMin"), Key(16)]
public float MinimumZoneRadius = 500;
[InspectableField] [JsonProperty("zoneRadiusMax")] [Key(18)]
[InspectableField, JsonProperty("zoneRadiusMax"), Key(17)]
public float MaximumZoneRadius = 2000;
[InspectableField] [JsonProperty("zoneMassMin")] [Key(19)]
[InspectableField, JsonProperty("zoneMassMin"), Key(18)]
public float MinimumZoneMass = 10000;
[InspectableField] [JsonProperty("zoneMassMax")] [Key(20)]
[InspectableField, JsonProperty("zoneMassMax"), Key(19)]
public float MaximumZoneMass = 100000;
[InspectableField] [JsonProperty("orbitPeriodExponent")] [Key(21)]
[InspectableField, JsonProperty("orbitPeriodExponent"), Key(20)]
public float OrbitPeriodExponent = 1.5f;
[InspectableField] [JsonProperty("orbitPeriodMultiplier")] [Key(22)]
[InspectableField, JsonProperty("orbitPeriodMultiplier"), Key(21)]
public float OrbitPeriodMultiplier = 1f;
[InspectableField] [JsonProperty("gravityRadiusExponent")] [Key(23)]
[InspectableField, JsonProperty("gravityRadiusExponent"), Key(22)]
public float GravityRadiusExponent = 1.5f;
[InspectableField] [JsonProperty("gravityRadiusMultiplier")] [Key(24)]
[InspectableField, JsonProperty("gravityRadiusMultiplier"), Key(23)]
public float GravityRadiusMultiplier = 1f;
[InspectableField] [JsonProperty("beltProbability")] [Key(25)]
[InspectableField, JsonProperty("beltProbability"), Key(24)]
public float BeltProbability = .05f;
[InspectableField] [JsonProperty("beltMassCeiling")] [Key(26)]
[InspectableField, JsonProperty("beltMassCeiling"), Key(25)]
public float BeltMassCeiling = 500f;
[InspectableField] [JsonProperty("beltMassRatio")] [Key(27)]
[InspectableField, JsonProperty("beltMassRatio"), Key(26)]
public float BeltMassRatio = 100f;
[InspectableField] [JsonProperty("beltMassExponent")] [Key(28)]
[InspectableField, JsonProperty("beltMassExponent"), Key(27)]
public float BeltMassExponent = 100f;
[InspectableField, JsonProperty("planetMass"), Key(28)]
public float PlanetMass = 100f;
public float PlanetRadius(float mass)
{
@ -104,52 +104,50 @@ public class GlobalData : DatabaseEntry
}
}
[Serializable]
[RethinkTable("Galaxy")]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
public class GalaxyMapLayerData : DatabaseEntry
[Inspectable, Serializable, RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class GalaxyMapLayerData : DatabaseEntry, INamedEntry
{
[InspectableField] [JsonProperty("coreBoost")] [Key(1)]
[InspectableField, JsonProperty("coreBoost"), Key(1)]
public float CoreBoost = 1.05f;
[InspectableField] [JsonProperty("coreBoostOffset")] [Key(2)]
[InspectableField, JsonProperty("coreBoostOffset"), Key(2)]
public float CoreBoostOffset = .1f;
[InspectableField] [JsonProperty("coreBoostPower")] [Key(3)]
[InspectableField, JsonProperty("coreBoostPower"), Key(3)]
public float CoreBoostPower = 2.25f;
[InspectableField] [JsonProperty("spokeScale")] [Key(4)]
[InspectableField, JsonProperty("spokeScale"), Key(4)]
public float SpokeScale = 1;
[InspectableField] [JsonProperty("spokeOffset")] [Key(5)]
[InspectableField, JsonProperty("spokeOffset"), Key(5)]
public float SpokeOffset = 0;
[InspectableField] [JsonProperty("edgeReduction")] [Key(6)]
[InspectableField, JsonProperty("edgeReduction"), Key(6)]
public float EdgeReduction = 3;
[InspectableField] [JsonProperty("noiseOffset")] [Key(7)]
[InspectableField, JsonProperty("noiseOffset"), Key(7)]
public float NoiseOffset = 0;
[InspectableField] [JsonProperty("noiseAmplitude")] [Key(8)]
[InspectableField, JsonProperty("noiseAmplitude"), Key(8)]
public float NoiseAmplitude = 1.5f;
[InspectableField] [JsonProperty("noiseGain")] [Key(9)]
[InspectableField, JsonProperty("noiseGain"), Key(9)]
public float NoiseGain = .7f;
[InspectableField] [JsonProperty("noiseLacunarity")] [Key(10)]
[InspectableField, JsonProperty("noiseLacunarity"), Key(10)]
public float NoiseLacunarity = 2;
[InspectableField] [JsonProperty("noiseOctaves")] [Key(11)]
[InspectableField, JsonProperty("noiseOctaves"), Key(11)]
public int NoiseOctaves = 7;
[InspectableField] [JsonProperty("noiseFrequency")] [Key(12)]
[InspectableField, JsonProperty("noiseFrequency"), Key(12)]
public float NoiseFrequency = 1;
[InspectableField] [JsonProperty("noisePosition")] [Key(13)]
[InspectableField, JsonProperty("noisePosition"), Key(13)]
public float NoisePosition = 1337;
[IgnoreMember] public string Name;
[InspectableField, JsonProperty("name"), Key(14)]
public string Name;
public float Evaluate(float2 uv, GlobalData data)
{
@ -165,6 +163,12 @@ public class GalaxyMapLayerData : DatabaseEntry
return gal;
}
[IgnoreMember] public string EntryName
{
get => Name;
set => Name = value;
}
}
public static class NoiseFbm

View file

@ -1,22 +1,20 @@
using System.Collections.Generic;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;
[RethinkTable("Items")]
[InspectableField]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class AfterburnerBehaviorData : IItemBehaviorData
{
[InspectableField] [JsonProperty("thrust")] [Key(0)]
public PerformanceStat ThrustModifier;
[InspectableField, JsonProperty("thrust"), Key(0)]
public PerformanceStat ThrustModifier = new PerformanceStat();
[InspectableField] [JsonProperty("speed")] [Key(1)]
public PerformanceStat SpeedModifier;
[InspectableField, JsonProperty("speed"), Key(1)]
public PerformanceStat SpeedModifier = new PerformanceStat();
[InspectableField] [JsonProperty("torque")] [Key(2)]
public PerformanceStat TorqueModifier;
[InspectableField, JsonProperty("torque"), Key(2)]
public PerformanceStat TorqueModifier = new PerformanceStat();
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
{
@ -28,6 +26,7 @@ public class AfterburnerBehavior : IActivatedItemBehavior
{
private List<Dictionary<IItemBehavior,float>> _modifiers = new List<Dictionary<IItemBehavior, float>>();
private AfterburnerBehaviorData _data;
private ThrusterBehaviorData[] _thrusters;
public Ship Ship { get; }
public Gear Item { get; }
@ -43,6 +42,11 @@ public class AfterburnerBehavior : IActivatedItemBehavior
Item = item;
}
public void Initialize()
{
_thrusters = Ship.GetBehaviorData<ThrusterBehaviorData>().ToArray();
}
public void Update(float delta)
{
}
@ -53,17 +57,22 @@ public class AfterburnerBehavior : IActivatedItemBehavior
public void Activate()
{
var thrustMod = Ship.GetEquipped<ThrusterData>().Thrust.GetScaleModifiers(Ship);
_modifiers.Add(thrustMod);
thrustMod.Add(this,Context.Evaluate(_data.ThrustModifier,Item, Ship));
if (_thrusters.Length == 0) return;
var speedMod = (Ship.Hull.ItemData as HullData).TopSpeed.GetScaleModifiers(Ship);
_modifiers.Add(speedMod);
speedMod.Add(this,Context.Evaluate(_data.SpeedModifier,Item, Ship));
foreach (var thruster in _thrusters)
{
var thrustMod = thruster.Thrust.GetScaleModifiers(Ship);
thrustMod.Add(this,Context.Evaluate(_data.ThrustModifier,Item, Ship));
_modifiers.Add(thrustMod);
}
var torqueMod = (Ship.GetEquipped(HardpointType.Thruster).ItemData as ThrusterData).Torque.GetScaleModifiers(Ship);
_modifiers.Add(torqueMod);
torqueMod.Add(this,Context.Evaluate(_data.TorqueModifier,Item, Ship));
// var speedMod = (Ship.Hull.ItemData as HullData).TopSpeed.GetScaleModifiers(Ship);
// _modifiers.Add(speedMod);
// speedMod.Add(this,Context.Evaluate(_data.SpeedModifier,Item, Ship));
//
// var torqueMod = (Ship.GetEquipped(HardpointType.Thruster).ItemData as ThrusterData).Torque.GetScaleModifiers(Ship);
// _modifiers.Add(torqueMod);
// torqueMod.Add(this,Context.Evaluate(_data.TorqueModifier,Item, Ship));
Ship.ForceThrust = true;
}

View file

@ -11,6 +11,7 @@ using static Unity.Mathematics.noise;
public interface IItemBehavior
{
void Initialize();
void Update(float delta);
void FixedUpdate(float delta);
Ship Ship { get; }
@ -25,15 +26,19 @@ public interface IActivatedItemBehavior : IItemBehavior
void Deactivate();
}
[InspectableField]
[Union(0, typeof(CannonBehaviorData))]
[Union(1, typeof(LauncherBehaviorData))]
[Union(2, typeof(ReactorBehaviorData))]
public interface IAnalogItemBehavior : IItemBehavior
{
void SetAxis(float value);
}
[InspectableField,
Union(0, typeof(CannonBehaviorData)),
Union(1, typeof(LauncherBehaviorData)),
Union(2, typeof(ReactorBehaviorData)),
Union(4, typeof(AfterburnerBehaviorData)),
Union(5, typeof(SensorBehaviorData)),
JsonConverter(typeof(JsonKnownTypesConverter<IItemBehaviorData>)), JsonObject(MemberSerialization.OptIn)]
// [Union(3, typeof(PlusUltraBehaviorData))]
[Union(4, typeof(AfterburnerBehaviorData))]
[Union(5, typeof(SensorBehaviorData))]
[JsonConverter(typeof(JsonKnownTypesConverter<IItemBehaviorData>))]
[JsonObject(MemberSerialization.OptIn)]
public interface IItemBehaviorData
{
IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item);

View file

@ -1,53 +1,20 @@
using MessagePack;
using Newtonsoft.Json;
[RethinkTable("Items")]
[InspectableField]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
public class CannonBehaviorData : IItemBehaviorData
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class CannonBehaviorData : WeaponBehaviorData, IItemBehaviorData
{
[InspectablePrefab] [JsonProperty("bullet")] [Key(0)]
[InspectablePrefab, JsonProperty("bullet"), Key(9)]
public string BulletPrefab;
[InspectableField] [JsonProperty("damageType")] [Key(1)]
public DamageType DamageType;
[InspectableField] [JsonProperty("burstCount")] [Key(2)]
public int BurstCount;
[InspectableField, JsonProperty("spread"), Key(10)]
public PerformanceStat Spread = new PerformanceStat();
[InspectableField] [JsonProperty("burstTime")] [Key(3)]
public PerformanceStat BurstTime;
[InspectableField] [JsonProperty("bulletRange")] [Key(4)]
public PerformanceStat Range;
[InspectableField] [JsonProperty("spread")] [Key(5)]
public PerformanceStat Spread;
[InspectableField] [JsonProperty("bulletInherit")] [Key(6)]
[InspectableField, JsonProperty("bulletInherit"), Key(11)]
public float Inherit;
[InspectableField] [JsonProperty("deflection")] [Key(7)]
public float Deflection;
[InspectableField] [JsonProperty("visibility")] [Key(8)]
public PerformanceStat Visibility;
[InspectableField] [JsonProperty("visibilityDecay")] [Key(9)]
public PerformanceStat VisibilityDecay;
[InspectableField] [JsonProperty("bulletVelocity")] [Key(10)]
public PerformanceStat Velocity;
[InspectableField] [JsonProperty("cooldown")] [Key(11)]
public PerformanceStat Cooldown;
[InspectableField] [JsonProperty("damage")] [Key(12)]
public PerformanceStat Damage;
[InspectableField] [JsonProperty("heat")] [Key(13)]
public PerformanceStat Heat;
[InspectableField, JsonProperty("bulletVelocity"), Key(12)]
public PerformanceStat Velocity = new PerformanceStat();
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
{
@ -114,6 +81,10 @@ public class CannonBehavior : IActivatedItemBehavior
_firing = false;
}
public void Initialize()
{
}
public void Update(float delta)
{
_cooldown -= delta / Context.Evaluate(_cannon.Cooldown, Item, Ship);

View file

@ -4,72 +4,38 @@ using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
[RethinkTable("Items")]
[InspectableField]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class LauncherBehaviorData : IItemBehaviorData
{
// [MessagePackFormatter(typeof(UnityGameObjectFormatter))]
// [Inspectable] [Key("missile")] public GameObject MissilePrefab;
// [MessagePackFormatter(typeof(ClipListFormatter))]
// [Inspectable] [Key("sounds")] public List<AudioClip> Sounds;
// [MessagePackFormatter(typeof(UnityAudioClipFormatter))]
// [Inspectable] [Key("beepSound")] public AudioClip BeepSound;
// [Inspectable] [Key("beepCount")] public int Beeps;
[InspectableField] [JsonProperty("damageType")] [Key(0)]
public DamageType DamageType;
[InspectablePrefab, JsonProperty("missile"), Key(9)]
public string MissilePrefab;
[InspectableField] [JsonProperty("burstCount")] [Key(1)]
public int BurstCount;
[InspectableField] [JsonProperty("burstTime")] [Key(2)]
public PerformanceStat BurstTime;
[InspectableField] [JsonProperty("range")] [Key(3)]
public PerformanceStat Range;
[InspectableAnimationCurve] [JsonProperty("guidance")] [Key(4)]
[InspectableAnimationCurve, JsonProperty("guidance"), Key(10)]
public float4[] GuidanceCurve;
[InspectableAnimationCurve] [JsonProperty("thrustCurve")] [Key(5)]
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(11)]
public float4[] ThrustCurve;
[InspectableAnimationCurve] [JsonProperty("liftCurve")] [Key(6)]
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(12)]
public float4[] LiftCurve;
[InspectableField] [JsonProperty("thrust")] [Key(7)]
public PerformanceStat Thrust;
[InspectableField, JsonProperty("thrust"), Key(13)]
public PerformanceStat Thrust = new PerformanceStat();
[InspectableField] [JsonProperty("deflection")] [Key(8)]
public float Deflection;
[InspectableField, JsonProperty("lockAngle"), Key(14)]
public float LockAngle;
[InspectableField] [JsonProperty("lockOnBuffer")] [Key(9)]
public float LockOnDegrees;
[InspectableField] [JsonProperty("frequency")] [Key(10)]
[InspectableField, JsonProperty("frequency"), Key(15)]
public float DodgeFrequency;
[InspectableField] [JsonProperty("visibility")] [Key(11)]
public PerformanceStat Visibility;
[InspectableField, JsonProperty("launchSpeed"), Key(16)]
public PerformanceStat LaunchSpeed = new PerformanceStat();
[InspectableField] [JsonProperty("launchSpeed")] [Key(12)]
public PerformanceStat LaunchSpeed;
[InspectableField, JsonProperty("missileSpeed"), Key(17)]
public PerformanceStat MissileSpeed = new PerformanceStat();
[InspectableField] [JsonProperty("missileSpeed")] [Key(13)]
public PerformanceStat MissileSpeed;
[InspectableField] [JsonProperty("cooldown")] [Key(14)]
public PerformanceStat Cooldown;
[InspectableField] [JsonProperty("lockOnTime")] [Key(15)]
public PerformanceStat LockOnTime;
[InspectableField] [JsonProperty("damage")] [Key(16)]
public PerformanceStat Damage;
[InspectableField] [JsonProperty("heat")] [Key(17)]
public PerformanceStat Heat;
[InspectableField, JsonProperty("lockOnTime"), Key(18)]
public PerformanceStat LockOnTime = new PerformanceStat();
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
{
@ -154,6 +120,10 @@ public class LauncherBehavior : IActivatedItemBehavior
// _lockingTimer = 1;
}
public void Initialize()
{
}
public void Update(float delta)
{
// if (Ship.Target == null)

View file

@ -1,25 +1,23 @@
using MessagePack;
using Newtonsoft.Json;
[RethinkTable("Items")]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ReactorBehaviorData : IItemBehaviorData
{
[InspectableField] [JsonProperty("charge")] [Key(0)]
public PerformanceStat Charge;
[InspectableField, JsonProperty("charge"), Key(0)]
public PerformanceStat Charge = new PerformanceStat();
[InspectableField] [JsonProperty("capacitance")] [Key(1)]
public PerformanceStat Capacitance;
[InspectableField, JsonProperty("capacitance"), Key(1)]
public PerformanceStat Capacitance = new PerformanceStat();
[InspectableField] [JsonProperty("efficiency")] [Key(2)]
public PerformanceStat Efficiency;
[InspectableField, JsonProperty("efficiency"), Key(2)]
public PerformanceStat Efficiency = new PerformanceStat();
[InspectableField] [JsonProperty("overload")] [Key(3)]
public PerformanceStat OverloadEfficiency;
[InspectableField, JsonProperty("overload"), Key(3)]
public PerformanceStat OverloadEfficiency = new PerformanceStat();
[InspectableField] [JsonProperty("underload")] [Key(4)]
public PerformanceStat UnderloadRecovery;
[InspectableField, JsonProperty("underload"), Key(4)]
public PerformanceStat UnderloadRecovery = new PerformanceStat();
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
{
@ -68,6 +66,10 @@ public class ReactorBehavior : IItemBehavior
}
public void Initialize()
{
}
public void Update(float delta)
{
}

View file

@ -2,23 +2,20 @@
using MessagePack;
using Newtonsoft.Json;
[RethinkTable("Items")]
[InspectableField]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class SensorBehaviorData : IItemBehaviorData
{
[InspectableField] [JsonProperty("radiance")] [Key(0)]
public PerformanceStat Radiance;
[InspectableField, JsonProperty("radiance"), Key(0)]
public PerformanceStat Radiance = new PerformanceStat();
[InspectableField] [JsonProperty("masking")] [Key(1)]
public PerformanceStat RadianceMasking;
[InspectableField, JsonProperty("masking"), Key(1)]
public PerformanceStat RadianceMasking = new PerformanceStat();
[InspectableField] [JsonProperty("sensitivity")] [Key(2)]
public PerformanceStat Sensitivity;
[InspectableField, JsonProperty("sensitivity"), Key(2)]
public PerformanceStat Sensitivity = new PerformanceStat();
[InspectableField] [JsonProperty("range")] [Key(3)]
public PerformanceStat Range;
[InspectableField, JsonProperty("range"), Key(3)]
public PerformanceStat Range = new PerformanceStat();
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
{
@ -44,6 +41,10 @@ public class SensorBehavior : IItemBehavior
Context = context;
}
public void Initialize()
{
}
public void Update(float delta)
{
// var ship = Hardpoint.Ship.Ship.transform;

View file

@ -0,0 +1,52 @@
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ShieldBehaviorData : IItemBehaviorData
{
[InspectableField, JsonProperty("efficiency"), Key(0)]
public PerformanceStat Efficiency = new PerformanceStat();
[InspectableField, JsonProperty("shielding"), Key(1)]
public PerformanceStat Shielding = new PerformanceStat();
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
{
return new ShieldBehavior(context, this, ship, item);
}
}
public class ShieldBehavior : IItemBehavior
{
public Ship Ship { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IItemBehaviorData Data => _data;
private ShieldBehaviorData _data;
public ShieldBehavior(GameContext context, ShieldBehaviorData data, Ship ship, Gear item)
{
Context = context;
_data = data;
Ship = ship;
Item = item;
// TODO: Detect hits on Ship, keep a list of callbacks that modify the hit by reference
}
public void FixedUpdate(float delta)
{
}
public void Initialize()
{
}
public void Update(float delta)
{
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dbb1419b4645402aad5a394b983a637f
timeCreated: 1586275939

View file

@ -0,0 +1,67 @@
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ThrusterBehaviorData : IItemBehaviorData
{
[InspectableField, JsonProperty("thrust"), Key(0)]
public PerformanceStat Thrust = new PerformanceStat();
[InspectableField, JsonProperty("torque"), Key(1)]
public PerformanceStat Torque = new PerformanceStat();
[InspectableField, JsonProperty("visibility"), Key(2)]
public PerformanceStat Visibility = new PerformanceStat();
[InspectableField, JsonProperty("heat"), Key(3)]
public PerformanceStat Heat = new PerformanceStat();
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
{
return new ThrusterBehavior(context, this, ship, item);
}
}
public class ThrusterBehavior : IAnalogItemBehavior
{
public Ship Ship { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IItemBehaviorData Data => _data;
private ThrusterBehaviorData _data;
private float _thrust;
public ThrusterBehavior(GameContext context, ThrusterBehaviorData data, Ship ship, Gear item)
{
Context = context;
_data = data;
Ship = ship;
Item = item;
}
public void SetAxis(float value)
{
_thrust = saturate(value);
}
public void FixedUpdate(float delta)
{
}
public void Initialize()
{
}
public void Update(float delta)
{
Ship.Velocity += _thrust * Context.Evaluate(_data.Thrust, Item, Ship) * delta;
Ship.AddHeat(_thrust * Context.Evaluate(_data.Heat, Item, Ship) * delta);
Ship.VisibilitySources[this] = _thrust * Context.Evaluate(_data.Visibility, Item, Ship);
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f46e0da62f8c40f69bba0b7bcff8662f
timeCreated: 1586267627

View file

@ -0,0 +1,64 @@
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class TurningBehaviorData : IItemBehaviorData
{
[InspectableField, JsonProperty("torque"), Key(0)]
public PerformanceStat Torque = new PerformanceStat();
[InspectableField, JsonProperty("visibility"), Key(1)]
public PerformanceStat Visibility = new PerformanceStat();
[InspectableField, JsonProperty("heat"), Key(2)]
public PerformanceStat Heat = new PerformanceStat();
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
{
return new TurningBehavior(context, this, ship, item);
}
}
public class TurningBehavior : IAnalogItemBehavior
{
public Ship Ship { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IItemBehaviorData Data => _data;
private TurningBehaviorData _data;
private float _turning;
public TurningBehavior(GameContext context, TurningBehaviorData data, Ship ship, Gear item)
{
Context = context;
_data = data;
Ship = ship;
Item = item;
}
public void SetAxis(float value)
{
_turning = clamp(value, -1, 1);
}
public void FixedUpdate(float delta)
{
}
public void Initialize()
{
}
public void Update(float delta)
{
Ship.Direction = mul(Ship.Direction, Unity.Mathematics.float2x2.Rotate(_turning * Context.Evaluate(_data.Torque, Item, Ship) * delta));
Ship.AddHeat(abs(_turning) * Context.Evaluate(_data.Heat, Item, Ship) * delta);
Ship.VisibilitySources[this] = abs(_turning) * Context.Evaluate(_data.Visibility, Item, Ship);
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 21343037bc4842669c20b0606b03a622
timeCreated: 1586270198

View file

@ -0,0 +1,34 @@
using MessagePack;
using Newtonsoft.Json;
[Union(0, typeof(CannonBehaviorData)),
Union(1, typeof(LauncherBehaviorData))]
public abstract class WeaponBehaviorData
{
[InspectableField, JsonProperty("damageType"), Key(0)]
public DamageType DamageType;
[InspectableField, JsonProperty("damage"), Key(1)]
public PerformanceStat Damage = new PerformanceStat();
[InspectableField, JsonProperty("range"), Key(2)]
public PerformanceStat Range = new PerformanceStat();
[InspectableField, JsonProperty("cooldown"), Key(3)]
public PerformanceStat Cooldown = new PerformanceStat();
[InspectableField, JsonProperty("heat"), Key(4)]
public PerformanceStat Heat = new PerformanceStat();
[InspectableField, JsonProperty("visibility"), Key(5)]
public PerformanceStat Visibility = new PerformanceStat();
[InspectableField, JsonProperty("visibilityDecay"), Key(6)]
public PerformanceStat VisibilityDecay = new PerformanceStat();
[InspectableField, JsonProperty("burstCount"), Key(7)]
public int BurstCount;
[InspectableField, JsonProperty("burstTime"), Key(8)]
public PerformanceStat BurstTime = new PerformanceStat();
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d87bbbe67d6d48cb8f0cca9611985c00
timeCreated: 1586295838

View file

@ -6,27 +6,25 @@ using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
[MessagePackObject]
[Union(0, typeof(SimpleCommodityData))]
[Union(1, typeof(CompoundCommodityData))]
[Union(2, typeof(GearData))]
[Union(3, typeof(HullData))]
[Union(4, typeof(ShieldData))]
[Union(5, typeof(ThrusterData))]
[JsonObject(MemberSerialization.OptIn)]
[JsonConverter(typeof(JsonKnownTypesConverter<ItemData>))]
[MessagePackObject,
Union(0, typeof(SimpleCommodityData)),
Union(1, typeof(CompoundCommodityData)),
Union(2, typeof(GearData)),
Union(3, typeof(HullData)),
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<ItemData>))]
public abstract class ItemData : DatabaseEntry, INamedEntry
{
[InspectableField] [JsonProperty("name")] [Key(1)]
[InspectableField, JsonProperty("name"), Key(1)]
public string Name;
[InspectableField] [JsonProperty("mass")] [Key(2)]
[InspectableField, JsonProperty("mass"), Key(2)]
public float Mass;
[InspectableField] [JsonProperty("size")] [Key(3)]
[InspectableField, JsonProperty("size"), Key(3)]
public float Size;
[InspectableField] [JsonProperty("specificHeat")] [Key(4)]
// Heat needed to change temperature of 1 gram by 1 degree
[InspectableField, JsonProperty("specificHeat"), Key(4)]
public float SpecificHeat;
[IgnoreMember] public string EntryName
@ -36,61 +34,66 @@ public abstract class ItemData : DatabaseEntry, INamedEntry
}
}
[RethinkTable("Items")]
[Inspectable]
[MessagePackObject]
public class SimpleCommodityData : ItemData {}
[MessagePackObject]
[Union(0, typeof(CompoundCommodityData))]
[Union(1, typeof(GearData))]
[Union(2, typeof(HullData))]
[Union(3, typeof(ShieldData))]
[Union(4, typeof(ThrusterData))]
[JsonObject(MemberSerialization.OptIn)]
[JsonConverter(typeof(JsonKnownTypesConverter<CraftedItemData>))]
public abstract class CraftedItemData : ItemData
[RethinkTable("Items"), Inspectable, MessagePackObject]
public class SimpleCommodityData : ItemData
{
[InspectableField] [JsonProperty("ingredients")] [Key(5)]
public Dictionary<Guid, int> Ingredients = new Dictionary<Guid, int>();
// Types of body where this resource can be found
[InspectableField, JsonProperty("resourceBodyType"), Key(5)]
public BodyType ResourceBodyType;
// Link to map(s) controlling density of resource, multiplied together when more than one
[InspectableDatabaseLink(typeof(GalaxyMapLayerData)), JsonProperty("resourceDensity"), Key(6)]
public List<Guid> ResourceDensity = new List<Guid>();
// Controls the bias power variable during resource placement
[InspectableField, JsonProperty("resourceDensityBiasPower"), Key(7)]
public float ResourceDensityBiasPower = 5;
// Minimum amount of resources needed for presence to register
[InspectableField, JsonProperty("resourceFloor"), Key(8)]
public float ResourceFloor = 10f;
}
[RethinkTable("Items")]
[Inspectable]
[MessagePackObject]
[MessagePackObject,
Union(0, typeof(CompoundCommodityData)),
Union(1, typeof(GearData)),
Union(2, typeof(HullData)),
JsonObject(MemberSerialization.OptIn),
JsonConverter(typeof(JsonKnownTypesConverter<CraftedItemData>))]
public abstract class CraftedItemData : ItemData
{
}
[RethinkTable("Items"), Inspectable, MessagePackObject]
public class CompoundCommodityData : CraftedItemData {}
[Union(0, typeof(GearData))]
[Union(1, typeof(HullData))]
[Union(2, typeof(ShieldData))]
[Union(3, typeof(ThrusterData))]
[JsonObject(MemberSerialization.OptIn)]
[JsonConverter(typeof(JsonKnownTypesConverter<EquippableItemData>))]
[Union(0, typeof(GearData)),
Union(1, typeof(HullData)),
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<EquippableItemData>))]
public abstract class EquippableItemData : CraftedItemData
{
[InspectableField, JsonProperty("draw"), Key(6)]
public PerformanceStat EnergyDraw = new PerformanceStat();
[InspectableField] [JsonProperty("draw")] [Key(6)]
public PerformanceStat EnergyDraw;
[InspectableAnimationCurve] [JsonProperty("performanceCurve")] [Key(7)]
[InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(7)]
public float4[] HeatPerformanceCurve;
[TemperatureInspectable] [JsonProperty("minTemp")] [Key(8)]
[TemperatureInspectable, JsonProperty("minTemp"), Key(8)]
public float MinimumTemperature;
[TemperatureInspectable] [JsonProperty("maxTemp")] [Key(9)]
[TemperatureInspectable, JsonProperty("maxTemp"), Key(9)]
public float MaximumTemperature;
[InspectableField] [JsonProperty("durability")] [Key(10)]
[InspectableField, JsonProperty("durability"), Key(10)]
public float Durability;
[InspectableField] [JsonProperty("durabilityExponent")] [Key(11)]
public PerformanceStat DurabilityExponent;
[InspectableField, JsonProperty("durabilityExponent"), Key(11)]
public PerformanceStat DurabilityExponent = new PerformanceStat();
[InspectableField] [JsonProperty("heatExponent")] [Key(12)]
public PerformanceStat HeatExponent;
[InspectableField] [JsonProperty("behaviors")] [Key(13)]
[InspectableField, JsonProperty("heatExponent"), Key(12)]
public PerformanceStat HeatExponent = new PerformanceStat();
[InspectableField, JsonProperty("behaviors"), Key(13)]
public List<IItemBehaviorData> Behaviors = new List<IItemBehaviorData>();
[IgnoreMember]
@ -125,117 +128,70 @@ public abstract class EquippableItemData : CraftedItemData
}
}
[RethinkTable("Items")]
[Inspectable]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class GearData : EquippableItemData
{
[InspectableField] [JsonProperty("hardpointType")] [Key(14)] public HardpointType Hardpoint;
[InspectableField, JsonProperty("hardpointType"), Key(14)]
public HardpointType Hardpoint;
[IgnoreMember] public override HardpointType HardpointType => Hardpoint;
}
[RethinkTable("Items")]
[Inspectable]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class HullData : EquippableItemData
{
[InspectableField] [JsonProperty("hullCapacity")] [Key(14)]
public PerformanceStat Capacity;
[InspectableField, JsonProperty("hullCapacity"), Key(14)]
public PerformanceStat Capacity = new PerformanceStat();
[InspectableField] [JsonProperty("traction")] [Key(15)]
public PerformanceStat Traction;
[InspectableField, JsonProperty("traction"), Key(15)]
public PerformanceStat Traction = new PerformanceStat();
[InspectableField] [JsonProperty("topSpeed")] [Key(16)]
public PerformanceStat TopSpeed;
[InspectableField, JsonProperty("topSpeed"), Key(16)]
public PerformanceStat TopSpeed = new PerformanceStat();
[InspectableField] [JsonProperty("emissivity")] [Key(17)]
public PerformanceStat Emissivity;
[InspectableField, JsonProperty("emissivity"), Key(17)]
public PerformanceStat Emissivity = new PerformanceStat();
[InspectableField] [JsonProperty("crossSection")] [Key(18)]
public PerformanceStat CrossSection;
[InspectableField, JsonProperty("crossSection"), Key(18)]
public PerformanceStat CrossSection = new PerformanceStat();
[InspectableField] [JsonProperty("hardpoints")] [Key(19)]
[InspectableField, JsonProperty("hardpoints"), Key(19)]
public List<HardpointData> Hardpoints = new List<HardpointData>();
[InspectableAnimationCurve] [JsonProperty("visibility")] [Key(20)]
[InspectableAnimationCurve, JsonProperty("visibility"), Key(20)]
public float4[] VisibilityCurve;
[InspectablePrefab] [JsonProperty("prefab")] [Key(21)]
[InspectablePrefab, JsonProperty("prefab"), Key(21)]
public string Prefab;
[IgnoreMember] public override HardpointType HardpointType => HardpointType.Hull;
}
[RethinkTable("Items")]
[InspectableField]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[RethinkTable("Items"), InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class HardpointData
{
[JsonProperty("type")] [Key(0)]
public HardpointType Type;
[JsonProperty("type"), Key(0)] public HardpointType Type;
}
[RethinkTable("Items")]
[Inspectable]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
public class ShieldData : EquippableItemData
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class PerformanceStat
{
[InspectableField] [JsonProperty("efficiency")] [Key(14)]
public PerformanceStat Efficiency;
[JsonProperty("min"), Key(0)] public float Min;
[InspectableField] [JsonProperty("shielding")] [Key(15)]
public PerformanceStat Shielding;
[JsonProperty("max"), Key(1)] public float Max;
[IgnoreMember] public override HardpointType HardpointType => HardpointType.Shield;
}
[RethinkTable("Items")]
[Inspectable]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
public class ThrusterData : EquippableItemData
{
[InspectableField] [JsonProperty("thrust")] [Key(14)]
public PerformanceStat Thrust;
[InspectableField] [JsonProperty("torque")] [Key(15)]
public PerformanceStat Torque;
[InspectableField] [JsonProperty("visibility")] [Key(16)]
public PerformanceStat Visibility;
[InspectableField] [JsonProperty("thrusterHeat")] [Key(17)]
public PerformanceStat Heat;
[IgnoreMember] public override HardpointType HardpointType => HardpointType.Thruster;
}
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
public struct PerformanceStat
{
[JsonProperty("min")] [Key(0)]
public float Min;
[JsonProperty("max")] [Key(1)]
public float Max;
[JsonProperty("durabilityDependent")] [Key(2)]
[JsonProperty("durabilityDependent"), Key(2)]
public bool DurabilityDependent;
[JsonProperty("heatDependent")] [Key(3)]
[JsonProperty("heatDependent"), Key(3)]
public bool HeatDependent;
[JsonProperty("qualityExponent")] [Key(4)]
[JsonProperty("qualityExponent"), Key(4)]
public float QualityExponent;
[JsonProperty("ingredient")] [Key(5)]
public Guid? Ingredient;
//[JsonProperty("id"), Key(5)] public Guid ID = Guid.NewGuid();
// [JsonProperty("ingredient"), Key(5)] public Guid? Ingredient;
[IgnoreMember] private Dictionary<Ship,Dictionary<IItemBehavior,float>> _scaleModifiers;
[IgnoreMember] private Dictionary<Ship,Dictionary<IItemBehavior,float>> _constantModifiers;

View file

@ -12,63 +12,50 @@ using Unity.Mathematics;
// TODO: USE THIS EVERYWHERE
using static Unity.Mathematics.math;
[Union(0, typeof(SimpleCommodity))]
[Union(1, typeof(CompoundCommodity))]
[Union(2, typeof(Gear))]
[JsonObject(MemberSerialization.OptIn)]
[JsonConverter(typeof(JsonKnownTypesConverter<ItemInstance>))]
[Union(0, typeof(SimpleCommodity)), Union(1, typeof(CompoundCommodity)), Union(2, typeof(Gear)),
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<ItemInstance>))]
public abstract class ItemInstance : DatabaseEntry
{
[JsonProperty("data")] [Key(1)]
public Guid Data;
[JsonProperty("data"), Key(1)] public Guid Data;
public float Mass => Context.GetMass(this);
public float HeatCapacity => Context.GetHeatCapacity(this);
}
[Union(0, typeof(CompoundCommodity))]
[Union(1, typeof(Gear))]
[JsonObject(MemberSerialization.OptIn)]
[JsonConverter(typeof(JsonKnownTypesConverter<CraftedItemInstance>))]
[Union(0, typeof(CompoundCommodity)), Union(1, typeof(Gear)), JsonObject(MemberSerialization.OptIn),
JsonConverter(typeof(JsonKnownTypesConverter<CraftedItemInstance>))]
public abstract class CraftedItemInstance : ItemInstance
{
[JsonProperty("quality")] [Key(2)]
public float Quality;
[JsonProperty("quality"), Key(2)] public float Quality;
[JsonProperty("ingredients")] [Key(3)]
public List<ItemInstance> Ingredients = new List<ItemInstance>();
[JsonProperty("ingredients"), Key(3)] public List<ItemInstance> Ingredients = new List<ItemInstance>();
[JsonProperty("blueprint"), Key(4)] public BlueprintData Blueprint;
}
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class CompoundCommodity : CraftedItemInstance {}
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class SimpleCommodity : ItemInstance
{
[JsonProperty("quantity")] [Key(2)]
public int Quantity;
[JsonProperty("quantity"), Key(2)] public int Quantity;
public SimpleCommodityData ItemData => Context.GetData(this);
}
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class Gear : CraftedItemInstance
{
[JsonProperty("durability")] [Key(4)]
public float Durability;
[JsonProperty("durability"), Key(5)] public float Durability;
public EquippableItemData ItemData => Context.GetData(this);
}
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class Hardpoint
{
[JsonProperty("item")] [Key(0)]
public Gear Item;
[JsonProperty("item"), Key(0)] public Gear Item;
[IgnoreMember] public HardpointData HardpointData;
}

View file

@ -5,20 +5,11 @@ using LiteNetLib;
using MessagePack;
using Unity.Mathematics;
[Union(0,typeof(PingMessage))]
[Union(1,typeof(LoginMessage))]
[Union(2,typeof(RegisterMessage))]
[Union(3,typeof(VerifyMessage))]
[Union(4,typeof(ErrorMessage))]
[Union(5,typeof(LoginSuccessMessage))]
[Union(6,typeof(ChatMessage))]
[Union(7,typeof(ChatBroadcastMessage))]
[Union(8,typeof(ChangeNameMessage))]
[Union(9,typeof(GalaxyRequestMessage))]
[Union(10,typeof(GalaxyResponseMessage))]
[Union(11,typeof(ZoneRequestMessage))]
[Union(12,typeof(ZoneResponseMessage))]
[MessagePackObject]
[Union(0, typeof(PingMessage)), Union(1, typeof(LoginMessage)), Union(2, typeof(RegisterMessage)),
Union(3, typeof(VerifyMessage)), Union(4, typeof(ErrorMessage)), Union(5, typeof(LoginSuccessMessage)),
Union(6, typeof(ChatMessage)), Union(7, typeof(ChatBroadcastMessage)), Union(8, typeof(ChangeNameMessage)),
Union(9, typeof(GalaxyRequestMessage)), Union(10, typeof(GalaxyResponseMessage)),
Union(11, typeof(ZoneRequestMessage)), Union(12, typeof(ZoneResponseMessage)), MessagePackObject]
public abstract class Message
{
[IgnoreMember] public NetPeer Peer;

View file

@ -27,7 +27,9 @@ public class Ship : DatabaseEntry
[IgnoreMember] public float Temperature;
[IgnoreMember] public float Charge;
// [IgnoreMember] public Targetable Target;
[IgnoreMember] public float2 Position;
[IgnoreMember] public float2 Direction;
[IgnoreMember] public float2 Velocity;
[IgnoreMember] public Dictionary<object, float> VisibilitySources = new Dictionary<object, float>();
private HullData _hullData;
@ -51,6 +53,20 @@ public class Ship : DatabaseEntry
return null;
}
public IEnumerable<T> GetBehaviors<T>() where T : class, IItemBehavior
{
foreach (var behavior in ItemBehaviors)
if (behavior is T b)
yield return b;
}
public IEnumerable<T> GetBehaviorData<T>() where T : class, IItemBehaviorData
{
foreach (var behavior in ItemBehaviors)
if (behavior.Data is T b)
yield return b;
}
public void AddHeat(float heat)
{
Temperature += heat / SpecificHeat;
@ -192,4 +208,5 @@ public class Ship : DatabaseEntry
// }
//
// }
}
}

View file

@ -6,33 +6,31 @@ using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[RethinkTable("Galaxy")]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ZoneData : DatabaseEntry, INamedEntry
{
[JsonProperty("name")] [Key(1)]
[JsonProperty("name"), Key(1)]
public string Name;
[JsonProperty("position")] [Key(2)]
[JsonProperty("position"), Key(2)]
public float2 Position = 500;
[JsonProperty("wormholes")] [Key(3)]
[JsonProperty("wormholes"), Key(3)]
public List<Guid> Wormholes = new List<Guid>();
[JsonProperty("stations")] [Key(4)]
[JsonProperty("stations"), Key(4)]
public List<Guid> Stations = new List<Guid>();
[JsonProperty("planets")] [Key(5)]
[JsonProperty("planets"), Key(5)]
public List<Guid> Planets = new List<Guid>();
[JsonProperty("orbits")] [Key(6)]
[JsonProperty("orbits"), Key(6)]
public List<Guid> Orbits = new List<Guid>();
[JsonProperty("radius")] [Key(7)]
[JsonProperty("radius"), Key(7)]
public float Radius = 2000;
[JsonProperty("visited")] [Key(8)]
[JsonProperty("visited"), Key(8)]
public bool Visited;
[IgnoreMember] public string EntryName
@ -42,31 +40,29 @@ public class ZoneData : DatabaseEntry, INamedEntry
}
}
[RethinkTable("Galaxy")]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class Station : DatabaseEntry, INamedEntry
{
[JsonProperty("name")] [Key(1)]
[JsonProperty("name"), Key(1)]
public string Name;
// Can be Planet or Orbit
[JsonProperty("parent")] [Key(2)]
[JsonProperty("parent"), Key(2)]
public Guid Parent;
[JsonProperty("owner")] [Key(3)]
[JsonProperty("owner"), Key(3)]
public Guid Owner;
[JsonProperty("inventory")] [Key(4)]
[JsonProperty("inventory"), Key(4)]
public List<ItemInstance> Inventory = new List<ItemInstance>();
[JsonProperty("buying")] [Key(5)]
[JsonProperty("buying"), Key(5)]
public Dictionary<Guid, float> BuyPrices = new Dictionary<Guid, float>();
[JsonProperty("selling")] [Key(6)]
[JsonProperty("selling"), Key(6)]
public Dictionary<Guid, float> SellPrices = new Dictionary<Guid, float>();
[JsonProperty("zone")] [Key(7)]
[JsonProperty("zone"), Key(7)]
public Guid Zone;
[IgnoreMember] public string EntryName
@ -76,25 +72,26 @@ public class Station : DatabaseEntry, INamedEntry
}
}
[RethinkTable("Galaxy")]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class PlanetData : DatabaseEntry, INamedEntry
{
[JsonProperty("name")] [Key(1)]
[JsonProperty("name"), Key(1)]
public string Name;
[JsonProperty("orbit")] [Key(2)]
[JsonProperty("orbit"), Key(2)]
public Guid Orbit;
[JsonProperty("mass")] [Key(3)]
[JsonProperty("mass"), Key(3)]
public float Mass;
[JsonProperty("zone")] [Key(4)]
[JsonProperty("zone"), Key(4)]
public Guid Zone;
[JsonProperty("belt")] [Key(5)]
[JsonProperty("belt"), Key(5)]
public bool Belt;
[JsonProperty("resources"), Key(5)]
public Dictionary<Guid, float> Resources = new Dictionary<Guid, float>();
// [JsonProperty("radius")] [Key(5)]
// public float GravityRadius;
@ -106,24 +103,22 @@ public class PlanetData : DatabaseEntry, INamedEntry
}
}
[RethinkTable("Galaxy")]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
[RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class OrbitData : DatabaseEntry
{
[JsonProperty("parent")] [Key(1)]
[JsonProperty("parent"), Key(1)]
public Guid Parent;
[JsonProperty("distance")] [Key(2)]
[JsonProperty("distance"), Key(2)]
public float Distance;
[JsonProperty("phase")] [Key(3)]
[JsonProperty("phase"), Key(3)]
public float Phase;
[JsonProperty("period")] [Key(4)]
[JsonProperty("period"), Key(4)]
public float Period;
[JsonProperty("zone")] [Key(5)]
[JsonProperty("zone"), Key(5)]
public Guid Zone;
public static float2 Evaluate(float phase)

View file

@ -12,25 +12,27 @@ using Random = Unity.Mathematics.Random;
public class ZoneGenerator
{
// public float BinaryFloor = 100;
// public float BinaryProbability = .1f;
// public float MassPowerMinimum = 1.35f;
// public float MassPowerMaximum = 1.75f;
// public float DistancePowerMinimum = 1.35f;
// public float DistancePowerMaximum = 1.75f;
// public float Radius = 500;
// public float Mass = 100000;
// public float MassFloor = 1;
// public float SunMass = 10000;
// public float GasGiantMass = 2000;
// public float RadiusPower = 1.75f;
public static void GenerateZone(GlobalData global, ZoneData zone, GalaxyMapLayerData mass, GalaxyMapLayerData radius, out OrbitData[] orbitData, out PlanetData[] planetData)
public static void GenerateZone(
GlobalData global,
ZoneData zone,
IEnumerable<GalaxyMapLayerData> mapLayers,
IEnumerable<SimpleCommodityData> resources,
out OrbitData[] orbitData,
out PlanetData[] planetsData)
{
var zoneRadius = lerp(global.MinimumZoneRadius, global.MaximumZoneRadius, radius.Evaluate(zone.Position, global));
var zoneRadius = lerp(global.MinimumZoneRadius,
global.MaximumZoneRadius,
mapLayers.First(m => m.Name == "Radius")
.Evaluate(zone.Position,
global));
zone.Radius = zoneRadius;
var zoneMass = lerp(global.MinimumZoneMass, global.MaximumZoneMass, mass.Evaluate(zone.Position, global));
var zoneMass = lerp(global.MinimumZoneMass,
global.MaximumZoneMass,
mapLayers.First(m => m.Name == "Mass")
.Evaluate(zone.Position,
global));
//Debug.Log($"Generating zone at position {zone.Position} with radius {zoneRadius} and mass {zoneMass}");
@ -62,21 +64,45 @@ public class ZoneGenerator
? orbitMap[orbitInverseMap[data].Parent].ID
: Guid.Empty;
planetData = planets.Where(p=>!p.Empty).Select(planet =>
// Cache resource densities
var resourceMaps = mapLayers.ToDictionary(m => m.ID, m => m.Evaluate(zone.Position, global));
var random = new Random();
planetsData = planets.Where(p=>!p.Empty).Select(planet =>
{
var planetDatum = new PlanetData
var planetData = new PlanetData
{
Mass = planet.Mass,
ID = Guid.NewGuid(),
Orbit = orbitMap[planet].ID,
Zone = zone.ID,
Belt = planet.Belt
Belt = planet.Belt,
Resources = resources
// Filter resources where the body type matches the current planet
.Where(r =>
((planet.Belt ? BodyType.Asteroid :
planet.Mass > global.SunMass ? BodyType.Sun :
planet.Mass > global.GasGiantMass ? BodyType.GasGiant :
planet.Mass > global.PlanetMass ? BodyType.Planet : BodyType.Planetoid) & r.ResourceBodyType) != 0)
// NextUnbounded is our extension function containing resource placement formula
// Obtain bias variable by multiplying all resource maps together
.Select(r => new
{
resource = r,
quantity = random.NextUnbounded(
r.ResourceDensity.Aggregate(1f, (m, rdm) => m * resourceMaps[rdm]),
r.ResourceDensityBiasPower)
})
// Only include resources above a minimum quantity
.Where(r => r.resource.ResourceFloor < r.quantity)
.ToDictionary(r => r.resource.ID, r => r.quantity)
};
planetDatum.Name = planetDatum.ID.ToString().Substring(0, 8);
return planetDatum;
planetData.Name = planetData.ID.ToString().Substring(0, 8);
return planetData;
}).ToArray();
zone.Planets = planetData.Select(pd => pd.ID).ToList();
zone.Planets = planetsData.Select(pd => pd.ID).ToList();
zone.Orbits = orbitData.Select(od => od.ID).ToList();
}
@ -105,7 +131,7 @@ public class ZoneGenerator
// Create a small number of less massive "captured" planets orbiting past the rosette
root.ExpandSolar(
count: random.NextInt(1,5),
count: (int)(random.NextFloat(1, 3) * random.NextFloat(1, 2)),
massMulMin: .6f,
massMulMax: .8f,
distMulMin: 1.25f,
@ -119,7 +145,7 @@ public class ZoneGenerator
var m = p.Mass / averageChildMass;
// Give each child in the rosette its own mini solar system
p.ExpandSolar(
count: (int) (m * 5),
count: (int) (random.NextFloat() * random.NextFloat() * m * 5 + 1),
massMulMin: 0.75f,
massMulMax: 2.5f,
distMulMin: 1 + m * .25f,