class_name InteractionResolver extends RefCounted const TurnResolverType = preload("res://scripts/domain/turn_resolver.gd") const TurnResultType = preload("res://scripts/domain/turn_result.gd") const TARGET_OFFSETS: Array[Vector2i] = [ Vector2i.ZERO, Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT, Vector2i(1, -1), Vector2i(1, 1), Vector2i(-1, 1), Vector2i(-1, -1), ] static func resolve(state: GameState) -> Array[TurnResult]: var results: Array[TurnResult] = [] var door_cell := _find_closed_door(state) if door_cell.x >= 0: state.map.set_cell(door_cell, GridMapState.CellKind.FLOOR) results.append(TurnResultType.new(state.player.id, &"door_opened", state.player.cell, door_cell, &"", 0, "You open the door.")) TurnResolverType.append_enemy_response(state, results) return results results.append(TurnResultType.new(state.player.id, &"nothing_to_interact", state.player.cell, state.player.cell, &"", 0, "Nothing to interact with.")) return results static func _find_closed_door(state: GameState) -> Vector2i: for offset in TARGET_OFFSETS: var cell := state.player.cell + offset if state.map.get_cell(cell) == GridMapState.CellKind.CLOSED_DOOR: return cell return Vector2i(-1, -1)