Skip to content

Commit

Permalink
Merge pull request #365 from IUrreta/fix-udpate-game
Browse files Browse the repository at this point in the history
Fix udpate game
  • Loading branch information
IUrreta authored Sep 7, 2024
2 parents 7d0a76c + d5fa9a6 commit c86c469
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 29 deletions.
1 change: 0 additions & 1 deletion back/commands/commandFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion back/commands/partRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions back/scripts/car_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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:
Expand Down
57 changes: 40 additions & 17 deletions back/scripts/transfer_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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)")
Expand All @@ -99,26 +99,37 @@ 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]
self.cursor.execute(f"UPDATE Staff_DriverNumbers SET CurrentHolder = {driverID} WHERE Number = {new_num[0]}")


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]
Expand Down Expand Up @@ -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}")
Expand All @@ -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}")

Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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
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")


1 change: 0 additions & 1 deletion front/js/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion front/js/transfers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion launcher/version.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3
2.2.4
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit c86c469

Please sign in to comment.