Skip to content

Commit

Permalink
client config: realm leveling
Browse files Browse the repository at this point in the history
  • Loading branch information
credence0x committed Sep 27, 2024
1 parent 5fff80f commit 50bff2b
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 0 deletions.
5 changes: 5 additions & 0 deletions client/src/dojo/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export function createSystemCalls({ provider }: SetupNetworkResult) {
await provider.create_realm(props);
};

const upgrade_realm = async (props: SystemProps.UpgradeRealmProps) => {
await provider.upgrade_realm(props);
};

const create_multiple_realms = async (props: SystemProps.CreateMultipleRealmsProps) => {
await provider.create_multiple_realms(props);
};
Expand Down Expand Up @@ -321,6 +325,7 @@ export function createSystemCalls({ provider }: SetupNetworkResult) {
cancel_order: withQueueing(withErrorHandling(cancel_order)),
accept_partial_order: withQueueing(withErrorHandling(accept_partial_order)),
create_realm: withQueueing(withErrorHandling(create_realm)),
upgrade_realm: withQueueing(withErrorHandling(upgrade_realm)),
create_multiple_realms: withQueueing(withErrorHandling(create_multiple_realms)),
transfer_resources: withQueueing(withErrorHandling(transfer_resources)),
travel: withQueueing(withErrorHandling(travel)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export const generateMockArmyInfo = (
regions: 1,
wonder: 1,
order: 1,
level: 1,
},
homePosition: { entity_id: ARMY_ENTITY_ID, x: 0, y: 0 },
};
Expand Down
2 changes: 2 additions & 0 deletions config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
setMercenariesConfig,
setPopulationConfig,
setProductionConfig,
setRealmLevelConfig,
setResourceBuildingConfig,
setSpeedConfig,
setStaminaConfig,
Expand Down Expand Up @@ -56,6 +57,7 @@ console.log("Account set up");
await setBuildingCategoryPopConfig(account, provider);
await setPopulationConfig(account, provider);
await setBuildingConfig(account, provider);
await setRealmLevelConfig(account, provider);
await setResourceBuildingConfig(account, provider);
await setWeightConfig(account, provider);
await setCombatConfig(account, provider);
Expand Down
24 changes: 24 additions & 0 deletions sdk/packages/eternum/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { TickIds, TravelTypes } from "../types";
import {
BUILDING_COSTS_SCALED,
HYPERSTRUCTURE_TOTAL_COSTS_SCALED,
REALM_LEVEL_COSTS_SCALED,
RESOURCE_BUILDING_COSTS_SCALED,
RESOURCE_INPUTS_SCALED,
RESOURCE_OUTPUTS_SCALED,
Expand Down Expand Up @@ -106,6 +107,29 @@ export const setBuildingConfig = async (account: Account, provider: EternumProvi
console.log(`Configuring building cost config ${tx.statusReceipt}...`);
};

export const setRealmLevelConfig = async (account: Account, provider: EternumProvider) => {
const calldataArray = [];

for (const level of Object.keys(REALM_LEVEL_COSTS_SCALED) as unknown as number[]) {
if (REALM_LEVEL_COSTS_SCALED[level].length !== 0) {
const calldata = {
level,
cost_of_level: REALM_LEVEL_COSTS_SCALED[level].map((cost) => {
return {
...cost,
amount: cost.amount * EternumGlobalConfig.resources.resourcePrecision,
};
}),
};

calldataArray.push(calldata);
}
}

const tx = await provider.set_realm_level_config({ signer: account, calls: calldataArray });
console.log(`Configuring realm level cost config ${tx.statusReceipt}...`);
};

export const setResourceBuildingConfig = async (account: Account, provider: EternumProvider) => {
const calldataArray = [];

Expand Down
15 changes: 15 additions & 0 deletions sdk/packages/eternum/src/constants/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,21 @@ export const RESOURCE_INPUTS: ResourceInputs = {
[ResourcesIds.Earthenshard]: [],
};

export const REALM_LEVEL_COSTS: ResourceInputs = {
[1]: [
{ resource: ResourcesIds.Wheat, amount: 500 },
{ resource: ResourcesIds.Fish, amount: 500 },
],
[2]: [
{ resource: ResourcesIds.Wheat, amount: 1000 },
{ resource: ResourcesIds.Fish, amount: 1000 },
],
[3]: [
{ resource: ResourcesIds.Wheat, amount: 2000 },
{ resource: ResourcesIds.Fish, amount: 2000 },
],
};

export const BUILDING_COSTS: ResourceInputs = {
[BuildingType.Castle]: [],
[BuildingType.Bank]: [],
Expand Down
29 changes: 29 additions & 0 deletions sdk/packages/eternum/src/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ export class EternumProvider extends EnhancedDojoProvider {
return await this.waitForTransactionWithCheck(tx.transaction_hash);
}

public async upgrade_realm(props: SystemProps.UpgradeRealmProps) {
const { realm_entity_id, signer } = props;

return await this.executeAndCheckTransaction(signer, {
contractAddress: getContractByName(this.manifest, `${NAMESPACE}-realm_systems`),
entrypoint: "upgrade_level",
calldata: [realm_entity_id],
});
}

create_multiple_realms = async (props: SystemProps.CreateMultipleRealmsProps) => {
let { realms, signer } = props;

Expand Down Expand Up @@ -888,6 +898,25 @@ export class EternumProvider extends EnhancedDojoProvider {
});
}

public async set_realm_level_config(props: SystemProps.SetRealmLevelConfigProps) {
const { calls, signer } = props;

return await this.executeAndCheckTransaction(
signer,
calls.map((call) => {
return {
contractAddress: getContractByName(this.manifest, `${NAMESPACE}-config_systems`),
entrypoint: "set_realm_level_config",
calldata: [
call.level,
call.cost_of_level.length,
...call.cost_of_level.flatMap(({ resource, amount }) => [resource, amount]),
],
};
}),
);
}

public async set_building_config(props: SystemProps.SetBuildingConfigProps) {
const { calls, signer } = props;

Expand Down
10 changes: 10 additions & 0 deletions sdk/packages/eternum/src/types/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ export interface CreateMultipleRealmsProps extends SystemSigner {
}

export interface CreateRealmProps extends Realm, SystemSigner {}
export interface UpgradeRealmProps extends SystemSigner {
realm_entity_id: num.BigNumberish;
}

export interface TransferItemsProps extends SystemSigner {
sender_id: num.BigNumberish;
Expand Down Expand Up @@ -456,6 +459,13 @@ export interface SetBuildingConfigProps extends SystemSigner {
}[];
}

export interface SetRealmLevelConfigProps extends SystemSigner {
calls: {
level: num.BigNumberish;
cost_of_level: ResourceCosts[];
}[];
}

export interface SetWorldConfigProps extends SystemSigner {
admin_address: num.BigNumberish;
realm_l2_contract: num.BigNumberish;
Expand Down
6 changes: 6 additions & 0 deletions sdk/packages/eternum/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
HYPERSTRUCTURE_CREATION_COSTS,
HYPERSTRUCTURE_TOTAL_COSTS,
QUEST_RESOURCES,
REALM_LEVEL_COSTS,
RESOURCE_BUILDING_COSTS,
RESOURCE_INPUTS,
RESOURCE_OUTPUTS,
Expand Down Expand Up @@ -104,6 +105,11 @@ export const BUILDING_COSTS_SCALED: ResourceInputs = scaleResourceInputs(
EternumGlobalConfig.resources.resourceMultiplier,
);

export const REALM_LEVEL_COSTS_SCALED: ResourceInputs = scaleResourceInputs(
REALM_LEVEL_COSTS,
EternumGlobalConfig.resources.resourceMultiplier,
);

export const RESOURCE_INPUTS_SCALED: ResourceInputs = scaleResourceInputs(
RESOURCE_INPUTS,
EternumGlobalConfig.resources.resourceMultiplier,
Expand Down

0 comments on commit 50bff2b

Please sign in to comment.