fix: properly wire cost tracking and loot tracking to new HUD

- Add weapon cost tracking on damage_dealt using session_costs
- Add armor cost tracking on damage_taken using session_costs
- Fix on_loot to use update_kills() and update_loot() with proper params
- Fix on_heal to use update_healing_cost() and on_heal_event() with proper params
- All cost tracking now uses _session_costs from loadout selection
This commit is contained in:
LemonNexus 2026-02-10 13:57:41 +00:00
parent c0cb42cd54
commit e17f7e3565
1 changed files with 38 additions and 10 deletions

View File

@ -1020,13 +1020,25 @@ class MainWindow(QMainWindow):
decay_cost = Decimal('0.02') decay_cost = Decimal('0.02')
# Update HUD with heal event # Update HUD with heal event
self.hud.on_heal_event(heal_amount, decay_cost) try:
# Track healing cost
if self._session_costs:
cost_per_heal = self._session_costs.get('cost_per_heal', Decimal('0'))
if cost_per_heal > 0:
self.hud.update_healing_cost(cost_per_heal)
# Track heal amount (as event dict for new HUD)
self.hud.on_heal_event({'heal_amount': heal_amount})
except Exception as e:
logger.error(f"Error updating HUD heal: {e}")
# Log to UI # Log to UI
self.log_info("Heal", f"Healed {heal_amount} HP (Cost: {decay_cost:.4f} PED)") self.log_info("Heal", f"Healed {heal_amount} HP (Cost: {decay_cost:.4f} PED)")
def on_loot(event): def on_loot(event):
"""Handle loot events.""" """Handle loot events."""
from decimal import Decimal
item_name = event.data.get('item_name', 'Unknown') item_name = event.data.get('item_name', 'Unknown')
value_ped = event.data.get('value_ped', Decimal('0.0')) value_ped = event.data.get('value_ped', Decimal('0.0'))
quantity = event.data.get('quantity', 1) quantity = event.data.get('quantity', 1)
@ -1035,8 +1047,15 @@ class MainWindow(QMainWindow):
if item_name == 'Universal Ammo': if item_name == 'Universal Ammo':
return return
# Estimated Kills: Every loot event = 1 mob killed try:
self.hud.update_stats({'kills_add': 1}) # Update kill count (each loot event = 1 kill)
self.hud.update_kills(1)
# Update loot value
is_shrapnel = 'shrapnel' in item_name.lower()
self.hud.update_loot(value_ped, is_shrapnel=is_shrapnel)
except Exception as e:
logger.error(f"Error updating HUD loot: {e}")
# Queue database write for main thread (SQLite thread safety) # Queue database write for main thread (SQLite thread safety)
if self._current_db_session_id: if self._current_db_session_id:
@ -1049,9 +1068,6 @@ class MainWindow(QMainWindow):
'raw_line': event.raw_line 'raw_line': event.raw_line
}) })
# Update HUD (thread-safe)
self.hud.on_loot_event(item_name, value_ped)
# Log to UI (main thread only - use signal/slot or queue) # Log to UI (main thread only - use signal/slot or queue)
# We'll log this in _process_queued_events instead # We'll log this in _process_queued_events instead
@ -1094,13 +1110,19 @@ class MainWindow(QMainWindow):
self.log_info("Skill", f"{skill_name} +{gained}") self.log_info("Skill", f"{skill_name} +{gained}")
def on_damage_dealt(event): def on_damage_dealt(event):
"""Handle damage dealt - track damage stats.""" """Handle damage dealt - track damage stats and weapon cost."""
from decimal import Decimal from decimal import Decimal
try: try:
damage = event.data.get('damage', 0) damage = event.data.get('damage', 0)
if damage: if damage:
# Pass as Decimal to avoid type errors # Track damage amount
self.hud.on_damage_dealt(Decimal(str(damage))) self.hud.on_damage_dealt(Decimal(str(damage)))
# Track weapon cost per shot
if self._session_costs:
cost_per_shot = self._session_costs.get('cost_per_shot', Decimal('0'))
if cost_per_shot > 0:
self.hud.update_weapon_cost(cost_per_shot)
except Exception as e: except Exception as e:
logger.error(f"Error in on_damage_dealt: {e}") logger.error(f"Error in on_damage_dealt: {e}")
@ -1112,13 +1134,19 @@ class MainWindow(QMainWindow):
logger.error(f"Error in on_critical_hit: {e}") logger.error(f"Error in on_critical_hit: {e}")
def on_damage_taken(event): def on_damage_taken(event):
"""Handle damage taken - track armor decay cost.""" """Handle damage taken - track damage stats and armor cost."""
from decimal import Decimal from decimal import Decimal
try: try:
damage = event.data.get('damage', 0) damage = event.data.get('damage', 0)
if damage: if damage:
# Pass as Decimal to avoid type errors # Track damage amount
self.hud.on_damage_taken(Decimal(str(damage))) self.hud.on_damage_taken(Decimal(str(damage)))
# Track armor cost per hit
if self._session_costs:
cost_per_hit = self._session_costs.get('cost_per_hit', Decimal('0'))
if cost_per_hit > 0:
self.hud.update_armor_cost(cost_per_hit)
except Exception as e: except Exception as e:
logger.error(f"Error in on_damage_taken: {e}") logger.error(f"Error in on_damage_taken: {e}")