forked from Bitcoindefi/OpenAO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactions.ts
More file actions
157 lines (134 loc) · 4.3 KB
/
Copy pathfactions.ts
File metadata and controls
157 lines (134 loc) · 4.3 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
export type CharacterFaction = "none" | "armada" | "caos";
export type FactionRankConfig = {
rank: number;
title: string;
minLevel: number;
minScore: number;
rewardItemIds: number[];
};
export type FactionConfig = {
key: Exclude<CharacterFaction, "none">;
enlistNpcId: number;
rewardNpcId: number;
color: string;
ranks: FactionRankConfig[];
restrictedItemIds: number[];
};
const ARMADA_RANKS: FactionRankConfig[] = [
{ rank: 1, title: "Soldado", minLevel: 25, minScore: 100, rewardItemIds: [] },
{ rank: 2, title: "Caballero", minLevel: 30, minScore: 500, rewardItemIds: [] },
{ rank: 3, title: "Capitan", minLevel: 35, minScore: 1000, rewardItemIds: [] },
{
rank: 4,
title: "Protector del Reino",
minLevel: 40,
minScore: 2500,
rewardItemIds: [],
},
{
rank: 5,
title: "Campeon de la Luz",
minLevel: 43,
minScore: 5000,
rewardItemIds: [],
},
];
const CAOS_RANKS: FactionRankConfig[] = [
{ rank: 1, title: "Acolito", minLevel: 25, minScore: 350, rewardItemIds: [] },
{
rank: 2,
title: "Emisario del Caos",
minLevel: 30,
minScore: 1000,
rewardItemIds: [],
},
{ rank: 3, title: "Sanguinario", minLevel: 35, minScore: 2500, rewardItemIds: [] },
{
rank: 4,
title: "Caballero de la Oscuridad",
minLevel: 40,
minScore: 5000,
rewardItemIds: [],
},
{
rank: 5,
title: "Devorador de Almas",
minLevel: 43,
minScore: 10000,
rewardItemIds: [],
},
];
function collectRestrictedItems(ranks: FactionRankConfig[]): number[] {
return Array.from(new Set(ranks.flatMap((rank) => rank.rewardItemIds)));
}
export const FACTIONS: Record<Exclude<CharacterFaction, "none">, FactionConfig> = {
armada: {
key: "armada",
enlistNpcId: 72,
rewardNpcId: 72,
color: "#00AFFF",
ranks: ARMADA_RANKS,
restrictedItemIds: collectRestrictedItems(ARMADA_RANKS),
},
caos: {
key: "caos",
enlistNpcId: 98,
rewardNpcId: 98,
color: "#9B0000",
ranks: CAOS_RANKS,
restrictedItemIds: collectRestrictedItems(CAOS_RANKS),
},
};
export function getFactionConfig(faction: CharacterFaction | undefined | null): FactionConfig | null {
if (!faction || faction === "none") {
return null;
}
return FACTIONS[faction];
}
export function getFactionColor(faction: CharacterFaction | undefined | null): string | null {
return getFactionConfig(faction)?.color ?? null;
}
export function getFactionRankConfig(faction: CharacterFaction, rank: number): FactionRankConfig | null {
return getFactionConfig(faction)?.ranks.find((entry) => entry.rank === rank) ?? null;
}
export function getFactionRankTitle(faction: CharacterFaction, rank: number): string | null {
return getFactionRankConfig(faction, rank)?.title ?? null;
}
export function getMaxEligibleFactionRank(faction: CharacterFaction, level: number, score: number): number {
const config = getFactionConfig(faction);
if (!config) {
return 0;
}
let eligibleRank = 0;
for (const rank of config.ranks) {
if (level >= rank.minLevel && score >= rank.minScore) {
eligibleRank = rank.rank;
}
}
return eligibleRank;
}
export function getFactionRewardItemIdsUpToRank(faction: CharacterFaction, rank: number): number[] {
const config = getFactionConfig(faction);
if (!config || rank <= 0) {
return [];
}
return config.ranks.filter((entry) => entry.rank <= rank).flatMap((entry) => entry.rewardItemIds);
}
export function isFactionRewardItem(itemId: number): boolean {
return Object.values(FACTIONS).some((config) => config.restrictedItemIds.includes(itemId));
}
export function getRequiredFactionForItem(itemId: number): CharacterFaction {
for (const [faction, config] of Object.entries(FACTIONS) as Array<
[Exclude<CharacterFaction, "none">, FactionConfig]
>) {
if (config.restrictedItemIds.includes(itemId)) {
return faction;
}
}
return "none";
}
export function calculateBaseFactionScore(attackerLevel: number, victimLevel: number): number {
void attackerLevel;
void victimLevel;
return 10;
}