void FAFAttributeBase::InitializeAttribute(UAFAbilityComponent* InComponent, const FName InAttributeName)
{
	CurrentValue = BaseValue;
	CalculateBonus();
	CurrentValue = GetFinalValue();
	Modifiers.Empty();
	Modifiers.AddDefaulted(7);// static_cast<int32>(EGAAttributeMod::Invalid));
	//Modifiers.AddDefaulted(static_cast<int32>(EGAAttributeMod::Invalid));
	AbilityComp = InComponent;
	SelfName = FGAAttribute(InAttributeName);
}
void FAFAttributeBase::CopyFromOther(FAFAttributeBase* Other)
{
	if (!Other)
		return;

	BaseValue = Other->BaseValue;
	MinValue = Other->MinValue;
	MaxValue = Other->MaxValue;
	CurrentValue = Other->CurrentValue;
	BaseBonusValue = Other->BaseBonusValue;

	CurrentValue = BaseValue;
	CalculateBonus();
	CurrentValue = GetFinalValue();
}
float FAFAttributeBase::Modify(const FGAEffectMod& ModIn, const FGAEffectHandle& HandleIn,
	FGAEffectProperty& InProperty, const FGAEffectContext& InContext)
{
	//FString name = GetTypeName<FAFAttributeBase>();
	if (ExtensionClass)
	{
		ExtensionClass.GetDefaultObject()->OnPreAttributeModify(AbilityComp, SelfName, CurrentValue);
		
		ExtensionClass.GetDefaultObject()->PreAttributeModify(InContext
			, CurrentValue);
		
		
	}
	float returnValue = -1;
	bool isPeriod = InProperty.GetPeriod() > 0;
	bool IsDuration = InProperty.GetDuration() > 0;

	float PreValue = CurrentValue;
	
	if ( !InProperty.GetIsInstant())
	{
		FGAModifier AttrMod(ModIn.AttributeMod, ModIn.Value, HandleIn);
		AttrMod.Tags.AppendTags(InProperty.GetSpecData()->AttributeTags);
		AddBonus(ModIn, HandleIn);
		return ModIn.Value;
	}
	else
	{
		switch (ModIn.AttributeMod)
		{
		case EGAAttributeMod::Add:
		{
			float OldCurrentValue = CurrentValue;
			UE_LOG(GameAttributes, Log, TEXT("FAFAttributeBase::Add:: OldCurrentValue: %f"), OldCurrentValue);
			UE_LOG(GameAttributes, Log, TEXT("FAFAttributeBase::Add:: AddValue: %f"), ModIn.Value);
			float Val = CurrentValue - (OldCurrentValue + ModIn.Value);
			UE_LOG(GameAttributes, Log, TEXT("FAFAttributeBase::Add:: ActuallAddVal: %f"), Val);
			CurrentValue -= Val;
			CurrentValue = FMath::Clamp<float>(CurrentValue, 0, GetFinalValue());
			UE_LOG(GameAttributes, Log, TEXT("FAFAttributeBase::Add:: CurrentValue: %f"), CurrentValue);
			returnValue = CurrentValue;
			break;
		}
		case EGAAttributeMod::Subtract:
		{
			float OldCurrentValue = CurrentValue;
			UE_LOG(GameAttributes, Log, TEXT("FAFAttributeBase::Subtract:: OldCurrentValue: %f"), OldCurrentValue);
			UE_LOG(GameAttributes, Log, TEXT("FAFAttributeBase::Subtract:: SubtractValue: %f"), ModIn.Value);
			float Val = CurrentValue - (OldCurrentValue - ModIn.Value);
			UE_LOG(GameAttributes, Log, TEXT("FAFAttributeBase::Subtract:: ActuallSubtractVal: %f"), Val);
			CurrentValue -= Val;
			CurrentValue = FMath::Clamp<float>(CurrentValue, 0, GetFinalValue());
			UE_LOG(GameAttributes, Log, TEXT("FAFAttributeBase::Subtract:: CurrentValue: %f"), CurrentValue);

			returnValue = CurrentValue;
			break;
		}
		case EGAAttributeMod::Multiply:
		{
			returnValue = -1;
			break;
		}
		case EGAAttributeMod::Divide:
		{
			returnValue = -1;
			break;
		}
		}
	}
	if (ExtensionClass)
	{
		ExtensionClass.GetDefaultObject()->OnPostAttributeModify(AbilityComp, SelfName, returnValue);
		
		ExtensionClass.GetDefaultObject()->PostAttributeModify(
			InContext
			, PreValue
			, returnValue);
		
	}
	return returnValue;
}
Example #4
0
// this function is an exact copy of MBSLoad::GetConstraintStepFact
double Constraint::GetCStepsFact(double t) const
{
	if(t <= 0) 
		return 0.;
	
  double steptime = GetCStepTime(t);    // step number (computation step number from TimeInt)
	int stepnumber = GetCStepNumber(t);   // step time   (computation step time from TimeInt)

// return value when time is after last computation step endtime...
	if(stepnumber < 0 && t > 0.) 
		return GetFinalValue(steps.Length());

// return value when too few load steps are defined
	if(stepnumber > NSteps()) 
		return GetFinalValue(steps.Length());


	double finalvalue = GetFinalValue(stepnumber); // value at the end of this interval
// return value for STEP ( finalvalue is valid for entire interval )
	if(GetRampMode(stepnumber) == TCSRStep)
		return finalvalue; 

	double startvalue = 1.;  // value at beginning of this interval, =1. means that all constraints start ON !!!
	if (stepnumber != 1) 
    startvalue = GetFinalValue(stepnumber-1);
// return value for LINEAR ( linear interpolation between beginning and end of the interval )
  if(GetRampMode(stepnumber) == TCSRLinear)
	{
		double stepfactor = startvalue + (finalvalue-startvalue)*steptime;
		return stepfactor;
	}

	const double eps_t = 1e-12;
// return value for EXPONENTIAL ( eponential interpolation between beginning and end of the interval )
	if(steptime < eps_t) 
		return startvalue;
	else if(steptime == 1.)
		return finalvalue;
	else
	{
		double factor_growth_decay = 1.;
		if(finalvalue < startvalue) 
			factor_growth_decay=-1;

// exponential interpolation:  y(x) = y(0) * (y(1) / y(0))^x ... with y(0) and y(1) may not be 0.
// but this always works
// with y(x) = a*e^+x + d , x[0..1] --> y(0) = a+d, y(1) = ae+d    --> a = (y(1)-y(0)) / (e-1),    d = y(0) - a  (growth)
// with y(x) = a*e^-x + d , x[0..1] --> y(0) = a+d, y(1) = ae^-1+d --> a = (y(1)-y(0)) / (e^-1-1), d = y(0) - a  (decay)
		double a = (finalvalue-startvalue) / (exp(factor_growth_decay)-1.);
		double d = startvalue - a;
		double stepfactor = a * exp(steptime*factor_growth_decay) + d;

////// exponential interpolation Mk.II  factor 10 in 1/10 th step (  10^0 for 1, 10^-1 for 0.9, 10^-4 for 0.5, cutoff 10^-20,...
////// results:  y(x)  = (y(1)-y(0)) * max(10^-(10*(1-x)), cutoff) + y(0)    (growth)
//////	         y(x)  = (y(1)-y(0)) * max(10^-(10*(x)), cutoff) + y(0)
////	  const double eps_factor = 1e-20; // <-- minimum for 
////    double exponent = (1.-steptime) * 10.;
////		if (finalvalue < startvalue)
////			exponent = (-steptime) * 10;
////		double stepfactor = (finalvalue - startvalue) * Maximum(eps_factor, pow(10.,exponent)) + startvalue;


		return stepfactor;
	}
  return 0.;
}