internal void HandleFlagGrab(ServerPlayer player, MsgGrabFlag message) { if (message == null || !player.CanDoPlayActions()) { return; } int flagID = message.FlagData.FlagID; FlagInstance candidateFlag = FindFlagByID(flagID); if (candidateFlag == null || !candidateFlag.Grabable()) { return; } float dist = Vector3F.Distance(player.Info.LastSentUpdate.Position, candidateFlag.Position); if (false && dist > GetFlagGrabDistance(player)) { return; } Logger.Log4("Player " + player.Callsign + " wants to grab flag " + candidateFlag.FlagID.ToString() + " " + candidateFlag.ToString()); GrantFlag(player, candidateFlag); }
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); }