Beispiel #1
0
    public void TriggerEvent(Events.GameEvent e)
    {
        EventDelegate del;

        if (delegates.TryGetValue(e.GetType(), out del))
        {
            del.Invoke(e);

            // remove listeners which should only be called once
            foreach (EventDelegate k in delegates[e.GetType()].GetInvocationList())
            {
                if (onceLookups.ContainsKey(k))
                {
                    delegates[e.GetType()] -= k;

                    if (delegates[e.GetType()] == null)
                    {
                        delegates.Remove(e.GetType());
                    }

                    delegateLookup.Remove(onceLookups[k]);
                    onceLookups.Remove(k);
                }
            }
        }
        else
        {
            Debug.LogWarning("Event: " + e.GetType() + " has no listeners");
        }
    }
Beispiel #2
0
    //Inserts the event into the current queue.
    public bool QueueEvent(Events.GameEvent evt)
    {
        if (!delegates.ContainsKey(evt.GetType()))
        {
            Debug.LogWarning("EventManager: QueueEvent failed due to no listeners for event: " + evt.GetType());
            return(false);
        }

        m_eventQueue.Enqueue(evt);
        return(true);
    }
Beispiel #3
0
    //Every update cycle the queue is processed, if the queue processing is limited,
    //a maximum processing time per update can be set after which the events will have
    //to be processed next update loop.
    void Update()
    {
        float timer = 0.0f;

        while (m_eventQueue.Count > 0)
        {
            if (LimitQueueProcesing)
            {
                if (timer > QueueProcessTime)
                {
                    return;
                }
            }

            Events.GameEvent evt = m_eventQueue.Dequeue() as Events.GameEvent;
            TriggerEvent(evt);

            if (LimitQueueProcesing)
            {
                timer += Time.deltaTime;
            }
        }
    }
Beispiel #4
0
        public void TriggerEvent(Events.GameEvent e)
        {
            EventDelegate del;

#if UNITY_EDITOR
            Debug.Log("Event " + e.ToString() + " triggered.");
#endif

            if (delegates.TryGetValue(e.GetType(), out del))
            {
                del.Invoke(e);
#if UNITY_EDITOR
                Debug.Log("Listener " + del.Target.ToString().Split('[', ']')[1] + " invoked.");
#endif

                // remove listeners which should only be called once
                foreach (EventDelegate k in delegates[e.GetType()].GetInvocationList())
                {
                    if (onceLookups.ContainsKey(k))
                    {
                        delegates[e.GetType()] -= k;

                        if (delegates[e.GetType()] == null)
                        {
                            delegates.Remove(e.GetType());
                        }

                        delegateLookup.Remove(onceLookups[k]);
                        onceLookups.Remove(k);
                    }
                }
            }
            else
            {
                Debug.LogWarning("Event: " + e.GetType() + " has no listeners");
            }
        }
Beispiel #5
0
        private void EventsManager_ActionAppended(object sender, Events.GameEvent ac)
        {
            if (Player == null)
            {
                return;
            }
            var sndName = "";

            if (ac is EnemyAction)
            {
                var ea = ac as EnemyAction;
                if (ea.Kind == EnemyActionKind.Moved)
                {
                    //sndName = "foot_steps";
                }
            }
            else if (ac is LootAction)
            {
                var la = ac as LootAction;
                if (la.Kind == LootActionKind.Consumed)
                {
                    sndName = (la.Loot as Consumable).ConsumedSound;
                }
                else if (la.Kind == LootActionKind.Collected)
                {
                    sndName = la.Loot.CollectedSound;
                }
            }
            else if (ac is InteractiveTileAction)
            {
                var ia = ac as InteractiveTileAction;
                if (ia.InteractiveKind == InteractiveActionKind.Destroyed)
                {
                    sndName = ia.InvolvedTile.DestroySound;
                }
                else if (ia.InteractiveKind == InteractiveActionKind.DoorOpened)
                {
                    var door = ia.InvolvedTile as Tiles.Interactive.Door;
                    sndName = door.Secret ? "annulet-of-absorption" : door.OpenedSound();
                }
                else if (ia.InteractiveKind == InteractiveActionKind.DoorClosed)
                {
                    var door = ia.InvolvedTile as Tiles.Interactive.Door;
                    sndName = door.ClosedSound();
                }
                else //if (ia.InteractiveKind == InteractiveActionKind.ChestOpened)
                {
                    sndName = ia.InvolvedTile.InteractSound;
                }
            }
            else if (ac is HeroAction)
            {
                var ha = ac as HeroAction;
                if (ha.Kind == HeroActionKind.HitWall || ha.Kind == HeroActionKind.HitLockedChest)
                {
                    sndName = "punch";
                }
            }
            else if (ac is SoundRequestAction)
            {
                var snd = ac as SoundRequestAction;
                sndName = snd.SoundName;
            }

            else if (ac is LivingEntityAction)
            {
                var lea = ac as LivingEntityAction;
                if (lea.Kind == LivingEntityActionKind.Moved)
                {
                    if (lea.InvolvedEntity is Hero)
                    {
                        var sur = gm.CurrentNode.GetSurfaceKindUnderTile(lea.InvolvedEntity);
                        if (sur != SurfaceKind.DeepWater && sur != SurfaceKind.ShallowWater)
                        {
                            sndName = "foot_steps";
                        }
                    }
                }
                else if (lea.Kind == LivingEntityActionKind.LeveledUp)
                {
                    sndName = "bell";
                }
                else if (lea.Kind == LivingEntityActionKind.Missed)
                {
                    sndName = "melee_missed";
                }
                else if (lea.Kind == LivingEntityActionKind.Died)
                {
                    sndName = "death";
                    var enemy = lea.InvolvedEntity as Enemy;
                    if (enemy != null)
                    {
                        if (enemy.PowerKind == EnemyPowerKind.Champion)
                        {
                            sndName = "chemp_death";
                        }
                        else if (enemy.PowerKind == EnemyPowerKind.Boss)
                        {
                            sndName = "boss_death";
                        }
                    }
                }
                //if (lea.Kind == LivingEntityActionKind.GainedDamage)
                //{
                //  Player.PlaySound("punch");
                //}
            }

            if (!string.IsNullOrEmpty(sndName))
            {
                Player.PlaySound(sndName);
            }
        }