From 91f3ec424a783229e302daae5189e5871fbe5f4c Mon Sep 17 00:00:00 2001 From: Axel Cocat Date: Mon, 21 Mar 2022 00:28:13 +0100 Subject: [PATCH] fix(character): fix sheath type when mounted (#5) --- src/armory/controllers/CharacterController.ts | 13 +++- src/armory/data/DbcReader.ts | 3 +- static/character.hbs | 67 +++++++++++++++++-- 3 files changed, 77 insertions(+), 6 deletions(-) diff --git a/src/armory/controllers/CharacterController.ts b/src/armory/controllers/CharacterController.ts index bc56c90..fcdbf19 100644 --- a/src/armory/controllers/CharacterController.ts +++ b/src/armory/controllers/CharacterController.ts @@ -29,6 +29,8 @@ interface IEquipmentData { flags: number; enchantments: string; randomPropertyId: number; + classId: number; + subclassId: number; } interface ICustomizationOption { @@ -338,7 +340,16 @@ export class CharacterController { values: [charGuid], timeout: this.armory.config.dbQueryTimeout, }); - return rows as RowDataPacket[] as IEquipmentData[]; + + const data = rows as RowDataPacket[] as IEquipmentData[]; + + for (const row of data) { + const item = await this.armory.dbc.item().find(item => item.id === row.itemEntry); + row.classId = item.classId; + row.subclassId = item.subclassId; + } + + return data; } private async getMounts(realm: string, charGuid: number): Promise { diff --git a/src/armory/data/DbcReader.ts b/src/armory/data/DbcReader.ts index 2fa6582..212e502 100644 --- a/src/armory/data/DbcReader.ts +++ b/src/armory/data/DbcReader.ts @@ -28,6 +28,7 @@ export interface IAchievementCategory { export interface IItemDbc { id: number; classId: number; + subclassId: number; displayInfoId: number; inventoryType: number; } @@ -316,7 +317,7 @@ const dbcFields = { achievement: ["id", "faction", "titleLang0", "descriptionLang0", "category", "points", "flags", "iconId"], achievementCategory: ["id", "parent", "nameLang0"], glyphProperties: ["id", "spellId"], - item: ["id", "classId", "displayInfoId", "inventoryType"], + item: ["id", "classId", "subclassId", "displayInfoId", "inventoryType"], itemRetail: ["id", "inventoryType"], itemAppearance: ["id", "itemDisplayInfoId"], itemModifiedAppearance: ["id", "itemId", "itemAppearanceId"], diff --git a/static/character.hbs b/static/character.hbs index 0a93c09..7b82c02 100644 --- a/static/character.hbs +++ b/static/character.hbs @@ -66,7 +66,7 @@ debug: () => { }, }; - const charData = {{{JSONstringify data}}}; + const charData = {{{ JSONstringify data }}}; const races = { 1: "human", 2: "orc", @@ -199,10 +199,37 @@ onResize(true); function setMount(mountId) { - if (characterModel.mount.id !== mountId) { - characterModel.mount.id = mountId; - createViewer(); + if (characterModel.mount.id === mountId) { + return; } + + if (mountId !== 0) { + const mainHand = charData.equipment.find(e => e.slot === 15); + const offHand = charData.equipment.find(e => e.slot === 16); + const ranged = charData.equipment.find(e => e.slot === 17); + + characterModel.charCustomization.sheathMain = sheathTypes[mainHand.classId][mainHand.subclassId]; + if (offHand !== undefined) { + characterModel.charCustomization.sheathOff = sheathTypes[offHand.classId][offHand.subclassId]; + } else if (ranged !== undefined) { + characterModel.charCustomization.sheathOff = sheathTypes[ranged.classId][ranged.subclassId]; + } else { + characterModel.charCustomization.sheathOff = -1; + } + + if (characterModel.charCustomization.sheathMain === undefined) { + characterModel.charCustomization.sheathMain = 0; + } + if (characterModel.charCustomization.sheathOff === undefined) { + characterModel.charCustomization.sheathOff = 0; + } + } else { + characterModel.charCustomization.sheathMain = -1; + characterModel.charCustomization.sheathOff = -1; + } + + characterModel.mount.id = mountId; + createViewer(); } if (charData.mounts.length === 0) { @@ -233,6 +260,38 @@ $("#mounts").slideToggle("fast"); }); + const sheathTypes = { + 2: { + // One handed weapons + 0: 3, + 4: 3, + 7: 3, + 14: 3, + 15: 3, + 17: 3, + 20: 3, + + // Two handed weapons + 1: 1, + 5: 1, + 8: 1, + + // Others + 10: 2, // Staff + 6: 1, // Polearm + 2: 4, // Bow + 3: 4, // Gun + 18: 4, // Crossbow + 13: 0, // Fist weapons + 19: 3, // Wand + 20: 1, // Fishing pole + }, + 4: { + 0: 3, // Held in off-hand + 6: 9, // Shield + }, + }; + const characterModel = { type: ZamModelViewer.WOW, contentPath: "{{websiteRoot}}/data/",