Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check to ensure a player can't spend more attribute credits than they should at character creation. #483

Merged
merged 1 commit into from
Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions Source/ACE/Network/Handlers/CharacterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,26 @@ private static void CharacterCreateEx(ClientMessage message, Session session, ui
character.NumCharacterTitles = 1;

// stats
// TODO - Validate this is equal to 330 (Total Attribute Credits)
character.StrengthAbility.Base = (ushort)reader.ReadUInt32();
character.EnduranceAbility.Base = (ushort)reader.ReadUInt32();
character.CoordinationAbility.Base = (ushort)reader.ReadUInt32();
character.QuicknessAbility.Base = (ushort)reader.ReadUInt32();
character.FocusAbility.Base = (ushort)reader.ReadUInt32();
character.SelfAbility.Base = (ushort)reader.ReadUInt32();
uint totalAttributeCredits = cg.HeritageGroups[(int)character.Heritage].AttributeCredits;
uint usedAttributeCredits = 0;
// Validate this is equal to actual attribute credits (330 for all but "Olthoi", which have 60
character.StrengthAbility.Base = ValidateAttributeCredits(reader.ReadUInt32(), usedAttributeCredits, totalAttributeCredits);
usedAttributeCredits += character.StrengthAbility.Base;

character.EnduranceAbility.Base = ValidateAttributeCredits(reader.ReadUInt32(), usedAttributeCredits, totalAttributeCredits);
usedAttributeCredits += character.EnduranceAbility.Base;

character.CoordinationAbility.Base = ValidateAttributeCredits(reader.ReadUInt32(), usedAttributeCredits, totalAttributeCredits);
usedAttributeCredits += character.CoordinationAbility.Base;

character.QuicknessAbility.Base = ValidateAttributeCredits(reader.ReadUInt32(), usedAttributeCredits, totalAttributeCredits);
usedAttributeCredits += character.QuicknessAbility.Base;

character.FocusAbility.Base = ValidateAttributeCredits(reader.ReadUInt32(), usedAttributeCredits, totalAttributeCredits);
usedAttributeCredits += character.FocusAbility.Base;

character.SelfAbility.Base = ValidateAttributeCredits(reader.ReadUInt32(), usedAttributeCredits, totalAttributeCredits);
usedAttributeCredits += character.SelfAbility.Base;

// data we don't care about
uint characterSlot = reader.ReadUInt32();
Expand All @@ -252,7 +265,7 @@ private static void CharacterCreateEx(ClientMessage message, Session session, ui
character.Stamina.Current = character.Stamina.MaxValue;
character.Mana.Current = character.Mana.MaxValue;

// set initial skill credit amount. 52 for all but "OlthoiAcid", which have 68
// set initial skill credit amount. 52 for all but "Olthoi", which have 68
character.AvailableSkillCredits = cg.HeritageGroups[(int)character.Heritage].SkillCredits;

uint numOfSkills = reader.ReadUInt32();
Expand Down Expand Up @@ -322,6 +335,19 @@ private static void CharacterCreateEx(ClientMessage message, Session session, ui
}));
}

/// <summary>
/// Checks if the total credits is more than this class is allowed.
/// </summary>
/// <returns>The original value or the max allowed.</returns>
private static ushort ValidateAttributeCredits(uint attributeValue, uint allAttributes, uint maxAttributes) {
if ((attributeValue + allAttributes) > maxAttributes)
{
return (ushort)(maxAttributes - allAttributes);
}
else
return (ushort)attributeValue;
}

private static void CharacterCreateSetDefaultCharacterOptions(AceCharacter character)
{
character.SetCharacterOption(CharacterOption.VividTargetingIndicator, true);
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ACEmulator Change Log

### 2017-07-31
[OptimShi]
* Added check to ensure a player can't spend more attribute credits than they should at character creation.

### 2017-07-30
[Og II]
* Added spellbar management and persistance. This continues the work for learning and persisting spells.
Expand Down