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

update labor #2667

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions contracts/game/manifest_sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@
},
{
"address": "0x5827e314ca954f7eb04127a2a321e5c1f8fa6d51546b8fa6d6b38830f2b6d18",
"class_hash": "0x7fb2e9574aa693d81a15f3734dd0a8612ba8d64057b2aef692bd3117118a446",
"class_hash": "0x37798122f6085a277eedb203c93fe5ee2fbc99afe7427e4508b79000301dc2c",
"abi": [
{
"type": "impl",
Expand Down Expand Up @@ -2995,10 +2995,6 @@
{
"name": "produced_amount",
"type": "core::integer::u128"
},
{
"name": "labor_amount",
"type": "core::integer::u128"
}
],
"outputs": [],
Expand Down Expand Up @@ -5405,7 +5401,7 @@
},
{
"address": "0x43b2a3f4e47fa52ef2549162f89258dbcbd23bc62a51d0a331b80039a66bc9b",
"class_hash": "0x48a8ae3f6841aed95fb3186cf390db19854c8174fea69fdca19c88fd8c58c63",
"class_hash": "0x1829437a65fddf03e8f1322558035b38be8c06a5dd81f6a863a68569364b4cc",
"abi": [
{
"type": "impl",
Expand Down Expand Up @@ -6345,7 +6341,7 @@
},
{
"address": "0x47773b52867c0867b40b26408e3ff84fca0b1a9afe55c0cb0fe284c1a18c3d8",
"class_hash": "0x72be272c9af1769ad38beaf68495533628fdb4ead0a7879760d17b1f6bab196",
"class_hash": "0x580ae58de580e41af4107e2b651ba52fa4ebeb5266568c6658cfa95fdecf48b",
"abi": [
{
"type": "impl",
Expand Down
2 changes: 1 addition & 1 deletion contracts/game/src/models/config.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ pub struct ProductionConfig {
resource_type: u8,
// production amount per tick
produced_amount: u128,
// labor cost amount per tick
// todo: remove
labor_cost: u128,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dojo::world::WorldStorage;
use s1_eternum::alias::ID;
use s1_eternum::models::config::{ProductionConfig};
use s1_eternum::models::config::{TickConfig, TickImpl, TickTrait};
use s1_eternum::models::resource::resource::{Resource, ResourceImpl, ResourceTypes, ResourceFoodImpl};
use s1_eternum::models::resource::resource::{Resource, RESOURCE_PRECISION, ResourceImpl, ResourceTypes, ResourceFoodImpl};
use starknet::get_block_timestamp;

#[derive(IntrospectPacked, Copy, Drop, Serde)]
Expand Down Expand Up @@ -52,11 +52,9 @@ impl ProductionImpl of ProductionTrait {
fn spend_labor_resource(ref self: Production, production_config: @ProductionConfig, labor_amount: u128) {
assert!(labor_amount.is_non_zero(), "zero labor amount");
assert!(
labor_amount % (*production_config).labor_cost == 0, "labor amount not exactly divisible by labor cost"
labor_amount % RESOURCE_PRECISION == 0, "labor amount not exactly divisible by resource precision"
);

let additional_labor_units: u64 = (labor_amount / (*production_config).labor_cost).try_into().unwrap();
self.increase_labor_units(additional_labor_units);
self.increase_labor_units(labor_amount.try_into().unwrap());
}

#[inline(always)]
Expand Down
5 changes: 2 additions & 3 deletions contracts/game/src/systems/config/contracts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ trait IMapConfig<T> {

#[starknet::interface]
trait IProductionConfig<T> {
fn set_production_config(ref self: T, resource_type: u8, produced_amount: u128, labor_amount: u128);
fn set_production_config(ref self: T, resource_type: u8, produced_amount: u128);
}

#[starknet::interface]
Expand Down Expand Up @@ -601,14 +601,13 @@ mod config_systems {
#[abi(embed_v0)]
impl ProductionConfigImpl of super::IProductionConfig<ContractState> {
fn set_production_config(
ref self: ContractState, resource_type: u8, produced_amount: u128, labor_amount: u128
ref self: ContractState, resource_type: u8, produced_amount: u128
) {
let mut world: WorldStorage = self.world(DEFAULT_NS());
assert_caller_is_admin(world);

let mut resource_production_config: ProductionConfig = world.read_model(resource_type);
resource_production_config.produced_amount = produced_amount;
resource_production_config.labor_cost = labor_amount;
world.write_model(@resource_production_config);
}
}
Expand Down
6 changes: 1 addition & 5 deletions contracts/game/src/systems/map/map_generation.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ mod map_generation_systems {
}

fn get_shards_reward(ref world: WorldStorage, randomness: u256, mine_entity_id: ID) -> u128 {
let shards_production_config: ProductionConfig = world.read_model(ResourceTypes::EARTHEN_SHARD);
let random_multiplier: u128 = *random::choices(
array![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].span(),
array![1, 1, 1, 1, 1, 1, 1, 1, 1, 1].span(),
Expand All @@ -164,10 +163,7 @@ mod map_generation_systems {
)[0];
let min_production_amount: u128 = 100_000 * RESOURCE_PRECISION;
let actual_production_amount: u128 = min_production_amount * random_multiplier;
let mut labor_amount_required: u128 = actual_production_amount / shards_production_config.labor_cost;
if actual_production_amount % shards_production_config.labor_cost != 0 {
labor_amount_required += 1;
}
let mut labor_amount_required: u128 = actual_production_amount;

labor_amount_required
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/game/src/utils/testing/config.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn set_battle_config(config_systems_address: ContractAddress) {

fn set_mine_production_config(config_systems_address: ContractAddress) {
IProductionConfigDispatcher { contract_address: config_systems_address }
.set_production_config(ResourceTypes::EARTHEN_SHARD, EARTHEN_SHARD_PRODUCTION_AMOUNT_PER_TICK, array![].span());
.set_production_config(ResourceTypes::EARTHEN_SHARD, EARTHEN_SHARD_PRODUCTION_AMOUNT_PER_TICK);
}

fn set_stamina_config(config_systems_address: ContractAddress) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@ export class EternumProvider extends EnhancedDojoProvider {
return {
contractAddress: getContractByName(this.manifest, `${NAMESPACE}-config_systems`),
entrypoint: "set_production_config",
calldata: [call.resource_type, call.amount, call.amount],
calldata: [call.resource_type, call.amount],
};
});

Expand Down
Loading