private void AttemptToFireWeapon(bool suicideShot = false) { //ignore if we are hovering over UI if (EventSystem.current.IsPointerOverGameObject()) { return; } //if we have no mag/clip loaded play empty sound if (CurrentMagazine == null) { InAutomaticAction = false; PlayEmptySFX(); } //if we are out of ammo for this weapon eject magazine and play out of ammo sfx else if (Projectile != null && CurrentMagazine.ammoRemains <= 0 && FireCountDown <= 0) { InAutomaticAction = false; ManualUnload(CurrentMagazine); OutOfAmmoSFX(); } else { //if we have a projectile to shoot, we have ammo and we are not waiting to be allowed to shoot again, Fire! if (Projectile != null && CurrentMagazine.ammoRemains > 0 && FireCountDown <= 0) { //Add too the cooldown timer to being allowed to shoot again FireCountDown += 1.0 / FireRate; //fire a single round if its a semi or automatic weapon if (WeaponType == WeaponType.SemiAutomatic || WeaponType == WeaponType.FullyAutomatic) { Vector2 dir = (Camera.main.ScreenToWorldPoint(Input.mousePosition) - PlayerManager.LocalPlayer.transform.position).normalized; RequestShootMessage.Send(gameObject, dir, Projectile.name, UIManager.DamageZone, suicideShot, PlayerManager.LocalPlayer); if (!isServer) { //Prediction (client bullets don't do any damage) Shoot(PlayerManager.LocalPlayer, dir, Projectile.name, UIManager.DamageZone, suicideShot); } if (WeaponType == WeaponType.FullyAutomatic) { PlayerManager.LocalPlayerScript.inputController.OnMouseDownDir(dir); } } if (WeaponType == WeaponType.FullyAutomatic) { InAutomaticAction = true; } } } }
public static RequestShootMessage Send(GameObject weapon, Vector2 direction, string bulletName, BodyPartType damageZone, bool isSuicideShot, GameObject shotBy) { RequestShootMessage msg = new RequestShootMessage { Target = direction, DamageZone = damageZone, IsSuicideShot = isSuicideShot, }; msg.Send(); return(msg); }
public static RequestShootMessage Send(GameObject weapon, Vector2 direction, string bulletName, BodyPartType damageZone, bool isSuicideShot, GameObject shotBy) { RequestShootMessage msg = new RequestShootMessage { Weapon = weapon ? weapon.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid, Direction = direction, BulletName = bulletName, DamageZone = damageZone, IsSuicideShot = isSuicideShot, ShotBy = shotBy ? shotBy.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid }; msg.Send(); return(msg); }
/// <summary> /// Attempt to fire a single shot of the weapon (this is called once per bullet for a burst of automatic fire). This /// should be invoked by the client when they want to perform a shot. /// </summary> /// <param name="isSuicide">if the shot should be a suicide shot, striking the weapon holder</param> /// <returns>true iff something happened</returns> private bool AttemptToFireWeapon(bool isSuicide) { PlayerMove shooter = ClientScene.FindLocalObject(ControlledByPlayer).GetComponent <PlayerMove>(); if (!shooter.allowInput || shooter.isGhost) { return(false); } //suicide is not allowed in some cases. isSuicide = isSuicide && AllowSuicide; //ignore if we are hovering over UI if (EventSystem.current.IsPointerOverGameObject()) { return(false); } //if we have no mag/clip loaded play empty sound if (CurrentMagazine == null) { StopAutomaticBurst(); PlayEmptySFX(); return(true); } //if we are out of ammo for this weapon eject magazine and play out of ammo sfx else if (Projectile != null && CurrentMagazine.ammoRemains <= 0 && FireCountDown <= 0) { StopAutomaticBurst(); RequestUnload(CurrentMagazine); OutOfAmmoSFX(); return(true); } else { //if we have a projectile to shoot, we have ammo and we are not waiting to be allowed to shoot again, Fire! if (Projectile != null && CurrentMagazine.ammoRemains > 0 && FireCountDown <= 0) { //fire a single round if its a semi or automatic weapon if (WeaponType == WeaponType.SemiAutomatic || WeaponType == WeaponType.FullyAutomatic) { //shot direction Vector2 dir = (Camera.main.ScreenToWorldPoint(Input.mousePosition) - PlayerManager.LocalPlayer.transform.position).normalized; if (!isServer) { //we're a client, request the server to make us shoot RequestShootMessage.Send(gameObject, dir, Projectile.name, UIManager.DamageZone, isSuicide, PlayerManager.LocalPlayer); //Prediction (client bullets don't do any damage) dir = ApplyRecoil(dir); DisplayShot(PlayerManager.LocalPlayer, dir, UIManager.DamageZone, isSuicide); } else { // we are the server, go ahead and shoot ServerShoot(PlayerManager.LocalPlayer, dir, UIManager.DamageZone, isSuicide); } if (WeaponType == WeaponType.FullyAutomatic) { PlayerManager.LocalPlayerScript.mouseInputController.OnMouseDownDir(dir); } } if (WeaponType == WeaponType.FullyAutomatic && !InAutomaticAction) { StartBurst(isSuicide); } else { ContinueBurst(isSuicide); } return(true); } } return(true); }