Examine System (#65)

* Examine System

* Adds some relevant comments
This commit is contained in:
clusterfack
2018-05-09 09:34:26 -05:00
committed by Pieter-Jan Briers
parent 61a1e769d7
commit 3915b735ae
14 changed files with 148 additions and 5 deletions

View File

@@ -3,13 +3,14 @@ using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Utility;
using YamlDotNet.RepresentationModel;
using SS14.Server.GameObjects;
using Content.Server.GameObjects.EntitySystems;
namespace Content.Server.GameObjects.Components.Interactable.Tools
{
/// <summary>
/// Tool used to weld metal together, light things on fire, or melt into constituent parts
/// </summary>
class WelderComponent : ToolComponent, EntitySystems.IUse
class WelderComponent : ToolComponent, EntitySystems.IUse, EntitySystems.IExamine
{
SpriteComponent spriteComponent;
@@ -138,5 +139,14 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools
return false;
}
}
string IExamine.Examine()
{
if(Activated)
{
return "The welding tool is currently lit";
}
return null;
}
}
}

View File

@@ -1,4 +1,5 @@
using SS14.Server.GameObjects;
using Content.Server.GameObjects.EntitySystems;
using SS14.Server.GameObjects;
using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.IoC;
@@ -12,7 +13,7 @@ namespace Content.Server.GameObjects.Components.Power
/// <summary>
/// Component that requires power to function
/// </summary>
public class PowerDeviceComponent : Component
public class PowerDeviceComponent : Component, EntitySystems.IExamine
{
public override string Name => "PowerDevice";
@@ -134,6 +135,15 @@ namespace Content.Server.GameObjects.Components.Power
}
}
string IExamine.Examine()
{
if(!Powered)
{
return "The device is not powered";
}
return null;
}
private void UpdateLoad(float value)
{
var oldLoad = _load;

View File

@@ -59,7 +59,7 @@ namespace Content.Server.GameObjects.EntitySystems
EntitySystemManager.GetEntitySystem<InteractionSystem>().UserInteraction(message, player);
break;
case (ClickType.Left | ClickType.Shift):
//Examine system
EntitySystemManager.GetEntitySystem<ExamineSystem>().Examine(message, player);
break;
case ClickType.Right:
//Verb System

View File

@@ -0,0 +1,71 @@
using SS14.Server.Interfaces.Chat;
using SS14.Server.Interfaces.GameObjects;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.System;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.IoC;
using SS14.Shared.Log;
using System;
using System.Text;
namespace Content.Server.GameObjects.EntitySystems
{
public interface IExamine
{
/// <summary>
/// Returns an status examine value for components appended to the end of the description of the entity
/// </summary>
/// <returns></returns>
string Examine();
}
public class ExamineSystem : EntitySystem
{
public void Examine(ClickEventMessage msg, IEntity player)
{
//Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null
IEntity examined = null;
if (msg.Uid.IsValid())
examined = EntityManager.GetEntity(msg.Uid);
if (examined == null)
return;
//Verify player has a transform component
if (!player.TryGetComponent<IServerTransformComponent>(out var playerTransform))
{
return;
}
//Verify player is on the same map as the entity he clicked on
else if (msg.Coordinates.MapID != playerTransform.MapID)
{
Logger.Warning(string.Format("Player named {0} clicked on a map he isn't located on", player.Name));
return;
}
//Start a stringbuilder since we have no idea how many times this could be appended to
StringBuilder fullexaminetext = new StringBuilder("This is " + examined.Name);
//Add an entity description if one is declared
if(!string.IsNullOrEmpty(examined.Description))
{
fullexaminetext.Append(Environment.NewLine + examined.Description);
}
//Add component statuses from components that report one
foreach (var examinecomponents in examined.GetComponents<IExamine>())
{
string componentdescription = examinecomponents.Examine();
if(!string.IsNullOrEmpty(componentdescription))
{
fullexaminetext.Append(Environment.NewLine + componentdescription);
}
}
//Send to client chat channel
//TODO: Fix fact you can only send to all clients because you cant resolve clients from player entities
IoCManager.Resolve<IChatManager>().DispatchMessage(SS14.Shared.Console.ChatChannel.Visual, fullexaminetext.ToString());
}
}
}