Skip to content

Commit

Permalink
Added better intent effect calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterbrandsen authored Mar 18, 2024
1 parent 65f5cea commit 042d901
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/data/converter/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,37 +100,47 @@ export function summarizeObjects(objects) {
export function getIntentEffect(action, originalObject) {
try {
switch (action) {
case "harvest":
case "harvest": {
const usableParts = Math.max(Math.floor(originalObject.store.energy / 2), originalObject.groupedBody.work);
return {
action,
energy: originalObject.groupedBody.work * 2,
effect: originalObject.groupedBodyEffect.harvest
energy: usableParts * 2,
effect: (originalObject.groupedBodyEffect.harvest / originalObject.groupedBody.work) * usableParts
};
case "build":
}
case "build": {
const usableParts = Math.max(Math.floor(originalObject.store.energy / 5), originalObject.groupedBody.work);
return {
action,
energy: originalObject.groupedBody.work * 5,
effect: originalObject.groupedBodyEffect.build
energy: usableParts * 5,
effect: (originalObject.groupedBodyEffect.build / originalObject.groupedBody.work) * usableParts
};
case "repair":
}
case "repair": {
if (originalObject.type === "tower") return { action, energy: 10 };
const usableParts = Math.max(originalObject.store.energy, originalObject.groupedBody.work);
return {
action,
energy: originalObject.groupedBody.work * 1,
effect: originalObject.groupedBodyEffect.repair
energy: usableParts * 1,
effect: (originalObject.groupedBodyEffect.repair / originalObject.groupedBody.work) * usableParts
};
case "upgradeController":
}
case "upgradeController": {
const usableParts = Math.max(originalObject.store.energy, originalObject.groupedBody.work);
return {
action,
energy: originalObject.groupedBody.work * 1,
effect: originalObject.groupedBodyEffect.upgradeController
energy: usableParts * 1,
effect: (originalObject.groupedBodyEffect.upgradeController / originalObject.groupedBody.work) * usableParts
};
case "dismantle":
}
case "dismantle": {
const usableParts = originalObject.groupedBody.work;
return {
action,
energy: originalObject.groupedBody.work * 0.25,
effect: originalObject.groupedBodyEffect.dismantle
effect: (originalObject.groupedBodyEffect.dismantle / originalObject.groupedBody.work) * usableParts
};
}
case "attack":
if (originalObject.type === "tower")
return { action, energy: 10, damage: 300 };
Expand Down
9 changes: 9 additions & 0 deletions src/data/converter/prepare/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ export default async function prepareObject(object, originalObject) {
object.groupedBody = originalObject.groupedBody || {}
object.groupedBodyEffect = originalObject.groupedBodyEffect || {}

if (!object.store) object.store = {}
if (!originalObject.store) originalObject.store = {}
const changedStore = Object.entries(object.store);
for (let i = 0; i < changedStore.length; i += 1) {
const [resourceType, amount] = changedStore[i];
originalObject.store[resourceType] = amount;
}
if (!originalObject.store.energy) originalObject.store.energy = 0;

object.type = originalObject.type;
switch (object.type) {
case 'controller':
Expand Down

0 comments on commit 042d901

Please sign in to comment.