Merge branches '20-06-08-submodule', 'virtualize-netids', 'betterConstruction' and '20-06-08-addcomp-default'

This commit is contained in:
Pieter-Jan Briers
2020-06-08 14:20:05 +02:00
32 changed files with 184 additions and 68 deletions

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Content.Client.GameObjects.Components.Construction;
using Content.Client.Interfaces.GameObjects;
using Content.Shared.Construction;
using Content.Shared.GameObjects.Components.Interactable;
using Robust.Client.Graphics;
@@ -48,7 +49,7 @@ namespace Content.Client.Construction
{
IoCManager.InjectDependencies(this);
Placement = (PlacementManager) IoCManager.Resolve<IPlacementManager>();
Placement.PlacementCanceled += OnPlacementCanceled;
Placement.PlacementChanged += OnPlacementChanged;
Title = "Construction";
@@ -95,7 +96,7 @@ namespace Content.Client.Construction
TextAlign = Label.AlignMode.Center,
Text = "Build!",
Disabled = true,
ToggleMode = false
ToggleMode = true
};
EraseButton = new Button
{
@@ -108,7 +109,7 @@ namespace Content.Client.Construction
hSplitContainer.AddChild(guide);
Contents.AddChild(hSplitContainer);
BuildButton.OnPressed += OnBuildPressed;
BuildButton.OnToggled += OnBuildToggled;
EraseButton.OnToggled += OnEraseToggled;
SearchBar.OnTextChanged += OnTextEntered;
RecipeList.OnItemSelected += OnItemSelected;
@@ -123,7 +124,7 @@ namespace Content.Client.Construction
if (disposing)
{
Placement.PlacementCanceled -= OnPlacementCanceled;
Placement.PlacementChanged -= OnPlacementChanged;
}
}
@@ -226,37 +227,49 @@ namespace Content.Client.Construction
PopulateTree(string.IsNullOrWhiteSpace(str) ? null : str.ToLowerInvariant());
}
void OnBuildPressed(BaseButton.ButtonEventArgs args)
void OnBuildToggled(BaseButton.ButtonToggledEventArgs args)
{
var prototype = (ConstructionPrototype) RecipeList.Selected.Metadata;
if (prototype == null)
if (args.Pressed)
{
return;
var prototype = (ConstructionPrototype) RecipeList.Selected.Metadata;
if (prototype == null)
{
return;
}
if (prototype.Type == ConstructionType.Item)
{
Owner.TryStartItemConstruction(prototype.ID);
BuildButton.Pressed = false;
return;
}
Placement.BeginHijackedPlacing(
new PlacementInformation
{
IsTile = false,
PlacementOption = prototype.PlacementMode
},
new ConstructionPlacementHijack(prototype, Owner));
}
if (prototype.Type != ConstructionType.Structure)
else
{
// In-hand attackby doesn't exist so this is the best alternative.
var loc = Owner.Owner.GetComponent<ITransformComponent>().GridPosition;
Owner.SpawnGhost(prototype, loc, Direction.North);
return;
Placement.Clear();
}
var hijack = new ConstructionPlacementHijack(prototype, Owner);
var info = new PlacementInformation
{
IsTile = false,
PlacementOption = prototype.PlacementMode,
};
Placement.BeginHijackedPlacing(info, hijack);
BuildButton.Pressed = args.Pressed;
}
private void OnEraseToggled(BaseButton.ButtonToggledEventArgs args)
{
var hijack = new ConstructionPlacementHijack(null, Owner);
Placement.ToggleEraserHijacked(hijack);
if (args.Pressed) Placement.Clear();
Placement.ToggleEraserHijacked(new ConstructionPlacementHijack(null, Owner));
EraseButton.Pressed = args.Pressed;
}
private void OnPlacementChanged(object sender, EventArgs e)
{
BuildButton.Pressed = false;
EraseButton.Pressed = false;
}
void PopulatePrototypeList()
@@ -363,11 +376,6 @@ namespace Content.Client.Construction
}
}
private void OnPlacementCanceled(object sender, EventArgs e)
{
EraseButton.Pressed = false;
}
private static int ComparePrototype(ConstructionPrototype x, ConstructionPrototype y)
{
return String.Compare(x.Name, y.Name, StringComparison.Ordinal);

View File

@@ -114,6 +114,12 @@ namespace Content.Client.GameObjects.Components.Construction
SendNetworkMessage(msg);
}
public void TryStartItemConstruction(string prototypeName)
{
var msg = new TryStartItemConstructionMessage(prototypeName);
SendNetworkMessage(msg);
}
public void ClearGhost(int ghostId)
{
if (Ghosts.TryGetValue(ghostId, out var ghost))

View File

@@ -42,7 +42,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
private Solution _containedSolution = new Solution();
private ReagentUnit _maxVolume;
private SolutionCaps _capabilities;
private string _fillInitState = "";
private string _fillInitState;
private int _fillInitSteps;
private string _fillPathString = "Objects/Chemistry/fillings.rsi";
private ResourcePath _fillPath;

View File

@@ -1,10 +1,8 @@
using System;
using Content.Server.GameObjects.Components.Stack;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Utility;
using Content.Shared.Construction;
using Content.Shared.GameObjects.Components.Construction;
using Content.Shared.Interfaces;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
@@ -13,7 +11,6 @@ using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Players;
@@ -40,6 +37,9 @@ namespace Content.Server.GameObjects.Components.Construction
case TryStartStructureConstructionMessage tryStart:
TryStartStructureConstruction(tryStart.Location, tryStart.PrototypeName, tryStart.Angle, tryStart.Ack);
break;
case TryStartItemConstructionMessage tryStart:
TryStartItemConstruction(tryStart.PrototypeName);
break;
}
}
@@ -102,5 +102,56 @@ namespace Content.Server.GameObjects.Components.Construction
var msg = new AckStructureConstructionMessage(ack);
SendNetworkMessage(msg);
}
void TryStartItemConstruction(string prototypeName)
{
var prototype = _prototypeManager.Index<ConstructionPrototype>(prototypeName);
if (prototype.Stages.Count < 2)
{
throw new InvalidOperationException($"Prototype '{prototypeName}' does not have enough stages.");
}
var stage0 = prototype.Stages[0];
if (!(stage0.Forward is ConstructionStepMaterial matStep))
{
throw new NotImplementedException();
}
// Try to find the stack with the material in the user's hand.
var hands = Owner.GetComponent<HandsComponent>();
var activeHand = hands.GetActiveHand?.Owner;
if (activeHand == null)
{
return;
}
if (!activeHand.TryGetComponent(out StackComponent stack) || !ConstructionComponent.MaterialStackValidFor(matStep, stack))
{
return;
}
if (!stack.Use(matStep.Amount))
{
return;
}
// OK WE'RE GOOD CONSTRUCTION STARTED.
EntitySystem.Get<AudioSystem>().Play("/Audio/items/deconstruct.ogg", Owner);
if (prototype.Stages.Count == 2)
{
// Exactly 2 stages, so don't make an intermediate frame.
var ent = _serverEntityManager.SpawnEntity(prototype.Result, Owner.Transform.GridPosition);
hands.PutInHandOrDrop(ent.GetComponent<ItemComponent>());
}
else
{
//TODO: Make these viable as an item and try putting them in the players hands
var frame = _serverEntityManager.SpawnEntity("structureconstructionframe", Owner.Transform.GridPosition);
var construction = frame.GetComponent<ConstructionComponent>();
construction.Init(prototype);
}
}
}
}

View File

@@ -16,7 +16,9 @@ namespace Content.Shared.GameObjects.Components.Cargo
public class CargoOrderDatabaseState : ComponentState
{
public readonly List<CargoOrderData> Orders;
public CargoOrderDatabaseState(List<CargoOrderData> orders) : base(ContentNetIDs.CARGO_ORDER_DATABASE)
public override uint NetID => ContentNetIDs.CARGO_ORDER_DATABASE;
public CargoOrderDatabaseState(List<CargoOrderData> orders)
{
Orders = orders;
}

View File

@@ -88,7 +88,9 @@ namespace Content.Shared.GameObjects.Components.Cargo
public class GalacticMarketState : ComponentState
{
public List<string> Products;
public GalacticMarketState(List<string> technologies) : base(ContentNetIDs.GALACTIC_MARKET)
public override uint NetID => ContentNetIDs.GALACTIC_MARKET;
public GalacticMarketState(List<string> technologies)
{
Products = technologies;
}

View File

@@ -22,8 +22,9 @@ namespace Content.Shared.GameObjects.Components.Chemistry
public ReagentUnit CurrentVolume { get; }
public ReagentUnit TotalVolume { get; }
public InjectorToggleMode CurrentMode { get; }
public override uint NetID => ContentNetIDs.REAGENT_INJECTOR;
public InjectorComponentState(ReagentUnit currentVolume, ReagentUnit totalVolume, InjectorToggleMode currentMode) : base(ContentNetIDs.REAGENT_INJECTOR)
public InjectorComponentState(ReagentUnit currentVolume, ReagentUnit totalVolume, InjectorToggleMode currentMode)
{
CurrentVolume = currentVolume;
TotalVolume = totalVolume;

View File

@@ -20,7 +20,9 @@ namespace Content.Shared.GameObjects.Components.Chemistry
[Serializable, NetSerializable]
public class SolutionComponentState : ComponentState
{
public SolutionComponentState() : base(ContentNetIDs.SOLUTION) { }
public override uint NetID => ContentNetIDs.SOLUTION;
public SolutionComponentState() { }
}
/// <inheritdoc />

View File

@@ -48,6 +48,26 @@ namespace Content.Shared.GameObjects.Components.Construction
}
}
/// <summary>
/// Sent client -> server to to tell the server that we started building
/// an item-construction.
/// </summary>
[Serializable, NetSerializable]
protected class TryStartItemConstructionMessage : ComponentMessage
{
/// <summary>
/// The construction prototype to start building.
/// </summary>
public readonly string PrototypeName;
public TryStartItemConstructionMessage(string prototypeName)
{
Directed = true;
PrototypeName = prototypeName;
}
}
[Serializable, NetSerializable]
protected class AckStructureConstructionMessage : ComponentMessage
{

View File

@@ -16,8 +16,9 @@ namespace Content.Shared.GameObjects
public class DamageComponentState : ComponentState
{
public Dictionary<DamageType, int> CurrentDamage = new Dictionary<DamageType, int>();
public override uint NetID => ContentNetIDs.DAMAGEABLE;
public DamageComponentState(Dictionary<DamageType, int> damage) : base(ContentNetIDs.DAMAGEABLE)
public DamageComponentState(Dictionary<DamageType, int> damage)
{
CurrentDamage = damage;
}

View File

@@ -59,8 +59,9 @@ namespace Content.Shared.GameObjects.Components.Instruments
public class InstrumentState : ComponentState
{
public bool Playing { get; }
public override uint NetID => ContentNetIDs.INSTRUMENTS;
public InstrumentState(bool playing, uint sequencerTick = 0) : base(ContentNetIDs.INSTRUMENTS)
public InstrumentState(bool playing, uint sequencerTick = 0)
{
Playing = playing;
}

View File

@@ -27,8 +27,9 @@ namespace Content.Shared.GameObjects.Components.Interactable
public class MultiToolComponentState : ComponentState
{
public ToolQuality Quality { get; }
public override uint NetID => ContentNetIDs.MULTITOOLS;
public MultiToolComponentState(ToolQuality quality) : base(ContentNetIDs.MULTITOOLS)
public MultiToolComponentState(ToolQuality quality)
{
Quality = quality;
}
@@ -41,8 +42,9 @@ namespace Content.Shared.GameObjects.Components.Interactable
public float Fuel { get; }
public bool Activated { get; }
public ToolQuality Quality { get; }
public override uint NetID => ContentNetIDs.WELDER;
public WelderComponentState(float fuelCapacity, float fuel, bool activated) : base(ContentNetIDs.WELDER)
public WelderComponentState(float fuelCapacity, float fuel, bool activated)
{
FuelCapacity = fuelCapacity;
Fuel = fuel;

View File

@@ -51,8 +51,9 @@ namespace Content.Shared.GameObjects
protected class InventoryComponentState : ComponentState
{
public List<KeyValuePair<Slots, EntityUid>> Entities { get; }
public override uint NetID => ContentNetIDs.STORAGE;
public InventoryComponentState(List<KeyValuePair<Slots, EntityUid>> entities) : base(ContentNetIDs.STORAGE)
public InventoryComponentState(List<KeyValuePair<Slots, EntityUid>> entities)
{
Entities = entities;
}

View File

@@ -7,8 +7,9 @@ namespace Content.Shared.GameObjects.Components.Items
public class ClothingComponentState : ItemComponentState
{
public string ClothingEquippedPrefix { get; set; }
public override uint NetID => ContentNetIDs.CLOTHING;
public ClothingComponentState(string clothingEquippedPrefix, string equippedPrefix) : base(equippedPrefix, ContentNetIDs.CLOTHING)
public ClothingComponentState(string clothingEquippedPrefix, string equippedPrefix) : base(equippedPrefix)
{
ClothingEquippedPrefix = clothingEquippedPrefix;
}

View File

@@ -8,15 +8,12 @@ namespace Content.Shared.GameObjects.Components.Items
public class ItemComponentState : ComponentState
{
public string EquippedPrefix { get; set; }
public override uint NetID => ContentNetIDs.ITEM;
public ItemComponentState(string equippedPrefix) : base(ContentNetIDs.ITEM)
public ItemComponentState(string equippedPrefix)
{
EquippedPrefix = equippedPrefix;
}
protected ItemComponentState(string equippedPrefix, uint netId) : base(netId)
{
EquippedPrefix = equippedPrefix;
}
}
}

View File

@@ -74,8 +74,9 @@ namespace Content.Shared.GameObjects.Components.Items
{
public TimeSpan? CooldownStart { get; set; }
public TimeSpan? CooldownEnd { get; set; }
public override uint NetID => ContentNetIDs.ITEMCOOLDOWN;
public ItemCooldownComponentState() : base(ContentNetIDs.ITEMCOOLDOWN)
public ItemCooldownComponentState()
{
}
}

View File

@@ -17,8 +17,9 @@ namespace Content.Shared.GameObjects
{
public readonly Dictionary<string, EntityUid> Hands;
public readonly string ActiveIndex;
public override uint NetID => ContentNetIDs.HANDS;
public HandsComponentState(Dictionary<string, EntityUid> hands, string activeIndex) : base(ContentNetIDs.HANDS)
public HandsComponentState(Dictionary<string, EntityUid> hands, string activeIndex)
{
Hands = hands;
ActiveIndex = activeIndex;

View File

@@ -57,9 +57,9 @@ namespace Content.Shared.GameObjects.Components.Mobs
{
public bool IsInCombatMode { get; }
public TargetingZone TargetingZone { get; }
public override uint NetID => ContentNetIDs.COMBATMODE;
public CombatModeComponentState(bool isInCombatMode, TargetingZone targetingZone)
: base(ContentNetIDs.COMBATMODE)
{
IsInCombatMode = isInCombatMode;
TargetingZone = targetingZone;

View File

@@ -69,7 +69,9 @@ namespace Content.Shared.GameObjects.Components.Mobs
[NetSerializable]
private sealed class HumanoidAppearanceComponentState : ComponentState
{
public HumanoidAppearanceComponentState(HumanoidCharacterAppearance appearance, Sex sex) : base(ContentNetIDs.HUMANOID_APPEARANCE)
public override uint NetID => ContentNetIDs.HUMANOID_APPEARANCE;
public HumanoidAppearanceComponentState(HumanoidCharacterAppearance appearance, Sex sex)
{
Appearance = appearance;
Sex = sex;

View File

@@ -24,8 +24,9 @@ namespace Content.Shared.GameObjects.Components.Mobs
public class OverlayEffectComponentState : ComponentState
{
public ScreenEffects ScreenEffect;
public override uint NetID => ContentNetIDs.OVERLAYEFFECTS;
public OverlayEffectComponentState(ScreenEffects screenEffect) : base(ContentNetIDs.OVERLAYEFFECTS)
public OverlayEffectComponentState(ScreenEffects screenEffect)
{
ScreenEffect = screenEffect;
}

View File

@@ -19,8 +19,9 @@ namespace Content.Shared.GameObjects.Components.Mobs
public class StatusEffectComponentState : ComponentState
{
public Dictionary<StatusEffect, string> StatusEffects;
public override uint NetID => ContentNetIDs.STATUSEFFECTS;
public StatusEffectComponentState(Dictionary<StatusEffect, string> statusEffects) : base(ContentNetIDs.STATUSEFFECTS)
public StatusEffectComponentState(Dictionary<StatusEffect, string> statusEffects)
{
StatusEffects = statusEffects;
}

View File

@@ -14,8 +14,9 @@ namespace Content.Shared.GameObjects.Components.Observer
public class GhostComponentState : ComponentState
{
public bool CanReturnToBody { get; }
public override uint NetID => ContentNetIDs.GHOST;
public GhostComponentState(bool canReturnToBody) : base(ContentNetIDs.GHOST)
public GhostComponentState(bool canReturnToBody)
{
CanReturnToBody = canReturnToBody;
}

View File

@@ -166,10 +166,11 @@ namespace Content.Shared.GameObjects.Components.PDA
public UplinkCategory Category;
public string Description;
public string ListingName;
public override uint NetID => ContentNetIDs.PDA;
public UplinkListingData(string listingName,string itemId,
int price, UplinkCategory category,
string description) : base(ContentNetIDs.PDA)
string description)
{
ListingName = listingName;
Price = price;

View File

@@ -117,7 +117,9 @@ namespace Content.Shared.GameObjects.Components.Research
public class LatheDatabaseState : ComponentState
{
public readonly List<string> Recipes;
public LatheDatabaseState(List<string> recipes) : base(ContentNetIDs.LATHE_DATABASE)
public override uint NetID => ContentNetIDs.LATHE_DATABASE;
public LatheDatabaseState(List<string> recipes)
{
Recipes = recipes;
}

View File

@@ -69,7 +69,9 @@ namespace Content.Shared.GameObjects.Components.Research
public class MaterialStorageState : ComponentState
{
public readonly Dictionary<string, int> Storage;
public MaterialStorageState(Dictionary<string, int> storage) : base(ContentNetIDs.MATERIAL_STORAGE)
public override uint NetID => ContentNetIDs.MATERIAL_STORAGE;
public MaterialStorageState(Dictionary<string, int> storage)
{
Storage = storage;
}

View File

@@ -63,7 +63,9 @@ namespace Content.Shared.GameObjects.Components.Research
public class ProtolatheDatabaseState : ComponentState
{
public readonly List<string> Recipes;
public ProtolatheDatabaseState(List<string> recipes) : base(ContentNetIDs.PROTOLATHE_DATABASE)
public override uint NetID => ContentNetIDs.PROTOLATHE_DATABASE;
public ProtolatheDatabaseState(List<string> recipes)
{
Recipes = recipes;
}

View File

@@ -104,12 +104,14 @@ namespace Content.Shared.GameObjects.Components.Research
public class TechnologyDatabaseState : ComponentState
{
public List<string> Technologies;
public TechnologyDatabaseState(List<string> technologies) : base(ContentNetIDs.TECHNOLOGY_DATABASE)
public override uint NetID => ContentNetIDs.TECHNOLOGY_DATABASE;
public TechnologyDatabaseState(List<string> technologies)
{
Technologies = technologies;
}
public TechnologyDatabaseState(List<TechnologyPrototype> technologies) : base(ContentNetIDs.TECHNOLOGY_DATABASE)
public TechnologyDatabaseState(List<TechnologyPrototype> technologies)
{
Technologies = new List<string>();
foreach (var technology in technologies)

View File

@@ -12,7 +12,9 @@ namespace Content.Shared.GameObjects.Components
[Serializable, NetSerializable]
protected sealed class HandheldLightComponentState : ComponentState
{
public HandheldLightComponentState(float? charge) : base(ContentNetIDs.HANDHELD_LIGHT)
public override uint NetID => ContentNetIDs.HANDHELD_LIGHT;
public HandheldLightComponentState(float? charge)
{
Charge = charge;
}

View File

@@ -107,8 +107,9 @@ namespace Content.Shared.GameObjects.Components
{
public int Count { get; }
public int MaxCount { get; }
public override uint NetID => ContentNetIDs.STACK;
public StackComponentState(int count, int maxCount) : base(ContentNetIDs.STACK)
public StackComponentState(int count, int maxCount)
{
Count = count;
MaxCount = maxCount;

View File

@@ -20,7 +20,9 @@ namespace Content.Shared.GameObjects.Components.Weapons.Ranged
/// </remarks>
public (int count, int max)? MagazineCount { get; }
public BallisticMagazineWeaponComponentState(bool chambered, (int count, int max)? magazineCount) : base(ContentNetIDs.BALLISTIC_MAGAZINE_WEAPON)
public override uint NetID => ContentNetIDs.BALLISTIC_MAGAZINE_WEAPON;
public BallisticMagazineWeaponComponentState(bool chambered, (int count, int max)? magazineCount)
{
Chambered = chambered;
MagazineCount = magazineCount;

View File

@@ -12,7 +12,7 @@ namespace Content.Shared.Materials
/// Materials are read-only storage for the properties of specific materials.
/// Properties should be intrinsic (or at least as much is necessary for game purposes).
/// </summary>
public class Material : IExposeData
public class Material : IExposeData
{
public string Name => _name;
private string _name = "unobtanium";