Ship Building & Drydock

Made it possible to turn new hulls into drones which can then be outfitted and activated for service
Missing blueprint ingredients no longer crash the game and gracefully log what's broken
Loadout cargo is now stored entirely separate from gear
This commit is contained in:
hyperion51 2020-06-11 02:55:11 +01:00
commit a901a8e829
17 changed files with 167 additions and 226 deletions

View file

@ -29,7 +29,7 @@ public abstract class ControllerData : BehaviorData
public abstract class ControllerBase : IBehavior, IController, IInitializableBehavior
{
public Guid HomeEntity;
public bool Available => Task == Guid.Empty;
public bool Available => _spaceworthy && Task == Guid.Empty;
public abstract TaskType TaskType { get; }
public Guid Zone => _entity.Zone;
public BehaviorData Data => _controllerData;
@ -49,12 +49,14 @@ public abstract class ControllerBase : IBehavior, IController, IInitializableBeh
private ControllerData _controllerData;
private MovementPhase _movementPhase;
private Action _onFinishMoving;
private bool _spaceworthy;
public ControllerBase(GameContext context, ControllerData data, Entity entity)
{
_context = context;
_controllerData = data;
_entity = entity;
entity.GearEvent.OnChanged += () => _spaceworthy = entity.GetBehavior<Thruster>() != null && entity.GetBehavior<Reactor>() != null;
}
public void Initialize()

View file

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JsonKnownTypes;
using MessagePack;
@ -29,7 +28,7 @@ public interface INamedEntry
Union(8, typeof(GalaxyMapLayerData)),
Union(9, typeof(GlobalData)),
Union(10, typeof(ZoneData)),
Union(11, typeof(Player)),
Union(11, typeof(PlayerData)),
Union(12, typeof(Corporation)),
Union(13, typeof(MegaCorporation)),
Union(14, typeof(OrbitalEntity)),
@ -50,48 +49,4 @@ public abstract class DatabaseEntry
[JsonProperty("id"), Key(0)]
public Guid ID = Guid.NewGuid();
[IgnoreMember] public GameContext Context { get; set; }
}
[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;
[IgnoreMember] public string EntryName
{
get => Username;
set => Username = value;
}
}
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class LoadoutData : DatabaseEntry, INamedEntry
{
[InspectableField, JsonProperty("name"), Key(1)]
public string Name;
[InspectableDatabaseLink(typeof(HullData)), JsonProperty("hull"), Key(2)]
public Guid Hull;
[JsonProperty("items"), Key(3)]
public List<Guid> Items = new List<Guid>();
[InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("resourceRequirements"), Key(4)]
public Dictionary<Guid, int> SimpleCargo = new Dictionary<Guid, int>();
[IgnoreMember] public string EntryName
{
get => Name;
set => Name = value;
}
}

View file

@ -66,6 +66,9 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
[JsonProperty("incompleteCargo"), Key(17)]
public Dictionary<Guid, double> IncompleteCargo = new Dictionary<Guid, double>();
[JsonProperty("active"), Key(18)]
public bool Active { get; set; }
//public List<IncompleteItem> IncompleteCargo = new List<IncompleteItem>();
[IgnoreMember] public Guid Zone;
@ -130,6 +133,11 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
Hydrate();
}
// private void GenerateHardpoints()
// {
//
// }
public void Hydrate()
{
//var gearIDs = EquippedItems.Append(Hull);
@ -162,9 +170,6 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
foreach (var hardpoint in Hardpoints)
if(hardpoint.Gear!=null)
foreach (var behavior in hardpoint.Behaviors
.Where(behavior => behavior is IInitializableBehavior))
((IInitializableBehavior) behavior).Initialize();
RecalculateMass();
}
@ -193,10 +198,14 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
Trigger = (Trigger) g.FirstOrDefault(b=>b is Trigger)
})
.ToArray();
foreach(var behavior in hardpoint.Behaviors)
foreach (var behavior in hardpoint.Behaviors)
{
if(behavior is IPopulationAssignment populationAssignment)
PopulationAssignments.Add(populationAssignment);
if(behavior is IInitializableBehavior initializableBehavior)
initializableBehavior.Initialize();
}
}
public void Unequip(Hardpoint hardpoint)
@ -541,6 +550,8 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
public virtual void Update(float delta)
{
if (!Active)
return;
foreach (var hardpoint in Hardpoints.Where(hp=>hp.Gear!=null))
{
foreach (var group in hardpoint.BehaviorGroups)

View file

@ -120,7 +120,7 @@ public class GameContext
{
// Create a list of available controllers for this task type
var availableControllers = CorporationControllers[corporation.ID]
.Where(controller => controller.TaskType == tasks.Key && controller.Available).ToList();
.Where(controller => controller.Available && controller.TaskType == tasks.Key).ToList();
// Iterate over the highest priority tasks for which controllers are available
foreach (var task in tasks.OrderByDescending(task => task.Priority).Take(availableControllers.Count))
@ -649,7 +649,7 @@ public class GameContext
return null;
}
var gearData = loadoutData.Items
var gearData = loadoutData.Gear
.Take(hullData.Hardpoints.Count)
.Where(id => id != Guid.Empty)
.Select(id => Cache.Get<GearData>(id))
@ -661,18 +661,6 @@ public class GameContext
return null;
}
var cargoData = loadoutData.Items
.Skip(hullData.Hardpoints.Count)
.Where(id => id != Guid.Empty)
.Select(id => Cache.Get<CraftedItemData>(id))
.ToArray();
if (cargoData.Any(g=>g==null))
{
_logger("Attempted to spawn loadout with invalid cargo ID");
return null;
}
var gear = gearData
.Select(gd => CreateInstance(gd.ID, GlobalData.StartingGearQualityMin, GlobalData.StartingGearQualityMax))
.ToArray();
@ -683,6 +671,16 @@ public class GameContext
foreach(var g in gear)
Cache.Add(g);
var cargoData = loadoutData.CompoundCargo
.SelectMany(x => Enumerable.Repeat(Cache.Get<CraftedItemData>(x.Key), x.Value))
.ToArray();
if (cargoData.Any(g=>g==null))
{
_logger("Attempted to spawn loadout with invalid cargo ID");
return null;
}
var cargo = cargoData
.Select(gd => CreateInstance(gd.ID, GlobalData.StartingGearQualityMin, GlobalData.StartingGearQualityMax))
.ToArray();
@ -716,6 +714,7 @@ public class GameContext
{
Name = $"{loadoutData.Name} {Random.NextInt(1,255):X}"
};
entity.Active = true;
Cache.Add(entity);
ZoneEntities[zone][entity.ID] = entity;
@ -746,6 +745,7 @@ public class GameContext
Temperature = 293,
Population = 4
};
entity.Active = true;
var parentCorp = Cache.Get<MegaCorporation>(corpData.Parent);
foreach (var attribute in parentCorp.Personality)
entity.Personality[attribute.Key] = attribute.Value;
@ -792,15 +792,45 @@ public class GameContext
_logger("Attempted to create crafted item instance which has no blueprint!");
return null;
}
var ingredients = blueprint.Ingredients.SelectMany(ci =>
bool invalidIngredientFound = false;
ItemData invalidIngredient = null;
var ingredients = new List<ItemInstance>();
foreach (var ingredient in blueprint.Ingredients)
{
var itemData = Cache.Get<ItemData>(ingredient.Key);
if (itemData is SimpleCommodityData)
{
var ingredient = Cache.Get(ci.Key);
return ingredient is SimpleCommodityData
? (IEnumerable<ItemInstance>) new[] {CreateInstance(ci.Key, ci.Value)}
: Enumerable.Range(0, ci.Value).Select(i => CreateInstance(ci.Key, qualityMin, qualityMax));
})
.ToList();
var itemInstance = CreateInstance(ingredient.Key, ingredient.Value);
if(itemInstance == null)
{
invalidIngredientFound = true;
invalidIngredient = itemData;
}
else ingredients.Add(itemInstance);
}
else
{
for (int i = 0; i < ingredient.Value; i++)
{
var itemInstance = CreateInstance(ingredient.Key, qualityMin, qualityMax);
if (itemInstance == null)
{
invalidIngredientFound = true;
invalidIngredient = itemData;
break;
}
ingredients.Add(itemInstance);
}
}
}
if (invalidIngredientFound)
{
_logger($"Unable to create crafted item ingredient: {invalidIngredient?.Name??"null"} for item {item.Name}");
}
Cache.AddAll(ingredients);

View file

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using MessagePack;
using Newtonsoft.Json;
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class LoadoutData : DatabaseEntry, INamedEntry
{
[InspectableField, JsonProperty("name"), Key(1)]
public string Name;
[InspectableDatabaseLink(typeof(HullData)), JsonProperty("hull"), Key(2)]
public Guid Hull;
[JsonProperty("items"), Key(3)]
public List<Guid> Gear = new List<Guid>();
[InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("simpleCargo"), Key(4)]
public Dictionary<Guid, int> SimpleCargo = new Dictionary<Guid, int>();
[InspectableDatabaseLink(typeof(CraftedItemData)), JsonProperty("compoundCargo"), Key(5)]
public Dictionary<Guid, int> CompoundCargo = new Dictionary<Guid, int>();
[IgnoreMember] public string EntryName
{
get => Name;
set => Name = value;
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 897e13bb0462456b800522cd213bf70d
timeCreated: 1591829121

View file

@ -0,0 +1,25 @@
using System;
using MessagePack;
using Newtonsoft.Json;
[RethinkTable("Users"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class PlayerData : 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;
[IgnoreMember] public string EntryName
{
get => Username;
set => Username = value;
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6daac48880264dcc91c928f0dd9c2abb
timeCreated: 1591829144

View file

@ -21,113 +21,10 @@ public class Ship : Entity
{
}
// public Gear GetEquipped(HardpointType type)
// {
// return Hardpoints.FirstOrDefault(hp => hp.HardpointData.Type == type)?.Item;
// }
//
// public T GetEquipped<T>() where T : EquippableItemData
// {
// var data = Hardpoints.FirstOrDefault(hp => Context.GetData(hp.Item) is T);
// if (data != null)
// return Context.GetData(data.Item) as T;
// return null;
// }
//
// public void Hydrate()
// {
// GenerateBehaviors();
//
// //HullHardpointCount = Hardpoints.Count(hp => hp.HardpointData.Type == HardpointType.Hull);
// }
//
// private void GenerateBehaviors()
// {
// }
// public void GenerateBindings()
// {
// Bindings = new Dictionary<KeyCode, Guid>();
//
// var bindables =
// ItemBindings.Select(id => new {id=id.Key, eq = id.Value.First().Hardpoint.Item.ItemData}).ToList();
//
// var weapons = bindables.Where(i => i.eq.HardpointType.IsWeapon()).ToArray();
//
// var mouseButtons = Enumerable.Range((int) KeyCode.Mouse0, 3).Cast<KeyCode>();
// foreach (var x in weapons.Zip(mouseButtons, (binding, key) => new {binding,key}))
// {
// Bindings.Add(x.key, x.binding.id);
// bindables.Remove(x.binding);
// }
//
// var thruster = bindables.FirstOrDefault(x => x.eq.HardpointType == HardpointType.Thruster);
// if (thruster != null)
// {
// Bindings.Add(KeyCode.LeftShift, thruster.id);
// bindables.Remove(thruster);
// }
//
// var utility = bindables.FirstOrDefault(x => !x.eq.HardpointType.IsWeapon());
// if (utility != null)
// {
// Bindings.Add(KeyCode.Space, utility.id);
// bindables.Remove(utility);
// }
//
// var numKeys = Enumerable.Range((int) KeyCode.Alpha1, 9).Cast<KeyCode>();
// foreach (var x in bindables.Zip(numKeys, (binding, key) => new {binding,key}))
// {
// Bindings.Add(x.key, x.binding.id);
// }
//
// }
// public void Activate(KeyCode binding)
// {
// if (Bindings.ContainsKey(binding))
// foreach (var behavior in ItemBindings[Bindings[binding]])
// {
// behavior.Activate();
// if(behavior.Hardpoint.ActionBarButton!=null)
// behavior.Hardpoint.ActionBarButton.Background.color = Color.yellow;
// }
// }
//
// public void Deactivate(KeyCode binding)
// {
// if(Bindings.ContainsKey(binding))
// foreach (var behavior in ItemBindings[Bindings[binding]])
// {
// behavior.Deactivate();
// if(behavior.Hardpoint.ActionBarButton!=null)
// behavior.Hardpoint.ActionBarButton.Background.color = GlobalData.Instance.UnselectedElementColor;
// }
// }
public override void Update(float delta)
{
Position += Velocity * delta;
base.Update(delta);
// foreach (var kvp in Contacts.ToArray())
// if (kvp.Key == null || Time.time - kvp.Value > GlobalData.Instance.TargetPersistenceDuration)
// {
// Contacts.Remove(kvp.Key);
// if (kvp.Key == Target)
// Target = null;
// }
}
// public void UpdateInput(float delta)
// {
// foreach (var key in Bindings.Keys)
// {
// if(Input.GetKeyDown(key))
// Activate(key);
// if(Input.GetKeyUp(key))
// Deactivate(key);
// }
//
// }
}