Advertisement
Guest User

spell.cpp

a guest
Jul 9th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.84 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "lilSpellBase.h"
  4. #include "Components/CapsuleComponent.h"
  5. #include "Kismet/GameplayStatics.h"
  6. #include "Runtime/Engine/Classes/Particles/ParticleSystemComponent.h"
  7.  
  8. // Sets default values
  9. AlilSpellBase::AlilSpellBase()
  10. {
  11.     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  12.     //PrimaryActorTick.bCanEverTick = true;
  13.  
  14.     fDamage = 0.f;
  15.     fCapsuleHeight = 1.f;
  16.     fCapsuleRadius = 1.f;
  17.     bSelf = false;
  18.  
  19.     //set capsule size and attach
  20.     sSpellAttach = TEXT("sCapsule");
  21.     cSpellComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT("cSpellComponent"));
  22.     cSpellComponent->SetCapsuleSize(fCapsuleRadius, fCapsuleHeight);
  23.     cSpellComponent->OnComponentBeginOverlap.AddDynamic(this, &AlilSpellBase::BeginOverlap);
  24.  
  25.     RootComponent = cSpellComponent;
  26.  
  27.     pSpellEffects = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("pSpellEffects"));
  28.    
  29.     pSpellEffects->AttachToComponent(cSpellComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
  30. }
  31.  
  32. // Called when the game starts or when spawned
  33. void AlilSpellBase::BeginPlay()
  34. {
  35.     Super::BeginPlay();
  36.     GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("begin play"));
  37.    
  38.     setIgnoreActors();
  39.     if (bSelf)
  40.     {
  41.         GetWorld()->GetTimerManager().SetTimer(SelfCastHandle, this, &AlilSpellBase::selfCast, .01, true, 0);
  42.     }
  43. }
  44.  
  45. void AlilSpellBase::BeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
  46. {
  47.     MyOwner = GetOwner();
  48.     if (!bSelf) {
  49.         if (aIgnoreActors.Num() < 1) {
  50.             setIgnoreActors();
  51.         }
  52.         if (MyOwner != nullptr)
  53.         {
  54.             FString sMyOwner = MyOwner->GetName();
  55.             GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, sMyOwner);
  56.             if (IsValid(MyOwner->GetInstigatorController())) {
  57.                 GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("True"));
  58.                 UGameplayStatics::ApplyDamage(OtherActor, fDamage, MyOwner->GetInstigatorController(), this, dType);
  59.             }
  60.         }
  61.         else {
  62.             GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("No Owner"));
  63.         }
  64.     }
  65.    
  66. }
  67.  
  68. void AlilSpellBase::setIgnoreActors()
  69. {
  70.     MyOwner = GetOwner();
  71.     if (MyOwner) {
  72.         GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("setting actors"));
  73.         MyOwner->GetAttachedActors(aIgnoreActors);
  74.         aIgnoreActors.AddUnique(MyOwner);
  75.     }
  76. }
  77.  
  78. void AlilSpellBase::selfCast()
  79. {
  80.     MyOwner = GetOwner();
  81.     GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("self effect"));
  82.     UGameplayStatics::ApplyDamage(MyOwner, fDamage, MyOwner->GetInstigatorController(), this, dType);
  83. }
  84.  
  85. // Called every frame
  86. /*
  87. void AlilSpellBase::Tick(float DeltaTime)
  88. {
  89.     Super::Tick(DeltaTime);
  90.  
  91. }
  92.  
  93. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement