From 88da6cab8739706a2da320d9980e169b85c63a10 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Tue, 19 Mar 2024 14:10:10 -0400 Subject: set levelset available levels --- srb_lib.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'srb_lib.py') diff --git a/srb_lib.py b/srb_lib.py index b659028..64d323e 100644 --- a/srb_lib.py +++ b/srb_lib.py @@ -451,10 +451,32 @@ def get_levelset_status(data_object,profile_id,levelset): x += 1 completed_letters = ''.join(completed_letters) print(f"Debug: letters, uppercase is collected: {completed_letters}") - # it comes back as an int, but does it look better as a hex? return profile_levelset_status +def set_levelset_available_levels(data_object,profile_id,levelset,completed_count): + data = _get_data_from_data_object(data_object) + levelset_obj, message = get_levelset_info(levelset) + if message != "": + return -1, f"For set_levelset_available_levels unable to get levelset for {levelset}." + if completed_count == "all": + completed_count = 8 # no levelset has more than 6 levels so this is a safe maximum, and it will get checked farther below. + if completed_count == "none": + completed_count = 0 + # by this point, it better be an integer + try: + completed_count = int(completed_count) + except: + return -1, f"cannot set levelset available levels to {completed_count}" + if completed_count < 0: + completed_count = 0 + completed_count = min(levelset_obj["l"], completed_count) + pos_levelset_completed_mission_mask = PROFILE_START_POSITION[profile_id]+POS_LEVELSET_COMPLETED_MISSIONS_MASK+(INT_SIZE*levelset_obj["id"]) + completed_bitmask = pow(2,completed_count)-1 + #print(f"debug: need to set levelset {levelset} available count to {completed_count}, which stored as a bitmask should be {completed_bitmask:07b}") + data = srb_pack('<1i',data,pos_levelset_completed_mission_mask,completed_bitmask) + return data, "" + def get_collected_balloons_for_levelset(data_object,profile_id,levelset,silent=False): data = _get_data_from_data_object(data_object) levelset_obj, message = get_levelset_info(levelset) -- cgit