-
Notifications
You must be signed in to change notification settings - Fork 37
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
contracts: feature: introduce realm levels #1721
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
73dd618
contracts: realm leveling
credence0x b8ccd2a
contracts: realm leveling
credence0x b9e4732
contracts: realm leveling
credence0x 210f327
contracts: realm leveling
credence0x 53a26e7
contracts: realm leveling tests
credence0x 5fff80f
contracts: realm leveling update
credence0x 50bff2b
client config: realm leveling
credence0x 4fb9af1
Merge branch 'rc' of https://github.com/BibliothecaDAO/eternum into r…
credence0x eb6d4e5
Merge branch 'rc' of https://github.com/BibliothecaDAO/eternum into r…
credence0x 101c1fc
add actual realm level
ponderingdemocritus 0033cb7
add signer
ponderingdemocritus 1ced5a1
formatting
credence0x b8807ec
Merge branch 'realm-level' of https://github.com/BibliothecaDAO/etern…
credence0x b5cf5c9
formatting
credence0x cd2f2ae
formatting
credence0x 446c996
merge bug fix
credence0x b0e10ac
fix conflict
credence0x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ mod tests { | |
regions: 0, | ||
wonder: 0, | ||
order: 0, | ||
level: 0 | ||
} | ||
); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -15,6 +15,7 @@ trait IRealmSystems { | |||
wonder: u8, | ||||
order: u8, | ||||
) -> ID; | ||||
fn upgrade_level(ref world: IWorldDispatcher, realm_id: ID); | ||||
fn mint_starting_resources(ref world: IWorldDispatcher, config_id: ID, entity_id: ID) -> ID; | ||||
} | ||||
|
||||
|
@@ -29,7 +30,7 @@ mod realm_systems { | |||
use eternum::constants::REALM_ENTITY_TYPE; | ||||
use eternum::constants::{WORLD_CONFIG_ID, REALM_FREE_MINT_CONFIG_ID, MAX_REALMS_PER_ADDRESS}; | ||||
use eternum::models::capacity::{CapacityCategory}; | ||||
use eternum::models::config::{CapacityConfigCategory, SettlementConfig, SettlementConfigImpl}; | ||||
use eternum::models::config::{CapacityConfigCategory, RealmLevelConfig, SettlementConfig, SettlementConfigImpl}; | ||||
use eternum::models::config::{RealmFreeMintConfig, HasClaimedStartingResources}; | ||||
use eternum::models::event::{SettleRealmData, EventType}; | ||||
|
||||
|
@@ -38,10 +39,10 @@ mod realm_systems { | |||
use eternum::models::metadata::EntityMetadata; | ||||
use eternum::models::movable::Movable; | ||||
use eternum::models::name::{AddressName}; | ||||
use eternum::models::owner::{Owner, EntityOwner}; | ||||
use eternum::models::owner::{Owner, EntityOwner, EntityOwnerCustomTrait}; | ||||
use eternum::models::position::{Position, Coord}; | ||||
use eternum::models::quantity::QuantityTracker; | ||||
use eternum::models::realm::{Realm, RealmCustomTrait}; | ||||
use eternum::models::realm::{Realm, RealmCustomTrait, RealmCustomImpl}; | ||||
use eternum::models::resources::{DetachedResource, Resource, ResourceCustomImpl, ResourceCustomTrait}; | ||||
use eternum::models::structure::{Structure, StructureCategory, StructureCount, StructureCountCustomTrait}; | ||||
use eternum::systems::map::contracts::map_systems::InternalMapSystemsImpl; | ||||
|
@@ -153,6 +154,7 @@ mod realm_systems { | |||
regions, | ||||
wonder, | ||||
order, | ||||
level: 0 | ||||
}, | ||||
Position { entity_id: entity_id.into(), x: coord.x, y: coord.y, }, | ||||
EntityMetadata { entity_id: entity_id.into(), entity_type: REALM_ENTITY_TYPE, } | ||||
|
@@ -191,5 +193,42 @@ mod realm_systems { | |||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider emitting an event when a realm is upgraded. This would be useful for tracking realm progress and could be used by the frontend or other systems.
Suggested change
|
||||
entity_id.into() | ||||
} | ||||
|
||||
|
||||
fn upgrade_level(ref world: IWorldDispatcher, realm_id: ID) { | ||||
// ensure caller owns the realm | ||||
get!(world, realm_id, EntityOwner).assert_caller_owner(world); | ||||
|
||||
// ensure entity is a realm | ||||
let mut realm = get!(world, realm_id, Realm); | ||||
realm.assert_is_set(); | ||||
|
||||
// ensure realm is not already at max level | ||||
assert(realm.level < realm.max_level(world), 'realm is already at max level'); | ||||
|
||||
// make payment to upgrade to next level | ||||
let next_level = realm.level + 1; | ||||
let realm_level_config = get!(world, next_level, RealmLevelConfig); | ||||
let required_resources_id = realm_level_config.required_resources_id; | ||||
let required_resource_count = realm_level_config.required_resource_count; | ||||
let mut index = 0; | ||||
loop { | ||||
if index == required_resource_count { | ||||
break; | ||||
} | ||||
|
||||
let mut required_resource = get!(world, (required_resources_id, index), DetachedResource); | ||||
|
||||
// burn resource from realm | ||||
let mut realm_resource = ResourceCustomImpl::get(world, (realm_id, required_resource.resource_type)); | ||||
realm_resource.burn(required_resource.resource_amount); | ||||
realm_resource.save(world); | ||||
index += 1; | ||||
}; | ||||
|
||||
// set new level | ||||
realm.level = next_level; | ||||
set!(world, (realm)); | ||||
} | ||||
} | ||||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message 'building outside of what realm level allows' could be more informative. Consider including the current realm level and the required level in the message.