Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Add a few Glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Gagnon committed Jun 9, 2024
1 parent 58a4719 commit e2e7150
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 18 deletions.
44 changes: 42 additions & 2 deletions src/Myrian/Helper.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import { DeviceType, Component, Lock } from "@nsdefs";
import { DeviceType, Component, Lock, Glitch } from "@nsdefs";
import { Myrian } from "./Myrian";
import { getNextISocketRequest } from "./formulas/formulas";

export const myrianSize = 12;

const defaultGlitches = {
[Glitch.Segmentation]: 0,
[Glitch.Roaming]: 0,
[Glitch.Encryption]: 0,
[Glitch.Magnetism]: 0,
[Glitch.Rust]: 0,
[Glitch.Friction]: 0,
[Glitch.Isolation]: 0,
[Glitch.Jamming]: 0,
[Glitch.Virtualization]: 0,
};

const defaultMyrian: Myrian = {
vulns: 0,
totalVulns: 0,
devices: [],
glitches: { ...defaultGlitches },
};

export const myrian: Myrian = defaultMyrian;
Expand All @@ -26,7 +39,8 @@ export const NewBus = (name: string, x: number, y: number) => {
transferLvl: 0,
reduceLvl: 0,
installLvl: 0,
// energy: 16,
energy: 16,
maxEnergy: 16,
});
};

Expand Down Expand Up @@ -96,6 +110,19 @@ export const NewLock = (name: string, x: number, y: number) => {
return lock;
};

export const NewBattery = (name: string, x: number, y: number) => {
myrian.devices.push({
name,
type: DeviceType.Battery,
isBusy: false,
x,
y,
tier: 0,
energy: 64,
maxEnergy: 64,
});
};

export const loadMyrian = (save: string) => {
if (!save) return;
// const savedFactory = JSON.parse(save);
Expand All @@ -104,9 +131,14 @@ export const loadMyrian = (save: string) => {

export const resetMyrian = () => {
myrian.vulns = 0;
myrian.totalVulns = 0;
myrian.devices = [];
myrian.glitches = { ...defaultGlitches };

Object.assign(myrian, defaultMyrian);

NewBus("alice", Math.floor(myrianSize / 2), Math.floor(myrianSize / 2));

NewISocket("isocket0", Math.floor(myrianSize / 4), 0, Component.R0);
NewISocket("isocket1", Math.floor(myrianSize / 2), 0, Component.G0);
NewISocket("isocket2", Math.floor((myrianSize * 3) / 4), 0, Component.B0);
Expand All @@ -116,4 +148,12 @@ export const resetMyrian = () => {
NewOSocket("osocket2", Math.floor((myrianSize * 3) / 4), Math.floor(myrianSize - 1));
};

setInterval(() => {
myrian.devices.forEach((device) => {
if (device.type !== DeviceType.Battery) return;
const up = Math.pow(2, device.tier + 1);
device.energy = Math.min(device.energy + up, device.maxEnergy);
});
}, 1000);

resetMyrian();
10 changes: 10 additions & 0 deletions src/Myrian/Myrian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import {
Lock,
BaseDevice,
DeviceID,
Glitch,
Battery,
} from "@nsdefs";
import { myrian, myrianSize } from "./Helper";
import { glitchMult } from "./formulas/glitches";

export interface Myrian {
vulns: number;
totalVulns: number;
devices: Device[];
glitches: Record<Glitch, number>;
}

export const distance = (a: Device, b: Device) => Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
Expand Down Expand Up @@ -112,6 +116,7 @@ export const isDeviceOSocket = (d: Device): d is OSocket => d.type === DeviceTyp
export const isDeviceReducer = (d: Device): d is Reducer => d.type === DeviceType.Reducer;
export const isDeviceCache = (d: Device): d is Cache => d.type === DeviceType.Cache;
export const isDeviceLock = (d: Device): d is Lock => d.type === DeviceType.Lock;
export const isDeviceBattery = (d: Device): d is Battery => d.type === DeviceType.Battery;

export const findDevice = (id: DeviceID, type?: DeviceType): Device | undefined =>
myrian.devices.find(
Expand All @@ -123,3 +128,8 @@ export const removeDevice = (id: DeviceID, type?: DeviceType) => {
(e) => !((typeof id === "string" ? e.name === id : e.x === id[0] && e.y === id[1]) && (!type || type === e.type)),
);
};

export const getTotalGlitchMult = () =>
Object.entries(myrian.glitches).reduce((acc, [glitch, lvl]) => {
return acc * glitchMult(glitch as Glitch, lvl);
}, 1);
23 changes: 22 additions & 1 deletion src/Myrian/formulas/formulas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const maxContentScale: Record<DeviceType, FactoryFormulaParams> = {
[DeviceType.Reducer]: [Infinity, 1, -1, 4095],
[DeviceType.Cache]: [1.2, 10, 0, 63],
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Battery]: [Infinity, Infinity, Infinity, Infinity],
};

// a^(b*X+c)+d
Expand All @@ -35,6 +36,7 @@ export const deviceScale: Record<DeviceType, FactoryFormulaParams> = {
[DeviceType.Reducer]: [1.5, 1, 2, 0],
[DeviceType.Cache]: [1.2, 10, 0, 63],
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Battery]: [1.2, 10, 0, 63],
};

export const deviceCost = (type: DeviceType, count?: number) =>
Expand All @@ -54,6 +56,7 @@ export const tierScale: Record<DeviceType, FactoryFormulaParams> = {
[DeviceType.Reducer]: [1.5, 1, 2, 0],
[DeviceType.Cache]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Battery]: [2, 1, 3, 0],
};

export const tierCost = (type: DeviceType, tier: number) => exp(tierScale[type], tier);
Expand All @@ -65,6 +68,7 @@ export const emissionScale: Record<DeviceType, FactoryFormulaParams> = {
[DeviceType.Reducer]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Cache]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Battery]: [Infinity, Infinity, Infinity, Infinity],
};

export const emissionCost = (type: DeviceType, emissionLvl: number) => exp(emissionScale[type], emissionLvl);
Expand All @@ -76,6 +80,7 @@ export const moveLvlScale: Record<DeviceType, FactoryFormulaParams> = {
[DeviceType.Reducer]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Cache]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Battery]: [Infinity, Infinity, Infinity, Infinity],
};

export const moveLvlCost = (type: DeviceType, moveLvl: number) => exp(moveLvlScale[type], moveLvl);
Expand All @@ -87,6 +92,7 @@ export const transferLvlScale: Record<DeviceType, FactoryFormulaParams> = {
[DeviceType.Reducer]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Cache]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Battery]: [Infinity, Infinity, Infinity, Infinity],
};

export const transferLvlCost = (type: DeviceType, transferLvl: number) => exp(transferLvlScale[type], transferLvl);
Expand All @@ -98,6 +104,7 @@ export const reduceLvlScale: Record<DeviceType, FactoryFormulaParams> = {
[DeviceType.Reducer]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Cache]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Battery]: [Infinity, Infinity, Infinity, Infinity],
};

export const reduceLvlCost = (type: DeviceType, reduceLvl: number) => exp(reduceLvlScale[type], reduceLvl);
Expand All @@ -109,21 +116,35 @@ export const installLvlScale: Record<DeviceType, FactoryFormulaParams> = {
[DeviceType.Reducer]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Cache]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Battery]: [Infinity, Infinity, Infinity, Infinity],
};

export const installLvlCost = (type: DeviceType, installLvl: number) => exp(installLvlScale[type], installLvl);

export const maxEnergyScale: Record<DeviceType, FactoryFormulaParams> = {
[DeviceType.Bus]: [2, 1, 3, 0],
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Reducer]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Cache]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.Battery]: [1.1, 1, 3, 8],
};

export const maxEnergyCost = (type: DeviceType, maxEnergy: number) => exp(maxEnergyScale[type], maxEnergy);

/**
glitches:
- random walls (higher level more randomly spawning walls, level 0 is no walls)
- moving dock & dispensers (higher level move faster, level 0 does not move)
- dock complexity (higher level more complex, level 0 is repeating request)
- energy consumption (higher level consume more, level 0 is no consumption)
- ugrade degradation (higher level degrade faster, level 0 does not degrade)
- ugrade degradation (hidden tile degrade upgrades, level 0 does not degrade)
- move hinderance (speed) (higher level slower, level 0 is no hinderance)
- connection hinderance (transfer / charge) (higher level slower, level 0 is immediate transfer speed and charge)
- allocation hinderance (craft & build) (higher level slower, level 0 is no hinderance)
special requests like "has red" that increases the reward
*/
42 changes: 42 additions & 0 deletions src/Myrian/formulas/glitches.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Glitch } from "@nsdefs";

export const glitchMaxLvl: Record<Glitch, number> = {
[Glitch.Segmentation]: 10,
[Glitch.Roaming]: 10,
[Glitch.Encryption]: 7,
[Glitch.Magnetism]: 10,
[Glitch.Rust]: 10,
[Glitch.Friction]: 3,
[Glitch.Isolation]: 3,
[Glitch.Virtualization]: 3,
[Glitch.Jamming]: 3,
};

export const giltchMultCoefficients: Record<Glitch, number> = {
[Glitch.Segmentation]: 0, // 1,
[Glitch.Roaming]: 0, // 1,
[Glitch.Encryption]: 0, // 0.1,
[Glitch.Magnetism]: 0.2,
[Glitch.Rust]: 0, // 1,
[Glitch.Friction]: 0.2,
[Glitch.Isolation]: 0.2,
[Glitch.Virtualization]: 0.2,
[Glitch.Jamming]: 0.2,
};

export const glitchMult = (glitch: Glitch, lvl: number) => 1 + lvl * giltchMultCoefficients[glitch];

// move hinderance
export const frictionMult = (lvl: number) => Math.pow(1.25, lvl);

// transfer slow down
export const isolationMult = (lvl: number) => Math.pow(2, lvl);

// install/uninstall slow down
export const virtualizationMult = (lvl: number) => Math.pow(3, lvl);

// reduce slow down
export const jammingMult = (lvl: number) => Math.pow(1.3, lvl);

// energy loss
export const magnetismLoss = (lvl: number) => lvl;
29 changes: 29 additions & 0 deletions src/Myrian/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ These devices act as storage for components.

These devices cannot be installed. They appear after various conditions are fulfilled in order to block certain tiles.

### Battery

These devices are only relevant when the Magnetism glitch is active. It recharges the energy of a bus.

## Installing

Bus can install new devices, when they do so a lock will appear over the tile that will eventually become the device. The cost of any device depends on the number of that type of device currently in the OS.
Expand All @@ -54,3 +58,28 @@ Currently 2 devices have tiers, reducers and OSockets.
Upgrading a reducer allows it to reduce components of a higher tier and ONLY that higher tier. A tier 2 reducer can only tier 2 components like r1 + r1 => r2 and loses access to r0 + r0 => r1

Upgrading a OSocket allows it to request higher tier components (as well as more components at a time).

## Glitches

glitches are optional difficulty modifiers that make the myrian more difficult BUT increase the amount of vulns gained.
All glitches start at level 0 and must be activated when you chose. They also have a max level that differs from glitch to glitch.

### Magnetism

By default bus lose 0 energy when moving. But when this glitch is active they start losing energy, at 0 energy bus move much more slowly. Batteries must be installed and used to charge busses.

### Friction

When Friction is active busses move more slowly.

### Isolation

When Isolation is active busses transfer and charge more slowly.

### Virtualization

When Virtualization is active busses install and uninstall devices more slowly.

### Jamming

When Jamming is active busses use reducers more slowly.
21 changes: 21 additions & 0 deletions src/Myrian/ui/DeviceIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MoveToInboxIcon from "@mui/icons-material/MoveToInbox";
import OutboxIcon from "@mui/icons-material/Outbox";
import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank";
import MergeTypeIcon from "@mui/icons-material/MergeType";
import BatteryChargingFullIcon from "@mui/icons-material/BatteryChargingFull";
import BlockIcon from "@mui/icons-material/Block";
import { Tooltip, Typography } from "@mui/material";
import { isDeviceContainer } from "../Myrian";
Expand Down Expand Up @@ -110,6 +111,8 @@ const ReducerIcon = styled(MergeTypeIcon)(defaultIconStyle);

const CacheIcon = styled(CheckBoxOutlineBlankIcon)(defaultIconStyle);

const BatteryIcon = styled(BatteryChargingFullIcon)(defaultIconStyle);

interface ITooltipContentProps {
device: Device;
content: React.ReactElement;
Expand Down Expand Up @@ -143,6 +146,24 @@ export const DeviceIcon = ({ device }: { device: Device }): React.ReactElement =
case DeviceType.Lock: {
return <LockIcon />;
}
case DeviceType.Battery: {
return (
<Tooltip
title={
<TooltipContent
device={device}
content={
<Typography>
{device.energy} / {device.maxEnergy}
</Typography>
}
/>
}
>
<BatteryIcon />
</Tooltip>
);
}
case DeviceType.Cache: {
return (
<Tooltip title={<TooltipContent device={device} content={<TooltipInventory device={device} />} />}>
Expand Down
Loading

0 comments on commit e2e7150

Please sign in to comment.