-
Notifications
You must be signed in to change notification settings - Fork 7
/
AffixesProvider.cs
105 lines (85 loc) · 3.3 KB
/
AffixesProvider.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System.Collections.Generic;
using System.Linq;
namespace Shockah.SeasonAffixes;
internal interface IAffixesProvider
{
IEnumerable<ISeasonAffix> Affixes { get; }
}
internal static class IAffixesProviderExt
{
public static IAffixesProvider Effective(this IAffixesProvider provider, IAffixScoreProvider scoreProvider, OrdinalSeason season)
=> new EffectiveAffixesProvider(provider, scoreProvider, season);
public static IAffixesProvider ApplicableToSeason(this IAffixesProvider provider, IAffixProbabilityWeightProvider probabilityWeightProvider, OrdinalSeason season)
=> new ApplicableToSeasonAffixesProvider(provider, probabilityWeightProvider, season);
public static IAffixesProvider Excluding(this IAffixesProvider provider, IReadOnlySet<ISeasonAffix> excludedAffixes)
=> new ExcludingAffixesProvider(provider, excludedAffixes);
}
internal sealed class AffixesProvider : IAffixesProvider
{
public IEnumerable<ISeasonAffix> Affixes { get; init; }
public AffixesProvider(IEnumerable<ISeasonAffix> affixes)
{
this.Affixes = affixes;
}
}
internal sealed class CompoundAffixesProvider : IAffixesProvider
{
private IEnumerable<IAffixesProvider> Providers { get; init; }
public IEnumerable<ISeasonAffix> Affixes
{
get
{
foreach (var provider in Providers)
foreach (var affix in provider.Affixes)
yield return affix;
}
}
public CompoundAffixesProvider(params IAffixesProvider[] providers) : this((IEnumerable<IAffixesProvider>)providers) { }
public CompoundAffixesProvider(IEnumerable<IAffixesProvider> providers)
{
this.Providers = providers;
}
}
internal sealed class EffectiveAffixesProvider : IAffixesProvider
{
private IAffixesProvider Wrapped { get; init; }
private IAffixScoreProvider ScoreProvider { get; init; }
private OrdinalSeason Season { get; init; }
public IEnumerable<ISeasonAffix> Affixes =>
Wrapped.Affixes
.Where(affix => ScoreProvider.GetPositivity(affix, Season) > 0 || ScoreProvider.GetNegativity(affix, Season) > 0);
public EffectiveAffixesProvider(IAffixesProvider wrapped, IAffixScoreProvider scoreProvider, OrdinalSeason season)
{
this.Wrapped = wrapped;
this.ScoreProvider = scoreProvider;
this.Season = season;
}
}
internal sealed class ApplicableToSeasonAffixesProvider : IAffixesProvider
{
private IAffixesProvider Wrapped { get; init; }
private IAffixProbabilityWeightProvider ProbabilityWeightProvider { get; init; }
private OrdinalSeason Season { get; init; }
public IEnumerable<ISeasonAffix> Affixes =>
Wrapped.Affixes
.Where(affix => ProbabilityWeightProvider.GetProbabilityWeight(affix, Season) > 0);
public ApplicableToSeasonAffixesProvider(IAffixesProvider wrapped, IAffixProbabilityWeightProvider probabilityWeightProvider, OrdinalSeason season)
{
this.Wrapped = wrapped;
this.ProbabilityWeightProvider = probabilityWeightProvider;
this.Season = season;
}
}
internal sealed class ExcludingAffixesProvider : IAffixesProvider
{
private IAffixesProvider Wrapped { get; init; }
private IReadOnlySet<ISeasonAffix> ExcludedAffixes { get; init; }
public IEnumerable<ISeasonAffix> Affixes =>
Wrapped.Affixes
.Where(affix => !ExcludedAffixes.Contains(affix));
public ExcludingAffixesProvider(IAffixesProvider wrapped, IReadOnlySet<ISeasonAffix> excludedAffixes)
{
this.Wrapped = wrapped;
this.ExcludedAffixes = excludedAffixes;
}
}