diff --git a/scripts/Statemachine/BulletBase.gd b/scripts/Statemachine/BulletBase.gd index a65c5d9..70f31ce 100644 --- a/scripts/Statemachine/BulletBase.gd +++ b/scripts/Statemachine/BulletBase.gd @@ -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)