Done I hope. Needs testing and type checker updates.
waiting on https://github.com/space-wizards/space-station-14/pull/422
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
using Content.Server.Interfaces.GameObjects;
|
using Content.Server.Interfaces.GameObjects;
|
||||||
using SS14.Shared.GameObjects;
|
using SS14.Shared.GameObjects;
|
||||||
using SS14.Shared.Interfaces.GameObjects;
|
using SS14.Shared.Interfaces.GameObjects;
|
||||||
|
using SS14.Shared.Utility;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using YamlDotNet.RepresentationModel;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects
|
namespace Content.Server.GameObjects
|
||||||
{
|
{
|
||||||
@@ -32,10 +34,28 @@ namespace Content.Server.GameObjects
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
inventory = Owner.GetComponent<IInventoryComponent>();
|
inventory = Owner.GetComponent<IInventoryComponent>();
|
||||||
|
base.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IItemComponent> GetAllHands()
|
public override void OnRemove()
|
||||||
{
|
{
|
||||||
|
inventory = null;
|
||||||
|
base.OnRemove();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LoadParameters(YamlMappingNode mapping)
|
||||||
|
{
|
||||||
|
foreach (var node in mapping.GetNode<YamlSequenceNode>("hands"))
|
||||||
|
{
|
||||||
|
AddHand(node.AsString());
|
||||||
|
}
|
||||||
|
base.LoadParameters(mapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<IItemComponent> GetAllHeldItems()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
/*
|
||||||
foreach (var slot in hands.Values)
|
foreach (var slot in hands.Values)
|
||||||
{
|
{
|
||||||
if (slot.Item != null)
|
if (slot.Item != null)
|
||||||
@@ -43,6 +63,7 @@ namespace Content.Server.GameObjects
|
|||||||
yield return slot.Item;
|
yield return slot.Item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public IItemComponent GetHand(string index)
|
public IItemComponent GetHand(string index)
|
||||||
@@ -56,6 +77,8 @@ namespace Content.Server.GameObjects
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private IEnumerable<string> ActivePriorityEnumerable()
|
private IEnumerable<string> ActivePriorityEnumerable()
|
||||||
{
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
/*
|
||||||
yield return ActiveIndex;
|
yield return ActiveIndex;
|
||||||
foreach (var hand in hands.Keys)
|
foreach (var hand in hands.Keys)
|
||||||
{
|
{
|
||||||
@@ -66,6 +89,7 @@ namespace Content.Server.GameObjects
|
|||||||
|
|
||||||
yield return hand;
|
yield return hand;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool PutInHand(IItemComponent item)
|
public bool PutInHand(IItemComponent item)
|
||||||
@@ -127,5 +151,37 @@ namespace Content.Server.GameObjects
|
|||||||
var slot = hands[index];
|
var slot = hands[index];
|
||||||
return slot.Item != null && slot.Owner.CanDrop(slot.Name);
|
return slot.Item != null && slot.Owner.CanDrop(slot.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddHand(string index)
|
||||||
|
{
|
||||||
|
if (HasHand(index))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Hand '{index}' already exists.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var slot = inventory.AddSlot(HandSlotName(index));
|
||||||
|
hands[index] = slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveHand(string index)
|
||||||
|
{
|
||||||
|
if (!HasHand(index))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Hand '{index}' does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.RemoveSlot(HandSlotName(index));
|
||||||
|
hands.Remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasHand(string index)
|
||||||
|
{
|
||||||
|
return hands.ContainsKey(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the name of the slot passed to the inventory component.
|
||||||
|
/// </summary>
|
||||||
|
private string HandSlotName(string index) => $"_hand_{index}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ using Content.Server.Interfaces.GameObjects;
|
|||||||
using SS14.Server.GameObjects;
|
using SS14.Server.GameObjects;
|
||||||
using SS14.Server.GameObjects.Components.Container;
|
using SS14.Server.GameObjects.Components.Container;
|
||||||
using SS14.Server.Interfaces.GameObjects;
|
using SS14.Server.Interfaces.GameObjects;
|
||||||
|
using SS14.Shared.Utility;
|
||||||
using SS14.Shared.GameObjects;
|
using SS14.Shared.GameObjects;
|
||||||
using SS14.Shared.Interfaces.GameObjects;
|
using SS14.Shared.Interfaces.GameObjects;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using YamlDotNet.RepresentationModel;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects
|
namespace Content.Server.GameObjects
|
||||||
{
|
{
|
||||||
@@ -36,6 +38,18 @@ namespace Content.Server.GameObjects
|
|||||||
base.OnRemove();
|
base.OnRemove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void LoadParameters(YamlMappingNode mapping)
|
||||||
|
{
|
||||||
|
if (mapping.TryGetNode<YamlSequenceNode>("slots", out var slotsNode))
|
||||||
|
{
|
||||||
|
foreach (var node in slotsNode)
|
||||||
|
{
|
||||||
|
AddSlot(node.AsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
base.LoadParameters(mapping);
|
||||||
|
}
|
||||||
|
|
||||||
public IItemComponent Get(string slot)
|
public IItemComponent Get(string slot)
|
||||||
{
|
{
|
||||||
return _GetSlot(slot).Item;
|
return _GetSlot(slot).Item;
|
||||||
@@ -106,14 +120,14 @@ namespace Content.Server.GameObjects
|
|||||||
return item != null && container.CanRemove(item.Owner);
|
return item != null && container.CanRemove(item.Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddSlot(string slot)
|
public IInventorySlot AddSlot(string slot)
|
||||||
{
|
{
|
||||||
if (HasSlot(slot))
|
if (HasSlot(slot))
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Slot '{slot}' already exists.");
|
throw new InvalidOperationException($"Slot '{slot}' already exists.");
|
||||||
}
|
}
|
||||||
|
|
||||||
slots[slot] = new InventorySlot(slot, this);
|
return slots[slot] = new InventorySlot(slot, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveSlot(string slot)
|
public void RemoveSlot(string slot)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace Content.Server.Interfaces.GameObjects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enumerates over every held item.
|
/// Enumerates over every held item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IEnumerable<IItemComponent> GetAllHands();
|
IEnumerable<IItemComponent> GetAllHeldItems();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the item held by a hand.
|
/// Gets the item held by a hand.
|
||||||
@@ -70,5 +70,30 @@ namespace Content.Server.Interfaces.GameObjects
|
|||||||
/// True if the item can be dropped, false if the hand is empty or the item in the hand cannot be dropped.
|
/// True if the item can be dropped, false if the hand is empty or the item in the hand cannot be dropped.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
bool CanDrop(string index);
|
bool CanDrop(string index);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a new hand to this hands component.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index">The name of the hand to add.</param>
|
||||||
|
/// <exception cref="InvalidOperationException">
|
||||||
|
/// Thrown if a hand with specified name already exists.
|
||||||
|
/// </exception>
|
||||||
|
void AddHand(string index);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a hand from this hands component.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// If the hand contains an item, the item is dropped.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="index">The name of the hand to remove.</param>
|
||||||
|
void RemoveHand(string index);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks whether a hand with the specified name exists.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index">The hand name to check.</param>
|
||||||
|
/// <returns>True if the hand exists, false otherwise.</returns>
|
||||||
|
bool HasHand(string index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ namespace Content.Server.Interfaces.GameObjects
|
|||||||
/// <exception cref="InvalidOperationException">
|
/// <exception cref="InvalidOperationException">
|
||||||
/// Thrown if the slot with specified name already exists.
|
/// Thrown if the slot with specified name already exists.
|
||||||
/// </exception>
|
/// </exception>
|
||||||
void AddSlot(string slot);
|
IInventorySlot AddSlot(string slot);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes a slot from this inventory component.
|
/// Removes a slot from this inventory component.
|
||||||
|
|||||||
Reference in New Issue
Block a user