protected virtual void OnDeathEvent(PublicEventArgs eventArgs) { if (DeathEvent != null) { DeathEvent(this, eventArgs); } }
// Send a hit event to all handlers protected virtual void OnHitEvent(PublicEventArgs eventArgs) { if (HitEvent != null) { HitEvent(this, eventArgs); } }
// Whenever a public event is triggered sort it and send it to all handlers public void OnPublicEvent(object source, PublicEventArgs args) { // If the event is a restart event if (args == EventArgs.Empty) { Start(); return; } // Send the event information switch (args._eventType) { default: case EventType.Hit: { Debug.Log("Broadcasting a hit event"); OnHitEvent(args); break; } case EventType.Death: { Debug.Log("Broadcasting a death event"); OnDeathEvent(args); break; } } }
// A nearby robot died public void OnDeathEvent(object source, PublicEventArgs args) { // If the bot is in range of the event && they didn't trigger it if (Vector3.Distance(args.Agent.transform.position, gameObject.transform.position) < args.Range && args.Agent != gameObject) { switch (Stats.faction) { default: case Factions.Neutral: { // Flee NController.SetEvent(EventType.Death, args.Agent.transform.position); Stats.ModifyStat("fear", 10.0f); break; } case Factions.Barbarians: { NController.SetEvent(EventType.Hit, args.Agent.transform.position); NController.SetTarget(args.Agent); break; } case Factions.Guards: { NController.SetEvent(EventType.Hit, args.Agent.transform.position); NController.SetTarget(args.Agent); break; } } } }
// Dispatch hit event protected virtual void OnHitEvent(Collider other) { PublicEventArgs args; if (HitEvent != null) { args = new PublicEventArgs(GetComponent <Collider>().transform.root.gameObject, other.transform.root.gameObject, EventType.Hit, 50); HitEvent(this, args); } }
protected virtual void SendDeathEvent() { PublicEventArgs args; if (DeathEvent != null) { args = new PublicEventArgs(gameObject, null, EventType.Death, 100); DeathEvent(this, args); } }
public IPublicInterface FireEvent(PublicEventArgs args) { return(MyEvent(this, args)); }
// A nearby robot has been hit public void OnHitEvent(object source, PublicEventArgs args) { CharacterStats agentStats; CharacterStats subjectStats; if (args.Agent == null || args.Subject == null) { return; } agentStats = args.Agent.GetComponent <CharacterStats>(); subjectStats = args.Subject.GetComponent <CharacterStats>(); if (agentStats == null || subjectStats == null) { return; } // If the bot is in range of the event if (Vector3.Distance(args.Agent.transform.position, gameObject.transform.position) < args.Range && currentState == State.Idle) { switch (Stats.faction) { default: case Factions.Neutral: { // Interuption event and add fear NController.SetEvent(EventType.Hit, args.Agent.transform.position); NController.SetTarget(args.Agent); Stats.ModifyStat("fear", 1.0f); break; } case Factions.Barbarians: { // Join in fight if (subjectStats.faction == Stats.faction) { NController.SetTarget(args.Agent); NController.SetEvent(EventType.Hit, args.Agent.transform.position); } else if (agentStats.faction == Stats.faction) { NController.SetTarget(args.Subject); NController.SetEvent(EventType.Hit, args.Subject.transform.position); } else // Or just watch { NController.SetTarget(args.Subject); NController.SetEvent(EventType.Other, args.Subject.transform.position); } break; } case Factions.Guards: { // Apprehend aggressor if (agentStats.faction == Stats.faction) { NController.SetTarget(args.Subject); NController.SetEvent(EventType.Other, args.Subject.transform.position); } else { NController.SetTarget(args.Agent); NController.SetEvent(EventType.Hit, args.Agent.transform.position); } break; } } } }