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

Commit

Permalink
add Add several upgrade functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Gagnon committed Jun 9, 2024
1 parent ffaa657 commit 863be2a
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 24 deletions.
10 changes: 5 additions & 5 deletions src/Myrian/Helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export const NewBus = (name: string, x: number, y: number) => {
content: [],
maxContent: 1,

moveLvl: 1,
transferLvl: 1,
reduceLvl: 1,
installLvl: 1,
moveLvl: 0,
transferLvl: 0,
reduceLvl: 0,
installLvl: 0,
// energy: 16,
});
};
Expand Down Expand Up @@ -63,7 +63,7 @@ export const NewISocket = (name: string, x: number, y: number, dispensing: Compo
x,
y,
emitting: dispensing,
cooldown: 10000,
emissionLvl: 0,
cooldownUntil: 0,
content: [dispensing],
maxContent: 1,
Expand Down
70 changes: 60 additions & 10 deletions src/Myrian/formulas/formulas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export const upgradeMaxContentCost = (type: DeviceType, currentMaxContent: numbe
exp(maxContentScale[type], currentMaxContent);

export const busPrice = (currentBusses: number): number => Math.pow(2, currentBusses + 3);
export const moveSpeed = (level: number) => 1000 / (level + 9);
export const reduceSpeed = (level: number) => 50000 / (level + 9);
export const transferSpeed = (level: number) => 1000 / (level + 9);
export const installSpeed = (level: number) => 100000 / (level + 9);
export const moveSpeed = (level: number) => 1000 / (level + 10);
export const reduceSpeed = (level: number) => 50000 / (level + 10);
export const transferSpeed = (level: number) => 1000 / (level + 10);
export const installSpeed = (level: number) => 100000 / (level + 10);
export const isocketSpeed = (level: number) => 10000 / (level + 10);

const countDevices = (type: DeviceType) => myrian.devices.reduce((acc, d) => (d.type === type ? acc + 1 : acc), 0);

Expand All @@ -46,12 +47,6 @@ export const getNextISocketRequest = (tier: number) => {
.map(() => potential[Math.floor(Math.random() * potential.length)]);
};

(() => {
for (let i = 0; i < 10; i++) {
console.log(getNextISocketRequest(0));
}
})();

export const tierScale: Record<DeviceType, FactoryFormulaParams> = {
[DeviceType.Bus]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
Expand All @@ -63,6 +58,61 @@ export const tierScale: Record<DeviceType, FactoryFormulaParams> = {

export const tierCost = (type: DeviceType, tier: number) => exp(tierScale[type], tier);

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

export const emissionCost = (type: DeviceType, emissionLvl: number) => exp(emissionScale[type], emissionLvl);

export const moveLvlScale: 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],
};

export const moveLvlCost = (type: DeviceType, moveLvl: number) => exp(moveLvlScale[type], moveLvl);

export const transferLvlScale: 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],
};

export const transferLvlCost = (type: DeviceType, transferLvl: number) => exp(transferLvlScale[type], transferLvl);

export const reduceLvlScale: 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],
};

export const reduceLvlCost = (type: DeviceType, reduceLvl: number) => exp(reduceLvlScale[type], reduceLvl);

export const installLvlScale: 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],
};

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

/**
glitches:
Expand Down
113 changes: 105 additions & 8 deletions src/NetscriptFunctions/Myrian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ import {
} from "../Myrian/Myrian";
import {
deviceCost,
emissionCost,
getNextISocketRequest,
installLvlCost,
installSpeed,
isocketSpeed,
moveLvlCost,
moveSpeed,
reduceLvlCost,
reduceSpeed,
tierCost,
transferLvlCost,
transferSpeed,
upgradeMaxContentCost,
} from "../Myrian/formulas/formulas";
Expand All @@ -39,6 +45,10 @@ import { componentTiers } from "../Myrian/formulas/components";
export function NetscriptMyrian(): InternalAPI<IMyrian> {
return {
DEUBG_RESET: () => resetMyrian,
DEBUG_GIVE_VULNS: (ctx) => (_amount) => {
const amount = helpers.number(ctx, "amount", _amount);
myrian.vulns += amount;
},
getDevice: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "id", _id);
const device = findDevice(id);
Expand Down Expand Up @@ -170,10 +180,11 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {

switch (container.type) {
case DeviceType.ISocket: {
container.cooldownUntil = Date.now() + container.cooldown;
const cooldown = isocketSpeed(container.emissionLvl);
container.cooldownUntil = Date.now() + cooldown;
setTimeout(() => {
container.content = new Array(container.maxContent).fill(container.emitting);
}, container.cooldown);
}, cooldown);
break;
}

Expand Down Expand Up @@ -409,6 +420,13 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
placedDevice.isBusy = false;
});
},
getUpgradeTierCost: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "device", _id);
const device = findDevice(id);
if (!device) return -1;
if (!("tier" in device)) return -1;
return tierCost(device.type, device.tier);
},
upgradeTier: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "device", _id);
const device = findDevice(id);
Expand All @@ -420,16 +438,95 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
device.tier++;
return true;
},
getUpgradeTierCost: (ctx) => (_id) => {
getUpgradeEmissionLvlCost: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "device", _id);
const device = findDevice(id);
if (!device) return -1;
if (!("tier" in device)) return -1;
return tierCost(device.type, device.tier);
if (!("emissionLvl" in device)) return -1;
return emissionCost(device.type, device.emissionLvl);
},
DEBUG_GIVE_VULNS: (ctx) => (_amount) => {
const amount = helpers.number(ctx, "amount", _amount);
myrian.vulns += amount;
upgradeEmissionLvl: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "device", _id);
const device = findDevice(id);
if (!device) return false;
if (!("emissionLvl" in device)) return false;
const cost = emissionCost(device.type, device.emissionLvl);
if (myrian.vulns < cost) return false;
myrian.vulns -= cost;
device.emissionLvl++;
return true;
},
getUpgradeMoveLvlCost: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "device", _id);
const device = findDevice(id);
if (!device) return -1;
if (!("moveLvl" in device)) return -1;
return moveLvlCost(device.type, device.moveLvl);
},
upgradeMoveLvl: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "device", _id);
const device = findDevice(id);
if (!device) return false;
if (!("moveLvl" in device)) return false;
const cost = moveLvlCost(device.type, device.moveLvl);
if (myrian.vulns < cost) return false;
myrian.vulns -= cost;
device.moveLvl++;
return true;
},
getUpgradeTransferLvlCost: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "device", _id);
const device = findDevice(id);
if (!device) return -1;
if (!("transferLvl" in device)) return -1;
return transferLvlCost(device.type, device.transferLvl);
},
upgradeTransferLvl: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "device", _id);
const device = findDevice(id);
if (!device) return false;
if (!("transferLvl" in device)) return false;
const cost = transferLvlCost(device.type, device.transferLvl);
if (myrian.vulns < cost) return false;
myrian.vulns -= cost;
device.transferLvl++;
return true;
},
getUpgradeReduceLvlCost: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "device", _id);
const device = findDevice(id);
if (!device) return -1;
if (!("reduceLvl" in device)) return -1;
return reduceLvlCost(device.type, device.reduceLvl);
},
upgradeReduceLvl: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "device", _id);
const device = findDevice(id);
if (!device) return false;
if (!("reduceLvl" in device)) return false;
const cost = reduceLvlCost(device.type, device.reduceLvl);
if (myrian.vulns < cost) return false;
myrian.vulns -= cost;
device.reduceLvl++;
return true;
},
getUpgradeInstallLvlCost: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "device", _id);
const device = findDevice(id);
if (!device) return -1;
if (!("installLvl" in device)) return -1;
return installLvlCost(device.type, device.installLvl);
},
upgradeInstallLvl: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "device", _id);
const device = findDevice(id);
if (!device) return false;
if (!("installLvl" in device)) return false;
const cost = installLvlCost(device.type, device.installLvl);
if (myrian.vulns < cost) return false;
myrian.vulns -= cost;
device.installLvl++;
return true;
},
};
}
82 changes: 81 additions & 1 deletion src/ScriptEditor/NetscriptDefinitions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5248,7 +5248,7 @@ export interface ContainerDevice extends BaseDevice {
export interface ISocket extends ContainerDevice {
type: DeviceType.ISocket;
emitting: Component;
cooldown: number;
emissionLvl: number;
cooldownUntil: number;
}

Expand Down Expand Up @@ -5396,6 +5396,86 @@ interface Myrian {
* @returns cost of upgrading the tier of a device, -1 on failure.
*/
getUpgradeTierCost(device: DeviceID): number;

/**
* Get the cost of upgrading the emission of a device
* @remarks
* RAM cost: 0 GB
* @returns cost of upgrading the emission of a device, -1 on failure.
*/
getUpgradeEmissionLvlCost(device: DeviceID): number;

/**
* Upgrade the emissionLvl of a device
* @remarks
* RAM cost: 0 GB
* @returns true if the upgrade succeeded, false otherwise.
*/
upgradeEmissionLvl(device: DeviceID): boolean;

/**
* Get the cost of upgrading the moveLvl of a device
* @remarks
* RAM cost: 0 GB
* @returns cost of upgrading the moveLvl of a device, -1 on failure.
*/
getUpgradeMoveLvlCost(device: DeviceID): number;

/**
* Upgrade the moveLvl of a device
* @remarks
* RAM cost: 0 GB
* @returns true if the upgrade succeeded, false otherwise.
*/
upgradeMoveLvl(device: DeviceID): boolean;

/**
* Get the cost of upgrading the transferLvl of a device
* @remarks
* RAM cost: 0 GB
* @returns cost of upgrading the transferLvl of a device, -1 on failure.
*/
getUpgradeTransferLvlCost(device: DeviceID): number;

/**
* Upgrade the moveLvl of a device
* @remarks
* RAM cost: 0 GB
* @returns true if the upgrade succeeded, false otherwise.
*/
upgradeTransferLvl(device: DeviceID): boolean;

/**
* Get the cost of upgrading the reduceLvl of a device
* @remarks
* RAM cost: 0 GB
* @returns cost of upgrading the reduceLvl of a device, -1 on failure.
*/
getUpgradeReduceLvlCost(device: DeviceID): number;

/**
* Upgrade the reduceLvl of a device
* @remarks
* RAM cost: 0 GB
* @returns true if the upgrade succeeded, false otherwise.
*/
upgradeReduceLvl(device: DeviceID): boolean;

/**
* Get the cost of upgrading the installLvl of a device
* @remarks
* RAM cost: 0 GB
* @returns cost of upgrading the installLvl of a device, -1 on failure.
*/
getUpgradeInstallLvlCost(device: DeviceID): number;

/**
* Upgrade the installLvl of a device
* @remarks
* RAM cost: 0 GB
* @returns true if the upgrade succeeded, false otherwise.
*/
upgradeInstallLvl(device: DeviceID): boolean;
}

/** @public */
Expand Down

0 comments on commit 863be2a

Please sign in to comment.