Skip to content

Commit

Permalink
Completely moved Death-related distributions to On Death Distribution.
Browse files Browse the repository at this point in the history
Now Dead NPCs need to be targeted explicitly.
  • Loading branch information
adya committed Jul 31, 2024
1 parent 6ca28fb commit af6a028
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
7 changes: 7 additions & 0 deletions SPID/include/DeathDistribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ namespace DeathDistribution
/// </summary>
/// <returns>true if given entry was an on death distribuatble form. Note that returned value doesn't represent whether parsing was successful.</returns>
bool TryParse(const std::string& key, const std::string& value, const Path&);

/// <summary>
/// Explicitly adds a parsed entry to the on death distributable forms.
///
/// This method is used when another Distribution detects a use of Starts Dead trait, which qualifies entry to become on death distributable.
/// </summary>
void AddEntry(const Distribution::INI::Data&);
}

using namespace Forms;
Expand Down
4 changes: 4 additions & 0 deletions SPID/src/DeathDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ namespace DeathDistribution
}
return true;
}
void AddEntry(const Distribution::INI::Data& data)
{
deathConfigs[data.type].emplace_back(data);
}
}

#pragma endregion
Expand Down
5 changes: 3 additions & 2 deletions SPID/src/Distribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,11 @@ namespace Distribute
void Distribute(NPCData& npcData, bool onlyLeveledEntries)
{
const auto input = PCLevelMult::Input{ npcData.GetActor(), npcData.GetNPC(), onlyLeveledEntries };
Distribute(npcData, input);


if (npcData.IsDead()) { // If NPC is already dead, perform the On Death Distribution.
DeathDistribution::Manager::GetSingleton()->Distribute(npcData);
} else {
Distribute(npcData, input);
}
}

Expand Down
17 changes: 15 additions & 2 deletions SPID/src/LookupConfigs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,23 @@ namespace Distribution

data.path = path;

configs[data.type].emplace_back(data);
if (data.traits.startsDead.has_value()) {
logger::info("\t\t[{} = {}]", key, value);
if (*data.traits.startsDead) {
logger::info("\t\t\tEntry uses Starts Dead Trait filter and will be converted to On Death Distribution. Use 'Death{} = ...' instead of '{} = ...'", key, key);
DeathDistribution::INI::AddEntry(data);
} else {
logger::info("\t\t\tTrait '-D' is redundant, because Regular Distribution ignores Dead NPCs by default.");
}

} else {
configs[data.type].emplace_back(data);
}

}
} catch (const std::exception& e) {
logger::warn("\t\tFailed to parse entry [{} = {}]: {}", key, value, e.what());
logger::warn("\t\t[{} = {}]", key, value);
logger::warn("\t\t\tFailed to parse entry: {}", e.what());
}
}

Expand Down

0 comments on commit af6a028

Please sign in to comment.