void RPCExplode() { explosionParticle.transform.SetParent(null, true); explosionParticle.transform.localScale = Vector3.one; explosionParticle.Emit(explosionParticle.maxParticles); Destroy(explosionParticle.gameObject, Mathf.Max(explosionParticle.startLifetime * 1.1f, source.clip.length * 1.1f)); source.Play(); if (Physics.CheckSphere(transform.position, maxRadius, GameController.Instance.explosionLayers)) { Collider[] colliders = Physics.OverlapSphere(transform.position, maxRadius, GameController.Instance.explosionLayers); for (int i = 0; i < colliders.Length; i++) { Collider coll = colliders[i]; Player player = coll.transform.root.GetComponent <Player>(); if (player == null || coll.tag != "Player") { continue; } if (!player.photonView.isMine) { continue; } RaycastHit hit; if (Physics.Linecast(transform.position, player.mouseLook.mouseLookRoot.position, out hit, GameController.Instance.explosionLayers)) { if (hit.collider == coll && !ServerController.AreFriends(photonView.owner, player.photonView.owner, true)) { float ratio = Mathf.InverseLerp(maxRadius, radius, Mathf.Clamp( Vector3.Distance(player.transform.position, transform.position), radius, maxRadius )); int finalDamage = Mathf.RoundToInt(damage * ratio); if (player.health - finalDamage > 0) { player.photonView.RPC("RPCDamageCustomReason", player.photonView.owner, finalDamage, grenade.KillfeedName); } else { if (player.photonView.owner != photonView.owner) { player.photonView.RPC("RPCDamage", player.photonView.owner, finalDamage, Vector3.zero, Vector3.forward, 0f, photonView.ownerId, grenade.ID ); } else { player.photonView.RPC("RPCDamageCustomReason", player.photonView.owner, finalDamage, grenade.KillfeedName); } } } } } } }
public void Fire() { if (!canShoot) { return; } CrosshairRecoill(); player.photonView.RPC("RPCFire", PhotonTargets.Others); t = Time.time + info.RPMToFireRate(aiming ? info.aimedRPM : info.RPM); StartCoroutine(IMuzzle()); player.ShowLocalMuzzle(); ammo--; float multiplier = 1f; if (player.running) { multiplier = info.runningMultiplier; } else if (player.crouching) { multiplier = info.crouchingMultiplier; } else { multiplier = 1f; } for (int i = 0; i < info.shots; i++) { float randomX = Random.Range(-info.coneAngle / 4f, info.coneAngle / 4f) * multiplier; float randomY = Random.Range(-info.coneAngle / 4f, info.coneAngle / 4f) * multiplier; if (aiming) { randomX = Random.Range(-info.aimedConeAngle / 4f, info.aimedConeAngle / 4f) * multiplier; randomY = Random.Range(-info.aimedConeAngle / 4f, info.aimedConeAngle / 4f) * multiplier; } player.raycaster.localEulerAngles = new Vector3(randomX, randomY); RaycastHit hit; if (Physics.Raycast(player.raycaster.position, player.raycaster.forward, out hit, float.MaxValue, GameController.Instance.fireLayers)) { if (hit.transform.gameObject.layer == 31 && hit.transform.root != transform.root) { Player target = hit.transform.root.GetComponent <Player>(); if (target != null && !ServerController.AreFriends(target.photonView.owner, PhotonNetwork.player)) { int damage = info.damage.torso; if (ServerController.gamemode != ServerController.Gamemode.OITC) { if (hit.transform.tag == "Head") { damage = info.damage.head; } else if (hit.transform.tag == "Arm") { damage = info.damage.arms; } else if (hit.transform.tag == "Leg") { damage = info.damage.legs; } } else { damage = 100; } target.photonView.RPC("RPCDamage", target.photonView.owner, damage, player.raycaster.position, player.raycaster.forward, info.physicsForce, player.photonView.ownerId, info.ID ); player.photonView.RPC("RPCBlood", PhotonTargets.All, hit.point, hit.normal); MapController.hud.ShowHitmarker(); } } else if (hit.transform.gameObject.layer != 30) { player.photonView.RPC("RPCBulletHole", PhotonTargets.All, hit.point, hit.normal); } } } anim.PlayQueued(info.fireClip.name, QueueMode.PlayNow); anim.PlayQueued(info.idleClip.name, QueueMode.CompleteOthers); player.Recoill(aiming ? info.aimedRecoill : info.recoill); main.source.PlayOneShot(info.fireSound); }
void Attack() { if (!canAttack) { return; } CrosshairRecoill(); t = Time.time + fireRate; AudioClip soundToPlay = missSound; player.raycaster.localEulerAngles = Vector3.zero; Ray ray = new Ray(player.raycaster.position, player.raycaster.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, hitDistance, GameController.Instance.fireLayers)) { if (hit.transform.gameObject.layer == 31 && hit.transform.root != transform.root) { Player target = hit.transform.root.GetComponent <Player>(); if (target != null && !ServerController.AreFriends(target.photonView.owner, PhotonNetwork.player)) { soundToPlay = fleshSound; int finalDamage = ServerController.gamemode != ServerController.Gamemode.OITC ? damage : 100; target.photonView.RPC("RPCDamage", target.photonView.owner, finalDamage, ray.origin, ray.direction, hitForce, player.photonView.ownerId, info.ID); player.photonView.RPC("RPCBlood", PhotonTargets.All, hit.point, hit.normal); MapController.hud.ShowHitmarker(); } } else { if (hit.transform.gameObject.layer == 30) { soundToPlay = fleshSound; } else { soundToPlay = wallSound; player.photonView.RPC("RPCBulletHole", PhotonTargets.All, hit.point, hit.normal); } } } anim.Stop(); anim.PlayQueued(attackAnimation.name, QueueMode.PlayNow); anim.PlayQueued(drawAnimation.name, QueueMode.CompleteOthers); RandomizeSize(); main.source.PlayOneShot(soundToPlay); if (soundToPlay == wallSound) { player.photonView.RPC("RPCPlayCustomSound", PhotonTargets.Others, 1); } else if (soundToPlay == fleshSound) { player.photonView.RPC("RPCPlayCustomSound", PhotonTargets.Others, 2); } else { player.photonView.RPC("RPCPlayCustomSound", PhotonTargets.Others, 0); } }