diff --git a/CGO/ClientGameObject.csproj b/CGO/ClientGameObject.csproj index abff0f0c..b1706052 100644 --- a/CGO/ClientGameObject.csproj +++ b/CGO/ClientGameObject.csproj @@ -109,7 +109,9 @@ + + diff --git a/CGO/Component/Equipment/EquipmentComponent.cs b/CGO/Component/Equipment/EquipmentComponent.cs index c1d1b67c..0c349e97 100644 --- a/CGO/Component/Equipment/EquipmentComponent.cs +++ b/CGO/Component/Equipment/EquipmentComponent.cs @@ -1,8 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using GameObject; using Lidgren.Network; using SS13_Shared; using SS13_Shared.GO; +using SS13_Shared.GO.Component.Equipment; namespace CGO { @@ -16,19 +19,12 @@ public EquipmentComponent() Family = ComponentFamily.Equipment; } - public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender) + public override Type StateType { - switch ((EquipmentComponentNetMessage) message.MessageParameters[0]) - { - case EquipmentComponentNetMessage.ItemEquipped: - EquipItem((EquipmentSlot) message.MessageParameters[1], (int) message.MessageParameters[2]); - break; - case EquipmentComponentNetMessage.ItemUnEquipped: - UnEquipItem((EquipmentSlot) message.MessageParameters[1], (int) message.MessageParameters[2]); - break; - } + get { return typeof(EquipmentComponentState); } } + public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type, params object[] list) { @@ -103,21 +99,82 @@ private void EquipItem(EquipmentSlot part, int uid) if (!IsEmpty(part)) // Uh oh we are confused about something! But it's better to just do what the server says { - UnEquipItem(part, EquippedEntities[part].Uid); + UnEquipItem(part); } EquippedEntities.Add(part, Owner.EntityManager.GetEntity(uid)); } + + private void EquipItem(EquipmentSlot part, Entity entity) + { + if (!IsEmpty(part)) + { + UnEquipItem(part); + } + if (IsEquipped(entity)) + { + UnEquipItem(entity); + } + EquippedEntities.Add(part, entity); + } - private void UnEquipItem(EquipmentSlot part, int uid) + private void UnEquipItem(EquipmentSlot part) { EquippedEntities.Remove(part); } + public void UnEquipItem(Entity entity) + { + if (EquippedEntities.ContainsValue(entity)) + EquippedEntities.Remove(EquippedEntities.Where(x => x.Value == entity).Select(x => x.Key).First()); + } + public bool IsEmpty(EquipmentSlot part) { if (EquippedEntities.ContainsKey(part)) return false; return true; } + + public bool IsEquipped(Entity entity, EquipmentSlot slot) + { + return EquippedEntities.ContainsKey(slot) && EquippedEntities[slot] == entity; + } + + public bool IsEquipped(Entity entity) + { + return EquippedEntities.ContainsValue(entity); + } + + public override void HandleComponentState(dynamic state) + { + foreach (KeyValuePair curr in state.EquippedEntities) + { + Entity retEnt = Owner.EntityManager.GetEntity(curr.Value); + if(retEnt == null && !IsEmpty(curr.Key)) + { + UnEquipItem(curr.Key); + } + else if (retEnt != null) + { + if (!IsEquipped(retEnt, curr.Key)) + { + if (IsEquipped(retEnt)) + { + UnEquipItem(retEnt); + } + EquipItem(curr.Key, retEnt.Uid); + } + } + } + + var removed = EquippedEntities.Where(x => !state.EquippedEntities.ContainsKey(x.Key)); + foreach(KeyValuePair rem in removed) + { + UnEquipItem(rem.Key); + } + + //Find differences and raise event? + ActiveSlots = state.ActiveSlots; + } } } \ No newline at end of file diff --git a/CGO/Component/Renderable/AnimatedSpriteComponent.cs b/CGO/Component/Renderable/AnimatedSpriteComponent.cs index 7df1c82a..311b9fc5 100644 --- a/CGO/Component/Renderable/AnimatedSpriteComponent.cs +++ b/CGO/Component/Renderable/AnimatedSpriteComponent.cs @@ -306,8 +306,6 @@ public void SetMaster(Entity m) if (mastercompo == null) return; - // lets get gay together and do some shit like in that stupid book 50 shades of gay - // “His pointer finger circled my puckered love cave. “Are you ready for this?” he mewled, smirking at me like a mother hamster about to eat her three-legged young.” mastercompo.AddSlave(this); master = mastercompo; } diff --git a/CGO/Component/Renderable/ParticleSystemComponent.cs b/CGO/Component/Renderable/ParticleSystemComponent.cs index cd8d9b04..0f080059 100644 --- a/CGO/Component/Renderable/ParticleSystemComponent.cs +++ b/CGO/Component/Renderable/ParticleSystemComponent.cs @@ -146,8 +146,6 @@ public void SetMaster(Entity m) if (mastercompo == null) return; - // lets get gay together and do some shit like in that stupid book 50 shades of gay - // “His pointer finger circled my puckered love cave. “Are you ready for this?” he mewled, smirking at me like a mother hamster about to eat her three-legged young.” mastercompo.AddSlave(this); master = mastercompo; } diff --git a/CGO/Component/Renderable/SpriteComponent.cs b/CGO/Component/Renderable/SpriteComponent.cs index 837b37e4..4a5af8a7 100644 --- a/CGO/Component/Renderable/SpriteComponent.cs +++ b/CGO/Component/Renderable/SpriteComponent.cs @@ -364,8 +364,6 @@ public void SetMaster(Entity m) if (mastercompo == null) return; - // lets get gay together and do some shit like in that stupid book 50 shades of gay - // “His pointer finger circled my puckered love cave. “Are you ready for this?” he mewled, smirking at me like a mother hamster about to eat her three-legged young.” mastercompo.AddSlave(this); master = mastercompo; } diff --git a/ClientServices/UserInterface/Components/HandsGui.cs b/ClientServices/UserInterface/Components/HandsGui.cs index ffbce0b0..87c01304 100644 --- a/ClientServices/UserInterface/Components/HandsGui.cs +++ b/ClientServices/UserInterface/Components/HandsGui.cs @@ -241,13 +241,13 @@ public override bool MouseUp(MouseInputEventArgs e) else { if (handL.Contains(new Point((int) e.Position.X, (int) e.Position.Y)) && - hands.HandSlots.ContainsKey(Hand.Left)) + hands.HandSlots.ContainsKey(Hand.Left) && hands.HandSlots[Hand.Right] != null) { hands.HandSlots[Hand.Left].SendMessage(this, ComponentMessageType.ClickedInHand, _playerManager.ControlledEntity.Uid); } else if (handR.Contains(new Point((int) e.Position.X, (int) e.Position.Y)) && - hands.HandSlots.ContainsKey(Hand.Right)) + hands.HandSlots.ContainsKey(Hand.Right) && hands.HandSlots[Hand.Right] != null) { hands.HandSlots[Hand.Right].SendMessage(this, ComponentMessageType.ClickedInHand, _playerManager.ControlledEntity.Uid); diff --git a/SGO/Component/Equipment/EquipmentComponent.cs b/SGO/Component/Equipment/EquipmentComponent.cs index 73f33cfd..9949e1aa 100644 --- a/SGO/Component/Equipment/EquipmentComponent.cs +++ b/SGO/Component/Equipment/EquipmentComponent.cs @@ -5,7 +5,7 @@ using SGO.Item.ItemCapability; using SS13_Shared; using SS13_Shared.GO; -using SS13_Shared.GO.Equipment; +using SS13_Shared.GO.Component.Equipment; namespace SGO { @@ -111,8 +111,8 @@ public override void HandleInstantiationMessage(NetConnection netConnection) { Entity e = equippedEntities[p]; e.SendMessage(this, ComponentMessageType.ItemEquipped, Owner); - Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, netConnection, - EquipmentComponentNetMessage.ItemEquipped, p, e.Uid); + //Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, netConnection, + // EquipmentComponentNetMessage.ItemEquipped, p, e.Uid); } } } @@ -129,8 +129,8 @@ private void EquipEntityToPart(EquipmentSlot part, Entity e) equippedEntities.Add(part, e); e.SendMessage(this, ComponentMessageType.ItemEquipped, Owner); - Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, null, - EquipmentComponentNetMessage.ItemEquipped, part, e.Uid); + //Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, null, + // EquipmentComponentNetMessage.ItemEquipped, part, e.Uid); } } @@ -176,9 +176,9 @@ private void UnEquipEntity(EquipmentSlot part) if (!IsEmpty(part)) //If the part is not empty { equippedEntities[part].SendMessage(this, ComponentMessageType.ItemUnEquipped); - Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, null, - EquipmentComponentNetMessage.ItemUnEquipped, part, - equippedEntities[part].Uid); + //Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, null, + // EquipmentComponentNetMessage.ItemUnEquipped, part, + // equippedEntities[part].Uid); equippedEntities.Remove(part); } } @@ -347,7 +347,7 @@ public bool AddEntity(Entity user, Entity toAdd) public override ComponentState GetComponentState() { Dictionary equipped = equippedEntities.Select(x => new KeyValuePair(x.Key, x.Value.Uid)).ToDictionary(key => key.Key, va => va.Value); - return new EquipmentState(equipped, activeSlots); + return new EquipmentComponentState(equipped, activeSlots); } } } \ No newline at end of file diff --git a/SGO/Component/Equipment/NewEquipmentComponent.cs b/SGO/Component/Equipment/NewEquipmentComponent.cs index ceaf7cd6..b312cc4b 100644 --- a/SGO/Component/Equipment/NewEquipmentComponent.cs +++ b/SGO/Component/Equipment/NewEquipmentComponent.cs @@ -7,7 +7,7 @@ using SGO.Item.ItemCapability; using SS13_Shared; using SS13_Shared.GO; -using SS13_Shared.GO.Equipment; +using SS13_Shared.GO.Component.Equipment; namespace SGO { @@ -77,7 +77,7 @@ public bool AddEntity(Entity user, Entity toAdd) public override ComponentState GetComponentState() { Dictionary equipped = equippedEntities.Select(x => new KeyValuePair(x.Key, x.Value.Uid)).ToDictionary(key => key.Key, va => va.Value); - return new EquipmentState(equipped, activeSlots); + return new EquipmentComponentState(equipped, activeSlots); } } } \ No newline at end of file diff --git a/SGO/Component/Equippable/EquippableComponent.cs b/SGO/Component/Equippable/EquippableComponent.cs index 56936264..9a8945d1 100644 --- a/SGO/Component/Equippable/EquippableComponent.cs +++ b/SGO/Component/Equippable/EquippableComponent.cs @@ -3,6 +3,7 @@ using Lidgren.Network; using SS13_Shared; using SS13_Shared.GO; +using SS13_Shared.GO.Component.Equippable; namespace SGO { @@ -71,5 +72,10 @@ public override void SetParameter(ComponentParameter parameter) break; } } + + public override ComponentState GetComponentState() + { + return new EquippableComponentState(); + } } } \ No newline at end of file diff --git a/SGO/Component/Renderable/AnimatedSpriteComponent.cs b/SGO/Component/Renderable/AnimatedSpriteComponent.cs index 34fe4a50..9a47b9bc 100644 --- a/SGO/Component/Renderable/AnimatedSpriteComponent.cs +++ b/SGO/Component/Renderable/AnimatedSpriteComponent.cs @@ -90,8 +90,6 @@ public void SetMaster(Entity m) if (mastercompo == null) return; - // lets get gay together and do some shit like in that stupid book 50 shades of gay - // “His pointer finger circled my puckered love cave. “Are you ready for this?” he mewled, smirking at me like a mother hamster about to eat her three-legged young.” mastercompo.AddSlave(this); master = mastercompo; } diff --git a/SGO/Component/Renderable/SpriteComponent.cs b/SGO/Component/Renderable/SpriteComponent.cs index 27b791cf..8bed2c37 100644 --- a/SGO/Component/Renderable/SpriteComponent.cs +++ b/SGO/Component/Renderable/SpriteComponent.cs @@ -114,8 +114,6 @@ public void SetMaster(Entity m) if (mastercompo == null) return; - // lets get gay together and do some shit like in that stupid book 50 shades of gay - // “His pointer finger circled my puckered love cave. “Are you ready for this?” he mewled, smirking at me like a mother hamster about to eat her three-legged young.” mastercompo.AddSlave(this); master = mastercompo; } diff --git a/SS3D_shared/GO/Equipment/EquipmentState.cs b/SS3D_shared/GO/Component/Equipment/EquipmentComponentState.cs similarity index 63% rename from SS3D_shared/GO/Equipment/EquipmentState.cs rename to SS3D_shared/GO/Component/Equipment/EquipmentComponentState.cs index f109e87a..f4152aae 100644 --- a/SS3D_shared/GO/Equipment/EquipmentState.cs +++ b/SS3D_shared/GO/Component/Equipment/EquipmentComponentState.cs @@ -1,20 +1,20 @@ -using System; -using System.Collections.Generic; -using SS13_Shared.Serialization; - -namespace SS13_Shared.GO.Equipment -{ - [Serializable] - public class EquipmentState : ComponentState - { - public Dictionary EquippedEntities; - public List ActiveSlots; - - public EquipmentState(Dictionary _EquippedEntities, List _ActiveSlots) - : base(ComponentFamily.Equipment) - { - EquippedEntities = _EquippedEntities; - ActiveSlots = _ActiveSlots; - } - } +using System; +using System.Collections.Generic; +using SS13_Shared.Serialization; + +namespace SS13_Shared.GO.Component.Equipment +{ + [Serializable] + public class EquipmentComponentState : ComponentState + { + public Dictionary EquippedEntities; + public List ActiveSlots; + + public EquipmentComponentState(Dictionary _EquippedEntities, List _ActiveSlots) + : base(ComponentFamily.Equipment) + { + EquippedEntities = _EquippedEntities; + ActiveSlots = _ActiveSlots; + } + } } \ No newline at end of file diff --git a/SS3D_shared/GO/Component/Equippable/EquippableComponentState.cs b/SS3D_shared/GO/Component/Equippable/EquippableComponentState.cs new file mode 100644 index 00000000..7f9fc78d --- /dev/null +++ b/SS3D_shared/GO/Component/Equippable/EquippableComponentState.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SS13_Shared.GO.Component.Equippable +{ + [Serializable] + public class EquippableComponentState : ComponentState + { + public EquippableComponentState() + : base() + { + + } + } +} diff --git a/SS3D_shared/SS13_Shared.csproj b/SS3D_shared/SS13_Shared.csproj index 31122b85..c84c0261 100644 --- a/SS3D_shared/SS13_Shared.csproj +++ b/SS3D_shared/SS13_Shared.csproj @@ -118,8 +118,9 @@ + - +