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-05-25 15:28:33 -07:00
|
|
|
namespace SupaLidlGame.State.Character
|
2022-11-13 15:42:04 -08:00
|
|
|
{
|
2023-05-25 15:28:33 -07:00
|
|
|
public abstract partial class PlayerState : CharacterState
|
2022-11-13 15:42:04 -08:00
|
|
|
{
|
|
|
|
protected Player _player => Character as Player;
|
|
|
|
|
2022-11-19 21:21:12 -08:00
|
|
|
[Export]
|
|
|
|
public PlayerIdleState IdleState { get; set; }
|
|
|
|
|
|
|
|
public override CharacterState Input(InputEvent @event)
|
|
|
|
{
|
2023-04-16 14:11:17 -07:00
|
|
|
var inventory = Character.Inventory;
|
|
|
|
|
2023-05-25 15:28:33 -07:00
|
|
|
if (this is PlayerIdleState or PlayerMoveState &&
|
|
|
|
!_player.Inventory.IsUsingItem)
|
2022-11-19 21:21:12 -08:00
|
|
|
{
|
2023-04-16 14:11:17 -07:00
|
|
|
if (@event.IsActionPressed("equip_1"))
|
|
|
|
{
|
|
|
|
inventory.SelectedItem = inventory.GetItemByMap("equip_1");
|
|
|
|
}
|
2022-11-19 21:21:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return base.Input(@event);
|
|
|
|
}
|
|
|
|
|
2022-11-13 15:42:04 -08:00
|
|
|
public override CharacterState Process(double delta)
|
|
|
|
{
|
|
|
|
Character.Direction = Godot.Input.GetVector("ui_left", "ui_right",
|
|
|
|
"ui_up", "ui_down");
|
2022-11-19 21:21:12 -08:00
|
|
|
Vector2 mousePos = Character.GetGlobalMousePosition();
|
|
|
|
Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos);
|
2023-05-26 17:42:50 -07:00
|
|
|
if (Character.Inventory.SelectedItem is Items.Weapon weapon)
|
2022-11-19 21:21:12 -08:00
|
|
|
{
|
|
|
|
if (!weapon.IsUsing)
|
|
|
|
{
|
|
|
|
Character.Target = dirToMouse;
|
|
|
|
}
|
|
|
|
}
|
2023-04-16 14:11:17 -07:00
|
|
|
else if (!Character.Direction.IsZeroApprox())
|
|
|
|
{
|
|
|
|
Character.Target = Character.Direction;
|
|
|
|
}
|
2022-11-25 09:11:46 -08:00
|
|
|
|
2022-11-25 11:59:55 -08:00
|
|
|
if (Godot.Input.IsActionPressed("attack1"))
|
|
|
|
{
|
2023-05-26 22:28:08 -07:00
|
|
|
var item = Character.Inventory.SelectedItem;
|
|
|
|
if (item is not null)
|
2022-11-25 11:59:55 -08:00
|
|
|
{
|
2023-05-26 22:28:08 -07:00
|
|
|
if (!item.IsUsing)
|
|
|
|
{
|
|
|
|
Character.Target = dirToMouse;
|
|
|
|
}
|
|
|
|
Character.Target = dirToMouse;
|
2022-11-25 11:59:55 -08:00
|
|
|
Character.UseCurrentItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-13 15:42:04 -08:00
|
|
|
return base.Process(delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|