-
Notifications
You must be signed in to change notification settings - Fork 1
/
WeaponHelper.ts
50 lines (47 loc) · 1.88 KB
/
WeaponHelper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Proficiencies } from "../../../../../PF2eCoreLib/Proficiencies";
import {
IsWeapon,
Weapon,
} from "../../../../../PF2eCoreLib/PlayerCharacter/Weapon";
import { WeaponProficiencies } from "../../../../../PF2eCoreLib/PlayerCharacter/WeaponProficiencies";
import Store from "../../../../../store/Store";
// TODO [#31]: Write TESTS for WeaponHelper.ts!
export function GetProficiencyForWeapon(weapon: Weapon): Proficiencies {
const state = Store.getState();
const proficiencies = state.playerCharacter.weaponProficiencies;
switch (weapon.weaponCategory) {
case "Other":
proficiencies.Other.forEach((customProficiency) => {
// TODO [#32]: Make Other weapon proficiency and weapon name not need to match
// i.e.Currently you need to have +1 Shortsword as a weapon name and Other proficiency for it to match here.
// This will be tricky.
if (customProficiency.description === weapon.name) {
return customProficiency.proficiency;
}
});
return Proficiencies.Untrained;
case "Unarmed":
return proficiencies.Unarmed;
case "Simple":
return proficiencies.Simple;
case "Martial":
return proficiencies.Martial;
default:
return Proficiencies.Untrained;
}
}
export function CurrentPCWeaponProficiencies(): WeaponProficiencies {
const state = Store.getState();
return state.playerCharacter.weaponProficiencies;
}
export function getWeaponsFromInventory(): string[] {
const state = Store.getState();
let weaponsInInventory: string[] = [];
const weapons: Weapon[] = state.playerCharacter.inventory.items.filter<Weapon>(
IsWeapon
);
weapons.forEach((weapon) => {
weaponsInInventory.push(weapon.name);
});
return weaponsInInventory;
}