Skip to content

Commit

Permalink
NWN2: Feat check for required skill ranks and minimum class level
Browse files Browse the repository at this point in the history
  • Loading branch information
rjshae authored and DrMcCoy committed Feb 4, 2019
1 parent d724e0b commit 131a233
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/engines/nwn2/feats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ bool Feats::meetsRequirements(const Creature &creature, uint32 id) const {
static const Common::UString kFeatMinCols[] = {"MINSTR", "MINDEX", "MINCON", "MININT", "MINWIS", "MINCHA"};
static const Common::UString kFeatMaxCols[] = {"MAXSTR", "MAXDEX", "MAXCON", "MAXINT", "MAXWIS", "MAXCHA"};
static const Common::UString kFeatPrereq1 = "PREREQFEAT1", kFeatPrereq2 = "PREREQFEAT2";
static const Common::UString kFeatReqSkill1 = "ReqSkill", kFeatReqSkillMinRanks1 = "ReqSkillMinRanks";
static const Common::UString kFeatReqSkill2 = "ReqSkill2", kFeatReqSkillMinRanks2 = "ReqSkillMinRanks2";
static const Common::UString kFeatMinLevelClass = "MinLevelClass", kFeatMinLevel = "MinLevel";
static const Common::UString kFeatRemoved = "REMOVED";

// Ready the feat.2da file
const Aurora::TwoDAFile &twoDA = TwoDAReg.get2DA("feat");
Expand All @@ -151,6 +155,11 @@ bool Feats::meetsRequirements(const Creature &creature, uint32 id) const {
// Load the feats row
const Aurora::TwoDARow &row = twoDA.getRow(id);

// Check if feat was removed by the developers
const uint16 removed = row.getInt(kFeatRemoved);
if (removed == 1)
return false;

// Check the ability range
for (uint i = (uint)kAbilityStrength; i < (uint)kAbilityMAX; i++) {
// Check minimum ability
Expand Down Expand Up @@ -179,6 +188,38 @@ bool Feats::meetsRequirements(const Creature &creature, uint32 id) const {
if (prereq2 != 0 && !getHasFeat(prereq2))
return false;

// Check for required skill ranks
uint32 skill = row.getInt(kFeatReqSkill1);
if (skill != 0) {
uint32 rankMin = row.getInt(kFeatReqSkillMinRanks1);
if (rankMin != 0) {
uint32 ranks = creature.getSkillRank(skill, true);
if (ranks < rankMin)
return false;

skill = row.getInt(kFeatReqSkill2);
if (skill != 0) {
rankMin = row.getInt(kFeatReqSkillMinRanks2);
if (rankMin != 0) {
ranks = creature.getSkillRank(skill, true);
if (ranks < rankMin)
return false;
}
}
}
}

// Check for required minimum class level
const uint32 reqClass = row.getInt(kFeatMinLevelClass);
if (reqClass != 0) {
const uint minLevel = row.getInt(kFeatMinLevel);
if (minLevel != 0) {
const uint32 classLevel = creature.getClassLevel(reqClass);
if (classLevel < minLevel)
return false;
}
}

// TODO: Check other feat requirements
return true;
}
Expand Down

0 comments on commit 131a233

Please sign in to comment.