-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerCommands.cs
More file actions
216 lines (188 loc) · 8.04 KB
/
PlayerCommands.cs
File metadata and controls
216 lines (188 loc) · 8.04 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Data.Entity;
using TextEngine.Models;
namespace TextEngine
{
public static class PlayerCommands
{
public static void Look(string[] cmdParts)
{
if(cmdParts.Length == 1)
{
Program.character.CurrentRoom.Look();
}
else
{
var itemName = cmdParts[1].ToLower();
// check if item exists in room
var item = Program.character.CurrentRoom.Inventory.Items.FirstOrDefault(x => x.Name.ToLower() == itemName);
if(item != null)
{
item.Look();
return;
}
// check if item exists in character inventory
item = Program.character.Inventory.Items.FirstOrDefault(x => x.Name.ToLower() == itemName);
if (item != null)
{
item.Look();
return;
}
// is the item a monster?
var monster = Program.character.CurrentRoom.Monsters.FirstOrDefault(x => x.MonsterType.Name.ToLower() == itemName);
if (monster != null)
{
monster.Look();
return;
}
Utility.Print(ConsoleColor.DarkMagenta, "You don't see that item here!");
}
}
public static void Help()
{
Utility.Print(ConsoleColor.DarkGreen, " *** Command List *** ");
Utility.Print(ConsoleColor.DarkGreen, "Directions: n, s, e, w, ne, nw, se, sw, u, d");
Utility.Print(ConsoleColor.DarkGreen, "Look: l [<dir>, <item>, <monster>]");
Utility.Print(ConsoleColor.DarkGreen, "Combat: a <monster>");
Utility.Print(ConsoleColor.DarkGreen, "Get: g <item>");
Utility.Print(ConsoleColor.DarkGreen, "Map: map");
Console.WriteLine();
#if TEXTENGINEADMIN
Utility.Print(ConsoleColor.DarkGreen, " *** Admin Commands *** ");
Utility.Print(ConsoleColor.DarkGreen, "create room <dir>");
Utility.Print(ConsoleColor.DarkGreen, "set name <room name>");
Utility.Print(ConsoleColor.DarkGreen, "set desc <room description>");
Utility.Print(ConsoleColor.DarkGreen, "set <dir> item <itemid>");
Utility.Print(ConsoleColor.DarkGreen, "create item <item name>");
Utility.Print(ConsoleColor.DarkGreen, "set item name <itemid> <new name>");
Utility.Print(ConsoleColor.DarkGreen, "create monster <monster name>");
Utility.Print(ConsoleColor.DarkGreen, "list");
Utility.Print(ConsoleColor.DarkGreen, "set monster <monster id> <stat> <value>");
Utility.Print(ConsoleColor.DarkGreen, "spawn <monster id>");
#endif
}
public static void Get(string[] cmdParts)
{
string itemName = string.Join(" ", cmdParts.Skip(1)).ToLower();
using (var context = new TextEngineContext())
{
var localItem = Program.character.CurrentRoom.Inventory.Items.FirstOrDefault(i => i.Name.ToLower() == itemName);
if (localItem == null)
{
Utility.Print(ConsoleColor.Yellow, "You don't see that item here!");
return;
}
var item = context.Items.FirstOrDefault(i => i.ItemID == localItem.ItemID);
var character = Character.GetInstance(context);
item.Inventory = character.Inventory;
context.SaveChanges();
Program.RefreshGameState(context);
Utility.Print(ConsoleColor.DarkGreen, "Taken.");
}
}
public static void Drop(string[] cmdParts)
{
string itemName = string.Join(" ", cmdParts.Skip(1)).ToLower();
using (var context = new TextEngineContext())
{
var localItem = Program.character.Inventory.Items.FirstOrDefault(i => i.Name.ToLower() == itemName);
if (localItem == null)
{
Utility.Print(ConsoleColor.Yellow, "You don't seem to have that item!");
return;
}
var item = context.Items.FirstOrDefault(i => i.ItemID == localItem.ItemID);
var character = Character.GetInstance(context);
item.Inventory = character.CurrentRoom.Inventory;
context.SaveChanges();
Program.RefreshGameState(context);
Utility.Print(ConsoleColor.DarkGreen, "Dropped.");
}
}
public static void Attack(string[] cmdParts)
{
if(cmdParts.Length < 2)
{
Utility.Print(ConsoleColor.Yellow, "Invalid command!");
return;
}
string monsterName = cmdParts[1].ToLower();
var monster = Program.character.CurrentRoom.Monsters.FirstOrDefault(m => m.MonsterType.Name.ToLower() == monsterName);
if(monster == null)
{
Utility.Print(ConsoleColor.Yellow, "You don't see that monster here!");
return;
}
int attack = Program.Random.Next(1, 101);
if (attack < 75)
{
int damage = Program.Random.Next(1, 10);
Utility.Print(ConsoleColor.DarkRed, "You smash the " + monster.MonsterType.Name + " for " + damage + " points of damage!");
monster.MonsterType.HP -= damage;
if(monster.MonsterType.HP <= 0)
{
monster.Die();
using (var context = new TextEngineContext())
{
context.Monsters.Remove(monster);
context.SaveChanges();
Program.RefreshGameState(context);
}
}
}
else
{
Utility.Print(ConsoleColor.DarkGreen, "You miss the " + monster.MonsterType.Name + ".");
}
}
public static void DrawMap()
{
int x_min = Program.character.CurrentRoom.X - 3;
int x_max = Program.character.CurrentRoom.X + 3;
int y_min = Program.character.CurrentRoom.Y - 3;
int y_max = Program.character.CurrentRoom.Y + 3;
using (var context = new TextEngineContext())
{
var rooms = context.Rooms.Where(
r => r.X <= x_max &&
r.X >= x_min &&
r.Y <= y_max &&
r.Y >= y_min &&
r.Z == Program.character.CurrentRoom.Z);
for(int y = y_max; y >= y_min; y--)
{
string line1 = string.Empty;
string line2 = string.Empty;
string line3 = string.Empty;
for (int x = x_min; x <= x_max; x++)
{
var room = rooms
.Where(r => r.X == x && r.Y == y)
.Include(r => r.Doors)
.FirstOrDefault();
if(room == null)
{
line1 += " ";
line2 += " ";
line3 += " ";
}
else
{
string[] temp = room.getMap();
line1 += temp[0];
line2 += temp[1];
line3 += temp[2];
}
}
Utility.Print(ConsoleColor.DarkGreen, line1);
Utility.Print(ConsoleColor.DarkGreen, line2);
Utility.Print(ConsoleColor.DarkGreen, line3);
}
}
}
}
}