From bf2cf81d09c6d26a50555e561e96925216dcd5c1 Mon Sep 17 00:00:00 2001 From: LootNanny Date: Tue, 12 Apr 2022 18:44:38 +0200 Subject: [PATCH] v0.0.9 - Fixes that should mitigate some of the json read crashes, - Updates to Crafting functionality - Small usability fixes --- LootNanny.py | 9 ++++++-- modules/combat.py | 26 +++++++++++++-------- version.py | 2 +- views/crafting.py | 59 ++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 73 insertions(+), 23 deletions(-) diff --git a/LootNanny.py b/LootNanny.py index cd11221..c5e5e89 100644 --- a/LootNanny.py +++ b/LootNanny.py @@ -97,7 +97,7 @@ def __init__(self): statusBar.addWidget(self.theme_btn) - + self.combat_module.load_runs() layout.addWidget(statusBar) self.initialize_from_config() @@ -139,6 +139,8 @@ def on_toggle_logging(self): self.logging_pause_btn.setEnabled(False) self.logging_pause_btn.setText("Pause Logging") self.logging_pause_btn.setStyleSheet("background-color: grey: color; white;") + self.combat_module.save_active_run(force=True) + self.combat_module.update_tables() else: self.combat_module.is_logging = True self.combat_module.is_paused = False @@ -153,10 +155,12 @@ def on_pause_logging(self): self.combat_module.is_paused = False self.logging_pause_btn.setStyleSheet("background-color: green") self.logging_pause_btn.setText("Pause Logging") + self.combat_module.save_active_run(force=True) else: self.combat_module.is_paused = True self.logging_pause_btn.setStyleSheet("background-color: red") self.logging_pause_btn.setText("Unpause Logging") + self.combat_module.save_active_run(force=True) def on_tick(self): global TICK_COUNTER @@ -164,7 +168,6 @@ def on_tick(self): TICK_COUNTER += 1 if not TICK_COUNTER % 5: TICK_COUNTER %= 5 - self.combat_module.save_runs() self.chat_reader.delay_start_reader() @@ -442,6 +445,8 @@ def set_stylesheet(self, target, path): self.save_config() def closeEvent(self, event): + print("Close Event") + self.combat_module.save_active_run(force=True) if self.streamer_window: self.streamer_window.close() if self.twitch.twitch_bot: diff --git a/modules/combat.py b/modules/combat.py index dc2bc1a..c32e425 100644 --- a/modules/combat.py +++ b/modules/combat.py @@ -154,7 +154,7 @@ def from_seralized(cls, seralized, include_loot=False): if include_loot: for k, v in seralized["loot"].items(): - inst.looted_items[k] = {"c": v["c"], "v": Decimal(v["v"])} + inst.looted_items[k] = {"c": int(v["c"]), "v": Decimal(v["v"])} return inst @@ -338,8 +338,6 @@ def __init__(self, app): self.multiplier_graph = None self.return_graph = None - self.load_runs() - def update_active_run_cost(self): if self.active_run: cost = Decimal(self.ammo_burn) / Decimal(10000) + self.decay @@ -356,7 +354,6 @@ def tick(self, lines: List[BaseChatRow]): self.active_run.add_combat_chat_row(chat_instance) self.should_redraw_runs = True elif isinstance(chat_instance, LootInstance): - print(chat_instance) self.active_run.add_loot_instance_chat_row(chat_instance) self.should_redraw_runs = True elif isinstance(chat_instance, EnhancerBreakages): @@ -476,18 +473,21 @@ def get_runs_data(self): else: d["%"].append("%") d["mu%"].append("%") + print(d) return d def create_new_run(self): self.active_run = HuntingTrip(datetime.now(), Decimal(self.ammo_burn) / Decimal(10000) + self.decay) self.runs.append(self.active_run) - def save_runs(self, force=False): - all_runs = [] + def save_active_run(self, force=False): if not self.active_run: if not force: return - self.active_run.save_to_disk() + if self.runs: + self.runs[-1].save_to_disk() + else: + self.active_run.save_to_disk() def load_runs(self): if os.path.exists(RUNS_FILE): @@ -505,14 +505,22 @@ def load_runs(self): for fn in os.listdir(RUNS_DIRECTORY): if fn.startswith("LootNannyLog_"): - run_files.append(fn) + try: + with open(format_filename(fn), 'r') as f: + json.loads(f.read()) + run_files.append(fn) + except: + os.remove(format_filename(fn)) for i, run_fn in enumerate(run_files, 1): run = HuntingTrip.load_from_filename(run_fn, include_loot=(i == len(run_files))) self.runs.append(run) if self.runs: - self.active_run = self.runs[-1] + if self.runs[-1].time_end is None: + self.active_run = self.runs[-1] + else: + self.update_runs_table() def migrate_runs(): diff --git a/version.py b/version.py index 05ce580..81c2367 100644 --- a/version.py +++ b/version.py @@ -1 +1 @@ -VERSION = "0.0.8" \ No newline at end of file +VERSION = "0.0.9" \ No newline at end of file diff --git a/views/crafting.py b/views/crafting.py index 6eeb445..d55c88b 100644 --- a/views/crafting.py +++ b/views/crafting.py @@ -24,8 +24,10 @@ def __init__(self, app: "LootNanny", *args, **kwargs): self.total_clicks = 1 self.total_tt_cost = Decimal("0.0") self.total_cost = Decimal("0.0") + self.max_tt = Decimal("100.00") self.use_residue = False + self.one_item_per_success = False self.residue_markup = Decimal("1.02") self.blueprint_table_selected_row = None @@ -63,6 +65,15 @@ def create_layout(self): self.use_residue_check.toggled.connect(self.use_residue_toggled) form_inputs.addRow("Use Residue:", self.use_residue_check) + self.one_item_per_success_check = QCheckBox() + self.one_item_per_success_check.setChecked(self.one_item_per_success) + self.one_item_per_success_check.toggled.connect(self.one_item_per_success_check_toggled) + form_inputs.addRow("OVERRIDE: 1 Item Per Success:", self.one_item_per_success_check) + + self.item_max_tt = QLineEdit(text="100.00", enabled=True) + form_inputs.addRow("Item Max TT:", self.item_max_tt) + self.item_max_tt.textChanged.connect(self.item_max_tt_text_changed) + self.residue_markup_text = QLineEdit(text="102%", enabled=True) form_inputs.addRow("Residue Markup:", self.residue_markup_text) self.residue_markup_text.textChanged.connect(self.residue_markup_text_changed) @@ -109,6 +120,10 @@ def create_layout(self): layout.addStretch() self.setLayout(layout) + def one_item_per_success_check_toggled(self): + self.one_item_per_success = self.one_item_per_success_check.isChecked() + self.calculate_crafting_totals() + def use_residue_toggled(self): self.use_residue = self.use_residue_check.isChecked() self.calculate_crafting_totals() @@ -117,6 +132,10 @@ def residue_markup_text_changed(self): self.residue_markup = Decimal(self.residue_markup_text.text().replace("%", "")) / 100 self.calculate_crafting_totals() + def item_max_tt_text_changed(self): + self.max_tt = Decimal(self.item_max_tt.text()) + self.calculate_crafting_totals() + def get_selected_item_name(self): if self.selected_blueprint: return self.selected_blueprint.replace(" Blueprint", "").rsplit(" (L)", 1)[0] @@ -165,16 +184,31 @@ def calculate_crafting_totals(self): slot.count, slot.count * ALL_RESOURCES[slot.name]) * self.total_clicks - exp_successes = int(self.total_clicks * 0.42) - actual_item_tt = (self.total_tt_cost * Decimal("0.5")) + average_input_markup = self.total_cost / self.total_tt_cost + + expected_successes = int(self.total_clicks * 0.42) + + # Calculate total TT of successes + if self.one_item_per_success: + item_name = self.get_selected_item_name() + if item_name in ALL_RESOURCES: + item_tt_value = ALL_RESOURCES[item_name] + else: + item_tt_value = self.max_tt + actual_item_tt = expected_successes * item_tt_value + extra_residues = (self.total_tt_cost * Decimal("0.5")) - actual_item_tt + else: + actual_item_tt = (self.total_tt_cost * Decimal("0.5")) + extra_residues = Decimal("0.0") + residue_costs = Decimal("0.0") required_residue = Decimal("0.0") if self.use_residue: - TOTAL_TT = Decimal(74) - required_residue = (TOTAL_TT * exp_successes) - (self.total_tt_cost * Decimal("0.5")) + required_residue = (self.max_tt * expected_successes) - (self.total_tt_cost * Decimal("0.5")) residue_costs = required_residue * self.residue_markup self.residue_required_text.setText("{:.2f} PED".format(required_residue)) - actual_item_tt = TOTAL_TT * exp_successes + actual_item_tt = self.max_tt * expected_successes + self.total_cost += self.total_clicks * Decimal("0.01") * MarkupSingleton.get_markup_for_item(self.selected_blueprint).value self.total_tt_cost_text.setText("%.2f" % (self.total_tt_cost + required_residue) + " PED") @@ -183,19 +217,22 @@ def calculate_crafting_totals(self): # Set Calculated Totals item = self.get_selected_item_name() - self.exepcted_successes.setText(str(exp_successes)) - self.tt_as_final_item.setText("%.2f" % (self.total_tt_cost * Decimal("0.5")) + " PED") - self.expected_near_success_text.setText("%.2f" % (self.total_tt_cost * Decimal("0.45")) + " PED") + self.exepcted_successes.setText(str(expected_successes)) + self.tt_as_final_item.setText("%.2f" % (actual_item_tt) + " PED") + + near_success_tt = (self.total_tt_cost * Decimal("0.45")) + near_success_markup = (Decimal("0.4") * near_success_tt * average_input_markup) + (Decimal("0.6") * near_success_tt) + self.expected_near_success_text.setText("%.2f" % (near_success_tt + extra_residues) + " PED") mu = MarkupSingleton.get_markup_for_item(item) if mu.is_absolute: - expected = (self.total_tt_cost * Decimal("0.95")) + Decimal(exp_successes * mu.value) + expected = actual_item_tt + near_success_markup + Decimal(expected_successes * mu.value) else: - expected = (actual_item_tt * mu.value) + (self.total_tt_cost * Decimal("0.45")) + expected = (actual_item_tt * mu.value) + near_success_markup + extra_residues self.expected_return.setText("%.2f" % expected + " PED") - delta = (self.total_cost + residue_costs) - (self.total_tt_cost * Decimal("0.45")) + delta = (self.total_cost + residue_costs) - (near_success_markup + extra_residues) if mu.is_absolute: try: