mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-27 22:41:56 +08:00
fix(BulletBase): 修复子弹分裂和折射时的空引用问题
确保在子弹分裂和折射时检查返回的子弹对象是否有效,避免空引用异常
This commit is contained in:
@@ -39,3 +39,7 @@ func hitBullet(bullet: BulletBase): # 当前子弹与其他子弹相撞
|
||||
):
|
||||
if b is ParryBallBullet:
|
||||
b.atk = atk * bullet.baseDamage
|
||||
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
|
||||
|
||||
@@ -13,6 +13,7 @@ func destroy(_beacuseMap: bool):
|
||||
func ai():
|
||||
PresetBulletAI.selfRotate(self , 5)
|
||||
hitbox.disabled = !launcher.sprinting # 玩家在冲刺时气的碰撞箱才生效
|
||||
hitbox.global_position = launcher.position
|
||||
func succeedToHit(_dmg: float, entity: EntityBase): # 当撞到敌人时
|
||||
for bullet in BulletBase.generate(
|
||||
ComponentManager.getBullet("QKSword"),
|
||||
|
||||
@@ -37,6 +37,7 @@ var initialSpeed: float = 0
|
||||
var initialDamage: float = 0
|
||||
var speedScale: float = 1
|
||||
var isFirstFrame: bool = true
|
||||
var cycleStateAngle: float = 0
|
||||
|
||||
func _ready():
|
||||
initialSpeed = speed
|
||||
@@ -182,7 +183,9 @@ func trySplit():
|
||||
cloned.launcher = launcher
|
||||
if is_instance_valid(parent):
|
||||
cloned.parent = parent
|
||||
get_parent().add_child.call_deferred(split(cloned, i, total, last))
|
||||
var splited = split(cloned, i, total, last)
|
||||
if !is_instance_valid(splited): continue
|
||||
get_parent().add_child.call_deferred(splited)
|
||||
func tryRefract():
|
||||
if is_instance_valid(launcher) and canDuplicateSelf:
|
||||
var value = launcher.fields.get(FieldStore.Entity.BULLET_REFRACTION)
|
||||
@@ -204,7 +207,9 @@ func tryRefract():
|
||||
cloned.launcher = launcher
|
||||
if is_instance_valid(parent):
|
||||
cloned.parent = parent
|
||||
get_parent().add_child.call_deferred(refract(cloned, entity, i, total, last))
|
||||
var refracted = refract(cloned, entity, i, total, last)
|
||||
if !is_instance_valid(refracted): continue
|
||||
get_parent().add_child.call_deferred(refracted)
|
||||
|
||||
# 抽象方法
|
||||
func firstFrame():
|
||||
|
||||
@@ -12,13 +12,15 @@ func start():
|
||||
running = true
|
||||
func lifetime():
|
||||
return Time.get_ticks_msec() - startTime
|
||||
func periodPercent(count: int):
|
||||
return lifetime() / period * deg_to_rad(360) - deg_to_rad(360.0 * count / len(bullets))
|
||||
func getStateAngle(index: int):
|
||||
return lifetime() / period * deg_to_rad(360) - deg_to_rad(360.0 * index / len(bullets))
|
||||
func apply():
|
||||
bullets = bullets.filter(is_instance_valid)
|
||||
for index in len(bullets):
|
||||
var bullet = bullets[index]
|
||||
var offset = Vector2.from_angle(periodPercent(index))
|
||||
var newStateAngle = lerp_angle(bullet.cycleStateAngle, getStateAngle(index), 0.1)
|
||||
var offset = Vector2.from_angle(newStateAngle)
|
||||
bullet.cycleStateAngle = newStateAngle
|
||||
offset.y *= 0.25
|
||||
bullet.position = bullet.launcher.position + offset * distance
|
||||
bullet.scale = Vector2.ONE * (1 + offset.y)
|
||||
|
||||
Reference in New Issue
Block a user