bitburner-src/src/Crime/CrimeHelpers.ts

62 lines
1.9 KiB
TypeScript
Raw Normal View History

import { Crimes } from "./Crimes";
2021-05-01 09:17:31 +02:00
import { Crime } from "./Crime";
import { IPlayer } from "../PersonObjects/IPlayer";
import { dialogBoxCreate } from "../../utils/DialogBox";
2021-05-01 09:17:31 +02:00
export function determineCrimeSuccess(p: IPlayer, type: string): boolean {
2021-04-30 05:52:56 +02:00
let chance = 0;
let found = false;
for (const i in Crimes) {
2021-04-30 05:52:56 +02:00
const crime = Crimes[i];
if (crime.type == type) {
chance = crime.successRate(p);
found = true;
break;
}
}
if (!found) {
dialogBoxCreate(`ERR: Unrecognized crime type: ${type} This is probably a bug please contact the developer`, false);
2021-05-01 09:17:31 +02:00
return false;
}
if (Math.random() <= chance) {
//Success
return true;
} else {
//Failure
return false;
}
}
2021-05-01 09:17:31 +02:00
export function findCrime(roughName: string): Crime | null {
if (roughName.includes("shoplift")) {
return Crimes.Shoplift;
} else if (roughName.includes("rob") && roughName.includes("store")) {
return Crimes.RobStore;
} else if (roughName.includes("mug")) {
return Crimes.Mug;
} else if (roughName.includes("larceny")) {
return Crimes.Larceny;
} else if (roughName.includes("drugs")) {
return Crimes.DealDrugs;
} else if (roughName.includes("bond") && roughName.includes("forge")) {
return Crimes.BondForgery;
} else if (roughName.includes("traffick") && roughName.includes("arms")) {
return Crimes.TraffickArms;
} else if (roughName.includes("homicide")) {
return Crimes.Homicide;
} else if (roughName.includes("grand") && roughName.includes("auto")) {
return Crimes.GrandTheftAuto;
} else if (roughName.includes("kidnap")) {
return Crimes.Kidnap;
} else if (roughName.includes("assassinate")) {
return Crimes.Assassination;
} else if (roughName.includes("heist")) {
return Crimes.Heist;
}
return null;
}