Skip to content

Commit 11a858a

Browse files
committed
chore: Contract creation refactoring
I'm going to resume this tomorrow, but I'm adding support for specific items (number 3 in the new enum, as it's currently incorrect). Ref #551
1 parent 6b53d2e commit 11a858a

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

components/statemachines/contractCreation.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ import type { MissionManifestObjective, RepositoryId } from "../types/types"
2020
import { randomUUID } from "crypto"
2121
import assert from "assert"
2222

23+
/**
24+
* The player gets a choice of which kill method the contract should be created with.
25+
* It has the following 4 levels of granularity.
26+
* I tried to find a corresponding internal enum from the SDK's `Glacier.h`, but to no avail.
27+
*/
28+
export const enum RequiredKillMethodType {
29+
/** Any method. */
30+
Any = 0,
31+
/** Pistol, fiberwire, shotgun, explosive, any thrown, any melee, any poison. */
32+
BroadMethod = 1,
33+
/** A specific method but not a specific item. consumed_poison, injected_poison, accident_*. Keyed off `KillMethodStrict`. */
34+
SpecificMethod = 2,
35+
/** A specific item (e.g. screwdriver, or lack thereof in the case of unarmed aka a neck snap). */
36+
SpecificRepositoryId = 3,
37+
}
38+
2339
/**
2440
* The payload provided to the game for each target in the create menu route.
2541
*/
@@ -31,7 +47,7 @@ export type ContractCreationNpcTargetPayload = {
3147
KillMethodBroad: string
3248
KillMethodStrict: string
3349
RequiredKillMethod: string
34-
RequiredKillMethodType: number
50+
RequiredKillMethodType: RequiredKillMethodType
3551
}
3652
Outfit: {
3753
RepositoryId: string
@@ -415,7 +431,7 @@ export function genStateMachineKillSuccessCondition(
415431
export function weaponToKillMethod(weapon: Weapon): ContractKillMethod {
416432
const type = weapon.RequiredKillMethodType
417433

418-
if (type === 0) {
434+
if (type === RequiredKillMethodType.Any) {
419435
return ContractKillMethod.Any
420436
}
421437

@@ -435,29 +451,33 @@ export function weaponToKillMethod(weapon: Weapon): ContractKillMethod {
435451
case "fiberwire":
436452
return ContractKillMethod.FiberWire
437453
case "throw": {
438-
return type === 1
454+
return type === RequiredKillMethodType.BroadMethod
439455
? ContractKillMethod.AnyThrown
440456
: ContractKillMethod.ObjectThrown
441457
}
442458
case "melee_lethal": {
443-
return type === 1
459+
return type === RequiredKillMethodType.BroadMethod
444460
? ContractKillMethod.AnyMelee
445461
: ContractKillMethod.ObjectMelee
446462
}
447463
case "poison": {
448-
if (weapon.KillMethodStrict === "consumed_poison" && type === 2) {
464+
if (
465+
weapon.KillMethodStrict === "consumed_poison" &&
466+
type === RequiredKillMethodType.SpecificMethod
467+
) {
449468
return ContractKillMethod.ConsumedPoison
450469
}
451470

452471
if (
453472
weapon.KillMethodStrict === "injected_poison" &&
454-
weapon.RequiredKillMethodType === 2
473+
weapon.RequiredKillMethodType ===
474+
RequiredKillMethodType.SpecificMethod
455475
) {
456476
return ContractKillMethod.InjectedPoison
457477
}
458478

459479
assert(
460-
type === 1,
480+
type === RequiredKillMethodType.BroadMethod,
461481
`Unhandled poison: ${weapon.KillMethodStrict} ${type}`,
462482
)
463483

0 commit comments

Comments
 (0)