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

@ -56,6 +56,19 @@ namespace RacesOfValheim
public static ConfigEntry<bool> PierceWeaknessEnabled;
public static ConfigEntry<float> PierceWeakness;
// ─── Running Water ─────────────────────────────────────────────────────
// Lore says a vampire cannot cross running water unaided (Dagaz's report). Swimming costs
// more, and the open sea burns, swimming or flying; standing on a boat is being carried,
// which the lore allows. The camera sway is a per-player comfort choice and stays local
// (ConfigSync's "camera sway" key part).
public static ConfigEntry<bool> RunningWaterEnabled;
public static ConfigEntry<float> SwimStaminaMultiplier;
public static ConfigEntry<float> SeaHealthLossPerSecond;
public static ConfigEntry<float> SeaStaminaDrainPerSecond;
public static ConfigEntry<float> SeaHealthFloor;
public static ConfigEntry<bool> SeaCameraSway;
public static ConfigEntry<float> SeaCameraSwayStrength;
// ─── Bat Form ────────────────────────────────────────────────────────────
// The bat flies on the same directed flight as the Skadi's drakes (DirectedFlight.cs),
// with its own numbers. It used to fly on vanilla's debug-fly flag: 50 m/s, free, blind
@ -207,6 +220,22 @@ namespace RacesOfValheim
PierceWeakness = config.Bind(weak, "Pierce Weakness Amount", 0.2f,
new ConfigDescription("Extra pierce damage taken. 0.2 = 20% more.", new AcceptableValueRange<float>(0f, 2f)));
const string water = "Aswid - Running Water";
RunningWaterEnabled = config.Bind(water, "Running Water", true,
new ConfigDescription("Swimming costs more stamina, and the open sea (the Ocean biome, over deep water) hurts you while you swim or fly over it. Standing on or steering a boat protects you.", null));
SwimStaminaMultiplier = config.Bind(water, "Swim Stamina Multiplier", 2f,
new ConfigDescription("Multiplies the stamina swimming costs, anywhere. At 0 stamina the game's own drowning starts. Around 5 and up, swimming any distance is no longer possible.", new AcceptableValueRange<float>(1f, 10f)));
SeaHealthLossPerSecond = config.Bind(water, "Open Sea Health Loss Per Second", 1f,
new ConfigDescription("Health the open sea burns away each second.", new AcceptableValueRange<float>(0f, 20f)));
SeaStaminaDrainPerSecond = config.Bind(water, "Open Sea Stamina Drain Per Second", 2f,
new ConfigDescription("Stamina the open sea drains each second, on top of what swimming or flying costs.", new AcceptableValueRange<float>(0f, 30f)));
SeaHealthFloor = config.Bind(water, "Open Sea Health Floor", 0.1f,
new ConfigDescription("The sea's burn stops at this fraction of your max health. Drowning, once your stamina runs out, has no floor.", new AcceptableValueRange<float>(0f, 1f)));
SeaCameraSway = config.Bind(water, "Camera Sway", true,
new ConfigDescription("The camera rolls gently while the open sea is hurting you, as if seasick. Local: each player chooses for themselves.", null));
SeaCameraSwayStrength = config.Bind(water, "Camera Sway Strength", 1f,
new ConfigDescription("How far the camera rolls. 1 is about 4 degrees. Local.", new AcceptableValueRange<float>(0f, 3f)));
const string batform = "Aswid - Bat Form";
// Same controls as the Skadi's drake: aim with the camera, W beats forward, Shift
// sprints, S beats backwards, and letting go hovers briefly before gliding down.

View file

@ -874,6 +874,60 @@ namespace RacesOfValheim
{
if (__instance != Player.m_localPlayer || !AswidRace.IsAswid()) return;
v *= AswidConfig.StaminaCostMultiplier.Value;
if (Aswid_SwimCost_Patch.Swimming && AswidConfig.RunningWaterEnabled.Value)
{
v *= AswidConfig.SwimStaminaMultiplier.Value;
}
}
}
/// <summary>
/// Marks the frames where vanilla charges for a swim stroke, so Aswid_UseStamina_Patch can
/// make that one cost dearer. Player.OnSwimming is the only place swimming spends stamina,
/// and it also runs the drowning check right after - which is what makes a high multiplier
/// play as "cannot swim" without any code of ours deciding who drowns.
/// </summary>
[HarmonyPatch(typeof(Player), "OnSwimming")]
public static class Aswid_SwimCost_Patch
{
public static bool Swimming { get; private set; }
public static void Prefix(Player __instance)
{
Swimming = __instance == Player.m_localPlayer;
}
public static void Finalizer()
{
Swimming = false;
}
}
/// <summary>
/// The seasick camera: a slow roll while the open sea is hurting the Aswid. Applied after
/// vanilla has settled the camera's rotation for the frame, as a roll around the view axis,
/// so it never moves where the player aims - only how the horizon sits.
/// </summary>
[HarmonyPatch(typeof(GameCamera), "GetCameraPosition")]
public static class Aswid_SeaCameraSway_Patch
{
private const float DegreesAtStrengthOne = 4f;
private static float sway;
public static void Postfix(float dt, ref Quaternion rot)
{
bool on = AswidRace.AtSea && AswidConfig.SeaCameraSway.Value && AswidRace.IsAswid() &&
Player.m_localPlayer != null && !Player.m_localPlayer.IsDead();
// Eased in and out over about a second, so leaving the sea does not snap the horizon.
sway = Mathf.MoveTowards(sway, on ? 1f : 0f, dt);
if (sway <= 0f) return;
float t = Time.time;
float roll = (Mathf.Sin(t * 0.9f) + 0.4f * Mathf.Sin(t * 2.3f)) * DegreesAtStrengthOne *
AswidConfig.SeaCameraSwayStrength.Value * sway;
rot *= Quaternion.AngleAxis(roll, Vector3.forward);
}
}

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

View file

@ -89,6 +89,21 @@ namespace RacesOfValheim
}
}
/// <summary>
/// The open sea under an Aswid. Only a marker: the burn and the drain are applied by
/// AswidRace.UpdateOpenSea, and the camera sway reads AswidRace.AtSea.
/// </summary>
public class SE_AswidOpenSea : SE_Stats
{
public override void Setup(Character character)
{
base.Setup(character);
name = "SE_AswidOpenSea";
m_name = "$rov_se_aswid_opensea_name";
m_tooltip = "$rov_se_aswid_opensea_tooltip";
}
}
public class SE_MistForm : SE_Stats
{
public override void Setup(Character character)
@ -153,6 +168,11 @@ namespace RacesOfValheim
sunlight.m_icon = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophySurtling")?.m_itemData.m_shared.m_icons[0];
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(sunlight, fixReference: false));
var openSea = ScriptableObject.CreateInstance<SE_AswidOpenSea>();
openSea.name = "SE_AswidOpenSea";
openSea.m_icon = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophySerpent")?.m_itemData.m_shared.m_icons[0];
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(openSea, fixReference: false));
var mistForm = ScriptableObject.CreateInstance<SE_MistForm>();
mistForm.name = "SE_MistForm";
mistForm.m_icon = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyWraith")?.m_itemData.m_shared.m_icons[0];