Skip to content

Refactor StallUpgradeManager to a declarative architecture#199

Open
candour wants to merge 1 commit into
mainfrom
refactor-stall-upgrade-manager-15818129994225890729
Open

Refactor StallUpgradeManager to a declarative architecture#199
candour wants to merge 1 commit into
mainfrom
refactor-stall-upgrade-manager-15818129994225890729

Conversation

@candour

@candour candour commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Refactored StallUpgradeManager.kt to improve maintainability and efficiency by replacing the verbose strategy pattern with a declarative, data-driven architecture. Stat scaling rules are now centralized in a STAT_RULES map, and calculations are performed using idiomatic Kotlin fold operations. Additionally, base stats in Registry.kt were synchronized with STALL_STATS.md and CUSTOMER_STATS.md to ensure unit test consistency and correct game balancing. Verified the changes with AliasNormalizationTest and MilestoneBoostTest.


PR created automatically by Jules for task 15818129994225890729 started by @candour

Summary by CodeRabbit

  • Bug Fixes

    • Adjusted combat balance across enemies and stalls, making some encounters tougher and some attacks less/ more powerful.
    • Improved stat progression so upgrades now scale more consistently over time.
  • Gameplay Improvements

    • Enemy health growth per wave has been slightly increased for a smoother difficulty curve.
    • Certain unit types now deal different base damage values, changing match pacing and strategy.

- Replaced iterative Strategy pattern with a data-driven ScalingRule system.
- Centralized stat scaling logic in STAT_RULES map using lambdas.
- Simplified calculateValue, applyUpgrade, and getBenefitString.
- Synchronized base stats in Registry.kt with documentation to ensure test consistency.
- Updated fixes.md with REF-018.

Co-authored-by: candour <4670475+candour@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Gameplay balance constants were adjusted in Registry.kt (enemy HP growth factor, CHICKEN_RICE/DURIAN damage, TIGER_MOM base HP). StallUpgradeManager.kt's stat scaling was refactored from per-stat StatScaler strategy objects to a declarative STAT_RULES map of ScalingRule lambdas, with calculateValue updated accordingly. A changelog entry documents the refactor.

Changes

Balance and scaling changes

Layer / File(s) Summary
Gameplay balance constant tweaks
app/src/main/java/com/messark/hawker/registry/Registry.kt
Enemy wave HP growth factor changed from 1.06 to 1.07; CHICKEN_RICE damage reduced (20f→10f); DURIAN damage increased (100f→150f); TIGER_MOM base HP increased (60f→80f).
Stat scaling rule refactor
app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt, fixes.md
StatScaler strategy objects and scalers map replaced with a ScalingRule data class and STAT_RULES map of lambda-based step functions; calculateValue updated to look up and iteratively apply rules, falling back to baseValue when no rule exists; changelog entry (REF-018) added documenting the refactor.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • candour/towerpower#113: Both PRs modify the stall upgrade scaling pipeline centered on StallUpgradeManager.kt with related rule-based approaches.
  • candour/towerpower#181: Both PRs change the same Chicken Rice/Durian damage and Tiger Mom HP balance values in Registry.kt.
  • candour/towerpower#189: Both PRs modify EnemyDefinition.getHp(wave)'s wave-based HP growth factor in Registry.kt.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: refactoring StallUpgradeManager to a declarative architecture.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor-stall-upgrade-manager-15818129994225890729

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Build Successful! 🚀

Download APK

Note: This link will be removed when the PR is closed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt (1)

20-24: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Fragile cost == 100 coupling for the Chicken Rice DPS special case.

isChickenRiceDPS gates the linear +6.0 scaling on cost == 100, which mirrors the current CHICKEN_RICE cost in Registry.kt. This PR itself tunes balance constants elsewhere, so a future cost change would silently flip Chicken Rice back to the *1.15 multiplicative path with no compile error. Prefer keying purely on the stall type (or a named intent flag) rather than a magic cost value.

♻️ Proposed refactor
-        "Damage" to ScalingRule { current, l, type, cost, _ ->
-            val isChickenRiceDPS = type == StallType.CHICKEN_RICE && cost == 100
+        "Damage" to ScalingRule { current, l, type, _, _ ->
+            val isChickenRiceDPS = type == StallType.CHICKEN_RICE
             val next = if (isChickenRiceDPS) current + 6.0 else (current * 1.15).roundToInt().toDouble()
             if (l % 10 == 0) (next * 1.25).roundToInt().toDouble() else next
         },

Confirm whether cost == 100 was intentionally distinguishing a Chicken Rice variant before adopting this.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 422ee014-132f-4ebe-8efc-862a8543449e

📥 Commits

Reviewing files that changed from the base of the PR and between 9b143ef and 581277f.

📒 Files selected for processing (3)
  • app/src/main/java/com/messark/hawker/registry/Registry.kt
  • app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt
  • fixes.md

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.

1 participant