-
Notifications
You must be signed in to change notification settings - Fork 0
/
SAttributeComponent.h
107 lines (71 loc) · 3.71 KB
/
SAttributeComponent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "SAttributeComponent.generated.h"
//DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FOnHealthChanged, AActor*, InstigatorActor, USAttributeComponent*, OwningComp, float, NewHealth, float, Delta);
//DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FOnRageChanged, AActor*, InstigatorActor, USAttributeComponent*, OwningComp, float, NewRage, float, Delta);
// Alternative: Share the same signature with generic names
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FOnAttributeChanged, AActor*, InstigatorActor, USAttributeComponent*, OwningComp, float, NewValue, float, Delta);
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class ACTIONROGUELIKE_API USAttributeComponent : public UActorComponent
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "Attributes")
static USAttributeComponent* GetAttributes(AActor* FromActor);
UFUNCTION(BlueprintCallable, Category = "Attributes", meta = (DisplayName = "IsAlive"))
static bool IsActorAlive(AActor* Actor);
USAttributeComponent();
protected:
// EditAnywhere - edit in BP editor and per-instance in level.
// VisibleAnywhere - 'read-only' in editor and level. (Use for Components)
// EditDefaultsOnly - hide variable per-instance, edit in BP editor only
// VisibleDefaultsOnly - 'read-only' access for variable, only in BP editor (uncommon)
// EditInstanceOnly - allow only editing of instance (eg. when placed in level)
// --
// BlueprintReadOnly - read-only in the Blueprint scripting (does not affect 'details'-panel)
// BlueprintReadWrite - read-write access in Blueprints
// --
// Category = "" - display only for detail panels and blueprint context menu.
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Replicated, Category = "Attributes")
float Health;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Replicated, Category = "Attributes")
float HealthMax;
/* Resource used to power certain Actions */
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Replicated, Category = "Attributes")
float Rage;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Replicated, Category = "Attributes")
float RageMax;
//UPROPERTY(ReplicatedUsing="")
//bool bIsAlive;
UFUNCTION(NetMulticast, Reliable) // @note: could mark as unreliable once we moved the 'state' out of scharacter (eg. once its cosmetic only)
void MulticastHealthChanged(AActor* InstigatorActor, float NewHealth, float Delta);
UFUNCTION(NetMulticast, Unreliable) // Used for cosmetic changes only
void MulticastRageChanged(AActor* InstigatorActor, float NewRage, float Delta);
public:
UFUNCTION(BlueprintCallable, Category = "Attributes")
bool Kill(AActor* InstigatorActor);
UFUNCTION(BlueprintCallable, Category = "Attributes")
bool IsAlive() const;
UFUNCTION(BlueprintCallable, Category = "Attributes")
bool IsFullHealth() const;
UFUNCTION(BlueprintCallable, Category = "Attributes")
bool IsFullRage() const;
UFUNCTION(BlueprintCallable, Category = "Attributes")
float GetHealth() const;
UFUNCTION(BlueprintCallable, Category = "Attributes")
float GetHealthMax() const;
UPROPERTY(BlueprintAssignable, Category = "Attributes")
FOnAttributeChanged OnHealthChanged;
UPROPERTY(BlueprintAssignable, Category = "Attributes")
FOnAttributeChanged OnRageChanged;
UFUNCTION(BlueprintCallable, Category = "Attributes")
bool ApplyHealthChange(AActor* InstigatorActor, float Delta);
UFUNCTION(BlueprintCallable)
float GetRage() const;
UFUNCTION(BlueprintCallable, Category = "Attributes")
float GetRageMax() const;
UFUNCTION(BlueprintCallable, Category = "Attributes")
bool ApplyRage(AActor* InstigatorActor, float Delta);
};