From 3adb7c553a8c8c2bad21940e9d3c8f35ea6ac94a Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Mon, 11 Mar 2024 17:13:40 -0400 Subject: get/set purchased weapons --- srb.py | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'srb.py') diff --git a/srb.py b/srb.py index 9c6a941..658c272 100755 --- a/srb.py +++ b/srb.py @@ -23,10 +23,16 @@ import srb_lib, argparse, sys from srb_lib import ferror, debuglev +HELP_WEAPONS = "" + +for w in srb_lib.WEAPONS: + HELP_WEAPONS += str(w["id"]) + "," + w["name"] + ',' +HELP_WEAPONS = HELP_WEAPONS.rstrip(",") + parser = argparse.ArgumentParser(description="Cli tool for manipulating savegame files for srb.exe", formatter_class=argparse.RawDescriptionHelpFormatter, epilog=f"""LEVELS include {[i['name'] for i in srb_lib.LEVELS]+list(range(0,len(srb_lib.LEVELS)))} -WEAPONS include {[i for i in srb_lib.WEAPONS if i != "undefined"]+list(range(0,16))} +WEAPONS include {HELP_WEAPONS} NAME_CHARS include "{srb_lib.NAME_CHARS}" """) parser.add_argument("-V","--version",action="version",version="%(prog)s " + srb_lib.srb_lib_version) @@ -35,14 +41,19 @@ parser.add_argument("--profile",type=int,choices=range(1,4),help="Profile in use parser.add_argument("--get-money",action="store_true",help="Print current money for profile.") parser.add_argument("--set-money",type=int,help="Set money for profile.") parser.add_argument("--get-weapon",action="store_true",help="Print currently equipped weapon for profile.") -# choices seems to be too strict here for the numbers. We can live with just the +# choices seems to be too strict here for the numbers. We can live with just the #choices=[i for i in srb_lib.WEAPONS if i != "undefined"]+list(range(0,16)) #parser.add_argument("--set-weapon",choices=[i for i in srb_lib.WEAPONS if i != "undefined"],help="Print currently equipped weapon for profile.") parser.add_argument("--set-weapon",help="Set currently equipped weapon for profile.") +parser.add_argument("--get-purchased-weapons",action="store_true",help="Print currently purchased weapon for profile.") +parser.add_argument("--add-purchased-weapons",action="append",help="For profile, add these purchased weapons. Can be used multiple times.") +parser.add_argument("--remove-purchased-weapons",action="append",help="For profile, add these purchased weapons. Can be used multiple times.") parser.add_argument("--get-level",help="Print status for this level for profile.") parser.add_argument("--get-name",action="store_true",help="Print name for profile.") parser.add_argument("--set-name",help="Set name for profile.") parser.add_argument("--get-profile-in-use",action="store_true",help="Print if profile is in use.") +parser.add_argument("--get-tutorial-completed",action="store_true",help="Print if profile has completed the tutorial.") +parser.add_argument("--set-tutorial-completed",choices=["True","False"],help="Set tutorial-completed for profile.") parser.add_argument("--checksum",action=argparse.BooleanOptionalAction,default=True,help="Correct checksum. Default is to do this. It happens at the end of everything else.") parser.add_argument("file",default="Profile 1.sav") args = parser.parse_args() @@ -61,7 +72,7 @@ profile_id = args.profile #print(f"profile_id={profile_id}") # WORKHERE: new actions that need --profile must be added here. -if not profile_id and (args.get_money or args.set_money or args.get_weapon or args.set_weapon or args.get_level or args.get_name or args.set_name or args.get_profile_in_use): +if not profile_id and (args.get_money or args.set_money or args.get_weapon or args.set_weapon or args.get_level or args.get_name or args.set_name or args.get_profile_in_use or args.get_purchased_weapons or args.get_tutorial_completed or args.add_purchased_weapons or args.remove_purchased_weapons): ferror("Warning: Cannot perform most actions without --profile. Not all tasks may run.") else: if args.get_money: @@ -98,6 +109,26 @@ else: srb_lib.write_file(args.file,0,data) if args.get_profile_in_use: print(f"Profile {profile_id} in use is {srb_lib.get_profile_in_use(args.file,profile_id)}") + if args.get_purchased_weapons: + print(f"Profile {profile_id} has weapons {srb_lib.get_purchased_weapons(args.file,profile_id)}") + if args.add_purchased_weapons: + data, message = srb_lib.set_purchased_weapons(args.file,profile_id,"add",args.add_purchased_weapons) + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to add purchased weapons {args.add_purchased_weapons} because {message}") + else: + srb_lib.write_file(args.file,0,data) + if args.remove_purchased_weapons: + data, message = srb_lib.set_purchased_weapons(args.file,profile_id,"remove",args.remove_purchased_weapons) + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to add purchased weapons {args.remove_purchased_weapons} because {message}") + else: + srb_lib.write_file(args.file,0,data) + if args.get_tutorial_completed: + print(f"Profile {profile_id} completed-tutorial is {srb_lib.get_tutorial_completed(args.file,profile_id)}") + if args.set_tutorial_completed: + thisbool = False if args.set_tutorial_completed == "False" else True + data, newstatus = srb_lib.set_tutorial_completed(args.file,profile_id,thisbool) + srb_lib.write_file(args.file,0,data) if args.checksum: f = args.file -- cgit