Skip to content

Commit

Permalink
v0.0.9
Browse files Browse the repository at this point in the history
- Fixes that should mitigate some of the json read crashes,
- Updates to Crafting functionality
- Small usability fixes
  • Loading branch information
euloggeradmin committed Apr 12, 2022
1 parent 0a74c1a commit bf2cf81
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 23 deletions.
9 changes: 7 additions & 2 deletions LootNanny.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(self):

statusBar.addWidget(self.theme_btn)


self.combat_module.load_runs()
layout.addWidget(statusBar)

self.initialize_from_config()
Expand Down Expand Up @@ -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
Expand All @@ -153,18 +155,19 @@ 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
try:
TICK_COUNTER += 1
if not TICK_COUNTER % 5:
TICK_COUNTER %= 5
self.combat_module.save_runs()

self.chat_reader.delay_start_reader()

Expand Down Expand Up @@ -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:
Expand Down
26 changes: 17 additions & 9 deletions modules/combat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.0.8"
VERSION = "0.0.9"
59 changes: 48 additions & 11 deletions views/crafting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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]
Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand Down

0 comments on commit bf2cf81

Please sign in to comment.