@@ -2,40 +2,41 @@ import { Injectable } from '@nestjs/common';
2
2
import { ICommand , ofType , Saga } from '@nestjs/cqrs' ;
3
3
import { Observable } from 'rxjs' ;
4
4
import { filter , map } from 'rxjs/operators' ;
5
- import { FindGameServerCommand } from 'gameserver/command/FindGameServer/find-game-server.command' ;
6
- import { MatchInfo , RoomReadyEvent } from 'gateway/events/room-ready.event' ;
5
+ import { RoomReadyEvent } from 'gateway/events/room-ready.event' ;
7
6
import { MatchmakingMode } from 'gateway/shared-types/matchmaking-mode' ;
8
7
import { ProcessRankedMatchCommand } from 'gameserver/command/ProcessRankedMatch/process-ranked-match.command' ;
9
8
import { PlayerId } from 'gateway/shared-types/player-id' ;
10
9
import * as uuidr from 'uuid' ;
11
10
import { ProcessAchievementsCommand } from 'gameserver/command/ProcessAchievements/process-achievements.command' ;
12
11
import { MatchRecordedEvent } from 'gameserver/event/match-recorded.event' ;
12
+ import { PrepareGameCommand } from 'gameserver/command/PrepareGame/prepare-game.command' ;
13
+ import { GamePreparedEvent } from 'gameserver/event/game-prepared.event' ;
14
+ import { FindGameServerCommand } from 'gameserver/command/FindGameServer/find-game-server.command' ;
13
15
14
16
export const uuid = ( ) : string => uuidr . v4 ( ) ;
15
17
16
-
17
18
@Injectable ( )
18
19
export class GameserverSaga {
19
20
@Saga ( )
20
- listenReactions = ( events$ : Observable < any > ) : Observable < ICommand > => {
21
+ prepareRoomGame = ( events$ : Observable < any > ) : Observable < ICommand > => {
21
22
return events$ . pipe (
22
23
ofType ( RoomReadyEvent ) ,
23
24
map (
24
- e =>
25
- new FindGameServerCommand (
26
- new MatchInfo (
27
- e . mode ,
28
- e . roomId ,
29
- e . players ,
30
- 0 ,
31
- e . version ,
32
- ) ,
33
- 0 ,
34
- ) ,
25
+ ( e : RoomReadyEvent ) =>
26
+ new PrepareGameCommand ( e . mode , e . roomId , e . players , e . version ) ,
35
27
) ,
36
28
) ;
37
29
} ;
38
30
31
+ @Saga ( )
32
+ findServer = ( events$ : Observable < any > ) : Observable < ICommand > => {
33
+ return events$ . pipe (
34
+ ofType ( GamePreparedEvent ) ,
35
+ map ( ( e : GamePreparedEvent ) => new FindGameServerCommand ( e , 0 ) ) ,
36
+ ) ;
37
+ } ;
38
+
39
+ // GamePreparedEvent
39
40
40
41
// @Saga ()
41
42
// tournamentGameReady = (events$: Observable<any>): Observable<ICommand> => {
@@ -76,17 +77,25 @@ export class GameserverSaga {
76
77
processRanked = ( events$ : Observable < any > ) : Observable < ICommand > => {
77
78
return events$ . pipe (
78
79
ofType ( MatchRecordedEvent ) ,
79
- filter ( ( t : MatchRecordedEvent ) => t . type === MatchmakingMode . RANKED || t . type === MatchmakingMode . UNRANKED ) ,
80
+ filter (
81
+ ( t : MatchRecordedEvent ) =>
82
+ t . type === MatchmakingMode . RANKED ||
83
+ t . type === MatchmakingMode . UNRANKED ,
84
+ ) ,
80
85
map ( ( e : MatchRecordedEvent ) => {
81
-
82
86
const losers = e . players
83
- . filter ( p => p . team !== e . winner )
84
- . map ( t => new PlayerId ( t . steam_id ) ) ;
87
+ . filter ( ( p ) => p . team !== e . winner )
88
+ . map ( ( t ) => new PlayerId ( t . steam_id ) ) ;
85
89
const winners = e . players
86
- . filter ( p => p . team === e . winner )
87
- . map ( t => new PlayerId ( t . steam_id ) ) ;
90
+ . filter ( ( p ) => p . team === e . winner )
91
+ . map ( ( t ) => new PlayerId ( t . steam_id ) ) ;
88
92
89
- return new ProcessRankedMatchCommand ( e . matchId , winners , losers , e . type ) ;
93
+ return new ProcessRankedMatchCommand (
94
+ e . matchId ,
95
+ winners ,
96
+ losers ,
97
+ e . type ,
98
+ ) ;
90
99
} ) ,
91
100
) ;
92
101
} ;
0 commit comments