servuo/Scripts/Multis/Houses/DynamicDecay.cs
TrueUO a99dec6807
Changes (#4781)
All loot pack items are now generated when the mobile is killed.

Reworked monster stealing and begging.

Various re-structuring and bug fixes.

Co-authored-by: TrueUO <knight.daniel.r@gmail.com>
2020-05-13 07:58:04 -07:00

63 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
namespace Server.Multis
{
public class DynamicDecay
{
private static readonly Dictionary<DecayLevel, DecayStageInfo> m_Stages;
static DynamicDecay()
{
m_Stages = new Dictionary<DecayLevel, DecayStageInfo>();
Register(DecayLevel.LikeNew, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
Register(DecayLevel.Slightly, TimeSpan.FromDays(1), TimeSpan.FromDays(2));
Register(DecayLevel.Somewhat, TimeSpan.FromDays(1), TimeSpan.FromDays(2));
Register(DecayLevel.Fairly, TimeSpan.FromDays(1), TimeSpan.FromDays(2));
Register(DecayLevel.Greatly, TimeSpan.FromDays(1), TimeSpan.FromDays(2));
Register(DecayLevel.IDOC, TimeSpan.FromHours(12), TimeSpan.FromHours(24));
}
public static bool Enabled => true;
public static void Register(DecayLevel level, TimeSpan min, TimeSpan max)
{
DecayStageInfo info = new DecayStageInfo(min, max);
if (m_Stages.ContainsKey(level))
m_Stages[level] = info;
else
m_Stages.Add(level, info);
}
public static bool Decays(DecayLevel level)
{
return m_Stages.ContainsKey(level);
}
public static TimeSpan GetRandomDuration(DecayLevel level)
{
if (!m_Stages.ContainsKey(level))
return TimeSpan.Zero;
DecayStageInfo info = m_Stages[level];
long min = info.MinDuration.Ticks;
long max = info.MaxDuration.Ticks;
return TimeSpan.FromTicks(min + (long)(Utility.RandomDouble() * (max - min)));
}
}
public class DecayStageInfo
{
private readonly TimeSpan m_MinDuration;
private readonly TimeSpan m_MaxDuration;
public DecayStageInfo(TimeSpan min, TimeSpan max)
{
m_MinDuration = min;
m_MaxDuration = max;
}
public TimeSpan MinDuration => m_MinDuration;
public TimeSpan MaxDuration => m_MaxDuration;
}
}