private void Initialize() { grabbable = GetComponent <VR_Grabbable>(); audioSource = GetComponent <AudioSource>(); hapticsController = GetComponent <VR_Haptics>(); twoHandGrabbable = transform.GetComponentInChildren <VR_TwoHandGrabbable>(); if (twoHandGrabbable != null) { twoHandGrabbable.SetApplyTwoHandTransformManually(true); } if (reloadMode == ReloadMode.Realistic) { if (magazineDropZone != null && magazineDropZone.StartingDrop != null) { CurrentMagazine = magazineDropZone.StartingDrop.GetComponent <VR_WeaponMag>(); if (CurrentMagazine != null) { CurrentMagazine.SetOwner(this); //say to the grabbable that ignore disabling and enabling the mag collider grabbable.IgnoreCollider(CurrentMagazine.GetComponent <Collider>()); } } magazineDropZone.OnDrop.AddListener(OnMagazineDropStateChange); magazineDropZone.OnUnDrop.AddListener(OnMagazineUnDropStateChange); } }
public override void ServerPerformInteraction(AimApply interaction) { if (firemodeUsage[currentFiremode] > battery.Watts) { return; } base.ServerPerformInteraction(interaction); CurrentMagazine.ServerSetAmmoRemains(battery.Watts / firemodeUsage[currentFiremode]); }
private IEnumerator StartCooldown() { allowRecharge = false; yield return(WaitFor.Seconds(rechargeTime)); CurrentMagazine.ExpendAmmo(-1); SoundManager.PlayNetworkedAtPos("ReloadKinetic", gameObject.AssumedWorldPosServer(), sourceObj: serverHolder); allowRecharge = true; }
private IEnumerator StartCooldown() { allowRecharge = false; yield return(WaitFor.Seconds(rechargeTime)); CurrentMagazine.ServerSetAmmoRemains(1); CurrentMagazine.LoadProjectile(CurrentMagazine.Projectile, CurrentMagazine.ProjectilesFired); SoundManager.PlayNetworkedAtPos("ReloadKinetic", gameObject.AssumedWorldPosServer(), sourceObj: serverHolder); allowRecharge = true; }
void Start() { Cursor.lockState = CursorLockMode.Locked; HealthText.text = "HP: " + Health.ToString(); AmmoText.text = "Magazine: " + CurrentMagazine.ToString() + "/ Ammo:" + Ammo.ToString(); MyBody = GetComponent <Rigidbody>(); Col = GetComponent <Collider>(); GroundDistance = Col.bounds.extents.y; }
public override void ServerPerformInteraction(HandActivate interaction) { if (firemodeProjectiles.Count <= 1) { return; } if (currentFiremode == firemodeProjectiles.Count - 1) { UpdateFiremode(currentFiremode, 0); } else { UpdateFiremode(currentFiremode, currentFiremode + 1); } Chat.AddExamineMsgFromServer(interaction.Performer, $"You switch your {gameObject.ExpensiveName()} into {firemodeName[currentFiremode]} mode"); CurrentMagazine.ServerSetAmmoRemains(battery.Watts / firemodeUsage[currentFiremode]); }
private IEnumerator StartCooldown() { allowRecharge = false; yield return(WaitFor.Seconds(rechargeTime)); CurrentMagazine.ServerSetAmmoRemains(1); CurrentMagazine.LoadProjectile(Projectile, 1); if (isSuppressed) { Chat.AddExamineMsgFromServer(serverHolder, $"Your {gameObject.ExpensiveName()} silently recharges"); } else { SoundManager.PlayNetworkedAtPos("ReloadKinetic", gameObject.AssumedWorldPosServer(), sourceObj: serverHolder); } allowRecharge = true; }
IEnumerator Fire() { if (CanAttack && CurrentMagazine > 0 && !Reload) { CanAttack = false; CurrentMagazine--; AmmoText.text = "Magazine: " + CurrentMagazine.ToString() + "/ Ammo:" + Ammo.ToString(); Instantiate(Bullet, StartBullet.transform.position, StartBullet.transform.rotation); if (CurrentMagazine <= 0) { StartCoroutine(StartReload()); Reload = true; } CanAttack = true; yield return(new WaitForSeconds(1f)); } }
IEnumerator StartReload() { yield return(new WaitForSeconds(1f)); if (Ammo > Magazine) { int Num = Magazine; Num = Num - CurrentMagazine; Ammo -= Num; CurrentMagazine = Magazine; } else { CurrentMagazine = Ammo; Ammo = 0; } AmmoText.text = "Magazine: " + CurrentMagazine.ToString() + "/ Ammo:" + Ammo.ToString(); Reload = false; }
public override void OnSpawnServer(SpawnInfo info) { base.OnSpawnServer(info); CurrentMagazine.containedBullets[0] = Projectile; CurrentMagazine.ServerSetAmmoRemains(1); }
public override void DisplayShot(GameObject shooter, Vector2 finalDirection, BodyPartType damageZone, bool isSuicideShot) { if (!MatrixManager.IsInitialized) { return; } //if this is our gun (or server), last check to ensure we really can shoot if ((isServer || PlayerManager.LocalPlayer == shooter) && CurrentMagazine.ClientAmmoRemains <= 0) { if (isServer) { Logger.LogTrace("Server rejected shot - out of ammo", Category.Firearms); } return; } //TODO: If this is not our gun, simply display the shot, don't run any other logic if (shooter == PlayerManager.LocalPlayer) { //this is our gun so we need to update our predictions FireCountDown += 1.0 / FireRate; //add additional recoil after shooting for the next round AppendRecoil(); //Default camera recoil params until each gun is configured separately if (CameraRecoilConfig == null || CameraRecoilConfig.Distance == 0f) { CameraRecoilConfig = new CameraRecoilConfig { Distance = 0.2f, RecoilDuration = 0.05f, RecoveryDuration = 0.6f }; } Camera2DFollow.followControl.Recoil(-finalDirection, CameraRecoilConfig); } if (CurrentMagazine == null) { Logger.Log("Why is CurrentMagazine null on this client?"); } else { //call ExpendAmmo outside of previous check, or it won't run serverside and state will desync. CurrentMagazine.ExpendAmmo(); } //display the effects of the shot //get the bullet prefab being shot if (isSuicideShot) { GameObject bullet = Spawn.ClientPrefab(Projectile.name, shooter.transform.position, parent: shooter.transform.parent).GameObject; var b = bullet.GetComponent <Projectile>(); b.Suicide(shooter, this, damageZone); } else { for (int n = 0; n < CurrentMagazine.ProjectilesFired; n++) { GameObject Abullet = Spawn.ClientPrefab(Projectile.name, shooter.transform.position, parent: shooter.transform.parent).GameObject; var A = Abullet.GetComponent <Projectile>(); var finalDirectionOverride = CalcDirection(finalDirection, n); A.Shoot(finalDirectionOverride, shooter, this, damageZone); } } SoundManager.PlayAtPosition(FiringSound, shooter.transform.position, shooter); shooter.GetComponent <PlayerSprites>().ShowMuzzleFlash(); }