feat(aswid): running water weakness and a seasick camera

Swimming costs double stamina, scaled on vanilla's own swim charge so
its drowning check does the rest at high settings. Over deep water in
the Ocean, swimming or flying, the Aswid loses health and stamina each
second; a boat protects. A gentle camera roll plays while the sea hurts,
kept local through ConfigSync so a server cannot force it on anyone.
This commit is contained in:
kanym 2026-10-26 15:26:25 +01:00
commit 5c41d80cae
14 changed files with 173 additions and 3 deletions

View file

@ -509,6 +509,7 @@ namespace RacesOfValheim
updateTimer = 0f;
UpdateAswidState();
UpdateSunlight(UpdateInterval);
UpdateOpenSea(UpdateInterval);
}
try
@ -1508,6 +1509,56 @@ namespace RacesOfValheim
return biome != Heightmap.Biome.Swamp && biome != Heightmap.Biome.Mistlands;
}
private static readonly int OpenSeaHash = "SE_AswidOpenSea".GetStableHashCode();
/// <summary>True while the open sea is hurting the local Aswid. Read by the camera sway.</summary>
public static bool AtSea { get; private set; }
/// <summary>
/// Dagaz's running water: the Ocean biome burns and drains an Aswid in it or over it,
/// swimming or flying - a bat cannot simply cross the sea. A boat carries you across, as
/// the lore allows, so standing on one, steering one or sitting in one protects you.
/// </summary>
private void UpdateOpenSea(float dt)
{
Player player = Player.m_localPlayer;
SEMan seman = player.GetSEMan();
AtSea = OnOpenSea(player);
bool has = seman.HaveStatusEffect(OpenSeaHash);
if (!AtSea)
{
if (has) seman.RemoveStatusEffect(OpenSeaHash, true);
return;
}
if (!has) seman.AddStatusEffect(OpenSeaHash, true);
float drain = AswidConfig.SeaStaminaDrainPerSecond.Value * dt;
if (drain > 0f) player.UseStamina(drain);
// SetHealth for the same reasons as the sun: no stagger, no flash each second.
float floor = player.GetMaxHealth() * AswidConfig.SeaHealthFloor.Value;
float health = player.GetHealth();
float loss = AswidConfig.SeaHealthLossPerSecond.Value * dt;
if (loss > 0f && health > floor)
{
player.SetHealth(Mathf.Max(floor, health - loss));
}
}
private static bool OnOpenSea(Player player)
{
if (!AswidConfig.RunningWaterEnabled.Value) return false;
if (player.GetCurrentBiome() != Heightmap.Biome.Ocean) return false;
if (player.GetStandingOnShip() != null || player.IsAttachedToShip() || player.GetControlledShip() != null) return false;
// The Ocean biome reaches up the beaches, so being in it is not enough: the seabed
// under you has to be below the water. A shore walk stays dry; a swim or a flight
// out past the shallows does not.
if (ZoneSystem.instance == null) return false;
return ZoneSystem.instance.GetGroundHeight(player.transform.position) < ZoneSystem.instance.m_waterLevel;
}
private void UpdateAswidState()
{
AswidSpectralClaw.PurgeAll(Player.m_localPlayer); // feature disabled for now, see AswidSpectralClaw.cs