void StoreModelKey(Dictionary <Saint.EquipSlot, ModelData> keys, Saint.Quad model, Saint.Stain stain, Saint.EquipSlot slot) { if (!model.IsEmpty) { keys[slot] = new ModelData(model, stain); } }
Tuple <Saint.Items.Equipment, int> Match(Saint.EquipSlot slot, Saint.Quad key) { if (!_equipmentBySlotByModelKey.ContainsKey(slot)) { Console.WriteLine(_equipmentBySlotByModelKey.Keys.ToString()); } var equipmentByModelKey = _equipmentBySlotByModelKey[slot]; // Check for an exact match. if (equipmentByModelKey.TryGetValue(key, out var equipment)) { return(Tuple.Create(equipment, 0)); } // Search for the closest-matching equipment with this key. var matchComplexity = int.MaxValue; var matchUncertainty = int.MaxValue; Saint.Items.Equipment matchEquipment = null; foreach (var pair in equipmentByModelKey) { // The first value must always match. if (pair.Key.Value1 != key.Value1) { continue; } // If the equipment is a weapon or shield, the second value must always match too. if ((pair.Value is Saint.Items.Weapon || pair.Value is Saint.Items.Shield) && pair.Key.Value2 != key.Value2) { continue; } // For every 10 levels of variance in the second value, match uncertainty increases. var uncertainty = 1 + Math.Abs(pair.Key.Value2 - key.Value2) / 10; if (uncertainty > matchUncertainty) { continue; } // Now find the least complicated match on the lowest uncertainty level. var complexity = _complexity.GetNqComplexity(pair.Value.Key); if (complexity < matchComplexity) { matchUncertainty = uncertainty; matchEquipment = pair.Value; } } return(Tuple.Create(matchEquipment, matchUncertainty)); }
public ModelData(Saint.Quad key, Saint.Stain stain) { Key = key; Stain = stain; }