fixed char targets being locked

pull/6/head
John Montagu, the 4th Earl of Sandvich 2023-08-10 23:08:41 -07:00
parent 9a3d6fa8e4
commit f3452f7d3e
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
19 changed files with 368 additions and 93 deletions

Binary file not shown.

View File

@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://m1sbk3c4eask"
path="res://.godot/imported/metal-bash2.wav-3ea9a3703d6c6ed7f37e297733bfe0d8.sample"
[deps]
source_file="res://Assets/Sounds/metal-bash2.wav"
dest_files=["res://.godot/imported/metal-bash2.wav-3ea9a3703d6c6ed7f37e297733bfe0d8.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0

Binary file not shown.

View File

@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://kao8wbfaum27"
path="res://.godot/imported/metal-bash3.wav-b24475b91529aedafa73cefb49261c75.sample"
[deps]
source_file="res://Assets/Sounds/metal-bash3.wav"
dest_files=["res://.godot/imported/metal-bash3.wav-b24475b91529aedafa73cefb49261c75.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0

View File

@ -213,10 +213,6 @@ public partial class Character : CharacterBody2D, IFaction
if (Inventory.SelectedItem is Weapon weapon) if (Inventory.SelectedItem is Weapon weapon)
{ {
if (!weapon.IsUsing)
{
Inventory.EmitSignal(Inventory.SignalName.UsedItem, weapon);
}
weapon.Use(); weapon.Use();
} }
} }

View File

@ -324,6 +324,7 @@ script = ExtResource("1_flygr")
Camera = NodePath("Camera2D") Camera = NodePath("Camera2D")
DirectionMarker = NodePath("Direction2D") DirectionMarker = NodePath("Direction2D")
Speed = 80.0 Speed = 80.0
Stealth = 1.0
HandTexture = ExtResource("3_3dqh7") HandTexture = ExtResource("3_3dqh7")
Sprite = NodePath("Sprites/Node2D/Character") Sprite = NodePath("Sprites/Node2D/Character")
Inventory = NodePath("Inventory") Inventory = NodePath("Inventory")
@ -486,16 +487,17 @@ position = Vector2(0, -4)
script = ExtResource("7_xyenu") script = ExtResource("7_xyenu")
InventoryMap = { InventoryMap = {
"equip_1": 0, "equip_1": 0,
"equip_2": 1 "equip_2": 1,
"equip_3": 2
} }
[node name="Sword" parent="Inventory" instance=ExtResource("22_mqpn7")] [node name="Sword" parent="Inventory" instance=ExtResource("22_mqpn7")]
[node name="Shotgun" parent="Inventory" instance=ExtResource("22_rmciq")]
[node name="Node2D" parent="Inventory" instance=ExtResource("7_4rxuv")] [node name="Node2D" parent="Inventory" instance=ExtResource("7_4rxuv")]
visible = false visible = false
[node name="Shotgun" parent="Inventory" instance=ExtResource("22_rmciq")]
[node name="Railgun" parent="Inventory" instance=ExtResource("21_n8w32")] [node name="Railgun" parent="Inventory" instance=ExtResource("21_n8w32")]
UseTime = 0.2 UseTime = 0.2

View File

@ -21,22 +21,13 @@ public partial class Inventory : Node2D
private Item _selectedItem; private Item _selectedItem;
private Item _offhandItem;
public Item SelectedItem public Item SelectedItem
{ {
get => _selectedItem; get => _selectedItem;
set => EquipItem(value, ref _selectedItem); set => EquipItem(value, ref _selectedItem);
} }
public Item OffhandItem public bool IsUsingItem => SelectedItem?.IsUsing ?? false;
{
get => _selectedItem;
set => EquipItem(value, ref _offhandItem);
}
public bool IsUsingItem => (SelectedItem?.IsUsing ?? false) ||
(OffhandItem?.IsUsing ?? false);
public Inventory() public Inventory()
{ {
@ -70,22 +61,6 @@ public partial class Inventory : Node2D
{ {
if (item is not null) if (item is not null)
{ {
if (item.IsOneHanded)
{
// we can not equip this if either hand is occupied by
// two-handed item
if (_selectedItem is not null && !_selectedItem.IsOneHanded)
{
return false;
}
if (_offhandItem is not null && !_offhandItem.IsOneHanded)
{
return false;
}
}
if (!Items.Contains(item)) if (!Items.Contains(item))
{ {
GD.PrintErr("Tried to equip an item not in the inventory."); GD.PrintErr("Tried to equip an item not in the inventory.");

View File

@ -5,6 +5,9 @@ namespace SupaLidlGame.Items;
public abstract partial class Item : Node2D public abstract partial class Item : Node2D
{ {
[Signal]
public delegate void UsedItemEventHandler(Item item);
[Export] [Export]
public string ItemName { get; set; } public string ItemName { get; set; }

View File

@ -153,7 +153,7 @@ tracks/0/path = NodePath("Anchor:position")
tracks/0/interp = 1 tracks/0/interp = 1
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/keys = { tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.65), "times": PackedFloat32Array(0, 0.1, 0.3),
"transitions": PackedFloat32Array(1, 1, 1), "transitions": PackedFloat32Array(1, 1, 1),
"update": 1, "update": 1,
"values": [Vector2(-8, 0), Vector2(8, 0), Vector2(0, 0)] "values": [Vector2(-8, 0), Vector2(8, 0), Vector2(0, 0)]
@ -181,7 +181,7 @@ _data = {
} }
[sub_resource type="RectangleShape2D" id="RectangleShape2D_rrgwb"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_rrgwb"]
size = Vector2(8, 32) size = Vector2(10, 34)
[node name="DocLance" type="Node2D" node_paths=PackedStringArray("Hitbox", "AnimationPlayer", "ParryParticles", "StateMachine", "Anchor", "HandAnchor")] [node name="DocLance" type="Node2D" node_paths=PackedStringArray("Hitbox", "AnimationPlayer", "ParryParticles", "StateMachine", "Anchor", "HandAnchor")]
y_sort_enabled = true y_sort_enabled = true
@ -206,6 +206,8 @@ Description = "\"Violence. Speed. Momentum.\""
[node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")] [node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")]
script = ExtResource("2_c41ov") script = ExtResource("2_c41ov")
InitialState = NodePath("Idle") InitialState = NodePath("Idle")
UsedItemStates = Array[NodePath]([NodePath("Attack")])
DeusedItemStates = Array[NodePath]([NodePath("Idle")])
[node name="Idle" type="Node" parent="State" node_paths=PackedStringArray("UseState", "Sword")] [node name="Idle" type="Node" parent="State" node_paths=PackedStringArray("UseState", "Sword")]
script = ExtResource("3_sxffm") script = ExtResource("3_sxffm")
@ -269,6 +271,7 @@ position = Vector2(16, -4)
IsDisabled = true IsDisabled = true
[node name="CollisionShape2D" parent="Hitbox" index="0"] [node name="CollisionShape2D" parent="Hitbox" index="0"]
position = Vector2(1, 0)
rotation = 1.5708 rotation = 1.5708
shape = SubResource("RectangleShape2D_rrgwb") shape = SubResource("RectangleShape2D_rrgwb")
disabled = true disabled = true

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=26 format=3 uid="uid://5y1acxl4j4n7"] [gd_scene load_steps=28 format=3 uid="uid://5y1acxl4j4n7"]
[ext_resource type="Script" path="res://Items/Weapons/Sword.cs" id="1_mai31"] [ext_resource type="Script" path="res://Items/Weapons/Sword.cs" id="1_mai31"]
[ext_resource type="Script" path="res://State/Weapon/WeaponStateMachine.cs" id="2_5ramr"] [ext_resource type="Script" path="res://State/Weapon/WeaponStateMachine.cs" id="2_5ramr"]
@ -8,7 +8,9 @@
[ext_resource type="Texture2D" uid="uid://dfpe74vxvuwal" path="res://Assets/Sprites/Items/pugio.png" id="6_d28k5"] [ext_resource type="Texture2D" uid="uid://dfpe74vxvuwal" path="res://Assets/Sprites/Items/pugio.png" id="6_d28k5"]
[ext_resource type="Script" path="res://State/Weapon/SwordBlockState.cs" id="6_yvm8x"] [ext_resource type="Script" path="res://State/Weapon/SwordBlockState.cs" id="6_yvm8x"]
[ext_resource type="Material" uid="uid://cbfaqolx1ydvv" path="res://Assets/Sprites/Particles/ParryParticles.tres" id="8_we1sv"] [ext_resource type="Material" uid="uid://cbfaqolx1ydvv" path="res://Assets/Sprites/Particles/ParryParticles.tres" id="8_we1sv"]
[ext_resource type="AudioStream" uid="uid://m1sbk3c4eask" path="res://Assets/Sounds/metal-bash2.wav" id="9_b6yro"]
[ext_resource type="PackedScene" uid="uid://du5vhccg75nrq" path="res://BoundingBoxes/Hitbox.tscn" id="9_qimey"] [ext_resource type="PackedScene" uid="uid://du5vhccg75nrq" path="res://BoundingBoxes/Hitbox.tscn" id="9_qimey"]
[ext_resource type="AudioStream" uid="uid://kao8wbfaum27" path="res://Assets/Sounds/metal-bash3.wav" id="10_istfq"]
[ext_resource type="Texture2D" uid="uid://ct0m4lk2icx3p" path="res://Assets/Sprites/sword-swing-small.png" id="10_q8b54"] [ext_resource type="Texture2D" uid="uid://ct0m4lk2icx3p" path="res://Assets/Sprites/sword-swing-small.png" id="10_q8b54"]
[ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="11_b1fwx"] [ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="11_b1fwx"]
[ext_resource type="Texture2D" uid="uid://417j1ckcjg2i" path="res://Assets/Sprites/Items/doc-shield.png" id="11_qpejo"] [ext_resource type="Texture2D" uid="uid://417j1ckcjg2i" path="res://Assets/Sprites/Items/doc-shield.png" id="11_qpejo"]
@ -309,7 +311,7 @@ tracks/0/path = NodePath("Shield:scale")
tracks/0/interp = 1 tracks/0/interp = 1
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/keys = { tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5, 1), "times": PackedFloat32Array(0, 0.7, 1),
"transitions": PackedFloat32Array(1, 0.25, 1), "transitions": PackedFloat32Array(1, 0.25, 1),
"update": 0, "update": 0,
"values": [Vector2(1.4, 1.4), Vector2(1.4, 1.4), Vector2(1, 1)] "values": [Vector2(1.4, 1.4), Vector2(1.4, 1.4), Vector2(1, 1)]
@ -321,11 +323,30 @@ tracks/1/path = NodePath("Shield:material:shader_parameter/intensity")
tracks/1/interp = 1 tracks/1/interp = 1
tracks/1/loop_wrap = true tracks/1/loop_wrap = true
tracks/1/keys = { tracks/1/keys = {
"times": PackedFloat32Array(0, 0.5, 1), "times": PackedFloat32Array(0, 0.7, 1),
"transitions": PackedFloat32Array(1, 1, 1), "transitions": PackedFloat32Array(1, 1, 1),
"update": 0, "update": 0,
"values": [1.0, 1.0, 0.0] "values": [1.0, 1.0, 0.0]
} }
tracks/2/type = "audio"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("ShieldSound")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"clips": [{
"end_offset": 0.0870516,
"start_offset": 0.0,
"stream": ExtResource("9_b6yro")
}, {
"end_offset": 0.383027,
"start_offset": 0.0,
"stream": ExtResource("10_istfq")
}],
"times": PackedFloat32Array(0, 0.7)
}
tracks/2/use_blend = true
[sub_resource type="AnimationLibrary" id="AnimationLibrary_11u25"] [sub_resource type="AnimationLibrary" id="AnimationLibrary_11u25"]
_data = { _data = {
@ -370,6 +391,8 @@ HandAnchor = NodePath("Anchor/Node2D/Sprite2D/Hand")
[node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")] [node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")]
script = ExtResource("2_5ramr") script = ExtResource("2_5ramr")
InitialState = NodePath("Idle") InitialState = NodePath("Idle")
UsedItemStates = Array[NodePath]([NodePath("Attack"), NodePath("Block")])
DeusedItemStates = Array[NodePath]([NodePath("Idle")])
[node name="Idle" type="Node" parent="State" node_paths=PackedStringArray("UseState", "UseAltState", "Sword")] [node name="Idle" type="Node" parent="State" node_paths=PackedStringArray("UseState", "UseAltState", "Sword")]
script = ExtResource("3_fwkit") script = ExtResource("3_fwkit")
@ -446,10 +469,17 @@ modulate = Color(2, 2, 2, 1)
texture = ExtResource("10_q8b54") texture = ExtResource("10_q8b54")
hframes = 3 hframes = 3
[node name="Node" type="Node" parent="."]
[node name="RemoteTransform2D" type="RemoteTransform2D" parent="Node"]
top_level = true
remote_path = NodePath("../../Shield")
update_position = false
[node name="Shield" type="Sprite2D" parent="."] [node name="Shield" type="Sprite2D" parent="."]
y_sort_enabled = true y_sort_enabled = true
material = SubResource("ShaderMaterial_rgypv") material = SubResource("ShaderMaterial_rgypv")
position = Vector2(7, 8) position = Vector2(10, 10)
texture = ExtResource("11_qpejo") texture = ExtResource("11_qpejo")
offset = Vector2(0, -12) offset = Vector2(0, -12)
@ -460,4 +490,7 @@ pitch_scale = 1.2
[node name="ParrySound" type="AudioStreamPlayer2D" parent="."] [node name="ParrySound" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("13_t5wmj") stream = ExtResource("13_t5wmj")
[node name="ShieldSound" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("13_t5wmj")
[editable path="Hitbox"] [editable path="Hitbox"]

View File

@ -134,6 +134,25 @@ public partial class Sword : Weapon, IParryable
{ {
Hitbox.Damage = Damage; Hitbox.Damage = Damage;
Hitbox.Hit += OnHitboxHit; Hitbox.Hit += OnHitboxHit;
StateMachine.StateChanged += OnStateChanged;
}
public void OnStateChanged(Node state)
{
if (StateMachine.UsedItemStates is null)
{
return;
}
foreach (var nodePath in StateMachine.UsedItemStates)
{
if (StateMachine.GetNode(nodePath) == state)
{
Character.Inventory.EmitSignal(
Inventory.SignalName.UsedItem, this);
//EmitSignal(SignalName.UsedItem, this);
}
}
} }
public override void _Process(double delta) public override void _Process(double delta)

View File

@ -374,6 +374,8 @@ HandAnchor = NodePath("Anchor/Node2D/Sprite2D/Hand")
[node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")] [node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")]
script = ExtResource("2_vwirq") script = ExtResource("2_vwirq")
InitialState = NodePath("Idle") InitialState = NodePath("Idle")
UsedItemStates = Array[NodePath]([NodePath("Attack")])
DeusedItemStates = Array[NodePath]([NodePath("Idle")])
[node name="Idle" type="Node" parent="State" node_paths=PackedStringArray("UseState", "Sword")] [node name="Idle" type="Node" parent="State" node_paths=PackedStringArray("UseState", "Sword")]
script = ExtResource("3_nw6r0") script = ExtResource("3_nw6r0")

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=14 format=3 uid="uid://b2x17su05ou5w"] [gd_scene load_steps=24 format=3 uid="uid://b2x17su05ou5w"]
[ext_resource type="PackedScene" uid="uid://clwv2owvk6abe" path="res://Scenes/BaseMap.tscn" id="1_ifiic"] [ext_resource type="PackedScene" uid="uid://clwv2owvk6abe" path="res://Scenes/BaseMap.tscn" id="1_ifiic"]
[ext_resource type="TileSet" uid="uid://l61kbx31ug4p" path="res://Scenes/Maps/ArenaTileset.tres" id="2_x0mh7"] [ext_resource type="TileSet" uid="uid://l61kbx31ug4p" path="res://Scenes/Maps/ArenaTileset.tres" id="2_x0mh7"]
@ -8,10 +8,68 @@
[ext_resource type="PackedScene" uid="uid://ceadk7pam7vab" path="res://Entities/TorchLamp.tscn" id="6_jy3pc"] [ext_resource type="PackedScene" uid="uid://ceadk7pam7vab" path="res://Entities/TorchLamp.tscn" id="6_jy3pc"]
[ext_resource type="Texture2D" uid="uid://d1ukste16yq6v" path="res://Assets/Sprites/Particles/player-light.png" id="7_y7j0e"] [ext_resource type="Texture2D" uid="uid://d1ukste16yq6v" path="res://Assets/Sprites/Particles/player-light.png" id="7_y7j0e"]
[ext_resource type="AudioStream" uid="uid://dy4qjflo1k28b" path="res://Assets/Sounds/calm-storm-ambient.mp3" id="8_wox7d"] [ext_resource type="AudioStream" uid="uid://dy4qjflo1k28b" path="res://Assets/Sounds/calm-storm-ambient.mp3" id="8_wox7d"]
[ext_resource type="PackedScene" uid="uid://dhamcei7tfta8" path="res://Characters/DocCenturion.tscn" id="9_4pmu0"]
[ext_resource type="PackedScene" uid="uid://dldnp8eunxj3q" path="res://BoundingBoxes/InteractionTrigger.tscn" id="9_3401j"] [ext_resource type="PackedScene" uid="uid://dldnp8eunxj3q" path="res://BoundingBoxes/InteractionTrigger.tscn" id="9_3401j"]
[ext_resource type="Script" path="res://BoundingBoxes/ConnectorBox.cs" id="9_fg062"] [ext_resource type="Script" path="res://BoundingBoxes/ConnectorBox.cs" id="9_fg062"]
[ext_resource type="PackedScene" uid="uid://cdj50hb84aujp" path="res://Characters/DocLegionary.tscn" id="10_o8yqo"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_tr5pw"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_5qrl0"]
resource_local_to_scene = true
shader = ExtResource("5_h8k5p")
shader_parameter/color = Vector4(1, 1, 1, 1)
shader_parameter/intensity = 0.0
shader_parameter/alpha_modulate = 1.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_a0x5h"]
resource_local_to_scene = true
shader = ExtResource("5_h8k5p")
shader_parameter/color = Vector4(1, 1, 1, 1)
shader_parameter/intensity = 0.0
shader_parameter/alpha_modulate = 1.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_mdq3p"]
resource_local_to_scene = true
shader = ExtResource("5_h8k5p")
shader_parameter/color = Vector4(1, 1, 1, 1)
shader_parameter/intensity = 0.0
shader_parameter/alpha_modulate = 1.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_emouq"]
resource_local_to_scene = true
shader = ExtResource("5_h8k5p")
shader_parameter/color = Vector4(1, 1, 1, 1)
shader_parameter/intensity = 0.0
shader_parameter/alpha_modulate = 1.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_42lqj"]
resource_local_to_scene = true
shader = ExtResource("5_h8k5p")
shader_parameter/color = Vector4(1, 1, 1, 1)
shader_parameter/intensity = 0.0
shader_parameter/alpha_modulate = 1.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_j5cfk"]
resource_local_to_scene = true
shader = ExtResource("5_h8k5p")
shader_parameter/color = Vector4(1, 1, 1, 1)
shader_parameter/intensity = 0.0
shader_parameter/alpha_modulate = 1.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_r1ooq"]
resource_local_to_scene = true
shader = ExtResource("5_h8k5p")
shader_parameter/color = Vector4(1, 1, 1, 1)
shader_parameter/intensity = 0.0
shader_parameter/alpha_modulate = 1.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_y76p0"]
resource_local_to_scene = true
shader = ExtResource("5_h8k5p")
shader_parameter/color = Vector4(1, 1, 1, 1)
shader_parameter/intensity = 0.0
shader_parameter/alpha_modulate = 1.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_4fvo0"]
resource_local_to_scene = true resource_local_to_scene = true
shader = ExtResource("5_h8k5p") shader = ExtResource("5_h8k5p")
shader_parameter/color = Vector4(1, 1, 1, 1) shader_parameter/color = Vector4(1, 1, 1, 1)
@ -113,7 +171,7 @@ visible = false
position = Vector2(120, -112) position = Vector2(120, -112)
[node name="Doc" parent="Entities" index="0" instance=ExtResource("4_ej0f3")] [node name="Doc" parent="Entities" index="0" instance=ExtResource("4_ej0f3")]
material = SubResource("ShaderMaterial_tr5pw") material = SubResource("ShaderMaterial_5qrl0")
[node name="PointLight2D" type="PointLight2D" parent="Entities" index="1"] [node name="PointLight2D" type="PointLight2D" parent="Entities" index="1"]
position = Vector2(168, -42) position = Vector2(168, -42)
@ -133,6 +191,58 @@ stream = ExtResource("8_wox7d")
volume_db = -5.0 volume_db = -5.0
autoplay = true autoplay = true
[node name="Centurion" parent="Entities" index="4" instance=ExtResource("9_4pmu0")]
material = SubResource("ShaderMaterial_a0x5h")
position = Vector2(-64, -16)
Faction = 1
[node name="Centurion3" parent="Entities" index="5" instance=ExtResource("9_4pmu0")]
material = SubResource("ShaderMaterial_mdq3p")
position = Vector2(-64, -44)
Faction = 1
[node name="Centurion2" parent="Entities" index="6" node_paths=PackedStringArray("DefaultSelectedItem", "ThinkerStateMachine", "Sprite", "Inventory", "StateMachine", "Hurtbox") instance=ExtResource("9_4pmu0")]
material = SubResource("ShaderMaterial_emouq")
position = Vector2(64, -48)
DefaultSelectedItem = NodePath("../Centurion/Inventory/Sword")
ThinkerStateMachine = NodePath("../Centurion/ThinkerStateMachine")
Sprite = NodePath("../Centurion/Sprites/Node2D/Character")
Inventory = NodePath("../Centurion/Inventory")
StateMachine = NodePath("../Centurion/StateMachine")
Hurtbox = NodePath("../Centurion/Hurtbox")
Faction = 2
[node name="Centurion4" parent="Entities" index="7" node_paths=PackedStringArray("DefaultSelectedItem", "ThinkerStateMachine", "Sprite", "Inventory", "StateMachine", "Hurtbox") instance=ExtResource("9_4pmu0")]
material = SubResource("ShaderMaterial_42lqj")
position = Vector2(107, -42)
DefaultSelectedItem = NodePath("../Centurion/Inventory/Sword")
ThinkerStateMachine = NodePath("../Centurion/ThinkerStateMachine")
Sprite = NodePath("../Centurion/Sprites/Node2D/Character")
Inventory = NodePath("../Centurion/Inventory")
StateMachine = NodePath("../Centurion/StateMachine")
Hurtbox = NodePath("../Centurion/Hurtbox")
Faction = 2
[node name="Legionary" parent="Entities" index="8" instance=ExtResource("10_o8yqo")]
material = SubResource("ShaderMaterial_j5cfk")
position = Vector2(-64, 48)
Faction = 1
[node name="Legionary3" parent="Entities" index="9" instance=ExtResource("10_o8yqo")]
material = SubResource("ShaderMaterial_r1ooq")
position = Vector2(-64, 12)
Faction = 1
[node name="Legionary2" parent="Entities" index="10" instance=ExtResource("10_o8yqo")]
material = SubResource("ShaderMaterial_y76p0")
position = Vector2(40, 40)
Faction = 2
[node name="Legionary4" parent="Entities" index="11" instance=ExtResource("10_o8yqo")]
material = SubResource("ShaderMaterial_4fvo0")
position = Vector2(50, 11)
Faction = 2
[node name="Area2D" type="Area2D" parent="Areas" index="0"] [node name="Area2D" type="Area2D" parent="Areas" index="0"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Areas/Area2D" index="0"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Areas/Area2D" index="0"]

File diff suppressed because one or more lines are too long

View File

@ -22,7 +22,6 @@ public abstract partial class CharacterState : Node, IState<CharacterState>
} }
var item = Character.Inventory.SelectedItem; var item = Character.Inventory.SelectedItem;
var offhand = Character.Inventory.OffhandItem;
// angle towards item use angle or offhand use angle if not used // angle towards item use angle or offhand use angle if not used
@ -39,7 +38,7 @@ public abstract partial class CharacterState : Node, IState<CharacterState>
return false; return false;
} }
var _ = targetTowards(item) || targetTowards(offhand); targetTowards(item);
return null; return null;
} }

View File

@ -26,6 +26,10 @@ public abstract partial class PlayerState : CharacterState
{ {
inventory.SelectedItem = inventory.GetItemByMap("equip_2"); inventory.SelectedItem = inventory.GetItemByMap("equip_2");
} }
else if (@event.IsActionPressed("equip_3"))
{
inventory.SelectedItem = inventory.GetItemByMap("equip_3");
}
if (@event.IsActionPressed("interact")) if (@event.IsActionPressed("interact"))
{ {
@ -47,43 +51,27 @@ public abstract partial class PlayerState : CharacterState
Vector2 mousePos = Character.GetGlobalMousePosition(); Vector2 mousePos = Character.GetGlobalMousePosition();
Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos); Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos);
bool targetTowards(Items.Item item) if (Character.Inventory.SelectedItem is Items.Weapon weapon)
{ {
if (Character.Inventory.SelectedItem is Items.Weapon weapon) var isAttack1On = Godot.Input.IsActionPressed("attack1");
var isAttack2On = Godot.Input.IsActionPressed("attack2");
if (!weapon.ShouldHideIdle || isAttack1On)
{ {
var isAttack1On = Godot.Input.IsActionPressed("attack1"); Character.Target = dirToMouse;
var isAttack2On = Godot.Input.IsActionPressed("attack2");
var ret = false;
if (!weapon.IsUsing)
{
if (!weapon.ShouldHideIdle || isAttack1On)
{
Character.Target = dirToMouse;
ret = true;
}
}
if (isAttack1On)
{
Character.UseCurrentItem();
}
else if (isAttack2On)
{
Character.UseCurrentItemAlt();
}
return ret;
} }
return false;
if (isAttack1On)
{
Character.UseCurrentItem();
}
else if (isAttack2On)
{
Character.UseCurrentItemAlt();
}
} }
var item = Character.Inventory.SelectedItem;
var offhand = Character.Inventory.OffhandItem;
var _ = targetTowards(item) || targetTowards(offhand);
return base.Process(delta); return base.Process(delta);
} }
} }

View File

@ -1,12 +1,13 @@
using Godot; using Godot;
using SupaLidlGame.Extensions; using SupaLidlGame.Extensions;
using System.Collections.Generic;
namespace SupaLidlGame.State; namespace SupaLidlGame.State;
public abstract partial class StateMachine<T> : Node where T : Node, IState<T> public abstract partial class StateMachine<T> : Node where T : Node, IState<T>
{ {
[Signal] [Signal]
public delegate void OnStateChangedEventHandler(Node state); public delegate void StateChangedEventHandler(Node state);
public T CurrentState { get; protected set; } public T CurrentState { get; protected set; }
@ -17,7 +18,30 @@ public abstract partial class StateMachine<T> : Node where T : Node, IState<T>
ChangeState(InitialState); ChangeState(InitialState);
} }
public virtual bool ChangeState(T nextState, bool isProxied = false) public virtual bool ChangeState(T nextState)
{
return ChangeState(nextState, out Stack<T> _);
}
public bool ChangeState(T nextState, out T finalState)
{
var status = ChangeState(nextState, out Stack<T> states);
finalState = states.Peek();
return status;
}
public bool ChangeState(T nextState, out Stack<T> states)
{
states = new Stack<T>();
states.Push(CurrentState);
var result = ChangeStateRecursive(nextState, states);
EmitSignal(SignalName.StateChanged, states.Peek());
return result;
}
protected virtual bool ChangeStateRecursive(
T nextState,
Stack<T> states)
{ {
if (nextState is null) if (nextState is null)
{ {
@ -32,6 +56,7 @@ public abstract partial class StateMachine<T> : Node where T : Node, IState<T>
var previousState = CurrentState; var previousState = CurrentState;
CurrentState = nextState; CurrentState = nextState;
states.Push(nextState);
// if the next state decides it should enter a different state, // if the next state decides it should enter a different state,
// then we enter that different state instead // then we enter that different state instead
@ -39,7 +64,7 @@ public abstract partial class StateMachine<T> : Node where T : Node, IState<T>
if (nextNextState is T t) if (nextNextState is T t)
{ {
return ChangeState(t, true); return ChangeStateRecursive(t, states);
} }
return true; return true;

View File

@ -42,7 +42,7 @@ public partial class ThinkerStateMachine : StateMachine<ThinkerState>
} }
} }
public override bool ChangeState(ThinkerState nextState, bool isProxied = false) public override bool ChangeState(ThinkerState nextState)
{ {
if (base.ChangeState(nextState)) if (base.ChangeState(nextState))
{ {

View File

@ -7,6 +7,12 @@ public partial class WeaponStateMachine : StateMachine<WeaponState>
[Export] [Export]
public override WeaponState InitialState { get; set; } public override WeaponState InitialState { get; set; }
[Export]
public Godot.Collections.Array<NodePath> UsedItemStates { get; protected set; }
[Export]
public Godot.Collections.Array<NodePath> DeusedItemStates { get; protected set; }
public void Use() public void Use()
{ {
var state = CurrentState.Use(); var state = CurrentState.Use();