80 lines
3.1 KiB
C#
80 lines
3.1 KiB
C#
using AcDream.App.World;
|
|
using AcDream.Core.Net.Messages;
|
|
using AcDream.Core.Vfx;
|
|
using DatReaderWriter.DBObjs;
|
|
|
|
namespace AcDream.App.Rendering.Vfx;
|
|
|
|
/// <summary>
|
|
/// DAT defaults and the currently installed network effect description for
|
|
/// one logical entity incarnation.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Retail precedence comes from <c>CPhysicsObj::InitDefaults</c>
|
|
/// (<c>0x005139D0</c>) followed by <c>CPhysicsObj::set_description</c>
|
|
/// (<c>0x00514F40</c>). Setup's direct default PES runs during initialization;
|
|
/// a network PhysicsDesc then unconditionally replaces the typed table, even
|
|
/// when PeTable was absent or zero.
|
|
/// </remarks>
|
|
public sealed class EntityEffectProfile : ILiveEntityEffectProfile
|
|
{
|
|
private EntityEffectProfile(Setup setup)
|
|
{
|
|
SetupDefaultScriptDid = NormalizePhysicsScriptDid(setup.DefaultScript.DataId);
|
|
CurrentPhysicsScriptTableDid = NormalizeTableDid((uint)setup.DefaultScriptTable);
|
|
CurrentSoundTableDid = NormalizeSoundTableDid((uint)setup.DefaultSoundTable);
|
|
}
|
|
|
|
public uint? SetupDefaultScriptDid { get; }
|
|
public uint? CurrentPhysicsScriptTableDid { get; private set; }
|
|
public uint? CurrentSoundTableDid { get; private set; }
|
|
public uint RawDefaultScriptType { get; private set; }
|
|
public float DefaultScriptIntensity { get; private set; }
|
|
public bool HasNetworkDescription { get; private set; }
|
|
|
|
/// <summary>Setup defaults remain active for a DAT/static object.</summary>
|
|
public static EntityEffectProfile CreateDatStatic(Setup setup)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(setup);
|
|
return new EntityEffectProfile(setup);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Applies Setup initialization followed by the live PhysicsDesc, matching
|
|
/// retail construction order.
|
|
/// </summary>
|
|
public static EntityEffectProfile CreateLive(
|
|
Setup setup,
|
|
PhysicsSpawnData physics)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(setup);
|
|
var profile = new EntityEffectProfile(setup);
|
|
profile.ApplyNetworkDescription(physics);
|
|
return profile;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Replaces all network-owned effect defaults. Nullable wire fields use
|
|
/// PhysicsDesc's initialized zero values; they never resurrect Setup's
|
|
/// typed table.
|
|
/// </summary>
|
|
public void ApplyNetworkDescription(PhysicsSpawnData physics)
|
|
{
|
|
CurrentPhysicsScriptTableDid = NormalizeTableDid(
|
|
physics.PhysicsScriptTableId.GetValueOrDefault());
|
|
CurrentSoundTableDid = NormalizeSoundTableDid(
|
|
physics.SoundTableId.GetValueOrDefault());
|
|
RawDefaultScriptType = physics.DefaultScriptType.GetValueOrDefault();
|
|
DefaultScriptIntensity = physics.DefaultScriptIntensity.GetValueOrDefault();
|
|
HasNetworkDescription = true;
|
|
}
|
|
|
|
private static uint? NormalizePhysicsScriptDid(uint did) =>
|
|
PhysicsScriptTableResolver.IsPhysicsScriptDid(did) ? did : null;
|
|
|
|
private static uint? NormalizeTableDid(uint did) =>
|
|
PhysicsScriptTableResolver.IsPhysicsScriptTableDid(did) ? did : null;
|
|
|
|
private static uint? NormalizeSoundTableDid(uint did) =>
|
|
(did & 0xFF000000u) == 0x20000000u ? did : null;
|
|
}
|