2022-11-19 21:21:12 -08:00
|
|
|
using Godot;
|
2023-05-25 15:28:33 -07:00
|
|
|
using SupaLidlGame.Characters;
|
2022-11-19 21:21:12 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
namespace SupaLidlGame.State.Character;
|
|
|
|
|
|
|
|
public abstract partial class PlayerState : CharacterState
|
2022-11-13 15:42:04 -08:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
protected Player _player => Character as Player;
|
2022-11-13 15:42:04 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
[Export]
|
|
|
|
public PlayerIdleState IdleState { get; set; }
|
2022-11-19 21:21:12 -08:00
|
|
|
|
2023-09-17 22:35:27 -07:00
|
|
|
[Export]
|
|
|
|
public PlayerMaxLevelState MaxLevelState { get; set; }
|
|
|
|
|
2024-01-06 14:13:11 -08:00
|
|
|
public override CharacterState UnhandledInput(InputEvent @event)
|
2023-06-03 18:21:46 -07:00
|
|
|
{
|
|
|
|
var inventory = Character.Inventory;
|
2023-06-10 22:15:28 -07:00
|
|
|
var player = _player;
|
2023-04-16 14:11:17 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
if (this is PlayerIdleState or PlayerMoveState &&
|
2023-06-10 22:15:28 -07:00
|
|
|
!player.Inventory.IsUsingItem)
|
2023-06-03 18:21:46 -07:00
|
|
|
{
|
|
|
|
if (@event.IsActionPressed("equip_1"))
|
2022-11-19 21:21:12 -08:00
|
|
|
{
|
2024-01-01 22:55:53 -08:00
|
|
|
inventory.SelectedIndex = 0;
|
2022-11-19 21:21:12 -08:00
|
|
|
}
|
2023-06-06 18:39:23 -07:00
|
|
|
else if (@event.IsActionPressed("equip_2"))
|
|
|
|
{
|
2024-01-01 22:55:53 -08:00
|
|
|
inventory.SelectedIndex = 1;
|
2023-06-06 18:39:23 -07:00
|
|
|
}
|
2023-08-10 23:08:41 -07:00
|
|
|
else if (@event.IsActionPressed("equip_3"))
|
|
|
|
{
|
2024-01-01 22:55:53 -08:00
|
|
|
inventory.SelectedIndex = 2;
|
2023-08-10 23:08:41 -07:00
|
|
|
}
|
2023-08-15 00:44:44 -07:00
|
|
|
else if (@event.IsActionPressed("next_item"))
|
|
|
|
{
|
|
|
|
inventory.EquipIndex(++inventory.CurrentQuickSwitchIndex);
|
|
|
|
}
|
|
|
|
else if (@event.IsActionPressed("prev_item"))
|
|
|
|
{
|
|
|
|
inventory.EquipIndex(--inventory.CurrentQuickSwitchIndex);
|
|
|
|
}
|
2023-06-10 22:15:28 -07:00
|
|
|
|
|
|
|
if (@event.IsActionPressed("interact"))
|
|
|
|
{
|
|
|
|
// if looking at a trigger then interact with it
|
|
|
|
player.InteractionRay.Trigger?.InvokeInteraction();
|
|
|
|
}
|
2023-09-17 22:35:27 -07:00
|
|
|
|
|
|
|
if (@event.IsActionPressed("cast"))
|
|
|
|
{
|
|
|
|
if (_player.Stats.Level.Value >= MaxLevelState.LevelCost)
|
|
|
|
{
|
|
|
|
return MaxLevelState;
|
|
|
|
}
|
|
|
|
}
|
2024-08-21 16:20:35 -07:00
|
|
|
|
|
|
|
if (@event.IsActionPressed("inventory"))
|
|
|
|
{
|
|
|
|
var bus = Events.EventBus.Instance;
|
|
|
|
bus.EmitSignal(Events.EventBus.SignalName.PlayerOpenInventory,
|
|
|
|
player.Inventory);
|
|
|
|
}
|
2022-11-19 21:21:12 -08:00
|
|
|
}
|
|
|
|
|
2024-01-06 14:13:11 -08:00
|
|
|
return base.UnhandledInput(@event);
|
2023-06-03 18:21:46 -07:00
|
|
|
}
|
2023-05-28 17:54:48 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public override CharacterState Process(double delta)
|
|
|
|
{
|
2023-08-07 02:38:51 -07:00
|
|
|
Character.Direction = Godot.Input.GetVector("left", "right",
|
|
|
|
"up", "down");
|
2023-05-28 10:57:23 -07:00
|
|
|
|
2023-09-06 23:07:51 -07:00
|
|
|
var player = _player;
|
2024-01-06 14:13:11 -08:00
|
|
|
|
2023-09-06 23:18:53 -07:00
|
|
|
var desiredTarget = player.GetDesiredInputFromInput();
|
|
|
|
if (!desiredTarget.IsZeroApprox())
|
|
|
|
{
|
|
|
|
// can never be zero
|
|
|
|
player.DesiredTarget = desiredTarget;
|
|
|
|
}
|
2023-06-03 18:21:46 -07:00
|
|
|
|
2024-01-06 14:13:11 -08:00
|
|
|
Character.LookTowardsDirection();
|
|
|
|
|
2023-08-10 23:08:41 -07:00
|
|
|
if (Character.Inventory.SelectedItem is Items.Weapon weapon)
|
2023-06-03 18:21:46 -07:00
|
|
|
{
|
2023-08-10 23:08:41 -07:00
|
|
|
var isAttack1On = Godot.Input.IsActionPressed("attack1");
|
|
|
|
var isAttack2On = Godot.Input.IsActionPressed("attack2");
|
2023-05-28 10:57:23 -07:00
|
|
|
|
2023-09-10 17:08:14 -07:00
|
|
|
if (!weapon.ShouldHideIdle || !weapon.ShouldFreezeAngleOnUse || isAttack1On)
|
2023-08-10 23:08:41 -07:00
|
|
|
{
|
2023-09-06 23:07:51 -07:00
|
|
|
player.Target = player.DesiredTarget;
|
2022-11-25 11:59:55 -08:00
|
|
|
}
|
|
|
|
|
2023-08-10 23:08:41 -07:00
|
|
|
if (isAttack1On)
|
|
|
|
{
|
|
|
|
Character.UseCurrentItem();
|
|
|
|
}
|
|
|
|
else if (isAttack2On)
|
|
|
|
{
|
|
|
|
Character.UseCurrentItemAlt();
|
|
|
|
}
|
2023-09-10 17:08:14 -07:00
|
|
|
|
|
|
|
if (Godot.Input.IsActionJustReleased("attack1"))
|
|
|
|
{
|
|
|
|
Character.DeuseCurrentItem();
|
|
|
|
}
|
2023-08-10 23:08:41 -07:00
|
|
|
}
|
2023-05-28 17:54:48 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
return base.Process(delta);
|
2022-11-13 15:42:04 -08:00
|
|
|
}
|
|
|
|
}
|