From 443b0b6a892751e133f857d390f0d4c9b49f6d24 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Tue, 29 Mar 2022 14:20:40 -0400 Subject: [PATCH] rename functions in staneks gift --- src/Gang/Gang.ts | 2 +- src/NetscriptFunctions/Stanek.ts | 87 +++++++++++----------- src/ScriptEditor/NetscriptDefinitions.d.ts | 16 ++-- 3 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/Gang/Gang.ts b/src/Gang/Gang.ts index 8f3055343..733a36bf5 100644 --- a/src/Gang/Gang.ts +++ b/src/Gang/Gang.ts @@ -227,7 +227,7 @@ export class Gang implements IGang { AllGangs[thisGang].territory += territoryGain; if (AllGangs[thisGang].territory > 0.999) AllGangs[thisGang].territory = 1; AllGangs[otherGang].territory -= territoryGain; - if (AllGangs[thisGang].territory < 0.001) AllGangs[thisGang].territory = 0; + if (AllGangs[thisGang].territory) AllGangs[thisGang].territory = 0; if (thisGang === gangName) { this.clash(true); // Player won AllGangs[otherGang].power *= 1 / 1.01; diff --git a/src/NetscriptFunctions/Stanek.ts b/src/NetscriptFunctions/Stanek.ts index 45350406d..eefaff190 100644 --- a/src/NetscriptFunctions/Stanek.ts +++ b/src/NetscriptFunctions/Stanek.ts @@ -22,28 +22,29 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel } return { - width: function (): number { - helper.updateDynamicRam("width", getRamCost(player, "stanek", "width")); - checkStanekAPIAccess("width"); + giftWidth: function (): number { + helper.updateDynamicRam("giftWidth", getRamCost(player, "stanek", "giftWidth")); + checkStanekAPIAccess("giftWidth"); return staneksGift.width(); }, - height: function (): number { - helper.updateDynamicRam("height", getRamCost(player, "stanek", "height")); - checkStanekAPIAccess("height"); + giftHeight: function (): number { + helper.updateDynamicRam("giftHeight", getRamCost(player, "stanek", "giftHeight")); + checkStanekAPIAccess("giftHeight"); return staneksGift.height(); }, - charge: function (_rootX: unknown, _rootY: unknown): Promise { - const rootX = helper.number("stanek.charge", "rootX", _rootX); - const rootY = helper.number("stanek.charge", "rootY", _rootY); + chargeFragment: function (_rootX: unknown, _rootY: unknown): Promise { + const rootX = helper.number("stanek.chargeFragment", "rootX", _rootX); + const rootY = helper.number("stanek.chargeFragment", "rootY", _rootY); - helper.updateDynamicRam("charge", getRamCost(player, "stanek", "charge")); - checkStanekAPIAccess("charge"); + helper.updateDynamicRam("chargeFragment", getRamCost(player, "stanek", "chargeFragment")); + checkStanekAPIAccess("chargeFragment"); const fragment = staneksGift.findFragment(rootX, rootY); - if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.charge", `No fragment with root (${rootX}, ${rootY}).`); + if (!fragment) + throw helper.makeRuntimeErrorMsg("stanek.chargeFragment", `No fragment with root (${rootX}, ${rootY}).`); const time = staneksGift.inBonus() ? 200 : 1000; return netscriptDelay(time, workerScript).then(function () { const charge = staneksGift.charge(player, fragment, workerScript.scriptRef.threads); - workerScript.log("stanek.charge", () => `Charged fragment for ${charge} charge.`); + workerScript.log("stanek.chargeFragment", () => `Charged fragment for ${charge} charge.`); return Promise.resolve(); }); }, @@ -61,49 +62,49 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel return { ...af.copy(), ...af.fragment().copy() }; }); }, - clear: function (): void { - helper.updateDynamicRam("clear", getRamCost(player, "stanek", "clear")); - checkStanekAPIAccess("clear"); - workerScript.log("stanek.clear", () => `Cleared Stanek's Gift.`); + clearGift: function (): void { + helper.updateDynamicRam("clearGift", getRamCost(player, "stanek", "clearGift")); + checkStanekAPIAccess("clearGift"); + workerScript.log("stanek.clearGift", () => `Cleared Stanek's Gift.`); staneksGift.clear(); }, - canPlace: function (_rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean { - const rootX = helper.number("stanek.canPlace", "rootX", _rootX); - const rootY = helper.number("stanek.canPlace", "rootY", _rootY); - const rotation = helper.number("stanek.canPlace", "rotation", _rotation); - const fragmentId = helper.number("stanek.canPlace", "fragmentId", _fragmentId); - helper.updateDynamicRam("canPlace", getRamCost(player, "stanek", "canPlace")); - checkStanekAPIAccess("canPlace"); + canPlaceFragment: function (_rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean { + const rootX = helper.number("stanek.canPlaceFragment", "rootX", _rootX); + const rootY = helper.number("stanek.canPlaceFragment", "rootY", _rootY); + const rotation = helper.number("stanek.canPlaceFragment", "rotation", _rotation); + const fragmentId = helper.number("stanek.canPlaceFragment", "fragmentId", _fragmentId); + helper.updateDynamicRam("canPlaceFragment", getRamCost(player, "stanek", "canPlaceFragment")); + checkStanekAPIAccess("canPlaceFragment"); const fragment = FragmentById(fragmentId); - if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.canPlace", `Invalid fragment id: ${fragmentId}`); + if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.canPlaceFragment", `Invalid fragment id: ${fragmentId}`); const can = staneksGift.canPlace(rootX, rootY, rotation, fragment); return can; }, - place: function (_rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean { - const rootX = helper.number("stanek.place", "rootX", _rootX); - const rootY = helper.number("stanek.place", "rootY", _rootY); - const rotation = helper.number("stanek.place", "rotation", _rotation); - const fragmentId = helper.number("stanek.place", "fragmentId", _fragmentId); - helper.updateDynamicRam("place", getRamCost(player, "stanek", "place")); - checkStanekAPIAccess("place"); + placeFragment: function (_rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean { + const rootX = helper.number("stanek.placeFragment", "rootX", _rootX); + const rootY = helper.number("stanek.placeFragment", "rootY", _rootY); + const rotation = helper.number("stanek.placeFragment", "rotation", _rotation); + const fragmentId = helper.number("stanek.placeFragment", "fragmentId", _fragmentId); + helper.updateDynamicRam("placeFragment", getRamCost(player, "stanek", "placeFragment")); + checkStanekAPIAccess("placeFragment"); const fragment = FragmentById(fragmentId); - if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.place", `Invalid fragment id: ${fragmentId}`); + if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.placeFragment", `Invalid fragment id: ${fragmentId}`); return staneksGift.place(rootX, rootY, rotation, fragment); }, - get: function (_rootX: unknown, _rootY: unknown): IActiveFragment | undefined { - const rootX = helper.number("stanek.get", "rootX", _rootX); - const rootY = helper.number("stanek.get", "rootY", _rootY); - helper.updateDynamicRam("get", getRamCost(player, "stanek", "get")); - checkStanekAPIAccess("get"); + getFragment: function (_rootX: unknown, _rootY: unknown): IActiveFragment | undefined { + const rootX = helper.number("stanek.getFragment", "rootX", _rootX); + const rootY = helper.number("stanek.getFragment", "rootY", _rootY); + helper.updateDynamicRam("getFragment", getRamCost(player, "stanek", "getFragment")); + checkStanekAPIAccess("getFragment"); const fragment = staneksGift.findFragment(rootX, rootY); if (fragment !== undefined) return fragment.copy(); return undefined; }, - remove: function (_rootX: unknown, _rootY: unknown): boolean { - const rootX = helper.number("stanek.remove", "rootX", _rootX); - const rootY = helper.number("stanek.remove", "rootY", _rootY); - helper.updateDynamicRam("remove", getRamCost(player, "stanek", "remove")); - checkStanekAPIAccess("remove"); + removeFragment: function (_rootX: unknown, _rootY: unknown): boolean { + const rootX = helper.number("stanek.removeFragment", "rootX", _rootX); + const rootY = helper.number("stanek.removeFragment", "rootY", _rootY); + helper.updateDynamicRam("removeFragment", getRamCost(player, "stanek", "removeFragment")); + checkStanekAPIAccess("removeFragment"); return staneksGift.delete(rootX, rootY); }, }; diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 49393dca4..12d741e27 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -4066,14 +4066,14 @@ interface Stanek { * RAM cost: 0.4 GB * @returns The width of the gift. */ - width(): number; + giftWidth(): number; /** * Stanek's Gift height. * @remarks * RAM cost: 0.4 GB * @returns The height of the gift. */ - height(): number; + giftHeight(): number; /** * Charge a fragment, increasing its power. @@ -4083,7 +4083,7 @@ interface Stanek { * @param rootY - rootY Root Y against which to align the top left of the fragment. * @returns Promise that lasts until the charge action is over. */ - charge(rootX: number, rootY: number): Promise; + chargeFragment(rootX: number, rootY: number): Promise; /** * List possible fragments. @@ -4108,7 +4108,7 @@ interface Stanek { * @remarks * RAM cost: 0 GB */ - clear(): void; + clearGift(): void; /** * Check if fragment can be placed at specified location. @@ -4121,7 +4121,7 @@ interface Stanek { * @param fragmentId - fragmentId ID of the fragment to place. * @returns true if the fragment can be placed at that position. false otherwise. */ - canPlace(rootX: number, rootY: number, rotation: number, fragmentId: number): boolean; + canPlaceFragment(rootX: number, rootY: number, rotation: number, fragmentId: number): boolean; /** * Place fragment on Stanek's Gift. * @remarks @@ -4133,7 +4133,7 @@ interface Stanek { * @param fragmentId - ID of the fragment to place. * @returns true if the fragment can be placed at that position. false otherwise. */ - place(rootX: number, rootY: number, rotation: number, fragmentId: number): boolean; + placeFragment(rootX: number, rootY: number, rotation: number, fragmentId: number): boolean; /** * Get placed fragment at location. * @remarks @@ -4143,7 +4143,7 @@ interface Stanek { * @param rootY - Y against which to align the top left of the fragment. * @returns The fragment at [rootX, rootY], if any. */ - get(rootX: number, rootY: number): ActiveFragment | undefined; + getFragment(rootX: number, rootY: number): ActiveFragment | undefined; /** * Remove fragment at location. @@ -4154,7 +4154,7 @@ interface Stanek { * @param rootY - Y against which to align the top left of the fragment. * @returns The fragment at [rootX, rootY], if any. */ - remove(rootX: number, rootY: number): boolean; + removeFragment(rootX: number, rootY: number): boolean; } /**