Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kill characters before removing them with status effects #15280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Barotrauma/BarotraumaClient/ClientSource/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ partial void OnAttackedProjSpecific(Character attacker, AttackResult attackResul
}
}

partial void KillProjSpecific(CauseOfDeathType causeOfDeath, Affliction causeOfDeathAffliction, bool log)
partial void KillProjSpecific(CauseOfDeathType causeOfDeath, Affliction causeOfDeathAffliction, bool log, bool triggerDeathEffects)
{
HintManager.OnCharacterKilled(this);

Expand All @@ -564,7 +564,10 @@ partial void KillProjSpecific(CauseOfDeathType causeOfDeath, Affliction causeOfD

RespawnManager.ShowDeathPromptIfNeeded();

GameMain.NetworkMember.AddChatMessage(chatMessage.Value, ChatMessageType.Dead);
if (triggerDeathEffects)
{
GameMain.NetworkMember.AddChatMessage(chatMessage.Value, ChatMessageType.Dead);
}
GameMain.LightManager.LosEnabled = false;
controlled = null;
if (Screen.Selected?.Cam is Camera cam)
Expand All @@ -577,7 +580,10 @@ partial void KillProjSpecific(CauseOfDeathType causeOfDeath, Affliction causeOfD
}
}

PlaySound(CharacterSound.SoundType.Die);
if (triggerDeathEffects)
{
PlaySound(CharacterSound.SoundType.Die);
}
}

partial void DisposeProjSpecific()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ public static Character ReadSpawnData(IReadMessage inc)

private void ReadStatus(IReadMessage msg)
{
TriggerDeathEffects = msg.ReadBoolean();
bool isDead = msg.ReadBoolean();
if (isDead)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ partial void OnAttackedProjSpecific(Character attacker, AttackResult attackResul
GameMain.Server.KarmaManager.OnCharacterHealthChanged(this, attacker, attackResult.Damage, stun, attackResult.Afflictions);
}

partial void KillProjSpecific(CauseOfDeathType causeOfDeath, Affliction causeOfDeathAffliction, bool log)
partial void KillProjSpecific(CauseOfDeathType causeOfDeath, Affliction causeOfDeathAffliction, bool log, bool triggerDeathEffects)
{
if (log)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ public virtual void ServerEventWrite(IWriteMessage msg, Client c, NetEntityEvent
/// <param name="forceAfflictionData">Normally full affliction data is not written for dead characters, this can be used to force them to be written</param>
private void WriteStatus(IWriteMessage msg, bool forceAfflictionData = false)
{
msg.WriteBoolean(TriggerDeathEffects);
msg.WriteBoolean(IsDead);
if (IsDead)
{
Expand Down
12 changes: 9 additions & 3 deletions Barotrauma/BarotraumaShared/SharedSource/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,9 @@ public bool IsDead
}
}

// If set to false, the character won't trigger death status effects, death sounds or have death notifications show up in their chat when they die.
public bool TriggerDeathEffects { get; set; } = true;

public bool EnableDespawn { get; set; } = true;

public CauseOfDeath CauseOfDeath
Expand Down Expand Up @@ -5027,7 +5030,10 @@ public void Kill(CauseOfDeathType causeOfDeath, Affliction causeOfDeathAfflictio
//it's important that we set isDead before executing the status effects,
//otherwise a statuseffect might kill the character "again" and trigger a loop that crashes the game
isDead = true;
ApplyStatusEffects(ActionType.OnDeath, 1.0f);
if (TriggerDeathEffects)
{
ApplyStatusEffects(ActionType.OnDeath, 1.0f);
}

#if CLIENT
// Keep permadeath status in sync (to show it correctly in the UI, the server takes care of the actual logic)
Expand Down Expand Up @@ -5095,7 +5101,7 @@ static string GetCharacterType(Character character)
AchievementManager.OnCharacterKilled(this, CauseOfDeath);
}

KillProjSpecific(causeOfDeath, causeOfDeathAffliction, log);
KillProjSpecific(causeOfDeath, causeOfDeathAffliction, log, TriggerDeathEffects);

if (info != null)
{
Expand Down Expand Up @@ -5132,7 +5138,7 @@ static string GetCharacterType(Character character)
}
GameMain.GameSession?.KillCharacter(this);
}
partial void KillProjSpecific(CauseOfDeathType causeOfDeath, Affliction causeOfDeathAffliction, bool log);
partial void KillProjSpecific(CauseOfDeathType causeOfDeath, Affliction causeOfDeathAffliction, bool log, bool triggerDeathEffects);

public void Revive(bool removeAfflictions = true, bool createNetworkEvent = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,7 @@ entity is Item item &&
}
#endif
}
if (characterSpawnInfo.RemovePreviousCharacter) { Entity.Spawner?.AddEntityToRemoveQueue(character); }
if (characterSpawnInfo.RemovePreviousCharacter) { character.TriggerDeathEffects = false; character.Kill(CauseOfDeathType.Unknown, null); Entity.Spawner?.AddEntityToRemoveQueue(character); }
}
}
if (characterSpawnInfo.InheritEventTags)
Expand Down Expand Up @@ -2305,6 +2305,8 @@ void OnItemContainerSpawned(Item item)
}
}
}
character.TriggerDeathEffects = false;
character.Kill(CauseOfDeathType.Unknown, null);
Entity.Spawner?.AddEntityToRemoveQueue(character);
}

Expand Down