Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathund authored Aug 31, 2024
2 parents 95a8274 + a6c6550 commit da17826
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/structures/SkyBlock/SkyblockMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,65 @@ export class MemberStats {
}
}

class SkyblockMemberMinion {
t1: boolean;
t2: boolean;
t3: boolean;
t4: boolean;
t5: boolean;
t6: boolean;
t7: boolean;
t8: boolean;
t9: boolean;
t10: boolean;
t11: boolean;
t12: boolean;
[key: string]: boolean;
constructor(data: number[]) {
this.t1 = false;
this.t2 = false;
this.t3 = false;
this.t4 = false;
this.t5 = false;
this.t6 = false;
this.t7 = false;
this.t8 = false;
this.t9 = false;
this.t10 = false;
this.t11 = false;
this.t12 = false;
data.forEach((tier) => {
if (1 <= tier && 12 >= tier) {
this[`t${tier}`] = true;
}
});
}
}

class SkyblockMemberMinions {
[key: string]: SkyblockMemberMinion;
constructor(data: string[]) {
const parsed = this.#parse(data);
Object.keys(parsed).forEach((minion) => {
this[minion] = new SkyblockMemberMinion(parsed[minion]);
});
}

#parse(data: string[]): { [key: string]: number[] } {
return data.reduce((acc: { [key: string]: number[] }, item: string) => {
const lastUnderscoreIndex = item.lastIndexOf('_');
if (-1 === lastUnderscoreIndex) return acc;
const name = item.substring(0, lastUnderscoreIndex);
const number = item.substring(lastUnderscoreIndex + 1);
const num = parseInt(number, 10);
if (isNaN(num)) return acc;
if (!acc[name]) acc[name] = [];
acc[name].push(num);
return acc;
}, {});
}
}

class SkyblockMember {
uuid: string;
gameMode: string | null;
Expand Down Expand Up @@ -192,6 +251,7 @@ class SkyblockMember {
pets: SkyblockPet[];
jacob: JacobData;
chocolate: ChocolateFactoryData;
minions: SkyblockMemberMinions;
getArmor: () => Promise<Armor>;
getWardrobe: () => Promise<SkyblockInventoryItem[]>;
getEnderChest: () => Promise<SkyblockInventoryItem[]>;
Expand Down Expand Up @@ -228,6 +288,7 @@ class SkyblockMember {
this.pets = data.m?.pets_data?.pets ? data.m.pets_data.pets.map((pet: any) => new SkyblockPet(pet)) : [];
this.jacob = getJacobData(data.m);
this.chocolate = getChocolateFactory(data.m);
this.minions = new SkyblockMemberMinions(data.m?.player_data?.crafted_generators ?? []);
this.getArmor = async () => {
const base64 = data.m.inventory.inv_armor;
const decoded = await decode(base64.data);
Expand Down

0 comments on commit da17826

Please sign in to comment.