fix: Implement missing critical hit sound (#1141)

* Fix

* Crit Sound Now Plays On Death

* Revert BuildVer.h

---------

Co-authored-by: Loki <lokio.casebstv@gmail.com>
This commit is contained in:
Tyler Reese 2026-04-12 21:24:29 -07:00 committed by GitHub
parent 2d41711055
commit 78afb091a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 64 additions and 9 deletions

View file

@ -223,6 +223,8 @@ const WCHAR *ConsoleSoundEngine::wchSoundNames[eSoundType_MAX]=
// 4J-PB - Some sounds were updated, but we can't do that for the 360 or we have to do a new sound bank
// instead, we'll add the sounds as new ones and change the code to reference them
L"fire.new_ignite",
L"damage.critical", //eSoundType_DAMAGE_CRITICAL,
};

View file

@ -124,6 +124,7 @@ DamageSource::DamageSource(ChatPacket::EChatPacketMessage msgId, ChatPacket::ECh
_isProjectile = false;
_isMagic = false;
_isExplosion = false;
_isCritical = false;
//this->msgId = msgId;
m_msgId = msgId;
@ -153,7 +154,15 @@ DamageSource *DamageSource::bypassInvul()
_bypassInvul = true;
return this;
}
bool DamageSource::isCritical()
{
return _isCritical;
}
DamageSource *DamageSource::setIsCritical()
{
_isCritical = true;
return this;
}
DamageSource *DamageSource::setIsFire()
{
isFireSource = true;

View file

@ -47,8 +47,11 @@ private:
bool _scalesWithDifficulty;
bool _isMagic;
bool _isExplosion;
bool _isCritical;
public:
bool isCritical();
DamageSource *setIsCritical();
bool isProjectile();
DamageSource *setProjectile();
bool isExplosion();

View file

@ -5,6 +5,9 @@ class EntityEvent
public:
static const BYTE JUMP = 1;
static const BYTE HURT = 2;
//New
static const BYTE HURT_CRITICAL = 19;
static const BYTE DEATH_CRITICAL = 20;
static const BYTE DEATH = 3;
static const BYTE START_ATTACKING = 4;
static const BYTE STOP_ATTACKING = 5;

View file

@ -831,7 +831,12 @@ bool LivingEntity::hurt(DamageSource *source, float dmg)
if (sound)
{
level->broadcastEntityEvent(shared_from_this(), EntityEvent::HURT);
if (source->isCritical()) {
level->broadcastEntityEvent(shared_from_this(), EntityEvent::HURT_CRITICAL);
}
else {
level->broadcastEntityEvent(shared_from_this(), EntityEvent::HURT);
}
if (source != DamageSource::drown) markHurt();
if (sourceEntity != nullptr)
{
@ -854,12 +859,19 @@ bool LivingEntity::hurt(DamageSource *source, float dmg)
MemSect(31);
if (getHealth() <= 0)
{
if (sound) playSound(getDeathSound(), getSoundVolume(), getVoicePitch());
if (sound) {
//New: both death AND hurt sounds should play critical sound as well.
if (source->isCritical()) playSound(getCriticalSound(), getSoundVolume(), getVoicePitch());
playSound(getDeathSound(), getSoundVolume(), getVoicePitch());
};
die(source);
}
else
{
if (sound) playSound(getHurtSound(), getSoundVolume(), getVoicePitch());
if (sound) {
if (source->isCritical()) playSound(getCriticalSound(), getSoundVolume(), getVoicePitch());
playSound(getHurtSound(), getSoundVolume(), getVoicePitch());
}
}
MemSect(0);
@ -926,7 +938,11 @@ void LivingEntity::die(DamageSource *source)
}
}
level->broadcastEntityEvent(shared_from_this(), EntityEvent::DEATH);
if (source->isCritical()) {
level->broadcastEntityEvent(shared_from_this(), EntityEvent::DEATH_CRITICAL);
} else {
level->broadcastEntityEvent(shared_from_this(), EntityEvent::DEATH);
}
}
void LivingEntity::dropEquipment(bool byPlayer, int playerBonusLevel)
@ -959,7 +975,10 @@ int LivingEntity::getHurtSound()
{
return eSoundType_DAMAGE_HURT;
}
int LivingEntity::getCriticalSound()
{
return eSoundType_DAMAGE_CRITICAL;
}
int LivingEntity::getDeathSound()
{
return eSoundType_DAMAGE_HURT;
@ -1181,7 +1200,8 @@ void LivingEntity::swing()
void LivingEntity::handleEntityEvent(byte id)
{
if (id == EntityEvent::HURT)
//These gotta be in parentheses
if ((id == EntityEvent::HURT) || (id == EntityEvent::HURT_CRITICAL))
{
walkAnimSpeed = 1.5f;
@ -1191,19 +1211,30 @@ void LivingEntity::handleEntityEvent(byte id)
MemSect(31);
// 4J-PB -added because villagers have no sounds
int iHurtSound=getHurtSound();
int iHurtSound = getHurtSound();
int iCritSound = getCriticalSound();
if(iHurtSound!=-1)
{
playSound(iHurtSound, getSoundVolume(), (random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f);
}
if(iCritSound!=-1 && (id == EntityEvent::HURT_CRITICAL))
{
playSound(iCritSound, getSoundVolume(), (random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f);
}
MemSect(0);
hurt(DamageSource::genericSource, 0);
}
else if (id == EntityEvent::DEATH)
else if ((id == EntityEvent::DEATH) || (id == EntityEvent::DEATH_CRITICAL))
{
MemSect(31);
// 4J-PB -added because villagers have no sounds
int iDeathSound=getDeathSound();
int iCritSound = getCriticalSound();
if (iCritSound != -1 && (id == EntityEvent::DEATH_CRITICAL))
{
playSound(iCritSound, getSoundVolume(), (random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f);
}
if(iDeathSound!=-1)
{
playSound(iDeathSound, getSoundVolume(), (random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f);

View file

@ -185,6 +185,7 @@ public:
virtual void knockback(shared_ptr<Entity> source, float dmg, double xd, double zd);
protected:
virtual int getCriticalSound();
virtual int getHurtSound();
virtual int getDeathSound();

View file

@ -1631,6 +1631,10 @@ void Player::attack(shared_ptr<Entity> entity)
}
DamageSource *damageSource = DamageSource::playerAttack(dynamic_pointer_cast<Player>(shared_from_this()));
if (bCrit) {
damageSource->setIsCritical();
}
bool wasHurt = entity->hurt(damageSource, dmg);
delete damageSource;
if (wasHurt)

View file

@ -213,6 +213,8 @@ enum eSOUND_TYPE
eSoundType_FIRE_NEWIGNITE,
eSoundType_DAMAGE_CRITICAL,
eSoundType_MAX
};