Skip to content

Commit fd2f90c

Browse files
authored
feat: Adds SerializableFieldChanged option (#2324)
1 parent 06bb2f5 commit fd2f90c

File tree

6 files changed

+60
-120
lines changed

6 files changed

+60
-120
lines changed

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"modernuoschemagenerator": {
6-
"version": "2.14.1",
6+
"version": "2.14.2",
77
"commands": [
88
"ModernUOSchemaGenerator"
99
]
Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*************************************************************************
22
* ModernUO *
3-
* Copyright 2019-2023 - ModernUO Development Team *
3+
* Copyright 2019-2026 - ModernUO Development Team *
44
* Email: [email protected] *
55
* File: ResistanceMod.cs *
66
* *
@@ -13,13 +13,28 @@
1313
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
1414
*************************************************************************/
1515

16+
using System.Runtime.CompilerServices;
1617
using ModernUO.Serialization;
1718

1819
namespace Server;
1920

2021
[SerializationGenerator(0)]
2122
public partial class ResistanceMod : MobileMod
2223
{
24+
[SerializableField(0)]
25+
private ResistanceType _type;
26+
27+
[SerializableFieldChanged(0)]
28+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29+
private void OnTypeChanged(ResistanceType oldValue, ResistanceType newValue) => Owner?.UpdateResistances();
30+
31+
[SerializableField(1)]
32+
private int _offset;
33+
34+
[SerializableFieldChanged(1)]
35+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
36+
private void OnOffsetChanged(int oldValue, int newValue) => Owner?.UpdateResistances();
37+
2338
public ResistanceMod(Mobile owner) : base(owner)
2439
{
2540
}
@@ -29,36 +44,4 @@ public ResistanceMod(ResistanceType type, string name, int offset, Mobile owner
2944
_type = type;
3045
_offset = offset;
3146
}
32-
33-
[SerializableProperty(0)]
34-
public ResistanceType Type
35-
{
36-
get => _type;
37-
set
38-
{
39-
if (_type != value)
40-
{
41-
_type = value;
42-
43-
Owner?.UpdateResistances();
44-
MarkDirty();
45-
}
46-
}
47-
}
48-
49-
[SerializableProperty(1)]
50-
public int Offset
51-
{
52-
get => _offset;
53-
set
54-
{
55-
if (_offset != value)
56-
{
57-
_offset = value;
58-
59-
Owner?.UpdateResistances();
60-
MarkDirty();
61-
}
62-
}
63-
}
6447
}

Projects/Server/Mobiles/Mods/SkillMod.cs

Lines changed: 28 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*************************************************************************
22
* ModernUO *
3-
* Copyright 2019-2023 - ModernUO Development Team *
3+
* Copyright 2019-2026 - ModernUO Development Team *
44
* Email: [email protected] *
55
* File: SkillMod.cs *
66
* *
@@ -21,66 +21,44 @@ namespace Server;
2121
[SerializationGenerator(0)]
2222
public abstract partial class SkillMod : MobileMod
2323
{
24-
public SkillMod(Mobile owner) : base(owner)
25-
{
26-
}
24+
[SerializableField(0)]
25+
private bool _obeyCap;
2726

28-
public SkillMod(SkillName skill, string name, bool relative, double value, Mobile owner = null) : base(owner, name)
27+
[SerializableFieldChanged(0)]
28+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29+
private void OnObeCapChanged(bool oldValue, bool newValue) => Owner?.Skills[_skill]?.Update();
30+
31+
[SerializableField(1)]
32+
private SkillName _skill;
33+
34+
[SerializableFieldChanged(1)]
35+
private void OnSkillChanged(SkillName oldValue, SkillName newValue)
2936
{
30-
_skill = skill;
31-
_relative = relative;
32-
_value = value;
37+
Owner?.Skills[newValue]?.Update();
38+
Owner?.Skills[oldValue]?.Update();
3339
}
3440

35-
[SerializableProperty(0)]
36-
public bool ObeyCap
37-
{
38-
get => _obeyCap;
39-
set
40-
{
41-
_obeyCap = value;
41+
[SerializableField(2)]
42+
private bool _relative;
4243

43-
var sk = Owner?.Skills[_skill];
44-
sk?.Update();
45-
MarkDirty();
46-
}
47-
}
44+
[SerializableFieldChanged(2)]
45+
private void OnRelativeChanged(bool oldValue, bool newValue) => Owner?.Skills[_skill]?.Update();
4846

49-
[SerializableProperty(1)]
50-
public SkillName Skill
51-
{
52-
get => _skill;
53-
set
54-
{
55-
if (_skill != value)
56-
{
57-
var oldUpdate = Owner?.Skills[_skill];
47+
[SerializableField(3)]
48+
private double _value;
5849

59-
_skill = value;
50+
[SerializableFieldChanged(3)]
51+
private void OnValueChanged(double oldValue, double newValue) => Owner?.Skills[_skill]?.Update();
6052

61-
var sk = Owner?.Skills[_skill];
62-
sk?.Update();
63-
oldUpdate?.Update();
64-
MarkDirty();
65-
}
66-
}
53+
public SkillMod(Mobile owner) : base(owner)
54+
{
6755
}
6856

69-
[SerializableProperty(2)]
70-
public bool Relative
57+
public SkillMod(SkillName skill, string name, bool relative, double value, Mobile owner = null) : base(owner, name)
7158
{
72-
get => _relative;
73-
set
74-
{
75-
if (_relative != value)
76-
{
77-
_relative = value;
78-
79-
var sk = Owner?.Skills[_skill];
80-
sk?.Update();
81-
MarkDirty();
82-
}
83-
}
59+
_skill = skill;
60+
_relative = relative;
61+
_value = value;
8462
}
8563

8664
public bool Absolute
@@ -89,23 +67,6 @@ public bool Absolute
8967
set => Relative = !value;
9068
}
9169

92-
[SerializableProperty(3)]
93-
public double Value
94-
{
95-
get => _value;
96-
set
97-
{
98-
if (_value != value)
99-
{
100-
_value = value;
101-
102-
var sk = Owner?.Skills[_skill];
103-
sk?.Update();
104-
MarkDirty();
105-
}
106-
}
107-
}
108-
10970
[MethodImpl(MethodImplOptions.AggressiveInlining)]
11071
public void Remove() => Owner?.RemoveSkillMod(this);
11172

Projects/Server/Server.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<PackageReference Include="LibDeflate.Bindings" Version="1.0.2.120" />
4040
<PackageReference Include="System.IO.Hashing" Version="10.0.2" />
4141

42-
<PackageReference Include="ModernUO.Serialization.Annotations" Version="2.14.0" />
43-
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.14.1" />
42+
<PackageReference Include="ModernUO.Serialization.Annotations" Version="2.14.2" />
43+
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.14.2" />
4444
</ItemGroup>
4545
<ItemGroup>
4646
<AdditionalFiles Include="Migrations/*.v*.json" />

Projects/UOContent/Items/Clothing/Shoes.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Runtime.CompilerServices;
12
using ModernUO.Serialization;
23

34
namespace Server.Items
@@ -51,6 +52,16 @@ public Boots(int hue = 0) : base(0x170B, hue)
5152
[SerializationGenerator(2, false)]
5253
public partial class ThighBoots : BaseShoes, IArcaneEquip
5354
{
55+
[EncodedInt]
56+
[InvalidateProperties]
57+
[SerializableField(0)]
58+
[SerializedCommandProperty(AccessLevel.GameMaster)]
59+
private int _curArcaneCharges;
60+
61+
[SerializableFieldChanged(0)]
62+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
63+
private void OnCurArcaneChargesChanged(int oldValue, int newValue) => Update();
64+
5465
[Constructible]
5566
public ThighBoots(int hue = 0) : base(0x1711, hue)
5667
{
@@ -60,21 +71,6 @@ public ThighBoots(int hue = 0) : base(0x1711, hue)
6071

6172
public override CraftResource DefaultResource => CraftResource.RegularLeather;
6273

63-
[EncodedInt]
64-
[SerializableProperty(0)]
65-
[CommandProperty(AccessLevel.GameMaster)]
66-
public int CurArcaneCharges
67-
{
68-
get => _curArcaneCharges;
69-
set
70-
{
71-
_curArcaneCharges = value;
72-
InvalidateProperties();
73-
Update();
74-
this.MarkDirty();
75-
}
76-
}
77-
7874
[EncodedInt]
7975
[SerializableProperty(1)]
8076
[CommandProperty(AccessLevel.GameMaster)]

Projects/UOContent/UOContent.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
<PackageReference Include="ModernUO.CodeGeneratedEvents.Generator" Version="1.0.3.2" PrivateAssets="all" />
4848
<PackageReference Include="Zstd.Binaries" Version="1.6.0" />
4949

50-
<PackageReference Include="ModernUO.Serialization.Annotations" Version="2.14.0" />
51-
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.14.1" />
50+
<PackageReference Include="ModernUO.Serialization.Annotations" Version="2.14.2" />
51+
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.14.2" />
5252
</ItemGroup>
5353
<ItemGroup>
5454
<AdditionalFiles Include="Migrations/*.v*.json" />

0 commit comments

Comments
 (0)