diff --git a/back/commands/commandFactory.py b/back/commands/commandFactory.py index 8512d52d..761d50b6 100644 --- a/back/commands/commandFactory.py +++ b/back/commands/commandFactory.py @@ -43,7 +43,6 @@ def __init__(self): def create_command(self, message, client): command_type = message["command"] - # print(message) #for debugging if command_type in self.command_dict: return self.command_dict[command_type](message, client) else: diff --git a/back/commands/partRequest.py b/back/commands/partRequest.py index 029b6fbe..cd1cb4d8 100644 --- a/back/commands/partRequest.py +++ b/back/commands/partRequest.py @@ -8,7 +8,6 @@ def __init__(self, message, client): super().__init__(message, client) async def execute(self): - print(self.message) car_analysis = CarAnalysisUtils(self.client) part_values = ["Part values fetched", car_analysis.get_unitvalue_from_one_part(self.message['designID'])] data_json_part_values = json.dumps(part_values) diff --git a/back/scripts/car_analysis.py b/back/scripts/car_analysis.py index df6a6c51..bb681e80 100644 --- a/back/scripts/car_analysis.py +++ b/back/scripts/car_analysis.py @@ -379,13 +379,12 @@ def update_items_for_design_dict(self, design_dict, team_id): self.conn.commit() def fit_loadouts_dict(self, loadouts_dict, team_id): - print(loadouts_dict) for part in loadouts_dict: design_1 = loadouts_dict[part][0] design_2 = loadouts_dict[part][1] fitted_design_1 = self.cursor.execute(f"SELECT DesignID, ItemID FROM Parts_CarLoadout WHERE TeamID = {team_id} AND PartType = {part} AND LoadoutID = 1").fetchone() if design_1 is not None: - if fitted_design_1[0] is not None: + if fitted_design_1[0] is not None and fitted_design_1[1] is not None: self.cursor.execute(f"UPDATE Parts_Items SET AssociatedCar = NULL WHERE ItemID = {fitted_design_1[1]}") fitted_design_1 = fitted_design_1[0] @@ -396,10 +395,9 @@ def fit_loadouts_dict(self, loadouts_dict, team_id): else: item_1 = items_1[0][0] self.add_part_to_loadout(design_1, int(part), team_id, 1, item_1) - if design_2 is not None: fitted_design_2 = self.cursor.execute(f"SELECT DesignID, ItemID FROM Parts_CarLoadout WHERE TeamID = {team_id} AND PartType = {part} AND LoadoutID = 2").fetchone() - if fitted_design_2[0] is not None: + if fitted_design_2[0] is not None and fitted_design_2[1] is not None: self.cursor.execute(f"UPDATE Parts_Items SET AssociatedCar = NULL WHERE ItemID = {fitted_design_2[1]}") fitted_design_2 = fitted_design_2[0] if fitted_design_2 != design_2: diff --git a/back/scripts/transfer_driver.py b/back/scripts/transfer_driver.py index 8a03d84b..179f5f87 100644 --- a/back/scripts/transfer_driver.py +++ b/back/scripts/transfer_driver.py @@ -69,7 +69,7 @@ def hire_driver(self, type, driverID, teamID, position, salary=None, starting_bo day = self.cursor.execute("SELECT Day FROM Player_State").fetchone()[0] year = self.cursor.execute("SELECT CurrentSeason FROM Player_State").fetchone()[0] - + staff_type = self.fetch_type_staff(driverID) isRetired = self.cursor.execute(f"SELECT Retired FROM Staff_GameData WHERE StaffID = {driverID}").fetchone() if isRetired[0] == 1: @@ -78,7 +78,7 @@ def hire_driver(self, type, driverID, teamID, position, salary=None, starting_bo self.cursor.execute(f"INSERT INTO Staff_Contracts VALUES ({driverID}, 0, 1, {day}, 1, {teamID}, {position}, 1, '[OPINION_STRING_NEUTRAL]', {day}, {year_end}, 1, '[OPINION_STRING_NEUTRAL]', {salary}, 1, '[OPINION_STRING_NEUTRAL]', {starting_bonus}, 1, '[OPINION_STRING_NEUTRAL]', {race_bonus}, 1, '[OPINION_STRING_NEUTRAL]', {race_bonus_pos}, 1, '[OPINION_STRING_NEUTRAL]', 0, 1, '[OPINION_STRING_NEUTRAL]')") elif year_iteration == "24": self.cursor.execute(f"INSERT INTO Staff_Contracts VALUES ({driverID}, 0, {teamID}, {position}, {day}, {year_end}, {salary}, {starting_bonus}, {race_bonus}, {race_bonus_pos}, 0.5, 0)") - if int(position) < 3: + if int(position) < 3 and staff_type == 0: self.cursor.execute(f"UPDATE Staff_DriverData SET AssignedCarNumber = {position} WHERE StaffID = {driverID}") is_driving_in_f2_f3 = self.cursor.execute(f"SELECT TeamID FROM Staff_Contracts WHERE StaffID = {driverID} AND ContractType = 0 AND (TeamID > 10 AND TeamID < 32)").fetchone() if is_driving_in_f2_f3 is not None: @@ -89,8 +89,8 @@ def hire_driver(self, type, driverID, teamID, position, salary=None, starting_bo position_in_standings = self.cursor.execute(f"SELECT MAX(Position) FROM Races_DriverStandings WHERE SeasonID = {year} AND RaceFormula = 1").fetchone() points_driver_in_standings = self.cursor.execute(f"SELECT Points FROM Races_DriverStandings WHERE DriverID = {driverID} AND SeasonID = {year} AND RaceFormula = 1").fetchone() - type = self.fetch_type_staff(driverID) - if int(type) == 0: + + if int(staff_type) == 0: if points_driver_in_standings is None: points_driver_in_standings = (0,) self.cursor.execute(f"INSERT INTO Races_DriverStandings VALUES ({year}, {driverID}, {points_driver_in_standings[0]}, {position_in_standings[0] + 1}, 0, 0, 1)") @@ -99,15 +99,14 @@ def hire_driver(self, type, driverID, teamID, position, salary=None, starting_bo was_in_f3 = self.cursor.execute(f"SELECT Points FROM Races_DriverStandings WHERE DriverID = {driverID} AND SeasonID = {year} AND RaceFormula = 3").fetchone() if was_in_f2 is not None: - # print("was in f2") self.cursor.execute(f"DELETE FROM Races_DriverStandings WHERE DriverID = {driverID} AND SeasonID = {year} AND RaceFormula = 2") if was_in_f3 is not None: - # print("was in f3") self.cursor.execute(f"DELETE FROM Races_DriverStandings WHERE DriverID = {driverID} AND SeasonID = {year} AND RaceFormula = 3") #gives new numbers to newcommers in f1 driver_has_number = self.cursor.execute(f"SELECT Number FROM Staff_DriverNumbers WHERE CurrentHolder = {driverID}").fetchone() if driver_has_number is None: + self.free_numbers_not_f1() free_numbers = self.cursor.execute("SELECT Number FROM Staff_DriverNumbers WHERE CurrentHolder IS NULL AND Number != 0").fetchall() rand_index = random.randrange(len(free_numbers)) new_num = free_numbers[rand_index] @@ -115,10 +114,22 @@ def hire_driver(self, type, driverID, teamID, position, salary=None, starting_bo self.rearrange_driver_engineer_pairings(teamID) + self.fix_driver_standings() self.conn.commit() self.conn.close() + def free_numbers_not_f1(self): + numbers = self.cursor.execute("SELECT CurrentHolder, Number FROM Staff_DriverNumbers WHERE Number != 0 AND CurrentHolder IS NOT NULL").fetchall() + for driver, number in numbers: + team_id = self.cursor.execute(f"SELECT MIN(TeamID) FROM Staff_Contracts WHERE StaffID = {driver} AND ContractType = 0").fetchone() + if team_id[0] is not None: + if team_id[0] > 10 and team_id[0] < 32: + self.cursor.execute(f"UPDATE Staff_DriverNumbers SET CurrentHolder = NULL WHERE Number = {number}") + + self.conn.commit() + + def fetch_type_staff(self, driverID): type = self.cursor.execute(f"SELECT StaffType FROM Staff_GameData WHERE StaffID = {driverID}").fetchone() return type[0] @@ -230,9 +241,11 @@ def swap_drivers(self, driver_1_id, driver_2_id): team_1_id = self.cursor.execute(f"SELECT TeamID FROM Staff_Contracts WHERE StaffID = {driver_1_id}").fetchone() team_2_id = self.cursor.execute(f"SELECT TeamID FROM Staff_Contracts WHERE StaffID = {driver_2_id}").fetchone() year = self.cursor.execute("SELECT CurrentSeason FROM Player_State").fetchone() + type_1 = self.fetch_type_staff(driver_1_id) + type_2 = self.fetch_type_staff(driver_2_id) + is_staff = type_1 == 1 or type_2 == 1 - if(position_1[0] < 3 and position_2[0] < 3): - #no reserve drivers + if(position_1[0] < 3 and position_2[0] < 3) and not is_staff: self.cursor.execute(f"UPDATE Staff_Contracts SET TeamID = {team_2_id[0]}, PosInTeam = {position_2[0]} WHERE ContractType = 0 AND StaffID = {driver_1_id}") self.cursor.execute(f"UPDATE Staff_Contracts SET TeamID = {team_1_id[0]}, PosInTeam = {position_1[0]} WHERE ContractType = 0 AND StaffID = {driver_2_id}") self.cursor.execute(f"UPDATE Staff_DriverData SET AssignedCarNumber = {position_2[0]} WHERE StaffID = {driver_1_id}") @@ -241,8 +254,7 @@ def swap_drivers(self, driver_1_id, driver_2_id): self.rearrange_driver_engineer_pairings(team_1_id[0]) self.rearrange_driver_engineer_pairings(team_2_id[0]) - elif position_1[0] >= 3 and position_2[0] >= 3: - # both reserves + elif (position_1[0] >= 3 and position_2[0] >= 3) or is_staff: self.cursor.execute(f"UPDATE Staff_Contracts SET TeamID = {team_2_id[0]} WHERE ContractType = 0 AND StaffID = {driver_1_id}") self.cursor.execute(f"UPDATE Staff_Contracts SET TeamID = {team_1_id[0]} WHERE ContractType = 0 AND StaffID = {driver_2_id}") @@ -258,10 +270,8 @@ def swap_drivers(self, driver_1_id, driver_2_id): was_in_f3 = self.cursor.execute(f"SELECT Points FROM Races_DriverStandings WHERE DriverID = {driver_1_id} AND SeasonID = {year[0]} AND RaceFormula = 3").fetchone() if was_in_f2 is not None: - # print("was in f2") self.cursor.execute(f"DELETE FROM Races_DriverStandings WHERE DriverID = {driver_1_id} AND SeasonID = {year[0]} AND RaceFormula = 2") if was_in_f3 is not None: - # print("was in f3") self.cursor.execute(f"DELETE FROM Races_DriverStandings WHERE DriverID = {driver_1_id} AND SeasonID = {year[0]} AND RaceFormula = 3") position_1in_standings = self.cursor.execute(f"SELECT MAX(Position) FROM Races_DriverStandings WHERE RaceFormula = 1 AND SeasonID = {year[0]}").fetchone() @@ -293,10 +303,8 @@ def swap_drivers(self, driver_1_id, driver_2_id): was_in_f3 = self.cursor.execute(f"SELECT Points FROM Races_DriverStandings WHERE DriverID = {driver_2_id} AND SeasonID = {year[0]} AND RaceFormula = 3").fetchone() if was_in_f2 is not None: - # print("was in f2") self.cursor.execute(f"DELETE FROM Races_DriverStandings WHERE DriverID = {driver_2_id} AND SeasonID = {year[0]} AND RaceFormula = 2") if was_in_f3 is not None: - # print("was in f3") self.cursor.execute(f"DELETE FROM Races_DriverStandings WHERE DriverID = {driver_2_id} AND SeasonID = {year[0]} AND RaceFormula = 3") #checks if the driver was in the standings and if it wasn't it updates the standings @@ -315,6 +323,8 @@ def swap_drivers(self, driver_1_id, driver_2_id): self.rearrange_driver_engineer_pairings(team_1_id[0]) self.rearrange_driver_engineer_pairings(team_2_id[0]) + self.fix_driver_standings() + self.conn.commit() self.conn.close() @@ -382,12 +392,14 @@ def get_tier(self, driverID): reactions = float(driver_stats[7][0]) accuracy = float(driver_stats[8][0]) rating = (cornering + braking*0.75 + reactions*0.5 +control*0.75 + smoothness*0.5 + accuracy*0.75 + adaptability*0.25 + overtaking*0.25+ defence*0.25)/5 - else: + elif len(driver_stats) > 0: type = "staff" rating = 0 for i in range(len(driver_stats)): rating += float(driver_stats[i][0]) rating = rating/len(driver_stats) + else: + rating = 0 if(rating >= 89): tier = 1 elif(rating >= 85): tier = 2 @@ -413,6 +425,17 @@ def get_driver_id(self, name): else: driver_id = self.cursor.execute(f"SELECT StaffID FROM Staff_BasicData WHERE LastName = '[StaffName_Surname_{driver}]'").fetchone() - # print(name, driver_id) - return driver_id \ No newline at end of file + return driver_id + + + def fix_driver_standings(self): + year = self.cursor.execute("SELECT CurrentSeason FROM Player_State").fetchone() + drivers_in_standings = self.cursor.execute(f"SELECT DriverID FROM Races_DriverStandings WHERE SeasonID = {year[0]} AND RaceFormula = 1").fetchall() + for driver in drivers_in_standings: + driver_id = driver[0] + is_driver = self.cursor.execute(f"SELECT StaffType FROM Staff_GameData WHERE StaffID = {driver_id}").fetchone() + if is_driver[0] != 0: + self.cursor.execute(f"DELETE FROM Races_DriverStandings WHERE DriverID = {driver_id} AND SeasonID = {year[0]} AND RaceFormula = 1") + + diff --git a/front/js/performance.js b/front/js/performance.js index cc4168e0..804d3380 100644 --- a/front/js/performance.js +++ b/front/js/performance.js @@ -158,7 +158,6 @@ function order_by(criterion) { let bar = car.querySelector(".performance-bar-progress"); bar.style.width = bar.dataset[criterion] + "%"; let number = car.querySelector(".performance-number") - console.log(car.querySelector(".car-missing-parts")) let value = car.querySelector(".car-missing-parts .value") value.innerText = parseFloat(bar.dataset[criterion]).toFixed(2) + " %"; number.innerText = index + 1 diff --git a/front/js/transfers.js b/front/js/transfers.js index fe6908d6..ca92545f 100644 --- a/front/js/transfers.js +++ b/front/js/transfers.js @@ -831,7 +831,7 @@ function manageDrivers(...divs) { */ document.getElementById("confirmButton").addEventListener('click', function () { if (modalType === "hire") { - if (((f2_teams.includes(originalTeamId) | f3_teams.includes(originalTeamId)) && !destinationParent.classList.contains("affiliates-space") ) | originalParent.className === "driver-space" | originalParent.classList.contains("affiliates-space")) { + if (((f2_teams.includes(originalTeamId) | f3_teams.includes(originalTeamId)) && !destinationParent.classList.contains("affiliates-space") ) | originalParent.className === "driver-space" | originalParent.classList.contains("affiliates-space") | originalParent.className === "staff-space") { signDriver("fireandhire") } signDriver("regular") diff --git a/launcher/version.conf b/launcher/version.conf index 58594069..530cdd91 100644 --- a/launcher/version.conf +++ b/launcher/version.conf @@ -1 +1 @@ -2.2.3 +2.2.4 diff --git a/package-lock.json b/package-lock.json index 2b8fe80d..582f8264 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "Database Editor F1 Manager", - "version": "2.2.3", + "version": "2.2.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "Database Editor F1 Manager", - "version": "2.2.3", + "version": "2.2.4", "license": "LGPL-3.0-or-later", "dependencies": { "bootstrap": "^5.3.2", diff --git a/package.json b/package.json index 9906b9b1..2d11e498 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Database Editor F1 Manager", - "version": "2.2.3", + "version": "2.2.4", "description": "A tool that will let you edit your save file from F1 Manager games", "main": "main.js", "scripts": {