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:
parent
90595a8ebe
commit
303bb3b538
|
|
@ -1094,46 +1094,33 @@ 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 - also track weapon cost and shots fired."""
|
"""Handle damage dealt - track damage stats."""
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
damage = event.data.get('damage', 0)
|
try:
|
||||||
# Pass as Decimal to avoid type errors
|
damage = event.data.get('damage', 0)
|
||||||
self.hud.on_damage_dealt(Decimal(str(damage)))
|
if damage:
|
||||||
|
# Pass as Decimal to avoid type errors
|
||||||
# Track shots fired (1 shot per damage event)
|
self.hud.on_damage_dealt(Decimal(str(damage)))
|
||||||
self.hud.update_stats({'shots_add': 1})
|
except Exception as e:
|
||||||
|
logger.error(f"Error in on_damage_dealt: {e}")
|
||||||
# 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)
|
|
||||||
|
|
||||||
def on_critical_hit(event):
|
def on_critical_hit(event):
|
||||||
"""Handle critical hit - same as damage dealt."""
|
"""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):
|
def on_damage_taken(event):
|
||||||
"""Handle damage taken - track armor decay cost."""
|
"""Handle damage taken - track armor decay cost."""
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
try:
|
||||||
damage = event.data.get('damage', 0)
|
damage = event.data.get('damage', 0)
|
||||||
# Pass as Decimal to avoid type errors
|
if damage:
|
||||||
self.hud.on_damage_taken(Decimal(str(damage)))
|
# Pass as Decimal to avoid type errors
|
||||||
|
self.hud.on_damage_taken(Decimal(str(damage)))
|
||||||
# Calculate armor decay cost per hit
|
except Exception as e:
|
||||||
# Formula: cost_per_hit = armor_decay_pec / 100 (PED)
|
logger.error(f"Error in on_damage_taken: {e}")
|
||||||
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)")
|
|
||||||
|
|
||||||
def on_evade(event):
|
def on_evade(event):
|
||||||
"""Handle evade."""
|
"""Handle evade."""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue