Exemplo n.º 1
0
        public void HandleShotBegin(ServerPlayer sender, MsgShotBegin shotMessage)
        {
            ShotInfo shot = new ShotInfo();

            shot.GlobalID     = NewShotID();
            shot.Owner        = sender;
            shot.PlayerShotID = shotMessage.ShotID;
            shot.Allow        = true;

            if (sender.Info.CariedFlag == null)
            {
                shot.ShotType   = GetDefaultShotType(sender);
                shot.SourceFlag = null;
            }
            else
            {
                shot.ShotType   = sender.Info.CariedFlag.Flag.FlagShot;
                shot.SourceFlag = sender.Info.CariedFlag.Flag;
            }

            shot.InitalPostion = shotMessage.Position;
            shot.InitalVector  = shotMessage.Velocity;
            shot.FireTimestamp = shotMessage.TimeSent;
            shot.TeamColor     = sender.ActualTeam;
            shot.Lifetime      = shotMessage.Lifetime;

            ShotPreFire?.Invoke(this, shot);

            if (shot.Allow)
            {
                FireShot(shot);
            }
        }
Exemplo n.º 2
0
        public void FireShot(ShotInfo shot)
        {
            shot.CreateTimeStamp = GameTime.Now;

            MsgShotBegin shotMessage = new MsgShotBegin();

            if (shot.Owner == null)
            {
                shotMessage.PlayerID = BZFlag.Data.Players.PlayerConstants.ServerPlayerID;
            }
            else
            {
                shotMessage.PlayerID = shot.Owner.PlayerID;
            }

            shotMessage.ShotID   = shot.PlayerShotID;
            shotMessage.Team     = shot.TeamColor;
            shotMessage.TimeSent = (float)shot.FireTimestamp;
            shotMessage.Position = shot.InitalPostion;
            shotMessage.Velocity = shot.InitalVector;
            shotMessage.Lifetime = (float)shot.Lifetime;
            if (shot.SourceFlag != null)
            {
                shotMessage.Flag = shot.SourceFlag.FlagAbbv;
            }

            lock (ShotList)
                ShotList.Add(shot);

            Players.SendToAll(shotMessage, false);

            ShotFired?.Invoke(this, shot);
            shot.Allow = true;
        }
Exemplo n.º 3
0
        private static void HandleShotBegin(NetworkMessage msg)
        {
            MsgShotBegin sb = msg as MsgShotBegin;

            WriteLine("MsgShotBegin " + sb.PlayerID.ToString() + " With flag [" + sb.Flag + "]");
            WriteLine("\tShotID " + sb.ShotID.ToString());
            WriteLine(String.Format("\tPosition = X{0} Y{1} Z{2}", sb.Position.X, sb.Position.Y, sb.Position.Z));
            WriteLine(String.Format("\tVelocity = X{0} Y{1} Z{2}", sb.Velocity.X, sb.Velocity.Y, sb.Velocity.Z));
        }
Exemplo n.º 4
0
        public void HandleShotBegin(NetworkMessage msg)
        {
            MsgShotBegin sb = msg as MsgShotBegin;

            Shot s = new Shot();

            s.GlobalID   = NewShotID();
            s.BZFSShotID = BuildBZFSShotID(sb.PlayerID, sb.ShotID);

            if (BZFStoGlobalIDMap.ContainsKey(s.BZFSShotID))
            {
                BZFStoGlobalIDMap[s.BZFSShotID] = s.GlobalID;
            }
            else
            {
                BZFStoGlobalIDMap.Add(s.BZFSShotID, s.GlobalID);
            }

            s.Owner          = PlayerList.GetPlayerByID(sb.PlayerID);
            s.InitalPosition = sb.Position;
            s.InitalVelocity = sb.Velocity;

            s.Position = new Vector3F(s.InitalPosition.X, s.InitalPosition.Y, s.InitalPosition.Z);
            s.Velocity = new Vector3F(s.InitalVelocity.X, s.InitalVelocity.Y, s.InitalVelocity.Z);

            s.TimeSent  = sb.TimeSent;
            s.Team      = sb.Team;
            s.DeltaTime = sb.DeltaTime;
            s.Lifetime  = sb.Lifetime;

            s.Path = GetShotPath(s);

            if (s.Owner != null)
            {
                int id = s.Owner.AddShot(s);
                if (id != s.GlobalID)       // the player had a replacement, so kill the shot that was replaced
                {
                    RemoveShotByGID(id);
                }
            }

            ShotList.Add(s.GlobalID, s);
            if (ShotCreated != null)
            {
                ShotCreated.Invoke(this, s);
            }
        }