Skip to content

Conversation

@KashGiannis34
Copy link
Contributor

Implemented dynamic xp for each level

Issue Number(s): #157

What does this PR change and why?

Added the dynamic xp req for each level. 90xp for level 0, 100xp for level 1, etc. Didn't need to change tutorial logic because the user only gets 5 xp from that anyway so they cant level up from it.

Checklist

  • Requirements have been implemented
  • Acceptance criteria is met
  • Database schema docs have been updated or are not necessary
  • Code follows design and style guidelines
  • Commits follow guidelines (concise, squashed, etc)
  • Relevant reviewers (Senior Dev/EM/Designers) have been assigned to this PR

Critical Changes

N/A

Related PRs

Testing

Tested manually.

@netlify
Copy link

netlify bot commented Nov 18, 2025

Deploy Preview for bog-ican ready!

Name Link
🔨 Latest commit b00ee7e
🔍 Latest deploy log https://app.netlify.com/projects/bog-ican/deploys/691cf9a328373900084c1c8a
😎 Deploy Preview https://deploy-preview-202--bog-ican.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@greptile-apps
Copy link

greptile-apps bot commented Nov 18, 2025

Disclaimer: This comment was AI-generated and is not necessarily completely accurate. Please take code comments with a grain of salt.

Greptile Summary

  • Replaced hardcoded 100 XP level threshold with dynamic formula: 90 XP for level 0, increasing by 10 XP per level
  • Updated backend leveling logic and frontend components to calculate XP requirements dynamically per level

Confidence Score: 4/5

  • Safe to merge with one edge case limitation in existing leveling logic
  • Implementation correctly handles normal gameplay scenarios where pets gain 5 XP per feeding. The dynamic XP formula matches requirements (90 + level*10). However, the leveling logic in pets.ts only increments level once per feeding, so if a pet somehow accumulated enough XP to skip multiple levels, it would only level up once. Given current game mechanics (5 XP per feeding, 90+ XP thresholds), this edge case is unlikely to occur in practice.
  • Review src/services/pets.ts:103-107 to understand the leveling logic limitation with multi-level XP gains

Important Files Changed

Filename Overview
src/utils/constants.ts Replaced hardcoded LEVEL_THRESHOLD constant with dynamic calculateXPForLevel function implementing the 90 + level*10 formula
src/services/pets.ts Updated feedPet to calculate XP threshold dynamically per level; logic correct for normal gameplay but won't handle multi-level jumps

Sequence Diagram

sequenceDiagram
    participant User
    participant "feedPet()" as Feed
    participant "calculateXPForLevel()" as Calc
    participant Database
    
    User->>Feed: "Feed pet"
    Feed->>Database: "Get pet by petId"
    Database-->>Feed: "Return pet (level, xpGained, food)"
    Feed->>Feed: "Decrement food"
    Feed->>Calc: "calculateXPForLevel(currentLevel)"
    Calc-->>Feed: "Return threshold (90 + level*10)"
    Feed->>Feed: "Check if xpGained >= threshold - 5"
    alt "Level up"
        Feed->>Feed: "Increment level"
        Feed->>Feed: "Add 100 coins"
        Feed->>Feed: "Calculate overflow XP"
    else "No level up"
        Feed->>Feed: "Add 5 XP"
    end
    Feed->>Database: "Update pet (xpGained, xpLevel, food, coins)"
    Database-->>Feed: "Confirm update"
    Feed-->>User: "Return updated pet"
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

@rgodha24 rgodha24 merged commit 4c60947 into main Nov 19, 2025
4 checks passed
@rgodha24 rgodha24 deleted the akash/dynamic-xp-leveling branch November 19, 2025 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants