Skip to content

Commit

Permalink
ChaosMod/EffectDispatcher: Effect weighting fixes
Browse files Browse the repository at this point in the history
- Fix broken weighting for effects with group type on dispatch

- Do weighting on all effects rather than just filtered ones
  • Loading branch information
pongo1231 committed Feb 6, 2025
1 parent aa8705a commit 0e997e1
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions ChaosMod/Components/EffectDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,20 @@ static void _DispatchEffect(EffectDispatcher *effectDispatcher, const EffectDisp
LOG("Dispatching effect \"" << effectData.Name << "\"");
#endif

const auto &filteredEffects = GetFilteredEnabledEffects();

// Increase weight for all effects first
for (auto &effectData : filteredEffects)
if (!effectData->IsMeta())
effectData->Weight += effectData->WeightMult;
for (auto &[effectId, enabledEffectData] : g_EnabledEffects)
if (!enabledEffectData.IsMeta())
enabledEffectData.Weight += enabledEffectData.WeightMult;

// Reset weight of this effect (or every effect in group) to reduce chance of same effect (group) happening multiple
// times in a row
if (effectData.GroupType.empty())
effectData.Weight = effectData.WeightMult;
else
{
for (auto &effectData : filteredEffects)
if (effectData->GroupType == effectData->GroupType)
effectData->Weight = effectData->WeightMult;
for (auto &[effectId, enabledEffectData] : g_EnabledEffects)
if (enabledEffectData.GroupType == effectData.GroupType)
effectData.Weight = effectData.WeightMult;
}

auto playEffectDispatchSound = [&](EffectDispatcher::ActiveEffect &activeEffect)
Expand Down Expand Up @@ -430,14 +428,17 @@ void EffectDispatcher::UpdateMetaEffects(float deltaTime)
{
totalWeight += effectData->GetEffectWeight();

effectData->Weight += effectData->WeightMult;

if (!targetEffectId && chosen <= totalWeight)
targetEffectId = &effectId;
}

if (targetEffectId)
{
// Increase weight of all meta effects (including ones with an unfulfilled condition)
for (auto &[effectId, effectData] : g_EnabledEffects)
if (effectData.IsMeta() && !effectData.IsUtility() && !effectData.IsHidden())
effectData.Weight += effectData.WeightMult;

_DispatchEffect(this,
{ .Id = *targetEffectId, .Suffix = "(Meta)", .Flags = DispatchEffectFlag_NoAddToLog });
}
Expand Down

0 comments on commit 0e997e1

Please sign in to comment.