-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuff.h
More file actions
83 lines (74 loc) · 1.21 KB
/
buff.h
File metadata and controls
83 lines (74 loc) · 1.21 KB
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
#pragma once
enum BuffID
{
NoBuff = 0,
Speed,
JumpBoost, //就当是bw中的跳跃5了
Regeneration,
Poisoned,
Strength,
Invisibility,
InstantHeal,
};
vector<string> buff_names
{
"无效果",
"迅捷",
"跳跃提升",
"生命恢复",
"中毒",
"力量",
"隐身",
"瞬间治疗",
};
#define BUFF_SPEED_RATE 1.2
#define BUFF_JUMP_BOOST_RATE 2.5
#define BUFF_STRENGTH_DAMAGE_ADDITION 3.0
#define BUFF_MAX_CNT 6
class Buff //增益/减益
{
public:
BuffID id;
clock_t duration{ 0L };
clock_t lastAction{ 0L }; //上一次触发buff效果的时间戳
clock_t start{ 0L };
inline bool IsActive() const
{
return duration > 0L && (clock() - start <= duration);
}
clock_t RemainTime() const
{
return Clamp(duration - (clock() - start), 0L, duration);
}
void Clear()
{
duration = 0L;
}
};
class BuffAttribute
{
public:
array<Buff, BUFF_MAX_CNT> buffs;
BuffAttribute()
{
Clear();
}
void Clear()
{
for (auto& b : buffs)
b.Clear();
}
inline bool HasBuff(BuffID bid) const
{
return buffs[bid].IsActive();
}
void AddBuff(BuffID bid, clock_t duration)
{
buffs[bid].duration = duration;
buffs[bid].start = clock();
}
void RemoveBuff(BuffID bid)
{
buffs[bid].Clear();
}
};