Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "lilSpellBase.h"
- #include "Components/CapsuleComponent.h"
- #include "Kismet/GameplayStatics.h"
- #include "Runtime/Engine/Classes/Particles/ParticleSystemComponent.h"
- // Sets default values
- AlilSpellBase::AlilSpellBase()
- {
- // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
- //PrimaryActorTick.bCanEverTick = true;
- fDamage = 0.f;
- fCapsuleHeight = 1.f;
- fCapsuleRadius = 1.f;
- bSelf = false;
- //set capsule size and attach
- sSpellAttach = TEXT("sCapsule");
- cSpellComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT("cSpellComponent"));
- cSpellComponent->SetCapsuleSize(fCapsuleRadius, fCapsuleHeight);
- cSpellComponent->OnComponentBeginOverlap.AddDynamic(this, &AlilSpellBase::BeginOverlap);
- RootComponent = cSpellComponent;
- pSpellEffects = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("pSpellEffects"));
- pSpellEffects->AttachToComponent(cSpellComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
- }
- // Called when the game starts or when spawned
- void AlilSpellBase::BeginPlay()
- {
- Super::BeginPlay();
- GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("begin play"));
- setIgnoreActors();
- if (bSelf)
- {
- GetWorld()->GetTimerManager().SetTimer(SelfCastHandle, this, &AlilSpellBase::selfCast, .01, true, 0);
- }
- }
- void AlilSpellBase::BeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
- {
- MyOwner = GetOwner();
- if (!bSelf) {
- if (aIgnoreActors.Num() < 1) {
- setIgnoreActors();
- }
- if (MyOwner != nullptr)
- {
- FString sMyOwner = MyOwner->GetName();
- GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, sMyOwner);
- if (IsValid(MyOwner->GetInstigatorController())) {
- GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("True"));
- UGameplayStatics::ApplyDamage(OtherActor, fDamage, MyOwner->GetInstigatorController(), this, dType);
- }
- }
- else {
- GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("No Owner"));
- }
- }
- }
- void AlilSpellBase::setIgnoreActors()
- {
- MyOwner = GetOwner();
- if (MyOwner) {
- GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("setting actors"));
- MyOwner->GetAttachedActors(aIgnoreActors);
- aIgnoreActors.AddUnique(MyOwner);
- }
- }
- void AlilSpellBase::selfCast()
- {
- MyOwner = GetOwner();
- GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("self effect"));
- UGameplayStatics::ApplyDamage(MyOwner, fDamage, MyOwner->GetInstigatorController(), this, dType);
- }
- // Called every frame
- /*
- void AlilSpellBase::Tick(float DeltaTime)
- {
- Super::Tick(DeltaTime);
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement