/// <summary> /// Handles incoming damage /// </summary> /// <param name="Damage">Amount of incoming damage</param> /// <returns>Status result and remaining damage</returns> public DefenseResult TakeHit(int Damage, string damageType) { DefenseResult result = new DefenseResult(); if (HP.Current <= 0) { result.Remainder = Damage; result.Messages.Add(string.Format("{0} is {1}!", this.Name, DownAdjective)); return(result); } int DR = 0; if (damageType == DamageType.Energy) { DR = this.DRVsEnergy; } else if (damageType == DamageType.Plasma) { DR = this.DRVsPlasma; } else if (damageType == DamageType.Explosive) { DR = this.DRVsExplosive; } else if (damageType == DamageType.Kinetic) { DR = this.DRVsKinetic; } if (Damage <= DR) { result.Remainder = 0; result.Messages.Add(string.Format("Bounces off {0} for No Damage!", this.Name)); } else { int afterDR = Damage - DR; if (afterDR >= HP.Current) { result.Remainder = afterDR - HP.Current; result.Messages.Add(string.Format("Hits {0} for {1}{2}, {3} It!", this.Name, HP.Current, (DR > 0 ? string.Format("(DR: {0})", DR) : string.Empty), PenetrateVerb)); HP.Current = 0; } else { result.Remainder = 0; result.Messages.Add(string.Format("Hits {0} for {1}{2}", this.Name, afterDR, (DR > 0 ? string.Format("(DR: {0})", DR) : string.Empty))); HP.Current -= afterDR; } } return(result); }
/// <summary> /// Handles incoming damage to the Ship through any equipped DefenseParts, including resistance based on damage type /// </summary> /// <param name="damage">Amount of damage to take</param> /// <param name="damageType">Type of damage to take (Data Driven)</param> /// <returns>List of status results from DefenseParts</returns> public List <string> HitFor(int damage, string damageType, out bool isDestroyed) { List <string> result = new List <string>(); isDestroyed = false; // loop through all defense parts and apply the damage to each foreach (DefensePart defense in Parts.Where(f => f is DefensePart && !f.IsDestroyed)) { DefenseResult res = defense.TakeHit(damage, damageType); damage = res.Remainder; foreach (string message in res.Messages) { result.Add(string.Format(" ==> {0}", message)); } if (damage <= 0) { break; } } // if there is any damage that got past the defense parts... if (damage > 0) { // decrease current HP HP.Current -= damage; result.Add(string.Format("{0} Damage made it through!", damage)); // chance to destroy ship part using (RNG rand = new RNG()) { // 50% chance of a part being affected int countOfEquipment = Parts.Count * 2; int random = rand.d(countOfEquipment); if (random <= Parts.Count) { // only matters if the selected part isn't already destroyed if (!Parts[random - 1].IsDestroyed) { Parts[random - 1].IsDestroyed = true; result.Add(string.Format("{0} is destroyed by the damage!", Parts[random - 1].Name)); } } } // oh no, we died! if (HP.Current <= 0) { isDestroyed = true; IsDestroyed = true; } } return(result); }