blob: 26c9fc1f6512e8c856de03b378864b6aa3697f79 (
plain)
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
|
using Sandbox;
using Sandbox.UI;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MurderGame;
public class AssignPhase : BasePhase
{
public override string Title => "Assigning teams";
public int TicksElapsed;
public override void Activate()
{
foreach (var entity in Entity.All.OfType<DroppedWeapon>())
{
entity.Delete();
}
var detectivesNeeded = 1;
var murderersNeeded = 1;
List<SpawnPoint> spawnpoints = Entity.All.OfType<SpawnPoint>().OrderBy( x => Guid.NewGuid() ).ToList();
var clients = Game.Clients.ToList();
foreach ( int i in Enumerable.Range( 0, clients.Count ).OrderBy( x => Guid.NewGuid() ) )
{
var client = clients[i];
if (client.Pawn != null)
{
((Player) client.Pawn).Cleanup();
client.Pawn.Delete();
}
Player pawn = new();
client.Pawn = pawn;
if (spawnpoints.Count == 0)
{
ChatBox.Say( "Could not spawn " + client.Name + " as there are not enough spawn points." );
pawn.CurrentTeam = Team.Spectator;
continue;
}
pawn.DressFromClient( client );
if (murderersNeeded > 0)
{
pawn.CurrentTeam = Team.Murderer;
--murderersNeeded;
}
else if (detectivesNeeded > 0)
{
pawn.CurrentTeam = Team.Detective;
--detectivesNeeded;
}
else
{
pawn.CurrentTeam = Team.Bystander;
}
Log.Info( "Assigning " + client.Name + " to team " + TeamOperations.GetTeamName( pawn.CurrentTeam ) );
var spawnpoint = spawnpoints[0];
spawnpoints.RemoveAt( 0 );
var tx = spawnpoint.Transform;
tx.Position = tx.Position + Vector3.Up * 50.0f;
pawn.Transform = tx;
RoleOverlay.Show( To.Single( client ) );
}
base.TimeLeft = 5;
}
public override void Deactivate()
{
foreach (var client in Game.Clients)
{
RoleOverlay.Hide( To.Single( client ) );
}
}
public override void Tick()
{
++TicksElapsed;
if ( base.TimeLeft != -1 && TicksElapsed % Game.TickRate == 0 && --base.TimeLeft == 0 )
{
base.IsFinished = true;
base.NextPhase = new PlayPhase();
}
}
}
|