Hand switching works!

This commit is contained in:
PJB3005
2017-09-29 18:38:27 +02:00
parent 5fd0e31920
commit b0b220f085
3 changed files with 47 additions and 14 deletions

View File

@@ -1,5 +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.Shared;
using SS14.Shared.GameObjects; using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.GameObjects; using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Utility; using SS14.Shared.Utility;
@@ -28,6 +30,7 @@ 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 IInventoryComponent inventory; private IInventoryComponent inventory;
private YamlMappingNode tempParametersMapping; private YamlMappingNode tempParametersMapping;
@@ -42,6 +45,7 @@ namespace Content.Server.GameObjects
} }
} }
Owner.SubscribeEvent<BoundKeyChangeEventArgs>(OnKeyChange, this);
base.Initialize(); base.Initialize();
} }
@@ -160,6 +164,7 @@ 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);
} }
public void RemoveHand(string index) public void RemoveHand(string index)
@@ -171,6 +176,19 @@ namespace Content.Server.GameObjects
inventory.RemoveSlot(HandSlotName(index)); inventory.RemoveSlot(HandSlotName(index));
hands.Remove(index); hands.Remove(index);
orderedHands.Remove(index);
if (index == ActiveIndex)
{
if (orderedHands.Count == 0)
{
activeIndex = null;
}
else
{
activeIndex = orderedHands[0];
}
}
} }
public bool HasHand(string index) public bool HasHand(string index)
@@ -195,5 +213,24 @@ namespace Content.Server.GameObjects
} }
return new HandsComponentState(dict); return new HandsComponentState(dict);
} }
// Game logic goes here.
public void OnKeyChange(object sender, EntityEventArgs uncast)
{
var cast = (BoundKeyChangeEventArgs)uncast;
if (cast.Actor != Owner || cast.KeyFunction != BoundKeyFunctions.SwitchHands || cast.KeyState != BoundKeyState.Down)
{
return;
}
var index = orderedHands.FindIndex(x => x == ActiveIndex);
index++;
if (index >= orderedHands.Count)
{
index = 0;
}
ActiveIndex = orderedHands[index];
}
} }
} }

View File

@@ -0,0 +1,10 @@
- type: entity
name: Urist McHands
id: HumanMob_Content
parent: HumanMob
components:
- type: Hands
hands:
- left
- right
- type: Inventory

View File

@@ -1,14 +0,0 @@
- type: entity
name: IT HAS HANDS
id: thing_with_hands
components:
- type: Transform
- type: Hands
hands:
- left
- right
- type: Inventory
slots:
- head
- shoes
- uniform