feat(backend): Integrate Derived Stats into combat, loot, and crafting mechanics

This commit is contained in:
Joan
2026-02-25 10:05:14 +01:00
parent 185781d168
commit fd94387d54
10 changed files with 727 additions and 101 deletions

View File

@@ -195,9 +195,13 @@ async def loot_corpse(
# Parse corpse ID
corpse_type, corpse_db_id = req.corpse_id.split('_', 1)
corpse_db_id = int(corpse_db_id)
player = current_user # current_user is already the character dict
# Get player derived stats for loot quality
from ..services.stats import calculate_derived_stats
stats = await calculate_derived_stats(player['id'], redis_manager)
loot_quality = stats.get('loot_quality', 1.0)
# Get player's current capacity
inventory = await db.get_inventory(player['id'])
current_weight, max_weight, current_volume, max_volume = await calculate_player_capacity(inventory, ITEMS_MANAGER)
@@ -246,7 +250,6 @@ async def loot_corpse(
success, error_msg, tools_consumed = await consume_tool_durability(player['id'], tool_req, inventory)
if not success:
raise HTTPException(status_code=400, detail=error_msg)
# Determine quantity
quantity = random.randint(loot_item['quantity_min'], loot_item['quantity_max'])
@@ -254,6 +257,13 @@ async def loot_corpse(
# Check if item fits in inventory
item_def = ITEMS_MANAGER.get_item(loot_item['item_id'])
if item_def:
# Apply loot quality bonus for resources and consumables
if getattr(item_def, 'category', item_def.type) in ['resource', 'consumable'] and loot_quality > 1.0:
# e.g., loot_quality 1.15 = 15% chance for +1 extra
bonus_chance = loot_quality - 1.0
if random.random() < bonus_chance:
quantity += 1
item_weight = item_def.weight * quantity
item_volume = item_def.volume * quantity
@@ -305,11 +315,16 @@ async def loot_corpse(
if can_loot:
# Can loot this item
quantity = random.randint(loot_item['quantity_min'], loot_item['quantity_max'])
if quantity > 0:
# Check if item fits in inventory
item_def = ITEMS_MANAGER.get_item(loot_item['item_id'])
if item_def:
# Apply loot quality bonus for resources and consumables
if getattr(item_def, 'category', item_def.type) in ['resource', 'consumable'] and loot_quality > 1.0:
bonus_chance = loot_quality - 1.0
if random.random() < bonus_chance:
quantity += 1
item_weight = item_def.weight * quantity
item_volume = item_def.volume * quantity