private void RocketExplode() { //Reset some parameter and set the rocket to explode //Stop the search target coroutine searchStarted = false; targetHit = true; StopCoroutine(SearchForTarget()); if (!highExploActivated) { if (!rocket.hasExploded) { rocket.OnExplode(); } } else { if (!bombHasExploded && explosiveCharge != 0) { bombHasExploded = true; //Generate a bomb from level editor and let it explode try { GameObject bomb = (GameObject)Instantiate(PrefabMaster.LevelPrefabs[levelBombCategory].GetValue(levelBombID).gameObject, rocket.transform.position, rocket.transform.rotation); ExplodeOnCollide bombControl = bomb.GetComponent <ExplodeOnCollide>(); bomb.transform.localScale = Vector3.one * bombExplosiveCharge; bombControl.radius = radius * bombExplosiveCharge; bombControl.power = power * bombExplosiveCharge; bombControl.torquePower = torquePower * bombExplosiveCharge; bombControl.upPower = upPower; bombControl.Explodey(); } catch { } //Add explode and ignition effects to the affected objects try { Collider[] hits = Physics.OverlapSphere(rocket.transform.position, radius * bombExplosiveCharge); foreach (var hit in hits) { if (hit.attachedRigidbody != null && hit.attachedRigidbody.gameObject.layer != 22) { try { if (hit.attachedRigidbody.gameObject.GetComponent <RocketScript>()) { continue; } } catch { } try { hit.attachedRigidbody.WakeUp(); hit.attachedRigidbody.constraints = RigidbodyConstraints.None; hit.attachedRigidbody.AddExplosionForce(power * bombExplosiveCharge, rocket.transform.position, radius * bombExplosiveCharge, upPower); hit.attachedRigidbody.AddRelativeTorque(UnityEngine.Random.insideUnitSphere.normalized * torquePower * bombExplosiveCharge); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <FireTag>().Ignite(); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <ExplodeMultiplier>().Explodey(power * bombExplosiveCharge, rocket.transform.position, radius * bombExplosiveCharge, upPower); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <SimpleBirdAI>().Explode(); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <EnemyAISimple>().Die(); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <CastleWallBreak>().BreakExplosion(power * bombExplosiveCharge, rocket.transform.position, radius * bombExplosiveCharge, upPower); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <BreakOnForce>().BreakExplosion(power * bombExplosiveCharge, rocket.transform.position, radius * bombExplosiveCharge, upPower); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <BreakOnForceNoSpawn>().BreakExplosion(power * bombExplosiveCharge, rocket.transform.position, radius * bombExplosiveCharge, upPower); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <InjuryController>().activeType = InjuryType.Fire; hit.attachedRigidbody.gameObject.GetComponent <InjuryController>().Kill(); } catch { } } } } catch { } if (!rocket.hasExploded) { rocket.OnExplode(); } } } }
public MessageController() { //Initiating messages Messages.rocketFiredMsg = ModNetworking.CreateMessageType(DataType.Block); Messages.rocketTargetBlockBehaviourMsg = ModNetworking.CreateMessageType(DataType.Block, DataType.Block); Messages.rocketTargetEntityMsg = ModNetworking.CreateMessageType(DataType.Entity, DataType.Block); Messages.rocketTargetNullMsg = ModNetworking.CreateMessageType(DataType.Block); Messages.rocketRayToHostMsg = ModNetworking.CreateMessageType(DataType.Vector3, DataType.Vector3, DataType.Block); Messages.rocketHighExploPosition = ModNetworking.CreateMessageType(DataType.Vector3, DataType.Single); Messages.rocketLockOnMeMsg = ModNetworking.CreateMessageType(DataType.Block, DataType.Integer); Messages.rocketLostTargetMsg = ModNetworking.CreateMessageType(DataType.Block); //Initiating callbacks ModNetworking.Callbacks[Messages.rocketHighExploPosition] += (Message msg) => { if (StatMaster.isClient) { Vector3 position = (Vector3)msg.GetData(0); float bombExplosiveCharge = (float)msg.GetData(1); int levelBombCategory = 4; int levelBombID = 5001; float radius = 7f; float power = 3600f; float torquePower = 100000f; float upPower = 0.25f; try { GameObject bomb = UnityEngine.Object.Instantiate(PrefabMaster.LevelPrefabs[levelBombCategory].GetValue(levelBombID).gameObject); bomb.transform.position = position; ExplodeOnCollide bombControl = bomb.GetComponent <ExplodeOnCollide>(); bomb.transform.localScale = Vector3.one * bombExplosiveCharge; bombControl.radius = radius * bombExplosiveCharge; bombControl.power = power * bombExplosiveCharge; bombControl.torquePower = torquePower * bombExplosiveCharge; bombControl.upPower = upPower; bombControl.Explodey(); } catch { } } }; ModNetworking.Callbacks[Messages.rocketFiredMsg] += (Message msg) => { Block rocketBlock = (Block)msg.GetData(0); TimedRocket rocket = rocketBlock.GameObject.GetComponent <TimedRocket>(); RocketsController.Instance.UpdateRocketFiredStatus(rocket); }; ModNetworking.Callbacks[Messages.rocketTargetBlockBehaviourMsg] += (Message msg) => { #if DEBUG Debug.Log("Receive block target"); #endif Block rocketBlock = (Block)msg.GetData(1); RocketScript rocket = rocketBlock.GameObject.GetComponent <RocketScript>(); rocket.target = ((Block)msg.GetData(0)).GameObject.transform; rocket.targetCollider = rocket.target.gameObject.GetComponentInChildren <Collider>(true); }; ModNetworking.Callbacks[Messages.rocketTargetEntityMsg] += (Message msg) => { #if DEBUG Debug.Log("Receive entity target"); #endif Block rocketBlock = (Block)msg.GetData(1); RocketScript rocket = rocketBlock.GameObject.GetComponent <RocketScript>(); rocket.target = ((Entity)msg.GetData(0)).GameObject.transform; rocket.targetCollider = rocket.target.gameObject.GetComponentInChildren <Collider>(true); }; ModNetworking.Callbacks[Messages.rocketTargetNullMsg] += (Message msg) => { #if DEBUG Debug.Log("Receive entity target"); #endif Block rocketBlock = (Block)msg.GetData(0); RocketScript rocket = rocketBlock.GameObject.GetComponent <RocketScript>(); rocket.target = null; rocket.targetCollider = null; }; ModNetworking.Callbacks[Messages.rocketRayToHostMsg] += (Message msg) => { Block rocketBlock = (Block)msg.GetData(2); RocketScript rocket = rocketBlock.GameObject.GetComponent <RocketScript>(); rocket.rayFromClient = new Ray((Vector3)msg.GetData(0), (Vector3)msg.GetData(1)); rocket.activeGuide = false; rocket.receivedRayFromClient = true; }; ModNetworking.Callbacks[Messages.rocketLockOnMeMsg] += (Message msg) => { Block rocket = (Block)msg.GetData(0); int targetMachineID = (int)msg.GetData(1); RocketsController.Instance.UpdateRocketTarget(rocket.InternalObject, targetMachineID); }; ModNetworking.Callbacks[Messages.rocketLostTargetMsg] += (Message msg) => { Block rocket = (Block)msg.GetData(0); RocketsController.Instance.RemoveRocketTarget(rocket.InternalObject); }; }
private IEnumerator RocketExplode() { Vector3 position = rocket.transform.position; Quaternion rotation = rocket.transform.rotation; if (!rocket.hasExploded) { rocket.ExplodeMessage(); } if (!HighExploToggle.IsActive) { yield break; } if (!bombHasExploded && explosiveCharge != 0) { if (StatMaster.isHosting) { SendExplosionPositionToAll(position); } bombHasExploded = true; //Generate a bomb from level editor and let it explode try { GameObject bomb = (GameObject)Instantiate(PrefabMaster.LevelPrefabs[levelBombCategory].GetValue(levelBombID).gameObject, position, rotation); ExplodeOnCollide bombControl = bomb.GetComponent <ExplodeOnCollide>(); bomb.transform.localScale = Vector3.one * bombExplosiveCharge; bombControl.radius = radius * bombExplosiveCharge; bombControl.power = power * bombExplosiveCharge; bombControl.torquePower = torquePower * bombExplosiveCharge; bombControl.upPower = upPower; bombControl.Explodey(); } catch { } //Add explode and ignition effects to the affected objects Collider[] hits = Physics.OverlapSphere(rocket.transform.position, radius * bombExplosiveCharge, Game.BlockEntityLayerMask); int index = 0; int rank = 60; if (hits.Length <= 0) { yield break; } foreach (var hit in hits) { if (index > rank) { index = 0; yield return(0); } if (hit.attachedRigidbody != null && hit.attachedRigidbody && hit.attachedRigidbody != rocket.Rigidbody && hit.attachedRigidbody.gameObject.layer != 20 && hit.attachedRigidbody.gameObject.layer != 22 && hit.attachedRigidbody.tag != "KeepConstraintsAlways" && hit.attachedRigidbody.gameObject.layer != RadarScript.CollisionLayer) { try { hit.attachedRigidbody.WakeUp(); hit.attachedRigidbody.constraints = RigidbodyConstraints.None; hit.attachedRigidbody.AddExplosionForce(power * bombExplosiveCharge, rocket.transform.position, radius * bombExplosiveCharge, upPower); hit.attachedRigidbody.AddRelativeTorque(UnityEngine.Random.insideUnitSphere.normalized * torquePower * bombExplosiveCharge); } catch { } try { RocketScript rocketScript = hit.attachedRigidbody.gameObject.GetComponent <RocketScript>(); rocketScript.StartCoroutine(rocketScript.RocketExplode()); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <FireTag>().Ignite(); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <ExplodeMultiplier>().Explodey(power * bombExplosiveCharge, rocket.transform.position, radius * bombExplosiveCharge, upPower); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <SimpleBirdAI>().Explode(); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <EnemyAISimple>().Die(); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <CastleWallBreak>().BreakExplosion(power * bombExplosiveCharge, rocket.transform.position, radius * bombExplosiveCharge, upPower); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <BreakOnForce>().BreakExplosion(power * bombExplosiveCharge, rocket.transform.position, radius * bombExplosiveCharge, upPower); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <BreakOnForceNoSpawn>().BreakExplosion(power * bombExplosiveCharge, rocket.transform.position, radius * bombExplosiveCharge, upPower); } catch { } try { hit.attachedRigidbody.gameObject.GetComponent <InjuryController>().activeType = InjuryType.Fire; hit.attachedRigidbody.gameObject.GetComponent <InjuryController>().Kill(); } catch { } } else { continue; } index++; } } }