Core/Instances: Delete InstanceSaveMgr and replace most of its uses with new InstanceLockMgr

Port From (https://github.com/TrinityCore/TrinityCore/commit/9b924522d0549dd67b10e2cbdfc20297dd21e182)
This commit is contained in:
hondacrx
2022-10-04 10:57:04 -04:00
parent 793cf91a24
commit 66c7047a29
27 changed files with 186 additions and 1545 deletions
+16 -40
View File
@@ -78,7 +78,7 @@ namespace Game
lockoutInfo.MapID = (int)instanceLock.GetMapId();
lockoutInfo.DifficultyID = (uint)instanceLock.GetDifficultyId();
lockoutInfo.ExpireTime = (int)(instanceLock.GetEffectiveExpiryTime() - GameTime.GetSystemTime()).TotalSeconds;
lockoutInfo.ExpireTime = (int)Math.Max((instanceLock.GetEffectiveExpiryTime() - GameTime.GetSystemTime()).TotalSeconds, 0);
lockoutInfo.InstanceID = instanceLock.GetInstanceId();
packet.RaidLockouts.Add(lockoutInfo);
@@ -538,21 +538,22 @@ namespace Game
[WorldPacketHandler(ClientOpcodes.SetSavedInstanceExtend)]
void HandleSetSavedInstanceExtend(SetSavedInstanceExtend setSavedInstanceExtend)
{
Player player = GetPlayer();
if (player)
{
InstanceBind instanceBind = player.GetBoundInstance((uint)setSavedInstanceExtend.MapID, (Difficulty)setSavedInstanceExtend.DifficultyID, setSavedInstanceExtend.Extend); // include expired instances if we are toggling extend on
if (instanceBind == null || instanceBind.save == null || !instanceBind.perm)
return;
// cannot modify locks currently in use
if (_player.GetMapId() == setSavedInstanceExtend.MapID)
return;
BindExtensionState newState;
if (!setSavedInstanceExtend.Extend || instanceBind.extendState == BindExtensionState.Expired)
newState = BindExtensionState.Normal;
else
newState = BindExtensionState.Extended;
var expiryTimes = Global.InstanceLockMgr.UpdateInstanceLockExtensionForPlayer(_player.GetGUID(), new MapDb2Entries((uint)setSavedInstanceExtend.MapID, (Difficulty)setSavedInstanceExtend.DifficultyID), setSavedInstanceExtend.Extend);
player.BindToInstance(instanceBind.save, true, newState, false);
}
if (expiryTimes.Item1 == DateTime.MinValue)
return;
CalendarRaidLockoutUpdated calendarRaidLockoutUpdated = new();
calendarRaidLockoutUpdated.ServerTime = GameTime.GetGameTime();
calendarRaidLockoutUpdated.MapID = setSavedInstanceExtend.MapID;
calendarRaidLockoutUpdated.DifficultyID = setSavedInstanceExtend.DifficultyID;
calendarRaidLockoutUpdated.OldTimeRemaining = (int)Math.Max((expiryTimes.Item1 - GameTime.GetSystemTime()).TotalSeconds, 0);
calendarRaidLockoutUpdated.NewTimeRemaining = (int)Math.Max((expiryTimes.Item2 - GameTime.GetSystemTime()).TotalSeconds, 0);
SendPacket(calendarRaidLockoutUpdated);
}
public void SendCalendarRaidLockoutAdded(InstanceLock instanceLock)
@@ -562,35 +563,10 @@ namespace Game
calendarRaidLockoutAdded.ServerTime = (uint)GameTime.GetGameTime();
calendarRaidLockoutAdded.MapID = (int)instanceLock.GetMapId();
calendarRaidLockoutAdded.DifficultyID = instanceLock.GetDifficultyId();
calendarRaidLockoutAdded.TimeRemaining = (int)(instanceLock.GetExpiryTime() - GameTime.GetSystemTime()).TotalSeconds;
calendarRaidLockoutAdded.TimeRemaining = (int)(instanceLock.GetEffectiveExpiryTime() - GameTime.GetSystemTime()).TotalSeconds;
SendPacket(calendarRaidLockoutAdded);
}
public void SendCalendarRaidLockoutUpdated(InstanceSave save)
{
if (save == null)
return;
long currTime = GameTime.GetGameTime();
CalendarRaidLockoutUpdated packet = new();
packet.DifficultyID = (uint)save.GetDifficultyID();
packet.MapID = (int)save.GetMapId();
packet.NewTimeRemaining = 0; // FIXME
packet.OldTimeRemaining = (int)(save.GetResetTime() - currTime);
SendPacket(packet);
}
public void SendCalendarRaidLockoutRemoved(InstanceSave save)
{
CalendarRaidLockoutRemoved calendarRaidLockoutRemoved = new();
calendarRaidLockoutRemoved.InstanceID = save.GetInstanceId();
calendarRaidLockoutRemoved.MapID = (int)save.GetMapId();
calendarRaidLockoutRemoved.DifficultyID = save.GetDifficultyID();
SendPacket(calendarRaidLockoutRemoved);
}
void SendCalendarRaidLockoutRemoved(InstanceLock instanceLock)
{
CalendarRaidLockoutRemoved calendarRaidLockoutRemoved = new();
-5
View File
@@ -2583,10 +2583,6 @@ namespace Game
stmt.AddValue(0, lowGuid);
SetQuery(PlayerLoginQueryLoad.Group, stmt);
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARACTER_INSTANCE);
stmt.AddValue(0, lowGuid);
SetQuery(PlayerLoginQueryLoad.BoundInstances, stmt);
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARACTER_AURAS);
stmt.AddValue(0, lowGuid);
SetQuery(PlayerLoginQueryLoad.Auras, stmt);
@@ -2866,7 +2862,6 @@ namespace Game
From,
Customizations,
Group,
BoundInstances,
Auras,
AuraEffects,
AuraStoredLocations,
+21 -10
View File
@@ -354,25 +354,36 @@ namespace Game
if (!teleported)
{
WorldSafeLocsEntry entranceLocation = null;
InstanceSave instanceSave = player.GetInstanceSave(at.target_mapId);
if (instanceSave != null)
MapRecord mapEntry = CliDB.MapStorage.LookupByKey(at.target_mapId);
if (mapEntry.Instanceable())
{
// Check if we can contact the instancescript of the instance for an updated entrance location
Map map = Global.MapMgr.FindMap(at.target_mapId, player.GetInstanceSave(at.target_mapId).GetInstanceId());
if (map)
uint targetInstanceId = Global.MapMgr.FindInstanceIdForPlayer(at.target_mapId, _player);
if (targetInstanceId != 0)
{
InstanceMap instanceMap = map.ToInstanceMap();
if (instanceMap != null)
Map map = Global.MapMgr.FindMap(at.target_mapId, targetInstanceId);
if (map != null)
{
InstanceScript instanceScript = instanceMap.GetInstanceScript();
if (instanceScript != null)
entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceScript.GetEntranceLocation());
InstanceMap instanceMap = map.ToInstanceMap();
if (instanceMap)
{
InstanceScript instanceScript = instanceMap.GetInstanceScript();
if (instanceScript != null)
entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceScript.GetEntranceLocation());
}
}
}
// Finally check with the instancesave for an entrance location if we did not get a valid one from the instancescript
if (entranceLocation == null)
entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceSave.GetEntranceLocation());
{
Group group = player.GetGroup();
Difficulty difficulty = group ? group.GetDifficultyID(mapEntry) : player.GetDifficultyID(mapEntry);
ObjectGuid instanceOwnerGuid = group ? group.GetRecentInstanceOwner(at.target_mapId) : player.GetGUID();
InstanceLock instanceLock = Global.InstanceLockMgr.FindActiveInstanceLock(instanceOwnerGuid, new MapDb2Entries(mapEntry, Global.DB2Mgr.GetDownscaledMapDifficultyData(at.target_mapId, ref difficulty)));
if (instanceLock != null)
entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceLock.GetData().EntranceWorldSafeLocId);
}
}
if (entranceLocation != null)
+18 -10
View File
@@ -377,19 +377,27 @@ namespace Game
if (mapEntry.IsDungeon())
{
// check if this instance has a reset time and send it to player if so
Difficulty diff = newMap.GetDifficultyID();
MapDifficultyRecord mapDiff = Global.DB2Mgr.GetMapDifficultyData(mapEntry.Id, diff);
if (mapDiff != null)
MapDb2Entries entries = new(mapEntry.Id, newMap.GetDifficultyID());
if (entries.MapDifficulty.HasResetSchedule())
{
if (mapDiff.GetRaidDuration() != 0)
RaidInstanceMessage raidInstanceMessage = new();
raidInstanceMessage.Type = InstanceResetWarningType.Welcome;
raidInstanceMessage.MapID = mapEntry.Id;
raidInstanceMessage.DifficultyID = newMap.GetDifficultyID();
InstanceLock playerLock = Global.InstanceLockMgr.FindActiveInstanceLock(GetPlayer().GetGUID(), entries);
if (playerLock != null)
{
long timeReset = Global.InstanceSaveMgr.GetResetTimeFor(mapEntry.Id, diff);
if (timeReset != 0)
{
uint timeleft = (uint)(timeReset - GameTime.GetGameTime());
player.SendInstanceResetWarning(mapEntry.Id, diff, timeleft, true);
}
raidInstanceMessage.Locked = !playerLock.IsExpired();
raidInstanceMessage.Extended = playerLock.IsExtended();
}
else
{
raidInstanceMessage.Locked = false;
raidInstanceMessage.Extended = false;
}
SendPacket(raidInstanceMessage);
}
// check if instance is valid