Implement upgrader machine

This commit is contained in:
thepaperpilot 2023-05-10 00:57:49 -05:00
parent ae53b56e8b
commit fb44fc8349
4 changed files with 108 additions and 11 deletions

View file

@ -50,6 +50,12 @@ export interface BoosterState {
level: DecimalSource;
}
export interface UpgraderState {
portals: string[];
maxConnections: number;
powered: boolean;
}
export const mineLootTable = {
dirt: 120,
sand: 60,

View file

@ -40,6 +40,7 @@ import {
QuarryState,
ResourceState,
Resources,
UpgraderState,
increaseBoostFormula,
influences,
passives,
@ -526,7 +527,13 @@ export const portal = {
classes: node => ({
running: isPowered(node),
showNotif: (layers[(node.state as unknown as PortalState).id] as GenericPlane).showNotif
.value
.value,
"affected-node":
main.booster.value != null &&
isPowered(main.booster.value) &&
(main.booster.value.state as unknown as BoosterState).portals.includes(
(node.state as unknown as PortalState).id
)
}),
outlineColor: node =>
(layers[(node.state as unknown as PortalState).id] as GenericPlane).background,
@ -611,8 +618,10 @@ export const booster = {
? "Booster - Drag a portal to me!"
: `Boosting by ${formatWhole(
Decimal.add(1, (node.state as unknown as BoosterState).level)
)}x (${(node.state as { tools: Passives[] }).tools.length}/${Decimal.add(
(node.state as { maxConnections: number }).maxConnections,
)}x (${
(node.state as unknown as BoosterState).portals.length
}/${Decimal.add(
(node.state as unknown as BoosterState).maxConnections,
main.computedBonusConnectionsModifier.value
)})`
};
@ -679,3 +688,52 @@ export const booster = {
}),
draggable: true
} as NodeTypeOptions;
export const upgrader = {
shape: Shape.Diamond,
size: 50,
title: "🤖",
label: node => {
if (node === main.board.selectedNode.value) {
return {
text:
(node.state as unknown as UpgraderState).portals.length === 0
? "Upgrader - Drag a portal to me!"
: `Auto-Upgrading (${
(node.state as unknown as UpgraderState).portals.length
}/${Decimal.add(
(node.state as unknown as UpgraderState).maxConnections,
main.computedBonusConnectionsModifier.value
)})`
};
}
return labelForAcceptingPortal(node, portal => {
return `Auto-buy ${(layers[portal] as GenericPlane).name}'s upgrades`;
});
},
actionDistance: Math.PI / 4,
actions: [
{
id: "deselect",
icon: "close",
tooltip: {
text: "Disconnect portals"
},
onClick(node: BoardNode) {
node.state = { ...(node.state as object), portals: [] };
main.board.selectedAction.value = null;
main.board.selectedNode.value = null;
},
visibility: (node: BoardNode) =>
(node.state as unknown as UpgraderState)?.portals.length ?? 0 > 0
},
getIncreaseConnectionsAction(x => x.add(4).pow_base(1e6)),
togglePoweredAction
],
canAccept: canAcceptPortal,
onDrop: onDropPortal,
classes: node => ({
running: isPowered(node)
}),
draggable: true
} as NodeTypeOptions;

View file

@ -12,14 +12,19 @@ import { createReset } from "features/reset";
import { Resource, createResource, displayResource } from "features/resources/resource";
import TooltipVue from "features/tooltips/Tooltip.vue";
import { addTooltip } from "features/tooltips/tooltip";
import { GenericUpgrade, UpgradeType, createUpgrade } from "features/upgrades/upgrade";
import {
GenericUpgrade,
UpgradeType,
createUpgrade,
setupAutoPurchase
} from "features/upgrades/upgrade";
import Formula, {
calculateCost,
calculateMaxAffordable,
unrefFormulaSource
} from "game/formulas/formulas";
import { FormulaSource, GenericFormula, InvertibleIntegralFormula } from "game/formulas/types";
import { BaseLayer, createLayer } from "game/layers";
import { BaseLayer, GenericLayer, createLayer } from "game/layers";
import {
Modifier,
createAdditiveModifier,
@ -29,13 +34,13 @@ import {
} from "game/modifiers";
import { State, noPersist, persistent } from "game/persistence";
import { createCostRequirement } from "game/requirements";
import Decimal, { DecimalSource } from "util/bignum";
import { format, formatWhole } from "util/break_eternity";
import Decimal, { format, formatWhole, DecimalSource } from "util/bignum";
import { Direction, WithRequired, camelToTitle } from "util/common";
import { Computable, ProcessedComputable, convertComputable } from "util/computed";
import { VueFeature, render, renderCol, renderRow, trackHover } from "util/vue";
import { ComputedRef, Ref, computed, ref, unref } from "vue";
import { useToast } from "vue-toastification";
import { isPowered } from "./boardUtils";
import { createCollapsibleModifierSections, createFormulaPreview, estimateTime } from "./common";
import {
BoosterState,
@ -1065,6 +1070,12 @@ export function createPlane(
});
});
setupAutoPurchase(
this as GenericLayer,
() => main.upgrader.value != null && isPowered(main.upgrader.value),
upgrades
);
const resourceChange = computed(() => {
const preview = previews.find(p => p.shouldShowPreview.value);
if (preview) {

View file

@ -49,6 +49,7 @@ import {
QuarryState,
ResourceState,
Resources,
UpgraderState,
mineLootTable,
resourceNames,
tools
@ -66,7 +67,8 @@ import {
portal,
portalGenerator,
quarry,
resource
resource,
upgrader
} from "./nodeTypes";
import { GenericPlane, createPlane } from "./planes";
@ -84,7 +86,8 @@ const types = {
portalGenerator,
portal,
influence,
booster
booster,
upgrader
};
/**
@ -109,7 +112,8 @@ export const main = createLayer("main", function (this: BaseLayer) {
wood: board.types.quarry.nodes.value[0],
coal: board.types.empowerer.nodes.value[0],
iron: board.types.portalGenerator.nodes.value[0],
gold: board.types.booster.nodes.value[0]
gold: board.types.booster.nodes.value[0],
platinum: board.types.upgrader.nodes.value[0]
}));
const influenceNodes: ComputedRef<Record<Influences, BoardNode>> = computed(() => ({
@ -343,6 +347,20 @@ export const main = createLayer("main", function (this: BaseLayer) {
});
});
}
if (upgrader.value != null) {
(upgrader.value.state as unknown as UpgraderState).portals.forEach(portal => {
links.push({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
startNode: upgrader.value!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
endNode: (board as GenericBoard).types.portal.nodes.value.find(
node => (node.state as unknown as PortalState).id === portal
)!,
stroke: "var(--foreground)",
strokeWidth: 4
});
});
}
Object.values(influenceNodes.value).forEach(node => {
const state = node.state as unknown as InfluenceState;
if (state.type === "increaseResources" || state.type === "decreaseResources") {
@ -371,7 +389,8 @@ export const main = createLayer("main", function (this: BaseLayer) {
() => toolNodes.value.iron
);
const booster: ComputedRef<BoardNode | undefined> = computed(() => toolNodes.value.gold);
const poweredMachines = [mine, dowsing, quarry, empowerer, booster];
const upgrader: ComputedRef<BoardNode | undefined> = computed(() => toolNodes.value.platinum);
const poweredMachines = [mine, dowsing, quarry, empowerer, booster, upgrader];
function grantResource(type: Resources, amount: DecimalSource) {
let node = resourceNodes.value[type];
@ -780,6 +799,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
checkConnections(curr, quarry, "resources");
checkConnections(curr, empowerer, "tools");
checkConnections(curr, booster, "portals");
checkConnections(curr, upgrader, "portals");
}
});
@ -800,6 +820,8 @@ export const main = createLayer("main", function (this: BaseLayer) {
dropRates,
dowsing,
empowerer,
booster,
upgrader,
resourceLevels,
planarMultis,
display: jsx(() => (