Skip to content

Game.Prefabs.Crime

Assembly: Game
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Represents a prefab component that configures crime events for the game's event system. Exposes parameters controlling which targets can be affected, the crime type, probabilities for occurrence and recurrence, alarm delay, crime duration, stolen income ranges (absolute and relative), and punishment durations (jail/prison) with a prison probability. During prefab initialization this component writes a CrimeData struct onto the entity so the runtime event systems can use the configured values.


Fields

  • public EventTargetType m_RandomTargetType = EventTargetType.Citizen
    Specifies what target type the crime will choose by default (for example a citizen). Used to pick a random target for the event.

  • public CrimeType m_CrimeType
    Type of crime (enum). Defines the kind of criminal event (e.g., theft, assault, etc.) as understood by the game's event logic.

  • public Bounds1 m_OccurenceProbability = new Bounds1(0f, 50f)
    The probability (as a range) that a citizen will commit the crime the first time. Bounds1 stores a min/max value.

  • public Bounds1 m_RecurrenceProbability = new Bounds1(0f, 100f)
    The probability range for a criminal to commit the crime again (recurrence).

  • public Bounds1 m_AlarmDelay = new Bounds1(5f, 10f)
    Delay range (in seconds) after crime start before the police may be requested; ensures a minimum and maximum alarm delay.

  • public Bounds1 m_CrimeDuration = new Bounds1(20f, 60f)
    Duration range (in seconds) that the crime may last. If the crime lasts longer than the max without police securing the scene, the criminal will not be caught.

  • public Bounds1 m_CrimeIncomeAbsolute = new Bounds1(100f, 1000f)
    Absolute amount range of money that can be stolen from the victim (combined with the relative amount to determine final stolen amount).

  • public Bounds1 m_CrimeIncomeRelative = new Bounds1(0f, 0.25f)
    Relative percentage range (0.0–1.0) of the victim's money that may be stolen, combined with the absolute range to compute final stolen amount.

  • public Bounds1 m_JailTimeRange = new Bounds1(0.125f, 1f)
    Range (in game days) the criminal will spend in jail when caught.

  • public Bounds1 m_PrisonTimeRange = new Bounds1(1f, 100f)
    Range (in game days) for prison sentence after jail time when convicted.

  • public float m_PrisonProbability = 50f
    Probability (expressed as percent, e.g., 50f = 50%) that a jailed criminal will be sentenced to prison after jail time.

Properties

  • None (this class exposes configuration via public fields and writes a CrimeData component during Initialize)

Constructors

  • public Crime()
    Implicit default constructor. The component is typically instantiated and configured in the editor as a prefab component.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime data component type required for the prefab to function. Implementation: adds ReadWrite so the prefab will include CrimeData when converted to an entity.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Specifies archetype components used by the entity archetype. Implementation: adds ReadWrite() and ReadWrite() to the archetype component set.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Populates and writes a CrimeData struct to the provided entity using the values configured on this prefab component. Copies m_RandomTargetType, m_CrimeType, all Bounds1 ranges, and m_PrisonProbability into CrimeData, then calls entityManager.SetComponentData(entity, componentData).

Usage Example

// Example: configure a Crime component on a prefab (can be done in code or via inspector)
var crime = someGameObject.AddComponent<Game.Prefabs.Crime>();
crime.m_CrimeType = CrimeType.Pickpocket;
crime.m_RandomTargetType = EventTargetType.Citizen;
crime.m_OccurenceProbability = new Bounds1(10f, 30f); // 10–30% initial occurrence
crime.m_AlarmDelay = new Bounds1(3f, 8f);
crime.m_CrimeIncomeAbsolute = new Bounds1(50f, 200f);
crime.m_CrimeIncomeRelative = new Bounds1(0f, 0.15f);
crime.m_JailTimeRange = new Bounds1(0.25f, 0.5f);
crime.m_PrisonProbability = 25f;

// At runtime, when the prefab is converted to an entity, Crime.Initialize will write
// a CrimeData component to the entity with these values so the event/job systems can use them.

Additional notes: - Bounds1 holds a minimum and maximum value; many fields use ranges so the actual runtime value is sampled from that range. - m_PrisonProbability is treated as a percentage (0–100). Confirm with game code if probabilities elsewhere use 0–1 instead. - The class ties prefab configuration (MonoBehaviour-style) to ECS data (CrimeData/Game.Events.Crime), so changes in the inspector will affect the entity component data produced by Initialize.