-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCharacterExample.cs
68 lines (53 loc) · 1.93 KB
/
CharacterExample.cs
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
using CleverCrow.Fluid.StatsSystem.Editors;
using CleverCrow.Fluid.StatsSystem.StatsContainers;
using UnityEngine;
using UnityEngine.UI;
namespace CleverCrow.Fluid.StatsSystem {
[RequireComponent(typeof(StatsContainerExample))]
public class CharacterExample : MonoBehaviour {
private StatsContainer stats;
[SerializeField]
private Slider healthBar;
void Start () {
stats = GetComponent<StatsContainerExample>().copy;
var health = stats.GetStat("health");
healthBar.maxValue = health;
healthBar.value = health;
}
void Update () {
healthBar.maxValue = stats.GetStat("health");
}
public void ReceiveDamage (int damage) {
healthBar.value -= Mathf.Max(0, damage - stats.GetStat("armor"));
if (healthBar.value < 1) {
Destroy(gameObject);
}
}
public void AttackTarget (CharacterExample target) {
if (target == null) return;
target.ReceiveDamage((int)stats.GetStat("attack"));
}
public void AddHealth (float amount) {
var health = stats.GetModifier(OperatorType.Add, "health", "example");
stats.SetModifier(OperatorType.Add, "health", "example", health + amount);
}
public void RemoveHealth (float amount) {
var health = stats.GetModifier(OperatorType.Subtract, "health", "example");
stats.SetModifier(OperatorType.Subtract, "health", "example", health + amount);
}
public void MultiplyHealth (float amount) {
var health = stats.GetModifier(OperatorType.Multiply, "health", "example");
stats.SetModifier(OperatorType.Multiply, "health", "example", health + amount);
}
public void DivideHealth (float amount) {
var health = stats.GetModifier(OperatorType.Divide, "health", "example");
stats.SetModifier(OperatorType.Divide, "health", "example", health + amount);
}
public void RefillHealth () {
healthBar.value = healthBar.maxValue;
}
public void ClearAll () {
stats.ClearAllModifiers(stats.GetRecord("health"), "example");
}
}
}