diff --git a/Projects/Server/Migrations/Server.DefaultSkillMod.v0.json b/Projects/Server/Migrations/Server.DefaultSkillMod.v0.json new file mode 100644 index 000000000..846a99051 --- /dev/null +++ b/Projects/Server/Migrations/Server.DefaultSkillMod.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.DefaultSkillMod" +} \ No newline at end of file diff --git a/Projects/Server/Migrations/Server.EquippedSkillMod.v0.json b/Projects/Server/Migrations/Server.EquippedSkillMod.v0.json new file mode 100644 index 000000000..e1761685f --- /dev/null +++ b/Projects/Server/Migrations/Server.EquippedSkillMod.v0.json @@ -0,0 +1,11 @@ +{ + "version": 0, + "type": "Server.EquippedSkillMod", + "properties": [ + { + "name": "Item", + "type": "Server.Item", + "rule": "SerializableInterfaceMigrationRule" + } + ] +} \ No newline at end of file diff --git a/Projects/Server/Migrations/Server.MobileMod.v0.json b/Projects/Server/Migrations/Server.MobileMod.v0.json new file mode 100644 index 000000000..5e9c66631 --- /dev/null +++ b/Projects/Server/Migrations/Server.MobileMod.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.MobileMod" +} \ No newline at end of file diff --git a/Projects/Server/Migrations/Server.ResistanceMod.v0.json b/Projects/Server/Migrations/Server.ResistanceMod.v0.json new file mode 100644 index 000000000..b2d027d5f --- /dev/null +++ b/Projects/Server/Migrations/Server.ResistanceMod.v0.json @@ -0,0 +1,19 @@ +{ + "version": 0, + "type": "Server.ResistanceMod", + "properties": [ + { + "name": "Type", + "type": "Server.ResistanceType", + "rule": "EnumMigrationRule" + }, + { + "name": "Offset", + "type": "int", + "rule": "PrimitiveTypeMigrationRule", + "ruleArguments": [ + "" + ] + } + ] +} \ No newline at end of file diff --git a/Projects/Server/Migrations/Server.SkillMod.v0.json b/Projects/Server/Migrations/Server.SkillMod.v0.json new file mode 100644 index 000000000..174c434c2 --- /dev/null +++ b/Projects/Server/Migrations/Server.SkillMod.v0.json @@ -0,0 +1,43 @@ +{ + "version": 0, + "type": "Server.SkillMod", + "properties": [ + { + "name": "ObeyCap", + "type": "bool", + "rule": "PrimitiveTypeMigrationRule", + "ruleArguments": [ + "" + ] + }, + { + "name": "Skill", + "type": "Server.SkillName", + "rule": "EnumMigrationRule" + }, + { + "name": "Relative", + "type": "bool", + "rule": "PrimitiveTypeMigrationRule", + "ruleArguments": [ + "" + ] + }, + { + "name": "Absolute", + "type": "bool", + "rule": "PrimitiveTypeMigrationRule", + "ruleArguments": [ + "" + ] + }, + { + "name": "Value", + "type": "double", + "rule": "PrimitiveTypeMigrationRule", + "ruleArguments": [ + "" + ] + } + ] +} \ No newline at end of file diff --git a/Projects/Server/Migrations/Server.StatMod.v0.json b/Projects/Server/Migrations/Server.StatMod.v0.json new file mode 100644 index 000000000..5b3b28174 --- /dev/null +++ b/Projects/Server/Migrations/Server.StatMod.v0.json @@ -0,0 +1,40 @@ +{ + "version": 0, + "type": "Server.StatMod", + "properties": [ + { + "name": "Added", + "type": "System.DateTime", + "rule": "PrimitiveTypeMigrationRule", + "ruleArguments": [ + "" + ] + }, + { + "name": "Duration", + "type": "System.TimeSpan", + "rule": "PrimitiveTypeMigrationRule" + }, + { + "name": "Type", + "type": "Server.StatType", + "rule": "EnumMigrationRule" + }, + { + "name": "Name", + "type": "string", + "rule": "PrimitiveTypeMigrationRule", + "ruleArguments": [ + "" + ] + }, + { + "name": "Offset", + "type": "int", + "rule": "PrimitiveTypeMigrationRule", + "ruleArguments": [ + "" + ] + } + ] +} \ No newline at end of file diff --git a/Projects/Server/Migrations/Server.TimedSkillMod.v0.json b/Projects/Server/Migrations/Server.TimedSkillMod.v0.json new file mode 100644 index 000000000..d1c4b0296 --- /dev/null +++ b/Projects/Server/Migrations/Server.TimedSkillMod.v0.json @@ -0,0 +1,14 @@ +{ + "version": 0, + "type": "Server.TimedSkillMod", + "properties": [ + { + "name": "Expire", + "type": "System.DateTime", + "rule": "PrimitiveTypeMigrationRule", + "ruleArguments": [ + "" + ] + } + ] +} \ No newline at end of file diff --git a/Projects/Server/Mobiles/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs index c811926af..2677a6051 100644 --- a/Projects/Server/Mobiles/Mobile.cs +++ b/Projects/Server/Mobiles/Mobile.cs @@ -27,224 +27,6 @@ namespace Server public delegate void PromptStateCallback(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; diff --git a/Projects/Server/Mobiles/Mods/DefaultSkillMod.cs b/Projects/Server/Mobiles/Mods/DefaultSkillMod.cs new file mode 100644 index 000000000..578cf2cb5 --- /dev/null +++ b/Projects/Server/Mobiles/Mods/DefaultSkillMod.cs @@ -0,0 +1,32 @@ +/************************************************************************* + * ModernUO * + * Copyright 2019-2022 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: DefaultSkillMod.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using ModernUO.Serialization; + +namespace Server; + +[SerializationGenerator(0)] +public partial class DefaultSkillMod : SkillMod +{ + public DefaultSkillMod(Mobile owner) : base(owner) + { + } + + public DefaultSkillMod(SkillName skill, bool relative, double value) : base(skill, relative, value) + { + } + + public override bool CheckCondition() => true; +} diff --git a/Projects/Server/Mobiles/Mods/EquippedSkillMod.cs b/Projects/Server/Mobiles/Mods/EquippedSkillMod.cs new file mode 100644 index 000000000..101a19681 --- /dev/null +++ b/Projects/Server/Mobiles/Mods/EquippedSkillMod.cs @@ -0,0 +1,34 @@ +/************************************************************************* + * ModernUO * + * Copyright 2019-2022 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: EquippedSkillMod.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using ModernUO.Serialization; + +namespace Server; + +[SerializationGenerator(0)] +public partial class EquippedSkillMod : SkillMod +{ + [SerializableField(0)] + private Item _item; + + public EquippedSkillMod(Mobile owner) : base(owner) + { + } + + public EquippedSkillMod(SkillName skill, bool relative, double value, Item item, Mobile mobile) + : base(skill, relative, value, mobile) => _item = item; + + public override bool CheckCondition() => !_item.Deleted && Owner?.Deleted == false && _item.Parent == Owner; +} diff --git a/Projects/Server/Mobiles/Mods/MobileMod.cs b/Projects/Server/Mobiles/Mods/MobileMod.cs new file mode 100644 index 000000000..be1083c0d --- /dev/null +++ b/Projects/Server/Mobiles/Mods/MobileMod.cs @@ -0,0 +1,27 @@ +/************************************************************************* + * ModernUO * + * Copyright 2019-2022 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: MobileMod.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using ModernUO.Serialization; + +namespace Server; + +[SerializationGenerator(0)] +public partial class MobileMod +{ + [DirtyTrackingEntity] + public virtual Mobile Owner { get; set; } + + public MobileMod(Mobile owner) => Owner = owner; +} diff --git a/Projects/Server/Mobiles/Mods/ResistanceMod.cs b/Projects/Server/Mobiles/Mods/ResistanceMod.cs new file mode 100644 index 000000000..8b14cc1a5 --- /dev/null +++ b/Projects/Server/Mobiles/Mods/ResistanceMod.cs @@ -0,0 +1,70 @@ +/************************************************************************* + * ModernUO * + * Copyright 2019-2022 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: ResistanceMod.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using ModernUO.Serialization; + +namespace Server; + +[SerializationGenerator(0)] +public partial class ResistanceMod : MobileMod +{ + // Field 0 + private int _offset; + + // Field 1 + private ResistanceType _type; + + public ResistanceMod(Mobile owner) : base(owner) + { + } + + public ResistanceMod(ResistanceType type, int offset, Mobile owner = null) : base(owner) + { + _type = type; + _offset = offset; + } + + [SerializableField(0)] + public ResistanceType Type + { + get => _type; + set + { + if (_type != value) + { + _type = value; + + Owner?.UpdateResistances(); + MarkDirty(); + } + } + } + + [SerializableField(1)] + public int Offset + { + get => _offset; + set + { + if (_offset != value) + { + _offset = value; + + Owner?.UpdateResistances(); + MarkDirty(); + } + } + } +} diff --git a/Projects/Server/Mobiles/Mods/SkillMod.cs b/Projects/Server/Mobiles/Mods/SkillMod.cs new file mode 100644 index 000000000..a30f29ad1 --- /dev/null +++ b/Projects/Server/Mobiles/Mods/SkillMod.cs @@ -0,0 +1,146 @@ +/************************************************************************* + * ModernUO * + * Copyright 2019-2022 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: SkillMod.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using ModernUO.Serialization; + +namespace Server; + +[SerializationGenerator(0)] +public abstract partial class SkillMod : MobileMod +{ + private bool _obeyCap; + + private bool _relative; + private SkillName _skill; + private double _value; + + public SkillMod(Mobile owner) : base(owner) + { + } + + public SkillMod(SkillName skill, bool relative, double value, Mobile owner = null) : base(owner) + { + _skill = skill; + _relative = relative; + _value = value; + } + + [SerializableField(0)] + public bool ObeyCap + { + get => _obeyCap; + set + { + _obeyCap = value; + + var sk = Owner?.Skills[_skill]; + sk?.Update(); + MarkDirty(); + } + } + + public override Mobile Owner + { + get => base.Owner; + set + { + var owner = base.Owner; + if (owner != value) + { + owner?.RemoveSkillMod(this); + owner = value; + owner?.AddSkillMod(this); + } + } + } + + [SerializableField(1)] + public SkillName Skill + { + get => _skill; + set + { + if (_skill != value) + { + var oldUpdate = Owner?.Skills[_skill]; + + _skill = value; + + var sk = Owner?.Skills[_skill]; + sk?.Update(); + oldUpdate?.Update(); + MarkDirty(); + } + } + } + + [SerializableField(2)] + public bool Relative + { + get => _relative; + set + { + if (_relative != value) + { + _relative = value; + + var sk = Owner?.Skills[_skill]; + sk?.Update(); + MarkDirty(); + } + } + } + + [SerializableField(3)] + public bool Absolute + { + get => !_relative; + set + { + if (_relative == value) + { + _relative = !value; + + var sk = Owner?.Skills[_skill]; + sk?.Update(); + MarkDirty(); + } + } + } + + [SerializableField(4)] + public double Value + { + get => _value; + set + { + if (_value != value) + { + _value = value; + + var sk = Owner?.Skills[_skill]; + sk?.Update(); + MarkDirty(); + } + } + } + + public void Remove() + { + Owner = null; + } + + public abstract bool CheckCondition(); +} diff --git a/Projects/Server/Mobiles/Mods/StatMod.cs b/Projects/Server/Mobiles/Mods/StatMod.cs new file mode 100644 index 000000000..d92067368 --- /dev/null +++ b/Projects/Server/Mobiles/Mods/StatMod.cs @@ -0,0 +1,53 @@ +/************************************************************************* + * ModernUO * + * Copyright 2019-2022 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: StatMod.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using System; +using ModernUO.Serialization; + +namespace Server; + +[SerializationGenerator(0)] +public partial class StatMod : MobileMod +{ + [SerializableField(0, getter: "private", setter: "private")] + private DateTime _added; + + [SerializableField(1, getter: "private", setter: "private")] + private TimeSpan _duration; + + [SerializableField(2, setter: "private")] + private StatType _type; + + [SerializableField(3, setter: "private")] + private string _name; + + [SerializableField(4, setter: "private")] + private int _offset; + + public StatMod(Mobile owner) : base(owner) + { + } + + public StatMod(StatType type, string name, int offset, TimeSpan duration, Mobile owner = null) : base(owner) + { + _type = type; + _name = name; + _offset = offset; + _duration = duration; + _added = Core.Now; + } + + public bool HasElapsed() => _duration != TimeSpan.Zero && Core.Now - _added >= _duration; +} diff --git a/Projects/Server/Mobiles/Mods/TimedSkillMod.cs b/Projects/Server/Mobiles/Mods/TimedSkillMod.cs new file mode 100644 index 000000000..388e79c0e --- /dev/null +++ b/Projects/Server/Mobiles/Mods/TimedSkillMod.cs @@ -0,0 +1,40 @@ +/************************************************************************* + * ModernUO * + * Copyright 2019-2022 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: TimedSkillMod.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using System; +using ModernUO.Serialization; + +namespace Server; + +[SerializationGenerator(0)] +public partial class TimedSkillMod : SkillMod +{ + [SerializableField(0, setter: "private")] + private DateTime _expire; + + public TimedSkillMod(Mobile owner) : base(owner) + { + } + + 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) => _expire = expire; + + public override bool CheckCondition() => Core.Now < _expire; +} diff --git a/Projects/Server/Serialization/ISerializableExtensions.cs b/Projects/Server/Serialization/ISerializableExtensions.cs index b98b239ef..15ecb4f1c 100644 --- a/Projects/Server/Serialization/ISerializableExtensions.cs +++ b/Projects/Server/Serialization/ISerializableExtensions.cs @@ -24,7 +24,10 @@ namespace Server [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MarkDirty(this ISerializable entity) { - entity.SavePosition = -1; + if (entity != null) + { + entity.SavePosition = -1; + } } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Projects/UOContent/Migrations/Server.Items.Candle.v0.json b/Projects/UOContent/Migrations/Server.Items.Candle.v0.json new file mode 100644 index 000000000..fa8c3c662 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.Candle.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.Candle" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.Lantern.v0.json b/Projects/UOContent/Migrations/Server.Items.Lantern.v0.json new file mode 100644 index 000000000..98dd8da0b --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.Lantern.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.Lantern" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.LanternOfSouls.v0.json b/Projects/UOContent/Migrations/Server.Items.LanternOfSouls.v0.json new file mode 100644 index 000000000..aeede5b0e --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.LanternOfSouls.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.LanternOfSouls" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.Torch.v0.json b/Projects/UOContent/Migrations/Server.Items.Torch.v0.json new file mode 100644 index 000000000..d1ed7780a --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.Torch.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.Torch" +} \ No newline at end of file