Exemplo n.º 1
0
 void Update()
 {
     Timer += Time.deltaTime;
     if (Timer >= SecondsToDespawn)
     {
         EmeraldAIObjectPool.Despawn(gameObject);
     }
 }
Exemplo n.º 2
0
        void DeadTargetDetection()
        {
            if (m_PreviousPosition != Vector3.zero)
            {
                m_CurrentVelocity = (m_PreviousPosition - transform.position) / Time.deltaTime;
            }
            m_PreviousPosition = transform.position;

            if (!Collided && ProjectileCurrentTarget != null && Vector3.Distance(ProjectileCurrentTarget.position, transform.position) <= 2 || m_CurrentVelocity.magnitude < 1)
            {
                if (ObjectToDisableOnCollision != null)
                {
                    ObjectToDisableOnCollision.SetActive(true);
                }

                m_TargetDeadTimer += Time.deltaTime;

                if (m_TargetDeadTimer >= 0.1f)
                {
                    if (ObjectToDisableOnCollision != null)
                    {
                        ObjectToDisableOnCollision.SetActive(false);
                    }
                    if (ImpactSound != null && SoundOnCollisionRef == EffectOnCollision.Yes)
                    {
                        CollisionSound = EmeraldAIObjectPool.SpawnEffect(CollisionSoundObject, transform.position, Quaternion.identity, 2);
                        CollisionSound.transform.SetParent(EmeraldAISystem.ObjectPool.transform);
                        AudioSource CollisionAudioSource = CollisionSound.GetComponent <AudioSource>();
                        CollisionAudioSource.PlayOneShot(ImpactSound);
                    }
                    if (EffectOnCollisionRef == EffectOnCollision.Yes)
                    {
                        if (CollisionEffect != null)
                        {
                            SpawnedEffect = EmeraldAIObjectPool.SpawnEffect(CollisionEffect, transform.position, Quaternion.identity, CollisionTimeout);
                            SpawnedEffect.transform.SetParent(EmeraldAISystem.ObjectPool.transform);
                        }
                    }
                    Collided = true;
                    ProjectileCollider.enabled = false;
                }
            }
        }
Exemplo n.º 3
0
        void Update()
        {
            DamageTimer       += Time.deltaTime;
            ActiveLengthTimer += Time.deltaTime;

            if (ActiveLengthTimer >= m_AbilityLength + 0.05f)
            {
                if (m_TargetType == EmeraldAISystem.TargetType.AI)
                {
                    if (m_TargetEmeraldComponent.ActiveEffects.Contains(m_AbilityName))
                    {
                        m_TargetEmeraldComponent.ActiveEffects.Remove(m_AbilityName);
                    }
                }
                else if (m_TargetType == EmeraldAISystem.TargetType.Player)
                {
                    if (m_EmeraldAIPlayerDamage.ActiveEffects.Contains(m_AbilityName))
                    {
                        m_EmeraldAIPlayerDamage.ActiveEffects.Remove(m_AbilityName);
                    }
                }

                if (!m_AudioSource.isPlaying)
                {
                    EmeraldAIObjectPool.Despawn(gameObject);
                }
            }

            if (DamageTimer >= m_DamageIncrement && ActiveLengthTimer <= m_AbilityLength + 0.05f)
            {
                if (m_DamageOverTimeEffect != null)
                {
                    if (m_TargetType == EmeraldAISystem.TargetType.AI)
                    {
                        m_EffectPosition = m_TargetEmeraldComponent.transform.position + new Vector3(0, m_TargetEmeraldComponent.HitPointTransform.localPosition.y, 0);
                    }
                    else
                    {
                        m_EffectPosition = m_TargetTransform.position;
                    }

                    EmeraldAIObjectPool.SpawnEffect(m_DamageOverTimeEffect, m_EffectPosition, Quaternion.identity, m_DamageOverTimeTimeout);
                }

                if (m_DamageOverTimeSound != null)
                {
                    m_AudioSource.PlayOneShot(m_DamageOverTimeSound);
                }

                //Apply damage over time to another AI
                if (m_TargetType == EmeraldAISystem.TargetType.AI)
                {
                    m_TargetEmeraldComponent.Damage(m_DamageAmount);
                    m_AttackerEmeraldComponent.OnDoDamageEvent.Invoke();
                }
                else if (m_TargetType == EmeraldAISystem.TargetType.Player) //Apply damage over time to the player
                {
                    if (m_TargetTransform.GetComponent <EmeraldAIPlayerDamage>() != null)
                    {
                        m_TargetTransform.GetComponent <EmeraldAIPlayerDamage>().SendPlayerDamage(m_DamageAmount, m_AttackerEmeraldComponent.transform, m_AttackerEmeraldComponent);
                        m_AttackerEmeraldComponent.OnDoDamageEvent.Invoke();
                    }
                    else
                    {
                        m_TargetTransform.gameObject.AddComponent <EmeraldAIPlayerDamage>();
                        m_TargetTransform.GetComponent <EmeraldAIPlayerDamage>().SendPlayerDamage(m_DamageAmount, m_AttackerEmeraldComponent.transform, m_AttackerEmeraldComponent);
                        m_AttackerEmeraldComponent.OnDoDamageEvent.Invoke();
                    }
                }
                else if (m_TargetType == EmeraldAISystem.TargetType.NonAITarget) //Apply the damage over time to a non-AI target
                {
                    if (m_TargetTransform.GetComponent <EmeraldAINonAIDamage>() != null)
                    {
                        m_TargetTransform.GetComponent <EmeraldAINonAIDamage>().SendNonAIDamage(m_DamageAmount, m_AttackerEmeraldComponent.transform);
                        m_AttackerEmeraldComponent.OnDoDamageEvent.Invoke();
                    }
                    else
                    {
                        m_TargetTransform.gameObject.AddComponent <EmeraldAINonAIDamage>();
                        m_TargetTransform.GetComponent <EmeraldAINonAIDamage>().SendNonAIDamage(m_DamageAmount, m_AttackerEmeraldComponent.transform);
                        m_AttackerEmeraldComponent.OnDoDamageEvent.Invoke();
                    }
                }

                DamageTimer = 0;
            }

            if (m_TargetType == EmeraldAISystem.TargetType.AI && m_TargetEmeraldComponent.IsDead)
            {
                if (m_TargetEmeraldComponent.ActiveEffects.Contains(m_AbilityName))
                {
                    m_TargetEmeraldComponent.ActiveEffects.Remove(m_AbilityName);
                }
                EmeraldAIObjectPool.Despawn(gameObject);
            }
            else if (m_TargetType == EmeraldAISystem.TargetType.NonAITarget && m_NonAIDamageComponent.Health <= 0)
            {
                if (m_NonAIDamageComponent.ActiveEffects.Contains(m_AbilityName))
                {
                    m_NonAIDamageComponent.ActiveEffects.Remove(m_AbilityName);
                }
                EmeraldAIObjectPool.Despawn(gameObject);
            }
        }
Exemplo n.º 4
0
        //Handle all of our collision related calculations here. When this happens, effects and sound can be played before the object is despawned.
        void OnTriggerEnter(Collider C)
        {
            if (!Collided && EmeraldSystem != null && ProjectileCurrentTarget != null && C.gameObject == ProjectileCurrentTarget.gameObject && C.gameObject.layer != 2)
            {
                if (EffectOnCollisionRef == EffectOnCollision.Yes)
                {
                    if (CollisionEffect != null)
                    {
                        SpawnedEffect = EmeraldAIObjectPool.SpawnEffect(CollisionEffect, transform.position, Quaternion.identity, 2);
                        SpawnedEffect.transform.SetParent(EmeraldAISystem.ObjectPool.transform);
                    }
                }
                if (ImpactSound != null && SoundOnCollisionRef == EffectOnCollision.Yes)
                {
                    CollisionSound = EmeraldAIObjectPool.SpawnEffect(CollisionSoundObject, transform.position, Quaternion.identity, 2);
                    CollisionSound.transform.SetParent(EmeraldAISystem.ObjectPool.transform);
                    AudioSource CollisionAudioSource = CollisionSound.GetComponent <AudioSource>();
                    CollisionAudioSource.PlayOneShot(ImpactSound);
                }

                //Damage AI target with damage based off of currently applied ability
                if (TargetTypeRef == TargetType.AI && TargetEmeraldSystem != null)
                {
                    if (AbilityType == AbilityTypeEnum.Damage && DamageType == DamageTypeEnum.Instant)
                    {
                        TargetEmeraldSystem.Damage(Damage, EmeraldAISystem.TargetType.AI, EmeraldSystem.transform, EmeraldSystem.SentRagdollForceAmount, CriticalHit);
                        EmeraldSystem.OnDoDamageEvent.Invoke();
                    }
                    else if (AbilityType == AbilityTypeEnum.Damage && DamageType == DamageTypeEnum.OverTime)
                    {
                        //Apply the initial damage to our target
                        TargetEmeraldSystem.Damage(AbilityImpactDamage, EmeraldAISystem.TargetType.AI, EmeraldSystem.transform, EmeraldSystem.SentRagdollForceAmount);
                        EmeraldSystem.OnDoDamageEvent.Invoke();
                        if (AbilityStacksRef == Yes_No.No && !TargetEmeraldSystem.ActiveEffects.Contains(EmeraldSystem.CurrentlyCreatedAbility.AbilityName) && AbilityName != string.Empty || AbilityStacksRef == Yes_No.Yes)
                        {
                            //Initialize the damage over time component
                            GameObject SpawnedDamageOverTimeComponent = EmeraldAIObjectPool.Spawn(DamageOverTimeComponent, ProjectileCurrentTarget.position, Quaternion.identity);
                            SpawnedDamageOverTimeComponent.transform.SetParent(EmeraldAISystem.ObjectPool.transform);
                            SpawnedDamageOverTimeComponent.GetComponent <EmeraldAIDamageOverTime>().Initialize(AbilityName, AbilityDamagePerIncrement, AbilityDamageIncrement, AbilityLength,
                                                                                                               DamageOverTimeEffect, DamageOvertimeTimeout, DamageOverTimeSound, null, m_EmeraldAIPlayerDamage, TargetEmeraldSystem, EmeraldSystem, EmeraldSystem.CurrentTarget, (EmeraldAISystem.TargetType)TargetTypeRef);
                            TargetEmeraldSystem.ActiveEffects.Add(AbilityName);
                        }
                    }
                }
                else if (TargetTypeRef == TargetType.Player) //Damage the Player with damage based off of currently applied ability
                {
                    if (AbilityType == AbilityTypeEnum.Damage && DamageType == DamageTypeEnum.Instant)
                    {
                        DamagePlayer(Damage);
                    }
                    else if (AbilityType == AbilityTypeEnum.Damage && DamageType == DamageTypeEnum.OverTime)
                    {
                        //Apply the initial damage to our target
                        DamagePlayer(AbilityImpactDamage);
                        if (AbilityStacksRef == Yes_No.No && !EmeraldSystem.CurrentTarget.GetComponent <EmeraldAIPlayerDamage>().ActiveEffects.Contains(EmeraldSystem.CurrentlyCreatedAbility.AbilityName) &&
                            AbilityName != string.Empty || AbilityStacksRef == Yes_No.Yes)
                        {
                            //Initialize the damage over time component
                            GameObject SpawnedDamageOverTimeComponent = EmeraldAIObjectPool.Spawn(DamageOverTimeComponent, ProjectileCurrentTarget.position, Quaternion.identity);
                            SpawnedDamageOverTimeComponent.transform.SetParent(EmeraldAISystem.ObjectPool.transform);
                            SpawnedDamageOverTimeComponent.GetComponent <EmeraldAIDamageOverTime>().Initialize(AbilityName, AbilityDamagePerIncrement, AbilityDamageIncrement, AbilityLength,
                                                                                                               DamageOverTimeEffect, DamageOvertimeTimeout, DamageOverTimeSound, null, m_EmeraldAIPlayerDamage, TargetEmeraldSystem, EmeraldSystem, EmeraldSystem.CurrentTarget, (EmeraldAISystem.TargetType)TargetTypeRef);
                            EmeraldSystem.CurrentTarget.GetComponent <EmeraldAIPlayerDamage>().ActiveEffects.Add(AbilityName);
                        }
                    }
                }
                else if (TargetTypeRef == TargetType.NonAITarget) //Damage a non-AI target with damage based off of currently applied ability
                {
                    if (AbilityType == AbilityTypeEnum.Damage && DamageType == DamageTypeEnum.Instant)
                    {
                        DamageNonAITarget(Damage);
                    }
                    else if (AbilityType == AbilityTypeEnum.Damage && DamageType == DamageTypeEnum.OverTime)
                    {
                        //Apply the initial damage to our target
                        DamageNonAITarget(AbilityImpactDamage);

                        //Get a reference to the Non-AI Target component
                        EmeraldAINonAIDamage m_EmeraldAINonAIDamage = StartingTarget.GetComponent <EmeraldAINonAIDamage>();

                        if (AbilityStacksRef == Yes_No.No && !m_EmeraldAINonAIDamage.ActiveEffects.Contains(EmeraldSystem.CurrentlyCreatedAbility.AbilityName) && AbilityName != string.Empty || AbilityStacksRef == Yes_No.Yes)
                        {
                            //Initialize the damage over time component
                            GameObject SpawnedDamageOverTimeComponent = EmeraldAIObjectPool.Spawn(DamageOverTimeComponent, ProjectileCurrentTarget.position, Quaternion.identity);
                            SpawnedDamageOverTimeComponent.transform.SetParent(EmeraldAISystem.ObjectPool.transform);
                            SpawnedDamageOverTimeComponent.GetComponent <EmeraldAIDamageOverTime>().Initialize(AbilityName, AbilityDamagePerIncrement, AbilityDamageIncrement, AbilityLength,
                                                                                                               DamageOverTimeEffect, DamageOvertimeTimeout, DamageOverTimeSound, m_EmeraldAINonAIDamage, m_EmeraldAIPlayerDamage, TargetEmeraldSystem, EmeraldSystem, EmeraldSystem.CurrentTarget, (EmeraldAISystem.TargetType)TargetTypeRef);
                            m_EmeraldAINonAIDamage.ActiveEffects.Add(AbilityName);
                        }
                    }
                }

                if (ObjectToDisableOnCollision != null)
                {
                    ObjectToDisableOnCollision.SetActive(false);
                }

                if (ArrowProjectileRef == ArrowObject.Yes)
                {
                    CollisionTime = 0;
                }
                Collided = true;
                ProjectileCollider.enabled = false;
            }
            else if (!Collided && EmeraldSystem != null && ProjectileCurrentTarget != null && C.gameObject != ProjectileCurrentTarget.gameObject && C.gameObject != EmeraldSystem.gameObject && C.gameObject.layer != 2)
            {
                Collided = true;
                ProjectileCollider.enabled = false;

                if (ObjectToDisableOnCollision != null)
                {
                    ObjectToDisableOnCollision.SetActive(false);
                }

                if (EffectOnCollisionRef == EffectOnCollision.Yes)
                {
                    if (CollisionEffect != null)
                    {
                        SpawnedEffect = EmeraldAIObjectPool.SpawnEffect(CollisionEffect, transform.position, Quaternion.identity, 2);
                        SpawnedEffect.transform.SetParent(EmeraldAISystem.ObjectPool.transform);
                    }
                }
                if (ImpactSound != null && SoundOnCollisionRef == EffectOnCollision.Yes)
                {
                    CollisionSound = EmeraldAIObjectPool.SpawnEffect(CollisionSoundObject, transform.position, Quaternion.identity, 2);
                    CollisionSound.transform.SetParent(EmeraldAISystem.ObjectPool.transform);
                    AudioSource CollisionAudioSource = CollisionSound.GetComponent <AudioSource>();
                    CollisionAudioSource.PlayOneShot(ImpactSound);
                }

                if (ArrowProjectileRef == ArrowObject.Yes && !C.CompareTag(EmeraldSystem.EmeraldTag))
                {
                    CollisionTime = 10;
                }
                else if (ArrowProjectileRef == ArrowObject.Yes && C.CompareTag(EmeraldSystem.EmeraldTag))
                {
                    CollisionTime = 0;
                }
            }
        }
Exemplo n.º 5
0
        void Update()
        {
            //If the target exceeds the AI's firing angle, fire the projectile towards the last detected destination.
            if (AngleTooBig && !Collided)
            {
                if (TargetTypeRef == TargetType.AI && TargetEmeraldSystem != null && !ProjectileDirectionReceived)
                {
                    AdjustTargetPosition        = TargetEmeraldSystem.HitPointTransform.position - transform.position;
                    ProjectileDirectionReceived = true;
                }
                else if (TargetTypeRef != TargetType.AI && !ProjectileDirectionReceived)
                {
                    AdjustTargetPosition        = EmeraldSystem.m_InitialTargetPosition - new Vector3(EmeraldSystem.transform.position.x, transform.position.y, EmeraldSystem.transform.position.z);
                    ProjectileDirectionReceived = true;
                }

                transform.position = transform.position + AdjustTargetPosition.normalized * Time.deltaTime * ProjectileSpeed;

                if (AdjustTargetPosition != Vector3.zero)
                {
                    transform.rotation = Quaternion.LookRotation(AdjustTargetPosition);
                }
            }

            if (!AngleTooBig)
            {
                //Continue to have our AI projectile follow the direction of its target until it collides with something
                if (!Collided && HeatSeekingRef == HeatSeeking.No && ProjectileDirection != Vector3.zero ||
                    !TargetInView && !Collided && ProjectileDirection != Vector3.zero)
                {
                    DeadTargetDetection();

                    if (TargetTypeRef == TargetType.AI && TargetEmeraldSystem != null && !ProjectileDirectionReceived)
                    {
                        AdjustTargetPosition        = TargetEmeraldSystem.HitPointTransform.position - transform.position;
                        ProjectileDirectionReceived = true;
                    }
                    else if (TargetTypeRef == TargetType.Player && !ProjectileDirectionReceived)
                    {
                        AdjustTargetPosition        = new Vector3(ProjectileDirection.x, ProjectileDirection.y + ProjectileCurrentTarget.localScale.y / 2 + EmeraldSystem.PlayerYOffset, ProjectileDirection.z);
                        ProjectileDirectionReceived = true;
                    }
                    else if (TargetTypeRef == TargetType.NonAITarget && !ProjectileDirectionReceived)
                    {
                        AdjustTargetPosition        = new Vector3(ProjectileDirection.x, ProjectileDirection.y + ProjectileCurrentTarget.localScale.y / 2, ProjectileDirection.z);
                        ProjectileDirectionReceived = true;
                    }

                    transform.position += AdjustTargetPosition.normalized * Time.deltaTime * ProjectileSpeed;
                    transform.rotation  = Quaternion.LookRotation(AdjustTargetPosition);
                }

                if (!Collided && HeatSeekingRef == HeatSeeking.Yes && TargetInView)
                {
                    if (!HeatSeekingFinished)
                    {
                        if (TargetTypeRef == TargetType.AI && TargetEmeraldSystem != null)
                        {
                            AdjustTargetPosition = TargetEmeraldSystem.HitPointTransform.position;
                        }
                        else if (TargetTypeRef == TargetType.Player)
                        {
                            AdjustTargetPosition = new Vector3(ProjectileCurrentTarget.position.x, ProjectileCurrentTarget.position.y + ProjectileCurrentTarget.localScale.y / 2 + EmeraldSystem.PlayerYOffset, ProjectileCurrentTarget.position.z);
                        }
                        else if (TargetTypeRef == TargetType.NonAITarget)
                        {
                            AdjustTargetPosition = new Vector3(ProjectileCurrentTarget.position.x, ProjectileCurrentTarget.position.y + ProjectileCurrentTarget.localScale.y / 2, ProjectileCurrentTarget.position.z);
                        }

                        if (ProjectileCurrentTarget != null)
                        {
                            DeadTargetDetection();

                            transform.position = Vector3.MoveTowards(transform.position, AdjustTargetPosition, Time.deltaTime * ProjectileSpeed);
                            transform.LookAt(AdjustTargetPosition);
                            HeatSeekingTimer += Time.deltaTime;

                            if (HeatSeekingTimer >= HeatSeekingSeconds || TargetEmeraldSystem != null && TargetEmeraldSystem.CurrentHealth <= 0)
                            {
                                LastDirection       = ProjectileCurrentTarget.position - transform.position;
                                HeatSeekingFinished = true;
                            }
                        }
                    }
                    else if (HeatSeekingFinished && LastDirection != Vector3.zero || TargetEmeraldSystem != null && TargetEmeraldSystem.CurrentHealth <= 0)
                    {
                        DeadTargetDetection();

                        if (TargetTypeRef == TargetType.AI && TargetEmeraldSystem != null && !ProjectileDirectionReceived)
                        {
                            AdjustTargetPosition        = TargetEmeraldSystem.HitPointTransform.position - transform.position;
                            ProjectileDirectionReceived = true;
                        }
                        else if (TargetTypeRef != TargetType.AI && !ProjectileDirectionReceived)
                        {
                            AdjustTargetPosition        = new Vector3(LastDirection.x, LastDirection.y, LastDirection.z);
                            ProjectileDirectionReceived = true;
                        }

                        transform.position = transform.position + AdjustTargetPosition.normalized * Time.deltaTime * ProjectileSpeed;

                        if (AdjustTargetPosition != Vector3.zero)
                        {
                            transform.rotation = Quaternion.LookRotation(AdjustTargetPosition);
                        }
                    }
                }
            }

            if (Collided)
            {
                CollisionTimer += Time.deltaTime;
                if (CollisionTimer >= CollisionTime)
                {
                    EmeraldAIObjectPool.Despawn(gameObject);
                }
            }
        }