-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
365 lines (309 loc) · 12.1 KB
/
Player.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
using RPGTestC.Items;
using RPGTestC.Items.Armour;
using RPGTestC.Items.Weapons;
using RPGTestC.Locations;
using RPGTestC.UI;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace RPGTestC
{
public class Player
{
#region Variables
public enum Status // Тип перечисления статусов игрока
{
None,
Poisoned,
OnFire,
Frozen,
Blind
}
public static int LVL = 0;
public static float XP = 0;
public static float MaxXP = 25;
public static float HP = 50;
public static float MaxHP = 50 + (float)Math.Pow(2,LVL) - 1;
public static Item[] Inventory = new Item[3]
{
//0-Weapon, 1-Armour, 2-Special Item
new Default_W(),
new Default_A(),
new PotionBag()
};
public static Item Weapon
{
get
{
return Inventory[0];
}
set
{
Inventory[0] = value;
}
}
public static Item Armour
{
get
{
return Inventory[1];
}
set
{
Inventory[1] = value;
}
}
public static Item Special
{
get
{
return Inventory[2];
}
set
{
Inventory[2] = value;
}
}
public static Item[] Passive_Inventory = new Item[8]
{
new None_Item(),
new None_Item(),
new None_Item(),
new None_Item(),
new None_Item(),
new None_Item(),
new None_Item(),
new None_Item(),
};
static public Status PStatus; // Переменная статуса игрока
static public int healCount = 3; // Кол-во зарядов
static public int maxHealCount = 3; // Макс. кол-во зарядов
public const float critCoeff = 1.75f; // Коэффициент критического урона
public static int questNum = 0; //Номер квеста, который в процессе выполнения (0 - игрок не был в таверне, 1 - Страж в Голубой Долине и т. д., всего 14(пока что))
public static int Money = 20;
public static int MasteryPoints = 0;
static public bool towerLoc = false; // Доступна ли башня
static public bool gotAnarchy = false; // Получено ли секретное достижение
static public bool ahShit = false; // Получено ли секретное достижение
static public bool brokeOut = false; // Выбил ли игрок дверь
static public bool BHDweller = false; // Выпил ли игрок чёрную дыру
static public string savename;
public static string[] subDirs;
#endregion
static public float GetMaxXP() => 25 * (float)Math.Round(Math.Pow(1.5, LVL), 1);
static public float GetMaxHP() => 50 + (float)Math.Pow(2, LVL);
static public void SaveFileHandler()
{
subDirs = Directory.GetFiles("Saves");
SaveFileMenu.ShowMenu();
/*
Console.Clear();
Console.WriteLine("Выберите название для файла сохранения (Образец: saveFile)");
foreach (string subDir in subDirs) Console.WriteLine(subDir);
savename = "Saves\\" + Console.ReadLine() + ".RPGSF" + RPG.VERSION;
if (isSaving) SaveProgress(false);
*/
}
static public void SaveProgress(bool currentSave)
{
List<object> saveList = new List<object>
{
City.cityBank,
LVL,
XP,
HP,
Money,
City.currentPlotState,
questNum,
City.wasInCity,
MasteryPoints,
towerLoc,
Tower.mageName,
Tower.wasIntroduced,
gotAnarchy,
ahShit,
brokeOut,
BHDweller,
};
foreach (Item it in Inventory)
{
saveList.Add(it.ID);
saveList.Add(it.LVL);
};
foreach (Item it in Passive_Inventory)
{
saveList.Add(it.ID);
saveList.Add(it.LVL);
};
if (!currentSave)
{
if (File.Exists(savename))
{
Console.WriteLine("Данный файл существует. Перезаписать? 1 - Да, 2 - Нет, 3 - Загрузить этот файл");
switch (Console.ReadKey().Key)
{
case ConsoleKey.D1:
case ConsoleKey.NumPad1:
SaveProgress(true);
break;
case ConsoleKey.D2:
case ConsoleKey.NumPad2:
SaveFileHandler();
break;
case ConsoleKey.D3:
case ConsoleKey.NumPad3:
LoadProgress(true);
break;
default:
Console.WriteLine("Некорректный ввод");
SaveProgress(currentSave);
break;
}
}
else SaveProgress(true);
}
else
{
try
{
string str = "";
foreach (object obj in saveList) str += obj + "\n";
using (StreamWriter sw = new StreamWriter(savename, false, Encoding.Default)) sw.Write(str);
Console.WriteLine("Файл сохранён.");
}
catch
{
Console.WriteLine("Некорректный ввод");
SaveFileMenu.ShowMenu();
}
}
}
static public void LoadProgress(bool currentSave)
{
int ID;
int ILVL;
if (!currentSave)
{
SaveFileMenu.isLoading = true;
SaveFileHandler();
if (!File.Exists(savename))
{
Console.WriteLine("Данный файл не существует. Попробуйте ещё раз.");
LoadProgress(false);
}
}
using (StreamReader sr = new StreamReader(savename))
{
try
{
string line;
line = sr.ReadLine();
City.cityBank = Convert.ToSingle(line);
line = sr.ReadLine();
LVL = Convert.ToByte(line);
line = sr.ReadLine();
XP = Convert.ToInt32(line);
MaxXP = GetMaxXP();
line = sr.ReadLine();
HP = Convert.ToInt32(line);
MaxHP = GetMaxHP();
line = sr.ReadLine();
Money = Convert.ToInt32(line);
line = sr.ReadLine();
City.currentPlotState = (City.QuestState)Enum.Parse(typeof(City.QuestState), line);
line = sr.ReadLine();
questNum = Convert.ToInt32(line);
line = sr.ReadLine();
City.wasInCity = Convert.ToBoolean(line);
line = sr.ReadLine();
MasteryPoints = Convert.ToInt32(line);
line = sr.ReadLine();
towerLoc = Convert.ToBoolean(line);
line = sr.ReadLine();
Tower.mageName = line;
line = sr.ReadLine();
Tower.wasIntroduced = Convert.ToBoolean(line);
line = sr.ReadLine();
gotAnarchy = Convert.ToBoolean(line);
line = sr.ReadLine();
ahShit = Convert.ToBoolean(line);
line = sr.ReadLine();
brokeOut = Convert.ToBoolean(line);
line = sr.ReadLine();
BHDweller = Convert.ToBoolean(line);
#region Inventory Loading (Leave for last)
for (int i = 0; i < Inventory.Length + Passive_Inventory.Length; i++)
{
line = sr.ReadLine();
ID = Convert.ToInt16(line);
// This is absolutely fucking horrible and disgusting, but I have no other clue on how to implement this. ffs!
/*
* Let me explain why I have to resort to such measures: Even though I could have a list of Items from wich I could pull from in
* the previous version of loading/saving the inventory, that would lead to something unpleasant: if you have Ying and have
* leveled it up, then each new Ying you get will be leveled up as well. See why this is an issue?
*
* Basically, all I want to do is make unique examples of Items everytime the player gets one. Which is not ideal anyway.
*/
Item buffer;
switch (ID)
{
case 0:
buffer = new None_Item();
break;
case 1:
buffer = new Default_A();
break;
case 2:
buffer = new Ying_A();
break;
case 3:
buffer = new Default_W();
break;
case 4:
buffer = new Yang_W();
break;
case 5:
buffer = new PotionBag();
break;
default:
buffer = new None_Item();
break;
}
line = sr.ReadLine();
ILVL = Convert.ToInt16(line);
buffer.LVL = ILVL;
buffer.Upgrade();
if (i >= Inventory.Length) Passive_Inventory[i - Inventory.Length] = buffer;
else Inventory[i] = buffer;
}
#endregion
}
catch
{
Console.WriteLine("Загружаемый файл, скорее всего, повреждён.");
LoadProgress(false);
}
Console.WriteLine("Файл загружен");
}
}
static public void LvlUp(bool cheat = false)
{
while ((XP >= MaxXP || cheat) && LVL <= 14)
{
LVL++;
MaxXP = GetMaxXP();
MaxHP = GetMaxHP();
cheat = false;
}
if (LVL == 15)
{
MaxXP = 10950;
MasteryPoints += (int)Math.Round((XP - MaxXP) / 10);
XP = MaxXP;
}
Console.Clear();
}
}
}