mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +01:00
change the way charge works
This commit is contained in:
parent
4bef2f09a5
commit
35a5e2f343
22
dist/vendor.bundle.js
vendored
22
dist/vendor.bundle.js
vendored
File diff suppressed because one or more lines are too long
@ -12,12 +12,11 @@ placedFragments() Netscript Function
|
||||
// In world coordinates
|
||||
x: number;
|
||||
y: number;
|
||||
heat: number;
|
||||
charge: number;
|
||||
id: number;
|
||||
shape: boolean[][];
|
||||
type: string;
|
||||
magnitude: number;
|
||||
power: number;
|
||||
limit: number;
|
||||
}
|
||||
]
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -7,12 +7,13 @@ export interface IStaneksGift {
|
||||
fragments: ActiveFragment[];
|
||||
width(): number;
|
||||
height(): number;
|
||||
charge(worldX: number, worldY: number, ram: number): number;
|
||||
charge(rootX: number, rootY: number, ram: number): number;
|
||||
process(p: IPlayer, n: number): void;
|
||||
effect(fragment: ActiveFragment): number;
|
||||
canPlace(x: number, y: number, rotation: number, fragment: Fragment): boolean;
|
||||
place(x: number, y: number, rotation: number, fragment: Fragment): boolean;
|
||||
fragmentAt(worldX: number, worldY: number): ActiveFragment | null;
|
||||
findFragment(rootX: number, rootY: number): ActiveFragment | undefined;
|
||||
fragmentAt(worldX: number, worldY: number): ActiveFragment | undefined;
|
||||
deleteAt(worldX: number, worldY: number): boolean;
|
||||
clear(): void;
|
||||
count(fragment: Fragment): number;
|
||||
|
@ -29,9 +29,9 @@ export class StaneksGift implements IStaneksGift {
|
||||
return Math.floor(this.baseSize() / 2 + 0.6);
|
||||
}
|
||||
|
||||
charge(worldX: number, worldY: number, ram: number): number {
|
||||
const af = this.fragmentAt(worldX, worldY);
|
||||
if (af === null) return 0;
|
||||
charge(rootX: number, rootY: number, ram: number): number {
|
||||
const af = this.findFragment(rootX, rootY);
|
||||
if (af === undefined) return 0;
|
||||
|
||||
const charge = CalculateCharge(ram);
|
||||
af.charge += charge;
|
||||
@ -60,8 +60,8 @@ export class StaneksGift implements IStaneksGift {
|
||||
// find the neighbooring active fragments.
|
||||
const maybeFragments = cells.map((n) => this.fragmentAt(n[0], n[1]));
|
||||
|
||||
// Filter out nulls with typescript "Type guard". Whatever
|
||||
let neighboors = maybeFragments.filter((v: ActiveFragment | null): v is ActiveFragment => !!v);
|
||||
// Filter out undefined with typescript "Type guard". Whatever
|
||||
let neighboors = maybeFragments.filter((v: ActiveFragment | undefined): v is ActiveFragment => !!v);
|
||||
|
||||
neighboors = neighboors.filter((fragment) => fragment.fragment().type === FragmentType.Booster);
|
||||
let boost = 1;
|
||||
@ -90,14 +90,18 @@ export class StaneksGift implements IStaneksGift {
|
||||
return true;
|
||||
}
|
||||
|
||||
fragmentAt(worldX: number, worldY: number): ActiveFragment | null {
|
||||
findFragment(rootX: number, rootY: number): ActiveFragment | undefined {
|
||||
return this.fragments.find((f) => f.x === rootX && f.y === rootY);
|
||||
}
|
||||
|
||||
fragmentAt(worldX: number, worldY: number): ActiveFragment | undefined {
|
||||
for (const aFrag of this.fragments) {
|
||||
if (aFrag.fullAt(worldX, worldY)) {
|
||||
return aFrag;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
count(fragment: Fragment): number {
|
||||
|
@ -9,7 +9,7 @@ import Typography from "@mui/material/Typography";
|
||||
|
||||
type IProps = {
|
||||
gift: IStaneksGift;
|
||||
fragment: ActiveFragment | null;
|
||||
fragment: ActiveFragment | undefined;
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
@ -23,7 +23,7 @@ export function FragmentInspector(props: IProps): React.ReactElement {
|
||||
return () => clearInterval(id);
|
||||
}, []);
|
||||
|
||||
if (props.fragment === null) {
|
||||
if (props.fragment === undefined) {
|
||||
return (
|
||||
<Paper>
|
||||
<Typography>
|
||||
|
@ -49,7 +49,7 @@ export function MainBoard(props: IProps): React.ReactElement {
|
||||
for (let i = 0; i < gift.width(); i++) {
|
||||
for (let j = 0; j < gift.height(); j++) {
|
||||
const fragment = gift.fragmentAt(i, j);
|
||||
if (fragment === null) continue;
|
||||
if (!fragment) continue;
|
||||
newgrid[i][j] = 1;
|
||||
}
|
||||
}
|
||||
@ -64,6 +64,7 @@ export function MainBoard(props: IProps): React.ReactElement {
|
||||
const [selectedFragment, setSelectedFragment] = React.useState(NoneFragment);
|
||||
|
||||
function moveGhost(worldX: number, worldY: number, rotation: number): void {
|
||||
setPos([worldX, worldY]);
|
||||
if (selectedFragment.type === FragmentType.None || selectedFragment.type === FragmentType.Delete) return;
|
||||
const newgrid = zeros([props.gift.width(), props.gift.height()]);
|
||||
for (let y = 0; y < selectedFragment.height(rotation); y++) {
|
||||
@ -76,7 +77,6 @@ export function MainBoard(props: IProps): React.ReactElement {
|
||||
}
|
||||
|
||||
setGhostGrid(newgrid);
|
||||
setPos([worldX, worldY]);
|
||||
}
|
||||
|
||||
function deleteAt(worldX: number, worldY: number): boolean {
|
||||
@ -97,9 +97,10 @@ export function MainBoard(props: IProps): React.ReactElement {
|
||||
function color(worldX: number, worldY: number): string {
|
||||
if (ghostGrid[worldX][worldY] && grid[worldX][worldY]) return "red";
|
||||
if (ghostGrid[worldX][worldY]) return "white";
|
||||
|
||||
if (grid[worldX][worldY]) {
|
||||
const fragment = props.gift.fragmentAt(worldX, worldY);
|
||||
if (fragment === null) throw new Error("ActiveFragment should not be null");
|
||||
if (!fragment) throw new Error("ActiveFragment should not be null");
|
||||
return randomColor(fragment);
|
||||
}
|
||||
return "";
|
||||
|
@ -8,12 +8,15 @@ import { staneksGift } from "../CotMG/Helper";
|
||||
import { Fragments, FragmentById } from "../CotMG/Fragment";
|
||||
|
||||
export interface INetscriptStanek {
|
||||
charge(worldX: number, worldY: number): any;
|
||||
width(): number;
|
||||
height(): number;
|
||||
charge(rootX: number, rootY: number): any;
|
||||
fragmentDefinitions(): any;
|
||||
placedFragments(): any;
|
||||
clear(): void;
|
||||
canPlace(worldX: number, worldY: number, rotation: number, fragmentId: number): boolean;
|
||||
place(worldX: number, worldY: number, rotation: number, fragmentId: number): boolean;
|
||||
findFragment(rootX: any, rootY: any): any;
|
||||
fragmentAt(worldX: number, worldY: number): any;
|
||||
deleteAt(worldX: number, worldY: number): boolean;
|
||||
}
|
||||
@ -24,28 +27,38 @@ export function NetscriptStanek(
|
||||
helper: INetscriptHelper,
|
||||
): INetscriptStanek {
|
||||
return {
|
||||
charge: function (worldX: any, worldY: any): any {
|
||||
width: function (): number {
|
||||
return staneksGift.width();
|
||||
},
|
||||
height: function (): number {
|
||||
return staneksGift.height();
|
||||
},
|
||||
charge: function (rootX: any, rootY: any): any {
|
||||
helper.updateDynamicRam("charge", getRamCost("stanek", "charge"));
|
||||
//checkStanekAPIAccess("charge");
|
||||
const fragment = staneksGift.fragmentAt(worldX, worldY);
|
||||
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.charge", `No fragment at (${worldX}, ${worldY})`);
|
||||
const fragment = staneksGift.findFragment(rootX, rootY);
|
||||
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.charge", `No fragment with root (${rootX}, ${rootY}).`);
|
||||
const time = staneksGift.inBonus() ? 200 : 1000;
|
||||
return netscriptDelay(time, workerScript).then(function () {
|
||||
if (workerScript.env.stopFlag) {
|
||||
return Promise.reject(workerScript);
|
||||
}
|
||||
const ram = workerScript.scriptRef.ramUsage * workerScript.scriptRef.threads;
|
||||
return Promise.resolve(staneksGift.charge(worldX, worldY, ram));
|
||||
const charge = staneksGift.charge(rootX, rootY, ram);
|
||||
workerScript.log("stanek.charge", `Charged fragment for ${charge} charge.`);
|
||||
return Promise.resolve(charge);
|
||||
});
|
||||
},
|
||||
fragmentDefinitions: function () {
|
||||
helper.updateDynamicRam("fragmentDefinitions", getRamCost("stanek", "fragmentDefinitions"));
|
||||
//checkStanekAPIAccess("fragmentDefinitions");
|
||||
workerScript.log("stanek.fragmentDefinitions", `Returned ${Fragments.length} fragments`);
|
||||
return Fragments.map((f) => f.copy());
|
||||
},
|
||||
placedFragments: function () {
|
||||
helper.updateDynamicRam("placedFragments", getRamCost("stanek", "placedFragments"));
|
||||
//checkStanekAPIAccess("placedFragments");
|
||||
workerScript.log("stanek.placedFragments", `Returned ${staneksGift.fragments.length} fragments`);
|
||||
return staneksGift.fragments.map((af) => {
|
||||
return { ...af.copy(), ...af.fragment().copy() };
|
||||
});
|
||||
@ -53,6 +66,7 @@ export function NetscriptStanek(
|
||||
clear: function () {
|
||||
helper.updateDynamicRam("clear", getRamCost("stanek", "clear"));
|
||||
//checkStanekAPIAccess("clear");
|
||||
workerScript.log("stanek.clear", `Cleared Stanek's Gift.`);
|
||||
staneksGift.clear();
|
||||
},
|
||||
canPlace: function (worldX: any, worldY: any, rotation: any, fragmentId: any): any {
|
||||
@ -60,7 +74,8 @@ export function NetscriptStanek(
|
||||
//checkStanekAPIAccess("canPlace");
|
||||
const fragment = FragmentById(fragmentId);
|
||||
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.canPlace", `Invalid fragment id: ${fragmentId}`);
|
||||
return staneksGift.canPlace(worldX, worldY, rotation, fragment);
|
||||
const can = staneksGift.canPlace(worldX, worldY, rotation, fragment);
|
||||
return can;
|
||||
},
|
||||
place: function (worldX: any, worldY: any, rotation: any, fragmentId: any): any {
|
||||
helper.updateDynamicRam("place", getRamCost("stanek", "place"));
|
||||
@ -69,12 +84,19 @@ export function NetscriptStanek(
|
||||
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.place", `Invalid fragment id: ${fragmentId}`);
|
||||
return staneksGift.place(worldX, worldY, rotation, fragment);
|
||||
},
|
||||
findFragment: function (rootX: any, rootY: any): any {
|
||||
helper.updateDynamicRam("findFragment", getRamCost("stanek", "findFragment"));
|
||||
//checkStanekAPIAccess("fragmentAt");
|
||||
const fragment = staneksGift.findFragment(rootX, rootY);
|
||||
if (fragment !== undefined) return fragment.copy();
|
||||
return undefined;
|
||||
},
|
||||
fragmentAt: function (worldX: any, worldY: any): any {
|
||||
helper.updateDynamicRam("fragmentAt", getRamCost("stanek", "fragmentAt"));
|
||||
//checkStanekAPIAccess("fragmentAt");
|
||||
const fragment = staneksGift.fragmentAt(worldX, worldY);
|
||||
if (fragment !== null) return fragment.copy();
|
||||
return null;
|
||||
if (fragment !== undefined) return fragment.copy();
|
||||
return undefined;
|
||||
},
|
||||
deleteAt: function (worldX: any, worldY: any): any {
|
||||
helper.updateDynamicRam("deleteAt", getRamCost("stanek", "deleteAt"));
|
||||
|
@ -751,7 +751,7 @@ export function SidebarRoot(props: IProps): React.ReactElement {
|
||||
<Typography color={props.page !== Page.Options ? "secondary" : "primary"}>Options</Typography>
|
||||
</ListItemText>
|
||||
</ListItem>
|
||||
{process.env.NODE_ENV === "development" && (
|
||||
{true && (
|
||||
<ListItem
|
||||
classes={{ root: classes.listitem }}
|
||||
button
|
||||
|
Loading…
Reference in New Issue
Block a user