148 lines
3.3 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "SkillEffect.h"
#include "AsyncTreeDifferences.h"
#include "Skill.h"
#include "SkillManager.h"
void USkillEffect::InitSkillEffect(class USkill* skill, FSkillEffectData data)
{
this->OwnerSkill = skill;
this->effectData = data;
}
// Add default functionality here for any ISkillEffect functions that are not pure virtual.
void USkillEffect::Execute(const FSkillContext& context)
{
TArray<UObject*> targets= GetApplyTargets(context);
FString strTargets;
for (auto target: targets)
{
if (target->GetClass()->IsChildOf(APawnWithSkill::StaticClass()))
{
strTargets += (Cast<APawnWithSkill>(target))->GetActorNameOrLabel() +"|" ;
}
else
{
strTargets += (Cast<USkill>(target))->GetSkillData().SkillName.ToString() + "|" ;
}
}
const UEnum* EnumPtr = StaticEnum<ESkillEffectType>();
FString type = EnumPtr->GetNameStringByValue(static_cast<int64>(effectData.EffectType)) ;
UE_LOG(LogTemp, Warning, TEXT("技能:%s 拥有者: %s 目标: %s 效果: %s")
, *OwnerSkill->GetSkillData().SkillName.ToString()
,*OwnerSkill->GetOwner()->GetActorNameOrLabel()
,*strTargets
, *( GetSkillEffectDes()));
}
void USkillEffect::EffectEnded(const FSkillContext& context)
{
}
TArray<UObject*> USkillEffect::GetApplyTargets(const FSkillContext& context)
{
TArray<UObject*> result;
switch (effectData.SkillSelecter.SelecterType)
{
case ETargetSelecterType::SkillPos:
{
GetEffectTargetsByTargetType(context, result);
break;;
}
case ETargetSelecterType::SkillTag:
{
//根据Tag 决定应用对象
for (auto skill: context.SkillManager->GetAllSkills())
{
if (effectData.SkillSelecter.ApplySkillTags.HasTag(skill->GetSkillData().SkillTag))
{
result.Add(skill);
}
}
break;;
}
case ETargetSelecterType::RandomScope:
{
//应用到随机技能
switch (effectData.SkillSelecter.RandomType)
{
case ERandomTargetType::AllSelf:
{
//所有我方的技能
for (auto skill: context.SkillManager->GetAllSkills())
{
if (OwnerSkill->GetOwner() == skill->GetOwner())
{
result.Add(skill);
}
}
break;
}
case ERandomTargetType::AllOther:
{
//所有地方的技能
for (auto skill: context.SkillManager->GetAllSkills())
{
if (OwnerSkill->GetOwner() != skill->GetOwner())
{
result.Add(skill);
}
}
break;
}
}
break;
}
}
return result;
}
FString USkillEffect::GetSkillEffectDes()
{
return FString();
}
void USkillEffect::GetEffectTargetsByTargetType(const FSkillContext& context, TArray<UObject*>& result)
{
//根据位置决定应用对象
ESkillTargetType targetType = effectData.SkillSelecter.TargetType;
switch (targetType)
{
case ESkillTargetType::Self:
{
result.Add(OwnerSkill->GetOwner());
break;
}
case ESkillTargetType::Other:
{
for (auto pawn: context.SkillManager->GetAllPawns())
{
if (pawn != OwnerSkill->GetOwner())
{
result.Add(pawn);
}
}
break;
}
case ESkillTargetType::Around:
{
//技能左侧的技能
TArray<USkill*> aroundSkills = context.SkillManager->GetSkillsAround(context.OwnerSkill);
for (auto skill: aroundSkills)
{
result.Add(skill);
}
break;;
}
}
}