fixed attack problem

pull/6/head
m4xxx1m 2 years ago
parent 2be6c07339
commit d7738e00a6

@ -24,17 +24,15 @@ void AMyGameState::StartGame() const {
PlayerInTurn()->StartTurn();
}
void AMyGameState::CycleTurns_Implementation(uint8 CurrentPlayerIndex) {
if (CurrentPlayerTurn == CurrentPlayerIndex) {
PlayerInTurn()->EndTurn();
for (const auto Trooper : Troopers) {
if (Trooper != nullptr) {
Trooper->ResetActionPoints();
}
void AMyGameState::CycleTurns_Implementation() {
PlayerInTurn()->EndTurn();
for (const auto Trooper : Troopers) {
if (Trooper != nullptr) {
Trooper->ResetActionPoints();
}
CurrentPlayerTurn = !CurrentPlayerTurn;
PlayerInTurn()->StartTurn();
}
CurrentPlayerTurn = !CurrentPlayerTurn;
PlayerInTurn()->StartTurn();
}
// void AMyGameState::CycleTurns(uint8 CurrentPlayerIndex) {

@ -24,7 +24,7 @@ public:
void StartGame() const;
UFUNCTION(BlueprintCallable, Server, Reliable)
void CycleTurns(uint8 CurrentPlayerIndex);
void CycleTurns();
UFUNCTION(BlueprintPure)
AMyPlayerState *PlayerInTurn() const;

@ -50,6 +50,13 @@ auto AMyPlayerController::GetMyGameMode() const {
}
void AMyPlayerController::EndTurn() {
// if (GetMyPlayerState()->IsMyTurn()) {
// GetMyGameState()->CycleTurns();
// }
GetMyPlayerState()->CycleTurns();
}
// void AMyPlayerController::EndTurn_Implementation() {
// GetMyPlayerState()->EndTurn();
// }
@ -125,17 +132,17 @@ void AMyPlayerController::SetPlayerIndex(uint8 NewPlayerIndex) {
// GetMyPlayerState()->PlayerIndex = NewPlayerIndex;
}
float AMyPlayerController::SetCurrentActionAndReturnRadius(int action) {
return GetMyPlayerState()->SetCurrentActionAndReturnRadius(action);
// CurrentAction = action;
// UE_LOG(LogTemp, Warning, TEXT("SetCurrentAction: %d on Player Controller "
// "with index %d"), CurrentAction, PlayerIndex);
// if (SelectedTrooper) {
// return SelectedTrooper->GetActionRadius(CurrentAction);
// }
// return 0.0f;
}
// float AMyPlayerController::SetCurrentActionAndReturnRadius(int action) {
// return GetMyPlayerState()->SetCurrentActionAndReturnRadius(action);
//
// // CurrentAction = action;
// // UE_LOG(LogTemp, Warning, TEXT("SetCurrentAction: %d on Player Controller "
// // "with index %d"), CurrentAction, PlayerIndex);
// // if (SelectedTrooper) {
// // return SelectedTrooper->GetActionRadius(CurrentAction);
// // }
// // return 0.0f;
// }
void AMyPlayerController::SetEnemySelection_Implementation(

@ -19,6 +19,9 @@ public:
AMyPlayerController();
UFUNCTION(BlueprintCallable)
void EndTurn();
// UFUNCTION(Client, Reliable)
// void StartTurn();
@ -37,8 +40,8 @@ public:
UFUNCTION()
void SetPlayerIndex(uint8 NewPlayerIndex);
UFUNCTION(BlueprintCallable)
float SetCurrentActionAndReturnRadius(int action);
// UFUNCTION(BlueprintCallable)
// float SetCurrentActionAndReturnRadius(int action);
UFUNCTION(Client, Reliable)
void SetEnemySelection(const TArray<ATrooper *> &Troopers) const;

@ -19,6 +19,37 @@ void AMyPlayerState::SetPlayerIndex(uint8 NewPlayerIndex) {
PlayerIndex = NewPlayerIndex;
}
void AMyPlayerState::MoveTrooper_Implementation(ATrooper *Trooper,
FVector Location) {
if (Trooper->CheckMoveCorrectness(Location)) {
Trooper->MoveTrooper(Location);
// GetMyGameMode()->CycleTurns();
} else {
GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Red,
FString::Printf(
TEXT("Out of move radius!")));
}
}
void AMyPlayerState::Attack_Implementation(ATrooper *Attacker,
FVector Location,
int ActionIndex) {
if (Attacker->CheckAttackCorrectness(Location, ActionIndex)) {
Attacker->Attack(ActionIndex);
} else {
GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Red,
FString::Printf(
TEXT(
"Out of radius or not enough Action Points!")));
}
}
void AMyPlayerState::CycleTurns() const {
if (bIsMyTurn) {
Cast<AMyGameState>(GetWorld()->GetGameState())->CycleTurns();
}
}
bool AMyPlayerState::IsMyTurn() const {
return bIsMyTurn;
}
@ -53,30 +84,6 @@ void AMyPlayerState::EndTurn_Implementation() {
}
}
void AMyPlayerState::MoveTrooper_Implementation(
ATrooper *Trooper,
FVector Location) {
if (Trooper->CheckMoveCorrectness(Location)) {
Trooper->MoveTrooper(Location);
// GetMyGameMode()->CycleTurns();
} else {
GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Red,
FString::Printf(
TEXT("Out of move radius!")));
}
}
void AMyPlayerState::Attack_Implementation(ATrooper *Attacker,
FVector Location,
int ActionIndex) {
if (Attacker && CurrentAction >= 1 && CurrentAction <= 2 &&
Attacker->CheckAttackCorrectness(Location, CurrentAction)) {
Attacker->Attack(CurrentAction);
} else {
UE_LOG(LogTemp, Warning,
TEXT("Out of radius or not enough Action Points"));
}
}
void AMyPlayerState::OnPlayerAction(const FHitResult &HitResult) {
auto const NewlySelectedLocation = HitResult.Location;
@ -125,16 +132,13 @@ void AMyPlayerState::OnPlayerAction(const FHitResult &HitResult) {
}
}
float AMyPlayerState::SetCurrentActionAndReturnRadius(int Action) {
void AMyPlayerState::SetCurrentAction_Implementation(int Action) {
CurrentAction = Action;
UE_LOG(LogTemp, Warning, TEXT("SetCurrentAction: %d on Player Controller "
"with index %d"), CurrentAction, PlayerIndex);
if (SelectedTrooper) {
return SelectedTrooper->GetActionRadius(CurrentAction);
}
return 0.0f;
}
uint8 AMyPlayerState::GetPlayerIndex() {
return PlayerIndex;
}

@ -30,13 +30,16 @@ public:
void Attack(ATrooper *Attacker, FVector Location, int ActionIndex);
UFUNCTION()
void CycleTurns() const;
UFUNCTION(BlueprintCallable)
bool IsMyTurn() const;
UFUNCTION()
void OnPlayerAction(const FHitResult &HitResult);
UFUNCTION(BlueprintCallable)
float SetCurrentActionAndReturnRadius(int Action);
UFUNCTION(BlueprintCallable, Client, Reliable)
void SetCurrentAction(int Action);
UFUNCTION(BlueprintCallable)
uint8 GetPlayerIndex();
@ -56,8 +59,7 @@ private:
UPROPERTY(Replicated)
int CurrentAction = 0;
UPROPERTY(Replicated)
ATrooper *SelectedTrooper;
};

@ -214,7 +214,8 @@ bool ATrooper::CheckMoveCorrectness(const FVector newPos) const {
bool ATrooper::CheckAttackCorrectness(const FVector attackLocation,
int abilityIndex) const {
return (attackLocation - CurrentLocation).Size() <=
return GetAbility(abilityIndex) != nullptr && (
attackLocation - CurrentLocation).Size() <=
GetAbility(abilityIndex)->ActionRadius && ActionPoints >=
GetAbility(abilityIndex)->ActionCost;
// return (attackLocation - CurrentLocation).Size() <= AttackRadius;

Loading…
Cancel
Save