diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 88ab38b..8aa0d34 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -98,6 +98,9 @@ var _cursor_highlight : MeshInstance3D = null var _hover_team_overlay : MeshInstance3D = null var _hovered_coord : Vector2i = Vector2i(-1, -1) var _hovered_unit_mesh : MeshInstance3D = null +var _aura_hover_root : Node3D = null +var _hovered_aura_unit_id : String = "" +var _aura_hover_tweens : Array[Tween] = [] # ── Lifecycle ───────────────────────────────────────────────────────────────── @@ -516,8 +519,16 @@ func _input(event: InputEvent) -> void: func _on_board_clicked(screen_pos: Vector2) -> void: var coord: Vector2i = _pathfinder.mouse_to_tile_coord(screen_pos, _board_ctrl.tile_bodies) var unit_id: String = _mouse_to_unit_id(screen_pos) + if unit_id.is_empty() and coord.x >= 0: + var tile: Dictionary = Game.get_tile(coord.x, coord.y) + var raw_occ: Variant = tile.get("occupantId") + unit_id = str(raw_occ) if raw_occ != null else "" _sel_ctrl.handle_board_click(screen_pos, coord, unit_id) _update_hover(screen_pos) + if unit_id.is_empty(): + _clear_aura_hover_overlay() + else: + _show_aura_hover_overlay(unit_id) func _on_board_held(coord: Vector2i) -> void: _held_coord_show_popup(coord) @@ -667,7 +678,7 @@ func _refresh_hand_selection() -> void: func _clear_highlights() -> void: var children: Array = _hi_root.get_children() for c: Node in children: - if c != _cursor_highlight and c != _hover_team_overlay: + if c != _cursor_highlight and c != _hover_team_overlay and c != _aura_hover_root: c.queue_free() @@ -779,6 +790,14 @@ func _update_hover(mouse_pos: Vector2) -> void: _hovered_coord = Vector2i(-1, -1) return var coord: Vector2i = _pathfinder.mouse_to_tile_coord(mouse_pos, _board_ctrl.tile_bodies) + var direct_unit_id: String = _mouse_to_unit_id(mouse_pos) + var tile: Dictionary = {} + var occ_id: String = direct_unit_id + if coord.x >= 0: + tile = Game.get_tile(coord.x, coord.y) + if occ_id.is_empty(): + var raw_occ: Variant = tile.get("occupantId") + occ_id = str(raw_occ) if raw_occ != null else "" if coord == _hovered_coord: return _reset_unit_hover_glow() @@ -790,9 +809,6 @@ func _update_hover(mouse_pos: Vector2) -> void: var sel_tex: Texture2D = HighlightConfig.get_texture("selector") var sel_col: Color = HighlightConfig.get_color("selector") _place_highlight_quad(_cursor_highlight, coord.x, coord.y, sel_col, sel_tex) - var tile: Dictionary = Game.get_tile(coord.x, coord.y) - var raw_occ: Variant = tile.get("occupantId") - var occ_id: String = str(raw_occ) if raw_occ != null else "" if occ_id.is_empty(): _hover_team_overlay.visible = false return @@ -816,6 +832,232 @@ func _reset_unit_hover_glow() -> void: if _hovered_unit_mesh != null and is_instance_valid(_hovered_unit_mesh): _hovered_unit_mesh.set_surface_override_material(0, null) _hovered_unit_mesh = null + _clear_aura_hover_overlay() + + +func _show_aura_hover_overlay(unit_id: String) -> void: + if unit_id == _hovered_aura_unit_id and is_instance_valid(_aura_hover_root): + return + _clear_aura_hover_overlay() + _hovered_aura_unit_id = unit_id + var unit: Dictionary = Game.get_unit_by_id(unit_id) + if unit.is_empty(): + return + var ranges: Array[Dictionary] = _aura_ranges_for_unit(unit) + if ranges.is_empty(): + return + var pos: Dictionary = unit.get("position", {}) + if pos.is_empty(): + return + + var ux: int = int(pos.get("x", 0)) + var uy: int = int(pos.get("y", 0)) + var root: Node3D = Node3D.new() + root.name = "AuraHoverOverlay" + _hi_root.add_child(root) + _aura_hover_root = root + + var affinity: String = str(unit.get("affinity", unit.get("Affinity", ""))) + var aura_color: Color = GameConstants.AFFINITY_COLORS.get(affinity, Color(0.55, 0.9, 1.0)) + var affected_units: Dictionary = {} + var bw: int = Game.board_width() + var bh: int = Game.board_height() + for tx: int in range(bw): + for ty: int in range(bh): + if not _board_ctrl.tile_bodies.has("%d,%d" % [tx, ty]): + continue + if not _coord_in_any_aura_range(ux, uy, tx, ty, ranges): + continue + root.add_child(_make_aura_tile_particles(Vector2i(tx, ty), aura_color, unit_id)) + var tile: Dictionary = Game.get_tile(tx, ty) + var raw_occ: Variant = tile.get("occupantId") + var occ_id: String = str(raw_occ) if raw_occ != null else "" + if not occ_id.is_empty(): + affected_units[occ_id] = Vector2i(tx, ty) + + for affected_id: String in affected_units.keys(): + var affected_coord: Vector2i = affected_units[affected_id] + root.add_child(_make_aura_unit_particles(affected_coord, aura_color, "%s_unit" % unit_id)) + + +func _clear_aura_hover_overlay() -> void: + for tween: Tween in _aura_hover_tweens: + if tween != null and tween.is_valid(): + tween.kill() + _aura_hover_tweens.clear() + if is_instance_valid(_aura_hover_root): + _aura_hover_root.queue_free() + _aura_hover_root = null + _hovered_aura_unit_id = "" + + +func _aura_ranges_for_unit(unit: Dictionary) -> Array[Dictionary]: + var raw_abil: Variant = unit.get("abilitiesJson") + var parsed: Variant = JSON.parse_string("[]" if raw_abil == null else str(raw_abil)) + if not (parsed is Array): + return [] + var ranges: Array[Dictionary] = [] + for raw_ab: Variant in parsed: + if not (raw_ab is Dictionary): + continue + var ab: Dictionary = raw_ab as Dictionary + var type_name: String = str(_dict_get_any(ab, ["type", "Type"], "")) + if type_name.to_lower() != "aura": + continue + var range_v: Variant = _dict_get_any(ab, ["auraRange", "AuraRange", "abilityRange", "AbilityRange", "range", "Range"], {}) + if not (range_v is Dictionary): + continue + var range_dict: Dictionary = range_v as Dictionary + var min_r: int = int(_dict_get_any(range_dict, ["min", "Min"], 0)) + var max_r: int = int(_dict_get_any(range_dict, ["max", "Max"], min_r)) + if max_r < min_r: + var tmp: int = min_r + min_r = max_r + max_r = tmp + ranges.append({ + "min": maxi(0, min_r), + "max": maxi(0, max_r), + "requires_los": bool(_dict_get_any(range_dict, ["requiresLos", "RequiresLos", "requireslos"], false)), + "linear_only": bool(_dict_get_any(range_dict, ["linearOnly", "LinearOnly", "linearonly"], false)) + }) + return ranges + + +func _coord_in_any_aura_range(sx: int, sy: int, tx: int, ty: int, ranges: Array[Dictionary]) -> bool: + for range_dict: Dictionary in ranges: + var dist: int = _pathfinder.board_distance(sx, sy, tx, ty) + if dist < int(range_dict.get("min", 0)) or dist > int(range_dict.get("max", 0)): + continue + if bool(range_dict.get("linear_only", false)) and not _is_linear_coord(sx, sy, tx, ty): + continue + if bool(range_dict.get("requires_los", false)) and not _pathfinder.client_has_los(sx, sy, tx, ty): + continue + return true + return false + + +func _is_linear_coord(sx: int, sy: int, tx: int, ty: int) -> bool: + if sx == tx and sy == ty: + return true + if _pathfinder.grid_type == "Hexagon": + return sx == tx or sy == ty or (sx - sy) == (tx - ty) + var dx: int = abs(tx - sx) + var dy: int = abs(ty - sy) + return sx == tx or sy == ty or dx == dy + + +func _make_aura_tile_particles(coord: Vector2i, color: Color, seed_key: String) -> Node3D: + var root: Node3D = Node3D.new() + root.name = "AuraTileMotes" + var rng: RandomNumberGenerator = RandomNumberGenerator.new() + rng.seed = hash("%s_%d_%d_aura_tile" % [seed_key, coord.x, coord.y]) + var tile_top: float = _board_ctrl.tile_visual_tops.get( + "%d,%d" % [coord.x, coord.y], + _board_ctrl.tile_y_bases.get("%d,%d" % [coord.x, coord.y], 0.0) + + _board_ctrl.tile_heights.get("%d,%d" % [coord.x, coord.y], 1.0)) + root.position = _pathfinder.coord_to_world(coord.x, coord.y) + Vector3(0, tile_top + 0.26, 0) + var mote_count: int = rng.randi_range(4, 7) + for i: int in range(mote_count): + var offset: Vector3 = Vector3( + rng.randf_range(-0.42, 0.42), + rng.randf_range(0.0, 0.24), + rng.randf_range(-0.42, 0.42)) + var radius: float = rng.randf_range(0.024, 0.062) + var energy: float = rng.randf_range(1.25, 2.25) + var mote: MeshInstance3D = _make_aura_mote( + color, offset, radius, energy, rng.randf_range(0.2, 0.55)) + root.add_child(mote) + _animate_aura_mote( + mote, + rng.randf_range(0.045, 0.14), + rng.randf_range(0.9, 1.85), + color, + rng.randf_range(0.18, 0.5)) + return root + + +func _make_aura_unit_particles(coord: Vector2i, color: Color, seed_key: String) -> Node3D: + var root: Node3D = Node3D.new() + root.name = "AuraAffectedUnitMotes" + var rng: RandomNumberGenerator = RandomNumberGenerator.new() + rng.seed = hash("%s_%d_%d_aura_unit" % [seed_key, coord.x, coord.y]) + var tile_top: float = _board_ctrl.tile_visual_tops.get( + "%d,%d" % [coord.x, coord.y], + _board_ctrl.tile_y_bases.get("%d,%d" % [coord.x, coord.y], 0.0) + + _board_ctrl.tile_heights.get("%d,%d" % [coord.x, coord.y], 1.0)) + root.position = _pathfinder.coord_to_world(coord.x, coord.y) + Vector3(0, tile_top + 0.62, 0) + var mote_count: int = rng.randi_range(5, 8) + for i: int in range(mote_count): + var offset: Vector3 = Vector3( + rng.randf_range(-0.28, 0.28), + rng.randf_range(0.0, 0.42), + rng.randf_range(-0.28, 0.28)) + var radius: float = rng.randf_range(0.04, 0.085) + var energy: float = rng.randf_range(2.0, 3.4) + var mote: MeshInstance3D = _make_aura_mote( + color, offset, radius, energy, rng.randf_range(0.28, 0.62)) + root.add_child(mote) + _animate_aura_mote( + mote, + rng.randf_range(0.07, 0.19), + rng.randf_range(0.85, 1.65), + color, + rng.randf_range(0.25, 0.58)) + return root + + +func _make_aura_mote(color: Color, local_pos: Vector3, radius: float, energy: float, alpha: float) -> MeshInstance3D: + var mi: MeshInstance3D = MeshInstance3D.new() + mi.name = "AuraMote" + var mesh: SphereMesh = SphereMesh.new() + mesh.radius = radius + mesh.height = radius * 2.0 + mesh.radial_segments = 10 + mesh.rings = 5 + mi.mesh = mesh + mi.position = local_pos + var mat: StandardMaterial3D = StandardMaterial3D.new() + mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA + mat.albedo_color = Color(color.r, color.g, color.b, alpha) + mat.emission_enabled = true + mat.emission = Color(color.r, color.g, color.b) + mat.emission_energy_multiplier = energy + mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED + mat.cull_mode = BaseMaterial3D.CULL_DISABLED + mi.material_override = mat + return mi + + +func _animate_aura_mote(mote: MeshInstance3D, lift: float, duration: float, base_color: Color, dullness: float) -> void: + var base_pos: Vector3 = mote.position + var drift: Vector3 = Vector3(lift * 0.45, lift, -lift * 0.3) + var mat: StandardMaterial3D = mote.material_override as StandardMaterial3D + var dull_color: Color = base_color.darkened(dullness).lerp(Color(0.65, 0.65, 0.65), dullness * 0.35) + var tween: Tween = create_tween() + tween.set_loops() + tween.set_parallel(true) + tween.tween_property(mote, "position", base_pos + drift, duration)\ + .set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT) + tween.tween_property(mote, "scale", Vector3.ONE * 1.16, duration)\ + .set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT) + tween.chain().tween_property(mote, "position", base_pos - Vector3(drift.x * 0.35, 0.0, drift.z * 0.35), duration * 0.85)\ + .set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT) + tween.parallel().tween_property(mote, "scale", Vector3.ONE * 0.88, duration * 0.85)\ + .set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT) + if mat != null: + tween.parallel().tween_method(func(value: float) -> void: + var c: Color = dull_color.lerp(base_color, value) + mat.albedo_color = Color(c.r, c.g, c.b, mat.albedo_color.a) + mat.emission = c + , 0.0, 1.0, duration * 0.85).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT) + _aura_hover_tweens.append(tween) + + +func _dict_get_any(dict: Dictionary, keys: Array, fallback: Variant = null) -> Variant: + for key: Variant in keys: + if dict.has(key): + return dict[key] + return fallback func _place_highlight_quad(quad: MeshInstance3D, x: int, y: int,