코드 정리 + stats FName구현체

This commit is contained in:
2023-10-08 04:45:12 +09:00
parent deef14d8b5
commit 52e4c37ee5
10 changed files with 217 additions and 283 deletions

Binary file not shown.

Binary file not shown.

BIN
Content/Character/Lb/BP_Lb.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Maps/DevMap.umap (Stored with Git LFS)

Binary file not shown.

View File

@@ -25,39 +25,18 @@ ADefaultPlayerCharacter::ADefaultPlayerCharacter()
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera")); Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(CameraSpringArm, USpringArmComponent::SocketName); Camera->SetupAttachment(CameraSpringArm, USpringArmComponent::SocketName);
Health = 0.0f; const UEnum* CharStateEnum = FindObject<UEnum>(ANY_PACKAGE, TEXT("EStats"), true);
HPRegeneration = 0.0f; if (!CharStateEnum)
HealAndShieldpower = 0.0f; {
Armor = 0.0f; UE_LOG(LogTemp, Error, TEXT("EStats Missing"));
MagicResistance = 0.0f; return;
Tenacity = 0.0f; }
SlowRisist = 0.0f;
AttackSpeed = 0.0f; for (uint8 i = 0; i < (uint8)EStats::SIZE; i++)
AttackDamage = 0.0f; DefaultStats.Add(*CharStateEnum->GetNameByValue((uint8)i).ToString(), 0.0f);
AbilityPower = 0.0f;
CriticalStrikeChance = 0.0f; for (uint8 i = 0; i < (uint8)CooldownType::SIZE; i++)
CriticalStrikeDamage = 0.0f; CooldownDuration.Add((CooldownType)i, 0.0f);
ArmorPenetration = 0.0f;
MagicPenetration = 0.0f;
LifeSteal = 0.0f;
PhysicalVamp = 0.0f;
Omnivamp = 0.0f;
AbilityHaste = 0.0f;
Mana = 0.0f;
ManaRegeneration = 0.0f;
Energy = 0.0f;
EnergyRegeneration = 0.0f;
AttackRange = 0.0f;
MovementSpeed = 0.0f;
GoldGeneration = 0.0f;
AttackDamageGrowth = 0.0f;
AttackSpeedGrowth = 0.0f;
ArmorGrowth = 0.0f;
MagicResistanceGrowth = 0.0f;
HealthGrowth = 0.0f;
HealthRegenerationGrowth = 0.0f;
ManaGrowth = 0.0f;
ManaRegenerationGrowth = 0.0f;
} }
void ADefaultPlayerCharacter::Tick(float DeltaTime) void ADefaultPlayerCharacter::Tick(float DeltaTime)
@@ -104,15 +83,15 @@ float ADefaultPlayerCharacter::TakeDamage_Implementation(float DamageAmount, str
float ADDamageMultiplier = 0; float ADDamageMultiplier = 0;
float APDamageMultiplier = 0; float APDamageMultiplier = 0;
if (MyState->Stats.Armor >= 0) if (MyState->Stats[(uint8)EStats::Armor] >= 0)
ADDamageMultiplier = 100 / (100 + MyState->Stats.Armor); ADDamageMultiplier = 100 / (100 + MyState->Stats[(uint8)EStats::Armor]);
else else
ADDamageMultiplier = 2 - 100 / (100 - MyState->Stats.Armor); ADDamageMultiplier = 2 - 100 / (100 - MyState->Stats[(uint8)EStats::Armor]);
if (MyState->Stats.MagicResistance >= 0) if (MyState->Stats[(uint8)EStats::MagicResistance] >= 0)
APDamageMultiplier = 100 / (100 + MyState->Stats.MagicResistance); APDamageMultiplier = 100 / (100 + MyState->Stats[(uint8)EStats::MagicResistance]);
else else
APDamageMultiplier = 2 - 100 / (100 - MyState->Stats.MagicResistance); APDamageMultiplier = 2 - 100 / (100 - MyState->Stats[(uint8)EStats::MagicResistance]);
UE_LOG(LogTemp, Warning, TEXT("%s : ADDamageMultiplier : %f CalculatedDamage : %f"), *DamageCauser->GetName(), ADDamageMultiplier, DamageAmount * ADDamageMultiplier); UE_LOG(LogTemp, Warning, TEXT("%s : ADDamageMultiplier : %f CalculatedDamage : %f"), *DamageCauser->GetName(), ADDamageMultiplier, DamageAmount * ADDamageMultiplier);
@@ -122,17 +101,17 @@ float ADefaultPlayerCharacter::TakeDamage_Implementation(float DamageAmount, str
{ {
UE_LOG(LogTemp, Warning, TEXT("DamageType : BaseAttack")); UE_LOG(LogTemp, Warning, TEXT("DamageType : BaseAttack"));
float UpdatedHealth = MyState->Stats.Health - EventInstigatorState->Stats.AttackDamage * ADDamageMultiplier; float UpdatedHealth = MyState->Stats[(uint8)EStats::Health] - EventInstigatorState->Stats[(uint8)EStats::AttackDamage] * ADDamageMultiplier;
if (UpdatedHealth < 0) if (UpdatedHealth < 0)
{ {
MyState->Stats.Health = 0; MyState->Stats[(uint8)EStats::Health] = 0;
} }
else else
{ {
MyState->Stats.Health = UpdatedHealth; MyState->Stats[(uint8)EStats::Health] = UpdatedHealth;
} }
UE_LOG(LogTemp, Warning, TEXT("Current Health : %f"), MyState->Stats.Health); UE_LOG(LogTemp, Warning, TEXT("Current Health : %f"), MyState->Stats[(uint8)EStats::Health]);
} }
} }

View File

@@ -89,83 +89,11 @@ public:
UFUNCTION(NetMulticast, Reliable) UFUNCTION(NetMulticast, Reliable)
void NetMulticast_Skill7(); void NetMulticast_Skill7();
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Defensive") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats")
float Health; TMap<FName, float> DefaultStats;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Defensive")
float HPRegeneration;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Defensive")
float HealAndShieldpower;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Defensive")
float Armor;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Defensive")
float MagicResistance;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Defensive")
float Tenacity;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Defensive")
float SlowRisist;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Offensive")
float AttackSpeed;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Offensive")
float AttackDamage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Offensive")
float AbilityPower;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Offensive")
float CriticalStrikeChance;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Offensive")
float CriticalStrikeDamage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Offensive")
float ArmorPenetration;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Offensive")
float MagicPenetration;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Offensive")
float LifeSteal;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Offensive")
float PhysicalVamp;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Offensive")
float Omnivamp;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Utility|Haste")
float AbilityHaste;
UPROPERTY(EditAnywhere, Category = "Stats|Utility|Haste")
float CooldownDuration[(uint8)CooldownType::SIZE] = { 0.0f, };
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Utility|Resource")
float Mana;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Utility|Resource")
float ManaRegeneration;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Utility|Resource")
float Energy;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Utility|Resource")
float EnergyRegeneration;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Utility")
float AttackRange;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Utility")
float MovementSpeed;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Utility|Non-Combat")
float GoldGeneration;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Increasing Statistics")
float AttackDamageGrowth;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Increasing Statistics")
float AttackSpeedGrowth;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Increasing Statistics")
float ArmorGrowth;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Increasing Statistics")
float MagicResistanceGrowth;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Increasing Statistics")
float HealthGrowth;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Increasing Statistics")
float HealthRegenerationGrowth;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Increasing Statistics")
float ManaGrowth;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats|Increasing Statistics")
float ManaRegenerationGrowth;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats")
TMap<CooldownType, float> CooldownDuration;
protected: protected:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
USpringArmComponent* CameraSpringArm; USpringArmComponent* CameraSpringArm;

View File

@@ -18,18 +18,23 @@ void ADefaultPlayerController::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
if (ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player)) { ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
if (UEnhancedInputLocalPlayerSubsystem* InputSystem = LocalPlayer->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>()) { if (!LocalPlayer) return;
if (!PlayerInputMapping.IsNull()) { UEnhancedInputLocalPlayerSubsystem* InputSystem = LocalPlayer->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>();
InputSystem->AddMappingContext(PlayerInputMapping.LoadSynchronous(), 0); if (!InputSystem) return;
} ADefaultPlayerCharacter* ControlledPawn = GetPawn<ADefaultPlayerCharacter>();
else { if (!ControlledPawn) return;
UE_LOG(LogTemp, Error, TEXT("AddMappingContext Failed")); ADefaultPlayerState* MyPlayerState = GetPlayerState<ADefaultPlayerState>();
} if (!MyPlayerState) return;
} if (PlayerInputMapping.IsNull())
{
UE_LOG(LogTemp, Error, TEXT("AddMappingContext Failed"));
return;
} }
InputSystem->AddMappingContext(PlayerInputMapping.LoadSynchronous(), 0);
this->bShowMouseCursor = true; this->bShowMouseCursor = true;
//MyPlayerState->InitPlayerStats(ControlledPawn->DefaultStats, ControlledPawn->CooldownDuration);
} }
void ADefaultPlayerController::OnPossess(APawn* aPawn) void ADefaultPlayerController::OnPossess(APawn* aPawn)
@@ -39,16 +44,15 @@ void ADefaultPlayerController::OnPossess(APawn* aPawn)
Server_SpawnPlayerCamera(); Server_SpawnPlayerCamera();
AActor *PlayerCamera = GetPlayerState<ADefaultPlayerState>()->GetPlayerCamera(); AActor *PlayerCamera = GetPlayerState<ADefaultPlayerState>()->GetPlayerCamera();
if (PlayerCamera) if (!PlayerCamera)
{
SetViewTarget(PlayerCamera);
UE_LOG(LogTemp, Warning, TEXT("SetViewTarget Success : %s"), *GetPlayerState<ADefaultPlayerState>()->GetPlayerCamera()->GetName());
}
else
{ {
UE_LOG(LogTemp, Error, TEXT("GetPlayerCamera Failed.")); UE_LOG(LogTemp, Error, TEXT("GetPlayerCamera Failed."));
return;
} }
SetViewTarget(PlayerCamera);
UE_LOG(LogTemp, Warning, TEXT("SetViewTarget Success : %s"), *GetPlayerState<ADefaultPlayerState>()->GetPlayerCamera()->GetName());
} }
void ADefaultPlayerController::OnUnPossess() void ADefaultPlayerController::OnUnPossess()
@@ -66,48 +70,46 @@ void ADefaultPlayerController::Server_SpawnPlayerCamera_Implementation()
UE_LOG(LogTemp, Warning, TEXT("SpawnPlayerCamera")); UE_LOG(LogTemp, Warning, TEXT("SpawnPlayerCamera"));
if (APawn* MyPawn = GetPawn()) APawn* MyPawn = GetPawn();
if (!MyPawn) return;
FTransform SpawnTransform = FTransform();
SpawnTransform.SetLocation(MyPawn->GetActorLocation());
OutContextPlayerCamera = GetWorld()->SpawnActor<AActor>(ADefaultPlayerCamera::StaticClass(), SpawnTransform, SpawnInfo);
if (!OutContextPlayerCamera)
{ {
FTransform SpawnTransform = FTransform(); UE_LOG(LogTemp, Error, TEXT("Camera Spawn Failed."));
return;
SpawnTransform.SetLocation(MyPawn->GetActorLocation());
OutContextPlayerCamera = GetWorld()->SpawnActor<AActor>(ADefaultPlayerCamera::StaticClass(), SpawnTransform, SpawnInfo);
if (OutContextPlayerCamera)
{
GetPlayerState<ADefaultPlayerState>()->SetPlayerCamera(OutContextPlayerCamera);
OutContextPlayerCamera->AttachToActor(GetPawn(), FAttachmentTransformRules(EAttachmentRule::SnapToTarget, EAttachmentRule::KeepWorld, EAttachmentRule::KeepWorld, false));
UE_LOG(LogTemp, Warning, TEXT("SetPlayerCamera Success : %s, %d"), *GetPlayerState<ADefaultPlayerState>()->GetPlayerCamera()->GetName(), GetPlayerState<ADefaultPlayerState>()->GetPlayerCamera());
}
else
{
UE_LOG(LogTemp, Error, TEXT("Camera Spawn Failed."));
}
} }
GetPlayerState<ADefaultPlayerState>()->SetPlayerCamera(OutContextPlayerCamera);
OutContextPlayerCamera->AttachToActor(GetPawn(), FAttachmentTransformRules(EAttachmentRule::SnapToTarget, EAttachmentRule::KeepWorld, EAttachmentRule::KeepWorld, false));
UE_LOG(LogTemp, Warning, TEXT("SetPlayerCamera Success : %s, %d"), *GetPlayerState<ADefaultPlayerState>()->GetPlayerCamera()->GetName(), GetPlayerState<ADefaultPlayerState>()->GetPlayerCamera());
} }
void ADefaultPlayerController::SetACharacterOutlineColor(ACharacter* Target, bool Visible) void ADefaultPlayerController::SetACharacterOutlineColor(ACharacter* Target, bool Visible)
{ {
if (!HasAuthority()) if (HasAuthority()) return;
ADefaultPlayerState* State = Target->GetPlayerState<ADefaultPlayerState>();
if (!State)
{ {
if (ADefaultPlayerState* State = Target->GetPlayerState<ADefaultPlayerState>()) UE_LOG(LogTemp, Error, TEXT("GetPlayerState<ADefaultPlayerState> Failed"));
{ return;
if (State->GetTeam() == GetPlayerState<ADefaultPlayerState>()->GetTeam()) }
{
Target->GetMesh()->SetRenderCustomDepth(Visible); if (State->GetTeam() == GetPlayerState<ADefaultPlayerState>()->GetTeam())
Target->GetMesh()->CustomDepthStencilValue = 1; {
} Target->GetMesh()->SetRenderCustomDepth(Visible);
else Target->GetMesh()->CustomDepthStencilValue = 1;
{ }
Target->GetMesh()->SetRenderCustomDepth(Visible); else
Target->GetMesh()->CustomDepthStencilValue = 2; {
} Target->GetMesh()->SetRenderCustomDepth(Visible);
} Target->GetMesh()->CustomDepthStencilValue = 2;
else
{
UE_LOG(LogTemp, Error, TEXT("GetPlayerState<ADefaultPlayerState> Failed"));
}
} }
} }
@@ -215,20 +217,20 @@ void ADefaultPlayerController::SetupInputComponent()
{ {
Super::SetupInputComponent(); Super::SetupInputComponent();
if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent)) UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent);
{ if (!EnhancedInputComponent) return;
EnhancedInputComponent->BindAction(Skill1Action.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Skill1);
EnhancedInputComponent->BindAction(Skill2Action.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Skill2); EnhancedInputComponent->BindAction(Skill1Action.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Skill1);
EnhancedInputComponent->BindAction(Skill3Action.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Skill3); EnhancedInputComponent->BindAction(Skill2Action.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Skill2);
EnhancedInputComponent->BindAction(Skill4Action.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Skill4Triggered); EnhancedInputComponent->BindAction(Skill3Action.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Skill3);
EnhancedInputComponent->BindAction(Skill4Action.Get(), ETriggerEvent::Completed, this, &ADefaultPlayerController::Skill4Completed); EnhancedInputComponent->BindAction(Skill4Action.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Skill4Triggered);
EnhancedInputComponent->BindAction(RuneSpell1Action.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::RuneSpell1); EnhancedInputComponent->BindAction(Skill4Action.Get(), ETriggerEvent::Completed, this, &ADefaultPlayerController::Skill4Completed);
EnhancedInputComponent->BindAction(RuneSpell2Action.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::RuneSpell2); EnhancedInputComponent->BindAction(RuneSpell1Action.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::RuneSpell1);
EnhancedInputComponent->BindAction(WardAction.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Ward); EnhancedInputComponent->BindAction(RuneSpell2Action.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::RuneSpell2);
EnhancedInputComponent->BindAction(BombAction.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Bomb); EnhancedInputComponent->BindAction(WardAction.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Ward);
EnhancedInputComponent->BindAction(ObjectSelectAction.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::ObjectSelect); EnhancedInputComponent->BindAction(BombAction.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Bomb);
EnhancedInputComponent->BindAction(MoveAction.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Move); EnhancedInputComponent->BindAction(ObjectSelectAction.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::ObjectSelect);
} EnhancedInputComponent->BindAction(MoveAction.Get(), ETriggerEvent::Triggered, this, &ADefaultPlayerController::Move);
} }
void ADefaultPlayerController::Skill1() void ADefaultPlayerController::Skill1()
@@ -236,6 +238,12 @@ void ADefaultPlayerController::Skill1()
//if (!(GetPlayerState<ADefaultPlayerState>()->Stats.Mana >= 100)) //if (!(GetPlayerState<ADefaultPlayerState>()->Stats.Mana >= 100))
// return; // return;
FVector Location = GetPawn()->GetActorLocation();
Location.Z = 0;
SimpleMoveToLocation(this, Location);
this->MoveToLocation(Location);
Server_SetRotation(GetMouseHitLocation()); Server_SetRotation(GetMouseHitLocation());
UE_LOG(LogTemp, Warning, TEXT("Skill1")); UE_LOG(LogTemp, Warning, TEXT("Skill1"));
@@ -245,6 +253,12 @@ void ADefaultPlayerController::Skill1()
void ADefaultPlayerController::Skill2() void ADefaultPlayerController::Skill2()
{ {
FVector Location = GetPawn()->GetActorLocation();
Location.Z = 0;
SimpleMoveToLocation(this, Location);
this->MoveToLocation(Location);
Server_SetRotation(GetMouseHitLocation()); Server_SetRotation(GetMouseHitLocation());
UE_LOG(LogTemp, Warning, TEXT("Skill2")); UE_LOG(LogTemp, Warning, TEXT("Skill2"));
@@ -254,6 +268,12 @@ void ADefaultPlayerController::Skill2()
void ADefaultPlayerController::Skill3() void ADefaultPlayerController::Skill3()
{ {
FVector Location = GetPawn()->GetActorLocation();
Location.Z = 0;
SimpleMoveToLocation(this, Location);
this->MoveToLocation(Location);
Server_SetRotation(GetMouseHitLocation()); Server_SetRotation(GetMouseHitLocation());
UE_LOG(LogTemp, Warning, TEXT("Skill3")); UE_LOG(LogTemp, Warning, TEXT("Skill3"));
@@ -263,6 +283,12 @@ void ADefaultPlayerController::Skill3()
void ADefaultPlayerController::Skill4Triggered() void ADefaultPlayerController::Skill4Triggered()
{ {
FVector Location = GetPawn()->GetActorLocation();
Location.Z = 0;
SimpleMoveToLocation(this, Location);
this->MoveToLocation(Location);
Server_SetRotation(GetMouseHitLocation()); Server_SetRotation(GetMouseHitLocation());
UE_LOG(LogTemp, Warning, TEXT("Skill4 Triggered")); UE_LOG(LogTemp, Warning, TEXT("Skill4 Triggered"));
@@ -272,6 +298,12 @@ void ADefaultPlayerController::Skill4Triggered()
void ADefaultPlayerController::Skill4Completed() void ADefaultPlayerController::Skill4Completed()
{ {
FVector Location = GetPawn()->GetActorLocation();
Location.Z = 0;
SimpleMoveToLocation(this, Location);
this->MoveToLocation(Location);
Server_SetRotation(GetMouseHitLocation()); Server_SetRotation(GetMouseHitLocation());
UE_LOG(LogTemp, Warning, TEXT("Skill4 Completed")); UE_LOG(LogTemp, Warning, TEXT("Skill4 Completed"));
@@ -316,11 +348,11 @@ void ADefaultPlayerController::ObjectSelect()
GetHitResultUnderCursorForObjects(ObjectTypes, true, HitResult); GetHitResultUnderCursorForObjects(ObjectTypes, true, HitResult);
if (ACharacter* HitObject = Cast<ACharacter>(HitResult.GetActor())) ACharacter* HitObject = Cast<ACharacter>(HitResult.GetActor());
{ if (!HitObject) return;
UE_LOG(LogTemp, Warning, TEXT("%s"), *HitObject->GetName());
SetACharacterOutlineColor(HitObject, true); UE_LOG(LogTemp, Warning, TEXT("%s"), *HitObject->GetName());
} SetACharacterOutlineColor(HitObject, true);
} }
void ADefaultPlayerController::Move() void ADefaultPlayerController::Move()
@@ -337,9 +369,6 @@ void ADefaultPlayerController::Multicast_SetRotation_Implementation(FVector Mous
FVector Location = GetPawn()->GetActorLocation(); FVector Location = GetPawn()->GetActorLocation();
Location.Z = 0; Location.Z = 0;
SimpleMoveToLocation(this, Location);
this->MoveToLocation(Location);
GetPawn()->SetActorRotation((MouseHitLocation - Location).Rotation()); GetPawn()->SetActorRotation((MouseHitLocation - Location).Rotation());
} }
@@ -367,22 +396,21 @@ FVector ADefaultPlayerController::GetMouseHitLocation()
DrawDebugLine(GetWorld(), HitResult.Location, Destination, FColor::Emerald, false, 1, 0, 1); DrawDebugLine(GetWorld(), HitResult.Location, Destination, FColor::Emerald, false, 1, 0, 1);
const UWorld* CurrentWorld = GetWorld(); const UWorld* CurrentWorld = GetWorld();
if (CurrentWorld) if (!CurrentWorld) return Destination;
{
FHitResult CollisionCheck;
FCollisionQueryParams CollisionParams; FHitResult CollisionCheck;
CollisionParams.AddIgnoredActor(GetPawn());
FVector Start = HitResult.Location; FCollisionQueryParams CollisionParams;
FVector End = Destination; CollisionParams.AddIgnoredActor(GetPawn());
if (CurrentWorld->LineTraceSingleByChannel(CollisionCheck, Start, End, ECC_Visibility, CollisionParams)) FVector Start = HitResult.Location;
{ FVector End = Destination;
DrawDebugLine(CurrentWorld, Start, End, FColor::Red, false, 1.5, 0, 2);
Destination = HitResult.Location; if (!CurrentWorld->LineTraceSingleByChannel(CollisionCheck, Start, End, ECC_Visibility, CollisionParams))
} return Destination;
}
DrawDebugLine(CurrentWorld, Start, End, FColor::Red, false, 1.5, 0, 2);
Destination = HitResult.Location;
return Destination; return Destination;
} }
@@ -467,18 +495,18 @@ void ADefaultPlayerController::SimpleMoveToLocation(AController* Controller, con
void ADefaultPlayerController::OnMoveCompleted(FAIRequestID RequestID, const FPathFollowingResult& MovementResult) void ADefaultPlayerController::OnMoveCompleted(FAIRequestID RequestID, const FPathFollowingResult& MovementResult)
{ {
if (MovementResult.IsSuccess()) if (!MovementResult.IsSuccess()) return;
if (!GPlayInEditorID)
{ {
if (!GPlayInEditorID) UE_LOG(LogTemp, Warning, TEXT("Server MoveCompleted"));
{
UE_LOG(LogTemp, Warning, TEXT("Server MoveCompleted"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Client%d MoveCompleted"), GPlayInEditorID);
}
GetPlayerState<ADefaultPlayerState>()->SetState(ECharacterState::Idle);
} }
else
{
UE_LOG(LogTemp, Warning, TEXT("Client%d MoveCompleted"), GPlayInEditorID);
}
GetPlayerState<ADefaultPlayerState>()->SetState(ECharacterState::Idle);
} }
void ADefaultPlayerController::Attack() void ADefaultPlayerController::Attack()

View File

@@ -26,46 +26,11 @@ void ADefaultPlayerState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>&
DOREPLIFETIME(ADefaultPlayerState, PlayerCamera); DOREPLIFETIME(ADefaultPlayerState, PlayerCamera);
} }
void ADefaultPlayerState::InitPlayerStats() void ADefaultPlayerState::InitPlayerStats_Implementation(const TArray<float>& StatsValue, const TArray<float>& CooldownDurationValue)
{ {
ADefaultPlayerCharacter* Initializer = Cast<ADefaultPlayerCharacter>(CharacterBPRef); MaxStats.Append(StatsValue);
Stats.Append(StatsValue);
Stats.Health = Initializer->Health; CooldownDuration.Append(CooldownDurationValue);
Stats.HPRegeneration = Initializer->HPRegeneration;
Stats.HealAndShieldpower = Initializer->HealAndShieldpower;
Stats.Armor = Initializer->Armor;
Stats.MagicResistance = Initializer->MagicResistance;
Stats.Tenacity = Initializer->Tenacity;
Stats.SlowRisist = Initializer->SlowRisist;
Stats.AttackSpeed = Initializer->AttackSpeed;
Stats.AttackDamage = Initializer->AttackDamage;
Stats.AbilityPower = Initializer->AbilityPower;
Stats.CriticalStrikeChance = Initializer->CriticalStrikeChance;
Stats.CriticalStrikeDamage = Initializer->CriticalStrikeDamage;
Stats.ArmorPenetration = Initializer->ArmorPenetration;
Stats.MagicPenetration = Initializer->MagicPenetration;
Stats.LifeSteal = Initializer->LifeSteal;
Stats.PhysicalVamp = Initializer->PhysicalVamp;
Stats.Omnivamp = Initializer->Omnivamp;
Stats.AbilityHaste = Initializer->AbilityHaste;
SetMultipleCooldownDuration(Initializer->CooldownDuration);
Stats.Mana = Initializer->Mana;
Stats.ManaRegeneration = Initializer->ManaRegeneration;
Stats.Energy = Initializer->Energy;
Stats.EnergyRegeneration = Initializer->EnergyRegeneration;
Stats.AttackRange = Initializer->AttackRange;
Stats.MovementSpeed = Initializer->MovementSpeed;
Stats.GoldGeneration = Initializer->GoldGeneration;
Stats.AttackDamageGrowth = Initializer->AttackDamageGrowth;
Stats.AttackSpeedGrowth = Initializer->AttackSpeedGrowth;
Stats.ArmorGrowth = Initializer->ArmorGrowth;
Stats.MagicResistanceGrowth = Initializer->MagicResistanceGrowth;
Stats.HealthGrowth = Initializer->HealthGrowth;
Stats.HealthRegenerationGrowth = Initializer->HealthRegenerationGrowth;
Stats.ManaGrowth = Initializer->ManaGrowth;
Stats.ManaRegenerationGrowth = Initializer->ManaRegenerationGrowth;
} }
void ADefaultPlayerState::NetMulticast_SetAttackType_Implementation(CooldownType Value) void ADefaultPlayerState::NetMulticast_SetAttackType_Implementation(CooldownType Value)
@@ -92,8 +57,3 @@ int32 ADefaultPlayerState::GetCharacterLevel() const
{ {
return int32(); return int32();
} }
void ADefaultPlayerState::SetMultipleCooldownDuration(const float* Value)
{
std::memcpy(&CooldownDuration, Value, sizeof(float) * (uint8)CooldownType::SIZE);
}

View File

@@ -21,7 +21,8 @@ public:
ADefaultPlayerState(); ADefaultPlayerState();
void GetLifetimeReplicatedProps(TArray< FLifetimeProperty >& OutLifetimeProps) const override; void GetLifetimeReplicatedProps(TArray< FLifetimeProperty >& OutLifetimeProps) const override;
void InitPlayerStats(); UFUNCTION(Server, Reliable)
void InitPlayerStats(const TArray<float>& StatsValue, const TArray<float>& CooldownDurationValue);
void SetCharacterBPRef(UClass* Value) { CharacterBPRef = Value; } void SetCharacterBPRef(UClass* Value) { CharacterBPRef = Value; }
UClass* GetCharacterBPRef() const { return CharacterBPRef; } UClass* GetCharacterBPRef() const { return CharacterBPRef; }
@@ -34,10 +35,11 @@ public:
void SetPlayerCamera(AActor* Actor) { PlayerCamera = Actor; } void SetPlayerCamera(AActor* Actor) { PlayerCamera = Actor; }
AActor* GetPlayerCamera() const { return PlayerCamera; } AActor* GetPlayerCamera() const { return PlayerCamera; }
UFUNCTION(BlueprintCallable) //fix later
void SetCooldownDuration(CooldownType Key, float Value) { CooldownDuration[(uint8)Key] = Value; } //UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable) //void SetCooldownDuration(CooldownType Key, float Value) { CooldownDuration[(uint8)Key] = Value; }
float GetCooldownDuration(CooldownType Key) const { return CooldownDuration[(uint8)Key]; } //UFUNCTION(BlueprintCallable)
//float GetCooldownDuration(CooldownType Key) const { return CooldownDuration[(uint8)Key]; }
//Execute on server //Execute on server
UFUNCTION(BlueprintCallable, Server, Reliable) UFUNCTION(BlueprintCallable, Server, Reliable)
@@ -58,13 +60,15 @@ public:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
int32 GetCharacterLevel() const; int32 GetCharacterLevel() const;
//Should be ONLY executed on server!! UPROPERTY(Replicated, Transient, EditAnywhere, BlueprintReadWrite)
void SetMultipleCooldownDuration(const float* Value) ; TArray<float> Stats;
UPROPERTY(Replicated, Transient, EditAnywhere, BlueprintReadWrite)
TArray<float> MaxStats;
UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) UPROPERTY(Replicated, Transient, BlueprintReadWrite)
FDefaultStats Stats; TArray<float> CooldownDuration;
UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) UPROPERTY(Replicated, Transient, BlueprintReadWrite)
FDefaultStats MaxStats; TArray<float> MaxCooldownDuration;
private: private:
UPROPERTY(Replicated, Transient) UPROPERTY(Replicated, Transient)
@@ -72,9 +76,6 @@ private:
UPROPERTY(Replicated, Transient) UPROPERTY(Replicated, Transient)
TeamType Team; TeamType Team;
UPROPERTY(Replicated, Transient)
float CooldownDuration[(uint8)CooldownType::SIZE] = { 0.0f, };
UPROPERTY(Replicated, Transient) UPROPERTY(Replicated, Transient)
ECharacterState State; ECharacterState State;
UPROPERTY(Replicated, Transient) UPROPERTY(Replicated, Transient)

View File

@@ -91,3 +91,41 @@ struct FUniqueObjectID
int32 RandomUniqueNumber; int32 RandomUniqueNumber;
}; };
UENUM(BlueprintType)
enum class EStats : uint8
{
Health,
HPRegeneration,
HealAndShieldpower,
Armor,
MagicResistance,
Tenacity,
SlowRisist,
AttackSpeed,
AttackDamage,
AbilityPower,
CriticalStrikeChance,
CriticalStrikeDamage,
ArmorPenetration,
MagicPenetration,
LifeSteal,
PhysicalVamp,
Omnivamp,
AbilityHaste,
Mana,
ManaRegeneration,
Energy,
EnergyRegeneration,
AttackRange,
MovementSpeed,
GoldGeneration,
AttackDamageGrowth,
AttackSpeedGrowth,
ArmorGrowth,
MagicResistanceGrowth,
HealthGrowth,
HealthRegenerationGrowth,
ManaGrowth,
ManaRegenerationGrowth,
SIZE
};