public bool HasNotification(int level, long blockIndex) { var availableSlots = UnlockHelper.GetAvailableEquipmentSlots(level); foreach (var(type, slotCount) in availableSlots) { var equipments = Equipments.Where(e => e.ItemSubType == type && e.RequiredBlockIndex <= blockIndex); var current = equipments.Where(e => e.equipped); // When an equipment slot is empty. if (current.Count() < Math.Min(equipments.Count(), slotCount)) { return(true); } // When any other equipments are stronger than current one. foreach (var equipment in equipments) { if (equipment.equipped) { continue; } var cp = CPHelper.GetCP(equipment); if (current.Any(i => CPHelper.GetCP(i) < cp)) { return(true); } } } return(false); }
public void UpdateEquipmentNotification(List <ElementalType> elementalTypes = null) { var currentAvatarState = Game.Game.instance.States.CurrentAvatarState; if (currentAvatarState is null) { return; } if (State.Value != ItemType.Equipment) { return; } var equipments = Equipments; foreach (var item in equipments) { item.HasNotification.Value = false; } var level = currentAvatarState.level; var availableSlots = UnlockHelper.GetAvailableEquipmentSlots(level); foreach (var(type, slotCount) in availableSlots) { var matchedEquipments = Equipments .Where(e => e.ItemBase.Value.ItemSubType == type); if (elementalTypes != null) { matchedEquipments = matchedEquipments.Where(e => elementalTypes.Exists(x => x == e.ItemBase.Value.ElementalType)); } var equippedEquipments = matchedEquipments.Where(e => e.EquippedEnabled.Value); var unequippedEquipments = matchedEquipments.Where(e => !e.EquippedEnabled.Value) .OrderByDescending(i => CPHelper.GetCP(i.ItemBase.Value as Equipment)); var equippedCount = equippedEquipments.Count(); if (equippedCount < slotCount) { var itemsToNotify = unequippedEquipments.Take(slotCount - equippedCount); foreach (var item in itemsToNotify) { item.HasNotification.Value = true; } } else { var itemsToNotify = unequippedEquipments.Where(e => { var cp = CPHelper.GetCP(e.ItemBase.Value as Equipment); return(equippedEquipments.Any(i => CPHelper.GetCP(i.ItemBase.Value as Equipment) < cp)); }).Take(slotCount); foreach (var item in itemsToNotify) { item.HasNotification.Value = true; } } } }