Ejemplo n.º 1
0
        /// <summary>
        /// Handles death reports by players and broadcasts that to all other <see cref="Player"/>s.
        /// </summary>
        /// <param name="incomingMessage"></param>
        public void Die(NetIncomingMessage incomingMessage)
        {
            MsgDeathPacket incomingDeathPacket = MsgDeathPacket.Read(incomingMessage);

            // create our death message and packet
            NetOutgoingMessage deathMessage = gameKeeper.Server.CreateMessage();

            MsgDeathPacket deathPacket = new MsgDeathPacket(this.Slot, incomingDeathPacket.Killer);

            // write to the message
            deathMessage.Write((Byte)deathPacket.MsgType);
            deathPacket.Write(deathMessage);

            // send the death message to everyone except the player who reported it
            gameKeeper.Server.SendToAll(deathMessage, this.Connection, NetDeliveryMethod.ReliableOrdered, 0);

            // update our score
            this.Score.Losses++;

            // update killer's score, but only if the killer wasn't myself
            if (this.Slot != incomingDeathPacket.Killer)
            {
                Player killer = gameKeeper.GetPlayerBySlot(incomingDeathPacket.Killer);

                if (killer != null)
                {
                    killer.Score.Wins++;
                    gameKeeper.Server.SendToAll(killer.GetMsgScore(), null, NetDeliveryMethod.ReliableOrdered, 0);
                }
            }

            // broadcast our score
            gameKeeper.Server.SendToAll(this.GetMsgScore(), null, NetDeliveryMethod.ReliableOrdered, 0);

            // update our last died time
            lastDiedTime = DateTime.Now;

            // we're now dead as far as we're concerned
            state = PlayerState.Dead;
        }
Ejemplo n.º 2
0
        public override void Die(Player killer)
        {
            // send out the death packet right away
            NetOutgoingMessage deathMessage = World.ServerLink.CreateMessage();

            MsgDeathPacket deathPacket = new MsgDeathPacket(killer.Slot);

            deathMessage.Write((Byte)deathPacket.MsgType);
            deathPacket.Write(deathMessage);

            World.ServerLink.SendMessage(deathMessage, NetDeliveryMethod.ReliableOrdered, 0);

            // write to console that you were killed
            ConsoleMessageLine consoleMessage;

            if (killer != this)
            {
                consoleMessage =
                    new ConsoleMessageLine(
                        "You were killed by ", Color.White,
                        killer.Callsign, ProtocolHelpers.TeamTypeToColor(killer.Team));
            }
            else
            {
                consoleMessage = new ConsoleMessageLine("You blew yourself up!", Color.White);
            }

            World.Console.WriteLine(consoleMessage);

            base.Die(killer);
        }