EBTNodeResult::Type UMyBTTask_ResetRoute::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	
	/* Check whether the AIController component exists to avoid errors */
	ABotAI* MyController = Cast<ABotAI>(OwnerComp.GetAIOwner());
	if (MyController == nullptr)
	{
		return EBTNodeResult::Failed;
	}


	//uint8 BBResetRoute = OwnerComp.GetBlackboardComponent()->GetKeyID("ResetRoute");
	//uint8 BBResetRoute = OwnerComp.GetBlackboardComponent()->GetKeyID("ResetRoute");


	uint8 BBResetRoute = OwnerComp.GetBlackboardComponent()->GetKeyID("ResetRoute");
	OwnerComp.GetBlackboardComponent()->SetValueAsBool(BBResetRoute, true);
	//	uint8 BBResetRoute = OwnerComp.GetBlackboardComponent()->GetKeyID("ResetRoute");
		
	return EBTNodeResult::Succeeded;

		
		



}
void UBTDecorator_BlueprintBase::OnBecomeRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	if (AIOwner != nullptr && ReceiveObserverActivatedImplementations & FBTNodeBPImplementationHelper::AISpecific)
	{
		ReceiveObserverActivatedAI(AIOwner, AIOwner->GetPawn());
	}
	else if (ReceiveObserverActivatedImplementations & FBTNodeBPImplementationHelper::Generic)
	{
		ReceiveObserverActivated(ActorOwner);
	}

	if (GetNeedsTickForConditionChecking())
	{
		// if set up as observer, and has a condition check, we want to check the condition every frame
		// highly inefficient, but hopefully people will use it only for prototyping.
		bNotifyTick = true;
	}

	UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
	if (BlackboardComp)
	{
		for (int32 NameIndex = 0; NameIndex < ObservedKeyNames.Num(); NameIndex++)
		{
			const FBlackboard::FKey KeyID = BlackboardComp->GetKeyID(ObservedKeyNames[NameIndex]);
			if (KeyID != FBlackboard::InvalidKey)
			{
				BlackboardComp->RegisterObserver(KeyID, this, FOnBlackboardChange::CreateUObject(this, &UBTDecorator_BlueprintBase::OnBlackboardChange));
			}
		}
	}
}
EBTNodeResult::Type USetMaxWalkSpeed::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	Super::ExecuteTask(OwnerComp, NodeMemory);

	if (!GetWorld())
	{
		return EBTNodeResult::Failed;
	}

	AActor* AnnaActor = OwnerComp.GetBlackboardComponent()->GetOwner();

	if (AnnaActor)
	{
		ACharacter*  AnnaCharacter = Cast<AController>(AnnaActor)->GetCharacter();

		if (AnnaCharacter)
		{
			AnnaCharacter->GetCharacterMovement()->MaxWalkSpeed = DesiredMaxSpeed;

			EBTNodeResult::Succeeded;
		}
	}

	return EBTNodeResult::Failed;
}
EBTNodeResult::Type USetNextTargetPoint::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	Super::ExecuteTask(OwnerComp, NodeMemory);

	if (!GetWorld())
	{
		return EBTNodeResult::Failed;
	}

	//Set the blackboard to make calling it easier in the future

	UBlackboardComponent* Blackboard = OwnerComp.GetBlackboardComponent();

	//Get the ID of the key that we state in the editor
	uint8 TargetKeyID = Blackboard->GetKeyID(TargetName);

	//Get the AI so we can call a function on it
	UObject* SelfActor = Blackboard->GetValue<UBlackboardKeyType_Object>(TargetKeyID);

	//Cast it to the proper class
	AShadowAnnaCharacter* ShadowAnna = Cast<AShadowAnnaCharacter>(SelfActor);
	if (ShadowAnna)
	{
	//IF the cast works call the function
		//FVector NewTarget = ShadowAnna->SetNextTargetPoint();

		//Blackboard->SetValue<UBlackboardKeyType_Vector>(BlackboardKey.GetSelectedKeyID(), NewTarget);

		return EBTNodeResult::Succeeded;
	}

	return EBTNodeResult::Failed;
}
Ejemplo n.º 5
0
EBTNodeResult::Type URandomWander::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{

	UBlackboardComponent* Blackboard = OwnerComp.GetBlackboardComponent();

	if (!GetWorld())
	{
		return EBTNodeResult::Failed;
	}

	FVector NewWaypoint = FVector::ZeroVector;

	FVector CurrentPos = Blackboard->GetOwner()->GetActorLocation();

	NewWaypoint.X = CurrentPos.X + FMath::FRandRange(-5000, 5000);
	NewWaypoint.Y = CurrentPos.Y + FMath::FRandRange(-5000, 5000);

	while (FVector::Dist(NewWaypoint, Blackboard->GetOwner()->GetActorLocation()) <= 2000.f && TraceFromPosition(OutResult, 100.f, ECollisionChannel::ECC_EngineTraceChannel1, NewWaypoint, OwnerComp) == false)
	{
		NewWaypoint.X = CurrentPos.X + FMath::FRandRange(-5000, 5000);
		NewWaypoint.Y = CurrentPos.Y + FMath::FRandRange(-5000, 5000);
	}

	if (!NewWaypoint.IsZero())
	{
		Blackboard->SetValue<UBlackboardKeyType_Vector>(BlackboardKey.GetSelectedKeyID(), NewWaypoint);

		return EBTNodeResult::Succeeded;
	}

	return EBTNodeResult::Failed;
}
bool UBTDecorator_IsAtLocation::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const
{
	bool bHasReached = false;

	AAIController* AIOwner = OwnerComp.GetAIOwner();
	UPathFollowingComponent* PathFollowingComponent = AIOwner ? AIOwner->GetPathFollowingComponent() : nullptr;
	if (PathFollowingComponent)
	{
		const UBlackboardComponent* MyBlackboard = OwnerComp.GetBlackboardComponent();

		if (BlackboardKey.SelectedKeyType == UBlackboardKeyType_Object::StaticClass())
		{
			UObject* KeyValue = MyBlackboard->GetValue<UBlackboardKeyType_Object>(BlackboardKey.GetSelectedKeyID());
			AActor* TargetActor = Cast<AActor>(KeyValue);
			if (TargetActor)
			{
				bHasReached = PathFollowingComponent->HasReached(*TargetActor, AcceptableRadius, false, bUseNavAgentGoalLocation);
			}
		}
		else if (BlackboardKey.SelectedKeyType == UBlackboardKeyType_Vector::StaticClass())
		{
			const FVector TargetLocation = MyBlackboard->GetValue<UBlackboardKeyType_Vector>(BlackboardKey.GetSelectedKeyID());
			if (FAISystem::IsValidLocation(TargetLocation))
			{
				bHasReached = PathFollowingComponent->HasReached(TargetLocation, AcceptableRadius);
			}
		}
	}

	return bHasReached;
}
Ejemplo n.º 7
0
EBTNodeResult::Type UBTTask_MoveToPlayer::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	AEnemyAI *CharPC = Cast<AEnemyAI>(OwnerComp.GetAIOwner());

	ASacredHeartCharacter *Enemy = Cast<ASacredHeartCharacter>(OwnerComp.GetBlackboardComponent()->GetValue<UBlackboardKeyType_Object>(CharPC->EnemyKeyID));
	if (Enemy)
	{
		int bpm = Enemy->heartRate;

		if (bpm > 100)
		{
		CharPC->GetCharacter()->GetCharacterMovement()->MaxWalkSpeed = 550;
		CharPC->MoveToActor(Enemy, 5.f, true, true, true, 0, true);
		return EBTNodeResult::Succeeded;
		}
		else
		{

			return EBTNodeResult::Failed;
		}
	}
	else
	{
		return EBTNodeResult::Failed;
	}

	
}
EBTNodeResult::Type UMyBTTask_FindWayPoint::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{

/* Check whether the AIController component exists to avoid errors */
ABotAI* MyController = Cast<ABotAI>(OwnerComp.GetAIOwner());
if (MyController == nullptr)
{
	return EBTNodeResult::Failed;
} 

/* Gets pointer to a waypoint */
AEnemyWayPoint* CurrentWaypoint = MyController->GetWaypoint();
AActor* NewWaypoint = nullptr;

/* Get all Actors of type "EnemyWayPoint" in the level, and Iterate through them */
TArray<AActor*> AllWaypoints;
UGameplayStatics::GetAllActorsOfClass(MyController, AEnemyWayPoint::StaticClass(), AllWaypoints);

/* Select one random waypoint by index */
NewWaypoint = AllWaypoints[FMath::RandRange(0, AllWaypoints.Num() - 1)];

if (NewWaypoint)
{
	/* Assign the retrieved waypoint to blackboard as the new move destination */
	OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Object>(BlackboardKey.GetSelectedKeyID(), NewWaypoint);
	return EBTNodeResult::Succeeded;
}

return EBTNodeResult::Failed;


}
EBTNodeResult::Type UChooseNextWaypoint::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	// Get the patrol route
	auto ControlledPawn = OwnerComp.GetAIOwner()->GetPawn();
	auto PatrolRoute = ControlledPawn->FindComponentByClass<UPatrolRoute>();
	if (!ensure(PatrolRoute)) { return EBTNodeResult::Failed; }

	// Warn about empty patrol routes
	auto PatrolPoints = PatrolRoute->GetPatrolPoints();
	if (PatrolPoints.Num() == 0)
	{
		UE_LOG(LogTemp, Warning, TEXT("A guard is missing patrol points."));
		return EBTNodeResult::Failed;
	}

	// Set the next waypoint
	auto BlackboardComp = OwnerComp.GetBlackboardComponent();
	auto Index = BlackboardComp->GetValueAsInt(IndexKey.SelectedKeyName);
	BlackboardComp->SetValueAsObject(WaypointKey.SelectedKeyName, PatrolPoints[Index]);
	
	// Cycle the index
	auto NextIndex = (Index + 1) % PatrolPoints.Num();
	BlackboardComp->SetValueAsInt(IndexKey.SelectedKeyName, NextIndex);

	// UE_LOG(LogTemp, Warning, TEXT("Waypoint index: %i"), Index);

	return EBTNodeResult::Succeeded;
}
// @note I know it's ugly to have "return" statements in many places inside a function, but the way 
// around was very awkward here 
bool UBTDecorator_CompareBBEntries::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const
{
	// first of all require same type
	// @todo this could be checked statically (i.e. in editor, asset creation time)!
	if (BlackboardKeyA.SelectedKeyType != BlackboardKeyB.SelectedKeyType)
	{
		return false;
	}
	
	const UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
	if (BlackboardComp)
	{
		//BlackboardComp->GetKeyType
		const EBlackboardCompare::Type Result = BlackboardComp->CompareKeyValues(BlackboardKeyA.SelectedKeyType, 
			BlackboardKeyA.GetSelectedKeyID(), BlackboardKeyB.GetSelectedKeyID());

		static_assert(int32(EBlackboardCompare::Equal) == int32(EBlackBoardEntryComparison::Equal)
			&& int32(EBlackboardCompare::NotEqual) == int32(EBlackBoardEntryComparison::NotEqual),
			"These values need to be equal");

		return int32(Operator) == int32(Result);
	}

	return false;
}
void UBTDecorator_CompareBBEntries::OnCeaseRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
	if (BlackboardComp)
	{
		BlackboardComp->UnregisterObserversFrom(this);
	}
}
void UBTDecorator_CompareBBEntries::OnBecomeRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
	if (BlackboardComp)
	{
		BlackboardComp->RegisterObserver(BlackboardKeyA.GetSelectedKeyID(), this, FOnBlackboardChange::CreateUObject(this, &UBTDecorator_CompareBBEntries::OnBlackboardChange));
		BlackboardComp->RegisterObserver(BlackboardKeyB.GetSelectedKeyID(), this, FOnBlackboardChange::CreateUObject(this, &UBTDecorator_CompareBBEntries::OnBlackboardChange));
	}
}
Ejemplo n.º 13
0
EBTNodeResult::Type UBoolChange::ExecuteTask(UBehaviorTreeComponent & OwnerComp, uint8 * NodeMemory)
{
	Super::ExecuteTask(OwnerComp, NodeMemory);

	if (!GetWorld())
	{
		return EBTNodeResult::Failed;
	}
	if (!CurrentBanditController)
	{
		Controller = OwnerComp.GetAIOwner();
		CurrentBanditController = Cast<ABanditController>(Controller);
	}
	if (CurrentBanditController)
	{
		OwnerComp.GetBlackboardComponent()->SetValueAsBool(TEXT("PlayerSpotted"), true);
		OwnerComp.GetBlackboardComponent()->SetValueAsBool(TEXT("PlayerNearby"), true);
		return EBTNodeResult::Succeeded;
	}
	return EBTNodeResult::Failed;
}
EBTNodeResult::Type UBTTaskNode_ChooseNextSpell::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	Super::ExecuteTask(OwnerComp, NodeMemory);

	auto controller = Cast<ABaseAIController>(OwnerComp.GetAIOwner());
	auto blackboard = OwnerComp.GetBlackboardComponent();

	auto spellData = controller->GetNextSpell();

	blackboard->SetValueAsObject("NextSpell", spellData);

	return EBTNodeResult::Type::Succeeded;
}
Ejemplo n.º 15
0
void UBTTask_MoveDirectlyToward::DescribeRuntimeValues(const UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, EBTDescriptionVerbosity::Type Verbosity, TArray<FString>& Values) const
{
	Super::DescribeRuntimeValues(OwnerComp, NodeMemory, Verbosity, Values);

	const UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
	FBTMoveDirectlyTowardMemory* MyMemory = reinterpret_cast<FBTMoveDirectlyTowardMemory*>(NodeMemory);

	if (MyMemory->MoveRequestID && BlackboardComp)
	{
		FString KeyValue = BlackboardComp->DescribeKeyValue(BlackboardKey.GetSelectedKeyID(), EBlackboardDescription::OnlyValue);
		Values.Add(FString::Printf(TEXT("move target: %s"), *KeyValue));
	}
}
void UBTService_SearchPlayer::TickNode(UBehaviorTreeComponent &OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
	if (!OwnerComp.GetBlackboardComponent())
	{
		GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, "Failed to get Blackboard Component");
		return;
	}

	OwnerComp.GetBlackboardComponent()->SetValueAsObject("Player", (UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)));

	if (OwnerComp.GetBlackboardComponent()->GetValueAsEnum("State") == static_cast<uint8>(EState::ES_Combat))
	{
		APawn* Player = (UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
		ALivingEntity* Enemy = nullptr;
		
		AEnemyController* EnemyController = Cast<AEnemyController>(OwnerComp.GetOwner());
		if (EnemyController)
		{
			Enemy = Cast<ALivingEntity>(EnemyController->GetPawn());
		}

		if (Player && Enemy)
		{
			if (!CanSeePlayer(Enemy, Player))
			{
				OwnerComp.GetBlackboardComponent()->SetValueAsEnum("State", static_cast<uint8>(EState::ES_Walking));
			}
			else
			{
				EnemyController->UpdateMemoryMarker(Player->GetActorLocation());
			}
		}
		else
		{
			GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, "Error whilst casting");
		}
	}
}
void UBTDecorator_UtilityBlackboard::DescribeRuntimeValues(const UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, EBTDescriptionVerbosity::Type Verbosity, TArray<FString>& Values) const
{
	Super::DescribeRuntimeValues(OwnerComp, NodeMemory, Verbosity, Values);

	const UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
	FString DescKeyValue;

	if (BlackboardComp)
	{
		DescKeyValue = BlackboardComp->DescribeKeyValue(UtilityValueKey.GetSelectedKeyID(), EBlackboardDescription::OnlyValue);
	}

	Values.Add(FString::Printf(TEXT("utility: %s"), *DescKeyValue));
}
Ejemplo n.º 18
0
EBTNodeResult::Type UATBTTask_MoveArea::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	UNavigationSystem* NavigationSystem = UNavigationSystem::GetCurrent(GetWorld());
	AATCharacterAI* MyCharacter = Cast<AATCharacterAI>(OwnerComp.GetAIOwner()->GetPawn());

	if (NavigationSystem != nullptr && MyCharacter != nullptr)
	{
		FNavLocation RandomPointIn;
		if (NavigationSystem->GetRandomPointInNavigableRadius(MyCharacter->GetActorLocation(), MyCharacter->AreaRadius, RandomPointIn))
		{
			OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Vector>(GetSelectedBlackboardKey(), RandomPointIn.Location);
			return EBTNodeResult::Succeeded;
		}
	}
	return EBTNodeResult::Failed;
}
float UBTDecorator_UtilityBlackboard::CalculateUtilityValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const
{
	const UBlackboardComponent* MyBlackboard = OwnerComp.GetBlackboardComponent();
	float Value = 0.0f;

	if (UtilityValueKey.SelectedKeyType == UBlackboardKeyType_Float::StaticClass())
	{
		Value = MyBlackboard->GetValue< UBlackboardKeyType_Float >(UtilityValueKey.GetSelectedKeyID());
	}
	else if (UtilityValueKey.SelectedKeyType == UBlackboardKeyType_Int::StaticClass())
	{
		Value = (float)MyBlackboard->GetValue< UBlackboardKeyType_Int >(UtilityValueKey.GetSelectedKeyID());
	}

	return FMath::Max(Value, 0.0f);
}
Ejemplo n.º 20
0
EBTNodeResult::Type UBTTask_MoveDirectlyToward::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	const UBlackboardComponent* MyBlackboard = OwnerComp.GetBlackboardComponent();
	FBTMoveDirectlyTowardMemory* MyMemory = reinterpret_cast<FBTMoveDirectlyTowardMemory*>(NodeMemory);
	AAIController* MyController = OwnerComp.GetAIOwner();
	EBTNodeResult::Type NodeResult = EBTNodeResult::Failed;

	if (MyController && MyBlackboard)
	{
		EPathFollowingRequestResult::Type RequestResult = EPathFollowingRequestResult::Failed;

		if (BlackboardKey.SelectedKeyType == UBlackboardKeyType_Object::StaticClass())
		{
			UObject* KeyValue = MyBlackboard->GetValue<UBlackboardKeyType_Object>(BlackboardKey.GetSelectedKeyID());
			AActor* TargetActor = Cast<AActor>(KeyValue);
			if (TargetActor)
			{
				RequestResult = bDisablePathUpdateOnGoalLocationChange ?
					MyController->MoveToLocation(TargetActor->GetActorLocation(), AcceptableRadius, bStopOnOverlap, /*bUsePathfinding=*/false, /*bProjectDestinationToNavigation=*/bProjectVectorGoalToNavigation, bAllowStrafe) :
					MyController->MoveToActor(TargetActor, AcceptableRadius, bStopOnOverlap, /*bUsePathfinding=*/false, bAllowStrafe);
			}
		}
		else if (BlackboardKey.SelectedKeyType == UBlackboardKeyType_Vector::StaticClass())
		{
			const FVector TargetLocation = MyBlackboard->GetValue<UBlackboardKeyType_Vector>(BlackboardKey.GetSelectedKeyID());
			RequestResult = MyController->MoveToLocation(TargetLocation, AcceptableRadius, bStopOnOverlap, /*bUsePathfinding=*/false, /*bProjectDestinationToNavigation=*/bProjectVectorGoalToNavigation, bAllowStrafe);
		}

		if (RequestResult == EPathFollowingRequestResult::RequestSuccessful)
		{
			const FAIRequestID RequestID = MyController->GetCurrentMoveRequestID();

			MyMemory->MoveRequestID = RequestID;
			WaitForMessage(OwnerComp, UBrainComponent::AIMessage_MoveFinished, RequestID);

			NodeResult = EBTNodeResult::InProgress;
		}
		else if (RequestResult == EPathFollowingRequestResult::AlreadyAtGoal)
		{
			NodeResult = EBTNodeResult::Succeeded;
		}
	}

	return NodeResult;
}
Ejemplo n.º 21
0
EBTNodeResult::Type UGoToWaypoint::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	Super::ExecuteTask(OwnerComp, NodeMemory);

	if (!GetWorld())
	{
		return EBTNodeResult::Failed;
	}
	AAIController* MyController = OwnerComp.GetAIOwner();
	ABanditController* CurrBanditController = Cast<ABanditController>(MyController);

	if (CurrBanditController)
	{
		
		ATestTargetPoint* CurrentWaypoint = CurrBanditController->CurrentWaypoint();
		if (CurrentWaypoint)
		{
			OwnerComp.GetBlackboardComponent()->SetValueAsObject(TEXT("CurrentTarget"), CurrentWaypoint);
			return EBTNodeResult::Succeeded;
		}
		else
		{
			return EBTNodeResult::Failed;
		}
	}
	else
	{
		return EBTNodeResult::Failed;
	}
	//for (TActorIterator<ATestTargetPoint> ActorItr(GetWorld()); ActorItr; ++ActorItr)
	//{
	//	ATestTargetPoint* Waypoint = *ActorItr;
	//	if (Waypoint)
	//	{
	//		OwnerComp.GetBlackboardComponent()->SetValueAsObject(TEXT("Target1"), Waypoint);
	//		OwnerComp.GetBlackboardComponent()->SetValueAsObject(TEXT("CurrentTarget"), Waypoint);
	//		
	//		return EBTNodeResult::Succeeded;
	//	}
	//}
	return EBTNodeResult::Failed;
}
void ULowEnergyService::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
	Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);

	// If the blackboard comp doesnt exist, exit
	UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
	if (!BlackboardComp)
		return;

	// Get the mech controller and see if it exists
	AMechAIController* MechController = Cast<AMechAIController>(OwnerComp.GetAIOwner());
	if (!MechController)
		return;

	// Get the ai character and see if it exists
	AMechAICharacter* AICharacter = Cast<AMechAICharacter>(MechController->GetControlledPawn());
	if (!AICharacter)
		return;

}
bool UBTDecorator_HasLoSTo::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const
{
	const UBlackboardComponent* MyBlackboard = OwnerComp.GetBlackboardComponent();
	AAIController* MyController = OwnerComp.GetAIOwner();
	bool HasLOS = false;

	if (MyController && MyBlackboard)
	{
		auto MyID = MyBlackboard->GetKeyID(EnemyKey.SelectedKeyName);
		auto TargetKeyType = MyBlackboard->GetKeyType(MyID);

		FVector TargetLocation;
		bool bGotTarget = false;
		AActor* EnemyActor = NULL;
		if (TargetKeyType == UBlackboardKeyType_Object::StaticClass())
		{
			UObject* KeyValue = MyBlackboard->GetValue<UBlackboardKeyType_Object>(MyID);
			EnemyActor = Cast<AActor>(KeyValue);
			if (EnemyActor)
			{
				TargetLocation = EnemyActor->GetActorLocation();
				bGotTarget = true;
			}
		}
		else if (TargetKeyType == UBlackboardKeyType_Vector::StaticClass())
		{
			TargetLocation = MyBlackboard->GetValue<UBlackboardKeyType_Vector>(MyID);
			bGotTarget = true;
		}

		if (bGotTarget == true)
		{
			if (LOSTrace(OwnerComp.GetOwner(), EnemyActor, TargetLocation) == true)
			{
				HasLOS = true;
			}
		}
	}

	return HasLOS;
}
void UDistanceToGhost::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
	Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);

	UBlackboardComponent* Blackboard = OwnerComp.GetBlackboardComponent();

	UObject* TargetObject = Blackboard->GetValue<UBlackboardKeyType_Object>(TargetName);

	AGGJ16_AIController* AIController = Cast<AGGJ16_AIController>(Blackboard->GetOwner());

	AGGJ16_Vani* VaniCharacter = Cast<AGGJ16_Vani>(TargetObject);

	if (AIController && VaniCharacter)
	{
		Distance = FVector::Dist(VaniCharacter->GetActorLocation(), AIController->GetPawn()->GetActorLocation());

		Blackboard->SetValue<UBlackboardKeyType_Float>(BlackboardKey.GetSelectedKeyID(), Distance);
	}

	GEngine->AddOnScreenDebugMessage(4, 1, FColor::Blue, TEXT("Ding"));
}
Ejemplo n.º 25
0
EBTNodeResult::Type UFindEnemyTask::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	if (!GetWorld())
	{
		return EBTNodeResult::Failed;
	}

	for (TActorIterator<AMyCharacter> ActorItr(GetWorld()); ActorItr; ++ActorItr)
	{
		AMyCharacter* PlayerCharacter = *ActorItr;
		if (PlayerCharacter)
		{
			OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Object>(
				BlackboardKey.GetSelectedKeyID(), PlayerCharacter);

			return EBTNodeResult::Succeeded;
		}
	}

	return EBTNodeResult::Failed;
}
void UCheckDistanceService::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
	Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);

	UBlackboardComponent* Blackboard = OwnerComp.GetBlackboardComponent();

	UObject* TargetObject = Blackboard->GetValue<UBlackboardKeyType_Object>(TargetName);

	AArin* PlayerCharacter = Cast<AArin>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));

	ABaseAIController* AIController = Cast<ABaseAIController>(Blackboard->GetOwner());

	if (AIController && PlayerCharacter)
	{
		Distance = FVector::Dist(PlayerCharacter->GetActorLocation(), AIController->GetPawn()->GetActorLocation());

		Blackboard->SetValue<UBlackboardKeyType_Float>(BlackboardKey.GetSelectedKeyID(), Distance);
	}

	GEngine->AddOnScreenDebugMessage(4, 1, FColor::Blue, TEXT("Ding"));
}
bool UBTDecorator_KeepInCone::CalculateCurrentDirection(const UBehaviorTreeComponent& OwnerComp, FVector& Direction) const
{
	const UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
	if (BlackboardComp == NULL)
	{
		return false;
	}

	FVector PointA = FVector::ZeroVector;
	FVector PointB = FVector::ZeroVector;
	const bool bHasPointA = BlackboardComp->GetLocationFromEntry(ConeOrigin.GetSelectedKeyID(), PointA);
	const bool bHasPointB = BlackboardComp->GetLocationFromEntry(Observed.GetSelectedKeyID(), PointB);

	if (bHasPointA && bHasPointB)
	{
		Direction = (PointB - PointA).GetSafeNormal();
		return true;
	}

	return false;
}
Ejemplo n.º 28
0
EBTNodeResult::Type UBTTask_FindPointNearWaypoint::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	AsbrAIController* aiController = Cast<AsbrAIController>(OwnerComp.GetAIOwner());
	if (aiController == NULL)
		return EBTNodeResult::Failed;

	ATargetPoint* waypoint = aiController->GetWaypoint();
	if (waypoint)
	{
		const float SearchRadius = 200.0f;
		const FVector SearchOrigin = waypoint->GetActorLocation();
		const FVector Loc = UNavigationSystem::GetRandomPointInNavigableRadius(aiController, SearchOrigin, SearchRadius);
		if (Loc != FVector::ZeroVector)
		{
			OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Vector>(BlackboardKey.GetSelectedKeyID(), Loc);
			aiController->SetWaypointVisited(waypoint);	// сообщаем что посетили waypoint (todo: надо учесть расстояние)
			return EBTNodeResult::Succeeded;
		}
	}

	return EBTNodeResult::Failed;
}
Ejemplo n.º 29
0
void UBTDecorator_BlueprintBase::OnCeaseRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
	if (BlackboardComp)
	{
		BlackboardComp->UnregisterObserversFrom(this);
	}
		
	if (AIOwner != nullptr && ReceiveObserverDeactivatedImplementations & FBTNodeBPImplementationHelper::AISpecific)
	{
		ReceiveObserverDeactivatedAI(AIOwner, AIOwner->GetPawn());
	}
	else if (ReceiveObserverDeactivatedImplementations & FBTNodeBPImplementationHelper::Generic)
	{
		ReceiveObserverDeactivated(ActorOwner);
	}

	if (GetNeedsTickForConditionChecking() == true && ReceiveTickImplementations == 0)
	{
		// clean up the tick request if no longer "active"
		bNotifyTick = false;
	}
}
Ejemplo n.º 30
-1
EBTNodeResult::Type UEngageTask::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	UBehaviorTreeComponent* BTComp = &OwnerComp;
	const UBlackboardComponent* BlackboardComp = BTComp->GetBlackboardComponent();
	AAgentController* Controller = Cast<AAgentController>(BTComp->GetAIOwner());

	if (Controller == NULL)
	{
		return EBTNodeResult::Failed;
	}
	else
	{
		class AAgent* Agent = Controller->GetAgentOwner();
		// If the agent's weapon has ammo in it
		if (Agent->GetCurrentWeapon()->CalculateAmmo() > 0)
		{
			// Ensure reload is set to false because it should have been reloaded at this stage
			Agent->EndReload();
			// Shoot
			Agent->Fire();
		}
		else
		{
			// Stop firing if firing
			Agent->StopFiring();
			// Reload
			Agent->BeginReload();
		}

		return EBTNodeResult::Succeeded;
	}
	return EBTNodeResult::Failed;
}