Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/food labor #2664

Merged
merged 7 commits into from
Jan 24, 2025
Merged

Fix/food labor #2664

merged 7 commits into from
Jan 24, 2025

Conversation

credence0x
Copy link
Collaborator

@credence0x credence0x commented Jan 24, 2025

  • fixed food production by allowing harvest with zero labor
  • fixed other production bugs
  • fixed config run (pnpm run config:deploy:{env})

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for a local development environment configuration.
    • Introduced new methods for managing food resources in the resource management system.
  • Improvements

    • Updated deployment scripts to use the new configuration directory.
    • Refined production and resource management logic for better efficiency.
    • Updated contract manifests and configurations to reflect recent changes.
  • Technical Updates

    • Modified contract deployment configurations for various networks.
    • Updated class hashes and contract implementations.
    • Streamlined resource production and labor management processes.

Copy link
Contributor

mentatbot bot commented Jan 24, 2025

Hi @credence0x! You need to be added as a user to interact with me. Please ask @ponderingdemocritus to add you on the settings page.

You are receiving this comment because I am set to review all PRs. That is configurable here.

Copy link

vercel bot commented Jan 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eternum ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 24, 2025 0:20am
eternum-docs ❌ Failed (Inspect) Jan 24, 2025 0:20am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
eternum-landing ⬜️ Ignored (Inspect) Visit Preview Jan 24, 2025 0:20am

Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Walkthrough

This pull request introduces comprehensive changes across multiple files to support a new "local" chain environment. The modifications primarily focus on expanding utility functions in configuration management, updating game contract implementations, and adjusting deployment scripts. The changes enable better support for local development by adding new import statements, updating type declarations, and modifying resource and production-related logic across the codebase.

Changes

File Change Summary
config/utils/utils.ts Added support for "local" chain, updated type declarations and utility functions to handle local environment configurations
contracts/game/dojo_local.toml, contracts/game/dojo_sepolia.toml Removed "s1_eternum-dev_realm_systems" from writers section
contracts/game/manifest_sepolia.json Updated multiple contract class hashes, removed a specific contract entry
contracts/game/src/models/resource/* Modified labor and production logic, renamed methods, added new helper methods for resource management
package.json Updated deployment script paths from ./client/config to ./config
packages/core/src/managers/resource-manager.ts Added isFood() method, updated resource processing logic
config/.gitignore, contracts/common/.gitignore Removed entries for local.json and addresses/local.json to track them in version control
contracts/common/addresses/local.json Added new JSON file defining addresses for various entities and resources
contracts/game/.gitignore Removed entry for manifest_local.json to track it in version control

Possibly related PRs

  • fix: resource prod cap #1834: The changes in this PR involve resource production logic, which may relate to the new "local" chain functionality introduced in the main PR.
  • contracts: allow production amount change #2427: The modifications to production configuration in this PR could relate to the changes made in the main PR regarding the handling of configurations for different environments.
  • Enh/clean assets #2637: The changes in asset management and organization may connect with the overall improvements in the main PR regarding local chain support.

Suggested Reviewers

  • ponderingdemocritus

Poem

🐰 In config's realm, a local spark ignites,
Utility functions dance with new delights,
Contracts shimmer, resources take flight,
A rabbit's code leaps with pure delight!
Local magic weaves its clever might 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Failed to generate code suggestions for PR

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
config/utils/utils.ts (1)

101-103: Address lint formatting.
Note the extra space in slotConfig.configuration ;. Remove it to match code style guidelines.

-        return slotConfig.configuration ;
+        return slotConfig.configuration;
🧰 Tools
🪛 GitHub Actions: lint

[warning] Code formatting does not match Prettier standards

contracts/game/src/models/resource/production/production.cairo (2)

78-80: Free production logic.
Any resource classified as food is free from labor constraints. Confirm with game design that this is desired for all food resources.


122-123: Update resource balance.
Good approach to finalize the new amount. Add event logging if needed.

packages/core/src/managers/resource-manager.ts (1)

31-33: isFood() method introduction.
This is a straightforward check. Consider storing food resource IDs in a config array if more food types are added later.

🧰 Tools
🪛 GitHub Actions: lint

[warning] Code formatting does not match Prettier standards

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4222dfd and a820b86.

📒 Files selected for processing (9)
  • config/utils/utils.ts (4 hunks)
  • contracts/game/dojo_local.toml (0 hunks)
  • contracts/game/dojo_sepolia.toml (0 hunks)
  • contracts/game/manifest_sepolia.json (16 hunks)
  • contracts/game/src/models/resource/production/labor.cairo (1 hunks)
  • contracts/game/src/models/resource/production/production.cairo (2 hunks)
  • contracts/game/src/models/resource/resource.cairo (1 hunks)
  • package.json (4 hunks)
  • packages/core/src/managers/resource-manager.ts (4 hunks)
💤 Files with no reviewable changes (2)
  • contracts/game/dojo_sepolia.toml
  • contracts/game/dojo_local.toml
🧰 Additional context used
🪛 GitHub Actions: lint
packages/core/src/managers/resource-manager.ts

[warning] Code formatting does not match Prettier standards

config/utils/utils.ts

[warning] Code formatting does not match Prettier standards

🔇 Additional comments (25)
config/utils/utils.ts (6)

2-2: Validate import path.
It looks good to have a dedicated JSON for local environments. Just ensure that ../../contracts/common/addresses/local.json is the correct relative path.

🧰 Tools
🪛 GitHub Actions: lint

[warning] Code formatting does not match Prettier standards


6-6: Import statement for localGameManifest.
Again, confirm the local manifest JSON path. Otherwise, all good.

🧰 Tools
🪛 GitHub Actions: lint

[warning] Code formatting does not match Prettier standards


11-11: Double-check the localConfig path.
Same consideration as above—ensure the relative path is valid in all build environments.

🧰 Tools
🪛 GitHub Actions: lint

[warning] Code formatting does not match Prettier standards


17-17: Chain type extension.
Adding "local" is straightforward. Confirm usage throughout the code to avoid type mismatches.

🧰 Tools
🪛 GitHub Actions: lint

[warning] Code formatting does not match Prettier standards


34-35: Local chain case for getSeasonAddresses.
Looks consistent with the approach for other chains.

🧰 Tools
🪛 GitHub Actions: lint

[warning] Code formatting does not match Prettier standards


67-68: Handle local chain in getGameManifest.
Implementation is aligned with other chain cases; no issues.

🧰 Tools
🪛 GitHub Actions: lint

[warning] Code formatting does not match Prettier standards

contracts/game/src/models/resource/production/labor.cairo (1)

70-70: Method rename consistency.
Using resource.production.spend_labor_resource aligns with the new naming. Double-check all calls to the old use_labor.

contracts/game/src/models/resource/production/production.cairo (13)

10-10: New import – ensure usage.
ResourceFoodImpl is imported to support free production logic. This is good. Just confirm it’s only used for “food” checks to avoid confusion.


52-61: Renamed function and labor cost check.
Renaming use_labor to spend_labor_resource clarifies intent. The divisibility check by labor_cost is correct.


63-66: increase_labor_units method.
Implementation is straightforward—just increments labor_units_left. Confirm there's no overflow possibility if labor_units_left gets large.


68-71: decrease_labor_units method.
Similarly, ensure labor_units_left cannot go below zero. The calling code appears to handle actual usage checks.


73-76: set_last_updated_tick method.
This setter method clarifies tick updates. Good for code readability.


89-91: Capture the start tick.
Good approach to store the old last_updated_tick for differential labor calculation.


92-94: Updating last updated tick.
Always updating the tick ensures harvest calculations remain consistent with the current time.


96-99: Excluding LORDS resource from production.
A direct check ensures LORDS remain off-limits. The short-circuit return is good.


100-103: Check building availability.
Skipping production if no active building count is correct.


105-109: Calculate labor units burned.
Multiplying elapsed ticks by the number of buildings is straightforward. Ensure it matches the intended game design.


110-116: Cap labor usage for non-free production.
This portion is essential: capping labor usage based on labor_units_left helps prevent negative labor.


119-120: Compute total produced amount.
Uses labor_units_burned × production_rate. Straightforward.


125-126: Return production result.
Returning true if total_produced_amount is non-zero is clear for subsequent logic.

packages/core/src/managers/resource-manager.ts (2)

109-109: Differential labor usage logic.
Capping laborUnitsBurned only if not food matches the new “free production” approach.

🧰 Tools
🪛 GitHub Actions: lint

[warning] Code formatting does not match Prettier standards


122-125: Extending production indefinitely for food.
Using 1 << 64 effectively sets no expiration. Confirm that such a large number has no undesired side effects in frontend logic or anywhere else.

🧰 Tools
🪛 GitHub Actions: lint

[warning] Code formatting does not match Prettier standards

contracts/game/src/models/resource/resource.cairo (1)

281-290: Revisit capacity enforcement and test zero-labor production.
The new condition removes the has_building() check, allowing harvesting even with zero labor/buildings. This aligns with the PR objective of zero-labor food production. However, restricting the storehouse capacity check to only when non_zero_harvest might miss cases where the capacity could change independently. You may consider always calling self.limit_balance_by_storehouse_capacity(ref world) to handle any external capacity changes.

Additionally, it's worth verifying this approach with a scenario where building_count is zero, confirming that appropriate amounts are harvested and stored.

Below is a script to detect references to a zero-labor or zero-building setup so you can confirm coverage in your tests:

package.json (1)

28-28: Verify references to the old config path.
Changing the directory from ./client/config to ./config is a good move to unify or simplify your deployment process. However, ensure no lingering references remain.

Here is a script to locate any residual references to client/config throughout the repository:

Also applies to: 44-44, 55-55, 66-66

contracts/game/manifest_sepolia.json (1)

1485-1485: Verify contract upgrades for production-related changes.

The class hash updates for battle_pillage_systems, battle_systems, and dev_resource_systems contracts align with the PR objectives of fixing food production and labor-related bugs.

Let's verify the contract changes:

Also applies to: 1689-1689, 4069-4069

✅ Verification successful

Contract upgrades verified for production and labor changes

The class hash updates in the manifest align with the PR objectives of modifying food harvesting and fixing production bugs. The contract interfaces and models support the required functionality for managing production, labor, and food consumption.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify contract changes related to food production and labor
# Expected: Changes in production and labor-related functions

# Search for production and labor-related functions in the old and new implementations
for contract in "battle_pillage_systems" "battle_systems" "dev_resource_systems"; do
  echo "Checking $contract changes..."
  
  # Search for production and labor-related functions
  rg -A 5 "production|labor|food|harvest" 
  
  # Search for function calls that might be affected by zero labor changes
  ast-grep --pattern 'function $_($_, $_) { $$$ labor $$$ }'
done

Length of output: 73906

@aymericdelab aymericdelab self-requested a review January 24, 2025 08:31
@bob0005 bob0005 merged commit 5c8b52a into next Jan 24, 2025
4 of 27 checks passed
@bob0005 bob0005 deleted the fix/food-labor branch January 24, 2025 12:18
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
contracts/game/src/models/resource/production/production.cairo (2)

62-80: Consider adding documentation for the new utility methods.

The new utility methods are well-structured and properly marked as inline. However, adding documentation would help explain their purpose and usage, especially for is_free_production which implements critical business logic.

Add documentation like this:

 #[inline(always)]
+/// Checks if a resource type can be produced without consuming labor units.
+/// Currently applies to food resources only.
 fn is_free_production(resource_type: u8) -> bool {
     return ResourceFoodImpl::is_food(resource_type);
 }

124-124: Consider implementing the event for production tracking.

The TODO comment indicates a missing event that could be useful for tracking production activities.

Would you like me to help implement the event for production tracking? This could include:

  • Amount produced
  • Resource type
  • Labor units burned (if applicable)
contracts/common/addresses/local.json (1)

5-36: Consider organizing resources by category for better maintainability.

The resources object mixes different types (basic materials, military units, food items) without clear categorization. Consider organizing them into sub-objects by type:

 "resources": {
-  "STONE": [1, "0x1d0e..."],
-  "COAL": [2, "0x116..."],
+  "materials": {
+    "STONE": [1, "0x1d0e..."],
+    "COAL": [2, "0x116..."],
+  },
+  "military": {
+    "DONKEY": [25, "0x9c3..."],
+    "KNIGHT": [26, "0x2da..."],
+  },
+  "food": {
+    "WHEAT": [29, "0x39e..."],
+    "FISH": [30, "0x2ae..."],
+  }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a820b86 and f554b48.

📒 Files selected for processing (5)
  • config/.gitignore (0 hunks)
  • contracts/common/.gitignore (0 hunks)
  • contracts/common/addresses/local.json (1 hunks)
  • contracts/game/.gitignore (0 hunks)
  • contracts/game/src/models/resource/production/production.cairo (2 hunks)
💤 Files with no reviewable changes (3)
  • contracts/common/.gitignore
  • contracts/game/.gitignore
  • config/.gitignore
🔇 Additional comments (5)
contracts/game/src/models/resource/production/production.cairo (3)

10-10: LGTM! Import addition aligns with food production changes.

The addition of ResourceFoodImpl import supports the new food-specific production logic.


52-60: Well-structured refactoring of labor spending logic.

Good improvements:

  • More descriptive method name
  • Extraction of labor unit manipulation to a helper method
  • Retained important validations

88-125: Improved harvest logic with better control flow.

The changes improve the harvest method by:

  • Updating tick timing first to prevent edge cases
  • Properly implementing food production without labor requirement
  • Providing more meaningful return value
contracts/common/addresses/local.json (2)

33-34: Verify food resource configuration for production fix.

Since this PR aims to fix food production bugs, please verify that the WHEAT and FISH resource configurations align with the production system requirements.

Let's analyze the food production system:

✅ Verification successful

Food resource configurations are correctly aligned with production requirements

The WHEAT and FISH resource configurations in local.json are properly set up with:

  • Correct resource IDs (WHEAT=29, FISH=30) matching production
  • Environment-appropriate hash values
  • Proper integration with game mechanics including travel costs, realm leveling, and mercenary rewards
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for food production related code
rg -l "food.*production|production.*food"

# Check for WHEAT and FISH resource usage
rg -A 5 -B 5 "WHEAT|FISH" --type typescript --type javascript

Length of output: 142


Script:

#!/bin/bash
# Search for food production and resource configurations
rg -l "food.*production|production.*food"

# Find all JSON files that might contain resource configurations
fd -e json

# Search for WHEAT and FISH references
rg -A 5 -B 5 "WHEAT|FISH"

# Look for resource-related code
rg -l "resource.*config|config.*resource"

Length of output: 87344


2-4: Consider standardizing address format with '0x' prefix.

The addresses are missing the '0x' prefix. While these are valid 32-byte hex strings, ensure that all consuming code handles addresses without the prefix correctly. Consider standardizing the format to include the prefix for consistency with Ethereum address conventions.

Let's verify how these addresses are used in the codebase:

"SAPPHIRE": [20, "0x7cd99ce1dc8ab26473d35ddee6fa2389a2e22f0435686155c2f2bf62a9b0e2"],
"ETHEREALSILICA": [21, "0x3b03aea5ed81397478d50b2b67401f38557d2e6e14eb3b1caebab21d8459daf"],
"DRAGONHIDE": [22, "0x420f281f9c469e5315024702724dfb1f6bd53bfe4f0eacff9233f916d57663c"],
"ANCIENTFRAGMENT": [24, "0xa2f3f8da01fc3c71aa698f19f774d4a2af7702d73bfde7c4c93ae787e6f359"],
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Missing DEMONHIDE (ID 23) entry in local.json

Resource ID 23 corresponds to DEMONHIDE and is actively used in the game (referenced in constants.cairo and resources.ts). Add the missing entry to local.json to maintain consistency with the rest of the codebase.

🔗 Analysis chain

Verify the gap in resource ID sequence.

Resource ID 23 is missing in the sequence (jumps from 22 to 24). If this is intentional, consider adding a comment explaining why. If not, verify if a resource is missing.

Let's check the codebase for any references to resource ID 23:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for references to resource ID 23
rg -A 3 -B 3 "resource.*23|23.*resource"

Length of output: 1687

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