2026-08-10 14:57:50 +01:00
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2020-12-22 03:13:43 +00:00
|
|
|
|
* 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;
|
2020-04-09 10:33:16 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2026-08-10 14:57:50 +01:00
|
|
|
|
using MessagePack;
|
|
|
|
|
|
using Newtonsoft.Json;
|
2026-09-14 17:39:12 +02:00
|
|
|
|
using CultMath;
|
|
|
|
|
|
using static CultMath.math;
|
2020-04-09 10:33:16 +01:00
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
|
public abstract class Behavior
|
2020-04-09 10:33:16 +01:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
public BehaviorData Data { get; }
|
2021-04-18 05:13:20 +01:00
|
|
|
|
public EquippedItem Item { get; }
|
|
|
|
|
|
private ConsumableItemEffect Consumable { get; }
|
|
|
|
|
|
protected ItemManager ItemManager { get; }
|
|
|
|
|
|
|
|
|
|
|
|
protected Entity Entity => Item?.Entity ?? Consumable.Entity;
|
|
|
|
|
|
public float Temperature => Item?.Temperature ?? Consumable.Entity.MaxTemp;
|
|
|
|
|
|
|
Cut 2: give every entity its own StatResolver, delete the catalog leak
PerformanceStat kept two Dictionary<Entity, ...> fields for attached modifiers,
grown by one key per entity that ever evaluated the stat and never trimmed
(docs/stats-and-power-cut.md §0.3). StatResolver.cs is the new sole owner of
every resolved (item, stat) value and every attached modifier, one instance
per Entity and reachable only from it. EquippedItem and ConsumableItemEffect
now read and write through it instead of through the catalog object; the two
dictionaries and their four accessors are deleted outright, not hidden.
StatModifier no longer resolves its (type name, field name) reference by
runtime reflection search on every equip: StatValidation.ResolveStatField
does it once, memoized, and StatValidation.ValidateStatModifiers checks it at
catalog load and at Upsert, naming the record instead of failing with an
opaque NullReferenceException the first time something equips it. A modifier
whose own magnitude stat is (directly or transitively, through another
modifier on the same entity) one of the stats it writes is refused at equip:
resolving it would depend on a value computed from itself one tick late.
A resolved value now caches by the generation of the sources its declared
Terms actually read, invalidated per source by EquippedItem.UpdatePerformance
(Heat, Durability) and ConsumableItemEffect.Update (ConsumableProgress), so a
stat recomputes only when a term it declared moves.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 19:53:59 +02:00
|
|
|
|
// The StatResolver key for whichever of Item/Consumable this behaviour has -- the two owners a resolved stat
|
|
|
|
|
|
// value or an attached modifier can belong to (StatResolver.cs, docs/stats-and-power-cut.md Cut 2).
|
|
|
|
|
|
protected object StatOwner => (object) Item ?? Consumable;
|
|
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
|
public float3 Direction
|
2021-04-18 05:13:20 +01:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if(Item != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var hardpoint = Entity.Hardpoints[Item.Position.x, Item.Position.y];
|
2026-08-10 14:57:50 +01:00
|
|
|
|
if (hardpoint != null && Entity.HardpointTransforms.ContainsKey(hardpoint))
|
2021-04-18 05:13:20 +01:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
return normalize(Entity.HardpointTransforms[hardpoint].direction);
|
2021-04-18 05:13:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
var itemDirection = Entity.Direction.Rotate(Item.EquippableItem.Rotation);
|
|
|
|
|
|
return float3(itemDirection.x, 0, itemDirection.y);
|
2021-04-18 05:13:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
|
return float3(Entity.Direction.x, 0, Entity.Direction.y);
|
2021-04-18 05:13:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
|
protected Behavior(BehaviorData data, EquippedItem item)
|
2026-06-15 18:51:59 +01:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
Data = data;
|
2026-06-15 18:51:59 +01:00
|
|
|
|
Item = item;
|
|
|
|
|
|
ItemManager = Item.ItemManager;
|
|
|
|
|
|
}
|
2026-08-10 14:57:50 +01:00
|
|
|
|
|
|
|
|
|
|
protected Behavior(BehaviorData data, ConsumableItemEffect consumable)
|
2026-06-15 18:51:59 +01:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
Data = data;
|
2026-06-15 18:51:59 +01:00
|
|
|
|
Consumable = consumable;
|
|
|
|
|
|
ItemManager = consumable.Entity.ItemManager;
|
|
|
|
|
|
}
|
2026-08-10 14:57:50 +01:00
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
|
public float Evaluate(PerformanceStat stat) => Item?.Evaluate(stat) ?? Consumable.Evaluate(stat);
|
|
|
|
|
|
protected void AddHeat(float heat) => Item?.AddHeat(heat); // TODO: Heat for Consumables
|
|
|
|
|
|
|
|
|
|
|
|
protected void CauseDamage(float damage)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Item != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Item.EquippableItem.Durability -= damage;
|
|
|
|
|
|
Entity.ItemDamage.OnNext((Item, damage));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Consumable.Entity.Hull.Durability -= damage;
|
|
|
|
|
|
Consumable.Entity.HullDamage.OnNext(damage);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void CauseWearDamage(float multiplier)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Item != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
CauseDamage(Item.Wear * multiplier);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-08-10 14:57:50 +01:00
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
|
public virtual bool Execute(float dt)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2020-04-09 10:33:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
|
public interface IActivatedBehavior
|
2021-01-25 05:53:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
void Activate();
|
|
|
|
|
|
void Deactivate();
|
|
|
|
|
|
}
|
2020-04-09 10:33:16 +01:00
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
|
public interface IAnalogBehavior
|
2020-04-09 10:33:16 +01:00
|
|
|
|
{
|
2020-06-05 04:16:33 +01:00
|
|
|
|
float Axis { get; set; }
|
2020-04-09 10:33:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-21 01:55:25 +00:00
|
|
|
|
public interface IEventBehavior
|
|
|
|
|
|
{
|
|
|
|
|
|
void ResetEvents();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-12 01:42:13 +01:00
|
|
|
|
public interface IInitializableBehavior
|
|
|
|
|
|
{
|
|
|
|
|
|
void Initialize();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-25 05:53:36 +00:00
|
|
|
|
public interface IInteractiveBehavior
|
|
|
|
|
|
{
|
|
|
|
|
|
bool Exposed { get; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-12 01:42:13 +01:00
|
|
|
|
public interface IAlwaysUpdatedBehavior
|
|
|
|
|
|
{
|
2021-01-10 03:59:47 +00:00
|
|
|
|
void Update(float delta);
|
2020-05-12 01:42:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-31 19:53:16 +00:00
|
|
|
|
public interface IProgressBehavior
|
|
|
|
|
|
{
|
|
|
|
|
|
float Progress { get; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
|
public interface IOrderedBehavior
|
|
|
|
|
|
{
|
|
|
|
|
|
int Order { get; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-08 01:01:33 +01:00
|
|
|
|
public interface IPopulationAssignment
|
|
|
|
|
|
{
|
|
|
|
|
|
int AssignedPopulation { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
|
[Inspectable,
|
|
|
|
|
|
Union(0, typeof(GuidedWeaponData)),
|
|
|
|
|
|
Union(1, typeof(LauncherData)),
|
|
|
|
|
|
Union(2, typeof(ReactorData)),
|
|
|
|
|
|
Union(3, typeof(RadiatorData)),
|
|
|
|
|
|
Union(4, typeof(StatModifierData)),
|
|
|
|
|
|
Union(5, typeof(SensorData)),
|
|
|
|
|
|
Union(6, typeof(ReflectorData)),
|
|
|
|
|
|
Union(7, typeof(ShieldData)),
|
|
|
|
|
|
Union(8, typeof(ThrusterData)),
|
|
|
|
|
|
Union(9, typeof(WearData)),
|
|
|
|
|
|
Union(10, typeof(VelocityConversionData)),
|
|
|
|
|
|
Union(11, typeof(VelocityLimitData)),
|
|
|
|
|
|
Union(12, typeof(AetherDriveData)),
|
|
|
|
|
|
// Union(14, typeof(TowingControllerData)),
|
|
|
|
|
|
Union(15, typeof(CooldownData)),
|
|
|
|
|
|
Union(16, typeof(HeatData)),
|
|
|
|
|
|
// Union(17, typeof(HitscanData)),
|
|
|
|
|
|
Union(18, typeof(ItemUsageData)),
|
|
|
|
|
|
//Union(19, typeof(RadianceData)),
|
|
|
|
|
|
Union(20, typeof(SwitchData)),
|
|
|
|
|
|
Union(21, typeof(TriggerData)),
|
|
|
|
|
|
Union(22, typeof(VisibilityData)),
|
|
|
|
|
|
Union(23, typeof(ThermotoggleData)),
|
|
|
|
|
|
Union(24, typeof(EnergyDrawData)),
|
|
|
|
|
|
// Union(25, typeof(MiningControllerData)),
|
|
|
|
|
|
Union(26, typeof(MiningToolData)),
|
|
|
|
|
|
// Union(27, typeof(SurveyControllerData)),
|
|
|
|
|
|
Union(28, typeof(ResourceScannerData)),
|
|
|
|
|
|
// Union(29, typeof(WanderControllerData)),
|
|
|
|
|
|
// Union(30, typeof(HaulingControllerData)),
|
|
|
|
|
|
Union(31, typeof(CapacitorData)),
|
|
|
|
|
|
Union(32, typeof(CockpitData)),
|
|
|
|
|
|
Union(33, typeof(HeatStorageData)),
|
|
|
|
|
|
Union(34, typeof(TurretControllerData)),
|
|
|
|
|
|
Union(35, typeof(InstantWeaponData)),
|
|
|
|
|
|
Union(36, typeof(ConstantWeaponData)),
|
|
|
|
|
|
Union(37, typeof(ChargedWeaponData)),
|
|
|
|
|
|
Union(38, typeof(AutoWeaponData)),
|
Move the ServerShared data model onto CultLib's CultCache
Cut 8b. Aetheria.Shared builds headless against GameCult.Caching and
GameCult.Caching.MessagePack at the pinned CultLib; the pin guard also
checks the Caching project exists.
Documents: [CultDocument("aetheria.<type>", "1")] with [MessagePackObject]
and integer [Key]s on the Q7 concrete types (the eight ItemData leaves,
Faction, FactionProductData, PersonalityAttribute, NameFile, OrbitData, the
four BodyData leaves, SavedZone, SavedGame, PlayerSettings, InputLayout).
SavedGame and PlayerSettings are [CultGlobal]; Name members are [CultName].
ItemData, CraftedItemData, EquippableItemData, BodyData and AgentTask lose
[MessagePackObject]; BodyData and AgentTask lose their [Union]s. InputLayout
moves into ServerShared so AetheriaStores can route it.
References: Guid and DatabaseLink<T> members become CultRecordRef<T>;
Guid-keyed maps become ref-keyed with [CultReference(..., many: true)];
ZonePack holds refs to orbit and body records. Runtime maps (Zone orbits,
bodies and belts, cargo ItemsOfType, agent targets) key by CultRecordKey.
Identity is the record key: ID comparisons become reference or key
comparisons. StatModifierData.RequireBehavior is a simple type name.
AetheriaStores.Open composes the catalog (read-only unless writable), run
and player stores, one home per type. CultRecordRefs carries IsSet, a
null-safe Get(ref), RefOf (key from TryGetHandle) and Upsert.
ItemManager.GetData is the one item resolution path. MathResolver is
declared by [assembly: CultCacheFormatterResolver].
Inspector attributes: text, range and asset path map onto CultLib's
CultInspector attributes (asset path only on string members); every
replaced Aetheria attribute keeps [Inspectable] for the runtime panel.
Builds: Aetheria.Shared. Does not build: AetherDb and the Unity project,
which follow.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 19:00:42 +02:00
|
|
|
|
JsonObject(MemberSerialization.OptIn)]
|
2026-08-10 14:57:50 +01:00
|
|
|
|
public abstract class BehaviorData
|
|
|
|
|
|
{
|
|
|
|
|
|
[Inspectable, JsonProperty("group"), Key(0)]
|
|
|
|
|
|
public int Group;
|
|
|
|
|
|
|
|
|
|
|
|
public abstract Behavior CreateInstance(EquippedItem item);
|
|
|
|
|
|
public abstract Behavior CreateInstance(ConsumableItemEffect consumable);
|
2026-06-21 09:37:54 +01:00
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
|
public override string ToString()
|
2026-06-21 09:37:54 +01:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
return base.ToString().FormatTypeName();
|
2026-06-21 09:37:54 +01:00
|
|
|
|
}
|
2026-08-10 14:57:50 +01:00
|
|
|
|
}
|