### Summary - Fixes issues with non-_ISerializable_ objects having bad serialization (Skill/Stat. Mods) - Fixes issues with MarkDirty and namespaces: https://github.com/modernuo/SerializationGenerator/issues/29 - Fixes missing dirty tracking for some data structures. - Fixes cascading MarkDirty for non-serializable types that have owners that are also non-serializable types. ### New Codegenned API When a data structure (Array, List, Dictionary, HashSet, etc) is source generated for serialization, new methods are added which will handle dirty tracking. Use these instead of the built in methods for that data structure. _All Data Structures_ ```cs public void Clear<PropertyName>(); ``` _Lists and Sets_ ```cs public void AddTo<PropertyName>(V value); public void RemoveFrom<PropertyName>(V value); ``` _Lists_ ```cs public void InsertInto<PropertyName>(int index, V value); public void RemoveFrom<PropertyName>At(int index); ``` _Dictionaries_ ```cs public void AddTo<PropertyName>(T key, V value); public void RemoveFrom<PropertyName>(T key); public void ReplaceIn<PropertyName>(T key, V value); ``` Over time, they will be cleaned up and more variants added such as `bool RemoveFrom<PropertyName>(T key, out V value)`
204 lines
5.5 KiB
C#
204 lines
5.5 KiB
C#
using System;
|
|
using ModernUO.Serialization;
|
|
|
|
namespace Server.Items;
|
|
|
|
[SerializationGenerator(1, false)]
|
|
public partial class MiniHouseAddon : BaseAddon
|
|
{
|
|
[Constructible]
|
|
public MiniHouseAddon(MiniHouseType type = MiniHouseType.StoneAndPlaster)
|
|
{
|
|
_type = type;
|
|
|
|
Construct();
|
|
}
|
|
|
|
[CommandProperty(AccessLevel.GameMaster)]
|
|
[SerializableProperty(0)]
|
|
public MiniHouseType Type
|
|
{
|
|
get => _type;
|
|
set
|
|
{
|
|
_type = value;
|
|
Construct();
|
|
this.MarkDirty();
|
|
}
|
|
}
|
|
|
|
public override BaseAddonDeed Deed => new MiniHouseDeed(_type);
|
|
|
|
public void Construct()
|
|
{
|
|
foreach (var c in Components)
|
|
{
|
|
c.Addon = null;
|
|
c.Delete();
|
|
}
|
|
|
|
ClearComponents();
|
|
|
|
var info = MiniHouseInfo.GetInfo(_type);
|
|
|
|
var size = (int)Math.Sqrt(info.Graphics.Length);
|
|
var num = 0;
|
|
|
|
for (var y = 0; y < size; ++y)
|
|
{
|
|
for (var x = 0; x < size; ++x)
|
|
{
|
|
if (info.Graphics[num] != 0x1) // Veteran Rewards Mod
|
|
{
|
|
AddComponent(new AddonComponent(info.Graphics[num++]), size - x - 1, size - y - 1, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Deserialize(IGenericReader reader, int version)
|
|
{
|
|
_type = (MiniHouseType)reader.ReadInt();
|
|
}
|
|
}
|
|
|
|
[SerializationGenerator(1, false)]
|
|
public partial class MiniHouseDeed : BaseAddonDeed
|
|
{
|
|
[InvalidateProperties]
|
|
[SerializableField(0)]
|
|
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
|
private MiniHouseType _type;
|
|
|
|
[Constructible]
|
|
public MiniHouseDeed(MiniHouseType type = MiniHouseType.StoneAndPlaster)
|
|
{
|
|
_type = type;
|
|
|
|
Weight = 1.0;
|
|
LootType = LootType.Blessed;
|
|
}
|
|
|
|
public override BaseAddon Addon => new MiniHouseAddon(_type);
|
|
public override int LabelNumber => 1062096; // a mini house deed
|
|
|
|
public override void GetProperties(IPropertyList list)
|
|
{
|
|
base.GetProperties(list);
|
|
|
|
list.Add(MiniHouseInfo.GetInfo(_type).LabelNumber);
|
|
}
|
|
|
|
private void Deserialize(IGenericReader reader, int version)
|
|
{
|
|
_type = (MiniHouseType)reader.ReadInt();
|
|
}
|
|
}
|
|
|
|
public enum MiniHouseType
|
|
{
|
|
StoneAndPlaster,
|
|
FieldStone,
|
|
SmallBrick,
|
|
Wooden,
|
|
WoodAndPlaster,
|
|
ThatchedRoof,
|
|
Brick,
|
|
TwoStoryWoodAndPlaster,
|
|
TwoStoryStoneAndPlaster,
|
|
Tower,
|
|
SmallStoneKeep,
|
|
Castle,
|
|
LargeHouseWithPatio,
|
|
MarbleHouseWithPatio,
|
|
SmallStoneTower,
|
|
TwoStoryLogCabin,
|
|
TwoStoryVilla,
|
|
SandstoneHouseWithPatio,
|
|
SmallStoneWorkshop,
|
|
SmallMarbleWorkshop,
|
|
MalasMountainPass, // Veteran reward house
|
|
ChurchAtNight // Veteran reward house
|
|
}
|
|
|
|
public class MiniHouseInfo
|
|
{
|
|
private static readonly MiniHouseInfo[] m_Info =
|
|
{
|
|
/* Stone and plaster house */ new(0x22C4, 1, 1011303),
|
|
/* Field stone house */ new(0x22DE, 1, 1011304),
|
|
/* Small brick house */ new(0x22DF, 1, 1011305),
|
|
/* Wooden house */ new(0x22C9, 1, 1011306),
|
|
/* Wood and plaster house */ new(0x22E0, 1, 1011307),
|
|
/* Thatched-roof cottage */ new(0x22E1, 1, 1011308),
|
|
/* Brick house */ new(1011309, 0x22CD, 0x22CB, 0x22CC, 0x22CA),
|
|
/* Two-story wood and plaster house */ new(1011310, 0x2301, 0x2302, 0x2304, 0x2303),
|
|
/* Two-story stone and plaster house */ new(1011311, 0x22FC, 0x22FD, 0x22FF, 0x22FE),
|
|
/* Tower */ new(1011312, 0x22F7, 0x22F8, 0x22FA, 0x22F9),
|
|
/* Small stone keep */ new(0x22E6, 9, 1011313),
|
|
/* Castle */
|
|
new(
|
|
1011314,
|
|
0x22CE,
|
|
0x22D0,
|
|
0x22D2,
|
|
0x22D7,
|
|
0x22CF,
|
|
0x22D1,
|
|
0x22D4,
|
|
0x22D9,
|
|
0x22D3,
|
|
0x22D5,
|
|
0x22D6,
|
|
0x22DB,
|
|
0x22D8,
|
|
0x22DA,
|
|
0x22DC,
|
|
0x22DD
|
|
),
|
|
/* Large house with patio */ new(0x22E2, 4, 1011315),
|
|
/* Marble house with patio */ new(0x22EF, 4, 1011316),
|
|
/* Small stone tower */ new(0x22F5, 1, 1011317),
|
|
/* Two-story log cabin */ new(0x22FB, 1, 1011318),
|
|
/* Two-story villa */ new(0x2300, 1, 1011319),
|
|
/* Sandstone house with patio */ new(0x22F3, 1, 1011320),
|
|
/* Small stone workshop */ new(0x22F6, 1, 1011321),
|
|
/* Small marble workshop */ new(0x22F4, 1, 1011322),
|
|
/* Malas Mountain Pass */ new(1062692, 0x2316, 0x2315, 0x2314, 0x2313),
|
|
/* Church At Night */ new(1072215, 0x2318, 0x2317, 0x2319, 0x1)
|
|
};
|
|
|
|
public MiniHouseInfo(int start, int count, int labelNumber)
|
|
{
|
|
Graphics = new int[count];
|
|
|
|
for (var i = 0; i < count; ++i)
|
|
{
|
|
Graphics[i] = start + i;
|
|
}
|
|
|
|
LabelNumber = labelNumber;
|
|
}
|
|
|
|
public MiniHouseInfo(int labelNumber, params int[] graphics)
|
|
{
|
|
LabelNumber = labelNumber;
|
|
Graphics = graphics;
|
|
}
|
|
|
|
public int[] Graphics { get; }
|
|
|
|
public int LabelNumber { get; }
|
|
|
|
public static MiniHouseInfo GetInfo(MiniHouseType type)
|
|
{
|
|
var v = (int)type;
|
|
|
|
if (v < 0 || v >= m_Info.Length)
|
|
{
|
|
v = 0;
|
|
}
|
|
|
|
return m_Info[v];
|
|
}
|
|
}
|