Wide attacks on space, remove UseOrAttack.

This commit is contained in:
Pieter-Jan Briers
2020-05-03 14:26:49 +02:00
parent 5d7514674e
commit e2677bab51
7 changed files with 21 additions and 131 deletions

View File

@@ -25,8 +25,6 @@ namespace Content.Client.GameObjects.EntitySystems
[UsedImplicitly] [UsedImplicitly]
public sealed class CombatModeSystem : SharedCombatModeSystem public sealed class CombatModeSystem : SharedCombatModeSystem
{ {
private const float AttackTimeThreshold = 0.15f;
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private readonly IGameHud _gameHud; [Dependency] private readonly IGameHud _gameHud;
[Dependency] private readonly IPlayerManager _playerManager; [Dependency] private readonly IPlayerManager _playerManager;
@@ -37,9 +35,6 @@ namespace Content.Client.GameObjects.EntitySystems
private InputSystem _inputSystem; private InputSystem _inputSystem;
public bool UseOrAttackIsDown { get; private set; }
private float _timeHeld;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -48,10 +43,8 @@ namespace Content.Client.GameObjects.EntitySystems
_gameHud.OnTargetingZoneChanged = OnTargetingZoneChanged; _gameHud.OnTargetingZoneChanged = OnTargetingZoneChanged;
_inputSystem = EntitySystemManager.GetEntitySystem<InputSystem>(); _inputSystem = EntitySystemManager.GetEntitySystem<InputSystem>();
_inputSystem.BindMap.BindFunction(ContentKeyFunctions.UseOrAttack, new InputHandler(this));
_inputSystem.BindMap.BindFunction(ContentKeyFunctions.ToggleCombatMode, _inputSystem.BindMap.BindFunction(ContentKeyFunctions.ToggleCombatMode,
InputCmdHandler.FromDelegate(CombatModeToggled)); InputCmdHandler.FromDelegate(CombatModeToggled));
_overlayManager.AddOverlay(new CombatModeOverlay(this));
} }
private void CombatModeToggled(ICommonSession session) private void CombatModeToggled(ICommonSession session)
@@ -60,20 +53,10 @@ namespace Content.Client.GameObjects.EntitySystems
{ {
EntityManager.RaisePredictiveEvent( EntityManager.RaisePredictiveEvent(
new CombatModeSystemMessages.SetCombatModeActiveMessage(!IsInCombatMode())); new CombatModeSystemMessages.SetCombatModeActiveMessage(!IsInCombatMode()));
// Just in case.
UseOrAttackIsDown = false;
} }
} }
public override void Shutdown() public bool IsInCombatMode()
{
base.Shutdown();
_overlayManager.RemoveOverlay(nameof(CombatModeOverlay));
}
private bool IsInCombatMode()
{ {
var entity = _playerManager.LocalPlayer.ControlledEntity; var entity = _playerManager.LocalPlayer.ControlledEntity;
if (entity == null || !entity.TryGetComponent(out CombatModeComponent combatMode)) if (entity == null || !entity.TryGetComponent(out CombatModeComponent combatMode))
@@ -92,104 +75,6 @@ namespace Content.Client.GameObjects.EntitySystems
private void OnCombatModeChanged(bool obj) private void OnCombatModeChanged(bool obj)
{ {
EntityManager.RaisePredictiveEvent(new CombatModeSystemMessages.SetCombatModeActiveMessage(obj)); EntityManager.RaisePredictiveEvent(new CombatModeSystemMessages.SetCombatModeActiveMessage(obj));
// Just in case.
UseOrAttackIsDown = false;
}
private bool HandleInputMessage(ICommonSession session, InputCmdMessage message)
{
if (!(message is FullInputCmdMessage msg))
return false;
void SendMsg(BoundKeyFunction function, BoundKeyState state)
{
var functionId = _inputManager.NetworkBindMap.KeyFunctionID(function);
var sendMsg = new FullInputCmdMessage(msg.Tick, functionId, state,
msg.Coordinates, msg.ScreenCoordinates, msg.Uid);
_inputSystem.HandleInputCommand(session, function, sendMsg);
}
// If we are not in combat mode, relay it as a regular Use instead.
if (!IsInCombatMode())
{
SendMsg(EngineKeyFunctions.Use, msg.State);
return true;
}
if (msg.State == BoundKeyState.Down)
{
UseOrAttackIsDown = true;
_timeHeld = 0;
return true;
}
// Up.
if (UseOrAttackIsDown && _timeHeld >= AttackTimeThreshold)
{
// Attack.
SendMsg(ContentKeyFunctions.Attack, BoundKeyState.Down);
SendMsg(ContentKeyFunctions.Attack, BoundKeyState.Up);
}
else
{
// Use.
SendMsg(EngineKeyFunctions.Use, BoundKeyState.Down);
SendMsg(EngineKeyFunctions.Use, BoundKeyState.Up);
}
UseOrAttackIsDown = false;
return true;
}
public override void FrameUpdate(float frameTime)
{
if (UseOrAttackIsDown)
{
_timeHeld += frameTime;
}
}
// Custom input handler type so we get the ENTIRE InputCmdMessage.
private sealed class InputHandler : InputCmdHandler
{
private readonly CombatModeSystem _combatModeSystem;
public InputHandler(CombatModeSystem combatModeSystem)
{
_combatModeSystem = combatModeSystem;
}
public override bool HandleCmdMessage(ICommonSession session, InputCmdMessage message)
{
return _combatModeSystem.HandleInputMessage(session, message);
}
}
private sealed class CombatModeOverlay : Overlay
{
private readonly CombatModeSystem _system;
public CombatModeOverlay(CombatModeSystem system) : base(nameof(CombatModeOverlay))
{
_system = system;
}
protected override void Draw(DrawingHandleBase handle)
{
var screenHandle = (DrawingHandleScreen) handle;
var mousePos = IoCManager.Resolve<IInputManager>().MouseScreenPosition;
if (_system.UseOrAttackIsDown && _system._timeHeld > AttackTimeThreshold)
{
var tex = ResC.GetTexture($"/Textures/Objects/Tools/toolbox_r.png");
screenHandle.DrawTextureRect(tex, UIBox2.FromDimensions(mousePos, tex.Size * 2));
}
}
} }
} }
} }

View File

@@ -39,8 +39,8 @@ namespace Content.Client.GameObjects.EntitySystems
base.Update(frameTime); base.Update(frameTime);
var canFireSemi = _isFirstShot; var canFireSemi = _isFirstShot;
var state = _inputSystem.CmdStates.GetState(ContentKeyFunctions.Attack); var state = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use);
if (!_combatModeSystem.UseOrAttackIsDown && state != BoundKeyState.Down) if (!_combatModeSystem.IsInCombatMode() && state != BoundKeyState.Down)
{ {
_isFirstShot = true; _isFirstShot = true;
_blocked = false; _blocked = false;

View File

@@ -15,7 +15,6 @@ namespace Content.Client.Input
common.AddFunction(ContentKeyFunctions.FocusChat); common.AddFunction(ContentKeyFunctions.FocusChat);
common.AddFunction(ContentKeyFunctions.ExamineEntity); common.AddFunction(ContentKeyFunctions.ExamineEntity);
common.AddFunction(ContentKeyFunctions.OpenTutorial); common.AddFunction(ContentKeyFunctions.OpenTutorial);
common.AddFunction(ContentKeyFunctions.UseOrAttack);
common.AddFunction(ContentKeyFunctions.TakeScreenshot); common.AddFunction(ContentKeyFunctions.TakeScreenshot);
common.AddFunction(ContentKeyFunctions.TakeScreenshotNoUI); common.AddFunction(ContentKeyFunctions.TakeScreenshotNoUI);
@@ -31,7 +30,7 @@ namespace Content.Client.Input
human.AddFunction(ContentKeyFunctions.OpenInventoryMenu); human.AddFunction(ContentKeyFunctions.OpenInventoryMenu);
human.AddFunction(ContentKeyFunctions.MouseMiddle); human.AddFunction(ContentKeyFunctions.MouseMiddle);
human.AddFunction(ContentKeyFunctions.ToggleCombatMode); human.AddFunction(ContentKeyFunctions.ToggleCombatMode);
human.AddFunction(ContentKeyFunctions.Attack); human.AddFunction(ContentKeyFunctions.WideAttack);
var ghost = contexts.New("ghost", "common"); var ghost = contexts.New("ghost", "common");
ghost.AddFunction(EngineKeyFunctions.MoveUp); ghost.AddFunction(EngineKeyFunctions.MoveUp);

View File

@@ -73,6 +73,8 @@ Open inventory: [color=#a4885c]{7}[/color]
Open character window: [color=#a4885c]{8}[/color] Open character window: [color=#a4885c]{8}[/color]
Open crafting window: [color=#a4885c]{9}[/color] Open crafting window: [color=#a4885c]{9}[/color]
Focus chat: [color=#a4885c]{10}[/color] Focus chat: [color=#a4885c]{10}[/color]
Use hand/object in hand: [color=#a4885c]{22}[/color]
Do wide attack: [color=#a4885c]{23}[/color]
Use targeted entity: [color=#a4885c]{11}[/color] Use targeted entity: [color=#a4885c]{11}[/color]
Throw held item: [color=#a4885c]{12}[/color] Throw held item: [color=#a4885c]{12}[/color]
Examine entity: [color=#a4885c]{13}[/color] Examine entity: [color=#a4885c]{13}[/color]
@@ -102,16 +104,18 @@ Toggle sandbox window: [color=#a4885c]{21}[/color]",
Key(ShowDebugMonitors), Key(ShowDebugMonitors),
Key(OpenEntitySpawnWindow), Key(OpenEntitySpawnWindow),
Key(OpenTileSpawnWindow), Key(OpenTileSpawnWindow),
Key(OpenSandboxWindow))); Key(OpenSandboxWindow),
Key(Use),
//Gameplay Key(WideAttack)));
VBox.AddChild(new Label { FontOverride = headerFont, Text = Loc.GetString("\nSandbox spawner", Key(OpenSandboxWindow)) });
AddFormattedText(SandboxSpawnerContents);
//Gameplay //Gameplay
VBox.AddChild(new Label { FontOverride = headerFont, Text = "\nGameplay" }); VBox.AddChild(new Label { FontOverride = headerFont, Text = "\nGameplay" });
AddFormattedText(GameplayContents); AddFormattedText(GameplayContents);
//Gameplay
VBox.AddChild(new Label { FontOverride = headerFont, Text = Loc.GetString("\nSandbox spawner", Key(OpenSandboxWindow)) });
AddFormattedText(SandboxSpawnerContents);
//Feedback //Feedback
VBox.AddChild(new Label { FontOverride = headerFont, Text = "\nFeedback" }); VBox.AddChild(new Label { FontOverride = headerFont, Text = "\nFeedback" });
AddFormattedText(FeedbackContents); AddFormattedText(FeedbackContents);

View File

@@ -302,8 +302,8 @@ namespace Content.Server.GameObjects.EntitySystems
var inputSys = EntitySystemManager.GetEntitySystem<InputSystem>(); var inputSys = EntitySystemManager.GetEntitySystem<InputSystem>();
inputSys.BindMap.BindFunction(EngineKeyFunctions.Use, inputSys.BindMap.BindFunction(EngineKeyFunctions.Use,
new PointerInputCmdHandler(HandleUseItemInHand)); new PointerInputCmdHandler(HandleUseItemInHand));
inputSys.BindMap.BindFunction(ContentKeyFunctions.Attack, inputSys.BindMap.BindFunction(ContentKeyFunctions.WideAttack,
new PointerInputCmdHandler(HandleAttack)); new PointerInputCmdHandler(HandleWideAttack));
inputSys.BindMap.BindFunction(ContentKeyFunctions.ActivateItemInWorld, inputSys.BindMap.BindFunction(ContentKeyFunctions.ActivateItemInWorld,
new PointerInputCmdHandler(HandleActivateItemInWorld)); new PointerInputCmdHandler(HandleActivateItemInWorld));
} }
@@ -362,7 +362,7 @@ namespace Content.Server.GameObjects.EntitySystems
activateComp.Activate(new ActivateEventArgs {User = user}); activateComp.Activate(new ActivateEventArgs {User = user});
} }
private bool HandleAttack(ICommonSession session, GridCoordinates coords, EntityUid uid) private bool HandleWideAttack(ICommonSession session, GridCoordinates coords, EntityUid uid)
{ {
// client sanitization // client sanitization
if (!_mapManager.GridExists(coords.GridID)) if (!_mapManager.GridExists(coords.GridID))

View File

@@ -5,8 +5,7 @@ namespace Content.Shared.Input
[KeyFunctions] [KeyFunctions]
public static class ContentKeyFunctions public static class ContentKeyFunctions
{ {
public static readonly BoundKeyFunction UseOrAttack = "UseOrAttack"; public static readonly BoundKeyFunction WideAttack = "WideAttack";
public static readonly BoundKeyFunction Attack = "Attack";
public static readonly BoundKeyFunction ActivateItemInHand = "ActivateItemInHand"; public static readonly BoundKeyFunction ActivateItemInHand = "ActivateItemInHand";
public static readonly BoundKeyFunction ActivateItemInWorld = "ActivateItemInWorld"; // default action on world entity public static readonly BoundKeyFunction ActivateItemInWorld = "ActivateItemInWorld"; // default action on world entity
public static readonly BoundKeyFunction Drop = "Drop"; public static readonly BoundKeyFunction Drop = "Drop";

View File

@@ -1,9 +1,12 @@
version: 1 # Not used right now, whatever. version: 1 # Not used right now, whatever.
binds: binds:
- function: UseOrAttack - function: Use
type: state type: state
key: MouseLeft key: MouseLeft
canFocus: true canFocus: true
- function: WideAttack
type: state
key: Space
- function: ShowDebugMonitors - function: ShowDebugMonitors
type: Toggle type: Toggle
key: F3 key: F3