Block matching basics complete
This commit is contained in:
@@ -58,8 +58,6 @@
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Model\Item.cs" />
|
||||
<Compile Include="Model\ItemCollection.cs" />
|
||||
<Compile Include="Model\Socket.cs" />
|
||||
<Compile Include="Model\SocketGroup.cs" />
|
||||
<Compile Include="Services\ItemBlockItemMatcher.cs" />
|
||||
<Compile Include="Services\ItemFilterProcessor.cs" />
|
||||
<Compile Include="UserControls\ItemSocketsControl.xaml.cs">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Filtration.ObjectModel;
|
||||
using Filtration.ObjectModel.Enums;
|
||||
|
||||
namespace Filtration.ItemFilterPreview.Model
|
||||
@@ -18,6 +19,7 @@ namespace Filtration.ItemFilterPreview.Model
|
||||
ItemRarity ItemRarity { get; set; }
|
||||
int Sockets { get; }
|
||||
int LinkedSockets { get; }
|
||||
IEnumerable<SocketGroup> LinkedSocketGroups { get; }
|
||||
}
|
||||
|
||||
public class Item : IItem
|
||||
@@ -29,6 +31,11 @@ namespace Filtration.ItemFilterPreview.Model
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<SocketGroup> LinkedSocketGroups
|
||||
{
|
||||
get { return SocketGroups.Where(s => s.Linked); }
|
||||
}
|
||||
|
||||
public List<SocketGroup> SocketGroups
|
||||
{
|
||||
get { return _socketGroups; }
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Filtration.ItemFilterPreview.Model
|
||||
{
|
||||
public class Socket
|
||||
{
|
||||
public Socket(Color color)
|
||||
{
|
||||
Color = color;
|
||||
}
|
||||
|
||||
public Color Color { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Filtration.ItemFilterPreview.Model
|
||||
{
|
||||
public class SocketGroup : List<Socket>
|
||||
{
|
||||
public SocketGroup(List<Socket> sockets, bool linked)
|
||||
{
|
||||
if (sockets.Count < 1 || sockets.Count > 6)
|
||||
{
|
||||
throw new InvalidOperationException("A socket group must have between 2 and 6 sockets");
|
||||
}
|
||||
|
||||
|
||||
if (linked && sockets.Count < 2)
|
||||
{
|
||||
throw new InvalidOperationException("A linked socket group must have at least 2 sockets");
|
||||
}
|
||||
|
||||
AddRange(sockets);
|
||||
Linked = linked;
|
||||
}
|
||||
|
||||
public bool Linked { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Filtration.ItemFilterPreview.Model;
|
||||
using Filtration.ObjectModel;
|
||||
using Filtration.ObjectModel.BlockItemBaseTypes;
|
||||
using Filtration.ObjectModel.BlockItemTypes;
|
||||
using Filtration.ObjectModel.Enums;
|
||||
using Filtration.ObjectModel.Extensions;
|
||||
|
||||
namespace Filtration.ItemFilterPreview.Services
|
||||
{
|
||||
@@ -31,35 +35,78 @@ namespace Filtration.ItemFilterPreview.Services
|
||||
return NumericFilterPredicateBlockItemMatch(dropLevelBlockItem, item.DropLevel);
|
||||
}
|
||||
|
||||
private bool NumericFilterPredicateBlockItemMatch<T>(T numericFilterPredicateBlockItem, int matchValue) where T : NumericFilterPredicateBlockItem
|
||||
public bool HeightBlockItemMatch(HeightBlockItem heightBlockItem, IItem item)
|
||||
{
|
||||
switch (numericFilterPredicateBlockItem.FilterPredicate.PredicateOperator)
|
||||
return NumericFilterPredicateBlockItemMatch(heightBlockItem, item.Height);
|
||||
}
|
||||
|
||||
public bool ItemLevelBlockItemMatch(ItemLevelBlockItem itemLevelBlockItem, IItem item)
|
||||
{
|
||||
return NumericFilterPredicateBlockItemMatch(itemLevelBlockItem, item.ItemLevel);
|
||||
}
|
||||
|
||||
public bool LinkedSocketsBlockItemMatch(LinkedSocketsBlockItem linkedSocketsBlockItem, IItem item)
|
||||
{
|
||||
return NumericFilterPredicateBlockItemMatch(linkedSocketsBlockItem, item.LinkedSockets);
|
||||
}
|
||||
|
||||
public bool QualityBlockItemMatch(QualityBlockItem qualityBlockItem, IItem item)
|
||||
{
|
||||
return NumericFilterPredicateBlockItemMatch(qualityBlockItem, item.Quality);
|
||||
}
|
||||
|
||||
public bool RarityBlockItemMatch(RarityBlockItem qualityBlockItem, IItem item)
|
||||
{
|
||||
return NumericFilterPredicateBlockItemMatch(qualityBlockItem, (int)item.ItemRarity);
|
||||
}
|
||||
|
||||
public bool SocketsBlockItemMatch(SocketsBlockItem socketsBlockItem, IItem item)
|
||||
{
|
||||
return NumericFilterPredicateBlockItemMatch(socketsBlockItem, item.Sockets);
|
||||
}
|
||||
|
||||
public bool WidthBlockItemMatch(WidthBlockItem widthBlockItem, IItem item)
|
||||
{
|
||||
return NumericFilterPredicateBlockItemMatch(widthBlockItem, item.Width);
|
||||
}
|
||||
|
||||
public bool SocketGroupBlockItemMatch(SocketGroupBlockItem socketGroupBlockItem, IItem item)
|
||||
{
|
||||
|
||||
foreach (var blockItemSocketGroup in socketGroupBlockItem.SocketGroups) // for each group of sockets in the block item
|
||||
{
|
||||
case FilterPredicateOperator.Equal:
|
||||
foreach (var itemLinkedSocketGroup in item.LinkedSocketGroups) // for each linked socket group in the item
|
||||
{
|
||||
return matchValue == numericFilterPredicateBlockItem.FilterPredicate.PredicateOperand;
|
||||
if (SocketGroupHasRequiredSocketColors(itemLinkedSocketGroup, blockItemSocketGroup))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
case FilterPredicateOperator.GreaterThan:
|
||||
{
|
||||
return matchValue > numericFilterPredicateBlockItem.FilterPredicate.PredicateOperand;
|
||||
}
|
||||
case FilterPredicateOperator.GreaterThanOrEqual:
|
||||
{
|
||||
return matchValue >= numericFilterPredicateBlockItem.FilterPredicate.PredicateOperand;
|
||||
}
|
||||
case FilterPredicateOperator.LessThan:
|
||||
{
|
||||
return matchValue < numericFilterPredicateBlockItem.FilterPredicate.PredicateOperand;
|
||||
}
|
||||
case FilterPredicateOperator.LessThanOrEqual:
|
||||
{
|
||||
return matchValue <= numericFilterPredicateBlockItem.FilterPredicate.PredicateOperand;
|
||||
}
|
||||
default:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool SocketGroupHasRequiredSocketColors(SocketGroup itemLinkedSocketGroup, SocketGroup blockItemSocketGroup)
|
||||
{
|
||||
|
||||
var blockSocketGroupColorCounts = blockItemSocketGroup.GroupBy(i => i.Color, (key, values) => new { SocketColor = key, Count = values.Count() }).ToList();
|
||||
var itemSocketGroupColorCounts = itemLinkedSocketGroup.GroupBy(i => i.Color, (key, values) => new {SocketColor = key, Count = values.Count()}).ToList();
|
||||
|
||||
foreach (var blockItemSocketColorCount in blockSocketGroupColorCounts)
|
||||
{
|
||||
var match = itemSocketGroupColorCounts.FirstOrDefault(i => i.SocketColor == blockItemSocketColorCount.SocketColor && i.Count >= blockItemSocketColorCount.Count);
|
||||
if (match == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool NumericFilterPredicateBlockItemMatch<T>(T numericFilterPredicateBlockItem, int matchValue) where T : NumericFilterPredicateBlockItem
|
||||
{
|
||||
return numericFilterPredicateBlockItem.FilterPredicate.CompareUsing(matchValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user