private void Damaged() { Collider2D[] collider2Ds = Physics2D.OverlapCircleAll(transform.position, Radius, layerTarget); if (collider2Ds == null || collider2Ds.Length == 0) { return; } foreach (Collider2D collider2D in collider2Ds) { DamageData damage = DamageData.Clone; damage.Type = DamageElement.Fire; ITakeHit take = collider2D.gameObject.GetComponent <ITakeHit>(); if (take != null) { float Distance = Vector2.Distance(take.GetCollider().bounds.center, transform.position); Distance = Mathf.Clamp(Distance, 0f, Radius); damage.Damage = (int)(((float)((Radius - Distance) / Radius)) * Damage); damage.BackForce = ((Radius - Distance) / (Radius)) * BackFore; damage.Direction = (take.GetCollider().bounds.center - transform.position).normalized; damage.FireRatio = 1f; damage.FromTNT = true; take.TakeDamaged(damage); } } }
private void TakeHit(DamageData damageData, ITakeHit takeHit) { damageData.Direction = (takeHit.GetCollider().bounds.center - transform.position).normalized; takeHit.TakeDamaged(damageData.Clone); listTH.Add(takeHit); ShowVFX(takeHit.GetCollider()); }
protected override void OnHitTarget(ITakeHit take, Vector3 point) { if (take is TakeDamage) { targetHit = ((TakeDamage)take).entity; } base.OnHitTarget(take, point); }
protected virtual void OnHitTarget(ITakeHit take, Vector3 point) { DamageData da = damage.Clone; da.PointHit = point; take.TakeDamaged(da); Destroyed(point); }
private IEnumerator DoAttack(ITakeHit target) { yield return(new WaitForSeconds(attackImpactDelay)); if (target.Alive && InAttackRange(target)) { target.TakeHit(this); } }
internal bool InAttackRange(ITakeHit target) { if (!target.Alive) { return(false); } var distance = Vector3.Distance(transform.position, target.transform.position); return(distance < attackRange); }
private bool isExits(ITakeHit takeHit, List <ITakeHit> takeHits) { foreach (ITakeHit take in takeHits) { if (takeHit == take) { return(true); } } return(false); }
private void CheckCollider(Collider2D collision) { if (GameController.isLayerIn(collision.gameObject, TargetLayerAttack)) { ITakeHit takeHit = collision.gameObject.GetComponent <ITakeHit>(); if (takeHit != null && !isExits(takeHit, listTH)) { TakeHit(damageData, takeHit); } } }
protected override void OnHitTarget(ITakeHit take, Vector3 point) { if (take is TakeDamage && skipGameobject != null) { if (skipGameobject != null && ((TakeDamage)take).entity != null && ((TakeDamage)take).entity == skipGameobject) { return; } } base.OnHitTarget(take, point); }
private void HandleImpact() { int hitCount = Physics2D.OverlapCircleNonAlloc(attackDirection.position + attackDirection.forward, attackRadius, _attackResults); for (int i = 0; i < hitCount; i++) { ITakeHit takeHit = _attackResults[i].GetComponent <ITakeHit>(); if (takeHit != null) { Attack(takeHit); } } }
protected override void OnHitTarget(ITakeHit take, Vector3 point) { DamageData da = damage.Clone; da.PointHit = point; attaked.Add(take.GetCollider()); take.TakeDamaged(da); if (VFXDestroyed != null) { Quaternion rotation = Quaternion.Euler(new Vector3(0, 0, Random.Range(0, 360f))); OnDestroyed(pool.Spawn(id_pooling_vfx, transform.position, rotation) as ControlPartice); } }
protected virtual void Shoot(DamageData damage) { laser.Lit(out RaycastHit2D ray, out bool has); if (!has) { return; } DamageData damageData = damage.Clone; if (ray.collider == null) { return; } ITakeHit takehit = ray.collider.GetComponent <ITakeHit>(); if (ReadyToDamaged(takehit)) { SetUpDamageData(damageData); takehit.TakeDamaged(damageData); } }
protected virtual void Daming() { Collider2D[] cols = Physics2D.OverlapCircleAll(transform.position, Radius, target); if (cols == null || cols.Length == 0) { return; } else { foreach (Collider2D col in cols) { ITakeHit take = col.GetComponent <ITakeHit>(); if (ReadyToDamaged(take)) { DamageData damage = new DamageData(); SetUpDamageData(damage); damage.Direction = Vector3.zero; take.TakeDamaged(damage); takehits.Add(new TimeToTakeHit(take, Time.time)); } } } }
protected virtual bool ReadyToDamaged(ITakeHit take) { if (take == null) { return(false); } TimeToTakeHit tt = Array.Find(takehits.ToArray(), e => e.takeHit == take); if (tt == null) { takehits.Add(new TimeToTakeHit(take, Time.time)); return(true); } if (Time.time - tt.time > distanceTakeDamage) { tt.time = Time.time; return(true); } else { return(false); } }
protected virtual void Attacking() { Collider2D[] cols = Physics2D.OverlapCircleAll(center, radius, layerAttack); if (cols == null || cols.Length == 0) { return; } else { foreach (Collider2D col in cols) { ITakeHit take = col.GetComponent <ITakeHit>(); if (ReadyToDamaged(take)) { DamageData damage = new DamageData(); SetUpDamageData(damage); damage.Direction = Direct_Attack; take.TakeDamaged(damage); takehits.Add(new TimeToTakeHit(take, Time.time)); } } } }
void Damaging() { Collider2D[] collider2Ds = Physics2D.OverlapCircleAll(transform.position, 2f, Target); if (collider2Ds == null || collider2Ds.Length == 0) { return; } DamageData damageData = new DamageData(); damageData.Damage = 3; damageData.PoisonFrom = true; damageData.Type = DamageElement.Poison; foreach (Collider2D collider2D in collider2Ds) { DamageData damage = damageData.Clone; ITakeHit take = collider2D.gameObject.GetComponent <ITakeHit>(); if (take != null && Vector2.Distance(transform.position, take.GetCollider().bounds.center) < 2f) { damage.BackForce = 0; damage.Direction = Vector3.zero; take.TakeDamaged(damage); } } }
public void Attack(ITakeHit target) { attackTimer = 0; target.TakeHit(this); }
public virtual void Attack(ITakeHit takeHit) { takeHit.TakeHit(this); }
protected void AttackRoutine() { _attackSound.Play(); StartCoroutine("FireVFX"); HashSet <ITakeHit> hitSet = new HashSet <ITakeHit>(); Dictionary <ITakeHit, List <Transform> > transformListDic = new Dictionary <ITakeHit, List <Transform> >(); Dictionary <ITakeHit, List <Vector3> > normalListDic = new Dictionary <ITakeHit, List <Vector3> >(); // Penetrating Effect if (modificationEffects.isPenetrating) { Ray environmentRay; RaycastHit environmentHit; for (int i = 0; i < Stats.pelletsPerShot; i++) { // Looks For Any Walls Blocking the Ray environmentRay = GetBulletSpreadRay(_currentSpread); // If There Is if (Physics.Raycast(environmentRay, out environmentHit, 100f, RaycastLayers.EnvironmentLayer, QueryTriggerInteraction.Ignore)) { float distance = Vector3.Distance(_playerCam.transform.position, environmentHit.point); RaycastHit[] hits = Physics.RaycastAll(environmentRay, distance * 1.01f, RaycastLayers.BulletLayer, QueryTriggerInteraction.Ignore); if (hits.Length > 0) { foreach (RaycastHit hit in hits) { ITakeHit hitTarget = hit.transform.root.GetComponent <ITakeHit>(); if (hitTarget != null) { if (hitSet.Contains(hitTarget)) { transformListDic[hitTarget].Add(hit.transform); normalListDic[hitTarget].Add(hit.normal); } else { hitSet.Add(hitTarget); transformListDic[hitTarget] = new List <Transform> { hit.transform }; normalListDic[hitTarget] = new List <Vector3> { hit.normal }; } } else { InstantiateHitImpact(hit.transform.tag, hit.transform, hit.point, hit.normal); } // Bullet Push Rigidbody rb = hit.rigidbody; if (rb != null) { rb.AddForceAtPosition(environmentRay.direction.normalized * _stats.concussionPerPellet, hit.point, ForceMode.VelocityChange); rb.AddTorque(environmentRay.direction.normalized * _stats.concussionPerPellet * 2, ForceMode.VelocityChange); } } } } // If There Is Not else { Debug.Log("Did not hit wall"); RaycastHit[] hits = Physics.RaycastAll(environmentRay, 100f, (RaycastLayers.BulletLayer & ~RaycastLayers.EnvironmentLayer), QueryTriggerInteraction.Ignore); if (hits.Length > 0) { foreach (RaycastHit hit in hits) { string hitTag = hit.transform.tag; ITakeHit hitTarget = hit.transform.root.GetComponent <ITakeHit>(); if (hitTarget != null) { if (hitSet.Contains(hitTarget)) { transformListDic[hitTarget].Add(hit.transform); normalListDic[hitTarget].Add(hit.normal); } else { hitSet.Add(hitTarget); transformListDic[hitTarget] = new List <Transform> { hit.transform }; normalListDic[hitTarget] = new List <Vector3> { hit.normal }; } } else { InstantiateHitImpact(hit.transform.tag, hit.transform, hit.point, hit.normal); } // Bullet Push Rigidbody rb = hit.rigidbody; if (rb != null) { rb.AddForceAtPosition(environmentRay.direction.normalized * _stats.concussionPerPellet, hit.point, ForceMode.VelocityChange); rb.AddTorque(environmentRay.direction.normalized * _stats.concussionPerPellet * 2, ForceMode.VelocityChange); } } } } } foreach (ITakeHit hitTarget in hitSet) { Transform[] transformArray = transformListDic[hitTarget].ToArray(); Vector3[] normalArray = normalListDic[hitTarget].ToArray(); if (transformArray.Length != normalArray.Length) { continue; } else { hitTarget.OnHit(transformArray, normalArray, _stats.damagePerPellet, _stats.concussionPerPellet, false); } } } else { Ray ray; RaycastHit hit; for (int i = 0; i < Stats.pelletsPerShot; i++) { ray = GetBulletSpreadRay(_currentSpread); if (Physics.Raycast(ray, out hit, 100f, RaycastLayers.BulletLayer, QueryTriggerInteraction.Ignore)) { ITakeHit hitTarget = hit.transform.root.GetComponent <ITakeHit>(); if (hitTarget != null) { if (hitSet.Contains(hitTarget)) { transformListDic[hitTarget].Add(hit.transform); normalListDic[hitTarget].Add(hit.normal); } else { hitSet.Add(hitTarget); transformListDic[hitTarget] = new List <Transform> { hit.transform }; normalListDic[hitTarget] = new List <Vector3> { hit.normal }; } } else { InstantiateHitImpact(hit.transform.tag, hit.transform, hit.point, hit.normal); } // Bullet Push Rigidbody rb = hit.rigidbody; if (rb != null) { rb.AddForceAtPosition(ray.direction.normalized * _stats.concussionPerPellet, hit.point, ForceMode.VelocityChange); rb.AddTorque(ray.direction.normalized * _stats.concussionPerPellet * 2, ForceMode.VelocityChange); } } } foreach (ITakeHit hitTarget in hitSet) { Transform[] transformArray = transformListDic[hitTarget].ToArray(); Vector3[] normalArray = normalListDic[hitTarget].ToArray(); if (transformArray.Length != normalArray.Length) { continue; } else { hitTarget.OnHit(transformArray, normalArray, _stats.damagePerPellet, _stats.concussionPerPellet, false); } } } }
private void Explode() { _exploding = true; // VFX if (_grenadeCard.explosionVFX != null) { GameObject explosion = Instantiate(_grenadeCard.explosionVFX); explosion.transform.position = transform.position; } // Camera Shake PlayerCharacter player = GameManager.Instance.Player; PlayerCamera playerCamera = CameraManager.Instance.PlayerCamera; if (playerCamera != null && player != null) { if (Vector3.Distance(transform.position, player.transform.position) < _grenadeCard.explosionRadius) { playerCamera.ShakeCameraExplosionMajor(); } else { playerCamera.ShakeCameraExplosionMedium(); } } // Search and Damage characters or grenades HashSet <ITakeHit> hitSet = new HashSet <ITakeHit>(); Dictionary <ITakeHit, List <Transform> > transformListDic = new Dictionary <ITakeHit, List <Transform> >(); Dictionary <ITakeHit, List <Vector3> > normalListDic = new Dictionary <ITakeHit, List <Vector3> >(); RaycastHit[] raycastHits = Physics.SphereCastAll(new Ray(transform.position, transform.up), _grenadeCard.explosionRadius, 0.1f, RaycastLayers.ExplosionLayer); foreach (RaycastHit hit in raycastHits) { // Exclude itself if (hit.transform == transform) { continue; } // Check if there's a wall (or any environmetal object blocking the blast) if (Physics.Raycast(new Ray(transform.position, hit.transform.position), hit.distance * 1.01f, RaycastLayers.EnvironmentLayer)) { continue; } Rigidbody hitRB = hit.rigidbody; ITakeHit hitTarget = hit.transform.root.GetComponent <ITakeHit>(); if (hitRB != null) { Vector3 relVec = (hit.transform.position - transform.position); float forceMagnitude = Mathf.Clamp(_grenadeCard.explosionRadius / Vector3.Magnitude(relVec), 0.01f, 5f) * _grenadeCard.explosionForce; hitRB.AddForceAtPosition(relVec.normalized * forceMagnitude, hit.point, ForceMode.Impulse); } if (hitTarget != null) { if (hitSet.Contains(hitTarget)) { transformListDic[hitTarget].Add(hit.transform); normalListDic[hitTarget].Add(hit.normal); } else { hitSet.Add(hitTarget); transformListDic[hitTarget] = new List <Transform> { hit.transform }; normalListDic[hitTarget] = new List <Vector3> { hit.normal }; } } } foreach (ITakeHit hitTarget in hitSet) { Transform[] transformArray = transformListDic[hitTarget].ToArray(); Vector3[] normalArray = normalListDic[hitTarget].ToArray(); if (transformArray.Length != normalArray.Length) { continue; } else { hitTarget.OnHit(transformArray, normalArray, _grenadeCard.damage, _grenadeCard.concussion, true); } } Destroy(gameObject); }
public TakeHitWithPartice(ITakeHit take, ControlPartice con) { this.take = take; this.control = con; }
private void Awake() { entity = GetComponent <ITakeHit>(); }
public TimeToTakeHit(ITakeHit takeHit, float time) { this.takeHit = takeHit; this.time = time; }
public void DealDamage(ITakeHit to) { to.GetHit(); onCollision?.Invoke(); }
public void Attack(ITakeHit target) //why not Character or Enemy parameter? { attackTimer = 0; target.TakeHit(this); }
private void Impact(ITakeHit hit) { impactParticlePrefab.Get <PooledMonoBehaviour>(transform.position, Quaternion.identity); hit.TakeHit(this); ReturnToPool(); }
protected virtual void OnTakeHit(ITakeHit takeHit, DamageData damage) { damage.Direction = Host.DirectFire; takeHit.TakeDamaged(damage); }