fix: Moves mods and fixes migrations for lights (#1080)

- [X] Removes duplicate property for owner.
- [X] Codegens them all (even though they aren't used, just in case someone wants to).
This commit is contained in:
Kamron Batman 2022-06-18 21:28:51 -07:00 • committed by GitHub
parent dc7033d71f
commit 7adf52ef48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 557 additions and 219 deletions

View file

@ -27,224 +27,6 @@ namespace Server
public delegate void PromptStateCallback<in T>(Mobile from, string text, T state);
public class TimedSkillMod : SkillMod
{
private readonly DateTime m_Expire;
public TimedSkillMod(SkillName skill, bool relative, double value, TimeSpan delay)
: this(skill, relative, value, Core.Now + delay)
{
}
public TimedSkillMod(SkillName skill, bool relative, double value, DateTime expire)
: base(skill, relative, value) =>
m_Expire = expire;
public override bool CheckCondition() => Core.Now < m_Expire;
}
public class EquippedSkillMod : SkillMod
{
private readonly Item m_Item;
private readonly Mobile m_Mobile;
public EquippedSkillMod(SkillName skill, bool relative, double value, Item item, Mobile mobile)
: base(skill, relative, value)
{
m_Item = item;
m_Mobile = mobile;
}
public override bool CheckCondition() => !m_Item.Deleted && !m_Mobile.Deleted && m_Item.Parent == m_Mobile;
}
public class DefaultSkillMod : SkillMod
{
public DefaultSkillMod(SkillName skill, bool relative, double value)
: base(skill, relative, value)
{
}
public override bool CheckCondition() => true;
}
public abstract class SkillMod
{
private bool m_ObeyCap;
private Mobile m_Owner;
private bool m_Relative;
private SkillName m_Skill;
private double m_Value;
protected SkillMod(SkillName skill, bool relative, double value)
{
m_Skill = skill;
m_Relative = relative;
m_Value = value;
}
public bool ObeyCap
{
get => m_ObeyCap;
set
{
m_ObeyCap = value;
var sk = m_Owner?.Skills[m_Skill];
sk?.Update();
}
}
public Mobile Owner
{
get => m_Owner;
set
{
if (m_Owner != value)
{
m_Owner?.RemoveSkillMod(this);
m_Owner = value;
m_Owner?.AddSkillMod(this);
}
}
}
public SkillName Skill
{
get => m_Skill;
set
{
if (m_Skill != value)
{
var oldUpdate = m_Owner?.Skills[m_Skill];
m_Skill = value;
var sk = m_Owner?.Skills[m_Skill];
sk?.Update();
oldUpdate?.Update();
}
}
}
public bool Relative
{
get => m_Relative;
set
{
if (m_Relative != value)
{
m_Relative = value;
var sk = m_Owner?.Skills[m_Skill];
sk?.Update();
}
}
}
public bool Absolute
{
get => !m_Relative;
set
{
if (m_Relative == value)
{
m_Relative = !value;
var sk = m_Owner?.Skills[m_Skill];
sk?.Update();
}
}
}
public double Value
{
get => m_Value;
set
{
if (m_Value != value)
{
m_Value = value;
var sk = m_Owner?.Skills[m_Skill];
sk?.Update();
}
}
}
public void Remove()
{
Owner = null;
}
public abstract bool CheckCondition();
}
public class ResistanceMod
{
private int m_Offset;
private ResistanceType m_Type;
public ResistanceMod(ResistanceType type, int offset)
{
m_Type = type;
m_Offset = offset;
}
public Mobile Owner { get; set; }
public ResistanceType Type
{
get => m_Type;
set
{
if (m_Type != value)
{
m_Type = value;
Owner?.UpdateResistances();
}
}
}
public int Offset
{
get => m_Offset;
set
{
if (m_Offset != value)
{
m_Offset = value;
Owner?.UpdateResistances();
}
}
}
}
public class StatMod
{
private readonly DateTime m_Added;
private readonly TimeSpan m_Duration;
public StatMod(StatType type, string name, int offset, TimeSpan duration)
{
Type = type;
Name = name;
Offset = offset;
m_Duration = duration;
m_Added = Core.Now;
}
public StatType Type { get; }
public string Name { get; }
public int Offset { get; }
public bool HasElapsed() => m_Duration != TimeSpan.Zero && Core.Now - m_Added >= m_Duration;
}
public class DamageEntry
{
public DamageEntry(Mobile damager) => Damager = damager;