Skip to content
Draft
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
28 changes: 26 additions & 2 deletions Coroner/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class API
/// You can set this to a default one (see `Coroner.AdvancedCauseOfDeath`) or a custom one (see `Register()`).
/// </summary>
/// <param name="player">The player to set the cause of death for.</param>
/// <param name="causeOfDeath">The cause of death to use. Set to `null` to clear.</param>
/// <param name="causeOfDeath">The cause of death to use.</param>
/// <example> SetCauseOfDeath(player, AdvancedCauseOfDeath.Enemy_ForestGiant); </example>
public static void SetCauseOfDeath(PlayerControllerB player, AdvancedCauseOfDeath? causeOfDeath)
{
Expand All @@ -25,7 +25,7 @@ public static void SetCauseOfDeath(PlayerControllerB player, AdvancedCauseOfDeat
/// You can set this to a default one (see `Coroner.AdvancedCauseOfDeath`) or a custom one (see `Register()`).
/// </summary>
/// <param name="playerId">The ID of the player.</param>
/// <param name="causeOfDeath">The cause of death to use. Set to `null` to clear.</param>
/// <param name="causeOfDeath">The cause of death to use.</param>
/// <example> SetCauseOfDeath(0, AdvancedCauseOfDeath.Enemy_ForestGiant); </example>
public static void SetCauseOfDeath(int playerId, AdvancedCauseOfDeath? causeOfDeath)
{
Expand Down Expand Up @@ -56,6 +56,30 @@ public static void SetCauseOfDeath(int playerId, AdvancedCauseOfDeath? causeOfDe
// Call the proper internal method.
return AdvancedDeathTracker.GetCauseOfDeath(playerId);
}

/// <summary>
/// Resets the cause of death to null for a player object.
/// </summary>
/// <param name="player">The player to set the cause of death for.</param>
/// <returns>The cause of death for the player.</returns>
/// <example> GetCauseOfDeath(0); </example>
public static void ResetCauseOfDeath(PlayerControllerB player)
{
// Call the proper internal method.
AdvancedDeathTracker.SetCauseOfDeath(player, null, true);
}

/// <summary>
/// Resets the cause of death to null for a player with the given ID.
/// </summary>
/// <param name="playerId">The ID of the player.</param>
/// <returns>The cause of death for the player.</returns>
/// <example> GetCauseOfDeath(0); </example>
public static void ResetCauseOfDeath(int playerId)
{
// Call the proper internal method.
AdvancedDeathTracker.SetCauseOfDeath(playerId, null, true);
}

/// <summary>
/// Register a new cause of death. Useful for mods.
Expand Down
5 changes: 5 additions & 0 deletions Coroner/NetworkRPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public static void ReportCauseOfDeathServerRpc(int playerClientId, string? codLa
[ClientRpc]
public static void BroadcastCauseOfDeathClientRpc(int playerClientId, string? codLanguageTag, bool forceOverride) {
Plugin.Instance.PluginLogger.LogDebug($"Client received cause of death via RPC: ({playerClientId}, {(codLanguageTag == null ? "null" : codLanguageTag)})");
if (codLanguageTag == null && !forceOverride)
{
Plugin.Instance.PluginLogger.LogDebug("Resetting cause of death.");
AdvancedDeathTracker.StoreLocalCauseOfDeath(playerClientId,null, forceOverride);
}

if (codLanguageTag == null || !AdvancedCauseOfDeath.IsTagRegistered(codLanguageTag)) {
Plugin.Instance.PluginLogger.LogError($"Could not deserialize cause of death ({codLanguageTag})");
Expand Down
10 changes: 8 additions & 2 deletions MODDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,17 @@ In `BepInEx/config/EliteMasterEric-Coroner/` in your mod upload, create a file n
- Retrieves the currently known cause of death for the player by reference, if any.
- Returns: An `AdvancedCauseOfDeath`, or `null` if no cause of death is known.
- `Coroner.API.SetCauseOfDeath(PlayerControllerB player, AdvancedCauseOfDeath? causeOfDeath)`
- Applies a given cause of death to the player by their client ID.
- Applies a given cause of death to the player by reference.
- Provide the `AdvancedCauseOfDeath` via argument. `AdvancedCauseOfDeath` has static constants for all the vanilla causes of death, or you can use one created by `Coroner.API.Register()`.
- `Coroner.API.SetCauseOfDeath(int playerId, AdvancedCauseOfDeath? causeOfDeath)`
- Applies a given cause of death to the player by reference.
- Applies a given cause of death to the player by their client ID.
- Provide the `AdvancedCauseOfDeath` via argument. `AdvancedCauseOfDeath` has static constants for all the vanilla causes of death, or you can use one created by `Coroner.API.Register()`.
- `Coroner.API.ResetCauseOfDeath(PlayerControllerB player)`
- Resets the cause of death of the player by reference.
- Sets the cause of death to null.
- `Coroner.API.ResetCauseOfDeath(int playerId)`
- Resets the cause of death of the player by their client ID.
- Sets the cause of death to null.
- `Coroner.API.StringifyCauseOfDeath(AdvancedCauseOfDeath causeOfDeath, Random? random)`
- Translate a cause of death to the user's current language.
- Pass this the result of `Coroner.API.GetCauseOfDeath()` for best results.
Expand Down