feat: implemented full reload for revolver

This commit is contained in:
Sara 2025-08-09 15:36:48 +02:00
parent f40f01a569
commit 905726c862
18 changed files with 81 additions and 7 deletions

View file

@ -50,6 +50,12 @@ void Revolver::stop_running() {
} }
} }
void Revolver::start_reloading() {
this->alt_active = false;
get_anim()->queue("double_to_reload");
get_anim()->queue("reload_one");
}
void Revolver::play_equip_anim() { void Revolver::play_equip_anim() {
get_anim()->play("equip", 0.0); get_anim()->play("equip", 0.0);
queue_idle_anim(); queue_idle_anim();
@ -57,7 +63,7 @@ void Revolver::play_equip_anim() {
} }
void Revolver::shoot() { void Revolver::shoot() {
if (animation_is_idle()) { if (animation_is_idle() && try_use_ammo(1)) {
stop_running(); stop_running();
if (this->alt_active) { if (this->alt_active) {
this->alt_active = false; this->alt_active = false;
@ -93,10 +99,26 @@ void Revolver::on_alt_mode(bool pressed) {
} }
void Revolver::on_reload() { void Revolver::on_reload() {
if (get_loaded_ammo() < get_max_ammo() && !is_animating()) {
start_reloading();
}
}
void Revolver::on_animation_finished(String old_anim) {
if (old_anim == "reload_one" && get_anim()->get_queue().is_empty()) {
reload_num(1);
if (get_loaded_ammo() < get_max_ammo()) {
get_anim()->queue("reload_one");
} else {
get_anim()->queue("reload_to_double");
get_anim()->queue("idle_double");
}
}
} }
void Revolver::ready() { void Revolver::ready() {
this->muzzle = cast_to<HitscanMuzzle>(get_node(NodePath("%HitscanMuzzle"))); this->muzzle = cast_to<HitscanMuzzle>(get_node(NodePath("%HitscanMuzzle")));
get_anim()->connect("animation_finished", callable_mp(this, &self_type::on_animation_finished));
get_input()->connect(PlayerInput::sig_primary_fire, callable_mp(this, &self_type::on_primary_fire)); get_input()->connect(PlayerInput::sig_primary_fire, callable_mp(this, &self_type::on_primary_fire));
get_input()->connect(PlayerInput::sig_alt_mode, callable_mp(this, &self_type::on_alt_mode)); get_input()->connect(PlayerInput::sig_alt_mode, callable_mp(this, &self_type::on_alt_mode));
get_input()->connect(PlayerInput::sig_reload, callable_mp(this, &self_type::on_reload)); get_input()->connect(PlayerInput::sig_reload, callable_mp(this, &self_type::on_reload));

View file

@ -10,6 +10,8 @@ class Revolver : public WeaponBase {
void queue_idle_anim(); void queue_idle_anim();
void start_running(); void start_running();
void stop_running(); void stop_running();
void start_reloading();
void interrupt_reloading();
void interrupt_running(); void interrupt_running();
void play_equip_anim(); void play_equip_anim();
void shoot(); void shoot();
@ -17,6 +19,7 @@ class Revolver : public WeaponBase {
void on_primary_fire(bool pressed); void on_primary_fire(bool pressed);
void on_alt_mode(bool pressed); void on_alt_mode(bool pressed);
void on_reload(); void on_reload();
void on_animation_finished(String old_anim);
void ready(); void ready();
void process(double delta); void process(double delta);

View file

@ -20604,7 +20604,7 @@ _subresources={
"save_to_file/fallback_path": "res://assets/animations/weapons/rifle/run.res", "save_to_file/fallback_path": "res://assets/animations/weapons/rifle/run.res",
"save_to_file/keep_custom_tracks": "", "save_to_file/keep_custom_tracks": "",
"save_to_file/path": "uid://cd4fiv3icakog", "save_to_file/path": "uid://cd4fiv3icakog",
"settings/loop_mode": 0, "settings/loop_mode": 1,
"slice_1/end_frame": 0, "slice_1/end_frame": 0,
"slice_1/loop_mode": 0, "slice_1/loop_mode": 0,
"slice_1/name": "", "slice_1/name": "",

View file

@ -44,7 +44,7 @@ size = Vector2i(1152, 648)
render_target_update_mode = 4 render_target_update_mode = 4
[node name="PlayerBody" parent="SubViewportContainer/SubViewport" instance=ExtResource("1_mhgjp")] [node name="PlayerBody" parent="SubViewportContainer/SubViewport" instance=ExtResource("1_mhgjp")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -20.454895, 0.006988764, -8.196066) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -20.417719, 1.340589, -8.014704)
[node name="Map" parent="SubViewportContainer/SubViewport" instance=ExtResource("2_41t38")] [node name="Map" parent="SubViewportContainer/SubViewport" instance=ExtResource("2_41t38")]

View file

@ -739,6 +739,18 @@ size = Vector3(5.7617188, 4.102051, 0.33398438)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.6718082, 0.008475304, 14.933871) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.6718082, 0.008475304, 14.933871)
patrol_path = NodePath("../PatrolPath") patrol_path = NodePath("../PatrolPath")
[node name="NpcUnit2" parent="." node_paths=PackedStringArray("patrol_path") instance=ExtResource("12_plog7")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -13.331992, 0.008471491, 31.940985)
patrol_path = NodePath("../PatrolPath2")
[node name="NpcUnit3" parent="." node_paths=PackedStringArray("patrol_path") instance=ExtResource("12_plog7")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 20.503181, 0.008473398, 23.28323)
patrol_path = NodePath("../PatrolPath3")
[node name="NpcUnit4" parent="." node_paths=PackedStringArray("patrol_path") instance=ExtResource("12_plog7")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -10.339678, 0.008469582, -33.651123)
patrol_path = NodePath("../PatrolPath4")
[node name="PatrolPath" type="PatrolPath" parent="."] [node name="PatrolPath" type="PatrolPath" parent="."]
[node name="Node3D" type="Node3D" parent="PatrolPath"] [node name="Node3D" type="Node3D" parent="PatrolPath"]
@ -746,3 +758,39 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.7201138, 0.0069904327, -26
[node name="Node3D2" type="Node3D" parent="PatrolPath"] [node name="Node3D2" type="Node3D" parent="PatrolPath"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.4366512, 0.0069885254, 11.854935) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.4366512, 0.0069885254, 11.854935)
[node name="PatrolPath2" type="PatrolPath" parent="."]
[node name="Node3D" type="Node3D" parent="PatrolPath2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -18.294239, 0.00699234, 27.044983)
[node name="Node3D2" type="Node3D" parent="PatrolPath2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.3810759, 0.0069847107, 38.745106)
[node name="Node3D3" type="Node3D" parent="PatrolPath2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.0630617, 0.0069885254, 29.593536)
[node name="Node3D4" type="Node3D" parent="PatrolPath2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15.879017, 0.0069847107, 20.841759)
[node name="PatrolPath3" type="PatrolPath" parent="."]
[node name="Node3D" type="Node3D" parent="PatrolPath3"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 12.753383, 0.0069885254, 0.7593994)
[node name="Node3D2" type="Node3D" parent="PatrolPath3"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 25.776007, 0.0069885254, 27.428339)
[node name="Node3D3" type="Node3D" parent="PatrolPath3"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10.903455, 0.0069885254, 22.506834)
[node name="PatrolPath4" type="PatrolPath" parent="."]
[node name="Node3D" type="Node3D" parent="PatrolPath4"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.0805378, 0.0069885254, -41.387714)
[node name="Node3D2" type="Node3D" parent="PatrolPath4"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.2224083, 0.00699234, -20.997375)
[node name="Node3D3" type="Node3D" parent="PatrolPath4"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -22.787289, 0.006986618, -26.568882)

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=6 format=3 uid="uid://snjgu4yp5swd"] [gd_scene load_steps=6 format=3 uid="uid://snjgu4yp5swd"]
[ext_resource type="PackedScene" uid="uid://ce40pq785yoyi" path="res://objects/weapons/rifle.tscn" id="1_eqqp1"] [ext_resource type="PackedScene" uid="uid://cfgwif53qypko" path="res://objects/weapons/revolver.tscn" id="1_eqqp1"]
[sub_resource type="SphereShape3D" id="SphereShape3D_eqqp1"] [sub_resource type="SphereShape3D" id="SphereShape3D_eqqp1"]
radius = 0.2 radius = 0.2
@ -23,7 +23,7 @@ wall_min_slide_angle = 0.0
[node name="PlayerCamera" type="PlayerCamera" parent="."] [node name="PlayerCamera" type="PlayerCamera" parent="."]
unique_name_in_owner = true unique_name_in_owner = true
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 1.60811, 0) transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0.27450943, 0)
fov = 60.0 fov = 60.0
[node name="PlayerInteractor" type="PlayerInteractor" parent="PlayerCamera"] [node name="PlayerInteractor" type="PlayerInteractor" parent="PlayerCamera"]
@ -45,10 +45,11 @@ health = 10
script = SubResource("GDScript_eqqp1") script = SubResource("GDScript_eqqp1")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.33360052, 0)
shape = SubResource("CapsuleShape3D_bxedw") shape = SubResource("CapsuleShape3D_bxedw")
[node name="Hitbox" type="Hitbox" parent="." node_paths=PackedStringArray("health")] [node name="Hitbox" type="Hitbox" parent="." node_paths=PackedStringArray("health")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.3336005, 0)
collision_layer = 8 collision_layer = 8
collision_mask = 0 collision_mask = 0
monitoring = false monitoring = false

View file

@ -14,7 +14,7 @@ anim = NodePath("revolver/AnimationPlayer")
max_ammo = 6 max_ammo = 6
loaded_ammo = 6 loaded_ammo = 6
single_action_spread = 0.003 single_action_spread = 0.003
double_action_spread = 0.02 double_action_spread = 0.04
[node name="revolver" parent="." instance=ExtResource("1_5ynga")] [node name="revolver" parent="." instance=ExtResource("1_5ynga")]