- Entity.Target is one slot of TargetRef, read-only from outside (IReadOnlyReactiveProperty); Entity.SetTarget is its one writer. A chunk is taken only while the entity can see it, so a rock in darkness cannot be picked. Every handler, agent, turret and test writes through SetTarget. - Entity.ChunkInfo (Q14 A): the value the per-tick sensor rule settles at, computed on demand through Sensor.PassiveRate/Sensor.Gain -- sum of the active sensors' passive rates over (sensors x TargetInfoDecay), capped at 1. Stored nowhere; no per-tick loop over chunks. ChunkVisible is the detection threshold through the chunk path. - The lost-track rule reads through the chunk path: Activate's reconciliation and a per-tick check of the one slot drop a chunk target that has gone dark. - Entity.VisibleChunksInReach (Q13 A): visible chunks within the longest range among active weapons -- the one reach rule for cycling and programmatic picks. - Entity-only readers take .Entity: TargetedBy/TargetedByCount, target items, the stance gate (a chunk has no stance), lock (Q12 A: never on a chunk), turrets, Combat, Minion, FireControl (a chunk fires untargeted until Cut 4). TargetRange and the arc gate read a chunk's planar position. - ActionGameManager: the reticle and next/previous offer visible ships and visible chunks in reach; nearest stays enemies-only; the target panel, indicator and fire-control debug take TargetRef. EntityInstance reads .Entity. - MiningCut3Tests pin parity, darkness, monotone brightness, wear and break, reach, the chunk query, target survival and loss, TargetRef equality, lock, and field-kind assignment at generation and first load. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
3.6 KiB
C#
109 lines
3.6 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();
|
|
|
|
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 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;
|
|
|
|
|
|
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.LookDirection))) * 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));
|
|
}
|
|
else _lock = saturate(_lock - dt * Decay);
|
|
}
|
|
|
|
return base.Execute(dt);
|
|
}
|
|
}
|
|
|