-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTelegramPlayer.cs
204 lines (172 loc) · 6.81 KB
/
TelegramPlayer.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using System.Collections.Generic;
using HungerGamesTelegram.Events;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups;
namespace HungerGamesTelegram
{
public class TelegramPlayer : Actor
{
public Game Game { get; }
public long Id {get;}
private readonly ITelegramBotClient _client;
public TelegramPlayer(Game game, long id, ITelegramBotClient client, string name)
{
Game = game;
Id = id;
_client = client;
Name = name;
Level = 1;
}
enum State
{
AskForDirection,
None,
AskForEvent
}
private State _currentState = State.None;
internal void ParseMessage(Message message)
{
Logger.Log(this, $" > {message.Text}");
if(IsDead || !Game.Started)
{
return;
}
if(_currentState == State.None){
return;
}
if(_currentState == State.AskForDirection){
var direction = message.Text;
if(direction != null && Location.Directions.ContainsKey(direction))
{
nextLocation = Location.Directions[direction];
}
}
else
{
EventEncounterReply = message.Text ?? "";
}
}
public void Write(params string[] message)
{
Logger.Log(this, string.Join("\n", message));
_client.SendTextMessageAsync(Id, string.Join("\n", message), ParseMode.Markdown, true, false, 0, new ReplyKeyboardRemove());
}
public void Write(IReplyMarkup markup, params string[] message)
{
Logger.Log(this, string.Join("\n", message));
_client.SendTextMessageAsync(Id, string.Join("\n", message), ParseMode.Markdown, true, false, 0, markup);
}
public override void EventPrompt(string message, string[] options)
{
_currentState = State.AskForEvent;
List<List<KeyboardButton>> optionButtons = new List<List<KeyboardButton>>();
foreach (var option in options)
{
optionButtons.Add(new List<KeyboardButton> {new KeyboardButton(option)});
}
ReplyKeyboardMarkup keyboard = new ReplyKeyboardMarkup(optionButtons);
Write(keyboard, $"Du er ved *{Location.Name}*", $"Du er level *{Level}*", message);
}
public override void MovePrompt()
{
List<string> locations = new List<string>();
foreach (var location in Location.Directions)
{
locations.Add($"*{location.Key}*: {location.Value.Name}" + (location.Value.IsDeadly ? $" ({location.Value.Environment})" : ""));
}
var north = Location.Directions.ContainsKey("Nord") && !Location.Directions["Nord"].IsDeadly;
var west = Location.Directions.ContainsKey("Vest") && !Location.Directions["Vest"].IsDeadly;
var east = Location.Directions.ContainsKey("Øst") && !Location.Directions["Øst"].IsDeadly;
var south = Location.Directions.ContainsKey("Sør") && !Location.Directions["Sør"].IsDeadly;
var directions = new List<List<KeyboardButton>>
{
new List<KeyboardButton>()
{
new KeyboardButton(" "),
new KeyboardButton(north ? "Nord" : " "),
new KeyboardButton(" "),
},
new List<KeyboardButton>()
{
new KeyboardButton(west ? "Vest" : " "),
new KeyboardButton("Bli her"),
new KeyboardButton(east ? "Øst" : " "),
},
new List<KeyboardButton>()
{
new KeyboardButton(" "),
new KeyboardButton(south ? "Sør" : " "),
new KeyboardButton(" "),
}
};
ReplyKeyboardMarkup keyboard = new ReplyKeyboardMarkup(directions, false, false);
if (Location.IsDeadly)
{
Write(keyboard,
$"Du er ved *{Location.Name}*",
Game.GetLocationString(Location),
Location.Environment,
"*Du må flytte på deg, ellers dør du!*",
string.Join("\n", locations),
"Hvor vil du gå?");
}
else
{
Write(keyboard, $"Du er ved *{Location.Name}*",
Game.GetLocationString(Location),
string.Join("\n", locations),
"Hvor vil du gå?");
}
nextLocation = null;
_currentState = State.AskForDirection;
}
Location nextLocation;
public override void Move()
{
Move(nextLocation);
}
public override void Result(int rank)
{
Write($"Du ble *#{rank}!*");
}
public override void Message(params string[] message)
{
Write(string.Join("\n", message));
}
public override void Loot(Actor player1)
{
var item1 = LootEvent.GetWeightedRandomItem();
var item2 = LootEvent.GetWeightedRandomItem();
Level += item1.value + item2.value;
Write($"{player1.Name} ville ikke være kompis og stakk av.", $"Du fant {item1.name} **({(item1.value+1):+0;-#} level)** og {item2.name} **({(item2.value + 1):+0;-#} level)** istedet.", $"Du er level *{Level}*");
}
public override void RunAway(Actor player2)
{
Write($"Du løp vekk fra *{player2.Name}*");
}
public override void FailAttack(Actor actor)
{
var item = LootEvent.GetWeightedRandomItem();
Level += item.value;
Write($"{actor.Name} løp vekk.", $"Du fant {item.name} **({item.value:+0;-#} level)**", $"Du er level *{Level}*");
}
public override void SuccessAttack(Actor actor)
{
var item = LootEvent.GetWeightedRandomItem();
Level += item.value + 2;
Write($"Du beseiret *{actor.Name}* (+2 level).", $"Du fant {item.name} **({item.value:+0;-#} level)**", $"Du er level *{Level}*");
}
public override void Die(Actor actor)
{
Write($"*{actor.Name}* beseiret deg.", "*Du er ute av spillet.*");
base.Die(actor);
}
public override void KillZone()
{
IsDead = true;
Write($"Du ble tatt av {Location.Environment}","Du er ute av spillet.");
}
}
}