Files
Naked-Desire/Source/NakedDesire/Player/PlayerImpostor.cpp
T

139 lines
5.1 KiB
C++

#include "PlayerImpostor.h"
#include "NakedDesireCharacter.h"
#include "Kismet/GameplayStatics.h"
#include "NakedDesire/Clothing/ClothingItem.h"
#include "NakedDesire/Clothing/ClothingItemInstance.h"
#include "NakedDesire/Clothing/ClothingManager.h"
APlayerImpostor::APlayerImpostor()
{
PrimaryActorTick.bCanEverTick = false;
RootSceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
SetRootComponent(RootSceneComponent);
Mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("RootMesh"));
Mesh->SetupAttachment(RootComponent);
NipplesMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Nipples"));
NipplesMeshComponent->SetupAttachment(GetMesh());
AnalMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Anal"));
AnalMeshComponent->SetupAttachment(GetMesh());
VaginaMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Vagina"));
VaginaMeshComponent->SetupAttachment(GetMesh());
HeadMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Head"));
HeadMeshComponent->SetupAttachment(GetMesh());
NeckMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Neck"));
NeckMeshComponent->SetupAttachment(GetMesh());
FaceMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Face"));
FaceMeshComponent->SetupAttachment(GetMesh());
EyesMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Eyes"));
EyesMeshComponent->SetupAttachment(GetMesh());
BodyMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Body"));
BodyMeshComponent->SetupAttachment(GetMesh());
TopMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Top"));
TopMeshComponent->SetupAttachment(GetMesh());
BottomMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Bottom"));
BottomMeshComponent->SetupAttachment(GetMesh());
BraMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Bra"));
BraMeshComponent->SetupAttachment(GetMesh());
PantiesMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Panties"));
PantiesMeshComponent->SetupAttachment(GetMesh());
SocksMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Socks"));
SocksMeshComponent->SetupAttachment(GetMesh());
ShoesMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Shoes"));
ShoesMeshComponent->SetupAttachment(GetMesh());
}
void APlayerImpostor::OnClothingEquip(const UClothingItemInstance* ClothingItemInstance)
{
EquipClothing(ClothingItemInstance);
}
void APlayerImpostor::OnClothingUnequip(const UClothingItemInstance* ClothingItemInstance)
{
UnequipClothing(ClothingItemInstance);
}
void APlayerImpostor::BeginPlay()
{
Super::BeginPlay();
Player = Cast<ANakedDesireCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
if (!Player)
{
return;
}
Player->ClothingManager->OnClothingEquip.AddUniqueDynamic(this, &APlayerImpostor::OnClothingEquip);
Player->ClothingManager->OnClothingUnequip.AddUniqueDynamic(this, &APlayerImpostor::OnClothingUnequip);
for (const UClothingItemInstance* ClothingItemInstance : Player->ClothingManager->GetEquippedClothing())
{
EquipClothing(ClothingItemInstance);
}
}
USkeletalMeshComponent* APlayerImpostor::GetMeshByType(const EClothingSlotType SlotType) const
{
switch (SlotType)
{
case EClothingSlotType::Nipples:
return NipplesMeshComponent;
case EClothingSlotType::Anal:
return AnalMeshComponent;
case EClothingSlotType::Vagina:
return VaginaMeshComponent;
case EClothingSlotType::Head:
return HeadMeshComponent;
case EClothingSlotType::Neck:
return NeckMeshComponent;
case EClothingSlotType::Face:
return FaceMeshComponent;
case EClothingSlotType::Eyes:
return EyesMeshComponent;
case EClothingSlotType::Body:
return BodyMeshComponent;
case EClothingSlotType::Top:
return TopMeshComponent;
case EClothingSlotType::Bottom:
return BottomMeshComponent;
case EClothingSlotType::Bra:
return BraMeshComponent;
case EClothingSlotType::Panties:
return PantiesMeshComponent;
case EClothingSlotType::Socks:
return SocksMeshComponent;
case EClothingSlotType::Shoes:
return ShoesMeshComponent;
default:
return NipplesMeshComponent;
}
}
void APlayerImpostor::EquipClothing(const UClothingItemInstance* ClothingItemInstance)
{
USkeletalMeshComponent* MeshComponent = GetMeshByType(ClothingItemInstance->GetClothingItem()->SlotType);
MeshComponent->SetSkeletalMesh(ClothingItemInstance->GetClothingItem()->SkeletalMesh);
if (ClothingItemInstance->GetClothingItem()->UseLeaderPose)
{
MeshComponent->SetLeaderPoseComponent(GetMesh());
}
if (!ClothingItemInstance->GetClothingItem()->Materials.IsEmpty())
{
for (const TPair<FName, UMaterialInstance*>& Material : ClothingItemInstance->GetClothingItem()->Materials)
{
MeshComponent->SetMaterialByName(Material.Key, Material.Value);
}
}
}
void APlayerImpostor::UnequipClothing(const UClothingItemInstance* ClothingItemInstance)
{
USkeletalMeshComponent* MeshComponent = GetMeshByType(ClothingItemInstance->GetClothingItem()->SlotType);
MeshComponent->SetSkeletalMesh(nullptr);
MeshComponent->SetLeaderPoseComponent(nullptr);
}