コード例 #1
0
bool ASpellCPP::IsValidTarget(AActor* target)
{
	if (!target) {
		return false;
	}

	if (target->IsA(ABaseCharacter::StaticClass())) {
		auto targetCharacter = Cast<ABaseCharacter>(target);
		auto ownerCharacter = Cast<ABaseCharacter>(this->GetOwner());
		if (ownerCharacter) {
			if (ownerCharacter == target) {
				return false;
			}

			if (ownerCharacter->TeamID != targetCharacter->TeamID) {
				return TargetType == FTargetType::Enemy || TargetType == FTargetType::All;
			}
			else {
				return TargetType == FTargetType::Friendly || TargetType == FTargetType::All;
			}
		}
		else {
			// If this spell is not owned by a character, then it is owned by the level, in which case we only want it to affect players.
			return targetCharacter->IsPlayerControlled();
		}
	}

	// We'll collide with anything that isn't a character, probably environment geometry
	return true;
}
コード例 #2
0
ファイル: Tank.cpp プロジェクト: benmyb/TankGame
float ATank::TakeDamage(float DamageAmount, FDamageEvent const & DamageEvent, AController * EventInstigator, AActor * DamageCauser)
{
	float DamagePoint = DamageAmount;
	float DamageToApply = FMath::Clamp<float>(DamagePoint, 0.0f, CurrentHp);
	CurrentHp -= DamageToApply;
	if (CurrentHp <= 0) {
		//̹¿ËËÀÍö
		//UE_LOG(LogTemp, Warning, TEXT("Tank dead,Tank Name:%s"), *GetName());
		OnDeath.Broadcast();
		if (IsPlayerControlled()) {

		}
		else {
			Destroy();
		}
	}
	return DamageToApply;
}