Skip to content

Commit

Permalink
Fucked around with components
Browse files Browse the repository at this point in the history
  • Loading branch information
spoogemonster committed Jan 16, 2015
1 parent 1541f5e commit 4a9cc51
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 56 deletions.
2 changes: 2 additions & 0 deletions CGO/ClientGameObject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@
<Compile Include="Component\Mover\SlaveMoverComponent.cs" />
<Compile Include="Component\Physics\PhysicsComponent.cs" />
<Compile Include="Component\PlayerActionComp\PlayerActionCompC.cs" />
<Compile Include="Component\Renderable\AnimatedItemSpriteComponent.cs" />
<Compile Include="Component\Renderable\AnimatedSpriteComponent.cs" />
<Compile Include="Component\Renderable\AnimatedWearableSpriteComponent.cs" />
<Compile Include="Component\Renderable\ParticleSystem.cs" />
<Compile Include="Component\Renderable\ParticleSystemComponent.cs" />
<Compile Include="Component\Renderable\Speechbubble.cs" />
Expand Down
83 changes: 70 additions & 13 deletions CGO/Component/Equipment/EquipmentComponent.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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<EquipmentSlot, int> 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<EquipmentSlot, Entity> rem in removed)
{
UnEquipItem(rem.Key);
}

//Find differences and raise event?
ActiveSlots = state.ActiveSlots;
}
}
}
2 changes: 0 additions & 2 deletions CGO/Component/Renderable/AnimatedSpriteComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions CGO/Component/Renderable/ParticleSystemComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions CGO/Component/Renderable/SpriteComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions ClientServices/UserInterface/Components/HandsGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions SGO/Component/Equipment/EquipmentComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -347,7 +347,7 @@ public bool AddEntity(Entity user, Entity toAdd)
public override ComponentState GetComponentState()
{
Dictionary<EquipmentSlot, int> equipped = equippedEntities.Select(x => new KeyValuePair<EquipmentSlot, int>(x.Key, x.Value.Uid)).ToDictionary(key => key.Key, va => va.Value);
return new EquipmentState(equipped, activeSlots);
return new EquipmentComponentState(equipped, activeSlots);
}
}
}
4 changes: 2 additions & 2 deletions SGO/Component/Equipment/NewEquipmentComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -77,7 +77,7 @@ public bool AddEntity(Entity user, Entity toAdd)
public override ComponentState GetComponentState()
{
Dictionary<EquipmentSlot, int> equipped = equippedEntities.Select(x => new KeyValuePair<EquipmentSlot, int>(x.Key, x.Value.Uid)).ToDictionary(key => key.Key, va => va.Value);
return new EquipmentState(equipped, activeSlots);
return new EquipmentComponentState(equipped, activeSlots);
}
}
}
6 changes: 6 additions & 0 deletions SGO/Component/Equippable/EquippableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Equippable;

namespace SGO
{
Expand Down Expand Up @@ -71,5 +72,10 @@ public override void SetParameter(ComponentParameter parameter)
break;
}
}

public override ComponentState GetComponentState()
{
return new EquippableComponentState();
}
}
}
2 changes: 0 additions & 2 deletions SGO/Component/Renderable/AnimatedSpriteComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions SGO/Component/Renderable/SpriteComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<EquipmentSlot, int> EquippedEntities;
public List<EquipmentSlot> ActiveSlots;

public EquipmentState(Dictionary<EquipmentSlot, int> _EquippedEntities, List<EquipmentSlot> _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<EquipmentSlot, int> EquippedEntities;
public List<EquipmentSlot> ActiveSlots;

public EquipmentComponentState(Dictionary<EquipmentSlot, int> _EquippedEntities, List<EquipmentSlot> _ActiveSlots)
: base(ComponentFamily.Equipment)
{
EquippedEntities = _EquippedEntities;
ActiveSlots = _ActiveSlots;
}
}
}
17 changes: 17 additions & 0 deletions SS3D_shared/GO/Component/Equippable/EquippableComponentState.cs
Original file line number Diff line number Diff line change
@@ -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()
{

}
}
}
3 changes: 2 additions & 1 deletion SS3D_shared/SS13_Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@
<Compile Include="AdminPermissions.cs" />
<Compile Include="BoundKeyEventArgs.cs" />
<Compile Include="EntityEvents.cs" />
<Compile Include="GO\Component\Equippable\EquippableComponentState.cs" />
<Compile Include="GO\Component\Item\ItemComponentState.cs" />
<Compile Include="GO\Equipment\EquipmentState.cs" />
<Compile Include="GO\Component\Equipment\EquipmentComponentState.cs" />
<Compile Include="GO\Events\InputEvents.cs" />
<Compile Include="GO\Component\Hands\HandsComponentState.cs" />
<Compile Include="GO\Inventory\InventoryState.cs" />
Expand Down

0 comments on commit 4a9cc51

Please sign in to comment.