/// <summary> /// Loads and adds the Character to its Map. /// </summary> /// <remarks>Called initially from the IO-Context</remarks> internal void LoadAndLogin() { // set Zone *before* Map // TODO: Also retrieve Battlegrounds m_Map = World.GetMap(m_record); InstanceMgr.RetrieveInstances(this); AreaCharCount++; // Characters are always in active regions if (!Role.IsStaff) { Stunned++; } var isStaff = Role.IsStaff; if (m_Map == null && (!isStaff || (m_Map = InstanceMgr.CreateInstance(this, m_record.MapId)) == null)) { // map does not exist anymore Load(); TeleportToBindLocation(); AddMessage(InitializeCharacter); return; } else { Load(); if (m_Map.IsDisposed || (m_Map.IsInstance && !isStaff && (m_Map.CreationTime > m_record.LastLogout || !m_Map.CanEnter(this)))) { // invalid Map or not allowed back in (might be an Instance) m_Map.TeleportOutside(this); AddMessage(InitializeCharacter); } else { m_Map.AddMessage(() => { // add to map if (m_Map is Battleground) { var bg = (Battleground)m_Map; if (!bg.LogBackIn(this)) { // teleport out of BG AddMessage(InitializeCharacter); return; } } m_position = new Vector3(m_record.PositionX, m_record.PositionY, m_record.PositionZ); m_zone = m_Map.GetZone(m_record.Zone); if (m_zone != null && m_record.JustCreated) { // set initial zone explored automatically SetZoneExplored(m_zone.Id, false); } // during the next Map-wide Character-update, the Character is going to be added to the map // and created/initialized immediately afterwards m_Map.AddObjectNow(this); InitializeCharacter(); }); } } }