2021-09-25 23:21:50 +02:00
|
|
|
import { FragmentType } from "./FragmentType";
|
2021-10-16 23:27:35 +02:00
|
|
|
import { Shapes } from "./data/Shapes";
|
2021-09-25 23:21:50 +02:00
|
|
|
|
|
|
|
export const Fragments: Fragment[] = [];
|
|
|
|
|
|
|
|
export class Fragment {
|
2021-10-04 18:28:57 +02:00
|
|
|
id: number;
|
|
|
|
shape: boolean[][];
|
|
|
|
type: FragmentType;
|
|
|
|
power: number;
|
|
|
|
limit: number;
|
2021-09-25 23:21:50 +02:00
|
|
|
|
2021-10-04 18:28:57 +02:00
|
|
|
constructor(id: number, shape: boolean[][], type: FragmentType, power: number, limit: number) {
|
|
|
|
this.id = id;
|
|
|
|
this.shape = shape;
|
|
|
|
this.type = type;
|
|
|
|
this.power = power;
|
|
|
|
this.limit = limit;
|
|
|
|
}
|
2021-09-25 23:21:50 +02:00
|
|
|
|
2021-10-17 01:10:11 +02:00
|
|
|
fullAt(x: number, y: number, rotation: number): boolean {
|
2021-10-04 18:28:57 +02:00
|
|
|
if (y < 0) return false;
|
2021-10-16 23:12:04 +02:00
|
|
|
if (y >= this.height(rotation)) return false;
|
2021-10-04 18:28:57 +02:00
|
|
|
if (x < 0) return false;
|
2021-10-16 23:12:04 +02:00
|
|
|
if (x >= this.width(rotation)) return false;
|
|
|
|
// start xy, modifier xy
|
|
|
|
let [sx, sy, mx, my] = [0, 0, 1, 1];
|
|
|
|
if (rotation === 1) {
|
|
|
|
[sx, sy, mx, my] = [this.width(rotation) - 1, 0, -1, 1];
|
|
|
|
} else if (rotation === 2) {
|
|
|
|
[sx, sy, mx, my] = [this.width(rotation) - 1, this.height(rotation) - 1, -1, -1];
|
|
|
|
} else if (rotation === 3) {
|
|
|
|
[sx, sy, mx, my] = [0, this.height(rotation) - 1, 1, -1];
|
|
|
|
}
|
|
|
|
let [qx, qy] = [sx + mx * x, sy + my * y];
|
|
|
|
if (rotation % 2 === 1) [qx, qy] = [qy, qx];
|
|
|
|
return this.shape[qy][qx];
|
2021-10-04 18:28:57 +02:00
|
|
|
}
|
2021-09-25 23:21:50 +02:00
|
|
|
|
2021-10-16 23:12:04 +02:00
|
|
|
width(rotation: number): number {
|
|
|
|
if (rotation % 2 === 0) return this.shape[0].length;
|
|
|
|
return this.shape.length;
|
2021-10-04 18:28:57 +02:00
|
|
|
}
|
2021-09-25 23:21:50 +02:00
|
|
|
|
2021-10-16 23:12:04 +02:00
|
|
|
height(rotation: number): number {
|
|
|
|
if (rotation % 2 === 0) return this.shape.length;
|
|
|
|
return this.shape[0].length;
|
2021-10-04 18:28:57 +02:00
|
|
|
}
|
2021-09-25 23:21:50 +02:00
|
|
|
|
2021-10-04 18:28:57 +02:00
|
|
|
// List of direct neighboors of this fragment.
|
2021-10-16 23:12:04 +02:00
|
|
|
neighboors(rotation: number): number[][] {
|
2021-10-04 18:28:57 +02:00
|
|
|
const candidates: number[][] = [];
|
2021-09-25 23:21:50 +02:00
|
|
|
|
2021-10-04 18:28:57 +02:00
|
|
|
const add = (x: number, y: number): void => {
|
2021-10-16 23:12:04 +02:00
|
|
|
if (this.fullAt(x, y, rotation)) return;
|
2021-10-04 18:28:57 +02:00
|
|
|
if (candidates.some((coord) => coord[0] === x && coord[1] === y)) return;
|
|
|
|
candidates.push([x, y]);
|
|
|
|
};
|
2021-10-17 06:35:50 +02:00
|
|
|
for (let y = 0; y < this.height(rotation); y++) {
|
|
|
|
for (let x = 0; x < this.width(rotation); x++) {
|
2021-10-04 18:28:57 +02:00
|
|
|
// This cell is full, add all it's neighboors.
|
2021-10-17 06:35:50 +02:00
|
|
|
if (!this.fullAt(x, y, rotation)) continue;
|
2021-10-04 18:28:57 +02:00
|
|
|
add(x - 1, y);
|
|
|
|
add(x + 1, y);
|
|
|
|
add(x, y - 1);
|
|
|
|
add(x, y + 1);
|
|
|
|
}
|
2021-09-25 23:21:50 +02:00
|
|
|
}
|
2021-10-04 18:28:57 +02:00
|
|
|
const cells: number[][] = [];
|
|
|
|
for (const candidate of candidates) {
|
|
|
|
if (cells.some((cell) => cell[0] === candidate[0] && cell[1] === candidate[1])) continue;
|
|
|
|
cells.push(candidate);
|
2021-09-25 23:21:50 +02:00
|
|
|
}
|
2021-10-04 18:28:57 +02:00
|
|
|
|
|
|
|
return cells;
|
|
|
|
}
|
|
|
|
|
|
|
|
copy(): Fragment {
|
|
|
|
return new Fragment(
|
|
|
|
this.id,
|
|
|
|
this.shape.map((a) => a.slice()),
|
|
|
|
this.type,
|
|
|
|
this.power,
|
|
|
|
this.limit,
|
|
|
|
);
|
|
|
|
}
|
2021-09-25 23:21:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function FragmentById(id: number): Fragment | null {
|
2021-10-04 18:28:57 +02:00
|
|
|
for (const fragment of Fragments) {
|
|
|
|
if (fragment.id === id) return fragment;
|
|
|
|
}
|
|
|
|
return null;
|
2021-09-25 23:21:50 +02:00
|
|
|
}
|
|
|
|
|
2021-10-04 18:28:57 +02:00
|
|
|
(function () {
|
|
|
|
const _ = false;
|
|
|
|
const X = true;
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
0, // id
|
2021-10-17 03:00:36 +02:00
|
|
|
Shapes.S,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.Hacking, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
1,
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
1, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.Z,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.Hacking, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
1,
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
5, // id
|
2021-10-17 03:00:36 +02:00
|
|
|
Shapes.T,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.HackingSpeed, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
1.3,
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
2021-09-25 23:21:50 +02:00
|
|
|
|
2021-10-04 18:28:57 +02:00
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
6, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.I,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.HackingMoney, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
2, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
7, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.J,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.HackingGrow, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
0.5, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
10, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.T,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.Strength, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
2, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
12, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.L,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.Defense, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
2, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
14, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.L,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.Dexterity, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
2, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
16, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.S,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.Agility, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
2, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
18, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.S,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.Charisma, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
3, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
20, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.I,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.HacknetMoney, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
1, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
21, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.O,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.HacknetCost, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
-1, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
25, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.J,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.Rep, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
0.5, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
27, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.J,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.WorkMoney, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
10, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
28, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.L,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.Crime, // type
|
2021-10-07 07:36:59 +02:00
|
|
|
2, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
30, // id
|
2021-10-16 23:27:35 +02:00
|
|
|
Shapes.S,
|
2021-10-04 18:28:57 +02:00
|
|
|
FragmentType.Bladeburner, // type
|
2021-10-15 21:40:19 +02:00
|
|
|
0.4, // power
|
2021-10-04 18:28:57 +02:00
|
|
|
1, // limit
|
|
|
|
),
|
|
|
|
);
|
2021-10-07 07:36:59 +02:00
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
2021-10-17 03:00:36 +02:00
|
|
|
100, // id
|
|
|
|
[
|
|
|
|
// shape
|
|
|
|
[_, X, X],
|
|
|
|
[X, X, _],
|
|
|
|
[_, X, _],
|
|
|
|
],
|
|
|
|
FragmentType.Booster, // type
|
|
|
|
1.1, // power
|
|
|
|
99, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
101, // id
|
2021-10-07 07:36:59 +02:00
|
|
|
[
|
|
|
|
// shape
|
2021-10-15 21:40:19 +02:00
|
|
|
[X, X, X, X],
|
2021-10-17 03:00:36 +02:00
|
|
|
[X, _, _, _],
|
|
|
|
],
|
|
|
|
FragmentType.Booster, // type
|
|
|
|
1.1, // power
|
|
|
|
99, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
102, // id
|
|
|
|
[
|
|
|
|
// shape
|
|
|
|
[_, X, X, X],
|
|
|
|
[X, X, _, _],
|
|
|
|
],
|
|
|
|
FragmentType.Booster, // type
|
|
|
|
1.1, // power
|
|
|
|
99, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
103, // id
|
|
|
|
[
|
|
|
|
// shape
|
2021-11-14 04:44:17 +01:00
|
|
|
[X, X, X, _],
|
|
|
|
[_, _, X, X],
|
2021-10-17 03:00:36 +02:00
|
|
|
],
|
|
|
|
FragmentType.Booster, // type
|
|
|
|
1.1, // power
|
|
|
|
99, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
104, // id
|
|
|
|
[
|
|
|
|
// shape
|
|
|
|
[_, X, X],
|
|
|
|
[_, X, _],
|
|
|
|
[X, X, _],
|
|
|
|
],
|
|
|
|
FragmentType.Booster, // type
|
|
|
|
1.1, // power
|
|
|
|
99, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
105, // id
|
|
|
|
[
|
|
|
|
// shape
|
|
|
|
[_, _, X],
|
|
|
|
[_, X, X],
|
|
|
|
[X, X, _],
|
|
|
|
],
|
|
|
|
FragmentType.Booster, // type
|
|
|
|
1.1, // power
|
|
|
|
99, // limit
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
|
|
|
106, // id
|
|
|
|
[
|
|
|
|
// shape
|
|
|
|
[X, _, _],
|
|
|
|
[X, X, X],
|
|
|
|
[X, _, _],
|
2021-10-07 07:36:59 +02:00
|
|
|
],
|
|
|
|
FragmentType.Booster, // type
|
|
|
|
1.1, // power
|
2021-10-17 03:00:36 +02:00
|
|
|
99, // limit
|
2021-10-07 07:36:59 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
Fragments.push(
|
|
|
|
new Fragment(
|
2021-10-17 03:00:36 +02:00
|
|
|
107, // id
|
2021-10-07 07:36:59 +02:00
|
|
|
[
|
|
|
|
// shape
|
2021-10-17 03:00:36 +02:00
|
|
|
[_, X, _],
|
|
|
|
[X, X, X],
|
|
|
|
[_, X, _],
|
2021-10-07 07:36:59 +02:00
|
|
|
],
|
|
|
|
FragmentType.Booster, // type
|
|
|
|
1.1, // power
|
2021-10-17 03:00:36 +02:00
|
|
|
99, // limit
|
2021-10-07 07:36:59 +02:00
|
|
|
),
|
|
|
|
);
|
2021-09-25 23:21:50 +02:00
|
|
|
})();
|
|
|
|
|
|
|
|
export const NoneFragment = new Fragment(-2, [], FragmentType.None, 0, Infinity);
|
|
|
|
export const DeleteFragment = new Fragment(-2, [], FragmentType.Delete, 0, Infinity);
|