private void SendExplosionPositionToAll(Vector3 position) { if (StatMaster.isHosting) { Message explosionPositionMsg = Messages.rocketHighExploPosition.CreateMessage(position, bombExplosiveCharge); ModNetworking.SendToAll(explosionPositionMsg); } }
protected void SendPortalPlacement(Portal portal, ShootState state, Vector3 impact, Vector3 pos, Vector3 normal) { MuzzlePlarticle(portal); VidyaMod.PlayAudio(audioSource, state == ShootState.Place ? clips[portal.index] : clips[2], 0.9f); if (!StatMaster.isLocalSim) { Message targetMessage = portalShotMessageType.CreateMessage(Block.From(this), portal.index, (int)state, impact, pos, normal); ModNetworking.SendToAll(targetMessage); } }
protected void SendTargetPos() { if (!simulationStarted) { return; } if (!StatMaster.isLocalSim) { Message targetMessage = targetingMessageType.CreateMessage(Block.From(this), targeter.transform.position); ModNetworking.SendToAll(targetMessage); } }
private void SendClientTargetNull() { if (StatMaster.isHosting) { Message rocketTargetNullMsg = Messages.rocketTargetNullMsg.CreateMessage(parentBlock); Player player1 = Player.GetAllPlayers().Find(player => player.NetworkId == parentBlock.ParentMachine.PlayerID); if (player1 != null) { ModNetworking.SendTo(player1, rocketTargetNullMsg); } ModNetworking.SendToAll(Messages.rocketLostTargetMsg.CreateMessage(parentBlock)); } RocketsController.Instance.RemoveRocketTarget(parentBlock); }
protected void SendPolymorph(MonoBehaviour m, bool heated) { if (!StatMaster.isLocalSim) { LevelEntity le = m.GetComponent <LevelEntity>(); if (le == null) { return; } Entity e = Entity.From(le); Message targetMessage = polymorphMessageType.CreateMessage(Block.From(poultryizer), e, heated); ModNetworking.SendToAll(targetMessage); } }
private void fire() { if (!LaunchEnable && Time.timeScale != 0) { LaunchEnable = true; StartCoroutine(Launch(BulletParticleEffectEvent)); } void BulletParticleEffectEvent() { fireBaseMethod((bullet) => { var message = FireMessage.CreateMessage(BlockBehaviour, Rigidbody.velocity, bullet.GetComponent <RayBulletScript>().Guid.ToString()); ModNetworking.SendToAll(message); }); } }
public override void SimulateUpdateAlways() { if ((launch_key.IsPressed || launch_key.EmulationPressed()) && !rocketScript.Launched) { rocketScript.LaunchEnabled = true; if (StatMaster.isHosting) { var message = LaunchMessage.CreateMessage(BlockBehaviour, rocketScript.Guid.ToString()); ModNetworking.SendToAll(message); } } if (healthBar.health <= 0 && isExploded == false) { rocketScript.Explody(); } }
public void Explody() { if (!StatMaster.isClient) { var message = ExplodeMessage.CreateMessage(Guid.ToString()); ModNetworking.SendToAll(message); rigidbody.isKinematic = true; exploder.Explodey(transform.position); gameObject.GetComponentInChildren <CapsuleCollider>().isTrigger = true; gameObject.GetComponentsInChildren <MeshRenderer>().ToList().Find(match => match.name == "Vis").enabled = false; enabled = false; } }
public void Fire() { if (StatMaster.isClient) { return; } StartCoroutine(Launch(fireEvent)); void fireEvent() { GameObject gameObject = rocketPool.Work.GetChild(0).gameObject; Vector3 position = Vector3.right * Vector3.Project(Rigidbody.velocity, transform.right).magnitude *transform.localScale.x *Time.fixedDeltaTime * 3f; gameObject.transform.localPosition += position; gameObject.transform.SetParent(/*transform.parent*/ Machine.InternalObject.transform); gameObject.SetActive(true); Rigidbody rigidbody = gameObject.GetComponent <Rigidbody>(); rigidbody.isKinematic = false; rigidbody.velocity = Rigidbody.velocity; rigidbody.AddRelativeForce(Vector3.right * 25f, ForceMode.Impulse); RocketScript rocketScript = gameObject.GetComponent <RocketScript>(); rocketScript.LaunchEnabled = true; if (StatMaster.isHosting) { var message = LaunchMessage.CreateMessage(BlockBehaviour, BulletCurrentNumber, rocketScript.Guid.ToString(), position); ModNetworking.SendToAll(message); } StartCoroutine(delay()); IEnumerator delay() { yield return(new WaitForSeconds(rocketScript.DelayEnableCollisionTime)); rigidbody.detectCollisions = true; gameObject.GetComponentInChildren <CapsuleCollider>().isTrigger = false; yield break; } } }
void fire() { if (!LaunchEnable && Time.timeScale != 0) { LaunchEnable = true; StartCoroutine(Launch(BulletParticleEffectEvent)); } void BulletParticleEffectEvent() { var bullet = (GameObject)Instantiate(BulletObject, transform.TransformPoint(SpawnPoint + Direction), transform.rotation); bullet.SetActive(true); var bs = bullet.GetComponent <BulletScript>(); bs.Fire(null, (value) => { bs.gameObject.AddComponent <ExplodeScript>().Explodey(ExplodeScript.explosionType.Small, bullet.transform.position, bulletPowerSlider.Value, 3f); bs.GetComponent <TimedSelfDestruct>().Begin(5f); } ); if (StatMaster.isMP && Modding.Common.Player.GetAllPlayers().Count > 1) { var message = FireMessage.CreateMessage(BlockBehaviour, Rigidbody.velocity, bs.Guid.ToString()); ModNetworking.SendToAll(message); } fireAudioSource.PlayOneShot(fireAudioSource.clip); fireAudioSource.pitch = UnityEngine.Random.Range(0.8f, 1.2f); EffectsObject.SetActive(true); EffectsObject.GetComponent <Reactivator>().Switch = true; } }
private IEnumerator explodey(explosionType explosiontype, Vector3 position, float power, float radius) { if (StatMaster.isClient) { yield break; } if (isExplodey) { yield break; } else { fireEffect = getExplodeEffectObject(explosiontype); if (ExplosionType == explosionType.Big) { fireEffect.transform.FindChild("Debris").localRotation = Quaternion.AngleAxis(UnityEngine.Random.Range(0f, 360f), Vector3.up); } fireEffect.transform.position = position; if (!StatMaster.isClient) { var message = ExplodyMessage.CreateMessage((int)explosiontype, position); ModNetworking.SendToAll(message); } } yield return(new WaitForFixedUpdate()); isExplodey = true; fireEffect.SetActive(true); OnExplode?.Invoke(); //定义爆炸位置为炸弹位置 Vector3 explosionPos = position; //这个方法用来返回球型半径之内(包括半径)的所有碰撞体collider[] Collider[] colliders = Physics.OverlapSphere(explosionPos, radius); //遍历返回的碰撞体,如果是刚体,则给刚体添加力 foreach (Collider hit in colliders) { if (hit.attachedRigidbody != null) { float force = UnityEngine.Random.Range(30000f, 50000f) * power * (Vector3.Distance(hit.transform.position, explosionPos) / (radius + 0.25f)); hit.attachedRigidbody.AddExplosionForce(force, explosionPos, radius); hit.attachedRigidbody.AddTorque(force * Vector3.Cross((hit.transform.position - explosionPos), Vector3.up)); reduceBlockHealth(hit.attachedRigidbody.gameObject); } } OnExploded?.Invoke(colliders); yield return(new WaitForSeconds(3f)); fireEffect.SetActive(false); OnExplodeFinal?.Invoke(); //------------------------------------------------------------- void reduceBlockHealth(GameObject gameObject) { var bhb = gameObject.GetComponent <BlockHealthBar>(); if (bhb != null) { bhb.DamageBlock(1); } } //--------------------------------------------------------------- }
private void Update() { if (!isCollision) { if (Time.timeScale == 0f) { return; } _deltaTime = Time.smoothDeltaTime / Time.timeScale; Vector3 gravityVelocity = (!StatMaster.GodTools.GravityDisabled) ? (bulletPropertise.GravityAcceleration) : Vector3.zero; Vector3 dragVelocity = -(bulletPropertise.Velocity.normalized * bulletPropertise.Drag); bulletPropertise.Velocity += gravityVelocity + dragVelocity; ePoint = sPoint + bulletPropertise.Velocity * _deltaTime; lineRenderer.SetPosition(0, sPoint); if (Physics.Raycast(sPoint, bulletPropertise.Velocity, out hitInfo, (sPoint - ePoint).magnitude) && bulletPropertise.ColliderEnabled == true) { if ((hitInfo.transform == gunbodyTransform && gunbodyTransform != null)) { shootingNothing(); } else { if (hasRigidbody(hitInfo, out rigidbody_Aim)) { shootingSomething(); } else if (hitInfo.collider.isTrigger == false) { shootingSomething(); } else { shootingNothing(); } } } else { shootingNothing(); } } else { lineRenderer.enabled = false; Destroy(gameObject); } bool hasRigidbody(RaycastHit hit, out Rigidbody rigidbody) { var value = false; rigidbody = null; if (hit.rigidbody != null && hit.rigidbody.isKinematic == false) { value = true; rigidbody = hit.rigidbody; return(value); } else if (hit.collider.attachedRigidbody != null && hit.collider.attachedRigidbody.isKinematic == false) { value = true; rigidbody = hit.collider.attachedRigidbody; return(value); } else { var blockBehaviour = hit.transform.GetComponentInParent <BlockBehaviour>() ?? hit.transform.GetComponentInChildren <BlockBehaviour>(); if (blockBehaviour != null) { rigidbody = blockBehaviour.transform.GetComponent <Rigidbody>(); if (rigidbody != null && rigidbody.isKinematic == false) { value = true; return(value); } } var levelEntity = hit.transform.GetComponentInParent <LevelEntity>() ?? hit.transform.GetComponentInChildren <LevelEntity>(); if (levelEntity != null) { rigidbody = levelEntity.transform.GetComponent <Rigidbody>(); if (rigidbody != null && rigidbody.isKinematic == false) { value = true; return(value); } } return(value); } } void shootingSomething() { var targetType = "stone"; lineRenderer.SetPosition(1, hitInfo.point); isCollision = true; if (!StatMaster.isClient) { OnCollisionEvent?.Invoke(rigidbody_Aim); targetType = createImpactEffect(); var message = ImpactMessage.CreateMessage(Guid.ToString(), targetType, hitInfo.point, hitInfo.normal); ModNetworking.SendToAll(message); } } void shootingNothing() { lineRenderer.SetPosition(1, ePoint); sPoint = ePoint; } }