Пример #1
0
        static void EndTO()
        {
            phase = TOPhases.None;

            ArenaClient.ForEach(c =>
            {
                ArenaClient client = (ArenaClient)c;
                if (client.Team != null || client.BaseClient.SpecWorld == world.BaseWorld)
                {
                    client.Spectate();
                }

                client.TODeaths = client.TOKills = client.TOScore = 0;
            });
            teams.Clear();

            activeTODef = null;
            world       = null;

            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.TOEnd);
            ArenaClient.ForEach(c => c.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered));

            CheckStartTO();
        }
Пример #2
0
        public void SendPointsMessage(sbyte points)
        {
            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.PointsMessage);
            stream.Write(points);
            this.SendScriptMessage(stream, NetPriority.Low, NetReliability.Unreliable);
        }
Пример #3
0
        public static void SendTeamMessage(string message)
        {
            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.ChatTeamMessage);
            stream.Write(message);
            ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable);
        }
Пример #4
0
        void Spectate()
        {
            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.HordeSpectate);
            ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable);
            Close();
        }
Пример #5
0
        static PacketWriter GetData()
        {
            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.TOTeamCount);
            stream.Write((byte)TeamMode.Teams.Count);
            for (int i = 0; i < TeamMode.Teams.Count; i++)
            {
                stream.Write((byte)TeamMode.Teams[i].Players.Count);
            }
            return(stream);
        }
Пример #6
0
        static void SendGameInfo(ArenaClient client)
        {
            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.GameInfo);
            stream.Write((byte)client.ID);

            stream.Write((byte)ArenaClient.GetCount());
            ArenaClient.ForEach(c => c.WritePlayerInfo(stream));

            GameMode.WriteGameInfo(stream);

            client.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered);
        }
Пример #7
0
        static void PhaseWarmup()
        {
            phase = TOPhases.Warmup;

            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.TOWarmup);
            stream.Write(activeTODef.Name);
            ArenaClient.ForEach(c => c.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered));

            phaseTimer.SetInterval(WarmUpDuration);
            phaseTimer.SetCallback(PhaseStart);
            phaseTimer.Start();

            Log.Logger.Log(phase.ToString());
        }
Пример #8
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();
        }
Пример #9
0
        public static void StartTO(TODef def)
        {
            if (def == null)
            {
                return;
            }

            if (activeTODef != null)
            {
                ArenaClient.ForEach(c =>
                {
                    ArenaClient client = (ArenaClient)c;
                    if (client.Team != null || client.BaseClient.SpecWorld == world.BaseWorld)
                    {
                        client.Spectate();
                    }

                    client.TODeaths = client.TOKills = client.TOScore = 0;
                });
                teams.Clear();

                var stream = ArenaClient.GetScriptMessageStream();
                stream.Write((byte)ScriptMessages.TOEnd);
                ArenaClient.ForEach(c => c.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered));
            }

            world = WorldInst.List.Find(w => w.Path == def.WorldPath);
            if (world == null)
            {
                return;
            }

            activeTODef = def;
            foreach (var teamDef in activeTODef.Teams)
            {
                teams.Add(new TOTeamInst(teamDef));
            }

            PhaseWarmup();
        }
Пример #10
0
        static void SetPhase(HordePhase phase)
        {
            if (Phase == phase)
            {
                return;
            }

            Phase = phase;

            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.HordePhase);
            stream.Write((byte)Phase);
            if (Phase == HordePhase.Stand)
            {
                stream.Write((byte)ActiveStandInst.Index);
            }

            ArenaClient.ForEach(c => c.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered));

            OnPhaseChange?.Invoke(phase);
        }
Пример #11
0
        void SelectClass(int index)
        {
            if (HordeMode.Phase != HordePhase.WarmUp)
            {
                Sumpfkraut.Menus.ScreenScrollText.AddText("Dem Horde-Modus kann nur beim Start beigtreten werden.", GUCView.Fonts.Menu);
                Close();
                return;
            }

            var classDef = HordeMode.ActiveDef.Classes.ElementAtOrDefault(index);

            if (classDef == null)
            {
                return;
            }

            if (classDef == ArenaClient.Client.HordeClass)
            {
                Close();
                return;
            }

            if (!lockTimer.IsReady)
            {
                return;
            }

            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.HordeJoin);
            stream.Write((byte)index);
            ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable);

            ArenaClient.Client.HordeClass = classDef;

            Close();
        }
Пример #12
0
        static void PhaseStart()
        {
            phase = TOPhases.Battle;

            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.TOStart);
            ArenaClient.ForEach(c => c.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered));

            phaseTimer.SetInterval(activeTODef.Duration * TimeSpan.TicksPerMinute);
            phaseTimer.SetCallback(PhaseFinish);
            Log.Logger.Log(phase.ToString());

            foreach (var team in teams)
            {
                foreach (var player in team.Players)
                {
                    if (player.Character == null || player.Character.IsDead)
                    {
                        SpawnCharacter(player);
                    }
                }
            }
        }
Пример #13
0
        static void PhaseFinish()
        {
            phase = TOPhases.Finish;

            // first, check which teams beat the score limit
            List <int> winIndices = new List <int>(teams.Count);

            for (int i = 0; i < teams.Count; i++)
            {
                if (teams[i].Score >= activeTODef.ScoreToWin)
                {
                    winIndices.Add(i);
                }
            }

            // no teams beat the score limit? Select highest scores.
            if (winIndices.Count == 0)
            {
                int max = teams.Max(t => t.Score);
                for (int i = 0; i < teams.Count; i++)
                {
                    if (teams[i].Score >= max)
                    {
                        winIndices.Add(i);
                    }
                }
            }

            for (int i = 0; i < teams.Count; i++)
            {
                if (!winIndices.Contains(i))
                {
                    teams[i].Players.ForEach(c =>
                    {
                        if (c.Character != null && !c.Character.IsDead && c.Character.TeamID != -1)
                        {
                            var inv = c.Character.Inventory;
                            inv.ForEachItem(item =>
                            {
                                if (item.IsWeapon)
                                {
                                    c.Character.UnequipItem(item);
                                    inv.RemoveItem(item);
                                }
                            });
                        }
                    });
                }
            }

            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.TOFinish);
            stream.Write((byte)winIndices.Count); // write the winners
            winIndices.ForEach(i => stream.Write((byte)i));
            ArenaClient.ForEach(c => c.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered));

            phaseTimer.SetInterval(FinishDuration);
            phaseTimer.SetCallback(EndTO);

            Log.Logger.Log(phase.ToString());
        }
Пример #14
0
        public static void StartHorde(HordeDef def)
        {
            if (def == null)
            {
                return;
            }

            Log.Logger.Log("horde init");

            ArenaClient.ForEach(c =>
            {
                var client         = (ArenaClient)c;
                client.HordeScore  = 0;
                client.HordeDeaths = 0;
                client.HordeKills  = 0;
                client.HordeClass  = null;
            });
            players.ForEach(c => c.Spectate());
            players.Clear();

            if (activeWorld != null)
            {
                activeWorld.BaseWorld.ForEachVob(v => v.Despawn());
            }

            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.HordeStart);
            stream.Write(def.Name);
            ArenaClient.ForEach(c => c.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered));

            activeDef   = def;
            activeWorld = WorldInst.List.Find(w => w.Path == def.WorldPath);

            spawnBarriers.Clear();
            foreach (var bar in activeDef.SpawnBarriers)
            {
                if (!bar.AddAfterEvent)
                {
                    spawnBarriers.Add(CreateBarrier(bar));
                }
            }

            ActiveStands.Clear();
            for (int i = 0; i < activeDef.Stands.Length; i++)
            {
                var       stand = activeDef.Stands[i];
                StandInst inst  = new StandInst()
                {
                    Index = i,
                    Stand = stand,
                };

                if (stand.Boss != null)
                {
                    inst.Boss            = SpawnEnemy(stand.Boss, stand.Position);
                    inst.Boss.CanGetHit += BossProtection;
                }

                inst.Barriers = new List <VobInst>(stand.Barriers.Length);
                foreach (var bar in stand.Barriers)
                {
                    if (!bar.AddAfterEvent)
                    {
                        inst.Barriers.Add(CreateBarrier(bar));
                    }
                }

                ActiveStands.Add(inst);
            }

            foreach (var hi in activeDef.Items)
            {
                ItemInst item = new ItemInst(ItemDef.Get(hi.ItemDef));
                item.Spawn(activeWorld, hi.Position, hi.Angles);
            }

            standEnemyCount = 0;
            ActiveStandInst = null;

            gameTimer.SetInterval(30 * TimeSpan.TicksPerSecond);
            gameTimer.SetCallback(Start);
            gameTimer.Stop();

            SetPhase(HordePhase.WarmUp);
        }