HandsSystem now uses InputSystem. (#95)
Fixed TemperatureSystem namespace.
This commit is contained in:
@@ -94,11 +94,12 @@
|
|||||||
<Compile Include="GameObjects\EntitySystems\Click\ExamineSystem.cs" />
|
<Compile Include="GameObjects\EntitySystems\Click\ExamineSystem.cs" />
|
||||||
<Compile Include="GameObjects\EntitySystems\Click\InteractionSystem.cs" />
|
<Compile Include="GameObjects\EntitySystems\Click\InteractionSystem.cs" />
|
||||||
<Compile Include="GameObjects\EntitySystems\DoorSystem.cs" />
|
<Compile Include="GameObjects\EntitySystems\DoorSystem.cs" />
|
||||||
|
<Compile Include="GameObjects\EntitySystems\HandsSystem.cs" />
|
||||||
<Compile Include="GameObjects\EntitySystems\PowerApcSystem.cs" />
|
<Compile Include="GameObjects\EntitySystems\PowerApcSystem.cs" />
|
||||||
<Compile Include="GameObjects\EntitySystems\PowerSmesSystem.cs" />
|
<Compile Include="GameObjects\EntitySystems\PowerSmesSystem.cs" />
|
||||||
<Compile Include="GameObjects\EntitySystems\PowerSystem.cs" />
|
<Compile Include="GameObjects\EntitySystems\PowerSystem.cs" />
|
||||||
<Compile Include="GameObjects\EntitySystems\WelderSystem.cs" />
|
<Compile Include="GameObjects\EntitySystems\WelderSystem.cs" />
|
||||||
<Compile Include="GameObjects\TemperatureSystem.cs" />
|
<Compile Include="GameObjects\EntitySystems\TemperatureSystem.cs" />
|
||||||
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs" />
|
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs" />
|
||||||
<Compile Include="GameObjects\Components\GUI\ServerHandsComponent.cs" />
|
<Compile Include="GameObjects\Components\GUI\ServerHandsComponent.cs" />
|
||||||
<Compile Include="GameObjects\Components\GUI\InventoryComponent.cs" />
|
<Compile Include="GameObjects\Components\GUI\InventoryComponent.cs" />
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ using SS14.Shared.Interfaces.GameObjects;
|
|||||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||||
using SS14.Shared.Interfaces.Network;
|
using SS14.Shared.Interfaces.Network;
|
||||||
using SS14.Shared.IoC;
|
using SS14.Shared.IoC;
|
||||||
using SS14.Shared.Players;
|
|
||||||
using SS14.Shared.Serialization;
|
using SS14.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects
|
namespace Content.Server.GameObjects
|
||||||
@@ -43,10 +42,6 @@ namespace Content.Server.GameObjects
|
|||||||
// Mostly arbitrary.
|
// Mostly arbitrary.
|
||||||
public const float PICKUP_RANGE = 2;
|
public const float PICKUP_RANGE = 2;
|
||||||
|
|
||||||
private InputCmdHandler _swapHandsCmdHandler;
|
|
||||||
private InputCmdHandler _dropCmdHandler;
|
|
||||||
private InputCmdHandler _activateItemInHandCmdHandler;
|
|
||||||
|
|
||||||
public override void ExposeData(ObjectSerializer serializer)
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
base.ExposeData(serializer);
|
base.ExposeData(serializer);
|
||||||
@@ -251,7 +246,7 @@ namespace Content.Server.GameObjects
|
|||||||
return new HandsComponentState(dict, ActiveIndex);
|
return new HandsComponentState(dict, ActiveIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SwapHands(ICommonSession channel)
|
public void SwapHands()
|
||||||
{
|
{
|
||||||
var index = orderedHands.FindIndex(x => x == ActiveIndex);
|
var index = orderedHands.FindIndex(x => x == ActiveIndex);
|
||||||
index++;
|
index++;
|
||||||
@@ -263,6 +258,15 @@ namespace Content.Server.GameObjects
|
|||||||
ActiveIndex = orderedHands[index];
|
ActiveIndex = orderedHands[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ActivateItem()
|
||||||
|
{
|
||||||
|
var used = GetActiveHand?.Owner;
|
||||||
|
if (used != null)
|
||||||
|
{
|
||||||
|
InteractionSystem.TryUseInteraction(Owner, used);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
|
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
|
||||||
{
|
{
|
||||||
base.HandleMessage(message, netChannel, component);
|
base.HandleMessage(message, netChannel, component);
|
||||||
@@ -294,42 +298,7 @@ namespace Content.Server.GameObjects
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Boundkeychangedmsg only works for the player entity and doesn't need any extra verification
|
|
||||||
case PlayerAttachedMsg msg:
|
|
||||||
InitInputCommands();
|
|
||||||
input = msg.NewPlayer.Input;
|
|
||||||
input.SetCommand(ContentKeyFunctions.SwapHands, _swapHandsCmdHandler);
|
|
||||||
input.SetCommand(ContentKeyFunctions.Drop, _dropCmdHandler);
|
|
||||||
input.SetCommand(ContentKeyFunctions.ActivateItemInHand, _activateItemInHandCmdHandler);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PlayerDetachedMsg msg:
|
|
||||||
input = msg.OldPlayer.Input;
|
|
||||||
input.SetCommand(ContentKeyFunctions.SwapHands, null);
|
|
||||||
input.SetCommand(ContentKeyFunctions.Drop, null);
|
|
||||||
input.SetCommand(ContentKeyFunctions.ActivateItemInHand, null);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitInputCommands()
|
|
||||||
{
|
|
||||||
if (_swapHandsCmdHandler != null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_swapHandsCmdHandler = InputCmdHandler.FromDelegate(SwapHands);
|
|
||||||
_dropCmdHandler = InputCmdHandler.FromDelegate(session => Drop(ActiveIndex));
|
|
||||||
_activateItemInHandCmdHandler = InputCmdHandler.FromDelegate(session =>
|
|
||||||
{
|
|
||||||
var used = GetActiveHand?.Owner;
|
|
||||||
if (used != null)
|
|
||||||
{
|
|
||||||
InteractionSystem.TryUseInteraction(Owner, used);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
78
Content.Server/GameObjects/EntitySystems/HandsSystem.cs
Normal file
78
Content.Server/GameObjects/EntitySystems/HandsSystem.cs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
using Content.Shared.Input;
|
||||||
|
using SS14.Server.GameObjects.EntitySystems;
|
||||||
|
using SS14.Server.Interfaces.Player;
|
||||||
|
using SS14.Shared.GameObjects;
|
||||||
|
using SS14.Shared.GameObjects.Systems;
|
||||||
|
using SS14.Shared.Input;
|
||||||
|
using SS14.Shared.Players;
|
||||||
|
|
||||||
|
namespace Content.Server.GameObjects.EntitySystems
|
||||||
|
{
|
||||||
|
internal class HandsSystem : EntitySystem
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
var input = EntitySystemManager.GetEntitySystem<InputSystem>();
|
||||||
|
input.BindMap.BindFunction(ContentKeyFunctions.SwapHands, InputCmdHandler.FromDelegate(HandleSwapHands));
|
||||||
|
input.BindMap.BindFunction(ContentKeyFunctions.Drop, InputCmdHandler.FromDelegate(HandleDrop));
|
||||||
|
input.BindMap.BindFunction(ContentKeyFunctions.ActivateItemInHand, InputCmdHandler.FromDelegate(HandleActivateItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void Shutdown()
|
||||||
|
{
|
||||||
|
if (EntitySystemManager.TryGetEntitySystem(out InputSystem input))
|
||||||
|
{
|
||||||
|
input.BindMap.UnbindFunction(ContentKeyFunctions.SwapHands);
|
||||||
|
input.BindMap.UnbindFunction(ContentKeyFunctions.Drop);
|
||||||
|
input.BindMap.UnbindFunction(ContentKeyFunctions.ActivateItemInHand);
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool TryGetAttachedComponent<T>(IPlayerSession session, out T component)
|
||||||
|
where T : Component
|
||||||
|
{
|
||||||
|
component = default(T);
|
||||||
|
|
||||||
|
var ent = session.AttachedEntity;
|
||||||
|
|
||||||
|
if (ent == null || !ent.IsValid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!ent.TryGetComponent(out T comp))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
component = comp;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void HandleSwapHands(ICommonSession session)
|
||||||
|
{
|
||||||
|
if (!TryGetAttachedComponent(session as IPlayerSession, out HandsComponent handsComp))
|
||||||
|
return;
|
||||||
|
|
||||||
|
handsComp.SwapHands();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void HandleDrop(ICommonSession session)
|
||||||
|
{
|
||||||
|
if (!TryGetAttachedComponent(session as IPlayerSession, out HandsComponent handsComp))
|
||||||
|
return;
|
||||||
|
|
||||||
|
handsComp.Drop(handsComp.ActiveIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void HandleActivateItem(ICommonSession session)
|
||||||
|
{
|
||||||
|
if (!TryGetAttachedComponent(session as IPlayerSession, out HandsComponent handsComp))
|
||||||
|
return;
|
||||||
|
|
||||||
|
handsComp.ActivateItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using SS14.Shared.GameObjects;
|
using SS14.Shared.GameObjects;
|
||||||
using SS14.Shared.GameObjects.Systems;
|
using SS14.Shared.GameObjects.Systems;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects
|
namespace Content.Server.GameObjects.EntitySystems
|
||||||
{
|
{
|
||||||
class TemperatureSystem : EntitySystem
|
class TemperatureSystem : EntitySystem
|
||||||
{
|
{
|
||||||
Reference in New Issue
Block a user