Updated WeaponTemplate's FiringInterval calculation so that it can be changed by FiringIntervalAsMillisecond even after instantiation.

更新了WeaponTemplate的FiringInterval计算方式以使该值即便在实例化之后也可通过FiringIntervalAsMillisecond更改
This commit is contained in:
霧雨烨 2024-06-15 17:16:41 +08:00
parent 197930f446
commit edaa490b5b
2 changed files with 12 additions and 3 deletions

View File

@ -16,6 +16,7 @@ collision_mask = 34
script = ExtResource("1_w8hhv") script = ExtResource("1_w8hhv")
ProjectileScenes = [ExtResource("2_34250")] ProjectileScenes = [ExtResource("2_34250")]
Id = "staff_of_the_undead" Id = "staff_of_the_undead"
FiringIntervalAsMillisecond = 300
metadata/Projectiles = PackedStringArray("res://prefab/projectile/curseOfTheUndead.tscn") metadata/Projectiles = PackedStringArray("res://prefab/projectile/curseOfTheUndead.tscn")
[node name="DamageArea2D" type="Area2D" parent="."] [node name="DamageArea2D" type="Area2D" parent="."]

View File

@ -3,6 +3,7 @@ using System;
using ColdMint.scripts.camp; using ColdMint.scripts.camp;
using ColdMint.scripts.character; using ColdMint.scripts.character;
using ColdMint.scripts.damage; using ColdMint.scripts.damage;
using Godot; using Godot;
namespace ColdMint.scripts.item.weapon; namespace ColdMint.scripts.item.weapon;
@ -70,7 +71,16 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem
/// <para>开火间隔</para> /// <para>开火间隔</para>
/// </summary> /// </summary>
private TimeSpan _firingInterval; private TimeSpan _firingInterval;
[Export] private long _firingIntervalAsMillisecond = 100; private long _firingIntervalAsMillisecond = 100;
[Export] protected long FiringIntervalAsMillisecond
{
get => _firingIntervalAsMillisecond;
set
{
_firingIntervalAsMillisecond = value;
_firingInterval = TimeSpan.FromMilliseconds(_firingIntervalAsMillisecond);
}
}
/// <summary> /// <summary>
@ -101,8 +111,6 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem
_damageArea2D = GetNode<Area2D>("DamageArea2D"); _damageArea2D = GetNode<Area2D>("DamageArea2D");
_damageArea2D.BodyEntered += OnBodyEnter; _damageArea2D.BodyEntered += OnBodyEnter;
_damageArea2D.BodyExited += OnBodyExited; _damageArea2D.BodyExited += OnBodyExited;
_firingInterval = TimeSpan.FromMilliseconds(_firingIntervalAsMillisecond);
} }
private void OnBodyExited(Node node) private void OnBodyExited(Node node)