Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 6x 6x 7x 8x 8x 2x 2x 6x 6x 9x 9x 10x 20x 20x 2x 2x 18x 9x | import {AgentInventory, ItemWithBreakdown, KeyInfo} from '../../types/Types'
type InventoryField = 'resonators' | 'weapons' | 'mods' | 'cubes' | 'boosts'
export class InventoryHelper {
public aggregateKeys(agents: AgentInventory[]): Map<string, KeyInfo> {
const result = new Map<string, KeyInfo>()
for (const agent of agents) {
for (const key of agent.keys) {
const existing = result.get(key.guid)
if (existing) {
existing.total += key.total
existing.agentCounts.set(
agent.name,
(existing.agentCounts.get(agent.name) ?? 0) + key.total
)
} else {
result.set(key.guid, {
portal: {guid: key.guid, title: key.title, lat: key.lat, lng: key.lng},
total: key.total,
agentCounts: new Map([[agent.name, key.total]]),
})
}
}
}
return result
}
public aggregateItems(agents: AgentInventory[], field: InventoryField): Map<string, ItemWithBreakdown> {
const result = new Map<string, ItemWithBreakdown>()
for (const agent of agents) {
for (const [key, count] of Object.entries(agent[field])) {
const existing = result.get(key)
if (existing) {
existing.total += count
existing.agents.set(agent.name, (existing.agents.get(agent.name) ?? 0) + count)
} else {
result.set(key, {total: count, agents: new Map([[agent.name, count]])})
}
}
}
return result
}
}
|