|
3 | 3 | using System.Collections.Generic; |
4 | 4 | using System.Diagnostics; |
5 | 5 | using Gadgetlemage.DarkSouls; |
| 6 | +using System.Windows; |
6 | 7 |
|
7 | 8 | namespace Gadgetlemage |
8 | 9 | { |
@@ -37,14 +38,14 @@ public class Model : PHook |
37 | 38 | public DarkSouls.DarkSouls DarkSouls { get; set; } |
38 | 39 |
|
39 | 40 | /// <summary> |
40 | | - /// Whether or not the weapon has created |
| 41 | + /// Whether or not the game was loaded on the previous loop |
41 | 42 | /// </summary> |
42 | | - public bool WeaponCreated { get; set; } |
| 43 | + public bool PreviousLoaded { get; set; } |
43 | 44 |
|
44 | 45 | /// <summary> |
45 | | - /// Whether or not the shield was deleted |
| 46 | + /// Whether or not the black knight deaths has already been processed |
46 | 47 | /// </summary> |
47 | | - public bool ShieldDeleted { get; set; } |
| 48 | + public bool DeathProcessed { get; set; } |
48 | 49 |
|
49 | 50 | /// <summary> |
50 | 51 | /// List of all available black knight weapons |
@@ -72,7 +73,7 @@ public BlackKnightWeapon BlackKnightShield |
72 | 73 | { |
73 | 74 | get |
74 | 75 | { |
75 | | - return (Hooked) ? HOOKED_INTERVAL : UNHOOKED_INTERVAL; |
| 76 | + return (Hooked) ? HOOKED_INTERVAL : UNHOOKED_INTERVAL; |
76 | 77 | } |
77 | 78 | } |
78 | 79 |
|
@@ -148,8 +149,8 @@ public Model() : base(0, MIN_LIFE_SPAN, processSelector) // RefreshInterval at 0 |
148 | 149 | OnHooked += DarkSoulsProcess_OnHooked; |
149 | 150 | OnUnhooked += DarkSoulsProcess_OnUnhooked; |
150 | 151 |
|
151 | | - WeaponCreated = true; |
152 | | - ShieldDeleted = true; |
| 152 | + DeathProcessed = false; |
| 153 | + PreviousLoaded = false; |
153 | 154 | } |
154 | 155 |
|
155 | 156 | /// <summary> |
@@ -207,135 +208,72 @@ public void DeleteShield() |
207 | 208 | } |
208 | 209 |
|
209 | 210 | /// <summary> |
210 | | - /// Automatically delete the shield from the player's inventory |
| 211 | + /// Main update loop that will automatically create and delete black knight weapons if needed |
211 | 212 | /// </summary> |
212 | | - public void AutomaticallyRemoveShield() |
| 213 | + /// <param name="createWeapon">If it should automatically create the weapon</param> |
| 214 | + /// <param name="deleteShield">If it should automatically delete the shield</param> |
| 215 | + public void UpdateLoop(bool createWeapon, bool deleteShield) |
213 | 216 | { |
214 | | - if (Ready) |
| 217 | + bool CurrentLoaded = Loaded; |
| 218 | + |
| 219 | + if (CurrentLoaded) |
215 | 220 | { |
216 | | - bool alreadyOwns = DarkSouls.FindBlackKnightWeapon(BlackKnightShield); |
217 | 221 | bool IsBlackKnightDead = SelectedWeapon.IsConditionSatisfied(); |
| 222 | + bool IsBlackKnightAlive = !IsBlackKnightDead; |
| 223 | + bool JustLoaded = !PreviousLoaded && CurrentLoaded; |
218 | 224 |
|
219 | 225 | /** |
220 | | - * If the black knight is still alive, we reset the state of the Weapon |
| 226 | + * If the black knight is still alive, we reset the state of the Weapon and Shield |
| 227 | + * Only checks after the player just loaded back in because it is the only |
| 228 | + * reliable moment |
221 | 229 | */ |
222 | | - if (!IsBlackKnightDead) |
223 | | - { |
224 | | - ShieldDeleted = false; |
225 | | - } |
226 | | - // else the black knight is dead... |
227 | | - else |
| 230 | + if (JustLoaded && IsBlackKnightAlive) |
228 | 231 | { |
229 | | - if (alreadyOwns) |
230 | | - { |
231 | | - if (!ShieldDeleted) |
232 | | - { |
233 | | - /** |
234 | | - * If the black knight is dead and the player has the shield |
235 | | - * so we need to delete it |
236 | | - */ |
237 | | - DeleteShield(); |
238 | | - ShieldDeleted = true; |
239 | | - } |
240 | | - else |
241 | | - { |
242 | | - /** |
243 | | - * If the black knight is dead but the player still has the |
244 | | - * shield. Maybe another black knight dropped one so we don't |
245 | | - * do anything |
246 | | - */ |
247 | | - // Nothing to do here |
248 | | - } |
249 | | - } |
250 | | - else |
251 | | - { |
252 | | - if (!ShieldDeleted) |
253 | | - { |
254 | | - /** |
255 | | - * The black knight is dead and we didn't delete the shield. |
256 | | - * Hence it didn't drop so we don't need to delete anything |
257 | | - */ |
258 | | - ShieldDeleted = true; |
259 | | - } |
260 | | - else |
261 | | - { |
262 | | - /** |
263 | | - * The black knight is dead, the player doesn't have the shield |
264 | | - * and we already removed it from the inventory. Everything's |
265 | | - * good |
266 | | - */ |
267 | | - // Nothing to do here |
268 | | - } |
269 | | - } |
| 232 | + DeathProcessed = false; |
270 | 233 | } |
271 | | - } |
272 | | - } |
273 | | - |
274 | | - /// <summary> |
275 | | - /// Automatically Get the item if needed |
276 | | - /// </summary> |
277 | | - public void AutomaticallyCreateWeapon() |
278 | | - { |
279 | | - if (Ready) |
280 | | - { |
281 | | - bool IsBlackKnightDead = SelectedWeapon.IsConditionSatisfied(); |
282 | 234 |
|
283 | 235 | /** |
284 | | - * If the black knight is still alive, we reset the state of the Weapon |
285 | | - */ |
286 | | - if (!IsBlackKnightDead) |
| 236 | + * Only run logic when the black is dead and only run that logic once, |
| 237 | + * until the black knight is alive again |
| 238 | + */ |
| 239 | + if (IsBlackKnightDead && !DeathProcessed) |
287 | 240 | { |
288 | | - WeaponCreated = false; |
289 | | - } |
290 | | - // else the black knight is dead... |
291 | | - else |
292 | | - { |
293 | | - bool alreadyOwns = DarkSouls.FindBlackKnightWeapon(SelectedWeapon); |
294 | | - |
295 | | - if (alreadyOwns) |
296 | | - { |
297 | | - if (!WeaponCreated) |
298 | | - { |
299 | | - /** |
300 | | - * If the black knight is dead and the player has the weapon |
301 | | - * but we never gave it to him then it's a legit drop |
302 | | - */ |
303 | | - WeaponCreated = true; |
304 | | - } |
305 | | - else |
306 | | - { |
307 | | - /** |
308 | | - * If the black knight is dead and the player has the weapon |
309 | | - * and we already gave it to him then it's all good and we |
310 | | - * don't do anything |
311 | | - */ |
312 | | - // Nothing to do here |
313 | | - } |
314 | | - } |
315 | | - else |
| 241 | + // weapon |
| 242 | + if (createWeapon) |
316 | 243 | { |
317 | | - if (!WeaponCreated) |
| 244 | + bool needsToCreate = !DarkSouls.FindBlackKnightWeapon(SelectedWeapon); |
| 245 | + |
| 246 | + if (needsToCreate) |
318 | 247 | { |
319 | 248 | /** |
320 | 249 | * If the black knight is dead, the player doesn't have the |
321 | 250 | * weapon and we didn't already gave it, then we give it |
322 | 251 | */ |
323 | 252 | CreateWeapon(); |
324 | | - WeaponCreated = true; |
325 | 253 | } |
326 | | - else |
| 254 | + } |
| 255 | + |
| 256 | + // shield |
| 257 | + if (deleteShield) |
| 258 | + { |
| 259 | + bool needsToDelete = DarkSouls.FindBlackKnightWeapon(BlackKnightShield); |
| 260 | + |
| 261 | + if (needsToDelete) |
327 | 262 | { |
328 | 263 | /** |
329 | | - * If the black knight is dead, the player doesn't have the |
330 | | - * weapon but we aleady gave it, then we don't do anything. |
331 | | - * Maybe the player intentionally removed the weapon from his |
332 | | - * inventory. |
| 264 | + * If the black knight is dead and the player has the shield |
| 265 | + * so we need to delete it |
333 | 266 | */ |
334 | | - // Nothing to do here |
| 267 | + DeleteShield(); |
335 | 268 | } |
336 | 269 | } |
| 270 | + |
| 271 | + // only execute this once per black knight death |
| 272 | + DeathProcessed = true; |
337 | 273 | } |
338 | 274 | } |
| 275 | + |
| 276 | + PreviousLoaded = CurrentLoaded; |
339 | 277 | } |
340 | 278 |
|
341 | 279 | /// <summary> |
|
0 commit comments