|
6 | 6 | namespace Mythril.Tests; |
7 | 7 |
|
8 | 8 | [TestClass] |
9 | | -public class ResourceManagerTests |
| 9 | +public class ResourceManagerTests : ResourceManagerTestBase |
10 | 10 | { |
11 | | - private ResourceManager? _resourceManager; |
12 | | - private Quests? _quests; |
13 | | - private QuestDetails? _questDetails; |
14 | | - private Cadences? _cadences; |
15 | | - private GameStore? _gameStore; |
16 | | - |
17 | | - [TestInitialize] |
18 | | - public void Setup() |
19 | | - { |
20 | | - TestContentLoader.Load(); |
21 | | - var items = ContentHost.GetContent<Items>(); |
22 | | - _quests = ContentHost.GetContent<Quests>(); |
23 | | - _questDetails = ContentHost.GetContent<QuestDetails>(); |
24 | | - _cadences = ContentHost.GetContent<Cadences>(); |
25 | | - |
26 | | - _gameStore = new GameStore(); |
27 | | - var inventory = new InventoryManager(_gameStore); |
28 | | - var junctionManager = new JunctionManager(_gameStore, inventory, ContentHost.GetContent<StatAugments>(), _cadences); |
29 | | - var pathfinding = new PathfindingService( |
30 | | - ContentHost.GetContent<Locations>(), |
31 | | - _quests!, |
32 | | - ContentHost.GetContent<QuestUnlocks>(), |
33 | | - _questDetails!, |
34 | | - _cadences!, |
35 | | - ContentHost.GetContent<QuestToCadenceUnlocks>() |
36 | | - ); |
37 | | - _resourceManager = new ResourceManager( |
38 | | - _gameStore, |
39 | | - items, |
40 | | - _quests!, |
41 | | - ContentHost.GetContent<QuestUnlocks>(), |
42 | | - ContentHost.GetContent<QuestToCadenceUnlocks>(), |
43 | | - _questDetails, |
44 | | - _cadences, |
45 | | - ContentHost.GetContent<Locations>(), |
46 | | - junctionManager, |
47 | | - inventory, |
48 | | - ContentHost.GetContent<ItemRefinements>(), |
49 | | - pathfinding); |
50 | | - _resourceManager.Initialize(); |
51 | | - } |
52 | | - |
53 | | - [TestMethod] |
54 | | - public void ResourceManager_ReevaluateActiveQuests_Works() |
55 | | - { |
56 | | - var character = _resourceManager!.Characters[0]; |
57 | | - var scholar = _cadences!.All.First(c => c.Name == "Scholar"); |
58 | | - _resourceManager.UnlockCadence(scholar); |
59 | | - _resourceManager.UnlockAbility("Scholar", "Logistics II"); |
60 | | - _resourceManager.JunctionManager.AssignCadence(scholar, character, _resourceManager.UnlockedAbilities); |
61 | | - |
62 | | - // Initial limit is 1. With Logistics II, it should be 3. |
63 | | - Assert.AreEqual(3, _resourceManager.GetTaskLimit(character)); |
64 | | - |
65 | | - var q1 = new QuestData(_quests!.All.First(q => q.Name == "Hunt Goblins"), _questDetails![_quests.All.First(q => q.Name == "Hunt Goblins")]); |
66 | | - var q2 = new QuestData(_quests.All.First(q => q.Name == "Hunt Bats"), _questDetails[_quests.All.First(q => q.Name == "Hunt Bats")]); |
67 | | - var q3 = new QuestData(_quests.All.First(q => q.Name == "Hunt Spiders"), _questDetails[_quests.All.First(q => q.Name == "Hunt Spiders")]); |
68 | | - |
69 | | - _resourceManager.StartQuest(q1, character); |
70 | | - _resourceManager.StartQuest(q2, character); |
71 | | - _resourceManager.StartQuest(q3, character); |
72 | | - |
73 | | - Assert.AreEqual(3, _resourceManager.ActiveQuests.Count); |
74 | | - |
75 | | - // Remove assignment |
76 | | - _resourceManager.JunctionManager.Unassign(scholar, _resourceManager.UnlockedAbilities); |
77 | | - |
78 | | - // Manual call or via event |
79 | | - _resourceManager.ReevaluateActiveQuests(character); |
80 | | - |
81 | | - Assert.AreEqual(1, _resourceManager.ActiveQuests.Count); |
82 | | - } |
83 | | - |
84 | | - [TestMethod] |
85 | | - public void ReevaluateActiveQuests_CancelsOnRequirementFailure() |
86 | | - { |
87 | | - var character = _resourceManager!.Characters[0]; |
88 | | - var recruit = _cadences!.All.First(c => c.Name == "Recruit"); |
89 | | - _resourceManager.UnlockCadence(recruit); |
90 | | - _resourceManager.UnlockAbility("Recruit", "J-Str"); |
91 | | - _resourceManager.JunctionManager.AssignCadence(recruit, character, _resourceManager.UnlockedAbilities); |
92 | | - |
93 | | - // Add 100 Magic I to inventory for Strength junction |
94 | | - var magicI = new Item("Magic I", "Magic", ItemType.Spell); |
95 | | - _resourceManager.Inventory.Add(magicI, 100); |
96 | | - _resourceManager.JunctionManager.JunctionMagic(character, new Stat("Strength", ""), magicI, _resourceManager.UnlockedAbilities); |
97 | | - |
98 | | - // Verify strength > 10 (base 10 + 100/10 = 20) |
99 | | - Assert.IsTrue(_resourceManager.JunctionManager.GetStatValue(character, "Strength") >= 20); |
100 | | - |
101 | | - // Create quest with Strength 15 requirement |
102 | | - var quest = new Quest("Str Quest", "Requires 15 Str"); |
103 | | - var detail = new QuestDetail(10, [], [], QuestType.Recurring, RequiredStats: new Dictionary<string, int> { { "Strength", 15 } }); |
104 | | - var questData = new QuestData(quest, detail); |
105 | | - |
106 | | - _resourceManager.StartQuest(questData, character); |
107 | | - Assert.AreEqual(1, _resourceManager.ActiveQuests.Count); |
108 | | - |
109 | | - // Remove magic junction -> strength falls to 10 |
110 | | - _resourceManager.JunctionManager.JunctionMagic(character, new Stat("Strength", ""), new Item(), _resourceManager.UnlockedAbilities); |
111 | | - Assert.AreEqual(10, _resourceManager.JunctionManager.GetStatValue(character, "Strength")); |
112 | | - |
113 | | - // Reevaluate should cancel the quest |
114 | | - _resourceManager.ReevaluateActiveQuests(character); |
115 | | - Assert.AreEqual(0, _resourceManager.ActiveQuests.Count); |
116 | | - } |
117 | | - |
118 | | - [TestMethod] |
119 | | - public void ReevaluateActiveQuests_CancelsRefinementOnAbilityLoss() |
120 | | - { |
121 | | - var character = _resourceManager!.Characters[0]; |
122 | | - var refData = _resourceManager.Refinements.GetRefinement("Refine Fire", "Basic Gem")!.Value; |
123 | | - |
124 | | - // Need ability to start refinement |
125 | | - var student = _cadences!.All.First(c => c.Name == "Student"); |
126 | | - _resourceManager.UnlockCadence(student); |
127 | | - _resourceManager.UnlockAbility("Student", "Refine Fire"); |
128 | | - _resourceManager.JunctionManager.AssignCadence(student, character, _resourceManager.UnlockedAbilities); |
129 | | - |
130 | | - _resourceManager.Inventory.Add(refData.InputItem, refData.Recipe.InputQuantity); |
131 | | - _resourceManager.StartQuest(refData, character); |
132 | | - |
133 | | - Assert.AreEqual(1, _resourceManager.ActiveQuests.Count); |
134 | | - |
135 | | - // Remove assignment -> loses ability |
136 | | - _resourceManager.JunctionManager.Unassign(student, _resourceManager.UnlockedAbilities); |
137 | | - |
138 | | - // Reevaluate should cancel the refinement |
139 | | - _resourceManager.ReevaluateActiveQuests(character); |
140 | | - Assert.AreEqual(0, _resourceManager.ActiveQuests.Count); |
141 | | - } |
142 | | - |
143 | | - [TestMethod] |
144 | | - public void ResourceManager_IsInProgress_Works() |
145 | | - { |
146 | | - var character = _resourceManager!.Characters[0]; |
147 | | - var q1 = new QuestData(_quests!.All.First(q => q.Name == "Hunt Goblins"), _questDetails![_quests.All.First(q => q.Name == "Hunt Goblins")]); |
148 | | - |
149 | | - Assert.IsFalse(_resourceManager.IsInProgress(q1)); |
150 | | - |
151 | | - _resourceManager.StartQuest(q1, character); |
152 | | - Assert.IsTrue(_resourceManager.IsInProgress(q1)); |
153 | | - } |
154 | | - |
155 | | - [TestMethod] |
156 | | - public void StartQuest_PreventsDuplicateInProgress() |
157 | | - { |
158 | | - var character = _resourceManager!.Characters[0]; |
159 | | - var prologue = new QuestData(_quests!.All.First(q => q.Name == "Prologue"), _questDetails![_quests.All.First(q => q.Name == "Prologue")]); |
160 | | - |
161 | | - _resourceManager.StartQuest(prologue, character); |
162 | | - Assert.AreEqual(1, _resourceManager.ActiveQuests.Count); |
163 | | - |
164 | | - _resourceManager.StartQuest(prologue, character); |
165 | | - Assert.AreEqual(1, _resourceManager.ActiveQuests.Count, "Should not start duplicate single-use quest."); |
166 | | - } |
167 | | - |
168 | | - [TestMethod] |
169 | | - public void StartQuest_PreventsCompletedSingleUse() |
170 | | - { |
171 | | - var character = _resourceManager!.Characters[0]; |
172 | | - var prologue = new QuestData(_quests!.All.First(q => q.Name == "Prologue"), _questDetails![_quests.All.First(q => q.Name == "Prologue")]); |
173 | | - |
174 | | - _resourceManager.ReceiveRewards(prologue).Wait(); |
175 | | - Assert.IsTrue(_resourceManager.GetCompletedQuests().Contains(prologue.Quest)); |
176 | | - |
177 | | - _resourceManager.StartQuest(prologue, character); |
178 | | - Assert.AreEqual(0, _resourceManager.ActiveQuests.Count, "Should not start completed single-use quest."); |
179 | | - } |
180 | | - |
181 | | - [TestMethod] |
182 | | - public void StartQuest_CadenceUnlock_Works() |
183 | | - { |
184 | | - var character = _resourceManager!.Characters[0]; |
185 | | - var arcanist = _cadences!.All.First(c => c.Name == "Arcanist"); |
186 | | - var unlock = arcanist.Abilities.First(a => a.Ability.Name == "Refine Ice"); |
187 | | - |
188 | | - // Find requirements for Refine Ice in Arcanist |
189 | | - foreach(var req in unlock.Requirements) _resourceManager.Inventory.Add(req.Item, req.Quantity); |
190 | | - |
191 | | - _resourceManager.StartQuest(unlock, character); |
192 | | - |
193 | | - Assert.AreEqual(1, _resourceManager.ActiveQuests.Count); |
194 | | - Assert.IsTrue(_resourceManager.ActiveQuests[0].Item is CadenceUnlock); |
195 | | - } |
196 | | - |
197 | 11 | [TestMethod] |
198 | 12 | public void ResourceManager_RefundCosts_CadenceUnlock_Works() |
199 | 13 | { |
|
0 commit comments