Make UpgradeWeapon overrideable for child classes
This commit is contained in:
		
							parent
							
								
									55ec2cbfda
								
							
						
					
					
						commit
						9f7d2bf4c7
					
				| @ -20,21 +20,22 @@ void AWeapon::BeginPlay() | |||||||
| 	GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true); | 	GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void AWeapon::ResetWeaponTimer() | ||||||
|  | { | ||||||
|  | 	GetWorldTimerManager().ClearTimer(WeaponTimerHandle); | ||||||
|  | 	GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void AWeapon::FireWeaponAction_Implementation() | void AWeapon::FireWeaponAction_Implementation() | ||||||
| { | { | ||||||
| 	// This should be overridden in child weapon classes 
 | 	// This should be overridden in child weapon classes 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool AWeapon::UpgradeWeapon() | bool AWeapon::UpgradeWeapon_Implementation() | ||||||
| { | { | ||||||
| 	if (CurrentLevel + 1 <= Upgrades.Num()) | 	if (CurrentLevel < MaxLevel) | ||||||
| 	{ | 	{ | ||||||
| 		CurrentLevel++; | 		CurrentLevel++; | ||||||
| 		WeaponCooldown *= Upgrades[CurrentLevel - 1].WeaponCooldownMultiplier; |  | ||||||
| 		Damage *= Upgrades[CurrentLevel - 1].WeaponDamageMultiplier; |  | ||||||
| 		 |  | ||||||
| 		GetWorldTimerManager().ClearTimer(WeaponTimerHandle); |  | ||||||
| 		GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true); |  | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
|  | |||||||
| @ -9,24 +9,6 @@ | |||||||
| class UPaperSprite; | class UPaperSprite; | ||||||
| class UWeaponDataAsset; | class UWeaponDataAsset; | ||||||
| 
 | 
 | ||||||
| USTRUCT(BlueprintType) |  | ||||||
| struct FWeaponLevelUpgrades |  | ||||||
| { |  | ||||||
| 	GENERATED_BODY() |  | ||||||
| 
 |  | ||||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin = 0.01f, ClampMax = 1.0f)) |  | ||||||
| 	float WeaponCooldownMultiplier = 1.0f; |  | ||||||
| 
 |  | ||||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin = 0.01f)) |  | ||||||
| 	float WeaponDamageMultiplier = 1.0f; |  | ||||||
| 
 |  | ||||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin = 0.01f)) |  | ||||||
| 	float WeaponRangeMultiplier = 1.0f; |  | ||||||
| 
 |  | ||||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite) |  | ||||||
| 	FText WeaponUpgradeText; |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| UCLASS() | UCLASS() | ||||||
| class VAMPIRES_API AWeapon : public AActor | class VAMPIRES_API AWeapon : public AActor | ||||||
| { | { | ||||||
| @ -55,10 +37,13 @@ public: | |||||||
| 	float Damage; | 	float Damage; | ||||||
| 
 | 
 | ||||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties") | 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties") | ||||||
| 	TArray<FWeaponLevelUpgrades> Upgrades = TArray<FWeaponLevelUpgrades>(); | 	TArray<FText> UpgradeDescriptions; | ||||||
| 	 | 	 | ||||||
| 	int CurrentLevel = 0; | 	int CurrentLevel = 0; | ||||||
| 
 | 
 | ||||||
|  | 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) | ||||||
|  | 	int MaxLevel = 0; | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
| 	FTimerHandle WeaponTimerHandle; | 	FTimerHandle WeaponTimerHandle; | ||||||
| 
 | 
 | ||||||
| @ -71,11 +56,14 @@ protected: | |||||||
| 	// Called when the game starts or when spawned
 | 	// Called when the game starts or when spawned
 | ||||||
| 	virtual void BeginPlay() override; | 	virtual void BeginPlay() override; | ||||||
| 
 | 
 | ||||||
|  | 	void ResetWeaponTimer(); | ||||||
|  | 	 | ||||||
| public: | public: | ||||||
| 	UFUNCTION(BlueprintNativeEvent) | 	UFUNCTION(BlueprintNativeEvent) | ||||||
| 	void FireWeaponAction(); | 	void FireWeaponAction(); | ||||||
| 	virtual void FireWeaponAction_Implementation(); | 	virtual void FireWeaponAction_Implementation(); | ||||||
| 
 | 
 | ||||||
| 	UFUNCTION() | 	UFUNCTION(BlueprintNativeEvent) | ||||||
| 	virtual bool UpgradeWeapon(); | 	bool UpgradeWeapon(); | ||||||
|  | 	virtual bool UpgradeWeapon_Implementation(); | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -43,7 +43,7 @@ void ULevelUpWidget::NativeConstruct() | |||||||
| 		TArray<UUpgradeButtonDataObject*> upgradeItems; | 		TArray<UUpgradeButtonDataObject*> upgradeItems; | ||||||
| 		for (AWeapon* weapon : Inventory) | 		for (AWeapon* weapon : Inventory) | ||||||
| 		{ | 		{ | ||||||
| 			if (weapon->CurrentLevel < weapon->Upgrades.Num()) | 			if (weapon->CurrentLevel < weapon->UpgradeDescriptions.Num()) | ||||||
| 			{ | 			{ | ||||||
| 				UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this); | 				UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this); | ||||||
| 				Temp->SetData(weapon, this); | 				Temp->SetData(weapon, this); | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ | |||||||
| void UUpgradeButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent) | void UUpgradeButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent) | ||||||
| { | { | ||||||
| 	WeaponName = Weapon->Name; | 	WeaponName = Weapon->Name; | ||||||
| 	Description = Weapon->Description; | 	Description = Weapon->UpgradeDescriptions[Weapon->CurrentLevel]; | ||||||
| 	WeaponIcon = Weapon->Icon; | 	WeaponIcon = Weapon->Icon; | ||||||
| 	WeaponInstance = Weapon; | 	WeaponInstance = Weapon; | ||||||
| 	Parent = parent; | 	Parent = parent; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user