示例#1
0
        protected void OnClientDisconnect(ClientSessionEventArgs e)
        {
            var characterSessions = this.characterManager.ActiveCharacterSessions;

            foreach (var vehicle in this.ActiveVehicles.Where(v => v.Handle != null).ToList())
            {
                var nearestCharacter = characterSessions
                                       .Where(c => c.IsConnected && c.SessionId != e.Session.Id)
                                       .Select(s => new
                {
                    CharSession = s,
                    Dist        = Vector3.Distance(vehicle.Position.ToVector3(), s.Character.Position.ToVector3())
                })
                                       .OrderBy(c => c.Dist)
                                       .FirstOrDefault();
                if (nearestCharacter == null)
                {
                    this.Destroy(null, vehicle.NetId ?? 0);
                }
                else
                {
                    this.Transfer(null, vehicle.Id, nearestCharacter.CharSession.Session.UserId);
                }
            }
        }