345 lines
14 KiB
C#
345 lines
14 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.Windows.Forms;
|
|
|
|
namespace SaveWizard_rewritten
|
|
{
|
|
public partial class SecondForm: Form
|
|
{
|
|
private readonly Dictionary<string, List<int>> garages_stat = new Dictionary<string, List<int>>
|
|
{
|
|
{ "Small", new List<int>{ 1, 1 } },
|
|
{ "Medium", new List<int>{ 2, 3 } },
|
|
{ "Big", new List<int>{ 3, 5 } },
|
|
};
|
|
|
|
private readonly string selected_game;
|
|
private readonly Dictionary<string, bool> owns = null;
|
|
|
|
private List<string> dealers = null;
|
|
private List<string> agencies = null;
|
|
|
|
private List<string> AllCities()
|
|
{
|
|
List<string> cities = new List<string>();
|
|
string city;
|
|
foreach (string line in RegexHandler.GetArrayItems("companies:"))
|
|
{
|
|
city = Regex.Match(line, "company.volatile.[a-z0-9_]+[.]([a-z_]+)").Groups[1].ToString();
|
|
if (!cities.Contains(city))
|
|
cities.Add(city);
|
|
}
|
|
return cities;
|
|
}
|
|
|
|
private void AddVehiclesAndDrivers(int start_line, int garage_size)
|
|
{
|
|
int vehicles_array = RegexHandler.SearchLine("vehicles:", start: start_line);
|
|
int drivers_array = RegexHandler.SearchLine("drivers:", start: start_line);
|
|
for (int i = 1; i <= garage_size; i++)
|
|
{
|
|
RegexHandler.AddArrayValue(vehicles_array, "null");
|
|
RegexHandler.AddArrayValue(drivers_array + i, "null");
|
|
}
|
|
}
|
|
|
|
private List<string> PurchasedGarages()
|
|
{
|
|
List<string> garages = new List<string>();
|
|
string city;
|
|
foreach (int index in RegexHandler.SearchAllLines("garage : garage."))
|
|
{
|
|
city = Regex.Match(RegexHandler.GetLine(index), "garage : garage.(.+) {$").Groups[1].ToString();
|
|
if (RegexHandler.GetValue(RegexHandler.SearchLine("status:", start: index)) != "0")
|
|
garages.Add(city);
|
|
}
|
|
return garages;
|
|
}
|
|
|
|
private void CheckGarages()
|
|
{
|
|
lb_owned_garages.Items.Clear();
|
|
List<string> owned_garages = PurchasedGarages();
|
|
foreach (string garage in owned_garages)
|
|
lb_owned_garages.Items.Add(garage);
|
|
}
|
|
|
|
private void CheckCities()
|
|
{
|
|
txt_headquarter.Text = RegexHandler.GetValue(RegexHandler.SearchLine("hq_city:"));
|
|
lb_visited_cities.Items.Clear();
|
|
List<string> visited_cities = RegexHandler.GetArrayItems("visited_cities:");
|
|
if (visited_cities == null)
|
|
{
|
|
lb_visited_cities.Items.Add("No cities visited yet.");
|
|
return;
|
|
}
|
|
foreach (string city in visited_cities)
|
|
lb_visited_cities.Items.Add(city);
|
|
}
|
|
|
|
private void CheckDealers()
|
|
{
|
|
lb_dealerships.Items.Clear();
|
|
List<string> visited_dealers = RegexHandler.GetArrayItems("unlocked_dealers:");
|
|
if (visited_dealers == null)
|
|
{
|
|
lb_dealerships.Items.Add("No dealerships unlocked yet.");
|
|
return;
|
|
}
|
|
foreach (string city in visited_dealers)
|
|
lb_dealerships.Items.Add(city);
|
|
}
|
|
|
|
private void CheckAgencies()
|
|
{
|
|
lb_agencies.Items.Clear();
|
|
List<string> visited_agencies = RegexHandler.GetArrayItems("unlocked_recruitments:");
|
|
if (visited_agencies == null)
|
|
{
|
|
lb_agencies.Items.Add("No recruitment agencies unlocked yet.");
|
|
return;
|
|
}
|
|
foreach (string city in visited_agencies)
|
|
lb_agencies.Items.Add(city);
|
|
}
|
|
|
|
public SecondForm(string _selected_game, Dictionary<string, bool> _owns)
|
|
{
|
|
InitializeComponent();
|
|
selected_game = _selected_game;
|
|
//owns = new Dictionary<string, bool>(_owns);
|
|
owns = _owns;
|
|
KeyValuePair<string, string>[] kvpArr = new KeyValuePair<string, string>[] {
|
|
new KeyValuePair<string, string>("Small", "Small"),
|
|
new KeyValuePair<string, string>("Medium", "Medium"),
|
|
new KeyValuePair<string, string>("Big", "Big"),
|
|
};
|
|
cb_garage_size.DataSource = kvpArr;
|
|
cb_garage_size.DisplayMember = "value";
|
|
cb_garage_size.ValueMember = "key";
|
|
}
|
|
|
|
private void SecondForm_Load(object sender, EventArgs e)
|
|
{
|
|
if (selected_game != null && owns != null)
|
|
{
|
|
string config_path = $"configs/{selected_game}";
|
|
if (File.Exists($"{config_path}/dealers.json"))
|
|
{
|
|
dealers = new List<string>();
|
|
Dictionary<string, string[]> dealers_file = JsonConvert.DeserializeObject<Dictionary<string, string[]>>(File.ReadAllText($"{config_path}/dealers.json"));
|
|
foreach (KeyValuePair<string, bool> dlc in owns)
|
|
if (dlc.Value)
|
|
if (dealers_file.Keys.Contains(dlc.Key))
|
|
dealers.AddRange(dealers_file[dlc.Key]);
|
|
}
|
|
else
|
|
{
|
|
txt_dealer_name.Enabled = false;
|
|
btn_dealer_research.Enabled = false;
|
|
btn_dealer_research_all.Enabled = false;
|
|
}
|
|
if (File.Exists($"{config_path}/agencies.json"))
|
|
{
|
|
agencies = new List<string>();
|
|
Dictionary<string, string[]> agencies_file = JsonConvert.DeserializeObject<Dictionary<string, string[]>>(File.ReadAllText($"{config_path}/agencies.json"));
|
|
foreach (KeyValuePair<string, bool> dlc in owns)
|
|
if (dlc.Value)
|
|
if (agencies_file.Keys.Contains(dlc.Key))
|
|
agencies.AddRange(agencies_file[dlc.Key]);
|
|
}
|
|
else
|
|
{
|
|
txt_agency_name.Enabled = false;
|
|
btn_agency_research.Enabled = false;
|
|
btn_agency_research_all.Enabled = false;
|
|
}
|
|
CheckGarages();
|
|
CheckCities();
|
|
CheckDealers();
|
|
CheckAgencies();
|
|
}
|
|
}
|
|
|
|
private void btn_garage_unlock_Click(object sender, EventArgs e)
|
|
{
|
|
string garage = txt_garage_name.Text.ToLower();
|
|
if (string.IsNullOrWhiteSpace(garage))
|
|
{
|
|
Utils.ShowError("Enter city name!");
|
|
return;
|
|
}
|
|
int garage_line = RegexHandler.SearchLine($"garage : garage.{garage} {{");
|
|
if (garage_line == 0)
|
|
{
|
|
Utils.ShowError($"Garage in \"{garage}\" not found.");
|
|
return;
|
|
}
|
|
int garage_status = RegexHandler.SearchLineInUnit("status:", $"garage.{garage}");
|
|
if (RegexHandler.GetValue(garage_status) != "0")
|
|
{
|
|
Utils.ShowError($"Garage in \"{garage}\" already unlocked.");
|
|
return;
|
|
}
|
|
List<int> garage_stat = garages_stat[cb_garage_size.SelectedValue.ToString()];
|
|
RegexHandler.SetValue(garage_status, garage_stat[0].ToString());
|
|
AddVehiclesAndDrivers(garage_status, garage_stat[1]);
|
|
Utils.ShowInfo($"Garage in \"{garage}\" successfully unlocked.");
|
|
CheckGarages();
|
|
}
|
|
|
|
private void btn_garage_unlock_all_Click(object sender, EventArgs e)
|
|
{
|
|
List<int> garage_stat = garages_stat[cb_garage_size.SelectedValue.ToString()];
|
|
string garage_match;
|
|
int current_garage, current_status;
|
|
foreach (string item in RegexHandler.GetArrayItems("garages:"))
|
|
{
|
|
garage_match = Regex.Match(item, "garage.(.+)$").Groups[1].ToString();
|
|
current_garage = RegexHandler.SearchLine($"garage : garage.{garage_match} {{");
|
|
current_status = RegexHandler.SearchLine("status:", start: current_garage);
|
|
if (RegexHandler.GetValue(current_status) == "0")
|
|
{
|
|
RegexHandler.SetValue(current_status, garage_stat[0].ToString());
|
|
AddVehiclesAndDrivers(current_garage, garage_stat[1]);
|
|
}
|
|
}
|
|
Utils.ShowInfo("All garages successfully unlocked.");
|
|
CheckGarages();
|
|
}
|
|
|
|
private void btn_headquarter_change_Click(object sender, EventArgs e)
|
|
{
|
|
string hq = txt_headquarter.Text.ToLower();
|
|
if (string.IsNullOrWhiteSpace(hq))
|
|
{
|
|
Utils.ShowError("Enter city name!");
|
|
return;
|
|
}
|
|
if (RegexHandler.GetValue(RegexHandler.SearchLine("hq_city:")) == hq)
|
|
Utils.ShowInfo("Your headquarter is already in this city.");
|
|
else if (!PurchasedGarages().Contains(hq))
|
|
Utils.ShowError($"You need a garage in \"{hq}\" to set headquarter.");
|
|
else
|
|
{
|
|
RegexHandler.SetValue(RegexHandler.SearchLine("hq_city:"), hq);
|
|
Utils.ShowInfo($"Headquarter successfully set to \"{hq}\".");
|
|
}
|
|
}
|
|
|
|
private void btn_visit_city_Click(object sender, EventArgs e)
|
|
{
|
|
string city = txt_city_name.Text.ToLower();
|
|
if (string.IsNullOrWhiteSpace(city))
|
|
{
|
|
Utils.ShowError("Enter city name!");
|
|
return;
|
|
}
|
|
txt_city_name.Text = "";
|
|
if (RegexHandler.GetArrayItems("visited_cities:").Contains(city))
|
|
{
|
|
Utils.ShowError($"You've already visited \"{city}\".");
|
|
return;
|
|
}
|
|
RegexHandler.AddArrayValue(RegexHandler.SearchLine("visited_cities:"), city);
|
|
RegexHandler.AddArrayValue(RegexHandler.SearchLine("visited_cities_count:"), "1");
|
|
Utils.ShowInfo($"City \"{city}\" successfully visited.");
|
|
}
|
|
|
|
private void btn_visit_all_Click(object sender, EventArgs e)
|
|
{
|
|
List<string> all_cities = AllCities();
|
|
List<string> visited_cities = RegexHandler.GetArrayItems("visited_cities:");
|
|
foreach (string city in all_cities)
|
|
{
|
|
if (!visited_cities.Contains(city))
|
|
{
|
|
RegexHandler.AddArrayValue(RegexHandler.SearchLine("visited_cities:"), city);
|
|
RegexHandler.AddArrayValue(RegexHandler.SearchLine("visited_cities_count:"), "1");
|
|
}
|
|
}
|
|
Utils.ShowInfo("All cities successfully visited.");
|
|
CheckCities();
|
|
}
|
|
|
|
private void dealer_agency_research_Click(object sender, EventArgs e)
|
|
{
|
|
TextBox new_city;
|
|
List<string> cities_list;
|
|
Action check_func;
|
|
string search_line, message;
|
|
if ((sender as Button) == btn_dealer_research)
|
|
{
|
|
new_city = txt_dealer_name;
|
|
cities_list = dealers;
|
|
search_line = "unlocked_dealers:";
|
|
check_func = CheckDealers;
|
|
message = "Dealership";
|
|
}
|
|
else
|
|
{
|
|
new_city = txt_agency_name;
|
|
cities_list = agencies;
|
|
search_line = "unlocked_recruitments:";
|
|
check_func = CheckAgencies;
|
|
message = "Recruitment agency";
|
|
}
|
|
string element = new_city.Text.ToLower();
|
|
if (string.IsNullOrWhiteSpace(element))
|
|
{
|
|
Utils.ShowError("Enter city name!");
|
|
return;
|
|
}
|
|
new_city.Text = "";
|
|
if (!cities_list.Contains(element))
|
|
{
|
|
Utils.ShowError($"There is no {message.ToLower()} in that city.");
|
|
return;
|
|
}
|
|
List<string> already_visited = RegexHandler.GetArrayItems(search_line);
|
|
if (already_visited != null && already_visited.Contains(element))
|
|
{
|
|
Utils.ShowInfo($"{message} in \"{element}\" is already unlocked.");
|
|
return;
|
|
}
|
|
RegexHandler.AddArrayValue(RegexHandler.SearchLine(search_line), element);
|
|
Utils.ShowInfo($"{message} in \"{element}\" successfully unlocked.");
|
|
check_func();
|
|
}
|
|
|
|
private void dealer_agency_research_all_Click(object sender, EventArgs e)
|
|
{
|
|
List<string> cities_list;
|
|
string search_line, message;
|
|
Action check_func;
|
|
if ((sender as Button) == btn_dealer_research_all)
|
|
{
|
|
cities_list = dealers;
|
|
search_line = "unlocked_dealers:";
|
|
check_func = CheckDealers;
|
|
message = "All dealerships unlocked.";
|
|
}
|
|
else
|
|
{
|
|
cities_list = agencies;
|
|
search_line = "unlocked_recruitments:";
|
|
check_func = CheckAgencies;
|
|
message = "All recruitment agencies unlocked.";
|
|
}
|
|
List<string> all_cities = AllCities();
|
|
int file_line = RegexHandler.SearchLine(search_line);
|
|
List<string> unlocked_cities = RegexHandler.GetArrayItems(search_line);
|
|
foreach (string element in cities_list)
|
|
if (all_cities.Contains(element) && (unlocked_cities == null || !unlocked_cities.Contains(element)))
|
|
RegexHandler.AddArrayValue(file_line, element);
|
|
Utils.ShowInfo(message);
|
|
check_func();
|
|
}
|
|
}
|
|
}
|