fix(alfar): Skrid lands on the floor under its end, never on a roof; cancelled in a dungeon with no floor

This commit is contained in:
kanym 2026-11-11 18:43:42 +01:00
commit ffed6fd33e

View file

@ -182,35 +182,64 @@ namespace RacesOfValheim
Vector3 direction = aim.forward; Vector3 direction = aim.forward;
float distance = AlfarPowerConfig.SkridDistance.Value; float distance = AlfarPowerConfig.SkridDistance.Value;
if (!Pay(player, AlfarPowerConfig.SkridCost.Value)) return;
// Stop short of whatever is in the way, so the blink never ends inside a wall. // Stop short of whatever is in the way, so the blink never ends inside a wall.
Vector3 destination = origin + direction * distance; Vector3 destination = origin + direction * distance;
RaycastHit[] hits = Physics.RaycastAll(origin, direction, distance, ~0, QueryTriggerInteraction.Ignore); if (NearestHit(player, origin, direction, distance, out RaycastHit wall))
float nearest = float.MaxValue;
foreach (RaycastHit hit in hits)
{ {
if (hit.collider.GetComponentInParent<Player>() == player) continue; destination = wall.point - direction * 0.6f;
if (hit.distance < nearest) }
// Back down to the player's own height: the origin was at the chest. The floor is found
// with a short ray down from the landing point, never with GetSolidHeight: that one casts
// from 1000 m up, so under any roof (a crypt, a cave, a house) it returned the roof and
// put the Alfr on top of it. A flat 1 m drop also sank the feet under the floor when the
// blink was aimed at it.
const float FloorSearch = 3f;
if (NearestHit(player, destination, Vector3.down, FloorSearch, out RaycastHit floor))
{
destination.y = floor.point.y + 0.05f;
}
else if (player.InInterior())
{
// No floor under the landing point inside a dungeon: it would end in the void the
// dungeon floats in. Cancel before paying.
return;
}
else
{
destination.y -= 1.0f;
if (ZoneSystem.instance != null)
{ {
nearest = hit.distance; // Terrain only, so a roof overhead is never mistaken for the ground.
destination = hit.point - direction * 0.6f; float ground = ZoneSystem.instance.GetGroundHeight(destination);
if (destination.y < ground) destination.y = ground + 0.1f;
} }
} }
// Back down to the player's own height: the origin was at the chest. if (!Pay(player, AlfarPowerConfig.SkridCost.Value)) return;
destination.y -= 1.0f;
if (ZoneSystem.instance != null)
{
float ground = ZoneSystem.instance.GetSolidHeight(destination);
if (destination.y < ground) destination.y = ground + 0.1f;
}
Teleport(player, destination); Teleport(player, destination);
StartCooldown("skrid", AlfarPowerConfig.SkridCooldown.Value); StartCooldown("skrid", AlfarPowerConfig.SkridCooldown.Value);
AlfarFx.Spawn("fx_JotunWitch_LightningBolt_Explosion", origin); AlfarFx.Spawn("fx_JotunWitch_LightningBolt_Explosion", origin);
} }
/// <summary>The nearest solid hit along a ray, skipping the caster's own colliders.</summary>
private static bool NearestHit(Player player, Vector3 origin, Vector3 direction, float distance, out RaycastHit nearest)
{
nearest = default;
bool found = false;
foreach (RaycastHit hit in Physics.RaycastAll(origin, direction, distance, ~0, QueryTriggerInteraction.Ignore))
{
if (hit.collider.GetComponentInParent<Player>() == player) continue;
if (!found || hit.distance < nearest.distance)
{
nearest = hit;
found = true;
}
}
return found;
}
/// <summary> /// <summary>
/// Moves the body without the teleport fade: the rigidbody is repositioned and its velocity /// Moves the body without the teleport fade: the rigidbody is repositioned and its velocity
/// zeroed, and the fall tracker is reset so a blink up a cliff does not count as a fall. /// zeroed, and the fall tracker is reset so a blink up a cliff does not count as a fall.