// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // namespace MUnique.OpenMU.Tests; using Moq; using MUnique.OpenMU.DataModel.Configuration; using MUnique.OpenMU.GameLogic; using MUnique.OpenMU.GameLogic.PlayerActions.Character; /// /// Tests the master level system. /// [TestFixture] public class MasterSystemTest { private readonly int _skillIdRank1 = 1; private readonly int _skillIdRank2 = 2; private readonly int _skillIdRank3 = 3; private Player _player = null!; private Skill _skillRank1 = null!; private Skill _skillRank2 = null!; private Skill _skillRank3 = null!; private AddMasterPointAction _addAction = null!; /// /// Setups the test data. /// [SetUp] public async Task SetupAsync() { this._player = await PlayerTestHelper.CreatePlayerAsync().ConfigureAwait(false); var context = this._player.GameContext; this._skillRank1 = this.CreateSkill(1, 1, 1, null, this._player.SelectedCharacter!.CharacterClass!); this._skillRank2 = this.CreateSkill(2, 2, 1, null, this._player.SelectedCharacter!.CharacterClass!); this._skillRank3 = this.CreateSkill((short)this._skillIdRank3, 3, 1, null, this._player.SelectedCharacter!.CharacterClass!); this._skillRank3.MasterDefinition!.MinimumLevel = 10; context.Configuration.Skills.Add(this._skillRank1); context.Configuration.Skills.Add(this._skillRank2); context.Configuration.Skills.Add(this._skillRank3); this._addAction = new AddMasterPointAction(); } /// /// Tests if the adding of master points failes because of insufficient level up points. /// [Test] public async Task FailedInsufficientLevelUpPointsAsync() { await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter!.LearnedSkills, Is.Empty); } /// /// Tests if the adding of master points succeeds. /// [Test] public async Task SucceededAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 1; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.LearnedSkills, Is.Not.Empty); } /// /// Tests if the adding of master points fails because of an insufficient reached skill rank. /// [Test] public async Task RankNotSufficientAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 1; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank2).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.LearnedSkills, Is.Empty); } /// /// Tests if the adding of master points fails because the skill of the previous rank does not have the required level 10. /// [Test] public async Task PreviousRankTooLowLevelAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 2; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); this._player.SelectedCharacter.LearnedSkills.First().Level = 9; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank2).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.LearnedSkills, Has.Count.EqualTo(1)); Assert.That(this._player.SelectedCharacter.LearnedSkills.First().Skill, Is.SameAs(this._skillRank1)); } /// /// Tests if the adding of master points succeeds because the skill of the previous rank has the required level 10. /// [Test] public async Task PreviousRankEnoughLevelsAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 2; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); this._player.SelectedCharacter.LearnedSkills.First().Level = 10; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank2).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.LearnedSkills, Has.Count.EqualTo(2)); Assert.That(this._player.SelectedCharacter.LearnedSkills.Any(l => l.Skill == this._skillRank1), Is.True); Assert.That(this._player.SelectedCharacter.LearnedSkills.Any(l => l.Skill == this._skillRank2), Is.True); } /// /// Tests if the adding of master points succeeds when a skill has a minium level of 10 and the character has enough master points. /// [Test] public async Task MinimumLevel10WithEnoughPointsAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 2; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); this._player.SelectedCharacter.LearnedSkills.First().Level = 10; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank2).ConfigureAwait(false); this._player.SelectedCharacter.LearnedSkills.Last().Level = 10; this._player.SelectedCharacter.MasterLevelUpPoints = 10; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank3).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.LearnedSkills, Has.Count.EqualTo(3)); Assert.That(this._player.SelectedCharacter.LearnedSkills.Any(l => l.Skill == this._skillRank3), Is.True); } /// /// Tests if the adding of master points succeeds when a skill has a minimum level of 10 and the character has not enough master points. /// [Test] public async Task MinimumLevel10WithoutEnoughPointsAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 2; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); this._player.SelectedCharacter.LearnedSkills.First().Level = 10; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank2).ConfigureAwait(false); this._player.SelectedCharacter.LearnedSkills.Last().Level = 10; this._player.SelectedCharacter.MasterLevelUpPoints = 9; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank3).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.LearnedSkills, Has.Count.EqualTo(2)); Assert.That(this._player.SelectedCharacter.LearnedSkills.Any(l => l.Skill == this._skillRank3), Is.False); } /// /// Tests if adding a point to a new skill results in the skill having level 1. /// [Test] public async Task AddedSkillGotLevelAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 1; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.LearnedSkills.First().Level, Is.EqualTo(1)); } /// /// Tests if adding a point to a skill increases its level by one. /// [Test] public async Task AddLevelToLearnedSkillAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 2; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.LearnedSkills.First().Level, Is.EqualTo(2)); } /// /// Tests if adding a point to a new skill fails because the required skill is not learned yet. /// [Test] public async Task RequiredSkillNotLearnedAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 2; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); this._player.SelectedCharacter.LearnedSkills.First().Level = 10; this._skillRank2.MasterDefinition!.RequiredMasterSkills.Add(new Skill()); await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank2).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.LearnedSkills, Has.Count.EqualTo(1)); Assert.That(this._player.SelectedCharacter.LearnedSkills.Any(l => l.Skill == this._skillRank2), Is.False); } /// /// Tests if adding a point to a new skill not fails because the required skill has been learned. /// [Test] public async Task RequiredSkillLearnedAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 2; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); this._player.SelectedCharacter.LearnedSkills.First().Level = 10; this._skillRank2.MasterDefinition!.RequiredMasterSkills.Add(this._skillRank1); await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank2).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.LearnedSkills, Has.Count.EqualTo(2)); Assert.That(this._player.SelectedCharacter.LearnedSkills.Any(l => l.Skill == this._skillRank2), Is.True); } /// /// Tests if adding master points decreases the available master points. /// [Test] public async Task MasterLevelUpPointDecreasedWhenLearnedAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 1; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.MasterLevelUpPoints, Is.EqualTo(0)); } /// /// Tests if a failed adding of master points does not decrease the available master points. /// [Test] public async Task MasterLevelUpPointNotDecreasedWhenNotLearnedAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 1; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank2).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.MasterLevelUpPoints, Is.EqualTo(1)); } /// /// Tests if the adding of master points fails when the maximum level (20) of a skill has been reached. /// [Test] public async Task MasterLevelMaximumReachedAsync() { this._player.SelectedCharacter!.MasterLevelUpPoints = 3; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); this._player.SelectedCharacter.LearnedSkills.First().Level = 19; await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); await this._addAction.AddMasterPointAsync(this._player, (ushort)this._skillIdRank1).ConfigureAwait(false); Assert.That(this._player.SelectedCharacter.LearnedSkills.First().Level, Is.EqualTo(20)); Assert.That(this._player.SelectedCharacter.MasterLevelUpPoints, Is.EqualTo(1)); } private Skill CreateSkill(short id, byte rank, byte rootId, Skill? requiredSkill, CharacterClass charClass) { var masterDef = new Mock(); masterDef.SetupAllProperties(); masterDef.Object.Rank = rank; masterDef.Object.MaximumLevel = 20; masterDef.Object.MinimumLevel = 1; masterDef.Object.Root = new MasterSkillRoot { Id = new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, rootId) }; masterDef.Setup(m => m.RequiredMasterSkills).Returns(new List()); if (requiredSkill != null) { masterDef.Object.RequiredMasterSkills.Add(requiredSkill); } var skill = new Mock(); skill.SetupAllProperties(); skill.Object.Number = id; skill.Setup(s => s.QualifiedCharacters).Returns(new List()); skill.Object.QualifiedCharacters.Add(charClass); skill.Object.MasterDefinition = masterDef.Object; return skill.Object; } }