Added selection trooper and view of action radius

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

Binary file not shown.

@ -143,8 +143,7 @@ void AMyGameMode::PostLogin(APlayerController *NewPlayer) {
}
}
void AMyGameMode::StartGame() {
void AMyGameMode::StartGame_Implementation() {
InitializeBattleField();
// PlayerNotInTurn()->SetEnemySelection(Troopers);
// PlayerInTurn()->SetEnemySelection(Troopers);
@ -154,6 +153,16 @@ void AMyGameMode::StartGame() {
}
// void AMyGameMode::StartGame() {
// InitializeBattleField();
// // PlayerNotInTurn()->SetEnemySelection(Troopers);
// // PlayerInTurn()->SetEnemySelection(Troopers);
//
// // PlayerInTurn()->StartTurn();
// GetMyGameState()->StartGame();
// }
// AMyPlayerController *AMyGameMode::PlayerInTurn() const {
// return GetMyPlayerController(CurrentPlayerTurn);
// }

@ -38,7 +38,7 @@ private:
// UPROPERTY()
// mutable TArray<ATrooper *> Troopers;
UFUNCTION(BlueprintCallable)
UFUNCTION(Server, Reliable)
void StartGame();
// UFUNCTION(BlueprintPure)

@ -18,12 +18,18 @@ void AMyGameState::AddTrooper(ATrooper *Trooper) {
Troopers.Add(Trooper);
}
void AMyGameState::StartGame() const {
// PlayerNotInTurn()->SetEnemySelection(Troopers);
// PlayerInTurn()->SetEnemySelection(Troopers);
void AMyGameState::StartGame_Implementation() const {
PlayerNotInTurn()->SetEnemySelection(Troopers);
PlayerInTurn()->SetEnemySelection(Troopers);
PlayerInTurn()->StartTurn();
}
// void AMyGameState::StartGame() const {
// PlayerNotInTurn()->SetEnemySelection(Troopers);
// PlayerInTurn()->SetEnemySelection(Troopers);
// PlayerInTurn()->StartTurn();
// }
void AMyGameState::CycleTurns_Implementation() {
PlayerInTurn()->EndTurn();
for (const auto Trooper : Troopers) {

@ -20,7 +20,7 @@ public:
UFUNCTION()
void AddTrooper(ATrooper *Trooper);
UFUNCTION()
UFUNCTION(Server, Reliable)
void StartGame() const;
UFUNCTION(BlueprintCallable, Server, Reliable)

@ -145,14 +145,14 @@ void AMyPlayerController::SetPlayerIndex(uint8 NewPlayerIndex) {
// }
void AMyPlayerController::SetEnemySelection_Implementation(
const TArray<ATrooper *> &Troopers) const {
for (const auto Trooper : Troopers) {
if (Trooper != nullptr && Trooper->GetPlayerIndex() != PlayerIndex) {
Trooper->HighlightAsEnemy();
}
}
}
// void AMyPlayerController::SetEnemySelection_Implementation(
// const TArray<ATrooper *> &Troopers) const {
// for (const auto Trooper : Troopers) {
// if (Trooper != nullptr && Trooper->GetPlayerIndex() != PlayerIndex) {
// Trooper->HighlightAsEnemy();
// }
// }
// }
// void AMyPlayerController::SetEnemySelection_Implementation() {

@ -43,8 +43,8 @@ public:
// UFUNCTION(BlueprintCallable)
// float SetCurrentActionAndReturnRadius(int action);
UFUNCTION(Client, Reliable)
void SetEnemySelection(const TArray<ATrooper *> &Troopers) const;
// UFUNCTION(Client, Reliable)
// void SetEnemySelection(const TArray<ATrooper *> &Troopers) const;
private:
// UPROPERTY(Replicated)

@ -19,6 +19,15 @@ void AMyPlayerState::SetPlayerIndex(uint8 NewPlayerIndex) {
PlayerIndex = NewPlayerIndex;
}
void AMyPlayerState::SetEnemySelection_Implementation(
const TArray<ATrooper *> &Troopers) const {
for (const auto Trooper : Troopers) {
if (Trooper != nullptr && Trooper->GetPlayerIndex() != PlayerIndex) {
Trooper->HighlightAsEnemy();
}
}
}
void AMyPlayerState::MoveTrooper_Implementation(ATrooper *Trooper,
FVector Location) {
if (Trooper->CheckMoveCorrectness(Location)) {
@ -74,7 +83,7 @@ void AMyPlayerState::EndTurn_Implementation() {
UE_LOG(LogTemp, Warning, TEXT("End Turn from player %d"), PlayerIndex);
SetMyTurn(false);
if (SelectedTrooper) {
SelectedTrooper->SetSelection(false);
SelectedTrooper->SetSelection(false, CurrentAction);
SelectedTrooper = nullptr;
}
UE_LOG(LogTemp, Warning, TEXT("Not your turn, %d"), PlayerIndex);
@ -106,7 +115,7 @@ void AMyPlayerState::OnPlayerAction(const FHitResult &HitResult) {
// move this mf
MoveTrooper(SelectedTrooper, NewlySelectedLocation);
// and reset the selection....
SelectedTrooper->SetSelection(false);
SelectedTrooper->SetSelection(false, CurrentAction);
SelectedTrooper = nullptr;
break;
default:
@ -114,7 +123,7 @@ void AMyPlayerState::OnPlayerAction(const FHitResult &HitResult) {
UE_LOG(LogTemp, Warning, TEXT("Do attack"));
Attack(SelectedTrooper, NewlySelectedLocation,
CurrentAction);
SelectedTrooper->SetSelection(false);
SelectedTrooper->SetSelection(false, CurrentAction);
SelectedTrooper = nullptr;
break;
}
@ -125,15 +134,18 @@ void AMyPlayerState::OnPlayerAction(const FHitResult &HitResult) {
UE_LOG(LogTemp, Warning, TEXT("Do reselect"));
// our move, selection
if (SelectedTrooper) {
SelectedTrooper->SetSelection(false);
SelectedTrooper->SetSelection(false, CurrentAction);
}
SelectedTrooper = NewlySelectedTrooper;
SelectedTrooper->SetSelection(true);
SelectedTrooper->SetSelection(true, CurrentAction);
}
}
void AMyPlayerState::SetCurrentAction_Implementation(int Action) {
CurrentAction = Action;
if (SelectedTrooper) {
SelectedTrooper->UpdateSelectionRadius(Action);
}
UE_LOG(LogTemp, Warning, TEXT("SetCurrentAction: %d on Player Controller "
"with index %d"), CurrentAction, PlayerIndex);
}

@ -47,6 +47,9 @@ public:
UFUNCTION()
void SetPlayerIndex(uint8 NewPlayerIndex);
UFUNCTION(Client, Reliable)
void SetEnemySelection(const TArray<ATrooper *> &Troopers) const;
private:
UPROPERTY(Replicated)
uint8 PlayerIndex;

@ -2,6 +2,7 @@
#include <Kismet/GameplayStatics.h>
#include "HealthBar.h"
#include "MyPlayerState.h"
#include "Components/WidgetComponent.h"
#include "Net/UnrealNetwork.h"
@ -26,7 +27,7 @@ ATrooper::ATrooper()
"StaticMesh'/Game/StarterContent/Shapes/Shape_Cylinder.Shape_Cylinder'"));
SelectionStaticMesh->AttachToComponent(RootComponent,
FAttachmentTransformRules::KeepRelativeTransform);
SelectionStaticMesh->SetRelativeScale3D({1.8, 1.8, 0.01});
SelectionStaticMesh->SetWorldScale3D({2.0f, 2.0f, 0.01f});
SelectionStaticMesh->SetVisibility(false);
if (MeshToUse.Object) {
@ -97,6 +98,18 @@ void ATrooper::Tick(float const DeltaTime) {
}
}
// void ATrooper::OnRepNotify_PlayerIndex() {
// UE_LOG(LogTemp, Warning,
// TEXT("On rep notify, index: %d, id: %d, on server: %d, player state: %d"),
// PlayerIndex, Id, GetNetMode() == NM_DedicatedServer, GetPlayerState() != nullptr);
// // if (GetNetMode() != NM_DedicatedServer && GetPlayerState()) {
// // if (Cast<AMyPlayerState>(GetPlayerState())->GetPlayerIndex() !=
// // PlayerIndex) {
// // HighlightAsEnemy();
// // }
// // }
// }
void ATrooper::MoveTrooper(FVector const NewPos) {
TargetLocation = NewPos;
bIsMoving = true;
@ -144,15 +157,18 @@ FVector ATrooper::GetLocation() const {
return CurrentLocation;
}
float ATrooper::GetActionRadius(int action) const {
switch (action) {
case 1:
return AttackAbility->ActionRadius;
return AttackAbility->ActionCost <= ActionPoints
? AttackAbility->ActionRadius
: 0;
case 2:
return SpecialAbility->ActionRadius;
return SpecialAbility->ActionCost <= ActionPoints
? SpecialAbility->ActionRadius
: 0;
default:
return ActionPoints;
return ActionPoints / MoveCost;
}
}
@ -164,16 +180,29 @@ float ATrooper::GetMaxHitPoints() const {
return StartHitPoints;
}
void ATrooper::SetSelection(bool Selection) const {
void ATrooper::SetSelection(bool Selection, uint8 ActionType) const {
if (SelectionStaticMesh) {
if (SelectionStaticMesh->GetMaterial(0) != GreenMaterial) {
SelectionStaticMesh->SetMaterial(0, GreenMaterial);
SelectionStaticMesh->SetRelativeLocation({0, 0, 1});
}
if (Selection) {
UpdateSelectionRadius(ActionType);
} else {
SelectionStaticMesh->SetWorldScale3D({2.f, 2.f, 0.01f});
}
SelectionStaticMesh->SetVisibility(Selection);
}
}
void ATrooper::HighlightAsEnemy() const {
void ATrooper::UpdateSelectionRadius(uint8 ActionType) const {
const float radiusScale =
GetActionRadius(ActionType) / PIXELS_IN_RADIUS;
SelectionStaticMesh->SetWorldScale3D(
{radiusScale, radiusScale, 0.01f});
}
void ATrooper::HighlightAsEnemy_Implementation() const {
SelectionStaticMesh->SetVisibility(true);
}
@ -215,8 +244,7 @@ bool ATrooper::CheckMoveCorrectness(const FVector newPos) const {
bool ATrooper::CheckAttackCorrectness(const FVector attackLocation,
int abilityIndex) const {
return GetAbility(abilityIndex) != nullptr && (
attackLocation - CurrentLocation).Size() <=
GetAbility(abilityIndex)->ActionRadius && ActionPoints >=
GetAbility(abilityIndex)->ActionCost;
attackLocation - CurrentLocation).Size() < GetActionRadius(
abilityIndex);
// return (attackLocation - CurrentLocation).Size() <= AttackRadius;
}

@ -51,9 +51,12 @@ public:
float GetMaxHitPoints() const;
UFUNCTION()
void SetSelection(bool Selected) const;
void SetSelection(bool Selected, uint8 ActionType) const;
UFUNCTION()
void UpdateSelectionRadius(uint8 ActionType) const;
UFUNCTION(Client, Reliable)
void HighlightAsEnemy() const;
UFUNCTION()
@ -63,6 +66,8 @@ public:
UAbility *GetAbility(int AbilityIndex) const;
protected:
constexpr static float PIXELS_IN_RADIUS = 50;
UPROPERTY(EditAnywhere)
UMaterialInterface *GreenMaterial = nullptr;
@ -118,9 +123,12 @@ protected:
// const TCHAR *MeshPath = nullptr;
UPROPERTY(Replicated)
uint8 PlayerIndex;
// UFUNCTION()
// void OnRepNotify_PlayerIndex();
UPROPERTY(Replicated/*Using = OnRepNotify_PlayerIndex*/)
uint8 PlayerIndex = -1;
UPROPERTY(Replicated)
uint8 Id;

Loading…
Cancel
Save