Ejemplo n.º 1
0
        static void RegeneratePlayer(ArenaClient client)
        {
            // no regen in horde mode
            if (client.GMTeamID >= TeamIdent.GMPlayer && GameModes.Horde.HordeMode.IsActive)
            {
                return;
            }

            var npc = client.Character;

            int diff = npc.HPMax - npc.HP;

            if (diff <= 0 || npc.IsDead)
            {
                return;
            }

            if (GameTime.Ticks - npc.LastHitMove < RegenerationOffset)
            {
                return;
            }

            int add = client.GMTeamID >= TeamIdent.GMPlayer ? 2 : 8;

            if (add > diff)
            {
                add = diff;
            }

            npc.SetHealth(npc.HP + add);
        }
Ejemplo n.º 2
0
        void SendToggleMessage(bool open)
        {
            var stream = ArenaClient.GetStream(msgID);

            stream.Write(open);
            ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable);
        }
Ejemplo n.º 3
0
        public static void ReadMessage(ArenaClient sender, PacketReader stream)
        {
            string message = stream.ReadString();

            const string modeCmd = "/startmode";

            if (message.StartsWith(modeCmd, StringComparison.OrdinalIgnoreCase))
            {
                var scen = GameModes.GameScenario.Get(message.Substring(modeCmd.Length + 1));
                if (scen != null)
                {
                    GameModes.GameMode.InitScenario(scen);
                }

                return;
            }

            builder.Clear();
            builder.Append(sender.CharInfo.Name);
            if (sender.IsSpecating)
            {
                builder.Append(" (Zuschauer)");
            }

            builder.Append(": ");
            builder.Append(message);
            SendMessage(builder.ToString());
        }
Ejemplo n.º 4
0
        public static void Kill(ArenaClient attacker, ArenaClient target)
        {
            if (Phase != TOPhases.Battle)
            {
                return;
            }

            target.TODeaths++;
            if (attacker.Team == target.Team)
            {
                attacker.TOScore--;
                attacker.Team.Score--;
                attacker.SendPointsMessage(-1);
            }
            else
            {
                attacker.TOScore++;
                attacker.TOKills++;
                attacker.Team.Score++;
                attacker.SendPointsMessage(+1);
                if (attacker.Team.Score >= activeTODef.ScoreToWin)
                {
                    PhaseFinish();
                }
            }
        }
Ejemplo n.º 5
0
 void SendUpdate(ArenaClient client)
 {
     if (client.IsConnected)
     {
         client.SendScriptMessage(packet, packet.Length, NetPriority.Low, NetReliability.Unreliable);
     }
 }
Ejemplo n.º 6
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.º 7
0
        public static void JoinClass(PacketReader stream, ArenaClient client)
        {
            int index = stream.ReadByte();

            HordeClassDef classDef = activeDef.Classes.ElementAtOrDefault(index);

            if (classDef == null)
            {
                return;
            }

            if (activeDef == null)
            {
                StartHorde();
            }

            if (Phase != HordePhase.WarmUp)
            {
                return;
            }

            client.HordeClass = classDef;
            players.Add(client);
            SpawnPlayer(client);

            if (players.Count == 1)
            {
                gameTimer.Start();
            }
        }
Ejemplo n.º 8
0
        void WriteUpdate()
        {
            var stream = ArenaClient.GetStream(msgID);

            WriteBoard(stream);
            this.packet = stream.CopyData();
        }
Ejemplo n.º 9
0
        static void SpawnPlayer(ArenaClient client)
        {
            var     charInfo = client.CharInfo;
            NPCInst npc      = new NPCInst(NPCDef.Get(charInfo.BodyMesh == HumBodyMeshs.HUM_BODY_NAKED0 ? "maleplayer" : "femaleplayer"))
            {
                UseCustoms     = true,
                CustomBodyTex  = charInfo.BodyTex,
                CustomHeadMesh = charInfo.HeadMesh,
                CustomHeadTex  = charInfo.HeadTex,
                CustomVoice    = charInfo.Voice,
                CustomFatness  = charInfo.Fatness,
                CustomScale    = new Vec3f(charInfo.BodyWidth, 1.0f, charInfo.BodyWidth),
                CustomName     = charInfo.Name
            };

            foreach (string e in client.HordeClass.Equipment)
            {
                ItemInst item = new ItemInst(ItemDef.Get(e));
                npc.Inventory.AddItem(item);
                npc.EffectHandler.TryEquipItem(item);
            }

            if (client.HordeClass.NeedsBolts)
            {
            }

            npc.Inventory.AddItem(new ItemInst(ItemDef.Get("hptrank")));

            Vec3f  spawnPos = Randomizer.GetVec3fRad(activeDef.SpawnPos, activeDef.SpawnRange);
            Angles spawnAng = Randomizer.GetYaw();

            //npc.TeamID = 0;
            npc.Spawn(activeWorld, spawnPos, spawnAng);
            client.SetControl(npc);
        }
Ejemplo n.º 10
0
        static void NPCInst_sOnNPCInstMove(NPCInst npc, Vec3f oldPos, Angles oldAng, NPCMovement oldMovement)
        {
            if (npc.IsDead || !npc.IsPlayer || npc.IsUnconscious)
            {
                return;
            }

            ArenaClient client = (ArenaClient)npc.Client;

            if (client.HordeClass == null)
            {
                return;
            }

            if (ActiveStandInst != null)
            {
                return;
            }

            foreach (var s in ActiveStands)
            {
                if (npc.GetPosition().GetDistance(s.Stand.Position) < s.Stand.Range)
                {
                    StartStand(s);
                    break;
                }
            }
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
 public static void LeaveHorde(ArenaClient client)
 {
     client.HordeClass = null;
     if (players.Remove(client) && players.Count == 0)
     {
         StartHorde(); // restart / next
     }
 }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
        void Spectate()
        {
            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.HordeSpectate);
            ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable);
            Close();
        }
Ejemplo n.º 15
0
 static void RegeneratePlayers()
 {
     ArenaClient.ForEach(c =>
     {
         ArenaClient client = (ArenaClient)c;
         if (client.IsCharacter && client.DuelEnemy == null)
         {
             RegeneratePlayer(client);
         }
     });
 }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        public static void ReadJoinTeam(ArenaClient client, PacketReader stream)
        {
            if (!IsRunning)
            {
                return;
            }

            int index = stream.ReadByte();
            var team  = Teams.ElementAtOrDefault(index);

            JoinTeam(client, team);
        }
Ejemplo n.º 18
0
        public void Remove(ArenaClient client)
        {
            if (clients.TryGetValue(client, out GUCTimer timer))
            {
                timer.Stop();
                clients.Remove(client);

                if (clients.Count == 0)
                {
                    packetTimer.Stop();
                }
            }
        }
Ejemplo n.º 19
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.º 20
0
        public static void AddScore(ArenaClient client)
        {
            if (client == null || client.Team == null)
            {
                return;
            }

            var team = client.Team;

            team.Score++;
            if (team.Score >= activeTODef.ScoreToWin)
            {
                PhaseFinish();
            }
        }
Ejemplo n.º 21
0
        public static void JoinSpectate(ArenaClient client)
        {
            PosAng specPA = activeDef.SpecPA;

            foreach (var player in players)
            {
                if (player.Character != null && player.Character.IsSpawned)
                {
                    specPA             = new PosAng(player.Character.GetPosition(), player.Character.GetAngles());
                    specPA.Position.Y += 100;
                    break;
                }
            }
            client.SetToSpectator(activeWorld, specPA.Position, specPA.Angles);
        }
Ejemplo n.º 22
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.º 23
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();
        }
Ejemplo n.º 24
0
        void WritePlayer(ArenaClient client, PacketWriter stream)
        {
            stream.Write((byte)client.ID);
            stream.Write((short)client.HordeScore);
            stream.Write((short)client.HordeKills);
            stream.Write((short)client.HordeDeaths);

            int ping = client.BaseClient.GetLastPing();

            if (ping < 0)
            {
                ping = -1;
            }
            else if (ping > short.MaxValue)
            {
                ping = short.MaxValue;
            }
            stream.Write((short)ping);
        }
Ejemplo n.º 25
0
        public static void Toggle(ArenaClient client)
        {
            if (!clients.Remove(client))
            {
                clients.Add(client);
                client.SendScriptMessage(GetData(), NetPriority.Low, NetReliability.Unreliable);

                if (clients.Count == 1)
                {
                    TeamMode.OnChangeTeamComposition += WriteUpdate;
                }
            }
            else
            {
                if (clients.Count == 0)
                {
                    TeamMode.OnChangeTeamComposition -= WriteUpdate;
                }
            }
        }
Ejemplo n.º 26
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);
            }
        }
Ejemplo n.º 27
0
        static void NPCInst_sOnHit(NPCInst attacker, NPCInst target, int damage)
        {
            if (attacker.IsPlayer)
            {
                if (target.IsPlayer)
                {
                    return;
                }

                ArenaClient player = (ArenaClient)attacker.Client;
                if (player.HordeClass == null)
                {
                    return;
                }

                player.HordeScore += damage / 10.0f;
                if (target.HP <= 0)
                {
                    player.HordeKills++;
                    player.HordeScore += 5;
                }
            }
            else if (target.IsPlayer)
            {
                ArenaClient player = (ArenaClient)target.Client;
                if (player.HordeClass == null)
                {
                    return;
                }

                if (target.HP <= 1)
                {
                    player.HordeDeaths++;
                    if (Players.TrueForAll(p => p.Character.HP <= 1))
                    {
                        EndHorde(false);
                    }
                }
            }
        }
Ejemplo n.º 28
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.º 29
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.º 30
0
        void CreateNewCharacter()
        {
            info.Name = Name.Input;
            if (info.Name.Length < 2)
            {
                SetCursor(Name);
                SetHelpText("Dein Charaktername ist zu kurz.");
                return;
            }

            info.Voice = (HumVoices)voice.Choice;

            ArenaClient.SendCharEditMessage(info);
            if (GUCScripts.Ingame)
            {
                Close();
            }
            else
            {
                Menus.MainMenu.Menu.Open();
            }
        }