Skip to content

Refactor StallUpgradeManager to Strategy Pattern#162

Merged
candour merged 1 commit into
mainfrom
refactor-stall-upgrade-manager-strategy-pattern-15292056635653905076
May 16, 2026
Merged

Refactor StallUpgradeManager to Strategy Pattern#162
candour merged 1 commit into
mainfrom
refactor-stall-upgrade-manager-strategy-pattern-15292056635653905076

Conversation

@candour

@candour candour commented May 16, 2026

Copy link
Copy Markdown
Owner

Refactored StallUpgradeManager.kt to use a declarative StatScaler strategy pattern. This simplifies the core stat calculation logic and improves efficiency by moving constant calculations and branching logic out of the level-iteration loops. Documented the change in fixes.md (REF-010).


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

Summary by CodeRabbit

  • Refactor
    • Optimized stall upgrade stat-scaling calculations with improved efficiency and simplified logic structure.

Review Change Stack

Refactored `StallUpgradeManager.kt` to use a declarative `StatScaler` strategy pattern for stat calculations. This change simplifies the core logic by replacing a large, monolithic `when` block with specialized scaler objects.

Efficiency improvements:
- Canonical stat lookup is performed once per `calculateValue` call instead of inside the level iteration loop.
- Stall-specific constants (e.g., rate floors, reductions, duration caps) are calculated once per `calculate` call instead of on every loop iteration.
- Encapsulated milestone and rounding logic within specific scalers, improving maintainability.

Updated `fixes.md` to record REF-010.
Verified with existing unit tests: `StallStatsTest`, `MilestoneBoostTest`, and `AliasNormalizationTest`.

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 May 16, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: aae769cc-e2a7-46be-8c5b-d8229746c6e8

📥 Commits

Reviewing files that changed from the base of the PR and between 997992e and 7081a73.

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

📝 Walkthrough

Walkthrough

StallUpgradeManager stat-scaling logic is refactored from a single large inline when/fold pattern into a declarative strategy pattern. Seven StatScaler implementations encapsulate per-stat progression rules, registered by canonical name in a scalers map. The calculateValue method delegates to the registered scaler instead of inline computation.

Changes

StallUpgradeManager Stat-Scaling Refactor

Layer / File(s) Summary
StatScaler Strategy Pattern and Registry
app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt
Introduces a private StatScaler interface and seven singleton implementations (DamageScaler, RangeScaler, RateScaler, RadiusScaler, DurationScaler, EffectScaler, BoostScaler). Each scaler encapsulates per-stat level-up progression rules, milestone behavior (every 10 levels), and stall-specific special cases (Chicken Rice DPS handling based on baseCost, TRAY_RETURN_UNCLE rate/duration caps/floors). A scalers registry map keys implementations by canonical stat names.
calculateValue Method Refactoring
app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt
Updates calculateValue to delegate to scalers[canonical]?.calculate(...) (passing baseValue, level, stallType, and stall definition cost) instead of executing the prior inline stat-specific logic. Maintains the existing valueCache keyed by (stallType, canonical stat, baseValue, level) and falls back to returning baseValue when no matching scaler is registered.
Changelog Documentation
fixes.md
Adds entry REF-010 (dated 2025-06-25) documenting the StallUpgradeManager.kt refactor to use a declarative StatScaler strategy pattern and associated efficiency simplifications.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • candour/towerpower#128: Refactors StallUpgradeManager.kt stat upgrade calculation around canonical stat keys and redesigned calculateValue/progression pipeline with caching.
  • candour/towerpower#67: Centralizes stall-specific upgrade/damage/benefit calculations (Chicken Rice and TRAY_RETURN_UNCLE special rules) that are now delegated by the strategy pattern.
  • candour/towerpower#116: Refactors StallUpgradeManager.kt around stat-scaling and canonical stat mapping with delegated per-stat progression rules.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Refactor StallUpgradeManager to Strategy Pattern' directly and accurately describes the primary change in the pull request: refactoring the StallUpgradeManager class to use a strategy pattern approach with StatScaler implementations.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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-strategy-pattern-15292056635653905076

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 and usage tips.

@github-actions

Copy link
Copy Markdown

Build Successful! 🚀

Download APK

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

@candour
candour merged commit 9657dc4 into main May 16, 2026
3 checks passed
@candour
candour deleted the refactor-stall-upgrade-manager-strategy-pattern-15292056635653905076 branch May 16, 2026 23:57
@coderabbitai coderabbitai Bot mentioned this pull request Jun 9, 2026
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