|
| 1 | +using System; |
| 2 | +using Moq; |
| 3 | +using NUnit.Framework; |
| 4 | +using Uchu.Core; |
| 5 | +using Uchu.Core.Client; |
| 6 | +using Uchu.World.Systems.Missions; |
| 7 | + |
| 8 | +namespace Uchu.World.Test.Objects.Components.Server |
| 9 | +{ |
| 10 | + public class MissionGiverComponentTest |
| 11 | + { |
| 12 | + /// <summary> |
| 13 | + /// Mission giver component used with the tests. |
| 14 | + /// </summary> |
| 15 | + private MissionGiverComponent _missionGiverComponent; |
| 16 | + |
| 17 | + /// <summary> |
| 18 | + /// Player mission inventory used with the tests. |
| 19 | + /// </summary> |
| 20 | + private MissionInventoryComponent _missionInventoryComponent; |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// Mission NPC component used with the tests. |
| 24 | + /// </summary> |
| 25 | + private MissionNPCComponent _missionNpcComponent; |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Sets up the tests. |
| 29 | + /// </summary> |
| 30 | + [SetUp] |
| 31 | + public void SetUp() |
| 32 | + { |
| 33 | + this._missionGiverComponent = new MissionGiverComponent(); |
| 34 | + this._missionInventoryComponent = new MissionInventoryComponent(); |
| 35 | + this._missionNpcComponent = new MissionNPCComponent() |
| 36 | + { |
| 37 | + AcceptsMission = true, |
| 38 | + OffersMission = true, |
| 39 | + }; |
| 40 | + } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Tests GetIdMissionToOffer with no stored missions. |
| 44 | + /// </summary> |
| 45 | + [Test] |
| 46 | + public void TestGetIdMissionToOfferEmpty() |
| 47 | + { |
| 48 | + this._missionGiverComponent.Missions = Array.Empty<(Missions, MissionNPCComponent)>(); |
| 49 | + Assert.AreEqual(0, this._missionGiverComponent.GetIdMissionToOffer(this._missionInventoryComponent)); |
| 50 | + } |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Tests GetIdMissionToOffer with a stored mission with the default id. |
| 54 | + /// </summary> |
| 55 | + [Test] |
| 56 | + public void TestGetIdMissionToOfferDefaultMissionId() |
| 57 | + { |
| 58 | + this._missionGiverComponent.Missions = new[] |
| 59 | + { |
| 60 | + (new Missions() { Id = default, }, this._missionNpcComponent) |
| 61 | + }; |
| 62 | + Assert.AreEqual(0, this._missionGiverComponent.GetIdMissionToOffer(this._missionInventoryComponent)); |
| 63 | + } |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Tests GetIdMissionToOffer with a stored mission but missions aren't offered. |
| 67 | + /// </summary> |
| 68 | + [Test] |
| 69 | + public void TestGetIdMissionToOfferDoesntOfferMission() |
| 70 | + { |
| 71 | + this._missionNpcComponent.OffersMission = false; |
| 72 | + this._missionGiverComponent.Missions = new[] |
| 73 | + { |
| 74 | + (new Missions() { Id = 1, }, this._missionNpcComponent) |
| 75 | + }; |
| 76 | + Assert.AreEqual(0, this._missionGiverComponent.GetIdMissionToOffer(this._missionInventoryComponent)); |
| 77 | + } |
| 78 | + |
| 79 | + /// <summary> |
| 80 | + /// Tests GetIdMissionToOffer with a mission ready to complete taking priority. |
| 81 | + /// </summary> |
| 82 | + [Test] |
| 83 | + public void TestGetIdMissionToOfferReadyToCompletePriority() |
| 84 | + { |
| 85 | + var mockMission1 = new Mock<MissionInstance>(1, null); |
| 86 | + mockMission1.SetupGet(mission => mission.State).Returns(MissionState.Available); |
| 87 | + var mockMission2 = new Mock<MissionInstance>(2, null); |
| 88 | + mockMission2.SetupGet(mission => mission.State).Returns(MissionState.ReadyToComplete); |
| 89 | + |
| 90 | + this._missionGiverComponent.Missions = new[] |
| 91 | + { |
| 92 | + (new Missions() { Id = 1, }, this._missionNpcComponent), |
| 93 | + (new Missions() { Id = 2, }, this._missionNpcComponent), |
| 94 | + }; |
| 95 | + this._missionInventoryComponent.AddTestMission(mockMission1.Object); |
| 96 | + this._missionInventoryComponent.AddTestMission(mockMission2.Object); |
| 97 | + Assert.AreEqual(2, this._missionGiverComponent.GetIdMissionToOffer(this._missionInventoryComponent)); |
| 98 | + } |
| 99 | + |
| 100 | + /// <summary> |
| 101 | + /// Tests GetIdMissionToOffer with a mission active taking priority over available. |
| 102 | + /// </summary> |
| 103 | + [Test] |
| 104 | + public void TestGetIdMissionToOfferActivePriority() |
| 105 | + { |
| 106 | + var mockMission1 = new Mock<MissionInstance>(1, null); |
| 107 | + mockMission1.SetupGet(mission => mission.State).Returns(MissionState.Available); |
| 108 | + var mockMission2 = new Mock<MissionInstance>(2, null); |
| 109 | + mockMission2.SetupGet(mission => mission.State).Returns(MissionState.Active); |
| 110 | + var mockMission3 = new Mock<MissionInstance>(1, null); |
| 111 | + mockMission3.SetupGet(mission => mission.State).Returns(MissionState.Available); |
| 112 | + |
| 113 | + this._missionGiverComponent.Missions = new[] |
| 114 | + { |
| 115 | + (new Missions() { Id = 1, }, this._missionNpcComponent), |
| 116 | + (new Missions() { Id = 2, }, this._missionNpcComponent), |
| 117 | + (new Missions() { Id = 3, }, this._missionNpcComponent), |
| 118 | + }; |
| 119 | + this._missionInventoryComponent.AddTestMission(mockMission1.Object); |
| 120 | + this._missionInventoryComponent.AddTestMission(mockMission2.Object); |
| 121 | + this._missionInventoryComponent.AddTestMission(mockMission3.Object); |
| 122 | + Assert.AreEqual(2, this._missionGiverComponent.GetIdMissionToOffer(this._missionInventoryComponent)); |
| 123 | + } |
| 124 | + |
| 125 | + /// <summary> |
| 126 | + /// Tests GetIdMissionToOffer with a mission completed active (repeating) taking priority over available. |
| 127 | + /// </summary> |
| 128 | + [Test] |
| 129 | + public void TestGetIdMissionToOfferCompletedActivePriority() |
| 130 | + { |
| 131 | + var mockMission1 = new Mock<MissionInstance>(1, null); |
| 132 | + mockMission1.SetupGet(mission => mission.State).Returns(MissionState.Available); |
| 133 | + var mockMission2 = new Mock<MissionInstance>(2, null); |
| 134 | + mockMission2.SetupGet(mission => mission.State).Returns(MissionState.CompletedActive); |
| 135 | + var mockMission3 = new Mock<MissionInstance>(1, null); |
| 136 | + mockMission3.SetupGet(mission => mission.State).Returns(MissionState.Available); |
| 137 | + |
| 138 | + this._missionGiverComponent.Missions = new[] |
| 139 | + { |
| 140 | + (new Missions() { Id = 1, }, this._missionNpcComponent), |
| 141 | + (new Missions() { Id = 2, }, this._missionNpcComponent), |
| 142 | + (new Missions() { Id = 3, }, this._missionNpcComponent), |
| 143 | + }; |
| 144 | + this._missionInventoryComponent.AddTestMission(mockMission1.Object); |
| 145 | + this._missionInventoryComponent.AddTestMission(mockMission2.Object); |
| 146 | + this._missionInventoryComponent.AddTestMission(mockMission3.Object); |
| 147 | + Assert.AreEqual(2, this._missionGiverComponent.GetIdMissionToOffer(this._missionInventoryComponent)); |
| 148 | + } |
| 149 | + |
| 150 | + /// <summary> |
| 151 | + /// Tests GetIdMissionToOffer with an empty random mission pool. |
| 152 | + /// </summary> |
| 153 | + [Test] |
| 154 | + public void TestGetIdMissionToOfferEmptyRandomPool() |
| 155 | + { |
| 156 | + var mockMission = new Mock<MissionInstance>(1, null); |
| 157 | + mockMission.SetupGet(mission => mission.State).Returns(MissionState.Available); |
| 158 | + |
| 159 | + this._missionGiverComponent.Missions = new[] |
| 160 | + { |
| 161 | + (new Missions() |
| 162 | + { |
| 163 | + Id = 1, |
| 164 | + RandomPool = "", |
| 165 | + }, this._missionNpcComponent), |
| 166 | + }; |
| 167 | + this._missionInventoryComponent.AddTestMission(mockMission.Object); |
| 168 | + Assert.AreEqual(1, this._missionGiverComponent.GetIdMissionToOffer(this._missionInventoryComponent)); |
| 169 | + } |
| 170 | + |
| 171 | + /// <summary> |
| 172 | + /// Tests GetIdMissionToOffer with a random mission pool. |
| 173 | + /// </summary> |
| 174 | + [Test] |
| 175 | + public void TestGetIdMissionToOfferRandomPool() |
| 176 | + { |
| 177 | + var mockMission = new Mock<MissionInstance>(1, null); |
| 178 | + mockMission.SetupGet(mission => mission.State).Returns(MissionState.Available); |
| 179 | + |
| 180 | + this._missionGiverComponent.Missions = new[] |
| 181 | + { |
| 182 | + (new Missions() |
| 183 | + { |
| 184 | + Id = 1, |
| 185 | + IsRandom = true, |
| 186 | + RandomPool = "2,3", |
| 187 | + }, this._missionNpcComponent), |
| 188 | + }; |
| 189 | + this._missionInventoryComponent.AddTestMission(mockMission.Object); |
| 190 | + var randomMission = this._missionGiverComponent.GetIdMissionToOffer(this._missionInventoryComponent); |
| 191 | + Assert.IsTrue(randomMission == 2 || randomMission == 3); |
| 192 | + } |
| 193 | + } |
| 194 | +} |
| 195 | + |
0 commit comments