Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        /*public static void ReadTeamMessage(ArenaClient sender, PacketReader stream)
         * {
         *  if (sender.Team == null)
         *      return;
         *
         *  string message = stream.ReadString();
         *
         *  builder.Clear();
         *  builder.Append(sender.CharInfo.Name);
         *  builder.Append(" (Team): ");
         *  builder.Append(message);
         *
         *  SendTeamMessage(sender.Team, builder.ToString());
         * }*/

        public static void SendMessage(string message)
        {
            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.ChatMessage);
            stream.Write(message);
            ArenaClient.ForEach(c => c.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable));
        }
Ejemplo n.º 3
0
 static void RegeneratePlayers()
 {
     ArenaClient.ForEach(c =>
     {
         ArenaClient client = (ArenaClient)c;
         if (client.IsCharacter && client.DuelEnemy == null)
         {
             RegeneratePlayer(client);
         }
     });
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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());
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
                    }
                }
            }
        }
Ejemplo n.º 9
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());
        }
Ejemplo n.º 10
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);
        }