-
Notifications
You must be signed in to change notification settings - Fork 1
/
SerotoninSensor.cs
73 lines (60 loc) · 2.24 KB
/
SerotoninSensor.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
namespace bootstrapper.sample
{
using System.Collections.Generic;
using bootstrapper.sample.Sirius;
public class SerotoninSensor : AbstractSensor, IVhptHeartbeatAware, IVphtHandleMessage<BlackHoleDetected>, ISerotoninSensor
{
private readonly Dictionary<int, string> knownSerotoninLevels =
new Dictionary<int, string>
{
{ 60, "Mouse (orally)" },
{ 81, "Mouse (intravenously)" },
{ 30, "Rat (intravenously)" },
{ 13, "guinea pig (intravenously)" },
{ 5, "Cat (intravenously)" },
{ 150, "Raver on ecstasy (intravenously)" },
};
private readonly IVphtSerotoninProbe probe;
public SerotoninSensor(IVphtSerotoninProbe probe)
{
this.probe = probe;
}
public override string Name
{
get { return "Serotonin Sensor"; }
}
public bool InPanicMode { get; private set; }
public bool PanicModeEnabled { get; private set; }
public override string Describe()
{
return "Measures the serotinin level of the people transported.";
}
protected override void MessageBusInitializedCore(IVphtMessageBus messageBus)
{
if (this.PanicModeEnabled)
{
messageBus.Subscribe(this);
}
}
public void Bumm()
{
if (this.InPanicMode)
{
this.DataBus.SendAsync(Data.New(this.Name, "We are going to die anyways! No need to detect serotonin level!"));
return;
}
int level = this.probe.Take();
string message;
if (!this.knownSerotoninLevels.TryGetValue(level, out message))
{
message = "You are not happy enought!";
}
this.DataBus.SendAsync(Data.New(this.Name, string.Format("Serotonin level of people transported is that of a {0}.", message)));
}
public void Handle(BlackHoleDetected message)
{
this.InPanicMode = true;
this.DataBus.SendAsync(Data.New(this.Name, "We are going to die!"));
}
}
}