-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemDropperMatcher.cs
60 lines (49 loc) · 1.61 KB
/
ItemDropperMatcher.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
using SideLoader;
using System.Collections.Generic;
namespace Nm1fiOutward.Drops
{
[SL_Serialized]
public abstract class ItemDropperMatcher : ITemplateListItem
{
public abstract bool IsMatch(ItemDropperWrapper dropper);
public virtual IList<string> Validate() => null;
public virtual void ApplyActualTemplate() { }
}
public class ItemGenatorNameMatcher : ItemDropperMatcher
{
public enum MatchType
{
Exact,
Contains,
}
public string Name = "";
public MatchType Match = MatchType.Exact;
public override string ToString() => $"{Match} '{Name}'";
public override bool IsMatch(ItemDropperWrapper dropper)
{
var name = dropper.ItemGenatorName;
if (string.IsNullOrEmpty(name))
return false;
switch (Match)
{
case MatchType.Exact: return Name == name;
case MatchType.Contains: return name.Contains(Name);
default: return false;
}
}
}
internal class ItemDropperMatcherSameComparer : IEqualityComparer<ItemDropperMatcher>
{
public bool Equals(ItemDropperMatcher a, ItemDropperMatcher b)
{
return a != null && b != null
&& a.GetType() == b.GetType()
&& a.ToString() == b.ToString();
}
public int GetHashCode(ItemDropperMatcher matcher)
{
if (matcher == null) return 0;
return matcher.GetType().GetHashCode() ^ matcher.ToString().GetHashCode();
}
}
}