mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 08:55:35 +00:00
Shootable switches react to shots
This commit is contained in:
parent
f58b9646df
commit
35275f9048
5 changed files with 523 additions and 390 deletions
|
|
@ -1480,12 +1480,15 @@
|
||||||
{
|
{
|
||||||
"classname" "actor_controlpad_shoot"
|
"classname" "actor_controlpad_shoot"
|
||||||
"origin" "132 212 28"
|
"origin" "132 212 28"
|
||||||
|
"target" "acid_pit_door"
|
||||||
|
"activationtype" "Open"
|
||||||
}
|
}
|
||||||
// entity 47
|
// entity 47
|
||||||
{
|
{
|
||||||
"classname" "actor_door_1"
|
"classname" "actor_door_1"
|
||||||
"origin" "240 252 32"
|
"origin" "240 252 32"
|
||||||
"angles" "0 90 0"
|
"angles" "0 90 0"
|
||||||
|
"targetname" "acid_pit_door"
|
||||||
}
|
}
|
||||||
// entity 48
|
// entity 48
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[gd_scene load_steps=7 format=3 uid="uid://c8vlgg70s5u3p"]
|
[gd_scene format=3 uid="uid://c8vlgg70s5u3p"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://qxh76ahgexqa" path="res://Scripts/Interactables/Switch3D.cs" id="1_uhypp"]
|
[ext_resource type="Script" uid="uid://dlfhqyy3ya8d4" path="res://Scripts/Interactables/ShootableSwitch3D.cs" id="1_uhypp"]
|
||||||
[ext_resource type="Texture2D" uid="uid://d24g1qb40t72l" path="res://Sprites/Button_Small.png" id="2_uok2k"]
|
[ext_resource type="Texture2D" uid="uid://d24g1qb40t72l" path="res://Sprites/Button_Small.png" id="2_uok2k"]
|
||||||
[ext_resource type="AudioStream" uid="uid://bjvklk7qmlivd" path="res://SFX/288963__littlerobotsoundfactory__click_electronic_14.wav" id="3_pmslt"]
|
[ext_resource type="AudioStream" uid="uid://bjvklk7qmlivd" path="res://SFX/288963__littlerobotsoundfactory__click_electronic_14.wav" id="3_pmslt"]
|
||||||
[ext_resource type="AudioStream" uid="uid://myr6n2c1u503" path="res://SFX/581602__samsterbirdies__beep-error.mp3" id="4_4smss"]
|
[ext_resource type="AudioStream" uid="uid://myr6n2c1u503" path="res://SFX/581602__samsterbirdies__beep-error.mp3" id="4_4smss"]
|
||||||
|
|
@ -9,14 +9,14 @@
|
||||||
[sub_resource type="SphereShape3D" id="SphereShape3D_itd0i"]
|
[sub_resource type="SphereShape3D" id="SphereShape3D_itd0i"]
|
||||||
radius = 0.868968
|
radius = 0.868968
|
||||||
|
|
||||||
[node name="ControlPad" type="Area3D" node_paths=PackedStringArray("Targets") groups=["Interactable"]]
|
[node name="ControlPad" type="Area3D" unique_id=454991887 groups=["Interactable"]]
|
||||||
collision_layer = 32
|
collision_layer = 0
|
||||||
collision_mask = 0
|
collision_mask = 136
|
||||||
script = ExtResource("1_uhypp")
|
script = ExtResource("1_uhypp")
|
||||||
Targets = []
|
ReactsTo = 1
|
||||||
metadata/_edit_group_ = true
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
[node name="Sprite3D" type="Sprite3D" parent="."]
|
[node name="Sprite3D" type="Sprite3D" parent="." unique_id=1668220059]
|
||||||
transform = Transform3D(1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 0, 0)
|
transform = Transform3D(1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 0, 0)
|
||||||
visible = false
|
visible = false
|
||||||
pixel_size = 0.1
|
pixel_size = 0.1
|
||||||
|
|
@ -24,17 +24,17 @@ texture_filter = 0
|
||||||
texture = ExtResource("2_uok2k")
|
texture = ExtResource("2_uok2k")
|
||||||
hframes = 4
|
hframes = 4
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=1191207257]
|
||||||
shape = SubResource("SphereShape3D_itd0i")
|
shape = SubResource("SphereShape3D_itd0i")
|
||||||
|
|
||||||
[node name="ActivationSound" type="AudioStreamPlayer3D" parent="."]
|
[node name="ActivationSound" type="AudioStreamPlayer3D" parent="." unique_id=1198083209]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.15351868)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.15351868)
|
||||||
stream = ExtResource("3_pmslt")
|
stream = ExtResource("3_pmslt")
|
||||||
bus = &"Effects"
|
bus = &"Effects"
|
||||||
|
|
||||||
[node name="DenySound" type="AudioStreamPlayer3D" parent="."]
|
[node name="DenySound" type="AudioStreamPlayer3D" parent="." unique_id=924351038]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.15351868)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.15351868)
|
||||||
stream = ExtResource("4_4smss")
|
stream = ExtResource("4_4smss")
|
||||||
bus = &"Effects"
|
bus = &"Effects"
|
||||||
|
|
||||||
[node name="blockbench_export2" parent="." instance=ExtResource("5_uhypp")]
|
[node name="blockbench_export2" parent="." unique_id=920256639 instance=ExtResource("5_uhypp")]
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
127
Scripts/Interactables/ShootableSwitch3D.cs
Normal file
127
Scripts/Interactables/ShootableSwitch3D.cs
Normal file
|
|
@ -0,0 +1,127 @@
|
||||||
|
using Cirno.Scripts.Weapons;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Cirno.Scripts.Interactables;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A Switch3D variant that activates when hit by a Bullet3D.
|
||||||
|
/// Supports filtering by bullet owner and an optional cooldown between activations.
|
||||||
|
/// </summary>
|
||||||
|
[Tool]
|
||||||
|
public partial class ShootableSwitch3D : Switch3D
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Which bullet owner can trigger this switch.
|
||||||
|
/// None means both Player and Enemy bullets are accepted.
|
||||||
|
/// </summary>
|
||||||
|
[Export] public BulletOwner ReactsTo { get; set; } = BulletOwner.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Minimum time in seconds between consecutive activations. 0 disables the cooldown.
|
||||||
|
/// </summary>
|
||||||
|
[Export] public float CooldownSeconds { get; set; } = 0f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enable runtime debug logging for this node. Toggle in the editor to diagnose bullet-trigger behavior.
|
||||||
|
/// </summary>
|
||||||
|
[Export]
|
||||||
|
public bool EnableDebugLogs { get; set; } = false;
|
||||||
|
|
||||||
|
private double _cooldownRemaining = 0.0;
|
||||||
|
|
||||||
|
// Track whether we were on cooldown last frame so we don't spam logs every frame.
|
||||||
|
private bool _wasOnCooldown = false;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
base._Ready();
|
||||||
|
|
||||||
|
Log($"_Ready() called (EditorHint={Engine.IsEditorHint()})");
|
||||||
|
|
||||||
|
// Log the initial ActivationType (name + numeric) to make it obvious what value was deserialized.
|
||||||
|
Log($"Initial ActivationType={ActivationType} ({(int)ActivationType})");
|
||||||
|
|
||||||
|
if (Engine.IsEditorHint()) return;
|
||||||
|
|
||||||
|
AreaEntered += OnAreaEntered;
|
||||||
|
|
||||||
|
Log("Subscribed to AreaEntered events");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
if (_cooldownRemaining > 0.0)
|
||||||
|
{
|
||||||
|
// Log only when cooldown starts/ends to avoid spamming the console every frame.
|
||||||
|
if (!_wasOnCooldown)
|
||||||
|
{
|
||||||
|
Log($"Cooldown started: {_cooldownRemaining:F2}s");
|
||||||
|
_wasOnCooldown = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_cooldownRemaining -= delta;
|
||||||
|
|
||||||
|
if (_cooldownRemaining <= 0.0 && _wasOnCooldown)
|
||||||
|
{
|
||||||
|
Log("Cooldown ended");
|
||||||
|
_wasOnCooldown = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAreaEntered(Area3D area)
|
||||||
|
{
|
||||||
|
Log($"AreaEntered event received from: {area?.GetType().Name}");
|
||||||
|
|
||||||
|
if (area is not Bullet3D bullet)
|
||||||
|
{
|
||||||
|
Log("Area is not a Bullet3D - ignoring");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log($"Bullet detected - Enabled={bullet.Enabled}, Owner={bullet.BulletOwner}");
|
||||||
|
|
||||||
|
if (!bullet.Enabled)
|
||||||
|
{
|
||||||
|
Log("Bullet is disabled - ignoring");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter by owner if a specific owner is configured
|
||||||
|
if (ReactsTo is not BulletOwner.None && bullet.BulletOwner != ReactsTo)
|
||||||
|
{
|
||||||
|
Log($"Bullet owner {bullet.BulletOwner} does not match configured ReactsTo={ReactsTo} - ignoring");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_cooldownRemaining > 0.0)
|
||||||
|
{
|
||||||
|
Log($"On cooldown ({_cooldownRemaining:F2}s remaining) - ignoring");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log("Requesting bullet collision destruction");
|
||||||
|
bullet.RequestCollisionDestruction();
|
||||||
|
|
||||||
|
// Include the numeric value when logging so it's easy to cross-reference serialized files.
|
||||||
|
Log($"Activating switch (ActivationType={ActivationType} ({(int)ActivationType}))");
|
||||||
|
Activate(ActivationType);
|
||||||
|
|
||||||
|
if (CooldownSeconds > 0f)
|
||||||
|
{
|
||||||
|
_cooldownRemaining = CooldownSeconds;
|
||||||
|
Log($"Cooldown set to {CooldownSeconds:F2}s");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper to centralize debug printing and include the node name for easier filtering.
|
||||||
|
/// Respects the <see cref="EnableDebugLogs"/> toggle.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">Message to print when logging is enabled.</param>
|
||||||
|
private void Log(string message)
|
||||||
|
{
|
||||||
|
if (!EnableDebugLogs) return;
|
||||||
|
GD.Print($"[ShootableSwitch3D:{Name}] {message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
1
Scripts/Interactables/ShootableSwitch3D.cs.uid
Normal file
1
Scripts/Interactables/ShootableSwitch3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dlfhqyy3ya8d4
|
||||||
Loading…
Add table
Add a link
Reference in a new issue