2019-01-18 18:57:21 +01:00
|
|
|
import { Crimes } from "./Crimes";
|
2021-05-01 09:17:31 +02:00
|
|
|
import { Crime } from "./Crime";
|
2019-02-22 03:26:28 +01:00
|
|
|
import { IPlayer } from "../PersonObjects/IPlayer";
|
2019-01-20 23:57:38 +01:00
|
|
|
|
2021-09-25 20:42:57 +02:00
|
|
|
import { dialogBoxCreate } from "../ui/React/DialogBox";
|
2019-01-18 18:57:21 +01:00
|
|
|
|
2021-05-01 09:17:31 +02:00
|
|
|
export function determineCrimeSuccess(p: IPlayer, type: string): boolean {
|
2021-09-05 01:09:30 +02:00
|
|
|
let chance = 0;
|
|
|
|
let found = false;
|
2022-01-16 01:45:03 +01:00
|
|
|
for (const i of Object.keys(Crimes)) {
|
2021-09-05 01:09:30 +02:00
|
|
|
const crime = Crimes[i];
|
|
|
|
if (crime.type == type) {
|
|
|
|
chance = crime.successRate(p);
|
|
|
|
found = true;
|
|
|
|
break;
|
2019-01-15 04:34:04 +01:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2019-01-15 04:34:04 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
if (!found) {
|
2021-10-01 16:39:09 +02:00
|
|
|
dialogBoxCreate(`ERR: Unrecognized crime type: ${type} This is probably a bug please contact the developer`);
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-01-15 04:34:04 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
if (Math.random() <= chance) {
|
|
|
|
//Success
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
//Failure
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-15 04:34:04 +01:00
|
|
|
}
|
|
|
|
|
2021-10-17 05:47:11 +02:00
|
|
|
export function findCrime(roughName: string): Crime | null {
|
|
|
|
roughName = roughName.toLowerCase();
|
2021-09-05 01:09:30 +02:00
|
|
|
if (roughName.includes("shoplift")) {
|
|
|
|
return Crimes.Shoplift;
|
2022-01-28 19:03:40 +01:00
|
|
|
} else if (roughName.includes("rob") && roughName.includes("store")) {
|
2021-09-05 01:09:30 +02:00
|
|
|
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;
|
2022-01-28 19:08:20 +01:00
|
|
|
} else if (roughName.includes("bond") && roughName.includes("forge")) {
|
2021-09-05 01:09:30 +02:00
|
|
|
return Crimes.BondForgery;
|
2022-01-28 19:08:20 +01:00
|
|
|
} else if ((roughName.includes("traffic") || roughName.includes("illegal")) && roughName.includes("arms")) {
|
2021-09-05 01:09:30 +02:00
|
|
|
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;
|
2022-01-27 20:36:06 +01:00
|
|
|
} else if (roughName.includes("assassin")) {
|
2021-09-05 01:09:30 +02:00
|
|
|
return Crimes.Assassination;
|
|
|
|
} else if (roughName.includes("heist")) {
|
|
|
|
return Crimes.Heist;
|
|
|
|
}
|
2019-01-15 04:34:04 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return null;
|
2019-01-15 04:34:04 +01:00
|
|
|
}
|