Core/Conditions: Implemented missing PlayerCondition columns - time and weather
Port From (https://github.com/TrinityCore/TrinityCore/commit/8aaf750be1ee16a299016cf038bd84bd9b387544)
This commit is contained in:
@@ -149,9 +149,7 @@ namespace Framework.IO
|
||||
|
||||
public uint ReadPackedTime()
|
||||
{
|
||||
uint packedDate = ReadUInt32();
|
||||
var time = new DateTime((int)((packedDate >> 24) & 0x1F) + 2000, (int)((packedDate >> 20) & 0xF) + 1, (int)((packedDate >> 14) & 0x3F) + 1, (int)(packedDate >> 6) & 0x1F, (int)(packedDate & 0x3F), 0);
|
||||
return (uint)Time.DateTimeToUnixTime(time);
|
||||
return (uint)Time.GetUnixTimeFromPackedTime(ReadUInt32());
|
||||
}
|
||||
|
||||
public Vector3 ReadVector3()
|
||||
@@ -360,14 +358,12 @@ namespace Framework.IO
|
||||
|
||||
public void WritePackedTime(long time)
|
||||
{
|
||||
var now = Time.UnixTimeToDateTime(time);
|
||||
WriteUInt32(Convert.ToUInt32((now.Year - 2000) << 24 | (now.Month - 1) << 20 | (now.Day - 1) << 14 | (int)now.DayOfWeek << 11 | now.Hour << 6 | now.Minute));
|
||||
WriteUInt32(Time.GetPackedTimeFromUnixTime(time));
|
||||
}
|
||||
|
||||
public void WritePackedTime()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
WriteUInt32(Convert.ToUInt32((now.Year - 2000) << 24 | (now.Month - 1) << 20 | (now.Day - 1) << 14 | (int)now.DayOfWeek << 11 | now.Hour << 6 | now.Minute));
|
||||
WriteUInt32(Time.GetPackedTimeFromDateTime(DateTime.Now));
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ public static class Time
|
||||
{
|
||||
return DateTimeOffset.FromUnixTimeSeconds(unixTime).LocalDateTime;
|
||||
}
|
||||
|
||||
public static long DateTimeToUnixTime(DateTime dateTime)
|
||||
{
|
||||
return ((DateTimeOffset)dateTime).ToUnixTimeSeconds();
|
||||
@@ -186,6 +187,23 @@ public static class Time
|
||||
return $"Days: {days} Hours: {hours} Minutes: {minute}";
|
||||
}
|
||||
|
||||
public static long GetUnixTimeFromPackedTime(uint packedDate)
|
||||
{
|
||||
var time = new DateTime((int)((packedDate >> 24) & 0x1F) + 2000, (int)((packedDate >> 20) & 0xF) + 1, (int)((packedDate >> 14) & 0x3F) + 1, (int)(packedDate >> 6) & 0x1F, (int)(packedDate & 0x3F), 0);
|
||||
return (uint)DateTimeToUnixTime(time);
|
||||
}
|
||||
|
||||
public static uint GetPackedTimeFromUnixTime(long unixTime)
|
||||
{
|
||||
var now = UnixTimeToDateTime(unixTime);
|
||||
return Convert.ToUInt32((now.Year - 2000) << 24 | (now.Month - 1) << 20 | (now.Day - 1) << 14 | (int)now.DayOfWeek << 11 | now.Hour << 6 | now.Minute);
|
||||
}
|
||||
|
||||
public static uint GetPackedTimeFromDateTime(DateTime now)
|
||||
{
|
||||
return Convert.ToUInt32((now.Year - 2000) << 24 | (now.Month - 1) << 20 | (now.Day - 1) << 14 | (int)now.DayOfWeek << 11 | now.Hour << 6 | now.Minute);
|
||||
}
|
||||
|
||||
public static void Profile(string description, int iterations, Action func)
|
||||
{
|
||||
//Run at highest priority to minimize fluctuations caused by other processes/threads
|
||||
|
||||
@@ -2043,7 +2043,14 @@ namespace Game
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: time condition
|
||||
if (condition.Time[0] != 0)
|
||||
{
|
||||
var from = Time.GetUnixTimeFromPackedTime(condition.Time[0]);
|
||||
var to = Time.GetUnixTimeFromPackedTime(condition.Time[1]);
|
||||
|
||||
if (GameTime.GetGameTime() < from || GameTime.GetGameTime() > to)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (condition.WorldStateExpressionID != 0)
|
||||
{
|
||||
@@ -2055,7 +2062,9 @@ namespace Game
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: weather condition
|
||||
if (condition.WeatherID != 0)
|
||||
if (player.GetMap().GetZoneWeather(player.GetZoneId()) != (WeatherState)condition.WeatherID)
|
||||
return false;
|
||||
|
||||
if (condition.Achievement[0] != 0)
|
||||
{
|
||||
|
||||
@@ -3467,6 +3467,21 @@ namespace Game.Maps
|
||||
return info.DefaultWeather;
|
||||
}
|
||||
|
||||
public WeatherState GetZoneWeather(uint zoneId)
|
||||
{
|
||||
ZoneDynamicInfo zoneDynamicInfo = _zoneDynamicInfo.LookupByKey(zoneId);
|
||||
if (zoneDynamicInfo != null)
|
||||
{
|
||||
if (zoneDynamicInfo.WeatherId != 0)
|
||||
return zoneDynamicInfo.WeatherId;
|
||||
|
||||
if (zoneDynamicInfo.DefaultWeather != null)
|
||||
return zoneDynamicInfo.DefaultWeather.GetWeatherState();
|
||||
}
|
||||
|
||||
return WeatherState.Fine;
|
||||
}
|
||||
|
||||
public void SetZoneWeather(uint zoneId, WeatherState weatherId, float weatherGrade)
|
||||
{
|
||||
if (!_zoneDynamicInfo.ContainsKey(zoneId))
|
||||
|
||||
@@ -339,7 +339,7 @@ namespace Game
|
||||
UpdateWeather();
|
||||
}
|
||||
|
||||
WeatherState GetWeatherState()
|
||||
public WeatherState GetWeatherState()
|
||||
{
|
||||
if (m_grade < 0.27f)
|
||||
return WeatherState.Fine;
|
||||
|
||||
Reference in New Issue
Block a user