2025-09-26 22:37:05 +08:00
|
|
|
class_name BulletTool
|
|
|
|
|
|
|
|
|
|
static func fromArea(area: Area2D) -> BulletBase:
|
|
|
|
|
if area is BulletBase:
|
|
|
|
|
return area as BulletBase
|
|
|
|
|
else:
|
|
|
|
|
return null
|
|
|
|
|
static func canDamage(bullet: BulletBase, target: EntityBase) -> bool:
|
2025-11-30 16:31:38 +08:00
|
|
|
if !bullet or !target or !bullet.launcher: return false
|
2025-09-26 22:37:05 +08:00
|
|
|
if target.currentInvinsible: return false
|
2026-01-28 20:34:32 +08:00
|
|
|
var launcherIsPlayer = bullet.launcher.isPlayer()
|
|
|
|
|
if bullet.launcher is SummonBase:
|
|
|
|
|
var summon = bullet.launcher as SummonBase
|
|
|
|
|
if is_instance_valid(summon.myMaster):
|
|
|
|
|
launcherIsPlayer = summon.myMaster.isPlayer()
|
|
|
|
|
if !GameRule.allowFriendlyFire and !bullet.allowFriendlyDamage:
|
|
|
|
|
if target.isPlayer() == launcherIsPlayer and bullet.launcher.currentFocusedBoss != target:
|
2026-01-28 20:20:55 +08:00
|
|
|
return false
|
|
|
|
|
if !bullet.canDamageSelf:
|
|
|
|
|
if target == bullet.launcher:
|
|
|
|
|
return false
|
2025-09-26 22:37:05 +08:00
|
|
|
return true
|
2025-12-07 17:04:47 +08:00
|
|
|
static func findClosetBullet(to: Vector2, fromTree: SceneTree) -> BulletBase:
|
|
|
|
|
var result: BulletBase = null
|
|
|
|
|
var lastDistance = INF
|
|
|
|
|
for bullet in fromTree.get_nodes_in_group("bullets"):
|
|
|
|
|
if to.distance_to(bullet.position) < lastDistance:
|
|
|
|
|
lastDistance = to.distance_to(bullet.position)
|
|
|
|
|
result = bullet
|
|
|
|
|
return result
|
2026-04-24 18:09:24 +08:00
|
|
|
static func findClosetBulletCanDamage(to: Vector2, fromTree: SceneTree, target: EntityBase, maxDistance: float = INF) -> BulletBase:
|
2025-12-07 17:04:47 +08:00
|
|
|
var result: BulletBase = null
|
|
|
|
|
var lastDistance = INF
|
|
|
|
|
for bullet in fromTree.get_nodes_in_group("bullets"):
|
|
|
|
|
if canDamage(bullet, target):
|
|
|
|
|
if to.distance_to(bullet.position) < lastDistance:
|
|
|
|
|
lastDistance = to.distance_to(bullet.position)
|
|
|
|
|
result = bullet
|
2026-04-24 18:09:24 +08:00
|
|
|
if is_instance_valid(result):
|
|
|
|
|
if result.position.distance_to(to) > maxDistance:
|
|
|
|
|
return null
|
2025-12-07 17:04:47 +08:00
|
|
|
return result
|