mirror of
https://github.com/thepaperpilot/Planar-Pioneers.git
synced 2024-11-24 17:31:47 +00:00
Implemented empowerer (except actual effect)
This commit is contained in:
parent
d18f731c75
commit
3c8f1be7d4
1 changed files with 137 additions and 15 deletions
|
@ -58,6 +58,12 @@ export interface QuarryState extends DowsingState {
|
||||||
progress: DecimalSource;
|
progress: DecimalSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface EmpowererState {
|
||||||
|
tools: Passives[];
|
||||||
|
maxConnections: number;
|
||||||
|
powered: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
const mineLootTable = {
|
const mineLootTable = {
|
||||||
dirt: 120,
|
dirt: 120,
|
||||||
sand: 60,
|
sand: 60,
|
||||||
|
@ -114,7 +120,8 @@ const tools = {
|
||||||
coal: {
|
coal: {
|
||||||
cost: 1e8,
|
cost: 1e8,
|
||||||
name: "Tool Empowerer",
|
name: "Tool Empowerer",
|
||||||
type: "empowerer"
|
type: "empowerer",
|
||||||
|
state: { tools: [], maxConnections: 1, powered: false }
|
||||||
},
|
},
|
||||||
copper: {
|
copper: {
|
||||||
cost: 1e9,
|
cost: 1e9,
|
||||||
|
@ -199,7 +206,6 @@ export type Passives = keyof typeof passives;
|
||||||
*/
|
*/
|
||||||
export const main = createLayer("main", function (this: BaseLayer) {
|
export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
const energy = createResource<DecimalSource>(0, "energy");
|
const energy = createResource<DecimalSource>(0, "energy");
|
||||||
const hasForged = persistent<boolean>(false);
|
|
||||||
|
|
||||||
const resourceLevelFormula = Formula.variable(0).add(1);
|
const resourceLevelFormula = Formula.variable(0).add(1);
|
||||||
|
|
||||||
|
@ -216,7 +222,8 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<Resources, BoardNode>),
|
}, {} as Record<Resources, BoardNode>),
|
||||||
sand: board.types.dowsing.nodes.value[0],
|
sand: board.types.dowsing.nodes.value[0],
|
||||||
wood: board.types.quarry.nodes.value[0]
|
wood: board.types.quarry.nodes.value[0],
|
||||||
|
coal: board.types.empowerer.nodes.value[0]
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const resourceLevels = computed(() =>
|
const resourceLevels = computed(() =>
|
||||||
|
@ -288,7 +295,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
});
|
});
|
||||||
|
|
||||||
const poweredMachines: ComputedRef<number> = computed(() => {
|
const poweredMachines: ComputedRef<number> = computed(() => {
|
||||||
return [mine, dowsing, quarry].filter(
|
return [mine, dowsing, quarry, empowerer].filter(
|
||||||
node => (node.value?.state as { powered: boolean })?.powered
|
node => (node.value?.state as { powered: boolean })?.powered
|
||||||
).length;
|
).length;
|
||||||
});
|
});
|
||||||
|
@ -312,14 +319,28 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
const deselectAllAction = {
|
const deselectAllAction = {
|
||||||
id: "deselect",
|
id: "deselect",
|
||||||
icon: "close",
|
icon: "close",
|
||||||
tooltip: { text: "Disconnect resources" },
|
tooltip: (node: BoardNode) => ({
|
||||||
|
text:
|
||||||
|
"resources" in (node.state as object) ? "Disconnect resources" : "Disconnect tools"
|
||||||
|
}),
|
||||||
onClick(node: BoardNode) {
|
onClick(node: BoardNode) {
|
||||||
|
if ("resources" in (node.state as object)) {
|
||||||
node.state = { ...(node.state as object), resources: [] };
|
node.state = { ...(node.state as object), resources: [] };
|
||||||
|
} else if ("tools" in (node.state as object)) {
|
||||||
|
node.state = { ...(node.state as object), tools: [] };
|
||||||
|
}
|
||||||
board.selectedAction.value = null;
|
board.selectedAction.value = null;
|
||||||
board.selectedNode.value = null;
|
board.selectedNode.value = null;
|
||||||
},
|
},
|
||||||
visibility: (node: BoardNode) =>
|
visibility: (node: BoardNode) => {
|
||||||
(node.state as { resources: Resources[] }).resources.length > 0
|
if ("resources" in (node.state as object)) {
|
||||||
|
return (node.state as { resources: Resources[] }).resources.length > 0;
|
||||||
|
}
|
||||||
|
if ("tools" in (node.state as object)) {
|
||||||
|
return (node.state as { tools: Passives[] }).tools.length > 0;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const togglePoweredAction = {
|
const togglePoweredAction = {
|
||||||
|
@ -398,6 +419,27 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function labelForAcceptingTool(
|
||||||
|
node: BoardNode,
|
||||||
|
description: (passive: Passives) => string
|
||||||
|
): NodeLabel | null {
|
||||||
|
if ((board as GenericBoard).draggingNode.value?.type === "passive") {
|
||||||
|
const passive = (board as GenericBoard).draggingNode.value?.state as Passives;
|
||||||
|
const { maxConnections, tools } = node.state as unknown as EmpowererState;
|
||||||
|
if (tools.includes(passive)) {
|
||||||
|
return { text: "Disconnect", color: "var(--accent2)" };
|
||||||
|
}
|
||||||
|
if (tools.length === maxConnections) {
|
||||||
|
return { text: "Max connections", color: "var(--danger)" };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
text: description(passive),
|
||||||
|
color: "var(--accent2)"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function canAcceptResource(node: BoardNode, otherNode: BoardNode) {
|
function canAcceptResource(node: BoardNode, otherNode: BoardNode) {
|
||||||
if (otherNode.type !== "resource") {
|
if (otherNode.type !== "resource") {
|
||||||
return false;
|
return false;
|
||||||
|
@ -433,6 +475,41 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
board.selectedNode.value = node;
|
board.selectedNode.value = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function canAcceptTool(node: BoardNode, otherNode: BoardNode) {
|
||||||
|
if (otherNode.type !== "passive") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const passive = otherNode.state as Passives;
|
||||||
|
const { maxConnections, tools } = node.state as unknown as EmpowererState;
|
||||||
|
if (tools.includes(passive)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (tools.length === maxConnections) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDropTool(node: BoardNode, otherNode: BoardNode) {
|
||||||
|
if (otherNode.type !== "passive") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const passive = otherNode.state as Passives;
|
||||||
|
const tools = (node.state as unknown as { tools: Passives[] }).tools;
|
||||||
|
if (tools.includes(passive)) {
|
||||||
|
node.state = {
|
||||||
|
...(node.state as object),
|
||||||
|
tools: tools.filter(r => r !== passive)
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
node.state = {
|
||||||
|
...(node.state as object),
|
||||||
|
tools: [...tools, passive]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
board.selectedNode.value = node;
|
||||||
|
}
|
||||||
|
|
||||||
const board = createBoard(board => ({
|
const board = createBoard(board => ({
|
||||||
startNodes: () => [
|
startNodes: () => [
|
||||||
{ position: { x: 0, y: 0 }, type: "mine", state: { progress: 0, powered: false } },
|
{ position: { x: 0, y: 0 }, type: "mine", state: { progress: 0, powered: false } },
|
||||||
|
@ -445,7 +522,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
title: "🪨",
|
title: "🪨",
|
||||||
label: node =>
|
label: node =>
|
||||||
node === board.selectedNode.value
|
node === board.selectedNode.value
|
||||||
? { text: "Mining..." }
|
? { text: "Mining" }
|
||||||
: Object.keys(resourceNodes.value).length === 0
|
: Object.keys(resourceNodes.value).length === 0
|
||||||
? { text: "Click me!" }
|
? { text: "Click me!" }
|
||||||
: null,
|
: null,
|
||||||
|
@ -497,10 +574,8 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
return {
|
return {
|
||||||
text:
|
text:
|
||||||
node.state == null
|
node.state == null
|
||||||
? hasForged.value
|
? "Forge - Drag a resource to me!"
|
||||||
? "Forge"
|
: `Forging ${tools[node.state as Resources].name}`
|
||||||
: "Forge - Drag a resource to me!"
|
|
||||||
: `Forge - ${tools[node.state as Resources].name} selected`
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if ((board as GenericBoard).draggingNode.value?.type === "resource") {
|
if ((board as GenericBoard).draggingNode.value?.type === "resource") {
|
||||||
|
@ -707,6 +782,41 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
running: isPowered(node)
|
running: isPowered(node)
|
||||||
}),
|
}),
|
||||||
draggable: true
|
draggable: true
|
||||||
|
},
|
||||||
|
empowerer: {
|
||||||
|
shape: Shape.Diamond,
|
||||||
|
size: 50,
|
||||||
|
title: "🔌",
|
||||||
|
label: node => {
|
||||||
|
if (node === board.selectedNode.value) {
|
||||||
|
return {
|
||||||
|
text:
|
||||||
|
(node.state as unknown as EmpowererState).tools.length === 0
|
||||||
|
? "Empowerer - Drag a tool to me!"
|
||||||
|
: `Empowering (${
|
||||||
|
(node.state as { tools: Passives[] }).tools.length
|
||||||
|
}/${
|
||||||
|
(node.state as { maxConnections: number }).maxConnections
|
||||||
|
})`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return labelForAcceptingTool(
|
||||||
|
node,
|
||||||
|
passive => `Double ${tools[passive].name}'s effect`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
actionDistance: Math.PI / 4,
|
||||||
|
actions: [
|
||||||
|
deselectAllAction,
|
||||||
|
getIncreaseConnectionsAction(x => x.add(2).pow_base(10000), 16),
|
||||||
|
togglePoweredAction
|
||||||
|
],
|
||||||
|
canAccept: canAcceptTool,
|
||||||
|
onDrop: onDropTool,
|
||||||
|
classes: node => ({
|
||||||
|
running: isPowered(node)
|
||||||
|
}),
|
||||||
|
draggable: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
style: {
|
style: {
|
||||||
|
@ -768,6 +878,18 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
strokeWidth: 5
|
strokeWidth: 5
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
if (empowerer.value != null) {
|
||||||
|
(empowerer.value.state as unknown as EmpowererState).tools.forEach(tool => {
|
||||||
|
links.push({
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
startNode: empowerer.value!,
|
||||||
|
endNode: toolNodes.value[tool],
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
stroke: "var(--foreground)",
|
||||||
|
strokeWidth: 4
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
return links;
|
return links;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -782,6 +904,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
);
|
);
|
||||||
const dowsing: ComputedRef<BoardNode | undefined> = computed(() => toolNodes.value.sand);
|
const dowsing: ComputedRef<BoardNode | undefined> = computed(() => toolNodes.value.sand);
|
||||||
const quarry: ComputedRef<BoardNode | undefined> = computed(() => toolNodes.value.wood);
|
const quarry: ComputedRef<BoardNode | undefined> = computed(() => toolNodes.value.wood);
|
||||||
|
const empowerer: ComputedRef<BoardNode | undefined> = computed(() => toolNodes.value.coal);
|
||||||
|
|
||||||
function grantResource(type: Resources, amount: DecimalSource) {
|
function grantResource(type: Resources, amount: DecimalSource) {
|
||||||
let node = resourceNodes.value[type];
|
let node = resourceNodes.value[type];
|
||||||
|
@ -1064,7 +1187,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
return -100;
|
return -100;
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
if (board.selectedAction.value === board.types.factory.actions![0]) {
|
if (board.selectedAction.value === board.types.factory.actions![1]) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
return Decimal.neg(tools[board.selectedNode.value!.state as Resources].cost);
|
return Decimal.neg(tools[board.selectedNode.value!.state as Resources].cost);
|
||||||
}
|
}
|
||||||
|
@ -1107,7 +1230,6 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
board,
|
board,
|
||||||
energy,
|
energy,
|
||||||
modifierTabs,
|
modifierTabs,
|
||||||
hasForged,
|
|
||||||
mineLootTable,
|
mineLootTable,
|
||||||
tools,
|
tools,
|
||||||
passives,
|
passives,
|
||||||
|
|
Loading…
Reference in a new issue