コード例 #1
0
        public static void JoinTeam(ArenaClient client, TOTeamInst team)
        {
            if (client.Team == team)
            {
                return;
            }

            if (team != null && (!IsRunning || Phase == TOPhases.None || Phase == TOPhases.Finish))
            {
                return;
            }

            client.KillCharacter();

            int index = teams.IndexOf(team);

            if (index >= 0)
            {
                // don't join a team which has already more players than the others
                //if (!teams.TrueForAll(t => team.Players.Count <= t.Players.Count - (t == client.Team ? 1 : 0)))
                //    return;

                if (client.Team != null)
                {
                    client.Team.Players.Remove(client);
                }

                client.Team = team;
                team.Players.Add(client);
            }
            else if (client.Team != null)
            {
                client.Team.Players.Remove(client);
                client.Team = null;
            }
            client.TOClass = null;

            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.TOJoinTeam);
            stream.Write((sbyte)index);
            client.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered);

            SpawnCharacter(client);

            OnChangeTeamComposition?.Invoke();
        }
コード例 #2
0
        public static void ReadSelectClass(ArenaClient client, PacketReader stream)
        {
            if (!IsRunning || client.Team == null || Phase == TOPhases.None || Phase == TOPhases.Finish)
            {
                return;
            }

            int index    = stream.ReadByte();
            var classDef = client.Team.Def.ClassDefs.ElementAtOrDefault(index);

            if (classDef != null)
            {
                client.TOClass = classDef;
            }

            client.KillCharacter();
            if (Phase == TOPhases.Warmup)
            {
                SpawnCharacter(client);
            }
        }