void ScanForAllSubjects() // get all subjects in the Sight Range { _scanClock = 0; Collider2D[] scanHits = Physics2D.OverlapCircleAll(transform.position, SightRange, ThreatMask); if (LogDebug) { Debug.Log("Scanning " + scanHits.Length + " hits."); } foreach (Collider2D thisHit in scanHits) { if (thisHit.gameObject == gameObject) { continue; // is it me? } Subject otherSubject = thisHit.GetComponentInParent <Subject>(); // TODO this is unfortunately frequent... if (!otherSubject) { continue; // is it null? } if (AllyList.Contains(otherSubject) || ThreatList.ContainsKey(otherSubject)) { continue; // is it a duplicate? } // none of that? then sort the new entry as Ally or Threat. if (StaticUtil.SameTeam(ThisSubject, otherSubject)) { DefineAsAlly(otherSubject); } else { DefineAsThreat(otherSubject, (MyProvokeType == ProvokeType.TargetIsInRange) ? 1 : 0); } } CleanLists(); }
/// <summary> /// Inflict damage to this subject /// </summary> public void DoDamage(int damage, Subject dealer) { if (IsDead) { return; } if (!Options.Data.FriendlyFire && StaticUtil.SameTeam(this, dealer)) { return; } LastAttacker = dealer; if (Stats.HitSound != null) { AudioSource.PlayClipAtPoint(Stats.HitSound, transform.position); } int damageProcessed = damage; #region #### Armor Calculation Block if (Armor > 0) { if (Stats.ArmorType == ArmorType.Absorb) { Armor = Armor - damage; // Absorb damage if (Armor < 0) // If any armor is left, count as excess { damageProcessed = -Armor; Armor = 0; } else { damageProcessed = 0; } } else { damageProcessed = damage - Armor; // Nullify damage if (Armor < 0) // if any is left, count as excess { damageProcessed = -Armor; Armor = 0; } } } #endregion if (damageProcessed < 0) { damageProcessed = 0; } else if (damageProcessed > Stats.Health.Actual) { damageProcessed = (int)Stats.Health.Actual; } Health -= damageProcessed; LastDamage = damageProcessed; Stats.DamageTaken += damageProcessed; LastAttacker.Stats.DamageDealt += damageProcessed; LastAttacker.Stats.ShotsConnected++; StaticUtil.SpawnFloatingText(this, transform.position, damageProcessed.ToString()); if (OnAttacked != null) { OnAttacked(); } }