feat(backend): Integrate Derived Stats into combat, loot, and crafting mechanics
This commit is contained in:
@@ -179,6 +179,11 @@ async def craft_item(request: CraftItemRequest, current_user: dict = Depends(get
|
||||
if not player:
|
||||
raise HTTPException(status_code=404, detail="Player not found")
|
||||
|
||||
# Get derived stats for crafting bonus
|
||||
from ..services.stats import calculate_derived_stats
|
||||
stats = await calculate_derived_stats(player['id'], redis_manager)
|
||||
crafting_bonus = stats.get('crafting_bonus', 0.0)
|
||||
|
||||
location_id = player['location_id']
|
||||
location = LOCATIONS.get(location_id)
|
||||
|
||||
@@ -287,11 +292,13 @@ async def craft_item(request: CraftItemRequest, current_user: dict = Depends(get
|
||||
if hasattr(item_def, 'durability') and item_def.durability:
|
||||
# This is a unique item - generate random stats
|
||||
base_durability = item_def.durability
|
||||
# Random durability: 90-110% of base
|
||||
random_durability = int(base_durability * random.uniform(0.9, 1.1))
|
||||
|
||||
# Generate tier based on durability roll
|
||||
durability_percent = (random_durability / base_durability)
|
||||
# Random durability: 90-110% of base, plus crafting_bonus (e.g. +0.05 from Intellect)
|
||||
base_roll = random.uniform(0.9, 1.1)
|
||||
durability_percent = base_roll + crafting_bonus
|
||||
random_durability = int(base_durability * durability_percent)
|
||||
|
||||
# Generate tier based on the final durability percentage
|
||||
if durability_percent >= 1.08:
|
||||
tier = 5 # Gold
|
||||
elif durability_percent >= 1.04:
|
||||
@@ -308,8 +315,9 @@ async def craft_item(request: CraftItemRequest, current_user: dict = Depends(get
|
||||
if hasattr(item_def, 'stats') and item_def.stats:
|
||||
for stat_key, stat_value in item_def.stats.items():
|
||||
if isinstance(stat_value, (int, float)):
|
||||
# Random stat: 90-110% of base
|
||||
random_stats[stat_key] = int(stat_value * random.uniform(0.9, 1.1))
|
||||
# Random stat: same multiplier logic applied to base stats
|
||||
stat_percent = random.uniform(0.9, 1.1) + crafting_bonus
|
||||
random_stats[stat_key] = int(stat_value * stat_percent)
|
||||
else:
|
||||
random_stats[stat_key] = stat_value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user