Core/Characters: Made homebind location a WorldLocation (this implicitly adds orientation)

Port From (https://github.com/TrinityCore/TrinityCore/commit/68c2fc8ff58d9ad272e8e17391a6bb6c3743923b)
This commit is contained in:
hondacrx
2021-10-16 17:59:01 -04:00
parent 86cc00ff57
commit 2d976d7421
11 changed files with 41 additions and 37 deletions
@@ -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 = ?");
+1 -2
View File
@@ -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;
}
+5
View File
@@ -427,5 +427,10 @@ namespace Game.Entities
{
return this;
}
public override string ToString()
{
return $"X: {posX} Y: {posY} Z: {posZ} O: {Orientation} MapId: {_mapId}";
}
}
}
+15 -16
View File
@@ -577,18 +577,13 @@ namespace Game.Entities
bool ok = false;
if (!result.IsEmpty())
{
homebind = new WorldLocation();
homebind.SetMapId(result.Read<uint>(0));
homebind.WorldRelocate(result.Read<uint>(0), result.Read<float>(2), result.Read<float>(3), result.Read<float>(4), result.Read<float>(5));
homebindAreaId = result.Read<uint>(1);
homebind.posX = result.Read<float>(2);
homebind.posY = result.Read<float>(3);
homebind.posZ = result.Read<float>(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));
+1 -1
View File
@@ -233,7 +233,7 @@ namespace Game.Entities
// Recall position
WorldLocation m_recall_location;
WorldLocation homebind;
WorldLocation homebind = new();
uint homebindAreaId;
uint m_HomebindTimer;
+7 -8
View File
@@ -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);
+1 -3
View File
@@ -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());
}
}
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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);
+3 -1
View File
@@ -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;
@@ -0,0 +1,2 @@
--
ALTER TABLE `character_homebind` ADD `orientation` float NOT NULL DEFAULT '0' AFTER `posZ`;