public void OnDamageTouch(IDamaging ec) { if (invincLeft > 0) { return; } if (lastHit < Time.time - .75 && alive) { int damage = (int)Random.Range(ec.GetDamageRange().x *GameController.maincontroller.difficutlyScale, ec.GetDamageRange().y *GameController.maincontroller.difficutlyScale + 1); AchievementTracker.instance.GetDamage(damage); this.health -= damage; if (damage > 0) { Grunt(); } if (health <= 0) { health = 0; if (alive) { Die(); } } uic.DisplayHearts(this.health, this.maxhealth); lastHit = Time.time; } }
private void AbsordBullets(IDamaging damaging) { if (m_CurrentCount < m_MaxBullets) { m_CurrentCount += damaging.BulletsToGiveShield; } OnBulletAbsorbed(); }
public Int32 Attack(IDamaging damagingItem) { HealthPoints -= damagingItem.Damage; if (HealthPoints <= 0) { Die(); } return(damagingItem.Damage); }
public virtual void OnCollisionEnter(Collision c) { IDamaging damaging = c.collider.GetComponent(typeof(IDamaging)) as IDamaging; if (damaging != null) { damaging.ApplyDamage(mSerpent); } }
private void OnTriggerExit(Collider other) { IDamaging damaging = GetIDamaging(other.gameObject); if (damaging != null && _damageable != null && this.gameObject.tag != damaging.IgnoreCollisionTag) { damaging.UnregisterHit(); } }
void OnCollisionEnter2D(Collision2D other) { IDamaging dmg = other.gameObject.GetComponent <IDamaging>(); if (dmg != null && !invincible) { Damage(dmg.GetDamageDealt()); } }
protected bool CheckIfIDamagableIsActive(IDamaging checkDamaging) { var ret = checkDamaging.IsAvailableForConsumption(this) && !IsAChild(checkDamaging); if (ret && checkDamaging.HasImmuneTargets) { //If it is not in the immunetargets collection, it should do damage ret = !checkDamaging.ImmuneTargets.Any(c => c == this); } return ret; }
protected bool CheckIfIDamagableIsActive(IDamaging checkDamaging) { var ret = checkDamaging.IsAvailableForConsumption(this) && !IsAChild(checkDamaging); if (ret && checkDamaging.HasImmuneTargets) { //If it is not in the immunetargets collection, it should do damage ret = !checkDamaging.ImmuneTargets.Any(c => c == this); } return(ret); }
private void OnTriggerEnter(Collider other) { IDamaging damaging = GetIDamaging(other.gameObject); if (damaging != null && _damageable != null && this.gameObject.tag != damaging.IgnoreCollisionTag) { if (damaging.DamageType == DamageType.INSTANTANEOUS || damaging.DamageType == DamageType.BOTH) { bool blocked = _damageable.TakeDamage(damaging.DamageInstantaneous); damaging.RegisterHit(blocked); } } }
private void OnTriggerStay(Collider other) { IDamaging damaging = GetIDamaging(other.gameObject); if (damaging != null && _damageable != null && this.gameObject.tag != damaging.IgnoreCollisionTag) { if (damaging.DamageType == DamageType.OVER_TIME || damaging.DamageType == DamageType.BOTH) { bool blocked = _damageable.TakeDamage(damaging.DamageOverTime * Time.deltaTime); damaging.RegisterHit(blocked); } } }
private void OnCollisionEnter2D(Collision2D collision) { IDamaging dmg = collision.gameObject.GetComponent <IDamaging>(); if (dmg != null) { animator.SetTrigger("Hit"); for (int i = 0; i <= dmg.GetDamageDealt(); i++) { barrier.TakeDamage(); } } }
protected virtual void OnCollisionEnter(Collision collision) { if (_hitParticlePrefab != null) { CreatePrefab(_hitParticlePrefab, collision.contacts[0].point); } IDamaging damaging = collision.collider.GetComponent <IDamaging>(); if (damaging != null) { TakeDamage(damaging.Damage); } }
protected Vector2 GetPointOfImpact(IDamaging chkDamaging, Collider2D targetCollider, Transform sourceReference, int raycastIterationsToFindTarget = 5, float raycastVariationPerTry = 0.1f) { Vector2 ret = new Vector2(); var othersPosition = targetCollider.gameObject.transform.position - sourceReference.position; RaycastHit2D hit = default(RaycastHit2D); if (chkDamaging.HasPreferredImpactPoint) { ret = chkDamaging.PreferredImpactPoint; } else { if (_legacyGetPointOfImpact) { for (int i = 0; i < raycastIterationsToFindTarget; i++) { var firstTarget = new Vector3(othersPosition.x + raycastVariationPerTry * i, othersPosition.y + raycastVariationPerTry * i, othersPosition.z); hit = Physics2D.Raycast(sourceReference.position, firstTarget, float.MaxValue); if (hit.collider == targetCollider) { break; } var secondTarget = new Vector3(othersPosition.x - raycastVariationPerTry * i, othersPosition.y - raycastVariationPerTry * i, othersPosition.z); hit = Physics2D.Raycast(sourceReference.position, secondTarget, float.MaxValue); if (hit.collider == targetCollider) { break; } } ret = hit.point; } else { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(sourceReference.position, othersPosition, Vector3.Distance(sourceReference.position, othersPosition)); //Debug.DrawRay(sourceReference.position, othersPosition, Color.green); hit = hits.FirstOrDefault(c => c.collider == targetCollider); ret = hit.point; if (hit == default(RaycastHit2D)) { ret = sourceReference.transform.position; } } } return(ret); }
protected virtual void Collision(GameObject other) { IDamageable damageable = other.GetComponent <IDamageable>(); if (damageable != null) { OnCollisionWithDamageable?.Invoke(damageable); } IDamaging damaging = other.GetComponent <IDamaging>(); if (damaging != null) { OnCollisionWithDamaging?.Invoke(damaging); } }
//private void OnCollisionEnter(Collision col) //{ // GameObject other = col.gameObject; // IDamaging damaging = GetIDamaging(other); // if (damaging != null && _damageable != null && this.gameObject.tag != damaging.IgnoreCollisionTag) // { // if (damaging.DamageType == DamageType.INSTANTANEOUS || damaging.DamageType == DamageType.BOTH) // { // bool blocked = _damageable.TakeDamage(damaging.DamageInstantaneous); // damaging.RegisterHit(blocked); // } // } //} private IDamaging GetIDamaging(GameObject obj) { IDamaging d = null; foreach (MonoBehaviour b in obj.GetComponents <MonoBehaviour>()) { d = b as IDamaging; if (d != null) { break; } } return(d); }
public void AddKnockBack(IDamaging impact) { Vector2 angle = impact.ImpactForceSettings.ImpactAngle; if (impact.ImpactForceSettings.DirectionComingForm == Direction2D.Right) { angle.x = -angle.x; } // normalize and add impulse value angle = angle.normalized * impact.ImpactForceSettings.ImpactForce * _impactForceModifier; _mainRigidbody.velocity = Vector2.zero; _mainRigidbody.AddForce(angle, m_ForceType); //set values for cooldown _DragResetDelay = impact.ImpactForceSettings.ImpactDragTimer; StartCoroutine(DashDragReset(_DragResetDelay, _mainRigidbody)); }
private bool DamagingDoesDamage(IDamaging checkDamaging, Vector2 pointOfCollision, out float damage) { bool ret = true; damage = checkDamaging.Damage; //Debug.Log("original Damage = " + damage); if (checkDamaging.ImpactForceSettings.IsFadeDmgOnDistance) { var distance = Vector2.Distance(checkDamaging.gameObject.transform.position, transform.position); if (distance <= checkDamaging.ImpactForceSettings.FadeMaxDmgDistance) { damage = damage * (checkDamaging.ImpactForceSettings.FadeMaxDmgDistance - distance) / checkDamaging.ImpactForceSettings.FadeMaxDmgDistance; } else { ret = false; } } //Debug.Log("afterCalc Damage = " + damage); return(ret); }
public void AddKnockBack(IDamaging impact) { if (m_CanDash) { m_DashTimer = float.MaxValue; m_CanDash = false; m_AirControl = false; m_Rigidbody2D.drag = impact.ImpactForceSettings.ImpactDrag; Vector2 angle = impact.ImpactForceSettings.ImpactAngle; // if grounded force y to positive if (IsGrounded && angle.y < 0) { angle.y = 0f; } // if not facing right force x negative //if (!m_Controller.m_FacingRight && angle.x > 0) angle.x = -angle.x; if (impact.ImpactForceSettings.DirectionComingForm == Direction2D.Right) { angle.x = -angle.x; } //print(angle); // normalize and add impulse value angle = angle.normalized * impact.ImpactForceSettings.ImpactForce; m_Rigidbody2D.velocity = Vector2.zero; m_Rigidbody2D.AddForce(angle, m_DashType); //set values for cooldown m_DashTimer = Time.time + impact.ImpactForceSettings.ImpactDragTimer; StartCoroutine(DashDragReset(m_DashDragRemove, m_Rigidbody2D)); } }
/// <summary> /// Take damage if the damage is from the player /// </summary> /// <param name="damageItem">The other world item that this boss collided with</param> public void TakeDamage(IDamaging damageItem) { if ((this.TakesDamageFrom != damageItem.DoesDamageTo) && !currentState.Equals("Dead") && !invincible) { //Can be used for when bullets hit the body of the boss this.World.playSound("nogoodHit"); SetAIState(hitAIState); ChangeState("Hit"); currentAIState.Update(); currentHealth -= (int)Math.Ceiling((MitigationFactor * damageItem.AmountOfDamage)); if (currentHealth > 0) { invincible = true; } if (facing == SpriteEffects.FlipHorizontally) { NetForce += (-1) * deathPushBack; } else { NetForce += deathPushBack; } Projectile p = damageItem as Projectile; if (p != null) { this.World.RemoveWorldObject(p); Dispose(); } if (currentHealth <= 0) { shootAIState.StopTimer(); jumpAIState.StopTimers(); } } }
/// <summary> /// Take damage if the damage is from the player /// </summary> /// <param name="damageItem">The other world item that this bandit collided with</param> public void TakeDamage(IDamaging damageItem) { if ((this.TakesDamageFrom != damageItem.DoesDamageTo) && !currentState.Equals("Dead")) { currentHealth -= (int)Math.Ceiling((MitigationFactor * damageItem.AmountOfDamage)); if (facing == SpriteEffects.FlipHorizontally) { NetForce += (-1) * deathPushBack; } else { NetForce += deathPushBack; } Projectile p = damageItem as Projectile; if (p != null) { this.World.RemoveWorldObject(p); Dispose(); } if (currentHealth <= 0) { this.World.playSound("banditDeath"); ChangeState("Dead"); } } }
public void AddKnockBack(IDamaging impact) { Vector2 angle = impact.ImpactForceSettings.ImpactAngle; if (impact.ImpactForceSettings.DirectionComingForm == Direction2D.Right) angle.x = -angle.x; // normalize and add impulse value angle = angle.normalized * impact.ImpactForceSettings.ImpactForce * _impactForceModifier; _mainRigidbody.velocity = Vector2.zero; _mainRigidbody.AddForce(angle, m_ForceType); //set values for cooldown _DragResetDelay = impact.ImpactForceSettings.ImpactDragTimer; StartCoroutine(DashDragReset(_DragResetDelay, _mainRigidbody)); }
private void AbsordBullets(IDamaging damaging) { if (m_CurrentCount < m_MaxBullets) m_CurrentCount += damaging.BulletsToGiveShield; OnBulletAbsorbed(); }
private bool DamagingDoesDamage(IDamaging checkDamaging, Vector2 pointOfCollision, out float damage) { bool ret = true; damage = checkDamaging.Damage; //Debug.Log("original Damage = " + damage); if (checkDamaging.ImpactForceSettings.IsFadeDmgOnDistance) { var distance = Vector2.Distance(checkDamaging.gameObject.transform.position, transform.position); if (distance <= checkDamaging.ImpactForceSettings.FadeMaxDmgDistance) { damage = damage * (checkDamaging.ImpactForceSettings.FadeMaxDmgDistance - distance)/ checkDamaging.ImpactForceSettings.FadeMaxDmgDistance; } else { ret = false; } } //Debug.Log("afterCalc Damage = " + damage); return ret; }
public void TakeDamage(IDamaging damageItem) { currentHealth -= damageItem.AmountOfDamage; if (currentHealth <= 0) { Destruct(); } }
public void TakeDamage(IDamaging damageItem) { this.currentHealth -= damageItem.AmountOfDamage; }
/// <summary> /// If the proper damage type is done subtract from the current health /// </summary> /// <param name="damageItem">The other world object that the player collided with</param> public void TakeDamage(IDamaging damageItem) { if ((this.TakesDamageFrom != damageItem.DoesDamageTo) && (damageItem.AmountOfDamage != 0) && !invincible) { ChangeState("Hit"); this.World.playSound("hitTemp"); if (facing == SpriteEffects.FlipHorizontally) { NetForce += (-1) * hitPushBack; } else { NetForce += hitPushBack; } currentHealth -= (int)Math.Ceiling((MitigationFactor * damageItem.AmountOfDamage)); if (currentHealth > 0) { invincible = true; } BossProjectile bp = damageItem as BossProjectile; if (bp != null && !currentState.Contains("Dead")) { bp.InformOwnerOfCollision(); this.World.RemoveWorldObject(bp); Dispose(); } Projectile p = damageItem as Projectile; if (p != null && !currentState.Contains("Dead")) { this.World.RemoveWorldObject(p); Dispose(); } } }
public void AddKnockBack(IDamaging impact) { if (m_CanDash) { m_DashTimer = float.MaxValue; m_CanDash = false; m_AirControl = false; m_Rigidbody2D.drag = impact.ImpactForceSettings.ImpactDrag; Vector2 angle = impact.ImpactForceSettings.ImpactAngle; // if grounded force y to positive if (IsGrounded && angle.y < 0) angle.y = 0f; // if not facing right force x negative //if (!m_Controller.m_FacingRight && angle.x > 0) angle.x = -angle.x; if (impact.ImpactForceSettings.DirectionComingForm == Direction2D.Right) angle.x = -angle.x; //print(angle); // normalize and add impulse value angle = angle.normalized * impact.ImpactForceSettings.ImpactForce; m_Rigidbody2D.velocity = Vector2.zero; m_Rigidbody2D.AddForce(angle, m_DashType); //set values for cooldown m_DashTimer = Time.time + impact.ImpactForceSettings.ImpactDragTimer; StartCoroutine(DashDragReset(m_DashDragRemove, m_Rigidbody2D)); } }
/// <summary> /// Take damage if the damage is from the player /// </summary> /// <param name="damageItem">The other world item that this bandit collided with</param> public void TakeDamage(IDamaging damageItem) { if (this.TakesDamageFrom != damageItem.DoesDamageTo) { if (damageItem is Projectile && !currentState.Equals("Dead")) { this.World.RemoveWorldObject(damageItem as Projectile); Dispose(); } currentHealth -= (int)Math.Ceiling((MitigationFactor * damageItem.AmountOfDamage)); if (currentHealth <= 0) { ChangeState("Dead"); this.amountOfDamage = 0; } } }
public bool IsAChild(IDamaging toCheck) { var checkComponents = GetComponentsInChildren <IDamaging>(); return(checkComponents.Any(c => c == toCheck)); }
void Awake() { thisCollider = GetComponent <Collider> (); parentDamageable = GetComponentInParent <IDamaging> (); }