-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterpreter.cs
63 lines (53 loc) · 1.89 KB
/
Interpreter.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
using System.Collections.Generic;
using ArmelloLogTools.Armello;
namespace ArmelloLogTools
{
public class Interpreter
{
private readonly Dictionary<int, Player> _players = new Dictionary<int, Player>(4);
public IReadOnlyDictionary<int, Player> Players => _players;
private int _currentPlayerId = 0;
private Player CurrentPlayer
{
get => _players[_currentPlayerId];
set => _players[_currentPlayerId] = value;
}
public void ProcessEvents(IEnumerable<Event> events)
{
foreach (var @event in events)
{
ProcessEvent(@event);
}
}
private void ProcessEvent(Event @event)
{
switch (@event.Type)
{
//New game, reset players
case EventType.LoadGame:
_players.Clear();
_currentPlayerId = 0;
break;
//Add player to _players
case EventType.LoadPlayer:
var playerEvent = (LoadPlayerEvent) @event;
_players[playerEvent.Player.Id] = playerEvent.Player;
break;
//New turn, update currentPlayerId
case EventType.StartTurn:
var turnEvent = (StartTurnEvent) @event;
_currentPlayerId = turnEvent.PlayerId;
break;
//Quest spawned, increment player's quest count
case EventType.OnQuestSpawnComplete:
{
var questSpawnEvent = (OnQuestSpawnComplete) @event;
var player = _players[questSpawnEvent.PlayerId];
player.QuestCount++;
_players[questSpawnEvent.PlayerId] = player;
break;
}
}
}
}
}