Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// DHUsableItem.h
- // Copyright 2015 Dirt Productions. All rights reserved.
- #pragma once
- #include "Items/DHItem.h"
- #include "DHUsableItem.generated.h"
- #define SPECS_ADDDEFAULTS_UsableItem ItemStorefront.AddUsableItemSpecifications(BaseSpeedModifier, UseSpeedModifier, AltUseSpeedModifier, UsageRepetition, AltUsageRepetition)
- // Forward declarations
- class ADHUsableItemMod;
- /** ADHUsableItem : AHDItem
- * Declared: DHUsableItem.h
- *
- * A usable item defines the behavior of an item that can be held in hand and used
- * Handles item repetition and in-hand mesh components automatically
- */
- UCLASS()
- class DISTANTHOME_API ADHUsableItem : public ADHItem
- {
- GENERATED_BODY()
- public:
- /** Default constructor */
- ADHUsableItem(const FObjectInitializer& ObjectInitializer);
- //////////////////////////////////////////////////////////////////////////
- // Components
- /** First person skeletal mesh component */
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Usable Item|Components")
- USkeletalMeshComponent* FirstPersonMeshComponent;
- /** Third person skeletal mesh component */
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Usable Item|Components")
- USkeletalMeshComponent* ThirdPersonMeshComponent;
- //////////////////////////////////////////////////////////////////////////
- // Usable item
- /** Modifier constantly applied to carrier's maximum movement speed */
- UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
- float BaseSpeedModifier = 1.0f;
- /** Modifier applied to carrier's maximum movement speed only while using */
- UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
- float UseSpeedModifier = 1.0f;
- /** Modifier applied to carrier's maximum movement speed only while using alternately */
- UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
- float AltUseSpeedModifier = 1.0f;
- /** Modifier applied to carrier's field of view at the moment */
- UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
- float CurrentFOVModifier = 1.0f;
- /** Modifier applied to carrier's view rate at the moment */
- UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
- float CurrentViewRateModifier = 1.0f;
- /** Attachment point of first person mesh component */
- UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
- FName FirstPersonAttachPoint = NAME_None;
- /** Attachment point of third person mesh component */
- UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
- FName ThirdPersonAttachPoint = NAME_None;
- /** Normal usage item repetition manager */
- UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item|Repetition")
- FDHUsableItemRepetition UsageRepetition;
- /** Alternate usage item repetition manager */
- UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item|Repetition")
- FDHUsableItemRepetition AltUsageRepetition;
- /** List of equipped item mods */
- UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
- TArray<ADHUsableItemMod*> EquippedMods;
- /** List of desired item mods to equip on construction */
- UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
- TArray<TSubclassOf<ADHUsableItem>> DesiredMods;
- /** Overridden to also set PawnOwner */
- virtual void SetOwner(AController* InOwner) override;
- /** @returns pawn that owns this item at the moment */
- UFUNCTION(BlueprintPure, Category = "Item|Usable Item")
- APawn* GetPawnOwner() const { return PawnOwner; }
- /** @returns true if item can be used at the moment, otherwise false
- *
- * @param bCheckAlt True to check alternate usage, false to check normal usage
- * @param bCheckAll True to check both, overrides bCheckAlt if true
- */
- UFUNCTION(BlueprintPure, Category = "Item|Usable Item")
- virtual bool CanUse(bool bCheckAlt = false, bool bCheckAll = true);
- /** @returns true if item is being normally used at the moment, otherwise false */
- UFUNCTION(BlueprintPure, Category = "Item|Usable Item")
- bool IsUsing() const { return bIsUsing; }
- /** @returns true if item is being alternately used at the moment, otherwise false */
- UFUNCTION(BlueprintPure, Category = "Item|Usable Item")
- bool IsAltUsing() const { return bIsAltUsing; }
- //////////////////////////////////////////////////////////////////////////
- // Item behavior
- /** Starts normally using this item
- *
- * @param bRepeat True to repeat if allowed, otherwise false
- */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Behavior")
- virtual void StartUse(bool bRepeat = true);
- /** Stops normally using this item if currently doing so */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Behavior")
- virtual void StopUse();
- /** Starts alternately using this item
- *
- * @param bRepeat True to repeat if allowed, otherwise false
- */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Behavior")
- virtual void StartAltUse(bool bRepeat = true);
- /** Stops alternately using this item if currently doing so */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Itme|Behavior")
- virtual void StopAltUse();
- /** Called when this item has been equipped */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Events")
- virtual void OnEquipped();
- /** Called when this item has been unequipped */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Events")
- virtual void OnUnequipped();
- /** Called when this item has entered an inventory
- *
- * @param Pawn Owner of inventory
- */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Events")
- virtual void OnInventoryEntered(APawn* Pawn);
- /** Called when this item has left an inventory */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Events")
- virtual void OnInventoryLeft() { Destroy(); }
- protected:
- /** Defines single normal usage of this item
- *
- * @note The base function already increments usage repetitions counter,
- * @note No need to do the same in overrides unless parent call is omitted
- */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Behavior")
- virtual void UseOnce() { if (UsageRepetition.bCanEverRepeat) UsageRepetition.Increment(); for (ADHUsableItemMod* Mod : EquippedMods) Mod->OnOwnerUse(); }
- /** Defines single alternate usage of this item
- *
- * @note The base function already increments alternate usage repetition counter,
- * @note No need to do the same in overrides, unless parent call is omitted
- */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Behavior")
- virtual void AltUseOnce() { if (AltUsageRepetition.bCanEverRepeat) AltUsageRepetition.Increment(); }
- /** True if item is being normally used at the moment */
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Usable Item")
- bool bIsUsing;
- /** True if item is being alternately used at the moment */
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Usable Item")
- bool bIsAltUsing;
- /** Pawn that owns this item at the moment */
- UPROPERTY()
- APawn* PawnOwner;
- /** BEGIN Timer handle for efficient management of item usage timers */
- FTimerHandle UsageHandle;
- FTimerHandle AltUsageHandle;
- /** END Timer handle for efficient management of item usage timers */
- };
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// DHUsableItemMod.h
- // Copyright 2015 Dirt Productions. All rights reserved.
- #pragma once
- #include "Items/DHItem.h"
- #include "UnrealNetwork.h"
- #include "Items/UsableItems/DHUsableItem.h"
- #include "DHUsableItemMod.generated.h"
- /** ADHUsableItemMod : ADHItem
- * Declared: DHUsableItemMod.h
- *
- * A usable item mod defines a subcomponent of a usable item
- * i.e. Weapon sights, Extra knife parts, etc.
- */
- UCLASS()
- class DISTANTHOME_API ADHUsableItemMod : public ADHItem
- {
- GENERATED_BODY()
- public:
- /** Default constructor */
- ADHUsableItemMod(const FObjectInitializer& ObjectInitializer);
- //////////////////////////////////////////////////////////////////////////
- // Components
- protected:
- /** First person skeletal mesh component */
- UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components", Replicated)
- USkeletalMeshComponent* FirstPersonMeshComponent;
- /** Third person skeletal mesh component */
- UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components", Replicated)
- USkeletalMeshComponent* ThirdPersonMeshComponent;
- public:
- /** @returns first person skeletal mesh component */
- UFUNCTION(BlueprintPure, Category = "Components")
- USkeletalMeshComponent* GetFirstPersonMeshComponent() const { return FirstPersonMeshComponent; }
- /** @returns third person skeletal mesh component */
- UFUNCTION(BlueprintPure, Category = "Components")
- USkeletalMeshComponent* GetThirdPersonMeshComponent() const { return ThirdPersonMeshComponent; }
- //////////////////////////////////////////////////////////////////////////
- // Usable item mod
- /** Current owner of this mod */
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Usable Item Mod")
- ADHUsableItem* ItemOwner;
- /** Called when owner is normally used once */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Item Mod")
- virtual void OnOwnerUseOnce() {}
- /** Called when owner is alternately used once */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Item Mod")
- virtual void OnOwnerAltUseOnce() {}
- //////////////////////////////////////////////////////////////////////////
- // Ownership
- /** Sets item owner and controller owner from item
- *
- * @param Item Desired item
- */
- UFUNCTION(BlueprintCallable, Category = "Item|Usable Item Mod")
- virtual void SetItemOwner(ADHUsableItem* Item) { if (Item) ItemOwner = Item; ControllerOwner = Item->GetControllerOwner(); }
- /** @returns item that owns this mod */
- UFUNCTION(BlueprintPure, Category = "Item|Usable Item Mod")
- virtual ADHUsableItem* GetItemOwner() const { return ItemOwner; }
- };
Advertisement
Add Comment
Please, Sign In to add comment