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

refactor(BulletBase): 重构子弹分裂和折射逻辑,移除parentScene字段

将子弹分裂和折射的逻辑从静态生成方法改为实例克隆方式,简化代码结构并提高可维护性。移除不再使用的parentScene字段,相关功能通过克隆实例实现。
This commit is contained in:
2026-01-17 12:21:38 +08:00
parent d3ac495ddb
commit 4f25daf987
+10 -22
View File
@@ -35,7 +35,6 @@ var isChildRefract: bool = false
var initialSpeed: float = 0
var initialDamage: float = 0
var speedScale: float = 1
var parentScene: PackedScene = null
var isFirstFrame: bool = true
func _ready():
@@ -150,7 +149,9 @@ func trySplit():
var total = MathTool.shrimpRate(value)
var last = value - floor(value)
for i in total:
split(i, total, last)
var cloned = duplicate() as BulletBase
cloned.rotation = deg_to_rad(360.0 / total * i)
split(cloned, i, total, last)
func tryRefract():
if is_instance_valid(launcher) and !isChildRefract:
var value = launcher.fields.get(FieldStore.Entity.BULLET_REFRACTION)
@@ -159,7 +160,9 @@ func tryRefract():
for i in total:
var entity = EntityTool.findClosetEntity(position, get_tree(), !launcher.isPlayer(), launcher.isPlayer(), [launcher])
if is_instance_valid(entity):
refract(entity, i, total, last)
var cloned = duplicate() as BulletBase
cloned.look_at(entity.position)
refract(cloned, entity, i, total, last)
# 抽象方法
func firstFrame():
@@ -176,24 +179,10 @@ func succeedToHit(_dmg: float, _entity: EntityBase):
pass
func register():
pass
func split(index: int, total: int, _lastBullet: float):
BulletBase.generate(
parentScene,
launcher,
position,
rotation + deg_to_rad(360.0 / total * index),
true,
isChildRefract
)
func refract(entity: EntityBase, _index: int, _total: int, _lastBullet: float):
BulletBase.generate(
parentScene,
launcher,
position,
position.angle_to_point(entity.position) if is_instance_valid(entity) else randf_range(0, deg_to_rad(360)),
isChildSplit,
true
)
func split(_newBullet: BulletBase, _index: int, _total: int, _lastBullet: float):
pass
func refract(_newBullet: BulletBase, _entity: EntityBase, _index: int, _total: int, _lastBullet: float):
pass
static func generate(
bullet: PackedScene,
@@ -214,7 +203,6 @@ static func generate(
instance.isChildRefract = asChildRefract
instance.launcher = launchBy
instance.position = spawnPosition
instance.parentScene = bullet
instance.rotation = spawnRotation + deg_to_rad(launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT) * randf_range(-1, 1) * int(!ignoreOffset))
if addToWorld:
WorldManager.rootNode.call_deferred("add_child", instance)