Skip to content

Commit

Permalink
added production
Browse files Browse the repository at this point in the history
  • Loading branch information
aymericdelab committed Dec 12, 2024
1 parent f8a07bd commit 1530c8f
Showing 1 changed file with 103 additions and 80 deletions.
183 changes: 103 additions & 80 deletions client/src/dojo/modelManager/ConfigManager.ts
Original file line number Diff line number Diff line change
@@ -59,32 +59,42 @@ export class ClientConfigManager {
}

private initializeResourceInputs() {
if (!this.components) return;

for (const resourceType of Object.values(ResourcesIds).filter(Number.isInteger)) {
const productionConfig = getComponentValue(
this.components.ProductionConfig,
getEntityIdFromKeys([BigInt(resourceType)]),
);

const inputCount = productionConfig?.input_count ?? 0;
const inputs: { resource: ResourcesIds; amount: number }[] = [];

for (let index = 0; index < inputCount; index++) {
const productionInput = getComponentValue(
this.components.ProductionInput,
getEntityIdFromKeys([BigInt(resourceType), BigInt(index)]),
);

if (productionInput) {
const resource = productionInput.input_resource_type;
const amount = divideByPrecision(Number(productionInput.input_resource_amount));
inputs.push({ resource, amount });
}
}

this.resourceInputs[Number(resourceType)] = inputs;
}
// if (!this.components) return;

// for (const resourceType of Object.values(ResourcesIds).filter(Number.isInteger)) {
// const productionConfig = getComponentValue(
// this.components.ProductionConfig,
// getEntityIdFromKeys([BigInt(resourceType)]),
// );

// const inputCount = productionConfig?.input_count ?? 0;
// const inputs: { resource: ResourcesIds; amount: number }[] = [];

// for (let index = 0; index < inputCount; index++) {
// const productionInput = getComponentValue(
// this.components.ProductionInput,
// getEntityIdFromKeys([BigInt(resourceType), BigInt(index)]),
// );

// if (productionInput) {
// const resource = productionInput.input_resource_type;
// const amount = divideByPrecision(Number(productionInput.input_resource_amount));
// inputs.push({ resource, amount });
// }
// }

// this.resourceInputs[Number(resourceType)] = inputs;
// }
this.resourceInputs = Object.entries(EternumGlobalConfig.resources.resourceInputs).reduce(
(acc, [key, inputs]) => {
acc[Number(key)] = inputs.map((input: { resource: number; amount: number }) => ({
resource: input.resource,
amount: input.amount * 1000,
}));
return acc;
},
{} as typeof EternumGlobalConfig.resources.resourceInputs,
);
}

private initializeResourceOutput() {
@@ -155,63 +165,76 @@ export class ClientConfigManager {
}

private initializeResourceBuildingCosts() {
for (const resourceId of Object.values(ResourcesIds).filter(Number.isInteger)) {
const buildingConfig = getComponentValue(
this.components.BuildingConfig,
getEntityIdFromKeys([WORLD_CONFIG_ID, BigInt(BuildingType.Resource), BigInt(resourceId)]),
);

const resourceCostCount = buildingConfig?.resource_cost_count || 0;
const resourceCostId = buildingConfig?.resource_cost_id || 0;

const resourceCosts: { resource: ResourcesIds; amount: number }[] = [];
for (let index = 0; index < resourceCostCount; index++) {
const resourceCost = getComponentValue(
this.components.ResourceCost,
getEntityIdFromKeys([BigInt(resourceCostId), BigInt(index)]),
);
if (!resourceCost) {
continue;
}

const resourceType = resourceCost.resource_type;
const amount = Number(resourceCost.amount) / EternumGlobalConfig.resources.resourcePrecision;

resourceCosts.push({ resource: resourceType, amount });
}
this.resourceBuildingCosts[Number(resourceId)] = resourceCosts;
}
// for (const resourceId of Object.values(ResourcesIds).filter(Number.isInteger)) {
// const buildingConfig = getComponentValue(
// this.components.BuildingConfig,
// getEntityIdFromKeys([WORLD_CONFIG_ID, BigInt(BuildingType.Resource), BigInt(resourceId)]),
// );

// const resourceCostCount = buildingConfig?.resource_cost_count || 0;
// const resourceCostId = buildingConfig?.resource_cost_id || 0;

// const resourceCosts: { resource: ResourcesIds; amount: number }[] = [];
// for (let index = 0; index < resourceCostCount; index++) {
// const resourceCost = getComponentValue(
// this.components.ResourceCost,
// getEntityIdFromKeys([BigInt(resourceCostId), BigInt(index)]),
// );
// if (!resourceCost) {
// continue;
// }

// const resourceType = resourceCost.resource_type;
// const amount = Number(resourceCost.amount) / EternumGlobalConfig.resources.resourcePrecision;

// resourceCosts.push({ resource: resourceType, amount });
// }
// this.resourceBuildingCosts[Number(resourceId)] = resourceCosts;

// }
this.resourceBuildingCosts = Object.fromEntries(
Object.entries(EternumGlobalConfig.resources.resourceBuildingCosts).map(([key, costs]) => [
key,
costs.map((cost: any) => ({ ...cost, amount: cost.amount * this.getResourceMultiplier() })),
]),
);
}

private initializeBuildingCosts() {
for (const buildingType of Object.values(BuildingType).filter(Number.isInteger)) {
const resourceType = this.getResourceBuildingProduced(Number(buildingType));

const buildingConfig = getComponentValue(
this.components.BuildingConfig,
getEntityIdFromKeys([WORLD_CONFIG_ID, BigInt(buildingType), BigInt(resourceType)]),
);

const resourceCostCount = buildingConfig?.resource_cost_count || 0;
const resourceCostId = buildingConfig?.resource_cost_id || 0;

const resourceCosts: { resource: ResourcesIds; amount: number }[] = [];
for (let index = 0; index < resourceCostCount; index++) {
const resourceCost = getComponentValue(
this.components.ResourceCost,
getEntityIdFromKeys([BigInt(resourceCostId), BigInt(index)]),
);
if (!resourceCost) {
continue;
}

const resourceType = resourceCost.resource_type;
const amount = Number(resourceCost.amount) / this.getResourcePrecision();

resourceCosts.push({ resource: resourceType, amount });
}
this.buildingCosts[Number(buildingType)] = resourceCosts;
}
// for (const buildingType of Object.values(BuildingType).filter(Number.isInteger)) {
// const resourceType = this.getResourceBuildingProduced(Number(buildingType));

// const buildingConfig = getComponentValue(
// this.components.BuildingConfig,
// getEntityIdFromKeys([WORLD_CONFIG_ID, BigInt(buildingType), BigInt(resourceType)]),
// );

// const resourceCostCount = buildingConfig?.resource_cost_count || 0;
// const resourceCostId = buildingConfig?.resource_cost_id || 0;

// const resourceCosts: { resource: ResourcesIds; amount: number }[] = [];
// for (let index = 0; index < resourceCostCount; index++) {
// const resourceCost = getComponentValue(
// this.components.ResourceCost,
// getEntityIdFromKeys([BigInt(resourceCostId), BigInt(index)]),
// );
// if (!resourceCost) {
// continue;
// }

// const resourceType = resourceCost.resource_type;
// const amount = Number(resourceCost.amount) / this.getResourcePrecision();

// resourceCosts.push({ resource: resourceType, amount });
// }
// this.buildingCosts[Number(buildingType)] = resourceCosts;
// }
this.buildingCosts = Object.fromEntries(
Object.entries(EternumGlobalConfig.buildings.buildingCosts).map(([key, costs]) => [
key,
costs.map((cost: any) => ({ ...cost, amount: cost.amount * this.getResourceMultiplier() })),
]),
);
}

private initializeStructureCosts() {

0 comments on commit 1530c8f

Please sign in to comment.