更新容器添加可旋转的shape物品
This commit is contained in:
parent
c340c59eab
commit
ce4efe2972
Binary file not shown.
Binary file not shown.
104
ProjectFish/Source/ProjectFish/Data/ContainerInfo.cpp
Normal file
104
ProjectFish/Source/ProjectFish/Data/ContainerInfo.cpp
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "ContainerInfo.h"
|
||||||
|
|
||||||
|
#include "Engine/AssetManager.h"
|
||||||
|
#include "Engine/StreamableManager.h"
|
||||||
|
|
||||||
|
void UContainerInfo::InitContainer(FPrimaryAssetId ContainerShapeId)
|
||||||
|
{
|
||||||
|
//加载形状资源
|
||||||
|
TSharedPtr<FStreamableHandle> LoadHandle = GEngine->AssetManager->LoadPrimaryAsset(ContainerShapeId);
|
||||||
|
if (LoadHandle.IsValid())
|
||||||
|
{
|
||||||
|
// 等待加载完成,这会阻塞线程
|
||||||
|
LoadHandle->WaitUntilComplete();
|
||||||
|
|
||||||
|
// 加载完成后,通过句柄获取资源
|
||||||
|
UObject* LoadedObject = LoadHandle->GetLoadedAsset();
|
||||||
|
if (LoadedObject)
|
||||||
|
{
|
||||||
|
ContainerShape = Cast<UShapeAsset>(LoadedObject);
|
||||||
|
for (int x = 0; x < ContainerShape->GetShapeWidth(); x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < ContainerShape->GetShapeHeight(); y++)
|
||||||
|
{
|
||||||
|
SlotInUsing.Add(FIntPoint(x, y), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LoadHandle->ReleaseHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UContainerInfo::AddContainerItem(FContainerItem Item, FIntPoint Position)
|
||||||
|
{
|
||||||
|
if (IsItemInContainerShape(Item, Position))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!IsItemOverlapOtherItem(Item, Position))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置容器指定位置的占用状态
|
||||||
|
for (int x = 0; x < Item.GetItemWIdth(); x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < Item.GetItemHeight(); y++)
|
||||||
|
{
|
||||||
|
if (Item.IsSlotUsing(FIntPoint(x, y)))
|
||||||
|
{
|
||||||
|
SlotInUsing.Add(FIntPoint(x + Position.X, y + Position.Y), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UContainerInfo::IsItemOverlapOtherItem(FContainerItem NewItem, FIntPoint Position)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (int x = 0; x < NewItem.GetItemWIdth(); x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < NewItem.GetItemHeight(); y++)
|
||||||
|
{
|
||||||
|
if (NewItem.IsSlotUsing(Position))
|
||||||
|
{
|
||||||
|
if (!ContainerShape->IsSlotActive(Position.X + x, Position.Y + y) ||
|
||||||
|
SlotInUsing.Find(FIntPoint(x + Position.X, y + Position.Y)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UContainerInfo::IsItemInContainerShape(FContainerItem NewItem, FIntPoint Position)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < NewItem.GetItemWIdth(); x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < NewItem.GetItemHeight(); y++)
|
||||||
|
{
|
||||||
|
if ( (x + Position.X) > 0 && (x + Position.X) < ContainerShape->GetShapeWidth() &&
|
||||||
|
(y + Position.Y) > 0 && (y + Position.Y) < ContainerShape->GetShapeHeight()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!ContainerShape->IsSlotActive(Position.X + x, Position.Y + y))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
106
ProjectFish/Source/ProjectFish/Data/ContainerInfo.h
Normal file
106
ProjectFish/Source/ProjectFish/Data/ContainerInfo.h
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "ProjectFish/DataAsset/ShapeAsset.h"
|
||||||
|
#include "UObject/Object.h"
|
||||||
|
#include "ContainerInfo.generated.h"
|
||||||
|
|
||||||
|
UENUM(BlueprintType)
|
||||||
|
enum class EItemDegreeType: uint8
|
||||||
|
{
|
||||||
|
Zero,
|
||||||
|
Ninety UMETA(DisplayName = "90度"),
|
||||||
|
OneEighty UMETA(DisplayName = "180度"),
|
||||||
|
TwentySeven UMETA(DisplayName = "270度"),
|
||||||
|
};
|
||||||
|
//仓库物品
|
||||||
|
|
||||||
|
class UShapeAsset;
|
||||||
|
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct FContainerItem
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
public:
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
EItemDegreeType DegreeType;
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
UShapeAsset* ItemShape;
|
||||||
|
|
||||||
|
//旋转后的水平宽度
|
||||||
|
int32 GetItemWIdth()
|
||||||
|
{
|
||||||
|
return DegreeType == EItemDegreeType::Ninety || DegreeType == EItemDegreeType::TwentySeven? ItemShape->GetShapeHeight()
|
||||||
|
: ItemShape->GetShapeWidth();
|
||||||
|
}
|
||||||
|
//旋转后的垂直高度
|
||||||
|
int32 GetItemHeight()
|
||||||
|
{
|
||||||
|
return DegreeType == EItemDegreeType::Ninety || DegreeType == EItemDegreeType::TwentySeven? ItemShape->GetShapeWidth()
|
||||||
|
: ItemShape->GetShapeHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsSlotUsing(FIntPoint Position)
|
||||||
|
{
|
||||||
|
FIntPoint BeforeRotationPos;
|
||||||
|
switch (DegreeType)
|
||||||
|
{
|
||||||
|
case EItemDegreeType::Zero:
|
||||||
|
BeforeRotationPos = Position;
|
||||||
|
break;
|
||||||
|
case EItemDegreeType::Ninety:
|
||||||
|
{
|
||||||
|
BeforeRotationPos.X = Position.Y;
|
||||||
|
BeforeRotationPos.Y = GetItemWIdth() - Position.X - 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EItemDegreeType::OneEighty:
|
||||||
|
{
|
||||||
|
BeforeRotationPos.X = GetItemWIdth() - Position.X - 1;
|
||||||
|
BeforeRotationPos.Y = GetItemHeight() - Position.Y- 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EItemDegreeType::TwentySeven:
|
||||||
|
{
|
||||||
|
BeforeRotationPos.X = Position.X;
|
||||||
|
BeforeRotationPos.Y = GetItemHeight() - Position.Y- 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ItemShape->IsSlotActive(BeforeRotationPos.X, BeforeRotationPos.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仓库
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class PROJECTFISH_API UContainerInfo : public UObject
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
void InitContainer(FPrimaryAssetId ContainerShapeId);
|
||||||
|
UFUNCTION(BlueprintPure)
|
||||||
|
bool AddContainerItem(FContainerItem Item, FIntPoint Position);
|
||||||
|
|
||||||
|
private:
|
||||||
|
//要添加的物品是否会覆盖其他物品
|
||||||
|
bool IsItemOverlapOtherItem(FContainerItem Item, FIntPoint Position);
|
||||||
|
//要添加的物品是否在容器范围内
|
||||||
|
bool IsItemInContainerShape(FContainerItem Item, FIntPoint Position);
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
TMap<int32, FContainerItem> Items;
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
UShapeAsset* ContainerShape;
|
||||||
|
|
||||||
|
private:
|
||||||
|
TMap<FIntPoint, bool> SlotInUsing;
|
||||||
|
};
|
||||||
@ -20,13 +20,13 @@ public:
|
|||||||
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "船只等级"))
|
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "船只等级"))
|
||||||
int32 ShipLevel;
|
int32 ShipLevel;
|
||||||
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "船舱信息"))
|
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "船舱信息"))
|
||||||
FContainerInfo ShipContainer;
|
class UContainerInfo* ShipContainer;
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "仓库资源"))
|
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "仓库资源"))
|
||||||
FPrimaryAssetId PlayerContainerAssetID;
|
FPrimaryAssetId PlayerContainerAssetID;
|
||||||
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "仓库等级"))
|
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "仓库等级"))
|
||||||
int32 PlayerContainerLevel;
|
int32 PlayerContainerLevel;
|
||||||
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "玩家仓库信息"))
|
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "玩家仓库信息"))
|
||||||
FContainerInfo PlayerContainer;
|
class UContainerInfo* PlayerContainer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
#include "FishInfoConfigAsset.generated.h"
|
#include "FishInfoConfigAsset.generated.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* 敌人 鱼的信息配置
|
||||||
*/
|
*/
|
||||||
UCLASS(BlueprintType)
|
UCLASS(BlueprintType)
|
||||||
class PROJECTFISH_API UFishInfoConfigAsset : public UDataAsset
|
class PROJECTFISH_API UFishInfoConfigAsset : public UDataAsset
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "ShapeAsset.h"
|
||||||
#include "Engine/DataAsset.h"
|
#include "Engine/DataAsset.h"
|
||||||
#include "FishingRewardDataAsset.generated.h"
|
#include "FishingRewardDataAsset.generated.h"
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ enum class ERewardRarityType: uint8
|
|||||||
Rare UMETA(DisplayName = "稀有"),
|
Rare UMETA(DisplayName = "稀有"),
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
*
|
* 鱼获配置
|
||||||
*/
|
*/
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class PROJECTFISH_API UFishingRewardDataAsset : public UPrimaryDataAsset
|
class PROJECTFISH_API UFishingRewardDataAsset : public UPrimaryDataAsset
|
||||||
@ -30,6 +31,9 @@ public:
|
|||||||
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Fishing Reward Data" , meta = (ToolTip = "鱼获重量"))
|
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Fishing Reward Data" , meta = (ToolTip = "鱼获重量"))
|
||||||
float RewardWeight;
|
float RewardWeight;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Fishing Reward Data" , meta = (ToolTip = "鱼获形状"))
|
||||||
|
class UShapeAsset* RewardShape;
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Fishing Reward Data" , meta = (ToolTip = "鱼获稀有度"))
|
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Fishing Reward Data" , meta = (ToolTip = "鱼获稀有度"))
|
||||||
ERewardRarityType RewardRarityType;
|
ERewardRarityType RewardRarityType;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -15,7 +15,7 @@ struct FShapeSlot
|
|||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
int32 Y;
|
int32 Y;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "该槽位是否为激活状态"))
|
||||||
bool bIsActive;
|
bool bIsActive;
|
||||||
FShapeSlot()
|
FShapeSlot()
|
||||||
{
|
{
|
||||||
@ -28,6 +28,7 @@ struct FShapeSlot
|
|||||||
X = InX;
|
X = InX;
|
||||||
Y = InY;
|
Y = InY;
|
||||||
bIsActive = InIsActive;
|
bIsActive = InIsActive;
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "ShipConfigAsset.h"
|
||||||
23
ProjectFish/Source/ProjectFish/DataAsset/ShipConfigAsset.h
Normal file
23
ProjectFish/Source/ProjectFish/DataAsset/ShipConfigAsset.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "ShapeAsset.h"
|
||||||
|
#include "Engine/DataAsset.h"
|
||||||
|
#include "ShipConfigAsset.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class PROJECTFISH_API UShipConfigAsset : public UPrimaryDataAsset
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
public:
|
||||||
|
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Ship")
|
||||||
|
FText ShipName;
|
||||||
|
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Ship", meta=(ToolTip = "等级对应的船舱形状"))
|
||||||
|
TArray<UShapeAsset*> Level_ShipShapes;
|
||||||
|
|
||||||
|
};
|
||||||
@ -5,6 +5,7 @@
|
|||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "GameplayTagContainer.h"
|
#include "GameplayTagContainer.h"
|
||||||
#include "PawnWithSkill.h"
|
#include "PawnWithSkill.h"
|
||||||
|
#include "DataAsset/ShapeAsset.h"
|
||||||
#include "UObject/Object.h"
|
#include "UObject/Object.h"
|
||||||
#include "Definations.generated.h"
|
#include "Definations.generated.h"
|
||||||
|
|
||||||
@ -460,3 +461,7 @@ struct FSimpleConnection
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
#include "GameFramework/CharacterMovementComponent.h"
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
#include "GameFramework/SpringArmComponent.h"
|
#include "GameFramework/SpringArmComponent.h"
|
||||||
#include "Kismet/KismetMathLibrary.h"
|
#include "Kismet/KismetMathLibrary.h"
|
||||||
#include "ProjectFish/Components/ShipSpringArmComponent.h"
|
#include "ProjectFish/Gameplay/Components/ShipSpringArmComponent.h"
|
||||||
#include "ProjectFish/Settings/GameConfigSettings.h"
|
#include "ProjectFish/Settings/GameConfigSettings.h"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "SkillEffect_EnhanceFishRod.h"
|
#include "SkillEffect_EnhanceFishRod.h"
|
||||||
|
|
||||||
#include "ProjectFish/Components/FishingRodComponent.h"
|
#include "ProjectFish/Gameplay/Components/FishingRodComponent.h"
|
||||||
#include "ProjectFish/Skill/Skill.h"
|
#include "ProjectFish/Skill/Skill.h"
|
||||||
|
|
||||||
void USkillEffect_EnhanceFishRod::Execute(const FSkillContext& context)
|
void USkillEffect_EnhanceFishRod::Execute(const FSkillContext& context)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user