//TODO: Add visual data here. Such as hair, color, costumes and etc. public CharacterCreationRequest(string characterName, CharacterClassRace characterClass) { if (string.IsNullOrWhiteSpace(characterName)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(characterName)); } if (!Enum.IsDefined(typeof(CharacterClassRace), characterClass)) { throw new ArgumentOutOfRangeException(nameof(characterClass), "Value should be defined in the CharacterClassRace enum."); } CharacterName = characterName; CharacterClass = characterClass; }
//TODO: add the actual visual details public CharacterAppearanceModel(int characterId, SectionId sectionId, CharacterClassRace characterClass) { if (characterId < 0) { throw new ArgumentOutOfRangeException(nameof(characterId)); } if (!Enum.IsDefined(typeof(SectionId), sectionId)) { throw new ArgumentOutOfRangeException(nameof(sectionId), "Value should be defined in the SectionId enum."); } if (!Enum.IsDefined(typeof(CharacterClassRace), characterClass)) { throw new ArgumentOutOfRangeException(nameof(characterClass), "Value should be defined in the CharacterClassRace enum."); } CharacterId = characterId; SectionId = sectionId; CharacterClass = characterClass; }
/// <inheritdoc /> public SectionId Compute(string inputName, CharacterClassRace classRace) { if (string.IsNullOrEmpty(inputName)) { throw new ArgumentException("Value cannot be null or empty.", nameof(inputName)); } if (!Enum.IsDefined(typeof(CharacterClassRace), classRace)) { throw new ArgumentOutOfRangeException(nameof(classRace), "Value should be defined in the CharacterClassRace enum."); } if (!CharacterNameValidator.isNameValidCharacters(inputName)) { throw new ArgumentException("Provided name must contain only letters or digits", nameof(inputName)); } //Sum the ASCII values modulo 10 + the class offset //Then grab the last digit which maps to the SectionId return((SectionId)(inputName.Aggregate(classRace.GetSectionIdOffset(), (sum, c) => sum + c % 10) % 10)); }
/// <summary> /// Gets the offset value for the section ID. /// </summary> /// <param name="classRace">The class race value.</param> /// <exception cref="InvalidEnumArgumentException">Throws if <see cref="classRace"/> is out of range.</exception> /// <returns>The offset value.</returns> public static int GetSectionIdOffset(this CharacterClassRace classRace) { if (!Enum.IsDefined(typeof(CharacterClassRace), classRace)) { throw new ArgumentOutOfRangeException(nameof(classRace), "Value should be defined in the CharacterClassRace enum."); } if (ClassRaceToFieldMap.ContainsKey(classRace)) { return(ClassRaceToFieldMap[classRace].Attribute <SectionIdWeightAttribute>().SectionIdWeight); } else { //Use reflection to read the metdata tagged on the class race ClassRaceToFieldMap[classRace] = typeof(CharacterClassRace).Field(classRace.ToString()); //just recur return(GetSectionIdOffset(classRace)); } }
public static void Test_Player_Strategy_Produces_PSOBB_Expected_SectionId_Values(SectionId expectedId, string name, CharacterClassRace classRace) { //arrange PlayerSectionIdCalculatorStrategy strat = new PlayerSectionIdCalculatorStrategy(); //act SectionId sectionId = strat.Compute(name, classRace); //assert Assert.AreEqual(expectedId, sectionId, $"Expected {expectedId} for {name} {classRace} but computed {sectionId}."); }