From 5cef96cd349ac740737afe9be62d2ac2c9adf0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Thu, 30 Apr 2026 18:32:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor(Bullets):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=AD=90=E5=BC=B9=E6=A0=BC=E6=8C=A1=E9=80=BB=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E6=8F=90=E5=8F=96=E5=85=AC=E5=85=B1=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构Parrier.gd中的格挡逻辑,将重复代码提取为parryEffect和penerateEffect方法 调整FoxZhua子弹的追踪位置和场景配置 修改waveDebugConfig使用测试BOSS而非测试小怪 --- components/Bullets/FoxZhua.tscn | 20 +++++----- scripts/Contents/Bullets/FoxZhua.gd | 2 +- scripts/Contents/Bullets/Parrier.gd | 62 ++++++++++++++++++----------- scripts/Contents/Wave.gd | 2 +- 4 files changed, 50 insertions(+), 36 deletions(-) diff --git a/components/Bullets/FoxZhua.tscn b/components/Bullets/FoxZhua.tscn index a8924c5..efba2a4 100644 --- a/components/Bullets/FoxZhua.tscn +++ b/components/Bullets/FoxZhua.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://btqtch0v58e7h"] +[gd_scene format=3 uid="uid://btqtch0v58e7h"] [ext_resource type="PackedScene" uid="uid://crtdkysmnkith" path="res://components/Abstracts/BulletBase.tscn" id="1_461id"] [ext_resource type="Texture2D" uid="uid://ddvmfyk2g4r1m" path="res://resources/bullets/fox-zhua/zhua.webp" id="2_45k2a"] @@ -192,33 +192,31 @@ _data = { radius = 91.0 height = 290.0 -[node name="FoxZhua" instance=ExtResource("1_461id")] +[node name="FoxZhua" unique_id=1451377674 instance=ExtResource("1_461id")] script = ExtResource("2_rl21b") canTrace = true displayName = "爪" speed = 0.07 +motionType = 0 penerate = 1.0 -indisDamage = true canDamageSelf = true autoSpawnAnimation = true freeAfterSpawn = true -[node name="texture" parent="." index="0"] +[node name="texture" parent="." index="0" unique_id=162977358] modulate = Color(1, 1, 1, 0) +position = Vector2(-400, 0) rotation = -0.7853982 scale = Vector2(0.5, 0.5) sprite_frames = SubResource("SpriteFrames_rl21b") -[node name="animator" parent="texture" index="0"] -libraries = { -&"": SubResource("AnimationLibrary_45k2a") -} +[node name="animator" parent="texture" index="0" unique_id=1114087117] +libraries/ = SubResource("AnimationLibrary_45k2a") -[node name="hand" type="Sprite2D" parent="texture" index="1"] +[node name="hand" type="Sprite2D" parent="texture" index="1" unique_id=314757183] position = Vector2(50, 0) texture = ExtResource("2_45k2a") -[node name="hitbox" parent="." index="1"] -position = Vector2(369, -1) +[node name="hitbox" parent="." index="1" unique_id=175349408] shape = SubResource("CapsuleShape2D_45k2a") disabled = true diff --git a/scripts/Contents/Bullets/FoxZhua.gd b/scripts/Contents/Bullets/FoxZhua.gd index 0a6304a..dffc916 100644 --- a/scripts/Contents/Bullets/FoxZhua.gd +++ b/scripts/Contents/Bullets/FoxZhua.gd @@ -5,4 +5,4 @@ class_name FoxZhua func ai(): if canTrace: - PresetBulletAI.lerpPosition(self, launcher.currentFocusedBoss.getTrackingAnchor() - Vector2(0, 200), speed) + PresetBulletAI.lerpPosition(self , launcher.currentFocusedBoss.getTrackingAnchor(), speed) diff --git a/scripts/Contents/Bullets/Parrier.gd b/scripts/Contents/Bullets/Parrier.gd index b625a3a..b736734 100644 --- a/scripts/Contents/Bullets/Parrier.gd +++ b/scripts/Contents/Bullets/Parrier.gd @@ -9,6 +9,32 @@ var maxBallCount: int = 5 var atk: float = 1 var reflectRate: float = 1 +func parryEffect(bullet: BulletBase): + # 生成格挡特效 + parryiedTimes += 1 + var eff = EffectController.create(ComponentManager.getEffect("Parry"), position + (bullet.position - position).normalized() * 200) # 从子弹位置,面向其他子弹的方向前进150 + eff.modulate = bullet.modulate.blend(bullet.texture.modulate) + eff.rotation = position.angle_to_point(bullet.position) + eff.shot() + launcher.impluse((position - bullet.position).normalized() * bullet.speed ** (1.0 / 2) * 250) +func penerateEffect(entity: EntityBase): + parryiedTimes += 1 + var eff = EffectController.create(ComponentManager.getEffect("ParryEntity"), position) + eff.rotation = position.angle_to_point(position) + eff.shot() + entity.impluse((position - entity.position).normalized() * 450) +func generateParryBall(targetBaseDamage: float): + var cycler = launcher.getOrCreateCycleTimer("parry", 2000, 100) + if len(cycler.bullets) < maxBallCount: # 玩家最多只能拥有多少气 + for b in BulletBase.generate( + ComponentManager.getBullet("ParryBall"), # 生成气的子弹 + launcher, + position, + 0 + ): + if b is ParryBallBullet: + b.atk = atk * targetBaseDamage + func spawn(): var varians = randi_range(0, 1) var inverts = [2] @@ -22,25 +48,17 @@ func spawn(): eff.shot() func succeedToHit(_dmg: float, entity: EntityBase): if parryiedTimes < maxParryTimes && MathTool.rate(parryRate): - parryiedTimes += 1 - var effSpawn = entity.texture.global_position - var eff = EffectController.create(ComponentManager.getEffect("ParryEntity"), effSpawn) - eff.rotation = position.angle_to_point(effSpawn) - eff.shot() - entity.impluse((effSpawn - position).normalized() * 450) + penerateEffect(entity) func hitBullet(bullet: BulletBase): # 当前子弹与其他子弹相撞 if !is_instance_valid(launcher): return if BulletTool.canDamage(bullet, launcher): # 其他子弹可以使当前子弹的发射者受伤吗? if parryiedTimes < maxParryTimes && MathTool.rate(parryRate): # 一个刀光最多格挡多少个敌方子弹? - parryiedTimes += 1 - # 生成格挡特效 - var eff = EffectController.create(ComponentManager.getEffect("Parry"), position + (bullet.position - position).normalized() * 200) # 从子弹位置,面向其他子弹的方向前进150 - eff.modulate = bullet.modulate.blend(bullet.texture.modulate) - eff.rotation = position.angle_to_point(bullet.position) - eff.shot() - launcher.impluse((position - bullet.position).normalized() * bullet.speed ** (1.0 / 2) * 250) var targetBaseDamage = bullet.baseDamage + # 可以格挡 挥舞运动(近战攻击)、射弹运动(远程攻击)和猛冲运动 的子弹,射弹如果被弹反则不会产生气力 + # 魔法运动和召唤运动的子弹虽不能格挡,但是可以储能,吐息运动的子弹会对发射者产生击退 if bullet.motionType == BulletBase.MotionType.PROJECTILE: + # 无论如何都要生成格挡特效 + parryEffect(bullet) # 弹反 还是 格挡? if MathTool.rate(reflectRate): bullet.look_at(bullet.launcher.getTrackingAnchor()) @@ -52,26 +70,24 @@ func hitBullet(bullet: BulletBase): # 当前子弹与其他子弹相撞 bullet.animator.speed_scale *= 0.5 else: bullet.tryDestroy() + generateParryBall(targetBaseDamage) elif bullet.motionType == BulletBase.MotionType.SWING: + parryEffect(bullet) bullet.hitbox.disabled = true + generateParryBall(targetBaseDamage) elif bullet.motionType == BulletBase.MotionType.SPRINT: + parryEffect(bullet) bullet.tryDestroy() bullet.launcher.velocity *= -0.1 + generateParryBall(targetBaseDamage) elif bullet.motionType == BulletBase.MotionType.BREATH: + penerateEffect(bullet.launcher) bullet.hitbox.disable = true bullet.launcher.impluse(Vector2.from_angle(bullet.rotation) * -500) elif bullet.motionType == BulletBase.MotionType.SUMMON || bullet.motionType == BulletBase.MotionType.MAGIC: + penerateEffect(bullet.launcher) launcher.storeEnergy(sqrt(bullet.baseDamage)) - var cycler = launcher.getOrCreateCycleTimer("parry", 2000, 100) - if len(cycler.bullets) < maxBallCount: # 玩家最多只能拥有多少气 - for b in BulletBase.generate( - ComponentManager.getBullet("ParryBall"), # 生成气的子弹 - launcher, - position, - 0 - ): - if b is ParryBallBullet: - b.atk = atk * targetBaseDamage + func refract(_newBullet: BulletBase, _entity: EntityBase, _index: int, _total: int, _lastBullet: float): return null func split(_newBullet: BulletBase, _index: int, _total: int, _lastBullet: float): diff --git a/scripts/Contents/Wave.gd b/scripts/Contents/Wave.gd index 7b547e4..edf53d0 100644 --- a/scripts/Contents/Wave.gd +++ b/scripts/Contents/Wave.gd @@ -57,7 +57,7 @@ static var WAVE_TESTMOB = [ ] static var WAVE_EMPTY = [] static var waveReleaseConfig = [WAVE_TESTBOSS, 1] -static var waveDebugConfig = [WAVE_TESTMOB, 1] +static var waveDebugConfig = [WAVE_TESTBOSS, 1] static var current: int = startWith(waveReleaseConfig[1]) if WorldManager.isRelease() else startWith(waveDebugConfig[1]) static var data = waveReleaseConfig[0] if WorldManager.isRelease() else waveDebugConfig[0]