コード例 #1
0
        public bool GrantFlag(ServerPlayer player, FlagInstance flag)
        {
            if (flag.Owner != null || player.Info.CariedFlag != null)
            {
                return(false);
            }

            OnGrantFlag?.Invoke(player, flag);

            FlagEventArgs args = new FlagEventArgs();

            args.Player = player;
            args.Flag   = flag;

            FlagPreGrab?.Invoke(this, args);

            if (flag.Status == FlagStatuses.FlagNoExist)
            {
                return(false);
            }

            lock (ActiveFlags)
            {
                if (!args.Allow || flag.Owner != null)
                {
                    return(false);
                }

                lock (WorldFlags)
                    WorldFlags.Remove(flag.FlagID);

                lock (CarriedFlags)
                    CarriedFlags.Add(flag.FlagID, flag);

                flag.Owner   = player;
                flag.Status  = FlagStatuses.FlagOnTank;
                flag.OwnerID = player.PlayerID;
            }

            FlagGrabbed?.Invoke(this, flag);

            player.Info.CariedFlag = flag;

            MsgGrabFlag grabMessage = new MsgGrabFlag();

            grabMessage.PlayerID = player.PlayerID;
            grabMessage.FlagData = flag;

            Logger.Log2("Player " + player.Callsign + " granted flag " + flag.FlagID.ToString() + " " + flag.ToString());

            Players.SendToAll(grabMessage, false);
            return(true);
        }
コード例 #2
0
        public void DropFlag(ServerPlayer player)
        {
            if (player == null || player.Info.CariedFlag == null)
            {
                return;
            }

            if (player.Info.CariedFlag.Flag == FlagTypeList.Identify)
            {
                player.SendMessage(new MsgNearFlag());  // send them an empty ID message to clear out the display
            }
            FlagInstance flag = player.Info.CariedFlag;

            ComputeFlagDrop?.Invoke(player, flag);

            MsgDropFlag drop = new MsgDropFlag();

            drop.FlagID   = flag.FlagID;
            drop.PlayerID = player.PlayerID;
            drop.Data     = flag;

            player.Info.CariedFlag = null;
            flag.Owner             = null;

            Players.SendToAll(drop, false);

            lock (CarriedFlags)
            {
                if (CarriedFlags.ContainsKey(flag.FlagID))
                {
                    CarriedFlags.Remove(flag.FlagID);
                }
            }

            lock (WorldFlags)
                WorldFlags.Add(flag.FlagID, flag);

            FlagDropped?.Invoke(this, flag);
        }