-
Notifications
You must be signed in to change notification settings - Fork 16
/
ItemDropValidator.cs
48 lines (39 loc) · 1.61 KB
/
ItemDropValidator.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
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Map;
using EOLib.IO;
using EOLib.IO.Repositories;
using System;
namespace EOLib.Domain.Item
{
[AutoMappedType]
public class ItemDropValidator : IItemDropValidator
{
private readonly IEIFFileProvider _eifFileProvider;
private readonly ICurrentMapStateProvider _currentMapStateProvider;
public ItemDropValidator(IEIFFileProvider eifFileProvider,
ICurrentMapStateProvider currentMapStateProvider)
{
_eifFileProvider = eifFileProvider;
_currentMapStateProvider = currentMapStateProvider;
}
public ItemDropResult ValidateItemDrop(ICharacter mainCharacter, IInventoryItem item, MapCoordinate dropPoint)
{
if (item.ItemID <= 0)
throw new ArgumentException("Item ID is invalid", nameof(item));
var itemData = _eifFileProvider.EIFFile[item.ItemID];
if (itemData.Special == ItemSpecial.Lore)
return ItemDropResult.Lore;
if (_currentMapStateProvider.JailMapID == _currentMapStateProvider.CurrentMapID)
return ItemDropResult.Jail;
var rp = mainCharacter.RenderProperties;
if (Math.Max(Math.Abs(rp.MapX - dropPoint.X), Math.Abs(rp.MapY - dropPoint.Y)) > 2)
return ItemDropResult.TooFar;
return ItemDropResult.Ok;
}
}
public interface IItemDropValidator
{
ItemDropResult ValidateItemDrop(ICharacter mainCharacter, IInventoryItem item, MapCoordinate dropPoint);
}
}