From ab7d1a8ce939fde26ded1d0a790459da76d0f373 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sat, 16 Oct 2021 17:27:35 -0400 Subject: [PATCH] Fix bug that allowed players to place pieces outside the baord. --- src/CotMG/Fragment.ts | 91 ++++++++----------------------------- src/CotMG/StaneksGift.ts | 15 +++--- src/CotMG/data/Constants.ts | 2 +- src/CotMG/data/Shapes.ts | 37 +++++++++++++++ 4 files changed, 64 insertions(+), 81 deletions(-) create mode 100644 src/CotMG/data/Shapes.ts diff --git a/src/CotMG/Fragment.ts b/src/CotMG/Fragment.ts index 86a5819db..0fe163f99 100644 --- a/src/CotMG/Fragment.ts +++ b/src/CotMG/Fragment.ts @@ -1,4 +1,5 @@ import { FragmentType } from "./FragmentType"; +import { Shapes } from "./data/Shapes"; export const Fragments: Fragment[] = []; @@ -101,12 +102,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 0, // id - [ - // shape - [X, X, X], - [_, _, X], - [_, _, X], - ], + Shapes.T, FragmentType.Hacking, // type 1, 1, // limit @@ -115,12 +111,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 1, // id - [ - // shape - [_, X, _], - [X, X, X], - [_, X, _], - ], + Shapes.Z, FragmentType.Hacking, // type 1, 1, // limit @@ -129,10 +120,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 5, // id - [ - // shape - [X, X], - ], + Shapes.S, FragmentType.HackingSpeed, // type 1.3, 1, // limit @@ -142,10 +130,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 6, // id - [ - [X, _], - [X, X], - ], // shape + Shapes.I, FragmentType.HackingMoney, // type 2, // power 1, // limit @@ -154,10 +139,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 7, // id - [ - [X, X], - [X, X], - ], // shape + Shapes.J, FragmentType.HackingGrow, // type 0.5, // power 1, // limit @@ -166,11 +148,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 8, // id - [ - [X, X, X], - [_, X, _], - [X, X, X], - ], // shape + Shapes.O, FragmentType.Hacking, // type 1, // power 1, // limit @@ -179,10 +157,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 10, // id - [ - [X, X], - [_, X], - ], // shape + Shapes.T, FragmentType.Strength, // type 2, // power 1, // limit @@ -191,10 +166,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 12, // id - [ - [_, X], - [X, X], - ], // shape + Shapes.L, FragmentType.Defense, // type 2, // power 1, // limit @@ -203,10 +175,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 14, // id - [ - [X, X], - [X, _], - ], // shape + Shapes.L, FragmentType.Dexterity, // type 2, // power 1, // limit @@ -215,10 +184,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 16, // id - [ - [X, _], - [X, X], - ], // shape + Shapes.S, FragmentType.Agility, // type 2, // power 1, // limit @@ -227,10 +193,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 18, // id - [ - [X, X], - [X, _], - ], // shape + Shapes.S, FragmentType.Charisma, // type 3, // power 1, // limit @@ -239,11 +202,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 20, // id - [ - [X, _, _], - [X, X, _], - [X, X, X], - ], // shape + Shapes.I, FragmentType.HacknetMoney, // type 1, // power 1, // limit @@ -252,11 +211,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 21, // id - [ - [X, X], - [_, X], - [_, X], - ], // shape + Shapes.O, FragmentType.HacknetCost, // type -1, // power 1, // limit @@ -265,10 +220,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 25, // id - [ - [X, X, X], - [_, X, _], - ], // shape + Shapes.J, FragmentType.Rep, // type 0.5, // power 1, // limit @@ -277,10 +229,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 27, // id - [ - [X, _], - [_, X], - ], // shape + Shapes.J, FragmentType.WorkMoney, // type 10, // power 1, // limit @@ -289,7 +238,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 28, // id - [[X, X]], // shape + Shapes.L, FragmentType.Crime, // type 2, // power 1, // limit @@ -298,11 +247,7 @@ export function FragmentById(id: number): Fragment | null { Fragments.push( new Fragment( 30, // id - [ - [X, X, X], - [X, X, X], - [X, X, X], - ], // shape + Shapes.S, FragmentType.Bladeburner, // type 0.4, // power 1, // limit diff --git a/src/CotMG/StaneksGift.ts b/src/CotMG/StaneksGift.ts index 3db4d8340..19b46bf5b 100644 --- a/src/CotMG/StaneksGift.ts +++ b/src/CotMG/StaneksGift.ts @@ -70,20 +70,21 @@ export class StaneksGift implements IStaneksGift { return CalculateEffect(fragment.charge, fragment.fragment().power, boost); } - canPlace(x: number, y: number, rotation: number, fragment: Fragment): boolean { - if (x + fragment.width(0) > this.width()) return false; - if (y + fragment.height(0) > this.height()) return false; + canPlace(worldX: number, worldY: number, rotation: number, fragment: Fragment): boolean { + if (worldX < 0 || worldY < 0) return false; + if (worldX + fragment.width(rotation) > this.width()) return false; + if (worldY + fragment.height(rotation) > this.height()) return false; if (this.count(fragment) >= fragment.limit) return false; - const newFrag = new ActiveFragment({ x: x, y: y, rotation: rotation, fragment: fragment }); + const newFrag = new ActiveFragment({ x: worldX, y: worldY, rotation: rotation, fragment: fragment }); for (const aFrag of this.fragments) { if (aFrag.collide(newFrag)) return false; } return true; } - place(x: number, y: number, rotation: number, fragment: Fragment): boolean { - if (!this.canPlace(x, y, rotation, fragment)) return false; - this.fragments.push(new ActiveFragment({ x: x, y: y, rotation: rotation, fragment: fragment })); + place(worldX: number, worldY: number, rotation: number, fragment: Fragment): boolean { + if (!this.canPlace(worldX, worldY, rotation, fragment)) return false; + this.fragments.push(new ActiveFragment({ x: worldX, y: worldY, rotation: rotation, fragment: fragment })); return true; } diff --git a/src/CotMG/data/Constants.ts b/src/CotMG/data/Constants.ts index 2ce02b93e..68a6f38ce 100644 --- a/src/CotMG/data/Constants.ts +++ b/src/CotMG/data/Constants.ts @@ -3,5 +3,5 @@ export const StanekConstants: { BaseSize: number; } = { RAMBonus: 0.1, - BaseSize: 12, + BaseSize: 9, }; diff --git a/src/CotMG/data/Shapes.ts b/src/CotMG/data/Shapes.ts new file mode 100644 index 000000000..00a5620b9 --- /dev/null +++ b/src/CotMG/data/Shapes.ts @@ -0,0 +1,37 @@ +const _ = false; +const X = true; +export const Shapes: { + O: boolean[][]; + I: boolean[][]; + L: boolean[][]; + J: boolean[][]; + S: boolean[][]; + Z: boolean[][]; + T: boolean[][]; +} = { + O: [ + [X, X], + [X, X], + ], + I: [[X, X, X, X]], + L: [ + [_, _, X], + [X, X, X], + ], + J: [ + [X, _, _], + [X, X, X], + ], + S: [ + [_, X, X], + [X, X, _], + ], + Z: [ + [X, X, _], + [_, X, X], + ], + T: [ + [X, X, X], + [_, X, _], + ], +};