Implement treasures doing things on earn, per tick, and showing links

This commit is contained in:
thepaperpilot 2023-04-28 23:35:05 -05:00
parent df01c32454
commit da393b7f5a
2 changed files with 51 additions and 4 deletions

View file

@ -18,14 +18,15 @@ import Decimal, { DecimalSource } from "util/bignum";
import { format } from "util/break_eternity";
import { Direction, WithRequired, camelToTitle } from "util/common";
import { VueFeature, render, renderRow, trackHover } from "util/vue";
import { Ref, computed, ref } from "vue";
import { ComputedRef, Ref, computed, ref } from "vue";
import { createCollapsibleModifierSections, createFormulaPreview, estimateTime } from "./common";
import { Resources, resourceNames } from "./projEntry";
import { main, Resources, resourceNames } from "./projEntry";
import { getColor, getName, sfc32 } from "./utils";
import ModalVue from "components/Modal.vue";
import { addTooltip } from "features/tooltips/tooltip";
import { GenericAchievement, createAchievement } from "features/achievements/achievement";
import { Computable } from "util/computed";
import { BoardNode } from "features/boards/board";
export function createPlane(id: string, tier: Resources, seed: number) {
return createLayer(id, function (this: BaseLayer) {
@ -205,9 +206,14 @@ export function createPlane(id: string, tier: Resources, seed: number) {
continue; // Should not happen
}
let description = "";
let update: (diff: number) => void;
let onComplete: VoidFunction;
let link: ComputedRef<BoardNode>;
switch (treasureType) {
case "dirtGeneration":
description = `Gain ${format(difficulty)} dirt/s while plane is active`;
update = diff => main.grantResource("dirt", Decimal.times(diff, difficulty));
link = computed(() => main.resourceNodes.value["dirt"]);
break;
}
const cost = Decimal.times(difficulty, random() + 0.5)
@ -228,7 +234,10 @@ export function createPlane(id: string, tier: Resources, seed: number) {
style: "width: 100%",
classes: {
final: i === length - 1
}
},
update,
onComplete,
link
})) as GenericAchievement;
features.push([milestone]);
visibility = milestone.earned;
@ -256,6 +265,15 @@ export function createPlane(id: string, tier: Resources, seed: number) {
this.on("preUpdate", diff => {
resource.value = Decimal.times(computedResourceGain.value, diff).add(resource.value);
for (let i = 1; i < features.length; i += 2) {
const treasure = features[i][0] as GenericAchievement & {
update?: (diff: number) => void;
};
if (treasure.earned.value) {
treasure.update?.(diff);
}
}
});
const resourceChange = computed(() => {
@ -286,6 +304,19 @@ export function createPlane(id: string, tier: Resources, seed: number) {
resourceProductionChange
);
const links = computed(() => {
const links = [];
for (let i = 1; i < features.length; i += 2) {
const treasure = features[i][0] as GenericAchievement & {
link?: ComputedRef<BoardNode>;
};
if (treasure.earned.value && treasure.link) {
links.push(treasure.link);
}
}
return links;
});
return {
tier: persistent(tier),
seed: persistent(seed),
@ -299,6 +330,7 @@ export function createPlane(id: string, tier: Resources, seed: number) {
},
features,
resourceTabCollapsed,
links,
display: jsx(() => (
<>
<StickyVue class="nav-container">

View file

@ -1105,9 +1105,23 @@ export const main = createLayer("main", function (this: BaseLayer) {
stroke: "var(--foreground)",
strokeWidth: 4
});
}
// TODO link to influences
}
links.push(
...activePortals.value
.map(node =>
(
layers[(node.state as unknown as PortalState).id] as GenericPlane
).links.value.map(n => ({
startNode: node,
endNode: n.value,
stroke: "var(--accent3)",
strokeWidth: 4
}))
)
.reduce((a, b) => [...a, ...b], [])
);
}
return links;
}
}));
@ -1507,6 +1521,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
passives,
resourceNodes,
toolNodes,
grantResource,
display: jsx(() => (
<>
<StickyVue class="nav-container">