Aetheria/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs
Meta Vens 9de7756006 Visibility 4b: a ping or a lock paint is an emission heard within its range over its intercept factor
Entity.Emit posts an ActiveEmission (item, range / InterceptFactor) from Sensor's sweep and LockWeapon's
Track paint; Sense hears every other ship's emissions within HearRange x HearingMultiple x obscuration
through RecordReveal, bearing only, feeding no track. SensorData key 13 and LockWeaponData key 34 carry
InterceptFactor (absent reads 1). Unverified at this commit: the headless suite has not run yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 01:56:50 +02:00

119 lines
4.2 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using MessagePack;
using Newtonsoft.Json;
using CultMath;
using static CultMath.math;
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class LockWeaponData : InstantWeaponData
{
[Inspectable, JsonProperty("speed"), Key(21), RuntimeInspectable]
public PerformanceStat LockSpeed = new PerformanceStat();
[Inspectable, JsonProperty("sensorImpact"), Key(22)]
public PerformanceStat SensorImpact = new PerformanceStat();
[Inspectable, JsonProperty("threshold"), Key(23), RuntimeInspectable]
public PerformanceStat LockAngle = new PerformanceStat();
[Inspectable, JsonProperty("directionImpact"), Key(24)]
public PerformanceStat DirectionImpact = new PerformanceStat();
[Inspectable, JsonProperty("decay"), Key(25)]
public PerformanceStat Decay = new PerformanceStat();
// The ratio of how far this lock sees to how far others hear it (ruling sensor-stat-set); a design without it
// reads as 1.
[Inspectable, JsonProperty("interceptFactor"), Key(34)]
public PerformanceStat InterceptFactor;
public override Behavior CreateInstance(EquippedItem item)
{
return new LockWeapon(this, item);
}
public override Behavior CreateInstance(ConsumableItemEffect item)
{
return new LockWeapon(this, item);
}
}
public class LockWeapon : InstantWeapon
{
private LockWeaponData _data;
private float _lock;
private bool _locking;
private Entity _target;
public event Action OnLocked;
public event Action OnBeginLocking;
public event Action OnLockLost;
public float LockSpeed { get; private set; }
public float SensorImpact { get; private set; }
public float LockAngle { get; private set; }
public float DirectionImpact { get; private set; }
public float Decay { get; private set; }
public float InterceptFactor => _data.InterceptFactor == null ? 1f : Evaluate(_data.InterceptFactor);
public override float Progress => saturate(_cooldown > 0 ? _cooldown : _lock);
public override bool CanFire => base.CanFire && _lock > .99f && Entity.TargetRange > MinRange && Entity.TargetRange < Range;
public float Lock
{
get => saturate(_lock);
}
// Cut 3 (docs/fire-control-cut.md): the same threshold CanFire above already gates firing on, exposed so
// FireControl.HitProbability can zero an unlocked LockWeapon's probability for AI/HUD decisions made
// before a shot is ever attempted.
public bool IsLocked => _lock > .99f;
// Q12 A: a launcher cannot mine.
public override bool CanMine => false;
public LockWeapon(LockWeaponData data, EquippedItem item) : base(data, item)
{
_data = data;
}
public LockWeapon(LockWeaponData data, ConsumableItemEffect item) : base(data, item)
{
_data = data;
}
public override bool Execute(float dt)
{
// Mining Cut 3 (Q12 A): lock builds on an entity only. A chunk target reads as no target here, so a
// launcher never locks a rock.
var target = Entity.Target.Value.Entity;
if (_target != target)
{
_lock = 0;
_target = target;
}
if (target != null && Entity.IsHostileTo(target))
{
LockSpeed = Evaluate(_data.LockSpeed);
SensorImpact = Evaluate(_data.SensorImpact);
LockAngle = Evaluate(_data.LockAngle);
DirectionImpact = Evaluate(_data.DirectionImpact);
Decay = Evaluate(_data.Decay);
var degrees = acos(dot(normalize(target.Position - Entity.Position), normalize(Entity.Aim))) * 57.2958f;
if (degrees < LockAngle)
{
var lerp = 1 - unlerp(0, 90, degrees);
_lock = saturate(_lock + pow(lerp, DirectionImpact) * dt * LockSpeed * pow(Entity.EntityInfoGathered[target], SensorImpact));
target.ReceivePaint(Entity, Item, PaintMode.Track, Lock);
Entity.Emit(Item, Range / InterceptFactor);
}
else _lock = saturate(_lock - dt * Decay);
}
return base.Execute(dt);
}
}