Skip to content

Commit

Permalink
Doh/DoL: add tests and optimize for maintainability
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenari committed Oct 19, 2024
1 parent 5186484 commit 8945fc4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
12 changes: 12 additions & 0 deletions NetStone.Test/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Tests
private const string TestCharacterIdEureka = "14556736";
private const string TestCharacterIdEureka2 = "6787158";
private const string TestCharacterIdBare = "9426169";
private const string TestCharacterIdDoH = "42256897";

private const string TestFreeCompany = "9232379236109629819";
private const string TestFreeCompanyRecruiting = "9232660711086374997";
Expand Down Expand Up @@ -289,6 +290,17 @@ public async Task TestFreeCompanySearch()
} while (page != null);
}

[Test]
public async Task CheckCharacterDoH()
{
var chara = await this.lodestone.GetCharacter(TestCharacterIdDoH);
Assert.NotNull(chara);
var attribs = chara.Attributes;
Assert.AreEqual(39, attribs.Craftsmanship);
Assert.AreEqual(7, attribs.Control);
Assert.AreEqual(180, attribs.MpGpCp);
}

[Test]
public async Task CheckCharacterBare()
{
Expand Down
25 changes: 15 additions & 10 deletions NetStone/Model/Parseables/Character/CharacterAttributes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HtmlAgilityPack;
using System;
using HtmlAgilityPack;
using NetStone.Definitions.Model.Character;

namespace NetStone.Model.Parseables.Character;
Expand Down Expand Up @@ -84,13 +85,13 @@ public CharacterAttributes(HtmlNode rootNode, CharacterAttributesDefinition defi
/// This characters' Attack Magic Potency value.
/// </summary>
/// <remarks>This value is only set for disciples of war/magic.</remarks>
public int? AttackMagicPotency => MpGpCpParameterName == "MP" ? int.Parse(Parse(this.definition.AttackMagicPotency)) : null;
public int? AttackMagicPotency => IsDoWOrDoM() ? this.AttackMagicPotencyInternal : null;

/// <summary>
/// This characters' Healing Magic Potency value.
/// </summary>
/// <remarks>This value is only set for disciples of war/magic.</remarks>
public int? HealingMagicPotency => MpGpCpParameterName == "MP" ? int.Parse(Parse(this.definition.HealingMagicPotency)) : null;
public int? HealingMagicPotency => IsDoWOrDoM() ? this.HealingMagicPotencyInternal : null;

/// <summary>
/// This characters' Spell Speed value.
Expand All @@ -112,25 +113,25 @@ public CharacterAttributes(HtmlNode rootNode, CharacterAttributesDefinition defi
/// This characters' Craftmanship value.
/// </summary>
/// <remarks>This value is only set for disciples of the hand.</remarks>
public int? Craftmanship => MpGpCpParameterName == "CP" ? AttackMagicPotencyValue : null;
public int? Craftsmanship => IsDoH() ? this.AttackMagicPotencyInternal : null;

/// <summary>
/// This characters' Control value.
/// </summary>
/// <remarks>This value is only set for disciples of the hand.</remarks>
public int? Control => MpGpCpParameterName == "CP" ? HealingMagicPotencyValue : null;
public int? Control => IsDoH() ? this.HealingMagicPotencyInternal : null;

/// <summary>
/// This characters' Gathering value.
/// </summary>
/// <remarks>This value is only set for disciples of the land.</remarks>
public int? Gathering => MpGpCpParameterName == "GP" ? AttackMagicPotencyValue : null;
public int? Gathering => IsDoL() ? this.AttackMagicPotencyInternal : null;

/// <summary>
/// This characters' Perception value.
/// </summary>
/// <remarks>This value is only set for disciples of the land.</remarks>
public int? Perception => MpGpCpParameterName == "GP" ? HealingMagicPotencyValue : null;
public int? Perception => IsDoL() ? this.HealingMagicPotencyInternal : null;

/// <summary>
/// This characters' HP value.
Expand All @@ -146,8 +147,12 @@ public CharacterAttributes(HtmlNode rootNode, CharacterAttributesDefinition defi
/// Value indicating which of MP, GP, or CP is indicated by <see cref="MpGpCp"/>.
/// </summary>
public string MpGpCpParameterName => Parse(this.definition.MpGpCpParameterName);

internal bool IsDoL() => this.MpGpCpParameterName.Equals("GP", StringComparison.InvariantCultureIgnoreCase);
internal bool IsDoWOrDoM() => this.MpGpCpParameterName.Equals("MP", StringComparison.InvariantCultureIgnoreCase);
internal bool IsDoH() => this.MpGpCpParameterName.Equals("CP", StringComparison.InvariantCultureIgnoreCase);

private int AttackMagicPotencyValue => int.Parse(Parse(this.definition.AttackMagicPotency));
private int HealingMagicPotencyValue => int.Parse(Parse(this.definition.HealingMagicPotency));
internal int AttackMagicPotencyInternal => int.TryParse(Parse(this.definition.AttackMagicPotency), out var val) ? val : 0;

internal int HealingMagicPotencyInternal => int.TryParse(Parse(this.definition.HealingMagicPotency), out var val) ? val : 0;
}
2 changes: 1 addition & 1 deletion NetStone/NetStone.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8945fc4

Please sign in to comment.