using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using Microsoft.CodeAnalysis; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("DualSwords.Core")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+7b567f59d6531825de4c7a0c772c630fbd264809")] [assembly: AssemblyProduct("DualSwords.Core")] [assembly: AssemblyTitle("DualSwords.Core")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace DualSwords.Core { public static class BalanceRules { private static readonly HashSet NonScalable = new HashSet(StringComparer.Ordinal) { "DyrnwynHiltFragment", "DyrnwynBladeFragment", "DyrnwynTipFragment", "Wishbone", "CryptKey", "DragonTear", "FaderDrop", "Upgrader1Weapon" }; public const float DualAttackForce = 20f; public const float DualBlockForce = 20f; public static int BlockPowerFor(int baseBlockPower) { if (baseBlockPower < 12) { return baseBlockPower + 8; } if (baseBlockPower < 21) { return baseBlockPower + 4; } return baseBlockPower; } public static int SecondaryStaminaFor(int baseSecondaryStamina) { return (int)Math.Round((double)baseSecondaryStamina * 0.8, MidpointRounding.AwayFromZero); } public static float WeightFor(float baseWeight) { return baseWeight * 2f; } public static bool IsScalable(string itemName) { if (string.IsNullOrWhiteSpace(itemName)) { return false; } if (NonScalable.Contains(itemName)) { return false; } if (itemName.StartsWith("Trophy", StringComparison.Ordinal)) { return false; } if (itemName.StartsWith("Upgrader", StringComparison.Ordinal) && itemName.EndsWith("Weapon", StringComparison.Ordinal)) { return false; } return true; } public static IReadOnlyList DoubleRequirements(IReadOnlyList requirements) { return RecipeScaling.Scale(requirements, 2); } } public static class BoneResolver { public const int NotFound = -1; public static int ResolveIndex(IReadOnlyList boneNames, IReadOnlyList jointChain) { if (boneNames == null) { throw new ArgumentNullException("boneNames"); } if (jointChain == null) { throw new ArgumentNullException("jointChain"); } foreach (string item in jointChain) { if (string.IsNullOrEmpty(item)) { continue; } for (int i = 0; i < boneNames.Count; i++) { if (string.Equals(boneNames[i], item, StringComparison.Ordinal)) { return i; } } } return -1; } } public static class BuildOrder { private enum State { Unvisited, InProgress, Done } public static bool Resolve(IReadOnlyList declarations, out IReadOnlyList ordered, out IReadOnlyList errors) { Dictionary dictionary = new Dictionary(); foreach (DualSwordDeclaration declaration in declarations) { dictionary[declaration.Id] = declaration; } string[] catalogueIds = dictionary.Keys.ToArray(); Dictionary state = new Dictionary(); List list = new List(); List list2 = new List(); bool flag = false; foreach (DualSwordDeclaration declaration2 in declarations) { if (!Visit(declaration2, dictionary, (IReadOnlyCollection)(object)catalogueIds, state, list, list2)) { flag = true; } } if (flag) { ordered = new DualSwordDeclaration[0]; errors = list2; return false; } ordered = list; errors = list2; return true; } private static bool Visit(DualSwordDeclaration declaration, IReadOnlyDictionary byId, IReadOnlyCollection catalogueIds, IDictionary state, List result, List errors) { state.TryGetValue(declaration.Id, out var value); switch (value) { case State.Done: return true; case State.InProgress: errors.Add(declaration.Id + ": цикл зависимостей — предмет требует сам себя через цепочку рецептов"); return false; default: state[declaration.Id] = State.InProgress; foreach (string item in DependenciesOf(declaration, catalogueIds)) { if (byId.TryGetValue(item, out var value2) && !Visit(value2, byId, catalogueIds, state, result, errors)) { return false; } } state[declaration.Id] = State.Done; result.Add(declaration); return true; } } public static IReadOnlyList DependenciesOf(DualSwordDeclaration declaration, IReadOnlyCollection catalogueIds) { HashSet hashSet = new HashSet(catalogueIds); HashSet hashSet2 = new HashSet(); List list = new List(); foreach (RequirementSpec item in declaration.DualRecipe?.Requirements ?? new RequirementSpec[0]) { if (item != null && !string.IsNullOrEmpty(item.Item) && hashSet.Contains(item.Item) && hashSet2.Add(item.Item)) { list.Add(item.Item); } } return list; } public static IReadOnlyList Dependents(string failedId, IReadOnlyList declarations) { string[] catalogueIds = declarations.Select((DualSwordDeclaration declaration) => declaration.Id).ToArray(); Dictionary> dictionary = new Dictionary>(); foreach (DualSwordDeclaration declaration in declarations) { foreach (string item in DependenciesOf(declaration, (IReadOnlyCollection)(object)catalogueIds)) { if (!dictionary.TryGetValue(item, out var value)) { value = (dictionary[item] = new List()); } value.Add(declaration.Id); } } List list2 = new List(); HashSet hashSet = new HashSet { failedId }; Queue queue = new Queue(); queue.Enqueue(failedId); while (queue.Count > 0) { string key = queue.Dequeue(); if (!dictionary.TryGetValue(key, out var value2)) { continue; } foreach (string item2 in value2) { if (hashSet.Add(item2)) { list2.Add(item2); queue.Enqueue(item2); } } } return list2; } } public static class ArmorySwords { public static IReadOnlyList All() { return new DualSwordDeclaration[8] { Flint(), Eikthyr(), Abyssal(), EldersBalance(), Bonemass(), ModersGrasp(), Queen(), Fader() }; } private static DualSwordDeclaration Flint() { return new DualSwordDeclaration("VAFlint_SwordDual", "VAFlint_Sword", optional: true, customRecipe: false, null, new StatSnapshot(Damage(15f), Damage(6f), 200, 50, 4, 0.8f, 6, 12, 0), new StatSnapshot(Damage(15f), Damage(6f), 200, 50, 12, 1.6f, 6, 10, 0), new RecipeSpec("piece_workbench", 1, new RequirementSpec[3] { new RequirementSpec("Wood", 2, 0), new RequirementSpec("Flint", 6, 3), new RequirementSpec("LeatherScraps", 0, 2) }), new RecipeSpec("piece_workbench", 1, new RequirementSpec[3] { new RequirementSpec("Wood", 4, 0), new RequirementSpec("Flint", 12, 6), new RequirementSpec("LeatherScraps", 0, 4) }), new LocalizedText("Flint dual swords", "Парные кремнёвые мечи"), new LocalizedText("A pair of flint swords, swung like the berzerkr's axes.", "Пара кремнёвых мечей, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Eikthyr() { return new DualSwordDeclaration("VAAntler_SwordDual", "VAAntler_Sword", optional: true, customRecipe: false, null, new StatSnapshot(Damage(16f, 8f, 0f, 0f, 0f, 6f), Damage(2f, 4f, 0f, 0f, 0f, 5f), 200, 50, 8, 0.8f, 8, 16, 0), new StatSnapshot(Damage(16f, 8f, 0f, 0f, 0f, 6f), Damage(2f, 4f, 0f, 0f, 0f, 5f), 200, 50, 16, 1.6f, 8, 13, 0), new RecipeSpec("piece_workbench", 1, new RequirementSpec[4] { new RequirementSpec("FineWood", 3, 1), new RequirementSpec("Resin", 16, 8), new RequirementSpec("HardAntler", 3, 3), new RequirementSpec("TrophyEikthyr", 1, 1) }), new RecipeSpec("piece_workbench", 1, new RequirementSpec[4] { new RequirementSpec("FineWood", 6, 2), new RequirementSpec("Resin", 32, 16), new RequirementSpec("HardAntler", 6, 6), new RequirementSpec("TrophyEikthyr", 1, 1) }), new LocalizedText("Eikthyr dual swords", "Парные мечи Эйктюра"), new LocalizedText("A pair of Eikthyr swords, swung like the berzerkr's axes.", "Пара мечей Эйктюра, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Abyssal() { return new DualSwordDeclaration("VASwordChitinDual", "VASwordChitin", optional: true, customRecipe: false, null, new StatSnapshot(Damage(25f, 20f), Damage(2f, 4f), 200, 50, 18, 0.8f, 10, 20, 2), new StatSnapshot(Damage(25f, 20f), Damage(2f, 4f), 200, 50, 22, 1.6f, 10, 16, 2), new RecipeSpec("piece_workbench", 1, new RequirementSpec[3] { new RequirementSpec("FineWood", 2, 1), new RequirementSpec("Chitin", 30, 15), new RequirementSpec("DeerHide", 2, 0) }), new RecipeSpec("piece_workbench", 1, new RequirementSpec[3] { new RequirementSpec("FineWood", 4, 2), new RequirementSpec("Chitin", 60, 30), new RequirementSpec("DeerHide", 4, 0) }), new LocalizedText("Abyssal dual swords", "Парные мечи Бездны"), new LocalizedText("A pair of Abyssal swords, swung like the berzerkr's axes.", "Пара мечей Бездны, что рубят как топоры берсерка.")); } private static DualSwordDeclaration EldersBalance() { return new DualSwordDeclaration("VAVine_SwordDual", "VAVine_Sword", optional: true, customRecipe: false, null, new StatSnapshot(Damage(40f, 0f, 0f, 0f, 0f, 0f, 0f, 10f), Damage(6f, 0f, 0f, 0f, 0f, 0f, 0f, 2f), 200, 50, 12, 0.8f, 8, 16, 1), new StatSnapshot(Damage(40f, 0f, 0f, 0f, 0f, 0f, 0f, 10f), Damage(6f, 0f, 0f, 0f, 0f, 0f, 0f, 2f), 200, 50, 16, 1.6f, 8, 13, 1), new RecipeSpec("forge", 1, new RequirementSpec[5] { new RequirementSpec("Bronze", 2, 1), new RequirementSpec("Stone", 16, 8), new RequirementSpec("CryptKey", 1, 0), new RequirementSpec("TrophyTheElder", 1, 0), new RequirementSpec("RoundLog", 0, 4) }), new RecipeSpec("forge", 1, new RequirementSpec[5] { new RequirementSpec("Bronze", 4, 2), new RequirementSpec("Stone", 32, 16), new RequirementSpec("CryptKey", 1, 0), new RequirementSpec("TrophyTheElder", 1, 0), new RequirementSpec("RoundLog", 0, 8) }), new LocalizedText("Elder's Balance dual swords", "Парные мечи Равновесия Старейшины"), new LocalizedText("A pair of Elder's Balance swords, swung like the berzerkr's axes.", "Пара мечей Равновесия Старейшины, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Bonemass() { return new DualSwordDeclaration("VABonemassSwordDual", "VABonemassSword", optional: true, customRecipe: false, null, new StatSnapshot(Damage(65f, 0f, 0f, 0f, 0f, 0f, 20f), Damage(6f, 0f, 0f, 0f, 0f, 0f, 5f), 200, 50, 30, 0.8f, 15, 30, 0), new StatSnapshot(Damage(65f, 0f, 0f, 0f, 0f, 0f, 20f), Damage(6f, 0f, 0f, 0f, 0f, 0f, 5f), 200, 50, 30, 1.6f, 15, 24, 0), new RecipeSpec("forge", 1, new RequirementSpec[6] { new RequirementSpec("WitheredBone", 10, 5), new RequirementSpec("Iron", 22, 15), new RequirementSpec("Wishbone", 1, 0), new RequirementSpec("TrophyBonemass", 1, 0), new RequirementSpec("ElderBark", 0, 2), new RequirementSpec("LeatherScraps", 0, 2) }), new RecipeSpec("forge", 1, new RequirementSpec[6] { new RequirementSpec("WitheredBone", 20, 10), new RequirementSpec("Iron", 44, 30), new RequirementSpec("Wishbone", 1, 0), new RequirementSpec("TrophyBonemass", 1, 0), new RequirementSpec("ElderBark", 0, 4), new RequirementSpec("LeatherScraps", 0, 4) }), new LocalizedText("Bonemass dual swords", "Парные мечи Бонемасса"), new LocalizedText("A pair of Bonemass swords, swung like the berzerkr's axes.", "Пара мечей Бонемасса, что рубят как топоры берсерка.")); } private static DualSwordDeclaration ModersGrasp() { return new DualSwordDeclaration("VASwordModerDual", "VASwordModer", optional: true, customRecipe: false, null, new StatSnapshot(Damage(35f, 0f, 30f, 0f, 25f), Damage(2f, 0f, 4f, 0f, 1f), 200, 50, 30, 0.8f, 12, 24, 3), new StatSnapshot(Damage(35f, 0f, 30f, 0f, 25f), Damage(2f, 0f, 4f, 0f, 1f), 200, 50, 30, 1.6f, 12, 19, 3), new RecipeSpec("forge", 1, new RequirementSpec[6] { new RequirementSpec("ElderBark", 4, 2), new RequirementSpec("Obsidian", 30, 15), new RequirementSpec("DragonTear", 10, 0), new RequirementSpec("TrophyDragonQueen", 1, 0), new RequirementSpec("Silver", 0, 2), new RequirementSpec("JuteRed", 0, 2) }), new RecipeSpec("forge", 1, new RequirementSpec[6] { new RequirementSpec("ElderBark", 8, 4), new RequirementSpec("Obsidian", 60, 30), new RequirementSpec("DragonTear", 10, 0), new RequirementSpec("TrophyDragonQueen", 1, 0), new RequirementSpec("Silver", 0, 4), new RequirementSpec("JuteRed", 0, 4) }), new LocalizedText("Moder's Grasp dual swords", "Парные мечи Хватки Модер"), new LocalizedText("A pair of Moder's Grasp swords, swung like the berzerkr's axes.", "Пара мечей Хватки Модер, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Queen() { return new DualSwordDeclaration("VASwordQueenDual", "VASwordQueen", optional: true, customRecipe: false, null, new StatSnapshot(Damage(95f, 0f, 0f, 0f, 0f, 30f, 25f), Damage(6f, 0f, 0f, 0f, 0f, 5f, 5f), 200, 50, 52, 0.8f, 16, 32, 5), new StatSnapshot(Damage(95f, 0f, 0f, 0f, 0f, 30f, 25f), Damage(6f, 0f, 0f, 0f, 0f, 5f, 5f), 200, 50, 52, 1.6f, 16, 26, 5), new RecipeSpec("blackforge", 1, new RequirementSpec[5] { new RequirementSpec("YggdrasilWood", 3, 1), new RequirementSpec("Eitr", 10, 5), new RequirementSpec("JuteBlue", 3, 1), new RequirementSpec("TrophySeekerQueen", 1, 0), new RequirementSpec("Carapace", 0, 6) }), new RecipeSpec("blackforge", 1, new RequirementSpec[5] { new RequirementSpec("YggdrasilWood", 6, 2), new RequirementSpec("Eitr", 20, 10), new RequirementSpec("JuteBlue", 6, 2), new RequirementSpec("TrophySeekerQueen", 1, 0), new RequirementSpec("Carapace", 0, 12) }), new LocalizedText("Queen dual swords", "Парные мечи Королевы"), new LocalizedText("A pair of Queen swords, swung like the berzerkr's axes.", "Пара мечей Королевы, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Fader() { return new DualSwordDeclaration("VASwordFaderDual", "VASwordFader", optional: true, customRecipe: false, null, new StatSnapshot(Damage(145f, 0f, 0f, 25f, 0f, 0f, 25f), Damage(3f, 0f, 0f, 1f, 0f, 0f, 1f), 200, 50, 60, 0.8f, 18, 30, 3), new StatSnapshot(Damage(145f, 0f, 0f, 25f, 0f, 0f, 25f), Damage(3f, 0f, 0f, 1f, 0f, 0f, 1f), 200, 50, 60, 1.6f, 18, 24, 3), new RecipeSpec("blackforge", 1, new RequirementSpec[4] { new RequirementSpec("FlametalNew", 30, 30), new RequirementSpec("CharredBone", 30, 30), new RequirementSpec("TrophyFader", 1, 0), new RequirementSpec("FaderDrop", 1, 0) }), new RecipeSpec("blackforge", 1, new RequirementSpec[4] { new RequirementSpec("FlametalNew", 60, 60), new RequirementSpec("CharredBone", 60, 60), new RequirementSpec("TrophyFader", 1, 0), new RequirementSpec("FaderDrop", 1, 0) }), new LocalizedText("Fader dual swords", "Парные мечи Фейдера"), new LocalizedText("A pair of Fader swords, swung like the berzerkr's axes.", "Пара мечей Фейдера, что рубят как топоры берсерка.")); } private static DamageProfile Damage(float slash = 0f, float blunt = 0f, float pierce = 0f, float fire = 0f, float frost = 0f, float lightning = 0f, float poison = 0f, float spirit = 0f) { return new DamageProfile { Slash = slash, Blunt = blunt, Pierce = pierce, Fire = fire, Frost = frost, Lightning = lightning, Poison = poison, Spirit = spirit }; } } public static class Catalogue { public static IReadOnlyList All() { List list = new List(); list.AddRange(VanillaSwords.All()); list.AddRange(NiedhoggSwords.All()); list.AddRange(GoldSwords.All()); list.AddRange(ArmorySwords.All()); return list; } } public static class GoldSwords { public static IReadOnlyList All() { return new DualSwordDeclaration[3] { Gold(), BloodLightning(), FrostFire() }; } private static DualSwordDeclaration Gold() { return new DualSwordDeclaration("SwordGoldDual", "SwordGold", optional: false, customRecipe: false, null, new StatSnapshot(Damage(170f), Damage(10f), 400, 50, 66, 0.8f, 16, 28, 6), new StatSnapshot(Damage(170f), Damage(10f), 400, 50, 66, 1.6f, 16, 22, 6), new RecipeSpec("blackforge", 4, new RequirementSpec[3] { new RequirementSpec("Gold", 20, 10), new RequirementSpec("MoldSword", 1, 0), new RequirementSpec("Frostwood", 10, 5) }), new RecipeSpec("blackforge", 4, new RequirementSpec[3] { new RequirementSpec("Gold", 40, 20), new RequirementSpec("MoldSword", 2, 0), new RequirementSpec("Frostwood", 20, 10) }), new LocalizedText("Gold dual swords", "Парные золотые мечи"), new LocalizedText("A pair of gold swords, swung like the berzerkr's axes.", "Пара золотых мечей, что рубят как топоры берсерка.")); } private static DualSwordDeclaration BloodLightning() { return new DualSwordDeclaration("SwordGold_BloodLightningDual", "SwordGold_BloodLightning", optional: false, customRecipe: true, null, new StatSnapshot(Damage(180f, 0f, 0f, 0f, 0f, 45f), Damage(10f, 0f, 0f, 0f, 0f, 5f), 400, 50, 66, 0.8f, 16, 28, 6), new StatSnapshot(Damage(180f, 0f, 0f, 0f, 0f, 45f), Damage(10f, 0f, 0f, 0f, 0f, 5f), 400, 50, 66, 1.6f, 16, 22, 6), new RecipeSpec("blackforge", 4, new RequirementSpec[3] { new RequirementSpec("SwordGold", 1, 0), new RequirementSpec("Gold", 20, 10), new RequirementSpec("OrbThunderBlood", 1, 1) }), new RecipeSpec("blackforge", 4, new RequirementSpec[3] { new RequirementSpec("SwordGoldDual", 1, 0), new RequirementSpec("Gold", 40, 20), new RequirementSpec("OrbThunderBlood", 2, 2) }), new LocalizedText("Gold Blood-Lightning dual swords", "Парные золотые мечи Крови и Молнии"), new LocalizedText("A pair of gold Blood-Lightning swords, swung like the berzerkr's axes.", "Пара золотых мечей Крови и Молнии, что рубят как топоры берсерка.")); } private static DualSwordDeclaration FrostFire() { return new DualSwordDeclaration("SwordGold_FrostFireDual", "SwordGold_FrostFire", optional: false, customRecipe: true, null, new StatSnapshot(Damage(138f, 0f, 0f, 12f, 88f), Damage(10f, 0f, 0f, 3f, 3f), 400, 50, 66, 0.8f, 16, 28, 6), new StatSnapshot(Damage(138f, 0f, 0f, 12f, 88f), Damage(10f, 0f, 0f, 3f, 3f), 400, 50, 66, 1.6f, 16, 22, 6), new RecipeSpec("blackforge", 4, new RequirementSpec[3] { new RequirementSpec("SwordGold", 1, 0), new RequirementSpec("Gold", 20, 10), new RequirementSpec("OrbFrostFire", 1, 1) }), new RecipeSpec("blackforge", 4, new RequirementSpec[3] { new RequirementSpec("SwordGoldDual", 1, 0), new RequirementSpec("Gold", 40, 20), new RequirementSpec("OrbFrostFire", 2, 2) }), new LocalizedText("Gold Frost-Fire dual swords", "Парные золотые мечи Мороза и Огня"), new LocalizedText("A pair of gold Frost-Fire swords, swung like the berzerkr's axes.", "Пара золотых мечей Мороза и Огня, что рубят как топоры берсерка.")); } private static DamageProfile Damage(float slash = 0f, float blunt = 0f, float pierce = 0f, float fire = 0f, float frost = 0f, float lightning = 0f, float poison = 0f, float spirit = 0f) { return new DamageProfile { Slash = slash, Blunt = blunt, Pierce = pierce, Fire = fire, Frost = frost, Lightning = lightning, Poison = poison, Spirit = spirit }; } } public static class NiedhoggSwords { public static IReadOnlyList All() { return new DualSwordDeclaration[3] { Blood(), Lightning(), Nature() }; } private static DualSwordDeclaration Blood() { return new DualSwordDeclaration("SwordNiedhoggBloodDual", "SwordNiedhoggBlood", optional: false, customRecipe: true, null, new StatSnapshot(Damage(135f), Damage(6f), 300, 50, 57, 0.8f, 16, 28, 6), new StatSnapshot(Damage(135f), Damage(6f), 300, 50, 57, 1.6f, 16, 22, 6), new RecipeSpec("blackforge", 4, new RequirementSpec[3] { new RequirementSpec("SwordNiedhogg", 1, 0), new RequirementSpec("FlametalNew", 6, 6), new RequirementSpec("GemstoneRed", 1, 1) }), new RecipeSpec("blackforge", 4, new RequirementSpec[3] { new RequirementSpec("SwordNiedhoggDual", 1, 0), new RequirementSpec("FlametalNew", 12, 12), new RequirementSpec("GemstoneRed", 2, 2) }), new LocalizedText("Niedhogg's Blood dual swords", "Парные мечи Нидхёгг Крови"), new LocalizedText("A pair of Niedhogg's Blood swords, swung like the berzerkr's axes.", "Пара кроволомных мечей Нидхёгг, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Lightning() { return new DualSwordDeclaration("SwordNiedhoggLightningDual", "SwordNiedhoggLightning", optional: false, customRecipe: true, null, new StatSnapshot(Damage(135f, 0f, 0f, 0f, 0f, 10f), Damage(6f), 300, 50, 57, 0.8f, 16, 28, 6), new StatSnapshot(Damage(135f, 0f, 0f, 0f, 0f, 10f), Damage(6f), 300, 50, 57, 1.6f, 16, 22, 6), new RecipeSpec("blackforge", 4, new RequirementSpec[3] { new RequirementSpec("SwordNiedhogg", 1, 0), new RequirementSpec("FlametalNew", 6, 6), new RequirementSpec("GemstoneBlue", 1, 1) }), new RecipeSpec("blackforge", 4, new RequirementSpec[3] { new RequirementSpec("SwordNiedhoggDual", 1, 0), new RequirementSpec("FlametalNew", 12, 12), new RequirementSpec("GemstoneBlue", 2, 2) }), new LocalizedText("Niedhogg's Lightning dual swords", "Парные мечи Нидхёгг Молнии"), new LocalizedText("A pair of Niedhogg's Lightning swords, swung like the berzerkr's axes.", "Пара громовых мечей Нидхёгг, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Nature() { return new DualSwordDeclaration("SwordNiedhoggNatureDual", "SwordNiedhoggNature", optional: false, customRecipe: true, null, new StatSnapshot(Damage(135f, 0f, 0f, 0f, 0f, 0f, 10f), Damage(6f), 300, 50, 57, 0.8f, 16, 28, 6), new StatSnapshot(Damage(135f, 0f, 0f, 0f, 0f, 0f, 10f), Damage(6f), 300, 50, 57, 1.6f, 16, 22, 6), new RecipeSpec("blackforge", 4, new RequirementSpec[3] { new RequirementSpec("SwordNiedhogg", 1, 0), new RequirementSpec("FlametalNew", 6, 6), new RequirementSpec("GemstoneGreen", 1, 1) }), new RecipeSpec("blackforge", 4, new RequirementSpec[3] { new RequirementSpec("SwordNiedhoggDual", 1, 0), new RequirementSpec("FlametalNew", 12, 12), new RequirementSpec("GemstoneGreen", 2, 2) }), new LocalizedText("Niedhogg's Nature dual swords", "Парные мечи Нидхёгг Природы"), new LocalizedText("A pair of Niedhogg's Nature swords, swung like the berzerkr's axes.", "Пара ядовитых мечей Нидхёгг, что рубят как топоры берсерка.")); } private static DamageProfile Damage(float slash = 0f, float blunt = 0f, float pierce = 0f, float fire = 0f, float frost = 0f, float lightning = 0f, float poison = 0f, float spirit = 0f) { return new DamageProfile { Slash = slash, Blunt = blunt, Pierce = pierce, Fire = fire, Frost = frost, Lightning = lightning, Poison = poison, Spirit = spirit }; } } public static class VanillaSwords { public static IReadOnlyList All() { return new DualSwordDeclaration[8] { Wood(), Bronze(), Iron(), Silver(), Blackmetal(), Mistwalker(), Niedhogg(), Dyrnwyn() }; } private static DualSwordDeclaration Wood() { return new DualSwordDeclaration("SwordWoodDual", "SwordWood", optional: false, customRecipe: false, null, new StatSnapshot(Damage(1f), Damage(1f), 200, 50, 12, 0.8f, 4, 4, 1), new StatSnapshot(Damage(1f), Damage(1f), 200, 50, 16, 1.6f, 4, 3, 1), new RecipeSpec("piece_workbench", 1, new RequirementSpec[4] { new RequirementSpec("Wood", 5, 1), new RequirementSpec("FineWood", 3, 10), new RequirementSpec("RoundLog", 2, 2), new RequirementSpec("Upgrader1Weapon", 1, 0) }), new RecipeSpec("piece_workbench", 1, new RequirementSpec[4] { new RequirementSpec("Wood", 10, 2), new RequirementSpec("FineWood", 6, 20), new RequirementSpec("RoundLog", 4, 4), new RequirementSpec("Upgrader1Weapon", 1, 0) }), new LocalizedText("Wood dual swords", "Парные деревянные мечи"), new LocalizedText("A pair of wood swords, swung like the berzerkr's axes.", "Пара деревянных мечей, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Bronze() { return new DualSwordDeclaration("SwordBronzeDual", "SwordBronze", optional: false, customRecipe: false, null, new StatSnapshot(Damage(35f), Damage(6f), 200, 50, 12, 0.8f, 8, 16, 1), new StatSnapshot(Damage(35f), Damage(6f), 200, 50, 16, 1.6f, 8, 13, 1), new RecipeSpec("forge", 1, new RequirementSpec[3] { new RequirementSpec("Wood", 2, 1), new RequirementSpec("Bronze", 8, 4), new RequirementSpec("LeatherScraps", 2, 1) }), new RecipeSpec("forge", 1, new RequirementSpec[3] { new RequirementSpec("Wood", 4, 2), new RequirementSpec("Bronze", 16, 8), new RequirementSpec("LeatherScraps", 4, 2) }), new LocalizedText("Bronze dual swords", "Парные бронзовые мечи"), new LocalizedText("A pair of bronze swords, swung like the berzerkr's axes.", "Пара бронзовых мечей, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Iron() { return new DualSwordDeclaration("SwordIronDual", "SwordIron", optional: false, customRecipe: false, null, new StatSnapshot(Damage(55f), Damage(6f), 200, 50, 21, 0.8f, 10, 20, 2), new StatSnapshot(Damage(55f), Damage(6f), 200, 50, 21, 1.6f, 10, 16, 2), new RecipeSpec("forge", 2, new RequirementSpec[3] { new RequirementSpec("Wood", 2, 1), new RequirementSpec("Iron", 20, 10), new RequirementSpec("LeatherScraps", 3, 2) }), new RecipeSpec("forge", 2, new RequirementSpec[3] { new RequirementSpec("Wood", 4, 2), new RequirementSpec("Iron", 40, 20), new RequirementSpec("LeatherScraps", 6, 4) }), new LocalizedText("Iron dual swords", "Парные железные мечи"), new LocalizedText("A pair of iron swords, swung like the berzerkr's axes.", "Пара железных мечей, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Silver() { return new DualSwordDeclaration("SwordSilverDual", "SwordSilver", optional: false, customRecipe: false, null, new StatSnapshot(Damage(75f, 0f, 0f, 0f, 0f, 0f, 0f, 30f), Damage(6f, 0f, 0f, 0f, 0f, 0f, 0f, 5f), 200, 50, 30, 1f, 12, 24, 3), new StatSnapshot(Damage(75f, 0f, 0f, 0f, 0f, 0f, 0f, 30f), Damage(6f, 0f, 0f, 0f, 0f, 0f, 0f, 5f), 200, 50, 30, 2f, 12, 19, 3), new RecipeSpec("forge", 3, new RequirementSpec[4] { new RequirementSpec("Wood", 2, 1), new RequirementSpec("Silver", 40, 20), new RequirementSpec("LeatherScraps", 3, 1), new RequirementSpec("Iron", 5, 3) }), new RecipeSpec("forge", 3, new RequirementSpec[4] { new RequirementSpec("Wood", 4, 2), new RequirementSpec("Silver", 80, 40), new RequirementSpec("LeatherScraps", 6, 2), new RequirementSpec("Iron", 10, 6) }), new LocalizedText("Silver dual swords", "Парные серебряные мечи"), new LocalizedText("A pair of silver swords, swung like the berzerkr's axes.", "Пара серебряных мечей, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Blackmetal() { return new DualSwordDeclaration("SwordBlackmetalDual", "SwordBlackmetal", optional: false, customRecipe: false, null, new StatSnapshot(Damage(95f), Damage(6f), 200, 50, 39, 0.8f, 14, 28, 4), new StatSnapshot(Damage(95f), Damage(6f), 200, 50, 39, 1.6f, 14, 22, 4), new RecipeSpec("forge", 4, new RequirementSpec[3] { new RequirementSpec("FineWood", 2, 0), new RequirementSpec("BlackMetal", 20, 10), new RequirementSpec("LinenThread", 5, 5) }), new RecipeSpec("forge", 4, new RequirementSpec[3] { new RequirementSpec("FineWood", 4, 0), new RequirementSpec("BlackMetal", 40, 20), new RequirementSpec("LinenThread", 10, 10) }), new LocalizedText("Black metal dual swords", "Парные чернометаллические мечи"), new LocalizedText("A pair of black metal swords, swung like the berzerkr's axes.", "Пара чернометаллических мечей, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Mistwalker() { return new DualSwordDeclaration("SwordMistwalkerDual", "SwordMistwalker", optional: false, customRecipe: false, null, new StatSnapshot(Damage(75f, 0f, 0f, 0f, 40f), Damage(0f, 0f, 0f, 0f, 6f, 0f, 0f, 5f), 250, 50, 48, 0.8f, 16, 32, 5), new StatSnapshot(Damage(75f, 0f, 0f, 0f, 40f), Damage(0f, 0f, 0f, 0f, 6f, 0f, 0f, 5f), 250, 50, 48, 1.6f, 16, 26, 5), new RecipeSpec("blackforge", 1, new RequirementSpec[4] { new RequirementSpec("FineWood", 3, 0), new RequirementSpec("Iron", 15, 10), new RequirementSpec("Eitr", 10, 5), new RequirementSpec("Wisp", 3, 1) }), new RecipeSpec("blackforge", 1, new RequirementSpec[4] { new RequirementSpec("FineWood", 6, 0), new RequirementSpec("Iron", 30, 20), new RequirementSpec("Eitr", 20, 10), new RequirementSpec("Wisp", 6, 2) }), new LocalizedText("Mistwalker dual swords", "Парные мечи Мистуокер"), new LocalizedText("A pair of Mistwalker swords, swung like the berzerkr's axes.", "Пара мечей Мистуокер, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Niedhogg() { return new DualSwordDeclaration("SwordNiedhoggDual", "SwordNiedhogg", optional: false, customRecipe: false, null, new StatSnapshot(Damage(135f), Damage(6f), 300, 50, 57, 0.8f, 16, 28, 6), new StatSnapshot(Damage(135f), Damage(6f), 300, 50, 57, 1.6f, 16, 22, 6), new RecipeSpec("blackforge", 3, new RequirementSpec[3] { new RequirementSpec("CharredBone", 3, 0), new RequirementSpec("FlametalNew", 12, 10), new RequirementSpec("AskHide", 2, 2) }), new RecipeSpec("blackforge", 3, new RequirementSpec[3] { new RequirementSpec("CharredBone", 6, 0), new RequirementSpec("FlametalNew", 24, 20), new RequirementSpec("AskHide", 4, 4) }), new LocalizedText("Niedhogg dual swords", "Парные мечи Нидхёгг"), new LocalizedText("A pair of Niedhogg swords, swung like the berzerkr's axes.", "Пара мечей Нидхёгг, что рубят как топоры берсерка.")); } private static DualSwordDeclaration Dyrnwyn() { return new DualSwordDeclaration("SwordDyrnwynDual", "SwordDyrnwyn", optional: false, customRecipe: true, null, new StatSnapshot(Damage(145f, 0f, 0f, 10f), Damage(6f), 300, 50, 57, 0.8f, 16, 28, 6), new StatSnapshot(Damage(145f, 0f, 0f, 10f), Damage(6f), 300, 50, 57, 1.6f, 16, 22, 6), new RecipeSpec("blackforge", 4, new RequirementSpec[5] { new RequirementSpec("DyrnwynHiltFragment", 1, 0), new RequirementSpec("DyrnwynBladeFragment", 1, 0), new RequirementSpec("DyrnwynTipFragment", 1, 0), new RequirementSpec("FlametalNew", 20, 10), new RequirementSpec("GemstoneRed", 1, 1) }), new RecipeSpec("blackforge", 4, new RequirementSpec[4] { new RequirementSpec("SwordDyrnwyn", 1, 0), new RequirementSpec("FlametalNew", 20, 20), new RequirementSpec("Eitr", 20, 0), new RequirementSpec("GemstoneRed", 1, 2) }), new LocalizedText("Dyrnwyn dual swords", "Парные мечи Дирнвин"), new LocalizedText("A pair of Dyrnwyn swords, swung like the berzerkr's axes.", "Пара мечей Дирнвин, что рубят как топоры берсерка.")); } private static DamageProfile Damage(float slash = 0f, float blunt = 0f, float pierce = 0f, float fire = 0f, float frost = 0f, float lightning = 0f, float poison = 0f, float spirit = 0f) { return new DamageProfile { Slash = slash, Blunt = blunt, Pierce = pierce, Fire = fire, Frost = frost, Lightning = lightning, Poison = poison, Spirit = spirit }; } } public static class ConfigKeys { public const string BalanceSection = "Balance"; public const string ItemsSection = "Items"; public const string DescriptionsSection = "Descriptions"; public const string ItemStatsSection = "Item stats"; public const string DamageMultiplier = "DamageMultiplier"; public const string RecipeMultiplier = "RecipeMultiplier"; public const string BlockPowerMultiplier = "BlockPowerMultiplier"; public static string Enabled(string id) { return id + ".Enabled"; } public static string Description(string id) { return id + ".Description"; } public static string CustomStats(string id) { return id + ".CustomStats"; } public static string Damage(string id, DamageType type) { return id + "." + type; } public static string DamagePerLevel(string id, DamageType type) { return id + "." + type.ToString() + "PerLevel"; } public static string BlockPower(string id) { return id + ".BlockPower"; } public static string Durability(string id) { return id + ".Durability"; } public static string DurabilityPerLevel(string id) { return id + ".DurabilityPerLevel"; } public static string Weight(string id) { return id + ".Weight"; } public static string PrimaryAttackStamina(string id) { return id + ".PrimaryAttackStamina"; } public static string SecondaryAttackStamina(string id) { return id + ".SecondaryAttackStamina"; } public static string AttackForce(string id) { return id + ".AttackForce"; } public static string BlockForce(string id) { return id + ".BlockForce"; } public static string Recipe(string id) { return id + ".Recipe"; } } public static class ConfigRanges { public const float DamageMin = 0f; public const float DamageMax = 500f; public const float BlockPowerMin = 0f; public const float BlockPowerMax = 500f; public const int DurabilityMin = 1; public const int DurabilityMax = 5000; public const int DurabilityPerLevelMin = 0; public const int DurabilityPerLevelMax = 1000; public const float WeightMin = 0f; public const float WeightMax = 100f; public const int StaminaMin = 0; public const int StaminaMax = 200; public const float ForceMin = 0f; public const float ForceMax = 500f; } public enum ConfigValueKind { Float, Int, Bool } public sealed class ConfigMigrationEntry { public string OldSection { get; } public string OldKey { get; } public string NewSection { get; } public string NewKey { get; } public ConfigValueKind Kind { get; } public ConfigMigrationEntry(string oldSection, string oldKey, string newSection, string newKey, ConfigValueKind kind) { OldSection = oldSection; OldKey = oldKey; NewSection = newSection; NewKey = newKey; Kind = kind; } } public static class ConfigMigration { public const string OldBalanceSection = "Баланс"; public const string OldItemsSection = "Предметы"; public static bool IsNeeded(string configText) { if (configText == null) { return false; } string[] array = configText.Split(new char[1] { '\n' }); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text == "[Баланс]" || text == "[Предметы]") { return true; } } return false; } public static IReadOnlyList PresentIn(string configText, IEnumerable declarations) { List list = new List(); if (string.IsNullOrEmpty(configText)) { return list; } HashSet hashSet = new HashSet(); string text = null; string[] array = configText.Split(new char[1] { '\n' }); for (int i = 0; i < array.Length; i++) { string text2 = array[i].Trim(); if (text2.Length == 0 || text2.StartsWith("#")) { continue; } if (text2.StartsWith("[") && text2.EndsWith("]")) { text = text2.Substring(1, text2.Length - 2); continue; } int num = text2.IndexOf('='); if (num >= 0 && text != null) { string text3 = text2.Substring(0, num).Trim(); hashSet.Add(text + "\u0001" + text3); } } foreach (ConfigMigrationEntry item in Entries(declarations)) { if (hashSet.Contains(item.OldSection + "\u0001" + item.OldKey)) { list.Add(item); } } return list; } public static IReadOnlyList Entries(IEnumerable declarations) { List list = new List { new ConfigMigrationEntry("Баланс", "DamageMultiplier", "Balance", "DamageMultiplier", ConfigValueKind.Float), new ConfigMigrationEntry("Баланс", "RecipeMultiplier", "Balance", "RecipeMultiplier", ConfigValueKind.Int), new ConfigMigrationEntry("Баланс", "BlockPowerMultiplier", "Balance", "BlockPowerMultiplier", ConfigValueKind.Float) }; foreach (DualSwordDeclaration declaration in declarations) { list.Add(new ConfigMigrationEntry("Предметы", declaration.Id + ".Enabled", "Items", ConfigKeys.Enabled(declaration.Id), ConfigValueKind.Bool)); } return list; } } public enum DamageType { Damage, Blunt, Slash, Pierce, Chop, Pickaxe, Fire, Frost, Lightning, Poison, Spirit, NonPlayer } public static class DamageFields { public static readonly IReadOnlyList All = (DamageType[])Enum.GetValues(typeof(DamageType)); public static float Get(DamageProfile profile, DamageType type) { return type switch { DamageType.Damage => profile.Damage, DamageType.Blunt => profile.Blunt, DamageType.Slash => profile.Slash, DamageType.Pierce => profile.Pierce, DamageType.Chop => profile.Chop, DamageType.Pickaxe => profile.Pickaxe, DamageType.Fire => profile.Fire, DamageType.Frost => profile.Frost, DamageType.Lightning => profile.Lightning, DamageType.Poison => profile.Poison, DamageType.Spirit => profile.Spirit, DamageType.NonPlayer => profile.NonPlayer, _ => throw new ArgumentOutOfRangeException("type", type, null), }; } public static void Set(DamageProfile profile, DamageType type, float value) { switch (type) { case DamageType.Damage: profile.Damage = value; break; case DamageType.Blunt: profile.Blunt = value; break; case DamageType.Slash: profile.Slash = value; break; case DamageType.Pierce: profile.Pierce = value; break; case DamageType.Chop: profile.Chop = value; break; case DamageType.Pickaxe: profile.Pickaxe = value; break; case DamageType.Fire: profile.Fire = value; break; case DamageType.Frost: profile.Frost = value; break; case DamageType.Lightning: profile.Lightning = value; break; case DamageType.Poison: profile.Poison = value; break; case DamageType.Spirit: profile.Spirit = value; break; case DamageType.NonPlayer: profile.NonPlayer = value; break; default: throw new ArgumentOutOfRangeException("type", type, null); } } public static IReadOnlyList NonZero(StatSnapshot stats) { return All.Where((DamageType type) => Get(stats.Damage, type) != 0f || Get(stats.DamagePerLevel, type) != 0f).ToList(); } } public sealed class DamageProfile { public float Damage; public float Blunt; public float Slash; public float Pierce; public float Chop; public float Pickaxe; public float Fire; public float Frost; public float Lightning; public float Poison; public float Spirit; public float NonPlayer; public DamageProfile Scale(float multiplier) { if (multiplier <= 0f) { throw new ArgumentOutOfRangeException("multiplier", multiplier, "Множитель урона должен быть больше нуля"); } return new DamageProfile { Damage = Damage * multiplier, Blunt = Blunt * multiplier, Slash = Slash * multiplier, Pierce = Pierce * multiplier, Chop = Chop * multiplier, Pickaxe = Pickaxe * multiplier, Fire = Fire * multiplier, Frost = Frost * multiplier, Lightning = Lightning * multiplier, Poison = Poison * multiplier, Spirit = Spirit * multiplier, NonPlayer = NonPlayer * multiplier }; } } public sealed class DualSwordDeclaration { public string Id { get; } public string BaseSwordPrefab { get; } public bool Optional { get; } public bool CustomRecipe { get; } public EulerOffset? MeshRotation { get; } public StatSnapshot BaseStats { get; } public StatSnapshot DualStats { get; } public RecipeSpec BaseRecipe { get; } public RecipeSpec DualRecipe { get; } public LocalizedText Name { get; } public LocalizedText Description { get; } public string TokenName => "$item_" + (Id ?? string.Empty).ToLowerInvariant(); public string TokenDescription => TokenName + "_description"; public bool IsValid => Validate().Count == 0; public DualSwordDeclaration(string id, string baseSwordPrefab, bool optional, bool customRecipe, EulerOffset? meshRotation, StatSnapshot baseStats, StatSnapshot dualStats, RecipeSpec baseRecipe, RecipeSpec dualRecipe, LocalizedText name, LocalizedText description) { Id = id; BaseSwordPrefab = baseSwordPrefab; Optional = optional; CustomRecipe = customRecipe; MeshRotation = meshRotation; BaseStats = baseStats; DualStats = dualStats; BaseRecipe = baseRecipe; DualRecipe = dualRecipe; Name = name; Description = description; } public IReadOnlyList Validate() { List list = new List(); RequireText(list, Id, "Id предмета"); RequireText(list, BaseSwordPrefab, "BaseSwordPrefab"); if (BaseStats == null) { list.Add(Id + ": нет снимка статов базового меча"); } if (DualStats == null) { list.Add(Id + ": нет статов парного предмета"); } ValidateRecipe(list, BaseRecipe, "рецепт базового меча"); ValidateRecipe(list, DualRecipe, "рецепт парного предмета"); ValidateText(list, Name, "название"); ValidateText(list, Description, "описание"); return list; } private void ValidateRecipe(List errors, RecipeSpec recipe, string what) { if (recipe == null) { errors.Add(Id + ": не задан " + what); return; } if (string.IsNullOrWhiteSpace(recipe.Station)) { errors.Add(Id + ": не задан станок (" + what + ")"); } if (recipe.MinStationLevel < 1) { errors.Add(Id + ": уровень станка должен быть не меньше 1 (" + what + ")"); } if (recipe.Requirements.Count == 0) { errors.Add(Id + ": " + what + " пуст"); return; } foreach (RequirementSpec requirement in recipe.Requirements) { if (string.IsNullOrWhiteSpace(requirement.Item)) { errors.Add(Id + ": в требовании не указан префаб (" + what + ")"); } else if (requirement.Amount < 0 || requirement.AmountPerLevel < 0) { errors.Add(Id + ": отрицательное количество " + requirement.Item + " (" + what + ")"); } else if (requirement.Amount == 0 && requirement.AmountPerLevel == 0) { errors.Add(Id + ": требование " + requirement.Item + " не стоит ничего (" + what + ")"); } } } private void ValidateText(List errors, LocalizedText text, string what) { if (text == null) { errors.Add(Id + ": не задано " + what); return; } RequireText(errors, text.English, what + " на английском"); RequireText(errors, text.Russian, what + " на русском"); } private void RequireText(List errors, string value, string what) { if (string.IsNullOrWhiteSpace(value)) { errors.Add(Id + ": не заполнено " + what); } } } public static class DualSwordsInfo { public const string PluginGuid = "dev.alex.dualswords"; public const string PluginName = "DualSwords"; public const string PluginVersion = "1.0.2"; } public struct EulerOffset { public float X { get; } public float Y { get; } public float Z { get; } public static EulerOffset Zero => new EulerOffset(0f, 0f, 0f); public EulerOffset(float x, float y, float z) { X = x; Y = y; Z = z; } public override string ToString() { return $"({X}, {Y}, {Z})"; } } public sealed class BalanceMultipliers { public static readonly BalanceMultipliers Neutral = new BalanceMultipliers(1f, 1, 1f); public float Damage { get; } public int Recipe { get; } public float BlockPower { get; } public BalanceMultipliers(float damage, int recipe, float blockPower) { Damage = damage; Recipe = recipe; BlockPower = blockPower; } } public sealed class ResolvedItemStats { public DamageProfile Damage { get; internal set; } public DamageProfile DamagePerLevel { get; internal set; } public float BlockPower { get; internal set; } public int MaxDurability { get; internal set; } public int DurabilityPerLevel { get; internal set; } public float Weight { get; internal set; } public int PrimaryStamina { get; internal set; } public int SecondaryStamina { get; internal set; } public int ToolTier { get; internal set; } public float? AttackForce { get; internal set; } public float? BlockForce { get; internal set; } public string Station { get; internal set; } public int MinStationLevel { get; internal set; } public IReadOnlyList Requirements { get; internal set; } public IReadOnlyList Warnings { get; internal set; } } public static class ItemStatsResolver { public static ResolvedItemStats Resolve(DualSwordDeclaration declaration, ItemStatValues values, BalanceMultipliers multipliers, Func isItem) { if (declaration == null) { throw new ArgumentNullException("declaration"); } if (multipliers == null) { throw new ArgumentNullException("multipliers"); } if (isItem == null) { throw new ArgumentNullException("isItem"); } List warnings = new List(); ResolvedItemStats resolvedItemStats = new ResolvedItemStats { ToolTier = declaration.DualStats.ToolTier, Station = declaration.DualRecipe.Station, MinStationLevel = declaration.DualRecipe.MinStationLevel, Warnings = warnings }; if (values == null || !values.CustomStats) { FromCatalogue(declaration, multipliers, resolvedItemStats, warnings); } else { FromConfig(declaration, values, isItem, resolvedItemStats, warnings); } return resolvedItemStats; } private static void FromCatalogue(DualSwordDeclaration declaration, BalanceMultipliers multipliers, ResolvedItemStats resolved, List warnings) { StatSnapshot dualStats = declaration.DualStats; float num = multipliers.Damage; if (num <= 0f) { warnings.Add($"{declaration.Id}: DamageMultiplier сконфигурирован как {num}, множитель урона должен быть больше нуля — беру 1.0"); num = 1f; } float num2 = multipliers.BlockPower; if (num2 <= 0f) { warnings.Add($"{declaration.Id}: BlockPowerMultiplier сконфигурирован как {num2}, множитель силы блока должен быть больше нуля — беру 1.0"); num2 = 1f; } int num3 = multipliers.Recipe; if (num3 < 1) { warnings.Add($"{declaration.Id}: RecipeMultiplier сконфигурирован как {num3}, множитель рецепта должен быть не меньше единицы — беру 1"); num3 = 1; } resolved.Damage = dualStats.Damage.Scale(num); resolved.DamagePerLevel = dualStats.DamagePerLevel.Scale(num); resolved.BlockPower = (float)dualStats.BlockPower * num2; resolved.MaxDurability = dualStats.MaxDurability; resolved.DurabilityPerLevel = dualStats.DurabilityPerLevel; resolved.Weight = dualStats.Weight; resolved.PrimaryStamina = dualStats.PrimaryStamina; resolved.SecondaryStamina = dualStats.SecondaryStamina; resolved.AttackForce = null; resolved.BlockForce = null; resolved.Requirements = RecipeScaling.Scale(declaration.DualRecipe.Requirements, num3); } private static void FromConfig(DualSwordDeclaration declaration, ItemStatValues values, Func isItem, ResolvedItemStats resolved, List warnings) { StatSnapshot dualStats = declaration.DualStats; resolved.Damage = new DamageProfile(); resolved.DamagePerLevel = new DamageProfile(); foreach (DamageType item in DamageFields.NonZero(dualStats)) { DamageFields.Set(resolved.Damage, item, values.Damage.TryGetValue(item, out var value) ? value : DamageFields.Get(dualStats.Damage, item)); DamageFields.Set(resolved.DamagePerLevel, item, values.DamagePerLevel.TryGetValue(item, out var value2) ? value2 : DamageFields.Get(dualStats.DamagePerLevel, item)); } resolved.BlockPower = values.BlockPower; resolved.MaxDurability = values.Durability; resolved.DurabilityPerLevel = values.DurabilityPerLevel; resolved.Weight = values.Weight; resolved.PrimaryStamina = values.PrimaryAttackStamina; resolved.SecondaryStamina = values.SecondaryAttackStamina; resolved.AttackForce = values.AttackForce; resolved.BlockForce = values.BlockForce; if (!RecipeText.TryParse(values.Recipe, out var requirements, out var error)) { warnings.Add(declaration.Id + ": рецепт из конфига не принят (" + error + ") — беру рецепт каталога"); resolved.Requirements = declaration.DualRecipe.Requirements; return; } List list = (from requirement in requirements select requirement.Item into item where !isItem(item) select item).ToList(); if (list.Count > 0) { warnings.Add(declaration.Id + ": в рецепте из конфига неизвестные префабы или не предметы: " + string.Join(", ", list) + " — беру рецепт каталога"); resolved.Requirements = declaration.DualRecipe.Requirements; } else { resolved.Requirements = requirements; } } } public sealed class ItemStatValues { public bool CustomStats { get; set; } public Dictionary Damage { get; } = new Dictionary(); public Dictionary DamagePerLevel { get; } = new Dictionary(); public float BlockPower { get; set; } public int Durability { get; set; } public int DurabilityPerLevel { get; set; } public float Weight { get; set; } public int PrimaryAttackStamina { get; set; } public int SecondaryAttackStamina { get; set; } public float AttackForce { get; set; } public float BlockForce { get; set; } public string Recipe { get; set; } public static ItemStatValues DefaultsFor(DualSwordDeclaration declaration) { StatSnapshot dualStats = declaration.DualStats; ItemStatValues itemStatValues = new ItemStatValues { CustomStats = false, BlockPower = dualStats.BlockPower, Durability = dualStats.MaxDurability, DurabilityPerLevel = dualStats.DurabilityPerLevel, Weight = dualStats.Weight, PrimaryAttackStamina = dualStats.PrimaryStamina, SecondaryAttackStamina = dualStats.SecondaryStamina, AttackForce = 20f, BlockForce = 20f, Recipe = RecipeText.Format(declaration.DualRecipe.Requirements) }; foreach (DamageType item in DamageFields.NonZero(dualStats)) { itemStatValues.Damage[item] = DamageFields.Get(dualStats.Damage, item); itemStatValues.DamagePerLevel[item] = DamageFields.Get(dualStats.DamagePerLevel, item); } return itemStatValues; } } public sealed class LocalizedText { public string English { get; } public string Russian { get; } public LocalizedText(string english, string russian) { English = english; Russian = russian; } } public static class RecipeScaling { public static IReadOnlyList Scale(IReadOnlyList source, int multiplier) { if (source == null) { throw new ArgumentNullException("source"); } if (multiplier < 1) { throw new ArgumentOutOfRangeException("multiplier", multiplier, "Множитель рецепта должен быть не меньше единицы"); } List list = new List(source.Count); foreach (RequirementSpec item in source) { if (item != null) { if (!BalanceRules.IsScalable(item.Item)) { list.Add(item); } else { list.Add(new RequirementSpec(item.Item, item.Amount * multiplier, item.AmountPerLevel * multiplier)); } } } return list; } } public sealed class RecipeSpec { public string Station { get; } public int MinStationLevel { get; } public IReadOnlyList Requirements { get; } public RecipeSpec(string station, int minStationLevel, IReadOnlyList requirements) { Station = station; MinStationLevel = minStationLevel; Requirements = requirements ?? new RequirementSpec[0]; } } public static class RecipeText { public static string Format(IReadOnlyList requirements) { if (requirements == null) { throw new ArgumentNullException("requirements"); } return string.Join("|", requirements.Select((RequirementSpec requirement) => string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", requirement.Item, requirement.Amount, requirement.AmountPerLevel))); } public static bool TryParse(string text, out IReadOnlyList requirements, out string error) { requirements = null; if (string.IsNullOrWhiteSpace(text)) { error = "строка рецепта пустая"; return false; } List list = new List(); string[] array = text.Split(new char[1] { '|' }); for (int i = 0; i < array.Length; i++) { string text2 = array[i].Trim(); if (text2.Length == 0) { error = "пустой ингредиент в «" + text + "»"; return false; } string[] array2 = text2.Split(new char[1] { ',' }); if (array2.Length != 3) { error = "«" + text2 + "»: нужно ровно три поля Prefab,Amount,AmountPerLevel"; return false; } string text3 = array2[0].Trim(); if (text3.Length == 0) { error = "«" + text2 + "»: не указан префаб"; return false; } if (!TryParseAmount(array2[1], out var value) || !TryParseAmount(array2[2], out var value2)) { error = "«" + text2 + "»: количество должно быть целым числом"; return false; } if (value < 0 || value2 < 0) { error = "«" + text2 + "»: отрицательное количество"; return false; } if (value == 0 && value2 == 0) { error = "«" + text2 + "»: ингредиент не стоит ничего"; return false; } list.Add(new RequirementSpec(text3, value, value2)); } requirements = list; error = null; return true; } private static bool TryParseAmount(string text, out int value) { return int.TryParse(text.Trim(), NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out value); } } public sealed class RequirementSpec { public string Item { get; } public int Amount { get; } public int AmountPerLevel { get; } public RequirementSpec(string item, int amount, int amountPerLevel) { Item = item; Amount = amount; AmountPerLevel = amountPerLevel; } } public sealed class StatSnapshot { public DamageProfile Damage { get; } public DamageProfile DamagePerLevel { get; } public int MaxDurability { get; } public int DurabilityPerLevel { get; } public int BlockPower { get; } public float Weight { get; } public int PrimaryStamina { get; } public int SecondaryStamina { get; } public int ToolTier { get; } public StatSnapshot(DamageProfile damage, DamageProfile damagePerLevel, int maxDurability, int durabilityPerLevel, int blockPower, float weight, int primaryStamina, int secondaryStamina, int toolTier) { Damage = damage; DamagePerLevel = damagePerLevel; MaxDurability = maxDurability; DurabilityPerLevel = durabilityPerLevel; BlockPower = blockPower; Weight = weight; PrimaryStamina = primaryStamina; SecondaryStamina = secondaryStamina; ToolTier = toolTier; } } }