diff --git a/docs-website/docs/admin-panel/game-configuration.md b/docs-website/docs/admin-panel/game-configuration.md index 7641f60189..ffaea208ce 100644 --- a/docs-website/docs/admin-panel/game-configuration.md +++ b/docs-website/docs/admin-panel/game-configuration.md @@ -69,6 +69,34 @@ This is where the values live which most server operators want to change: * **Misc** — info range, recovery interval, letter settings, durability consumption +### Party experience bonus + +A party gets more experience than its members would get alone. The experience of +a party with *n* members is multiplied by `Party Experience Multiplier`^(*n* − 1), +so every additional member multiplies it once more. The value is configured +through the *Global base attribute values* of the game configuration, which you +reach through the full configuration tree. + +The default is `1.05`, which is the party experience of all game versions +(0.75, 0.95d and Season 6): + +| Members | 2 | 3 | 4 | 5 | +|---|---|---|---|---| +| Experience bonus | 5% | 10.25% | 15.76% | 21.55% | + +A value of `0` or less (or an attribute which isn't configured) means no bonus, +and a single player never gets a bonus. + +A party can additionally get a `Set Party Experience Bonus`, which is added to +the multiplier (`0.02` adds 2%). It defaults to `0`, so it's disabled until you +configure it. Zero or negative values are ignored. A **set party** is a party of +at least three members in which every member belongs to a different class line, +for example a Dark Wizard (or Soul Master, Grand Master, …), a Dark Knight and a +Fairy Elf. + +The same attributes can also be defined per map, account or character, for +example for an event; the first member of the party decides. + ## Monsters Route `edit-config-grid/…MonsterDefinition/` diff --git a/src/AttributeSystem/Properties/AttributeTexts.de.resx b/src/AttributeSystem/Properties/AttributeTexts.de.resx index af0de49e4f..8c567ade29 100644 --- a/src/AttributeSystem/Properties/AttributeTexts.de.resx +++ b/src/AttributeSystem/Properties/AttributeTexts.de.resx @@ -789,6 +789,12 @@ Bonusschaden für Einhandschwerter (MST) + + Erfahrungsmultiplikator der Gruppe + + + Definiert den Erfahrungsmultiplikator einer Gruppe für jedes zusätzliche Gruppenmitglied (1,05 = 5 % mehr Erfahrung für das zweite Mitglied, was für jedes weitere Mitglied multipliziert wird, d. h. eine Gruppe mit 3 Mitgliedern erhält 1,05 * 1,05). Ein Wert von 0 oder weniger deaktiviert ihn. + Erhöhung der Begleiterhaltbarkeit @@ -903,6 +909,12 @@ Erhöht die Schadensabsorptionsrate des Schilds im PvP entsprechend dem eingestellten Wert. + + Erfahrungsbonus der Set-Gruppe + + + Definiert den Erfahrungsbonus, der zum Erfahrungsmultiplikator einer Set-Gruppe addiert wird, als Anteil der Erfahrung (0,02 = 2 %). + Chance, den Schild (SD) zu umgehen diff --git a/src/AttributeSystem/Properties/AttributeTexts.resx b/src/AttributeSystem/Properties/AttributeTexts.resx index b5d459d372..2f2c816ba7 100644 --- a/src/AttributeSystem/Properties/AttributeTexts.resx +++ b/src/AttributeSystem/Properties/AttributeTexts.resx @@ -792,6 +792,12 @@ One Handed Sword Bonus Damage (MST) + + Party Experience Multiplier + + + Defines the experience multiplier of a party for each additional party member (1.05 = 5% more experience for the second member, which is multiplied for each further member, so a party of 3 members gets 1.05 * 1.05). A value of 0 or less disables it. + Pet Duration Increase @@ -909,6 +915,12 @@ Increases the shield’s damage absorb rate in PVP according to set value. + + Set Party Experience Bonus + + + Defines the experience bonus which is added to the experience multiplier of a set party, as fraction of the experience (0.02 = 2%). + Shield Bypass Chance diff --git a/src/AttributeSystem/Properties/AttributeTexts.zh-CN.resx b/src/AttributeSystem/Properties/AttributeTexts.zh-CN.resx index 262e7b76fe..52abe96b4d 100644 --- a/src/AttributeSystem/Properties/AttributeTexts.zh-CN.resx +++ b/src/AttributeSystem/Properties/AttributeTexts.zh-CN.resx @@ -792,6 +792,12 @@ 单手剑伤害加成(大师技能) + + 队伍经验倍率 + + + 定义每增加一名队伍成员时队伍经验所乘的倍率(1.05 = 第二名成员增加5%经验,并对之后每名成员继续相乘,即3名成员的队伍获得 1.05 * 1.05)。值为0或更小则禁用。 + 宠物持续时间增加 @@ -909,6 +915,12 @@ 对玩家战斗时,按设定值提高防护值的伤害吸收比例。 + + 套装队伍经验加成 + + + 定义在套装队伍的经验倍率基础上额外增加的经验加成,以经验的比例表示(0.02 = 2%)。 + 无视防护值概率 diff --git a/src/GameLogic/Attributes/Stats.cs b/src/GameLogic/Attributes/Stats.cs index 89a758d170..44d5154799 100644 --- a/src/GameLogic/Attributes/Stats.cs +++ b/src/GameLogic/Attributes/Stats.cs @@ -121,6 +121,26 @@ public class Stats /// public static AttributeDefinition RandomExperienceMaxMultiplier { get; } = new(new Guid("74CE26C6-6D59-4420-AF3F-457E138AE41C"), "Random Experience Max Multiplier", "Defines the maximum multiplier for the randomized experience gain."); + /// + /// Gets the party experience multiplier, by which the experience of a party is multiplied for each additional party member. + /// + /// + /// A party of n members gets PartyExperienceMultiplier^(n-1) times the experience, so with the default of 1.05, + /// a party of 3 members gets 1.05 * 1.05. A value of 0 or less disables it. + /// It can be defined in the . + /// + public static AttributeDefinition PartyExperienceMultiplier { get; } = new(new Guid("A086BE24-8849-4C26-8C7F-9CEF8DE27DEB"), "Party Experience Multiplier", "Defines the experience multiplier of a party for each additional party member (1.05 = 5% more experience for the second member, which is multiplied for each further member, so a party of 3 members gets 1.05 * 1.05). A value of 0 or less disables it."); + + /// + /// Gets the bonus experience of a set party, which is added to . + /// + /// + /// A set party is a party of at least three members, in which every member belongs to a different character class line. + /// The value is a fraction which is added to the multiplier of the party, so 0.02 increases the experience by an additional 2%. By default it's 0, which means no bonus. + /// It can be defined in the . + /// + public static AttributeDefinition SetPartyExperienceBonus { get; } = new(new Guid("BAEAC94C-9B06-4C15-BA7F-6E6B062CAF27"), "Set Party Experience Bonus", "Defines the experience bonus which is added to the experience multiplier of a set party, as fraction of the experience (0.02 = 2%)."); + /// /// Gets the bonus experience rate attribute definition, which is added to or . /// diff --git a/src/GameLogic/Party.cs b/src/GameLogic/Party.cs index 41b6657067..df074940fd 100644 --- a/src/GameLogic/Party.cs +++ b/src/GameLogic/Party.cs @@ -386,7 +386,7 @@ private static float CalculatePartyExperiencePerLevel(List recipients, I var averageLevel = totalLevel / memberCount; var baseExperience = killed.CalculateBaseExperience(averageLevel); - var partyBonusMultiplier = Math.Pow(1.05, memberCount - 1); + var partyBonusMultiplier = PartyExperienceBonus.GetMultiplier(recipients); var mapExperienceMultiplier = killed.CurrentMap?.Definition.ExpMultiplier ?? 1; var totalBaseExperience = baseExperience * memberCount * partyBonusMultiplier * mapExperienceMultiplier; diff --git a/src/GameLogic/PartyExperienceBonus.cs b/src/GameLogic/PartyExperienceBonus.cs new file mode 100644 index 0000000000..92efa81675 --- /dev/null +++ b/src/GameLogic/PartyExperienceBonus.cs @@ -0,0 +1,129 @@ +// +// Licensed under the MIT License. See LICENSE file in the project root for full license information. +// + +namespace MUnique.OpenMU.GameLogic; + +using MUnique.OpenMU.DataModel.Configuration; +using MUnique.OpenMU.GameLogic.Attributes; + +/// +/// Determines the experience bonus of a party, depending on its size and composition. +/// +/// +/// +/// The bonuses are configurable through attributes, which are read from the attribute system of the party members, +/// so they can be defined globally, but also per map, account or character. +/// The first party member decides, as it does for the random experience multipliers. +/// +/// +/// The experience of a party with n members is multiplied by ^(n - 1), +/// which is 1.05^(n - 1) by default. A party with at least members, in which every +/// member belongs to a different character class line (e.g. Dark Wizard, Dark Knight and Fairy Elf), is a "set party" +/// and additionally gets added, which is 0 by default. +/// +/// +internal static class PartyExperienceBonus +{ + /// + /// The minimum number of members of a set party. + /// + internal const int MinimumSetPartySize = 3; + + /// + /// The minimum number of members of a party which gets an experience bonus. + /// + internal const int MinimumBonusPartySize = 2; + + /// + /// Gets the multiplier which is applied to the experience of the party. + /// + /// The party members which share the experience. + /// The multiplier, which is 1 if the party doesn't get a bonus. + public static double GetMultiplier(IReadOnlyList members) + { + if (members.Count < MinimumBonusPartySize || members[0].Attributes is not { } attributes) + { + return 1; + } + + var multiplier = 1.0; + var partyMultiplier = ToDouble(attributes[Stats.PartyExperienceMultiplier]); + if (partyMultiplier > 0) + { + multiplier = Math.Pow(partyMultiplier, members.Count - 1); + } + + var setPartyBonus = ToDouble(attributes[Stats.SetPartyExperienceBonus]); + if (setPartyBonus > 0 && IsSetParty(members)) + { + multiplier += setPartyBonus; + } + + return multiplier; + } + + /// + /// Determines whether the members form a set party, which means that they are at least + /// and each of them belongs to a different character class line. + /// + /// The party members. + /// true, if the members form a set party. + public static bool IsSetParty(IReadOnlyList members) + { + if (members.Count < MinimumSetPartySize) + { + return false; + } + + // Resolve the class line only once per member. The class hierarchy is configuration data and + // can be edited at runtime, so it is intentionally not cached across calls. + // Reference equality is used on purpose: the members share one game configuration, so their + // classes are the same instances, while CharacterClass overrides Equals by its id. + var classLines = new HashSet(members.Count, ReferenceEqualityComparer.Instance); + foreach (var member in members) + { + if (GetLastClassOfLine(member) is not { } classLine + || !classLines.Add(classLine)) + { + return false; + } + } + + return true; + } + + /// + /// Gets the last class of the line of the character class of the player. + /// + private static CharacterClass? GetLastClassOfLine(Player player) + { + var characterClass = player.SelectedCharacter?.CharacterClass; + if (characterClass is null) + { + return null; + } + + // The class count bounds the loop, so a misconfigured cycle can't hang the game logic. + var maximumSteps = player.GameContext.Configuration.CharacterClasses.Count; + for (var step = 0; step < maximumSteps && characterClass.NextGenerationClass is { } nextClass; step++) + { + characterClass = nextClass; + } + + return characterClass; + } + + /// + /// Converts the attribute value to a double. + /// + /// + /// The attribute values are floats, which can't represent fractions like 1.05 exactly. A plain conversion would + /// turn it into 1.0499999..., and the experience would differ slightly from the one calculated with + /// the literal 1.05. Rounding to seven decimal places, which is more than a float can hold reliably, avoids that. + /// + private static double ToDouble(float value) + { + return Math.Round((double)value, 7); + } +} diff --git a/src/Persistence/Initialization/GameConfigurationInitializerBase.cs b/src/Persistence/Initialization/GameConfigurationInitializerBase.cs index 3f61089f45..7ea3913af2 100644 --- a/src/Persistence/Initialization/GameConfigurationInitializerBase.cs +++ b/src/Persistence/Initialization/GameConfigurationInitializerBase.cs @@ -311,6 +311,12 @@ private void AddGlobalBaseAttributeValues() var randomExperienceMaxMultiplier = this.Context.CreateNew(1.2f, Stats.RandomExperienceMaxMultiplier.GetPersistent(this.GameConfiguration), AggregateType.AddRaw); this.GameConfiguration.GlobalBaseAttributeValues.Add(randomExperienceMaxMultiplier); + foreach (var (attribute, value) in PartyExperienceBonusDefaults.Values) + { + var partyExperienceBonus = this.Context.CreateNew(value, attribute.GetPersistent(this.GameConfiguration), AggregateType.AddRaw); + this.GameConfiguration.GlobalBaseAttributeValues.Add(partyExperienceBonus); + } + var movementSpeedFactor = this.Context.CreateNew(1f, Stats.MovementSpeedFactor.GetPersistent(this.GameConfiguration), AggregateType.AddRaw); this.GameConfiguration.GlobalBaseAttributeValues.Add(movementSpeedFactor); diff --git a/src/Persistence/Initialization/PartyExperienceBonusDefaults.cs b/src/Persistence/Initialization/PartyExperienceBonusDefaults.cs new file mode 100644 index 0000000000..242e58867f --- /dev/null +++ b/src/Persistence/Initialization/PartyExperienceBonusDefaults.cs @@ -0,0 +1,24 @@ +// +// Licensed under the MIT License. See LICENSE file in the project root for full license information. +// + +namespace MUnique.OpenMU.Persistence.Initialization; + +using MUnique.OpenMU.AttributeSystem; +using MUnique.OpenMU.GameLogic.Attributes; + +/// +/// The default values of the party experience attributes. They are shared by the data initialization, +/// which is used for new databases, and by the update plugins for existing databases. +/// +internal static class PartyExperienceBonusDefaults +{ + /// + /// Gets the party experience attributes with their default values. + /// + public static IReadOnlyList<(AttributeDefinition Attribute, float Value)> Values { get; } = + [ + (Stats.PartyExperienceMultiplier, 1.05f), + (Stats.SetPartyExperienceBonus, 0f), + ]; +} diff --git a/src/Persistence/Initialization/Properties/PlugInResources.Designer.cs b/src/Persistence/Initialization/Properties/PlugInResources.Designer.cs index 42208ee5b6..3ab06ea9a0 100644 --- a/src/Persistence/Initialization/Properties/PlugInResources.Designer.cs +++ b/src/Persistence/Initialization/Properties/PlugInResources.Designer.cs @@ -924,6 +924,24 @@ public static string AddMovementSpeedAttributesPlugInBase_Name { } } + /// + /// Looks up a localized string similar to Adds the attributes which define the party experience (the multiplier for each additional party member, and a bonus for set parties) with default values which keep the current party experience: 1.05 for each additional member, and no set party bonus. Existing values are not changed.. + /// + public static string AddPartyExperienceBonusAttributesPlugInBase_Description { + get { + return ResourceManager.GetString("AddPartyExperienceBonusAttributesPlugInBase_Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Add party experience bonus attributes. + /// + public static string AddPartyExperienceBonusAttributesPlugInBase_Name { + get { + return ResourceManager.GetString("AddPartyExperienceBonusAttributesPlugInBase_Name", resourceCulture); + } + } + /// /// Looks up a localized string similar to This update adds the attribute PointsPerReset.. /// diff --git a/src/Persistence/Initialization/Properties/PlugInResources.de.resx b/src/Persistence/Initialization/Properties/PlugInResources.de.resx index 9b60fcceed..3fe25248fa 100644 --- a/src/Persistence/Initialization/Properties/PlugInResources.de.resx +++ b/src/Persistence/Initialization/Properties/PlugInResources.de.resx @@ -842,6 +842,8 @@ Attribut für den Bonus der Erfolgsrate beim Kombinieren hinzufügen Fügt das Attribut hinzu, das die Prozentpunkte festlegt, die zur Erfolgsrate beim Kombinieren von Gegenständen addiert werden. + Attribute für den Erfahrungsbonus von Gruppen hinzufügen + Fügt die Attribute hinzu, die die Gruppenerfahrung festlegen (den Multiplikator für jedes zusätzliche Gruppenmitglied und einen Bonus für Set-Gruppen), mit Standardwerten, welche die aktuelle Gruppenerfahrung beibehalten: 1,05 für jedes zusätzliche Mitglied und kein Bonus für Set-Gruppen. Vorhandene Werte werden nicht geändert. Maximale Gegenstandsstufe der Seed Spheres korrigieren Diese Aktualisierung setzt die maximale Gegenstandsstufe der Seed Spheres auf die höchste Optionsnummer ihres Elements. Die Gegenstandsstufe einer Seed Sphere bestimmt ihre Option, daher konnten Seed Spheres mit einer anderen als der ersten Option nicht erstellt werden, z. B. mit dem Item-Chatbefehl. diff --git a/src/Persistence/Initialization/Properties/PlugInResources.resx b/src/Persistence/Initialization/Properties/PlugInResources.resx index e643df0e2e..f2fdcd9960 100644 --- a/src/Persistence/Initialization/Properties/PlugInResources.resx +++ b/src/Persistence/Initialization/Properties/PlugInResources.resx @@ -408,6 +408,8 @@ Add crafting bonus percentage attribute Adds the attribute which defines the percentage points which are added to the success rate of item craftings. + Add party experience bonus attributes + Adds the attributes which define the party experience (the multiplier for each additional party member, and a bonus for set parties) with default values which keep the current party experience: 1.05 for each additional member, and no set party bonus. Existing values are not changed. Fix maximum item level of seed spheres This update sets the maximum item level of the seed spheres to the highest option number of their element. The item level of a seed sphere defines its option, so seed spheres with other options than the first one could not be created, e.g. with the item chat command. Add item price definitions diff --git a/src/Persistence/Initialization/Properties/PlugInResources.zh-CN.resx b/src/Persistence/Initialization/Properties/PlugInResources.zh-CN.resx index 639d9de5df..577b79dc66 100644 --- a/src/Persistence/Initialization/Properties/PlugInResources.zh-CN.resx +++ b/src/Persistence/Initialization/Properties/PlugInResources.zh-CN.resx @@ -395,6 +395,8 @@ 添加合成成功率加成属性 添加用于定义物品合成成功率额外增加的百分点的属性。 + 添加组队经验加成属性 + 添加用于定义队伍经验的属性(每增加一名队伍成员的倍率以及套装队伍加成),其默认值保持当前的队伍经验:每增加一名成员乘以1.05,套装队伍无加成。已有的值不会被更改。 修正种子球的最大物品等级 将种子球的最大物品等级设置为其元素的最高选项编号。种子球的物品等级决定其选项,因此此前无法创建第一个选项以外的种子球,例如通过物品聊天命令。 diff --git a/src/Persistence/Initialization/Updates/AddPartyExperienceBonusAttributesPlugIn075.cs b/src/Persistence/Initialization/Updates/AddPartyExperienceBonusAttributesPlugIn075.cs new file mode 100644 index 0000000000..8b6c34c5ce --- /dev/null +++ b/src/Persistence/Initialization/Updates/AddPartyExperienceBonusAttributesPlugIn075.cs @@ -0,0 +1,20 @@ +// +// Licensed under the MIT License. See LICENSE file in the project root for full license information. +// + +namespace MUnique.OpenMU.Persistence.Initialization.Updates; + +using System.Runtime.InteropServices; +using MUnique.OpenMU.PlugIns; + +/// +/// This update adds the party experience bonus attributes for version 0.75. +/// +[PlugIn] +[Display(Name = nameof(MUnique.OpenMU.Persistence.Initialization.Properties.PlugInResources.AddPartyExperienceBonusAttributesPlugInBase_Name), Description = nameof(MUnique.OpenMU.Persistence.Initialization.Properties.PlugInResources.AddPartyExperienceBonusAttributesPlugInBase_Description), ResourceType = typeof(MUnique.OpenMU.Persistence.Initialization.Properties.PlugInResources))] +[Guid("4810A5FE-6E41-45C3-933F-71684D8C4DE2")] +public class AddPartyExperienceBonusAttributesPlugIn075 : AddPartyExperienceBonusAttributesPlugInBase +{ + /// + public override string DataInitializationKey => Version075.DataInitialization.Id; +} diff --git a/src/Persistence/Initialization/Updates/AddPartyExperienceBonusAttributesPlugIn095d.cs b/src/Persistence/Initialization/Updates/AddPartyExperienceBonusAttributesPlugIn095d.cs new file mode 100644 index 0000000000..43f7c8f538 --- /dev/null +++ b/src/Persistence/Initialization/Updates/AddPartyExperienceBonusAttributesPlugIn095d.cs @@ -0,0 +1,20 @@ +// +// Licensed under the MIT License. See LICENSE file in the project root for full license information. +// + +namespace MUnique.OpenMU.Persistence.Initialization.Updates; + +using System.Runtime.InteropServices; +using MUnique.OpenMU.PlugIns; + +/// +/// This update adds the party experience bonus attributes for version 0.95d. +/// +[PlugIn] +[Display(Name = nameof(MUnique.OpenMU.Persistence.Initialization.Properties.PlugInResources.AddPartyExperienceBonusAttributesPlugInBase_Name), Description = nameof(MUnique.OpenMU.Persistence.Initialization.Properties.PlugInResources.AddPartyExperienceBonusAttributesPlugInBase_Description), ResourceType = typeof(MUnique.OpenMU.Persistence.Initialization.Properties.PlugInResources))] +[Guid("5176D628-D19C-4048-A0AE-9B876912F38D")] +public class AddPartyExperienceBonusAttributesPlugIn095d : AddPartyExperienceBonusAttributesPlugInBase +{ + /// + public override string DataInitializationKey => Version095d.DataInitialization.Id; +} diff --git a/src/Persistence/Initialization/Updates/AddPartyExperienceBonusAttributesPlugInBase.cs b/src/Persistence/Initialization/Updates/AddPartyExperienceBonusAttributesPlugInBase.cs new file mode 100644 index 0000000000..023a014ec1 --- /dev/null +++ b/src/Persistence/Initialization/Updates/AddPartyExperienceBonusAttributesPlugInBase.cs @@ -0,0 +1,48 @@ +// +// Licensed under the MIT License. See LICENSE file in the project root for full license information. +// + +namespace MUnique.OpenMU.Persistence.Initialization.Updates; + +using MUnique.OpenMU.AttributeSystem; +using MUnique.OpenMU.DataModel.Configuration; + +/// +/// This update adds the attributes which define the party experience, and assigns their default values +/// to the global base attributes. +/// +public abstract class AddPartyExperienceBonusAttributesPlugInBase : UpdatePlugInBase +{ + /// + public override string Name => Properties.PlugInResources.AddPartyExperienceBonusAttributesPlugInBase_Name; + + /// + public override string Description => Properties.PlugInResources.AddPartyExperienceBonusAttributesPlugInBase_Description; + + /// + public override bool IsMandatory => true; + + /// + public override DateTime CreatedAt => new(2026, 11, 23, 12, 0, 0, DateTimeKind.Utc); + + /// + protected override ValueTask ApplyAsync(IContext context, GameConfiguration gameConfiguration) + { + foreach (var (stat, defaultValue) in PartyExperienceBonusDefaults.Values) + { + var definition = gameConfiguration.Attributes.FirstOrDefault(a => a.Id == stat.Id); + if (definition is null) + { + definition = context.CreateNew(stat.Id, stat.Designation, stat.Description); + gameConfiguration.Attributes.Add(definition); + } + + if (!gameConfiguration.GlobalBaseAttributeValues.Any(a => a.Definition?.Id == definition.Id)) + { + gameConfiguration.GlobalBaseAttributeValues.Add(context.CreateNew(defaultValue, definition)); + } + } + + return ValueTask.CompletedTask; + } +} diff --git a/src/Persistence/Initialization/Updates/AddPartyExperienceBonusAttributesPlugInSeason6.cs b/src/Persistence/Initialization/Updates/AddPartyExperienceBonusAttributesPlugInSeason6.cs new file mode 100644 index 0000000000..3de282cb8c --- /dev/null +++ b/src/Persistence/Initialization/Updates/AddPartyExperienceBonusAttributesPlugInSeason6.cs @@ -0,0 +1,20 @@ +// +// Licensed under the MIT License. See LICENSE file in the project root for full license information. +// + +namespace MUnique.OpenMU.Persistence.Initialization.Updates; + +using System.Runtime.InteropServices; +using MUnique.OpenMU.PlugIns; + +/// +/// This update adds the party experience bonus attributes for version season 6. +/// +[PlugIn] +[Display(Name = nameof(MUnique.OpenMU.Persistence.Initialization.Properties.PlugInResources.AddPartyExperienceBonusAttributesPlugInBase_Name), Description = nameof(MUnique.OpenMU.Persistence.Initialization.Properties.PlugInResources.AddPartyExperienceBonusAttributesPlugInBase_Description), ResourceType = typeof(MUnique.OpenMU.Persistence.Initialization.Properties.PlugInResources))] +[Guid("A4D7F25D-5836-4A90-ADA2-4C09014E2212")] +public class AddPartyExperienceBonusAttributesPlugInSeason6 : AddPartyExperienceBonusAttributesPlugInBase +{ + /// + public override string DataInitializationKey => VersionSeasonSix.DataInitialization.Id; +} diff --git a/tests/MUnique.OpenMU.Persistence.Initialization.Tests/PartyExperienceBonusAttributesTest.cs b/tests/MUnique.OpenMU.Persistence.Initialization.Tests/PartyExperienceBonusAttributesTest.cs new file mode 100644 index 0000000000..d0c841a6c7 --- /dev/null +++ b/tests/MUnique.OpenMU.Persistence.Initialization.Tests/PartyExperienceBonusAttributesTest.cs @@ -0,0 +1,145 @@ +// +// Licensed under the MIT License. See LICENSE file in the project root for full license information. +// + +namespace MUnique.OpenMU.Persistence.Initialization.Tests; + +using Microsoft.Extensions.Logging.Abstractions; +using MUnique.OpenMU.AttributeSystem; +using MUnique.OpenMU.DataModel.Configuration; +using MUnique.OpenMU.GameLogic.Attributes; +using MUnique.OpenMU.Persistence.Initialization.Updates; +using MUnique.OpenMU.Persistence.InMemory; + +/// +/// Tests that the party experience attributes and their default values are available in the configuration. +/// +[TestFixture] +internal class PartyExperienceBonusAttributesTest +{ + private static readonly (AttributeDefinition Attribute, float Value)[] ExpectedValues = + [ + (Stats.PartyExperienceMultiplier, 1.05f), + (Stats.SetPartyExperienceBonus, 0f), + ]; + + /// + /// Tests that a new database contains the attributes with their default values. + /// + /// The game version of the data initialization. + /// The async task. + [TestCase("075")] + [TestCase("095d")] + [TestCase("Season6")] + public async Task NewDatabaseHasPartyExperienceBonusesAsync(string version) + { + var (context, gameConfiguration) = await CreateConfigurationAsync(version).ConfigureAwait(false); + using var _ = context; + + AssertDefaults(gameConfiguration); + } + + /// + /// Tests that the update adds the attributes and values to a database which was created before they existed, + /// and that applying it twice doesn't add them twice. + /// + /// The game version of the data initialization and the update. + /// The async task. + [TestCase("075")] + [TestCase("095d")] + [TestCase("Season6")] + public async Task UpdateAddsPartyExperienceBonusesAsync(string version) + { + var (context, gameConfiguration) = await CreateConfigurationAsync(version).ConfigureAwait(false); + using var _ = context; + RemovePartyExperienceBonuses(gameConfiguration); + + var update = CreateUpdate(version); + await update.ApplyUpdateAsync(context, gameConfiguration).ConfigureAwait(false); + AssertDefaults(gameConfiguration); + + await update.ApplyUpdateAsync(context, gameConfiguration).ConfigureAwait(false); + AssertDefaults(gameConfiguration); + } + + /// + /// Tests that the update doesn't change values which have been customized by the server owner. + /// + /// The async task. + [Test] + public async Task UpdateKeepsCustomizedValuesAsync() + { + var (context, gameConfiguration) = await CreateConfigurationAsync("Season6").ConfigureAwait(false); + using var _ = context; + var customizedValues = new[] + { + (Stats.PartyExperienceMultiplier, 1.1f), + (Stats.SetPartyExperienceBonus, 0.5f), + }; + + foreach (var (attribute, value) in customizedValues) + { + var definition = gameConfiguration.Attributes.Single(a => a.Id == attribute.Id); + gameConfiguration.GlobalBaseAttributeValues.Remove(gameConfiguration.GlobalBaseAttributeValues.Single(a => a.Definition?.Id == definition.Id)); + gameConfiguration.GlobalBaseAttributeValues.Add(context.CreateNew(value, definition)); + } + + await new AddPartyExperienceBonusAttributesPlugInSeason6().ApplyUpdateAsync(context, gameConfiguration).ConfigureAwait(false); + + foreach (var (attribute, value) in customizedValues) + { + var values = gameConfiguration.GlobalBaseAttributeValues.Where(a => a.Definition?.Id == attribute.Id).ToList(); + Assert.That(values, Has.Count.EqualTo(1), $"Value of {attribute.Designation}"); + Assert.That(values[0].Value, Is.EqualTo(value), $"Value of {attribute.Designation}"); + } + } + + private static void AssertDefaults(GameConfiguration gameConfiguration) + { + foreach (var (attribute, value) in ExpectedValues) + { + Assert.That(gameConfiguration.Attributes.Count(a => a.Id == attribute.Id), Is.EqualTo(1), $"Attribute {attribute.Designation}"); + var values = gameConfiguration.GlobalBaseAttributeValues.Where(a => a.Definition?.Id == attribute.Id).ToList(); + Assert.That(values, Has.Count.EqualTo(1), $"Value of {attribute.Designation}"); + Assert.That(values[0].Value, Is.EqualTo(value), $"Value of {attribute.Designation}"); + } + } + + private static void RemovePartyExperienceBonuses(GameConfiguration gameConfiguration) + { + foreach (var (attribute, _) in ExpectedValues) + { + gameConfiguration.GlobalBaseAttributeValues.Remove(gameConfiguration.GlobalBaseAttributeValues.Single(a => a.Definition?.Id == attribute.Id)); + gameConfiguration.Attributes.Remove(gameConfiguration.Attributes.Single(a => a.Id == attribute.Id)); + } + } + + private static AddPartyExperienceBonusAttributesPlugInBase CreateUpdate(string version) + { + return version switch + { + "075" => new AddPartyExperienceBonusAttributesPlugIn075(), + "095d" => new AddPartyExperienceBonusAttributesPlugIn095d(), + "Season6" => new AddPartyExperienceBonusAttributesPlugInSeason6(), + _ => throw new ArgumentException($"Unknown version {version}", nameof(version)), + }; + } + + private static async Task<(IContext Context, GameConfiguration GameConfiguration)> CreateConfigurationAsync(string version) + { + var contextProvider = new InMemoryPersistenceContextProvider(); + DataInitializationBase dataInitialization = version switch + { + "075" => new Version075.DataInitialization(contextProvider, new NullLoggerFactory()), + "095d" => new Version095d.DataInitialization(contextProvider, new NullLoggerFactory()), + "Season6" => new VersionSeasonSix.DataInitialization(contextProvider, new NullLoggerFactory()), + _ => throw new ArgumentException($"Unknown version {version}", nameof(version)), + }; + + await dataInitialization.CreateInitialDataAsync(1, true).ConfigureAwait(false); + + var context = contextProvider.CreateNewContext(); + var gameConfiguration = (await context.GetAsync().ConfigureAwait(false)).First(); + return (context, gameConfiguration); + } +} diff --git a/tests/MUnique.OpenMU.Tests/Party/PartyExperienceBonusTest.cs b/tests/MUnique.OpenMU.Tests/Party/PartyExperienceBonusTest.cs new file mode 100644 index 0000000000..20f22ca909 --- /dev/null +++ b/tests/MUnique.OpenMU.Tests/Party/PartyExperienceBonusTest.cs @@ -0,0 +1,290 @@ +// +// Licensed under the MIT License. See LICENSE file in the project root for full license information. +// + +namespace MUnique.OpenMU.Tests; + +using MUnique.OpenMU.AttributeSystem; +using MUnique.OpenMU.GameLogic; +using MUnique.OpenMU.GameLogic.Attributes; +using CharacterClass = MUnique.OpenMU.Persistence.BasicModel.CharacterClass; + +/// +/// Tests the configurable experience bonus of parties. +/// +[TestFixture] +public class PartyExperienceBonusTest +{ + // The values which the data initializations of all versions configure. + private static readonly (AttributeDefinition Attribute, float Value)[] DefaultBonuses = + [ + (Stats.PartyExperienceMultiplier, 1.05f), + (Stats.SetPartyExperienceBonus, 0f), + ]; + + private IGameContext _gameContext = null!; + private CharacterClass _darkWizard = null!; + private CharacterClass _grandMaster = null!; + private CharacterClass _darkKnight = null!; + private CharacterClass _fairyElf = null!; + private CharacterClass _magicGladiator = null!; + private CharacterClass _darkLord = null!; + + /// + /// Sets up a game context with two generations of the dark wizard and dark knight lines, and further first generation classes. + /// + [SetUp] + public void SetUp() + { + this._gameContext = GameContextTestHelper.CreateGameContext(); + this._grandMaster = new CharacterClass { Number = 2 }; + this._darkWizard = new CharacterClass { Number = 0, NextGenerationClass = this._grandMaster }; + var blademaster = new CharacterClass { Number = 18 }; + this._darkKnight = new CharacterClass { Number = 16, NextGenerationClass = blademaster }; + this._fairyElf = new CharacterClass { Number = 32 }; + this._magicGladiator = new CharacterClass { Number = 48 }; + this._darkLord = new CharacterClass { Number = 64 }; + + var classes = this._gameContext.Configuration.CharacterClasses; + classes.Add(this._darkWizard); + classes.Add(this._grandMaster); + classes.Add(this._darkKnight); + classes.Add(blademaster); + classes.Add(this._fairyElf); + classes.Add(this._magicGladiator); + classes.Add(this._darkLord); + } + + /// + /// Tests that a single player doesn't get a party bonus. + /// + /// The async task. + [Test] + public async ValueTask SinglePlayerGetsNoBonusAsync() + { + var members = await this.CreateMembersAsync(this._darkWizard).ConfigureAwait(false); + + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(1.0)); + } + + /// + /// Tests that the default configuration, which is the one of the data initializations, keeps the party experience + /// of the original implementation: 1.05^(n-1). The calculated multiplier needs to be exactly the same + /// as the one of Math.Pow(1.05, memberCount - 1). + /// + /// The member count. + /// The expected multiplier, as literal. + /// The async task. + [TestCase(2, 1.05)] + [TestCase(3, 1.1025)] + [TestCase(4, 1.157625)] + [TestCase(5, 1.21550625)] + public async ValueTask DefaultsKeepCompoundingPartyExperienceAsync(int memberCount, double expectedMultiplier) + { + var members = await this.CreateMembersAsync(Enumerable.Repeat(this._darkWizard, memberCount).ToArray()).ConfigureAwait(false); + + Assert.That(PartyExperienceBonus.IsSetParty(members), Is.False); + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(Math.Pow(1.05, memberCount - 1))); + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(expectedMultiplier).Within(0.000000001)); + } + + /// + /// Tests that parties which are bigger than five members still get the bonus for every member. + /// + /// The async task. + [Test] + public async ValueTask DefaultsKeepCompoundingForBigPartiesAsync() + { + var members = await this.CreateMembersAsync(Enumerable.Repeat(this._darkWizard, 6).ToArray()).ConfigureAwait(false); + + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(Math.Pow(1.05, 5))); + } + + /// + /// Tests that the default configuration doesn't give set parties an additional bonus, because the set party bonus is 0. + /// + /// The member count. + /// The async task. + [TestCase(3)] + [TestCase(4)] + [TestCase(5)] + public async ValueTask DefaultsGiveSetPartiesNoExtraBonusAsync(int memberCount) + { + var members = await this.CreateMembersAsync(this.GetDifferentClasses(memberCount)).ConfigureAwait(false); + + Assert.That(PartyExperienceBonus.IsSetParty(members), Is.True); + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(Math.Pow(1.05, memberCount - 1))); + } + + /// + /// Tests that the multiplier is taken from the configured attribute value, and not hard-coded. + /// + /// The configured party experience multiplier. + /// The member count. + /// The expected multiplier. + /// The async task. + [TestCase(1.1f, 2, 1.1)] + [TestCase(1.1f, 3, 1.21)] + [TestCase(1.02f, 5, 1.08243216)] + [TestCase(1.0f, 5, 1.0)] + public async ValueTask ConfiguredPartyMultiplierIsUsedAsync(float partyMultiplier, int memberCount, double expectedMultiplier) + { + var members = await this.CreateMembersAsync(false, Enumerable.Repeat(this._darkWizard, memberCount).ToArray()).ConfigureAwait(false); + members[0].Attributes!.AddElement(new SimpleElement(partyMultiplier, AggregateType.AddRaw), Stats.PartyExperienceMultiplier); + + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(expectedMultiplier).Within(0.000001)); + } + + /// + /// Tests that a party multiplier of zero or less disables the party bonus. + /// + /// The configured party experience multiplier. + /// The async task. + [TestCase(0f)] + [TestCase(-1.05f)] + public async ValueTask NonPositivePartyMultiplierDisablesBonusAsync(float partyMultiplier) + { + var members = await this.CreateMembersAsync(false, this._darkWizard, this._darkWizard, this._darkWizard).ConfigureAwait(false); + members[0].Attributes!.AddElement(new SimpleElement(partyMultiplier, AggregateType.AddRaw), Stats.PartyExperienceMultiplier); + + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(1.0)); + } + + /// + /// Tests that a party gets no bonus if the attributes are not configured at all. + /// + /// The async task. + [Test] + public async ValueTask NotConfiguredBonusIsNoBonusAsync() + { + var members = await this.CreateMembersAsync(false, this._darkWizard, this._darkKnight, this._fairyElf).ConfigureAwait(false); + + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(1.0)); + } + + /// + /// Tests that the set party bonus is added to the multiplier of a set party, if it's configured. + /// + /// The member count. + /// The async task. + [TestCase(3)] + [TestCase(4)] + [TestCase(5)] + public async ValueTask SetPartyBonusIsAddedAsync(int memberCount) + { + var members = await this.CreateMembersAsync(this.GetDifferentClasses(memberCount)).ConfigureAwait(false); + members[0].Attributes!.AddElement(new SimpleElement(0.02f, AggregateType.AddRaw), Stats.SetPartyExperienceBonus); + + Assert.That(PartyExperienceBonus.IsSetParty(members), Is.True); + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(Math.Pow(1.05, memberCount - 1) + 0.02).Within(0.000001)); + } + + /// + /// Tests that the set party bonus is also added for parties which are bigger than five members. + /// + /// The async task. + [Test] + public async ValueTask SetPartyBonusIsAddedForBigPartiesAsync() + { + var members = await this.CreateMembersAsync( + this._darkWizard, + this._darkKnight, + this._fairyElf, + this._magicGladiator, + this._darkLord, + new CharacterClass { Number = 80 }).ConfigureAwait(false); + members[0].Attributes!.AddElement(new SimpleElement(0.02f, AggregateType.AddRaw), Stats.SetPartyExperienceBonus); + + Assert.That(PartyExperienceBonus.IsSetParty(members), Is.True); + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(Math.Pow(1.05, 5) + 0.02).Within(0.000001)); + } + + /// + /// Tests that a non-positive set party bonus is ignored and doesn't reduce the experience. + /// + /// The configured set party bonus. + /// The async task. + [TestCase(0f)] + [TestCase(-0.02f)] + public async ValueTask NonPositiveSetPartyBonusIsIgnoredAsync(float setPartyBonus) + { + var members = await this.CreateMembersAsync(this._darkWizard, this._darkKnight, this._fairyElf).ConfigureAwait(false); + members[0].Attributes!.AddElement(new SimpleElement(setPartyBonus, AggregateType.AddRaw), Stats.SetPartyExperienceBonus); + + Assert.That(PartyExperienceBonus.IsSetParty(members), Is.True); + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(Math.Pow(1.05, 2))); + } + + /// + /// Tests that the set party bonus is not added to parties with less than three members, even if they have different classes. + /// + /// The async task. + [Test] + public async ValueTask TwoDifferentClassesAreNoSetPartyAsync() + { + var members = await this.CreateMembersAsync(this._darkWizard, this._darkKnight).ConfigureAwait(false); + members[0].Attributes!.AddElement(new SimpleElement(0.02f, AggregateType.AddRaw), Stats.SetPartyExperienceBonus); + + Assert.That(PartyExperienceBonus.IsSetParty(members), Is.False); + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(1.05)); + } + + /// + /// Tests that the members of a set party can be of a different generation of their class line. + /// + /// The async task. + [Test] + public async ValueTask SetPartyWithEvolvedClassesAsync() + { + var members = await this.CreateMembersAsync(this._grandMaster, this._darkKnight, this._fairyElf).ConfigureAwait(false); + + Assert.That(PartyExperienceBonus.IsSetParty(members), Is.True); + } + + /// + /// Tests that two members of the same class line, even of different generations, are no set party, + /// so they don't get the set party bonus. + /// + /// The async task. + [Test] + public async ValueTask SameClassLineIsNoSetPartyAsync() + { + var members = await this.CreateMembersAsync(this._darkWizard, this._grandMaster, this._fairyElf).ConfigureAwait(false); + members[0].Attributes!.AddElement(new SimpleElement(0.02f, AggregateType.AddRaw), Stats.SetPartyExperienceBonus); + + Assert.That(PartyExperienceBonus.IsSetParty(members), Is.False); + Assert.That(PartyExperienceBonus.GetMultiplier(members), Is.EqualTo(Math.Pow(1.05, 2))); + } + + private CharacterClass[] GetDifferentClasses(int count) + { + var classes = new[] { this._darkWizard, this._darkKnight, this._fairyElf, this._magicGladiator, this._darkLord }; + return classes.Take(count).ToArray(); + } + + private ValueTask> CreateMembersAsync(params CharacterClass[] classes) + { + return this.CreateMembersAsync(true, classes); + } + + private async ValueTask> CreateMembersAsync(bool addDefaultBonuses, params CharacterClass[] classes) + { + var result = new List(classes.Length); + foreach (var characterClass in classes) + { + var player = await PlayerTestHelper.CreatePlayerAsync(this._gameContext).ConfigureAwait(false); + player.SelectedCharacter!.CharacterClass = characterClass; + if (addDefaultBonuses) + { + foreach (var (attribute, value) in DefaultBonuses) + { + player.Attributes!.AddElement(new SimpleElement(value, AggregateType.AddRaw), attribute); + } + } + + result.Add(player); + } + + return result; + } +}