Guest User

Untitled

a guest
Apr 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "ABItemBox.h"
  4. #include "ABWeapon.h"
  5. #include "ABCharacter.h"
  6.  
  7. // Sets default values
  8. AABItemBox::AABItemBox()
  9. {
  10. // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
  11. PrimaryActorTick.bCanEverTick = false;
  12.  
  13. Trigger = CreateDefaultSubobject<UBoxComponent>(TEXT("TRIGGER"));
  14. Box = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BOX"));
  15. Effect = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("EFFECT"));
  16.  
  17. RootComponent = Trigger;
  18. Box->SetupAttachment(RootComponent);
  19. Effect->SetupAttachment(RootComponent);
  20.  
  21. Trigger->SetBoxExtent(FVector(40.0f, 42.0f, 30.0f));
  22. static ConstructorHelpers::FObjectFinder<UStaticMesh> SM_BOX(TEXT("/Game/InfinityBladeGrassLands/Environments/Breakables/StaticMesh/Box/SM_Env_Breakables_Box1.SM_Env_Breakables_Box1"));
  23. if (SM_BOX.Succeeded())
  24. {
  25. Box->SetStaticMesh(SM_BOX.Object);
  26. }
  27.  
  28. static ConstructorHelpers::FObjectFinder<UParticleSystem> P_CHESTOPEN(TEXT("/Game/InfinityBladeGrassLands/Effects/FX_Treasure/Chest/P_TreasureChest_Open_Mesh.P_TreasureChest_Open_Mesh"));
  29. if (P_CHESTOPEN.Succeeded())
  30. {
  31. Effect->SetTemplate(P_CHESTOPEN.Object);
  32. Effect->bAutoActivate = false;
  33. }
  34.  
  35. Box->SetRelativeLocation(FVector(0.0f, -3.5f, -30.0f));
  36.  
  37. Trigger->SetCollisionProfileName(TEXT("ItemBox"));
  38. Box->SetCollisionProfileName(TEXT("NoCollision"));
  39.  
  40. WeaponItemClass = AABWeapon::StaticClass();
  41. }
  42.  
  43. // Called when the game starts or when spawned
  44. void AABItemBox::BeginPlay()
  45. {
  46. Super::BeginPlay();
  47.  
  48. }
  49.  
  50. void AABItemBox::PostInitializeComponents()
  51. {
  52. Super::PostInitializeComponents();
  53. Trigger->OnComponentBeginOverlap.AddDynamic(this, &AABItemBox::OnCharacterOverlap);
  54. }
  55.  
  56. void AABItemBox::OnCharacterOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
  57. {
  58. ABLOG_S(Warning);
  59.  
  60. auto ABCharacter = Cast<AABCharacter>(OtherActor);
  61. ABCHECK(nullptr != ABCharacter);
  62.  
  63. if (nullptr != ABCharacter && nullptr != WeaponItemClass)
  64. {
  65. if (ABCharacter->CanSetWeapon())
  66. {
  67. auto NewWeapon = GetWorld()->SpawnActor<AABWeapon>(WeaponItemClass, FVector::ZeroVector, FRotator::ZeroRotator);
  68. ABCharacter->SetWeapon(NewWeapon);
  69. Effect->Activate(true);
  70. Box->SetHiddenInGame(true, true);
  71. SetActorEnableCollision(false);
  72. Effect->OnSystemFinished.AddDynamic(this, &AABItemBox::OnEffectFinished);
  73. }
  74. else
  75. {
  76. ABLOG(Warning, TEXT("%s can't equip weapon currently."), *ABCharacter->GetName());
  77. }
  78. }
  79. }
  80.  
  81. void AABItemBox::OnEffectFinished(UParticleSystemComponent * PSystem)
  82. {
  83. Destroy();
  84. }
Add Comment
Please, Sign In to add comment