Beispiel #1
0
            // Gets the registered callbacks, unregisters them, and removes them from the related object.
            void UnRegister(TriggerSender sender)
            {
                MapTriggerCallbacks cbs = registeredCallbacks[sender];

                registeredCallbacks.Remove(sender);
                sender.GetComponent <EventDispatcher>().RemoveOnMovementFinishedListener(cbs.OnMapTriggerMoved);
            }
 /// <summary>
 /// Check collision and apply damage if other object is enemy
 /// </summary>
 /// <param name="other"></param>
 public void OnTriggerEnter(Collider other)
 {
     if (alive)
     {
         TriggerSender ts = other.GetComponent <TriggerSender>();
         if (ts != null)
         {
             GameObject triggerReciever = ts.GetReciever().GetRecieverGameObject();
             IDamagable damagable       = triggerReciever.GetComponent <IDamagable>();
             if (damagable != null)
             {
                 if ((damagable.GetFaction() & oppositeFaction) != 0)
                 {
                     if (damagable.RecieveAttack(gameObject, other, attackDamage, dir, attackForce))
                     {
                         SoundManager.GetInstance().Play(destructionClip);
                         Clear();
                     }
                 }
             }
         }
         else
         {
             if (other.CompareTag("Enviorment"))
             {
                 SoundManager.GetInstance().Play(destructionClip);
                 Clear();
             }
         }
     }
 }
Beispiel #3
0
            // Register a new sender, and add their callbacks
            void Register(TriggerSender sender)
            {
                registeredCallbacks[sender] = new MapTriggerCallbacks((direction) => {
                    CallOnMapTriggerMoved(sender.GetComponent <Positionable>());
                });

                sender.GetComponent <EventDispatcher>().AddOnMovementFinishedListener(registeredCallbacks[sender].OnMapTriggerMoved);
            }
Beispiel #4
0
            void OnTriggerExit2D(Collider2D collision)
            {
                TriggerSender sender = collision.GetComponent <TriggerSender>();

                if (sender != null && registeredCallbacks.ContainsKey(sender))
                {
                    ExitAndDisconnect(sender);
                }
            }
Beispiel #5
0
            void OnTriggerEnter2D(Collider2D collision)
            {
                TriggerSender sender = collision.GetComponent <TriggerSender>();

                if (sender != null && !registeredCallbacks.ContainsKey(sender))
                {
                    ConnectAndEnter(sender);
                }
            }
Beispiel #6
0
    /// <summary>
    /// Hides canvas when player steps out of the trigger
    /// </summary>
    public void OnTriggerExit(Collider other)
    {
        TriggerSender hitbox = other.GetComponent <TriggerSender>();

        if (hitbox != null && hitbox.GetReciever().GetRecieverGameObject().Equals(player.gameObject) && player.bodyHitbox.Equals(other.gameObject))
        {
            Debug.Log("Close");
            dialogCanvas.Close();
        }
    }
    /// <summary>
    /// Evaluate trigger and damage other instance.
    /// </summary>
    /// <param name="col"></param>
    void OnTriggerStay(Collider col)
    {
        IDamagable    other = null;
        TriggerSender ts    = col.gameObject.GetComponent <TriggerSender>();

        // Get IDamagable component on child or parent.
        if (ts != null)
        {
            other = ts.GetReciever().GetRecieverGameObject().GetComponent <IDamagable>();
        }
        if (other == null)
        {
            other = col.gameObject.GetComponent <IDamagable>();
        }

        // Check not null and other faction.
        if (other != null && (other.GetFaction() & targetFaction) != 0)
        {
            // Check state
            switch (state)
            {
            case SpikeState.hidden: {
                // Prepare spikes
                state = SpikeState.anticipated;
                anticipationProgress = 0;
                SoundManager.GetInstance().Play(anticipationClip);
            } break;

            case SpikeState.rised: {
                // Effect damage
                if (ignoreProgress == 0)
                {
                    Vector3 proy = Vector3.ProjectOnPlane(col.gameObject.transform.position - transform.position, Vector3.up);
                    int     dir;
                    if (Mathf.Abs(proy.z) > Mathf.Abs(proy.x))
                    {
                        dir = proy.z > 0 ? 0 : 2;
                    }
                    else
                    {
                        dir = proy.x > 0 ? 3 : 1;
                    }
                    other.Damage(damage, dir, pushForce, stunForce);
                    ignoreProgress = ignoreTime;
                }
            } break;
            }
        }
    }
Beispiel #8
0
 /// <summary>
 /// Apply damage to player if self attackHitbox collides with it.
 /// </summary>
 /// <param name="origin">GameObject on which OnTriggerExit method was called.</param>
 /// <param name="other">Collider data of the OnTriggerExit method.</param>
 public void OnExtensionTriggerEnter(GameObject origin, Collider other)
 {
     if (origin == attackHitbox)
     {
         TriggerSender ts = other.GetComponent <TriggerSender>();
         if (ts != null)
         {
             GameObject triggerReciever = ts.GetReciever().GetRecieverGameObject();
             IDamagable damagable       = triggerReciever.GetComponent <IDamagable>();
             if (damagable != null)
             {
                 if ((damagable.GetFaction() & oppositeFaction) != 0)
                 {
                     damagable.RecieveAttack(origin, other, stats.attackDamageMultiplier, lookingDirection, stats.attackForceMultiplier);
                 }
             }
         }
     }
 }
Beispiel #9
0
    /// <summary>
    /// Apply damage to player if the attack hitbox of any of the body trails collides with it.
    /// </summary>
    /// <param name="origin">GameObject on which OnTriggerExit method was called.</param>
    /// <param name="other">Collider data of the OnTriggerExit method.</param>
    public void OnExtensionTriggerEnter(GameObject origin, Collider other)
    {
        if (alive)
        {
            bool attackCollision = false;
            if (origin == attackHitbox)
            {
                attackCollision = true;
            }
            for (int i = 0; i < trailSections.Length; i++)
            {
                if (origin == trailSections[i].gameObject)
                {
                    attackCollision = true;
                    break;
                }
            }

            if (attackCollision)
            {
                TriggerSender ts = other.GetComponent <TriggerSender>();
                if (ts != null)
                {
                    GameObject triggerReciever = ts.GetReciever().GetRecieverGameObject();
                    IDamagable damagable       = triggerReciever.GetComponent <IDamagable>();
                    if (damagable != null)
                    {
                        if ((damagable.GetFaction() & oppositeFaction) != 0)
                        {
                            damagable.RecieveAttack(origin, other, stats.attackDamageMultiplier, Tools.Vector3ToDir4Int(other.transform.position - origin.transform.position), stats.attackForceMultiplier);
                        }
                    }
                }
            }
        }
    }
Beispiel #10
0
 void ConnectAndEnter(TriggerSender sender)
 {
     Register(sender);
     CallOnMapTriggerEnter(sender.GetComponent <Positionable>());
 }
Beispiel #11
0
 void ExitAndDisconnect(TriggerSender sender)
 {
     CallOnMapTriggerExit(sender.GetComponent <Positionable>());
     UnRegister(sender);
 }
Beispiel #12
0
    /// <summary>
    /// Check the colisions of the bodyHitbox and attackHitobx, and respond acordingly.
    /// </summary>
    /// <param name="origin"></param>
    /// <param name="other"></param>
    public void OnExtensionTriggerEnter(GameObject origin, Collider other)
    {
        if (isActive && isAlive && !isDespawning)
        {
            // Check attack
            if (attackCheck && origin == attackHitbox)
            {
                TriggerSender ts = other.GetComponent <TriggerSender>();
                if (ts != null)
                {
                    // Attacking enemy entities
                    GameObject triggerReciever = ts.GetReciever().GetRecieverGameObject();
                    IDamagable damagable       = triggerReciever.GetComponent <IDamagable>();
                    if (damagable != null)
                    {
                        // Apply damage
                        if (!attackWhitelist.Contains(triggerReciever))
                        {
                            if ((damagable.GetFaction() & oppositeFaction) != 0)
                            {
                                bool recieved = damagable.RecieveAttack(origin, other, attackDamage, facingDirection, pushForce, stunForce);
                                if (recieved)
                                {
                                    attackWhitelist.Add(triggerReciever);
                                }
                            }
                        }
                    }
                }
                else
                {
                    // Attacking destructible enviorment.
                    IDamagable damagable = other.GetComponent <IDamagable>();
                    if (damagable != null)
                    {
                        if (!attackWhitelist.Contains(other.gameObject))
                        {
                            if ((damagable.GetFaction() & oppositeFaction) != 0)
                            {
                                bool recieved = damagable.RecieveAttack(origin, other, attackDamage, facingDirection, pushForce, stunForce);
                                if (recieved)
                                {
                                    attackWhitelist.Add(other.gameObject);
                                }
                            }
                        }
                    }
                }
            }

            // Check other collisions
            if (origin == bodyHitbox)
            {
                // Pickups
                if (other.CompareTag("Collectible"))
                {
                    other.GetComponent <ICollectible>().Collect();
                }

                // Level end
                if (other.CompareTag("Endpoint"))
                {
                    if (other.GetComponent <EndpointController>().GoNextLevel())
                    {
                        despawnPosition = other.transform.position;
                        animator.SetTrigger("Despawn");
                        isDespawning = true;
                    }
                }
            }
        }
    }