fix(skeleton): Auto-Resurrect on the real deathblow; Summon on Kill toggle
Auto-Resurrect was decided in the Character.Damage prefix on the raw hit: before armour, blocking and resistances, with poison and fire counted in full. With good armour it fired on almost any hit. Damage also runs on the attacker's owner, so on a dedicated server a mob owned by the server or another player skipped the check entirely. It now runs in an ApplyDamage prefix, on the victim's own client, against the damage that is about to land. The rising-from-the-ground immunity is checked there too. Summon on Kill gets a toggle key (G, Skeleton - Keybinds) and a gamepad radial entry. The choice is saved on the character, on by default. A "Raise the Dead" status icon with the Dead Raiser's picture shows while it is on. Texts in English, Italian and Russian.
This commit is contained in:
parent
7411680553
commit
53f6fb71a2
10 changed files with 158 additions and 35 deletions
|
|
@ -597,6 +597,58 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Auto-Resurrect, decided on the hit that would actually kill.
|
||||
///
|
||||
/// It used to be decided in the Character.Damage prefix below, on hit.GetTotalDamage(),
|
||||
/// and that number is the raw hit: before armour, blocking and resistances, and with the
|
||||
/// hit's poison and fire counted in full although vanilla splits those off and lands them
|
||||
/// over time. Any hit whose raw size beat the current health raised the Skeleton, so with
|
||||
/// good armour it fired on "just about any damage" (akira's report). Damage also runs on
|
||||
/// whoever owns the attacker, so on a dedicated server a mob owned by the server or by
|
||||
/// another player never reached this check at all, and a real deathblow went through.
|
||||
///
|
||||
/// ApplyDamage is what RPC_Damage calls on the victim's owner, after armour, blocking and
|
||||
/// resistances, with poison, fire and spirit already moved out into their status effects.
|
||||
/// Those effects come back through here on each tick, so a lethal tick still counts. The
|
||||
/// one scaling left inside ApplyDamage for a player is the damage-taken rate.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Character), nameof(Character.ApplyDamage))]
|
||||
public static class Skeleton_ApplyDamage_Patch
|
||||
{
|
||||
private static readonly int CooldownHash = "SE_SkeletonResurrectCooldown".GetStableHashCode();
|
||||
|
||||
public static bool Prefix(Character __instance, HitData hit)
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null || __instance != player) return true;
|
||||
|
||||
// Here as well as in the Damage prefix, which only sees hits thrown from this client.
|
||||
if (SkeletonRise.IsRising(player)) return false;
|
||||
|
||||
if (!SkeletonRace.IsSkeleton() || player.IsDead()) return true;
|
||||
if (!SkeletonProgression.GetRules(BossProgressionManager.GetCurrentProgressionState()).AutoResurrect) return true;
|
||||
|
||||
float damage = hit.GetTotalDamage() * Game.m_localDamgeTakenRate;
|
||||
if (damage < player.GetHealth()) return true;
|
||||
if (player.GetSEMan().HaveStatusEffect(CooldownHash)) return true;
|
||||
|
||||
player.Heal(player.GetMaxHealth(), true);
|
||||
player.GetSEMan().AddStatusEffect(CooldownHash, true);
|
||||
|
||||
// Confirmed real via 'listprefabs'; see SummonOnKill below.
|
||||
GameObject vfx = PrefabManager.Cache.GetPrefab<GameObject>("fx_summon_skeleton_spawn") ??
|
||||
PrefabManager.Cache.GetPrefab<GameObject>("fx_summon_skeleton");
|
||||
if (vfx != null) UnityEngine.Object.Instantiate(vfx, player.transform.position, Quaternion.identity);
|
||||
|
||||
// The body climbs out of the ground the way a crypt skeleton does.
|
||||
SkeletonRise.Begin(player);
|
||||
|
||||
player.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_skeleton_have_been_resurrected_by_dark"));
|
||||
return false; // the lethal hit never lands
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Character), "Damage")]
|
||||
public static class Character_Damage_Patch
|
||||
{
|
||||
|
|
@ -624,34 +676,8 @@ namespace RacesOfValheim
|
|||
// Half in the ground: nothing lands on a Skeleton while it climbs back out.
|
||||
if (__instance == Player.m_localPlayer && SkeletonRise.IsRising(Player.m_localPlayer)) return false;
|
||||
|
||||
// Auto-Resurrect check
|
||||
if (__instance == Player.m_localPlayer && SkeletonRace.IsSkeleton() && rules.AutoResurrect)
|
||||
{
|
||||
if (hit.GetTotalDamage() >= __instance.GetHealth())
|
||||
{
|
||||
if (!Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_SkeletonResurrectCooldown".GetStableHashCode()))
|
||||
{
|
||||
// Cancel death!
|
||||
Player.m_localPlayer.Heal(Player.m_localPlayer.GetMaxHealth(), true);
|
||||
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_SkeletonResurrectCooldown".GetStableHashCode(), true);
|
||||
|
||||
// Spawn VFX - confirmed real via 'listprefabs'; see SummonOnKill below
|
||||
// for how the previous two guesses here were caught and replaced.
|
||||
GameObject vfx = PrefabManager.Cache.GetPrefab<GameObject>("fx_summon_skeleton_spawn") ??
|
||||
PrefabManager.Cache.GetPrefab<GameObject>("fx_summon_skeleton");
|
||||
if (vfx != null)
|
||||
{
|
||||
UnityEngine.Object.Instantiate(vfx, Player.m_localPlayer.transform.position, Quaternion.identity);
|
||||
}
|
||||
|
||||
// The body climbs out of the ground the way a crypt skeleton does.
|
||||
SkeletonRise.Begin(Player.m_localPlayer);
|
||||
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_skeleton_have_been_resurrected_by_dark"));
|
||||
return false; // Skip applying this lethal damage
|
||||
}
|
||||
}
|
||||
}
|
||||
// The Auto-Resurrect check used to live here and is now in
|
||||
// Skeleton_ApplyDamage_Patch below; see there for why.
|
||||
|
||||
// Outgoing damage (Lifesteal, Poison, Stun)
|
||||
Character attacker = hit.GetAttacker();
|
||||
|
|
@ -740,7 +766,7 @@ namespace RacesOfValheim
|
|||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
var rules = SkeletonProgression.GetRules(state);
|
||||
|
||||
if (rules.SummonOnKill && !string.IsNullOrEmpty(rules.SummonPrefab))
|
||||
if (rules.SummonOnKill && SkeletonRace.SummonOnKillEnabled && !string.IsNullOrEmpty(rules.SummonPrefab))
|
||||
{
|
||||
// Clean up dead minions
|
||||
activeMinions.RemoveAll(m => m == null || m.IsDead());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue