mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 06:51:54 +08:00
6e7272d7d9
移除子弹分裂参数,将子弹折射次数从2增加到3 更新武器从ChainGun到PurpleCrystal 优化子弹折射逻辑,避免重复目标 使用call_deferred安全添加子节点
37 lines
1.4 KiB
GDScript
37 lines
1.4 KiB
GDScript
class_name EntityTool
|
|
|
|
static func fromHurtbox(node: Node) -> EntityBase:
|
|
if node is Area2D:
|
|
var texture = node.get_parent()
|
|
if texture is AnimatedSprite2D:
|
|
var entity = texture.get_parent()
|
|
if entity is EntityBase:
|
|
return entity as EntityBase
|
|
return null
|
|
static func findClosetEntity(to: Vector2, fromTree: SceneTree, player: bool = false, mob: bool = false, excludes: Array = [], allowSummon: bool = false) -> EntityBase:
|
|
var result = null
|
|
var lastDistance = INF
|
|
var nodes = []
|
|
if player:
|
|
nodes += fromTree.get_nodes_in_group("players")
|
|
if mob:
|
|
nodes += fromTree.get_nodes_in_group("mobs")
|
|
for entity in nodes:
|
|
if entity is EntityBase and entity not in excludes:
|
|
if !allowSummon:
|
|
if entity.isSummon():
|
|
continue
|
|
if to.distance_to(entity.position) < lastDistance:
|
|
lastDistance = to.distance_to(entity.position)
|
|
result = entity
|
|
return result
|
|
static func findClosetPlayer(to: Vector2, fromTree: SceneTree, excludes: Array[EntityBase] = [], allowSummon: bool = false) -> EntityBase:
|
|
return findClosetEntity(to, fromTree, true, false, excludes, allowSummon)
|
|
static func findEntityByClass(cls: String, fromTree: SceneTree) -> Array[EntityBase]:
|
|
var results: Array[EntityBase] = []
|
|
var nodes = fromTree.get_nodes_in_group("mobs") + fromTree.get_nodes_in_group("players")
|
|
for entity in nodes:
|
|
if entity.get_class() == cls:
|
|
results.append(entity)
|
|
return results
|