From b0b220f085b5cee5123c906927aadd065b986705 Mon Sep 17 00:00:00 2001 From: PJB3005 Date: Fri, 29 Sep 2017 18:38:27 +0200 Subject: [PATCH] Hand switching works! --- .../Components/Items/HandsComponent.cs | 37 +++++++++++++++++++ Resources/Prototypes/Entities/Mobs.yml | 10 +++++ Resources/Prototypes/Entities/hands.yml | 14 ------- 3 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 Resources/Prototypes/Entities/Mobs.yml delete mode 100644 Resources/Prototypes/Entities/hands.yml diff --git a/Content.Server/GameObjects/Components/Items/HandsComponent.cs b/Content.Server/GameObjects/Components/Items/HandsComponent.cs index d03bdf9c91..f384741ae1 100644 --- a/Content.Server/GameObjects/Components/Items/HandsComponent.cs +++ b/Content.Server/GameObjects/Components/Items/HandsComponent.cs @@ -1,5 +1,7 @@ using Content.Server.Interfaces.GameObjects; using Content.Shared.GameObjects; +using SS14.Server.GameObjects.Events; +using SS14.Shared; using SS14.Shared.GameObjects; using SS14.Shared.Interfaces.GameObjects; using SS14.Shared.Utility; @@ -28,6 +30,7 @@ namespace Content.Server.GameObjects } private Dictionary hands = new Dictionary(); + private List orderedHands = new List(); private IInventoryComponent inventory; private YamlMappingNode tempParametersMapping; @@ -42,6 +45,7 @@ namespace Content.Server.GameObjects } } + Owner.SubscribeEvent(OnKeyChange, this); base.Initialize(); } @@ -160,6 +164,7 @@ namespace Content.Server.GameObjects var slot = inventory.AddSlot(HandSlotName(index)); hands[index] = slot; + orderedHands.Add(index); } public void RemoveHand(string index) @@ -171,6 +176,19 @@ namespace Content.Server.GameObjects inventory.RemoveSlot(HandSlotName(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) @@ -195,5 +213,24 @@ namespace Content.Server.GameObjects } 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]; + } } } diff --git a/Resources/Prototypes/Entities/Mobs.yml b/Resources/Prototypes/Entities/Mobs.yml new file mode 100644 index 0000000000..6e829fec7e --- /dev/null +++ b/Resources/Prototypes/Entities/Mobs.yml @@ -0,0 +1,10 @@ +- type: entity + name: Urist McHands + id: HumanMob_Content + parent: HumanMob + components: + - type: Hands + hands: + - left + - right + - type: Inventory diff --git a/Resources/Prototypes/Entities/hands.yml b/Resources/Prototypes/Entities/hands.yml deleted file mode 100644 index 4879b96150..0000000000 --- a/Resources/Prototypes/Entities/hands.yml +++ /dev/null @@ -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