97 lines
2.4 KiB
C++
97 lines
2.4 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "FishingRodComponent.h"
|
|
|
|
#include "EngineUtils.h"
|
|
#include "ProjectFish/Definations.h"
|
|
#include "ProjectFish/PawnWithSkill.h"
|
|
|
|
|
|
// Sets default values for this component's properties
|
|
UFishingRodComponent::UFishingRodComponent()
|
|
{
|
|
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
|
// off to improve performance if you don't need them.
|
|
PrimaryComponentTick.bCanEverTick = true;
|
|
|
|
// ...
|
|
}
|
|
|
|
void UFishingRodComponent::AddFishRodDamage(int32 Damage)
|
|
{
|
|
FishRodData.Damage += Damage;
|
|
}
|
|
|
|
|
|
// Called when the game starts
|
|
void UFishingRodComponent::BeginPlay()
|
|
{
|
|
|
|
|
|
for (auto rowName: FishRodDataTable.DataTable->GetRowMap())
|
|
{
|
|
FFishingRod* data = reinterpret_cast<FFishingRod*>(rowName.Value);
|
|
if (data && data->FishingRod_Name ==FishRodDataTable.RowContents )
|
|
{
|
|
FishRodData = *data;
|
|
break;
|
|
}
|
|
}
|
|
APawnWithSkill* OwnerPawn = Cast<APawnWithSkill>(GetOwner());
|
|
|
|
if (OwnerPawn != nullptr)
|
|
{
|
|
//叠加角色的属性信息
|
|
OwnerPawn->CurrentEndurance += FishRodData.Endurance_Add;
|
|
OwnerPawn->MaxEndurance += FishRodData.Endurance_Add;
|
|
OwnerPawn->CurrentTenacity += FishRodData.Tenacity_Add;
|
|
OwnerPawn->MaxTenacity+= FishRodData.Tenacity_Add;
|
|
|
|
GetWorld()->GetTimerManager().SetTimerForNextTick([this, OwnerPawn]()
|
|
{
|
|
// 执行依赖其他Actor的逻辑
|
|
for (auto pawn: TActorRange<APawnWithSkill>(GetWorld()))
|
|
{
|
|
if (pawn != OwnerPawn)
|
|
{
|
|
Enemy = pawn;
|
|
}
|
|
}
|
|
//初始化鱼竿技能
|
|
for (auto skill : FishRodData.Skills)
|
|
{
|
|
UFishingRodSKill_Base* SkillObject = NewObject<UFishingRodSKill_Base>(OwnerPawn, skill.SkillClass);
|
|
if (SkillObject != nullptr)
|
|
{
|
|
FRSkills.Add(SkillObject);
|
|
SkillObject->Init(OwnerPawn);
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
// ...
|
|
Super::BeginPlay();
|
|
}
|
|
|
|
|
|
// Called every frame
|
|
void UFishingRodComponent::TickComponent(float DeltaTime, ELevelTick TickType,
|
|
FActorComponentTickFunction* ThisTickFunction)
|
|
{
|
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
|
CurrentCDTime += DeltaTime;
|
|
if (CurrentCDTime >= FishRodData.DamageCD)
|
|
{
|
|
CurrentCDTime = 0;
|
|
UE_LOG(LogTemp, Warning, TEXT("鱼竿: %s 造成伤害 %d"), *FishRodData.FishingRod_Name.ToString(), FishRodData.Damage);
|
|
if (Enemy)
|
|
{
|
|
Enemy->ApplyyEndurance(-FishRodData.Damage);
|
|
}
|
|
}
|
|
// ...
|
|
}
|
|
|