2026-03-16 23:35:22 +08:00
|
|
|
extends BulletBase
|
|
|
|
|
class_name ParrierBullet
|
|
|
|
|
|
2026-03-17 06:49:46 +08:00
|
|
|
@export var parryRate: float = 1
|
|
|
|
|
|
2026-03-21 13:51:17 +08:00
|
|
|
var parryiedTimes: int = 0
|
|
|
|
|
var maxParryTimes: int = 1
|
2026-04-25 14:11:05 +08:00
|
|
|
var maxBallCount: int = 5
|
2026-04-24 18:09:24 +08:00
|
|
|
var atk: float = 1
|
2026-04-25 14:11:05 +08:00
|
|
|
var reflectRate: float = 1
|
2026-03-21 13:51:17 +08:00
|
|
|
|
2026-03-21 18:55:32 +08:00
|
|
|
func spawn():
|
2026-03-27 23:04:20 +08:00
|
|
|
var varians = randi_range(0, 1)
|
2026-03-21 23:09:40 +08:00
|
|
|
var inverts = [2]
|
2026-03-21 18:55:32 +08:00
|
|
|
var frames = load("res://resources/effects/parrier/%d/%d.tres" % [varians, varians])
|
|
|
|
|
var eff = EffectController.create(ComponentManager.getEffect("Parrier"), position)
|
|
|
|
|
eff.rotation = rotation
|
2026-03-21 23:09:40 +08:00
|
|
|
eff.texture.scale.y *= MathTool.randomChoiceFrom([-1, 1])
|
2026-03-21 18:55:32 +08:00
|
|
|
if varians in inverts:
|
2026-03-21 23:09:40 +08:00
|
|
|
eff.texture.scale.x *= -1
|
2026-03-21 18:55:32 +08:00
|
|
|
eff.texture.sprite_frames = frames
|
|
|
|
|
eff.shot()
|
2026-03-28 11:55:16 +08:00
|
|
|
func succeedToHit(_dmg: float, entity: EntityBase):
|
2026-04-02 22:39:29 +08:00
|
|
|
if parryiedTimes < maxParryTimes && MathTool.rate(parryRate):
|
2026-03-28 11:55:16 +08:00
|
|
|
parryiedTimes += 1
|
2026-03-28 12:25:45 +08:00
|
|
|
var effSpawn = entity.texture.global_position
|
|
|
|
|
var eff = EffectController.create(ComponentManager.getEffect("ParryEntity"), effSpawn)
|
|
|
|
|
eff.rotation = position.angle_to_point(effSpawn)
|
2026-03-28 11:55:16 +08:00
|
|
|
eff.shot()
|
2026-04-02 22:39:29 +08:00
|
|
|
entity.impluse((effSpawn - position).normalized() * 450)
|
2026-03-19 22:58:50 +08:00
|
|
|
func hitBullet(bullet: BulletBase): # 当前子弹与其他子弹相撞
|
2026-04-25 13:17:17 +08:00
|
|
|
if !is_instance_valid(launcher): return
|
2026-03-19 22:58:50 +08:00
|
|
|
if BulletTool.canDamage(bullet, launcher): # 其他子弹可以使当前子弹的发射者受伤吗?
|
2026-03-21 13:51:17 +08:00
|
|
|
if parryiedTimes < maxParryTimes && MathTool.rate(parryRate): # 一个刀光最多格挡多少个敌方子弹?
|
|
|
|
|
parryiedTimes += 1
|
2026-03-19 22:58:50 +08:00
|
|
|
# 生成格挡特效
|
2026-03-21 18:55:32 +08:00
|
|
|
var eff = EffectController.create(ComponentManager.getEffect("Parry"), position + (bullet.position - position).normalized() * 200) # 从子弹位置,面向其他子弹的方向前进150
|
2026-03-17 22:15:28 +08:00
|
|
|
eff.modulate = bullet.modulate.blend(bullet.texture.modulate)
|
2026-03-22 14:12:02 +08:00
|
|
|
eff.rotation = position.angle_to_point(bullet.position)
|
2026-03-17 06:49:46 +08:00
|
|
|
eff.shot()
|
2026-04-29 22:09:59 +08:00
|
|
|
launcher.impluse((position - bullet.position).normalized() * bullet.speed ** (1.0 / 2) * 250)
|
2026-03-28 10:45:46 +08:00
|
|
|
var targetBaseDamage = bullet.baseDamage
|
2026-04-30 06:39:56 +08:00
|
|
|
if bullet.motionType == BulletBase.MotionType.PROJECTILE:
|
|
|
|
|
# 弹反 还是 格挡?
|
|
|
|
|
if MathTool.rate(reflectRate):
|
|
|
|
|
bullet.look_at(bullet.launcher.getTrackingAnchor())
|
|
|
|
|
bullet.launcher = launcher
|
|
|
|
|
bullet.baseDamage *= atk
|
|
|
|
|
bullet.baseDamage *= reflectRate
|
|
|
|
|
bullet.lifeTime *= 2
|
|
|
|
|
if bullet.freeAfterSpawn && bullet.autoSpawnAnimation:
|
|
|
|
|
bullet.animator.speed_scale *= 0.5
|
|
|
|
|
else:
|
|
|
|
|
bullet.tryDestroy()
|
|
|
|
|
elif bullet.motionType == BulletBase.MotionType.SWING:
|
|
|
|
|
bullet.hitbox.disabled = true
|
2026-04-30 06:42:15 +08:00
|
|
|
elif bullet.motionType == BulletBase.MotionType.SPRINT:
|
|
|
|
|
bullet.tryDestroy()
|
|
|
|
|
bullet.launcher.velocity *= -0.1
|
2026-04-30 06:39:56 +08:00
|
|
|
elif bullet.motionType == BulletBase.MotionType.SUMMON || bullet.motionType == BulletBase.MotionType.MAGIC:
|
|
|
|
|
launcher.storeEnergy(sqrt(bullet.baseDamage))
|
2026-03-17 22:58:04 +08:00
|
|
|
var cycler = launcher.getOrCreateCycleTimer("parry", 2000, 100)
|
2026-03-22 14:12:02 +08:00
|
|
|
if len(cycler.bullets) < maxBallCount: # 玩家最多只能拥有多少气
|
2026-03-17 22:58:04 +08:00
|
|
|
for b in BulletBase.generate(
|
2026-03-19 22:58:50 +08:00
|
|
|
ComponentManager.getBullet("ParryBall"), # 生成气的子弹
|
2026-03-17 22:58:04 +08:00
|
|
|
launcher,
|
|
|
|
|
position,
|
|
|
|
|
0
|
|
|
|
|
):
|
|
|
|
|
if b is ParryBallBullet:
|
2026-03-28 10:45:46 +08:00
|
|
|
b.atk = atk * targetBaseDamage
|
2026-03-22 08:16:35 +08:00
|
|
|
func refract(_newBullet: BulletBase, _entity: EntityBase, _index: int, _total: int, _lastBullet: float):
|
|
|
|
|
return null
|
|
|
|
|
func split(_newBullet: BulletBase, _index: int, _total: int, _lastBullet: float):
|
|
|
|
|
return null
|