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
108
109
110
111
112
113
114
115
116
117
118
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Pawn.h"
#include "../World.h"
#include "../Bindings/PluginManager.h"
cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) :
super(a_EntityType, 0, 0, 0, a_Width, a_Height)
, m_EntityEffects(tEffectMap())
{
SetGravity(-32.0f);
SetAirDrag(0.02f);
}
void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
// Iterate through this entity's applied effects
for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
{
// Copies values to prevent pesky wrong accesses and erasures
cEntityEffect::eType EffectType = iter->first;
cEntityEffect * Effect = iter->second;
Effect->OnTick(*this);
// Iterates (must be called before any possible erasure)
++iter;
// Remove effect if duration has elapsed
if (Effect->GetDuration() - Effect->GetTicks() <= 0)
{
RemoveEntityEffect(EffectType);
}
// TODO: Check for discrepancies between client and server effect values
}
super::Tick(a_Dt, a_Chunk);
}
void cPawn::KilledBy(TakeDamageInfo & a_TDI)
{
ClearEntityEffects();
super::KilledBy(a_TDI);
}
void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier)
{
// Check if the plugins allow the addition:
if (cPluginManager::Get()->CallHookEntityAddEffect(*this, a_EffectType, a_Duration, a_Intensity, a_DistanceModifier))
{
// A plugin disallows the addition, bail out.
return;
}
// No need to add empty effects:
if (a_EffectType == cEntityEffect::effNoEffect)
{
return;
}
a_Duration = (int)(a_Duration * a_DistanceModifier);
m_EntityEffects[a_EffectType] = cEntityEffect::CreateEntityEffect(a_EffectType, a_Duration, a_Intensity, a_DistanceModifier);
m_World->BroadcastEntityEffect(*this, a_EffectType, a_Intensity, a_Duration);
m_EntityEffects[a_EffectType]->OnActivate(*this);
}
void cPawn::RemoveEntityEffect(cEntityEffect::eType a_EffectType)
{
m_World->BroadcastRemoveEntityEffect(*this, a_EffectType);
m_EntityEffects[a_EffectType]->OnDeactivate(*this);
delete m_EntityEffects[a_EffectType];
m_EntityEffects.erase(a_EffectType);
}
void cPawn::ClearEntityEffects()
{
// Iterate through this entity's applied effects
for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
{
// Copy values to prevent pesky wrong erasures
cEntityEffect::eType EffectType = iter->first;
// Iterates (must be called before any possible erasure)
++iter;
// Remove effect
RemoveEntityEffect(EffectType);
}
}
|