.time day / night: change the sky and the light, not only the clock

The client takes the frozen clock in the middle of a session (its clock
shows 12:00) but does not light the world again from it, so the sky
stayed as it was until the next login. Put a fixed light over every
area light of the map with SMSG_OVERRIDE_LIGHT, the packet scripted
events use to darken a zone: Light 15377 (daylight) or 16854 (night),
two Forever client lights with a single keyframe that look the same at
any hour. .time auto gives the map its own lights back.

Sent on .time and on every map entry, open world maps only (a dungeon
keeps its own light). A zone's scripted light still wins, and when it
ends, a player with their own sky goes back to it, not to the map's
light. The idea and the two lights come from SIN's Personal Day and
Night pack (0.1.35); written as our own on top of the day cycle.
This commit is contained in:
Karrz1
2026-11-16 19:57:06 +00:00
parent e0a89aa84c
commit ac91566dcd
5 changed files with 94 additions and 6 deletions
@@ -26570,6 +26570,48 @@ void Player::SetSkyMode(DayCycle::SkyMode mode)
CharacterDatabase.Execute(stmt);
SendDayCycle();
if (IsInWorld())
{
SendSkyLights(true);
GetMap()->SendZoneLightOverrides(GetZoneId(), this); // a zone's scripted light (an event darkening it) still wins
}
}
int32 Player::GetSkyOverrideLight(uint32 areaLightId) const
{
if (!IsInWorld() || GetMap()->Instanceable())
return 0;
int32 const skyLight = DayCycle::OverrideLightFor(GetSkyMode());
if (!skyLight || !sLightStore.HasRecord(skyLight))
return 0;
LightEntry const* areaLight = sLightStore.LookupEntry(areaLightId);
if (!areaLight || areaLight->ContinentID != int32(GetMapId()) || int32(areaLightId) == skyLight)
return 0;
return skyLight;
}
void Player::SendSkyLights(bool restore /*= false*/)
{
if (!IsInWorld() || GetMap()->Instanceable())
return;
if (!restore && DayCycle::OverrideLightFor(GetSkyMode()) == 0)
return;
for (LightEntry const* light : sLightStore)
{
if (light->ContinentID != int32(GetMapId()))
continue;
WorldPackets::Misc::OverrideLight overrideLight;
overrideLight.AreaLightID = light->ID;
overrideLight.OverrideLightID = GetSkyOverrideLight(light->ID);
overrideLight.TransitionMilliseconds = DayCycle::LightTransitionMs;
SendDirectMessage(overrideLight.Write());
}
}
void Player::SendInitialPacketsAfterAddToMap()
@@ -26592,6 +26634,7 @@ void Player::SendInitialPacketsAfterAddToMap()
// update zone
uint32 newzone, newarea;
GetZoneAndAreaId(newzone, newarea);
SendSkyLights(); // before UpdateZone: the zone's scripted lights win
UpdateZone(newzone, newarea); // also call SendInitWorldStates();
GetSession()->SendLoadCUFProfiles();
+5
View File
@@ -1288,6 +1288,11 @@ class TC_GAME_API Player final : public Unit, public GridObject<Player>
void SendDayCycle() const;
DayCycle::SkyMode GetSkyMode() const;
void SetSkyMode(DayCycle::SkyMode mode); // saved at once and sent
// .time day / night: a fixed light over every area light of the map (the client does not light the world again from
// a new clock); restore: give the map its own lights back (.time auto). Open world maps only.
void SendSkyLights(bool restore = false);
// the light this player's sky puts over an area light of the map they are on; 0: none
int32 GetSkyOverrideLight(uint32 areaLightId) const;
void SendSupercededSpell(uint32 oldSpell, uint32 newSpell) const;
void SendTransferAborted(uint32 mapid, TransferAbortReason reason, uint8 arg = 0, int32 mapDifficultyXConditionID = 0) const;
+28 -6
View File
@@ -4182,7 +4182,21 @@ void Map::SendZoneDynamicInfo(uint32 zoneId, Player* player) const
SendZoneWeather(itr->second, player);
for (ZoneDynamicInfo::LightOverride const& lightOverride : itr->second.LightOverrides)
SendZoneLightOverrides(itr->second, player);
}
void Map::SendZoneLightOverrides(uint32 zoneId, Player* player) const
{
auto itr = _zoneDynamicInfo.find(zoneId);
if (itr == _zoneDynamicInfo.end())
return;
SendZoneLightOverrides(itr->second, player);
}
void Map::SendZoneLightOverrides(ZoneDynamicInfo const& zoneDynamicInfo, Player* player) const
{
for (ZoneDynamicInfo::LightOverride const& lightOverride : zoneDynamicInfo.LightOverrides)
{
WorldPackets::Misc::OverrideLight overrideLight;
overrideLight.AreaLightID = lightOverride.AreaLightId;
@@ -4304,11 +4318,19 @@ void Map::SetZoneOverrideLight(uint32 zoneId, uint32 areaLightId, uint32 overrid
lightOverride.TransitionMilliseconds = static_cast<uint32>(transitionTime.count());
}
WorldPackets::Misc::OverrideLight overrideLight;
overrideLight.AreaLightID = areaLightId;
overrideLight.OverrideLightID = overrideLightId;
overrideLight.TransitionMilliseconds = static_cast<uint32>(transitionTime.count());
SendZoneMessage(zoneId, overrideLight.Write());
// when the zone's light ends, a player who keeps their own sky (.time day / night) goes back to that sky, not the map's light
for (MapReference const& ref : GetPlayers())
{
Player* player = ref.GetSource();
if (!player->IsInWorld() || player->GetZoneId() != zoneId)
continue;
WorldPackets::Misc::OverrideLight overrideLight;
overrideLight.AreaLightID = areaLightId;
overrideLight.OverrideLightID = overrideLightId ? int32(overrideLightId) : player->GetSkyOverrideLight(areaLightId);
overrideLight.TransitionMilliseconds = static_cast<uint32>(transitionTime.count());
player->SendDirectMessage(overrideLight.Write());
}
}
void Map::UpdateAreaDependentAuras()
+2
View File
@@ -556,6 +556,8 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
void SendRemoveTransports(Player* player);
void SendUpdateTransportVisibility(Player* player);
void SendZoneDynamicInfo(uint32 zoneId, Player* player) const;
void SendZoneLightOverrides(uint32 zoneId, Player* player) const;
void SendZoneLightOverrides(ZoneDynamicInfo const& zoneDynamicInfo, Player* player) const;
void SendZoneWeather(uint32 zoneId, Player* player) const;
void SendZoneWeather(ZoneDynamicInfo const& zoneDynamicInfo, Player* player) const;
void SendZoneText(uint32 zoneId, const char* text, WorldSession const* self = nullptr, Optional<Team> team = { }) const;
+16
View File
@@ -42,6 +42,22 @@ namespace DayCycle
return v == uint8(SkyMode::Day) ? SkyMode::Day : v == uint8(SkyMode::Night) ? SkyMode::Night : SkyMode::Auto;
}
// The client takes a new clock in the middle of a session (its clock shows it) but does not light the world again from
// it: the sky changes only at the next login. So .time day / night also put a fixed light over every area light of the
// map (SMSG_OVERRIDE_LIGHT, the same packet scripted events use to darken a zone). Two Light.db2 records of the Forever
// client whose LightParams have a single LightData keyframe, so they look the same at any hour: 15377 (map 2940, its
// global light, params 6730) is daylight, 16854 (map 2991, params 7601) is night. Found and tried in game by SIN
// (Personal Day and Night pack, 0.1.35).
constexpr int32 DayLightID = 15377;
constexpr int32 NightLightID = 16854;
constexpr int32 LightTransitionMs = 200;
// the light put over the map's area lights for a sky mode; 0: none, the map's own lights
constexpr int32 OverrideLightFor(SkyMode mode)
{
return mode == SkyMode::Day ? DayLightID : mode == SkyMode::Night ? NightLightID : 0;
}
// the client's speed for the realm clock: game minutes per real second
constexpr float NormalSpeed = 0.01666667f;