1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-31 08:21:54 +08:00

feat(武器系统): 重构武器攻击逻辑并添加音效支持

- 将武器攻击逻辑移至Weapon类中,添加tryAttack方法统一处理冷却和能量消耗
- 为武器添加音效支持,包括攻击音效的播放和管理
- 移除子弹生成时的能量消耗检查,改由武器统一处理
- 调整部分武器的属性和配置,如伤害值和冷却时间
- 修复紫水晶子弹的分裂和折射逻辑错误
This commit is contained in:
2025-09-06 08:50:37 +08:00
parent c593a809dc
commit 9ea534441b
10 changed files with 51 additions and 25 deletions
+3 -2
View File
@@ -11,7 +11,8 @@ func split(index, total, _last):
launcher,
position,
deg_to_rad(360 / total * index),
true
true,
isChildRefract
)
func refract(entity, _index, _total, _last):
BulletBase.generate(
@@ -19,6 +20,6 @@ func refract(entity, _index, _total, _last):
launcher,
position,
position.angle_to_point(entity.position) if is_instance_valid(entity) else randf_range(0, deg_to_rad(360)),
false,
isChildSplit,
true
)
+1 -1
View File
@@ -2,6 +2,6 @@ extends BulletBase
class_name Star
func register():
damage = 1
damage = 5
func ai():
PresetAIs.forward(self, rotation)
+8 -10
View File
@@ -8,7 +8,6 @@ class_name BulletBase
@export var lifeTime: float = -1 # -1表示无限时间
@export var indisDamage: bool = false # 是否无差别伤害(不区分敌我)
@export var canDamageSelf: bool = false # 是否可以伤害发射者
@export var needEnergy: float = 0.0 # 发射时需要消耗的能量
@export var autoSpawnAnimation: bool = false
@export var autoLoopAnimation: bool = false
@export var autoDestroyAnimation: bool = false
@@ -139,13 +138,12 @@ static func generate(
var instances = []
for i in range(count):
var instance: BulletBase = bullet.instantiate()
if launchBy.useEnergy(instance.needEnergy):
instance.isChildSplit = asChildSplit
instance.isChildRefract = asChildRefract
instance.launcher = launchBy
instance.position = spawnPosition
instance.rotation = spawnRotation + deg_to_rad(randf_range(-launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT), launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT)))
if addToWorld:
WorldManager.rootNode.call_deferred("add_child", instance)
instances.append(instance)
instance.isChildSplit = asChildSplit
instance.isChildRefract = asChildRefract
instance.launcher = launchBy
instance.position = spawnPosition
instance.rotation = spawnRotation + deg_to_rad(randf_range(-launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT), launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT)))
if addToWorld:
WorldManager.rootNode.call_deferred("add_child", instance)
instances.append(instance)
return len(instances)
+5 -6
View File
@@ -199,7 +199,7 @@ func tryAttack(type: int, needChargeUp: bool = false):
weapon = weapons[type]
var state
if isPlayer():
state = weapon.cooldownTimer.start()
state = true
else:
cooldownTimer.cooldown = attackCooldownMap.get(type, defaultCooldownUnit)
state = cooldownTimer.start()
@@ -208,13 +208,12 @@ func tryAttack(type: int, needChargeUp: bool = false):
charginup = true
await EffectController.create(preload("res://components/Effects/AttackStar.tscn"), damageAnchor.global_position).shot()
charginup = false
var done
if isPlayer():
done = weapon.attack(self)
if weapon.tryAttack(self):
weapon.playSound("attack")
else:
done = attack(type)
if done:
playSound("attack" + str(type))
if attack(type):
playSound("attack" + str(type))
return state
func trySprint():
trailing = true
+15
View File
@@ -27,6 +27,7 @@ signal selected(applied: bool)
@onready var descriptionLabel: RichTextLabel = $"%description"
@onready var costsBox: GridContainer = $"%costs"
@onready var updateButton: Button = $"%updateBtn"
@onready var sounds: Node2D = $"%sounds"
var cooldownTimer = CooldownTimer.new()
@@ -36,6 +37,8 @@ func _ready():
apply(UIState.player)
)
cooldownTimer.cooldown = cooldown
for i in sounds.get_children():
i.process_mode = ProcessMode.PROCESS_MODE_ALWAYS
rebuildInfo()
debugRebuild = false # 只能在编辑器里打开
func _physics_process(_delta):
@@ -99,6 +102,18 @@ func buildDescription():
return "[center]%s[/center]" % result
func readStore(key: String, default: Variant = null):
return store.get(key, default)
func playSound(sound: String):
var body = sounds.get_node_or_null(sound)
if body is AudioStreamPlayer2D:
var cloned = body.duplicate() as AudioStreamPlayer2D
add_child(cloned)
cloned.play()
await cloned.finished
cloned.queue_free()
func tryAttack(entity: EntityBase):
if cooldownTimer.start():
if entity.useEnergy(needEnergy):
attack(entity)
# 抽象
func update(_to: int, _origin: Dictionary, _entity: EntityBase):