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 { FragmentType } from "./FragmentType";
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../utils/JSONReviver"; 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 { export interface IActiveFragmentParams {
x: number; x: number;
@ -13,7 +13,6 @@ export interface IActiveFragmentParams {
export class ActiveFragment { export class ActiveFragment {
id: number; id: number;
charge: number; charge: number;
heat: number;
x: number; x: number;
y: number; y: number;
@ -24,13 +23,11 @@ export class ActiveFragment {
this.y = params.y; this.y = params.y;
this.charge = 1; this.charge = 1;
if (noCharge.includes(params.fragment.type)) this.charge = 0; if (noCharge.includes(params.fragment.type)) this.charge = 0;
this.heat = 1;
} else { } else {
this.id = -1; this.id = -1;
this.x = -1; this.x = -1;
this.y = -1; this.y = -1;
this.charge = -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."); if (fragment === null) throw new Error("ActiveFragment id refers to unknown Fragment.");
const c = new ActiveFragment({ x: this.x, y: this.y, fragment: fragment }); const c = new ActiveFragment({ x: this.x, y: this.y, fragment: fragment });
c.charge = this.charge; c.charge = this.charge;
c.heat = this.heat;
return c; return c;
} }

@ -126,31 +126,6 @@ export function FragmentById(id: number): Fragment | null {
3, // limit 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( Fragments.push(
new Fragment( new Fragment(
5, // id 5, // id

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

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

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

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

@ -12,7 +12,7 @@ type IProps = {
colorAt: (x: number, y: number) => string; 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. // switch the width/length to make axis consistent.
const elems = []; const elems = [];
for (let j = 0; j < props.height; j++) { 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 { Fragments, Fragment, NoneFragment, DeleteFragment } from "../Fragment";
import { FragmentType } from "../FragmentType"; import { FragmentType } from "../FragmentType";
import { IStaneksGift } from "../IStaneksGift"; import { IStaneksGift } from "../IStaneksGift";
import { G } from "./G"; import { FragmentPreview } from "./FragmentPreview";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../ui/numeralFormat";
import Select, { SelectChangeEvent } from "@mui/material/Select"; import Select, { SelectChangeEvent } from "@mui/material/Select";
@ -32,7 +32,7 @@ function FragmentOption(props: IOptionProps): React.ReactElement {
{remaining} {remaining}
</Typography> </Typography>
<br /> <br />
<G <FragmentPreview
width={props.fragment.width()} width={props.fragment.width()}
height={props.fragment.height()} height={props.fragment.height()}
colorAt={(x, y) => (props.fragment.fullAt(x, y) ? "green" : "")} colorAt={(x, y) => (props.fragment.fullAt(x, y) ? "green" : "")}
@ -53,7 +53,9 @@ export function FragmentSelector(props: IProps): React.ReactElement {
setValue(v); setValue(v);
if (v === "None") props.selectFragment(NoneFragment); if (v === "None") props.selectFragment(NoneFragment);
else if (v === "Delete") props.selectFragment(DeleteFragment); 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 ( return (
<Select sx={{ width: "100%" }} onChange={onChange} value={value}> <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()]); const newgrid = zeros([props.gift.width(), props.gift.height()]);
for (let i = 0; i < selectedFragment.shape.length; i++) { for (let i = 0; i < selectedFragment.shape.length; i++) {
for (let j = 0; j < selectedFragment.shape[i].length; j++) { 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 (!selectedFragment.shape[i][j]) continue;
if (worldX + j > newgrid.length - 1) continue; if (worldX + j > newgrid.length - 1) continue;
if (worldY + i > newgrid[worldX + j].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"; import { Fragments, FragmentById } from "../CotMG/Fragment";
export interface INetscriptStanek { export interface INetscriptStanek {
charge(worldX: any, worldY: any): any; charge(worldX: number, worldY: number): any;
fragmentDefinitions(): any; fragmentDefinitions(): any;
placedFragments(): any; placedFragments(): any;
clear(): any; clear(): void;
canPlace(worldX: any, worldY: any, fragmentId: any): any; canPlace(worldX: number, worldY: number, fragmentId: number): boolean;
place(worldX: any, worldY: any, fragmentId: any): any; place(worldX: number, worldY: number, fragmentId: number): boolean;
fragmentAt(worldX: any, worldY: any): any; fragmentAt(worldX: number, worldY: number): any;
deleteAt(worldX: any, worldY: any): any; deleteAt(worldX: number, worldY: number): boolean;
} }
export function NetscriptStanek( export function NetscriptStanek(