-
Notifications
You must be signed in to change notification settings - Fork 0
/
Matchmaker.cs
90 lines (80 loc) · 3.07 KB
/
Matchmaker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using Saltant.Matchmaking.Games;
using Saltant.Matchmaking.Interfaces;
using Saltant.Matchmaking.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace Saltant.Matchmaking
{
public partial class Matchmaker
{
readonly GameType gameType;
readonly Events events;
public Matchmaker(GameType gameType)
{
this.gameType = gameType;
events = new();
events.MatchCreated += OnMatchCreated;
events.CreateTeamError += OnCreateTeamError;
events.ElapsedTeam += OnElapsedTeam;
InitializeGameType();
}
void OnMatchCreated(IGameMatch gameMatch)
{
switch (gameType)
{
case GameType.Thunderdome:
MatchCreated.Invoke((ThunderdomeGameMatch)gameMatch);
break;
case GameType.Team5x5:
break;
case GameType.BattleRoyale:
break;
case GameType.Deathmatch:
break;
}
}
void OnCreateTeamError(string errorText, string playerName) => CreateTeamError.Invoke(errorText, playerName);
void OnElapsedTeam(string playerName) => ElapsedTeam.Invoke(playerName);
GameBase game;
public GameBase GetGame => game;
public event Action<string> PlayerJoined;
public event Action<IGameMatch> MatchCreated;
public event Action<string, string> CreateTeamError;
public event Action<string> ElapsedTeam;
public GameType GetGameType => gameType;
internal Events GetEvents => events;
void InitializeGameType()
{
switch (gameType)
{
case GameType.None:
throw new Exception("Game Type is not selected.");
case GameType.Thunderdome:
game = new Thunderdome(this);
break;
case GameType.Team5x5:
throw new NotImplementedException($"{GameType.Team5x5} is not implemented yet.");
case GameType.BattleRoyale:
throw new NotImplementedException($"{GameType.BattleRoyale} is not implemented yet.");
case GameType.Deathmatch:
throw new NotImplementedException($"{GameType.Deathmatch} is not implemented yet.");
}
}
public enum GameType
{
None,
Thunderdome,
Team5x5,
BattleRoyale,
Deathmatch
}
public void Join(string playerName, string data, Rank rank = Rank.Training)
{
PlayerJoined.Invoke(playerName);
events.InvokeEvent(gameType, Events.EventType.CreateTeam, playerName, data, rank);
}
public void EndMatch(IGameMatch gameMatch) => events.InvokeEvent(gameType, Events.EventType.RemoveMatch, gameMatch);
public void Disconnect(string playerName) => events.InvokeEvent(gameType, Events.EventType.Disconnect, playerName);
}
}