add reputation page
This commit is contained in:
parent
0a04f3bc81
commit
56732a68c1
7 changed files with 712 additions and 0 deletions
|
|
@ -154,6 +154,7 @@ export class Armory {
|
|||
app.get("/character/:realm/:name/achievements", this.wrapRoute(charsController.achievements.bind(charsController)));
|
||||
app.get("/character/:realm/:character/achievements/data", this.wrapRoute(charsController.achievementsData.bind(charsController)));
|
||||
app.get("/character/:realm/:name/pvp", this.wrapRoute(charsController.pvp.bind(charsController)));
|
||||
app.get("/character/:realm/:name/reputation", this.wrapRoute(charsController.reputation.bind(charsController)));
|
||||
|
||||
const guildsController = new GuildController(this);
|
||||
app.get("/guild/:realm/:name", this.wrapRoute(guildsController.guild.bind(guildsController)));
|
||||
|
|
|
|||
|
|
@ -308,6 +308,111 @@ export class CharacterController {
|
|||
});
|
||||
}
|
||||
|
||||
public async reputation(req: express.Request, res: express.Response, next: express.NextFunction): Promise<void> {
|
||||
const realmName = req.params.realm;
|
||||
const charName = req.params.name;
|
||||
|
||||
const realm = this.armory.getRealm(realmName);
|
||||
if (realm === undefined) {
|
||||
return next(404);
|
||||
}
|
||||
|
||||
const charData = await this.getCharacterData(realm, charName);
|
||||
if (charData === null) {
|
||||
return next(404);
|
||||
}
|
||||
|
||||
const reputations = await this.getReputations(realm.name, charData.guid);
|
||||
// Group reputations by expansion/category
|
||||
const classicReps = reputations.filter(rep => rep.expansionId === 0);
|
||||
const tbcReps = reputations.filter(rep => rep.expansionId === 1);
|
||||
const wotlkReps = reputations.filter(rep => rep.expansionId === 2);
|
||||
|
||||
res.render("character-reputation.hbs", {
|
||||
title: `Armory - ${charData.name} - Reputation`,
|
||||
...this.makeSharedDataObject(realm, charData),
|
||||
data: {
|
||||
classic: classicReps,
|
||||
tbc: tbcReps,
|
||||
wotlk: wotlkReps
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private async getReputations(realm: string, character: number): Promise<any[]> {
|
||||
const [rows] = await this.armory.getCharactersDb(realm).query({
|
||||
sql: `
|
||||
SELECT faction, standing, flags
|
||||
FROM character_reputation
|
||||
WHERE guid = ?
|
||||
AND flags NOT IN (0, 4, 8)
|
||||
AND standing != 0
|
||||
`,
|
||||
values: [character],
|
||||
timeout: this.armory.config.dbQueryTimeout,
|
||||
});
|
||||
|
||||
const reputations = [];
|
||||
for (const row of rows as RowDataPacket[]) {
|
||||
const factionInfo = await this.armory.dbc.faction().find(f => f.id === row.faction);
|
||||
if (factionInfo && factionInfo.reputationId >= 0) {
|
||||
reputations.push({
|
||||
id: row.faction,
|
||||
name: factionInfo.name,
|
||||
standing: this.getReputationStanding(row.standing),
|
||||
value: row.standing,
|
||||
valueInGrade: this.getReputationInGrade(row.standing),
|
||||
max: this.getReputationMax(row.standing),
|
||||
expansionId: this.getExpansionId(row.faction)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return reputations;
|
||||
}
|
||||
|
||||
private getReputationStanding(value: number): string {
|
||||
if (value < -6000) return 'Hated'; // These are probably not correct, but I don't have a character to test against
|
||||
if (value < -3000) return 'Hostile'; // These are probably not correct, but I don't have a character to test against
|
||||
if (value < 0) return 'Unfriendly'; // These are probably not correct, but I don't have a character to test against
|
||||
if (value < 1000) return 'Neutral'; // These are probably not correct, but I don't have a character to test against
|
||||
if (value < 6000) return 'Friendly';
|
||||
if (value < 19000) return 'Honored';
|
||||
if (value < 40000) return 'Revered';
|
||||
return 'Exalted'; // These are probably not correct, but I don't have a character to test against
|
||||
}
|
||||
|
||||
private getReputationMax(value: number): number {
|
||||
if (value < -6000) return -6000; // These are probably not correct, but I don't have a character to test against
|
||||
if (value < -3000) return -3000; // These are probably not correct, but I don't have a character to test against
|
||||
if (value < 0) return 0; // These are probably not correct, but I don't have a character to test against
|
||||
if (value < 1000) return 1000; // These are probably not correct, but I don't have a character to test against
|
||||
if (value < 6000) return 6000;
|
||||
if (value < 12000) return 12000;
|
||||
if (value < 21000) return 21000;
|
||||
return 40000; // This might not be right, but I dont have an exalted character to test against
|
||||
}
|
||||
|
||||
private getReputationInGrade(value: number): number {
|
||||
if (value < -6000) return value + 3000; // These are probably not correct, but I don't have a character to test against
|
||||
if (value < -3000) return value; // These are probably not correct, but I don't have a character to test against
|
||||
if (value < 0) return value; // These are probably not correct, but I don't have a character to test against
|
||||
if (value < 1000) return value - 1000; // These are probably not correct, but I don't have a character to test against
|
||||
if (value < 6000) return value - 1000;
|
||||
if (value < 12000) return value - 5900; // For some reason I needed to remove an extra 100 from this one to get it to match the client
|
||||
if (value < 21000) return value - 16900; // For some reason I needed to remove an extra 100 from this one to get it to match the client
|
||||
return value - 21100; // This might not be right, but I dont have an exalted character to test against
|
||||
}
|
||||
|
||||
private getExpansionId(factionId: number): number {
|
||||
// Classic factions
|
||||
if (factionId < 900) return 0;
|
||||
// TBC factions
|
||||
if (factionId < 1100) return 1;
|
||||
// WotLK factions
|
||||
return 2;
|
||||
}
|
||||
|
||||
public async achievements(req: express.Request, res: express.Response, next: express.NextFunction): Promise<void> {
|
||||
const realmName = req.params.realm;
|
||||
const charName = req.params.name;
|
||||
|
|
|
|||
|
|
@ -112,6 +112,12 @@ export interface ITalentTab {
|
|||
classMask: number;
|
||||
}
|
||||
|
||||
export interface IFactionDbc {
|
||||
id: number;
|
||||
reputationId: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface IAsyncGeneratorWithArrayMethods<T> {
|
||||
[Symbol.asyncIterator](): AsyncGenerator<T>;
|
||||
toArray(): Promise<T[]>;
|
||||
|
|
@ -315,6 +321,7 @@ const dir = path.join(process.cwd(), "data");
|
|||
export const DbcFiles = {
|
||||
achievement: path.join(dir, "Achievement_3.3.5_12340.csv"),
|
||||
achievementCategory: path.join(dir, "AchievementCategory_3.3.5_12340.csv"),
|
||||
faction: path.join(dir, "Factions.csv"),
|
||||
glyphProperties: path.join(dir, "GlyphProperties_3.3.5_12340.csv"),
|
||||
item: path.join(dir, "Item_3.3.5_12340.csv"),
|
||||
itemRetail: path.join(dir, "Item_9.2.0_41462.csv"),
|
||||
|
|
@ -360,12 +367,14 @@ const dbcFields = {
|
|||
"prereqRank0",
|
||||
],
|
||||
talentTab: ["id", "nameLang0", "spellIconId", "classMask"],
|
||||
faction: ["id", "reputationId", "name"],
|
||||
};
|
||||
|
||||
export class DbcManager {
|
||||
private _achievement: IAchievement[];
|
||||
private _achievementCategory: IAchievementCategory[];
|
||||
private _glyphProperties: IGlyphProperties[];
|
||||
private _faction: IFactionDbc[];
|
||||
private _item: IItemDbc[];
|
||||
private _itemRetail: IItemRetailDbc[];
|
||||
private _itemAppearance: IItemAppearanceDbc[];
|
||||
|
|
@ -416,6 +425,10 @@ export class DbcManager {
|
|||
return this.getLoadedDataOrRead(DbcFiles.achievementCategory, this._achievementCategory, dbcFields.achievementCategory);
|
||||
}
|
||||
|
||||
public faction() {
|
||||
return this.getLoadedDataOrRead(DbcFiles.faction, this._faction, dbcFields.faction);
|
||||
}
|
||||
|
||||
public glyphProperties() {
|
||||
return this.getLoadedDataOrRead(DbcFiles.glyphProperties, this._glyphProperties, dbcFields.glyphProperties);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue