Item pickup seems to work, crash due to netcode.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using Content.Server.Interfaces.GameObjects;
|
using Content.Server.Interfaces.GameObjects;
|
||||||
using Content.Shared.GameObjects;
|
using Content.Shared.GameObjects;
|
||||||
using SS14.Server.GameObjects.Events;
|
using SS14.Server.GameObjects.Events;
|
||||||
|
using SS14.Server.Interfaces.GameObjects;
|
||||||
using SS14.Shared;
|
using SS14.Shared;
|
||||||
using SS14.Shared.GameObjects;
|
using SS14.Shared.GameObjects;
|
||||||
using SS14.Shared.Interfaces.GameObjects;
|
using SS14.Shared.Interfaces.GameObjects;
|
||||||
@@ -32,11 +33,16 @@ namespace Content.Server.GameObjects
|
|||||||
private Dictionary<string, IInventorySlot> hands = new Dictionary<string, IInventorySlot>();
|
private Dictionary<string, IInventorySlot> hands = new Dictionary<string, IInventorySlot>();
|
||||||
private List<string> orderedHands = new List<string>();
|
private List<string> orderedHands = new List<string>();
|
||||||
private IInventoryComponent inventory;
|
private IInventoryComponent inventory;
|
||||||
|
private IServerTransformComponent transform;
|
||||||
private YamlMappingNode tempParametersMapping;
|
private YamlMappingNode tempParametersMapping;
|
||||||
|
|
||||||
|
// Mostly arbitrary.
|
||||||
|
public const float PICKUP_RANGE = 2;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
inventory = Owner.GetComponent<IInventoryComponent>();
|
inventory = Owner.GetComponent<IInventoryComponent>();
|
||||||
|
transform = Owner.GetComponent<IServerTransformComponent>();
|
||||||
if (tempParametersMapping != null)
|
if (tempParametersMapping != null)
|
||||||
{
|
{
|
||||||
foreach (var node in tempParametersMapping.GetNode<YamlSequenceNode>("hands"))
|
foreach (var node in tempParametersMapping.GetNode<YamlSequenceNode>("hands"))
|
||||||
@@ -46,12 +52,15 @@ namespace Content.Server.GameObjects
|
|||||||
}
|
}
|
||||||
|
|
||||||
Owner.SubscribeEvent<BoundKeyChangeEventArgs>(OnKeyChange, this);
|
Owner.SubscribeEvent<BoundKeyChangeEventArgs>(OnKeyChange, this);
|
||||||
|
Owner.SubscribeEvent<ClickedOnEntityEventArgs>(OnClick, this);
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnRemove()
|
public override void OnRemove()
|
||||||
{
|
{
|
||||||
inventory = null;
|
inventory = null;
|
||||||
|
Owner.UnsubscribeEvent<BoundKeyChangeEventArgs>(this);
|
||||||
|
Owner.UnsubscribeEvent<ClickedOnEntityEventArgs>(this);
|
||||||
base.OnRemove();
|
base.OnRemove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +174,10 @@ namespace Content.Server.GameObjects
|
|||||||
var slot = inventory.AddSlot(HandSlotName(index));
|
var slot = inventory.AddSlot(HandSlotName(index));
|
||||||
hands[index] = slot;
|
hands[index] = slot;
|
||||||
orderedHands.Add(index);
|
orderedHands.Add(index);
|
||||||
|
if (ActiveIndex == null)
|
||||||
|
{
|
||||||
|
ActiveIndex = index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveHand(string index)
|
public void RemoveHand(string index)
|
||||||
@@ -218,11 +231,24 @@ namespace Content.Server.GameObjects
|
|||||||
public void OnKeyChange(object sender, EntityEventArgs uncast)
|
public void OnKeyChange(object sender, EntityEventArgs uncast)
|
||||||
{
|
{
|
||||||
var cast = (BoundKeyChangeEventArgs)uncast;
|
var cast = (BoundKeyChangeEventArgs)uncast;
|
||||||
if (cast.Actor != Owner || cast.KeyFunction != BoundKeyFunctions.SwitchHands || cast.KeyState != BoundKeyState.Down)
|
if (cast.Actor != Owner || cast.KeyState != BoundKeyState.Down)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (cast.KeyFunction)
|
||||||
|
{
|
||||||
|
case BoundKeyFunctions.SwitchHands:
|
||||||
|
SwapHands();
|
||||||
|
break;
|
||||||
|
case BoundKeyFunctions.Drop:
|
||||||
|
Drop(ActiveIndex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SwapHands()
|
||||||
|
{
|
||||||
var index = orderedHands.FindIndex(x => x == ActiveIndex);
|
var index = orderedHands.FindIndex(x => x == ActiveIndex);
|
||||||
index++;
|
index++;
|
||||||
if (index >= orderedHands.Count)
|
if (index >= orderedHands.Count)
|
||||||
@@ -232,5 +258,23 @@ namespace Content.Server.GameObjects
|
|||||||
|
|
||||||
ActiveIndex = orderedHands[index];
|
ActiveIndex = orderedHands[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnClick(object sender, EntityEventArgs uncast)
|
||||||
|
{
|
||||||
|
var cast = (ClickedOnEntityEventArgs)uncast;
|
||||||
|
if (cast.MouseButton != MouseClickType.Left || Owner.EntityManager.GetEntity(cast.Clicker) != Owner)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var target = Owner.EntityManager.GetEntity(cast.Clicked);
|
||||||
|
var targetTransform = target.GetComponent<IServerTransformComponent>();
|
||||||
|
if (!target.TryGetComponent<IItemComponent>(out var item) || (targetTransform.WorldPosition - transform.WorldPosition).Length > PICKUP_RANGE)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PutInHand(item, ActiveIndex, fallback: false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
Resources/Prototypes/Entities/Items.yml
Normal file
7
Resources/Prototypes/Entities/Items.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
- type: entity
|
||||||
|
name: "Toolbox 2: Handle edition"
|
||||||
|
parent: Toolbox
|
||||||
|
id: ToolboxItem
|
||||||
|
components:
|
||||||
|
- type: Item
|
||||||
|
|
||||||
Reference in New Issue
Block a user