fix(aswid): make the Vampiric Aura land, and run it passively in every form

The aura dealt its damage through Character.ApplyDamage, which only edits
the local copy of a character. On anything we do not own - in multiplayer
that is most mobs - the owner overwrote the health change on the next sync,
so the aura neither hurt anything nor showed anything. It also bypassed our
own Character.Damage patches, which is why it never healed and never
triggered devour-on-kill despite being the *vampiric* aura. It now calls
Character.Damage, which routes RPC_Damage to whoever owns the target, and
sets m_dir so the target reacts to the hit.

The aura no longer has to be channelled by holding block in bat or mist
form. It ticks on its own in every form, with no key to hold and no icon or
message of its own; the form only decides how hard it bites - half damage
as a human, full as a bat, double as mist.

Also guarded the sunrise mist auto-revert with isTransformingSequence.
Without it the revert re-triggered on every frame of its own one-second
animation, stacking coroutines that fought over the same visuals and status
effect.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Ferdinando 2026-08-04 11:04:41 +02:00
commit a29b7e54b4

View file

@ -170,9 +170,6 @@ namespace RacesOfValheim
} }
} }
public bool IsChanneling { get; private set; } = false;
private float channelDamageTimer = 0f;
private float m_tintCheckTimer = 0f; private float m_tintCheckTimer = 0f;
private float sensesCheckTimer = 0f; private float sensesCheckTimer = 0f;
@ -306,7 +303,7 @@ namespace RacesOfValheim
{ {
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead() || !IsAswid()) if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead() || !IsAswid())
{ {
if (IsChanneling) StopChanneling(); damageTickTimer = 0f;
wasNight = null; // reset so it triggers correctly on spawn/respawn wasNight = null; // reset so it triggers correctly on spawn/respawn
if (Player.m_localPlayer != null) AswidSpectralClaw.PurgeAll(Player.m_localPlayer); // feature disabled for now, see AswidSpectralClaw.cs if (Player.m_localPlayer != null) AswidSpectralClaw.PurgeAll(Player.m_localPlayer); // feature disabled for now, see AswidSpectralClaw.cs
return; return;
@ -357,11 +354,11 @@ namespace RacesOfValheim
try try
{ {
HandleChanneling(); HandleVampiricAura();
} }
catch (Exception ex) catch (Exception ex)
{ {
Jotunn.Logger.LogError($"[Aswid] Error in HandleChanneling: {ex}"); Jotunn.Logger.LogError($"[Aswid] Error in HandleVampiricAura: {ex}");
} }
if (isTransformingSequence) return; if (isTransformingSequence) return;
@ -396,8 +393,11 @@ namespace RacesOfValheim
} }
} }
// Auto revert mist form at sunrise // Auto revert mist form at sunrise. The isTransformingSequence guard matters: without it
if (EnvMan.instance != null && EnvMan.IsDay() && Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_MistForm".GetStableHashCode())) // this fires again on every frame of the one-second revert, stacking a new coroutine each
// time, and they all fight over the same visuals and status effect.
if (EnvMan.instance != null && EnvMan.IsDay() && !isTransformingSequence &&
Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_MistForm".GetStableHashCode()))
{ {
StartCoroutine(RevertMistFormRoutine()); StartCoroutine(RevertMistFormRoutine());
} }
@ -816,57 +816,27 @@ namespace RacesOfValheim
private float damageTickTimer = 0f; private float damageTickTimer = 0f;
private void StopChanneling() /// <summary>
/// The Vampiric Aura is passive: it drains on its own, in every form, with no key to hold and
/// no icon or message of its own. The form only decides how hard it bites.
/// </summary>
private void HandleVampiricAura()
{ {
if (!IsChanneling) return;
IsChanneling = false;
channelDamageTimer = 0f;
damageTickTimer = 0f;
}
private void HandleChanneling()
{
bool hasMistForm = Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_MistForm".GetStableHashCode());
bool hasBatForm = Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_BatForm".GetStableHashCode());
if (Player.m_localPlayer.IsBlocking() && (hasMistForm || hasBatForm))
{
if (!IsChanneling)
{
IsChanneling = true;
if (mistTransformation != null)
{
var anim = mistTransformation.GetComponentInChildren<Animator>();
if (anim != null) anim.SetBool("alert", true);
}
}
channelDamageTimer += Time.deltaTime;
damageTickTimer += Time.deltaTime; damageTickTimer += Time.deltaTime;
if (damageTickTimer < 0.25f) return;
if (channelDamageTimer >= 0.25f)
{
channelDamageTimer = 0f;
}
if (damageTickTimer >= 0.25f)
{
damageTickTimer = 0f; damageTickTimer = 0f;
PerformLifeDrain(); PerformLifeDrain();
} }
}
else /// <summary>Half damage as a human, full as a bat, double as mist.</summary>
private float GetAuraFormMultiplier()
{ {
if (IsChanneling) SEMan seman = Player.m_localPlayer.GetSEMan();
{
StopChanneling(); if (seman.HaveStatusEffect("SE_MistForm".GetStableHashCode())) return 2f;
if (mistTransformation != null) if (seman.HaveStatusEffect("SE_BatForm".GetStableHashCode())) return 1f;
{ return 0.5f;
var anim = mistTransformation.GetComponentInChildren<Animator>();
if (anim != null) anim.SetBool("alert", false);
}
}
}
} }
private void PerformLifeDrain() private void PerformLifeDrain()
@ -882,8 +852,6 @@ namespace RacesOfValheim
int layerMask = LayerMask.GetMask("character", "character_net", "character_ghost"); int layerMask = LayerMask.GetMask("character", "character_net", "character_ghost");
var colliders = Physics.OverlapSphere(center, radius, layerMask); var colliders = Physics.OverlapSphere(center, radius, layerMask);
bool hitAnything = false;
foreach (var col in colliders) foreach (var col in colliders)
{ {
Character c = col.GetComponentInParent<Character>(); Character c = col.GetComponentInParent<Character>();
@ -894,19 +862,13 @@ namespace RacesOfValheim
continue; continue;
} }
hitAnything = true;
float maxHp = c.GetMaxHealth(); float maxHp = c.GetMaxHealth();
float currentHp = c.GetHealth(); float currentHp = c.GetHealth();
float baseDamage = 1.0f; float baseDamage = 1.0f;
float bloodMagicFactor = Player.m_localPlayer.GetSkillFactor(Skills.SkillType.BloodMagic); float bloodMagicFactor = Player.m_localPlayer.GetSkillFactor(Skills.SkillType.BloodMagic);
// Lo scaling aggiunge un massimo di +5.0 danni (al livello 100), indipendentemente dal danno base // Lo scaling aggiunge un massimo di +5.0 danni (al livello 100), indipendentemente dal danno base
float totalDamage = baseDamage + bloodMagicFactor * 5f; float totalDamage = (baseDamage + bloodMagicFactor * 5f) * GetAuraFormMultiplier();
if (Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_MistForm".GetStableHashCode()))
{
totalDamage *= 2.0f; // Damage doubled in Mist Form
}
if (currentHp > 0 && currentHp <= maxHp * 0.20f && !c.IsBoss()) if (currentHp > 0 && currentHp <= maxHp * 0.20f && !c.IsBoss())
{ {
@ -917,8 +879,14 @@ namespace RacesOfValheim
HitData hd = new HitData(); HitData hd = new HitData();
hd.m_damage.m_damage = totalDamage; hd.m_damage.m_damage = totalDamage;
hd.m_point = c.GetCenterPoint(); hd.m_point = c.GetCenterPoint();
hd.m_dir = (c.GetCenterPoint() - center).normalized;
hd.m_attacker = Player.m_localPlayer.GetZDOID(); hd.m_attacker = Player.m_localPlayer.GetZDOID();
c.ApplyDamage(hd, true, false);
// Damage() sends RPC_Damage to whoever owns the target, so the hit lands for
// everyone and still runs our Character.Damage patches (lifesteal, devour on
// kill). ApplyDamage() skipped all of that: it edited the local copy of a
// character we usually do not own, and the owner overwrote it on the next sync.
c.Damage(hd);
SpawnBloodVFX(c); SpawnBloodVFX(c);
} }