示例#1
0
        private void HandleTransferFlag(NetworkMessage msg)
        {
            MsgTransferFlag tf = msg as MsgTransferFlag;

            var flag = FindFlagByID(tf.FlagID);
            var from = PlayerList.GetPlayerByID(tf.FromID);
            var to   = PlayerList.GetPlayerByID(tf.ToID);

            if (from != null)
            {
                from.SetFlag(null);
            }

            if (to != null)
            {
                to.SetFlag(flag);
            }

            if (flag != null)
            {
                flag.Owner = to;
            }

            if (FlagTransfered != null)
            {
                FlagTransfered.Invoke(this, flag);
            }
        }
示例#2
0
        public void TransferFlag(ServerPlayer from, ServerPlayer to)
        {
            if (from == null || !from.CanDoPlayActions() || from.Info.CariedFlag == null)
            {
                return;
            }
            if (to == null || !to.CanDoPlayActions())
            {
                return;
            }

            FlagTransferEventArgs args = new FlagTransferEventArgs();

            args.From = from;
            args.To   = to;
            args.Flag = from.Info.CariedFlag;

            FlagPreTransfer?.Invoke(this, args);
            if (!args.Allow)
            {
                return;
            }

            DropFlag(to);
            from.Info.CariedFlag = null;
            to.Info.CariedFlag   = args.Flag;

            MsgTransferFlag transfer = new MsgTransferFlag();

            transfer.FromID = from.PlayerID;
            transfer.ToID   = to.PlayerID;
            transfer.FlagID = to.Info.CariedFlag.FlagID;

            Players.SendToAll(transfer, false);

            FlagTransfered?.Invoke(this, args);

            Logger.Log2("Flag transfered from  " + from.Callsign + " to " + to.Callsign);
        }