pogo-data-generator
Version:
Pokemon GO project data generator
123 lines (122 loc) • 4.93 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const pogo_protos_1 = require("@na-ji/pogo-protos");
const Masterfile_1 = __importDefault(require("./Masterfile"));
class Invasion extends Masterfile_1.default {
constructor(options) {
super();
this.options = options;
this.parsedInvasions = {};
}
async customInvasions(override = false) {
try {
if (this.options.customInvasions === true ||
(this.options.customInvasions === undefined && override)) {
return this.fetch('https://raw.githubusercontent.com/WatWowMap/Masterfile-Generator/master/custom-invasions.json');
}
else if (this.options.customInvasions) {
return this.options.customInvasions;
}
else {
return {};
}
}
catch (e) {
console.warn(e, 'Unable to get custom invasions');
}
}
mergeInvasions(existing, custom = {}) {
const invasions = existing;
Object.entries(custom).forEach(([key, info]) => {
if (invasions[key] === undefined) {
invasions[key] = info;
}
else {
invasions[key] = {
...invasions[key],
...info,
};
}
});
return invasions;
}
formatGrunts(character) {
const base = character
.replace('CHARACTER_', '')
.replace('_MALE', '')
.replace('_FEMALE', '');
const type = base
.replace('EXECUTIVE_', '')
.replace('_GRUNT', '')
.replace('EVENT_', '');
const grunt = base.split('_').length > 1
? base.replace(`${type}`, '').replace('_', '')
: base;
let gender = character.includes('MALE') || character.includes('FEMALE') ? 1 : 0;
if (character.includes('FEMALE')) {
gender = 2;
}
return {
type: type === 'GRUNT' ? 'Mixed' : this.capitalize(type),
gender: this.options.genderString ? this.genders[gender] : gender,
grunt: this.capitalize(grunt),
};
}
invasions(invasionData) {
const positions = [
this.customFieldNames.first || 'first',
this.customFieldNames.second || 'second',
this.customFieldNames.third || 'third',
];
Object.entries(pogo_protos_1.Rpc.EnumWrapper.InvasionCharacter).forEach((proto) => {
try {
const [name, id] = proto;
if ((this.options.includeBalloons && name.includes('BALLOON')) ||
!name.includes('BALLOON_')) {
const pogoInfo = invasionData[id];
this.parsedInvasions[id] = {
id: +id,
...this.formatGrunts(name),
proto: name,
active: !!pogoInfo?.active,
firstReward: false,
secondReward: false,
thirdReward: false,
};
if (pogoInfo && pogoInfo.active) {
this.parsedInvasions[id].firstReward =
pogoInfo.lineup.rewards.includes(0);
this.parsedInvasions[id].secondReward =
pogoInfo.lineup.rewards.includes(1);
this.parsedInvasions[id].thirdReward =
pogoInfo.lineup.rewards.includes(2);
this.parsedInvasions[id].encounters = [];
positions.forEach((position, i) => {
pogoInfo.lineup.team[i].forEach((pkmn) => {
this.parsedInvasions[id].encounters.push({
id: pkmn.id,
formId: pkmn.form,
position,
});
});
this.parsedInvasions[id].encounters.sort((a, b) => a.id - b.id);
this.parsedInvasions[id].encounters.sort((a, b) => a.position.localeCompare(b.position));
});
}
else if (this.options.placeholderData) {
this.parsedInvasions[id].encounters = positions.map((position) => ({
position,
}));
}
}
}
catch (e) {
console.warn(e, proto);
}
});
}
}
exports.default = Invasion;