Exemple #1
0
 private void OnCollision(Transform other)
 {
     if (other.transform.GetComponent <Fighter>())
     {
         Fighter f = other.transform.GetComponent <Fighter>();
         CombatMessageManager.AddMessage("Bullet collision with fighter." + transform.name + " - " + f.name, 0);
         if (f.data.stats.alliance != stats.alliance)
         {
             CombatMessageManager.AddMessage("Bullet collision with enemy fighter." + transform.name + " - " + f.name, 1);
             GameManager.Instance.fighterBehaviour.ApplyDmg(stats.damage, f);
             Destroy(gameObject);
         }
     }
     if (other.transform.GetComponent <StationModule>())
     {
         StationModule f = other.transform.GetComponent <StationModule>();
         CombatMessageManager.AddMessage("Bullet collision with station." + transform.name + " - " + f.name, 0);
         if (f.stats.alliance != stats.alliance)
         {
             CombatMessageManager.AddMessage("Bullet collision with enemy station." + transform.name + " - " + f.name, 1);
             GameManager.Instance.fighterBehaviour.ApplyDmg(stats.damage, f);
             Destroy(gameObject);
         }
     }
 }
    void ApplyDmg(int dmg, UnitStats stats, GameObject source, IDestructible destructibleSource)
    {
        if (dmg == 0 || stats == null)
        {
            return;
        }
        int nextShield = Mathf.Clamp(stats.shields - dmg, 0, stats.shields);
        int nextHp     = stats.health - Mathf.CeilToInt((Mathf.Clamp(dmg - stats.shields, 0, dmg)) * (1f - stats.armor));

        CombatMessageManager.AddMessage("DMG: " + dmg + " armor(hp):" + (100 - stats.armor * 100) +
                                        string.Format("Set shields on {0} {1} -> {2}", source.name, stats.shields, nextShield) +
                                        "Set hp on " + source.name + " " + stats.health + " -> " + nextHp, 10);
        stats.SetShields(nextShield, source);
        stats.SetHp(nextHp, source, destructibleSource);
    }