Adds advantage/disadvantage to saving throw display.
This commit is contained in:
@@ -119,6 +119,7 @@ extern NSString *const kAdvantageTypeDisadvantage;
|
|||||||
-(void)clearSavingThrows;
|
-(void)clearSavingThrows;
|
||||||
-(NSString*)savingThrowsDescription;
|
-(NSString*)savingThrowsDescription;
|
||||||
-(int)proficiencyBonus;
|
-(int)proficiencyBonus;
|
||||||
|
-(int)proficiencyBonusForType:(NSString*)proficiencyType;
|
||||||
-(void)addSkill: (Skill*)skill;
|
-(void)addSkill: (Skill*)skill;
|
||||||
-(void)removeSkill: (Skill*)skill;
|
-(void)removeSkill: (Skill*)skill;
|
||||||
-(void)clearSkills;
|
-(void)clearSkills;
|
||||||
|
|||||||
@@ -354,41 +354,90 @@ NSString *const kAdvantageTypeDisadvantage = @"disadvantage";
|
|||||||
@throw [[NSException alloc] initWithName:@"unimplemented" reason:@"Method not implemented." userInfo:nil];
|
@throw [[NSException alloc] initWithName:@"unimplemented" reason:@"Method not implemented." userInfo:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(int)proficiencyBonusForType:(NSString*)proficiencyType {
|
||||||
|
if ([kProficiencyTypeNone isEqualToString:proficiencyType]) {
|
||||||
|
return 0;
|
||||||
|
} else if ([kProficiencyTypeProficient isEqualToString:proficiencyType]) {
|
||||||
|
return self.proficiencyBonus;
|
||||||
|
} else if ([kProficiencyTypeExpertise isEqualToString:proficiencyType]) {
|
||||||
|
return self.proficiencyBonus * 2;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+(NSString*)advantageLabelStringForType:(NSString*)advantageType {
|
||||||
|
if ([kAdvantageTypeNone isEqualToString:advantageType]) {
|
||||||
|
return @"";
|
||||||
|
} else if ([kAdvantageTypeAdvantage isEqualToString:advantageType]) {
|
||||||
|
return @"(A)";
|
||||||
|
} else if ([kAdvantageTypeDisadvantage isEqualToString:advantageType]) {
|
||||||
|
return @"(D)";
|
||||||
|
} else {
|
||||||
|
return @"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
-(NSString*)savingThrowsDescription {
|
-(NSString*)savingThrowsDescription {
|
||||||
NSMutableArray *parts = [[NSMutableArray alloc] init];
|
NSMutableArray *parts = [[NSMutableArray alloc] init];
|
||||||
NSString *name;
|
NSString *name;
|
||||||
|
NSString *advantage;
|
||||||
int bonus;
|
int bonus;
|
||||||
if (self.strengthSavingThrowProficiency != kProficiencyTypeNone) {
|
if (self.strengthSavingThrowProficiency != kProficiencyTypeNone || self.strengthSavingThrowAdvantage != kAdvantageTypeNone) {
|
||||||
name = NSLocalizedString(@"Strength", @"");
|
name = NSLocalizedString(@"Strength", @"");
|
||||||
bonus = self.proficiencyBonus + self.strengthModifier;
|
bonus = self.strengthModifier + [self proficiencyBonusForType:self.strengthSavingThrowProficiency];
|
||||||
[parts addObject:[NSString stringWithFormat:@"%@ %+d", name, bonus]];
|
advantage = [Monster advantageLabelStringForType:self.strengthSavingThrowAdvantage];
|
||||||
|
if (advantage) {
|
||||||
|
advantage = [@" " stringByAppendingString:advantage];
|
||||||
|
}
|
||||||
|
[parts addObject:[NSString stringWithFormat:@"%@ %+d%@", name, bonus, advantage]];
|
||||||
}
|
}
|
||||||
if (self.dexteritySavingThrowProficiency != kProficiencyTypeNone) {
|
if (self.dexteritySavingThrowProficiency != kProficiencyTypeNone) {
|
||||||
name = NSLocalizedString(@"Dexterity", @"");
|
name = NSLocalizedString(@"Dexterity", @"");
|
||||||
bonus = self.proficiencyBonus + self.dexterityModifier;
|
bonus = self.dexterityModifier + [self proficiencyBonusForType:self.dexteritySavingThrowProficiency];
|
||||||
[parts addObject:[NSString stringWithFormat:@"%@ %+d", name, bonus]];
|
advantage = [Monster advantageLabelStringForType:self.dexteritySavingThrowAdvantage];
|
||||||
|
if (advantage) {
|
||||||
|
advantage = [@" " stringByAppendingString:advantage];
|
||||||
|
}
|
||||||
|
[parts addObject:[NSString stringWithFormat:@"%@ %+d%@", name, bonus, advantage]];
|
||||||
}
|
}
|
||||||
if (self.constitutionSavingThrowProficiency != kProficiencyTypeNone) {
|
if (self.constitutionSavingThrowProficiency != kProficiencyTypeNone) {
|
||||||
name = NSLocalizedString(@"Constitution", @"");
|
name = NSLocalizedString(@"Constitution", @"");
|
||||||
bonus = self.proficiencyBonus + self.constitutionModifier;
|
bonus = self.constitutionModifier + [self proficiencyBonusForType:self.constitutionSavingThrowProficiency];
|
||||||
[parts addObject:[NSString stringWithFormat:@"%@ %+d", name, bonus]];
|
advantage = [Monster advantageLabelStringForType:self.constitutionSavingThrowAdvantage];
|
||||||
|
if (advantage) {
|
||||||
|
advantage = [@" " stringByAppendingString:advantage];
|
||||||
|
}
|
||||||
|
[parts addObject:[NSString stringWithFormat:@"%@ %+d%@", name, bonus, advantage]];
|
||||||
}
|
}
|
||||||
if (self.intelligenceSavingThrowProficiency != kProficiencyTypeNone) {
|
if (self.intelligenceSavingThrowProficiency != kProficiencyTypeNone) {
|
||||||
name = NSLocalizedString(@"Intelligence", @"");
|
name = NSLocalizedString(@"Intelligence", @"");
|
||||||
bonus = self.proficiencyBonus + self.intelligenceModifier;
|
bonus = self.intelligenceModifier + [self proficiencyBonusForType:self.intelligenceSavingThrowProficiency];
|
||||||
[parts addObject:[NSString stringWithFormat:@"%@ %+d", name, bonus]];
|
advantage = [Monster advantageLabelStringForType:self.intelligenceSavingThrowAdvantage];
|
||||||
|
if (advantage) {
|
||||||
|
advantage = [@" " stringByAppendingString:advantage];
|
||||||
|
}
|
||||||
|
[parts addObject:[NSString stringWithFormat:@"%@ %+d%@", name, bonus, advantage]];
|
||||||
}
|
}
|
||||||
if (self.wisdomSavingThrowProficiency != kProficiencyTypeNone) {
|
if (self.wisdomSavingThrowProficiency != kProficiencyTypeNone) {
|
||||||
name = NSLocalizedString(@"Wisdom", @"");
|
name = NSLocalizedString(@"Wisdom", @"");
|
||||||
bonus = self.proficiencyBonus + self.wisdomModifier;
|
bonus = self.wisdomModifier + [self proficiencyBonusForType:self.wisdomSavingThrowProficiency];
|
||||||
[parts addObject:[NSString stringWithFormat:@"%@ %+d", name, bonus]];
|
advantage = [Monster advantageLabelStringForType:self.wisdomSavingThrowAdvantage];
|
||||||
|
if (advantage) {
|
||||||
|
advantage = [@" " stringByAppendingString:advantage];
|
||||||
|
}
|
||||||
|
[parts addObject:[NSString stringWithFormat:@"%@ %+d%@", name, bonus, advantage]];
|
||||||
}
|
}
|
||||||
if (self.charismaSavingThrowProficiency != kProficiencyTypeNone) {
|
if (self.charismaSavingThrowProficiency != kProficiencyTypeNone) {
|
||||||
name = NSLocalizedString(@"Charisma", @"");
|
name = NSLocalizedString(@"Charisma", @"");
|
||||||
bonus = self.proficiencyBonus + self.charismaModifier;
|
bonus = self.charismaModifier + [self proficiencyBonusForType:self.charismaSavingThrowProficiency];
|
||||||
[parts addObject:[NSString stringWithFormat:@"%@ %+d", name, bonus]];
|
advantage = [Monster advantageLabelStringForType:self.charismaSavingThrowAdvantage];
|
||||||
|
if (advantage) {
|
||||||
|
advantage = [@" " stringByAppendingString:advantage];
|
||||||
|
}
|
||||||
|
[parts addObject:[NSString stringWithFormat:@"%@ %+d%@", name, bonus, advantage]];
|
||||||
}
|
}
|
||||||
return [parts componentsJoinedByString:@" "];
|
return [parts componentsJoinedByString:@", "];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(int)proficiencyBonus {
|
-(int)proficiencyBonus {
|
||||||
|
|||||||
Reference in New Issue
Block a user