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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
//========= Copyright Valve Corporation, All rights reserved. ============//
// halloween_boss_base.cpp
// Shared code for the Halloween Bosses
// Michael Booth, October 2011
#include "cbase.h"
#include "tf_player.h"
#include "tf_gamerules.h"
#include "halloween_base_boss.h"
#include "tf_gamestats.h"
//-----------------------------------------------------------------------------------------------------
CHalloweenBaseBoss::CHalloweenBaseBoss()
{
m_wasSpawnedByCheats = false;
}
//-----------------------------------------------------------------------------------------------------
CHalloweenBaseBoss::~CHalloweenBaseBoss()
{
}
//-----------------------------------------------------------------------------------------------------
void CHalloweenBaseBoss::Spawn( void )
{
BaseClass::Spawn();
ConVarRef sv_cheats( "sv_cheats" );
if ( sv_cheats.IsValid() && sv_cheats.GetBool() )
{
// remember we spawned with a cheat command
m_wasSpawnedByCheats = true;
}
m_damagePerSecond = 0.0f;
m_maxDamagePerSecond = 0.0f;
if ( TFGameRules() )
{
TFGameRules()->AddActiveBoss( this );
}
// track how many players were playing when boss spawned
CUtlVector< CTFPlayer * > playerVector;
CollectPlayers( &playerVector, TF_TEAM_RED );
CollectPlayers( &playerVector, TF_TEAM_BLUE, false, APPEND_PLAYERS );
// status
CTF_GameStats.Event_HalloweenBossEvent( GetBossType(), GetLevel(), HALLOWEEN_EVENT_BOSS_SPAWN, playerVector.Count(), 0.0f );
}
//-----------------------------------------------------------------------------------------------------
void CHalloweenBaseBoss::Update( void )
{
BaseClass::Update();
UpdateDamagePerSecond();
}
//-----------------------------------------------------------------------------------------------------
void CHalloweenBaseBoss::UpdateOnRemove()
{
if ( TFGameRules() )
{
TFGameRules()->RemoveActiveBoss( this );
}
BaseClass::UpdateOnRemove();
}
//-----------------------------------------------------------------------------------------------------
int CHalloweenBaseBoss::OnTakeDamage( const CTakeDamageInfo &info )
{
if ( info.GetDamage() && ( info.GetAttacker() != this ) )
{
CTFPlayer *pAttacker = ToTFPlayer( info.GetAttacker() );
if ( pAttacker && info.GetWeapon() )
{
CTFWeaponBase *pWeapon = dynamic_cast<CTFWeaponBase *>( info.GetWeapon() );
if ( pWeapon )
{
pWeapon->ApplyOnHitAttributes( this, pAttacker, info );
}
}
}
return BaseClass::OnTakeDamage( info );
}
//-----------------------------------------------------------------------------------------------------
int CHalloweenBaseBoss::OnTakeDamage_Alive( const CTakeDamageInfo &rawInfo )
{
CTakeDamageInfo info = rawInfo;
if ( info.GetAttacker() && info.GetAttacker()->GetTeamNumber() == GetTeamNumber() )
{
return 0;
}
if ( TFGameRules()->RoundHasBeenWon() )
{
info.SetDamage( 0.0f );
}
if ( info.GetDamageType() & DMG_CRITICAL )
{
// do the critical damage increase
info.SetDamage( info.GetDamage() * GetCritInjuryMultiplier() );
}
// keep a list of everyone who hurt me, and when
CTFPlayer *playerAttacker = ToTFPlayer( info.GetAttacker() );
if ( playerAttacker )
{
CTFWeaponBase *attackerWeapon = assert_cast< CTFWeaponBase * >( info.GetWeapon() );
bool isMeleeAttack = attackerWeapon && attackerWeapon->IsMeleeWeapon();
RememberAttacker( playerAttacker, isMeleeAttack, info.GetDamage() );
for( int i=0; i<playerAttacker->m_Shared.GetNumHealers(); ++i )
{
CTFPlayer *medic = ToTFPlayer( playerAttacker->m_Shared.GetHealerByIndex( i ) );
if ( medic )
{
// medics healing my attacker are also considered attackers
// they do zero damage to keep DPS calculations sane
RememberAttacker( medic, isMeleeAttack, 0.0f );
}
}
}
// fire event for client combat text, beep, etc.
IGameEvent *event = gameeventmanager->CreateEvent( "npc_hurt" );
if ( event )
{
event->SetInt( "entindex", entindex() );
event->SetInt( "health", MAX( 0, GetHealth() ) );
event->SetInt( "damageamount", info.GetDamage() );
event->SetBool( "crit", ( info.GetDamageType() & DMG_CRITICAL ) ? true : false );
event->SetInt( "boss", GetBossType() );
CTFPlayer *attackerPlayer = ToTFPlayer( info.GetAttacker() );
if ( attackerPlayer )
{
event->SetInt( "attacker_player", attackerPlayer->GetUserID() );
if ( attackerPlayer->GetActiveTFWeapon() )
{
event->SetInt( "weaponid", attackerPlayer->GetActiveTFWeapon()->GetWeaponID() );
}
else
{
event->SetInt( "weaponid", 0 );
}
}
else
{
// hurt by world
event->SetInt( "attacker_player", 0 );
event->SetInt( "weaponid", 0 );
}
gameeventmanager->FireEvent( event );
}
return BaseClass::OnTakeDamage_Alive( info );
}
void CHalloweenBaseBoss::Event_Killed( const CTakeDamageInfo &info )
{
const CUtlVector< AttackerInfo > &attackerVector = GetAttackerVector();
for( int i=0; i<attackerVector.Count(); ++i )
{
if ( attackerVector[i].m_attacker != NULL )
{
IGameEvent *pEvent = gameeventmanager->CreateEvent( "halloween_boss_killed" );
if ( pEvent )
{
pEvent->SetInt( "boss", GetBossType() );
pEvent->SetInt( "killer", attackerVector[i].m_attacker->GetUserID() );
gameeventmanager->FireEvent( pEvent, true );
}
// Shoot a huge soul at players that have damaged the boss
TFGameRules()->DropHalloweenSoulPack( 25, EyePosition(), attackerVector[i].m_attacker, TEAM_SPECTATOR );
}
}
BaseClass::Event_Killed( info );
}
//---------------------------------------------------------------------------------------------
void CHalloweenBaseBoss::RememberAttacker( CTFPlayer *playerAttacker, bool wasMeleeHit, float damage )
{
// record the damage for dps calculations
DamageRateInfo info;
info.m_damage = damage;
info.m_timestamp = gpGlobals->curtime;
m_damageVector.AddToTail( info );
int i;
// has this player hurt me before
for( i=0; i<m_attackerVector.Count(); ++i )
{
if ( m_attackerVector[i].m_attacker && m_attackerVector[i].m_attacker->entindex() == playerAttacker->entindex() )
{
// this player is hurting me again
m_attackerVector[i].m_timestamp = gpGlobals->curtime;
m_attackerVector[i].m_wasLastHitFromMeleeWeapon = wasMeleeHit;
return;
}
}
// new attacker
AttackerInfo attackerInfo;
attackerInfo.m_attacker = playerAttacker;
attackerInfo.m_timestamp = gpGlobals->curtime;
attackerInfo.m_wasLastHitFromMeleeWeapon = wasMeleeHit;
m_attackerVector.AddToTail( attackerInfo );
}
//---------------------------------------------------------------------------------------------
void CHalloweenBaseBoss::UpdateDamagePerSecond( void )
{
const float windowDuration = 5.0f;
int i;
m_damagePerSecond = 0.0f;
for( i=0; i<m_damageVector.Count(); ++i )
{
float age = gpGlobals->curtime - m_damageVector[i].m_timestamp;
if ( age > windowDuration )
{
// too old
continue;
}
m_damagePerSecond += m_damageVector[i].m_damage;
}
m_damagePerSecond /= windowDuration;
if ( m_damagePerSecond > m_maxDamagePerSecond )
{
m_maxDamagePerSecond = m_damagePerSecond;
}
// if ( m_damagePerSecond > 0.0001f )
// {
// DevMsg( "%3.2f: dps = %3.2f\n", gpGlobals->curtime, m_damagePerSecond );
// }
}
//---------------------------------------------------------------------------------------------
void CHalloweenBaseBoss::Break( void )
{
CPVSFilter filter( GetAbsOrigin() );
UserMessageBegin( filter, "BreakModel" );
WRITE_SHORT( GetModelIndex() );
WRITE_VEC3COORD( GetAbsOrigin() );
WRITE_ANGLES( GetAbsAngles() );
WRITE_SHORT( m_nSkin );
MessageEnd();
}
//---------------------------------------------------------------------------------------------
/*static*/ CHalloweenBaseBoss* CHalloweenBaseBoss::SpawnBossAtPos( HalloweenBossType bossType, const Vector& vSpawnPos, int nTeam /*= TF_TEAM_HALLOWEEN*/, CBaseEntity* pOwner /*= NULL*/ )
{
const char* pszBossType = NULL;
switch ( bossType )
{
case HALLOWEEN_BOSS_HHH:
pszBossType = "headless_hatman";
break;
case HALLOWEEN_BOSS_MONOCULUS:
pszBossType = "eyeball_boss";
break;
case HALLOWEEN_BOSS_MERASMUS:
pszBossType = "merasmus";
break;
default:
AssertMsg( 0, "Invalid Halloween Boss Type" );
}
CHalloweenBaseBoss *pBoss = NULL;
if ( pszBossType )
{
pBoss = dynamic_cast< CHalloweenBaseBoss * >( CreateEntityByName( pszBossType ) );
if ( pBoss )
{
pBoss->SetAbsOrigin( vSpawnPos + Vector( 0, 0, 10.0f ) );
pBoss->ChangeTeam( nTeam );
pBoss->SetOwnerEntity( pOwner );
DispatchSpawn( pBoss );
}
}
return pBoss;
}
|