more work

This commit is contained in:
Olivier Gagnon 2021-10-04 23:51:39 -04:00
parent c5e29dafc4
commit 2f677c7ec8
10 changed files with 43 additions and 85 deletions

@ -2,7 +2,7 @@ import { Fragment, FragmentById } from "./Fragment";
import { FragmentType } from "./FragmentType";
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../utils/JSONReviver";
const noCharge = [FragmentType.None, FragmentType.Delete, FragmentType.Booster, FragmentType.Cooling];
const noCharge = [FragmentType.None, FragmentType.Delete, FragmentType.Booster];
export interface IActiveFragmentParams {
x: number;
@ -13,7 +13,6 @@ export interface IActiveFragmentParams {
export class ActiveFragment {
id: number;
charge: number;
heat: number;
x: number;
y: number;
@ -24,13 +23,11 @@ export class ActiveFragment {
this.y = params.y;
this.charge = 1;
if (noCharge.includes(params.fragment.type)) this.charge = 0;
this.heat = 1;
} else {
this.id = -1;
this.x = -1;
this.y = -1;
this.charge = -1;
this.heat = -1;
}
}
@ -71,7 +68,6 @@ export class ActiveFragment {
if (fragment === null) throw new Error("ActiveFragment id refers to unknown Fragment.");
const c = new ActiveFragment({ x: this.x, y: this.y, fragment: fragment });
c.charge = this.charge;
c.heat = this.heat;
return c;
}

@ -126,31 +126,6 @@ export function FragmentById(id: number): Fragment | null {
3, // limit
),
);
Fragments.push(
new Fragment(
3, // id
[
// shape
[X, X],
[X, X],
],
FragmentType.Cooling, // type
200,
Infinity, // limit
),
);
Fragments.push(
new Fragment(
4, // id
[
// shape
[X],
],
FragmentType.Cooling, // type
50,
1, // limit
),
);
Fragments.push(
new Fragment(
5, // id

@ -1,27 +1,26 @@
export enum FragmentType {
// Special fragments for the UI
None,
Delete,
// Special fragments for the UI
None,
Delete,
// Stats boosting fragments
HackingChance,
HackingSpeed,
HackingMoney,
HackingGrow,
Hacking,
Strength,
Defense,
Dexterity,
Agility,
Charisma,
HacknetMoney,
HacknetCost,
Rep,
WorkMoney,
Crime,
Bladeburner,
// Stats boosting fragments
HackingChance,
HackingSpeed,
HackingMoney,
HackingGrow,
Hacking,
Strength,
Defense,
Dexterity,
Agility,
Charisma,
HacknetMoney,
HacknetCost,
Rep,
WorkMoney,
Crime,
Bladeburner,
// utility fragments.
Booster,
Cooling,
}
// utility fragments.
Booster,
}

@ -36,16 +36,13 @@ export class StaneksGift implements IStaneksGift {
// count number of neighbooring boosts and cooling.
let boost = 1;
let cool = 1;
for (const neighboor of neighboors) {
const f = neighboor.fragment();
if (f.type === FragmentType.Cooling) cool *= 1 + f.power / 1000;
if (f.type === FragmentType.Booster) boost *= 1 + f.power / 1000;
}
const [extraCharge, extraHeat] = CalculateCharge(ram, af.heat, boost, cool);
const extraCharge = CalculateCharge(ram, boost);
af.charge += extraCharge;
af.heat += extraHeat;
Factions["Church of the Machine God"].playerReputation += extraCharge;
@ -57,10 +54,7 @@ export class StaneksGift implements IStaneksGift {
const fragment = activeFragment.fragment();
// Boosters and cooling don't deal with heat.
if (fragment.type === FragmentType.Booster || fragment.type === FragmentType.Cooling) continue;
activeFragment.heat *= 0.98;
activeFragment.heat -= 1;
if (activeFragment.heat < 1) activeFragment.heat = 1;
if (fragment.type === FragmentType.Booster) continue;
}
this.updateMults(p);

@ -1,6 +1,4 @@
export function CalculateCharge(ram: number, currentHeat: number, boost: number, cool: number): number[] {
const heatPenalty = Math.log(1+currentHeat)/Math.log(2);
const extraCharge = ram*Math.pow(boost, 2)/(heatPenalty*cool);
const extraHeat = ram;
return [extraCharge, extraHeat];
}
export function CalculateCharge(ram: number, boost: number): number {
const extraCharge = ram * Math.pow(boost, 2);
return extraCharge;
}

@ -48,11 +48,9 @@ export function FragmentInspector(props: IProps): React.ReactElement {
const f = props.fragment.fragment();
let charge = numeralWrapper.formatStaneksGiftCharge(props.fragment.charge);
let heat = numeralWrapper.formatStaneksGiftHeat(props.fragment.heat);
// Boosters and cooling don't deal with heat.
if (f.type === FragmentType.Booster || f.type === FragmentType.Cooling) {
if (f.type === FragmentType.Booster) {
charge = "N/A";
heat = "N/A";
}
const effect = numeralWrapper.format(CalculateEffect(props.fragment.charge, f.power) - 1, "+0.00%");
@ -67,8 +65,6 @@ export function FragmentInspector(props: IProps): React.ReactElement {
<br />
Charge: {charge}
<br />
Heat: {heat}
<br />
Effect: {effect}
<br />
root [X, Y] {props.fragment.x}, {props.fragment.y}

@ -12,7 +12,7 @@ type IProps = {
colorAt: (x: number, y: number) => string;
};
export function G(props: IProps): React.ReactElement {
export function FragmentPreview(props: IProps): React.ReactElement {
// switch the width/length to make axis consistent.
const elems = [];
for (let j = 0; j < props.height; j++) {

@ -2,7 +2,7 @@ import React, { useState } from "react";
import { Fragments, Fragment, NoneFragment, DeleteFragment } from "../Fragment";
import { FragmentType } from "../FragmentType";
import { IStaneksGift } from "../IStaneksGift";
import { G } from "./G";
import { FragmentPreview } from "./FragmentPreview";
import { numeralWrapper } from "../../ui/numeralFormat";
import Select, { SelectChangeEvent } from "@mui/material/Select";
@ -32,7 +32,7 @@ function FragmentOption(props: IOptionProps): React.ReactElement {
{remaining}
</Typography>
<br />
<G
<FragmentPreview
width={props.fragment.width()}
height={props.fragment.height()}
colorAt={(x, y) => (props.fragment.fullAt(x, y) ? "green" : "")}
@ -53,7 +53,9 @@ export function FragmentSelector(props: IProps): React.ReactElement {
setValue(v);
if (v === "None") props.selectFragment(NoneFragment);
else if (v === "Delete") props.selectFragment(DeleteFragment);
if (typeof v === "number") props.selectFragment(Fragments[v]);
const fragment = Fragments.find((f) => f.id === v);
if (fragment === undefined) throw new Error("Fragment selector selected an undefined fragment with id " + v);
if (typeof v === "number") props.selectFragment(fragment);
}
return (
<Select sx={{ width: "100%" }} onChange={onChange} value={value}>

@ -65,8 +65,6 @@ export function Grid(props: GridProps): React.ReactElement {
const newgrid = zeros([props.gift.width(), props.gift.height()]);
for (let i = 0; i < selectedFragment.shape.length; i++) {
for (let j = 0; j < selectedFragment.shape[i].length; j++) {
if (worldX + i > newgrid.length - 1) continue;
if (worldY + j > newgrid[worldX + i].length - 1) continue;
if (!selectedFragment.shape[i][j]) continue;
if (worldX + j > newgrid.length - 1) continue;
if (worldY + i > newgrid[worldX + j].length - 1) continue;

@ -8,14 +8,14 @@ import { staneksGift } from "../CotMG/Helper";
import { Fragments, FragmentById } from "../CotMG/Fragment";
export interface INetscriptStanek {
charge(worldX: any, worldY: any): any;
charge(worldX: number, worldY: number): any;
fragmentDefinitions(): any;
placedFragments(): any;
clear(): any;
canPlace(worldX: any, worldY: any, fragmentId: any): any;
place(worldX: any, worldY: any, fragmentId: any): any;
fragmentAt(worldX: any, worldY: any): any;
deleteAt(worldX: any, worldY: any): any;
clear(): void;
canPlace(worldX: number, worldY: number, fragmentId: number): boolean;
place(worldX: number, worldY: number, fragmentId: number): boolean;
fragmentAt(worldX: number, worldY: number): any;
deleteAt(worldX: number, worldY: number): boolean;
}
export function NetscriptStanek(