2014-04-24 19:35:28 -04:00
|
|
|
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "SkillSystemModulePrivatePCH.h"
|
2014-05-19 23:21:13 -04:00
|
|
|
#include "GameplayTagsModule.h"
|
2014-04-24 19:35:28 -04:00
|
|
|
#include "Crc.h"
|
|
|
|
|
|
|
|
|
|
const int32 MaxNumInStack = 2;
|
|
|
|
|
|
|
|
|
|
UGameplayEffectStackingExtension_CappedNumberTest::UGameplayEffectStackingExtension_CappedNumberTest(const class FPostConstructInitializeProperties& PCIP)
|
|
|
|
|
: Super(PCIP)
|
|
|
|
|
{
|
|
|
|
|
Handle = FCrc::StrCrc32("UGameplayEffectStackingExtension_CappedNumberTest");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UGameplayEffectStackingExtension_CappedNumberTest::CalculateStack(TArray<FActiveGameplayEffect*>& CustomGameplayEffects, FActiveGameplayEffectsContainer& Container, FActiveGameplayEffect& CurrentEffect)
|
|
|
|
|
{
|
|
|
|
|
// this effect shouldn't be in the array so be sure to count it as well
|
|
|
|
|
int32 EffectiveCount = FMath::Min(CustomGameplayEffects.Num() + 1, MaxNumInStack);
|
|
|
|
|
|
|
|
|
|
// find the most recent time one of these was applied
|
2014-04-29 21:55:02 -04:00
|
|
|
float StartTime = CurrentEffect.StartWorldTime;
|
2014-04-24 19:35:28 -04:00
|
|
|
|
|
|
|
|
for (FActiveGameplayEffect* Effect : CustomGameplayEffects)
|
|
|
|
|
{
|
2014-04-29 21:55:02 -04:00
|
|
|
StartTime = FMath::Max(StartTime, Effect->StartWorldTime);
|
2014-04-24 19:35:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// set the start time to be equal to the most recent start time so that the stacked effects stick around if a new effect has been added
|
2014-04-29 21:55:02 -04:00
|
|
|
CurrentEffect.StartWorldTime = StartTime;
|
2014-04-24 19:35:28 -04:00
|
|
|
int32 Idx = 0;
|
|
|
|
|
while (Idx < FMath::Min(MaxNumInStack - 1, CustomGameplayEffects.Num()))
|
|
|
|
|
{
|
2014-04-29 21:55:02 -04:00
|
|
|
CustomGameplayEffects[Idx]->StartWorldTime = StartTime;
|
2014-04-24 19:35:28 -04:00
|
|
|
++Idx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we don't need any effects beyond the cap
|
|
|
|
|
while (Idx < CustomGameplayEffects.Num())
|
|
|
|
|
{
|
|
|
|
|
Container.RemoveActiveGameplayEffect(CustomGameplayEffects[Idx]->Handle);
|
|
|
|
|
++Idx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (FModifierSpec Mod : CurrentEffect.Spec.Modifiers)
|
|
|
|
|
{
|
2014-05-20 16:40:26 -04:00
|
|
|
if (Mod.Info.OwnedTags.HasTag(IGameplayTagsModule::RequestGameplayTag("Stackable"), EGameplayTagMatchType::IncludeParentTags, EGameplayTagMatchType::Explicit))
|
2014-04-24 19:35:28 -04:00
|
|
|
{
|
|
|
|
|
// remove any stacking information that was already applied to the current modifier
|
|
|
|
|
for (int32 Idx = 0; Idx < Mod.Aggregator.Get()->Mods[EGameplayModOp::Multiplicitive].Num(); ++Idx)
|
|
|
|
|
{
|
|
|
|
|
FAggregatorRef& Agg = Mod.Aggregator.Get()->Mods[EGameplayModOp::Multiplicitive][Idx];
|
2014-05-20 16:40:26 -04:00
|
|
|
if (Agg.Get()->BaseData.Tags.HasTag(IGameplayTagsModule::RequestGameplayTag("Stack.CappedNumber"), EGameplayTagMatchType::IncludeParentTags, EGameplayTagMatchType::Explicit))
|
2014-04-24 19:35:28 -04:00
|
|
|
{
|
|
|
|
|
Mod.Aggregator.Get()->Mods[EGameplayModOp::Multiplicitive].RemoveAtSwap(Idx);
|
|
|
|
|
--Idx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
FGameplayModifierInfo ModInfo;
|
|
|
|
|
ModInfo.Magnitude.SetValue(EffectiveCount);
|
|
|
|
|
ModInfo.ModifierOp = EGameplayModOp::Multiplicitive;
|
2014-05-20 16:40:26 -04:00
|
|
|
ModInfo.OwnedTags.AddTag(IGameplayTagsModule::RequestGameplayTag("Stack.CappedNumber"));
|
2014-04-24 19:35:28 -04:00
|
|
|
ModInfo.Attribute = Mod.Info.Attribute;
|
|
|
|
|
|
|
|
|
|
TSharedPtr<FGameplayEffectLevelSpec> ModifierLevel(TSharedPtr< FGameplayEffectLevelSpec >(new FGameplayEffectLevelSpec()));
|
|
|
|
|
ModifierLevel->ApplyNewDef(ModInfo.LevelInfo, ModifierLevel);
|
|
|
|
|
|
|
|
|
|
FModifierSpec ModSpec(ModInfo, ModifierLevel, NULL);
|
|
|
|
|
|
|
|
|
|
ModSpec.ApplyModTo(Mod, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|