diff --git a/src/faction/faction.controller.ts b/src/faction/faction.controller.ts index c22ef1fab0c3ccddcddad9440a1803b2c93204d3..f430c3ed7f801a033df3e686dbddb9e22829e139 100644 --- a/src/faction/faction.controller.ts +++ b/src/faction/faction.controller.ts @@ -20,6 +20,7 @@ import { PromotePlayerDTO, JoinFactionDTO, JoinGameGroupDTO, + FactionDTO, } from './faction.dto'; import { FactionService } from './faction.service'; import { Roles, GameStates } from '../shared/guard.decorator'; @@ -99,6 +100,13 @@ export class FactionController { leaveFaction(@GamePerson('gamepersonId') gamepersonId) { return this.factionservice.leaveFaction(gamepersonId); } + // 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') diff --git a/src/faction/faction.service.ts b/src/faction/faction.service.ts index 016c405749dcbed0300db801a660499c8095159e..287b43438fa0818a60d85c77d4682a55ce4d064d 100644 --- a/src/faction/faction.service.ts +++ b/src/faction/faction.service.ts @@ -3,8 +3,14 @@ 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 { @@ -61,6 +67,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,