Files
echoes-of-the-ash/docs/GAME_UPDATES_DISTANCE_COOLDOWN.md
2025-11-07 15:27:13 +01:00

4.7 KiB

Game Updates - Distance, Title, Cooldown & UI Improvements

Summary

Implemented multiple enhancements including distance tracking in meters, game title update, movement cooldown, and UI improvements.

Changes Implemented

1. Distance Tracking in Meters

Problem: Statistics tracked stamina cost instead of actual distance
Solution: Updated move system to calculate and track real distance in meters

Files Changed:

  • api/game_logic.py: Updated move_player() to return distance as 5th value

    • Changed distance calculation to int(coord_distance * 100) (rounds to integer meters)
    • Returns: (success, message, new_location_id, stamina_cost, distance)
  • api/main.py:

    • Updated web move endpoint to track distance: await db.update_player_statistics(current_user['id'], distance_walked=distance, increment=True)
    • Updated bot move endpoint to track distance for Telegram users
    • Changed distance display in directions from round(distance, 1) to int(distance)

Result: Distance walked now shows actual meters traveled instead of stamina cost


2. Integer Distance Display

Problem: Distances showed decimal places (e.g., "141.4m")
Solution: Rounded all distances to integers

Changes:

  • All distance calculations now use int() instead of round(x, 1)
  • Displays as "141m" instead of "141.4m"

3. Game Title Update

Problem: Game called "Echoes of the Ashes"
Solution: Changed to "Echoes of the Ash"

Files Changed:

  • pwa/src/components/GameHeader.tsx: Updated <h1> title
  • pwa/src/components/Login.tsx: Updated login screen title
  • pwa/index.html: Updated page <title>
  • api/main.py: Updated FastAPI app title

4. 30-Second Movement Cooldown (Backend)

Problem: Players could move too quickly between zones
Solution: Added 30-second cooldown after each movement

Database Migration:

  • Created migrate_add_movement_cooldown.py
  • Added last_movement_time FLOAT DEFAULT 0 column to players table
  • Successfully migrated database

API Changes (api/main.py):

  • Move endpoint now checks cooldown before allowing movement:
    cooldown_remaining = max(0, 30 - (current_time - last_movement))
    if cooldown_remaining > 0:
        raise HTTPException(400, f"You must wait {int(cooldown_remaining)} seconds before moving again.")
    
  • Updates last_movement_time after successful move
  • Game state endpoint returns movement_cooldown (seconds remaining)

Files Changed:

  • api/database.py: Added last_movement_time column to players table definition
  • api/main.py: Added cooldown check in move endpoint
  • migrate_add_movement_cooldown.py: Migration script ( executed successfully)
  • Dockerfile.api: Added migration scripts to container

5. UI Improvements - Location Names & Danger Levels

Problem: Location names not centered, danger levels too small, safe zones not indicated
Solution: Enhanced danger badge styling and added safe zone indicator

Changes (pwa/src/components/Game.tsx):

  • Added safe zone badge for danger level 0:
    {location.danger_level === 0 && (
      <span className="danger-badge danger-safe" title="Safe Zone">
         Safe
      </span>
    )}
    

CSS Changes (pwa/src/components/Game.css):

  • Increased danger badge size:

    • Font size: 0.75rem1rem
    • Padding: 0.25rem 0.75rem0.5rem 1.2rem
    • Border radius: 20px24px
    • Gap: 0.25rem0.4rem
    • Border width: 1px2px
  • Added .danger-safe style:

    .danger-safe {
      background: rgba(76, 175, 80, 0.2);
      color: #4caf50;
      border: 2px solid #4caf50;
    }
    

Result: Danger badges are now larger and more prominent, safe zones clearly marked


Still To Implement

Frontend Movement Cooldown

  • Disable movement buttons when on cooldown
  • Show countdown timer on buttons
  • Poll movement_cooldown from game state

Enemy Turn Delay in Combat

  • Add 2-second visual delay for enemy turns
  • Show "Enemy's turn..." message
  • Display outcome after delay for dynamic feel

Encounter Rate on Arrival

  • Check encounter_rate when moving to dangerous zones
  • Spawn enemy and initiate combat based on probability
  • Only for zones with danger_level > 1

Deployment Status

API rebuilt and deployed
PWA rebuilt and deployed
Database migration executed successfully
All containers running

Testing Recommendations

  1. Verify distance statistics show meters
  2. Test movement cooldown (30-second wait)
  3. Check danger badges display correctly (including safe zones)
  4. Confirm game title updated everywhere
  5. Validate integer distance display (no decimals)