fix(codegen): Fixes bulk order deed hue and codegens (#647)
- [X] Codegens some Bulk Order stuff - [X] Fixes deserializing with a class that requires the parent as a constructor argument Closes #641 Closes #623
This commit is contained in:
parent
eb4e3ac070
commit
510d2e006b
32 changed files with 185 additions and 378 deletions
|
|
@ -203,7 +203,8 @@ namespace SerializationGenerator
|
|||
fieldOrPropertySymbol,
|
||||
order,
|
||||
allAttributes,
|
||||
serializableTypes
|
||||
serializableTypes,
|
||||
classSymbol
|
||||
);
|
||||
|
||||
serializablePropertySet.Add(serializableProperty);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ namespace SerializableMigration
|
|||
ISymbol symbol,
|
||||
ImmutableArray<AttributeData> attributes,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes,
|
||||
ISymbol? parentSymbol,
|
||||
out string[] ruleArguments
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ namespace SerializableMigration
|
|||
ISymbol symbol,
|
||||
ImmutableArray<AttributeData> attributes,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes,
|
||||
ISymbol? parentSymbol,
|
||||
out string[] ruleArguments
|
||||
)
|
||||
{
|
||||
|
|
@ -44,7 +45,8 @@ namespace SerializableMigration
|
|||
arrayTypeSymbol.ElementType,
|
||||
0,
|
||||
attributes,
|
||||
serializableTypes
|
||||
serializableTypes,
|
||||
parentSymbol
|
||||
);
|
||||
|
||||
var length = serializableArrayType.RuleArguments.Length;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ namespace SerializableMigration
|
|||
ISymbol symbol,
|
||||
ImmutableArray<AttributeData> attributes,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes,
|
||||
ISymbol? parentSymbol,
|
||||
out string[] ruleArguments
|
||||
)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ namespace SerializableMigration
|
|||
ISymbol symbol,
|
||||
ImmutableArray<AttributeData> attributes,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes,
|
||||
ISymbol? parentSymbol,
|
||||
out string[] ruleArguments
|
||||
)
|
||||
{
|
||||
|
|
@ -47,7 +48,8 @@ namespace SerializableMigration
|
|||
setTypeSymbol,
|
||||
0,
|
||||
attributes,
|
||||
serializableTypes
|
||||
serializableTypes,
|
||||
parentSymbol
|
||||
);
|
||||
|
||||
var length = serializableSetType.RuleArguments.Length;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ namespace SerializableMigration
|
|||
ISymbol symbol,
|
||||
ImmutableArray<AttributeData> attributes,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes,
|
||||
ISymbol? parentSymbol,
|
||||
out string[] ruleArguments
|
||||
)
|
||||
{
|
||||
|
|
@ -47,7 +48,8 @@ namespace SerializableMigration
|
|||
typeArguments[0],
|
||||
0,
|
||||
attributes,
|
||||
serializableTypes
|
||||
serializableTypes,
|
||||
parentSymbol
|
||||
);
|
||||
|
||||
var valueSerializedProperty = SerializableMigrationRulesEngine.GenerateSerializableProperty(
|
||||
|
|
@ -56,7 +58,8 @@ namespace SerializableMigration
|
|||
typeArguments[1],
|
||||
1,
|
||||
attributes,
|
||||
serializableTypes
|
||||
serializableTypes,
|
||||
parentSymbol
|
||||
);
|
||||
|
||||
// Key
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ namespace SerializableMigration
|
|||
ISymbol symbol,
|
||||
ImmutableArray<AttributeData> attributes,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes,
|
||||
ISymbol? parentSymbol,
|
||||
out string[] ruleArguments
|
||||
)
|
||||
{
|
||||
|
|
@ -47,7 +48,8 @@ namespace SerializableMigration
|
|||
listTypeSymbol,
|
||||
0,
|
||||
attributes,
|
||||
serializableTypes
|
||||
serializableTypes,
|
||||
parentSymbol
|
||||
);
|
||||
|
||||
var length = serializableListType.RuleArguments.Length;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ namespace SerializableMigration
|
|||
ISymbol symbol,
|
||||
ImmutableArray<AttributeData> attributes,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes,
|
||||
ISymbol? parentSymbol,
|
||||
out string[] ruleArguments
|
||||
)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ namespace SerializableMigration
|
|||
ISymbol symbol,
|
||||
ImmutableArray<AttributeData> attributes,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes,
|
||||
ISymbol? parentSymbol,
|
||||
out string[] ruleArguments
|
||||
)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ namespace SerializableMigration
|
|||
ISymbol symbol,
|
||||
ImmutableArray<AttributeData> attributes,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes,
|
||||
ISymbol? parentSymbol,
|
||||
out string[] ruleArguments
|
||||
)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ namespace SerializableMigration
|
|||
ISymbol symbol,
|
||||
ImmutableArray<AttributeData> attributes,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes,
|
||||
ISymbol? parentSymbol,
|
||||
out string[] ruleArguments
|
||||
)
|
||||
{
|
||||
|
|
@ -41,7 +42,7 @@ namespace SerializableMigration
|
|||
}
|
||||
|
||||
if (symbol is not INamedTypeSymbol namedTypeSymbol ||
|
||||
!namedTypeSymbol.HasGenericReaderCtor(compilation, out var requiresParent))
|
||||
!namedTypeSymbol.HasGenericReaderCtor(compilation, parentSymbol, out var requiresParent))
|
||||
{
|
||||
ruleArguments = null;
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ namespace SerializableMigration
|
|||
ISymbol fieldOrPropertySymbol,
|
||||
int order,
|
||||
ImmutableArray<AttributeData> attributes,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes,
|
||||
ISymbol? parentSymbol = default
|
||||
)
|
||||
{
|
||||
string propertyName;
|
||||
|
|
@ -78,7 +79,8 @@ namespace SerializableMigration
|
|||
propertyType,
|
||||
order,
|
||||
attributes,
|
||||
serializableTypes
|
||||
serializableTypes,
|
||||
parentSymbol
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +90,8 @@ namespace SerializableMigration
|
|||
ISymbol propertyType,
|
||||
int order,
|
||||
ImmutableArray<AttributeData> attributes,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes,
|
||||
ISymbol? parentSymbol = default
|
||||
)
|
||||
{
|
||||
foreach (var rule in Rules.Values)
|
||||
|
|
@ -98,6 +101,7 @@ namespace SerializableMigration
|
|||
propertyType,
|
||||
attributes,
|
||||
serializableTypes,
|
||||
parentSymbol,
|
||||
out var ruleArguments
|
||||
))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
|
@ -66,7 +67,12 @@ namespace SerializationGenerator
|
|||
symbol is INamedTypeSymbol namedSymbol &&
|
||||
symbols.Contains(namedSymbol, SymbolEqualityComparer.Default);
|
||||
|
||||
public static bool HasGenericReaderCtor(this INamedTypeSymbol symbol, Compilation compilation, out bool requiresParent)
|
||||
public static bool HasGenericReaderCtor(
|
||||
this INamedTypeSymbol symbol,
|
||||
Compilation compilation,
|
||||
ISymbol? parentSymbol,
|
||||
out bool requiresParent
|
||||
)
|
||||
{
|
||||
var genericReaderInterface = compilation.GetTypeByMetadataName(GENERIC_READER_INTERFACE);
|
||||
var genericCtor = symbol.Constructors.FirstOrDefault(
|
||||
|
|
@ -76,7 +82,7 @@ namespace SerializationGenerator
|
|||
SymbolEqualityComparer.Default.Equals(m.Parameters[0].Type, genericReaderInterface)
|
||||
);
|
||||
|
||||
requiresParent = genericCtor?.Parameters.Length == 2 && SymbolEqualityComparer.Default.Equals(genericCtor.Parameters[1].Type, symbol);
|
||||
requiresParent = genericCtor?.Parameters.Length == 2 && SymbolEqualityComparer.Default.Equals(genericCtor.Parameters[1].Type, parentSymbol);
|
||||
return genericCtor != null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,6 @@ namespace SerializationSchemaGenerator
|
|||
ReadCommentHandling = JsonCommentHandling.Skip
|
||||
};
|
||||
|
||||
// var generatedSourcePath = Path.Join(projectPath, "Generated");
|
||||
|
||||
var serializableTypes = syntaxReceiver.SerializableList;
|
||||
|
||||
foreach (var (classSymbol, (attributeData, fieldsList)) in syntaxReceiver.ClassAndFields)
|
||||
|
|
@ -80,18 +78,9 @@ namespace SerializationSchemaGenerator
|
|||
fieldsList.ToImmutableArray(),
|
||||
serializableTypes
|
||||
);
|
||||
|
||||
// WriteSource(generatedSourcePath, classSymbol.ToDisplayString(), source);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void WriteSource(string sourcePath, string className, string source)
|
||||
{
|
||||
Directory.CreateDirectory(sourcePath);
|
||||
var filePath = Path.Combine(sourcePath, $"{className}.Serialization.cs");
|
||||
File.WriteAllText(filePath, source, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,98 +0,0 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2021 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: SchemaGenerator.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 <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using SerializableMigration;
|
||||
using SerializationGenerator;
|
||||
|
||||
namespace SerializationSchemaGenerator
|
||||
{
|
||||
public static class SchemaGenerator
|
||||
{
|
||||
public static void GenerateSchema(
|
||||
this Compilation compilation,
|
||||
INamedTypeSymbol classSymbol,
|
||||
AttributeData serializableAttr,
|
||||
ImmutableArray<ISymbol> fieldsAndProperties,
|
||||
string migrationPath,
|
||||
JsonSerializerOptions jsonSerializerOptions,
|
||||
ImmutableArray<INamedTypeSymbol> serializableTypes
|
||||
)
|
||||
{
|
||||
var serializableFieldAttribute =
|
||||
compilation.GetTypeByMetadataName(SymbolMetadata.SERIALIZABLE_FIELD_ATTRIBUTE);
|
||||
|
||||
var version = (int)serializableAttr.ConstructorArguments[0].Value!;
|
||||
|
||||
var serializablePropertySet = new SortedSet<SerializableProperty>(new SerializablePropertyComparer());
|
||||
|
||||
foreach (var fieldOrPropertySymbol in fieldsAndProperties)
|
||||
{
|
||||
var allAttributes = fieldOrPropertySymbol.GetAttributes();
|
||||
|
||||
var serializableFieldAttr = allAttributes
|
||||
.FirstOrDefault(
|
||||
attr =>
|
||||
SymbolEqualityComparer.Default.Equals(attr.AttributeClass, serializableFieldAttribute)
|
||||
);
|
||||
|
||||
if (serializableFieldAttr == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var order = (int)serializableFieldAttr.ConstructorArguments[0].Value!;
|
||||
|
||||
var serializableProperty = SerializableMigrationRulesEngine.GenerateSerializableProperty(
|
||||
compilation,
|
||||
fieldOrPropertySymbol,
|
||||
order,
|
||||
allAttributes,
|
||||
serializableTypes
|
||||
);
|
||||
|
||||
if (serializableProperty == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
serializablePropertySet.Add(serializableProperty);
|
||||
}
|
||||
|
||||
var serializableProperties = serializablePropertySet.ToImmutableArray();
|
||||
|
||||
// Write the migration file
|
||||
var newMigration = new SerializableMetadata
|
||||
{
|
||||
Version = version,
|
||||
Type = classSymbol.ToDisplayString(),
|
||||
Properties = serializableProperties
|
||||
};
|
||||
WriteMigration(migrationPath, newMigration, jsonSerializerOptions);
|
||||
}
|
||||
|
||||
public static void WriteMigration(string migrationPath, SerializableMetadata metadata, JsonSerializerOptions options)
|
||||
{
|
||||
Directory.CreateDirectory(migrationPath);
|
||||
var filePath = Path.Combine(migrationPath, $"{metadata.Type}.v{metadata.Version}.json");
|
||||
File.WriteAllText(filePath, JsonSerializer.Serialize(metadata, options));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -384,6 +384,8 @@ namespace Server.Accounting
|
|||
}
|
||||
|
||||
_totalGameTime = reader.ReadTimeSpan();
|
||||
|
||||
Timer.DelayCall(AfterDeserialization);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -2,18 +2,15 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Server.Engines.BulkOrders
|
||||
{
|
||||
public abstract class BaseBOD : Item
|
||||
[Serializable(1)]
|
||||
public abstract partial class BaseBOD : Item
|
||||
{
|
||||
private int m_AmountMax;
|
||||
private BulkMaterialType m_Material;
|
||||
private bool m_RequireExceptional;
|
||||
|
||||
public BaseBOD(int hue, int amountMax, bool requireExeptional, BulkMaterialType material) : this()
|
||||
{
|
||||
Hue = hue;
|
||||
AmountMax = amountMax;
|
||||
RequireExceptional = requireExeptional;
|
||||
Material = material;
|
||||
_amountMax = amountMax;
|
||||
_requireExceptional = requireExeptional;
|
||||
_material = material;
|
||||
}
|
||||
|
||||
public BaseBOD() : base(Core.AOS ? 0x2258 : 0x14EF)
|
||||
|
|
@ -22,47 +19,22 @@ namespace Server.Engines.BulkOrders
|
|||
LootType = LootType.Blessed;
|
||||
}
|
||||
|
||||
public BaseBOD(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public abstract bool Complete { get; }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public sealed override int Hue { get; set; }
|
||||
[SerializableField(0)]
|
||||
[InvalidateProperties]
|
||||
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
||||
private int _amountMax;
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int AmountMax
|
||||
{
|
||||
get => m_AmountMax;
|
||||
set
|
||||
{
|
||||
m_AmountMax = value;
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
[SerializableField(1)]
|
||||
[InvalidateProperties]
|
||||
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
||||
private bool _requireExceptional;
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool RequireExceptional
|
||||
{
|
||||
get => m_RequireExceptional;
|
||||
set
|
||||
{
|
||||
m_RequireExceptional = value;
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public BulkMaterialType Material
|
||||
{
|
||||
get => m_Material;
|
||||
set
|
||||
{
|
||||
m_Material = value;
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
[SerializableField(1)]
|
||||
[InvalidateProperties]
|
||||
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
||||
private BulkMaterialType _material;
|
||||
|
||||
public static BulkMaterialType GetRandomMaterial(BulkMaterialType start, double[] chances)
|
||||
{
|
||||
|
|
@ -141,38 +113,22 @@ namespace Server.Engines.BulkOrders
|
|||
}
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
[AfterDeserialization]
|
||||
private void AfterDeserialization()
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.WriteEncodedInt(0); // version
|
||||
|
||||
writer.Write(m_AmountMax);
|
||||
writer.Write(m_RequireExceptional);
|
||||
writer.Write((int)m_Material);
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
var version = reader.ReadEncodedInt();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
m_AmountMax = reader.ReadInt();
|
||||
m_RequireExceptional = reader.ReadBool();
|
||||
m_Material = (BulkMaterialType)reader.ReadInt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Parent == null && Map == Map.Internal && Location == Point3D.Zero)
|
||||
{
|
||||
Delete();
|
||||
}
|
||||
}
|
||||
|
||||
private void Deserialize(IGenericReader reader, int version)
|
||||
{
|
||||
AmountMax = reader.ReadInt();
|
||||
RequireExceptional = reader.ReadBool();
|
||||
Material = (BulkMaterialType)reader.ReadInt();
|
||||
|
||||
Timer.DelayCall(AfterDeserialization);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,12 @@ namespace Server.Engines.BulkOrders
|
|||
{
|
||||
RequireExceptional = bod.RequireExceptional;
|
||||
|
||||
if (bod is LargeTailorBOD)
|
||||
DeedType = bod switch
|
||||
{
|
||||
DeedType = BODType.Tailor;
|
||||
}
|
||||
else if (bod is LargeSmithBOD)
|
||||
{
|
||||
DeedType = BODType.Smith;
|
||||
}
|
||||
LargeTailorBOD => BODType.Tailor,
|
||||
LargeSmithBOD => BODType.Smith,
|
||||
_ => DeedType
|
||||
};
|
||||
|
||||
Material = bod.Material;
|
||||
AmountMax = bod.AmountMax;
|
||||
|
|
@ -68,16 +66,12 @@ namespace Server.Engines.BulkOrders
|
|||
|
||||
public Item Reconstruct()
|
||||
{
|
||||
LargeBOD bod = null;
|
||||
|
||||
if (DeedType == BODType.Smith)
|
||||
LargeBOD bod = DeedType switch
|
||||
{
|
||||
bod = new LargeSmithBOD(AmountMax, RequireExceptional, Material, ReconstructEntries());
|
||||
}
|
||||
else if (DeedType == BODType.Tailor)
|
||||
{
|
||||
bod = new LargeTailorBOD(AmountMax, RequireExceptional, Material, ReconstructEntries());
|
||||
}
|
||||
BODType.Smith => new LargeSmithBOD(AmountMax, RequireExceptional, Material, ReconstructEntries()),
|
||||
BODType.Tailor => new LargeTailorBOD(AmountMax, RequireExceptional, Material, ReconstructEntries()),
|
||||
_ => null
|
||||
};
|
||||
|
||||
for (var i = 0; bod?.Entries.Length >= i; ++i)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,41 +2,30 @@ using Server.Mobiles;
|
|||
|
||||
namespace Server.Engines.BulkOrders
|
||||
{
|
||||
public abstract class LargeBOD : BaseBOD
|
||||
[Serializable(0)]
|
||||
public abstract partial class LargeBOD : BaseBOD
|
||||
{
|
||||
private LargeBulkEntry[] m_Entries;
|
||||
[InvalidateProperties]
|
||||
[SerializableField(0)]
|
||||
private LargeBulkEntry[] _entries;
|
||||
|
||||
public LargeBOD(
|
||||
int hue, int amountMax, bool requireExeptional, BulkMaterialType material, LargeBulkEntry[] entries
|
||||
) : base(hue, amountMax, requireExeptional, material) =>
|
||||
m_Entries = entries;
|
||||
_entries = entries;
|
||||
|
||||
public LargeBOD()
|
||||
{
|
||||
}
|
||||
|
||||
public LargeBOD(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public LargeBulkEntry[] Entries
|
||||
{
|
||||
get => m_Entries;
|
||||
set
|
||||
{
|
||||
m_Entries = value;
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public override bool Complete
|
||||
{
|
||||
get
|
||||
{
|
||||
for (var i = 0; i < m_Entries.Length; ++i)
|
||||
for (var i = 0; i < _entries.Length; ++i)
|
||||
{
|
||||
if (m_Entries[i].Amount < AmountMax)
|
||||
if (_entries[i].Amount < AmountMax)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -66,9 +55,9 @@ namespace Server.Engines.BulkOrders
|
|||
|
||||
list.Add(1060656, AmountMax.ToString()); // amount to make: ~1_val~
|
||||
|
||||
for (var i = 0; i < m_Entries.Length; ++i)
|
||||
for (var i = 0; i < _entries.Length; ++i)
|
||||
{
|
||||
list.Add(1060658 + i, "#{0}\t{1}", m_Entries[i].Details.Number, m_Entries[i].Amount); // ~1_val~: ~2_val~
|
||||
list.Add(1060658 + i, "#{0}\t{1}", _entries[i].Details.Number, _entries[i].Amount); // ~1_val~: ~2_val~
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +85,7 @@ namespace Server.Engines.BulkOrders
|
|||
|
||||
public override void EndCombine(Mobile from, Item item)
|
||||
{
|
||||
if (!(item is SmallBOD small))
|
||||
if (item is not SmallBOD small)
|
||||
{
|
||||
from.SendLocalizedMessage(1045159); // That is not a bulk order.
|
||||
return;
|
||||
|
|
@ -104,11 +93,11 @@ namespace Server.Engines.BulkOrders
|
|||
|
||||
LargeBulkEntry entry = null;
|
||||
|
||||
for (var i = 0; i < m_Entries.Length; ++i)
|
||||
for (var i = 0; i < _entries.Length; ++i)
|
||||
{
|
||||
if (m_Entries[i].Details.Type == small.Type)
|
||||
if (_entries[i].Details.Type == small.Type)
|
||||
{
|
||||
entry = m_Entries[i];
|
||||
entry = _entries[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -159,41 +148,5 @@ namespace Server.Engines.BulkOrders
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.WriteEncodedInt(0); // version
|
||||
|
||||
writer.Write(m_Entries.Length);
|
||||
|
||||
for (var i = 0; i < m_Entries.Length; ++i)
|
||||
{
|
||||
m_Entries[i].Serialize(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
var version = reader.ReadEncodedInt();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
m_Entries = new LargeBulkEntry[reader.ReadInt()];
|
||||
|
||||
for (var i = 0; i < m_Entries.Length; ++i)
|
||||
{
|
||||
m_Entries[i] = new LargeBulkEntry(this, reader);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace Server.Engines.BulkOrders
|
|||
Details = details;
|
||||
}
|
||||
|
||||
public LargeBulkEntry(LargeBOD owner, IGenericReader reader)
|
||||
public LargeBulkEntry(IGenericReader reader, LargeBOD owner)
|
||||
{
|
||||
Owner = owner;
|
||||
m_Amount = reader.ReadInt();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
namespace Server.Engines.BulkOrders
|
||||
{
|
||||
public class LargeSmithBOD : LargeBOD
|
||||
[Serializable(0, false)]
|
||||
public partial class LargeSmithBOD : LargeBOD
|
||||
{
|
||||
public static double[] m_BlacksmithMaterialChances =
|
||||
{
|
||||
|
|
@ -61,29 +62,11 @@ namespace Server.Engines.BulkOrders
|
|||
{
|
||||
}
|
||||
|
||||
public LargeSmithBOD(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override int ComputeFame() => SmithRewardCalculator.Instance.ComputeFame(this);
|
||||
|
||||
public override int ComputeGold() => SmithRewardCalculator.Instance.ComputeGold(this);
|
||||
|
||||
public override RewardGroup GetRewardGroup() =>
|
||||
SmithRewardCalculator.Instance.LookupRewards(SmithRewardCalculator.Instance.ComputePoints(this));
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.Write(0); // version
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
var version = reader.ReadInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
namespace Server.Engines.BulkOrders
|
||||
{
|
||||
public class LargeTailorBOD : LargeBOD
|
||||
[Serializable(0, false)]
|
||||
public partial class LargeTailorBOD : LargeBOD
|
||||
{
|
||||
public static double[] m_TailoringMaterialChances =
|
||||
{
|
||||
|
|
@ -87,29 +88,11 @@ namespace Server.Engines.BulkOrders
|
|||
{
|
||||
}
|
||||
|
||||
public LargeTailorBOD(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override int ComputeFame() => TailorRewardCalculator.Instance.ComputeFame(this);
|
||||
|
||||
public override int ComputeGold() => TailorRewardCalculator.Instance.ComputeGold(this);
|
||||
|
||||
public override RewardGroup GetRewardGroup() =>
|
||||
TailorRewardCalculator.Instance.LookupRewards(TailorRewardCalculator.Instance.ComputePoints(this));
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.Write(0); // version
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
var version = reader.ReadInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ using Server.Engines.Craft;
|
|||
|
||||
namespace Server.Engines.BulkOrders
|
||||
{
|
||||
public class SmallSmithBOD : SmallBOD
|
||||
[Serializable(0, false)]
|
||||
public partial class SmallSmithBOD : SmallBOD
|
||||
{
|
||||
public static double[] m_BlacksmithMaterialChances =
|
||||
{
|
||||
|
|
@ -63,10 +64,6 @@ namespace Server.Engines.BulkOrders
|
|||
{
|
||||
}
|
||||
|
||||
public SmallSmithBOD(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override int ComputeFame() => SmithRewardCalculator.Instance.ComputeFame(this);
|
||||
|
||||
public override int ComputeGold() => SmithRewardCalculator.Instance.ComputeGold(this);
|
||||
|
|
@ -165,19 +162,5 @@ namespace Server.Engines.BulkOrders
|
|||
var entry = validEntries.RandomElement();
|
||||
return new SmallSmithBOD(entry, material, amountMax, reqExceptional);
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.Write(0); // version
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
var version = reader.ReadInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ using Server.Engines.Craft;
|
|||
|
||||
namespace Server.Engines.BulkOrders
|
||||
{
|
||||
public class SmallTailorBOD : SmallBOD
|
||||
[Serializable(0, false)]
|
||||
public partial class SmallTailorBOD : SmallBOD
|
||||
{
|
||||
public static double[] m_TailoringMaterialChances =
|
||||
{
|
||||
|
|
@ -30,7 +31,6 @@ namespace Server.Engines.BulkOrders
|
|||
return;
|
||||
}
|
||||
|
||||
var hue = 0x483;
|
||||
var amountMax = Utility.RandomList(10, 15, 20);
|
||||
|
||||
var material = useMaterials
|
||||
|
|
@ -40,7 +40,7 @@ namespace Server.Engines.BulkOrders
|
|||
var reqExceptional = Utility.RandomBool() || material == BulkMaterialType.None;
|
||||
var entry = entries.RandomElement();
|
||||
|
||||
Hue = hue;
|
||||
Hue = 0x483;
|
||||
AmountMax = amountMax;
|
||||
Type = entry.Type;
|
||||
Number = entry.Number;
|
||||
|
|
@ -56,10 +56,6 @@ namespace Server.Engines.BulkOrders
|
|||
{
|
||||
}
|
||||
|
||||
public SmallTailorBOD(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override int ComputeFame() => TailorRewardCalculator.Instance.ComputeFame(this);
|
||||
|
||||
public override int ComputeGold() => TailorRewardCalculator.Instance.ComputeGold(this);
|
||||
|
|
@ -168,19 +164,5 @@ namespace Server.Engines.BulkOrders
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.Write(0); // version
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
var version = reader.ReadInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ namespace Server.Items
|
|||
bool CouldFit(IPoint3D p, Map map);
|
||||
}
|
||||
|
||||
public abstract class BaseAddon : Item, IChoppable, IAddon
|
||||
[Serializable(2, false)]
|
||||
public abstract partial class BaseAddon : Item, IChoppable, IAddon
|
||||
{
|
||||
private CraftResource m_Resource;
|
||||
|
||||
|
|
@ -32,15 +33,12 @@ namespace Server.Items
|
|||
Components = new List<AddonComponent>();
|
||||
}
|
||||
|
||||
public BaseAddon(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual bool RetainDeedHue => false;
|
||||
|
||||
public virtual BaseAddonDeed Deed => null;
|
||||
|
||||
public List<AddonComponent> Components { get; private set; }
|
||||
[SerializableField(0, setter: "private")]
|
||||
private List<AddonComponent> _components;
|
||||
|
||||
public virtual bool ShareHue => true;
|
||||
|
||||
|
|
@ -66,6 +64,7 @@ namespace Server.Items
|
|||
}
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
[SerializableField(1)]
|
||||
public CraftResource Resource
|
||||
{
|
||||
get => m_Resource;
|
||||
|
|
@ -77,6 +76,7 @@ namespace Server.Items
|
|||
Hue = CraftResources.GetHue(m_Resource);
|
||||
|
||||
InvalidateProperties();
|
||||
((ISerializable)this).MarkDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -277,30 +277,9 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
private void Deserialize(IGenericReader reader, int version)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.Write(1); // version
|
||||
|
||||
writer.Write(Components);
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
var version = reader.ReadInt();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 1:
|
||||
case 0:
|
||||
{
|
||||
Components = reader.ReadEntityList<AddonComponent>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
Components = reader.ReadEntityList<AddonComponent>();
|
||||
|
||||
if (version < 1 && Weight == 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"version": 1,
|
||||
"type": "Server.Engines.BulkOrders.BaseBOD",
|
||||
"properties": [
|
||||
{
|
||||
"name": "AmountMax",
|
||||
"type": "int",
|
||||
"rule": "PrimitiveTypeMigrationRule",
|
||||
"ruleArguments": []
|
||||
},
|
||||
{
|
||||
"name": "RequireExceptional",
|
||||
"type": "bool",
|
||||
"rule": "PrimitiveTypeMigrationRule",
|
||||
"ruleArguments": []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"version": 0,
|
||||
"type": "Server.Engines.BulkOrders.LargeBOD",
|
||||
"properties": [
|
||||
{
|
||||
"name": "Entries",
|
||||
"type": "Server.Engines.BulkOrders.LargeBulkEntry[]",
|
||||
"rule": "ArrayMigrationRule",
|
||||
"ruleArguments": [
|
||||
"Server.Engines.BulkOrders.LargeBulkEntry",
|
||||
"SerializationMethodSignatureMigrationRule",
|
||||
"DeserializationRequiresParent"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"version": 0,
|
||||
"type": "Server.Engines.BulkOrders.LargeSmithBOD",
|
||||
"properties": []
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"version": 0,
|
||||
"type": "Server.Engines.BulkOrders.LargeTailorBOD",
|
||||
"properties": []
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"version": 0,
|
||||
"type": "Server.Engines.BulkOrders.SmallSmithBOD",
|
||||
"properties": []
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"version": 0,
|
||||
"type": "Server.Engines.BulkOrders.SmallTailorBOD",
|
||||
"properties": []
|
||||
}
|
||||
21
Projects/UOContent/Migrations/Server.Items.BaseAddon.v2.json
Normal file
21
Projects/UOContent/Migrations/Server.Items.BaseAddon.v2.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"version": 2,
|
||||
"type": "Server.Items.BaseAddon",
|
||||
"properties": [
|
||||
{
|
||||
"name": "Components",
|
||||
"type": "System.Collections.Generic.List\u003CServer.Items.AddonComponent\u003E",
|
||||
"rule": "ListMigrationRule",
|
||||
"ruleArguments": [
|
||||
"Server.Items.AddonComponent",
|
||||
"SerializableInterfaceMigrationRule"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Resource",
|
||||
"type": "Server.Items.CraftResource",
|
||||
"rule": "EnumMigrationRule",
|
||||
"ruleArguments": []
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue