@skullandbonestools/snbdata
Version:
Inofficial data package for the Skull and Bones game by Ubisoft.
115 lines • 5.67 kB
JavaScript
import itemsData from '../../data/items.json';
import { Contracts } from './contracts';
import { Events } from './events';
import { Factions } from './factions';
import { Materials } from './materials';
import { Seasons } from './seasons';
import { WorldEvents } from './worldEvents';
export class Item {
constructor(id, type, season, dateAdded, lastUpdated, tier, blueprint, value, weight, gearScore, projectilesPerShot, damagePerShot, rateOfFire, chargeTime, reloadSpeed, optimalRange, projectileSpeed, timeToTarget, blastRadius, required, requiredRank, perks, rarity, obtainable, event, worldEvent, armor, damageMitigation,
/**
* @deprecated Not actively maintained anymore and may be removed in the future, obtainable field is used in favor
*/
contract, faction, unobtainable) {
this.id = id;
this.type = type;
this.season = season;
this.dateAdded = dateAdded;
this.lastUpdated = lastUpdated;
this.tier = tier;
this.blueprint = blueprint;
this.value = value;
this.weight = weight;
this.gearScore = gearScore;
this.projectilesPerShot = projectilesPerShot;
this.damagePerShot = damagePerShot;
this.rateOfFire = rateOfFire;
this.chargeTime = chargeTime;
this.reloadSpeed = reloadSpeed;
this.optimalRange = optimalRange;
this.projectileSpeed = projectileSpeed;
this.timeToTarget = timeToTarget;
this.blastRadius = blastRadius;
this.required = required;
this.requiredRank = requiredRank;
this.perks = perks;
this.rarity = rarity;
this.obtainable = obtainable;
this.event = event;
this.worldEvent = worldEvent;
this.armor = armor;
this.damageMitigation = damageMitigation;
this.contract = contract;
this.faction = faction;
this.unobtainable = unobtainable;
}
static fromRawData(rawData) {
const season = rawData.season;
const event = Array.isArray(rawData.event)
? rawData.event.map((_event) => Events[_event])
: Events[rawData.event];
const contract = rawData.contract;
const worldEvent = Array.isArray(rawData.worldEvent)
? rawData.worldEvent.map((_worldEvent) => WorldEvents[_worldEvent])
: WorldEvents[rawData.worldEvent];
const required = rawData.required ? new Map() : undefined;
if (required) {
for (const [requiredKey, quantity] of Object.entries(rawData.required)) {
const requiredMaterial = requiredKey;
required.set(Materials[requiredMaterial], quantity);
}
}
const faction = rawData.faction;
return new Item(rawData.id, rawData.type, Seasons[season], new Date(rawData.dateAdded), new Date(rawData.lastUpdated), rawData.tier, rawData.blueprint ?? undefined, rawData.value ?? undefined, rawData.weight ?? undefined, rawData.gearScore ?? undefined, rawData.projectilesPerShot ?? undefined, rawData.damagePerShot ?? undefined, rawData.rateOfFire ?? undefined, rawData.chargeTime ?? undefined, rawData.reloadSpeed ?? undefined, rawData.optimalRange ?? undefined, rawData.projectileSpeed ?? undefined, rawData.timeToTarget ?? undefined, rawData.blastRadius ?? undefined, required, rawData.requiredRank ?? undefined, rawData.perks ?? [], rawData.rarity ?? undefined, rawData.obtainable ?? undefined, event ?? undefined, worldEvent ?? undefined, rawData.armor ?? undefined, rawData.damageMitigation ?? undefined, rawData.contract ? Contracts[contract] : undefined, rawData.faction ? Factions[faction] : undefined, rawData.unobtainable ?? false);
}
static updateObtainableWithItems(key, rawData, items) {
if (!rawData.obtainable)
return;
if (Array.isArray(rawData.obtainable)) {
const obtainable = new Array();
for (const obtainableKey of rawData.obtainable) {
if (Array.isArray(obtainableKey)) {
const obtainableGroup = new Array();
for (const subKey of obtainableKey) {
const obtainableItem = items[subKey];
if (obtainableItem && obtainableItem.type === "chest") {
obtainableGroup.push(obtainableItem);
}
else {
obtainableGroup.push(subKey);
}
}
obtainable.push(obtainableGroup);
}
else {
const obtainableItem = items[obtainableKey];
if (obtainableItem && obtainableItem.type === "chest") {
obtainable.push(obtainableItem);
}
else {
obtainable.push(obtainableKey);
}
}
}
items[key].obtainable = obtainable;
}
else {
const obtainableItem = items[rawData.obtainable];
if (obtainableItem && obtainableItem.type === "chest") {
items[key].obtainable = obtainableItem;
}
}
}
static loadItems() {
const items = {};
for (const [key, value] of Object.entries(itemsData)) {
items[key] = Item.fromRawData(value);
}
for (const [key, value] of Object.entries(itemsData)) {
Item.updateObtainableWithItems(key, value, items);
}
return items;
}
}
export const Items = Item.loadItems();
//# sourceMappingURL=items.js.map