-
Notifications
You must be signed in to change notification settings - Fork 35
/
TeamADSFADS.cs
320 lines (278 loc) · 11.6 KB
/
TeamADSFADS.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
/*Explanation:
* Players added get color temporarily
* When players change maps (are sent MOTDs)? Or teams are removed, their colors and titles are reverted
* Players added with /team <team color>
* Points are scored whenever a flag is carried through the team's flag area
* Flags are picked up by walking through a special block (Block.Mover check)
* Flags are shown flying over the heads of the flag carrier? (would need to add a "hasFlag" char to player's)
*
* Flag position is set by /ctf flag [color]
* Flags are saved in the level properties (similar to Jail)
* Spawn is set by /ctf spawn [color]
* Spawn is saved same way as Flags
* Gotta make sure:
* To remove players who have logged off (since it wouldn't send MOTD)
* Reset hasFlag should the player not be on the map
*
* Started with /ctf, which toggles the CTF mode for that map
* /ctf reset; resets the teams
* /ctf balance; balances the teams
*/
using System;
using System.Collections.Generic;
using System.Threading;
namespace MCLawlasdfdas
{
public class Teamasdfd
{
public char color;
public int points;
public int maxpoints;
public ushort[] flagBase = { 0, 0, 0 };
public ushort[] flagLocation = { 0, 0, 0 };
public ushort[] spawn = { 0, 0, 0, 0, 0 };
public List<Player> onTeam = new List<Player>();
public Player hasFlag;
public Level mapOn;
public bool flagishome;
public bool spawnset;
public string teamname;
System.Timers.Timer onTeamCheck = new System.Timers.Timer(500);
public void killTeam()
{
foreach (Player p in onTeam)
{
p.onTeam = 'z';
}
}
public void addPlayer(Player p)
{
Team foundTeam = p.level.teams.Find(team => team.onTeam.Contains(p));
if (foundTeam != null)
foundTeam.removePlayer(p);
p.onTeam = color;
p.color = "&" + color;
onTeam.Add(p);
p.level.ChatLevel(p.color + p.prefix + p.name + Server.DefaultColor + " has joined the " + teamname + " team");
}
public void removePlayer(Player p)
{
p.onTeam = 'z';
if (p.holdingFlag) { DropFlag(p, (ushort)(p.pos[0] / 32), (ushort)(p.pos[1] / 32), (ushort)(p.pos[2] / 32)); }
onTeam.Remove(p);
p.inCtf = false;
p.holdingFlag = false;
p.level.ChatLevel(p.color + p.prefix + p.name + Server.DefaultColor + " has left the " + teamname + " team");
}
public void HaveFlag(Player p)
{
if (!p.inCtf) { return; }
mapOn.ChatLevel(p.color + p.name + Server.DefaultColor + " has stolen the " + teamname + " flag!");
p.holdingFlag = true;
p.hasFlag = this.color;
hasFlag = p;
CatchPos prevPos;
CatchPos newPos;
prevPos.x = (ushort)(hasFlag.pos[0] / 32);
prevPos.y = (ushort)(hasFlag.pos[1] / 32 + 1);
prevPos.z = (ushort)(hasFlag.pos[2] / 32);
ushort x1 = (ushort)((0.5 + hasFlag.pos[0]));
ushort y1 = (ushort)((1 + hasFlag.pos[1]));
ushort z1 = (ushort)((0.5 + hasFlag.pos[2]));
unchecked
{
hasFlag.SendSpawn((byte)-1, hasFlag.name, x1, y1, z1, hasFlag.rot[0], hasFlag.rot[1]);
}
Thread carryThread = new Thread(new ThreadStart(delegate
{
while (hasFlag != null)
{
ushort x = (ushort)(hasFlag.pos[0] / 32);
ushort y = (ushort)(hasFlag.pos[1] / 32 + 3);
ushort z = (ushort)(hasFlag.pos[2] / 32);
newPos.x = x;
newPos.y = y;
newPos.z = z;
mapOn.Blockchange(prevPos.x, prevPos.y, prevPos.z, Block.air);
mapOn.Blockchange(newPos.x, newPos.y, newPos.z, GetColorBlock(color));
prevPos.x = newPos.x;
prevPos.y = newPos.y;
prevPos.z = newPos.z;
Thread.Sleep(50);
}
mapOn.Blockchange(prevPos.x, prevPos.y, prevPos.z, Block.air);
})); carryThread.Start();
}
public void DropFlag(Player p, ushort x, ushort y, ushort z)
{
mapOn.ChatLevel(p.color + p.name + Server.DefaultColor + " has dropped the " + teamname + " flag!");
hasFlag = null;
p.holdingFlag = false;
flagLocation[0] = x;
flagLocation[1] = (ushort)(y - 1);
flagLocation[2] = z;
int i = mapOn.flags.FindIndex(flag => flag.team.color == this.color);
mapOn.flags[i].x = x;
mapOn.flags[i].y = (ushort)(y - 1);
mapOn.flags[i].z = z;
mapOn.Blockchange(x, (ushort)(y + 3), z, Block.air);
mapOn.Blockchange(x, (ushort)(y - 1), z, Block.flagbase);
mapOn.Blockchange(x, y, z, Block.mushroom);
mapOn.Blockchange(x, (ushort)(y + 1), z, GetColorBlock(color));
}
public void CaptureFlag(Player p, Team winteam, Team loseteam)
{
mapOn.ChatLevel(p.color + p.name + Server.DefaultColor + " has captured the " + teamname + " flag!");
hasFlag = null;
p.holdingFlag = false;
loseteam.flagishome = true;
flagLocation[0] = flagBase[0];
flagLocation[1] = flagBase[1];
flagLocation[2] = flagBase[2];
int i = mapOn.flags.FindIndex(flag => flag.team.color == this.color);
mapOn.flags[i].x = flagBase[0];
mapOn.flags[i].y = flagBase[1];
mapOn.flags[i].z = flagBase[2];
ushort x, y, z;
x = flagBase[0];
y = flagBase[1];
z = flagBase[2];
mapOn.Blockchange(((ushort)(p.pos[0] / 32)), ((ushort)((p.pos[1] / 32) + 2)), (ushort)(p.pos[2] / 32), Block.air);
mapOn.Blockchange(x, y, z, Block.flagbase);
mapOn.Blockchange(x, (ushort)(y + 1), z, Block.mushroom);
mapOn.Blockchange(x, (ushort)(y + 2), z, GetColorBlock(color));
winteam.points++;
mapOn.ChatLevel("The " + winteam.teamname + " team" + Server.DefaultColor + " has scored! They now have " + winteam.points + " points!");
if (winteam.points >= winteam.mapOn.maxroundpoints)
{
GameWin(winteam);
}
}
public void ReturnFlag(Player p, Team teamFlag)
{
mapOn.ChatLevel(p.color + p.name + Server.DefaultColor + " has returned the " + teamname + Server.DefaultColor + " flag!");
teamFlag.hasFlag = null;
teamFlag.flagishome = true;
teamFlag.flagLocation[0] = teamFlag.flagBase[0];
teamFlag.flagLocation[1] = teamFlag.flagBase[1];
teamFlag.flagLocation[2] = teamFlag.flagBase[2];
int i = mapOn.flags.FindIndex(flag => flag.team.color == this.color);
mapOn.flags[i].x = teamFlag.flagBase[0];
mapOn.flags[i].y = teamFlag.flagBase[1];
mapOn.flags[i].z = teamFlag.flagBase[2];
ushort x, y, z;
x = teamFlag.flagBase[0];
y = teamFlag.flagBase[1];
z = teamFlag.flagBase[2];
mapOn.Blockchange(((ushort)(p.pos[0] / 32)), ((ushort)((p.pos[1] / 32))), (ushort)(p.pos[2] / 32), Block.air);
mapOn.Blockchange(((ushort)(p.pos[0] / 32)), ((ushort)((p.pos[1] / 32) + 1)), (ushort)(p.pos[2] / 32), Block.air);
mapOn.Blockchange(((ushort)(p.pos[0] / 32)), ((ushort)((p.pos[1] / 32) - 1)), (ushort)(p.pos[2] / 32), Block.air);
mapOn.Blockchange(x, y, z, Block.flagbase);
mapOn.Blockchange(x, (ushort)(y + 1), z, Block.mushroom);
mapOn.Blockchange(x, (ushort)(y + 2), z, GetColorBlock(color));
}
public static byte GetColorBlock(char color)
{
if (color == '2')
return Block.red;
if (color == '5')
return Block.purple;
if (color == '8')
return Block.darkgrey;
if (color == '9')
return Block.blue;
if (color == 'c')
return Block.red;
if (color == 'e')
return Block.yellow;
if (color == 'f')
return Block.white;
else
return Block.air;
}
public void EndRound()
{
points = 0;
maxpoints = 0;
flagLocation[0] = flagBase[0];
flagLocation[1] = flagBase[1];
flagLocation[2] = flagBase[2];
flagishome = true;
hasFlag = null;
}
public void GameWin(Team team)
{
team.mapOn.ChatLevel("The " + team.teamname + " team" + Server.DefaultColor + " has won the game!");
team.mapOn.ctfmode = false;
foreach (Team derp in mapOn.teams)
{
derp.EndRound();
}
}
public void ResetRound()
{
onTeamCheck.Start();
onTeamCheck.Elapsed += delegate
{
foreach (Player player in onTeam)
{
if (!player.loggedIn || player.level != mapOn)
{
removePlayer(player);
}
}
};
if (!spawnset)
{
spawn[0] = mapOn.spawnx;
spawn[1] = mapOn.spawny;
spawn[2] = mapOn.spawnz;
spawn[3] = mapOn.rotx;
spawn[4] = mapOn.roty;
}
foreach (Player player in onTeam)
{
ushort x1 = (ushort)((0.5 + spawn[0]) * 32);
ushort y1 = (ushort)((1 + spawn[1]) * 32);
ushort z1 = (ushort)((0.5 + spawn[2]) * 32);
unchecked
{
player.SendSpawn((byte)-1, player.name, x1, y1, z1, (byte)spawn[3], (byte)spawn[4]);
player.SendPos((byte)-1, x1, y1, z1, (byte)spawn[3], (byte)spawn[4]);
player.inCtf = true;
}
}
points = 0;
Thread flagThread = new Thread(new ThreadStart(delegate
{
while (!flagishome)
{
if (!mapOn.ctfmode) goto exit;
if (hasFlag == null)
{
ushort x = flagLocation[0];
ushort y = flagLocation[1];
ushort z = flagLocation[2];
mapOn.Blockchange(x, y, z, Block.flagbase);
mapOn.Blockchange(x, (ushort)(y + 1), z, Block.mushroom);
mapOn.Blockchange(x, (ushort)(y + 2), z, GetColorBlock(color));
Thread.Sleep(200);
}
}
while (flagishome)
{
if (!mapOn.ctfmode) goto exit;
ushort x = flagBase[0];
ushort y = flagBase[1];
ushort z = flagBase[2];
mapOn.Blockchange(x, y, z, Block.flagbase);
mapOn.Blockchange(x, (ushort)(y + 1), z, Block.mushroom);
mapOn.Blockchange(x, (ushort)(y + 2), z, GetColorBlock(color));
Thread.Sleep(200);
}
exit: ;
})); flagThread.Start();
}
public struct CatchPos { public ushort x, y, z; public byte type;}
}
}