GIGA REFACTOR

This commit is contained in:
YotaXP
2015-01-23 01:15:33 -05:00
parent 6c85d8cd15
commit 0c78e9554e
640 changed files with 64817 additions and 65137 deletions

View File

@@ -1,2 +1,2 @@
cd bin\client
start SpaceStation13.exe
start SpaceStation14.exe

View File

@@ -1,2 +1,2 @@
cd bin\server
start SS13_Server.exe
start SpaceStation14_Server.exe

View File

@@ -1,6 +0,0 @@
namespace ClientInterfaces.Serialization
{
public interface ISS13Serializer
{
}
}

View File

@@ -1,8 +0,0 @@
using ClientInterfaces.Serialization;
namespace ClientServices.Serialization
{
public class SS13Serializer : SS13_Shared.Serialization.SS13Serializer, ISS13Serializer
{
}
}

View File

@@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
namespace MessagingProfiler
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

View File

@@ -1,27 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace MessagingProfiler
{
/// <summary>
/// Interaction logic for LogViewer.xaml
/// </summary>
public partial class LogViewer : Page
{
public LogViewer()
{
InitializeComponent();
}
}
}

View File

@@ -1,10 +0,0 @@
using GameObject;
using SS13_Shared;
namespace SGO.Events
{
public class BoundKeyChangeEventArgs:SS13_Shared.GO.Events.BoundKeyChangeEventArgs
{
public Entity Actor;
}
}

View File

@@ -1,102 +1,102 @@
using System.Drawing;
using GorgonLibrary;
namespace ClientWindow
{
public class ClientWindowData
{
#region Fields
/// <summary>
/// Internal singleton instance holder.
/// </summary>
private static ClientWindowData _singleton;
#endregion
#region Properties
/// <summary>
/// Public singleton accessor property.
/// </summary>
public static ClientWindowData Singleton
{
get { return _singleton ?? (_singleton = new ClientWindowData()); }
}
/// <summary>
/// The top left point of the screen in world coordinates.
/// </summary>
public Vector2D ScreenOrigin { get; private set; }
/// <summary>
/// Rectangle representing the viewable area in world coordinates
/// </summary>
public RectangleF ViewPort { get; private set; }
/// <summary>
/// Translates a world position to a screen position.
/// </summary>
/// <param name="position">position to translate</param>
public static Vector2D WorldToScreen(Vector2D position)
{
return position - Singleton.ScreenOrigin;
}
/// <summary>
/// Translates a screen position to a world position
/// </summary>
/// <param name="position">position to translate</param>
public static Vector2D ScreenToWorld(Vector2D position)
{
return position + Singleton.ScreenOrigin;
}
#endregion
#region Methods
#region Constructors
private ClientWindowData()
{
ScreenOrigin = new Point(0, 0);
ViewPort = new RectangleF(ScreenOrigin, new Size(0, 0));
}
#endregion
#region Publics
/// <summary>
/// Updates the ScreenTopLeft and Viewport variables given a center point.
/// WORLD POSITION
/// </summary>
/// <param name="x">Center point x</param>
/// <param name="y">Center point y</param>
public void UpdateViewPort(float x, float y)
{
ScreenOrigin = new Vector2D
(
x - Gorgon.CurrentClippingViewport.Width/2.0f,
y - Gorgon.CurrentClippingViewport.Height/2.0f
);
ViewPort = new RectangleF(ScreenOrigin,
new SizeF(Gorgon.CurrentClippingViewport.Width,
Gorgon.CurrentClippingViewport.Height));
}
/// <summary>
/// Updates the ScreenTopLeft and Viewport variables given a center point.
/// </summary>
/// <param name="center">Center point</param>
public void UpdateViewPort(Vector2D center)
{
UpdateViewPort(center.X, center.Y);
}
#endregion
#endregion
}
using GorgonLibrary;
using System.Drawing;
namespace SS14.Client.ClientWindow
{
public class ClientWindowData
{
#region Fields
/// <summary>
/// Internal singleton instance holder.
/// </summary>
private static ClientWindowData _singleton;
#endregion
#region Properties
/// <summary>
/// Public singleton accessor property.
/// </summary>
public static ClientWindowData Singleton
{
get { return _singleton ?? (_singleton = new ClientWindowData()); }
}
/// <summary>
/// The top left point of the screen in world coordinates.
/// </summary>
public Vector2D ScreenOrigin { get; private set; }
/// <summary>
/// Rectangle representing the viewable area in world coordinates
/// </summary>
public RectangleF ViewPort { get; private set; }
/// <summary>
/// Translates a world position to a screen position.
/// </summary>
/// <param name="position">position to translate</param>
public static Vector2D WorldToScreen(Vector2D position)
{
return position - Singleton.ScreenOrigin;
}
/// <summary>
/// Translates a screen position to a world position
/// </summary>
/// <param name="position">position to translate</param>
public static Vector2D ScreenToWorld(Vector2D position)
{
return position + Singleton.ScreenOrigin;
}
#endregion
#region Methods
#region Constructors
private ClientWindowData()
{
ScreenOrigin = new Point(0, 0);
ViewPort = new RectangleF(ScreenOrigin, new Size(0, 0));
}
#endregion
#region Publics
/// <summary>
/// Updates the ScreenTopLeft and Viewport variables given a center point.
/// WORLD POSITION
/// </summary>
/// <param name="x">Center point x</param>
/// <param name="y">Center point y</param>
public void UpdateViewPort(float x, float y)
{
ScreenOrigin = new Vector2D
(
x - Gorgon.CurrentClippingViewport.Width/2.0f,
y - Gorgon.CurrentClippingViewport.Height/2.0f
);
ViewPort = new RectangleF(ScreenOrigin,
new SizeF(Gorgon.CurrentClippingViewport.Width,
Gorgon.CurrentClippingViewport.Height));
}
/// <summary>
/// Updates the ScreenTopLeft and Viewport variables given a center point.
/// </summary>
/// <param name="center">Center point</param>
public void UpdateViewPort(Vector2D center)
{
UpdateViewPort(center.X, center.Y);
}
#endregion
#endregion
}
}

View File

@@ -1,39 +1,39 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ClientWindow")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClientWindow")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0d4ef57b-9e50-4c2f-a981-b3ef33d0d6cc")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SS14.Client.ClientWindow")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SS14.Client.ClientWindow")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0d4ef57b-9e50-4c2f-a981-b3ef33d0d6cc")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -1,4 +1,4 @@
<Project frameworkVersion="v4_0" name="ClientWindow" rootNamespace="ClientWindow" type="Library" path="ClientWindow">
<Project frameworkVersion="v4_0" name="SS14.Client.ClientWindow" rootNamespace="SS14.Client.ClientWindow" type="Library" path="SS14.Client.ClientWindow">
<Configuration name="Debug" platform="x86">
<Options>
<OutputPath>../Bin</OutputPath>

View File

@@ -1,59 +1,59 @@
using System.Drawing;
using GameObject;
using Lidgren.Network;
using SS13_Shared.GO;
namespace CGO
{
public class ClickableComponent : Component
{
public ClickableComponent()
{
Family = ComponentFamily.Click;
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this)
return reply;
switch (type)
{
case ComponentMessageType.ClickedInHand:
DispatchInHandClick((int) list[0]);
break;
}
return reply;
}
public bool CheckClick(PointF worldPos, out int drawdepth)
{
ComponentReplyMessage reply = Owner.SendMessage(this, ComponentFamily.Renderable,
ComponentMessageType.CheckSpriteClick, worldPos);
if (reply.MessageType == ComponentMessageType.SpriteWasClicked && (bool) reply.ParamsList[0])
{
drawdepth = (int) reply.ParamsList[1];
return (bool) reply.ParamsList[0];
}
drawdepth = -1;
return false;
}
public void DispatchClick(int userUID)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, ComponentMessageType.Click,
userUID);
}
public void DispatchInHandClick(int userUID)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.ClickedInHand, userUID);
}
}
using Lidgren.Network;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using System.Drawing;
namespace SS14.Client.GameObjects
{
public class ClickableComponent : Component
{
public ClickableComponent()
{
Family = ComponentFamily.Click;
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this)
return reply;
switch (type)
{
case ComponentMessageType.ClickedInHand:
DispatchInHandClick((int) list[0]);
break;
}
return reply;
}
public bool CheckClick(PointF worldPos, out int drawdepth)
{
ComponentReplyMessage reply = Owner.SendMessage(this, ComponentFamily.Renderable,
ComponentMessageType.CheckSpriteClick, worldPos);
if (reply.MessageType == ComponentMessageType.SpriteWasClicked && (bool) reply.ParamsList[0])
{
drawdepth = (int) reply.ParamsList[1];
return (bool) reply.ParamsList[0];
}
drawdepth = -1;
return false;
}
public void DispatchClick(int userUID)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, ComponentMessageType.Click,
userUID);
}
public void DispatchInHandClick(int userUID)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.ClickedInHand, userUID);
}
}
}

View File

@@ -1,236 +1,236 @@
using System;
using System.Drawing;
using ClientInterfaces.Collision;
using GameObject;
using GorgonLibrary;
using Lidgren.Network;
using SS13.IoC;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Collidable;
namespace CGO
{
public class CollidableComponent : Component, ICollidable
{
public Color DebugColor { get; set; }
private bool collisionEnabled = true;
private RectangleF currentAABB;
protected bool isHardCollidable = true;
/// <summary>
/// X - Top | Y - Right | Z - Bottom | W - Left
/// </summary>
private Vector4D tweakAABB;
public CollidableComponent()
{
Family = ComponentFamily.Collidable;
DebugColor = Color.Red;
tweakAABB = new Vector4D(0,0,0,0);
}
public override Type StateType
{
get { return typeof (CollidableComponentState); }
}
private Vector4D TweakAABB
{
get { return tweakAABB; }
set { tweakAABB = value; }
}
private RectangleF OffsetAABB
{
get
{
// Return tweaked AABB
if (currentAABB != null)
return
new RectangleF(
currentAABB.Left +
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X -
(currentAABB.Width/2) + tweakAABB.W,
currentAABB.Top +
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y -
(currentAABB.Height/2) + tweakAABB.X,
currentAABB.Width - (tweakAABB.W - tweakAABB.Y),
currentAABB.Height - (tweakAABB.X - tweakAABB.Z));
else
return RectangleF.Empty;
}
}
#region ICollidable Members
public RectangleF AABB
{
get { return OffsetAABB; }
}
/// <summary>
/// Called when the collidable is bumped into by someone/something
/// </summary>
public void Bump(Entity ent)
{
if (OnBump != null)
OnBump(this, new EventArgs());
Owner.SendMessage(this, ComponentMessageType.Bumped, ent);
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, ComponentMessageType.Bumped,
ent.Uid);
}
public bool IsHardCollidable
{
get { return isHardCollidable; }
}
#endregion
public event EventHandler OnBump;
/// <summary>
/// OnAdd override -- gets the AABB from the sprite component and sends it to the collision manager.
/// </summary>
/// <param name="owner"></param>
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
GetAABB();
var cm = IoCManager.Resolve<ICollisionManager>();
cm.AddCollidable(this);
}
/// <summary>
/// OnRemove override -- removes the AABB from the collisionmanager.
/// </summary>
public override void OnRemove()
{
var cm = IoCManager.Resolve<ICollisionManager>();
cm.RemoveCollidable(this);
base.OnRemove();
}
/// <summary>
/// Message handler --
/// SpriteChanged means the spritecomponent changed the current sprite.
/// </summary>
/// <param name="sender"></param>
/// <param name="type"></param>
/// <param name="reply"></param>
/// <param name="list"></param>
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.SpriteChanged:
if (collisionEnabled)
{
GetAABB();
var cm = IoCManager.Resolve<ICollisionManager>();
cm.UpdateCollidable(this);
}
break;
case ComponentMessageType.DisableCollision:
DisableCollision();
break;
case ComponentMessageType.EnableCollision:
EnableCollision();
break;
}
return reply;
}
/// <summary>
/// Parameter Setting
/// Settable params:
/// TweakAABB - Vector4D
/// </summary>
/// <param name="parameter"></param>
public override void SetParameter(ComponentParameter parameter)
{
base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "TweakAABB":
TweakAABB = parameter.GetValue<Vector4D>();
break;
case "TweakAABBtop":
tweakAABB.X = parameter.GetValue<float>();
break;
case "TweakAABBright":
tweakAABB.Y = parameter.GetValue<float>();
break;
case "TweakAABBbottom":
tweakAABB.Z = parameter.GetValue<float>();
break;
case "TweakAABBleft":
tweakAABB.W = parameter.GetValue<float>();
break;
case "DebugColor":
var color = ColorTranslator.FromHtml(parameter.GetValue<string>());
if (!color.IsEmpty)
DebugColor = color;
break;
}
}
/// <summary>
/// Enables collidable
/// </summary>
private void EnableCollision()
{
collisionEnabled = true;
var cm = IoCManager.Resolve<ICollisionManager>();
cm.AddCollidable(this);
}
/// <summary>
/// Disables Collidable
/// </summary>
private void DisableCollision()
{
collisionEnabled = false;
var cm = IoCManager.Resolve<ICollisionManager>();
cm.RemoveCollidable(this);
}
/// <summary>
/// Gets the current AABB from the sprite component.
/// </summary>
private void GetAABB()
{
ComponentReplyMessage reply = Owner.SendMessage(this, ComponentFamily.Renderable,
ComponentMessageType.GetAABB);
if (reply.MessageType == ComponentMessageType.CurrentAABB)
{
currentAABB = (RectangleF) reply.ParamsList[0];
}
else
return;
}
public override void HandleComponentState(dynamic state)
{
if (state.CollisionEnabled != collisionEnabled)
{
if (state.CollisionEnabled)
EnableCollision();
else
DisableCollision();
}
}
}
using GorgonLibrary;
using Lidgren.Network;
using SS14.Client.Interfaces.Collision;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Collidable;
using SS14.Shared.IoC;
using System;
using System.Drawing;
namespace SS14.Client.GameObjects
{
public class CollidableComponent : Component, ICollidable
{
public Color DebugColor { get; set; }
private bool collisionEnabled = true;
private RectangleF currentAABB;
protected bool isHardCollidable = true;
/// <summary>
/// X - Top | Y - Right | Z - Bottom | W - Left
/// </summary>
private Vector4D tweakAABB;
public CollidableComponent()
{
Family = ComponentFamily.Collidable;
DebugColor = Color.Red;
tweakAABB = new Vector4D(0,0,0,0);
}
public override Type StateType
{
get { return typeof (CollidableComponentState); }
}
private Vector4D TweakAABB
{
get { return tweakAABB; }
set { tweakAABB = value; }
}
private RectangleF OffsetAABB
{
get
{
// Return tweaked AABB
if (currentAABB != null)
return
new RectangleF(
currentAABB.Left +
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X -
(currentAABB.Width/2) + tweakAABB.W,
currentAABB.Top +
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y -
(currentAABB.Height/2) + tweakAABB.X,
currentAABB.Width - (tweakAABB.W - tweakAABB.Y),
currentAABB.Height - (tweakAABB.X - tweakAABB.Z));
else
return RectangleF.Empty;
}
}
#region ICollidable Members
public RectangleF AABB
{
get { return OffsetAABB; }
}
/// <summary>
/// Called when the collidable is bumped into by someone/something
/// </summary>
public void Bump(Entity ent)
{
if (OnBump != null)
OnBump(this, new EventArgs());
Owner.SendMessage(this, ComponentMessageType.Bumped, ent);
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, ComponentMessageType.Bumped,
ent.Uid);
}
public bool IsHardCollidable
{
get { return isHardCollidable; }
}
#endregion
public event EventHandler OnBump;
/// <summary>
/// OnAdd override -- gets the AABB from the sprite component and sends it to the collision manager.
/// </summary>
/// <param name="owner"></param>
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
GetAABB();
var cm = IoCManager.Resolve<ICollisionManager>();
cm.AddCollidable(this);
}
/// <summary>
/// OnRemove override -- removes the AABB from the collisionmanager.
/// </summary>
public override void OnRemove()
{
var cm = IoCManager.Resolve<ICollisionManager>();
cm.RemoveCollidable(this);
base.OnRemove();
}
/// <summary>
/// Message handler --
/// SpriteChanged means the spritecomponent changed the current sprite.
/// </summary>
/// <param name="sender"></param>
/// <param name="type"></param>
/// <param name="reply"></param>
/// <param name="list"></param>
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.SpriteChanged:
if (collisionEnabled)
{
GetAABB();
var cm = IoCManager.Resolve<ICollisionManager>();
cm.UpdateCollidable(this);
}
break;
case ComponentMessageType.DisableCollision:
DisableCollision();
break;
case ComponentMessageType.EnableCollision:
EnableCollision();
break;
}
return reply;
}
/// <summary>
/// Parameter Setting
/// Settable params:
/// TweakAABB - Vector4D
/// </summary>
/// <param name="parameter"></param>
public override void SetParameter(ComponentParameter parameter)
{
base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "TweakAABB":
TweakAABB = parameter.GetValue<Vector4D>();
break;
case "TweakAABBtop":
tweakAABB.X = parameter.GetValue<float>();
break;
case "TweakAABBright":
tweakAABB.Y = parameter.GetValue<float>();
break;
case "TweakAABBbottom":
tweakAABB.Z = parameter.GetValue<float>();
break;
case "TweakAABBleft":
tweakAABB.W = parameter.GetValue<float>();
break;
case "DebugColor":
var color = ColorTranslator.FromHtml(parameter.GetValue<string>());
if (!color.IsEmpty)
DebugColor = color;
break;
}
}
/// <summary>
/// Enables collidable
/// </summary>
private void EnableCollision()
{
collisionEnabled = true;
var cm = IoCManager.Resolve<ICollisionManager>();
cm.AddCollidable(this);
}
/// <summary>
/// Disables Collidable
/// </summary>
private void DisableCollision()
{
collisionEnabled = false;
var cm = IoCManager.Resolve<ICollisionManager>();
cm.RemoveCollidable(this);
}
/// <summary>
/// Gets the current AABB from the sprite component.
/// </summary>
private void GetAABB()
{
ComponentReplyMessage reply = Owner.SendMessage(this, ComponentFamily.Renderable,
ComponentMessageType.GetAABB);
if (reply.MessageType == ComponentMessageType.CurrentAABB)
{
currentAABB = (RectangleF) reply.ParamsList[0];
}
else
return;
}
public override void HandleComponentState(dynamic state)
{
if (state.CollisionEnabled != collisionEnabled)
{
if (state.CollisionEnabled)
EnableCollision();
else
DisableCollision();
}
}
}
}

View File

@@ -1,10 +1,10 @@
namespace CGO
{
public class TriggerableComponent : CollidableComponent
{
public TriggerableComponent()
{
isHardCollidable = false;
}
}
namespace SS14.Client.GameObjects
{
public class TriggerableComponent : CollidableComponent
{
public TriggerableComponent()
{
isHardCollidable = false;
}
}
}

View File

@@ -1,70 +1,69 @@
using System.Drawing;
using System.Linq;
using ClientInterfaces.Collision;
using ClientInterfaces.GOC;
using GameObject;
using GorgonLibrary;
using SS13.IoC;
using SS13_Shared.GO;
namespace CGO
{
public class ColliderComponent : Component
{
public Color DebugColor { get; set; }
private RectangleF AABB
{
get
{
if (Owner.HasComponent(ComponentFamily.Hitbox))
return Owner.GetComponent<HitboxComponent>(ComponentFamily.Hitbox).AABB;
else if (Owner.HasComponent(ComponentFamily.Renderable))
return Owner.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).AverageAABB;
else
return RectangleF.Empty;
}
}
public ColliderComponent()
{
Family = ComponentFamily.Collider;
DebugColor = Color.Lime;
}
public RectangleF WorldAABB
{
get
{
// Return tweaked AABB
var aabb = AABB;
var trans = Owner.GetComponent<TransformComponent>(ComponentFamily.Transform);
if (trans == null)
return aabb;
else if (aabb != null)
return new RectangleF(
aabb.Left + trans.X,
aabb.Top + trans.Y,
aabb.Width,
aabb.Height);
else
return RectangleF.Empty;
}
}
public bool TryCollision(Vector2D offset, bool bump = false)
{
return IoCManager.Resolve<ICollisionManager>().TryCollide(Owner, offset, bump);
}
public override void SetParameter(ComponentParameter parameter) {
switch (parameter.MemberName) {
case "DebugColor":
var color = ColorTranslator.FromHtml(parameter.GetValue<string>());
if (!color.IsEmpty)
DebugColor = color;
break;
}
}
}
using GorgonLibrary;
using SS14.Client.Interfaces.Collision;
using SS14.Client.Interfaces.GOC;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.IoC;
using System.Drawing;
namespace SS14.Client.GameObjects
{
public class ColliderComponent : Component
{
public Color DebugColor { get; set; }
private RectangleF AABB
{
get
{
if (Owner.HasComponent(ComponentFamily.Hitbox))
return Owner.GetComponent<HitboxComponent>(ComponentFamily.Hitbox).AABB;
else if (Owner.HasComponent(ComponentFamily.Renderable))
return Owner.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).AverageAABB;
else
return RectangleF.Empty;
}
}
public ColliderComponent()
{
Family = ComponentFamily.Collider;
DebugColor = Color.Lime;
}
public RectangleF WorldAABB
{
get
{
// Return tweaked AABB
var aabb = AABB;
var trans = Owner.GetComponent<TransformComponent>(ComponentFamily.Transform);
if (trans == null)
return aabb;
else if (aabb != null)
return new RectangleF(
aabb.Left + trans.X,
aabb.Top + trans.Y,
aabb.Width,
aabb.Height);
else
return RectangleF.Empty;
}
}
public bool TryCollision(Vector2D offset, bool bump = false)
{
return IoCManager.Resolve<ICollisionManager>().TryCollide(Owner, offset, bump);
}
public override void SetParameter(ComponentParameter parameter) {
switch (parameter.MemberName) {
case "DebugColor":
var color = ColorTranslator.FromHtml(parameter.GetValue<string>());
if (!color.IsEmpty)
DebugColor = color;
break;
}
}
}
}

View File

@@ -1,60 +1,60 @@
using System;
using GameObject;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Damageable;
namespace CGO
{
public class DamageableComponent : Component
//The basic Damageable component does not recieve health updates from the server and doesnt know what its health is.
{
//Used for things that are binary. Either broken or not broken. (windows?)
protected bool IsDead;
public DamageableComponent()
{
Family = ComponentFamily.Damageable;
;
}
public override Type StateType
{
get { return typeof (DamageableComponentState); }
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.GetCurrentHealth:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentHealth, IsDead ? 0 : 1, 1);
//HANDLE THIS CORRECTLY
break;
}
return reply;
}
protected virtual void Die()
{
if (IsDead) return;
IsDead = true;
Owner.SendMessage(this, ComponentMessageType.Die);
}
public override void HandleComponentState(dynamic state)
{
dynamic newIsDeadState = state.IsDead;
if (newIsDeadState && IsDead == false)
Die();
}
}
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Damageable;
using System;
namespace SS14.Client.GameObjects
{
public class DamageableComponent : Component
//The basic Damageable component does not recieve health updates from the server and doesnt know what its health is.
{
//Used for things that are binary. Either broken or not broken. (windows?)
protected bool IsDead;
public DamageableComponent()
{
Family = ComponentFamily.Damageable;
;
}
public override Type StateType
{
get { return typeof (DamageableComponentState); }
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.GetCurrentHealth:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentHealth, IsDead ? 0 : 1, 1);
//HANDLE THIS CORRECTLY
break;
}
return reply;
}
protected virtual void Die()
{
if (IsDead) return;
IsDead = true;
Owner.SendMessage(this, ComponentMessageType.Die);
}
public override void HandleComponentState(dynamic state)
{
dynamic newIsDeadState = state.IsDead;
if (newIsDeadState && IsDead == false)
Die();
}
}
}

View File

@@ -1,71 +1,71 @@
using System;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Damageable.Health;
namespace CGO
{
public class HealthComponent : DamageableComponent
//Behaves like the damageable component but recieves updates about its health.
{
//Useful for objects that need to show different stages of damage clientside.
protected float Health;
protected float MaxHealth;
public override Type StateType
{
get { return typeof (HealthComponentState); }
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
var type = (ComponentMessageType) message.MessageParameters[0];
/*switch (type)
{
case (ComponentMessageType.HealthStatus):
Health = (float)message.MessageParameters[1];
MaxHealth = (float)message.MessageParameters[2];
if (GetHealth() <= 0) Die();
break;
}*/
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.GetCurrentHealth:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentHealth, GetHealth(), GetMaxHealth());
break;
}
return reply;
}
public virtual float GetMaxHealth()
{
return MaxHealth;
}
public virtual float GetHealth()
{
return Health;
}
public override void HandleComponentState(dynamic state)
{
base.HandleComponentState((HealthComponentState) state);
Health = state.Health;
MaxHealth = state.MaxHealth;
}
}
using Lidgren.Network;
using SS14.Shared;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Damageable.Health;
using System;
namespace SS14.Client.GameObjects
{
public class HealthComponent : DamageableComponent
//Behaves like the damageable component but recieves updates about its health.
{
//Useful for objects that need to show different stages of damage clientside.
protected float Health;
protected float MaxHealth;
public override Type StateType
{
get { return typeof (HealthComponentState); }
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
var type = (ComponentMessageType) message.MessageParameters[0];
/*switch (type)
{
case (ComponentMessageType.HealthStatus):
Health = (float)message.MessageParameters[1];
MaxHealth = (float)message.MessageParameters[2];
if (GetHealth() <= 0) Die();
break;
}*/
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.GetCurrentHealth:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentHealth, GetHealth(), GetMaxHealth());
break;
}
return reply;
}
public virtual float GetMaxHealth()
{
return MaxHealth;
}
public virtual float GetHealth()
{
return Health;
}
public override void HandleComponentState(dynamic state)
{
base.HandleComponentState((HealthComponentState) state);
Health = state.Health;
MaxHealth = state.MaxHealth;
}
}
}

View File

@@ -1,32 +1,32 @@
using System.Collections.Generic;
using System.Linq;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO
{
public class DamageLocation
{
public int CurrentHealth;
public Dictionary<DamageType, int> DamageIndex = new Dictionary<DamageType, int>();
public BodyPart Location;
public int MaxHealth;
public DamageLocation(BodyPart myPart, int maxHealth, int currHealth)
{
Location = myPart;
MaxHealth = maxHealth;
CurrentHealth = currHealth;
}
public int UpdateTotalHealth()
{
int updatedHealth = DamageIndex.Aggregate(MaxHealth, (current, curr) => current - curr.Value);
CurrentHealth = updatedHealth;
return CurrentHealth;
}
}
using SS14.Shared;
using SS14.Shared.GO;
using System.Collections.Generic;
using System.Linq;
namespace SS14.Client.GameObjects
{
public class DamageLocation
{
public int CurrentHealth;
public Dictionary<DamageType, int> DamageIndex = new Dictionary<DamageType, int>();
public BodyPart Location;
public int MaxHealth;
public DamageLocation(BodyPart myPart, int maxHealth, int currHealth)
{
Location = myPart;
MaxHealth = maxHealth;
CurrentHealth = currHealth;
}
public int UpdateTotalHealth()
{
int updatedHealth = DamageIndex.Aggregate(MaxHealth, (current, curr) => current - curr.Value);
CurrentHealth = updatedHealth;
return CurrentHealth;
}
}
}

View File

@@ -1,180 +1,180 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ClientInterfaces.UserInterface;
using Lidgren.Network;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Damageable.Health.LocationalHealth;
namespace CGO
{
public class HumanHealthComponent : HealthComponent
//Behaves like health component but tracks damage of individual zones.
{
//Useful for mobs.
public List<DamageLocation> DamageZones = new List<DamageLocation>(); //makes this protected again.
public override Type StateType
{
get { return typeof (HumanHealthComponentState); }
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
var type = (ComponentMessageType) message.MessageParameters[0];
switch (type)
{
case (ComponentMessageType.HealthStatus):
HandleHealthUpdate(message);
break;
}
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.GetCurrentLocationHealth:
var location = (BodyPart) list[0];
if (DamageZones.Exists(x => x.Location == location))
{
DamageLocation dmgLoc = DamageZones.First(x => x.Location == location);
reply = new ComponentReplyMessage(ComponentMessageType.CurrentLocationHealth, location,
dmgLoc.UpdateTotalHealth(), dmgLoc.MaxHealth);
}
break;
case ComponentMessageType.GetCurrentHealth:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentHealth, GetHealth(), GetMaxHealth());
break;
}
return reply;
}
public void HandleHealthUpdate(IncomingEntityComponentMessage msg)
{
var part = (BodyPart) msg.MessageParameters[1];
var dmgCount = (int) msg.MessageParameters[2];
var maxHP = (int) msg.MessageParameters[3];
if (DamageZones.Exists(x => x.Location == part))
{
DamageLocation existingZone = DamageZones.First(x => x.Location == part);
existingZone.MaxHealth = maxHP;
for (int i = 0; i < dmgCount; i++)
{
var type = (DamageType) msg.MessageParameters[4 + (i*2)];
//Retrieve data from message in pairs starting at 4
var amount = (int) msg.MessageParameters[5 + (i*2)];
if (existingZone.DamageIndex.ContainsKey(type))
existingZone.DamageIndex[type] = amount;
else
existingZone.DamageIndex.Add(type, amount);
}
existingZone.UpdateTotalHealth();
}
else
{
var newZone = new DamageLocation(part, maxHP, maxHP);
DamageZones.Add(newZone);
for (int i = 0; i < dmgCount; i++)
{
var type = (DamageType) msg.MessageParameters[4 + (i*2)];
//Retrieve data from message in pairs starting at 4
var amount = (int) msg.MessageParameters[5 + (i*2)];
if (newZone.DamageIndex.ContainsKey(type))
newZone.DamageIndex[type] = amount;
else
newZone.DamageIndex.Add(type, amount);
}
newZone.UpdateTotalHealth();
}
MaxHealth = GetMaxHealth();
Health = GetHealth();
if (Health <= 0) Die(); //Need better logic here.
IoCManager.Resolve<IUserInterfaceManager>().ComponentUpdate(GuiComponentType.TargetingUi);
}
public override float GetMaxHealth()
{
return DamageZones.Sum(x => x.MaxHealth);
}
public override float GetHealth()
{
return DamageZones.Sum(x => x.UpdateTotalHealth());
}
public override void HandleComponentState(dynamic state)
{
base.HandleComponentState((HumanHealthComponentState) state);
foreach (LocationHealthState locstate in state.LocationHealthStates)
{
BodyPart part = locstate.Location;
int maxHP = locstate.MaxHealth;
if (DamageZones.Exists(x => x.Location == part))
{
DamageLocation existingZone = DamageZones.First(x => x.Location == part);
existingZone.MaxHealth = maxHP;
foreach (var kvp in locstate.DamageIndex)
{
DamageType type = kvp.Key;
int amount = kvp.Value;
if (existingZone.DamageIndex.ContainsKey(type))
existingZone.DamageIndex[type] = amount;
else
existingZone.DamageIndex.Add(type, amount);
}
existingZone.UpdateTotalHealth();
}
else
{
var newZone = new DamageLocation(part, maxHP, maxHP);
DamageZones.Add(newZone);
foreach (var kvp in locstate.DamageIndex)
{
DamageType type = kvp.Key;
int amount = kvp.Value;
if (newZone.DamageIndex.ContainsKey(type))
newZone.DamageIndex[type] = amount;
else
newZone.DamageIndex.Add(type, amount);
}
newZone.UpdateTotalHealth();
}
MaxHealth = GetMaxHealth();
Health = GetHealth();
if (Health <= 0) Die(); //Need better logic here.
IoCManager.Resolve<IUserInterfaceManager>().ComponentUpdate(GuiComponentType.TargetingUi);
}
}
}
using Lidgren.Network;
using SS14.Client.Interfaces.UserInterface;
using SS14.Shared;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Damageable.Health.LocationalHealth;
using SS14.Shared.IoC;
using System;
using System.Collections.Generic;
using System.Linq;
namespace SS14.Client.GameObjects
{
public class HumanHealthComponent : HealthComponent
//Behaves like health component but tracks damage of individual zones.
{
//Useful for mobs.
public List<DamageLocation> DamageZones = new List<DamageLocation>(); //makes this protected again.
public override Type StateType
{
get { return typeof (HumanHealthComponentState); }
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
var type = (ComponentMessageType) message.MessageParameters[0];
switch (type)
{
case (ComponentMessageType.HealthStatus):
HandleHealthUpdate(message);
break;
}
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.GetCurrentLocationHealth:
var location = (BodyPart) list[0];
if (DamageZones.Exists(x => x.Location == location))
{
DamageLocation dmgLoc = DamageZones.First(x => x.Location == location);
reply = new ComponentReplyMessage(ComponentMessageType.CurrentLocationHealth, location,
dmgLoc.UpdateTotalHealth(), dmgLoc.MaxHealth);
}
break;
case ComponentMessageType.GetCurrentHealth:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentHealth, GetHealth(), GetMaxHealth());
break;
}
return reply;
}
public void HandleHealthUpdate(IncomingEntityComponentMessage msg)
{
var part = (BodyPart) msg.MessageParameters[1];
var dmgCount = (int) msg.MessageParameters[2];
var maxHP = (int) msg.MessageParameters[3];
if (DamageZones.Exists(x => x.Location == part))
{
DamageLocation existingZone = DamageZones.First(x => x.Location == part);
existingZone.MaxHealth = maxHP;
for (int i = 0; i < dmgCount; i++)
{
var type = (DamageType) msg.MessageParameters[4 + (i*2)];
//Retrieve data from message in pairs starting at 4
var amount = (int) msg.MessageParameters[5 + (i*2)];
if (existingZone.DamageIndex.ContainsKey(type))
existingZone.DamageIndex[type] = amount;
else
existingZone.DamageIndex.Add(type, amount);
}
existingZone.UpdateTotalHealth();
}
else
{
var newZone = new DamageLocation(part, maxHP, maxHP);
DamageZones.Add(newZone);
for (int i = 0; i < dmgCount; i++)
{
var type = (DamageType) msg.MessageParameters[4 + (i*2)];
//Retrieve data from message in pairs starting at 4
var amount = (int) msg.MessageParameters[5 + (i*2)];
if (newZone.DamageIndex.ContainsKey(type))
newZone.DamageIndex[type] = amount;
else
newZone.DamageIndex.Add(type, amount);
}
newZone.UpdateTotalHealth();
}
MaxHealth = GetMaxHealth();
Health = GetHealth();
if (Health <= 0) Die(); //Need better logic here.
IoCManager.Resolve<IUserInterfaceManager>().ComponentUpdate(GuiComponentType.TargetingUi);
}
public override float GetMaxHealth()
{
return DamageZones.Sum(x => x.MaxHealth);
}
public override float GetHealth()
{
return DamageZones.Sum(x => x.UpdateTotalHealth());
}
public override void HandleComponentState(dynamic state)
{
base.HandleComponentState((HumanHealthComponentState) state);
foreach (LocationHealthState locstate in state.LocationHealthStates)
{
BodyPart part = locstate.Location;
int maxHP = locstate.MaxHealth;
if (DamageZones.Exists(x => x.Location == part))
{
DamageLocation existingZone = DamageZones.First(x => x.Location == part);
existingZone.MaxHealth = maxHP;
foreach (var kvp in locstate.DamageIndex)
{
DamageType type = kvp.Key;
int amount = kvp.Value;
if (existingZone.DamageIndex.ContainsKey(type))
existingZone.DamageIndex[type] = amount;
else
existingZone.DamageIndex.Add(type, amount);
}
existingZone.UpdateTotalHealth();
}
else
{
var newZone = new DamageLocation(part, maxHP, maxHP);
DamageZones.Add(newZone);
foreach (var kvp in locstate.DamageIndex)
{
DamageType type = kvp.Key;
int amount = kvp.Value;
if (newZone.DamageIndex.ContainsKey(type))
newZone.DamageIndex[type] = amount;
else
newZone.DamageIndex.Add(type, amount);
}
newZone.UpdateTotalHealth();
}
MaxHealth = GetMaxHealth();
Health = GetHealth();
if (Health <= 0) Die(); //Need better logic here.
IoCManager.Resolve<IUserInterfaceManager>().ComponentUpdate(GuiComponentType.TargetingUi);
}
}
}
}

View File

@@ -1,87 +1,87 @@
using System;
using GameObject;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Direction;
namespace CGO
{
public class DirectionComponent : Component
{
private Direction _lastDeterminedDirection = Direction.South;
public DirectionComponent()
{
Direction = Direction.South;
Family = ComponentFamily.Direction;
}
public Direction Direction { get; set; }
public override Type StateType
{
get { return typeof (DirectionComponentState); }
}
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
owner.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += HandleOnMove;
}
public override void OnRemove()
{
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove -= HandleOnMove;
base.OnRemove();
}
public void HandleOnMove(object sender, VectorEventArgs args)
{
if (!(Owner.GetComponent(ComponentFamily.Mover) is PlayerInputMoverComponent))
{
return;
}
if (args.VectorFrom == args.VectorTo)
return;
SetMoveDir(DetermineDirection(args.VectorFrom, args.VectorTo));
}
private Direction DetermineDirection(Vector2 from, Vector2 to)
{
Vector2 delta = to - from;
if (delta.Magnitude < 0.1f)
return _lastDeterminedDirection;
if (delta.X > 0 && delta.Y > 0)
_lastDeterminedDirection = Direction.SouthEast;
if (delta.X > 0 && delta.Y < 0)
_lastDeterminedDirection = Direction.NorthEast;
if (delta.X < 0 && delta.Y > 0)
_lastDeterminedDirection = Direction.SouthWest;
if (delta.X < 0 && delta.Y < 0)
_lastDeterminedDirection = Direction.NorthWest;
if (delta.X > 0 && Math.Abs(0 - delta.Y) < 0.05f)
_lastDeterminedDirection = Direction.East;
if (delta.X < 0 && Math.Abs(0 - delta.Y) < 0.05f)
_lastDeterminedDirection = Direction.West;
if (delta.Y > 0 && Math.Abs(0 - delta.X) < 0.05f)
_lastDeterminedDirection = Direction.South;
if (delta.Y < 0 && Math.Abs(0 - delta.X) < 0.05f)
_lastDeterminedDirection = Direction.North;
return _lastDeterminedDirection;
}
private void SetMoveDir(Direction movedir)
{
Direction = movedir;
Owner.SendMessage(this, ComponentMessageType.MoveDirection, movedir);
}
public override void HandleComponentState(dynamic state)
{
var dir = (Direction) state.Direction;
SetMoveDir(dir);
}
}
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Direction;
using System;
namespace SS14.Client.GameObjects
{
public class DirectionComponent : Component
{
private Direction _lastDeterminedDirection = Direction.South;
public DirectionComponent()
{
Direction = Direction.South;
Family = ComponentFamily.Direction;
}
public Direction Direction { get; set; }
public override Type StateType
{
get { return typeof (DirectionComponentState); }
}
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
owner.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += HandleOnMove;
}
public override void OnRemove()
{
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove -= HandleOnMove;
base.OnRemove();
}
public void HandleOnMove(object sender, VectorEventArgs args)
{
if (!(Owner.GetComponent(ComponentFamily.Mover) is PlayerInputMoverComponent))
{
return;
}
if (args.VectorFrom == args.VectorTo)
return;
SetMoveDir(DetermineDirection(args.VectorFrom, args.VectorTo));
}
private Direction DetermineDirection(Vector2 from, Vector2 to)
{
Vector2 delta = to - from;
if (delta.Magnitude < 0.1f)
return _lastDeterminedDirection;
if (delta.X > 0 && delta.Y > 0)
_lastDeterminedDirection = Direction.SouthEast;
if (delta.X > 0 && delta.Y < 0)
_lastDeterminedDirection = Direction.NorthEast;
if (delta.X < 0 && delta.Y > 0)
_lastDeterminedDirection = Direction.SouthWest;
if (delta.X < 0 && delta.Y < 0)
_lastDeterminedDirection = Direction.NorthWest;
if (delta.X > 0 && Math.Abs(0 - delta.Y) < 0.05f)
_lastDeterminedDirection = Direction.East;
if (delta.X < 0 && Math.Abs(0 - delta.Y) < 0.05f)
_lastDeterminedDirection = Direction.West;
if (delta.Y > 0 && Math.Abs(0 - delta.X) < 0.05f)
_lastDeterminedDirection = Direction.South;
if (delta.Y < 0 && Math.Abs(0 - delta.X) < 0.05f)
_lastDeterminedDirection = Direction.North;
return _lastDeterminedDirection;
}
private void SetMoveDir(Direction movedir)
{
Direction = movedir;
Owner.SendMessage(this, ComponentMessageType.MoveDirection, movedir);
}
public override void HandleComponentState(dynamic state)
{
var dir = (Direction) state.Direction;
SetMoveDir(dir);
}
}
}

View File

@@ -1,63 +1,63 @@
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.EntityStats;
namespace CGO
{
public class EntityStatsComp : Component
{
private Dictionary<DamageType, int> armorStats = new Dictionary<DamageType, int>();
public EntityStatsComp()
{
Family = ComponentFamily.EntityStats;
}
public override Type StateType
{
get { return typeof (EntityStatsComponentState); }
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
var type = (ComponentMessageType) message.MessageParameters[0];
switch (type)
{
case (ComponentMessageType.ReturnArmorValues):
if (!armorStats.Keys.Contains((DamageType) message.MessageParameters[1]))
armorStats.Add((DamageType) message.MessageParameters[1], (int) message.MessageParameters[2]);
else
armorStats[(DamageType) message.MessageParameters[1]] = (int) message.MessageParameters[2];
break;
default:
base.HandleNetworkMessage(message, sender);
break;
}
}
public void PullFullUpdate() //Add proper message for this.
{
foreach (object curr in Enum.GetValues(typeof (DamageType)))
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.GetArmorValues, (int) curr);
}
public int GetArmorValue(DamageType damType)
{
if (armorStats.ContainsKey(damType)) return armorStats[damType];
else return 0;
}
public override void HandleComponentState(dynamic state)
{
armorStats = state.ArmorStats;
}
}
using Lidgren.Network;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.EntityStats;
using System;
using System.Collections.Generic;
using System.Linq;
namespace SS14.Client.GameObjects
{
public class EntityStatsComp : Component
{
private Dictionary<DamageType, int> armorStats = new Dictionary<DamageType, int>();
public EntityStatsComp()
{
Family = ComponentFamily.EntityStats;
}
public override Type StateType
{
get { return typeof (EntityStatsComponentState); }
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
var type = (ComponentMessageType) message.MessageParameters[0];
switch (type)
{
case (ComponentMessageType.ReturnArmorValues):
if (!armorStats.Keys.Contains((DamageType) message.MessageParameters[1]))
armorStats.Add((DamageType) message.MessageParameters[1], (int) message.MessageParameters[2]);
else
armorStats[(DamageType) message.MessageParameters[1]] = (int) message.MessageParameters[2];
break;
default:
base.HandleNetworkMessage(message, sender);
break;
}
}
public void PullFullUpdate() //Add proper message for this.
{
foreach (object curr in Enum.GetValues(typeof (DamageType)))
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.GetArmorValues, (int) curr);
}
public int GetArmorValue(DamageType damType)
{
if (armorStats.ContainsKey(damType)) return armorStats[damType];
else return 0;
}
public override void HandleComponentState(dynamic state)
{
armorStats = state.ArmorStats;
}
}
}

View File

@@ -1,180 +1,180 @@
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
{
public class EquipmentComponent : Component
{
public List<EquipmentSlot> ActiveSlots = new List<EquipmentSlot>();
public Dictionary<EquipmentSlot, Entity> EquippedEntities = new Dictionary<EquipmentSlot, Entity>();
public EquipmentComponent()
{
Family = ComponentFamily.Equipment;
}
public override Type StateType
{
get { return typeof(EquipmentComponentState); }
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.GetItemInEquipmentSlot:
reply = !IsEmpty((EquipmentSlot) list[0])
? new ComponentReplyMessage(ComponentMessageType.ReturnItemInEquipmentSlot,
EquippedEntities[(EquipmentSlot) list[0]])
: new ComponentReplyMessage(ComponentMessageType.ItemSlotEmpty);
break;
case ComponentMessageType.Die:
foreach (Entity entity in EquippedEntities.Values)
{
entity.SendMessage(this, ComponentMessageType.WearerIsDead);
}
break;
case ComponentMessageType.Live:
foreach (Entity entity in EquippedEntities.Values)
{
entity.SendMessage(this, ComponentMessageType.WearerIsAlive);
}
break;
}
return reply;
}
public void DispatchEquip(int uid)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, ComponentMessageType.EquipItem,
uid);
}
public void DispatchEquipToPart(int uid, EquipmentSlot part)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.EquipItemToPart, uid, part);
}
public void DispatchEquipFromHand()
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.EquipItemInHand);
}
public void DispatchUnEquipToHand(int uid)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.UnEquipItemToHand, uid);
}
public void DispatchUnEquipItemToSpecifiedHand(int uid, Hand hand)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.UnEquipItemToSpecifiedHand, uid, hand);
}
public void DispatchUnEquipToFloor(int uid)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.UnEquipItemToFloor, uid);
}
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.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)
{
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.Keys.Where(x => !state.EquippedEntities.ContainsKey(x)).ToArray();
foreach(EquipmentSlot rem in removed)
{
UnEquipItem(rem);
}
//Find differences and raise event?
ActiveSlots = state.ActiveSlots;
}
}
using Lidgren.Network;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Equipment;
using System;
using System.Collections.Generic;
using System.Linq;
namespace SS14.Client.GameObjects
{
public class EquipmentComponent : Component
{
public List<EquipmentSlot> ActiveSlots = new List<EquipmentSlot>();
public Dictionary<EquipmentSlot, Entity> EquippedEntities = new Dictionary<EquipmentSlot, Entity>();
public EquipmentComponent()
{
Family = ComponentFamily.Equipment;
}
public override Type StateType
{
get { return typeof(EquipmentComponentState); }
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.GetItemInEquipmentSlot:
reply = !IsEmpty((EquipmentSlot) list[0])
? new ComponentReplyMessage(ComponentMessageType.ReturnItemInEquipmentSlot,
EquippedEntities[(EquipmentSlot) list[0]])
: new ComponentReplyMessage(ComponentMessageType.ItemSlotEmpty);
break;
case ComponentMessageType.Die:
foreach (Entity entity in EquippedEntities.Values)
{
entity.SendMessage(this, ComponentMessageType.WearerIsDead);
}
break;
case ComponentMessageType.Live:
foreach (Entity entity in EquippedEntities.Values)
{
entity.SendMessage(this, ComponentMessageType.WearerIsAlive);
}
break;
}
return reply;
}
public void DispatchEquip(int uid)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, ComponentMessageType.EquipItem,
uid);
}
public void DispatchEquipToPart(int uid, EquipmentSlot part)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.EquipItemToPart, uid, part);
}
public void DispatchEquipFromHand()
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.EquipItemInHand);
}
public void DispatchUnEquipToHand(int uid)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.UnEquipItemToHand, uid);
}
public void DispatchUnEquipItemToSpecifiedHand(int uid, Hand hand)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.UnEquipItemToSpecifiedHand, uid, hand);
}
public void DispatchUnEquipToFloor(int uid)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.UnEquipItemToFloor, uid);
}
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.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)
{
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.Keys.Where(x => !state.EquippedEntities.ContainsKey(x)).ToArray();
foreach(EquipmentSlot rem in removed)
{
UnEquipItem(rem);
}
//Find differences and raise event?
ActiveSlots = state.ActiveSlots;
}
}
}

View File

@@ -1,22 +1,22 @@
using SS13_Shared;
namespace CGO
{
public class HumanEquipmentComponent : EquipmentComponent
{
public HumanEquipmentComponent()
{
//These shit lines allow the fucking shit to be added to the shit
ActiveSlots.Add(EquipmentSlot.Back);
ActiveSlots.Add(EquipmentSlot.Belt);
ActiveSlots.Add(EquipmentSlot.Ears);
ActiveSlots.Add(EquipmentSlot.Eyes);
ActiveSlots.Add(EquipmentSlot.Feet);
ActiveSlots.Add(EquipmentSlot.Hands);
ActiveSlots.Add(EquipmentSlot.Head);
ActiveSlots.Add(EquipmentSlot.Inner);
ActiveSlots.Add(EquipmentSlot.Mask);
ActiveSlots.Add(EquipmentSlot.Outer);
}
}
using SS14.Shared;
namespace SS14.Client.GameObjects
{
public class HumanEquipmentComponent : EquipmentComponent
{
public HumanEquipmentComponent()
{
//These shit lines allow the fucking shit to be added to the shit
ActiveSlots.Add(EquipmentSlot.Back);
ActiveSlots.Add(EquipmentSlot.Belt);
ActiveSlots.Add(EquipmentSlot.Ears);
ActiveSlots.Add(EquipmentSlot.Eyes);
ActiveSlots.Add(EquipmentSlot.Feet);
ActiveSlots.Add(EquipmentSlot.Hands);
ActiveSlots.Add(EquipmentSlot.Head);
ActiveSlots.Add(EquipmentSlot.Inner);
ActiveSlots.Add(EquipmentSlot.Mask);
ActiveSlots.Add(EquipmentSlot.Outer);
}
}
}

View File

@@ -1,35 +1,34 @@
using System.Collections.Generic;
using GameObject;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO
{
public class NewEquipmentComponent : Component
{
public List<EquipmentSlot> ActiveSlots = new List<EquipmentSlot>();
public Dictionary<EquipmentSlot, Entity> EquippedEntities = new Dictionary<EquipmentSlot, Entity>();
public NewEquipmentComponent()
{
Family = ComponentFamily.Equipment;
}
public override void HandleComponentState(dynamic state)
{
Dictionary<EquipmentSlot, Entity> newInventory = new Dictionary<EquipmentSlot, Entity>();
foreach (KeyValuePair<EquipmentSlot, int> curr in state.EquippedEntities)
{
Entity retEnt = Owner.EntityManager.GetEntity(curr.Value);
newInventory.Add(curr.Key, retEnt);
}
//Find differences and raise event?
EquippedEntities = newInventory;
ActiveSlots = state.ActiveSlots;
}
}
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using System.Collections.Generic;
namespace SS14.Client.GameObjects
{
public class NewEquipmentComponent : Component
{
public List<EquipmentSlot> ActiveSlots = new List<EquipmentSlot>();
public Dictionary<EquipmentSlot, Entity> EquippedEntities = new Dictionary<EquipmentSlot, Entity>();
public NewEquipmentComponent()
{
Family = ComponentFamily.Equipment;
}
public override void HandleComponentState(dynamic state)
{
Dictionary<EquipmentSlot, Entity> newInventory = new Dictionary<EquipmentSlot, Entity>();
foreach (KeyValuePair<EquipmentSlot, int> curr in state.EquippedEntities)
{
Entity retEnt = Owner.EntityManager.GetEntity(curr.Value);
newInventory.Add(curr.Key, retEnt);
}
//Find differences and raise event?
EquippedEntities = newInventory;
ActiveSlots = state.ActiveSlots;
}
}
}

View File

@@ -1,110 +1,110 @@
using GameObject;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Equippable;
namespace CGO
{
public class EquippableComponent : Component
{
public EquipmentSlot wearloc;
public Entity currentWearer { get; set; }
public EquippableComponent()
{
Family = ComponentFamily.Equippable;
}
public override System.Type StateType
{
get { return typeof (EquippableComponentState); }
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
//base.HandleNetworkMessage(message);
switch ((EquippableComponentNetMessage) message.MessageParameters[0])
{
case EquippableComponentNetMessage.Equipped:
EquippedBy((int) message.MessageParameters[1], (EquipmentSlot) message.MessageParameters[2]);
break;
case EquippableComponentNetMessage.UnEquipped:
UnEquipped();
break;
}
}
private void EquippedBy(int uid, EquipmentSlot wearloc)
{
Owner.SendMessage(this, ComponentMessageType.ItemEquipped);
Owner.AddComponent(ComponentFamily.Mover,
Owner.EntityManager.ComponentFactory.GetComponent("SlaveMoverComponent"));
Owner.SendMessage(this, ComponentMessageType.SlaveAttach, uid);
switch (wearloc)
{
case EquipmentSlot.Back:
SendDrawDepth(DrawDepth.MobOverAccessoryLayer);
break;
case EquipmentSlot.Belt:
SendDrawDepth(DrawDepth.MobUnderAccessoryLayer);
break;
case EquipmentSlot.Ears:
SendDrawDepth(DrawDepth.MobUnderAccessoryLayer);
break;
case EquipmentSlot.Eyes:
SendDrawDepth(DrawDepth.MobUnderAccessoryLayer);
break;
case EquipmentSlot.Feet:
SendDrawDepth(DrawDepth.MobUnderClothingLayer);
break;
case EquipmentSlot.Hands:
SendDrawDepth(DrawDepth.MobOverAccessoryLayer);
break;
case EquipmentSlot.Head:
SendDrawDepth(DrawDepth.MobOverClothingLayer);
break;
case EquipmentSlot.Inner:
SendDrawDepth(DrawDepth.MobUnderClothingLayer);
break;
case EquipmentSlot.Mask:
SendDrawDepth(DrawDepth.MobUnderAccessoryLayer);
break;
case EquipmentSlot.Outer:
SendDrawDepth(DrawDepth.MobOverClothingLayer);
break;
}
}
private void SendDrawDepth(DrawDepth dd)
{
Owner.SendMessage(this, ComponentMessageType.SetWornDrawDepth, dd);
}
private void UnEquipped()
{
Owner.SendMessage(this, ComponentMessageType.ItemUnEquipped);
Owner.AddComponent(ComponentFamily.Mover,
Owner.EntityManager.ComponentFactory.GetComponent("BasicMoverComponent"));
}
public override void HandleComponentState(dynamic state)
{
int? holderUid = currentWearer != null ? currentWearer.Uid : (int?) null;
if(state.Holder != holderUid)
{
if(state.Holder == null)
{
UnEquipped();
currentWearer = null;
}
else
{
EquippedBy((int)state.Holder, state.WearLocation);
}
}
}
}
using Lidgren.Network;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Equippable;
namespace SS14.Client.GameObjects
{
public class EquippableComponent : Component
{
public EquipmentSlot wearloc;
public Entity currentWearer { get; set; }
public EquippableComponent()
{
Family = ComponentFamily.Equippable;
}
public override System.Type StateType
{
get { return typeof (EquippableComponentState); }
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
//base.HandleNetworkMessage(message);
switch ((EquippableComponentNetMessage) message.MessageParameters[0])
{
case EquippableComponentNetMessage.Equipped:
EquippedBy((int) message.MessageParameters[1], (EquipmentSlot) message.MessageParameters[2]);
break;
case EquippableComponentNetMessage.UnEquipped:
UnEquipped();
break;
}
}
private void EquippedBy(int uid, EquipmentSlot wearloc)
{
Owner.SendMessage(this, ComponentMessageType.ItemEquipped);
Owner.AddComponent(ComponentFamily.Mover,
Owner.EntityManager.ComponentFactory.GetComponent("SlaveMoverComponent"));
Owner.SendMessage(this, ComponentMessageType.SlaveAttach, uid);
switch (wearloc)
{
case EquipmentSlot.Back:
SendDrawDepth(DrawDepth.MobOverAccessoryLayer);
break;
case EquipmentSlot.Belt:
SendDrawDepth(DrawDepth.MobUnderAccessoryLayer);
break;
case EquipmentSlot.Ears:
SendDrawDepth(DrawDepth.MobUnderAccessoryLayer);
break;
case EquipmentSlot.Eyes:
SendDrawDepth(DrawDepth.MobUnderAccessoryLayer);
break;
case EquipmentSlot.Feet:
SendDrawDepth(DrawDepth.MobUnderClothingLayer);
break;
case EquipmentSlot.Hands:
SendDrawDepth(DrawDepth.MobOverAccessoryLayer);
break;
case EquipmentSlot.Head:
SendDrawDepth(DrawDepth.MobOverClothingLayer);
break;
case EquipmentSlot.Inner:
SendDrawDepth(DrawDepth.MobUnderClothingLayer);
break;
case EquipmentSlot.Mask:
SendDrawDepth(DrawDepth.MobUnderAccessoryLayer);
break;
case EquipmentSlot.Outer:
SendDrawDepth(DrawDepth.MobOverClothingLayer);
break;
}
}
private void SendDrawDepth(DrawDepth dd)
{
Owner.SendMessage(this, ComponentMessageType.SetWornDrawDepth, dd);
}
private void UnEquipped()
{
Owner.SendMessage(this, ComponentMessageType.ItemUnEquipped);
Owner.AddComponent(ComponentFamily.Mover,
Owner.EntityManager.ComponentFactory.GetComponent("BasicMoverComponent"));
}
public override void HandleComponentState(dynamic state)
{
int? holderUid = currentWearer != null ? currentWearer.Uid : (int?) null;
if(state.Holder != holderUid)
{
if(state.Holder == null)
{
UnEquipped();
currentWearer = null;
}
else
{
EquippedBy((int)state.Holder, state.WearLocation);
}
}
}
}
}

View File

@@ -1,163 +1,163 @@
using System.Collections.Generic;
using System.Linq;
using ClientInterfaces.UserInterface;
using GameObject;
using Lidgren.Network;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Hands;
namespace CGO
{
public class HumanHandsComponent : Component
{
public Dictionary<Hand, Entity> HandSlots { get; private set; }
public Hand CurrentHand { get; private set; }
public HumanHandsComponent()
{
HandSlots = new Dictionary<Hand, Entity>();
Family = ComponentFamily.Hands;
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
var type = (ComponentMessageType) message.MessageParameters[0];
int entityUid;
Hand usedHand;
Entity item;
switch (type)
{
case (ComponentMessageType.EntityChanged):
//This is not sent atm. Commented out serverside for later use.
entityUid = (int) message.MessageParameters[1];
usedHand = (Hand) message.MessageParameters[2];
item = Owner.EntityManager.GetEntity(entityUid);
if (HandSlots.Keys.Contains(usedHand))
HandSlots[usedHand] = item;
else
HandSlots.Add(usedHand, item);
break;
case (ComponentMessageType.HandsDroppedItem):
//entityUid = (int)message.MessageParameters[1];
usedHand = (Hand) message.MessageParameters[2];
//item = EntityManager.Singleton.GetEntity(entityUid);
//item.SendMessage(this, ComponentMessageType.Dropped, null);
HandSlots.Remove(usedHand);
break;
case (ComponentMessageType.HandsPickedUpItem):
entityUid = (int) message.MessageParameters[1];
usedHand = (Hand) message.MessageParameters[2];
item = Owner.EntityManager.GetEntity(entityUid);
//item.SendMessage(this, ComponentMessageType.PickedUp, null, usedHand);
HandSlots.Add(usedHand, item);
break;
case ComponentMessageType.ActiveHandChanged:
SwitchHandTo((Hand) message.MessageParameters[1]);
break;
}
IoCManager.Resolve<IUserInterfaceManager>().ComponentUpdate(GuiComponentType.HandsUi);
}
public override System.Type StateType
{
get
{
return typeof (HandsComponentState);
}
}
public void SendSwitchHands(Hand hand)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.ActiveHandChanged, hand);
}
public void SendDropEntity(Entity ent)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.DropEntityInHand, ent.Uid);
}
public bool IsHandEmpty(Hand hand)
{
return !HandSlots.ContainsKey(hand);
}
public void SendDropFromHand(Hand hand)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.DropItemInHand, hand);
}
private void SwitchHandTo(Hand hand)
{
CurrentHand = hand;
}
public override void HandleComponentState(dynamic state)
{
SetNewState(state);
}
private void SetNewState(HandsComponentState state)
{
bool changed = false;
var currentHand = Hand.None;
if(state.ActiveHand == InventoryLocation.HandLeft) currentHand = Hand.Left;
if(state.ActiveHand == InventoryLocation.HandRight) currentHand = Hand.Right;
if(CurrentHand != currentHand)
{
changed = true;
CurrentHand = currentHand;
}
foreach(var handSlot in state.Slots.Keys)
{
var hand = inventoryLocationToHand(handSlot);
if (!HandSlots.ContainsKey(hand))
{
HandSlots.Add(hand, null);
changed = true;
}
var existingSlotUid = HandSlots[hand] == null ? null : (int?)HandSlots[hand].Uid;
var newSlotUid = state.Slots[handSlot];
if(existingSlotUid == null)
{
if (newSlotUid != null)
{
HandSlots[hand] = Owner.EntityManager.GetEntity((int)newSlotUid);
changed = true;
}
}
else
{
if(newSlotUid != existingSlotUid)
{
if (newSlotUid != null)
HandSlots[hand] = Owner.EntityManager.GetEntity((int)newSlotUid);
else
HandSlots[hand] = null;
changed = true;
}
}
}
if(changed)
{
IoCManager.Resolve<IUserInterfaceManager>().ComponentUpdate(GuiComponentType.HandsUi);
}
}
private Hand inventoryLocationToHand(InventoryLocation location)
{
if(location == InventoryLocation.HandLeft)
return Hand.Left;
if(location == InventoryLocation.HandRight)
return Hand.Right;
return Hand.None;
}
}
using Lidgren.Network;
using SS14.Client.Interfaces.UserInterface;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Hands;
using SS14.Shared.IoC;
using System.Collections.Generic;
using System.Linq;
namespace SS14.Client.GameObjects
{
public class HumanHandsComponent : Component
{
public Dictionary<Hand, Entity> HandSlots { get; private set; }
public Hand CurrentHand { get; private set; }
public HumanHandsComponent()
{
HandSlots = new Dictionary<Hand, Entity>();
Family = ComponentFamily.Hands;
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
var type = (ComponentMessageType) message.MessageParameters[0];
int entityUid;
Hand usedHand;
Entity item;
switch (type)
{
case (ComponentMessageType.EntityChanged):
//This is not sent atm. Commented out serverside for later use.
entityUid = (int) message.MessageParameters[1];
usedHand = (Hand) message.MessageParameters[2];
item = Owner.EntityManager.GetEntity(entityUid);
if (HandSlots.Keys.Contains(usedHand))
HandSlots[usedHand] = item;
else
HandSlots.Add(usedHand, item);
break;
case (ComponentMessageType.HandsDroppedItem):
//entityUid = (int)message.MessageParameters[1];
usedHand = (Hand) message.MessageParameters[2];
//item = EntityManager.Singleton.GetEntity(entityUid);
//item.SendMessage(this, ComponentMessageType.Dropped, null);
HandSlots.Remove(usedHand);
break;
case (ComponentMessageType.HandsPickedUpItem):
entityUid = (int) message.MessageParameters[1];
usedHand = (Hand) message.MessageParameters[2];
item = Owner.EntityManager.GetEntity(entityUid);
//item.SendMessage(this, ComponentMessageType.PickedUp, null, usedHand);
HandSlots.Add(usedHand, item);
break;
case ComponentMessageType.ActiveHandChanged:
SwitchHandTo((Hand) message.MessageParameters[1]);
break;
}
IoCManager.Resolve<IUserInterfaceManager>().ComponentUpdate(GuiComponentType.HandsUi);
}
public override System.Type StateType
{
get
{
return typeof (HandsComponentState);
}
}
public void SendSwitchHands(Hand hand)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.ActiveHandChanged, hand);
}
public void SendDropEntity(Entity ent)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.DropEntityInHand, ent.Uid);
}
public bool IsHandEmpty(Hand hand)
{
return !HandSlots.ContainsKey(hand);
}
public void SendDropFromHand(Hand hand)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
ComponentMessageType.DropItemInHand, hand);
}
private void SwitchHandTo(Hand hand)
{
CurrentHand = hand;
}
public override void HandleComponentState(dynamic state)
{
SetNewState(state);
}
private void SetNewState(HandsComponentState state)
{
bool changed = false;
var currentHand = Hand.None;
if(state.ActiveHand == InventoryLocation.HandLeft) currentHand = Hand.Left;
if(state.ActiveHand == InventoryLocation.HandRight) currentHand = Hand.Right;
if(CurrentHand != currentHand)
{
changed = true;
CurrentHand = currentHand;
}
foreach(var handSlot in state.Slots.Keys)
{
var hand = inventoryLocationToHand(handSlot);
if (!HandSlots.ContainsKey(hand))
{
HandSlots.Add(hand, null);
changed = true;
}
var existingSlotUid = HandSlots[hand] == null ? null : (int?)HandSlots[hand].Uid;
var newSlotUid = state.Slots[handSlot];
if(existingSlotUid == null)
{
if (newSlotUid != null)
{
HandSlots[hand] = Owner.EntityManager.GetEntity((int)newSlotUid);
changed = true;
}
}
else
{
if(newSlotUid != existingSlotUid)
{
if (newSlotUid != null)
HandSlots[hand] = Owner.EntityManager.GetEntity((int)newSlotUid);
else
HandSlots[hand] = null;
changed = true;
}
}
}
if(changed)
{
IoCManager.Resolve<IUserInterfaceManager>().ComponentUpdate(GuiComponentType.HandsUi);
}
}
private Hand inventoryLocationToHand(InventoryLocation location)
{
if(location == InventoryLocation.HandLeft)
return Hand.Left;
if(location == InventoryLocation.HandRight)
return Hand.Right;
return Hand.None;
}
}
}

View File

@@ -1,38 +1,34 @@
using System.Collections.Generic;
using System.Linq;
using ClientInterfaces.UserInterface;
using GameObject;
using Lidgren.Network;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO
{
public class NewHandsComponent : Component
{
public NewHandsComponent()
{
HandSlots = new Dictionary<InventoryLocation, Entity>();
Family = ComponentFamily.Hands;
}
public Dictionary<InventoryLocation, Entity> HandSlots { get; private set; }
public InventoryLocation CurrentHand { get; private set; }
public override void HandleComponentState(dynamic state)
{
CurrentHand = state.ActiveHand;
Dictionary<InventoryLocation, Entity> newInventory = new Dictionary<InventoryLocation, Entity>();
foreach (KeyValuePair<InventoryLocation, int> curr in state.Slots)
{
Entity retEnt = Owner.EntityManager.GetEntity(curr.Value);
newInventory.Add(curr.Key, retEnt);
}
//Find differences and raise event?
HandSlots = newInventory;
}
}
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using System.Collections.Generic;
namespace SS14.Client.GameObjects
{
public class NewHandsComponent : Component
{
public NewHandsComponent()
{
HandSlots = new Dictionary<InventoryLocation, Entity>();
Family = ComponentFamily.Hands;
}
public Dictionary<InventoryLocation, Entity> HandSlots { get; private set; }
public InventoryLocation CurrentHand { get; private set; }
public override void HandleComponentState(dynamic state)
{
CurrentHand = state.ActiveHand;
Dictionary<InventoryLocation, Entity> newInventory = new Dictionary<InventoryLocation, Entity>();
foreach (KeyValuePair<InventoryLocation, int> curr in state.Slots)
{
Entity retEnt = Owner.EntityManager.GetEntity(curr.Value);
newInventory.Add(curr.Key, retEnt);
}
//Find differences and raise event?
HandSlots = newInventory;
}
}
}

View File

@@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Hitbox;
using System;
using System.Drawing;
using System.Linq;
using System.Text;
using GameObject;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Hitbox;
using ClientInterfaces.GOC;
namespace CGO {
namespace SS14.Client.GameObjects {
public class HitboxComponent : Component {
public RectangleF AABB { get; set; }

View File

@@ -1,43 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClientInterfaces.Resource;
using GameObject;
using SS13.IoC;
using SS13_Shared.GO;
using GorgonLibrary.Graphics;
namespace CGO
{
public class IconComponent : Component
{
public Sprite Icon;
public IconComponent()
{
Family = ComponentFamily.Icon;
}
/// <summary>
/// Set parameters :)
/// </summary>
/// <param name="parameter"></param>
public override void SetParameter(ComponentParameter parameter)
{
//base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "icon":
var iconName = parameter.GetValue<string>();
SetIcon(iconName);
break;
}
}
public void SetIcon(string name)
{
Icon = IoCManager.Resolve<IResourceManager>().GetSprite(name);
}
}
}
using GorgonLibrary.Graphics;
using SS14.Client.Interfaces.Resource;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.IoC;
namespace SS14.Client.GameObjects
{
public class IconComponent : Component
{
public Sprite Icon;
public IconComponent()
{
Family = ComponentFamily.Icon;
}
/// <summary>
/// Set parameters :)
/// </summary>
/// <param name="parameter"></param>
public override void SetParameter(ComponentParameter parameter)
{
//base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "icon":
var iconName = parameter.GetValue<string>();
SetIcon(iconName);
break;
}
}
public void SetIcon(string name)
{
Icon = IoCManager.Resolve<IResourceManager>().GetSprite(name);
}
}
}

View File

@@ -1,93 +1,93 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using GameObject;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO
{
public class ContextMenuComponent : Component
{
private readonly List<ContextMenuEntry> _entries = new List<ContextMenuEntry>();
public ContextMenuComponent()
{
Family = ComponentFamily.ContextMenu;
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.ContextAdd:
AddEntry((ContextMenuEntry) list[0]);
break;
case ComponentMessageType.ContextRemove:
RemoveEntryByName((string) list[0]);
break;
case ComponentMessageType.ContextGetEntries:
reply = new ComponentReplyMessage(ComponentMessageType.ContextGetEntries, _entries);
break;
}
return reply;
}
public void RemoveEntryByName(string name)
{
_entries.RemoveAll(x => x.EntryName.Equals(name, StringComparison.InvariantCultureIgnoreCase));
}
public void RemoveEntryByMessage(string message)
{
_entries.RemoveAll(x => x.ComponentMessage.Equals(message, StringComparison.InvariantCultureIgnoreCase));
}
public void AddEntry(ContextMenuEntry entry)
{
_entries.Add(entry);
}
public override void HandleExtendedParameters(XElement extendedParameters)
{
foreach (XElement param in extendedParameters.Descendants("ContextEntry"))
{
string name = "NULL";
string icon = "NULL";
string message = "NULL";
if (param.Attribute("name") != null)
name = param.Attribute("name").Value;
if (param.Attribute("icon") != null)
icon = param.Attribute("icon").Value;
if (param.Attribute("message") != null)
message = param.Attribute("message").Value;
var newEntry = new ContextMenuEntry
{
EntryName = name,
IconName = icon,
ComponentMessage = message
};
_entries.Add(newEntry);
}
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
}
}
using Lidgren.Network;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
namespace SS14.Client.GameObjects
{
public class ContextMenuComponent : Component
{
private readonly List<ContextMenuEntry> _entries = new List<ContextMenuEntry>();
public ContextMenuComponent()
{
Family = ComponentFamily.ContextMenu;
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.ContextAdd:
AddEntry((ContextMenuEntry) list[0]);
break;
case ComponentMessageType.ContextRemove:
RemoveEntryByName((string) list[0]);
break;
case ComponentMessageType.ContextGetEntries:
reply = new ComponentReplyMessage(ComponentMessageType.ContextGetEntries, _entries);
break;
}
return reply;
}
public void RemoveEntryByName(string name)
{
_entries.RemoveAll(x => x.EntryName.Equals(name, StringComparison.InvariantCultureIgnoreCase));
}
public void RemoveEntryByMessage(string message)
{
_entries.RemoveAll(x => x.ComponentMessage.Equals(message, StringComparison.InvariantCultureIgnoreCase));
}
public void AddEntry(ContextMenuEntry entry)
{
_entries.Add(entry);
}
public override void HandleExtendedParameters(XElement extendedParameters)
{
foreach (XElement param in extendedParameters.Descendants("ContextEntry"))
{
string name = "NULL";
string icon = "NULL";
string message = "NULL";
if (param.Attribute("name") != null)
name = param.Attribute("name").Value;
if (param.Attribute("icon") != null)
icon = param.Attribute("icon").Value;
if (param.Attribute("message") != null)
message = param.Attribute("message").Value;
var newEntry = new ContextMenuEntry
{
EntryName = name,
IconName = icon,
ComponentMessage = message
};
_entries.Add(newEntry);
}
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
}
}
}

View File

@@ -1,157 +1,157 @@
using System.Collections.Generic;
using System.Linq;
using ClientInterfaces.Input;
using GameObject;
using Lidgren.Network;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO
{
public class KeyBindingInputComponent : Component
{
#region Delegates
public delegate void KeyEvent(bool state);
#endregion
private readonly Dictionary<BoundKeyFunctions, KeyEvent> _keyHandlers;
private readonly Dictionary<BoundKeyFunctions, bool> _keyStates;
private bool _enabled = true;
public KeyBindingInputComponent()
{
Family = ComponentFamily.Input;
//Bind to the key binding manager
var keyBindingManager = IoCManager.Resolve<IKeyBindingManager>();
keyBindingManager.BoundKeyDown += KeyDown;
keyBindingManager.BoundKeyUp += KeyUp;
_keyStates = new Dictionary<BoundKeyFunctions, bool>();
_keyHandlers = new Dictionary<BoundKeyFunctions, KeyEvent>();
//Set up keystates
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this)
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.Die:
Disable();
break;
case ComponentMessageType.Live:
Enable();
break;
}
return reply;
}
public override void Shutdown()
{
base.Shutdown();
var keyBindingManager = IoCManager.Resolve<IKeyBindingManager>();
keyBindingManager.BoundKeyDown -= KeyDown;
keyBindingManager.BoundKeyUp -= KeyUp;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (_enabled)
UpdateKeys(frameTime);
}
private void Enable()
{
_enabled = true;
}
private void Disable()
{
_enabled = false;
//Remove all active key states and send keyup messages for them.
foreach (var state in _keyStates.ToList())
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, state.Key, BoundKeyState.Up);
Owner.SendMessage(this, ComponentMessageType.BoundKeyChange, state.Key, BoundKeyState.Up);
_keyStates.Remove(state.Key);
}
}
public virtual void KeyDown(object sender, BoundKeyEventArgs e)
{
if (!_enabled || GetKeyState(e.Function))
return; //Don't repeat keys that are already down.
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, e.Function, e.FunctionState);
SetKeyState(e.Function, true);
Owner.SendMessage(this, ComponentMessageType.BoundKeyChange, e.Function, e.FunctionState);
}
public virtual void KeyUp(object sender, BoundKeyEventArgs e)
{
if (!_enabled)
return;
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, e.Function, e.FunctionState);
SetKeyState(e.Function, false);
Owner.SendMessage(this, ComponentMessageType.BoundKeyChange, e.Function, e.FunctionState);
}
protected void SetKeyState(BoundKeyFunctions k, bool state)
{
// Check to see if we have a keyhandler for the key that's been pressed. Discard invalid keys.
_keyStates[k] = state;
}
public bool GetKeyState(BoundKeyFunctions k)
{
if (_keyStates.Keys.Contains(k))
return _keyStates[k];
return false;
}
public virtual void UpdateKeys(float frameTime)
{
//Rate limit
/*TimeSpan timeSinceLastUpdate = entityManager.now - lastKeyUpdate;
if (timeSinceLastUpdate.TotalMilliseconds < 1000 / keyUpdateRateLimit)
return;*/
// So basically we check for active keys with handlers and execute them. This is a linq query.
// Get all of the active keys' handlers
var activeKeyHandlers =
from keyState in _keyStates
join handler in _keyHandlers on keyState.Key equals handler.Key
select new {evt = handler.Value, state = keyState.Value};
//Execute the bastards!
foreach (var keyHandler in activeKeyHandlers)
{
//If there's even one active, we set updateRequired so that this gets hit again next update
//updateRequired = true; // QUICKNDIRTY
KeyEvent k = keyHandler.evt;
k(keyHandler.state);
}
//Delete false states from the dictionary so they don't get reprocessed and fuck up other stuff.
foreach (var state in _keyStates.ToList())
{
if (state.Value == false)
_keyStates.Remove(state.Key);
else
Owner.SendMessage(this, ComponentMessageType.BoundKeyRepeat, state.Key, BoundKeyState.Repeat);
}
//lastKeyUpdate = entityManager.now;
}
}
using Lidgren.Network;
using SS14.Client.Interfaces.Input;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.IoC;
using System.Collections.Generic;
using System.Linq;
namespace SS14.Client.GameObjects
{
public class KeyBindingInputComponent : Component
{
#region Delegates
public delegate void KeyEvent(bool state);
#endregion
private readonly Dictionary<BoundKeyFunctions, KeyEvent> _keyHandlers;
private readonly Dictionary<BoundKeyFunctions, bool> _keyStates;
private bool _enabled = true;
public KeyBindingInputComponent()
{
Family = ComponentFamily.Input;
//Bind to the key binding manager
var keyBindingManager = IoCManager.Resolve<IKeyBindingManager>();
keyBindingManager.BoundKeyDown += KeyDown;
keyBindingManager.BoundKeyUp += KeyUp;
_keyStates = new Dictionary<BoundKeyFunctions, bool>();
_keyHandlers = new Dictionary<BoundKeyFunctions, KeyEvent>();
//Set up keystates
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this)
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.Die:
Disable();
break;
case ComponentMessageType.Live:
Enable();
break;
}
return reply;
}
public override void Shutdown()
{
base.Shutdown();
var keyBindingManager = IoCManager.Resolve<IKeyBindingManager>();
keyBindingManager.BoundKeyDown -= KeyDown;
keyBindingManager.BoundKeyUp -= KeyUp;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (_enabled)
UpdateKeys(frameTime);
}
private void Enable()
{
_enabled = true;
}
private void Disable()
{
_enabled = false;
//Remove all active key states and send keyup messages for them.
foreach (var state in _keyStates.ToList())
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, state.Key, BoundKeyState.Up);
Owner.SendMessage(this, ComponentMessageType.BoundKeyChange, state.Key, BoundKeyState.Up);
_keyStates.Remove(state.Key);
}
}
public virtual void KeyDown(object sender, BoundKeyEventArgs e)
{
if (!_enabled || GetKeyState(e.Function))
return; //Don't repeat keys that are already down.
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, e.Function, e.FunctionState);
SetKeyState(e.Function, true);
Owner.SendMessage(this, ComponentMessageType.BoundKeyChange, e.Function, e.FunctionState);
}
public virtual void KeyUp(object sender, BoundKeyEventArgs e)
{
if (!_enabled)
return;
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, e.Function, e.FunctionState);
SetKeyState(e.Function, false);
Owner.SendMessage(this, ComponentMessageType.BoundKeyChange, e.Function, e.FunctionState);
}
protected void SetKeyState(BoundKeyFunctions k, bool state)
{
// Check to see if we have a keyhandler for the key that's been pressed. Discard invalid keys.
_keyStates[k] = state;
}
public bool GetKeyState(BoundKeyFunctions k)
{
if (_keyStates.Keys.Contains(k))
return _keyStates[k];
return false;
}
public virtual void UpdateKeys(float frameTime)
{
//Rate limit
/*TimeSpan timeSinceLastUpdate = entityManager.now - lastKeyUpdate;
if (timeSinceLastUpdate.TotalMilliseconds < 1000 / keyUpdateRateLimit)
return;*/
// So basically we check for active keys with handlers and execute them. This is a linq query.
// Get all of the active keys' handlers
var activeKeyHandlers =
from keyState in _keyStates
join handler in _keyHandlers on keyState.Key equals handler.Key
select new {evt = handler.Value, state = keyState.Value};
//Execute the bastards!
foreach (var keyHandler in activeKeyHandlers)
{
//If there's even one active, we set updateRequired so that this gets hit again next update
//updateRequired = true; // QUICKNDIRTY
KeyEvent k = keyHandler.evt;
k(keyHandler.state);
}
//Delete false states from the dictionary so they don't get reprocessed and fuck up other stuff.
foreach (var state in _keyStates.ToList())
{
if (state.Value == false)
_keyStates.Remove(state.Key);
else
Owner.SendMessage(this, ComponentMessageType.BoundKeyRepeat, state.Key, BoundKeyState.Repeat);
}
//lastKeyUpdate = entityManager.now;
}
}
}

View File

@@ -1,127 +1,127 @@
using System.Collections.Generic;
using System.Linq;
using GameObject;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO
{
public class InventoryComponent : Component
{
#region Delegates
public delegate void InventoryComponentUpdateHandler(
InventoryComponent sender, int maxSlots, List<Entity> entities);
public delegate void InventoryUpdateRequiredHandler(InventoryComponent sender);
#endregion
public InventoryComponent()
{
Family = ComponentFamily.Inventory;
ContainedEntities = new List<Entity>();
}
public List<Entity> ContainedEntities { get; private set; }
public int MaxSlots { get; private set; }
public event InventoryComponentUpdateHandler Changed;
public event InventoryUpdateRequiredHandler UpdateRequired;
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
switch ((ComponentMessageType) message.MessageParameters[0])
{
case ComponentMessageType.InventoryInformation:
UnpackListing(message);
break;
case ComponentMessageType.InventoryUpdateRequired:
if (UpdateRequired != null) UpdateRequired(this);
break;
}
}
private void UnpackListing(IncomingEntityComponentMessage msg)
{
MaxSlots = (int) msg.MessageParameters[1];
ContainedEntities.Clear();
for (int i = 0; i < (int) msg.MessageParameters[2]; i++)
{
int msgPos = 3 + i;
Entity entity = Owner.EntityManager.GetEntity((int) msg.MessageParameters[msgPos]);
if (entity != null)
ContainedEntities.Add(entity);
}
if (Changed != null) Changed(this, MaxSlots, ContainedEntities);
}
public bool ContainsEntity(Entity entity)
{
return ContainedEntities.Contains(entity);
}
public bool ContainsEntity(string templatename)
{
return ContainedEntities.Exists(x => x.Template.Name == templatename);
}
public Entity GetEntity(string templatename)
{
return ContainedEntities.Exists(x => x.Template.Name == templatename)
? ContainedEntities.First(x => x.Template.Name == templatename)
: null;
}
public void SendRequestListing()
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.InventoryInformation);
}
public void SendInventoryAdd(Entity ent)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.InventoryAdd, ent.Uid);
}
public void SendInventoryRemove(Entity ent)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.InventoryRemove, ent.Uid);
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.InventoryInformation:
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.InventoryInformation);
break;
case ComponentMessageType.InventoryAdd:
SendInventoryAdd((Entity) list[0]);
break;
case ComponentMessageType.InventoryRemove:
SendInventoryRemove((Entity) list[0]);
break;
}
return reply;
}
}
using Lidgren.Network;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using System.Collections.Generic;
using System.Linq;
namespace SS14.Client.GameObjects
{
public class InventoryComponent : Component
{
#region Delegates
public delegate void InventoryComponentUpdateHandler(
InventoryComponent sender, int maxSlots, List<Entity> entities);
public delegate void InventoryUpdateRequiredHandler(InventoryComponent sender);
#endregion
public InventoryComponent()
{
Family = ComponentFamily.Inventory;
ContainedEntities = new List<Entity>();
}
public List<Entity> ContainedEntities { get; private set; }
public int MaxSlots { get; private set; }
public event InventoryComponentUpdateHandler Changed;
public event InventoryUpdateRequiredHandler UpdateRequired;
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
switch ((ComponentMessageType) message.MessageParameters[0])
{
case ComponentMessageType.InventoryInformation:
UnpackListing(message);
break;
case ComponentMessageType.InventoryUpdateRequired:
if (UpdateRequired != null) UpdateRequired(this);
break;
}
}
private void UnpackListing(IncomingEntityComponentMessage msg)
{
MaxSlots = (int) msg.MessageParameters[1];
ContainedEntities.Clear();
for (int i = 0; i < (int) msg.MessageParameters[2]; i++)
{
int msgPos = 3 + i;
Entity entity = Owner.EntityManager.GetEntity((int) msg.MessageParameters[msgPos]);
if (entity != null)
ContainedEntities.Add(entity);
}
if (Changed != null) Changed(this, MaxSlots, ContainedEntities);
}
public bool ContainsEntity(Entity entity)
{
return ContainedEntities.Contains(entity);
}
public bool ContainsEntity(string templatename)
{
return ContainedEntities.Exists(x => x.Template.Name == templatename);
}
public Entity GetEntity(string templatename)
{
return ContainedEntities.Exists(x => x.Template.Name == templatename)
? ContainedEntities.First(x => x.Template.Name == templatename)
: null;
}
public void SendRequestListing()
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.InventoryInformation);
}
public void SendInventoryAdd(Entity ent)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.InventoryAdd, ent.Uid);
}
public void SendInventoryRemove(Entity ent)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.InventoryRemove, ent.Uid);
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.InventoryInformation:
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.InventoryInformation);
break;
case ComponentMessageType.InventoryAdd:
SendInventoryAdd((Entity) list[0]);
break;
case ComponentMessageType.InventoryRemove:
SendInventoryRemove((Entity) list[0]);
break;
}
return reply;
}
}
}

View File

@@ -1,37 +1,34 @@
using System.Collections.Generic;
using System.Linq;
using GameObject;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO
{
public class NewInventoryComponent : Component
{
public NewInventoryComponent()
{
Family = ComponentFamily.Inventory;
ContainedEntities = new List<Entity>();
}
public List<Entity> ContainedEntities { get; private set; }
public int MaxSlots { get; private set; }
public override void HandleComponentState(dynamic state)
{
List<Entity> newContents = new List<Entity>();
foreach (int uid in state.ContainedEntities)
{
Entity retEnt = Owner.EntityManager.GetEntity(uid);
newContents.Add(retEnt);
}
MaxSlots = state.MaxSlots;
//check for differences and raise event later?
ContainedEntities = newContents;
}
}
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using System.Collections.Generic;
namespace SS14.Client.GameObjects
{
public class NewInventoryComponent : Component
{
public NewInventoryComponent()
{
Family = ComponentFamily.Inventory;
ContainedEntities = new List<Entity>();
}
public List<Entity> ContainedEntities { get; private set; }
public int MaxSlots { get; private set; }
public override void HandleComponentState(dynamic state)
{
List<Entity> newContents = new List<Entity>();
foreach (int uid in state.ContainedEntities)
{
Entity retEnt = Owner.EntityManager.GetEntity(uid);
newContents.Add(retEnt);
}
MaxSlots = state.MaxSlots;
//check for differences and raise event later?
ContainedEntities = newContents;
}
}
}

View File

@@ -1,43 +1,42 @@
using GameObject;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Item;
namespace CGO
{
public class BasicItemComponent : Component
{
public Entity Holder;
public InventoryLocation HoldingHand;
public BasicItemComponent()
{
Family = ComponentFamily.Item;
}
public override System.Type StateType
{
get { return typeof (ItemComponentState); }
}
public override void HandleComponentState(dynamic state)
{
SetNewState(state);
}
private void SetNewState(ItemComponentState state)
{
if(state.Holder != null && (Holder == null || Holder.Uid != state.Holder))
{
Holder = Owner.EntityManager.GetEntity((int)state.Holder);
HoldingHand = state.InventoryLocation;
}
if(Holder != null && state.Holder == null)
{
Holder = null;
HoldingHand = state.InventoryLocation;
}
}
}
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Item;
namespace SS14.Client.GameObjects
{
public class BasicItemComponent : Component
{
public Entity Holder;
public InventoryLocation HoldingHand;
public BasicItemComponent()
{
Family = ComponentFamily.Item;
}
public override System.Type StateType
{
get { return typeof (ItemComponentState); }
}
public override void HandleComponentState(dynamic state)
{
SetNewState(state);
}
private void SetNewState(ItemComponentState state)
{
if(state.Holder != null && (Holder == null || Holder.Uid != state.Holder))
{
Holder = Owner.EntityManager.GetEntity((int)state.Holder);
HoldingHand = state.InventoryLocation;
}
if(Holder != null && state.Holder == null)
{
Holder = null;
HoldingHand = state.InventoryLocation;
}
}
}
}

View File

@@ -1,98 +1,98 @@
using GameObject;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO
{
public class FlashLightComponent : PointLightComponent
{
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this)
return reply;
switch (type)
{
case ComponentMessageType.MoveDirection:
var movedir = (Direction) list[0];
LightMoveDir(movedir);
break;
}
return reply;
}
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
_light.SetState(LightState.Off);
}
private void LightMoveDir(Direction movedir)
{
switch (movedir)
{
case Direction.East:
SetMask("flashlight_mask");
_light.LightArea.Rot90 = true;
_light.LightArea.MaskFlipX = true;
_light.LightArea.MaskFlipY = false;
_light.LightArea.Calculated = false;
break;
case Direction.SouthEast:
SetMask("flashlight_mask_diag");
_light.LightArea.Rot90 = false;
_light.LightArea.MaskFlipX = false;
_light.LightArea.MaskFlipY = true;
_light.LightArea.Calculated = false;
break;
case Direction.North:
SetMask("flashlight_mask");
_light.LightArea.Rot90 = false;
_light.LightArea.MaskFlipX = false;
_light.LightArea.MaskFlipY = false;
_light.LightArea.Calculated = false;
break;
case Direction.NorthEast:
SetMask("flashlight_mask_diag");
_light.LightArea.Rot90 = false;
_light.LightArea.MaskFlipX = false;
_light.LightArea.MaskFlipY = false;
_light.LightArea.Calculated = false;
break;
case Direction.West:
SetMask("flashlight_mask");
_light.LightArea.Rot90 = true;
_light.LightArea.MaskFlipX = false;
_light.LightArea.MaskFlipY = false;
_light.LightArea.Calculated = false;
break;
case Direction.NorthWest:
SetMask("flashlight_mask_diag");
_light.LightArea.Rot90 = false;
_light.LightArea.MaskFlipX = true;
_light.LightArea.MaskFlipY = false;
_light.LightArea.Calculated = false;
break;
case Direction.South:
SetMask("flashlight_mask");
_light.LightArea.Rot90 = false;
_light.LightArea.MaskFlipX = false;
_light.LightArea.MaskFlipY = true;
_light.LightArea.Calculated = false;
break;
case Direction.SouthWest:
SetMask("flashlight_mask_diag");
_light.LightArea.Rot90 = false;
_light.LightArea.MaskFlipX = true;
_light.LightArea.MaskFlipY = true;
_light.LightArea.Calculated = false;
break;
}
}
}
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
namespace SS14.Client.GameObjects
{
public class FlashLightComponent : PointLightComponent
{
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this)
return reply;
switch (type)
{
case ComponentMessageType.MoveDirection:
var movedir = (Direction) list[0];
LightMoveDir(movedir);
break;
}
return reply;
}
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
_light.SetState(LightState.Off);
}
private void LightMoveDir(Direction movedir)
{
switch (movedir)
{
case Direction.East:
SetMask("flashlight_mask");
_light.LightArea.Rot90 = true;
_light.LightArea.MaskFlipX = true;
_light.LightArea.MaskFlipY = false;
_light.LightArea.Calculated = false;
break;
case Direction.SouthEast:
SetMask("flashlight_mask_diag");
_light.LightArea.Rot90 = false;
_light.LightArea.MaskFlipX = false;
_light.LightArea.MaskFlipY = true;
_light.LightArea.Calculated = false;
break;
case Direction.North:
SetMask("flashlight_mask");
_light.LightArea.Rot90 = false;
_light.LightArea.MaskFlipX = false;
_light.LightArea.MaskFlipY = false;
_light.LightArea.Calculated = false;
break;
case Direction.NorthEast:
SetMask("flashlight_mask_diag");
_light.LightArea.Rot90 = false;
_light.LightArea.MaskFlipX = false;
_light.LightArea.MaskFlipY = false;
_light.LightArea.Calculated = false;
break;
case Direction.West:
SetMask("flashlight_mask");
_light.LightArea.Rot90 = true;
_light.LightArea.MaskFlipX = false;
_light.LightArea.MaskFlipY = false;
_light.LightArea.Calculated = false;
break;
case Direction.NorthWest:
SetMask("flashlight_mask_diag");
_light.LightArea.Rot90 = false;
_light.LightArea.MaskFlipX = true;
_light.LightArea.MaskFlipY = false;
_light.LightArea.Calculated = false;
break;
case Direction.South:
SetMask("flashlight_mask");
_light.LightArea.Rot90 = false;
_light.LightArea.MaskFlipX = false;
_light.LightArea.MaskFlipY = true;
_light.LightArea.Calculated = false;
break;
case Direction.SouthWest:
SetMask("flashlight_mask_diag");
_light.LightArea.Rot90 = false;
_light.LightArea.MaskFlipX = true;
_light.LightArea.MaskFlipY = true;
_light.LightArea.Calculated = false;
break;
}
}
}
}

View File

@@ -1,143 +1,143 @@
using System;
using ClientInterfaces.Lighting;
using GameObject;
using GorgonLibrary;
using Lidgren.Network;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Light;
namespace CGO
{
public class PointLightComponent : Component
{
//Contains a standard light
public ILight _light;
public Vector3D _lightColor = new Vector3D(190, 190, 190);
public Vector2D _lightOffset = new Vector2D(0, 0);
public int _lightRadius = 512;
protected string _mask = "";
public LightModeClass _mode = LightModeClass.Constant;
public PointLightComponent()
{
Family = ComponentFamily.Light;
}
public override Type StateType
{
get { return typeof (LightComponentState); }
}
//When added, set up the light.
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
_light = IoCManager.Resolve<ILightManager>().CreateLight();
IoCManager.Resolve<ILightManager>().AddLight(_light);
_light.SetRadius(_lightRadius);
_light.SetColor(255, (int) _lightColor.X, (int) _lightColor.Y, (int) _lightColor.Z);
_light.Move(Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position + _lightOffset);
_light.SetMask(_mask);
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += OnMove;
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
base.HandleNetworkMessage(message, sender);
var type = (ComponentMessageType) message.MessageParameters[0];
switch (type)
{
case ComponentMessageType.SetLightMode:
SetMode((LightModeClass) message.MessageParameters[1]);
break;
}
}
public override void SetParameter(ComponentParameter parameter)
{
switch (parameter.MemberName)
{
case "lightoffsetx":
_lightOffset.X = parameter.GetValue<float>();
//float.Parse((string)parameter.Parameter, System.Globalization.CultureInfo.InvariantCulture);
break;
case "lightoffsety":
_lightOffset.Y = parameter.GetValue<float>();
//float.Parse((string)parameter.Parameter, System.Globalization.CultureInfo.InvariantCulture);
break;
case "lightradius":
_lightRadius = parameter.GetValue<int>(); //int.Parse((string) parameter.Parameter);
break;
case "lightColorR":
_lightColor.X = parameter.GetValue<int>(); //int.Parse((string) parameter.Parameter);
break;
case "lightColorG":
_lightColor.Y = parameter.GetValue<int>(); //int.Parse((string)parameter.Parameter);
break;
case "lightColorB":
_lightColor.Z = parameter.GetValue<int>(); //int.Parse((string)parameter.Parameter);
break;
case "mask":
_mask = parameter.GetValue<string>(); // parameter.Parameter;
break;
}
}
protected void SetState(LightState state)
{
_light.SetState(state);
}
protected void SetMode(LightModeClass mode)
{
IoCManager.Resolve<ILightManager>().SetLightMode(mode, _light);
}
public override void OnRemove()
{
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove -= OnMove;
IoCManager.Resolve<ILightManager>().RemoveLight(_light);
base.OnRemove();
}
private void OnMove(object sender, VectorEventArgs args)
{
_light.Move(Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position + _lightOffset);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
_light.Update(frameTime);
}
protected void SetMask(string mask)
{
_light.SetMask(mask);
}
public override void HandleComponentState(dynamic state)
{
if (_light.LightState != state.State)
_light.SetState(state.State);
if (_light.Color.R != state.ColorR || _light.Color.G != state.ColorG || _light.Color.B != state.ColorB)
{
SetColor(state.ColorR, state.ColorG, state.ColorB);
}
if (_mode != state.Mode)
SetMode(state.Mode);
}
protected void SetColor(int R, int G, int B)
{
_lightColor.X = R;
_lightColor.Y = G;
_lightColor.Z = B;
_light.SetColor(255, R, G, B);
}
}
using GorgonLibrary;
using Lidgren.Network;
using SS14.Client.Interfaces.Lighting;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Light;
using SS14.Shared.IoC;
using System;
namespace SS14.Client.GameObjects
{
public class PointLightComponent : Component
{
//Contains a standard light
public ILight _light;
public Vector3D _lightColor = new Vector3D(190, 190, 190);
public Vector2D _lightOffset = new Vector2D(0, 0);
public int _lightRadius = 512;
protected string _mask = "";
public LightModeClass _mode = LightModeClass.Constant;
public PointLightComponent()
{
Family = ComponentFamily.Light;
}
public override Type StateType
{
get { return typeof (LightComponentState); }
}
//When added, set up the light.
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
_light = IoCManager.Resolve<ILightManager>().CreateLight();
IoCManager.Resolve<ILightManager>().AddLight(_light);
_light.SetRadius(_lightRadius);
_light.SetColor(255, (int) _lightColor.X, (int) _lightColor.Y, (int) _lightColor.Z);
_light.Move(Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position + _lightOffset);
_light.SetMask(_mask);
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += OnMove;
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
base.HandleNetworkMessage(message, sender);
var type = (ComponentMessageType) message.MessageParameters[0];
switch (type)
{
case ComponentMessageType.SetLightMode:
SetMode((LightModeClass) message.MessageParameters[1]);
break;
}
}
public override void SetParameter(ComponentParameter parameter)
{
switch (parameter.MemberName)
{
case "lightoffsetx":
_lightOffset.X = parameter.GetValue<float>();
//float.Parse((string)parameter.Parameter, System.Globalization.CultureInfo.InvariantCulture);
break;
case "lightoffsety":
_lightOffset.Y = parameter.GetValue<float>();
//float.Parse((string)parameter.Parameter, System.Globalization.CultureInfo.InvariantCulture);
break;
case "lightradius":
_lightRadius = parameter.GetValue<int>(); //int.Parse((string) parameter.Parameter);
break;
case "lightColorR":
_lightColor.X = parameter.GetValue<int>(); //int.Parse((string) parameter.Parameter);
break;
case "lightColorG":
_lightColor.Y = parameter.GetValue<int>(); //int.Parse((string)parameter.Parameter);
break;
case "lightColorB":
_lightColor.Z = parameter.GetValue<int>(); //int.Parse((string)parameter.Parameter);
break;
case "mask":
_mask = parameter.GetValue<string>(); // parameter.Parameter;
break;
}
}
protected void SetState(LightState state)
{
_light.SetState(state);
}
protected void SetMode(LightModeClass mode)
{
IoCManager.Resolve<ILightManager>().SetLightMode(mode, _light);
}
public override void OnRemove()
{
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove -= OnMove;
IoCManager.Resolve<ILightManager>().RemoveLight(_light);
base.OnRemove();
}
private void OnMove(object sender, VectorEventArgs args)
{
_light.Move(Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position + _lightOffset);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
_light.Update(frameTime);
}
protected void SetMask(string mask)
{
_light.SetMask(mask);
}
public override void HandleComponentState(dynamic state)
{
if (_light.LightState != state.State)
_light.SetState(state.State);
if (_light.Color.R != state.ColorR || _light.Color.G != state.ColorG || _light.Color.B != state.ColorB)
{
SetColor(state.ColorR, state.ColorG, state.ColorB);
}
if (_mode != state.Mode)
SetMode(state.Mode);
}
protected void SetColor(int R, int G, int B)
{
_lightColor.X = R;
_lightColor.Y = G;
_lightColor.Z = B;
_light.SetColor(255, R, G, B);
}
}
}

View File

@@ -1,68 +1,66 @@
using System;
using GameObject;
using GorgonLibrary;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Mover;
namespace CGO
{
/// <summary>
/// Recieves movement data from the server and updates the entity's position accordingly.
/// </summary>
public class BasicMoverComponent : Component
{
private bool interpolating;
private float movedtime; // Amount of time we've been moving since the last update packet.
private float movetime = 0.05f; // Milliseconds it should take to move.
private Vector2D startPosition;
private Vector2D targetPosition;
public BasicMoverComponent()
{
Family = ComponentFamily.Mover;
}
public override Type StateType
{
get { return typeof (MoverComponentState); }
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (interpolating)
{
movedtime = movedtime + frameTime;
if (movedtime >= movetime)
{
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position = targetPosition;
startPosition = targetPosition;
interpolating = false;
}
else
{
float X = Ease(movedtime, startPosition.X, targetPosition.X, movetime);
float Y = Ease(movedtime, startPosition.Y, targetPosition.Y, movetime);
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position = new Vector2D(X, Y);
}
}
}
/// <summary>
/// Returns a float position eased from a start position to an end position.
/// </summary>
/// <param name="time">elapsed time since the start of the easing</param>
/// <param name="start">start position</param>
/// <param name="end">end position</param>
/// <param name="duration">duration of the movement</param>
/// <returns>current position</returns>
private float Ease(float time, float start, float end, float duration = 1) // duration is in ms.
{
time = time/duration; // - 1;
return time*(end - start) + start;
}
}
using GorgonLibrary;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Mover;
using System;
namespace SS14.Client.GameObjects
{
/// <summary>
/// Recieves movement data from the server and updates the entity's position accordingly.
/// </summary>
public class BasicMoverComponent : Component
{
private bool interpolating;
private float movedtime; // Amount of time we've been moving since the last update packet.
private float movetime = 0.05f; // Milliseconds it should take to move.
private Vector2D startPosition;
private Vector2D targetPosition;
public BasicMoverComponent()
{
Family = ComponentFamily.Mover;
}
public override Type StateType
{
get { return typeof (MoverComponentState); }
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (interpolating)
{
movedtime = movedtime + frameTime;
if (movedtime >= movetime)
{
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position = targetPosition;
startPosition = targetPosition;
interpolating = false;
}
else
{
float X = Ease(movedtime, startPosition.X, targetPosition.X, movetime);
float Y = Ease(movedtime, startPosition.Y, targetPosition.Y, movetime);
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position = new Vector2D(X, Y);
}
}
}
/// <summary>
/// Returns a float position eased from a start position to an end position.
/// </summary>
/// <param name="time">elapsed time since the start of the easing</param>
/// <param name="start">start position</param>
/// <param name="end">end position</param>
/// <param name="duration">duration of the movement</param>
/// <returns>current position</returns>
private float Ease(float time, float start, float end, float duration = 1) // duration is in ms.
{
time = time/duration; // - 1;
return time*(end - start) + start;
}
}
}

View File

@@ -1,185 +1,185 @@
using GameObject;
using GorgonLibrary;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO
{
//Moves an entity based on key binding input
public class PlayerInputMoverComponent : Component
{
private const float BaseMoveSpeed = Constants.HumanWalkSpeed;
public const float FastMoveSpeed = Constants.HumanRunSpeed;
private const float MoveRateLimit = .06666f; // 15 movements allowed to be sent to the server per second.
private float _currentMoveSpeed;
private bool _moveDown;
private bool _moveLeft;
private bool _moveRight;
private float _moveTimeCache;
private bool _moveUp;
public bool ShouldSendPositionUpdate;
private Direction _movedir;
public PlayerInputMoverComponent()
{
Family = ComponentFamily.Mover;
;
_currentMoveSpeed = BaseMoveSpeed;
_movedir = Direction.South;
}
private Vector2D Velocity
{
get { return Owner.GetComponent<VelocityComponent>(ComponentFamily.Velocity).Velocity; }
set { Owner.GetComponent<VelocityComponent>(ComponentFamily.Velocity).Velocity = value; }
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
/*var x = (float)message.MessageParameters[0];
var y = (float)message.MessageParameters[1];
if((bool)message.MessageParameters[2]) //"forced" parameter -- if true forces position update
PlainTranslate((float)x, (float)y);*/
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.BoundKeyChange:
HandleKeyChange(list);
break;
}
return reply;
}
/// <summary>
/// Handles a changed keystate message
/// </summary>
/// <param name="list">0 - Function, 1 - Key State</param>
private void HandleKeyChange(params object[] list)
{
var function = (BoundKeyFunctions) list[0];
var state = (BoundKeyState) list[1];
bool setting = state == BoundKeyState.Down;
ShouldSendPositionUpdate = true;
/*if (state == BoundKeyState.Up)
SendPositionUpdate(Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);*/
// Send a position update so that the server knows what position the client ended at.
if (function == BoundKeyFunctions.MoveDown)
_moveDown = setting;
if (function == BoundKeyFunctions.MoveUp)
_moveUp = setting;
if (function == BoundKeyFunctions.MoveLeft)
_moveLeft = setting;
if (function == BoundKeyFunctions.MoveRight)
_moveRight = setting;
if (function == BoundKeyFunctions.Run)
{
_currentMoveSpeed = setting ? FastMoveSpeed : BaseMoveSpeed;
}
}
/// <summary>
/// Update function. Processes currently pressed keys and does shit etc.
/// </summary>
/// <param name="frameTime"></param>
public override void Update(float frameTime)
{
_moveTimeCache += frameTime;
base.Update(frameTime);
if (_moveUp && !_moveLeft && !_moveRight && !_moveDown) // Move Up
{
Velocity = new Vector2D(0, -1)*_currentMoveSpeed;
}
else if (_moveDown && !_moveLeft && !_moveRight && !_moveUp) // Move Down
{
Velocity = new Vector2D(0, 1)*_currentMoveSpeed;
}
else if (_moveLeft && !_moveRight && !_moveUp && !_moveDown) // Move Left
{
Velocity = new Vector2D(-1, 0)*_currentMoveSpeed;
}
else if (_moveRight && !_moveLeft && !_moveUp && !_moveDown) // Move Right
{
Velocity = new Vector2D(1, 0)*_currentMoveSpeed;
}
else if (_moveUp && _moveRight && !_moveLeft && !_moveDown) // Move Up & Right
{
Velocity = new Vector2D(0.7071f, -0.7071f)*_currentMoveSpeed;
}
else if (_moveUp && _moveLeft && !_moveRight && !_moveDown) // Move Up & Left
{
Velocity = new Vector2D(-0.7071f, -0.7071f)*_currentMoveSpeed;
}
else if (_moveDown && _moveRight && !_moveLeft && !_moveUp) // Move Down & Right
{
Velocity = new Vector2D(0.7071f, 0.7071f)*_currentMoveSpeed;
}
else if (_moveDown && _moveLeft && !_moveRight && !_moveUp) // Move Down & Left
{
Velocity = new Vector2D(-0.7071f, 0.7071f)*_currentMoveSpeed;
}
else
{
Velocity = new Vector2D(0f, 0f);
}
/*Vector2D translationVector = Velocity*frameTime;
var velcomp = Owner.GetComponent<VelocityComponent>(ComponentFamily.Velocity);
bool translated = TryTranslate(translationVector, false); //Only bump once...
bool translatedx = false, translatedy = false;
if (!translated)
translatedx = TryTranslate(new Vector2D(translationVector.X, 0), true);
if (!translated && !translatedx)
translatedy = TryTranslate(new Vector2D(0, translationVector.Y), true);
if (!translated)
{
if (!translatedx)
{
velcomp.Velocity = new Vector2D(0, velcomp.Velocity.Y);
}
if (!translatedy)
velcomp.Velocity = new Vector2D(velcomp.Velocity.X, 0);
if (!translatedx && !translatedy)
velcomp.Velocity = Vector2D.Zero;
translationVector = new Vector2D(translatedx?translationVector.X:0, translatedy?translationVector.Y:0);
}
if (_moveTimeCache >= MoveRateLimit)
{
var nextPosition = Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position + translationVector;
SendPositionUpdate(nextPosition);
_moveTimeCache = 0;
}*/
}
public virtual void SendPositionUpdate(Vector2D nextPosition)
{
Owner.SendComponentNetworkMessage(this,
NetDeliveryMethod.ReliableUnordered,
nextPosition.X,
nextPosition.Y,
Owner.GetComponent<VelocityComponent>(ComponentFamily.Velocity).Velocity.X,
Owner.GetComponent<VelocityComponent>(ComponentFamily.Velocity).Velocity.Y);
}
}
using GorgonLibrary;
using Lidgren.Network;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
namespace SS14.Client.GameObjects
{
//Moves an entity based on key binding input
public class PlayerInputMoverComponent : Component
{
private const float BaseMoveSpeed = Constants.HumanWalkSpeed;
public const float FastMoveSpeed = Constants.HumanRunSpeed;
private const float MoveRateLimit = .06666f; // 15 movements allowed to be sent to the server per second.
private float _currentMoveSpeed;
private bool _moveDown;
private bool _moveLeft;
private bool _moveRight;
private float _moveTimeCache;
private bool _moveUp;
public bool ShouldSendPositionUpdate;
private Direction _movedir;
public PlayerInputMoverComponent()
{
Family = ComponentFamily.Mover;
;
_currentMoveSpeed = BaseMoveSpeed;
_movedir = Direction.South;
}
private Vector2D Velocity
{
get { return Owner.GetComponent<VelocityComponent>(ComponentFamily.Velocity).Velocity; }
set { Owner.GetComponent<VelocityComponent>(ComponentFamily.Velocity).Velocity = value; }
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
/*var x = (float)message.MessageParameters[0];
var y = (float)message.MessageParameters[1];
if((bool)message.MessageParameters[2]) //"forced" parameter -- if true forces position update
PlainTranslate((float)x, (float)y);*/
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.BoundKeyChange:
HandleKeyChange(list);
break;
}
return reply;
}
/// <summary>
/// Handles a changed keystate message
/// </summary>
/// <param name="list">0 - Function, 1 - Key State</param>
private void HandleKeyChange(params object[] list)
{
var function = (BoundKeyFunctions) list[0];
var state = (BoundKeyState) list[1];
bool setting = state == BoundKeyState.Down;
ShouldSendPositionUpdate = true;
/*if (state == BoundKeyState.Up)
SendPositionUpdate(Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);*/
// Send a position update so that the server knows what position the client ended at.
if (function == BoundKeyFunctions.MoveDown)
_moveDown = setting;
if (function == BoundKeyFunctions.MoveUp)
_moveUp = setting;
if (function == BoundKeyFunctions.MoveLeft)
_moveLeft = setting;
if (function == BoundKeyFunctions.MoveRight)
_moveRight = setting;
if (function == BoundKeyFunctions.Run)
{
_currentMoveSpeed = setting ? FastMoveSpeed : BaseMoveSpeed;
}
}
/// <summary>
/// Update function. Processes currently pressed keys and does shit etc.
/// </summary>
/// <param name="frameTime"></param>
public override void Update(float frameTime)
{
_moveTimeCache += frameTime;
base.Update(frameTime);
if (_moveUp && !_moveLeft && !_moveRight && !_moveDown) // Move Up
{
Velocity = new Vector2D(0, -1)*_currentMoveSpeed;
}
else if (_moveDown && !_moveLeft && !_moveRight && !_moveUp) // Move Down
{
Velocity = new Vector2D(0, 1)*_currentMoveSpeed;
}
else if (_moveLeft && !_moveRight && !_moveUp && !_moveDown) // Move Left
{
Velocity = new Vector2D(-1, 0)*_currentMoveSpeed;
}
else if (_moveRight && !_moveLeft && !_moveUp && !_moveDown) // Move Right
{
Velocity = new Vector2D(1, 0)*_currentMoveSpeed;
}
else if (_moveUp && _moveRight && !_moveLeft && !_moveDown) // Move Up & Right
{
Velocity = new Vector2D(0.7071f, -0.7071f)*_currentMoveSpeed;
}
else if (_moveUp && _moveLeft && !_moveRight && !_moveDown) // Move Up & Left
{
Velocity = new Vector2D(-0.7071f, -0.7071f)*_currentMoveSpeed;
}
else if (_moveDown && _moveRight && !_moveLeft && !_moveUp) // Move Down & Right
{
Velocity = new Vector2D(0.7071f, 0.7071f)*_currentMoveSpeed;
}
else if (_moveDown && _moveLeft && !_moveRight && !_moveUp) // Move Down & Left
{
Velocity = new Vector2D(-0.7071f, 0.7071f)*_currentMoveSpeed;
}
else
{
Velocity = new Vector2D(0f, 0f);
}
/*Vector2D translationVector = Velocity*frameTime;
var velcomp = Owner.GetComponent<VelocityComponent>(ComponentFamily.Velocity);
bool translated = TryTranslate(translationVector, false); //Only bump once...
bool translatedx = false, translatedy = false;
if (!translated)
translatedx = TryTranslate(new Vector2D(translationVector.X, 0), true);
if (!translated && !translatedx)
translatedy = TryTranslate(new Vector2D(0, translationVector.Y), true);
if (!translated)
{
if (!translatedx)
{
velcomp.Velocity = new Vector2D(0, velcomp.Velocity.Y);
}
if (!translatedy)
velcomp.Velocity = new Vector2D(velcomp.Velocity.X, 0);
if (!translatedx && !translatedy)
velcomp.Velocity = Vector2D.Zero;
translationVector = new Vector2D(translatedx?translationVector.X:0, translatedy?translationVector.Y:0);
}
if (_moveTimeCache >= MoveRateLimit)
{
var nextPosition = Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position + translationVector;
SendPositionUpdate(nextPosition);
_moveTimeCache = 0;
}*/
}
public virtual void SendPositionUpdate(Vector2D nextPosition)
{
Owner.SendComponentNetworkMessage(this,
NetDeliveryMethod.ReliableUnordered,
nextPosition.X,
nextPosition.Y,
Owner.GetComponent<VelocityComponent>(ComponentFamily.Velocity).Velocity.X,
Owner.GetComponent<VelocityComponent>(ComponentFamily.Velocity).Velocity.Y);
}
}
}

View File

@@ -1,106 +1,103 @@
using System;
using ClientInterfaces.Configuration;
using GameObject;
using GorgonLibrary;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Mover;
using SS13_Shared.GO.Component.Transform;
namespace CGO
{
/// <summary>
/// Mover component that responds to movement by an entity.
/// </summary>
public class SlaveMoverComponent : Component
{
private Entity _master;
private Direction _movedir = Direction.South;
public SlaveMoverComponent()
{
Family = ComponentFamily.Mover;
}
public override Type StateType
{
get { return typeof(MoverComponentState); }
}
public override void OnRemove()
{
Detach();
base.OnRemove();
}
private void Attach(int uid)
{
_master = Owner.EntityManager.GetEntity(uid);
_master.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += HandleOnMove;
Translate(_master.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
}
private void Detach()
{
if (_master == null) return;
_master.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove -= HandleOnMove;
_master = null;
}
private void HandleOnMove(object sender, VectorEventArgs args)
{
Translate(Vector2TypeConverter.ToVector2D(args.VectorTo));
}
private void Translate(Vector2D toPosition)
{
Vector2D delta = toPosition - Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position;
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position = toPosition;
/*
if (delta.X > 0 && delta.Y > 0)
SetMoveDir(Constants.MoveDirs.southeast);
if (delta.X > 0 && delta.Y < 0)
SetMoveDir(Constants.MoveDirs.northeast);
if (delta.X < 0 && delta.Y > 0)
SetMoveDir(Constants.MoveDirs.southwest);
if (delta.X < 0 && delta.Y < 0)
SetMoveDir(Constants.MoveDirs.northwest);
if (delta.X > 0 && delta.Y == 0)
SetMoveDir(Constants.MoveDirs.east);
if (delta.X < 0 && delta.Y == 0)
SetMoveDir(Constants.MoveDirs.west);
if (delta.Y > 0 && delta.X == 0)
SetMoveDir(Constants.MoveDirs.south);
if (delta.Y < 0 && delta.X == 0)
SetMoveDir(Constants.MoveDirs.north);
*/
//Owner.Moved();
}
public override void HandleComponentState(dynamic state)
{
SetNewState(state);
}
private void SetNewState(MoverComponentState state)
{
if(_master == null && state.Master != null)
{
Attach((int)state.Master);
}
if(_master != null && state.Master == null)
{
Detach();
}
if(_master != null && state.Master != null && _master.Uid != state.Master)
{
Detach();
Attach((int)state.Master);
}
}
}
using GorgonLibrary;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Mover;
using System;
namespace SS14.Client.GameObjects
{
/// <summary>
/// Mover component that responds to movement by an entity.
/// </summary>
public class SlaveMoverComponent : Component
{
private Entity _master;
private Direction _movedir = Direction.South;
public SlaveMoverComponent()
{
Family = ComponentFamily.Mover;
}
public override Type StateType
{
get { return typeof(MoverComponentState); }
}
public override void OnRemove()
{
Detach();
base.OnRemove();
}
private void Attach(int uid)
{
_master = Owner.EntityManager.GetEntity(uid);
_master.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += HandleOnMove;
Translate(_master.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
}
private void Detach()
{
if (_master == null) return;
_master.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove -= HandleOnMove;
_master = null;
}
private void HandleOnMove(object sender, VectorEventArgs args)
{
Translate(Vector2TypeConverter.ToVector2D(args.VectorTo));
}
private void Translate(Vector2D toPosition)
{
Vector2D delta = toPosition - Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position;
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position = toPosition;
/*
if (delta.X > 0 && delta.Y > 0)
SetMoveDir(Constants.MoveDirs.southeast);
if (delta.X > 0 && delta.Y < 0)
SetMoveDir(Constants.MoveDirs.northeast);
if (delta.X < 0 && delta.Y > 0)
SetMoveDir(Constants.MoveDirs.southwest);
if (delta.X < 0 && delta.Y < 0)
SetMoveDir(Constants.MoveDirs.northwest);
if (delta.X > 0 && delta.Y == 0)
SetMoveDir(Constants.MoveDirs.east);
if (delta.X < 0 && delta.Y == 0)
SetMoveDir(Constants.MoveDirs.west);
if (delta.Y > 0 && delta.X == 0)
SetMoveDir(Constants.MoveDirs.south);
if (delta.Y < 0 && delta.X == 0)
SetMoveDir(Constants.MoveDirs.north);
*/
//Owner.Moved();
}
public override void HandleComponentState(dynamic state)
{
SetNewState(state);
}
private void SetNewState(MoverComponentState state)
{
if(_master == null && state.Master != null)
{
Attach((int)state.Master);
}
if(_master != null && state.Master == null)
{
Detach();
}
if(_master != null && state.Master != null && _master.Uid != state.Master)
{
Detach();
Attach((int)state.Master);
}
}
}
}

View File

@@ -1,27 +1,26 @@
using System;
using System.Collections.Generic;
using GameObject;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Physics;
namespace CGO
{
internal class PhysicsComponent : Component
{
public float Mass { get; set; }
public override Type StateType
{
get { return typeof(PhysicsComponentState); }
}
public PhysicsComponent()
{
Family = ComponentFamily.Physics;
}
public override void HandleComponentState(dynamic state)
{
Mass = state.Mass;
}
}
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Physics;
using System;
namespace SS14.Client.GameObjects
{
internal class PhysicsComponent : Component
{
public float Mass { get; set; }
public override Type StateType
{
get { return typeof(PhysicsComponentState); }
}
public PhysicsComponent()
{
Family = ComponentFamily.Physics;
}
public override void HandleComponentState(dynamic state)
{
Mass = state.Mass;
}
}
}

View File

@@ -1,188 +1,188 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using ClientInterfaces.GOC;
using GameObject;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO
{
public class PlayerActionComp : Component
{
#region Delegates
public delegate void PlayerActionsChangedHandler(PlayerActionComp sender);
#endregion
public List<IPlayerAction> Actions = new List<IPlayerAction>();
public PlayerActionComp()
{
Family = ComponentFamily.PlayerActions;
}
public event PlayerActionsChangedHandler Changed;
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
var type = (ComponentMessageType) message.MessageParameters[0];
switch (type)
{
case (ComponentMessageType.AddAction):
var typeName = (string) message.MessageParameters[1];
var uid = (uint) message.MessageParameters[2];
AddAction(typeName, uid);
break;
case (ComponentMessageType.RemoveAction):
var uid2 = (uint) message.MessageParameters[1];
RemoveAction(uid2);
break;
case (ComponentMessageType.RequestActionList):
UnpackFullListing(message);
break;
case (ComponentMessageType.GetActionChecksum):
CheckFullUpdate((uint) message.MessageParameters[1]);
break;
case (ComponentMessageType.CooldownAction):
var uidCd = (uint) message.MessageParameters[1];
var secCd = (uint) message.MessageParameters[2];
SetCooldown(uidCd, secCd);
break;
default:
base.HandleNetworkMessage(message, sender);
break;
}
}
public void CheckActionList()
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.GetActionChecksum);
}
private void SetCooldown(uint uid, uint seconds)
{
IPlayerAction toSet = Actions.FirstOrDefault(x => x.Uid == uid);
if (toSet != null)
toSet.CooldownExpires = DateTime.Now.AddSeconds(seconds);
}
private void CheckFullUpdate(uint checksum) //This should never happen. This just exists in case it desynchs.
{
long sum = Actions.Sum(x => x.Uid)*Actions.Count;
//Absolutely not perfect or safe. If this causes problems later (unlikely) we can still change it.
if (sum != checksum)
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.RequestActionList);
}
public void SendDoAction(IPlayerAction action, object target)
{
if (!Actions.Contains(action)) return;
double cdLeft = action.CooldownExpires.Subtract(DateTime.Now).TotalSeconds;
if (cdLeft > 0) return;
switch (action.TargetType)
{
case PlayerActionTargetType.Any:
{
var trg = (Entity) target;
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.DoAction, action.Uid, action.TargetType,
trg.Uid);
break;
}
case PlayerActionTargetType.None:
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.DoAction, action.Uid, action.TargetType,
Owner.Uid);
break;
}
case PlayerActionTargetType.Other:
{
var trg = (Entity) target;
if (trg == Owner) return;
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.DoAction, action.Uid, action.TargetType,
trg.Uid);
break;
}
case PlayerActionTargetType.Point:
{
var trg = (PointF) target;
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.DoAction, action.Uid, action.TargetType,
trg.X, trg.Y);
break;
}
}
}
private void Reset()
{
Actions.Clear();
if (Changed != null) Changed(this);
}
private void UnpackFullListing(IncomingEntityComponentMessage message)
{
Reset();
var numPacks = (uint) message.MessageParameters[1];
for (int i = 0; i < numPacks; i++)
{
var uid = (uint) message.MessageParameters[2 + (i*2)];
var typeName = (string) message.MessageParameters[3 + (i*2)];
AddAction(typeName, uid);
}
}
public override void Update(float frameTime)
{
base.Update(frameTime);
}
private void AddAction(string typeName, uint uid)
//Don't manually use this clientside. The server adds and removes what is needed.
{
Type t = Type.GetType("CGO." + typeName);
if (t == null || !t.IsSubclassOf(typeof (PlayerAction))) return;
var newAction = (PlayerAction) Activator.CreateInstance(t, new object[] {uid, this});
Actions.Add(newAction);
if (Changed != null) Changed(this);
}
private void RemoveAction(uint uid)
//Don't manually use this clientside. The server adds and removes what is needed.
{
IPlayerAction toRemove = Actions.FirstOrDefault(x => x.Uid == uid);
if (toRemove != null)
{
Actions.Remove(toRemove);
if (Changed != null) Changed(this);
}
}
public bool HasAction(string typeName)
{
foreach (IPlayerAction act in Actions)
if (act.GetType().Name.Equals(typeName, StringComparison.InvariantCultureIgnoreCase))
return true;
return false;
}
}
using Lidgren.Network;
using SS14.Client.Interfaces.GOC;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace SS14.Client.GameObjects
{
public class PlayerActionComp : Component
{
#region Delegates
public delegate void PlayerActionsChangedHandler(PlayerActionComp sender);
#endregion
public List<IPlayerAction> Actions = new List<IPlayerAction>();
public PlayerActionComp()
{
Family = ComponentFamily.PlayerActions;
}
public event PlayerActionsChangedHandler Changed;
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
var type = (ComponentMessageType) message.MessageParameters[0];
switch (type)
{
case (ComponentMessageType.AddAction):
var typeName = (string) message.MessageParameters[1];
var uid = (uint) message.MessageParameters[2];
AddAction(typeName, uid);
break;
case (ComponentMessageType.RemoveAction):
var uid2 = (uint) message.MessageParameters[1];
RemoveAction(uid2);
break;
case (ComponentMessageType.RequestActionList):
UnpackFullListing(message);
break;
case (ComponentMessageType.GetActionChecksum):
CheckFullUpdate((uint) message.MessageParameters[1]);
break;
case (ComponentMessageType.CooldownAction):
var uidCd = (uint) message.MessageParameters[1];
var secCd = (uint) message.MessageParameters[2];
SetCooldown(uidCd, secCd);
break;
default:
base.HandleNetworkMessage(message, sender);
break;
}
}
public void CheckActionList()
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.GetActionChecksum);
}
private void SetCooldown(uint uid, uint seconds)
{
IPlayerAction toSet = Actions.FirstOrDefault(x => x.Uid == uid);
if (toSet != null)
toSet.CooldownExpires = DateTime.Now.AddSeconds(seconds);
}
private void CheckFullUpdate(uint checksum) //This should never happen. This just exists in case it desynchs.
{
long sum = Actions.Sum(x => x.Uid)*Actions.Count;
//Absolutely not perfect or safe. If this causes problems later (unlikely) we can still change it.
if (sum != checksum)
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.RequestActionList);
}
public void SendDoAction(IPlayerAction action, object target)
{
if (!Actions.Contains(action)) return;
double cdLeft = action.CooldownExpires.Subtract(DateTime.Now).TotalSeconds;
if (cdLeft > 0) return;
switch (action.TargetType)
{
case PlayerActionTargetType.Any:
{
var trg = (Entity) target;
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.DoAction, action.Uid, action.TargetType,
trg.Uid);
break;
}
case PlayerActionTargetType.None:
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.DoAction, action.Uid, action.TargetType,
Owner.Uid);
break;
}
case PlayerActionTargetType.Other:
{
var trg = (Entity) target;
if (trg == Owner) return;
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.DoAction, action.Uid, action.TargetType,
trg.Uid);
break;
}
case PlayerActionTargetType.Point:
{
var trg = (PointF) target;
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered,
ComponentMessageType.DoAction, action.Uid, action.TargetType,
trg.X, trg.Y);
break;
}
}
}
private void Reset()
{
Actions.Clear();
if (Changed != null) Changed(this);
}
private void UnpackFullListing(IncomingEntityComponentMessage message)
{
Reset();
var numPacks = (uint) message.MessageParameters[1];
for (int i = 0; i < numPacks; i++)
{
var uid = (uint) message.MessageParameters[2 + (i*2)];
var typeName = (string) message.MessageParameters[3 + (i*2)];
AddAction(typeName, uid);
}
}
public override void Update(float frameTime)
{
base.Update(frameTime);
}
private void AddAction(string typeName, uint uid)
//Don't manually use this clientside. The server adds and removes what is needed.
{
Type t = Type.GetType("CGO." + typeName);
if (t == null || !t.IsSubclassOf(typeof (PlayerAction))) return;
var newAction = (PlayerAction) Activator.CreateInstance(t, new object[] {uid, this});
Actions.Add(newAction);
if (Changed != null) Changed(this);
}
private void RemoveAction(uint uid)
//Don't manually use this clientside. The server adds and removes what is needed.
{
IPlayerAction toRemove = Actions.FirstOrDefault(x => x.Uid == uid);
if (toRemove != null)
{
Actions.Remove(toRemove);
if (Changed != null) Changed(this);
}
}
public bool HasAction(string typeName)
{
foreach (IPlayerAction act in Actions)
if (act.GetType().Name.Equals(typeName, StringComparison.InvariantCultureIgnoreCase))
return true;
return false;
}
}
}

View File

@@ -1,382 +1,382 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using ClientInterfaces.GOC;
using ClientInterfaces.Resource;
using ClientWindow;
using GameObject;
using GorgonLibrary;
using GorgonLibrary.Graphics;
using SS13.Graphics;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Renderable;
using Image = GorgonLibrary.Graphics.Image;
namespace CGO
{
public class AnimatedSpriteComponent : Component, IRenderableComponent
{
protected string baseSprite;
protected string currentSprite;
protected AnimatedSprite sprite;
protected bool flip;
protected IRenderableComponent master;
protected List<IRenderableComponent> slaves;
protected bool visible = true;
public DrawDepth DrawDepth { get; set; }
private SpeechBubble _speechBubble;
public AnimatedSpriteComponent()
{
Family = ComponentFamily.Renderable;
slaves = new List<IRenderableComponent>();
}
public override Type StateType
{
get { return typeof(AnimatedSpriteComponentState); }
}
public float Bottom
{
get
{
return Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y +
(sprite.AABB.Height / 2);
}
}
public RectangleF AverageAABB
{
get { return sprite.AverageAABB; }
}
#region ISpriteComponent Members
public RectangleF AABB
{
get
{
return new RectangleF(0, 0, sprite.AABB.Width,
sprite.AABB.Height);
}
}
#endregion
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
//Send a spritechanged message so everything knows whassup.
Owner.SendMessage(this, ComponentMessageType.SpriteChanged);
}
public void SetSprite()
{
if(baseSprite != null)
{
SetSprite(baseSprite);
}
}
public void SetSprite(string name)
{
currentSprite = name;
sprite = (AnimatedSprite)IoCManager.Resolve<IResourceManager>().GetAnimatedSprite(name);
}
public void SetAnimationState(string state, bool loop = true)
{
sprite.SetAnimationState(state);
sprite.SetLoop(loop);
foreach(AnimatedSpriteComponent s in slaves)
{
s.SetAnimationState(state, loop);
}
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.CheckSpriteClick:
reply = new ComponentReplyMessage(ComponentMessageType.SpriteWasClicked,
WasClicked((PointF)list[0]), DrawDepth);
break;
case ComponentMessageType.GetAABB:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentAABB, AABB);
break;
case ComponentMessageType.GetSprite:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentSprite, sprite.GetCurrentSprite());
break;
case ComponentMessageType.SetDrawDepth:
SetDrawDepth((DrawDepth)list[0]);
break;
case ComponentMessageType.SlaveAttach:
SetMaster(Owner.EntityManager.GetEntity((int)list[0]));
break;
case ComponentMessageType.ItemUnEquipped:
case ComponentMessageType.Dropped:
UnsetMaster();
break;
case ComponentMessageType.MoveDirection:
switch ((Direction)list[0])
{
case Direction.North:
sprite.Direction = Direction.North;
break;
case Direction.South:
sprite.Direction = Direction.South;
break;
case Direction.East:
sprite.Direction = Direction.East;
break;
case Direction.West:
sprite.Direction = Direction.West;
break;
case Direction.NorthEast:
sprite.Direction = Direction.NorthEast;
break;
case Direction.NorthWest:
sprite.Direction = Direction.NorthWest;
break;
case Direction.SouthEast:
sprite.Direction = Direction.SouthEast;
break;
case Direction.SouthWest:
sprite.Direction = Direction.SouthWest;
break;
}
break;
case ComponentMessageType.EntitySaidSomething:
ChatChannel channel;
if (Enum.TryParse(list[0].ToString(), true, out channel))
{
string text = list[1].ToString();
if (channel == ChatChannel.Ingame || channel == ChatChannel.Player ||
channel == ChatChannel.Radio)
{
(_speechBubble ?? (_speechBubble = new SpeechBubble(Owner.Name + Owner.Uid))).SetText(text);
}
}
break;
}
return reply;
}
protected void SetDrawDepth(DrawDepth p)
{
DrawDepth = p;
}
protected virtual bool WasClicked(PointF worldPos)
{
if (sprite == null || !visible) return false;
Sprite spriteToCheck = sprite.GetCurrentSprite();
var AABB =
new RectangleF(
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X -
(spriteToCheck.Width / 2),
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y -
(spriteToCheck.Height / 2), spriteToCheck.Width, spriteToCheck.Height);
if (!AABB.Contains(worldPos)) return false;
var spritePosition = new Point((int)(worldPos.X - AABB.X + spriteToCheck.ImageOffset.X),
(int)(worldPos.Y - AABB.Y + spriteToCheck.ImageOffset.Y));
Image.ImageLockBox imgData = spriteToCheck.Image.GetImageData();
imgData.Lock(false);
Color pixColour = Color.FromArgb((int)(imgData[spritePosition.X, spritePosition.Y]));
imgData.Dispose();
imgData.Unlock();
if (pixColour.A == 0) return false;
return true;
}
public override void SetParameter(ComponentParameter parameter)
{
base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "drawdepth":
SetDrawDepth((DrawDepth)Enum.Parse(typeof(DrawDepth), parameter.GetValue<string>(), true));
break;
case "sprite":
baseSprite = parameter.GetValue<string>();
SetSprite(parameter.GetValue<string>());
break;
}
}
public virtual void Render(Vector2D topLeft, Vector2D bottomRight)
{
//Render slaves beneath
IEnumerable<IRenderableComponent> renderablesBeneath = from IRenderableComponent c in slaves
//FIXTHIS
orderby c.DrawDepth ascending
where c.DrawDepth < DrawDepth
select c;
foreach (IRenderableComponent component in renderablesBeneath.ToList())
{
component.Render(topLeft, bottomRight);
}
//Render this sprite
if (!visible) return;
if (sprite == null) return;
Vector2D renderPos =
ClientWindowData.WorldToScreen(
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
SetSpriteCenter(renderPos);
if (Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X + sprite.AABB.Right <
topLeft.X
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X > bottomRight.X
||
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y +
sprite.AABB.Bottom < topLeft.Y
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y > bottomRight.Y)
return;
sprite.HorizontalFlip = flip;
sprite.Draw();
sprite.HorizontalFlip = false;
//Render slaves above
IEnumerable<IRenderableComponent> renderablesAbove = from IRenderableComponent c in slaves
//FIXTHIS
orderby c.DrawDepth ascending
where c.DrawDepth >= DrawDepth
select c;
foreach (IRenderableComponent component in renderablesAbove.ToList())
{
component.Render(topLeft, bottomRight);
}
//Draw AABB
var aabb = AABB;
//Gorgon.CurrentRenderTarget.Rectangle(renderPos.X - aabb.Width/2, renderPos.Y - aabb.Height / 2, aabb.Width, aabb.Height, Color.Lime);
if (_speechBubble != null)
_speechBubble.Draw(Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position,
ClientWindowData.Singleton.ScreenOrigin, aabb);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if(sprite != null)
{
sprite.Update(frameTime);
}
}
public void SetSpriteCenter(Vector2D center)
{
sprite.SetPosition(center.X - (sprite.AABB.Width / 2),
center.Y - (sprite.AABB.Height / 2));
}
public bool IsSlaved()
{
return master != null;
}
public void SetMaster(Entity m)
{
if (m == null)
{
UnsetMaster();
return;
}
if (!m.HasComponent(ComponentFamily.Renderable))
return;
var mastercompo = m.GetComponent<IRenderableComponent>(ComponentFamily.Renderable);
//If there's no sprite component, then FUCK IT
if (mastercompo == null)
return;
mastercompo.AddSlave(this);
master = mastercompo;
}
public void SetMaster(int? mUid)
{
if (master != null)
{
if (mUid == null)
{
UnsetMaster();
}
else if (mUid != master.Owner.Uid)
{
UnsetMaster();
SetMaster(Owner.EntityManager.GetEntity((int)mUid));
}
}
else if (mUid != null)
{
SetMaster(Owner.EntityManager.GetEntity((int)mUid));
}
}
public void UnsetMaster()
{
if (master == null)
return;
master.RemoveSlave(this);
master = null;
}
public void AddSlave(IRenderableComponent slavecompo)
{
slaves.Add(slavecompo);
}
public void RemoveSlave(IRenderableComponent slavecompo)
{
if (slaves.Contains(slavecompo))
slaves.Remove(slavecompo);
}
public override void HandleComponentState(dynamic state)
{
DrawDepth = state.DrawDepth;
visible = state.Visible;
if(sprite.Name != state.Name)
SetSprite(state.Name);
if (sprite.CurrentAnimationStateKey != state.CurrentAnimation)
{
if(state.CurrentAnimation == null)
sprite.SetAnimationState("idle");
else
sprite.SetAnimationState(state.CurrentAnimation);
}
SetMaster((int?)state.MasterUid);
sprite.SetLoop(state.Loop);
}
}
using GorgonLibrary;
using GorgonLibrary.Graphics;
using SS14.Client.ClientWindow;
using SS14.Client.Graphics;
using SS14.Client.Interfaces.GOC;
using SS14.Client.Interfaces.Resource;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Renderable;
using SS14.Shared.IoC;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Image = GorgonLibrary.Graphics.Image;
namespace SS14.Client.GameObjects
{
public class AnimatedSpriteComponent : Component, IRenderableComponent
{
protected string baseSprite;
protected string currentSprite;
protected AnimatedSprite sprite;
protected bool flip;
protected IRenderableComponent master;
protected List<IRenderableComponent> slaves;
protected bool visible = true;
public DrawDepth DrawDepth { get; set; }
private SpeechBubble _speechBubble;
public AnimatedSpriteComponent()
{
Family = ComponentFamily.Renderable;
slaves = new List<IRenderableComponent>();
}
public override Type StateType
{
get { return typeof(AnimatedSpriteComponentState); }
}
public float Bottom
{
get
{
return Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y +
(sprite.AABB.Height / 2);
}
}
public RectangleF AverageAABB
{
get { return sprite.AverageAABB; }
}
#region ISpriteComponent Members
public RectangleF AABB
{
get
{
return new RectangleF(0, 0, sprite.AABB.Width,
sprite.AABB.Height);
}
}
#endregion
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
//Send a spritechanged message so everything knows whassup.
Owner.SendMessage(this, ComponentMessageType.SpriteChanged);
}
public void SetSprite()
{
if(baseSprite != null)
{
SetSprite(baseSprite);
}
}
public void SetSprite(string name)
{
currentSprite = name;
sprite = (AnimatedSprite)IoCManager.Resolve<IResourceManager>().GetAnimatedSprite(name);
}
public void SetAnimationState(string state, bool loop = true)
{
sprite.SetAnimationState(state);
sprite.SetLoop(loop);
foreach(AnimatedSpriteComponent s in slaves)
{
s.SetAnimationState(state, loop);
}
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.CheckSpriteClick:
reply = new ComponentReplyMessage(ComponentMessageType.SpriteWasClicked,
WasClicked((PointF)list[0]), DrawDepth);
break;
case ComponentMessageType.GetAABB:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentAABB, AABB);
break;
case ComponentMessageType.GetSprite:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentSprite, sprite.GetCurrentSprite());
break;
case ComponentMessageType.SetDrawDepth:
SetDrawDepth((DrawDepth)list[0]);
break;
case ComponentMessageType.SlaveAttach:
SetMaster(Owner.EntityManager.GetEntity((int)list[0]));
break;
case ComponentMessageType.ItemUnEquipped:
case ComponentMessageType.Dropped:
UnsetMaster();
break;
case ComponentMessageType.MoveDirection:
switch ((Direction)list[0])
{
case Direction.North:
sprite.Direction = Direction.North;
break;
case Direction.South:
sprite.Direction = Direction.South;
break;
case Direction.East:
sprite.Direction = Direction.East;
break;
case Direction.West:
sprite.Direction = Direction.West;
break;
case Direction.NorthEast:
sprite.Direction = Direction.NorthEast;
break;
case Direction.NorthWest:
sprite.Direction = Direction.NorthWest;
break;
case Direction.SouthEast:
sprite.Direction = Direction.SouthEast;
break;
case Direction.SouthWest:
sprite.Direction = Direction.SouthWest;
break;
}
break;
case ComponentMessageType.EntitySaidSomething:
ChatChannel channel;
if (Enum.TryParse(list[0].ToString(), true, out channel))
{
string text = list[1].ToString();
if (channel == ChatChannel.Ingame || channel == ChatChannel.Player ||
channel == ChatChannel.Radio)
{
(_speechBubble ?? (_speechBubble = new SpeechBubble(Owner.Name + Owner.Uid))).SetText(text);
}
}
break;
}
return reply;
}
protected void SetDrawDepth(DrawDepth p)
{
DrawDepth = p;
}
protected virtual bool WasClicked(PointF worldPos)
{
if (sprite == null || !visible) return false;
Sprite spriteToCheck = sprite.GetCurrentSprite();
var AABB =
new RectangleF(
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X -
(spriteToCheck.Width / 2),
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y -
(spriteToCheck.Height / 2), spriteToCheck.Width, spriteToCheck.Height);
if (!AABB.Contains(worldPos)) return false;
var spritePosition = new Point((int)(worldPos.X - AABB.X + spriteToCheck.ImageOffset.X),
(int)(worldPos.Y - AABB.Y + spriteToCheck.ImageOffset.Y));
Image.ImageLockBox imgData = spriteToCheck.Image.GetImageData();
imgData.Lock(false);
Color pixColour = Color.FromArgb((int)(imgData[spritePosition.X, spritePosition.Y]));
imgData.Dispose();
imgData.Unlock();
if (pixColour.A == 0) return false;
return true;
}
public override void SetParameter(ComponentParameter parameter)
{
base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "drawdepth":
SetDrawDepth((DrawDepth)Enum.Parse(typeof(DrawDepth), parameter.GetValue<string>(), true));
break;
case "sprite":
baseSprite = parameter.GetValue<string>();
SetSprite(parameter.GetValue<string>());
break;
}
}
public virtual void Render(Vector2D topLeft, Vector2D bottomRight)
{
//Render slaves beneath
IEnumerable<IRenderableComponent> renderablesBeneath = from IRenderableComponent c in slaves
//FIXTHIS
orderby c.DrawDepth ascending
where c.DrawDepth < DrawDepth
select c;
foreach (IRenderableComponent component in renderablesBeneath.ToList())
{
component.Render(topLeft, bottomRight);
}
//Render this sprite
if (!visible) return;
if (sprite == null) return;
Vector2D renderPos =
ClientWindowData.WorldToScreen(
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
SetSpriteCenter(renderPos);
if (Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X + sprite.AABB.Right <
topLeft.X
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X > bottomRight.X
||
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y +
sprite.AABB.Bottom < topLeft.Y
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y > bottomRight.Y)
return;
sprite.HorizontalFlip = flip;
sprite.Draw();
sprite.HorizontalFlip = false;
//Render slaves above
IEnumerable<IRenderableComponent> renderablesAbove = from IRenderableComponent c in slaves
//FIXTHIS
orderby c.DrawDepth ascending
where c.DrawDepth >= DrawDepth
select c;
foreach (IRenderableComponent component in renderablesAbove.ToList())
{
component.Render(topLeft, bottomRight);
}
//Draw AABB
var aabb = AABB;
//Gorgon.CurrentRenderTarget.Rectangle(renderPos.X - aabb.Width/2, renderPos.Y - aabb.Height / 2, aabb.Width, aabb.Height, Color.Lime);
if (_speechBubble != null)
_speechBubble.Draw(Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position,
ClientWindowData.Singleton.ScreenOrigin, aabb);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if(sprite != null)
{
sprite.Update(frameTime);
}
}
public void SetSpriteCenter(Vector2D center)
{
sprite.SetPosition(center.X - (sprite.AABB.Width / 2),
center.Y - (sprite.AABB.Height / 2));
}
public bool IsSlaved()
{
return master != null;
}
public void SetMaster(Entity m)
{
if (m == null)
{
UnsetMaster();
return;
}
if (!m.HasComponent(ComponentFamily.Renderable))
return;
var mastercompo = m.GetComponent<IRenderableComponent>(ComponentFamily.Renderable);
//If there's no sprite component, then FUCK IT
if (mastercompo == null)
return;
mastercompo.AddSlave(this);
master = mastercompo;
}
public void SetMaster(int? mUid)
{
if (master != null)
{
if (mUid == null)
{
UnsetMaster();
}
else if (mUid != master.Owner.Uid)
{
UnsetMaster();
SetMaster(Owner.EntityManager.GetEntity((int)mUid));
}
}
else if (mUid != null)
{
SetMaster(Owner.EntityManager.GetEntity((int)mUid));
}
}
public void UnsetMaster()
{
if (master == null)
return;
master.RemoveSlave(this);
master = null;
}
public void AddSlave(IRenderableComponent slavecompo)
{
slaves.Add(slavecompo);
}
public void RemoveSlave(IRenderableComponent slavecompo)
{
if (slaves.Contains(slavecompo))
slaves.Remove(slavecompo);
}
public override void HandleComponentState(dynamic state)
{
DrawDepth = state.DrawDepth;
visible = state.Visible;
if(sprite.Name != state.Name)
SetSprite(state.Name);
if (sprite.CurrentAnimationStateKey != state.CurrentAnimation)
{
if(state.CurrentAnimation == null)
sprite.SetAnimationState("idle");
else
sprite.SetAnimationState(state.CurrentAnimation);
}
SetMaster((int?)state.MasterUid);
sprite.SetLoop(state.Loop);
}
}
}

View File

@@ -1,204 +1,204 @@
using System;
using System.Drawing;
using ClientInterfaces.Resource;
using GorgonLibrary.Graphics;
using Lidgren.Network;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Renderable;
namespace CGO
{
public class ItemSpriteComponent : SpriteComponent
{
private bool IsInHand;
private string basename = "";
private Hand holdingHand = Hand.None;
public ItemSpriteComponent()
{
SetDrawDepth(DrawDepth.FloorObjects);
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.MoveDirection:
if (!IsInHand)
break;
SetDrawDepth(DrawDepth.HeldItems);
switch ((Direction) list[0])
{
case Direction.North:
if (SpriteExists(basename + "_inhand_back"))
SetSpriteByKey(basename + "_inhand_back");
else
SetSpriteByKey(basename + "_inhand");
if (holdingHand == Hand.Left)
flip = false;
else
flip = true;
break;
case Direction.South:
SetSpriteByKey(basename + "_inhand");
if (holdingHand == Hand.Left)
flip = true;
else
flip = false;
break;
case Direction.East:
if (holdingHand == Hand.Left)
SetDrawDepth(DrawDepth.FloorObjects);
else
SetDrawDepth(DrawDepth.HeldItems);
SetSpriteByKey(basename + "_inhand_side");
flip = true;
break;
case Direction.West:
if (holdingHand == Hand.Right)
SetDrawDepth(DrawDepth.FloorObjects);
else
SetDrawDepth(DrawDepth.HeldItems);
SetSpriteByKey(basename + "_inhand_side");
flip = false;
break;
case Direction.NorthEast:
if (SpriteExists(basename + "_inhand_back"))
SetSpriteByKey(basename + "_inhand_back");
else
SetSpriteByKey(basename + "_inhand");
if (holdingHand == Hand.Left)
flip = false;
else
flip = true;
break;
case Direction.NorthWest:
if (SpriteExists(basename + "_inhand_back"))
SetSpriteByKey(basename + "_inhand_back");
else
SetSpriteByKey(basename + "_inhand");
if (holdingHand == Hand.Left)
flip = false;
else
flip = true;
break;
case Direction.SouthEast:
SetSpriteByKey(basename + "_inhand");
if (holdingHand == Hand.Right)
flip = false;
else
flip = true;
break;
case Direction.SouthWest:
SetSpriteByKey(basename + "_inhand");
if (holdingHand == Hand.Right)
flip = false;
else
flip = true;
break;
}
break;
case ComponentMessageType.Dropped:
SetSpriteByKey(basename);
IsInHand = false;
SetDrawDepth(DrawDepth.FloorObjects);
holdingHand = Hand.None;
break;
case ComponentMessageType.PickedUp:
IsInHand = true;
holdingHand = (Hand) list[0];
break;
case ComponentMessageType.SetBaseName:
basename = (string) list[0];
break;
}
return reply;
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
base.HandleNetworkMessage(message, sender);
switch ((ComponentMessageType) message.MessageParameters[0])
{
case ComponentMessageType.SetBaseName:
//basename = (string) message.MessageParameters[1];
break;
}
}
/// <summary>
/// Set parameters :)
/// </summary>
/// <param name="parameter"></param>
public override void SetParameter(ComponentParameter parameter)
{
//base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "drawdepth":
SetDrawDepth((DrawDepth) Enum.Parse(typeof (DrawDepth), parameter.GetValue<string>(), true));
break;
case "basename":
basename = parameter.GetValue<string>();
LoadSprites();
break;
case "addsprite":
var spriteToAdd = parameter.GetValue<string>();
LoadSprites(spriteToAdd);
break;
}
}
protected override Sprite GetBaseSprite()
{
return sprites[basename];
}
/// <summary>
/// Load the mob sprites given the base name of the sprites.
/// </summary>
public void LoadSprites()
{
LoadSprites(basename);
SetSpriteByKey(basename);
}
public void LoadSprites(string name)
{
if (!HasSprite(name))
{
AddSprite(name);
AddSprite(name + "_inhand");
AddSprite(name + "_inhand_side");
if (IoCManager.Resolve<IResourceManager>().SpriteExists(name + "_inhand_back"))
AddSprite(name + "_inhand_back");
}
}
protected override bool WasClicked(PointF worldPos)
{
return base.WasClicked(worldPos) && !IsInHand;
}
public override void HandleComponentState(dynamic state)
{
base.HandleComponentState((SpriteComponentState) state);
if (state.BaseName != null && basename != state.BaseName)
{
basename = state.BaseName;
LoadSprites();
}
}
}
using GorgonLibrary.Graphics;
using Lidgren.Network;
using SS14.Client.Interfaces.Resource;
using SS14.Shared;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Renderable;
using SS14.Shared.IoC;
using System;
using System.Drawing;
namespace SS14.Client.GameObjects
{
public class ItemSpriteComponent : SpriteComponent
{
private bool IsInHand;
private string basename = "";
private Hand holdingHand = Hand.None;
public ItemSpriteComponent()
{
SetDrawDepth(DrawDepth.FloorObjects);
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.MoveDirection:
if (!IsInHand)
break;
SetDrawDepth(DrawDepth.HeldItems);
switch ((Direction) list[0])
{
case Direction.North:
if (SpriteExists(basename + "_inhand_back"))
SetSpriteByKey(basename + "_inhand_back");
else
SetSpriteByKey(basename + "_inhand");
if (holdingHand == Hand.Left)
flip = false;
else
flip = true;
break;
case Direction.South:
SetSpriteByKey(basename + "_inhand");
if (holdingHand == Hand.Left)
flip = true;
else
flip = false;
break;
case Direction.East:
if (holdingHand == Hand.Left)
SetDrawDepth(DrawDepth.FloorObjects);
else
SetDrawDepth(DrawDepth.HeldItems);
SetSpriteByKey(basename + "_inhand_side");
flip = true;
break;
case Direction.West:
if (holdingHand == Hand.Right)
SetDrawDepth(DrawDepth.FloorObjects);
else
SetDrawDepth(DrawDepth.HeldItems);
SetSpriteByKey(basename + "_inhand_side");
flip = false;
break;
case Direction.NorthEast:
if (SpriteExists(basename + "_inhand_back"))
SetSpriteByKey(basename + "_inhand_back");
else
SetSpriteByKey(basename + "_inhand");
if (holdingHand == Hand.Left)
flip = false;
else
flip = true;
break;
case Direction.NorthWest:
if (SpriteExists(basename + "_inhand_back"))
SetSpriteByKey(basename + "_inhand_back");
else
SetSpriteByKey(basename + "_inhand");
if (holdingHand == Hand.Left)
flip = false;
else
flip = true;
break;
case Direction.SouthEast:
SetSpriteByKey(basename + "_inhand");
if (holdingHand == Hand.Right)
flip = false;
else
flip = true;
break;
case Direction.SouthWest:
SetSpriteByKey(basename + "_inhand");
if (holdingHand == Hand.Right)
flip = false;
else
flip = true;
break;
}
break;
case ComponentMessageType.Dropped:
SetSpriteByKey(basename);
IsInHand = false;
SetDrawDepth(DrawDepth.FloorObjects);
holdingHand = Hand.None;
break;
case ComponentMessageType.PickedUp:
IsInHand = true;
holdingHand = (Hand) list[0];
break;
case ComponentMessageType.SetBaseName:
basename = (string) list[0];
break;
}
return reply;
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
base.HandleNetworkMessage(message, sender);
switch ((ComponentMessageType) message.MessageParameters[0])
{
case ComponentMessageType.SetBaseName:
//basename = (string) message.MessageParameters[1];
break;
}
}
/// <summary>
/// Set parameters :)
/// </summary>
/// <param name="parameter"></param>
public override void SetParameter(ComponentParameter parameter)
{
//base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "drawdepth":
SetDrawDepth((DrawDepth) Enum.Parse(typeof (DrawDepth), parameter.GetValue<string>(), true));
break;
case "basename":
basename = parameter.GetValue<string>();
LoadSprites();
break;
case "addsprite":
var spriteToAdd = parameter.GetValue<string>();
LoadSprites(spriteToAdd);
break;
}
}
protected override Sprite GetBaseSprite()
{
return sprites[basename];
}
/// <summary>
/// Load the mob sprites given the base name of the sprites.
/// </summary>
public void LoadSprites()
{
LoadSprites(basename);
SetSpriteByKey(basename);
}
public void LoadSprites(string name)
{
if (!HasSprite(name))
{
AddSprite(name);
AddSprite(name + "_inhand");
AddSprite(name + "_inhand_side");
if (IoCManager.Resolve<IResourceManager>().SpriteExists(name + "_inhand_back"))
AddSprite(name + "_inhand_back");
}
}
protected override bool WasClicked(PointF worldPos)
{
return base.WasClicked(worldPos) && !IsInHand;
}
public override void HandleComponentState(dynamic state)
{
base.HandleComponentState((SpriteComponentState) state);
if (state.BaseName != null && basename != state.BaseName)
{
basename = state.BaseName;
LoadSprites();
}
}
}
}

View File

@@ -1,156 +1,156 @@
using System;
using ClientWindow;
using GorgonLibrary;
using GorgonLibrary.Graphics;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Renderable;
namespace CGO
{
public class MobSpriteComponent : SpriteComponent
{
private string _basename;
private SpeechBubble _speechBubble;
public MobSpriteComponent()
{
DrawDepth = DrawDepth.MobBase;
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.MoveDirection:
switch ((Direction) list[0])
{
case Direction.North:
SetSpriteByKey(_basename + "_back");
flip = false;
break;
case Direction.South:
SetSpriteByKey(_basename + "_front");
flip = false;
break;
case Direction.East:
SetSpriteByKey(_basename + "_side");
flip = true;
break;
case Direction.West:
SetSpriteByKey(_basename + "_side");
flip = false;
break;
case Direction.NorthEast:
SetSpriteByKey(_basename + "_back");
flip = false;
break;
case Direction.NorthWest:
SetSpriteByKey(_basename + "_back");
flip = false;
break;
case Direction.SouthEast:
SetSpriteByKey(_basename + "_front");
flip = false;
break;
case Direction.SouthWest:
SetSpriteByKey(_basename + "_front");
flip = false;
break;
}
break;
case ComponentMessageType.Die:
SetSpriteByKey(_basename + "_incap_dead");
flip = false;
break;
case ComponentMessageType.EntitySaidSomething:
ChatChannel channel;
if (Enum.TryParse(list[0].ToString(), true, out channel))
{
string text = list[1].ToString();
if (channel == ChatChannel.Ingame || channel == ChatChannel.Player ||
channel == ChatChannel.Radio)
{
(_speechBubble ?? (_speechBubble = new SpeechBubble(Owner.Name + Owner.Uid))).SetText(text);
}
}
break;
}
return reply;
}
/// <summary>
/// Set parameters :)
/// </summary>
/// <param name="parameter"></param>
public override void SetParameter(ComponentParameter parameter)
{
//base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "drawdepth":
SetDrawDepth((DrawDepth) Enum.Parse(typeof (DrawDepth), parameter.GetValue<string>(), true));
break;
case "basename":
_basename = parameter.GetValue<string>();
LoadSprites();
break;
}
}
protected override Sprite GetBaseSprite()
{
//return sprites[basename + "_front"];
return currentBaseSprite;
}
/// <summary>
/// Load the mob sprites given the base name of the sprites.
/// </summary>
public void LoadSprites()
{
AddSprite(_basename + "_front");
AddSprite(_basename + "_back");
AddSprite(_basename + "_incap");
AddSprite(_basename + "_side");
AddSprite(_basename + "_incap_dead");
SetSpriteByKey(_basename + "_front");
}
public override void Render(Vector2D topLeft, Vector2D bottomRight)
{
if (!visible) return;
if (Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X < topLeft.X
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X > bottomRight.X
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y < topLeft.Y
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y > bottomRight.Y)
return;
base.Render(topLeft, bottomRight);
if (_speechBubble != null)
_speechBubble.Draw(Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position,
ClientWindowData.Singleton.ScreenOrigin, currentBaseSprite);
}
public override void HandleComponentState(dynamic state)
{
base.HandleComponentState((SpriteComponentState) state);
if (state.BaseName != null && _basename != state.BaseName)
{
_basename = state.BaseName;
LoadSprites();
}
}
}
using GorgonLibrary;
using GorgonLibrary.Graphics;
using SS14.Client.ClientWindow;
using SS14.Shared;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Renderable;
using System;
namespace SS14.Client.GameObjects
{
public class MobSpriteComponent : SpriteComponent
{
private string _basename;
private SpeechBubble _speechBubble;
public MobSpriteComponent()
{
DrawDepth = DrawDepth.MobBase;
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.MoveDirection:
switch ((Direction) list[0])
{
case Direction.North:
SetSpriteByKey(_basename + "_back");
flip = false;
break;
case Direction.South:
SetSpriteByKey(_basename + "_front");
flip = false;
break;
case Direction.East:
SetSpriteByKey(_basename + "_side");
flip = true;
break;
case Direction.West:
SetSpriteByKey(_basename + "_side");
flip = false;
break;
case Direction.NorthEast:
SetSpriteByKey(_basename + "_back");
flip = false;
break;
case Direction.NorthWest:
SetSpriteByKey(_basename + "_back");
flip = false;
break;
case Direction.SouthEast:
SetSpriteByKey(_basename + "_front");
flip = false;
break;
case Direction.SouthWest:
SetSpriteByKey(_basename + "_front");
flip = false;
break;
}
break;
case ComponentMessageType.Die:
SetSpriteByKey(_basename + "_incap_dead");
flip = false;
break;
case ComponentMessageType.EntitySaidSomething:
ChatChannel channel;
if (Enum.TryParse(list[0].ToString(), true, out channel))
{
string text = list[1].ToString();
if (channel == ChatChannel.Ingame || channel == ChatChannel.Player ||
channel == ChatChannel.Radio)
{
(_speechBubble ?? (_speechBubble = new SpeechBubble(Owner.Name + Owner.Uid))).SetText(text);
}
}
break;
}
return reply;
}
/// <summary>
/// Set parameters :)
/// </summary>
/// <param name="parameter"></param>
public override void SetParameter(ComponentParameter parameter)
{
//base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "drawdepth":
SetDrawDepth((DrawDepth) Enum.Parse(typeof (DrawDepth), parameter.GetValue<string>(), true));
break;
case "basename":
_basename = parameter.GetValue<string>();
LoadSprites();
break;
}
}
protected override Sprite GetBaseSprite()
{
//return sprites[basename + "_front"];
return currentBaseSprite;
}
/// <summary>
/// Load the mob sprites given the base name of the sprites.
/// </summary>
public void LoadSprites()
{
AddSprite(_basename + "_front");
AddSprite(_basename + "_back");
AddSprite(_basename + "_incap");
AddSprite(_basename + "_side");
AddSprite(_basename + "_incap_dead");
SetSpriteByKey(_basename + "_front");
}
public override void Render(Vector2D topLeft, Vector2D bottomRight)
{
if (!visible) return;
if (Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X < topLeft.X
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X > bottomRight.X
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y < topLeft.Y
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y > bottomRight.Y)
return;
base.Render(topLeft, bottomRight);
if (_speechBubble != null)
_speechBubble.Draw(Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position,
ClientWindowData.Singleton.ScreenOrigin, currentBaseSprite);
}
public override void HandleComponentState(dynamic state)
{
base.HandleComponentState((SpriteComponentState) state);
if (state.BaseName != null && _basename != state.BaseName)
{
_basename = state.BaseName;
LoadSprites();
}
}
}
}

View File

@@ -1,214 +1,212 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Xml.Linq;
using ClientInterfaces.GOC;
using ClientInterfaces.Resource;
using ClientWindow;
using GameObject;
using GorgonLibrary;
using GorgonLibrary.Graphics;
using GorgonLibrary.Graphics.Utilities;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Particles;
namespace CGO
{
public class ParticleSystemComponent : Component, IParticleSystemComponent, IRenderableComponent
{
#region Variables.
private Dictionary<string, ParticleSystem> _emitters = new Dictionary<string, ParticleSystem>(); // List of particle emitters.
protected IRenderableComponent master;
protected List<IRenderableComponent> slaves = new List<IRenderableComponent>();
public DrawDepth DrawDepth { get; set; }
#endregion
#region Properties
public RectangleF AverageAABB
{
get { return AABB; }
}
public RectangleF AABB
{
get { return RectangleF.Empty; }
}
#endregion
public ParticleSystemComponent()
{
Family = ComponentFamily.Particles;
DrawDepth = DrawDepth.ItemsOnTables;
}
public override Type StateType
{
get { return typeof(ParticleSystemComponentState); }
}
public void OnMove(object sender, VectorEventArgs args)
{
var offset = new Vector2D(args.VectorTo.X, args.VectorTo.Y) -
new Vector2D(args.VectorFrom.X, args.VectorFrom.Y);
foreach (KeyValuePair<string, ParticleSystem> particleSystem in _emitters)
{
particleSystem.Value.MoveEmitter(particleSystem.Value.EmitterPosition + offset);
}
//_emitter.MoveEmitter(_emitter.EmitterPosition + offset);
}
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
var transform = Owner.GetComponent<TransformComponent>(ComponentFamily.Transform);
transform.OnMove += OnMove;
}
public override void OnRemove()
{
var transform = Owner.GetComponent<TransformComponent>(ComponentFamily.Transform);
transform.OnMove -= OnMove;
base.OnRemove();
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.SetDrawDepth:
DrawDepth = (DrawDepth)list[0];
break;
}
return reply;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (KeyValuePair<string, ParticleSystem> particleSystem in _emitters)
{
particleSystem.Value.Update(frameTime);
}
//_emitter.Update(frameTime);
}
public virtual void Render(Vector2D topLeft, Vector2D bottomRight)
{
var blend = Gorgon.CurrentRenderTarget.BlendingMode;
Gorgon.CurrentRenderTarget.BlendingMode = BlendingModes.Additive;
Vector2D renderPos =
ClientWindowData.WorldToScreen(
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
foreach (KeyValuePair<string, ParticleSystem> particleSystem in _emitters.OrderBy(x => x.Value.ParticleSprite.Image.Name)) //Render sorted by atlas. Tiny performance improvement for entities with a bunch of particlesystems.
{
particleSystem.Value.Move(renderPos);
particleSystem.Value.Render();
}
//_emitter.Move(renderPos);
//_emitter.Render();
Gorgon.CurrentRenderTarget.BlendingMode = blend;
}
public float Bottom
{
get
{
return Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y;
//return Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y +
// (_particleSprite.Height / 2);
}
}
public bool IsSlaved()
{
return master != null;
}
public void SetMaster(Entity m)
{
if (!m.HasComponent(ComponentFamily.Renderable))
return;
var mastercompo = m.GetComponent<SpriteComponent>(ComponentFamily.Renderable);
//If there's no sprite component, then FUCK IT
if (mastercompo == null)
return;
mastercompo.AddSlave(this);
master = mastercompo;
}
public void UnsetMaster()
{
if (master == null)
return;
master.RemoveSlave(this);
master = null;
}
public void AddSlave(IRenderableComponent slavecompo)
{
slaves.Add(slavecompo);
}
public void RemoveSlave(IRenderableComponent slavecompo)
{
if (slaves.Contains(slavecompo))
slaves.Remove(slavecompo);
}
public void AddParticleSystem(string name, bool active)
{
if (!_emitters.ContainsKey(name))
{
ParticleSettings toAdd = IoCManager.Resolve<IResourceManager>().GetParticles(name);
if (toAdd != null)
{
_emitters.Add(name, new ParticleSystem(toAdd, Vector2D.Zero));
_emitters[name].Emit = active;
}
}
}
public void RemoveParticleSystem(string name)
{
if (_emitters.ContainsKey(name))
_emitters.Remove(name);
}
public void SetParticleSystemActive(string name, bool active)
{
if (_emitters.ContainsKey(name))
_emitters[name].Emit = active;
}
public override void HandleComponentState(dynamic _state)
{
ParticleSystemComponentState state = (ParticleSystemComponentState)_state;
foreach (var a in state.emitters)
{
if (_emitters.ContainsKey(a.Key))
SetParticleSystemActive(a.Key, a.Value);
else
AddParticleSystem(a.Key, a.Value);
}
foreach (var toRemove in new List<string>(_emitters.Keys.Except<string>(state.emitters.Keys))) //Remove emitters that are not in the new state.
RemoveParticleSystem(toRemove);
}
}
using GorgonLibrary;
using GorgonLibrary.Graphics;
using SS14.Client.ClientWindow;
using SS14.Client.Interfaces.GOC;
using SS14.Client.Interfaces.Resource;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Particles;
using SS14.Shared.IoC;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace SS14.Client.GameObjects
{
public class ParticleSystemComponent : Component, IParticleSystemComponent, IRenderableComponent
{
#region Variables.
private Dictionary<string, ParticleSystem> _emitters = new Dictionary<string, ParticleSystem>(); // List of particle emitters.
protected IRenderableComponent master;
protected List<IRenderableComponent> slaves = new List<IRenderableComponent>();
public DrawDepth DrawDepth { get; set; }
#endregion
#region Properties
public RectangleF AverageAABB
{
get { return AABB; }
}
public RectangleF AABB
{
get { return RectangleF.Empty; }
}
#endregion
public ParticleSystemComponent()
{
Family = ComponentFamily.Particles;
DrawDepth = DrawDepth.ItemsOnTables;
}
public override Type StateType
{
get { return typeof(ParticleSystemComponentState); }
}
public void OnMove(object sender, VectorEventArgs args)
{
var offset = new Vector2D(args.VectorTo.X, args.VectorTo.Y) -
new Vector2D(args.VectorFrom.X, args.VectorFrom.Y);
foreach (KeyValuePair<string, ParticleSystem> particleSystem in _emitters)
{
particleSystem.Value.MoveEmitter(particleSystem.Value.EmitterPosition + offset);
}
//_emitter.MoveEmitter(_emitter.EmitterPosition + offset);
}
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
var transform = Owner.GetComponent<TransformComponent>(ComponentFamily.Transform);
transform.OnMove += OnMove;
}
public override void OnRemove()
{
var transform = Owner.GetComponent<TransformComponent>(ComponentFamily.Transform);
transform.OnMove -= OnMove;
base.OnRemove();
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.SetDrawDepth:
DrawDepth = (DrawDepth)list[0];
break;
}
return reply;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (KeyValuePair<string, ParticleSystem> particleSystem in _emitters)
{
particleSystem.Value.Update(frameTime);
}
//_emitter.Update(frameTime);
}
public virtual void Render(Vector2D topLeft, Vector2D bottomRight)
{
var blend = Gorgon.CurrentRenderTarget.BlendingMode;
Gorgon.CurrentRenderTarget.BlendingMode = BlendingModes.Additive;
Vector2D renderPos =
ClientWindowData.WorldToScreen(
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
foreach (KeyValuePair<string, ParticleSystem> particleSystem in _emitters.OrderBy(x => x.Value.ParticleSprite.Image.Name)) //Render sorted by atlas. Tiny performance improvement for entities with a bunch of particlesystems.
{
particleSystem.Value.Move(renderPos);
particleSystem.Value.Render();
}
//_emitter.Move(renderPos);
//_emitter.Render();
Gorgon.CurrentRenderTarget.BlendingMode = blend;
}
public float Bottom
{
get
{
return Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y;
//return Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y +
// (_particleSprite.Height / 2);
}
}
public bool IsSlaved()
{
return master != null;
}
public void SetMaster(Entity m)
{
if (!m.HasComponent(ComponentFamily.Renderable))
return;
var mastercompo = m.GetComponent<SpriteComponent>(ComponentFamily.Renderable);
//If there's no sprite component, then FUCK IT
if (mastercompo == null)
return;
mastercompo.AddSlave(this);
master = mastercompo;
}
public void UnsetMaster()
{
if (master == null)
return;
master.RemoveSlave(this);
master = null;
}
public void AddSlave(IRenderableComponent slavecompo)
{
slaves.Add(slavecompo);
}
public void RemoveSlave(IRenderableComponent slavecompo)
{
if (slaves.Contains(slavecompo))
slaves.Remove(slavecompo);
}
public void AddParticleSystem(string name, bool active)
{
if (!_emitters.ContainsKey(name))
{
ParticleSettings toAdd = IoCManager.Resolve<IResourceManager>().GetParticles(name);
if (toAdd != null)
{
_emitters.Add(name, new ParticleSystem(toAdd, Vector2D.Zero));
_emitters[name].Emit = active;
}
}
}
public void RemoveParticleSystem(string name)
{
if (_emitters.ContainsKey(name))
_emitters.Remove(name);
}
public void SetParticleSystemActive(string name, bool active)
{
if (_emitters.ContainsKey(name))
_emitters[name].Emit = active;
}
public override void HandleComponentState(dynamic _state)
{
ParticleSystemComponentState state = (ParticleSystemComponentState)_state;
foreach (var a in state.emitters)
{
if (_emitters.ContainsKey(a.Key))
SetParticleSystemActive(a.Key, a.Value);
else
AddParticleSystem(a.Key, a.Value);
}
foreach (var toRemove in new List<string>(_emitters.Keys.Except<string>(state.emitters.Keys))) //Remove emitters that are not in the new state.
RemoveParticleSystem(toRemove);
}
}
}

View File

@@ -1,42 +1,42 @@
using System;
using ClientInterfaces.GOC;
using GameObject;
using GorgonLibrary;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Renderable;
namespace CGO
{
public class RenderableComponent : Component, IRenderableComponent
{
public RenderableComponent()
{
Family = ComponentFamily.Renderable;
}
public override Type StateType
{
get { return typeof (RenderableComponentState); }
}
#region IRenderableComponent Members
public DrawDepth DrawDepth { get; set; }
public virtual float Bottom
{
get { return 0f; }
}
public virtual void Render(Vector2D topLeft, Vector2D bottomRight)
{
}
#endregion
public override void HandleComponentState(dynamic state)
{
DrawDepth = state.DrawDepth;
}
}
using System;
using ClientInterfaces.GOC;
using GameObject;
using GorgonLibrary;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Renderable;
namespace CGO
{
public class RenderableComponent : Component, IRenderableComponent
{
public RenderableComponent()
{
Family = ComponentFamily.Renderable;
}
public override Type StateType
{
get { return typeof (RenderableComponentState); }
}
#region IRenderableComponent Members
public DrawDepth DrawDepth { get; set; }
public virtual float Bottom
{
get { return 0f; }
}
public virtual void Render(Vector2D topLeft, Vector2D bottomRight)
{
}
#endregion
public override void HandleComponentState(dynamic state)
{
DrawDepth = state.DrawDepth;
}
}
}

View File

@@ -1,199 +1,199 @@
using System;
using System.Drawing;
using System.Text;
using ClientInterfaces.Resource;
using GorgonLibrary;
using GorgonLibrary.Graphics;
using SS13.IoC;
namespace CGO
{
public class SpeechBubble
{
#region Fields
/// <summary>
/// Constant lifetime of speech bubble in milliseconds.
/// TODO: Consider making configurable?
/// </summary>
private const double MillisecondsToLive = 8000;
/// <summary>
/// Holder for built bubble render image.
/// Rebuilt upon text change.
/// </summary>
private readonly RenderImage _bubbleRender;
/// <summary>
/// Holder for built bubble sprite.
/// Rebuilt upon text change.
/// </summary>
private readonly Sprite _bubbleSprite;
/// <summary>
/// Owner mob unique name.
/// </summary>
private readonly string _mobName;
/// <summary>
/// Reference to Resource Manager service to prevent
/// calling IoCManager every time speechbubble is drawn.
/// </summary>
private readonly IResourceManager _resourceManager;
/// <summary>
/// StringBuilder to handle
/// </summary>
private readonly StringBuilder _stringBuilder;
/// <summary>
/// TextSprite used to hold and display speech text.
/// </summary>
private readonly TextSprite _textSprite;
/// <summary>
/// Holder for last time the sprite was
/// built. Used to detect if speech bubble
/// has expired.
/// </summary>
private DateTime _buildTime;
#endregion
#region Methods
#region Constructor
public SpeechBubble(string mobname)
{
_resourceManager = IoCManager.Resolve<IResourceManager>();
_mobName = mobname;
_buildTime = DateTime.Now;
_textSprite = new TextSprite
(
"chatBubbleTextSprite_" + _mobName,
String.Empty,
_resourceManager.GetFont("CALIBRI")
)
{
Color = Color.Black,
WordWrap = true
};
_textSprite.SetPosition(5, 3);
_stringBuilder = new StringBuilder();
_bubbleRender = new RenderImage("ChatBubbleRenderImage_" + _mobName, 1, 1, ImageBufferFormats.BufferRGB888A8);
_bubbleSprite = new Sprite("ChatBubbleRenderSprite_" + _mobName, _bubbleRender);
}
#endregion
#region Privates
#endregion
#region Publics
public void Draw(Vector2D position, Vector2D windowOrigin, Sprite spriteToDrawAbove)
{
if ((DateTime.Now - _buildTime).TotalMilliseconds >= MillisecondsToLive) return;
float x = position.X - windowOrigin.X - (_bubbleSprite.Width/2.0f);
float y = position.Y - windowOrigin.Y - (_bubbleSprite.Height) - (spriteToDrawAbove.Height/2.0f) - 5.0f;
_bubbleSprite.SetPosition(x, y);
_bubbleSprite.Draw();
}
public void Draw(Vector2D position, Vector2D windowOrigin, RectangleF boundingBox)
{
if ((DateTime.Now - _buildTime).TotalMilliseconds >= MillisecondsToLive) return;
float x = position.X - windowOrigin.X - (_bubbleSprite.Width / 2.0f);
float y = position.Y - windowOrigin.Y - (_bubbleSprite.Height) - (boundingBox.Height / 2.0f) - 5.0f;
_bubbleSprite.SetPosition(x, y);
_bubbleSprite.Draw();
}
public void SetText(string text)
{
for (int i = 0; i < text.Length; i++)
{
if (i > 0 && i%50 == 0)
_stringBuilder.Append("\n" + text[i]);
else
_stringBuilder.Append(text[i]);
}
_textSprite.Text = _stringBuilder.ToString();
_stringBuilder.Clear();
_textSprite.UpdateAABB();
DrawBubbleSprite();
}
#endregion
private void DrawBubbleSprite()
{
RenderTarget originalTarget = Gorgon.CurrentRenderTarget;
Sprite cornerSprite = _resourceManager.GetSprite("corners");
//Set up dimensions
_bubbleRender.SetDimensions((int) _textSprite.Size.X + 10, (int) _textSprite.Size.Y + 10);
_bubbleSprite.SetSize(_textSprite.Size.X + 10, _textSprite.Size.Y + 10);
//BEGIN RENDERING
Gorgon.CurrentRenderTarget = _bubbleRender;
_bubbleRender.Clear(Color.Transparent);
//Draw black triangle at the bottom.
var pointOneBlack = new Vector2D((_bubbleRender.Width/2) - 10, _bubbleRender.Height - 10);
var pointTwoBlack = new Vector2D((_bubbleRender.Width/2) + 10, _bubbleRender.Height - 10);
var pointThreeBlack = new Vector2D((_bubbleRender.Width/2), _bubbleRender.Height);
_bubbleRender.FilledTriangle(pointOneBlack, pointTwoBlack, pointThreeBlack, Color.Black);
//Draw the side lines
_bubbleRender.Line(10, 0, _bubbleRender.Width - 20, 1, Color.Black);
_bubbleRender.Line(_bubbleRender.Width - 1, 10, 1, _bubbleRender.Height - 26, Color.Black);
_bubbleRender.Line(10, _bubbleRender.Height - 7, _bubbleRender.Width - 20, 1, Color.Black);
_bubbleRender.Line(0, 10, 1, _bubbleRender.Height - 26, Color.Black);
//Fill in the middle without polluting the corners.
_bubbleRender.FilledRectangle(3, 1, _bubbleRender.Width - 6, _bubbleRender.Height - 8, Color.White);
_bubbleRender.FilledRectangle(1, 3, _bubbleRender.Width - 2, _bubbleRender.Height - 12, Color.White);
//Draw the white triangle at the bottom.
Vector2D pointOneWhite = pointOneBlack + new Vector2D(1, 0);
Vector2D pointTwoWhite = pointTwoBlack - new Vector2D(1, 0);
Vector2D pointThreeWhite = pointThreeBlack - new Vector2D(0, 1);
_bubbleRender.FilledTriangle(pointOneWhite, pointTwoWhite, pointThreeWhite, Color.White);
//Draw the corners.
cornerSprite.SourceBlend = AlphaBlendOperation.One;
cornerSprite.DestinationBlend = AlphaBlendOperation.Zero;
cornerSprite.VerticalFlip = true;
cornerSprite.SetPosition(0, 0);
cornerSprite.Draw();
cornerSprite.HorizontalFlip = true;
cornerSprite.SetPosition(_bubbleRender.Width - 16, 0);
cornerSprite.Draw();
cornerSprite.VerticalFlip = false;
cornerSprite.SetPosition(_bubbleRender.Width - 16, _bubbleRender.Height - 22);
cornerSprite.Draw();
cornerSprite.HorizontalFlip = false;
cornerSprite.SetPosition(0, _bubbleRender.Height - 22);
cornerSprite.Draw();
_textSprite.Draw();
Gorgon.CurrentRenderTarget = originalTarget;
_buildTime = DateTime.Now;
}
#endregion
}
using GorgonLibrary;
using GorgonLibrary.Graphics;
using SS14.Client.Interfaces.Resource;
using SS14.Shared.IoC;
using System;
using System.Drawing;
using System.Text;
namespace SS14.Client.GameObjects
{
public class SpeechBubble
{
#region Fields
/// <summary>
/// Constant lifetime of speech bubble in milliseconds.
/// TODO: Consider making configurable?
/// </summary>
private const double MillisecondsToLive = 8000;
/// <summary>
/// Holder for built bubble render image.
/// Rebuilt upon text change.
/// </summary>
private readonly RenderImage _bubbleRender;
/// <summary>
/// Holder for built bubble sprite.
/// Rebuilt upon text change.
/// </summary>
private readonly Sprite _bubbleSprite;
/// <summary>
/// Owner mob unique name.
/// </summary>
private readonly string _mobName;
/// <summary>
/// Reference to Resource Manager service to prevent
/// calling IoCManager every time speechbubble is drawn.
/// </summary>
private readonly IResourceManager _resourceManager;
/// <summary>
/// StringBuilder to handle
/// </summary>
private readonly StringBuilder _stringBuilder;
/// <summary>
/// TextSprite used to hold and display speech text.
/// </summary>
private readonly TextSprite _textSprite;
/// <summary>
/// Holder for last time the sprite was
/// built. Used to detect if speech bubble
/// has expired.
/// </summary>
private DateTime _buildTime;
#endregion
#region Methods
#region Constructor
public SpeechBubble(string mobname)
{
_resourceManager = IoCManager.Resolve<IResourceManager>();
_mobName = mobname;
_buildTime = DateTime.Now;
_textSprite = new TextSprite
(
"chatBubbleTextSprite_" + _mobName,
String.Empty,
_resourceManager.GetFont("CALIBRI")
)
{
Color = Color.Black,
WordWrap = true
};
_textSprite.SetPosition(5, 3);
_stringBuilder = new StringBuilder();
_bubbleRender = new RenderImage("ChatBubbleRenderImage_" + _mobName, 1, 1, ImageBufferFormats.BufferRGB888A8);
_bubbleSprite = new Sprite("ChatBubbleRenderSprite_" + _mobName, _bubbleRender);
}
#endregion
#region Privates
#endregion
#region Publics
public void Draw(Vector2D position, Vector2D windowOrigin, Sprite spriteToDrawAbove)
{
if ((DateTime.Now - _buildTime).TotalMilliseconds >= MillisecondsToLive) return;
float x = position.X - windowOrigin.X - (_bubbleSprite.Width/2.0f);
float y = position.Y - windowOrigin.Y - (_bubbleSprite.Height) - (spriteToDrawAbove.Height/2.0f) - 5.0f;
_bubbleSprite.SetPosition(x, y);
_bubbleSprite.Draw();
}
public void Draw(Vector2D position, Vector2D windowOrigin, RectangleF boundingBox)
{
if ((DateTime.Now - _buildTime).TotalMilliseconds >= MillisecondsToLive) return;
float x = position.X - windowOrigin.X - (_bubbleSprite.Width / 2.0f);
float y = position.Y - windowOrigin.Y - (_bubbleSprite.Height) - (boundingBox.Height / 2.0f) - 5.0f;
_bubbleSprite.SetPosition(x, y);
_bubbleSprite.Draw();
}
public void SetText(string text)
{
for (int i = 0; i < text.Length; i++)
{
if (i > 0 && i%50 == 0)
_stringBuilder.Append("\n" + text[i]);
else
_stringBuilder.Append(text[i]);
}
_textSprite.Text = _stringBuilder.ToString();
_stringBuilder.Clear();
_textSprite.UpdateAABB();
DrawBubbleSprite();
}
#endregion
private void DrawBubbleSprite()
{
RenderTarget originalTarget = Gorgon.CurrentRenderTarget;
Sprite cornerSprite = _resourceManager.GetSprite("corners");
//Set up dimensions
_bubbleRender.SetDimensions((int) _textSprite.Size.X + 10, (int) _textSprite.Size.Y + 10);
_bubbleSprite.SetSize(_textSprite.Size.X + 10, _textSprite.Size.Y + 10);
//BEGIN RENDERING
Gorgon.CurrentRenderTarget = _bubbleRender;
_bubbleRender.Clear(Color.Transparent);
//Draw black triangle at the bottom.
var pointOneBlack = new Vector2D((_bubbleRender.Width/2) - 10, _bubbleRender.Height - 10);
var pointTwoBlack = new Vector2D((_bubbleRender.Width/2) + 10, _bubbleRender.Height - 10);
var pointThreeBlack = new Vector2D((_bubbleRender.Width/2), _bubbleRender.Height);
_bubbleRender.FilledTriangle(pointOneBlack, pointTwoBlack, pointThreeBlack, Color.Black);
//Draw the side lines
_bubbleRender.Line(10, 0, _bubbleRender.Width - 20, 1, Color.Black);
_bubbleRender.Line(_bubbleRender.Width - 1, 10, 1, _bubbleRender.Height - 26, Color.Black);
_bubbleRender.Line(10, _bubbleRender.Height - 7, _bubbleRender.Width - 20, 1, Color.Black);
_bubbleRender.Line(0, 10, 1, _bubbleRender.Height - 26, Color.Black);
//Fill in the middle without polluting the corners.
_bubbleRender.FilledRectangle(3, 1, _bubbleRender.Width - 6, _bubbleRender.Height - 8, Color.White);
_bubbleRender.FilledRectangle(1, 3, _bubbleRender.Width - 2, _bubbleRender.Height - 12, Color.White);
//Draw the white triangle at the bottom.
Vector2D pointOneWhite = pointOneBlack + new Vector2D(1, 0);
Vector2D pointTwoWhite = pointTwoBlack - new Vector2D(1, 0);
Vector2D pointThreeWhite = pointThreeBlack - new Vector2D(0, 1);
_bubbleRender.FilledTriangle(pointOneWhite, pointTwoWhite, pointThreeWhite, Color.White);
//Draw the corners.
cornerSprite.SourceBlend = AlphaBlendOperation.One;
cornerSprite.DestinationBlend = AlphaBlendOperation.Zero;
cornerSprite.VerticalFlip = true;
cornerSprite.SetPosition(0, 0);
cornerSprite.Draw();
cornerSprite.HorizontalFlip = true;
cornerSprite.SetPosition(_bubbleRender.Width - 16, 0);
cornerSprite.Draw();
cornerSprite.VerticalFlip = false;
cornerSprite.SetPosition(_bubbleRender.Width - 16, _bubbleRender.Height - 22);
cornerSprite.Draw();
cornerSprite.HorizontalFlip = false;
cornerSprite.SetPosition(0, _bubbleRender.Height - 22);
cornerSprite.Draw();
_textSprite.Draw();
Gorgon.CurrentRenderTarget = originalTarget;
_buildTime = DateTime.Now;
}
#endregion
}
}

View File

@@ -1,402 +1,402 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using ClientInterfaces.GOC;
using ClientInterfaces.Resource;
using ClientWindow;
using GameObject;
using GorgonLibrary;
using GorgonLibrary.Graphics;
using Lidgren.Network;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Renderable;
using Image = GorgonLibrary.Graphics.Image;
namespace CGO
{
public class SpriteComponent : Component, IRenderableComponent, ISpriteComponent
{
protected Sprite currentBaseSprite;
protected Dictionary<string, Sprite> dirSprites;
protected bool flip;
protected IRenderableComponent master;
protected List<IRenderableComponent> slaves;
protected Dictionary<string, Sprite> sprites;
protected bool visible = true;
public DrawDepth DrawDepth { get; set; }
public SpriteComponent()
{
Family = ComponentFamily.Renderable;
sprites = new Dictionary<string, Sprite>();
dirSprites = new Dictionary<string, Sprite>();
slaves = new List<IRenderableComponent>();
}
public override Type StateType
{
get { return typeof (SpriteComponentState); }
}
public float Bottom
{
get
{
return Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y +
(GetActiveDirectionalSprite().AABB.Height/2);
}
}
#region ISpriteComponent Members
public RectangleF AverageAABB
{
get { return AABB; }
}
public RectangleF AABB
{
get
{
return new RectangleF(0, 0, GetActiveDirectionalSprite().AABB.Width,
GetActiveDirectionalSprite().AABB.Height);
}
}
public Sprite GetCurrentSprite()
{
return GetActiveDirectionalSprite();
}
public Sprite GetSprite(string spriteKey)
{
if (sprites.ContainsKey(spriteKey))
return sprites[spriteKey];
else
return null;
}
public List<Sprite> GetAllSprites()
{
return sprites.Values.ToList();
}
public void SetSpriteByKey(string spriteKey)
{
if (sprites.ContainsKey(spriteKey))
{
currentBaseSprite = sprites[spriteKey];
if (Owner != null)
Owner.SendMessage(this, ComponentMessageType.SpriteChanged);
}
else
throw new Exception("Whoops. That sprite isn't in the dictionary.");
}
public void AddSprite(string spriteKey)
{
if (sprites.ContainsKey(spriteKey))
throw new Exception("That sprite is already added.");
if (IoCManager.Resolve<IResourceManager>().SpriteExists(spriteKey))
AddSprite(spriteKey, IoCManager.Resolve<IResourceManager>().GetSprite(spriteKey));
//If there's only one sprite, and the current sprite is explicitly not set, then lets go ahead and set our sprite.
if (sprites.Count == 1)
SetSpriteByKey(sprites.Keys.First());
BuildDirectionalSprites();
}
public void AddSprite(string key, Sprite spritetoadd)
{
if (spritetoadd != null && key != "")
sprites.Add(key, spritetoadd);
BuildDirectionalSprites();
}
public bool HasSprite(string key)
{
return sprites.ContainsKey(key);
}
#endregion
private void BuildDirectionalSprites()
{
dirSprites.Clear();
var resMgr = IoCManager.Resolve<IResourceManager>();
foreach (var curr in sprites)
{
foreach (string dir in Enum.GetNames(typeof (Direction)))
{
string name = (curr.Key + "_" + dir).ToLowerInvariant();
if (resMgr.SpriteExists(name))
dirSprites.Add(name, resMgr.GetSprite(name));
}
}
}
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
//Send a spritechanged message so everything knows whassup.
Owner.SendMessage(this, ComponentMessageType.SpriteChanged);
}
public void ClearSprites()
{
sprites.Clear();
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
switch ((ComponentMessageType) message.MessageParameters[0])
{
case ComponentMessageType.SetVisible:
visible = (bool) message.MessageParameters[1];
break;
case ComponentMessageType.SetSpriteByKey:
SetSpriteByKey((string) message.MessageParameters[1]);
break;
case ComponentMessageType.SetDrawDepth:
SetDrawDepth((DrawDepth) message.MessageParameters[1]);
break;
}
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.CheckSpriteClick:
reply = new ComponentReplyMessage(ComponentMessageType.SpriteWasClicked,
WasClicked((PointF) list[0]), DrawDepth);
break;
case ComponentMessageType.GetAABB:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentAABB, AABB);
break;
case ComponentMessageType.GetSprite:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentSprite, GetBaseSprite());
break;
case ComponentMessageType.SetSpriteByKey:
SetSpriteByKey((string) list[0]);
break;
case ComponentMessageType.SetDrawDepth:
SetDrawDepth((DrawDepth) list[0]);
break;
case ComponentMessageType.SlaveAttach:
SetMaster(Owner.EntityManager.GetEntity((int) list[0]));
break;
case ComponentMessageType.ItemUnEquipped:
case ComponentMessageType.Dropped:
UnsetMaster();
break;
}
return reply;
}
protected virtual Sprite GetBaseSprite()
{
return currentBaseSprite;
}
protected void SetDrawDepth(DrawDepth p)
{
DrawDepth = p;
}
private Sprite GetActiveDirectionalSprite()
{
if (currentBaseSprite == null) return null;
Sprite sprite = currentBaseSprite;
string dirName =
(currentBaseSprite.Name + "_" +
Owner.GetComponent<DirectionComponent>(ComponentFamily.Direction).Direction.ToString()).
ToLowerInvariant();
if (dirSprites.ContainsKey(dirName))
sprite = dirSprites[dirName];
return sprite;
}
protected virtual bool WasClicked(PointF worldPos)
{
if (currentBaseSprite == null || !visible) return false;
Sprite spriteToCheck = GetActiveDirectionalSprite();
var AABB =
new RectangleF(
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X -
(spriteToCheck.Width/2),
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y -
(spriteToCheck.Height/2), spriteToCheck.Width, spriteToCheck.Height);
if (!AABB.Contains(worldPos)) return false;
var spritePosition = new Point((int) (worldPos.X - AABB.X + spriteToCheck.ImageOffset.X),
(int) (worldPos.Y - AABB.Y + spriteToCheck.ImageOffset.Y));
Image.ImageLockBox imgData = spriteToCheck.Image.GetImageData();
imgData.Lock(false);
Color pixColour = Color.FromArgb((int) (imgData[spritePosition.X, spritePosition.Y]));
imgData.Dispose();
imgData.Unlock();
if (pixColour.A == 0) return false;
return true;
}
public bool SpriteExists(string key)
{
if (sprites.ContainsKey(key))
return true;
return false;
}
public override void SetParameter(ComponentParameter parameter)
{
base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "drawdepth":
SetDrawDepth((DrawDepth) Enum.Parse(typeof (DrawDepth), parameter.GetValue<string>(), true));
break;
case "addsprite":
AddSprite(parameter.GetValue<string>());
break;
}
}
public virtual void Render(Vector2D topLeft, Vector2D bottomRight)
{
//Render slaves beneath
IEnumerable<SpriteComponent> renderablesBeneath = from SpriteComponent c in slaves
//FIXTHIS
orderby c.DrawDepth ascending
where c.DrawDepth < DrawDepth
select c;
foreach (SpriteComponent component in renderablesBeneath.ToList())
{
component.Render(topLeft, bottomRight);
}
//Render this sprite
if (!visible) return;
if (currentBaseSprite == null) return;
Sprite spriteToRender = GetActiveDirectionalSprite();
Vector2D renderPos =
ClientWindowData.WorldToScreen(
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
SetSpriteCenter(spriteToRender, renderPos);
if (Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X + spriteToRender.AABB.Right <
topLeft.X
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X > bottomRight.X
||
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y +
spriteToRender.AABB.Bottom < topLeft.Y
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y > bottomRight.Y)
return;
spriteToRender.HorizontalFlip = flip;
spriteToRender.Draw();
spriteToRender.HorizontalFlip = false;
//Render slaves above
IEnumerable<SpriteComponent> renderablesAbove = from SpriteComponent c in slaves
//FIXTHIS
orderby c.DrawDepth ascending
where c.DrawDepth >= DrawDepth
select c;
foreach (SpriteComponent component in renderablesAbove.ToList())
{
component.Render(topLeft, bottomRight);
}
//Draw AABB
var aabb = AABB;
//Gorgon.CurrentRenderTarget.Rectangle(renderPos.X - aabb.Width / 2, renderPos.Y - aabb.Height / 2, aabb.Width, aabb.Height, Color.Lime);
}
public void SetSpriteCenter(string sprite, Vector2D center)
{
SetSpriteCenter(sprites[sprite], center);
}
public void SetSpriteCenter(Sprite sprite, Vector2D center)
{
sprite.SetPosition(center.X - (GetActiveDirectionalSprite().AABB.Width/2),
center.Y - (GetActiveDirectionalSprite().AABB.Height/2));
}
public bool IsSlaved()
{
return master != null;
}
public void SetMaster(Entity m)
{
if (!m.HasComponent(ComponentFamily.Renderable))
return;
var mastercompo = m.GetComponent<SpriteComponent>(ComponentFamily.Renderable);
//If there's no sprite component, then FUCK IT
if (mastercompo == null)
return;
mastercompo.AddSlave(this);
master = mastercompo;
}
public void UnsetMaster()
{
if (master == null)
return;
master.RemoveSlave(this);
master = null;
}
public void AddSlave(IRenderableComponent slavecompo)
{
slaves.Add(slavecompo);
}
public void RemoveSlave(IRenderableComponent slavecompo)
{
if (slaves.Contains(slavecompo))
slaves.Remove(slavecompo);
}
public override void HandleComponentState(dynamic state)
{
DrawDepth = state.DrawDepth;
if (state.SpriteKey != null && sprites.ContainsKey(state.SpriteKey) &&
currentBaseSprite != sprites[state.SpriteKey])
{
SetSpriteByKey(state.SpriteKey);
}
visible = state.Visible;
}
}
using GorgonLibrary;
using GorgonLibrary.Graphics;
using Lidgren.Network;
using SS14.Client.ClientWindow;
using SS14.Client.Interfaces.GOC;
using SS14.Client.Interfaces.Resource;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Renderable;
using SS14.Shared.IoC;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Image = GorgonLibrary.Graphics.Image;
namespace SS14.Client.GameObjects
{
public class SpriteComponent : Component, IRenderableComponent, ISpriteComponent
{
protected Sprite currentBaseSprite;
protected Dictionary<string, Sprite> dirSprites;
protected bool flip;
protected IRenderableComponent master;
protected List<IRenderableComponent> slaves;
protected Dictionary<string, Sprite> sprites;
protected bool visible = true;
public DrawDepth DrawDepth { get; set; }
public SpriteComponent()
{
Family = ComponentFamily.Renderable;
sprites = new Dictionary<string, Sprite>();
dirSprites = new Dictionary<string, Sprite>();
slaves = new List<IRenderableComponent>();
}
public override Type StateType
{
get { return typeof (SpriteComponentState); }
}
public float Bottom
{
get
{
return Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y +
(GetActiveDirectionalSprite().AABB.Height/2);
}
}
#region ISpriteComponent Members
public RectangleF AverageAABB
{
get { return AABB; }
}
public RectangleF AABB
{
get
{
return new RectangleF(0, 0, GetActiveDirectionalSprite().AABB.Width,
GetActiveDirectionalSprite().AABB.Height);
}
}
public Sprite GetCurrentSprite()
{
return GetActiveDirectionalSprite();
}
public Sprite GetSprite(string spriteKey)
{
if (sprites.ContainsKey(spriteKey))
return sprites[spriteKey];
else
return null;
}
public List<Sprite> GetAllSprites()
{
return sprites.Values.ToList();
}
public void SetSpriteByKey(string spriteKey)
{
if (sprites.ContainsKey(spriteKey))
{
currentBaseSprite = sprites[spriteKey];
if (Owner != null)
Owner.SendMessage(this, ComponentMessageType.SpriteChanged);
}
else
throw new Exception("Whoops. That sprite isn't in the dictionary.");
}
public void AddSprite(string spriteKey)
{
if (sprites.ContainsKey(spriteKey))
throw new Exception("That sprite is already added.");
if (IoCManager.Resolve<IResourceManager>().SpriteExists(spriteKey))
AddSprite(spriteKey, IoCManager.Resolve<IResourceManager>().GetSprite(spriteKey));
//If there's only one sprite, and the current sprite is explicitly not set, then lets go ahead and set our sprite.
if (sprites.Count == 1)
SetSpriteByKey(sprites.Keys.First());
BuildDirectionalSprites();
}
public void AddSprite(string key, Sprite spritetoadd)
{
if (spritetoadd != null && key != "")
sprites.Add(key, spritetoadd);
BuildDirectionalSprites();
}
public bool HasSprite(string key)
{
return sprites.ContainsKey(key);
}
#endregion
private void BuildDirectionalSprites()
{
dirSprites.Clear();
var resMgr = IoCManager.Resolve<IResourceManager>();
foreach (var curr in sprites)
{
foreach (string dir in Enum.GetNames(typeof (Direction)))
{
string name = (curr.Key + "_" + dir).ToLowerInvariant();
if (resMgr.SpriteExists(name))
dirSprites.Add(name, resMgr.GetSprite(name));
}
}
}
public override void OnAdd(Entity owner)
{
base.OnAdd(owner);
//Send a spritechanged message so everything knows whassup.
Owner.SendMessage(this, ComponentMessageType.SpriteChanged);
}
public void ClearSprites()
{
sprites.Clear();
}
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
switch ((ComponentMessageType) message.MessageParameters[0])
{
case ComponentMessageType.SetVisible:
visible = (bool) message.MessageParameters[1];
break;
case ComponentMessageType.SetSpriteByKey:
SetSpriteByKey((string) message.MessageParameters[1]);
break;
case ComponentMessageType.SetDrawDepth:
SetDrawDepth((DrawDepth) message.MessageParameters[1]);
break;
}
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.CheckSpriteClick:
reply = new ComponentReplyMessage(ComponentMessageType.SpriteWasClicked,
WasClicked((PointF) list[0]), DrawDepth);
break;
case ComponentMessageType.GetAABB:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentAABB, AABB);
break;
case ComponentMessageType.GetSprite:
reply = new ComponentReplyMessage(ComponentMessageType.CurrentSprite, GetBaseSprite());
break;
case ComponentMessageType.SetSpriteByKey:
SetSpriteByKey((string) list[0]);
break;
case ComponentMessageType.SetDrawDepth:
SetDrawDepth((DrawDepth) list[0]);
break;
case ComponentMessageType.SlaveAttach:
SetMaster(Owner.EntityManager.GetEntity((int) list[0]));
break;
case ComponentMessageType.ItemUnEquipped:
case ComponentMessageType.Dropped:
UnsetMaster();
break;
}
return reply;
}
protected virtual Sprite GetBaseSprite()
{
return currentBaseSprite;
}
protected void SetDrawDepth(DrawDepth p)
{
DrawDepth = p;
}
private Sprite GetActiveDirectionalSprite()
{
if (currentBaseSprite == null) return null;
Sprite sprite = currentBaseSprite;
string dirName =
(currentBaseSprite.Name + "_" +
Owner.GetComponent<DirectionComponent>(ComponentFamily.Direction).Direction.ToString()).
ToLowerInvariant();
if (dirSprites.ContainsKey(dirName))
sprite = dirSprites[dirName];
return sprite;
}
protected virtual bool WasClicked(PointF worldPos)
{
if (currentBaseSprite == null || !visible) return false;
Sprite spriteToCheck = GetActiveDirectionalSprite();
var AABB =
new RectangleF(
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X -
(spriteToCheck.Width/2),
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y -
(spriteToCheck.Height/2), spriteToCheck.Width, spriteToCheck.Height);
if (!AABB.Contains(worldPos)) return false;
var spritePosition = new Point((int) (worldPos.X - AABB.X + spriteToCheck.ImageOffset.X),
(int) (worldPos.Y - AABB.Y + spriteToCheck.ImageOffset.Y));
Image.ImageLockBox imgData = spriteToCheck.Image.GetImageData();
imgData.Lock(false);
Color pixColour = Color.FromArgb((int) (imgData[spritePosition.X, spritePosition.Y]));
imgData.Dispose();
imgData.Unlock();
if (pixColour.A == 0) return false;
return true;
}
public bool SpriteExists(string key)
{
if (sprites.ContainsKey(key))
return true;
return false;
}
public override void SetParameter(ComponentParameter parameter)
{
base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "drawdepth":
SetDrawDepth((DrawDepth) Enum.Parse(typeof (DrawDepth), parameter.GetValue<string>(), true));
break;
case "addsprite":
AddSprite(parameter.GetValue<string>());
break;
}
}
public virtual void Render(Vector2D topLeft, Vector2D bottomRight)
{
//Render slaves beneath
IEnumerable<SpriteComponent> renderablesBeneath = from SpriteComponent c in slaves
//FIXTHIS
orderby c.DrawDepth ascending
where c.DrawDepth < DrawDepth
select c;
foreach (SpriteComponent component in renderablesBeneath.ToList())
{
component.Render(topLeft, bottomRight);
}
//Render this sprite
if (!visible) return;
if (currentBaseSprite == null) return;
Sprite spriteToRender = GetActiveDirectionalSprite();
Vector2D renderPos =
ClientWindowData.WorldToScreen(
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
SetSpriteCenter(spriteToRender, renderPos);
if (Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X + spriteToRender.AABB.Right <
topLeft.X
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X > bottomRight.X
||
Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y +
spriteToRender.AABB.Bottom < topLeft.Y
|| Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y > bottomRight.Y)
return;
spriteToRender.HorizontalFlip = flip;
spriteToRender.Draw();
spriteToRender.HorizontalFlip = false;
//Render slaves above
IEnumerable<SpriteComponent> renderablesAbove = from SpriteComponent c in slaves
//FIXTHIS
orderby c.DrawDepth ascending
where c.DrawDepth >= DrawDepth
select c;
foreach (SpriteComponent component in renderablesAbove.ToList())
{
component.Render(topLeft, bottomRight);
}
//Draw AABB
var aabb = AABB;
//Gorgon.CurrentRenderTarget.Rectangle(renderPos.X - aabb.Width / 2, renderPos.Y - aabb.Height / 2, aabb.Width, aabb.Height, Color.Lime);
}
public void SetSpriteCenter(string sprite, Vector2D center)
{
SetSpriteCenter(sprites[sprite], center);
}
public void SetSpriteCenter(Sprite sprite, Vector2D center)
{
sprite.SetPosition(center.X - (GetActiveDirectionalSprite().AABB.Width/2),
center.Y - (GetActiveDirectionalSprite().AABB.Height/2));
}
public bool IsSlaved()
{
return master != null;
}
public void SetMaster(Entity m)
{
if (!m.HasComponent(ComponentFamily.Renderable))
return;
var mastercompo = m.GetComponent<SpriteComponent>(ComponentFamily.Renderable);
//If there's no sprite component, then FUCK IT
if (mastercompo == null)
return;
mastercompo.AddSlave(this);
master = mastercompo;
}
public void UnsetMaster()
{
if (master == null)
return;
master.RemoveSlave(this);
master = null;
}
public void AddSlave(IRenderableComponent slavecompo)
{
slaves.Add(slavecompo);
}
public void RemoveSlave(IRenderableComponent slavecompo)
{
if (slaves.Contains(slavecompo))
slaves.Remove(slavecompo);
}
public override void HandleComponentState(dynamic state)
{
DrawDepth = state.DrawDepth;
if (state.SpriteKey != null && sprites.ContainsKey(state.SpriteKey) &&
currentBaseSprite != sprites[state.SpriteKey])
{
SetSpriteByKey(state.SpriteKey);
}
visible = state.Visible;
}
}
}

View File

@@ -1,17 +1,15 @@
using System;
using GorgonLibrary;
using GorgonLibrary.Graphics;
using SS14.Client.ClientWindow;
using SS14.Client.Interfaces.Resource;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Renderable;
using SS14.Shared.IoC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClientInterfaces.Resource;
using ClientWindow;
using GorgonLibrary;
using GorgonLibrary.Graphics;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Renderable;
namespace CGO
namespace SS14.Client.GameObjects
{
public class WearableAnimatedSpriteComponent : AnimatedSpriteComponent
{

View File

@@ -1,184 +1,184 @@
using System;
using System.Drawing;
using GorgonLibrary.Graphics;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Renderable;
namespace CGO
{
public class WearableSpriteComponent : SpriteComponent
{
private string _basename = "";
private bool worn;
private DrawDepth wornDrawDepth = DrawDepth.MobOverClothingLayer;
public WearableSpriteComponent()
{
DrawDepth = DrawDepth.FloorObjects; //Floor drawdepth
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.MoveDirection:
switch ((Direction) list[0])
{
case Direction.North:
if (worn)
{
SetSpriteByKey(_basename + "_back");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
case Direction.South:
if (worn)
{
SetSpriteByKey(_basename + "_front");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
case Direction.East:
if (worn)
{
SetSpriteByKey(_basename + "_side");
flip = true;
}
else
SetSpriteByKey(_basename);
break;
case Direction.West:
if (worn)
{
SetSpriteByKey(_basename + "_side");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
case Direction.NorthEast:
if (worn)
{
SetSpriteByKey(_basename + "_back");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
case Direction.NorthWest:
if (worn)
{
SetSpriteByKey(_basename + "_back");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
case Direction.SouthEast:
if (worn)
{
SetSpriteByKey(_basename + "_front");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
case Direction.SouthWest:
if (worn)
{
SetSpriteByKey(_basename + "_front");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
}
DrawDepth = wornDrawDepth;
break;
case ComponentMessageType.Incapacitated:
case ComponentMessageType.WearerIsDead:
SetSpriteByKey(_basename + "_incap");
flip = false;
break; //TODO do stuff here, incap and dead.
case ComponentMessageType.ItemEquipped:
worn = true;
DrawDepth = wornDrawDepth;
break;
case ComponentMessageType.ItemUnEquipped:
worn = false;
break;
case ComponentMessageType.SetWornDrawDepth:
wornDrawDepth = (DrawDepth) list[0];
break;
}
return reply;
}
/// <summary>
/// Set parameters :)
/// </summary>
/// <param name="parameter"></param>
public override void SetParameter(ComponentParameter parameter)
{
//base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "drawdepth":
SetDrawDepth((DrawDepth) Enum.Parse(typeof (DrawDepth), parameter.GetValue<string>(), true));
break;
case "basename":
_basename = parameter.GetValue<string>();
LoadSprites();
break;
}
}
protected override Sprite GetBaseSprite()
{
return sprites[_basename];
}
protected override bool WasClicked(PointF worldPos)
{
return base.WasClicked(worldPos) && !worn;
}
/// <summary>
/// Load the mob sprites given the base name of the sprites.
/// </summary>
public void LoadSprites()
{
AddSprite(_basename);
AddSprite(_basename + "_front");
AddSprite(_basename + "_back");
AddSprite(_basename + "_side");
AddSprite(_basename + "_incap");
SetSpriteByKey(_basename);
}
public override void HandleComponentState(dynamic state)
{
base.HandleComponentState((SpriteComponentState) state);
if (state.BaseName != null && _basename != state.BaseName)
{
_basename = state.BaseName;
LoadSprites();
}
}
}
using GorgonLibrary.Graphics;
using SS14.Shared;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Renderable;
using System;
using System.Drawing;
namespace SS14.Client.GameObjects
{
public class WearableSpriteComponent : SpriteComponent
{
private string _basename = "";
private bool worn;
private DrawDepth wornDrawDepth = DrawDepth.MobOverClothingLayer;
public WearableSpriteComponent()
{
DrawDepth = DrawDepth.FloorObjects; //Floor drawdepth
}
public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
params object[] list)
{
ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);
if (sender == this) //Don't listen to our own messages!
return ComponentReplyMessage.Empty;
switch (type)
{
case ComponentMessageType.MoveDirection:
switch ((Direction) list[0])
{
case Direction.North:
if (worn)
{
SetSpriteByKey(_basename + "_back");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
case Direction.South:
if (worn)
{
SetSpriteByKey(_basename + "_front");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
case Direction.East:
if (worn)
{
SetSpriteByKey(_basename + "_side");
flip = true;
}
else
SetSpriteByKey(_basename);
break;
case Direction.West:
if (worn)
{
SetSpriteByKey(_basename + "_side");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
case Direction.NorthEast:
if (worn)
{
SetSpriteByKey(_basename + "_back");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
case Direction.NorthWest:
if (worn)
{
SetSpriteByKey(_basename + "_back");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
case Direction.SouthEast:
if (worn)
{
SetSpriteByKey(_basename + "_front");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
case Direction.SouthWest:
if (worn)
{
SetSpriteByKey(_basename + "_front");
flip = false;
}
else
SetSpriteByKey(_basename);
break;
}
DrawDepth = wornDrawDepth;
break;
case ComponentMessageType.Incapacitated:
case ComponentMessageType.WearerIsDead:
SetSpriteByKey(_basename + "_incap");
flip = false;
break; //TODO do stuff here, incap and dead.
case ComponentMessageType.ItemEquipped:
worn = true;
DrawDepth = wornDrawDepth;
break;
case ComponentMessageType.ItemUnEquipped:
worn = false;
break;
case ComponentMessageType.SetWornDrawDepth:
wornDrawDepth = (DrawDepth) list[0];
break;
}
return reply;
}
/// <summary>
/// Set parameters :)
/// </summary>
/// <param name="parameter"></param>
public override void SetParameter(ComponentParameter parameter)
{
//base.SetParameter(parameter);
switch (parameter.MemberName)
{
case "drawdepth":
SetDrawDepth((DrawDepth) Enum.Parse(typeof (DrawDepth), parameter.GetValue<string>(), true));
break;
case "basename":
_basename = parameter.GetValue<string>();
LoadSprites();
break;
}
}
protected override Sprite GetBaseSprite()
{
return sprites[_basename];
}
protected override bool WasClicked(PointF worldPos)
{
return base.WasClicked(worldPos) && !worn;
}
/// <summary>
/// Load the mob sprites given the base name of the sprites.
/// </summary>
public void LoadSprites()
{
AddSprite(_basename);
AddSprite(_basename + "_front");
AddSprite(_basename + "_back");
AddSprite(_basename + "_side");
AddSprite(_basename + "_incap");
SetSpriteByKey(_basename);
}
public override void HandleComponentState(dynamic state)
{
base.HandleComponentState((SpriteComponentState) state);
if (state.BaseName != null && _basename != state.BaseName)
{
_basename = state.BaseName;
LoadSprites();
}
}
}
}

View File

@@ -1,61 +1,61 @@
using System;
using System.Collections.Generic;
using ClientInterfaces.GOC;
using GameObject;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO
{
public class SVarsComponent : Component, ISVarsComponent
{
public SVarsComponent()
{
Family = ComponentFamily.SVars;
}
#region ISVarsComponent Members
public event EventHandler<GetSVarsEventArgs> GetSVarsCallback;
public void DoSetSVar(MarshalComponentParameter svar)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, ComponentMessageType.SetSVar,
svar.Serialize());
}
public void DoGetSVars()
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, ComponentMessageType.GetSVars);
}
#endregion
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
switch ((ComponentMessageType) message.MessageParameters[0])
{
case ComponentMessageType.GetSVars:
HandleGetSVars(message);
break;
}
}
public void HandleGetSVars(IncomingEntityComponentMessage message)
{
//If nothing's listening, then why bother with this shit?
if (GetSVarsCallback == null)
return;
var count = (int) message.MessageParameters[1];
var svars = new List<MarshalComponentParameter>();
for (int i = 2; i < count + 2; i++)
{
svars.Add(MarshalComponentParameter.Deserialize((byte[]) message.MessageParameters[i]));
}
GetSVarsCallback(this, new GetSVarsEventArgs(svars));
GetSVarsCallback = null;
}
}
using Lidgren.Network;
using SS14.Client.Interfaces.GOC;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using System;
using System.Collections.Generic;
namespace SS14.Client.GameObjects
{
public class SVarsComponent : Component, ISVarsComponent
{
public SVarsComponent()
{
Family = ComponentFamily.SVars;
}
#region ISVarsComponent Members
public event EventHandler<GetSVarsEventArgs> GetSVarsCallback;
public void DoSetSVar(MarshalComponentParameter svar)
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, ComponentMessageType.SetSVar,
svar.Serialize());
}
public void DoGetSVars()
{
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, ComponentMessageType.GetSVars);
}
#endregion
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
{
switch ((ComponentMessageType) message.MessageParameters[0])
{
case ComponentMessageType.GetSVars:
HandleGetSVars(message);
break;
}
}
public void HandleGetSVars(IncomingEntityComponentMessage message)
{
//If nothing's listening, then why bother with this shit?
if (GetSVarsCallback == null)
return;
var count = (int) message.MessageParameters[1];
var svars = new List<MarshalComponentParameter>();
for (int i = 2; i < count + 2; i++)
{
svars.Add(MarshalComponentParameter.Deserialize((byte[]) message.MessageParameters[i]));
}
GetSVarsCallback(this, new GetSVarsEventArgs(svars));
GetSVarsCallback = null;
}
}
}

View File

@@ -1,120 +1,119 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GameObject;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.StatusEffect;
using SS13_Shared.GO.StatusEffect;
namespace CGO
{
public class StatusEffectComp : Component
{
#region Delegates
public delegate void StatusEffectsChangedHandler(StatusEffectComp sender);
#endregion
public List<StatusEffect> Effects = new List<StatusEffect>();
public StatusEffectComp()
{
Family = ComponentFamily.StatusEffects;
}
public override Type StateType
{
get { return typeof (StatusEffectComponentState); }
}
public event StatusEffectsChangedHandler Changed;
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (StatusEffect effect in Effects.ToArray())
effect.OnUpdate();
}
private void AddEffect(string typeName, uint uid, bool doesExpire, DateTime expiresAt,
StatusEffectFamily _family)
//Don't manually use this clientside. The server adds and removes what is needed.
{
Type t = Type.GetType("CGO." + typeName);
if (t == null || !t.IsSubclassOf(typeof (StatusEffect))) return;
var newEffect = (StatusEffect) Activator.CreateInstance(t, new object[] {uid, Owner});
newEffect.doesExpire = doesExpire;
newEffect.expiresAt = expiresAt;
newEffect.family = _family;
Effects.Add(newEffect);
newEffect.OnAdd();
if (Changed != null) Changed(this);
}
private void RemoveEffect(uint uid)
//Don't manually use this clientside. The server adds and removes what is needed.
{
StatusEffect toRemove = Effects.FirstOrDefault(x => x.uid == uid);
if (toRemove != null)
{
toRemove.OnRemove();
Effects.Remove(toRemove);
if (Changed != null) Changed(this);
}
}
public bool HasEffect(string typeName)
{
foreach (StatusEffect effect in Effects)
if (effect.GetType().Name.Equals(typeName, StringComparison.InvariantCultureIgnoreCase))
return true;
return false;
}
private StatusEffect GetEffect(uint uid)
{
return Effects.FirstOrDefault(e => e.uid == uid);
}
public bool HasFamily(StatusEffectFamily family)
{
foreach (StatusEffect effect in Effects)
if (effect.family == family)
return true;
return false;
}
public override void HandleComponentState(dynamic state)
{
List<uint> existing = Effects.Select(uid => uid.uid).ToList();
foreach (StatusEffectState effectState in state.EffectStates)
{
if (existing.Contains(effectState.Uid))
{
// Effect exists, update it
StatusEffect existingEffect = GetEffect(effectState.Uid);
existingEffect.UpdateEffectState(effectState);
}
else
{
//Effect doesn't exist, create it
AddEffect(effectState.TypeName, effectState.Uid, effectState.DoesExpire, effectState.ExpiresAt,
effectState.Family);
}
existing.Remove(effectState.Uid);
// Whittle down the list so we can remove the effects that aren't contained in the state.
}
foreach (uint u in existing)
{
RemoveEffect(u);
//The server did not send anything else, so we can remove whatever is left. No client-side only effects.
}
}
}
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.StatusEffect;
using SS14.Shared.GO.StatusEffect;
using System;
using System.Collections.Generic;
using System.Linq;
namespace SS14.Client.GameObjects
{
public class StatusEffectComp : Component
{
#region Delegates
public delegate void StatusEffectsChangedHandler(StatusEffectComp sender);
#endregion
public List<StatusEffect> Effects = new List<StatusEffect>();
public StatusEffectComp()
{
Family = ComponentFamily.StatusEffects;
}
public override Type StateType
{
get { return typeof (StatusEffectComponentState); }
}
public event StatusEffectsChangedHandler Changed;
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (StatusEffect effect in Effects.ToArray())
effect.OnUpdate();
}
private void AddEffect(string typeName, uint uid, bool doesExpire, DateTime expiresAt,
StatusEffectFamily _family)
//Don't manually use this clientside. The server adds and removes what is needed.
{
Type t = Type.GetType("CGO." + typeName);
if (t == null || !t.IsSubclassOf(typeof (StatusEffect))) return;
var newEffect = (StatusEffect) Activator.CreateInstance(t, new object[] {uid, Owner});
newEffect.doesExpire = doesExpire;
newEffect.expiresAt = expiresAt;
newEffect.family = _family;
Effects.Add(newEffect);
newEffect.OnAdd();
if (Changed != null) Changed(this);
}
private void RemoveEffect(uint uid)
//Don't manually use this clientside. The server adds and removes what is needed.
{
StatusEffect toRemove = Effects.FirstOrDefault(x => x.uid == uid);
if (toRemove != null)
{
toRemove.OnRemove();
Effects.Remove(toRemove);
if (Changed != null) Changed(this);
}
}
public bool HasEffect(string typeName)
{
foreach (StatusEffect effect in Effects)
if (effect.GetType().Name.Equals(typeName, StringComparison.InvariantCultureIgnoreCase))
return true;
return false;
}
private StatusEffect GetEffect(uint uid)
{
return Effects.FirstOrDefault(e => e.uid == uid);
}
public bool HasFamily(StatusEffectFamily family)
{
foreach (StatusEffect effect in Effects)
if (effect.family == family)
return true;
return false;
}
public override void HandleComponentState(dynamic state)
{
List<uint> existing = Effects.Select(uid => uid.uid).ToList();
foreach (StatusEffectState effectState in state.EffectStates)
{
if (existing.Contains(effectState.Uid))
{
// Effect exists, update it
StatusEffect existingEffect = GetEffect(effectState.Uid);
existingEffect.UpdateEffectState(effectState);
}
else
{
//Effect doesn't exist, create it
AddEffect(effectState.TypeName, effectState.Uid, effectState.DoesExpire, effectState.ExpiresAt,
effectState.Family);
}
existing.Remove(effectState.Uid);
// Whittle down the list so we can remove the effects that aren't contained in the state.
}
foreach (uint u in existing)
{
RemoveEffect(u);
//The server did not send anything else, so we can remove whatever is left. No client-side only effects.
}
}
}
}

View File

@@ -1,106 +1,106 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ClientInterfaces.Configuration;
using GameObject;
using GorgonLibrary;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Transform;
namespace CGO
{
public class TransformComponent : Component
{
private Vector2D _position = Vector2D.Zero;
private List<TransformComponentState> states = new List<TransformComponentState>();
private TransformComponentState lastState;
public TransformComponentState lerpStateFrom;
public TransformComponentState lerpStateTo;
public TransformComponent()
{
Family = ComponentFamily.Transform;
}
public Vector2D Position
{
get { return _position; }
set
{
Vector2D oldPosition = _position;
_position = value;
if (OnMove != null) OnMove(this, new VectorEventArgs(Vector2TypeConverter.ToVector2(oldPosition), Vector2TypeConverter.ToVector2(_position)));
}
}
public override Type StateType
{
get { return typeof (TransformComponentState); }
}
public float X
{
get { return Position.X; }
set { Position = new Vector2D(value, Position.Y); }
}
public float Y
{
get { return Position.Y; }
set { Position = new Vector2D(Position.X, value); }
}
public event EventHandler<VectorEventArgs> OnMove;
public override void Shutdown()
{
Position = Vector2D.Zero;
}
public void TranslateTo(Vector2D toPosition)
{
Position = toPosition;
}
public void TranslateByOffset(Vector2D offset)
{
Position = Position + offset;
}
public override void HandleComponentState(dynamic state)
{
SetNewState(state);
}
private void SetNewState(TransformComponentState state)
{
lastState = state;
states.Add(state);
var interp = IoCManager.Resolve<IConfigurationManager>().GetInterpolation();
//Remove all states older than the one just before the interp time.
lerpStateFrom = states.Where(s => s.ReceivedTime <= state.ReceivedTime - interp).OrderByDescending(s => s.ReceivedTime).FirstOrDefault();
if (lerpStateFrom != null)
{
lerpStateTo =
states.Where(s => s.ReceivedTime > lerpStateFrom.ReceivedTime).OrderByDescending(s => s.ReceivedTime).
LastOrDefault();
if (lerpStateTo == null)
lerpStateTo = lerpStateFrom;
states.RemoveAll(s => s.ReceivedTime < lerpStateFrom.ReceivedTime);
}
else
{
lerpStateFrom = state;
lerpStateTo = state;
}
if(lastState.ForceUpdate)
{
TranslateTo(new Vector2D(state.X, state.Y));
}
}
}
using GorgonLibrary;
using SS14.Client.Interfaces.Configuration;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Transform;
using SS14.Shared.IoC;
using System;
using System.Collections.Generic;
using System.Linq;
namespace SS14.Client.GameObjects
{
public class TransformComponent : Component
{
private Vector2D _position = Vector2D.Zero;
private List<TransformComponentState> states = new List<TransformComponentState>();
private TransformComponentState lastState;
public TransformComponentState lerpStateFrom;
public TransformComponentState lerpStateTo;
public TransformComponent()
{
Family = ComponentFamily.Transform;
}
public Vector2D Position
{
get { return _position; }
set
{
Vector2D oldPosition = _position;
_position = value;
if (OnMove != null) OnMove(this, new VectorEventArgs(Vector2TypeConverter.ToVector2(oldPosition), Vector2TypeConverter.ToVector2(_position)));
}
}
public override Type StateType
{
get { return typeof (TransformComponentState); }
}
public float X
{
get { return Position.X; }
set { Position = new Vector2D(value, Position.Y); }
}
public float Y
{
get { return Position.Y; }
set { Position = new Vector2D(Position.X, value); }
}
public event EventHandler<VectorEventArgs> OnMove;
public override void Shutdown()
{
Position = Vector2D.Zero;
}
public void TranslateTo(Vector2D toPosition)
{
Position = toPosition;
}
public void TranslateByOffset(Vector2D offset)
{
Position = Position + offset;
}
public override void HandleComponentState(dynamic state)
{
SetNewState(state);
}
private void SetNewState(TransformComponentState state)
{
lastState = state;
states.Add(state);
var interp = IoCManager.Resolve<IConfigurationManager>().GetInterpolation();
//Remove all states older than the one just before the interp time.
lerpStateFrom = states.Where(s => s.ReceivedTime <= state.ReceivedTime - interp).OrderByDescending(s => s.ReceivedTime).FirstOrDefault();
if (lerpStateFrom != null)
{
lerpStateTo =
states.Where(s => s.ReceivedTime > lerpStateFrom.ReceivedTime).OrderByDescending(s => s.ReceivedTime).
LastOrDefault();
if (lerpStateTo == null)
lerpStateTo = lerpStateFrom;
states.RemoveAll(s => s.ReceivedTime < lerpStateFrom.ReceivedTime);
}
else
{
lerpStateFrom = state;
lerpStateTo = state;
}
if(lastState.ForceUpdate)
{
TranslateTo(new Vector2D(state.X, state.Y));
}
}
}
}

View File

@@ -1,64 +1,64 @@
using System;
using GameObject;
using GorgonLibrary;
using SS13_Shared.GO;
using SS13_Shared.GO.Component.Velocity;
namespace CGO
{
public class VelocityComponent : Component
{
private VelocityComponentState _lastState;
private VelocityComponentState _previousState;
private Vector2D _velocity = Vector2D.Zero;
public VelocityComponent()
{
Family = ComponentFamily.Velocity;
Velocity = new Vector2D(0,0);
}
public Vector2D Velocity
{
get { return _velocity; }
set { _velocity = value; }
}
public override Type StateType
{
get { return typeof (VelocityComponentState); }
}
public float X
{
get { return Velocity.X; }
set { Velocity = new Vector2D(value, Velocity.Y); }
}
public float Y
{
get { return Velocity.Y; }
set { Velocity = new Vector2D(Velocity.X, value); }
}
public override void Shutdown()
{
Velocity = Vector2D.Zero;
}
public override void HandleComponentState(dynamic state)
{
if(Owner.GetComponent<PlayerInputMoverComponent>(ComponentFamily.Mover) == null)
SetNewState(state);
}
private void SetNewState(VelocityComponentState state)
{
if (_lastState != null)
_previousState = _lastState;
_lastState = state;
Velocity = new Vector2D(state.VelocityX, state.VelocityY);
}
}
using GorgonLibrary;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.Component.Velocity;
using System;
namespace SS14.Client.GameObjects
{
public class VelocityComponent : Component
{
private VelocityComponentState _lastState;
private VelocityComponentState _previousState;
private Vector2D _velocity = Vector2D.Zero;
public VelocityComponent()
{
Family = ComponentFamily.Velocity;
Velocity = new Vector2D(0,0);
}
public Vector2D Velocity
{
get { return _velocity; }
set { _velocity = value; }
}
public override Type StateType
{
get { return typeof (VelocityComponentState); }
}
public float X
{
get { return Velocity.X; }
set { Velocity = new Vector2D(value, Velocity.Y); }
}
public float Y
{
get { return Velocity.Y; }
set { Velocity = new Vector2D(Velocity.X, value); }
}
public override void Shutdown()
{
Velocity = Vector2D.Zero;
}
public override void HandleComponentState(dynamic state)
{
if(Owner.GetComponent<PlayerInputMoverComponent>(ComponentFamily.Mover) == null)
SetNewState(state);
}
private void SetNewState(VelocityComponentState state)
{
if (_lastState != null)
_previousState = _lastState;
_lastState = state;
Velocity = new Vector2D(state.VelocityX, state.VelocityY);
}
}
}

View File

@@ -1,9 +1,9 @@
namespace CGO
{
public struct ContextMenuEntry
{
public string ComponentMessage;
public string EntryName;
public string IconName;
}
namespace SS14.Client.GameObjects
{
public struct ContextMenuEntry
{
public string ComponentMessage;
public string EntryName;
public string IconName;
}
}

View File

@@ -1,81 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GameObject;
using GorgonLibrary;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
using ClientInterfaces.MessageLogging;
using SS13.IoC;
using ClientInterfaces.Configuration;
namespace CGO
{
/// <summary>
/// Base entity class. Acts as a container for components, and a place to store location data.
/// Should not contain any game logic whatsoever other than entity movement functions and
/// component management functions.
/// </summary>
public class Entity : GameObject.Entity
{
#region Variables
private bool _messageProfiling;
#endregion
#region Constructor/Destructor
/// <summary>
/// Constructor for realz. This one should be used eventually instead of the naked one.
/// </summary>
/// <param name="entityNetworkManager"></param>
public Entity(EntityManager entityManager)
:base(entityManager)
{
Initialize();
var cfg = IoCManager.Resolve<IConfigurationManager>();
_messageProfiling = cfg.GetMessageLogging();
}
#endregion
#region Component Manipulation
/// <summary>
/// Logs a component message to the messaging profiler
/// </summary>
/// <param name="sender"></param>
/// <param name="type"></param>
/// <param name="args"></param>
private void LogComponentMessage(object sender, ComponentMessageType type, params object[] args)
{
if (!_messageProfiling)
return;
var senderfamily = ComponentFamily.Generic;
var uid = 0;
var sendertype = "";
//if (sender.GetType().IsAssignableFrom(typeof(Component)))
if (typeof(Component).IsAssignableFrom(sender.GetType()))
{
var realsender = (Component)sender;
senderfamily = realsender.Family;
uid = realsender.Owner.Uid;
sendertype = realsender.GetType().ToString();
}
else
{
sendertype = sender.GetType().ToString();
}
//Log the message
IMessageLogger logger = IoCManager.Resolve<IMessageLogger>();
logger.LogComponentMessage(uid, senderfamily, sendertype, type);
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using GameObject;
using GorgonLibrary;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
using ClientInterfaces.MessageLogging;
using SS13.IoC;
using ClientInterfaces.Configuration;
namespace CGO
{
/// <summary>
/// Base entity class. Acts as a container for components, and a place to store location data.
/// Should not contain any game logic whatsoever other than entity movement functions and
/// component management functions.
/// </summary>
public class Entity : GameObject.Entity
{
#region Variables
private bool _messageProfiling;
#endregion
#region Constructor/Destructor
/// <summary>
/// Constructor for realz. This one should be used eventually instead of the naked one.
/// </summary>
/// <param name="entityNetworkManager"></param>
public Entity(EntityManager entityManager)
:base(entityManager)
{
Initialize();
var cfg = IoCManager.Resolve<IConfigurationManager>();
_messageProfiling = cfg.GetMessageLogging();
}
#endregion
#region Component Manipulation
/// <summary>
/// Logs a component message to the messaging profiler
/// </summary>
/// <param name="sender"></param>
/// <param name="type"></param>
/// <param name="args"></param>
private void LogComponentMessage(object sender, ComponentMessageType type, params object[] args)
{
if (!_messageProfiling)
return;
var senderfamily = ComponentFamily.Generic;
var uid = 0;
var sendertype = "";
//if (sender.GetType().IsAssignableFrom(typeof(Component)))
if (typeof(Component).IsAssignableFrom(sender.GetType()))
{
var realsender = (Component)sender;
senderfamily = realsender.Family;
uid = realsender.Owner.Uid;
sendertype = realsender.GetType().ToString();
}
else
{
sendertype = sender.GetType().ToString();
}
//Log the message
IMessageLogger logger = IoCManager.Resolve<IMessageLogger>();
logger.LogComponentMessage(uid, senderfamily, sendertype, type);
}
#endregion
}
}

View File

@@ -1,33 +1,33 @@
using System.Collections.Generic;
using System.Linq;
using ClientInterfaces.Network;
using GameObject;
using GorgonLibrary;
using SS13_Shared.GO;
namespace CGO
{
/// <summary>
/// Manager for entities -- controls things like template loading and instantiation
/// </summary>
public class EntityManager : GameObject.EntityManager
{
public EntityManager(INetworkManager networkManager)
: base(EngineType.Client, new EntityNetworkManager(networkManager))
{
}
public Entity[] GetEntitiesInRange(Vector2D position, float Range)
{
IEnumerable<Entity> entities = from e in _entities.Values
where
(position -
e.GetComponent<TransformComponent>(ComponentFamily.Transform).Position).
Length < Range
select e;
return entities.ToArray();
}
}
using GorgonLibrary;
using SS14.Client.Interfaces.Network;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using System.Collections.Generic;
using System.Linq;
namespace SS14.Client.GameObjects
{
/// <summary>
/// Manager for entities -- controls things like template loading and instantiation
/// </summary>
public class EntityManager : SS14.Shared.GameObjects.EntityManager
{
public EntityManager(INetworkManager networkManager)
: base(EngineType.Client, new EntityNetworkManager(networkManager))
{
}
public Entity[] GetEntitiesInRange(Vector2D position, float Range)
{
IEnumerable<Entity> entities = from e in _entities.Values
where
(position -
e.GetComponent<TransformComponent>(ComponentFamily.Transform).Position).
Length < Range
select e;
return entities.ToArray();
}
}
}

View File

@@ -1,334 +1,333 @@
using System;
using System.Collections.Generic;
using System.IO;
using ClientInterfaces.Configuration;
using ClientInterfaces.MessageLogging;
using ClientInterfaces.Network;
using GameObject;
using Lidgren.Network;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using NetSerializer;
using SS13_Shared.Serialization;
namespace CGO
{
public class EntityNetworkManager : IEntityNetworkManager
{
private readonly bool _messageProfiling;
private readonly INetworkManager _networkManager;
public EntityNetworkManager(INetworkManager networkManager)
{
_networkManager = networkManager;
_messageProfiling = IoCManager.Resolve<IConfigurationManager>().GetMessageLogging();
}
#region IEntityNetworkManager Members
public NetOutgoingMessage CreateEntityMessage()
{
NetOutgoingMessage message = _networkManager.CreateMessage();
message.Write((byte) NetMessage.EntityMessage);
return message;
}
#endregion
#region Sending
/// <summary>
/// Sends a message to the relevant system(s) serverside.
/// </summary>
public void SendSystemNetworkMessage(EntitySystemMessage message,
NetDeliveryMethod method = NetDeliveryMethod.ReliableUnordered)
{
NetOutgoingMessage newMsg = CreateEntityMessage();
newMsg.Write((byte)EntityMessage.SystemMessage);
var stream = new MemoryStream();
Serializer.Serialize(stream, message);
newMsg.Write((int)stream.Length);
newMsg.Write(stream.ToArray());
if (_messageProfiling)
{
//Log the message
}
//Send the message
_networkManager.SendMessage(newMsg, method);
}
public void SendDirectedComponentNetworkMessage(Entity sendingEntity, ComponentFamily family,
NetDeliveryMethod method, NetConnection recipient,
params object[] messageParams)
{
throw new NotImplementedException();
}
/// <summary>
/// Allows a component owned by this entity to send a message to a counterpart component on the
/// counterpart entities on all clients.
/// </summary>
/// <param name="sendingEntity">Entity sending the message (also entity to send to)</param>
/// <param name="family">Family of the component sending the message</param>
/// <param name="method">Net delivery method -- if null, defaults to NetDeliveryMethod.ReliableUnordered</param>
/// <param name="messageParams">Parameters of the message</param>
public void SendComponentNetworkMessage(Entity sendingEntity, ComponentFamily family,
NetDeliveryMethod method = NetDeliveryMethod.ReliableUnordered,
params object[] messageParams)
{
NetOutgoingMessage message = CreateEntityMessage();
message.Write((byte)EntityMessage.ComponentMessage);
message.Write(sendingEntity.Uid); //Write this entity's UID
message.Write((byte) family);
PackParams(message, messageParams);
if (_messageProfiling)
{
//Log the message
var logger = IoCManager.Resolve<IMessageLogger>();
logger.LogOutgoingComponentNetMessage(sendingEntity.Uid, family, messageParams);
}
//Send the message
_networkManager.SendMessage(message, method);
}
/// <summary>
/// Sends an arbitrary entity network message
/// </summary>
/// <param name="sendingEntity">The entity the message is going from(and to, on the other end)</param>
/// <param name="type">Message type</param>
/// <param name="list">List of parameter objects</param>
public void SendEntityNetworkMessage(Entity sendingEntity, EntityMessage type, params object[] list)
{
NetOutgoingMessage message = CreateEntityMessage();
message.Write((byte)type);
message.Write(sendingEntity.Uid); //Write this entity's UID
PackParams(message, list);
_networkManager.SendMessage(message, NetDeliveryMethod.ReliableUnordered);
}
private void PackParams(NetOutgoingMessage message, params object[] messageParams)
{
foreach (object messageParam in messageParams)
{
Type t = messageParam.GetType();
if (messageParam.GetType().IsSubclassOf(typeof (Enum)))
{
message.Write((byte) NetworkDataType.d_enum);
message.Write((int) messageParam); //Cast to int, because enums are stored as ints anyway.
}
else if (messageParam.GetType() == typeof (bool))
{
message.Write((byte) NetworkDataType.d_bool);
message.Write((bool) messageParam);
}
else if (messageParam.GetType() == typeof (byte))
{
message.Write((byte) NetworkDataType.d_byte);
message.Write((byte) messageParam);
}
else if (messageParam.GetType() == typeof (sbyte))
{
message.Write((byte) NetworkDataType.d_sbyte);
message.Write((sbyte) messageParam);
}
else if (messageParam.GetType() == typeof (ushort))
{
message.Write((byte) NetworkDataType.d_ushort);
message.Write((ushort) messageParam);
}
else if (messageParam.GetType() == typeof (short))
{
message.Write((byte) NetworkDataType.d_short);
message.Write((short) messageParam);
}
else if (messageParam.GetType() == typeof (int))
{
message.Write((byte) NetworkDataType.d_int);
message.Write((int) messageParam);
}
else if (messageParam.GetType() == typeof (uint))
{
message.Write((byte) NetworkDataType.d_uint);
message.Write((uint) messageParam);
}
else if (messageParam.GetType() == typeof (ulong))
{
message.Write((byte) NetworkDataType.d_ulong);
message.Write((ulong) messageParam);
}
else if (messageParam.GetType() == typeof (long))
{
message.Write((byte) NetworkDataType.d_long);
message.Write((long) messageParam);
}
else if (messageParam.GetType() == typeof (float))
{
message.Write((byte) NetworkDataType.d_float);
message.Write((float) messageParam);
}
else if (messageParam.GetType() == typeof (double))
{
message.Write((byte) NetworkDataType.d_double);
message.Write((double) messageParam);
}
else if (messageParam.GetType() == typeof (string))
{
message.Write((byte) NetworkDataType.d_string);
message.Write((string) messageParam);
}
else if (messageParam.GetType() == typeof (byte[]))
{
message.Write((byte) NetworkDataType.d_byteArray);
message.Write(((byte[]) messageParam).Length);
message.Write((byte[]) messageParam);
}
else
{
throw new NotImplementedException("Cannot write specified type.");
}
}
}
/// <summary>
/// Sends an SVar to the server to be set on the server-side entity.
/// </summary>
/// <param name="sendingEntity"></param>
/// <param name="svar"></param>
public void SendSVar(Entity sendingEntity, MarshalComponentParameter svar)
{
NetOutgoingMessage message = CreateEntityMessage();
message.Write((byte)EntityMessage.SetSVar);
message.Write(sendingEntity.Uid);
svar.Serialize(message);
_networkManager.SendMessage(message, NetDeliveryMethod.ReliableUnordered);
}
#endregion
#region Receiving
/// <summary>
/// Converts a raw NetIncomingMessage to an IncomingEntityMessage object
/// </summary>
/// <param name="message">raw network message</param>
/// <returns>An IncomingEntityMessage object</returns>
public IncomingEntityMessage HandleEntityNetworkMessage(NetIncomingMessage message)
{
var messageType = (EntityMessage) message.ReadByte();
int uid;
IncomingEntityMessage result = IncomingEntityMessage.Null;
switch (messageType)
{
case EntityMessage.ComponentMessage:
uid = message.ReadInt32();
IncomingEntityComponentMessage messageContent = HandleEntityComponentNetworkMessage(message);
result = new IncomingEntityMessage(uid, EntityMessage.ComponentMessage, messageContent,
message.SenderConnection);
if (_messageProfiling)
{
//Log the message
var logger = IoCManager.Resolve<IMessageLogger>();
logger.LogIncomingComponentNetMessage(result.Uid, result.MessageType,
messageContent.ComponentFamily,
messageContent.MessageParameters.ToArray());
}
break;
case EntityMessage.SystemMessage: //TODO: Not happy with this resolving the entmgr everytime a message comes in.
EntityManager eMgr = (EntityManager)IoCManager.Resolve<IEntityManager>();
eMgr.EntitySystemManager.HandleSystemMessage(new EntitySystemData(message.SenderConnection, message));
break;
case EntityMessage.PositionMessage:
uid = message.ReadInt32();
//TODO: Handle position messages!
break;
case EntityMessage.GetSVars:
uid = message.ReadInt32();
result = new IncomingEntityMessage(uid, EntityMessage.GetSVars, message, message.SenderConnection);
break;
}
return result;
}
/// <summary>
/// Handles an incoming entity component message
/// </summary>
/// <param name="message">Raw network message</param>
/// <returns>An IncomingEntityComponentMessage object</returns>
public IncomingEntityComponentMessage HandleEntityComponentNetworkMessage(NetIncomingMessage message)
{
var componentFamily = (ComponentFamily) message.ReadByte();
var messageParams = new List<object>();
while (message.Position < message.LengthBits)
{
switch ((NetworkDataType) message.ReadByte())
{
case NetworkDataType.d_enum:
messageParams.Add(message.ReadInt32());
break;
case NetworkDataType.d_bool:
messageParams.Add(message.ReadBoolean());
break;
case NetworkDataType.d_byte:
messageParams.Add(message.ReadByte());
break;
case NetworkDataType.d_sbyte:
messageParams.Add(message.ReadSByte());
break;
case NetworkDataType.d_ushort:
messageParams.Add(message.ReadUInt16());
break;
case NetworkDataType.d_short:
messageParams.Add(message.ReadInt16());
break;
case NetworkDataType.d_int:
messageParams.Add(message.ReadInt32());
break;
case NetworkDataType.d_uint:
messageParams.Add(message.ReadUInt32());
break;
case NetworkDataType.d_ulong:
messageParams.Add(message.ReadUInt64());
break;
case NetworkDataType.d_long:
messageParams.Add(message.ReadInt64());
break;
case NetworkDataType.d_float:
messageParams.Add(message.ReadFloat());
break;
case NetworkDataType.d_double:
messageParams.Add(message.ReadDouble());
break;
case NetworkDataType.d_string:
messageParams.Add(message.ReadString());
break;
case NetworkDataType.d_byteArray:
int length = message.ReadInt32();
messageParams.Add(message.ReadBytes(length));
break;
}
}
return new IncomingEntityComponentMessage(componentFamily, messageParams);
}
#endregion
#region dummy methods
public void SendMessage(NetOutgoingMessage message, NetConnection recipient,
NetDeliveryMethod method = NetDeliveryMethod.ReliableOrdered)
{
throw new NotImplementedException();
}
#endregion
}
using Lidgren.Network;
using NetSerializer;
using SS14.Client.Interfaces.Configuration;
using SS14.Client.Interfaces.MessageLogging;
using SS14.Client.Interfaces.Network;
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.IoC;
using System;
using System.Collections.Generic;
using System.IO;
namespace SS14.Client.GameObjects
{
public class EntityNetworkManager : IEntityNetworkManager
{
private readonly bool _messageProfiling;
private readonly INetworkManager _networkManager;
public EntityNetworkManager(INetworkManager networkManager)
{
_networkManager = networkManager;
_messageProfiling = IoCManager.Resolve<IConfigurationManager>().GetMessageLogging();
}
#region IEntityNetworkManager Members
public NetOutgoingMessage CreateEntityMessage()
{
NetOutgoingMessage message = _networkManager.CreateMessage();
message.Write((byte) NetMessage.EntityMessage);
return message;
}
#endregion
#region Sending
/// <summary>
/// Sends a message to the relevant system(s) serverside.
/// </summary>
public void SendSystemNetworkMessage(EntitySystemMessage message,
NetDeliveryMethod method = NetDeliveryMethod.ReliableUnordered)
{
NetOutgoingMessage newMsg = CreateEntityMessage();
newMsg.Write((byte)EntityMessage.SystemMessage);
var stream = new MemoryStream();
Serializer.Serialize(stream, message);
newMsg.Write((int)stream.Length);
newMsg.Write(stream.ToArray());
if (_messageProfiling)
{
//Log the message
}
//Send the message
_networkManager.SendMessage(newMsg, method);
}
public void SendDirectedComponentNetworkMessage(Entity sendingEntity, ComponentFamily family,
NetDeliveryMethod method, NetConnection recipient,
params object[] messageParams)
{
throw new NotImplementedException();
}
/// <summary>
/// Allows a component owned by this entity to send a message to a counterpart component on the
/// counterpart entities on all clients.
/// </summary>
/// <param name="sendingEntity">Entity sending the message (also entity to send to)</param>
/// <param name="family">Family of the component sending the message</param>
/// <param name="method">Net delivery method -- if null, defaults to NetDeliveryMethod.ReliableUnordered</param>
/// <param name="messageParams">Parameters of the message</param>
public void SendComponentNetworkMessage(Entity sendingEntity, ComponentFamily family,
NetDeliveryMethod method = NetDeliveryMethod.ReliableUnordered,
params object[] messageParams)
{
NetOutgoingMessage message = CreateEntityMessage();
message.Write((byte)EntityMessage.ComponentMessage);
message.Write(sendingEntity.Uid); //Write this entity's UID
message.Write((byte) family);
PackParams(message, messageParams);
if (_messageProfiling)
{
//Log the message
var logger = IoCManager.Resolve<IMessageLogger>();
logger.LogOutgoingComponentNetMessage(sendingEntity.Uid, family, messageParams);
}
//Send the message
_networkManager.SendMessage(message, method);
}
/// <summary>
/// Sends an arbitrary entity network message
/// </summary>
/// <param name="sendingEntity">The entity the message is going from(and to, on the other end)</param>
/// <param name="type">Message type</param>
/// <param name="list">List of parameter objects</param>
public void SendEntityNetworkMessage(Entity sendingEntity, EntityMessage type, params object[] list)
{
NetOutgoingMessage message = CreateEntityMessage();
message.Write((byte)type);
message.Write(sendingEntity.Uid); //Write this entity's UID
PackParams(message, list);
_networkManager.SendMessage(message, NetDeliveryMethod.ReliableUnordered);
}
private void PackParams(NetOutgoingMessage message, params object[] messageParams)
{
foreach (object messageParam in messageParams)
{
Type t = messageParam.GetType();
if (messageParam.GetType().IsSubclassOf(typeof (Enum)))
{
message.Write((byte) NetworkDataType.d_enum);
message.Write((int) messageParam); //Cast to int, because enums are stored as ints anyway.
}
else if (messageParam.GetType() == typeof (bool))
{
message.Write((byte) NetworkDataType.d_bool);
message.Write((bool) messageParam);
}
else if (messageParam.GetType() == typeof (byte))
{
message.Write((byte) NetworkDataType.d_byte);
message.Write((byte) messageParam);
}
else if (messageParam.GetType() == typeof (sbyte))
{
message.Write((byte) NetworkDataType.d_sbyte);
message.Write((sbyte) messageParam);
}
else if (messageParam.GetType() == typeof (ushort))
{
message.Write((byte) NetworkDataType.d_ushort);
message.Write((ushort) messageParam);
}
else if (messageParam.GetType() == typeof (short))
{
message.Write((byte) NetworkDataType.d_short);
message.Write((short) messageParam);
}
else if (messageParam.GetType() == typeof (int))
{
message.Write((byte) NetworkDataType.d_int);
message.Write((int) messageParam);
}
else if (messageParam.GetType() == typeof (uint))
{
message.Write((byte) NetworkDataType.d_uint);
message.Write((uint) messageParam);
}
else if (messageParam.GetType() == typeof (ulong))
{
message.Write((byte) NetworkDataType.d_ulong);
message.Write((ulong) messageParam);
}
else if (messageParam.GetType() == typeof (long))
{
message.Write((byte) NetworkDataType.d_long);
message.Write((long) messageParam);
}
else if (messageParam.GetType() == typeof (float))
{
message.Write((byte) NetworkDataType.d_float);
message.Write((float) messageParam);
}
else if (messageParam.GetType() == typeof (double))
{
message.Write((byte) NetworkDataType.d_double);
message.Write((double) messageParam);
}
else if (messageParam.GetType() == typeof (string))
{
message.Write((byte) NetworkDataType.d_string);
message.Write((string) messageParam);
}
else if (messageParam.GetType() == typeof (byte[]))
{
message.Write((byte) NetworkDataType.d_byteArray);
message.Write(((byte[]) messageParam).Length);
message.Write((byte[]) messageParam);
}
else
{
throw new NotImplementedException("Cannot write specified type.");
}
}
}
/// <summary>
/// Sends an SVar to the server to be set on the server-side entity.
/// </summary>
/// <param name="sendingEntity"></param>
/// <param name="svar"></param>
public void SendSVar(Entity sendingEntity, MarshalComponentParameter svar)
{
NetOutgoingMessage message = CreateEntityMessage();
message.Write((byte)EntityMessage.SetSVar);
message.Write(sendingEntity.Uid);
svar.Serialize(message);
_networkManager.SendMessage(message, NetDeliveryMethod.ReliableUnordered);
}
#endregion
#region Receiving
/// <summary>
/// Converts a raw NetIncomingMessage to an IncomingEntityMessage object
/// </summary>
/// <param name="message">raw network message</param>
/// <returns>An IncomingEntityMessage object</returns>
public IncomingEntityMessage HandleEntityNetworkMessage(NetIncomingMessage message)
{
var messageType = (EntityMessage) message.ReadByte();
int uid;
IncomingEntityMessage result = IncomingEntityMessage.Null;
switch (messageType)
{
case EntityMessage.ComponentMessage:
uid = message.ReadInt32();
IncomingEntityComponentMessage messageContent = HandleEntityComponentNetworkMessage(message);
result = new IncomingEntityMessage(uid, EntityMessage.ComponentMessage, messageContent,
message.SenderConnection);
if (_messageProfiling)
{
//Log the message
var logger = IoCManager.Resolve<IMessageLogger>();
logger.LogIncomingComponentNetMessage(result.Uid, result.MessageType,
messageContent.ComponentFamily,
messageContent.MessageParameters.ToArray());
}
break;
case EntityMessage.SystemMessage: //TODO: Not happy with this resolving the entmgr everytime a message comes in.
EntityManager eMgr = (EntityManager)IoCManager.Resolve<IEntityManager>();
eMgr.EntitySystemManager.HandleSystemMessage(new EntitySystemData(message.SenderConnection, message));
break;
case EntityMessage.PositionMessage:
uid = message.ReadInt32();
//TODO: Handle position messages!
break;
case EntityMessage.GetSVars:
uid = message.ReadInt32();
result = new IncomingEntityMessage(uid, EntityMessage.GetSVars, message, message.SenderConnection);
break;
}
return result;
}
/// <summary>
/// Handles an incoming entity component message
/// </summary>
/// <param name="message">Raw network message</param>
/// <returns>An IncomingEntityComponentMessage object</returns>
public IncomingEntityComponentMessage HandleEntityComponentNetworkMessage(NetIncomingMessage message)
{
var componentFamily = (ComponentFamily) message.ReadByte();
var messageParams = new List<object>();
while (message.Position < message.LengthBits)
{
switch ((NetworkDataType) message.ReadByte())
{
case NetworkDataType.d_enum:
messageParams.Add(message.ReadInt32());
break;
case NetworkDataType.d_bool:
messageParams.Add(message.ReadBoolean());
break;
case NetworkDataType.d_byte:
messageParams.Add(message.ReadByte());
break;
case NetworkDataType.d_sbyte:
messageParams.Add(message.ReadSByte());
break;
case NetworkDataType.d_ushort:
messageParams.Add(message.ReadUInt16());
break;
case NetworkDataType.d_short:
messageParams.Add(message.ReadInt16());
break;
case NetworkDataType.d_int:
messageParams.Add(message.ReadInt32());
break;
case NetworkDataType.d_uint:
messageParams.Add(message.ReadUInt32());
break;
case NetworkDataType.d_ulong:
messageParams.Add(message.ReadUInt64());
break;
case NetworkDataType.d_long:
messageParams.Add(message.ReadInt64());
break;
case NetworkDataType.d_float:
messageParams.Add(message.ReadFloat());
break;
case NetworkDataType.d_double:
messageParams.Add(message.ReadDouble());
break;
case NetworkDataType.d_string:
messageParams.Add(message.ReadString());
break;
case NetworkDataType.d_byteArray:
int length = message.ReadInt32();
messageParams.Add(message.ReadBytes(length));
break;
}
}
return new IncomingEntityComponentMessage(componentFamily, messageParams);
}
#endregion
#region dummy methods
public void SendMessage(NetOutgoingMessage message, NetConnection recipient,
NetDeliveryMethod method = NetDeliveryMethod.ReliableOrdered)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@@ -1,46 +1,46 @@
using GameObject;
using GameObject.System;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO.EntitySystems
{
public class InputSystem : EntitySystem
{
public InputSystem(EntityManager em, EntitySystemManager esm)
: base(em, esm)
{
EntityQuery = new EntityQuery();
EntityQuery.OneSet.Add(typeof(KeyBindingInputComponent));
}
public override void Update(float frametime)
{
var entities = EntityManager.GetEntities(EntityQuery);
foreach (var entity in entities)
{
var inputs = entity.GetComponent<KeyBindingInputComponent>(ComponentFamily.Input);
//Animation setting
if (entity.GetComponent(ComponentFamily.Renderable) is AnimatedSpriteComponent)
{
var animation = entity.GetComponent<AnimatedSpriteComponent>(ComponentFamily.Renderable);
//Char is moving
if (inputs.GetKeyState(BoundKeyFunctions.MoveRight) ||
inputs.GetKeyState(BoundKeyFunctions.MoveDown) ||
inputs.GetKeyState(BoundKeyFunctions.MoveLeft) ||
inputs.GetKeyState(BoundKeyFunctions.MoveUp))
{
animation.SetAnimationState(inputs.GetKeyState(BoundKeyFunctions.Run) ? "run" : "walk");
}
//Char is not moving
else
{
animation.SetAnimationState("idle");
}
}
}
}
}
using SS14.Shared;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.System;
using SS14.Shared.GO;
namespace SS14.Client.GameObjects.EntitySystems
{
public class InputSystem : EntitySystem
{
public InputSystem(EntityManager em, EntitySystemManager esm)
: base(em, esm)
{
EntityQuery = new EntityQuery();
EntityQuery.OneSet.Add(typeof(KeyBindingInputComponent));
}
public override void Update(float frametime)
{
var entities = EntityManager.GetEntities(EntityQuery);
foreach (var entity in entities)
{
var inputs = entity.GetComponent<KeyBindingInputComponent>(ComponentFamily.Input);
//Animation setting
if (entity.GetComponent(ComponentFamily.Renderable) is AnimatedSpriteComponent)
{
var animation = entity.GetComponent<AnimatedSpriteComponent>(ComponentFamily.Renderable);
//Char is moving
if (inputs.GetKeyState(BoundKeyFunctions.MoveRight) ||
inputs.GetKeyState(BoundKeyFunctions.MoveDown) ||
inputs.GetKeyState(BoundKeyFunctions.MoveLeft) ||
inputs.GetKeyState(BoundKeyFunctions.MoveUp))
{
animation.SetAnimationState(inputs.GetKeyState(BoundKeyFunctions.Run) ? "run" : "walk");
}
//Char is not moving
else
{
animation.SetAnimationState("idle");
}
}
}
}
}
}

View File

@@ -1,23 +1,21 @@
using CGO;
using GameObject;
using GameObject.System;
using EntityManager = GameObject.EntityManager;
namespace CGO.EntitySystems
{
public class InventorySystem : EntitySystem
{
public InventorySystem(EntityManager em, EntitySystemManager esm)
: base(em, esm)
{
EntityQuery = new EntityQuery();
EntityQuery.OneSet.Add(typeof(NewInventoryComponent));
EntityQuery.OneSet.Add(typeof(NewEquipmentComponent));
EntityQuery.OneSet.Add(typeof(NewHandsComponent));
}
public override void Update(float frametime)
{
}
}
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.System;
namespace SS14.Client.GameObjects.EntitySystems
{
public class InventorySystem : EntitySystem
{
public InventorySystem(EntityManager em, EntitySystemManager esm)
: base(em, esm)
{
EntityQuery = new EntityQuery();
EntityQuery.OneSet.Add(typeof(NewInventoryComponent));
EntityQuery.OneSet.Add(typeof(NewEquipmentComponent));
EntityQuery.OneSet.Add(typeof(NewHandsComponent));
}
public override void Update(float frametime)
{
}
}
}

View File

@@ -1,44 +1,42 @@
using CGO;
using ClientInterfaces.Resource;
using GameObject;
using GameObject.System;
using SS13.IoC;
using SS13_Shared.GO;
using EntityManager = GameObject.EntityManager;
namespace CGO.EntitySystems
{
public class ParticleSystem : EntitySystem
{
public ParticleSystem(EntityManager em, EntitySystemManager esm)
: base(em, esm)
{
EntityQuery = new EntityQuery();
EntityQuery.OneSet.Add(typeof(ParticleSystemComponent));
}
public void AddParticleSystem(Entity ent, string systemName)
{
ParticleSettings settings = IoCManager.Resolve<IResourceManager>().GetParticles(systemName);
if (settings != null)
{
//Add it.
}
}
public override void RegisterMessageTypes()
{
//EntitySystemManager.RegisterMessageType<>();
base.RegisterMessageTypes();
}
public override void Update(float frametime)
{
}
public override void HandleNetMessage(EntitySystemMessage sysMsg)
{
base.HandleNetMessage(sysMsg);
}
}
using SS14.Client.Interfaces.Resource;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.System;
using SS14.Shared.GO;
using SS14.Shared.IoC;
namespace SS14.Client.GameObjects.EntitySystems
{
public class ParticleSystem : EntitySystem
{
public ParticleSystem(EntityManager em, EntitySystemManager esm)
: base(em, esm)
{
EntityQuery = new EntityQuery();
EntityQuery.OneSet.Add(typeof(ParticleSystemComponent));
}
public void AddParticleSystem(Entity ent, string systemName)
{
ParticleSettings settings = IoCManager.Resolve<IResourceManager>().GetParticles(systemName);
if (settings != null)
{
//Add it.
}
}
public override void RegisterMessageTypes()
{
//EntitySystemManager.RegisterMessageType<>();
base.RegisterMessageTypes();
}
public override void Update(float frametime)
{
}
public override void HandleNetMessage(EntitySystemMessage sysMsg)
{
base.HandleNetMessage(sysMsg);
}
}
}

View File

@@ -1,91 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CGO;
using ClientInterfaces.Collision;
using ClientInterfaces.Map;
using GameObject;
using GameObject.System;
using GorgonLibrary;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using EntityManager = GameObject.EntityManager;
namespace CGO.EntitySystems
{
internal class PhysicsSystem : EntitySystem
{
public PhysicsSystem(EntityManager em, EntitySystemManager esm)
: base(em, esm)
{
EntityQuery = new EntityQuery();
EntityQuery.AllSet.Add(typeof(PhysicsComponent));
EntityQuery.AllSet.Add(typeof(VelocityComponent));
EntityQuery.AllSet.Add(typeof(TransformComponent));
EntityQuery.Exclusionset.Add(typeof(SlaveMoverComponent));
}
/// <summary>
/// Update
///
/// This system is currently slightly dumb -- it only does player movement right now because
/// all other movement is done via straight interpolation through coordinates sent from the server.
/// </summary>
/// <param name="frametime"></param>
public override void Update(float frametime)
{
var entities = EntityManager.GetEntities(EntityQuery);
return;
foreach(var entity in entities)
{
var transform = entity.GetComponent<TransformComponent>(ComponentFamily.Transform);
var velocity = entity.GetComponent<VelocityComponent>(ComponentFamily.Velocity);
//Decelerate
velocity.Velocity -= (velocity.Velocity * (frametime * 0.01f));
var movement = velocity.Velocity*frametime;
var mover = entity.GetComponent<PlayerInputMoverComponent>(ComponentFamily.Mover);
if(mover != null && movement.Length > 0)
{
//Check for collision
var collider = entity.GetComponent<ColliderComponent>(ComponentFamily.Collider);
if(collider != null)
{
bool collided = collider.TryCollision(movement);
bool collidedx, collidedy;
if(collided)
{
collidedx = collider.TryCollision(new Vector2D(movement.X, 0));
if(collidedx)
velocity.X = 0;
collidedy = collider.TryCollision(new Vector2D(0, movement.Y));
if (collidedy)
velocity.Y = 0;
movement = velocity.Velocity*frametime;
}
}
if (movement.Length > 0.001f)
{
transform.TranslateByOffset(movement);
mover.ShouldSendPositionUpdate = true;
}
}
if (mover != null && mover.ShouldSendPositionUpdate)
{
mover.SendPositionUpdate(transform.Position);
mover.ShouldSendPositionUpdate = false;
}
/*else
{
//Apply velocity
transform.Position += movement;
}*/
}
}
}
}
using GorgonLibrary;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.System;
using SS14.Shared.GO;
namespace SS14.Client.GameObjects.EntitySystems
{
internal class PhysicsSystem : EntitySystem
{
public PhysicsSystem(EntityManager em, EntitySystemManager esm)
: base(em, esm)
{
EntityQuery = new EntityQuery();
EntityQuery.AllSet.Add(typeof(PhysicsComponent));
EntityQuery.AllSet.Add(typeof(VelocityComponent));
EntityQuery.AllSet.Add(typeof(TransformComponent));
EntityQuery.Exclusionset.Add(typeof(SlaveMoverComponent));
}
/// <summary>
/// Update
///
/// This system is currently slightly dumb -- it only does player movement right now because
/// all other movement is done via straight interpolation through coordinates sent from the server.
/// </summary>
/// <param name="frametime"></param>
public override void Update(float frametime)
{
var entities = EntityManager.GetEntities(EntityQuery);
return;
foreach(var entity in entities)
{
var transform = entity.GetComponent<TransformComponent>(ComponentFamily.Transform);
var velocity = entity.GetComponent<VelocityComponent>(ComponentFamily.Velocity);
//Decelerate
velocity.Velocity -= (velocity.Velocity * (frametime * 0.01f));
var movement = velocity.Velocity*frametime;
var mover = entity.GetComponent<PlayerInputMoverComponent>(ComponentFamily.Mover);
if(mover != null && movement.Length > 0)
{
//Check for collision
var collider = entity.GetComponent<ColliderComponent>(ComponentFamily.Collider);
if(collider != null)
{
bool collided = collider.TryCollision(movement);
bool collidedx, collidedy;
if(collided)
{
collidedx = collider.TryCollision(new Vector2D(movement.X, 0));
if(collidedx)
velocity.X = 0;
collidedy = collider.TryCollision(new Vector2D(0, movement.Y));
if (collidedy)
velocity.Y = 0;
movement = velocity.Velocity*frametime;
}
}
if (movement.Length > 0.001f)
{
transform.TranslateByOffset(movement);
mover.ShouldSendPositionUpdate = true;
}
}
if (mover != null && mover.ShouldSendPositionUpdate)
{
mover.SendPositionUpdate(transform.Position);
mover.ShouldSendPositionUpdate = false;
}
/*else
{
//Apply velocity
transform.Position += movement;
}*/
}
}
}
}

View File

@@ -1,19 +1,19 @@
using GameObject;
using GameObject.System;
namespace SGO.EntitySystems
{
public class TestSystem : EntitySystem
{
public TestSystem(EntityManager em, EntitySystemManager esm)
: base(em, esm)
{
EntityQuery = new EntityQuery();
EntityQuery.OneSet.Add(typeof (BasicItemComponent));
}
public override void Update(float frametime)
{
}
}
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.System;
namespace SS14.Client.GameObjects.EntitySystems
{
public class TestSystem : EntitySystem
{
public TestSystem(EntityManager em, EntitySystemManager esm)
: base(em, esm)
{
EntityQuery = new EntityQuery();
EntityQuery.OneSet.Add(typeof (BasicItemComponent));
}
public override void Update(float frametime)
{
}
}
}

View File

@@ -1,176 +1,171 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using ClientInterfaces.Configuration;
using ClientInterfaces.GameTimer;
using ClientInterfaces.Player;
using GameObject;
using GameObject.System;
using GorgonLibrary;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
namespace CGO.EntitySystems
{
internal class TransformSystem : EntitySystem
{
public TransformSystem(EntityManager em, EntitySystemManager esm)
: base(em, esm)
{
EntityQuery = new EntityQuery();
EntityQuery.AllSet.Add(typeof(TransformComponent));
EntityQuery.Exclusionset.Add(typeof(SlaveMoverComponent));
}
public override void Update(float frametime)
{
var entities = EntityManager.GetEntities(EntityQuery);
//Interp constant -- determines how far back in time to interpolate from
var interpolation = IoCManager.Resolve<IConfigurationManager>().GetInterpolation();
Vector2D newPosition;
foreach (var entity in entities)
{
//Get transform component
var transform = entity.GetComponent<TransformComponent>(ComponentFamily.Transform);
//Check if the entity has a keyboard input mover component
bool isLocallyControlled = entity.GetComponent<PlayerInputMoverComponent>(ComponentFamily.Mover) != null
&& IoCManager.Resolve<IPlayerManager>().ControlledEntity == entity;
//Pretend that the current point in time is actually 100 or more milliseconds in the past depending on the interp constant
var currentTime = IoCManager.Resolve<IGameTimer>().CurrentTime - interpolation;
//Limit to how far a human can move
var humanMoveLimit = 6 * interpolation * PlayerInputMoverComponent.FastMoveSpeed;
// If the "to" interp position is equal to the "from" interp position,
// OR we're actually trying to interpolate past the "to" state
// OR we're trying to interpolate a point older than the oldest state in memory
if (transform.lerpStateTo == transform.lerpStateFrom ||
currentTime > transform.lerpStateTo.ReceivedTime ||
currentTime < transform.lerpStateFrom.ReceivedTime)
{
// Fall back to setting the position to the "To" state
newPosition = new Vector2D(transform.lerpStateTo.X, transform.lerpStateTo.Y);
}
else //OTHERWISE
{
//Interpolate
var p1 = new Vector2D(transform.lerpStateFrom.X, transform.lerpStateTo.Y);
var p2 = new Vector2D(transform.lerpStateTo.X, transform.lerpStateTo.Y);
var t1 = transform.lerpStateFrom.ReceivedTime;
var t2 = transform.lerpStateTo.ReceivedTime;
// linear interpolation from the state immediately prior to the "current time"
// to the state immediately after the "current time"
var lerp = (currentTime - t1)/(t2 - t1);
//lerp is a constant 0..1 value that says what position along the line from p1 to p2 we're at
newPosition = Interpolate(p1, p2, lerp, false);
if(isLocallyControlled)
{
newPosition = EaseExponential(currentTime - t1, transform.Position, newPosition, t2 - t1);
}
}
//Handle player movement
if (isLocallyControlled)
{
//var playerPosition = transform.Position +
var velocityComponent = entity.GetComponent<VelocityComponent>(ComponentFamily.Velocity);
if (velocityComponent != null)
{
var movement = velocityComponent.Velocity * frametime;
var playerPosition = movement + transform.Position;
var difference = playerPosition - newPosition;
if (difference.Length <= humanMoveLimit)
//TODO do this by reducing the length of the difference vector to the acceptable amount and applying it
//Instead of just snapping back to the server's position
newPosition = playerPosition;
}
// Reduce rubber banding by easing to the position we're supposed to be at
}
if ((newPosition - transform.Position).Length > 0.0001f)// &&
//(!haskbMover || (newPosition - transform.Position).Length > humanMoveLimit))
{
var doTranslate = false;
if (!isLocallyControlled)
doTranslate = true;
else
{
//Only for components with a keyboard input mover component, and a collider component
// Check for collision so we don't get shit stuck in objects
if (entity.GetComponent<ColliderComponent>(ComponentFamily.Collider) != null)
{
//Check for collision
var collider = entity.GetComponent<ColliderComponent>(ComponentFamily.Collider);
bool collided = collider.TryCollision(newPosition - transform.Position, true);
if (!collided)
doTranslate = true;
else
{
//Debugger.Break();
}
}
else
{
doTranslate = true;
}
}
if (doTranslate)
{
transform.TranslateTo(newPosition);
if (isLocallyControlled)
entity.GetComponent<PlayerInputMoverComponent>(ComponentFamily.Mover).SendPositionUpdate(newPosition);
}
}
}
}
private Vector2D EaseExponential(float time, Vector2D v1, Vector2D v2, float duration)
{
var dx = (v2.X - v1.X);
var x = EaseExponential(time, v1.X, dx, duration);
var dy = (v2.Y - v1.Y);
var y = EaseExponential(time, v1.Y, dy, duration);
return new Vector2D(x,y);
}
private float EaseExponential(float t, float b, float c, float d)
{
return c * ((float)-Math.Pow(2, -10 * t / d) + 1) + b;
}
private Vector2D Interpolate(Vector2D v1, Vector2D v2, float control, bool allowExtrapolation)
{
if (!allowExtrapolation && (control > 1 || control < 0))
{
// Error message includes information about the actual value of the argument
throw new ArgumentOutOfRangeException
(
"control",
control,
"Control parameter must be a value between 0 & 1\nThe argument provided has a value of " + control
);
}
else
{
return
(
new Vector2D
(
v1.X * (1 - control) + v2.X * control,
v1.Y * (1 - control) + v2.Y * control
)
);
}
}
}
}
using GorgonLibrary;
using SS14.Client.Interfaces.Configuration;
using SS14.Client.Interfaces.GameTimer;
using SS14.Client.Interfaces.Player;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.System;
using SS14.Shared.GO;
using SS14.Shared.IoC;
using System;
namespace SS14.Client.GameObjects.EntitySystems
{
internal class TransformSystem : EntitySystem
{
public TransformSystem(EntityManager em, EntitySystemManager esm)
: base(em, esm)
{
EntityQuery = new EntityQuery();
EntityQuery.AllSet.Add(typeof(TransformComponent));
EntityQuery.Exclusionset.Add(typeof(SlaveMoverComponent));
}
public override void Update(float frametime)
{
var entities = EntityManager.GetEntities(EntityQuery);
//Interp constant -- determines how far back in time to interpolate from
var interpolation = IoCManager.Resolve<IConfigurationManager>().GetInterpolation();
Vector2D newPosition;
foreach (var entity in entities)
{
//Get transform component
var transform = entity.GetComponent<TransformComponent>(ComponentFamily.Transform);
//Check if the entity has a keyboard input mover component
bool isLocallyControlled = entity.GetComponent<PlayerInputMoverComponent>(ComponentFamily.Mover) != null
&& IoCManager.Resolve<IPlayerManager>().ControlledEntity == entity;
//Pretend that the current point in time is actually 100 or more milliseconds in the past depending on the interp constant
var currentTime = IoCManager.Resolve<IGameTimer>().CurrentTime - interpolation;
//Limit to how far a human can move
var humanMoveLimit = 6 * interpolation * PlayerInputMoverComponent.FastMoveSpeed;
// If the "to" interp position is equal to the "from" interp position,
// OR we're actually trying to interpolate past the "to" state
// OR we're trying to interpolate a point older than the oldest state in memory
if (transform.lerpStateTo == transform.lerpStateFrom ||
currentTime > transform.lerpStateTo.ReceivedTime ||
currentTime < transform.lerpStateFrom.ReceivedTime)
{
// Fall back to setting the position to the "To" state
newPosition = new Vector2D(transform.lerpStateTo.X, transform.lerpStateTo.Y);
}
else //OTHERWISE
{
//Interpolate
var p1 = new Vector2D(transform.lerpStateFrom.X, transform.lerpStateTo.Y);
var p2 = new Vector2D(transform.lerpStateTo.X, transform.lerpStateTo.Y);
var t1 = transform.lerpStateFrom.ReceivedTime;
var t2 = transform.lerpStateTo.ReceivedTime;
// linear interpolation from the state immediately prior to the "current time"
// to the state immediately after the "current time"
var lerp = (currentTime - t1)/(t2 - t1);
//lerp is a constant 0..1 value that says what position along the line from p1 to p2 we're at
newPosition = Interpolate(p1, p2, lerp, false);
if(isLocallyControlled)
{
newPosition = EaseExponential(currentTime - t1, transform.Position, newPosition, t2 - t1);
}
}
//Handle player movement
if (isLocallyControlled)
{
//var playerPosition = transform.Position +
var velocityComponent = entity.GetComponent<VelocityComponent>(ComponentFamily.Velocity);
if (velocityComponent != null)
{
var movement = velocityComponent.Velocity * frametime;
var playerPosition = movement + transform.Position;
var difference = playerPosition - newPosition;
if (difference.Length <= humanMoveLimit)
//TODO do this by reducing the length of the difference vector to the acceptable amount and applying it
//Instead of just snapping back to the server's position
newPosition = playerPosition;
}
// Reduce rubber banding by easing to the position we're supposed to be at
}
if ((newPosition - transform.Position).Length > 0.0001f)// &&
//(!haskbMover || (newPosition - transform.Position).Length > humanMoveLimit))
{
var doTranslate = false;
if (!isLocallyControlled)
doTranslate = true;
else
{
//Only for components with a keyboard input mover component, and a collider component
// Check for collision so we don't get shit stuck in objects
if (entity.GetComponent<ColliderComponent>(ComponentFamily.Collider) != null)
{
//Check for collision
var collider = entity.GetComponent<ColliderComponent>(ComponentFamily.Collider);
bool collided = collider.TryCollision(newPosition - transform.Position, true);
if (!collided)
doTranslate = true;
else
{
//Debugger.Break();
}
}
else
{
doTranslate = true;
}
}
if (doTranslate)
{
transform.TranslateTo(newPosition);
if (isLocallyControlled)
entity.GetComponent<PlayerInputMoverComponent>(ComponentFamily.Mover).SendPositionUpdate(newPosition);
}
}
}
}
private Vector2D EaseExponential(float time, Vector2D v1, Vector2D v2, float duration)
{
var dx = (v2.X - v1.X);
var x = EaseExponential(time, v1.X, dx, duration);
var dy = (v2.Y - v1.Y);
var y = EaseExponential(time, v1.Y, dy, duration);
return new Vector2D(x,y);
}
private float EaseExponential(float t, float b, float c, float d)
{
return c * ((float)-Math.Pow(2, -10 * t / d) + 1) + b;
}
private Vector2D Interpolate(Vector2D v1, Vector2D v2, float control, bool allowExtrapolation)
{
if (!allowExtrapolation && (control > 1 || control < 0))
{
// Error message includes information about the actual value of the argument
throw new ArgumentOutOfRangeException
(
"control",
control,
"Control parameter must be a value between 0 & 1\nThe argument provided has a value of " + control
);
}
else
{
return
(
new Vector2D
(
v1.X * (1 - control) + v2.X * control,
v1.Y * (1 - control) + v2.Y * control
)
);
}
}
}
}

View File

@@ -1,13 +1,13 @@
namespace CGO
{
public class ExampleAction : PlayerAction
{
public ExampleAction(uint _uid, PlayerActionComp _parent)
: base(_uid, _parent)
{
name = "Stab";
description = "Stab someone with one of the many hidden knifes you carry around.";
icon = "action_stab";
}
}
namespace SS14.Client.GameObjects
{
public class ExampleAction : PlayerAction
{
public ExampleAction(uint _uid, PlayerActionComp _parent)
: base(_uid, _parent)
{
name = "Stab";
description = "Stab someone with one of the many hidden knifes you carry around.";
icon = "action_stab";
}
}
}

View File

@@ -1,78 +1,78 @@
using System;
using ClientInterfaces.GOC;
using ClientInterfaces.UserInterface;
using SS13.IoC;
using SS13_Shared;
namespace CGO
{
public class PlayerAction : IPlayerAction
{
private readonly PlayerActionComp parent;
protected readonly uint uid = 0;
protected DateTime cooldownExpires;
protected String description = "This is an undefined Action.";
protected String icon = "action_none";
protected String name = "Empty Action";
protected PlayerActionTargetType targetType = PlayerActionTargetType.Any;
public PlayerAction(uint _uid, PlayerActionComp _parent)
//Do not add more parameters to the constructors or bad things happen.
{
uid = _uid;
parent = _parent;
}
#region IPlayerAction Members
public uint Uid
{
get { return uid; }
}
public PlayerActionTargetType TargetType
{
get { return targetType; }
}
public String Name
{
get { return name; }
}
public String Description
{
get { return description; }
}
public String Icon
{
get { return icon; }
}
public DateTime CooldownExpires
{
get { return cooldownExpires; }
set { cooldownExpires = value; }
}
public void Activate()
//Activates this action. If it's targeted, the player will enter targeting mode - else it will be used.
{
if (cooldownExpires.Subtract(DateTime.Now).TotalSeconds > 0) return;
if (targetType == PlayerActionTargetType.None)
Use(null);
else
IoCManager.Resolve<IUserInterfaceManager>().StartTargeting(this);
}
public void Use(object target)
{
parent.SendDoAction(this, target);
}
#endregion
}
using SS14.Client.Interfaces.GOC;
using SS14.Client.Interfaces.UserInterface;
using SS14.Shared;
using SS14.Shared.IoC;
using System;
namespace SS14.Client.GameObjects
{
public class PlayerAction : IPlayerAction
{
private readonly PlayerActionComp parent;
protected readonly uint uid = 0;
protected DateTime cooldownExpires;
protected String description = "This is an undefined Action.";
protected String icon = "action_none";
protected String name = "Empty Action";
protected PlayerActionTargetType targetType = PlayerActionTargetType.Any;
public PlayerAction(uint _uid, PlayerActionComp _parent)
//Do not add more parameters to the constructors or bad things happen.
{
uid = _uid;
parent = _parent;
}
#region IPlayerAction Members
public uint Uid
{
get { return uid; }
}
public PlayerActionTargetType TargetType
{
get { return targetType; }
}
public String Name
{
get { return name; }
}
public String Description
{
get { return description; }
}
public String Icon
{
get { return icon; }
}
public DateTime CooldownExpires
{
get { return cooldownExpires; }
set { cooldownExpires = value; }
}
public void Activate()
//Activates this action. If it's targeted, the player will enter targeting mode - else it will be used.
{
if (cooldownExpires.Subtract(DateTime.Now).TotalSeconds > 0) return;
if (targetType == PlayerActionTargetType.None)
Use(null);
else
IoCManager.Resolve<IUserInterfaceManager>().StartTargeting(this);
}
public void Use(object target)
{
parent.SendDoAction(this, target);
}
#endregion
}
}

View File

@@ -1,39 +1,39 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ClientGameComponent")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClientGameComponent")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("705e9101-7489-4b75-a059-6e28b3acb511")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SS14.Client.GameObjects")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SS14.Client.GameObjects")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("705e9101-7489-4b75-a059-6e28b3acb511")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -1,28 +1,28 @@
using System;
using GameObject;
namespace CGO
{
public class Bleeding : StatusEffect
{
public Bleeding(uint _uid, Entity _affected)
: base(_uid, _affected)
{
name = "Bleeding";
description = "You are bleeding." + Environment.NewLine + "Causes additional damage over time.";
icon = "status_bleeding";
}
public override void OnAdd()
{
}
public override void OnRemove()
{
}
public override void OnUpdate()
{
}
}
using SS14.Shared.GameObjects;
using System;
namespace SS14.Client.GameObjects
{
public class Bleeding : StatusEffect
{
public Bleeding(uint _uid, Entity _affected)
: base(_uid, _affected)
{
name = "Bleeding";
description = "You are bleeding." + Environment.NewLine + "Causes additional damage over time.";
icon = "status_bleeding";
}
public override void OnAdd()
{
}
public override void OnRemove()
{
}
public override void OnUpdate()
{
}
}
}

View File

@@ -1,29 +1,29 @@
using GameObject;
namespace CGO
{
public class ExampleEffect : StatusEffect
{
public ExampleEffect(uint _uid, Entity _affected)
//Do not add more parameters to the constructors or bad things happen.
: base(_uid, _affected)
{
name = "Example Effect";
description = "This is an example...";
icon = "status_example";
isDebuff = false;
}
public override void OnAdd()
{
}
public override void OnRemove()
{
}
public override void OnUpdate()
{
}
}
using SS14.Shared.GameObjects;
namespace SS14.Client.GameObjects
{
public class ExampleEffect : StatusEffect
{
public ExampleEffect(uint _uid, Entity _affected)
//Do not add more parameters to the constructors or bad things happen.
: base(_uid, _affected)
{
name = "Example Effect";
description = "This is an example...";
icon = "status_example";
isDebuff = false;
}
public override void OnAdd()
{
}
public override void OnRemove()
{
}
public override void OnUpdate()
{
}
}
}

View File

@@ -1,28 +1,28 @@
using System;
using GameObject;
namespace CGO
{
public class Hypoxia : StatusEffect
{
public Hypoxia(uint _uid, Entity _affected)
: base(_uid, _affected)
{
name = "Hypoxia";
description = "You feel your chest aching." + Environment.NewLine + "Find some air, quick!";
icon = "status_hypoxia";
}
public override void OnAdd()
{
}
public override void OnRemove()
{
}
public override void OnUpdate()
{
}
}
using SS14.Shared.GameObjects;
using System;
namespace SS14.Client.GameObjects
{
public class Hypoxia : StatusEffect
{
public Hypoxia(uint _uid, Entity _affected)
: base(_uid, _affected)
{
name = "Hypoxia";
description = "You feel your chest aching." + Environment.NewLine + "Find some air, quick!";
icon = "status_hypoxia";
}
public override void OnAdd()
{
}
public override void OnRemove()
{
}
public override void OnUpdate()
{
}
}
}

View File

@@ -1,27 +1,27 @@
using GameObject;
namespace CGO
{
public class Rooted : StatusEffect
{
public Rooted(uint _uid, Entity _affected)
: base(_uid, _affected)
{
name = "Rooted";
description = "You can not move.";
icon = "status_stun";
}
public override void OnAdd()
{
}
public override void OnRemove()
{
}
public override void OnUpdate()
{
}
}
using SS14.Shared.GameObjects;
namespace SS14.Client.GameObjects
{
public class Rooted : StatusEffect
{
public Rooted(uint _uid, Entity _affected)
: base(_uid, _affected)
{
name = "Rooted";
description = "You can not move.";
icon = "status_stun";
}
public override void OnAdd()
{
}
public override void OnRemove()
{
}
public override void OnUpdate()
{
}
}
}

View File

@@ -1,47 +1,47 @@
using System;
using GameObject;
using SS13_Shared.GO;
using SS13_Shared.GO.StatusEffect;
namespace CGO
{
public class StatusEffect
{
public readonly uint uid = 0; //Don't set this clientside. The component handles this.
protected Entity affected;
public String description = "A Status Effect.";
public Boolean doesExpire = true; //Don't set this clientside. The component handles this.
public DateTime expiresAt; //Don't set this clientside. The component handles this.
public StatusEffectFamily family = StatusEffectFamily.None;
public String icon;
public Boolean isDebuff = true;
public Boolean isVisible = true;
public String name = "Effect";
public StatusEffect(uint _uid, Entity _affected)
//Do not add more parameters to the constructors or bad things happen.
{
uid = _uid;
affected = _affected;
}
public virtual void OnAdd()
{
}
public virtual void OnRemove()
{
}
public virtual void OnUpdate()
{
}
internal void UpdateEffectState(StatusEffectState effectState)
{
expiresAt = effectState.ExpiresAt;
doesExpire = effectState.DoesExpire;
}
}
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using SS14.Shared.GO.StatusEffect;
using System;
namespace SS14.Client.GameObjects
{
public class StatusEffect
{
public readonly uint uid = 0; //Don't set this clientside. The component handles this.
protected Entity affected;
public String description = "A Status Effect.";
public Boolean doesExpire = true; //Don't set this clientside. The component handles this.
public DateTime expiresAt; //Don't set this clientside. The component handles this.
public StatusEffectFamily family = StatusEffectFamily.None;
public String icon;
public Boolean isDebuff = true;
public Boolean isVisible = true;
public String name = "Effect";
public StatusEffect(uint _uid, Entity _affected)
//Do not add more parameters to the constructors or bad things happen.
{
uid = _uid;
affected = _affected;
}
public virtual void OnAdd()
{
}
public virtual void OnRemove()
{
}
public virtual void OnUpdate()
{
}
internal void UpdateEffectState(StatusEffectState effectState)
{
expiresAt = effectState.ExpiresAt;
doesExpire = effectState.DoesExpire;
}
}
}

View File

@@ -1,28 +1,28 @@
using System;
using GameObject;
namespace CGO
{
public class ToxinInhalation : StatusEffect
{
public ToxinInhalation(uint _uid, Entity _affected)
: base(_uid, _affected)
{
name = "Toxin Inhalation";
description = "You have inhaled toxins." + Environment.NewLine + "Causes additional damage over time.";
icon = "status_toxinh";
}
public override void OnAdd()
{
}
public override void OnRemove()
{
}
public override void OnUpdate()
{
}
}
using SS14.Shared.GameObjects;
using System;
namespace SS14.Client.GameObjects
{
public class ToxinInhalation : StatusEffect
{
public ToxinInhalation(uint _uid, Entity _affected)
: base(_uid, _affected)
{
name = "Toxin Inhalation";
description = "You have inhaled toxins." + Environment.NewLine + "Causes additional damage over time.";
icon = "status_toxinh";
}
public override void OnAdd()
{
}
public override void OnRemove()
{
}
public override void OnUpdate()
{
}
}
}

View File

@@ -1,75 +1,75 @@
using SS13_Shared;
using GorgonLibrary;
namespace CGO
{
public struct Vector2TypeConverter
{
/// <summary>
/// Property for the x component of the Vector2
/// </summary>
public float X
{
get { return x; }
set { x = value; }
}
/// <summary>
/// Property for the y component of the Vector2
/// </summary>
public float Y
{
get { return y; }
set { y = value; }
}
/// <summary>
/// The X component of the vector
/// </summary>
private float x;
/// <summary>
/// The Y component of the vector
/// </summary>
private float y;
public Vector2TypeConverter(float x, float y)
{
this.x = 0;
this.y = 0;
X = x;
Y = y;
}
public static implicit operator Vector2TypeConverter(Vector2 vec)
{
return new Vector2TypeConverter(vec.X, vec.Y);
}
public static implicit operator Vector2TypeConverter(Vector2D vec)
{
return new Vector2TypeConverter(vec.X, vec.Y);
}
public static implicit operator Vector2(Vector2TypeConverter vec)
{
return new Vector2(vec.X, vec.Y);
}
public static implicit operator Vector2D(Vector2TypeConverter vec)
{
return new Vector2D(vec.X, vec.Y);
}
public static Vector2 ToVector2(Vector2D vec)
{
return new Vector2(vec.X, vec.Y);
}
public static Vector2D ToVector2D(Vector2 vec)
{
return new Vector2D(vec.X, vec.Y);
}
}
}
using GorgonLibrary;
using SS14.Shared;
namespace SS14.Client.GameObjects
{
public struct Vector2TypeConverter
{
/// <summary>
/// Property for the x component of the Vector2
/// </summary>
public float X
{
get { return x; }
set { x = value; }
}
/// <summary>
/// Property for the y component of the Vector2
/// </summary>
public float Y
{
get { return y; }
set { y = value; }
}
/// <summary>
/// The X component of the vector
/// </summary>
private float x;
/// <summary>
/// The Y component of the vector
/// </summary>
private float y;
public Vector2TypeConverter(float x, float y)
{
this.x = 0;
this.y = 0;
X = x;
Y = y;
}
public static implicit operator Vector2TypeConverter(Vector2 vec)
{
return new Vector2TypeConverter(vec.X, vec.Y);
}
public static implicit operator Vector2TypeConverter(Vector2D vec)
{
return new Vector2TypeConverter(vec.X, vec.Y);
}
public static implicit operator Vector2(Vector2TypeConverter vec)
{
return new Vector2(vec.X, vec.Y);
}
public static implicit operator Vector2D(Vector2TypeConverter vec)
{
return new Vector2D(vec.X, vec.Y);
}
public static Vector2 ToVector2(Vector2D vec)
{
return new Vector2(vec.X, vec.Y);
}
public static Vector2D ToVector2D(Vector2 vec)
{
return new Vector2D(vec.X, vec.Y);
}
}
}

View File

@@ -1,4 +1,4 @@
<Project frameworkVersion="v4_0" name="ClientGameObject" rootNamespace="CGO" type="Library" path="CGO">
<Project frameworkVersion="v4_0" name="SS14.Client.GameObjects" rootNamespace="SS14.Client.GameObjects" type="Library" path="SS14.Client.GameObjects">
<Configuration name="Debug" platform="x86">
<Options>
<OutputPath>../Bin</OutputPath>
@@ -69,7 +69,6 @@
<File buildAction="Compile">EntitySystems/InventorySystem.cs</File>
<File buildAction="Compile">EntitySystems/TransformSystem.cs</File>
<File buildAction="Compile">Vector2.cs</File>
<File buildAction="None">ClassDiagram1.cd</File>
<File buildAction="None">Entity.cs</File>
<File buildAction="Compile">EntityManager.cs</File>
<File buildAction="Compile">EntityNetworkManager.cs</File>
@@ -87,11 +86,11 @@
<File buildAction="Compile">Status Effects/ExampleEffect.cs</File>
<File buildAction="Compile">Status Effects/StatusEffect.cs</File>
</Files>
<Reference name="ClientInterfaces"/>
<Reference name="ClientWindow"/>
<Reference name="GameObject"/>
<Reference name="SS14.Client.Interfaces"/>
<Reference name="SS14.Client.ClientWindow"/>
<Reference name="SS14.Shared.GameObjects"/>
<Reference name="Lidgren.Network"/>
<Reference name="SS13.Graphics"/>
<Reference name="SS13.IoC"/>
<Reference name="SS13_Shared"/>
<Reference name="SS14.Client.Graphics"/>
<Reference name="SS14.Shared.IoC"/>
<Reference name="SS14.Shared"/>
</Project>

View File

@@ -1,225 +1,234 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using ClientInterfaces.Resource;
using GorgonLibrary.Graphics;
using SS13_Shared;
namespace SS13.Graphics
{
public class AnimatedSprite
{
#region Public Properties
public string Name { get; set; }
public Dictionary<string, AnimationState> AnimationStates { get; private set; }
private AnimationState _currentAnimationState;
public string CurrentAnimationStateKey
{
get
{
if (_currentAnimationState != null)
return _currentAnimationState.Name;
return null;
}
}
public string BaseName { get; set; }
public Direction Direction
{
get { return _direction; }
set { _direction = value;
UpdateDirection();
}
}
public RectangleF AverageAABB
{
get
{
if (_currentSprite != null)
return _averageAABBs[_currentAnimationState.Name][Direction];
return RectangleF.Empty;
}
}
#region Sprite passthrough methods
public RectangleF AABB
{
get {
if (_currentSprite != null)
return _currentSprite.AABB;
return RectangleF.Empty;
}
}
public bool HorizontalFlip
{
get { if (_currentSprite != null) return _currentSprite.HorizontalFlip;
return false;
}
set
{
if (_currentSprite != null)
_currentSprite.HorizontalFlip = value;
}
}
#endregion
#endregion
#region private properties
#endregion
#region Variables
/// <summary>
/// Dictionary of animation names to directional sprite set
/// </summary>
private Dictionary<string, Dictionary<Direction, Sprite[]>> _sprites = new Dictionary<string, Dictionary<Direction, Sprite[]>>();
private Dictionary<string, Dictionary<Direction, RectangleF>> _averageAABBs = new Dictionary<string, Dictionary<Direction, RectangleF>>();
private Sprite _currentSprite;
private Direction _direction = Direction.South;
#endregion
#region Methods
//Todo encapsulate this further down as components -- AnimatedSpriteState, AnimatedSpriteStateDirection
public void LoadSprites(AnimationCollection collection, IResourceManager resourceManager)
{
float x=0, y=0, h=0, w=0;
int t=0;
foreach(var info in collection.Animations)
{
_sprites.Add(info.Name, new Dictionary<Direction, Sprite[]>());
//Because we have a shitload of frames, we're going to store the average size as the AABB for each direction and each animation
_averageAABBs.Add(info.Name, new Dictionary<Direction, RectangleF>());
var sprites = _sprites[info.Name];
var averageAABBs = _averageAABBs[info.Name];
AnimationStates.Add(info.Name, new AnimationState(info));
foreach( var dir in Enum.GetValues(typeof(Direction)).Cast<Direction>())
{
sprites.Add(dir, new Sprite[info.Frames]);
var thisDirSprites = sprites[dir];
for (var i = 0; i < info.Frames; i++)
{
var spritename = collection.Name.ToLowerInvariant() + "_" + info.Name.ToLowerInvariant() + "_"
+ DirectionToUriComponent(dir) + "_" + i;
thisDirSprites[i] = resourceManager.GetSprite(spritename);
x += thisDirSprites[i].AABB.X;
y += thisDirSprites[i].AABB.Y;
w += thisDirSprites[i].AABB.Width;
h += thisDirSprites[i].AABB.Height;
t++;
}
averageAABBs.Add(dir, new RectangleF(x / t, y / t, w / t, h / t));
t = 0;
x = 0;
y = 0;
w = 0;
h = 0;
}
}
}
public Sprite GetCurrentSprite()
{
return _currentSprite;
}
public void Draw()
{
_currentSprite.Draw();
}
public void SetPosition(float x, float y)
{
_currentSprite.SetPosition(x, y);
}
private void UpdateDirection()
{
SetCurrentSprite();
}
public void SetAnimationState(string state)
{
if(_currentAnimationState != null)
{
//Dont change the state to the current state or we'll be stuck always on the first frame :(
if (_currentAnimationState.Name == state)
return;
_currentAnimationState.Reset();
}
if (state != null)
{
_currentAnimationState = AnimationStates[state];
_currentAnimationState.Enabled = true;
}
}
private void SetCurrentSprite()
{
_currentSprite = _sprites[_currentAnimationState.Name][Direction][_currentAnimationState.CurrentFrame];
}
public void SetLoop(bool loop)
{
_currentAnimationState.Loop = loop;
}
public void Update(float time)
{
_currentAnimationState.AddTime(time);
SetCurrentSprite();
}
public static string DirectionToUriComponent(Direction dir)
{
switch (dir)
{
case Direction.East:
return "e";
case Direction.West:
return "w";
case Direction.North:
return "n";
case Direction.South:
return "s";
case Direction.NorthEast:
return "ne";
case Direction.SouthEast:
return "se";
case Direction.NorthWest:
return "nw";
case Direction.SouthWest:
return "sw";
default:
return "";
}
}
#endregion
#region constructor/destructor
public AnimatedSprite(string name, AnimationCollection collection, IResourceManager resourceManager)
{
AnimationStates = new Dictionary<string, AnimationState>();
Name = name;
LoadSprites(collection, resourceManager);
if (AnimationStates.ContainsKey("idle"))
SetAnimationState("idle");
SetLoop(true);
SetCurrentSprite();
//IoCManager.Resolve<IResourceManager>().
}
#endregion
}
}
using GorgonLibrary.Graphics;
using SS14.Client.Interfaces.Resource;
using SS14.Shared;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace SS14.Client.Graphics
{
public class AnimatedSprite
{
#region Public Properties
public string Name { get; set; }
public Dictionary<string, AnimationState> AnimationStates { get; private set; }
private AnimationState _currentAnimationState;
public string CurrentAnimationStateKey
{
get
{
if (_currentAnimationState != null)
return _currentAnimationState.Name;
return null;
}
}
public string BaseName { get; set; }
public Direction Direction
{
get { return _direction; }
set
{
_direction = value;
UpdateDirection();
}
}
public RectangleF AverageAABB
{
get
{
if (_currentSprite != null)
return _averageAABBs[_currentAnimationState.Name][Direction];
return RectangleF.Empty;
}
}
#region Sprite passthrough methods
public RectangleF AABB
{
get
{
if (_currentSprite != null)
return _currentSprite.AABB;
return RectangleF.Empty;
}
}
public bool HorizontalFlip
{
get
{
if (_currentSprite != null) return _currentSprite.HorizontalFlip;
return false;
}
set
{
if (_currentSprite != null)
_currentSprite.HorizontalFlip = value;
}
}
#endregion
#endregion
#region Variables
/// <summary>
/// Dictionary of animation names to directional sprite set
/// </summary>
private Dictionary<string, Dictionary<Direction, Sprite[]>> _sprites = new Dictionary<string, Dictionary<Direction, Sprite[]>>();
private Dictionary<string, Dictionary<Direction, RectangleF>> _averageAABBs = new Dictionary<string, Dictionary<Direction, RectangleF>>();
private Sprite _currentSprite;
private Direction _direction = Direction.South;
#endregion
#region Methods
//Todo encapsulate this further down as components -- AnimatedSpriteState, AnimatedSpriteStateDirection
public void LoadSprites(AnimationCollection collection, IResourceManager resourceManager)
{
float x = 0, y = 0, h = 0, w = 0;
int t = 0;
foreach (var info in collection.Animations)
{
_sprites.Add(info.Name, new Dictionary<Direction, Sprite[]>());
//Because we have a shitload of frames, we're going to store the average size as the AABB for each direction and each animation
_averageAABBs.Add(info.Name, new Dictionary<Direction, RectangleF>());
var sprites = _sprites[info.Name];
var averageAABBs = _averageAABBs[info.Name];
AnimationStates.Add(info.Name, new AnimationState(info));
foreach (var dir in Enum.GetValues(typeof(Direction)).Cast<Direction>())
{
sprites.Add(dir, new Sprite[info.Frames]);
var thisDirSprites = sprites[dir];
for (var i = 0; i < info.Frames; i++)
{
var spritename = collection.Name.ToLowerInvariant() + "_" + info.Name.ToLowerInvariant() + "_"
+ DirectionToUriComponent(dir) + "_" + i;
thisDirSprites[i] = resourceManager.GetSprite(spritename);
x += thisDirSprites[i].AABB.X;
y += thisDirSprites[i].AABB.Y;
w += thisDirSprites[i].AABB.Width;
h += thisDirSprites[i].AABB.Height;
t++;
}
averageAABBs.Add(dir, new RectangleF(x / t, y / t, w / t, h / t));
t = 0;
x = 0;
y = 0;
w = 0;
h = 0;
}
}
}
public Sprite GetCurrentSprite()
{
return _currentSprite;
}
public void Draw()
{
_currentSprite.Draw();
}
public void SetPosition(float x, float y)
{
_currentSprite.SetPosition(x, y);
}
private void UpdateDirection()
{
SetCurrentSprite();
}
public void SetAnimationState(string state)
{
if (_currentAnimationState != null)
{
//Dont change the state to the current state or we'll be stuck always on the first frame :(
if (_currentAnimationState.Name == state)
return;
_currentAnimationState.Reset();
}
if (state != null)
{
_currentAnimationState = AnimationStates[state];
_currentAnimationState.Enabled = true;
}
}
private void SetCurrentSprite()
{
_currentSprite = _sprites[_currentAnimationState.Name][Direction][_currentAnimationState.CurrentFrame];
}
public void SetLoop(bool loop)
{
_currentAnimationState.Loop = loop;
}
public void Update(float time)
{
_currentAnimationState.AddTime(time);
SetCurrentSprite();
}
public static string DirectionToUriComponent(Direction dir)
{
switch (dir)
{
case Direction.East:
return "e";
case Direction.West:
return "w";
case Direction.North:
return "n";
case Direction.South:
return "s";
case Direction.NorthEast:
return "ne";
case Direction.SouthEast:
return "se";
case Direction.NorthWest:
return "nw";
case Direction.SouthWest:
return "sw";
default:
return "";
}
}
#endregion
#region Constructor
public AnimatedSprite(string name, AnimationCollection collection, IResourceManager resourceManager)
{
AnimationStates = new Dictionary<string, AnimationState>();
Name = name;
LoadSprites(collection, resourceManager);
if (AnimationStates.ContainsKey("idle"))
SetAnimationState("idle");
SetLoop(true);
SetCurrentSprite();
//IoCManager.Resolve<IResourceManager>().
}
#endregion
}
}

View File

@@ -1,19 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SS13.Graphics
{
[Serializable]
public class AnimationCollection
{
public string Name { get; set; }
public List<AnimationInfo> Animations { get; set; }
public AnimationCollection()
{
Animations = new List<AnimationInfo>();
}
}
}
using System;
using System.Collections.Generic;
namespace SS14.Client.Graphics
{
[Serializable]
public class AnimationCollection
{
public string Name { get; set; }
public List<AnimationInfo> Animations { get; set; }
public AnimationCollection()
{
Animations = new List<AnimationInfo>();
}
}
}

View File

@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SS13.Graphics
{
[Serializable]
public class AnimationInfo
{
public string Name { get; set; }
public int Frames { get; set; }
public int FPS { get; set; }
}
}
using System;
namespace SS14.Client.Graphics
{
[Serializable]
public class AnimationInfo
{
public string Name { get; set; }
public int Frames { get; set; }
public int FPS { get; set; }
}
}

View File

@@ -1,45 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SS13_Shared;
namespace SS13.Graphics
{
public class AnimationState
{
private AnimationInfo _info;
public int CurrentFrame { get; private set; }
public float CurrentTime { get; private set; }
public float MaxTime { get { return ((float)1/_info.FPS)*(_info.Frames-1); } }
public bool Loop { get; set; }
public bool Enabled { get; set; }
public string Name { get { return _info.Name; } }
public AnimationState(AnimationInfo info)
{
_info = info;
}
public void Reset()
{
CurrentTime = 0;
Enabled = false;
Loop = false;
CurrentFrame = 0;
}
public void AddTime(float time)
{
CurrentTime += time;
if (CurrentTime >= MaxTime)
{
if (Loop)
CurrentTime -= MaxTime;
else
CurrentTime = MaxTime;
}
CurrentFrame = (int)Math.Floor(CurrentTime*_info.FPS);
}
}
}
using System;
namespace SS14.Client.Graphics
{
public class AnimationState
{
private AnimationInfo _info;
public int CurrentFrame { get; private set; }
public float CurrentTime { get; private set; }
public float MaxTime { get { return ((float)1/_info.FPS)*(_info.Frames-1); } }
public bool Loop { get; set; }
public bool Enabled { get; set; }
public string Name { get { return _info.Name; } }
public AnimationState(AnimationInfo info)
{
_info = info;
}
public void Reset()
{
CurrentTime = 0;
Enabled = false;
Loop = false;
CurrentFrame = 0;
}
public void AddTime(float time)
{
CurrentTime += time;
if (CurrentTime >= MaxTime)
{
if (Loop)
CurrentTime -= MaxTime;
else
CurrentTime = MaxTime;
}
CurrentFrame = (int)Math.Floor(CurrentTime*_info.FPS);
}
}
}

View File

@@ -1,36 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Graphics")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Graphics")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("fe23089c-5e14-496a-a2b8-ae31dcc45cf4")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SS14.Client.Graphics")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SS14.Client.Graphics")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("fe23089c-5e14-496a-a2b8-ae31dcc45cf4")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -1,4 +1,4 @@
<Project frameworkVersion="v4_0" name="SS13.Graphics" rootNamespace="SS13.Graphics" type="Library" path="SS13.Graphics">
<Project frameworkVersion="v4_0" name="SS14.Client.Graphics" rootNamespace="SS14.Client.Graphics" type="Library" path="SS14.Client.Graphics">
<Configuration name="Debug" platform="x86">
<Options>
<OutputPath>../Bin</OutputPath>
@@ -27,7 +27,7 @@
<File buildAction="Compile">AnimationState.cs</File>
<File buildAction="Compile">Properties/AssemblyInfo.cs</File>
</Files>
<Reference name="ClientInterfaces"/>
<Reference name="SS13.IoC"/>
<Reference name="SS13_Shared"/>
<Reference name="SS14.Client.Interfaces"/>
<Reference name="SS14.Shared.IoC"/>
<Reference name="SS14.Shared"/>
</Project>

View File

@@ -1,12 +1,12 @@
using System.Drawing;
using GameObject;
namespace ClientInterfaces.Collision
{
public interface ICollidable
{
RectangleF AABB { get; }
bool IsHardCollidable { get; } // true if collisions should prevent movement, or just trigger bumps.
void Bump(Entity ent);
}
using SS14.Shared.GameObjects;
using System.Drawing;
namespace SS14.Client.Interfaces.Collision
{
public interface ICollidable
{
RectangleF AABB { get; }
bool IsHardCollidable { get; } // true if collisions should prevent movement, or just trigger bumps.
void Bump(Entity ent);
}
}

View File

@@ -1,9 +1,9 @@
using System.Drawing;
namespace ClientInterfaces.Collision
{
public interface ICollider
{
RectangleF AABB { get; }
}
using System.Drawing;
namespace SS14.Client.Interfaces.Collision
{
public interface ICollider
{
RectangleF AABB { get; }
}
}

View File

@@ -1,23 +1,23 @@
using System.Drawing;
using GameObject;
using GorgonLibrary;
namespace ClientInterfaces.Collision
{
public interface ICollisionManager
{
/// <summary>
/// Checks to see if the specified collision rectangle collides with any of the colliders under management.
/// Also fires the OnCollide event of the first managed collidable to intersect with the collider.
/// </summary>
/// <param name="collider">Collision rectangle to check</param>
/// <returns>true if collides, false if not</returns>
bool IsColliding(RectangleF collider);
bool TryCollide(Entity collider);
bool TryCollide(Entity collider, Vector2D offset, bool bump = true);
void AddCollidable(ICollidable collidable);
void RemoveCollidable(ICollidable collidable);
void UpdateCollidable(ICollidable collidable);
}
using GorgonLibrary;
using SS14.Shared.GameObjects;
using System.Drawing;
namespace SS14.Client.Interfaces.Collision
{
public interface ICollisionManager
{
/// <summary>
/// Checks to see if the specified collision rectangle collides with any of the colliders under management.
/// Also fires the OnCollide event of the first managed collidable to intersect with the collider.
/// </summary>
/// <param name="collider">Collision rectangle to check</param>
/// <returns>true if collides, false if not</returns>
bool IsColliding(RectangleF collider);
bool TryCollide(Entity collider);
bool TryCollide(Entity collider, Vector2D offset, bool bump = true);
void AddCollidable(ICollidable collidable);
void RemoveCollidable(ICollidable collidable);
void UpdateCollidable(ICollidable collidable);
}
}

View File

@@ -1,32 +1,32 @@
namespace ClientInterfaces.Configuration
{
public interface IConfigurationManager
{
void Initialize(string configFile);
void SetPlayerName(string name);
void SetServerAddress(string address);
void SetFullscreen(bool fullscreen);
void SetResolution(uint width, uint height);
string GetPlayerName();
string GetResourcePath();
string GetResourcePassword();
bool GetFullscreen();
bool GetVsync();
void SetVsync(bool state);
uint GetDisplayWidth();
uint GetDisplayHeight();
uint GetDisplayRefresh();
void SetDisplayRefresh(uint rate);
string GetServerAddress();
bool GetMessageLogging();
bool GetSimulateLatency();
float GetSimulatedLoss();
float GetSimulatedMinimumLatency();
float GetSimulatedRandomLatency();
int GetRate();
int GetUpdateRate();
int GetCommandRate();
char GetConsoleKey();
float GetInterpolation();
}
namespace SS14.Client.Interfaces.Configuration
{
public interface IConfigurationManager
{
void Initialize(string configFile);
void SetPlayerName(string name);
void SetServerAddress(string address);
void SetFullscreen(bool fullscreen);
void SetResolution(uint width, uint height);
string GetPlayerName();
string GetResourcePath();
string GetResourcePassword();
bool GetFullscreen();
bool GetVsync();
void SetVsync(bool state);
uint GetDisplayWidth();
uint GetDisplayHeight();
uint GetDisplayRefresh();
void SetDisplayRefresh(uint rate);
string GetServerAddress();
bool GetMessageLogging();
bool GetSimulateLatency();
float GetSimulatedLoss();
float GetSimulatedMinimumLatency();
float GetSimulatedRandomLatency();
int GetRate();
int GetUpdateRate();
int GetCommandRate();
char GetConsoleKey();
float GetInterpolation();
}
}

View File

@@ -1,16 +1,16 @@
using System;
using System.Collections.Generic;
using SS13_Shared.GO;
namespace ClientInterfaces.GOC
{
public class GetSVarsEventArgs : EventArgs
{
public List<MarshalComponentParameter> SVars;
public GetSVarsEventArgs(List<MarshalComponentParameter> sVars)
{
SVars = sVars;
}
}
using SS14.Shared.GO;
using System;
using System.Collections.Generic;
namespace SS14.Client.Interfaces.GOC
{
public class GetSVarsEventArgs : EventArgs
{
public List<MarshalComponentParameter> SVars;
public GetSVarsEventArgs(List<MarshalComponentParameter> sVars)
{
SVars = sVars;
}
}
}

View File

@@ -1,30 +1,30 @@
using System;
using System.Collections.Generic;
using GorgonLibrary;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
namespace ClientInterfaces.GOC
{
public interface IEntity : GameObject.IEntity
{
IEntityTemplate Template { get; set; }
int Uid { get; set; }
bool Initialized { get; set; }
event EventHandler<VectorEventArgs> OnMove;
string GetDescriptionString();
void Initialize();
void SendMessage(object sender, ComponentMessageType type, List<ComponentReplyMessage> replies, params object[] args);
void SendMessage(object sender, ComponentMessageType type, params object[] args);
ComponentReplyMessage SendMessage(object sender, ComponentFamily family, ComponentMessageType type, params object[] args);
void SendComponentNetworkMessage(IGameObjectComponent component, NetDeliveryMethod method, params object[] messageParams);
void SendComponentInstantiationMessage(IGameObjectComponent component);
void HandleNetworkMessage(IncomingEntityMessage message);
void GetSVars();
void SetSVar(MarshalComponentParameter svar);
event EventHandler<GetSVarsEventArgs> GetSVarsCallback;
Vector2D Velocity { get; set; }
void HandleEntityState(EntityState state);
}
}
using System;
using System.Collections.Generic;
using GorgonLibrary;
using Lidgren.Network;
using SS13_Shared;
using SS13_Shared.GO;
namespace ClientInterfaces.GOC
{
public interface IEntity : GameObject.IEntity
{
IEntityTemplate Template { get; set; }
int Uid { get; set; }
bool Initialized { get; set; }
event EventHandler<VectorEventArgs> OnMove;
string GetDescriptionString();
void Initialize();
void SendMessage(object sender, ComponentMessageType type, List<ComponentReplyMessage> replies, params object[] args);
void SendMessage(object sender, ComponentMessageType type, params object[] args);
ComponentReplyMessage SendMessage(object sender, ComponentFamily family, ComponentMessageType type, params object[] args);
void SendComponentNetworkMessage(IGameObjectComponent component, NetDeliveryMethod method, params object[] messageParams);
void SendComponentInstantiationMessage(IGameObjectComponent component);
void HandleNetworkMessage(IncomingEntityMessage message);
void GetSVars();
void SetSVar(MarshalComponentParameter svar);
event EventHandler<GetSVarsEventArgs> GetSVarsCallback;
Vector2D Velocity { get; set; }
void HandleEntityState(EntityState state);
}
}

View File

@@ -1,9 +1,9 @@
using GameObject;
namespace ClientInterfaces.GOC
{
public interface IEntityManagerContainer
{
EntityManager EntityManager { get; set; }
}
using SS14.Shared.GameObjects;
namespace SS14.Client.Interfaces.GOC
{
public interface IEntityManagerContainer
{
EntityManager EntityManager { get; set; }
}
}

View File

@@ -1,17 +1,17 @@
using System.Collections.Generic;
using SS13_Shared.GO;
using SS13_Shared;
namespace ClientInterfaces.GOC
{
public interface IEntityTemplate
{
string Name { get; set; }
string Description { get; }
List<int> MountingPoints { get; }
KeyValuePair<int, int> PlacementOffset { get; }
string PlacementMode { get; }
IEnumerable<ComponentParameter> GetBaseSpriteParamaters();
}
}
using System.Collections.Generic;
using SS13_Shared.GO;
using SS13_Shared;
namespace ClientInterfaces.GOC
{
public interface IEntityTemplate
{
string Name { get; set; }
string Description { get; }
List<int> MountingPoints { get; }
KeyValuePair<int, int> PlacementOffset { get; }
string PlacementMode { get; }
IEnumerable<ComponentParameter> GetBaseSpriteParamaters();
}
}

View File

@@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using SS13_Shared;
using SS13_Shared.GO;
namespace ClientInterfaces.GOC
{
public interface IGameObjectComponent: GameObject.IComponent
{
//void RecieveMessage(object sender, ComponentMessageType type, List<ComponentReplyMessage> replies, params object[] list);
Type StateType { get; }
void HandleComponentState(dynamic compState);
}
}
using System;
using System.Collections.Generic;
using SS13_Shared;
using SS13_Shared.GO;
namespace ClientInterfaces.GOC
{
public interface IGameObjectComponent: GameObject.IComponent
{
//void RecieveMessage(object sender, ComponentMessageType type, List<ComponentReplyMessage> replies, params object[] list);
Type StateType { get; }
void HandleComponentState(dynamic compState);
}
}

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameObject;
namespace ServerInterfaces.GOC
{
public interface IParticleSystemComponent : IComponent
{
void AddParticleSystem(string name, bool active);
void RemoveParticleSystem(string name);
void SetParticleSystemActive(string name, bool active);
}
}
using SS14.Shared.GameObjects;
namespace SS14.Client.Interfaces.GOC
{
public interface IParticleSystemComponent : IComponent
{
void AddParticleSystem(string name, bool active);
void RemoveParticleSystem(string name);
void SetParticleSystemActive(string name, bool active);
}
}

View File

@@ -1,17 +1,17 @@
using System;
using SS13_Shared;
namespace ClientInterfaces.GOC
{
public interface IPlayerAction
{
PlayerActionTargetType TargetType { get; }
string Icon { get; }
string Name { get; }
string Description { get; }
DateTime CooldownExpires { get; set; }
uint Uid { get; }
void Activate();
void Use(object target);
}
using SS14.Shared;
using System;
namespace SS14.Client.Interfaces.GOC
{
public interface IPlayerAction
{
PlayerActionTargetType TargetType { get; }
string Icon { get; }
string Name { get; }
string Description { get; }
DateTime CooldownExpires { get; set; }
uint Uid { get; }
void Activate();
void Use(object target);
}
}

View File

@@ -1,21 +1,21 @@
using System.Drawing;
using GameObject;
using GorgonLibrary;
using SS13_Shared.GO;
namespace ClientInterfaces.GOC
{
public interface IRenderableComponent : IComponent
{
DrawDepth DrawDepth { get; set; }
float Bottom { get; }
void Render(Vector2D topLeft, Vector2D bottomRight);
RectangleF AABB { get; }
RectangleF AverageAABB { get; }
bool IsSlaved();
void SetMaster(Entity m);
void UnsetMaster();
void AddSlave(IRenderableComponent slavecompo);
void RemoveSlave(IRenderableComponent slavecompo);
}
using GorgonLibrary;
using SS14.Shared.GameObjects;
using SS14.Shared.GO;
using System.Drawing;
namespace SS14.Client.Interfaces.GOC
{
public interface IRenderableComponent : IComponent
{
DrawDepth DrawDepth { get; set; }
float Bottom { get; }
void Render(Vector2D topLeft, Vector2D bottomRight);
RectangleF AABB { get; }
RectangleF AverageAABB { get; }
bool IsSlaved();
void SetMaster(Entity m);
void UnsetMaster();
void AddSlave(IRenderableComponent slavecompo);
void RemoveSlave(IRenderableComponent slavecompo);
}
}

View File

@@ -1,12 +1,12 @@
using System;
using SS13_Shared.GO;
namespace ClientInterfaces.GOC
{
public interface ISVarsComponent
{
event EventHandler<GetSVarsEventArgs> GetSVarsCallback;
void DoSetSVar(MarshalComponentParameter svar);
void DoGetSVars();
}
using SS14.Shared.GO;
using System;
namespace SS14.Client.Interfaces.GOC
{
public interface ISVarsComponent
{
event EventHandler<GetSVarsEventArgs> GetSVarsCallback;
void DoSetSVar(MarshalComponentParameter svar);
void DoGetSVars();
}
}

View File

@@ -1,17 +1,17 @@
using System.Collections.Generic;
using System.Drawing;
using GorgonLibrary.Graphics;
namespace ClientInterfaces.GOC
{
public interface ISpriteComponent
{
RectangleF AABB { get; }
Sprite GetCurrentSprite();
Sprite GetSprite(string spriteKey);
List<Sprite> GetAllSprites();
void SetSpriteByKey(string spriteKey);
void AddSprite(string spriteKey);
void AddSprite(string key, Sprite spritetoadd);
}
using GorgonLibrary.Graphics;
using System.Collections.Generic;
using System.Drawing;
namespace SS14.Client.Interfaces.GOC
{
public interface ISpriteComponent
{
RectangleF AABB { get; }
Sprite GetCurrentSprite();
Sprite GetSprite(string spriteKey);
List<Sprite> GetAllSprites();
void SetSpriteByKey(string spriteKey);
void AddSprite(string spriteKey);
void AddSprite(string key, Sprite spritetoadd);
}
}

View File

@@ -1,12 +1,12 @@
using System.Collections.Generic;
using SS13_Shared.GameStates;
namespace ClientInterfaces.GameStates
{
public interface IGameStateManager : IDictionary<uint, GameState>
{
uint OldestStateAcked { get; }
void Cull();
void Ack(long uniqueIdentifier, uint state);
}
using SS14.Shared.GameStates;
using System.Collections.Generic;
namespace SS14.Client.Interfaces.GameStates
{
public interface IGameStateManager : IDictionary<uint, GameState>
{
uint OldestStateAcked { get; }
void Cull();
void Ack(long uniqueIdentifier, uint state);
}
}

View File

@@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClientInterfaces.GameTimer
{
public interface IGameTimer
{
float CurrentTime { get; }
void UpdateTime(float delta);
void SetTime(float time);
}
}

namespace SS14.Client.Interfaces.GameTimer
{
public interface IGameTimer
{
float CurrentTime { get; }
void UpdateTime(float delta);
void SetTime(float time);
}
}

View File

@@ -1,15 +1,15 @@
using System;
using GorgonLibrary.InputDevices;
using SS13_Shared;
namespace ClientInterfaces.Input
{
public interface IKeyBindingManager
{
bool Enabled { get; set; }
void Initialize(Keyboard keyboard);
event EventHandler<BoundKeyEventArgs> BoundKeyDown;
event EventHandler<BoundKeyEventArgs> BoundKeyUp;
}
using GorgonLibrary.InputDevices;
using SS14.Shared;
using System;
namespace SS14.Client.Interfaces.Input
{
public interface IKeyBindingManager
{
bool Enabled { get; set; }
void Initialize(Keyboard keyboard);
event EventHandler<BoundKeyEventArgs> BoundKeyDown;
event EventHandler<BoundKeyEventArgs> BoundKeyUp;
}
}

View File

@@ -1,26 +1,26 @@
using System.Drawing;
using GorgonLibrary;
using SS13_Shared;
namespace ClientInterfaces.Lighting
{
public interface ILight
{
int Radius { get; }
Color Color { get; }
Vector2D Position { get; }
LightState LightState { get; }
ILightArea LightArea { get; }
LightMode LightMode { get; set; }
void Move(Vector2D toPosition);
void SetRadius(int Radius);
void SetColor(int a, int r, int g, int b);
void SetColor(Color color);
void Update(float frametime);
void SetMask(string _mask);
Vector4D GetColorVec();
void SetState(LightState state);
}
using GorgonLibrary;
using SS14.Shared;
using System.Drawing;
namespace SS14.Client.Interfaces.Lighting
{
public interface ILight
{
int Radius { get; }
Color Color { get; }
Vector2D Position { get; }
LightState LightState { get; }
ILightArea LightArea { get; }
LightMode LightMode { get; set; }
void Move(Vector2D toPosition);
void SetRadius(int Radius);
void SetColor(int a, int r, int g, int b);
void SetColor(Color color);
void Update(float frametime);
void SetMask(string _mask);
Vector4D GetColorVec();
void SetState(LightState state);
}
}

View File

@@ -1,23 +1,23 @@
using GorgonLibrary;
using GorgonLibrary.Graphics;
namespace ClientInterfaces.Lighting
{
public interface ILightArea
{
RenderImage renderTarget { get; }
Vector2D LightPosition { get; set; }
Vector2D LightAreaSize { get; set; }
bool Calculated { get; set; }
Sprite Mask { get; set; }
bool MaskFlipX { get; set; }
bool MaskFlipY { get; set; }
bool Rot90 { get; set; }
Vector4D MaskProps { get; }
Vector2D ToRelativePosition(Vector2D worldPosition);
void BeginDrawingShadowCasters();
void EndDrawingShadowCasters();
void SetMask(string mask);
}
using GorgonLibrary;
using GorgonLibrary.Graphics;
namespace SS14.Client.Interfaces.Lighting
{
public interface ILightArea
{
RenderImage renderTarget { get; }
Vector2D LightPosition { get; set; }
Vector2D LightAreaSize { get; set; }
bool Calculated { get; set; }
Sprite Mask { get; set; }
bool MaskFlipX { get; set; }
bool MaskFlipY { get; set; }
bool Rot90 { get; set; }
Vector4D MaskProps { get; }
Vector2D ToRelativePosition(Vector2D worldPosition);
void BeginDrawingShadowCasters();
void EndDrawingShadowCasters();
void SetMask(string mask);
}
}

Some files were not shown because too many files have changed in this diff Show More