diff --git a/src/faction/faction.controller.ts b/src/faction/faction.controller.ts index 2940b036852718e3af74947e120a513e138f74c9..d53410cca56f8d2b22226e31f4e4b5ecfd1e63db 100644 --- a/src/faction/faction.controller.ts +++ b/src/faction/faction.controller.ts @@ -19,6 +19,7 @@ import { PromotePlayerDTO, JoinFactionDTO, JoinGameGroupDTO, + FactionDTO, } from './faction.dto'; import { FactionService } from './faction.service'; import { Roles, GameStates } from '../shared/guard.decorator'; @@ -90,6 +91,14 @@ export class FactionController { return this.factionservice.joinFaction(person, data); } + // used to change factions multiplier + @Put('faction-multiplier/:id') + @Roles('admin') + @GameStates('STARTED') + factionMultiplier(@Param('id') game, @Body() body: FactionDTO){ + return this.factionservice.changeFactionMultiplier(body); + } + // check if person belongs to a faction in a game @Get('check-faction/:id') @UseGuards(new AuthGuard()) diff --git a/src/faction/faction.service.ts b/src/faction/faction.service.ts index ab1dd014165b8c8c37b812b70757f3792fa59711..67677b1c36004a698465ae5df87ed8547df514b5 100644 --- a/src/faction/faction.service.ts +++ b/src/faction/faction.service.ts @@ -3,8 +3,9 @@ import { InjectRepository } from '@nestjs/typeorm'; import { Repository, Not } from 'typeorm'; import { FactionEntity, GameGroupEntity } from './faction.entity'; -import { JoinFactionDTO, GameGroupDTO, JoinGameGroupDTO } from './faction.dto'; +import { JoinFactionDTO, GameGroupDTO, JoinGameGroupDTO, FactionDTO } from './faction.dto'; import { Game_PersonEntity } from '../game/game.entity'; +import { async } from 'rxjs/internal/scheduler/async'; @Injectable() export class FactionService { @@ -53,6 +54,14 @@ export class FactionService { } } + async changeFactionMultiplier(body: FactionDTO){ + const faction = await this.factionRepository.findOne({ + where: {factionId: body.factionId} + }); + faction.multiplier = body.multiplier; + return await this.factionRepository.save(faction); + } + async promotePlayer(body) { const gamepersonId = body.player; // get playerdata diff --git a/src/score/score.service.ts b/src/score/score.service.ts index d22e8dd24b8bf219a9f28557169c18e0d9e79247..640970c8e5ca99e877982cc2f4174123595792bb 100644 --- a/src/score/score.service.ts +++ b/src/score/score.service.ts @@ -40,7 +40,7 @@ export class ScoreService { order: { scoreTimeStamp: 'DESC' }, }); if (lastScore) { - scoreData.score += lastScore.score; + scoreData.score += lastScore.score * faction.multiplier; } // add the score for Faction const newScore = await this.scoreRepository.create(scoreData); @@ -69,7 +69,7 @@ export class ScoreService { i => i.faction === current.owner.factionId, ); index !== -1 - ? await (scoreData[index]['score'] += box.objectivePointMultiplier) + ? await (scoreData[index]['score'] += box.objectivePointMultiplier * current.owner.multiplier) : await scoreData.push({ score: box.objectivePointMultiplier, faction: current.owner.factionId,