Skip to content

Commit

Permalink
Another bug fix to the calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Mar 7, 2021
1 parent 917935e commit 37565e3
Showing 1 changed file with 25 additions and 5 deletions.
Expand Up @@ -115,8 +115,8 @@ class CalculatorAscMaterialsItemBloc extends Bloc<CalculatorAscMaterialsItemEven
final cl = tuple.item1;
final dl = tuple.item2;

final cAsc = _getClosestAscensionLevel(cl, cl == currentLevel);
final dAsc = _getClosestAscensionLevel(dl, dl == desiredLevel);
final cAsc = _getClosestAscensionLevel(cl, _isLevelValidForAscensionLevel(cl, currentState.currentAscensionLevel));
final dAsc = _getClosestAscensionLevel(dl, _isLevelValidForAscensionLevel(dl, currentState.desiredAscensionLevel));
final skills = _updateSkills(cAsc, dAsc);

return currentState.copyWith.call(
Expand Down Expand Up @@ -144,8 +144,14 @@ class CalculatorAscMaterialsItemBloc extends Bloc<CalculatorAscMaterialsItemEven
return currentState;
}

final cl = _getItemLevelToUse(cAsc, currentState.currentLevel);
final dl = _getItemLevelToUse(dAsc, currentState.desiredLevel);
final levelTuple = _checkProvidedLevels(
_getItemLevelToUse(cAsc, currentState.currentLevel),
_getItemLevelToUse(dAsc, currentState.desiredLevel),
currentChanged,
);
final cl = levelTuple.item1;
final dl = levelTuple.item2;

final skills = _updateSkills(cAsc, dAsc);
return currentState.copyWith.call(
currentLevel: cl,
Expand Down Expand Up @@ -257,7 +263,7 @@ class CalculatorAscMaterialsItemBloc extends Bloc<CalculatorAscMaterialsItemEven
}

final currentKvp = itemAscensionLevelMap.entries.firstWhere((kvp) => kvp.key == currentAscensionLevel);
final suggestedAscLevel = _getClosestAscensionLevel(currentItemLevel, true);
final suggestedAscLevel = _getClosestAscensionLevel(currentItemLevel, false);

if (currentKvp.key != suggestedAscLevel) {
return currentKvp.value;
Expand Down Expand Up @@ -353,4 +359,18 @@ class CalculatorAscMaterialsItemBloc extends Bloc<CalculatorAscMaterialsItemEven

return Tuple4<bool, bool, bool, bool>(currentDecEnabled, currentIncEnabled, desiredDecEnabled, desiredIncEnabled);
}

bool _isLevelValidForAscensionLevel(int currentLevel, int ascensionLevel) {
if (ascensionLevel == 0) {
return itemAscensionLevelMap.entries.first.value >= currentLevel;
}

if (ascensionLevel == itemAscensionLevelMap.entries.last.key) {
return currentLevel >= itemAscensionLevelMap.entries.last.value;
}

final entry = itemAscensionLevelMap.entries.firstWhere((kvp) => kvp.key == ascensionLevel);
final nextEntry = itemAscensionLevelMap.entries.firstWhere((kvp) => kvp.key == ascensionLevel + 1);
return entry.value >= currentLevel && currentLevel <= nextEntry.value;
}
}

0 comments on commit 37565e3

Please sign in to comment.