feat(character): add mounts

This commit is contained in:
Axel Cocat 2022-01-21 14:52:19 +01:00
parent d0eb86daa7
commit b19bd0b0a3
11 changed files with 239 additions and 121 deletions

View file

@ -33,7 +33,14 @@ interface ICustomizationOption {
choiceId: number;
}
const ITEM_CLASS_GEM = 3;
interface IMount {
creatureDisplayId: number;
spell: number;
icon: string;
}
const ItemClassGem = 3;
const SpellMechanicMounted = 21;
const RaceDisplayName = {
1: "Human",
2: "Orc",
@ -66,6 +73,8 @@ export class CharacterController {
private gemItems: { [key: number]: boolean };
private enchantSrcItems: { [key: number]: number };
private itemSocketBonuses: { [key: number]: number };
private mountSpells: number[];
private mountBySpellId: { [key: number]: IMount };
public constructor(armory: Armory) {
this.armory = armory;
@ -94,7 +103,7 @@ export class CharacterController {
}
this.gemItems = {};
for await (const row of this.armory.dbc.item().filter(item => item.classId === ITEM_CLASS_GEM)) {
for await (const row of this.armory.dbc.item().filter(item => item.classId === ItemClassGem)) {
this.gemItems[row.id] = true;
}
@ -108,6 +117,26 @@ export class CharacterController {
for (const row of rows as RowDataPacket[]) {
this.itemSocketBonuses[row.entry] = row.socketBonus;
}
const mountSpells = await this.armory.dbc.spell()
.filter(m => m.mechanic === SpellMechanicMounted)
.toArray();
this.mountSpells = mountSpells.map(spell => spell.id);
this.mountBySpellId = {};
for (const spell of mountSpells) {
const mount = await this.armory.dbc.mount().find(m => m.sourceSpellId === spell.id);
const icon = await this.armory.dbc.spellIcon().find(icon => icon.id === spell.spellIconId);
if (mount !== undefined) {
const display = await this.armory.dbc.mountDisplay().find(d => d.mountId === mount.id);
if (display !== undefined) {
this.mountBySpellId[spell.id] = {
creatureDisplayId: display.creatureDisplayInfoId,
spell: spell.id,
icon: this.processSpellIconTexture(icon?.textureFilename ?? ""),
};
}
}
}
}
public async character(req: express.Request, res: express.Response): Promise<void> {
@ -136,6 +165,7 @@ export class CharacterController {
(row as any).enchantments = this.filterEnchantments(row.itemEntry, row.enchantments);
return row;
});
const mounts = await this.getMounts(realmName, charData.guid);
res.render("character.html", {
title: `Armory - ${charName}`,
@ -148,6 +178,7 @@ export class CharacterController {
characterModelItems: await this.getModelViewerItems(equipmentData, charData.class),
customizationOptions: customization,
equipment,
mounts,
}),
});
@ -221,6 +252,18 @@ export class CharacterController {
return rows as RowDataPacket[] as IEquipmentData[];
}
private async getMounts(realm: string, charGuid: number): Promise<IMount[]> {
const [rows, fields] = await this.armory.getCharactersDb(realm).query(`
SELECT spell
FROM character_spell
WHERE guid = ? AND spell IN (?)
`, [charGuid, this.mountSpells]);
return (rows as RowDataPacket[])
.map(row => this.mountBySpellId[row.spell])
.filter(m => m !== undefined);
}
private async getModelViewerItems(equipmentData: IEquipmentData[], charClass: number): Promise<number[][]> {
if (charClass !== 3) {
// Keep ranged weapon only if the character is a hunter