Guest User

PWNWeapon.h

a guest
Mar 11th, 2015
527
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. #pragma once
  4.  
  5. #include "GameFramework/Actor.h"
  6. #include "PWNGameGlobals.h"
  7. #include "PWNWeaponAnimInstance.h"
  8. #include "PWNAnimSet_Weapon.h"
  9. #include "PWNAnimSet_Basic.h"
  10. #include "PWNAnimSet_Attacking.h"
  11. #include "PWNMovementDirectionCalculator.h"
  12. #include "PWNDamageType.h"
  13. #include "PWNInterpLeader.h"
  14. #include "Interface_Serialisable.h"
  15. #include "PWNWeapon.generated.h"
  16.  
  17. /**
  18.  *
  19.  */
  20.  
  21. /**************************/
  22. /*** Weapon States Enum ***/
  23. /**************************/
  24. UENUM(BlueprintType)
  25. namespace EWeaponStateEnum
  26. {
  27.     enum EWeaponState
  28.     {
  29.         WEAPONSTATE_Equipping                       UMETA(DisplayName = "Equipping"),
  30.         WEAPONSTATE_Idling                          UMETA(DisplayName = "Idling"),
  31.         WEAPONSTATE_AttackPreparing                 UMETA(DisplayName = "AttackPreparing"),
  32.         WEAPONSTATE_PreAttacking                    UMETA(DisplayName = "PreAttacking"),
  33.         WEAPONSTATE_Attacking                       UMETA(DisplayName = "Attacking"),
  34.         WEAPONSTATE_PostAttacking                   UMETA(DisplayName = "PostAttacking"),
  35.         WEAPONSTATE_AttackReturning                 UMETA(DisplayName = "AttackReturning"),
  36.         WEAPONSTATE_ReloadPreparing                 UMETA(DisplayName = "ReloadPreparing"),
  37.         WEAPONSTATE_Reloading                       UMETA(DisplayName = "Reloading"),
  38.         WEAPONSTATE_ReloadReturning                 UMETA(DisplayName = "ReloadReturning"),
  39.         WEAPONSTATE_PuttingDown                     UMETA(DisplayName = "PuttingDown"),
  40.         WEAPONSTATE_AttackRebounding                UMETA(DisplayName = "AttackRebounding"),
  41.         WEAPONSTATE_AttackRebounded                 UMETA(DisplayName = "AttackRebounded"),
  42.         WEAPONSTATE_AttackReboundReturning          UMETA(DisplayName = "AttackReboundReturning"),
  43.         WEAPONSTATE_Inactive                        UMETA(DisplayName = "Inactive")
  44.     };
  45. }
  46.  
  47. USTRUCT()
  48. struct FMontageDetails
  49. {
  50.     GENERATED_USTRUCT_BODY()
  51.            
  52.     float Position;
  53.     FString Name;
  54.     float Length;
  55. };
  56.  
  57. UCLASS()
  58. class APWNWeapon : public AActor, public IInterface_Serialisable
  59. {
  60.     GENERATED_UCLASS_BODY()
  61.  
  62.     virtual void BeginPlay() override;
  63.     virtual void PostInitializeComponents() override;
  64.     virtual void Tick(float DeltaTime) override;
  65.     void UpdateDisplay(float deltaTime, FRotator newRotation, FVector newLocation);
  66.    
  67.     // Debug
  68.     void PWNDebugTest();
  69.  
  70.     // Arm anim ended notify
  71.     void ArmAnimEndedNotify(UAnimMontage* montage, bool bInterrupted); 
  72.    
  73.     // Actually equips the weapon
  74.     void Init(bool isInLeftHand);
  75.    
  76.     // Entry point to start weapon equip
  77.     virtual void Equip();
  78.  
  79.     // Entry point to start weapon attack
  80.     virtual void AttackStart(const TEnumAsByte<EMovementDirectionEnum::EMovementDirection> attackDirection = EMovementDirectionEnum::MOVEMENTDIRECTION_NoDirection);
  81.  
  82.     // Entry point to stop weapon attack
  83.     virtual void AttackStop();
  84.  
  85.     /*********************/
  86.     /*** Serialisation ***/
  87.     /*********************/
  88.     UPWNSerialiser* Serialise();
  89.     void DeSerialise(UPWNSerialiser* mySavedData);
  90.     /*********************/
  91.  
  92. protected:
  93.     FOnMontageEnded ArmAnimEndDelegate;
  94.  
  95.     /*****************************/
  96.     /*** Location and Rotation ***/
  97.     /*****************************/
  98.     UPROPERTY()
  99.     UPWNInterpLeader* InterpLeaderYaw;
  100.     FRotator PrevRot;
  101.  
  102.     // Dummy Root
  103.     UPROPERTY()
  104.     TSubobjectPtr<USceneComponent> RootComponentDummy;
  105.    
  106.     /*********************/
  107.     /*** Asset Loaders ***/
  108.     /*********************/
  109.     // Loads a skeletal mesh from a text path
  110.     USkeletalMesh* LoadSkeletalMeshFromPath(FString path);
  111.     UAnimBlueprintGeneratedClass* LoadAnimBlueprintGeneratedClassFromPath(FString path);
  112.  
  113.     // Used to set literal asset references during constructor execution - for assets that are always used
  114.     void SetAssetReferences_Base();
  115.     // Used to set literal asset references during constructor execution - for subclass-specific assets
  116.     virtual void SetAssetReferences_Specific();
  117.     /*********************/
  118.  
  119.     /****************/
  120.     /*** Arm Mesh ***/
  121.     /****************/
  122.     // Construction refs - these are the ones to set in SetAssetReferences_Base
  123.     UPROPERTY()
  124.     FString ConstRefArmMeshLeftName;
  125.     UPROPERTY()
  126.     FString ConstRefArmMeshRightName;
  127.     UPROPERTY()
  128.     FString ConstRefArmAnimBlueprintLeftClassName;
  129.     UPROPERTY()
  130.     FString ConstRefArmAnimBlueprintRightClassName;
  131.     // Anim Blueprints
  132.     UPROPERTY()
  133.     UAnimBlueprintGeneratedClass* ArmAnimBlueprintClass;   
  134.     // Anim Sets
  135.     UPROPERTY()
  136.     UPWNWeaponAnimInstance* ArmAnimInstance;
  137.  
  138.     // Arm Component
  139.     UPROPERTY()
  140.     TSubobjectPtr<USkeletalMeshComponent> Arm;
  141.  
  142.     // Relative location and scale for mesh
  143.     UPROPERTY()
  144.     FVector ArmRelativeLocation;
  145.     UPROPERTY()
  146.     FVector ArmRelativeScale;
  147.    
  148.     // Skeletal Mesh
  149.     UPROPERTY()
  150.     USkeletalMesh* ArmMesh;
  151.  
  152.     /******************/
  153.     /*** Animations ***/
  154.     /******************/   
  155.     // Animset Asset References
  156.     UPROPERTY()
  157.     FString ConstRef_ArmAnimSet_Basic_Left_BP;
  158.     UPROPERTY()
  159.     FString ConstRef_ArmAnimSet_Basic_Right_BP;
  160.     UPROPERTY()
  161.     FString ConstRef_ArmAnimSet_Attacking_Left_BP;
  162.     UPROPERTY()
  163.     FString ConstRef_ArmAnimSet_Attacking_Right_BP;
  164.  
  165.     // Animsets
  166.     UPROPERTY()
  167.     APWNAnimSet_Basic* ArmAnimSet_Basic;
  168.     UPROPERTY()
  169.     APWNAnimSet_Attacking* ArmAnimSet_Attacking;
  170.  
  171.     // Functions
  172.     virtual void SetAssets_Base();
  173.     virtual void SetAssets_Specific();
  174.     virtual void SpawnAssets_Base();
  175.     virtual void SpawnAssets_Specific();
  176.     TSubclassOf<APWNAnimSet_Basic> LoadPWNAnimSetBlueprintFromPath_Basic(FString path);
  177.     TSubclassOf<APWNAnimSet_Attacking> LoadPWNAnimSetBlueprintFromPath_Attacking(FString path);
  178.     void Spawn_AnimSet_Attacking_Instance(UWorld* world, FString animSetAttackingAssetRef, APWNAnimSet_Attacking* &animSetAttackingToAssignTo);
  179.     /************/
  180.  
  181.     // Set arm animset. Returns whether we can set it or not
  182.     bool SetArmAnimSet_Attacking(APWNAnimSet_Attacking* animSetToUse);
  183.    
  184.     /****************/
  185.     /*** Weapon Mesh ***/
  186.     /****************/
  187.     UPROPERTY()
  188.     FString ConstRefWeaponMeshName;
  189.     UPROPERTY()
  190.     FName WeaponSocketName;
  191.     UPROPERTY()
  192.     FVector WeaponRotationOffsetLeft;
  193.     UPROPERTY()
  194.     FVector WeaponRotationOffsetRight;
  195.  
  196.     // Weapon Component
  197.     UPROPERTY()
  198.     TSubobjectPtr<USkeletalMeshComponent> Weapon;
  199.  
  200.     // Skeletal Meshes
  201.     UPROPERTY()
  202.     USkeletalMesh* WeaponMesh;
  203.  
  204.     UPROPERTY()
  205.     FVector WeaponRelativeScale;
  206.     /****************/
  207.  
  208.     /***************/
  209.     /*** General ***/
  210.     /***************/
  211.     UPROPERTY()
  212.     bool IsInLeftHand;
  213.    
  214.     // Finds an anim based on the attack state enums
  215.     UAnimMontage* FindArmAnim(EWeaponStateEnum::EWeaponState animState);
  216.  
  217.     // Plays a given anim montage with params
  218.     float PlayArmAnim(EWeaponStateEnum::EWeaponState weaponState, float const rate = 1.0f, float const startPosPct = 0.0f);
  219.    
  220.     // Current Attack Direction
  221.     UPROPERTY()
  222.     TEnumAsByte<EMovementDirectionEnum::EMovementDirection> AttackDirection;
  223.  
  224.     // Handle animation set updates when attack direction changes
  225.     virtual void UpdateAttackDirectionAnimset();
  226.    
  227.     //Damage type
  228.     UPROPERTY()
  229.     TSubclassOf<UPWNDamageType> DamageTypeClass;
  230.     /***************/
  231.  
  232.     /**************/
  233.     /*** States ***/
  234.     /**************/
  235.     UPROPERTY()
  236.     TEnumAsByte<EWeaponStateEnum::EWeaponState> ArmStateCurrent;
  237.     UPROPERTY()
  238.     float ArmStateNextTimeLeft;
  239.     float ArmStateCurrentTimeSpent;
  240.     UPROPERTY()
  241.     TEnumAsByte<EWeaponStateEnum::EWeaponState> ArmStateNext;
  242.  
  243.     void ArmStateNextCheckTransition(float deltaTime);
  244.     void ArmStateNextHandleTransition(float const startPosPct = 0.0f);
  245.     // Used to let states auto transition to the next logical chained state if there is no animation for the current state.
  246.     void ArmStateCheckSkipToNext();
  247.     FMontageDetails GetActiveMontageDetails(USkeletalMeshComponent* skelComp);
  248.     float GetActiveMontagePosition(USkeletalMeshComponent* skelComp);
  249.     float GetActiveMontageLength(USkeletalMeshComponent* skelComp);
  250.     void SetActiveMontagePosition(USkeletalMeshComponent* skelComp, float pos);
  251.  
  252.     // Specific states
  253.     virtual void ArmState_Equipping_Start(float const startPosPct = 0.0f);
  254.     virtual void ArmState_Idling_Start(float const startPosPct = 0.0f);
  255.     virtual void ArmState_AttackPreparing_Start(float const startPosPct = 0.0f);
  256.     virtual void ArmState_PreAttacking_Start(float const startPosPct = 0.0f);
  257.     virtual void ArmState_Attacking_Start(float const startPosPct = 0.0f);
  258.     virtual void ArmState_PostAttacking_Start(float const startPosPct = 0.0f);
  259.     virtual void ArmState_AttackReturning_Start(float const startPosPct = 0.0f);   
  260.     virtual void ArmState_ReloadPreparing_Start(float const startPosPct = 0.0f);
  261.     virtual void ArmState_Reloading_Start(float const startPosPct = 0.0f);
  262.     virtual void ArmState_ReloadReturning_Start(float const startPosPct = 0.0f);
  263.     virtual void ArmState_PuttingDown_Start(float const startPosPct = 0.0f);
  264.     virtual void ArmState_AttackRebounding_Start(float const startPosPct = 0.0f);
  265.     virtual void ArmState_AttackRebounded_Start(float const startPosPct = 0.0f);
  266.     virtual void ArmState_AttackReboundReturning_Start(float const startPosPct = 0.0f);
  267.     virtual void ArmState_Inactive_Start(float const startPosPct = 0.0f);
  268.     /**************/
  269.  
  270.  
  271.     /*************/
  272.     /*** Debug ***/
  273.     /*************/
  274.     /****************/
  275.    
  276. };
RAW Paste Data