From a99f66bbbe0b1a74871060251fd24d86a27a0788 Mon Sep 17 00:00:00 2001 From: Chris Davoren Date: Tue, 29 Aug 2023 09:14:30 +1000 Subject: [PATCH] Multiple functions added. --- all-batches.bat | 6 ++++++ pack_weapons_advanced.txt | 7 +++++++ sheditor.py | 41 ++++++++++++++++++++++++++++++++------- 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 all-batches.bat create mode 100644 pack_weapons_advanced.txt diff --git a/all-batches.bat b/all-batches.bat new file mode 100644 index 0000000..086a4be --- /dev/null +++ b/all-batches.bat @@ -0,0 +1,6 @@ +python sheditor.py %1 --replace-original --add-item-set pack_building.txt +python sheditor.py %1 --replace-original --add-item-set pack_food.txt +python sheditor.py %1 --replace-original --add-item-set pack_medical.txt +python sheditor.py %1 --replace-original --add-item-set pack_trade.txt +python sheditor.py %1 --replace-original --add-item-set pack_weapons_basic.txt +python sheditor.py %1 --replace-original --add-item-set pack_weapons_advanced.txt diff --git a/pack_weapons_advanced.txt b/pack_weapons_advanced.txt new file mode 100644 index 0000000..0dcd3e5 --- /dev/null +++ b/pack_weapons_advanced.txt @@ -0,0 +1,7 @@ +# Advanced weapons pack +760 10 # Five-seven pistols +3069 10 # Laser Rifle +3070 10 # Laser Pistol +3071 10 # Plasma Clustergun +3072 10 # Plasma Rifle +3384 10 # Armored Vest \ No newline at end of file diff --git a/sheditor.py b/sheditor.py index 503bd16..6d6568f 100644 --- a/sheditor.py +++ b/sheditor.py @@ -7,6 +7,8 @@ from bs4 import BeautifulSoup import rich.console +DEFAULT_SAVEGAMEPATH = "c:\\Program Files (x86)\\GOG Galaxy\\Games\\SpaceHaven\\savegames\\" + # Only "normal storage" is used to insert requested items normal_storage_ids = [82, 632] @@ -146,7 +148,7 @@ class Character: # Max MXN should be 8 for some reason # Exp* keys are probably for a future experience system but I don't know how they work so I won't touch them for skill in self.skills: - skill['level'] = 5 + skill['level'] = 7 skill['mxn'] = 8 def maximize_attributes(self): @@ -156,6 +158,7 @@ class Character: def clone(self, new_name): # How to deep copy the skills/attributes appropriately? + print("Cloning character {}".format(self.name)) new_char = Character(new_name, copy.copy(self.tag)) new_char.is_clone = True new_char.tag['name'] = new_name @@ -214,6 +217,13 @@ class Ship: min_occupancy = min_storage_area.get_total_occupancy() min_storage_area.add_item(item) + def redistribute_storage(self): + normal_storage_areas = [sa for sa in self.storage_areas if sa.is_normal_storage] + total = 0 + for area in normal_storage_areas: + total += area.get_total_occupancy() + print(total) + class Player: @@ -224,11 +234,12 @@ class Player: class GameData: - def __init__(self, soup): + def __init__(self, soup, item_database): self.player = None self.ships = [] self.soup = soup + self.item_database = item_database def populate(self): # Step 1 - Player data @@ -335,8 +346,9 @@ class GameData: for ship in self.ships: for character in ship.characters: # Cloned character tags have to be added to the list + print('Doing chars...') if character.is_clone: - console.print("ADDING CLONED CHARACTER") + print("ADDING CLONED CHARACTER") charlist_tag = ship.tag.find('characters') charlist_tag.append(character.tag) @@ -380,9 +392,12 @@ class GameData: self.player.currency += amount def clone_character(self, character_name, new_name): + print("Clone char method called") + print("Warning names are case sensitive!") for ship in self.ships: for character in ship.characters: if character.name == character_name: + print("Found char to clone") new_char = character.clone(new_name) ship.characters.append(new_char) return @@ -451,6 +466,10 @@ class GameData: console.print(" {}".format(char.name)) # char.print_summary() + def redistribute(self): + for ship in self.ships: + ship.redistribute_storage() + def parse_item_file(filename): @@ -481,6 +500,7 @@ def main(): parser.add_argument('--add-item-set', required=False, type=str, nargs=1, metavar='PACK_FILENAME', help="Takes a file containing a list of item codes and quantities (whitespace separated) and adds all of these to player storage") parser.add_argument('--detailed-items', required=False, action='store_true', help='Print a detailed item listing from player inventory') parser.add_argument('--detailed-chars', required=False, action='store_true', help='Print a comprehensive listing of player character details') + parser.add_argument('--redistribute', required=False, action='store_true', help='Redistribute internal storage') parser.add_argument('--replace-original', required=False, action='store_true', help='Replace original file instead of creating edited alternative. Renames original for backup, but USE WITH CAUTION') args = parser.parse_args() @@ -489,7 +509,7 @@ def main(): console.print("--- Space Haven Saved Game Inspector ---") console.print() - filename = args.filename + filename = os.path.join(DEFAULT_SAVEGAMEPATH, args.filename, "save", "game") # console.print(filename) full_text = "" @@ -508,7 +528,7 @@ def main(): console.print("Character code database successfully loaded.") console.print() - game_data = GameData(soup) + game_data = GameData(soup, Item) game_data.populate() edits_made = False @@ -516,6 +536,7 @@ def main(): if args.buff_chars: game_data.buff_characters() edits_made = True + print("Buffed chars") if args.add_item: game_data.add_item(args.add_item[0], args.add_item[1]) @@ -529,6 +550,7 @@ def main(): game_data.print_summary() if args.clone_character: + print("Clone char requested.") game_data.clone_character(args.clone_character[0], args.clone_character[1]) edits_made = True @@ -547,6 +569,9 @@ def main(): if args.detailed_chars: game_data.print_detailed_character_summary() + if args.redistribute: + game_data.redistribute() + game_data.writeback() if args.test_gamedata: @@ -567,14 +592,16 @@ def main(): datetime_suffix = datetime.datetime.now().strftime('%Y-%m-%d-%H%M_%S_%f') new_filename = args.filename + "-" + datetime_suffix # console.print(datetime_suffix) - os.rename(args.filename, new_filename) + # os.rename(args.filename, new_filename) console.print('Now rewriting game file with new information') text = soup.prettify() # Delete XML header - game doesn't have it sansfirstline = '\n'.join(text.split('\n')[1:]) - f = open(args.filename, 'w') + filename = os.path.join(DEFAULT_SAVEGAMEPATH, args.filename, "save", "game") + + f = open(filename, 'w') f.write(sansfirstline) f.close() console.print('Complete.')