feat(character): add equipment tooltips

This commit is contained in:
Axel Cocat 2022-01-04 01:30:33 +01:00
parent 7a9bb172ea
commit 73916950b7
31 changed files with 60862 additions and 17 deletions

View file

@ -14,6 +14,7 @@ export class Armory {
public characterCustomization: CharacterCustomization;
public dbcReader: DbcReader;
public config: Config;
public worldDb: Connection;
private charsDbs: { [key: string]: Connection };
@ -27,14 +28,19 @@ export class Armory {
const app: Express = express();
const listenPort = 48733;
console.log("Loading config...");
this.config = await Config.load();
console.log("Loading data files...");
await this.dbcReader.loadAllFiles();
await this.characterCustomization.loadData();
console.log("Connecting to databases...");
this.worldDb = await createConnection(this.config.worldDatabase);
for (const realm of this.config.realms) {
this.charsDbs[realm.name.toLowerCase()] = await createConnection(realm.database);
}
console.log("Starting server...");
app.engine(".html", handlebarsEngine({
extname: "html",
partialsDir: path.join(process.cwd(), "static", "partials"),
@ -47,6 +53,7 @@ export class Armory {
app.use("/js", express.static(`static/js`));
app.use("/css", express.static(`static/css`));
app.use("/img", express.static(`static/img`));
app.use("/data/mo3", express.static(`data/mo3`));
app.use("/data/meta", express.static(`data/meta`));
app.use("/data/bone", express.static(`data/bone`));
@ -57,6 +64,7 @@ export class Armory {
app.get("/", indexController.index.bind(indexController));
const charsController = new CharacterController(this);
await charsController.load();
app.get("/character/:realm/:name", charsController.character.bind(charsController));
app.listen(listenPort, "0.0.0.0", () => {

View file

@ -16,6 +16,7 @@ export interface IRealmConfig {
export class Config {
public realms: IRealmConfig[];
public worldDatabase: IDatabaseConfig;
private static checkedMissingField: boolean = false;

View file

@ -31,19 +31,56 @@ interface ICustomizationOption {
choiceId: number;
}
const ITEM_CLASS_GEM = 3;
export class CharacterController {
private armory: Armory;
private itemInventoryTypes: { [key: number]: number };
private itemIcons: { [key: number]: number };
private gemItems: { [key: number]: boolean };
private enchantSrcItems: { [key: number]: number };
private itemSocketBonuses: { [key: number]: number };
public constructor(armory: Armory) {
this.armory = armory;
}
public async load(): Promise<void> {
this.itemInventoryTypes = {};
for (const item of armory.dbcReader.dbcItem) {
const retailItem = armory.dbcReader.dbcItemRetail.find(row => row.id === item.id);
for (const item of this.armory.dbcReader.dbcItem) {
const retailItem = this.armory.dbcReader.dbcItemRetail.find(row => row.id === item.id);
if (retailItem !== undefined) {
this.itemInventoryTypes[item.id] = retailItem.inventoryType;
}
}
this.itemIcons = {};
const itemIconsByDisplayInfoId: { [key: number]: number } = {};
for (const row of this.armory.dbcReader.dbcItemDisplayInfo) {
itemIconsByDisplayInfoId[row.id] = row.inventoryIcon0;
}
for (const item of this.armory.dbcReader.dbcItem) {
const icon = itemIconsByDisplayInfoId[item.displayInfoId];
if (icon !== undefined) {
this.itemIcons[item.id] = icon;
}
}
this.gemItems = {};
for (const row of this.armory.dbcReader.dbcItem.filter(item => item.classId === ITEM_CLASS_GEM)) {
this.gemItems[row.id] = true;
}
this.enchantSrcItems = {};
for (const row of this.armory.dbcReader.dbcSpellItemEnchantment) {
this.enchantSrcItems[row.id] = row.srcItemId;
}
this.itemSocketBonuses = {};
let [rows, fields] = await this.armory.worldDb.query("SELECT entry, socketBonus FROM item_template WHERE socketBonus <> 0");
for (const row of rows as RowDataPacket[]) {
this.itemSocketBonuses[row.entry] = row.socketBonus;
}
}
public async character(req: express.Request, res: express.Response): Promise<void> {
@ -62,12 +99,14 @@ export class CharacterController {
res.sendStatus(404);
return;
}
let equipmentData = await this.getEquipmentData(realm, charData.guid);
if (charData.class !== 3) {
// Keep ranged weapon only if the character is a hunter
equipmentData = equipmentData.filter(row => row.slot !== 17);
}
const equipmentData = await this.getEquipmentData(realm, charData.guid);
const customization = await this.getCustomizationOptions(charData);
const equipment = equipmentData.map(row => {
(row as any).icon = this.itemIcons[row.itemEntry];
(row as any).gems = this.getGemsFromEnchantments(row.enchantments);
(row as any).enchantments = this.filterEnchantments(row.itemEntry, row.enchantments);
return row;
});
res.render("character.html", {
title: `Armory - ${charName}`,
@ -78,8 +117,9 @@ export class CharacterController {
gender: charData.gender,
level: charData.level,
online: charData.online === 1,
characterModelItems: this.getModelViewerItems(equipmentData),
characterModelItems: this.getModelViewerItems(equipmentData, charData.class),
customizationOptions: customization,
equipment,
}),
});
}
@ -107,7 +147,11 @@ export class CharacterController {
return rows as RowDataPacket[] as IEquipmentData[];
}
private getModelViewerItems(equipmentData: IEquipmentData[]): number[][] {
private getModelViewerItems(equipmentData: IEquipmentData[], charClass: number): number[][] {
if (charClass !== 3) {
// Keep ranged weapon only if the character is a hunter
equipmentData = equipmentData.filter(row => row.slot !== 17);
}
const visibleEquipment = equipmentData.
filter(item =>
[0, 2, 3, 4, 5, 6, 7, 8, 9, 14, 15, 16, 17, 18].includes(item.slot) && // visible slots
@ -131,6 +175,26 @@ export class CharacterController {
return items;
}
private parseEnchantmentsString(enchantments: string): number[] {
return enchantments
.trim()
.split(" ")
.map(enchant => parseInt(enchant))
.filter(enchant => enchant !== 0);
}
private getGemsFromEnchantments(enchantments: string): number[] {
return this.parseEnchantmentsString(enchantments)
.filter(enchant => enchant in this.enchantSrcItems && this.enchantSrcItems[enchant] in this.gemItems)
.map(enchant => this.enchantSrcItems[enchant]);
}
private filterEnchantments(item: number, enchantments: string): number[] {
const socketBonus = this.itemSocketBonuses[item];
return this.parseEnchantmentsString(enchantments)
.filter(enchant => enchant in this.enchantSrcItems && !(this.enchantSrcItems[enchant] in this.gemItems) && enchant !== socketBonus);
}
private async getCustomizationOptions(charData: ICharacterData): Promise<ICustomizationOption[]> {
const data = this.armory.characterCustomization.getCharacterCustomizationData(charData.race, charData.gender);
const options = [];

View file

@ -47,6 +47,11 @@ export interface IItemModifiedAppearanceDbc {
transmogSourceTypeEnum: number;
}
export interface IItemDisplayInfoDbc {
id: number;
inventoryIcon0: number;
}
export interface IMountDbc {
nameLang: string;
sourceTextLang: string;
@ -75,14 +80,21 @@ export interface ISpellDbc {
mechanic: number;
}
export interface ISpellItemEnchantmentDbc {
id: number;
srcItemId: number;
}
export class DbcReader {
public dbcItem: IItemDbc[];
public dbcItemRetail: IItemRetailDbc[];
public dbcItemAppearance: IItemAppearanceDbc[];
public dbcItemModifiedAppearance: IItemModifiedAppearanceDbc[];
public dbcItemDisplayInfo: IItemDisplayInfoDbc[];
public dbcMount: IMountDbc[];
public dbcMountDisplay: IMountXDisplayDbc[];
public dbcSpell: ISpellDbc[];
public dbcSpellItemEnchantment: ISpellItemEnchantmentDbc[];
public readDbcFile<T>(file: string): Promise<T[]> {
return new Promise((res, rej) => {
@ -108,8 +120,10 @@ export class DbcReader {
this.dbcItemRetail = await this.readDbcFile<IItemRetailDbc>(path.join(dir, "Item_9.2.0_41462.csv"));
this.dbcItemAppearance = await this.readDbcFile<IItemAppearanceDbc>(path.join(dir, "ItemAppearance_9.2.0_41462.csv"));
this.dbcItemModifiedAppearance = await this.readDbcFile<IItemModifiedAppearanceDbc>(path.join(dir, "ItemModifiedAppearance_9.2.0_41462.csv"));
this.dbcItemDisplayInfo = await this.readDbcFile<IItemDisplayInfoDbc>(path.join(dir, "ItemDisplayInfo_3.3.5_12340.csv"));
this.dbcMount = await this.readDbcFile<IMountDbc>(path.join(dir, "Mount_9.2.0_41462.csv"));
this.dbcMountDisplay = await this.readDbcFile<IMountXDisplayDbc>(path.join(dir, "MountXDisplay_9.2.0_41462.csv"));
this.dbcSpell = await this.readDbcFile<ISpellDbc>(path.join(dir, "Spell_3.3.5_12340.csv"));
this.dbcSpellItemEnchantment = await this.readDbcFile<ISpellItemEnchantmentDbc>(path.join(dir, "SpellItemEnchantment_3.3.5_12340.csv"));
}
}