From a4f6721f4a1148b8f3e39cca8fd560ae07e31567 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marko=20Syd=C3=A4nmaa?= <L4072@student.jamk.fi>
Date: Fri, 12 Jul 2019 09:16:06 +0300
Subject: [PATCH] Faction multipliers have a meaning now

---
 src/faction/faction.controller.ts |  9 +++++++++
 src/faction/faction.service.ts    | 11 ++++++++++-
 src/score/score.service.ts        |  4 ++--
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/faction/faction.controller.ts b/src/faction/faction.controller.ts
index 2940b03..d53410c 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 ab1dd01..67677b1 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 d22e8dd..640970c 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,
-- 
GitLab