public void ReconstructPartMap() { if (PartMap == null) { PartMap = new Dictionary <DPart, DestructiblePart>(); } else { PartMap.Clear(); } foreach (var part in Parts) { if (part == null) { continue; } DPart id = part.ID; if (id == DPart.NONE) { Debug.LogWarning("ERROR: Why does '{0}' have a part ID of DPart.NONE??".Form(id)); } if (PartMap.ContainsKey(id)) { Debug.LogError("Duplicate part ID in this damage model - Id: {0}, Name: {1}".Form(id, part.Name)); } else { PartMap.Add(id, part); } } }
public void DealExplosionDamage(float maxDamage, DPart origin, float collateralMultiplier = 1f) { // Simulates an explosion on board based on the relative size and HP of destructible parts. // The origin is the center point of the explosion, so will receive full damage. if (maxDamage <= 0f) { return; } if (origin == DPart.NONE) { return; } if (ContainsPart(origin)) { var part = PartMap[origin]; part.Damage(maxDamage); } else { Debug.LogError("Passed explosion origin part '{0}', but that does not exist on this damage model ({1})".Form(origin, name)); } // Calculate collateral damage. collateralMultiplier = Mathf.Clamp01(collateralMultiplier); foreach (var part in Parts) { if (part == null) { continue; } if (part.ID == origin) { continue; } float damage = CalculateCollarteralDamage(maxDamage * collateralMultiplier, part); part.Damage(damage); } }
public bool ContainsPart(DPart part) { return(PartMap.ContainsKey(part)); }