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; level: DecimalSource;
} }
export interface UpgraderState {
portals: string[];
maxConnections: number;
powered: boolean;
}
export const mineLootTable = { export const mineLootTable = {
dirt: 120, dirt: 120,
sand: 60, sand: 60,

View file

@ -40,6 +40,7 @@ import {
QuarryState, QuarryState,
ResourceState, ResourceState,
Resources, Resources,
UpgraderState,
increaseBoostFormula, increaseBoostFormula,
influences, influences,
passives, passives,
@ -526,7 +527,13 @@ export const portal = {
classes: node => ({ classes: node => ({
running: isPowered(node), running: isPowered(node),
showNotif: (layers[(node.state as unknown as PortalState).id] as GenericPlane).showNotif 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 => outlineColor: node =>
(layers[(node.state as unknown as PortalState).id] as GenericPlane).background, (layers[(node.state as unknown as PortalState).id] as GenericPlane).background,
@ -611,8 +618,10 @@ export const booster = {
? "Booster - Drag a portal to me!" ? "Booster - Drag a portal to me!"
: `Boosting by ${formatWhole( : `Boosting by ${formatWhole(
Decimal.add(1, (node.state as unknown as BoosterState).level) Decimal.add(1, (node.state as unknown as BoosterState).level)
)}x (${(node.state as { tools: Passives[] }).tools.length}/${Decimal.add( )}x (${
(node.state as { maxConnections: number }).maxConnections, (node.state as unknown as BoosterState).portals.length
}/${Decimal.add(
(node.state as unknown as BoosterState).maxConnections,
main.computedBonusConnectionsModifier.value main.computedBonusConnectionsModifier.value
)})` )})`
}; };
@ -679,3 +688,52 @@ export const booster = {
}), }),
draggable: true draggable: true
} as NodeTypeOptions; } 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 { Resource, createResource, displayResource } from "features/resources/resource";
import TooltipVue from "features/tooltips/Tooltip.vue"; import TooltipVue from "features/tooltips/Tooltip.vue";
import { addTooltip } from "features/tooltips/tooltip"; 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, { import Formula, {
calculateCost, calculateCost,
calculateMaxAffordable, calculateMaxAffordable,
unrefFormulaSource unrefFormulaSource
} from "game/formulas/formulas"; } from "game/formulas/formulas";
import { FormulaSource, GenericFormula, InvertibleIntegralFormula } from "game/formulas/types"; import { FormulaSource, GenericFormula, InvertibleIntegralFormula } from "game/formulas/types";
import { BaseLayer, createLayer } from "game/layers"; import { BaseLayer, GenericLayer, createLayer } from "game/layers";
import { import {
Modifier, Modifier,
createAdditiveModifier, createAdditiveModifier,
@ -29,13 +34,13 @@ import {
} from "game/modifiers"; } from "game/modifiers";
import { State, noPersist, persistent } from "game/persistence"; import { State, noPersist, persistent } from "game/persistence";
import { createCostRequirement } from "game/requirements"; import { createCostRequirement } from "game/requirements";
import Decimal, { DecimalSource } from "util/bignum"; import Decimal, { format, formatWhole, DecimalSource } from "util/bignum";
import { format, formatWhole } from "util/break_eternity";
import { Direction, WithRequired, camelToTitle } from "util/common"; import { Direction, WithRequired, camelToTitle } from "util/common";
import { Computable, ProcessedComputable, convertComputable } from "util/computed"; import { Computable, ProcessedComputable, convertComputable } from "util/computed";
import { VueFeature, render, renderCol, renderRow, trackHover } from "util/vue"; import { VueFeature, render, renderCol, renderRow, trackHover } from "util/vue";
import { ComputedRef, Ref, computed, ref, unref } from "vue"; import { ComputedRef, Ref, computed, ref, unref } from "vue";
import { useToast } from "vue-toastification"; import { useToast } from "vue-toastification";
import { isPowered } from "./boardUtils";
import { createCollapsibleModifierSections, createFormulaPreview, estimateTime } from "./common"; import { createCollapsibleModifierSections, createFormulaPreview, estimateTime } from "./common";
import { import {
BoosterState, 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 resourceChange = computed(() => {
const preview = previews.find(p => p.shouldShowPreview.value); const preview = previews.find(p => p.shouldShowPreview.value);
if (preview) { if (preview) {

View file

@ -49,6 +49,7 @@ import {
QuarryState, QuarryState,
ResourceState, ResourceState,
Resources, Resources,
UpgraderState,
mineLootTable, mineLootTable,
resourceNames, resourceNames,
tools tools
@ -66,7 +67,8 @@ import {
portal, portal,
portalGenerator, portalGenerator,
quarry, quarry,
resource resource,
upgrader
} from "./nodeTypes"; } from "./nodeTypes";
import { GenericPlane, createPlane } from "./planes"; import { GenericPlane, createPlane } from "./planes";
@ -84,7 +86,8 @@ const types = {
portalGenerator, portalGenerator,
portal, portal,
influence, influence,
booster booster,
upgrader
}; };
/** /**
@ -109,7 +112,8 @@ export const main = createLayer("main", function (this: BaseLayer) {
wood: board.types.quarry.nodes.value[0], wood: board.types.quarry.nodes.value[0],
coal: board.types.empowerer.nodes.value[0], coal: board.types.empowerer.nodes.value[0],
iron: board.types.portalGenerator.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(() => ({ 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 => { Object.values(influenceNodes.value).forEach(node => {
const state = node.state as unknown as InfluenceState; const state = node.state as unknown as InfluenceState;
if (state.type === "increaseResources" || state.type === "decreaseResources") { if (state.type === "increaseResources" || state.type === "decreaseResources") {
@ -371,7 +389,8 @@ export const main = createLayer("main", function (this: BaseLayer) {
() => toolNodes.value.iron () => toolNodes.value.iron
); );
const booster: ComputedRef<BoardNode | undefined> = computed(() => toolNodes.value.gold); 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) { function grantResource(type: Resources, amount: DecimalSource) {
let node = resourceNodes.value[type]; let node = resourceNodes.value[type];
@ -780,6 +799,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
checkConnections(curr, quarry, "resources"); checkConnections(curr, quarry, "resources");
checkConnections(curr, empowerer, "tools"); checkConnections(curr, empowerer, "tools");
checkConnections(curr, booster, "portals"); checkConnections(curr, booster, "portals");
checkConnections(curr, upgrader, "portals");
} }
}); });
@ -800,6 +820,8 @@ export const main = createLayer("main", function (this: BaseLayer) {
dropRates, dropRates,
dowsing, dowsing,
empowerer, empowerer,
booster,
upgrader,
resourceLevels, resourceLevels,
planarMultis, planarMultis,
display: jsx(() => ( display: jsx(() => (