fix: remove calls to non-existent methods and add error handling

- Remove update_cost calls (method doesn't exist in new HUD)
- Remove update_stats with shots_add (not implemented)
- Add try/except to all event handlers to prevent crashes
- Simplify damage tracking to just update_damage methods
This commit is contained in:
LemonNexus 2026-02-10 13:50:24 +00:00
parent 90595a8ebe
commit 303bb3b538
1 changed files with 19 additions and 32 deletions

View File

@ -1094,46 +1094,33 @@ class MainWindow(QMainWindow):
self.log_info("Skill", f"{skill_name} +{gained}")
def on_damage_dealt(event):
"""Handle damage dealt - also track weapon cost and shots fired."""
"""Handle damage dealt - track damage stats."""
from decimal import Decimal
damage = event.data.get('damage', 0)
# Pass as Decimal to avoid type errors
self.hud.on_damage_dealt(Decimal(str(damage)))
# Track shots fired (1 shot per damage event)
self.hud.update_stats({'shots_add': 1})
# Track weapon decay cost per shot
# Only count as one shot fired per damage event
if self._selected_weapon_stats:
# Get decay per shot from weapon stats (in PEC)
decay = self._selected_weapon_stats.get('decay', 0)
if decay:
# Convert PEC to PED
cost_ped = Decimal(str(decay)) / Decimal('100')
self.hud.update_cost(cost_ped)
try:
damage = event.data.get('damage', 0)
if damage:
# Pass as Decimal to avoid type errors
self.hud.on_damage_dealt(Decimal(str(damage)))
except Exception as e:
logger.error(f"Error in on_damage_dealt: {e}")
def on_critical_hit(event):
"""Handle critical hit - same as damage dealt."""
on_damage_dealt(event)
try:
on_damage_dealt(event)
except Exception as e:
logger.error(f"Error in on_critical_hit: {e}")
def on_damage_taken(event):
"""Handle damage taken - track armor decay cost."""
from decimal import Decimal
damage = event.data.get('damage', 0)
# Pass as Decimal to avoid type errors
self.hud.on_damage_taken(Decimal(str(damage)))
# Calculate armor decay cost per hit
# Formula: cost_per_hit = armor_decay_pec / 100 (PED)
if self._selected_armor_stats and self._selected_armor_stats.get('decay'):
armor_decay_pec = Decimal(str(self._selected_armor_stats.get('decay', 0)))
if armor_decay_pec > 0:
# Convert PEC to PED (1 PED = 100 PEC)
cost_ped = armor_decay_pec / Decimal('100')
self.hud.update_cost(cost_ped)
self.log_debug("Armor", f"Armor decay: {cost_ped:.4f} PED (decay: {armor_decay_pec} PEC)")
try:
damage = event.data.get('damage', 0)
if damage:
# Pass as Decimal to avoid type errors
self.hud.on_damage_taken(Decimal(str(damage)))
except Exception as e:
logger.error(f"Error in on_damage_taken: {e}")
def on_evade(event):
"""Handle evade."""