public void AttackTarget() { if (CurrentTarget != null) { if (Vector3.Distance(transform.position, CurrentTarget.position) <= StoppingDistanceCombat) { Damage = Random.Range(MinDamage, MaxDamage); bool CriticalHit = GenerateCritOdds(); if (CriticalHit) { Damage = Mathf.RoundToInt(Damage * CritMultiplier); if (CameraShake.Instance != null) { CameraShake.Instance.ShakeCamera(0.32f, 0.35f); } PlayCriticalHitSound(); } else { PlayImpactSound(); } CombatTextSystem.Instance.CreateCombatText(Damage, CurrentTarget.position, CriticalHit, false, false); EmeraldAISystem m_EmeraldComponent = CurrentTarget.GetComponent <EmeraldAISystem>(); m_EmeraldComponent.Damage(Damage, EmeraldAISystem.TargetType.Player, transform, 300); m_EmeraldComponent.AIRenderer.material.SetFloat("_DamageFlash", 0.75f); StartCoroutine(DamageFlash(m_EmeraldComponent.AIRenderer)); UpdateHUD(); if (ImpactEffect != null) { EmeraldAI.Utility.EmeraldAIObjectPool.SpawnEffect(ImpactEffect, CurrentTarget.position + new Vector3(0, CurrentTarget.localScale.y * 0.5f, 0), Quaternion.identity, 1); } if (m_EmeraldComponent.IsDead) { StopHUDFade(); FadeHUDCoroutine = StartCoroutine(FadeHUD(2, 1)); if (TargetIndicatorType == TargetIndicatorEnum.Shader) { m_EmeraldComponent = CurrentTarget.GetComponent <EmeraldAISystem>(); m_EmeraldComponent.AIRenderer.material.SetInt("_OutlineEnabled", 0); } CurrentTarget = null; if (TargetIndicatorType == TargetIndicatorEnum.ObjectRing) { TargetIndicator.SetActive(false); } return; } PlayImpactSound(); } } }
public DamageResult AddDamage(float damage) { if (m_Multiplier > 0f) { int scaledDamage = Mathf.CeilToInt(damage * m_Multiplier); if (CombatTextSystem.Instance != null) { CombatTextSystem.Instance.CreateCombatTextAI(scaledDamage, transform.position, m_Critical, false); } m_EmeraldAISystem.Damage(scaledDamage); return(m_Critical ? DamageResult.Critical : DamageResult.Standard); } else { return(DamageResult.Ignored); } }
void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray; RaycastHit hit; ray = CameraComponent.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 50)) { if (hit.collider.GetComponent <EmeraldAISystem>() != null) { //Get a reference to the EmeraldAISystem script that is hit by the raycast. EmeraldAISystem EmeraldComponent = hit.collider.GetComponent <EmeraldAISystem>(); //Cause damage to the AI that is hit using the Emerald AI damage function. //This is can be a helpfull example for users who have VR games or games where the player is the camera. //In this case, the PlayerObject is a child of the camera. EmeraldComponent.Damage(DamageAmount, EmeraldAISystem.TargetType.Player, PlayerObject.transform, 400); } } } }
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; } } }