0% encontró este documento útil (0 votos)
12 vistas3 páginas

Program

El documento es un programa en C# que gestiona un archivo JSON de jugadores, permitiendo resetear sus puntos a 50,000. Los usuarios pueden elegir resetear solo a jugadores con puntos menores o iguales a -30,000, o a todos los jugadores. El programa también realiza copias de seguridad del archivo original antes de guardar los cambios.

Cargado por

Santi21
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como TXT, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
12 vistas3 páginas

Program

El documento es un programa en C# que gestiona un archivo JSON de jugadores, permitiendo resetear sus puntos a 50,000. Los usuarios pueden elegir resetear solo a jugadores con puntos menores o iguales a -30,000, o a todos los jugadores. El programa también realiza copias de seguridad del archivo original antes de guardar los cambios.

Cargado por

Santi21
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como TXT, PDF, TXT o lee en línea desde Scribd

using System;

using System.Collections.Generic;
using System.IO;
using System.Text.Json;

class Player
{
public string guid { get; set; }
public string name { get; set; }
public double points { get; set; }
public double kilometers { get; set; }
public int collisions { get; set; }
public Dictionary<string, Dictionary<string, LapData>> leaderboard { get;
set; }
public long last_seen { get; set; }
public int wins { get; set; }
public int podiums { get; set; }
public int poles { get; set; }
public int flaps { get; set; }
public int infr { get; set; }
}

class LapData
{
public int laptime { get; set; }
public int laps { get; set; }
public long ts { get; set; }
}

class Program
{
static void Main()
{
string filePath = @"C:\Program Files (x86)\Steam\steamapps\common\
assettocorsa\server\ac_kissmyrank_win\rank.json";

if (!File.Exists(filePath))
{
Console.WriteLine("ERROR: No se encontró el archivo JSON.");
return;
}

string json = File.ReadAllText(filePath);

var options = new JsonSerializerOptions


{
PropertyNameCaseInsensitive = true
};

List<Player> players;
try
{
players = JsonSerializer.Deserialize<List<Player>>(json, options);
}
catch (Exception ex)
{
Console.WriteLine($"Error al leer JSON: {ex.Message}");
return;
}
Console.WriteLine("¿Qué acción deseas realizar?");
Console.WriteLine("1. Resetear puntos a 50.000 solo para jugadores con <= -
30.000 puntos");
Console.WriteLine("2. Resetear puntos a 50.000 para TODOS los jugadores");
Console.Write("Opción (1/2): ");
string opcion = Console.ReadLine().Trim();

if (opcion == "1")
{
ResetearNegativos(players, filePath);
}
else if (opcion == "2")
{
ResetearTodos(players, filePath);
}
else
{
Console.WriteLine("Opción inválida. Saliendo.");
}
}
static void ResetearNegativos(List<Player> players, string filePath)
{
List<Player> reseteados = new List<Player>();

foreach (var player in players)


{
if (player.points <= -30.0)
{
reseteados.Add(player);
}
}

if (reseteados.Count == 0)
{
Console.WriteLine("No hay jugadores con puntos menores o iguales a -
30.000.");
return;
}
Console.WriteLine($"\nSe encontraron {reseteados.Count} jugador(es) con
puntos <= -30.000:");
foreach (var p in reseteados)
{
Console.WriteLine($"- {p.name} (points: {p.points})");
}
Console.Write("\n¿Deseas resetear sus puntos a 50.000? (s/n): ");
string input = Console.ReadLine().Trim().ToLower();

if (input == "s")
{
foreach (var player in reseteados)
{
player.points = 50;
}

GuardarCambios(players, filePath);
Console.WriteLine($"\n{reseteados.Count} jugador(es) fueron reseteados
a 50.000");
}
else
{
Console.WriteLine("No se realizaron cambios.");
}
}
static void ResetearTodos(List<Player> players, string filePath)
{
Console.Write("\n¿Estás seguro de que quieres resetear los puntos de TODOS
los jugadores a 50.000? (s/n): ");
string input = Console.ReadLine().Trim().ToLower();

if (input == "s")
{
foreach (var player in players)
{
player.points = 50;
}

GuardarCambios(players, filePath);
Console.WriteLine($"\nSe resetearon {players.Count} jugadores a 50.000
puntos.");
}
else
{
Console.WriteLine("No se realizaron cambios.");
}
}
static void GuardarCambios(List<Player> players, string filePath)
{
string backupPath = filePath + ".backup";
File.Copy(filePath, backupPath, true);

string nuevoJson = JsonSerializer.Serialize(players, new


JsonSerializerOptions
{
WriteIndented = true
});

File.WriteAllText(filePath, nuevoJson);
}
}

También podría gustarte