mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-06-30 15:22:30 +08:00
refactor(BulletBase): 重构子弹分裂和折射逻辑,移除parentScene字段
将子弹分裂和折射的逻辑从静态生成方法改为实例克隆方式,简化代码结构并提高可维护性。移除不再使用的parentScene字段,相关功能通过克隆实例实现。
This commit is contained in:
@@ -35,7 +35,6 @@ var isChildRefract: bool = false
|
|||||||
var initialSpeed: float = 0
|
var initialSpeed: float = 0
|
||||||
var initialDamage: float = 0
|
var initialDamage: float = 0
|
||||||
var speedScale: float = 1
|
var speedScale: float = 1
|
||||||
var parentScene: PackedScene = null
|
|
||||||
var isFirstFrame: bool = true
|
var isFirstFrame: bool = true
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
@@ -150,7 +149,9 @@ func trySplit():
|
|||||||
var total = MathTool.shrimpRate(value)
|
var total = MathTool.shrimpRate(value)
|
||||||
var last = value - floor(value)
|
var last = value - floor(value)
|
||||||
for i in total:
|
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():
|
func tryRefract():
|
||||||
if is_instance_valid(launcher) and !isChildRefract:
|
if is_instance_valid(launcher) and !isChildRefract:
|
||||||
var value = launcher.fields.get(FieldStore.Entity.BULLET_REFRACTION)
|
var value = launcher.fields.get(FieldStore.Entity.BULLET_REFRACTION)
|
||||||
@@ -159,7 +160,9 @@ func tryRefract():
|
|||||||
for i in total:
|
for i in total:
|
||||||
var entity = EntityTool.findClosetEntity(position, get_tree(), !launcher.isPlayer(), launcher.isPlayer(), [launcher])
|
var entity = EntityTool.findClosetEntity(position, get_tree(), !launcher.isPlayer(), launcher.isPlayer(), [launcher])
|
||||||
if is_instance_valid(entity):
|
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():
|
func firstFrame():
|
||||||
@@ -176,24 +179,10 @@ func succeedToHit(_dmg: float, _entity: EntityBase):
|
|||||||
pass
|
pass
|
||||||
func register():
|
func register():
|
||||||
pass
|
pass
|
||||||
func split(index: int, total: int, _lastBullet: float):
|
func split(_newBullet: BulletBase, _index: int, _total: int, _lastBullet: float):
|
||||||
BulletBase.generate(
|
pass
|
||||||
parentScene,
|
func refract(_newBullet: BulletBase, _entity: EntityBase, _index: int, _total: int, _lastBullet: float):
|
||||||
launcher,
|
pass
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
static func generate(
|
static func generate(
|
||||||
bullet: PackedScene,
|
bullet: PackedScene,
|
||||||
@@ -214,7 +203,6 @@ static func generate(
|
|||||||
instance.isChildRefract = asChildRefract
|
instance.isChildRefract = asChildRefract
|
||||||
instance.launcher = launchBy
|
instance.launcher = launchBy
|
||||||
instance.position = spawnPosition
|
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))
|
instance.rotation = spawnRotation + deg_to_rad(launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT) * randf_range(-1, 1) * int(!ignoreOffset))
|
||||||
if addToWorld:
|
if addToWorld:
|
||||||
WorldManager.rootNode.call_deferred("add_child", instance)
|
WorldManager.rootNode.call_deferred("add_child", instance)
|
||||||
|
|||||||
Reference in New Issue
Block a user