-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDropTableLogger.cs
67 lines (63 loc) · 2.76 KB
/
DropTableLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Nm1fiOutward.Drops
{
/// <summary>
/// <see cref="DropTableLogger"/> is used to simulate <see cref="DropTableAlteration"/>s on scene load.
/// </summary>
internal static class DropTableLogger
{
internal static IEnumerator LogAllCoro()
{
var merchants = Resources.FindObjectsOfTypeAll<Merchant>()
.Where(merchant => merchant.gameObject?.scene != null)
.Select(merchant => merchant.DropableInventory)
.ToList();
if (merchants.Any())
{
var coro = LogMerchantsCoro(merchants);
while (coro.MoveNext())
yield return coro.Current;
}
var enemies = Resources.FindObjectsOfTypeAll<LootableOnDeath>()
.Where(enemy => enemy.gameObject?.scene != null)
.ToList();
if (enemies.Any())
foreach (var enemy in enemies)
{
DropsPatcher.PatchLootOnDeath(enemy, true);
yield return null;
}
yield break;
}
private static IEnumerator LogMerchantsCoro(List<Dropable> merchants)
{
var alterations = DropTableAlterationCategory.GetAlterationsFor(DropTableAlteration.ItemSourceType.Merchant).ToList();
var additions = DropTableAlterationCategory.GetAdditionalDropsFor(DropTableAlteration.ItemSourceType.Merchant).ToList();
if (alterations.Any() || additions.Any())
{
DropsPlugin.Log($"Checking droptable alterations for {merchants.Count} merchants.");
var altered = new List<DropableWrapper>();
foreach (var dropable in merchants)
{
if (DropsPatcher.PatchMerchantInventory(dropable, alterations, true) is DropableWrapper wrapped)
{
foreach (var addition in additions)
addition.AddAdditionalDroppersTo(wrapped);
if (wrapped.HasChanges)
altered.Add(wrapped);
}
yield return null; // process a single per loop
}
foreach (var dropableWrapper in altered)
if (dropableWrapper.Real.transform.parent.GetComponent<Merchant>() is Merchant merchant)
DropsPlugin.LogInfo("Would update droptables for"
+ $" a merchant {merchant.ShopName} (UID={merchant.HolderUID}):"
+ $"\n{dropableWrapper.ToInfoString()}");
}
yield break;
}
}
}