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; } } }
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); } }
//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; } } }