diff --git a/package.json b/package.json index 5373fc3..8fa0b06 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,10 @@ "version": "1.0.0", "scripts": { "tsc": "tsc", - "start": "npm run build; node lib/src/backend/Launcher.js", + "launch": "node lib/src/backend/Launcher.js", + "start": "npm run build; npm run launch", "start-backend": "npm run build-backend; node lib/src/backend/Launcher.js", - "build": "npm run clean; npm run build-backend; npm run build-frontend", + "build": "npm run build-backend; npm run build-frontend", "test": "npm run clean && npm run build-backend && mocha lib/test/backendTest.js", "build-backend": "tsc;", "build-frontend": "mkdir dist; mkdir dist/static; npm run build-dashboard;", diff --git a/src/backend/Components/Item/Interface.ts b/src/backend/Components/Item/Interface.ts index 152988b..6e99f9a 100644 --- a/src/backend/Components/Item/Interface.ts +++ b/src/backend/Components/Item/Interface.ts @@ -1,14 +1,15 @@ import { Item, Character, SRToken, SRPriority, Spec, Signup } from "../../Types/Types" +import { Tiers } from "../../Types/Items" export class IItemManager{ getItems: () => Promise fetchItem: (name:string) => Promise - buyToken: (usertoken: string, charactername:string, itemname:string, signup:Signup) => Promise<(SRToken & Character & Item) | void> + buyToken: (usertoken: string, charactername:string, itemname:string, signup:Signup) => Promise<(SRToken & Character & Item) | undefined> setPriority: (itemname:string, priority: any) => Promise calculatePriorities: (itemname: string, character:Character) => Promise deletePriority: (priority:SRPriority) => Promise - getTokens: (character:Character, valid?:boolean) => Promise - getToken: (character:Character, item:Item, valid?:boolean) => Promise<(SRToken & Character & Item) | void> + getTokens: (character:Character, tiers: Tiers[], valid?:boolean) => Promise<(SRToken & Character & Item)[] | undefined> + getToken: (character:Character, item:Item, valid?:boolean) => Promise<(SRToken & Character & Item) | undefined> getAllPriorities: () => Promise<(SRPriority & Spec & Item)[]> wipeCurrencyAndItems: () => Promise } \ No newline at end of file diff --git a/src/backend/Components/Item/ItemManager.ts b/src/backend/Components/Item/ItemManager.ts index 751926a..25969a6 100644 --- a/src/backend/Components/Item/ItemManager.ts +++ b/src/backend/Components/Item/ItemManager.ts @@ -1,4 +1,4 @@ -import { T1, T2, allItems, _Tiers } from "../../Types/Items"; +import { T1, T2, allItems, _Tiers, Tiers } from "../../Types/Items"; import { Inject, Injectable } from "../../Injector/ServiceDecorator"; import { ItemManagerFeatureIfc, ItemManagerIfc } from "./RPCInterface"; import { FrontworkComponent } from "../../Types/FrontworkComponent"; @@ -54,7 +54,7 @@ implements FrontworkComponent, TableDefin wipeCurrencyAndItems = async () => { await Promise.all([ this.userManager.wipeCurrency(), - this.admin.knex('tokens').where(true).del() + Promise.all(_Tiers.map(tier => this.admin.knex(tier+'tokens').where(true).del())) ]) } @@ -84,19 +84,21 @@ implements FrontworkComponent, TableDefin getTableDefinitions(): TableDefiniton[] { return [ - { - name: 'tokens', - tableBuilder: (table) => { - table.primary(['characterid', 'itemname']) - table.integer("characterid") - table.foreign("characterid").references("id").inTable('characters') - table.string("itemname") - table.foreign("itemname").references("itemname").inTable('items') - table.string("signupid").nullable() - table.foreign("signupid").references("id").inTable('signups').onDelete('SET NULL') - table.integer("level").defaultTo(1) + ...['null',..._Tiers].map(tier => { + return { + name: tier+'tokens', + tableBuilder: (table) => { + table.primary(['characterid', 'itemname']) + table.integer("characterid") + table.foreign("characterid").references("id").inTable('characters') + table.string("itemname") + table.foreign("itemname").references("itemname").inTable('items') + table.string("signupid").nullable() + table.foreign("signupid").references("id").inTable('signups').onDelete('SET NULL') + table.integer("level").defaultTo(1) + } } - },{ + }),{ name: 'priorities', tableBuilder: (table) => { table.increments('id').primary() @@ -121,7 +123,7 @@ implements FrontworkComponent, TableDefin }] } - buyToken = async (usertoken: string, charactername:string, itemname:string, signup: Signup): Promise<(SRToken & Character & Item) | void> => { + buyToken = async (usertoken: string, charactername:string, itemname:string, signup: Signup): Promise<(SRToken & Character & Item) | undefined> => { const record = this.userManager.getUserRecordByToken(usertoken) const character = await this.character.getCharacterByName(charactername) @@ -130,52 +132,53 @@ implements FrontworkComponent, TableDefin const item = await this.getItem(itemname) if(!item) return - const currency = await this.userManager.getCurrency(record.user) + const currency = await this.userManager.getCurrency(record.user, item.tier) if(currency < 1) return - const shadowTokens = await this.getTokens(character, false) - const activeTokens = await this.getTokens(character, true) + const streaks = await this.getTokens(character, [item.tier], false) + const activeTokens = await this.getTokens(character, [item.tier], true) - await this.userManager.decrementCurrency(record.user, 1) + await this.userManager.decrementCurrency(record.user, item.tier, 1) const modifier = await this.calculatePriorities(itemname, character) - //tokens with deleted signups - if(shadowTokens.length > 0){ - //token for current item - const matchingtoken = shadowTokens.find(token => token.itemname === itemname) - if(matchingtoken){ - //update signupid and increment level - - + if(streaks.length > 0){ + const myStreak = streaks.find(token => token.itemname === itemname) + if(myStreak){ + //getLogger('ItemManager').debug('update signupid and increment level') await this.admin - .knex('tokens') + .knex(item.tier+'tokens') .where({ characterid: character.id, itemname: item.itemname }) .update({ signupid: signup.id, - level: matchingtoken.level+1 + level: myStreak.level+1 }) - - await this.admin - .knex('tokens') - .where({ - characterid: character.id, - itemname: item.itemname, - signupid: null - }).del() - - return await this.getToken(character, item) + } + + //getLogger('ItemManager').debug('delete streaks') + await Promise.all(streaks.map(async s => await this.admin + .knex(item.tier+'tokens') + .where({ + itemname: s.itemname, + characterid: character.id, + signupid: null + }) + .del() + )) + + if(myStreak) + return await this.getToken(character, item) } - const matchingtoken = activeTokens.find(token => token.itemname === itemname) - if(matchingtoken){ - //power up token + const matchingReserve = activeTokens.find(token => token.itemname === itemname) + if(matchingReserve){ + getLogger('ItemManager').debug('upgrade reserve') await this.admin - .knex('tokens') + .knex(item.tier+'tokens') .increment('level') .where({ signupid: signup.id, @@ -183,8 +186,9 @@ implements FrontworkComponent, TableDefin itemname: item.itemname }) }else{ + getLogger('ItemManager').debug('new reserve') await this.admin - .knex('tokens') + .knex(item.tier+'tokens') .insert({ characterid: character.id, itemname: item.itemname, @@ -257,9 +261,9 @@ implements FrontworkComponent, TableDefin }).reduce((prev, curr) => prev+curr, 0) } - getToken = async (character:Character, item:Item,valid=true): Promise<(SRToken & Character & Item) | void>=> { + getToken = async (character:Character, item:Item, valid=true): Promise<(SRToken & Character & Item) | undefined>=> { return await this.admin - .knex('tokens as t') + .knex(item.tier+'tokens as t') .select('*') .join('characters as c', 'c.id', '=', 't.characterid') .join('items as i', 'i.itemname', '=', 't.itemname') @@ -277,22 +281,25 @@ implements FrontworkComponent, TableDefin .first() } - getTokens = async (character:Character, valid=true) : Promise<(SRToken & Character & Item)[]> => { - return await this.admin - .knex('tokens as t') - .select('*') - .join('characters as c', 'c.id', '=', 't.characterid') - .join('items as i', 'i.itemname', '=', 't.itemname') - .where({ - characterid: character.id, - }) - .andWhere(function(){ - if(valid){ - this.whereNotNull('t.signupid') - }else{ - this.whereNull('t.signupid') - } - }) + getTokens = async (character:Character, tiers:Tiers[], valid=true) : Promise<(SRToken & Character & Item)[]> => { + const ret = await Promise.all(tiers.map(async tier => { + return await this.admin + .knex(tier+'tokens as t') + .select('*') + .join('characters as c', 'c.id', '=', 't.characterid') + .join('items as i', 'i.itemname', '=', 't.itemname') + .where({ + characterid: character.id, + }) + .andWhere(function(){ + if(valid){ + this.whereNotNull('t.signupid') + }else{ + this.whereNull('t.signupid') + } + }) + })) + return ret.flat() } countItems = async() :Promise => { diff --git a/src/backend/Components/Raid/RaidManager.ts b/src/backend/Components/Raid/RaidManager.ts index 4c983da..d723584 100644 --- a/src/backend/Components/Raid/RaidManager.ts +++ b/src/backend/Components/Raid/RaidManager.ts @@ -9,7 +9,6 @@ import { ICharacterManager } from "../Character/Interface"; import { _Tiers } from "../../Types/Items"; import { IItemManager } from "../Item/Interface"; import { ItemManager } from "../Item/ItemManager"; -import { SpecT } from "../../Types/PlayerSpecs"; @Injectable(IRaidManager) export class RaidManager @@ -126,11 +125,10 @@ implements FrontworkComponent, IRaidManag startRaid = async (raid:Raid) : Promise => { const archived = await this.archiveRaid(raid) - delete archived.participants.late - + const giveCurrency = async (b: Character) => { const usr = await this.characterManager.getUserOfCharacter(b) - await this.userManager.incrementCurrency(usr, 1) + await this.userManager.incrementCurrency(usr, raid.tier, 1) } await Promise.all([ @@ -144,10 +142,10 @@ implements FrontworkComponent, IRaidManag archiveRaid = async (raid:Raid) : Promise => { const raidData = await this.getRaidData(raid) - const tx = await this.admin.knex.transaction() + //const tx = await this.admin.knex.transaction() await this.admin.knex('archive') - .transacting(tx) + //.transacting(tx) .insert({ id:raidData.id, raiddata: JSON.stringify(raidData) @@ -155,8 +153,8 @@ implements FrontworkComponent, IRaidManag await Promise.all( Object.values(raidData.participants).flat().flatMap((signup) => this.admin - .knex('tokens') - .transacting(tx) + .knex(raid.tier+'tokens') + //.transacting(tx) .where({ characterid: signup.characterid, signupid: null @@ -165,10 +163,10 @@ implements FrontworkComponent, IRaidManag )) await this.admin.knex('raids') - .transacting(tx) + //.transacting(tx) .where('id', '=', raid.id) .del() - await tx.commit() + //await tx.commit() const row = await this.admin.knex('archive') @@ -216,7 +214,7 @@ implements FrontworkComponent, IRaidManag healers:<(Signup&Character&Spec)[]>[], tanks:<(Signup&Character&Spec)[]>[] } - const tx = await this.admin.knex.transaction() + //const tx = await this.admin.knex.transaction() const subQuery = this.admin .knex('signups') @@ -231,13 +229,13 @@ implements FrontworkComponent, IRaidManag const raidInDb: Raid = await this.admin.knex('raids') .select('*', subQuery) - .transacting(tx) + //.transacting(tx) .where('id','=',raid.id) .first() const characterData: (Signup & Character & Spec)[] = await this.admin .knex('signups as s') - .transacting(tx) + //.transacting(tx) .select('s.id as id', 'charactername', 'class', 'specid', 'specname', 'race', 'userid', 'benched', 'late', 'raidid', 'characterid', 'specid') .join('raids as r', 's.raidid','=','r.id') .join('characters as c', 's.characterid','=','c.id') @@ -259,18 +257,20 @@ implements FrontworkComponent, IRaidManag const tokenData: (Character & SRToken & Item)[] = await this.admin .knex('signups as s') - .transacting(tx) + //.transacting(tx) .select('*', 's.id as id') .join('raids as r', 's.raidid','=','r.id') - .where('r.id','=',raid.id) + .join('characters as c', 's.characterid','=','c.id') + .join(raidInDb.tier+'tokens as t', 't.characterid','=','c.id') + .join('items as i', 'i.itemname','=','t.itemname') + .where({ + 'r.id': raid.id, + }) .andWhere(function(){ this.whereNotNull('t.signupid') }) - .join('characters as c', 's.characterid','=','c.id') - .join('tokens as t', 't.characterid','=','c.id') - .join('items as i', 'i.itemname','=','t.itemname') - await tx.commit() + //await tx.commit() tokenData.forEach(data => { if(!raiddata.tokens[data.itemname]) @@ -313,11 +313,11 @@ implements FrontworkComponent, IRaidManag if(!maybeUserRecord || maybeUserRecord.user.id != character.userid){ throw new Error("Bad Usertoken") } - const tx = await this.admin.knex.transaction() + //const tx = await this.admin.knex.transaction() const exists = await this.admin .knex('signups') - .transacting(tx) + //.transacting(tx) .select('*') .where({ raidid: raid.id!, @@ -328,7 +328,7 @@ implements FrontworkComponent, IRaidManag if(!exists){ await this.admin .knex('signups') - .transacting(tx) + //.transacting(tx) .insert({ raidid: raid.id!, characterid: character.id!, @@ -338,7 +338,7 @@ implements FrontworkComponent, IRaidManag }else{ await this.admin .knex('signups') - .transacting(tx) + //.transacting(tx) .where({ id: exists.id }) @@ -349,7 +349,7 @@ implements FrontworkComponent, IRaidManag benched: false, }) } - await tx.commit() + //await tx.commit() return await this.admin .knex('signups') @@ -380,22 +380,22 @@ implements FrontworkComponent, IRaidManag "si.characterid": character.id!, }).first() - const tokens = await this.admin.knex('tokens as t') + const tokens = await this.admin.knex(raid.tier+'tokens as t') .where('t.signupid', signup.id) //check if token has to be deleted Promise.all( tokens.map(async token => { - await this.userManager.incrementCurrency(user, 1) + await this.userManager.incrementCurrency(user, raid.tier, 1) const prio = await this.itemManager.calculatePriorities(token.itemname, character) if(token.level <= prio+1){ - await this.admin.knex('tokens') + await this.admin.knex(raid.tier+'tokens') .where({ characterid: character.id, itemname: token.itemname }).del() }else{ - await this.admin.knex('tokens') + await this.admin.knex(raid.tier+'tokens') .where({ characterid: character.id, itemname: token.itemname diff --git a/src/backend/Components/User/Interface.ts b/src/backend/Components/User/Interface.ts index 952c5a5..cfd9adb 100644 --- a/src/backend/Components/User/Interface.ts +++ b/src/backend/Components/User/Interface.ts @@ -1,4 +1,5 @@ import { Auth, Rank, User, RPCPermission, UserRecord } from "../../Types/Types" +import { Tiers } from "../../Types/Items" export class IUserManager{ login: (username:string, pwHash:string) => Promise @@ -11,10 +12,10 @@ export class IUserManager{ getUserRecordByToken: (tokenValue: string) => UserRecord | void getUser: (username: string) => Promise - decrementCurrency: (user: User, value: number) => Promise - incrementCurrency: (user: User, value: number) => Promise - setCurrency: (user: User, value: number) => Promise - getCurrency: (user:User) => Promise + decrementCurrency: (user: User, tier:Tiers, value: number) => Promise + incrementCurrency: (user: User, tier:Tiers, value: number) => Promise + setCurrency: (user: User, tier:Tiers, value: number) => Promise + getCurrency: (user:User, tier:Tiers) => Promise changeRank: (user:User, rank: Rank) => Promise wipeCurrency: () => Promise } \ No newline at end of file diff --git a/src/backend/Components/User/UserManager.ts b/src/backend/Components/User/UserManager.ts index 7f7f5b4..6521379 100644 --- a/src/backend/Components/User/UserManager.ts +++ b/src/backend/Components/User/UserManager.ts @@ -12,6 +12,7 @@ import { IAdmin } from "../../Admin/Interface"; import { IUserManager } from "./Interface"; import { getLogger, Logger } from "log4js"; import { saltedHash } from "../../Util/hash"; +import { _Tiers, Tiers } from "../../Types/Items"; const uuid = require('uuid/v4') @@ -97,8 +98,9 @@ implements FrontworkComponent, IUserManag table.string("username").notNullable().unique() table.string("pwhash").notNullable() table.string("rank").notNullable() - table.string("email").nullable().unique() - table.integer("currency").defaultTo(1) + _Tiers.forEach(tier => { + table.integer(tier).defaultTo(1) + }) } },{ name: 'rpcpermissions', @@ -286,8 +288,13 @@ implements FrontworkComponent, IUserManag } wipeCurrency = async () => { - await this.admin.knex('users') - .update({currency: 0}) + await Promise.all(_Tiers.map(tier => { + const update = {} + update[tier] = 1 + + return this.admin.knex('users') + .update(update) + })) } login = async(username:string, pwHash:string) : Promise => { @@ -405,18 +412,19 @@ implements FrontworkComponent, IUserManag return token } - getCurrency = async(user:User) : Promise => { + getCurrency = async(user:User, tier?: Tiers) : Promise => { + if(!tier) return 0 const usr : User = await this.admin .knex('users') .where('username', '=', user.username) .select('*') .first() - return usr.currency! + return usr[tier]! } - decrementCurrency = async (user: User, value = 1) => { - if(value < 1) return + decrementCurrency = async (user: User, tier?: Tiers, value = 1) => { + if(!tier || value < 1) return const usr : User = await this.admin .knex('users') @@ -424,28 +432,28 @@ implements FrontworkComponent, IUserManag .select('*') .first() - if(!usr || usr.currency! <= 0) return + if(!usr || usr[tier]! <= 0) return await this.admin .knex('users') .where('id', '=', user.id) - .decrement('currency', value) + .decrement(tier, value) } - incrementCurrency = async (user: User, value = 1) => { - if(value < 1) return + incrementCurrency = async (user: User, tier: Tiers, value = 1) => { + if(!tier || value < 1) return await this.admin .knex('users') .where('id', '=', user.id) - .increment('currency', value) + .increment(tier, value) } - setCurrency = async (user: User, value: number) => { - if(value < 0) return + setCurrency = async (user: User, tier?:Tiers, value = 0) => { + if(!tier || value < 0) return await this.admin .knex('users') .where('id', '=', user.id) - .update('currency', value) + .update(tier, value) } diff --git a/src/backend/Types/Items.ts b/src/backend/Types/Items.ts index 29325d3..49c7b67 100644 --- a/src/backend/Types/Items.ts +++ b/src/backend/Types/Items.ts @@ -1,5 +1,5 @@ -export type Tiers = "MC" | 'BWL' | 'ZG' | 'AQ20' | 'AQ40' | 'Naxx' -export const _Tiers = ["MC", 'BWL', 'ZG', 'AQ20', 'AQ40', 'Naxx'] +export type Tiers = "MC" | 'BWL' | 'ZG' | 'AQ20' | 'AQ40' | 'Naxx' +export const _Tiers:Tiers[] = ["MC", 'BWL', 'ZG', 'AQ20', 'AQ40', 'Naxx'] export const T1 = [ "Robe of Volatile Power", diff --git a/src/backend/Types/Types.ts b/src/backend/Types/Types.ts index 8e818a4..75e02b1 100644 --- a/src/backend/Types/Types.ts +++ b/src/backend/Types/Types.ts @@ -94,6 +94,8 @@ export type User = { pwhash: string rank: Rank currency?: number +} & { + [currency in Tiers]? : number } export type Raid = { diff --git a/src/frontend/src/app/@theme/components/header/chat.component.ts b/src/frontend/src/app/@theme/components/header/chat.component.ts index 8905ea5..faac029 100644 --- a/src/frontend/src/app/@theme/components/header/chat.component.ts +++ b/src/frontend/src/app/@theme/components/header/chat.component.ts @@ -10,9 +10,12 @@ import { ShoutMessage } from '../../../../../../backend/Components/Shoutbox/Inte [type]="text" [message]="msg.message" [sender]="msg.sender" - [date]="msg.date"> + [date]="msg.date" + [reply]="msg.reply"> - + `, diff --git a/src/frontend/src/app/frontcraft/pages/character/character.component.html b/src/frontend/src/app/frontcraft/pages/character/character.component.html index 26985b4..e3fdec9 100644 --- a/src/frontend/src/app/frontcraft/pages/character/character.component.html +++ b/src/frontend/src/app/frontcraft/pages/character/character.component.html @@ -25,13 +25,7 @@ status="control">

[ {{token.level}} ] - - - {{token.itemname}} -
+
diff --git a/src/frontend/src/app/frontcraft/pages/character/character.component.ts b/src/frontend/src/app/frontcraft/pages/character/character.component.ts index 42c02d5..4d32467 100644 --- a/src/frontend/src/app/frontcraft/pages/character/character.component.ts +++ b/src/frontend/src/app/frontcraft/pages/character/character.component.ts @@ -3,6 +3,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { ApiService as ApiService } from '../../services/login-api'; import { Spec, User, Character } from '../../../../../../backend/Types/Types'; import { getClassColor } from '../../../../../../backend/Types/PlayerSpecs'; +import { _Tiers } from '../../../../../../backend/Types/Items'; @Component({ selector: 'character', @@ -35,7 +36,7 @@ export class FrontcraftCharacterComponent implements OnInit{ if(char){ this.color = getClassColor(char.class) this.char = char - this.api.get('ItemManager').getTokens(this.char).then(tokens => { + this.api.get('ItemManager').getTokens(this.char, _Tiers, true).then(tokens => { this.tokens = tokens }) } diff --git a/src/frontend/src/app/frontcraft/pages/pages.module.ts b/src/frontend/src/app/frontcraft/pages/pages.module.ts index b2e5879..101722d 100644 --- a/src/frontend/src/app/frontcraft/pages/pages.module.ts +++ b/src/frontend/src/app/frontcraft/pages/pages.module.ts @@ -38,6 +38,8 @@ import { FrontcraftItemSelectComponent } from './shop/itemselector.component'; import { NgxEchartsModule } from 'ngx-echarts'; import { FrontcraftCharactersComponent } from './characters/characters.component'; import { FrontcraftBuyTokenComponent } from './shop/buytoken.component'; +import { FrontcraftItemComponent } from './shop/item.component'; +import { FrontcraftWowheadComponent } from './shop/wowhead.component'; @NgModule({ @@ -81,6 +83,8 @@ import { FrontcraftBuyTokenComponent } from './shop/buytoken.component'; FrontcraftRulesComponent, FrontcraftCreateRaidsComponent, FrontcraftBuyTokenComponent, + FrontcraftWowheadComponent, + FrontcraftItemComponent ], entryComponents: [ FrontcraftItemSelectComponent, diff --git a/src/frontend/src/app/frontcraft/pages/raid/archive.component.ts b/src/frontend/src/app/frontcraft/pages/raid/archive.component.ts index d5f8dd5..aa9d58d 100644 --- a/src/frontend/src/app/frontcraft/pages/raid/archive.component.ts +++ b/src/frontend/src/app/frontcraft/pages/raid/archive.component.ts @@ -13,6 +13,7 @@ export class FrontcraftArchiveComponent implements OnInit{ canSignup = false isSignedup = false canManage = false + isTier = false mySignup raid: RaidData = { diff --git a/src/frontend/src/app/frontcraft/pages/raid/raid.component.html b/src/frontend/src/app/frontcraft/pages/raid/raid.component.html index 7d0e65c..adcc7ec 100644 --- a/src/frontend/src/app/frontcraft/pages/raid/raid.component.html +++ b/src/frontend/src/app/frontcraft/pages/raid/raid.component.html @@ -2,7 +2,10 @@ -

{{raid.title}}

+

+ + {{raid.title}} +

{{raid.signupcount}} / {{raid.size}} signups

@@ -167,10 +170,10 @@
- - + + - + diff --git a/src/frontend/src/app/frontcraft/pages/raid/raid.component.ts b/src/frontend/src/app/frontcraft/pages/raid/raid.component.ts index ccf3447..9fccfd0 100644 --- a/src/frontend/src/app/frontcraft/pages/raid/raid.component.ts +++ b/src/frontend/src/app/frontcraft/pages/raid/raid.component.ts @@ -6,6 +6,7 @@ import { NbWindowService, NbToastrService, NbDialogService } from '@nebular/them import { FrontcraftCharacerpickerComponent } from './characterpicker.component'; import { getClassColor, SpecT } from '../../../../../../backend/Types/PlayerSpecs'; import { FrontcraftBuyTokenComponent } from '../shop/buytoken.component'; +import { allItems } from '../../../../../../backend/Types/Items'; @Component({ selector: 'raid', @@ -16,6 +17,7 @@ export class FrontcraftRaidComponent implements OnInit{ canSignup = false isSignedup = false islate = false + isTier = false manageRaid mySignup: (Signup & Character & Spec) @@ -33,7 +35,8 @@ export class FrontcraftRaidComponent implements OnInit{ }, tanks: [], healers: [], - tokens:{} + tokens:{}, + tier: 'MC' } tokens = {} displayedtokens = {} @@ -50,6 +53,7 @@ export class FrontcraftRaidComponent implements OnInit{ } async ngOnInit(){ + this.manageRaid = this.api.get('manageRaid') const signupFeature = this.api.get('signup') @@ -63,7 +67,9 @@ export class FrontcraftRaidComponent implements OnInit{ this.dialogService.open(FrontcraftBuyTokenComponent, { context: { item: item, - signup: this.mySignup + signup: this.mySignup, + tier: this.raid.tier, + characterName: this.mySignup.charactername } }).onClose.subscribe(() => this.refresh()) } @@ -112,9 +118,6 @@ export class FrontcraftRaidComponent implements OnInit{ const signup = this.api.get('signup') if(!signup) return - console.log("setlate"); - - await signup.sign(auth.token.value, { ...this.mySignup, id: this.mySignup.characterid, @@ -140,7 +143,8 @@ export class FrontcraftRaidComponent implements OnInit{ const raiddata = await raidManager.getRaidData({ id: param }) - + this.isTier = allItems[raiddata.tier] != null + this.raid = raiddata this.tokens = raiddata.tokens; diff --git a/src/frontend/src/app/frontcraft/pages/raids/createraid.component.html b/src/frontend/src/app/frontcraft/pages/raids/createraid.component.html index 16da56c..75ff6cc 100644 --- a/src/frontend/src/app/frontcraft/pages/raids/createraid.component.html +++ b/src/frontend/src/app/frontcraft/pages/raids/createraid.component.html @@ -7,6 +7,10 @@ {{template.title}} {{template.start| date : 'd MMMM'}} + + + {{_tier}} + diff --git a/src/frontend/src/app/frontcraft/pages/raids/createraid.compontent.ts b/src/frontend/src/app/frontcraft/pages/raids/createraid.compontent.ts index 79b7756..23b03f1 100644 --- a/src/frontend/src/app/frontcraft/pages/raids/createraid.compontent.ts +++ b/src/frontend/src/app/frontcraft/pages/raids/createraid.compontent.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { ApiService } from '../../services/login-api'; import { Raid, RaidData } from '../../../../../../backend/Types/Types'; import { NbWindowRef, NbDialogRef } from '@nebular/theme'; +import { Tiers, _Tiers } from '../../../../../../backend/Types/Items'; const ONE_MINUTE = 60000 const ONE_HOUR = 60 * ONE_MINUTE @@ -21,6 +22,8 @@ export class FrontcraftCreateRaidsComponent implements OnInit { minute = 0 size = 40 description = "" + tier: Tiers = null + tiers = _Tiers constructor( protected dialogRef: NbDialogRef, @@ -37,6 +40,7 @@ export class FrontcraftCreateRaidsComponent implements OnInit { this.minute = templateDate.getMinutes() this.description = this.template.description this.startdate = new Date(parseInt(this.template.start) - templateDate.getHours()*ONE_HOUR - templateDate.getMinutes()*ONE_MINUTE) + this.tier = this.template.tier } ngOnInit(){ @@ -49,6 +53,7 @@ export class FrontcraftCreateRaidsComponent implements OnInit { size: this.size, start: ""+new Date(this.startdate.getTime() + this.hour*ONE_HOUR + this.minute*ONE_MINUTE).getTime(), title: this.title, + tier: this.tier } const manage = this.api.get('manageRaid') if(!manage) return diff --git a/src/frontend/src/app/frontcraft/pages/raids/raids.component.html b/src/frontend/src/app/frontcraft/pages/raids/raids.component.html index 48828b2..292d362 100644 --- a/src/frontend/src/app/frontcraft/pages/raids/raids.component.html +++ b/src/frontend/src/app/frontcraft/pages/raids/raids.component.html @@ -17,7 +17,7 @@ style="cursor: pointer;">
- +
diff --git a/src/frontend/src/app/frontcraft/pages/rules/rules.component.html b/src/frontend/src/app/frontcraft/pages/rules/rules.component.html index 7a98fae..472fffe 100644 --- a/src/frontend/src/app/frontcraft/pages/rules/rules.component.html +++ b/src/frontend/src/app/frontcraft/pages/rules/rules.component.html @@ -7,15 +7,7 @@ - - -   - {{item.key}} -
- +
{{rule.description}} diff --git a/src/frontend/src/app/frontcraft/pages/shop/buytoken.component.ts b/src/frontend/src/app/frontcraft/pages/shop/buytoken.component.ts index 3945054..8deafb9 100644 --- a/src/frontend/src/app/frontcraft/pages/shop/buytoken.component.ts +++ b/src/frontend/src/app/frontcraft/pages/shop/buytoken.component.ts @@ -15,49 +15,73 @@ import { _Tiers, allItems, Tiers } from '../../../../../../backend/Types/Items';

- You currently have {{currency}} softreserve currency + {{currency}} softreserves remaining

-
+ + Claiming this reserve invalidates the following streaks.
+ This is not reversible. +
    +
  • + [ {{item.level}} ] + + + {{item.itemname}} + +
  • +
+
+ + + The following reserve will be created
+
    +
  • + [ {{1+modifier}} ] + + + {{item.itemname}} + + (+{{modifier}} from priorities) +
  • +
+ +
+ + + The following reserve will be created
+
    +
  • + [ {{upgradableToken.level}} ] => [ {{upgradableToken.level+1}} ] + {{upgradableToken.itemname}} +
  • +
+
+
- {{kv.key}} (+{{kv.value}} from priorities) -
-
- - {{token.charactername}} [ {{token.level}} ] => [ {{token.level+1}} ] -
-
`, }) export class FrontcraftBuyTokenComponent implements OnInit{ - + @Input() characterName: string @Input() item : Item @Input() signup : Signup - @Input() tier: Tiers - characters: Character[] - modifier = {} + invalidatedTokens: (SRToken & Character & Item)[] | undefined = [] + upgradableToken : (SRToken & Character & Item) | undefined + noToken = false + modifier currency: number = 0 - ownedtokens: SRToken[] = [] constructor( private toastr: NbToastrService, @@ -65,38 +89,36 @@ import { _Tiers, allItems, Tiers } from '../../../../../../backend/Types/Items'; private api : ApiService ){} - ngOnInit(): void { + async ngOnInit() { + const char = await this.api.get('CharacterManager').getCharacterByName(this.characterName) + if(!char) return + + const passiveStreaks = await this.api.get('ItemManager').getTokens(char, [this.item.tier], false) + this.upgradableToken = passiveStreaks.find(p => p.itemname === this.item.itemname) + this.invalidatedTokens = passiveStreaks.filter(token => token.itemname !== this.item.itemname) + if(!this.upgradableToken) + this.upgradableToken = await this.api.get('ItemManager').getToken(char, this.item, true) + this.modifier = await this.api.get('ItemManager').calculatePriorities(this.item.itemname, char) + + if(!this.upgradableToken) this.noToken = true + const usr = this.api.getCurrentUser() this.api.get('CharacterManager') .getCharactersOfUser(usr.username) .then(chars => { - chars.forEach(char => { + chars.forEach(async char => { char['color'] = getClassColor(char.class) - this.api.get('ItemManager').getToken(char, this.item, false).then(token => { - if(token) this.ownedtokens.push(token) - else{ - this.api.get('ItemManager').getToken(char, this.item, true).then(tokken => { - if(tokken) this.ownedtokens.push(tokken) - else{ - this.api.get('ItemManager').calculatePriorities(this.item.itemname, char).then(modifier => { - this.modifier[char.charactername] = modifier - }) - } - }) - } - }) }) - this.characters = chars }) this.api.get('UserManager').getUser(usr.username).then(u => { if(!u) return - this.currency = u.currency + this.currency = u[this.tier] || 0 }) } - buyToken = async (charactername:string) => { + buyToken = async () => { const src = this.api.get('ItemManager') - const token = await src.buyToken(this.api.getAuth().token.value, charactername, this.item.itemname, this.signup) + const token = await src.buyToken(this.api.getAuth().token.value, this.characterName, this.item.itemname, this.signup) if(token){ this.toastr.show(token.charactername+' now has a token for '+token.itemname+' of level '+token.level, 'Yay', {status: 'success'}) diff --git a/src/frontend/src/app/frontcraft/pages/shop/item.component.ts b/src/frontend/src/app/frontcraft/pages/shop/item.component.ts new file mode 100644 index 0000000..8d6939e --- /dev/null +++ b/src/frontend/src/app/frontcraft/pages/shop/item.component.ts @@ -0,0 +1,30 @@ +import { Component, OnInit, ContentChild, AfterContentInit, ViewChild, AfterViewInit, Input, Output, EventEmitter } from '@angular/core'; +import { ApiService as ApiService } from '../../services/login-api'; +import { FrontcraftItemSelectComponent } from './itemselector.component'; +import { NbWindowService, NbWindowRef, NbToastrService, NbDialogService, NbDialogRef } from '@nebular/theme'; +import { Item, Character, SRToken, Signup } from '../../../../../../backend/Types/Types'; +import { getClassColor } from '../../../../../../backend/Types/PlayerSpecs'; +import { _Tiers, allItems, Tiers } from '../../../../../../backend/Types/Items'; + +@Component({ + selector: 'item', + template: ` + + +   + {{item.itemname}} + + `, + }) + export class FrontcraftItemComponent implements OnInit{ + @Input() item: Item + + constructor( + private toastr: NbToastrService, + private api : ApiService + ){} + + async ngOnInit() { + } + } \ No newline at end of file diff --git a/src/frontend/src/app/frontcraft/pages/shop/itemselect.component.html b/src/frontend/src/app/frontcraft/pages/shop/itemselect.component.html index 150d7ee..ae6f1cb 100644 --- a/src/frontend/src/app/frontcraft/pages/shop/itemselect.component.html +++ b/src/frontend/src/app/frontcraft/pages/shop/itemselect.component.html @@ -14,13 +14,7 @@ select   - - - -   - {{item.itemname}} - - + + diff --git a/src/frontend/src/app/frontcraft/pages/shop/itemselector.component.ts b/src/frontend/src/app/frontcraft/pages/shop/itemselector.component.ts index b7ec040..d93d02f 100644 --- a/src/frontend/src/app/frontcraft/pages/shop/itemselector.component.ts +++ b/src/frontend/src/app/frontcraft/pages/shop/itemselector.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { ApiService } from '../../services/login-api'; -import { Item } from '../../../../../../backend/Types/Types'; +import { Item, Character } from '../../../../../../backend/Types/Types'; @Component({ selector: 'itemselect', @@ -13,6 +13,7 @@ export class FrontcraftItemSelectComponent implements OnInit{ allItems:Item[] = [] displayedItems: any[] + @Input() character: string @Input() items: string[] @Output() onSelect = new EventEmitter(); @@ -21,6 +22,7 @@ export class FrontcraftItemSelectComponent implements OnInit{ ){} async ngOnInit(){ + Promise.all(this.items.map(itemname => this.api.get('ItemManager').getItem(itemname) )).then(items => { diff --git a/src/frontend/src/app/frontcraft/pages/shop/shop.component.html b/src/frontend/src/app/frontcraft/pages/shop/shop.component.html index d7308c7..13707b0 100644 --- a/src/frontend/src/app/frontcraft/pages/shop/shop.component.html +++ b/src/frontend/src/app/frontcraft/pages/shop/shop.component.html @@ -1,7 +1,5 @@ -

- {{tier}} items -

- - +(onSelect)="onSelect.emit($event)"> diff --git a/src/frontend/src/app/frontcraft/pages/shop/shop.component.ts b/src/frontend/src/app/frontcraft/pages/shop/shop.component.ts index 88ed0f1..75e72cf 100644 --- a/src/frontend/src/app/frontcraft/pages/shop/shop.component.ts +++ b/src/frontend/src/app/frontcraft/pages/shop/shop.component.ts @@ -10,7 +10,7 @@ import { _Tiers, allItems } from '../../../../../../backend/Types/Items'; selector: 'shop', templateUrl: './shop.component.html', }) -export class FrontcraftShopComponent{ +export class FrontcraftShopComponent implements OnInit{ @Input() character: Character @Input() signup: Signup @@ -22,5 +22,10 @@ export class FrontcraftShopComponent{ constructor( private api: ApiService, private dialogService : NbDialogService - ){} + ){ + + } + + ngOnInit(){ + } } diff --git a/src/frontend/src/app/frontcraft/pages/shop/wowhead.component.ts b/src/frontend/src/app/frontcraft/pages/shop/wowhead.component.ts new file mode 100644 index 0000000..1511831 --- /dev/null +++ b/src/frontend/src/app/frontcraft/pages/shop/wowhead.component.ts @@ -0,0 +1,26 @@ +import { Component, OnInit, ContentChild, AfterContentInit, ViewChild, AfterViewInit, Input, Output, EventEmitter } from '@angular/core'; +import { ApiService as ApiService } from '../../services/login-api'; +import { NbWindowService, NbWindowRef, NbToastrService, NbDialogService, NbDialogRef } from '@nebular/theme'; +import { Item, Character, SRToken, Signup } from '../../../../../../backend/Types/Types'; +import { _Tiers, allItems, Tiers } from '../../../../../../backend/Types/Items'; + +@Component({ + selector: 'wowhead', + template: ` + + + + + `, + }) + export class FrontcraftWowheadComponent implements OnInit{ + @Input() item: Item + + constructor( + private toastr: NbToastrService, + private api : ApiService + ){} + + async ngOnInit() { + } + } \ No newline at end of file diff --git a/src/frontend/src/app/frontcraft/pages/user/user.component.html b/src/frontend/src/app/frontcraft/pages/user/user.component.html index 46779ee..db414fa 100644 --- a/src/frontend/src/app/frontcraft/pages/user/user.component.html +++ b/src/frontend/src/app/frontcraft/pages/user/user.component.html @@ -6,7 +6,12 @@ accent="info">

{{user.username}}

- {{user.currency}} + {{user.MC}} MC + {{user.BWL}} BWL + {{user.ZG}} ZG + {{user.AQ20}} AQ20 + {{user.AQ40}} AQ40 + {{user.Naxx}} Naxx diff --git a/src/frontend/src/app/frontcraft/pages/user/user.component.ts b/src/frontend/src/app/frontcraft/pages/user/user.component.ts index 267c237..8a4ddc2 100644 --- a/src/frontend/src/app/frontcraft/pages/user/user.component.ts +++ b/src/frontend/src/app/frontcraft/pages/user/user.component.ts @@ -3,6 +3,7 @@ import { ApiService } from '../../services/login-api'; import { Router, ActivatedRoute } from '@angular/router'; import { User, Spec, Character } from '../../../../../../backend/Types/Types'; import { getClassColor } from '../../../../../../backend/Types/PlayerSpecs'; +import { _Tiers } from '../../../../../../backend/Types/Items'; @Component({ selector: 'user-component', @@ -28,7 +29,7 @@ export class FrontcraftUserComponent implements OnInit{ const characters = await this.api.get('CharacterManager').getCharactersOfUser(this.user.username) characters.forEach(async c => { - const tokens = await this.api.get('ItemManager').getTokens(c) + const tokens = await this.api.get('ItemManager').getTokens(c, _Tiers, true) c['tokens'] = tokens c['color'] = getClassColor(c.class) }) diff --git a/src/frontend/src/assets/images/aq20.png b/src/frontend/src/assets/images/aq20.png new file mode 100755 index 0000000..2545257 Binary files /dev/null and b/src/frontend/src/assets/images/aq20.png differ diff --git a/src/frontend/src/assets/images/aq40.png b/src/frontend/src/assets/images/aq40.png new file mode 100755 index 0000000..0f5d98c Binary files /dev/null and b/src/frontend/src/assets/images/aq40.png differ diff --git a/src/frontend/src/assets/images/bwl.png b/src/frontend/src/assets/images/bwl.png new file mode 100755 index 0000000..c880eb9 Binary files /dev/null and b/src/frontend/src/assets/images/bwl.png differ diff --git a/src/frontend/src/assets/images/mc.png b/src/frontend/src/assets/images/mc.png new file mode 100755 index 0000000..fae1daf Binary files /dev/null and b/src/frontend/src/assets/images/mc.png differ diff --git a/src/frontend/src/assets/images/naxx.png b/src/frontend/src/assets/images/naxx.png new file mode 100755 index 0000000..7a74913 Binary files /dev/null and b/src/frontend/src/assets/images/naxx.png differ diff --git a/src/frontend/src/assets/images/null.png b/src/frontend/src/assets/images/null.png new file mode 100644 index 0000000..bfec08c Binary files /dev/null and b/src/frontend/src/assets/images/null.png differ diff --git a/src/frontend/src/assets/images/ony.png b/src/frontend/src/assets/images/ony.png new file mode 100755 index 0000000..f2354a0 Binary files /dev/null and b/src/frontend/src/assets/images/ony.png differ diff --git a/src/frontend/src/assets/images/zg.png b/src/frontend/src/assets/images/zg.png new file mode 100755 index 0000000..f843121 Binary files /dev/null and b/src/frontend/src/assets/images/zg.png differ diff --git a/test/backendTest.ts b/test/backendTest.ts index 82ae6c3..f7a3a12 100644 --- a/test/backendTest.ts +++ b/test/backendTest.ts @@ -60,6 +60,12 @@ const testAccounts : protoAccount[] = [ race: 'Night Elf', spec: 'Protection', rank: 'Officer' + },{ + name: 'Silver', + class: 'Druid', + race: 'Night Elf', + spec: 'Restoration', + rank: 'Raider' },{ name: 'Dagger', race: 'Dwarf', @@ -117,7 +123,7 @@ describe('Frontcraft', () => { const account = await createAccount({ pwhash: 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', //sha256("a") rank: acc.rank, - username: acc.name + username: acc.name, }) const auth = await client.UserManager.login(acc.name, 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb') const id = await client.CharacterManager.getSpecId(acc.class, acc.spec) @@ -148,7 +154,7 @@ describe('Frontcraft', () => { pwhash: 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', //hash("a") rank: 'ADMIN', username: 'a', - currency: 2 + MC: 2 }).then(adminUser => { client.UserManager.login(adminUser.username, 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb').then(auth => { @@ -187,7 +193,8 @@ describe('Frontcraft', () => { let insertRaid = { description: "Test raid 1", title: 'MC', - start: Date.now().toString() + start: Date.now().toString(), + tier: 'MC' } adminClient.manageRaid.createRaid(insertRaid).then(() => { @@ -391,6 +398,11 @@ describe('Frontcraft', () => { {class:'Paladin', specname:'Holy'}, undefined, 2, "crit bias" ), + makePrio( + 'Empowered Leggings', + {class:'Druid', specname:'Restoration'}, + undefined, 2, "crit bias" + ), makePrio( 'Boots of the Shadow Flame', @@ -516,7 +528,7 @@ describe('Frontcraft', () => { const user = Object.values(users)[0] const itemname = T1[0] - adminClient.softreserveCurrency.incrementCurrency(user.account, 2).then(async ()=>{ + adminClient.softreserveCurrency.incrementCurrency(user.account, raids[0].tier, 2).then(async ()=>{ const item = await client.ItemManager.getItem(itemname) const before = await client.ItemManager.getToken(user.character, item) @@ -538,7 +550,7 @@ describe('Frontcraft', () => { it('should buy more tokens', (done) => { Promise.all(Object.values(users).map(async (user) => { - await adminClient.softreserveCurrency.incrementCurrency(user.account, 1) + await adminClient.softreserveCurrency.incrementCurrency(user.account,raids[0].tier, 1) return await client.ItemManager .buyToken( user.auth.token.value, @@ -565,7 +577,7 @@ describe('Frontcraft', () => { const dbRaids = await client.RaidManager.getRaids() if(dbRaids.length === 0){ await client.UserManager.getUser(testAccounts[0].name).then(dbUser => { - if(dbUser && dbUser.currency === 1){ + if(dbUser && dbUser.MC === 1){ adminClient.signup.getSignups(raids[0]).then(signups => { if(signups.length === 0){ done() @@ -586,9 +598,9 @@ describe('Frontcraft', () => { it('reset system', (done) => { adminClient.reset.wipeCurrencyAndItems().then(() => { client.UserManager.getUser(testAccounts[0].name).then(user => { - if(user && user.currency === 0){ - client.ItemManager.getTokens(users[testAccounts[0].name.toLowerCase()].character).then(tokens => { - if(tokens.length === 0){ + if(user && user.MC === 1){ + client.ItemManager.getTokens(users[testAccounts[0].name.toLowerCase()].character, ['MC']).then(tokens => { + if(tokens!.length === 0){ done() }else{ console.log(tokens); @@ -599,6 +611,5 @@ describe('Frontcraft', () => { } }) }) - }) }) \ No newline at end of file