private bool CheckBuildingHit(RaycastHit hit) { DestructibleBuilding building = null; try { building = hit.collider.gameObject.GetComponentUpwards <DestructibleBuilding>(); building.damageDecay = 600f; } catch (Exception) { } if (building != null && building.IsIntact) { float damageToBuilding = ((0.5f * (bulletMass * Mathf.Pow(currentVelocity.magnitude, 2))) * (BDArmorySettings.DMG_MULTIPLIER / 100) * bulletDmgMult * 1e-4f); damageToBuilding /= 8f; building.AddDamage(damageToBuilding); if (building.Damage > building.impactMomentumThreshold * 150) { building.Demolish(); } if (BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.Log("[BDArmory]: Ballistic hit destructible building! Hitpoints Applied: " + Mathf.Round(damageToBuilding) + ", Building Damage : " + Mathf.Round(building.Damage) + " Building Threshold : " + building.impactMomentumThreshold); } return(true); } return(false); }
private List <BlastHitEvent> ProcessingBlastSphere() { List <BlastHitEvent> result = new List <BlastHitEvent>(); List <Part> parstAdded = new List <Part>(); List <DestructibleBuilding> bulidingAdded = new List <DestructibleBuilding>(); using (var hitCollidersEnu = Physics.OverlapSphere(Position, Range, 9076737).AsEnumerable().GetEnumerator()) { while (hitCollidersEnu.MoveNext()) { if (hitCollidersEnu.Current == null) { continue; } Part partHit = hitCollidersEnu.Current.GetComponentInParent <Part>(); if (partHit != null && partHit.mass > 0 && !parstAdded.Contains(partHit)) { ProcessPartEvent(partHit, result, parstAdded); } else { DestructibleBuilding building = hitCollidersEnu.Current.GetComponentInParent <DestructibleBuilding>(); if (building != null && !bulidingAdded.Contains(building)) { ProcessBuildingEvent(building, result, bulidingAdded); } } } } return(result); }
void OnTriggerEnter(Collider other) { //hitting parts Part explodePart = null; try { explodePart = other.gameObject.GetComponentUpwards <Part>(); explodePart.Unpack(); } catch (NullReferenceException) { } if (explodePart != null) { explodePart.Destroy(); } else { //hitting buildings DestructibleBuilding hitBuilding = null; try { hitBuilding = other.gameObject.GetComponentUpwards <DestructibleBuilding>(); } catch (NullReferenceException) { } if (hitBuilding != null && hitBuilding.IsIntact) { hitBuilding.Demolish(); } } }
private void ExecuteBuildingBlastEvent(BuildingBlastHitEvent eventToExecute) { //TODO: Review if the damage is sensible after so many changes //buildings DestructibleBuilding building = eventToExecute.Building; building.damageDecay = 600f; if (building) { var distanceFactor = Mathf.Clamp01((Range - eventToExecute.Distance) / Range); float damageToBuilding = (BDArmorySettings.DMG_MULTIPLIER / 100) * BDArmorySettings.EXP_DMG_MOD_BALLISTIC_NEW * Power * distanceFactor; damageToBuilding *= 2f; building.AddDamage(damageToBuilding); if (building.Damage > building.impactMomentumThreshold) { building.Demolish(); } if (BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.Log("[BDArmory]: Explosion hit destructible building! Hitpoints Applied: " + Mathf.Round(damageToBuilding) + ", Building Damage : " + Mathf.Round(building.Damage) + " Building Threshold : " + building.impactMomentumThreshold); } } }
public void FacilityDestroyed(DestructibleBuilding facility) { if (facility.id.Contains("LaunchPad")) { KCTDebug.Log("LaunchPad was damaged."); KCTGameStates.ActiveKSC.ActiveLPInstance.RefreshDestructionNode(); } }
public void FacilityDestroyed(DestructibleBuilding facility) { if (facility.id.Contains("LaunchPad")) { KCTDebug.Log("LaunchPad was damaged."); //KCT_GameStates.ActiveKSC.LaunchPads[KCT_GameStates.ActiveKSC.ActiveLaunchPadID].destroyed = !KCT_Utilities.LaunchFacilityIntact(KCT_BuildListVessel.ListType.VAB); KCT_GameStates.ActiveKSC.ActiveLPInstance.RefreshDestructionNode(); } }
void AddDestructibleBuilding(DestructibleBuilding b) { if (b != null || buildings.Contains(b)) { buildings.Add(b); } buildings.RemoveWhere(x => x == null); }
void AddBuilding(DestructibleBuilding b) { if (!LoadedBuildings.Contains(b)) { LoadedBuildings.Add(b); } LoadedBuildings.RemoveAll(x => x == null); }
public void FaciliyRepaired(DestructibleBuilding facility) { if (facility.id.Contains("LaunchPad")) { KCTDebug.Log("LaunchPad was repaired."); //KCT_GameStates.ActiveKSC.LaunchPads[KCT_GameStates.ActiveKSC.ActiveLaunchPadID].destroyed = false; KCT_GameStates.ActiveKSC.ActiveLPInstance.RefreshDestructionNode(); KCT_GameStates.ActiveKSC.ActiveLPInstance.CompletelyRepairNode(); } }
void OnKSCStructureRepairing(DestructibleBuilding building) { Popup popup = popups.LastOrDefault(); if (popup != null) { popup.referencePosition = building.transform; popup.initialized = true; } }
public void FacilityRepaired(DestructibleBuilding building) { if (System.BuildingIdToIgnore == building.id) { return; } System.MessageSender.SendFacilityRepairMsg(building.id); ScenarioSystem.Singleton.SendScenarioModules(); }
public override void OnAwake() { Debug.Log("[BDArmory]: Modifying Buildings"); foreach (KeyValuePair <string, ProtoDestructible> bldg in protoDestructibles) { DestructibleBuilding building = bldg.Value.dBuildingRefs[0]; building.damageDecay = 600f; building.impactMomentumThreshold *= 150; } }
/// <summary> /// If we call building.Demolish() then we woud trigger the KSP event and send a message to the server. /// Therefore we add the id to the ignore field so the event FacilityCollapsing doesn't send a network message /// </summary> public void CollapseFacilityWithoutSendingMessage(DestructibleBuilding building) { if (building == null || !building.IsIntact || building.IsDestroyed) { return; } BuildingIdToIgnore = building.id; building.Demolish(); BuildingIdToIgnore = string.Empty; }
/*************************************************************************************************************************/ private void building_destroyed(DestructibleBuilding building) { Log.PushStackInfo("FMS_Core.building_destroyed", "enter building_destroyed(DestructibleBuilding building) " + building.name); Log.dbg("" + building.name + " destroyed"); if (!damaged_buildings.Contains(building.name)) { damaged_buildings.Add(building.name); } Log.PopStackInfo("leaving building_destroyed(DestructibleBuilding building)"); }
public void FacilityRepairingEvent(DestructibleBuilding facility) { if (KCT_GUI.PrimarilyDisabled) { return; } double cost = facility.RepairCost; double BP = Math.Sqrt(cost) * 2000 * KCT_PresetManager.Instance.ActivePreset.timeSettings.OverallMultiplier; KCTDebug.Log("Facility being repaired for " + cost + " funds, resulting in a BP of " + BP); //facility.StopCoroutine("Repair"); }
public static void DoExplosionRay(Ray ray, float power, float maxDistance, ref List <Part> ignoreParts, ref List <DestructibleBuilding> ignoreBldgs) { RaycastHit rayHit; if (Physics.Raycast(ray, out rayHit, maxDistance, 557057)) { float sqrDist = (rayHit.point - ray.origin).sqrMagnitude; float sqrMaxDist = maxDistance * maxDistance; float distanceFactor = Mathf.Clamp01((sqrMaxDist - sqrDist) / sqrMaxDist); //parts Part part = rayHit.collider.GetComponentInParent <Part>(); if (part && !ignoreParts.Contains(part) && part.physicalSignificance == Part.PhysicalSignificance.FULL) { ignoreParts.Add(part); Rigidbody rb = part.GetComponent <Rigidbody>(); if (rb) { rb.AddForceAtPosition(ray.direction * power * distanceFactor * ExplosionImpulseMultiplier, rayHit.point, ForceMode.Impulse); } float heatDamage = ExplosionHeatMultiplier * power * distanceFactor / part.crashTolerance; part.temperature += heatDamage; if (BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.Log("====== Explosion ray hit part! Damage: " + heatDamage); } return; } //buildings DestructibleBuilding building = rayHit.collider.GetComponentInParent <DestructibleBuilding>(); if (building && !ignoreBldgs.Contains(building)) { ignoreBldgs.Add(building); float damageToBuilding = ExplosionHeatMultiplier * 0.00685f * power * distanceFactor; if (damageToBuilding > building.impactMomentumThreshold / 10) { building.AddDamage(damageToBuilding); } if (building.Damage > building.impactMomentumThreshold) { building.Demolish(); } if (BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.Log("== Explosion hit destructible building! Damage: " + (damageToBuilding).ToString("0.00") + ", total Damage: " + building.Damage); } } } }
public void FacilityCollapsing(DestructibleBuilding building) { if (System.BuildingIdToIgnore == building.id) { return; } //Don't send this kind of messages when spectating as they are not accurate if (!VesselCommon.IsSpectating) { System.MessageSender.SendFacilityCollapseMsg(building.id); ScenarioSystem.Singleton.SendScenarioModules(); } }
public void FacilityDestroyed(DestructibleBuilding facility) { const string logBlockName = nameof(KCTEvents) + "." + nameof(FaciliyRepaired); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { if (facility.id.Contains("LaunchPad")) { Log.Info("LaunchPad was damaged."); //KCT_GameStates.ActiveKSC.LaunchPads[KCT_GameStates.ActiveKSC.ActiveLaunchPadID].destroyed = !KCT_Utilities.LaunchFacilityIntact(KCT_BuildListVessel.ListType.VAB); GameStates.ActiveKSC.ActiveLPInstance.RefreshDestructionNode(); } } }
void CalculateDamageAndForcesOnBuilding(DestructibleBuilding b, float dist) { float peakPressureDiff = (currentPeakPressure - prevPeakPressure); float impulseDiff = (currentPosImpulse - prevPosImpulse); float radiusDiff = currentBlastRadius - prevBlastRadius; if (radiusDiff <= 0 || float.IsNaN(peakPressureDiff) || float.IsNaN(impulseDiff)) { Debug.Log("Vessel damage error; radDiff: " + radiusDiff + " impulseDiff: " + impulseDiff + " peakDiff: " + peakPressureDiff); return; } float overpressureApplied = peakPressureDiff * (dist - prevBlastRadius) / radiusDiff + prevPeakPressure - (float)atmPres; float impulseApplied = impulseDiff * (dist - prevBlastRadius) / radiusDiff + prevPosImpulse; BlastwaveIsoDamageModel.Instance.CalculateDamage(b, impulseApplied, overpressureApplied); }
private bool CheckBuildingHit(RaycastHit hit) { DestructibleBuilding building = null; try { building = hit.collider.gameObject.GetComponentUpwards <DestructibleBuilding>(); } catch (Exception) { } if (building != null && building.IsIntact) { return(true); } return(false); }
public void FaciliyRepaired(DestructibleBuilding facility) { const string logBlockName = nameof(KCTEvents) + "." + nameof(FaciliyRepaired); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { if (facility.id.Contains("LaunchPad")) { Log.Info("LaunchPad was repaired."); //KCT_GameStates.ActiveKSC.LaunchPads[KCT_GameStates.ActiveKSC.ActiveLaunchPadID].destroyed = false; GameStates.ActiveKSC.ActiveLPInstance.RefreshDestructionNode(); GameStates.ActiveKSC.ActiveLPInstance.CompletelyRepairNode(); } } }
public void FacilityRepairingEvent(DestructibleBuilding facility) { const string logBlockName = nameof(KCTEvents) + "." + nameof(FacilityRepairingEvent); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { if (KCT_GUI.PrimarilyDisabled) { return; } double cost = facility.RepairCost; double BP = Math.Sqrt(cost) * 2000 * KCT_PresetManager.Instance.ActivePreset.timeSettings.OverallMultiplier; Log.Info("Facility being repaired for " + cost + " funds, resulting in a BP of " + BP); //facility.StopCoroutine("Repair"); } }
/// <summary> /// Collapses a building without replaying the special effects. /// Useful when reverting as you don't want to see the flames again... /// </summary> public void CollapseFacilityWithoutSfx(DestructibleBuilding building) { if (building == null || !building.IsIntact || building.IsDestroyed) { return; } BuildingIdToIgnore = building.id; foreach (var collapsibleObj in building.CollapsibleObjects) { collapsibleObj.SetDestroyed(true); } Traverse.Create(building).Field("destroyed").SetValue(true); Traverse.Create(building).Field("intact").SetValue(false); BuildingIdToIgnore = string.Empty; }
internal void Despawn() { //if (hasLauchSites && (KerbalKonstructs.selectedInstance != this)) //{ // return; //} // save the Color configs when we despawn, because they could be written to disk later GrassColor2[] grassArray = _mesh.GetComponents <GrassColor2>(); if (grassArray.Length > 0) { grassColor2Configs.Clear(); foreach (GrassColor2 grassColor in grassArray) { grassColor2Configs.Add(grassColor.GiveConfig()); } } foreach (StaticModule module in gameObject.GetComponentsInChildren <StaticModule>()) { GameObject.DestroyImmediate(module); } foreach (DestructibleBuilding building in gameObject.GetComponentsInChildren <DestructibleBuilding>()) { GameObject.DestroyImmediate(building); } destructible = null; _mesh.transform.parent = null; GameObject.DestroyImmediate(_mesh); wreck.transform.parent = null; GameObject.DestroyImmediate(wreck); wreck = new GameObject("wreck"); GameObject.DontDestroyOnLoad(wreck); wreck.transform.position = transform.position; wreck.transform.rotation = transform.rotation; wreck.transform.parent = transform; isSpawned = false; }
void OnKSCStructureCollapsing(DestructibleBuilding building) { Debug.Log("Strategia: OnKSCStructureCollapsing: " + building); if (currency == Currency.Funds) { Funding.Instance.AddFunds(amount, TransactionReasons.Strategies); } else if (currency == Currency.Reputation) { Reputation.Instance.AddReputation(amount, TransactionReasons.Strategies); } else if (currency == Currency.Science) { ResearchAndDevelopment.Instance.AddScience(amount, TransactionReasons.Strategies); } CurrencyPopup.Instance.AddPopup(currency, amount, TransactionReasons.StructureCollapse, Parent.Config.Title, building.FxTarget, true); }
private bool CheckBuildingHit(RaycastHit hit) { DestructibleBuilding building = null; try { building = hit.collider.gameObject.GetComponentUpwards <DestructibleBuilding>(); } catch (Exception e) { Debug.LogWarning("[BDArmory.ClusterBomb]: Exception thrown in CheckBuildingHit: " + e.Message + "\n" + e.StackTrace); } if (building != null && building.IsIntact) { return(true); } return(false); }
/*************************************************************************************************************************/ private void building_destroyed(DestructibleBuilding building) { #if DEBUG // if (Debug_Level_1_Active) Log.PushStackInfo("FMS_Core.building_destroyed", "enter building_destroyed(DestructibleBuilding building) " + building.name); if (Debug_Active) { Log.Info("" + building.name + " destroyed"); } #endif if (!damaged_buildings.Contains(building.name)) { damaged_buildings.Add(building.name); } #if DEBUG // if (Debug_Level_1_Active) Log.PopStackInfo("leaving building_destroyed(DestructibleBuilding building)"); #endif }
public override void OnAwake() { Debug.Log("[BDArmory]: Modifying Buildings"); if (!HighLogic.LoadedSceneIsFlight) { return; } foreach (KeyValuePair <string, ProtoDestructible> bldg in protoDestructibles) { if (bldg.Value == null) { return; } DestructibleBuilding building = bldg.Value.dBuildingRefs[0]; building.damageDecay = 600f; building.impactMomentumThreshold *= 150; } }
/// <summary> /// Removes the wreck model from an KSC Object. /// </summary> internal static void MangleSquadStatic(GameObject gameObject) { gameObject.transform.parent = null; var transforms = gameObject.transform.GetComponentsInChildren <Transform>(true); foreach (var transform in transforms) { if (transform.name.Equals("wreck", StringComparison.InvariantCultureIgnoreCase)) { transform.parent = null; GameObject.Destroy(transform.gameObject); } if (transform.name.Equals("commnetnode", StringComparison.InvariantCultureIgnoreCase)) { transform.parent = null; GameObject.Destroy(transform.gameObject); } } PQSCity2 pqs2 = gameObject.GetComponent <PQSCity2>(); if (pqs2 != null) { GameObject.Destroy(pqs2); } CommNet.CommNetHome cnhome = gameObject.GetComponent <CommNet.CommNetHome>(); if (cnhome != null) { GameObject.Destroy(cnhome); } DestructibleBuilding destBuilding = gameObject.GetComponentInChildren <DestructibleBuilding>(); if (destBuilding != null) { GameObject.Destroy(destBuilding); } }
public static bool CheckBuildingHit(RaycastHit hit, float projMass, Vector3 currentVelocity, float DmgMult) { DestructibleBuilding building = null; try { building = hit.collider.gameObject.GetComponentUpwards <DestructibleBuilding>(); if (building != null) { building.damageDecay = 600f; } } catch (Exception e) { Debug.LogWarning("[BDArmory.ProjectileUtils]: Exception thrown in CheckBuildingHit: " + e.Message + "\n" + e.StackTrace); } if (building != null && building.IsIntact) { float damageToBuilding = ((0.5f * (projMass * Mathf.Pow(currentVelocity.magnitude, 2))) * (BDArmorySettings.DMG_MULTIPLIER / 100) * DmgMult * 1e-4f); damageToBuilding /= 8f; building.AddDamage(damageToBuilding); if (building.Damage > building.impactMomentumThreshold * 150) { building.Demolish(); } if (BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.Log("[BDArmory.ProjectileUtils]: Ballistic hit destructible building! Hitpoints Applied: " + Mathf.Round(damageToBuilding) + ", Building Damage : " + Mathf.Round(building.Damage) + " Building Threshold : " + building.impactMomentumThreshold); } return(true); } return(false); }
public void FacilityRepairingEvent(DestructibleBuilding facility) { if (KCT_GUI.PrimarilyDisabled) return; double cost = facility.RepairCost; double BP = Math.Sqrt(cost) * 2000 * KCT_PresetManager.Instance.ActivePreset.timeSettings.OverallMultiplier; KCTDebug.Log("Facility being repaired for " + cost + " funds, resulting in a BP of " + BP); facility.StopCoroutine("Repair"); }
void AddBuilding(DestructibleBuilding b) { if(!LoadedBuildings.Contains(b)) { LoadedBuildings.Add(b); } LoadedBuildings.RemoveAll(x => x == null); }