🔬Avançado

Sistema de Eventos - EventTracker

Guia completo do EventTracker com 120+ tipos de eventos, listeners customizados e exemplos práticos.

📊 Arquitetura

O EventTracker segue o padrão Publish/Subscribe. Quando um evento é disparado, todos os listeners registrados para aquele tipo são notificados automaticamente.

1️⃣

Criando um EventListener

using Sims3.Gameplay.EventSystem;

namespace SeuMod.EventListeners
{
    public class RelationshipChangeListener : EventListener
    {
        public override ListenerAction ProcessEvent(Event e)
        {
            if (e is RelationshipEvent relEvent)
            {
                SimDescription simA = relEvent.SimDescriptionA;
                SimDescription simB = relEvent.SimDescriptionB;
                
                // Sua lógica aqui
                LogRelationshipChange(simA, simB);
                
                return ListenerAction.KeepListening;
            }
            return ListenerAction.KeepListening;
        }
        
        public override bool DoesEventApply(Event e)
        {
            return e.Id == EventTypeId.kRelationshipLTRChanged;
        }
    }
}
2️⃣

Registrando Listeners

// No ModMain.cs
private static RelationshipChangeListener sListener;

private static void OnWorldLoadFinished(object sender, EventArgs e)
{
    sListener = new RelationshipChangeListener();
    EventTracker.AddListener(EventTypeId.kRelationshipLTRChanged, sListener);
}

// Limpeza (importante!)
public static void Cleanup()
{
    if (sListener != null)
    {
        EventTracker.RemoveListener(EventTypeId.kRelationshipLTRChanged, sListener);
    }
}
3️⃣

Principais Eventos

kSimCreated
kSimDeath
kAgedUp
kCareerChanged
kSkillGained
kTraitGained
kBuffAdded
kBuffRemoved
kRelationshipLTRChanged
kSocialEvent
kWooHoo
kMarriage
kDivorce
kPregnancy
kBirth
kInteractionSuccess
4️⃣

Exemplo: Detectar WooHoo

public class WooHooDetector : EventListener
{
    public override ListenerAction ProcessEvent(Event e)
    {
        if (e.Id == EventTypeId.kWooHoo)
        {
            WooHooEvent wooEvent = e as WooHooEvent;
            Sim simA = wooEvent.SimA as Sim;
            Sim simB = wooEvent.SimB as Sim;
            
            // Adicionar buff especial
            if (simA != null)
            {
                simA.BuffManager.AddElement(
                    BuffNames.FeelingVeryConfident,
                    Origin.FromCustomSource
                );
            }
            if (simB != null)
            {
                simB.BuffManager.AddElement(
                    BuffNames.FeelingVeryConfident,
                    Origin.FromCustomSource
                );
            }
        }
        return ListenerAction.KeepListening;
    }
    
    public override bool DoesEventApply(Event e)
    {
        return e.Id == EventTypeId.kWooHoo;
    }
}