From 2d976d74213c86c5d70a89a2152ead74e08384eb Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sat, 16 Oct 2021 17:59:01 -0400 Subject: [PATCH] Core/Characters: Made homebind location a WorldLocation (this implicitly adds orientation) Port From (https://github.com/TrinityCore/TrinityCore/commit/68c2fc8ff58d9ad272e8e17391a6bb6c3743923b) --- .../Database/Databases/CharacterDatabase.cs | 8 ++--- Source/Game/Chat/Commands/MiscCommands.cs | 3 +- Source/Game/Entities/Object/Position.cs | 5 +++ Source/Game/Entities/Player/Player.DB.cs | 31 +++++++++---------- Source/Game/Entities/Player/Player.Fields.cs | 2 +- Source/Game/Entities/Player/Player.cs | 15 +++++---- Source/Game/Maps/Map.cs | 4 +-- Source/Game/Spells/Spell.cs | 2 +- Source/Game/Spells/SpellEffects.cs | 2 +- sql/base/characters_database.sql | 4 ++- .../master/2021_10_16_00_characters.sql | 2 ++ 11 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 sql/updates/characters/master/2021_10_16_00_characters.sql diff --git a/Source/Framework/Database/Databases/CharacterDatabase.cs b/Source/Framework/Database/Databases/CharacterDatabase.cs index b53556b62..89dd92e54 100644 --- a/Source/Framework/Database/Databases/CharacterDatabase.cs +++ b/Source/Framework/Database/Databases/CharacterDatabase.cs @@ -122,7 +122,7 @@ namespace Framework.Database PrepareStatement(CharStatements.SEL_CHARACTER_MAILDATE, "SELECT MIN(deliver_time) FROM mail WHERE receiver = ? AND (checked & 1) = 0"); PrepareStatement(CharStatements.SEL_MAIL_COUNT, "SELECT COUNT(*) FROM mail WHERE receiver = ?"); PrepareStatement(CharStatements.SEL_CHARACTER_SOCIALLIST, "SELECT cs.friend, c.account, cs.flags, cs.note FROM character_social cs JOIN characters c ON c.guid = cs.friend WHERE cs.guid = ? AND c.deleteinfos_name IS NULL LIMIT 255"); - PrepareStatement(CharStatements.SEL_CHARACTER_HOMEBIND, "SELECT mapId, zoneId, posX, posY, posZ FROM character_homebind WHERE guid = ?"); + PrepareStatement(CharStatements.SEL_CHARACTER_HOMEBIND, "SELECT mapId, zoneId, posX, posY, posZ, orientation FROM character_homebind WHERE guid = ?"); PrepareStatement(CharStatements.SEL_CHARACTER_SPELLCOOLDOWNS, "SELECT spell, item, time, categoryId, categoryEnd FROM character_spell_cooldown WHERE guid = ? AND time > UNIX_TIMESTAMP()"); PrepareStatement(CharStatements.SEL_CHARACTER_SPELL_CHARGES, "SELECT categoryId, rechargeStart, rechargeEnd FROM character_spell_charges WHERE guid = ? AND rechargeEnd > UNIX_TIMESTAMP() ORDER BY rechargeEnd"); PrepareStatement(CharStatements.SEL_CHARACTER_DECLINEDNAMES, "SELECT genitive, dative, accusative, instrumental, prepositional FROM character_declinedname WHERE guid = ?"); @@ -414,8 +414,8 @@ namespace Framework.Database PrepareStatement(CharStatements.DEL_PLAYER_BGDATA, "DELETE FROM character_battleground_data WHERE guid = ?"); // Character homebind - PrepareStatement(CharStatements.INS_PLAYER_HOMEBIND, "INSERT INTO character_homebind (guid, mapId, zoneId, posX, posY, posZ) VALUES (?, ?, ?, ?, ?, ?)"); - PrepareStatement(CharStatements.UPD_PLAYER_HOMEBIND, "UPDATE character_homebind SET mapId = ?, zoneId = ?, posX = ?, posY = ?, posZ = ? WHERE guid = ?"); + PrepareStatement(CharStatements.INS_PLAYER_HOMEBIND, "INSERT INTO character_homebind (guid, mapId, zoneId, posX, posY, posZ, orientation) VALUES (?, ?, ?, ?, ?, ?, ?)"); + PrepareStatement(CharStatements.UPD_PLAYER_HOMEBIND, "UPDATE character_homebind SET mapId = ?, zoneId = ?, posX = ?, posY = ?, posZ = ?, orientation = ? WHERE guid = ?"); PrepareStatement(CharStatements.DEL_PLAYER_HOMEBIND, "DELETE FROM character_homebind WHERE guid = ?"); // Corpse @@ -544,7 +544,7 @@ namespace Framework.Database PrepareStatement(CharStatements.SEL_PINFO_MAILS, "SELECT SUM(CASE WHEN (checked & 1) THEN 1 ELSE 0 END) AS 'readmail', COUNT(*) AS 'totalmail' FROM mail WHERE `receiver` = ?"); //0: lowGUID PrepareStatement(CharStatements.SEL_PINFO_XP, "SELECT a.xp, b.guid FROM characters a LEFT JOIN guild_member b ON a.guid = b.guid WHERE a.guid = ?"); - PrepareStatement(CharStatements.SEL_CHAR_HOMEBIND, "SELECT mapId, zoneId, posX, posY, posZ FROM character_homebind WHERE guid = ?"); + PrepareStatement(CharStatements.SEL_CHAR_HOMEBIND, "SELECT mapId, zoneId, posX, posY, posZ, orientation FROM character_homebind WHERE guid = ?"); PrepareStatement(CharStatements.SEL_CHAR_GUID_NAME_BY_ACC, "SELECT guid, name FROM characters WHERE account = ?"); PrepareStatement(CharStatements.SEL_POOL_QUEST_SAVE, "SELECT quest_id FROM pool_quest_save WHERE pool_id = ?"); PrepareStatement(CharStatements.SEL_CHAR_CUSTOMIZE_INFO, "SELECT name, race, class, gender, at_login FROM characters WHERE guid = ?"); diff --git a/Source/Game/Chat/Commands/MiscCommands.cs b/Source/Game/Chat/Commands/MiscCommands.cs index 32b74b85e..29e0fee8c 100644 --- a/Source/Game/Chat/Commands/MiscCommands.cs +++ b/Source/Game/Chat/Commands/MiscCommands.cs @@ -2362,8 +2362,7 @@ namespace Game.Chat if (location_str == "inn") { - var home = player.GetHomebind(); - player.TeleportTo(home.GetMapId(), home.GetPositionX(), home.GetPositionY(), home.GetPositionZ(), player.GetOrientation()); + player.TeleportTo(player.GetHomebind()); return true; } diff --git a/Source/Game/Entities/Object/Position.cs b/Source/Game/Entities/Object/Position.cs index 8153de9b3..af5eb0edc 100644 --- a/Source/Game/Entities/Object/Position.cs +++ b/Source/Game/Entities/Object/Position.cs @@ -427,5 +427,10 @@ namespace Game.Entities { return this; } + + public override string ToString() + { + return $"X: {posX} Y: {posY} Z: {posZ} O: {Orientation} MapId: {_mapId}"; + } } } diff --git a/Source/Game/Entities/Player/Player.DB.cs b/Source/Game/Entities/Player/Player.DB.cs index f7a6622b3..2657b31a2 100644 --- a/Source/Game/Entities/Player/Player.DB.cs +++ b/Source/Game/Entities/Player/Player.DB.cs @@ -577,18 +577,13 @@ namespace Game.Entities bool ok = false; if (!result.IsEmpty()) { - homebind = new WorldLocation(); - - homebind.SetMapId(result.Read(0)); + homebind.WorldRelocate(result.Read(0), result.Read(2), result.Read(3), result.Read(4), result.Read(5)); homebindAreaId = result.Read(1); - homebind.posX = result.Read(2); - homebind.posY = result.Read(3); - homebind.posZ = result.Read(4); var map = CliDB.MapStorage.LookupByKey(homebind.GetMapId()); // accept saved data only for valid position (and non instanceable), and accessable - if (GridDefines.IsValidMapCoord(homebind.GetMapId(), homebind.posX, homebind.posY, homebind.posZ) && + if (GridDefines.IsValidMapCoord(homebind) && !map.Instanceable() && GetSession().GetExpansion() >= map.Expansion()) ok = true; else @@ -605,9 +600,10 @@ namespace Game.Entities stmt.AddValue(0, GetGUID().GetCounter()); stmt.AddValue(1, homebind.GetMapId()); stmt.AddValue(2, homebindAreaId); - stmt.AddValue(3, homebind.posX); - stmt.AddValue(4, homebind.posY); - stmt.AddValue(5, homebind.posZ); + stmt.AddValue(3, homebind.GetPositionX()); + stmt.AddValue(4, homebind.GetPositionY()); + stmt.AddValue(5, homebind.GetPositionZ()); + stmt.AddValue(6, homebind.GetOrientation()); DB.Characters.Execute(stmt); }; @@ -615,12 +611,16 @@ namespace Game.Entities { var createPosition = m_createMode == PlayerCreateMode.NPE && info.createPositionNPE.HasValue ? info.createPositionNPE.Value : info.createPosition; - homebind = new WorldLocation(createPosition.Loc.GetMapId(), createPosition.Loc); + homebind.WorldRelocate(createPosition.Loc); if (createPosition.TransportGuid.HasValue) { Transport transport = Global.ObjAccessor.FindTransport(ObjectGuid.Create(HighGuid.Transport, createPosition.TransportGuid.Value)); if (transport != null) - transport.CalculatePassengerPosition(ref homebind.posX, ref homebind.posY, ref homebind.posZ, ref homebind.Orientation); + { + float orientation = homebind.GetOrientation(); + transport.CalculatePassengerPosition(ref homebind.posX, ref homebind.posY, ref homebind.posZ, ref orientation); + homebind.SetOrientation(orientation); + } } homebindAreaId = Global.MapMgr.GetAreaId(PhasingHandler.EmptyPhaseShift, homebind); @@ -637,14 +637,13 @@ namespace Game.Entities 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); + homebind.WorldRelocate(loc.Loc); homebindAreaId = Global.MapMgr.GetAreaId(PhasingHandler.EmptyPhaseShift, loc.Loc); saveHomebindToDb(); } - Log.outDebug(LogFilter.Player, "Setting player home position - mapid: {0}, areaid: {1}, {2}", - homebind.GetMapId(), homebindAreaId, homebind); + Log.outDebug(LogFilter.Player, $"Setting player home position - mapid: {homebind.GetMapId()}, areaid: {homebindAreaId}, {homebind}"); return true; } @@ -2774,7 +2773,7 @@ namespace Game.Entities SetRaidDifficultyID(CheckLoadedRaidDifficultyID(raidDifficulty)); SetLegacyRaidDifficultyID(CheckLoadedLegacyRaidDifficultyID(legacyRaidDifficulty)); - var RelocateToHomebind = new Action(() => { mapId = (ushort)homebind.GetMapId(); instance_id = 0; Relocate(homebind); }); + var RelocateToHomebind = new Action(() => { instance_id = 0; Relocate(homebind); }); _LoadGroup(holder.GetResult(PlayerLoginQueryLoad.Group)); diff --git a/Source/Game/Entities/Player/Player.Fields.cs b/Source/Game/Entities/Player/Player.Fields.cs index cfd078f73..a9f974796 100644 --- a/Source/Game/Entities/Player/Player.Fields.cs +++ b/Source/Game/Entities/Player/Player.Fields.cs @@ -233,7 +233,7 @@ namespace Game.Entities // Recall position WorldLocation m_recall_location; - WorldLocation homebind; + WorldLocation homebind = new(); uint homebindAreaId; uint m_HomebindTimer; diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index 5ccae5f8a..ed6d6bf8e 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -2808,17 +2808,18 @@ namespace Game.Entities } public void SetHomebind(WorldLocation loc, uint areaId) { - homebind = loc; + homebind.WorldRelocate(loc); homebindAreaId = areaId; // update sql homebind PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_PLAYER_HOMEBIND); stmt.AddValue(0, homebind.GetMapId()); stmt.AddValue(1, homebindAreaId); - stmt.AddValue(2, homebind.posX); - stmt.AddValue(3, homebind.posY); - stmt.AddValue(4, homebind.posZ); - stmt.AddValue(5, GetGUID().GetCounter()); + stmt.AddValue(2, homebind.GetPositionX()); + stmt.AddValue(3, homebind.GetPositionY()); + stmt.AddValue(4, homebind.GetPositionZ()); + stmt.AddValue(5, homebind.GetOrientation()); + stmt.AddValue(6, GetGUID().GetCounter()); DB.Characters.Execute(stmt); } public void SetBindPoint(ObjectGuid guid) @@ -2829,9 +2830,7 @@ namespace Game.Entities public void SendBindPointUpdate() { BindPointUpdate packet = new(); - packet.BindPosition.X = homebind.GetPositionX(); - packet.BindPosition.Y = homebind.GetPositionY(); - packet.BindPosition.Z = homebind.GetPositionZ(); + packet.BindPosition = new (homebind.GetPositionX(), homebind.GetPositionY(), homebind.GetPositionZ()); packet.BindMapID = homebind.GetMapId(); packet.BindAreaID = homebindAreaId; SendPacket(packet); diff --git a/Source/Game/Maps/Map.cs b/Source/Game/Maps/Map.cs index 216d54d65..6de34f91d 100644 --- a/Source/Game/Maps/Map.cs +++ b/Source/Game/Maps/Map.cs @@ -1605,9 +1605,7 @@ namespace Game.Maps if (!pl.IsBeingTeleportedFar()) { // this is happening for bg - Log.outError(LogFilter.Maps, - "Map.UnloadAll: player {0} is still in map {1} during unload, this should not happen!", - pl.GetName(), GetId()); + Log.outError(LogFilter.Maps, $"Map.UnloadAll: player {pl.GetName()} is still in map {GetId()} during unload, this should not happen!"); pl.TeleportTo(pl.GetHomebind()); } } diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 92ac8079b..a8b4d3d37 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -820,7 +820,7 @@ namespace Game.Spells case Targets.DestHome: Player playerCaster = m_caster.ToPlayer(); if (playerCaster != null) - dest = new SpellDestination(playerCaster.GetHomebind().posX, playerCaster.GetHomebind().posY, playerCaster.GetHomebind().posZ, playerCaster.GetOrientation(), playerCaster.GetHomebind().GetMapId()); + dest = new SpellDestination(playerCaster.GetHomebind()); break; case Targets.DestDb: SpellTargetPosition st = Global.SpellMgr.GetSpellTargetPosition(m_spellInfo.Id, spellEffectInfo.EffectIndex); diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index e1cd93e7c..cdeefbb2a 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -5120,7 +5120,7 @@ namespace Game.Spells player.SetHomebind(homeLoc, areaId); player.SendBindPointUpdate(); - Log.outDebug(LogFilter.Spells, "EffectBind: New homebind MapId: {0}, AreaId: {1}, {2}, ", homeLoc.GetMapId(), areaId, homeLoc); + Log.outDebug(LogFilter.Spells, $"EffectBind: New homebind: {homeLoc}, AreaId: {areaId}"); // zone update player.SendPlayerBound(m_caster.GetGUID(), areaId); diff --git a/sql/base/characters_database.sql b/sql/base/characters_database.sql index 54a95be78..bed77f5de 100644 --- a/sql/base/characters_database.sql +++ b/sql/base/characters_database.sql @@ -1078,6 +1078,7 @@ CREATE TABLE `character_homebind` ( `posX` float NOT NULL DEFAULT '0', `posY` float NOT NULL DEFAULT '0', `posZ` float NOT NULL DEFAULT '0', + `orientation` float NOT NULL DEFAULT '0', PRIMARY KEY (`guid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Player System'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -3723,7 +3724,8 @@ INSERT INTO `updates` VALUES ('2021_08_18_00_characters.sql','5BA1326EE8EC907CDE82E6E8BCB38EA2E661F10A','ARCHIVED','2021-08-18 15:14:17',0), ('2021_10_02_00_characters.sql','31CEACE4E9A4BE58A659A2BDE4A7C51D2DB8AC41','ARCHIVED','2021-10-02 21:21:37',0), ('2021_10_02_01_characters.sql','F97B956F3B5F909294CA399F75B5795A07C4D8EC','ARCHIVED','2021-10-02 21:47:38',0), -('2021_10_15_00_characters.sql','906FECD65CBA7C406969F45FDF28DDEF8AAF8715','ARCHIVED','2021-10-15 10:11:47',0); +('2021_10_15_00_characters.sql','906FECD65CBA7C406969F45FDF28DDEF8AAF8715','ARCHIVED','2021-10-15 10:11:47',0), +('2021_10_16_00_characters.sql','B5A31BB6FBC34512767475EDF13099DEC948EBB7','RELEASED','2021-10-16 01:12:20',0); /*!40000 ALTER TABLE `updates` ENABLE KEYS */; UNLOCK TABLES; diff --git a/sql/updates/characters/master/2021_10_16_00_characters.sql b/sql/updates/characters/master/2021_10_16_00_characters.sql new file mode 100644 index 000000000..b92c1b58a --- /dev/null +++ b/sql/updates/characters/master/2021_10_16_00_characters.sql @@ -0,0 +1,2 @@ +-- +ALTER TABLE `character_homebind` ADD `orientation` float NOT NULL DEFAULT '0' AFTER `posZ`;