-
-
Notifications
You must be signed in to change notification settings - Fork 399
/
Copy pathGroupContainerStats.cs
64 lines (52 loc) · 2.37 KB
/
GroupContainerStats.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
using System;
using System.Collections.Generic;
namespace Pathoschild.Stardew.Automate.Framework.Commands.Summary;
/// <summary>Metadata about containers of the same type within a machine group.</summary>
internal class GroupContainerStats
{
/*********
** Accessors
*********/
/// <summary>The container name.</summary>
public string Name { get; }
/// <summary>The preference for storing items in these containers.</summary>
public AutomateContainerPreference StoragePreference { get; }
/// <summary>The preference for taking items from these containers.</summary>
public AutomateContainerPreference TakeItemsPreference { get; }
/// <summary>The number of containers in the group.</summary>
public int Count { get; }
/// <summary>The number of slots filled with an item slot.</summary>
public int FilledSlots { get; }
/// <summary>The number of empty slots.</summary>
public int TotalSlots { get; }
/// <summary>Whether the container is a Junimo chest.</summary>
public HashSet<string> GlobalInventoryChests { get; } = new(StringComparer.OrdinalIgnoreCase);
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="name">The container name.</param>
/// <param name="storagePreference">The preference for storing items in these containers.</param>
/// <param name="takeItemsPreference">The preference for taking items from these containers.</param>
/// <param name="containers">The containers in the group.</param>
public GroupContainerStats(string name, AutomateContainerPreference storagePreference, AutomateContainerPreference takeItemsPreference, IEnumerable<IContainer> containers)
{
this.Name = name;
this.StoragePreference = storagePreference;
this.TakeItemsPreference = takeItemsPreference;
foreach (IContainer container in containers)
{
// only track same global inventory chest once
if (container.IsGlobalChest)
{
if (this.GlobalInventoryChests.Add(container.GlobalInventoryId))
continue;
}
// track stats
int filled = container.GetFilled();
this.Count++;
this.FilledSlots += filled;
this.TotalSlots += Math.Max(filled, container.GetCapacity());
}
}
}