-
Notifications
You must be signed in to change notification settings - Fork 16
/
UnlockChestValidator.cs
53 lines (47 loc) · 1.84 KB
/
UnlockChestValidator.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
using System.Linq;
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.IO.Map;
using EOLib.IO.Repositories;
using Optional;
namespace EOLib.Domain.Map
{
[AutoMappedType]
public class UnlockChestValidator : IUnlockChestValidator
{
private readonly ICharacterInventoryProvider _characterInventoryProvider;
private readonly IEIFFileProvider _eifFileProvider;
public UnlockChestValidator(ICharacterInventoryProvider characterInventoryProvider,
IEIFFileProvider eifFileProvider)
{
_characterInventoryProvider = characterInventoryProvider;
_eifFileProvider = eifFileProvider;
}
public bool CanMainCharacterOpenChest(ChestKey requiredKey)
{
return GetRequiredKeyName(requiredKey).Match(
some: keyName => _characterInventoryProvider
.ItemInventory
.Where(x => _eifFileProvider.EIFFile[x.ItemID].Type == IO.ItemType.Key)
.Select(x => _eifFileProvider.EIFFile[x.ItemID].Name)
.Any(keyName.Equals),
none: () => true);
}
public Option<string> GetRequiredKeyName(ChestKey requiredKey)
{
switch (requiredKey)
{
case ChestKey.Normal: return Option.Some("Normal Key");
case ChestKey.Silver: return Option.Some("Silver Key");
case ChestKey.Crystal: return Option.Some("Crystal Key");
case ChestKey.Wraith: return Option.Some("Wraith Key");
default: return Option.None<string>();
}
}
}
public interface IUnlockChestValidator
{
bool CanMainCharacterOpenChest(ChestKey requiredKey);
Option<string> GetRequiredKeyName(ChestKey requiredKey);
}
}