Skip to content

Commit

Permalink
Fixed improved gunnery cost when the number of actions changes
Browse files Browse the repository at this point in the history
such as when adding the duelist advanced control systems after adding the improved gunnery upgrade
found by Robear
  • Loading branch information
Ariemeth committed Mar 13, 2024
1 parent 08535a2 commit 61fc292
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
16 changes: 12 additions & 4 deletions lib/models/mods/veteranUpgrades/veteran_modification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ class VeteranModification extends BaseModification {
final modName = _vetModNames[improvedGunneryID];
assert(modName != null);

var modCost = u.actions != null ? u.actions! * 2 : 0;
int? modCostOverride;

final vm = VeteranModification(
name: modName ?? improvedGunneryID,
Expand All @@ -494,16 +494,24 @@ class VeteranModification extends BaseModification {
return false;
}

modCost = rs!.modCostOverride(modCost, improvedGunneryID, u);
modCostOverride = rs!.modCostOverride(improvedGunneryID, u);
return rs.veteranModCheck(u, cg!, modID: improvedGunneryID);
});

vm.addMod<int>(
UnitAttribute.tv,
(value) {
return value + (u.actions != null ? modCost : 0);
if (modCostOverride != null) {
return value + modCostOverride!;
}
return value + ((u.actions ?? 0) * 2);
},
dynamicDescription: () {
if (modCostOverride != null) {
return 'TV +$modCostOverride';
}
return 'TV +${(u.actions ?? 0) * 2}';
},
description: 'TV +${u.actions != null ? modCost : 0}',
);

vm.addMod<int>(
Expand Down
2 changes: 1 addition & 1 deletion lib/models/rules/faction_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class FactionRule extends ChangeNotifier {
veteranModCheck;
final bool? Function(Unit u, CombatGroup cg)? veteranCheckOverride;
final int? Function(UnitRoster ur, CombatGroup cg)? veteranCGCountOverride;
final int Function(int baseCost, String modID, Unit u)? modCostOverride;
final int? Function(String modID, Unit u)? modCostOverride;

/// Override a mod's requirement check
final bool? Function(Unit u, CombatGroup cg, {required String modID})?
Expand Down
4 changes: 2 additions & 2 deletions lib/models/rules/peace_river/poc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ final ruleGSwatSniper = FactionRule(
}
return null;
},
modCostOverride: (baseCost, modID, u) {
modCostOverride: (modID, u) {
if (modID == improvedGunneryID && u.hasMod(gSWATSniperID)) {
return 1;
}
return baseCost;
return null;
},
factionMods: (ur, cg, u) => [PeaceRiverFactionMods.gSWATSniper()],
description: 'One gear with a rifle, per combat group, may purchase the' +
Expand Down
17 changes: 10 additions & 7 deletions lib/models/rules/rule_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -657,22 +657,25 @@ abstract class RuleSet extends ChangeNotifier {
return count < 1;
}

int modCostOverride(int baseCost, String modID, Unit u) {
int? modCostOverride(String modID, Unit u) {
final modCostOverrides = allEnabledRules(u.group?.combatGroup?.options)
.where((rule) => rule.modCostOverride != null);
if (modCostOverrides.isEmpty) {
return baseCost;
return null;
}

// check the rule's modCostOverrides function for any override values for
// this mod. If multiple functions are found, return the min value from all
// of them.
final overrideValues = modCostOverrides
.map((r) => r.modCostOverride!(baseCost, modID, u))
.toList();
var minOverrideValue = baseCost;
final overrideValues =
modCostOverrides.map((r) => r.modCostOverride!(modID, u)).toList();
int? minOverrideValue;
overrideValues.forEach((v) {
minOverrideValue = min(minOverrideValue, v);
if (minOverrideValue == null) {
minOverrideValue = v;
} else if (v != null) {
minOverrideValue = min(minOverrideValue!, v);
}
});
return minOverrideValue;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/roster/roster.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import 'package:url_launcher/url_launcher_string.dart';
const double _leftPanelWidth = 670.0;
const double _titleHeight = 40.0;
const double _menuTitleHeight = 50.0;
const String _version = '1.3.5';
const String _version = '1.3.6';
const String _bugEmailAddress = '[email protected]';
const String _dp9URL = 'https://www.dp9.com/';
const String _sourceCodeURL = 'https://github.com/Ariemeth/gearforce-flutter';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

version: 1.3.5
version: 1.3.6
environment:
sdk: ">=3.0.0"

Expand Down

0 comments on commit 61fc292

Please sign in to comment.