EW 2 fix: the enemy schematic's rows, claimed class and range label are derived in ServerShared
Entity.SchematicRows(subject) owns which weapon rows a schematic shows, each row's item and claimed design, and its range (own ship: live; any other: the claimed design's rated range). SchematicDisplay renders SchematicRow and decides nothing. Headless tests cover default-to-truth, a weapon claimed as another weapon, a weapon claimed as a non-weapon, own rows, and the rebuild key. Builds on the Shared side not yet verified at this commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
adb632fe3d
commit
90294e0fef
4 changed files with 147 additions and 29 deletions
|
|
@ -985,6 +985,15 @@ public abstract class Entity
|
|||
RevealsOf(subject).Where(r => r.Claimed != null && r.Claimed.Behaviors.Any(b => b is WeaponData))
|
||||
.OrderBy(r => subject.Equipment.IndexOf(r.Item));
|
||||
|
||||
// The weapon rows of `subject`'s schematic as this ship reads it: its own equipment when `subject` is this ship (each
|
||||
// row its own data and live range, nothing to doubt about your own ship), otherwise RevealedWeapons (each row the
|
||||
// claimed class and that design's rated range). The one owner of which rows, which class and which range an
|
||||
// enemy schematic shows; the Unity SchematicDisplay renders it.
|
||||
public IEnumerable<SchematicRow> SchematicRows(Entity subject) =>
|
||||
subject == this
|
||||
? subject.Equipment.Where(i => i.Behaviors.Any(b => b.Data is WeaponData)).Select(i => new SchematicRow(i, i.Data, true))
|
||||
: RevealedWeapons(subject).Select(r => new SchematicRow(r.Item, r.Claimed, false));
|
||||
|
||||
// Whether this observer's book for `subject` holds `item`: the book's membership, no live gear read.
|
||||
internal bool HasReveal(Entity subject, EquippedItem item) =>
|
||||
_reveals.TryGetValue(subject, out var book) && book.ContainsKey(item);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Linq;
|
||||
using CultMath;
|
||||
|
||||
// Light signatures split by channel (ruling visibility-per-capability-reveal): an observer learns what a ship
|
||||
|
|
@ -118,6 +119,32 @@ public readonly struct Reveal
|
|||
}
|
||||
}
|
||||
|
||||
// One weapon row of a ship's schematic as its viewer is entitled to read it (aetheria-ew, classify-from-belief; ruling
|
||||
// ew-claim-weapon-measure-ruled). Made only by Entity.SchematicRows. `Item` is the true item: the selection mark's key and,
|
||||
// on the viewer's own ship, the live gear. `Claimed` is the class the row shows. The range label is the live range on
|
||||
// the viewer's own ship and the claimed design's rated range on any other; the viewer never sees a target weapon's
|
||||
// quality, wear or power. A renderer shows these and decides nothing.
|
||||
public readonly struct SchematicRow
|
||||
{
|
||||
public readonly EquippedItem Item;
|
||||
public readonly EquippableItemData Claimed;
|
||||
private readonly bool _own;
|
||||
|
||||
internal SchematicRow(EquippedItem item, EquippableItemData claimed, bool own)
|
||||
{
|
||||
Item = item;
|
||||
Claimed = claimed;
|
||||
_own = own;
|
||||
}
|
||||
|
||||
// What a renderer compares to know the rows changed. Range is a reading, not part of the key.
|
||||
public (EquippedItem, EquippableItemData) Key => (Item, Claimed);
|
||||
|
||||
public float Range => _own
|
||||
? Item.Behaviors.OfType<Weapon>().First().Range
|
||||
: Claimed.Behaviors.OfType<WeaponData>().First().RatedRange;
|
||||
}
|
||||
|
||||
// A subject's removal from a zone as the zone recorded it (death, dock, warp, any removal): where it was and how
|
||||
// bright its light was (its Visibility at removal). Judged by each observer's Sense under the
|
||||
// light-act gate; notification only, one tick long, it decides nothing.
|
||||
|
|
|
|||
|
|
@ -58,10 +58,8 @@ public class SchematicDisplay : MonoBehaviour
|
|||
|
||||
public class SchematicDisplayItem
|
||||
{
|
||||
// The true item: the selection mark's key and, on the player's own ship, the live gear. Never classifies an enemy row.
|
||||
public EquippedItem Item;
|
||||
// The class the row shows: the claim the player's book holds for an enemy row, the item's own data on the player's ship.
|
||||
public EquippableItemData Claimed;
|
||||
// The row Entity.SchematicRows derived: which item, which class and which range it shows.
|
||||
public SchematicRow Row;
|
||||
public SchematicListElement ListElement;
|
||||
public IProgressBehavior Cooldown;
|
||||
// public ItemUsage ItemUsage;
|
||||
|
|
@ -99,16 +97,9 @@ public class SchematicDisplay : MonoBehaviour
|
|||
BuildRows(WeaponRows());
|
||||
}
|
||||
|
||||
private static bool IsWeapon(EquippedItem item) => item.Behaviors.Any(b => b.Data is WeaponData);
|
||||
|
||||
// An enemy schematic lists what `_player` believes the ship's weapons are: the weapon reveals of the player's book on
|
||||
// it (Entity.RevealedWeapons), in book order (ruling reveal-ends-on-perception), each shown as the class it claimed
|
||||
// (aetheria-ew, classify-from-belief), never the ship's live gear. The player's own schematic is its equipment, each
|
||||
// row its own data; there is nothing to doubt about your own ship.
|
||||
private IEnumerable<(EquippedItem Item, EquippableItemData Claimed)> WeaponRows() =>
|
||||
_enemy
|
||||
? _player.RevealedWeapons(_entity).Select(r => (r.Item, r.Claimed))
|
||||
: _entity.Equipment.Where(IsWeapon).Select(item => (item, item.Data));
|
||||
// Which rows, which class and which range label are Entity.SchematicRows' decision (aetheria-ew, classify-from-belief);
|
||||
// this display only renders them.
|
||||
private IEnumerable<SchematicRow> WeaponRows() => (_player ?? _entity).SchematicRows(_entity);
|
||||
|
||||
private void ReturnRows()
|
||||
{
|
||||
|
|
@ -118,13 +109,12 @@ public class SchematicDisplay : MonoBehaviour
|
|||
_schematicItems = null;
|
||||
}
|
||||
|
||||
private void BuildRows(IEnumerable<(EquippedItem Item, EquippableItemData Claimed)> rows)
|
||||
private void BuildRows(IEnumerable<SchematicRow> rows)
|
||||
{
|
||||
_schematicItems = rows
|
||||
.Select(x => new SchematicDisplayItem
|
||||
{
|
||||
Item = x.Item,
|
||||
Claimed = x.Claimed,
|
||||
Row = x,
|
||||
ListElement = ListElementPrototype.Instantiate<SchematicListElement>(),
|
||||
Cooldown = _enemy ? null : (IProgressBehavior) x.Item.Behaviors.FirstOrDefault(b=> b is IProgressBehavior),
|
||||
// ItemUsage = _enemy ? null : (ItemUsage) x.Behaviors.FirstOrDefault(b=> b is ItemUsage),
|
||||
|
|
@ -133,7 +123,7 @@ public class SchematicDisplay : MonoBehaviour
|
|||
.ToArray();
|
||||
foreach (var x in _schematicItems)
|
||||
{
|
||||
if(x.Claimed is WeaponItemData weaponItemData)
|
||||
if(x.Row.Claimed is WeaponItemData weaponItemData)
|
||||
x.ListElement.ShowWeapon(weaponItemData);
|
||||
//x.ListElement.Label.text = x.Item.EquippableItem.Name;
|
||||
if (!_enemy)
|
||||
|
|
@ -205,7 +195,7 @@ public class SchematicDisplay : MonoBehaviour
|
|||
|
||||
// A reveal gained or ended after selection changes the rows with no event to hook: rebuild when the
|
||||
// revealed weapon set differs from the rows' items.
|
||||
if (_enemy && !WeaponRows().SequenceEqual(_schematicItems.Select(x => (x.Item, x.Claimed))))
|
||||
if (_enemy && !WeaponRows().Select(r => r.Key).SequenceEqual(_schematicItems.Select(x => x.Row.Key)))
|
||||
{
|
||||
ReturnRows();
|
||||
BuildRows(WeaponRows());
|
||||
|
|
@ -216,7 +206,7 @@ public class SchematicDisplay : MonoBehaviour
|
|||
// as info decays, with no event to hook.
|
||||
if (_enemy && _schematicItems != null)
|
||||
foreach (var x in _schematicItems)
|
||||
x.ListElement.SetSelected(x.Item == _player.ResolvedTargetItem);
|
||||
x.ListElement.SetSelected(x.Row.Item == _player.ResolvedTargetItem);
|
||||
|
||||
if(VisibilityLabel && !_enemy)
|
||||
VisibilityLabel.text = ((int)_entity.Visibility).ToString();
|
||||
|
|
@ -234,11 +224,11 @@ public class SchematicDisplay : MonoBehaviour
|
|||
{
|
||||
if (!_enemy)
|
||||
{
|
||||
var itemData = _entity.ItemManager.GetData(x.Item.EquippableItem);
|
||||
x.ListElement.HeatFill.anchorMax = new Vector2(unlerp(itemData.MinimumTemperature, itemData.MaximumTemperature, x.Item.Temperature), 0);
|
||||
var itemData = _entity.ItemManager.GetData(x.Row.Item.EquippableItem);
|
||||
x.ListElement.HeatFill.anchorMax = new Vector2(unlerp(itemData.MinimumTemperature, itemData.MaximumTemperature, x.Row.Item.Temperature), 0);
|
||||
if (x.Cooldown != null)
|
||||
x.ListElement.CooldownFill.anchorMax = new Vector2(x.Cooldown.Progress, 1);
|
||||
x.ListElement.DurabilityLabel.text = $"{(int)(x.Item.EquippableItem.Durability / itemData.Durability * 100)}%";
|
||||
x.ListElement.DurabilityLabel.text = $"{(int)(x.Row.Item.EquippableItem.Durability / itemData.Durability * 100)}%";
|
||||
if (x.Weapon.WeaponData.AmmoType.IsSet())
|
||||
{
|
||||
if(x.Weapon.WeaponData.MagazineSize > 1)
|
||||
|
|
@ -248,13 +238,8 @@ public class SchematicDisplay : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
// The range label: the live range on the player's own ship, the claimed design's rated range on an enemy row
|
||||
// (ew-claim-weapon-measure-ruled; the observer never sees a target weapon's quality, wear or power).
|
||||
if (x.ListElement.RangeLabel)
|
||||
{
|
||||
var range = _enemy ? x.Claimed.Behaviors.OfType<WeaponData>().First().RatedRange : x.Weapon.Range;
|
||||
x.ListElement.RangeLabel.text = ((int) range).ToString();
|
||||
}
|
||||
x.ListElement.RangeLabel.text = ((int) x.Row.Range).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,4 +269,101 @@ public sealed partial class ContactRevealTests
|
|||
}
|
||||
}
|
||||
}
|
||||
// ---- The schematic's rows (ruling ew-claim-weapon-measure-ruled; finding schematic-unreached) ----
|
||||
|
||||
// The unclaimed enemy row is the true gun, with the gun's own rated range (Gun: 40). Mutation: the row's Item.Data or
|
||||
// the true live range stands in for the claim.
|
||||
[Fact]
|
||||
public void AnEnemySchematicRowDefaultsToTheTruth()
|
||||
{
|
||||
var e = Add(float3(30, 0, 40), new[] { "Gun" });
|
||||
var o = Add(float3(0, 0, 0), new[] { "Eye" });
|
||||
var gun = Guns(e)[0];
|
||||
Fire(e, gun);
|
||||
|
||||
var row = Assert.Single(o.SchematicRows(e));
|
||||
Assert.Same(gun, row.Item);
|
||||
Assert.Same(gun.Data, row.Claimed);
|
||||
Assert.Equal(40f, row.Range);
|
||||
}
|
||||
|
||||
// A weapon claimed as another weapon shows the claimed design's rated range (SpanGun: Range.Max 120), not the true
|
||||
// gun's 40. Mutation: Range reads the true item, or the claimed stat's Min (50), or scales the figure.
|
||||
[Fact]
|
||||
public void AWeaponClaimedAsAnotherWeaponShowsTheClaimedRatedRange()
|
||||
{
|
||||
var e = Add(float3(30, 0, 40), new[] { "Gun" });
|
||||
var o = Add(float3(0, 0, 0), new[] { "Eye" });
|
||||
var gun = Guns(e)[0];
|
||||
var other = DataOf("SpanGun");
|
||||
e.Claim(gun, other);
|
||||
Fire(e, gun);
|
||||
|
||||
var row = Assert.Single(o.SchematicRows(e));
|
||||
Assert.Same(gun, row.Item);
|
||||
Assert.Same(other, row.Claimed);
|
||||
Assert.Equal(120f, row.Range);
|
||||
}
|
||||
|
||||
// Mutation: the rows are the book's reveals (RevealsOf) or the subject's equipment.
|
||||
[Fact]
|
||||
public void AWeaponClaimedAsANonWeaponHasNoSchematicRow()
|
||||
{
|
||||
var e = Add(float3(30, 0, 40), new[] { "Gun" });
|
||||
var o = Add(float3(0, 0, 0), new[] { "Eye" });
|
||||
var gun = Guns(e)[0];
|
||||
e.Claim(gun, DataOf("Eye"));
|
||||
Fire(e, gun);
|
||||
|
||||
Assert.Empty(o.SchematicRows(e));
|
||||
Assert.Single(o.RevealsOf(e));
|
||||
}
|
||||
|
||||
// Unrevealed gear never appears on an enemy schematic: a ship that has not fired shows no row.
|
||||
[Fact]
|
||||
public void AnArmedShipThatNeverFiredHasNoEnemySchematicRow()
|
||||
{
|
||||
var e = Add(float3(30, 0, 40), new[] { "Gun" });
|
||||
var o = Add(float3(0, 0, 0), new[] { "Eye" });
|
||||
Tick(.1f);
|
||||
Assert.Empty(o.SchematicRows(e));
|
||||
}
|
||||
|
||||
// Your own schematic is your own gear whatever you claim: the true data, the live range, weapons only.
|
||||
// Mutation: own rows read ClaimOf or the rated range of the claim (SpanGun 120), or list non-weapons.
|
||||
[Fact]
|
||||
public void OwnSchematicRowsShowOwnTruth()
|
||||
{
|
||||
var e = Add(float3(30, 0, 40), new[] { "Gun" });
|
||||
var gun = Guns(e)[0];
|
||||
e.Claim(gun, DataOf("SpanGun"));
|
||||
|
||||
var row = Assert.Single(e.SchematicRows(e));
|
||||
Assert.Same(gun, row.Item);
|
||||
Assert.Same(gun.Data, row.Claimed);
|
||||
Assert.Equal(40f, row.Range);
|
||||
Assert.Equal(gun.Behaviors.OfType<Weapon>().Single().Range, row.Range);
|
||||
}
|
||||
|
||||
// The renderer rebuilds when the key differs: a claim that changes between two acts changes the key, and an
|
||||
// unchanged claim does not. Mutation: Key drops Claimed.
|
||||
[Fact]
|
||||
public void TheRebuildKeyChangesWhenAClaimChanges()
|
||||
{
|
||||
var e = Add(float3(30, 0, 40), new[] { "Gun" });
|
||||
var o = Add(float3(0, 0, 0), new[] { "Eye" });
|
||||
var gun = Guns(e)[0];
|
||||
Fire(e, gun);
|
||||
var before = o.SchematicRows(e).Select(r => r.Key).ToArray();
|
||||
Assert.Equal(before, o.SchematicRows(e).Select(r => r.Key).ToArray());
|
||||
|
||||
e.Claim(gun, DataOf("SpanGun"));
|
||||
e.SetSignature(new object(), SignatureChannel.LaunchFlash, 1000000f, gun);
|
||||
Tick(.1f);
|
||||
|
||||
var after = o.SchematicRows(e).Select(r => r.Key).ToArray();
|
||||
Assert.Single(after);
|
||||
Assert.NotEqual(before, after);
|
||||
Assert.Same(DataOf("SpanGun"), after[0].Item2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue