unknown-ify the gang API.

This commit is contained in:
Olivier Gagnon 2022-03-29 20:12:55 -04:00
parent bbbaa89f74
commit c1401bef27

@ -1,5 +1,5 @@
import { FactionNames } from '../Faction/data/FactionNames'; import { FactionNames } from "../Faction/data/FactionNames";
import { GangConstants } from '../Gang/data/Constants'; import { GangConstants } from "../Gang/data/Constants";
import { INetscriptHelper } from "./INetscriptHelper"; import { INetscriptHelper } from "./INetscriptHelper";
import { IPlayer } from "../PersonObjects/IPlayer"; import { IPlayer } from "../PersonObjects/IPlayer";
import { getRamCost } from "../Netscript/RamCostGenerator"; import { getRamCost } from "../Netscript/RamCostGenerator";
@ -48,7 +48,8 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
}; };
return { return {
createGang: function (faction: string): boolean { createGang: function (_faction: unknown): boolean {
const faction = helper.string("createGang", "faction", _faction);
helper.updateDynamicRam("createGang", getRamCost(player, "gang", "createGang")); helper.updateDynamicRam("createGang", getRamCost(player, "gang", "createGang"));
// this list is copied from Faction/ui/Root.tsx // this list is copied from Faction/ui/Root.tsx
@ -101,12 +102,13 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return cpy; return cpy;
}, },
getMemberInformation: function (name: any): GangMemberInfo { getMemberInformation: function (_memberName: unknown): GangMemberInfo {
const memberName = helper.string("getMemberInformation", "memberName", _memberName);
helper.updateDynamicRam("getMemberInformation", getRamCost(player, "gang", "getMemberInformation")); helper.updateDynamicRam("getMemberInformation", getRamCost(player, "gang", "getMemberInformation"));
checkGangApiAccess("getMemberInformation"); checkGangApiAccess("getMemberInformation");
const gang = player.gang; const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang"); if (gang === null) throw new Error("Should not be called without Gang");
const member = getGangMember("getMemberInformation", name); const member = getGangMember("getMemberInformation", memberName);
return { return {
name: member.name, name: member.name,
task: member.task, task: member.task,
@ -161,16 +163,17 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
if (gang === null) throw new Error("Should not be called without Gang"); if (gang === null) throw new Error("Should not be called without Gang");
return gang.canRecruitMember(); return gang.canRecruitMember();
}, },
recruitMember: function (name: any): boolean { recruitMember: function (_memberName: unknown): boolean {
const memberName = helper.string("recruitMember", "memberName", _memberName);
helper.updateDynamicRam("recruitMember", getRamCost(player, "gang", "recruitMember")); helper.updateDynamicRam("recruitMember", getRamCost(player, "gang", "recruitMember"));
checkGangApiAccess("recruitMember"); checkGangApiAccess("recruitMember");
const gang = player.gang; const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang"); if (gang === null) throw new Error("Should not be called without Gang");
const recruited = gang.recruitMember(name); const recruited = gang.recruitMember(memberName);
if (recruited) { if (recruited) {
workerScript.log("gang.recruitMember", () => `Successfully recruited Gang Member '${name}'`); workerScript.log("gang.recruitMember", () => `Successfully recruited Gang Member '${memberName}'`);
} else { } else {
workerScript.log("gang.recruitMember", () => `Failed to recruit Gang Member '${name}'`); workerScript.log("gang.recruitMember", () => `Failed to recruit Gang Member '${memberName}'`);
} }
return recruited; return recruited;
@ -184,7 +187,9 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
tasks.unshift("Unassigned"); tasks.unshift("Unassigned");
return tasks; return tasks;
}, },
setMemberTask: function (memberName: any, taskName: any): boolean { setMemberTask: function (_memberName: unknown, _taskName: unknown): boolean {
const memberName = helper.string("setMemberTask", "memberName", _memberName);
const taskName = helper.string("setMemberTask", "taskName", _taskName);
helper.updateDynamicRam("setMemberTask", getRamCost(player, "gang", "setMemberTask")); helper.updateDynamicRam("setMemberTask", getRamCost(player, "gang", "setMemberTask"));
checkGangApiAccess("setMemberTask"); checkGangApiAccess("setMemberTask");
const member = getGangMember("setMemberTask", memberName); const member = getGangMember("setMemberTask", memberName);
@ -193,9 +198,10 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
if (!gang.getAllTaskNames().includes(taskName)) { if (!gang.getAllTaskNames().includes(taskName)) {
workerScript.log( workerScript.log(
"gang.setMemberTask", "gang.setMemberTask",
() => `Failed to assign Gang Member '${memberName}' to Invalid task '${taskName}'. '${memberName}' is now Unassigned`, () =>
`Failed to assign Gang Member '${memberName}' to Invalid task '${taskName}'. '${memberName}' is now Unassigned`,
); );
return member.assignToTask('Unassigned'); return member.assignToTask("Unassigned");
} }
const success = member.assignToTask(taskName); const success = member.assignToTask(taskName);
if (success) { if (success) {
@ -212,7 +218,8 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return success; return success;
}, },
getTaskStats: function (taskName: any): GangTaskStats { getTaskStats: function (_taskName: unknown): GangTaskStats {
const taskName = helper.string("getTaskStats", "taskName", _taskName);
helper.updateDynamicRam("getTaskStats", getRamCost(player, "gang", "getTaskStats")); helper.updateDynamicRam("getTaskStats", getRamCost(player, "gang", "getTaskStats"));
checkGangApiAccess("getTaskStats"); checkGangApiAccess("getTaskStats");
const task = getGangTask("getTaskStats", taskName); const task = getGangTask("getTaskStats", taskName);
@ -225,7 +232,8 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
checkGangApiAccess("getEquipmentNames"); checkGangApiAccess("getEquipmentNames");
return Object.keys(GangMemberUpgrades); return Object.keys(GangMemberUpgrades);
}, },
getEquipmentCost: function (equipName: any): number { getEquipmentCost: function (_equipName: any): number {
const equipName = helper.string("getEquipmentCost", "equipName", _equipName);
helper.updateDynamicRam("getEquipmentCost", getRamCost(player, "gang", "getEquipmentCost")); helper.updateDynamicRam("getEquipmentCost", getRamCost(player, "gang", "getEquipmentCost"));
checkGangApiAccess("getEquipmentCost"); checkGangApiAccess("getEquipmentCost");
const gang = player.gang; const gang = player.gang;
@ -234,14 +242,16 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
if (upg === null) return Infinity; if (upg === null) return Infinity;
return gang.getUpgradeCost(upg); return gang.getUpgradeCost(upg);
}, },
getEquipmentType: function (equipName: any): string { getEquipmentType: function (_equipName: unknown): string {
const equipName = helper.string("getEquipmentType", "equipName", _equipName);
helper.updateDynamicRam("getEquipmentType", getRamCost(player, "gang", "getEquipmentType")); helper.updateDynamicRam("getEquipmentType", getRamCost(player, "gang", "getEquipmentType"));
checkGangApiAccess("getEquipmentType"); checkGangApiAccess("getEquipmentType");
const upg = GangMemberUpgrades[equipName]; const upg = GangMemberUpgrades[equipName];
if (upg == null) return ""; if (upg == null) return "";
return upg.getType(); return upg.getType();
}, },
getEquipmentStats: function (equipName: any): EquipmentStats { getEquipmentStats: function (_equipName: unknown): EquipmentStats {
const equipName = helper.string("getEquipmentStats", "equipName", _equipName);
helper.updateDynamicRam("getEquipmentStats", getRamCost(player, "gang", "getEquipmentStats")); helper.updateDynamicRam("getEquipmentStats", getRamCost(player, "gang", "getEquipmentStats"));
checkGangApiAccess("getEquipmentStats"); checkGangApiAccess("getEquipmentStats");
const equipment = GangMemberUpgrades[equipName]; const equipment = GangMemberUpgrades[equipName];
@ -251,7 +261,9 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
const typecheck: EquipmentStats = equipment.mults; const typecheck: EquipmentStats = equipment.mults;
return Object.assign({}, typecheck) as any; return Object.assign({}, typecheck) as any;
}, },
purchaseEquipment: function (memberName: any, equipName: any): boolean { purchaseEquipment: function (_memberName: unknown, _equipName: unknown): boolean {
const memberName = helper.string("purchaseEquipment", "memberName", _memberName);
const equipName = helper.string("purchaseEquipment", "equipName", _equipName);
helper.updateDynamicRam("purchaseEquipment", getRamCost(player, "gang", "purchaseEquipment")); helper.updateDynamicRam("purchaseEquipment", getRamCost(player, "gang", "purchaseEquipment"));
checkGangApiAccess("purchaseEquipment"); checkGangApiAccess("purchaseEquipment");
const gang = player.gang; const gang = player.gang;
@ -271,28 +283,31 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return res; return res;
}, },
ascendMember: function (name: any): GangMemberAscension | undefined { ascendMember: function (_memberName: unknown): GangMemberAscension | undefined {
const memberName = helper.string("ascendMember", "memberName", _memberName);
helper.updateDynamicRam("ascendMember", getRamCost(player, "gang", "ascendMember")); helper.updateDynamicRam("ascendMember", getRamCost(player, "gang", "ascendMember"));
checkGangApiAccess("ascendMember"); checkGangApiAccess("ascendMember");
const gang = player.gang; const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang"); if (gang === null) throw new Error("Should not be called without Gang");
const member = getGangMember("ascendMember", name); const member = getGangMember("ascendMember", memberName);
if (!member.canAscend()) return; if (!member.canAscend()) return;
return gang.ascendMember(member, workerScript); return gang.ascendMember(member, workerScript);
}, },
getAscensionResult: function (name: any): GangMemberAscension | undefined { getAscensionResult: function (_memberName: unknown): GangMemberAscension | undefined {
const memberName = helper.string("getAscensionResult", "memberName", _memberName);
helper.updateDynamicRam("getAscensionResult", getRamCost(player, "gang", "getAscensionResult")); helper.updateDynamicRam("getAscensionResult", getRamCost(player, "gang", "getAscensionResult"));
checkGangApiAccess("getAscensionResult"); checkGangApiAccess("getAscensionResult");
const gang = player.gang; const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang"); if (gang === null) throw new Error("Should not be called without Gang");
const member = getGangMember("getAscensionResult", name); const member = getGangMember("getAscensionResult", memberName);
if (!member.canAscend()) return; if (!member.canAscend()) return;
return { return {
respect: member.earnedRespect, respect: member.earnedRespect,
...member.getAscensionResults(), ...member.getAscensionResults(),
}; };
}, },
setTerritoryWarfare: function (engage: any): void { setTerritoryWarfare: function (_engage: unknown): void {
const engage = helper.boolean(_engage);
helper.updateDynamicRam("setTerritoryWarfare", getRamCost(player, "gang", "setTerritoryWarfare")); helper.updateDynamicRam("setTerritoryWarfare", getRamCost(player, "gang", "setTerritoryWarfare"));
checkGangApiAccess("setTerritoryWarfare"); checkGangApiAccess("setTerritoryWarfare");
const gang = player.gang; const gang = player.gang;
@ -305,7 +320,8 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
workerScript.log("gang.setTerritoryWarfare", () => "Disengaging in Gang Territory Warfare"); workerScript.log("gang.setTerritoryWarfare", () => "Disengaging in Gang Territory Warfare");
} }
}, },
getChanceToWinClash: function (otherGang: any): number { getChanceToWinClash: function (_otherGang: unknown): number {
const otherGang = helper.string("getChanceToWinClash", "otherGang", _otherGang);
helper.updateDynamicRam("getChanceToWinClash", getRamCost(player, "gang", "getChanceToWinClash")); helper.updateDynamicRam("getChanceToWinClash", getRamCost(player, "gang", "getChanceToWinClash"));
checkGangApiAccess("getChanceToWinClash"); checkGangApiAccess("getChanceToWinClash");
const gang = player.gang; const gang = player.gang;