Randoloot/scripts/game/alien_weapon_effects.gd
2026-10-25 16:12:08 +01:00

27 lines
1.6 KiB
GDScript

extends RefCounted
const DATA := preload("res://scripts/planets/alien_research.gd")
static func roll_disabled_system(roll := -1.0, system := -1) -> int:
if not DATA.learned("weapons_a_next") or (randf() if roll < 0 else roll) >= 0.01: return -1
return randi_range(0,2) if system < 0 else clampi(system,0,2)
static func apply_hit(target: Variant, damage: float, critical: bool, kind: int, piercing: float, visited: Dictionary, splash := true, disabled_system := -2, damage_scale := 1.0) -> void:
if not target is Node or target.is_queued_for_deletion(): return
var id: int = target.get_instance_id()
if visited.has(id): return
visited[id] = true
if target.has_method("take_research_weapon_hit"):
target.take_research_weapon_hit(damage,critical,kind,piercing,disabled_system,damage_scale)
elif target.has_method("take_piercing_weapon_hit"):
target.take_piercing_weapon_hit(damage,critical,kind,piercing)
elif target.has_method("take_weapon_hit"):
target.take_weapon_hit(damage,critical,kind)
elif target.has_method("take_damage"):
target.take_damage(damage)
if not splash or not DATA.learned("weapons_a_next_next") or not target is Node2D or not target.is_in_group("enemies"): return
var radius := float(target.get_visual_size())*0.5+10.0
for other in target.get_tree().get_nodes_in_group("enemies"):
if other == target or other.is_queued_for_deletion() or float(other.get("hull")) <= 0: continue
if target.global_position.distance_to(other.global_position) <= radius+float(other.get_visual_size())*0.5:
apply_hit(other,damage,critical,kind,piercing,visited,false,-1,damage_scale)