Added phone item
This commit is contained in:
@@ -7,7 +7,10 @@
|
||||
#include "NakedDesire/Clothing/ClothingItemDefinition.h"
|
||||
#include "NakedDesire/Clothing/ClothingItemInstance.h"
|
||||
#include "NakedDesire/Clothing/ClothingManager.h"
|
||||
#include "NakedDesire/Items/ItemDefinition.h"
|
||||
#include "NakedDesire/Items/ItemInstance.h"
|
||||
#include "NakedDesire/Phone/PhoneItemDefinition.h"
|
||||
#include "NakedDesire/Phone/PhoneItemInstance.h"
|
||||
#include "NakedDesire/Player/NakedDesireCharacter.h"
|
||||
#include "NakedDesire/SaveGame/GlobalSaveGameData.h"
|
||||
#include "NakedDesire/SaveGame/ItemSaveRecord.h"
|
||||
@@ -19,6 +22,12 @@ const TArray<TObjectPtr<UItemInstance>>& UInventorySubsystem::GetWardrobeItems()
|
||||
return WardrobeItems;
|
||||
}
|
||||
|
||||
UPhoneItemInstance* UInventorySubsystem::GetEquippedPhone()
|
||||
{
|
||||
EnsureHydrated();
|
||||
return EquippedPhone;
|
||||
}
|
||||
|
||||
void UInventorySubsystem::AddToWardrobe(UItemInstance* Item)
|
||||
{
|
||||
EnsureHydrated();
|
||||
@@ -37,6 +46,12 @@ void UInventorySubsystem::EquipFromWardrobe(UItemInstance* Item)
|
||||
{
|
||||
EnsureHydrated();
|
||||
|
||||
if (UPhoneItemInstance* Phone = Cast<UPhoneItemInstance>(Item))
|
||||
{
|
||||
EquipPhone(Phone);
|
||||
return;
|
||||
}
|
||||
|
||||
UClothingItemInstance* Clothing = Cast<UClothingItemInstance>(Item);
|
||||
if (!Clothing || !Clothing->GetClothingItemDefinition())
|
||||
return;
|
||||
@@ -74,6 +89,12 @@ void UInventorySubsystem::UnequipToWardrobe(UItemInstance* Item)
|
||||
{
|
||||
EnsureHydrated();
|
||||
|
||||
if (UPhoneItemInstance* Phone = Cast<UPhoneItemInstance>(Item))
|
||||
{
|
||||
UnequipPhone(Phone);
|
||||
return;
|
||||
}
|
||||
|
||||
UClothingItemInstance* Clothing = Cast<UClothingItemInstance>(Item);
|
||||
if (!Clothing || !Clothing->GetClothingItemDefinition())
|
||||
return;
|
||||
@@ -90,6 +111,45 @@ void UInventorySubsystem::UnequipToWardrobe(UItemInstance* Item)
|
||||
OnWardrobeChanged.Broadcast();
|
||||
}
|
||||
|
||||
void UInventorySubsystem::EquipPhone(UPhoneItemInstance* Phone)
|
||||
{
|
||||
if (!Phone || Phone == EquippedPhone)
|
||||
return;
|
||||
|
||||
UGlobalSaveGameData* Save = GetSave();
|
||||
|
||||
// Hot-swap: the previously equipped phone returns to the wardrobe (§9.9).
|
||||
if (EquippedPhone)
|
||||
{
|
||||
if (Save)
|
||||
Save->RemoveEquippedItem(EquippedPhone);
|
||||
StoreItem(EquippedPhone);
|
||||
}
|
||||
|
||||
UnstoreItem(Phone);
|
||||
EquippedPhone = Phone;
|
||||
if (Save)
|
||||
Save->AddEquippedItem(Phone);
|
||||
|
||||
OnPhoneChanged.Broadcast(EquippedPhone);
|
||||
OnWardrobeChanged.Broadcast();
|
||||
}
|
||||
|
||||
void UInventorySubsystem::UnequipPhone(UPhoneItemInstance* Phone)
|
||||
{
|
||||
if (!Phone || EquippedPhone != Phone)
|
||||
return;
|
||||
|
||||
if (UGlobalSaveGameData* Save = GetSave())
|
||||
Save->RemoveEquippedItem(Phone);
|
||||
|
||||
EquippedPhone = nullptr;
|
||||
StoreItem(Phone);
|
||||
|
||||
OnPhoneChanged.Broadcast(nullptr);
|
||||
OnWardrobeChanged.Broadcast();
|
||||
}
|
||||
|
||||
void UInventorySubsystem::EnsureHydrated()
|
||||
{
|
||||
UGlobalSaveGameData* Save = GetSave();
|
||||
@@ -108,6 +168,23 @@ void UInventorySubsystem::EnsureHydrated()
|
||||
if (UItemInstance* Instance = UItemInstance::CreateFromRecord(this, Record))
|
||||
WardrobeItems.Add(Instance);
|
||||
}
|
||||
|
||||
// Only the phone is hydrated from the equipped bucket here; equipped clothing is owned and
|
||||
// hydrated by the per-character UClothingManager. Pre-check the definition type so we don't
|
||||
// mint throwaway clothing instances.
|
||||
EquippedPhone = nullptr;
|
||||
for (const FItemSaveRecord& Record : Save->GetEquippedItems())
|
||||
{
|
||||
const UItemDefinition* Definition = Record.Definition.LoadSynchronous();
|
||||
if (!Definition || !Definition->IsA<UPhoneItemDefinition>())
|
||||
continue;
|
||||
|
||||
if (UPhoneItemInstance* Phone = Cast<UPhoneItemInstance>(UItemInstance::CreateFromRecord(this, Record)))
|
||||
{
|
||||
EquippedPhone = Phone;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UInventorySubsystem::StoreItem(UItemInstance* Item)
|
||||
|
||||
Reference in New Issue
Block a user