diff --git a/Source/Game/Entities/Player/Player.DB.cs b/Source/Game/Entities/Player/Player.DB.cs index 2c9c477e5..92d514d1f 100644 --- a/Source/Game/Entities/Player/Player.DB.cs +++ b/Source/Game/Entities/Player/Player.DB.cs @@ -599,11 +599,8 @@ namespace Game.Entities } } - if (!ok) + void saveHomebindToDb() { - homebind = new WorldLocation(info.MapId, info.PositionX, info.PositionY, info.PositionZ, info.Orientation); - homebindAreaId = info.ZoneId; - PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_PLAYER_HOMEBIND); stmt.AddValue(0, GetGUID().GetCounter()); stmt.AddValue(1, homebind.GetMapId()); @@ -612,6 +609,29 @@ namespace Game.Entities stmt.AddValue(4, homebind.posY); stmt.AddValue(5, homebind.posZ); DB.Characters.Execute(stmt); + }; + + if (!ok && HasAtLoginFlag(AtLoginFlags.FirstLogin)) + { + homebind = new WorldLocation(info.MapId, info.PositionX, info.PositionY, info.PositionZ, info.Orientation); + homebindAreaId = info.ZoneId; + + saveHomebindToDb(); + ok = true; + } + + if (!ok) + { + WorldSafeLocsEntry loc = Global.ObjectMgr.GetDefaultGraveYard(GetTeam()); + if (loc == null && GetRace() == Race.PandarenNeutral) + loc = Global.ObjectMgr.GetWorldSafeLoc(3295); // The Wandering Isle, Starting Area GY + + Cypher.Assert(loc != null, "Missing fallback graveyard location for faction {GetTeamId()}"); + + homebind = new WorldLocation(loc.Loc.GetMapId(), loc.Loc.posX, loc.Loc.posY, loc.Loc.posZ); + homebindAreaId = Global.MapMgr.GetAreaId(PhasingHandler.EmptyPhaseShift, loc.Loc); + + saveHomebindToDb(); } Log.outDebug(LogFilter.Player, "Setting player home position - mapid: {0}, areaid: {1}, {2}", @@ -2703,6 +2723,8 @@ namespace Game.Entities SetPlayerFlagsEx(playerFlagsEx); SetWatchedFactionIndex(watchedFaction); + atLoginFlags = (AtLoginFlags)at_login; + if (!GetSession().ValidateAppearance(GetRace(), GetClass(), gender, customizations)) { Log.outError(LogFilter.Player, "Player {0} has wrong Appearance values (Hair/Skin/Color), can't be loaded.", guid.ToString()); @@ -3050,8 +3072,6 @@ namespace Game.Entities m_stableSlots = 4; } - atLoginFlags = (AtLoginFlags)at_login; - // Honor system // Update Honor kills data m_lastHonorUpdateTime = logoutTime; diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index 95b62d9f4..68d5ad2e2 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -197,6 +197,9 @@ namespace Game.Entities m_createTime = GameTime.GetGameTime(); UpdatePositionData(); + // set initial homebind position + SetHomebind(this, GetAreaId()); + PowerType powertype = cEntry.DisplayPower; SetObjectScale(1.0f); diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index 976676345..afe91c7ae 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -802,7 +802,7 @@ namespace Game Log.outInfo(LogFilter.ServerLoading, $"Loaded {_worldSafeLocs.Count} world locations {Time.GetMSTimeDiffToNow(oldMSTime)} ms"); } - WorldSafeLocsEntry GetDefaultGraveYard(Team team) + public WorldSafeLocsEntry GetDefaultGraveYard(Team team) { if (team == Team.Horde) return GetWorldSafeLoc(10); @@ -810,6 +810,7 @@ namespace Game return GetWorldSafeLoc(4); else return null; } + public WorldSafeLocsEntry GetClosestGraveYard(WorldLocation location, Team team, WorldObject conditionObject) { float x, y, z; diff --git a/Source/Game/Maps/MapManager.cs b/Source/Game/Maps/MapManager.cs index e0b601f2c..bca11f417 100644 --- a/Source/Game/Maps/MapManager.cs +++ b/Source/Game/Maps/MapManager.cs @@ -412,12 +412,22 @@ namespace Game.Entities return i_maps.LookupByKey(mapId); } - uint GetAreaId(PhaseShift phaseShift, uint mapid, float x, float y, float z) + public uint GetAreaId(PhaseShift phaseShift, uint mapid, float x, float y, float z) { Map m = CreateBaseMap(mapid); return m.GetAreaId(phaseShift, x, y, z); } + public uint GetAreaId(PhaseShift phaseShift, uint mapid, Position pos) + { + return GetAreaId(phaseShift, mapid, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ()); + } + + public uint GetAreaId(PhaseShift phaseShift, WorldLocation loc) + { + return GetAreaId(phaseShift, loc.GetMapId(), loc); + } + public uint GetZoneId(PhaseShift phaseShift, uint mapid, float x, float y, float z) { Map m = CreateBaseMap(mapid);