-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: main
Are you sure you want to change the base?
Changes from all commits
73dd618
b8ccd2a
b9e4732
210f327
53a26e7
5fff80f
50bff2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ mod tests { | |
regions: 0, | ||
wonder: 0, | ||
order: 0, | ||
level: 0 | ||
} | ||
); | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -33,26 +33,37 @@ mod building_systems { | |||||||
building_category: BuildingCategory, | ||||||||
produce_resource_type: Option<u8>, | ||||||||
) { | ||||||||
assert!(directions.len() <= 4, "cannot build on selected tile"); | ||||||||
let mut building_coord: Coord = BuildingCustomImpl::center(); | ||||||||
loop { | ||||||||
match directions.pop_front() { | ||||||||
Option::Some(direction) => { building_coord = building_coord.neighbor(*direction); }, | ||||||||
Option::None => { break; } | ||||||||
} | ||||||||
}; | ||||||||
|
||||||||
// ensure only realms can make buildings | ||||||||
let realm: Realm = get!(world, entity_id, Realm); | ||||||||
assert!(realm.realm_id != 0, "entity is not a realm"); | ||||||||
|
||||||||
// ensure caller owns the realm | ||||||||
get!(world, entity_id, EntityOwner).assert_caller_owner(world); | ||||||||
|
||||||||
// ensure buildings can't be made outside | ||||||||
// the range of what the realm level allows | ||||||||
let directions_count = directions.len(); | ||||||||
assert!(directions_count > 0, "building cant be made at the center"); | ||||||||
assert!(directions_count <= realm.max_level().into() + 1, "building outside of max bound"); | ||||||||
assert!(directions_count <= realm.level.into() + 1, "building outside of what realm level allows"); | ||||||||
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. 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.
Suggested change
|
||||||||
|
||||||||
// ensure that the realm produces the resource | ||||||||
if produce_resource_type.is_some() { | ||||||||
let resource_type: u8 = produce_resource_type.unwrap(); | ||||||||
let realm_produces_resource = realm.has_resource(resource_type); | ||||||||
assert!(realm_produces_resource, "realm does not produce specified resource"); | ||||||||
} | ||||||||
|
||||||||
get!(world, entity_id, EntityOwner).assert_caller_owner(world); | ||||||||
// get the location of the building | ||||||||
let mut building_coord: Coord = BuildingCustomImpl::center(); | ||||||||
loop { | ||||||||
match directions.pop_front() { | ||||||||
Option::Some(direction) => { building_coord = building_coord.neighbor(*direction); }, | ||||||||
Option::None => { break; } | ||||||||
} | ||||||||
}; | ||||||||
|
||||||||
// todo: check that entity is a realm | ||||||||
// create the building | ||||||||
let building: Building = BuildingCustomImpl::create( | ||||||||
world, entity_id, building_category, produce_resource_type, building_coord | ||||||||
); | ||||||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -16,6 +16,7 @@ trait IRealmSystems { | |||
order: u8, | ||||
position: eternum::models::position::Position | ||||
) -> ID; | ||||
fn upgrade_level(ref world: IWorldDispatcher, realm_id: ID); | ||||
fn mint_starting_resources(ref world: IWorldDispatcher, config_id: ID, entity_id: ID) -> ID; | ||||
} | ||||
|
||||
|
@@ -30,17 +31,17 @@ 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}; | ||||
use eternum::models::config::{CapacityConfigCategory, RealmLevelConfig}; | ||||
use eternum::models::config::{RealmFreeMintConfig, HasClaimedStartingResources}; | ||||
use eternum::models::event::{SettleRealmData, EventType}; | ||||
use eternum::models::map::Tile; | ||||
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; | ||||
|
@@ -142,6 +143,7 @@ mod realm_systems { | |||
regions, | ||||
wonder, | ||||
order, | ||||
level: 0 | ||||
}, | ||||
Position { entity_id: entity_id.into(), x: position.x, y: position.y, }, | ||||
EntityMetadata { entity_id: entity_id.into(), entity_type: REALM_ENTITY_TYPE, } | ||||
|
@@ -178,5 +180,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(), '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)); | ||||
} | ||||
} | ||||
} |
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.
Consider making the max_level configurable rather than hardcoded. This would allow for easier adjustments in the future if needed.