add warband rating

This commit is contained in:
Aaron Fischer 2019-08-11 23:37:12 +02:00
parent 9409f91330
commit 814e270eef
3 changed files with 36 additions and 6 deletions

View file

@ -63,6 +63,9 @@ class HenchmenGroup extends Unit {
@JsonKey(ignore: true) @JsonKey(ignore: true)
int experience; int experience;
@JsonKey(defaultValue: false)
bool large;
@JsonKey( @JsonKey(
fromJson: Unit._statsFromJson, toJson: Unit._statsToJson, required: true) fromJson: Unit._statsFromJson, toJson: Unit._statsToJson, required: true)
final Stats stats; final Stats stats;
@ -73,7 +76,8 @@ class HenchmenGroup extends Unit {
@JsonKey(fromJson: Unit._splitListFromJson, toJson: Unit._joinListToJson) @JsonKey(fromJson: Unit._splitListFromJson, toJson: Unit._joinListToJson)
final List<String> armour; final List<String> armour;
HenchmenGroup(this.header, this.stats, this.weapons, this.armour) { HenchmenGroup(
this.header, this.stats, this.weapons, this.armour, this.large) {
this.name = this.header['name']; this.name = this.header['name'];
this.type = this.header['type']; this.type = this.header['type'];
this.number = int.tryParse(this.header['number']) ?? 1; this.number = int.tryParse(this.header['number']) ?? 1;
@ -144,12 +148,14 @@ class Hero extends Unit {
@JsonKey(defaultValue: 0) @JsonKey(defaultValue: 0)
final int warbandaddition; final int warbandaddition;
@JsonKey(defaultValue: false)
bool large;
@JsonKey(defaultValue: false, name: 'hiredsword') @JsonKey(defaultValue: false, name: 'hiredsword')
final bool hiredSword; final bool hiredSword;
Hero(this.stats, this.skilllists, this.weapons, this.armour, this.rules, Hero(this.stats, this.skilllists, this.weapons, this.armour, this.rules,
this.warbandaddition, this.header, this.hiredSword) { this.warbandaddition, this.large, this.header, this.hiredSword) {
this.name = this.header['name']; this.name = this.header['name'];
this.type = this.header['type']; this.type = this.header['type'];
this.experience = int.tryParse(this.header['experience']) ?? 0; this.experience = int.tryParse(this.header['experience']) ?? 0;
@ -309,9 +315,29 @@ class WarbandRoster {
this.race = this.nameAndRace['race']; this.race = this.nameAndRace['race'];
} }
int experience() { int rating() {
// TODO: Calculate int rating = 0;
return 1337;
heros.forEach((hero) {
rating += hero.experience;
rating += hero.warbandaddition;
rating += 5;
if (hero.large) {
rating += 15;
}
});
henchmenGroups.forEach((henchmenGroup) {
rating += henchmenGroup.experience * henchmenGroup.number;
rating += 5 * henchmenGroup.number;
if (henchmenGroup.large) {
rating += 15 * henchmenGroup.number;
}
});
return rating;
} }
static HashMap<String, String> _warbandNameAndRaceFromJson( static HashMap<String, String> _warbandNameAndRaceFromJson(

View file

@ -13,12 +13,14 @@ HenchmenGroup _$HenchmenGroupFromJson(Map json) {
Unit._statsFromJson(json['stats'] as String), Unit._statsFromJson(json['stats'] as String),
Unit._splitListFromJson(json['weapons'] as String), Unit._splitListFromJson(json['weapons'] as String),
Unit._splitListFromJson(json['armour'] as String), Unit._splitListFromJson(json['armour'] as String),
json['large'] as bool ?? false,
); );
} }
Map<String, dynamic> _$HenchmenGroupToJson(HenchmenGroup instance) => Map<String, dynamic> _$HenchmenGroupToJson(HenchmenGroup instance) =>
<String, dynamic>{ <String, dynamic>{
'group': HenchmenGroup._henchmengroupHeaderToJson(instance.header), 'group': HenchmenGroup._henchmengroupHeaderToJson(instance.header),
'large': instance.large,
'stats': Unit._statsToJson(instance.stats), 'stats': Unit._statsToJson(instance.stats),
'weapons': Unit._joinListToJson(instance.weapons), 'weapons': Unit._joinListToJson(instance.weapons),
'armour': Unit._joinListToJson(instance.armour), 'armour': Unit._joinListToJson(instance.armour),
@ -33,6 +35,7 @@ Hero _$HeroFromJson(Map json) {
Unit._splitListFromJson(json['armour'] as String), Unit._splitListFromJson(json['armour'] as String),
Unit._splitListFromJson(json['rules'] as String), Unit._splitListFromJson(json['rules'] as String),
json['warbandaddition'] as int ?? 0, json['warbandaddition'] as int ?? 0,
json['large'] as bool ?? false,
Hero._heroHeaderFromJson(json['hero'] as String), Hero._heroHeaderFromJson(json['hero'] as String),
json['hiredsword'] as bool ?? false, json['hiredsword'] as bool ?? false,
); );
@ -46,6 +49,7 @@ Map<String, dynamic> _$HeroToJson(Hero instance) => <String, dynamic>{
'armour': Unit._joinListToJson(instance.armour), 'armour': Unit._joinListToJson(instance.armour),
'rules': Unit._joinListToJson(instance.rules), 'rules': Unit._joinListToJson(instance.rules),
'warbandaddition': instance.warbandaddition, 'warbandaddition': instance.warbandaddition,
'large': instance.large,
'hiredsword': instance.hiredSword, 'hiredsword': instance.hiredSword,
}; };

View file

@ -106,7 +106,7 @@ class WarbandDrawerWidget extends StatelessWidget {
badgeColor: Colors.black12, badgeColor: Colors.black12,
shape: BadgeShape.square, shape: BadgeShape.square,
borderRadius: 2, borderRadius: 2,
badgeContent: Text(roster.experience().toString() + ' xp', badgeContent: Text(roster.rating().toString(),
style: TextStyle(color: Colors.white)), style: TextStyle(color: Colors.white)),
), ),
), ),