Skip to content

Game.Citizens.CrimeVictim

Assembly: Assembly-CSharp.dll
Namespace: Game.Citizens

Type: public struct CrimeVictim : IComponentData, IQueryTypeParameter, ISerializable, IEnableableComponent

Base: IComponentData, IQueryTypeParameter, ISerializable, IEnableableComponent

Summary: ECS component used to mark a citizen (or other entity) as a victim of a crime. It stores a single byte value describing the "effect" applied to the victim (an effect id/flag). The component implements ISerializable for manual binary serialization of the single byte, IEnableableComponent so it can be toggled on/off per-entity, and IQueryTypeParameter so it can be used directly in EntityQuery definitions. The exact meaning of the effect values is defined by game systems; consumers should treat the field as an opaque effect identifier (0 is typically the default/none).


Fields

  • public byte m_Effect Holds a small, 0–255 effect identifier for the crime victim state. Systems reading this component use the value to determine which visual/behavioral effect to apply to the entity. Because it is a single byte it serializes compactly. Default semantics: 0 meaning no special effect; nonzero values select specific effects (mapping depends on game code).

Properties

  • This type has no CLR properties. It exposes a single public field (m_Effect) and relies on the IEnableableComponent capability for enable/disable state.

Constructors

  • public CrimeVictim(byte effect)
    Initializes the component with the provided effect id (assigns to m_Effect). Use to create component data to add to an entity.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_Effect byte to the provided writer. Designed for the game's binary serialization pipeline; writing a single byte is compact and version-stable for this field.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads a single byte from the provided reader into m_Effect. Should be used by the game's deserialization pipeline; callers must ensure reader state corresponds to the serialized format.

Notes: - Because serialization is a single byte, these methods are straightforward and cheap. - When changing the component layout in future, maintain backward-compatibility in Serialize/Deserialize to avoid corrupting saved data.

Usage Example

// Create or obtain an EntityManager (typical in systems or mod initialization)
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

// Create the component and add it to an entity
var victimComponent = new CrimeVictim(effect: 2); // effect id 2 (meaning defined by game)
entityManager.AddComponentData(entity, victimComponent);

// Enable/disable the component (IEnableableComponent support)
entityManager.SetComponentEnabled<CrimeVictim>(entity, true); // enable
entityManager.SetComponentEnabled<CrimeVictim>(entity, false); // disable

// Query for entities that are crime victims (read-only example)
var query = entityManager.CreateEntityQuery(
    ComponentType.ReadOnly<CrimeVictim>()
);

using var victims = query.ToComponentDataArray<CrimeVictim>(Allocator.TempJob);
for (int i = 0; i < victims.Length; i++)
{
    byte effectId = victims[i].m_Effect;
    // handle effectId...
}

Additional notes for modders: - Treat m_Effect as an index/flag — consult game code or data for the mapping of effect ids to visuals/behaviors. - Because this struct implements ISerializable, it participates in save/load; if you extend behavior tied to this field, ensure compatibility with saved data.