Dirt113

ADHItem inheritance

Dec 1st, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.26 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// DHUsableItem.h
  2.  
  3. // Copyright 2015 Dirt Productions. All rights reserved.
  4.  
  5. #pragma once
  6.  
  7. #include "Items/DHItem.h"
  8. #include "DHUsableItem.generated.h"
  9.  
  10. #define SPECS_ADDDEFAULTS_UsableItem ItemStorefront.AddUsableItemSpecifications(BaseSpeedModifier, UseSpeedModifier, AltUseSpeedModifier, UsageRepetition, AltUsageRepetition)
  11.  
  12. // Forward declarations
  13. class ADHUsableItemMod;
  14.  
  15. /** ADHUsableItem : AHDItem
  16.  * Declared: DHUsableItem.h
  17.  *
  18.  * A usable item defines the behavior of an item that can be held in hand and used
  19.  * Handles item repetition and in-hand mesh components automatically
  20.  */
  21. UCLASS()
  22. class DISTANTHOME_API ADHUsableItem : public ADHItem
  23. {
  24.     GENERATED_BODY()
  25.    
  26. public:
  27.     /** Default constructor */
  28.     ADHUsableItem(const FObjectInitializer& ObjectInitializer);
  29.  
  30.     //////////////////////////////////////////////////////////////////////////
  31.     // Components
  32.  
  33.     /** First person skeletal mesh component */
  34.     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Usable Item|Components")
  35.         USkeletalMeshComponent* FirstPersonMeshComponent;
  36.     /** Third person skeletal mesh component */
  37.     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Usable Item|Components")
  38.         USkeletalMeshComponent* ThirdPersonMeshComponent;
  39.    
  40.     //////////////////////////////////////////////////////////////////////////
  41.     // Usable item
  42.  
  43.     /** Modifier constantly applied to carrier's maximum movement speed */
  44.     UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
  45.         float BaseSpeedModifier = 1.0f;
  46.     /** Modifier applied to carrier's maximum movement speed only while using */
  47.     UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
  48.         float UseSpeedModifier = 1.0f;
  49.     /** Modifier applied to carrier's maximum movement speed only while using alternately */
  50.     UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
  51.         float AltUseSpeedModifier = 1.0f;
  52.     /** Modifier applied to carrier's field of view at the moment */
  53.     UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
  54.         float CurrentFOVModifier = 1.0f;
  55.     /** Modifier applied to carrier's view rate at the moment */
  56.     UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
  57.         float CurrentViewRateModifier = 1.0f;
  58.     /** Attachment point of first person mesh component */
  59.     UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
  60.         FName FirstPersonAttachPoint = NAME_None;
  61.     /** Attachment point of third person mesh component */
  62.     UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
  63.         FName ThirdPersonAttachPoint = NAME_None;
  64.     /** Normal usage item repetition manager */
  65.     UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item|Repetition")
  66.         FDHUsableItemRepetition UsageRepetition;
  67.     /** Alternate usage item repetition manager */
  68.     UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item|Repetition")
  69.         FDHUsableItemRepetition AltUsageRepetition;
  70.     /** List of equipped item mods */
  71.     UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
  72.         TArray<ADHUsableItemMod*> EquippedMods;
  73.     /** List of desired item mods to equip on construction */
  74.     UPROPERTY(EditDefaultsOnly, Category = "Item|Usable Item")
  75.         TArray<TSubclassOf<ADHUsableItem>> DesiredMods;
  76.     /** Overridden to also set PawnOwner */
  77.     virtual void SetOwner(AController* InOwner) override;
  78.  
  79.     /** @returns pawn that owns this item at the moment */
  80.     UFUNCTION(BlueprintPure, Category = "Item|Usable Item")
  81.         APawn* GetPawnOwner() const { return PawnOwner; }
  82.  
  83.     /** @returns true if item can be used at the moment, otherwise false
  84.      *
  85.      * @param bCheckAlt         True to check alternate usage, false to check normal usage
  86.      * @param bCheckAll         True to check both, overrides bCheckAlt if true
  87.      */
  88.     UFUNCTION(BlueprintPure, Category = "Item|Usable Item")
  89.         virtual bool CanUse(bool bCheckAlt = false, bool bCheckAll = true);
  90.     /** @returns true if item is being normally used at the moment, otherwise false */
  91.     UFUNCTION(BlueprintPure, Category = "Item|Usable Item")
  92.         bool IsUsing() const { return bIsUsing; }
  93.     /** @returns true if item is being alternately used at the moment, otherwise false */
  94.     UFUNCTION(BlueprintPure, Category = "Item|Usable Item")
  95.         bool IsAltUsing() const { return bIsAltUsing; }
  96.  
  97.     //////////////////////////////////////////////////////////////////////////
  98.     // Item behavior
  99.  
  100.     /** Starts normally using this item
  101.      *
  102.      * @param bRepeat       True to repeat if allowed, otherwise false
  103.      */
  104.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Behavior")
  105.         virtual void StartUse(bool bRepeat = true);
  106.     /** Stops normally using this item if currently doing so */
  107.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Behavior")
  108.         virtual void StopUse();
  109.     /** Starts alternately using this item
  110.      *
  111.      * @param bRepeat       True to repeat if allowed, otherwise false
  112.      */
  113.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Behavior")
  114.         virtual void StartAltUse(bool bRepeat = true);
  115.     /** Stops alternately using this item if currently doing so */
  116.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Itme|Behavior")
  117.         virtual void StopAltUse();
  118.     /** Called when this item has been equipped */
  119.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Events")
  120.         virtual void OnEquipped();
  121.     /** Called when this item has been unequipped */
  122.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Events")
  123.         virtual void OnUnequipped();
  124.     /** Called when this item has entered an inventory
  125.      *
  126.      * @param Pawn          Owner of inventory
  127.      */
  128.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Events")
  129.         virtual void OnInventoryEntered(APawn* Pawn);
  130.     /** Called when this item has left an inventory */
  131.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Events")
  132.         virtual void OnInventoryLeft() { Destroy(); }
  133. protected:
  134.     /** Defines single normal usage of this item
  135.      *
  136.      * @note                The base function already increments usage repetitions counter,
  137.      * @note                No need to do the same in overrides unless parent call is omitted
  138.      */
  139.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Behavior")
  140.         virtual void UseOnce() { if (UsageRepetition.bCanEverRepeat) UsageRepetition.Increment(); for (ADHUsableItemMod* Mod : EquippedMods) Mod->OnOwnerUse(); }
  141.     /** Defines single alternate usage of this item
  142.      *
  143.      * @note                The base function already increments alternate usage repetition counter,
  144.      * @note                No need to do the same in overrides, unless parent call is omitted
  145.      */
  146.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Item|Behavior")
  147.         virtual void AltUseOnce() { if (AltUsageRepetition.bCanEverRepeat) AltUsageRepetition.Increment(); }
  148.     /** True if item is being normally used at the moment */
  149.     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Usable Item")
  150.         bool bIsUsing;
  151.     /** True if item is being alternately used at the moment */
  152.     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Usable Item")
  153.         bool bIsAltUsing;
  154.     /** Pawn that owns this item at the moment */
  155.     UPROPERTY()
  156.         APawn* PawnOwner;
  157.     /** BEGIN Timer handle for efficient management of item usage timers */
  158.     FTimerHandle UsageHandle;
  159.     FTimerHandle AltUsageHandle;
  160.     /** END Timer handle for efficient management of item usage timers */
  161. };
  162.  
  163. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// DHUsableItemMod.h
  164.  
  165. // Copyright 2015 Dirt Productions. All rights reserved.
  166.  
  167. #pragma once
  168.  
  169. #include "Items/DHItem.h"
  170. #include "UnrealNetwork.h"
  171. #include "Items/UsableItems/DHUsableItem.h"
  172. #include "DHUsableItemMod.generated.h"
  173.  
  174. /** ADHUsableItemMod : ADHItem
  175.  * Declared: DHUsableItemMod.h
  176.  *
  177.  * A usable item mod defines a subcomponent of a usable item
  178.  * i.e. Weapon sights, Extra knife parts, etc.
  179.  */
  180. UCLASS()
  181. class DISTANTHOME_API ADHUsableItemMod : public ADHItem
  182. {
  183.     GENERATED_BODY()
  184.    
  185. public:
  186.     /** Default constructor */
  187.     ADHUsableItemMod(const FObjectInitializer& ObjectInitializer);
  188.  
  189.     //////////////////////////////////////////////////////////////////////////
  190.     // Components
  191. protected:
  192.     /** First person skeletal mesh component */
  193.     UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components", Replicated)
  194.         USkeletalMeshComponent* FirstPersonMeshComponent;
  195.     /** Third person skeletal mesh component */
  196.     UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components", Replicated)
  197.         USkeletalMeshComponent* ThirdPersonMeshComponent;
  198. public:
  199.     /** @returns first person skeletal mesh component */
  200.     UFUNCTION(BlueprintPure, Category = "Components")
  201.         USkeletalMeshComponent* GetFirstPersonMeshComponent() const { return FirstPersonMeshComponent; }
  202.     /** @returns third person skeletal mesh component */
  203.     UFUNCTION(BlueprintPure, Category = "Components")
  204.         USkeletalMeshComponent* GetThirdPersonMeshComponent() const { return ThirdPersonMeshComponent; }
  205.    
  206.     //////////////////////////////////////////////////////////////////////////
  207.     // Usable item mod
  208.  
  209.     /** Current owner of this mod */
  210.     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Usable Item Mod")
  211.         ADHUsableItem* ItemOwner;
  212.  
  213.     /** Called when owner is normally used once */
  214.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Item Mod")
  215.         virtual void OnOwnerUseOnce() {}
  216.     /** Called when owner is alternately used once */
  217.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Item Mod")
  218.         virtual void OnOwnerAltUseOnce() {}
  219.  
  220.     //////////////////////////////////////////////////////////////////////////
  221.     // Ownership
  222.    
  223.     /** Sets item owner and controller owner from item
  224.      *
  225.      * @param Item          Desired item
  226.      */
  227.     UFUNCTION(BlueprintCallable, Category = "Item|Usable Item Mod")
  228.         virtual void SetItemOwner(ADHUsableItem* Item) { if (Item) ItemOwner = Item; ControllerOwner = Item->GetControllerOwner(); }
  229.     /** @returns item that owns this mod */
  230.     UFUNCTION(BlueprintPure, Category = "Item|Usable Item Mod")
  231.         virtual ADHUsableItem* GetItemOwner() const { return ItemOwner; }
  232. };
Advertisement
Add Comment
Please, Sign In to add comment