Skip to content

Commit c11208c

Browse files
authoredApr 5, 2021
Game: Scale damage flash to max HP
The flash intensity is calculated proportionally to the maximal HP.
1 parent f0bad0e commit c11208c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
 

‎src/client/content_cao.h

+2
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ class GenericCAO : public ClientActiveObject
174174

175175
const bool isImmortal();
176176

177+
inline const ObjectProperties &getProperties() const { return m_prop; }
178+
177179
scene::ISceneNode *getSceneNode() const;
178180

179181
scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() const;

‎src/client/game.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -2568,14 +2568,18 @@ void Game::handleClientEvent_PlayerDamage(ClientEvent *event, CameraOrientation
25682568

25692569
// Damage flash and hurt tilt are not used at death
25702570
if (client->getHP() > 0) {
2571-
runData.damage_flash += 95.0f + 3.2f * event->player_damage.amount;
2572-
runData.damage_flash = MYMIN(runData.damage_flash, 127.0f);
2573-
25742571
LocalPlayer *player = client->getEnv().getLocalPlayer();
25752572

2573+
f32 hp_max = player->getCAO() ?
2574+
player->getCAO()->getProperties().hp_max : PLAYER_MAX_HP_DEFAULT;
2575+
f32 damage_ratio = event->player_damage.amount / hp_max;
2576+
2577+
runData.damage_flash += 95.0f + 64.f * damage_ratio;
2578+
runData.damage_flash = MYMIN(runData.damage_flash, 127.0f);
2579+
25762580
player->hurt_tilt_timer = 1.5f;
25772581
player->hurt_tilt_strength =
2578-
rangelim(event->player_damage.amount / 4.0f, 1.0f, 4.0f);
2582+
rangelim(damage_ratio * 5.0f, 1.0f, 4.0f);
25792583
}
25802584

25812585
// Play damage sound

0 commit comments

Comments
 (0)
Please sign in to comment.