From 1e08ee16ac5b2b89119fd75012cf162e996c4f86 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Thu, 23 May 2024 15:31:43 +0200 Subject: [PATCH] Fix grenade launchers --- .../CoopClientFirearmController.cs | 26 +++++++++++-- .../Coop/FreeCamera/FreeCameraController.cs | 5 +-- Fika.Core/Coop/GameMode/CoopGame.cs | 2 +- .../CoopObservedFirearmController.cs | 37 ++++++++++++++++--- .../Packets/FirearmController/WeaponPacket.cs | 6 +++ 5 files changed, 63 insertions(+), 13 deletions(-) diff --git a/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientFirearmController.cs b/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientFirearmController.cs index 91802259..cd92be42 100644 --- a/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientFirearmController.cs +++ b/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientFirearmController.cs @@ -237,7 +237,7 @@ public override void InitiateShot(GInterface322 weapon, BulletClass ammo, Vector FireportPosition = fireportPosition, ChamberIndex = chamberIndex, Overheat = overheat, - UnderbarrelShot = weapon.IsUnderbarrelWeapon, + UnderbarrelShot = Weapon.IsUnderBarrelDeviceActive, AmmoTemplate = ammo.AmmoTemplate._id, LastShotOverheat = weapon.MalfState.LastShotOverheat, LastShotTime = weapon.MalfState.LastShotTime, @@ -308,18 +308,36 @@ public override void ReloadGrenadeLauncher(GClass2495 ammoPack, Callback callbac return; } - CurrentOperation.ReloadGrenadeLauncher(ammoPack, callback); - string[] reloadingAmmoIds = ammoPack.GetReloadingAmmoIds(); - coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { + HasReloadLauncherPacket = true, ReloadLauncher = new() { Reload = true, AmmoIds = reloadingAmmoIds } }); + + CurrentOperation.ReloadGrenadeLauncher(ammoPack, callback); + } + + public override void UnderbarrelSightingRangeUp() + { + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() + { + UnderbarrelSightingRangeUp = true + }); + base.UnderbarrelSightingRangeUp(); + } + + public override void UnderbarrelSightingRangeDown() + { + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() + { + UnderbarrelSightingRangeDown = true + }); + base.UnderbarrelSightingRangeDown(); } public override void ReloadMag(MagazineClass magazine, GClass2769 gridItemAddress, Callback callback) diff --git a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs index b5e8cca0..812b80bb 100644 --- a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs +++ b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs @@ -12,7 +12,6 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Reflection; using TMPro; using UnityEngine; @@ -120,7 +119,7 @@ protected void Update() if (_player.PlayerHealthController == null) { return; - } + } CoopHandler.EQuitState quitState = coopHandler.GetQuitState(); @@ -201,7 +200,7 @@ private IEnumerator DeathRoutine() if (!_freeCamScript.IsActive) { ToggleCamera(); - ToggleUi(); + ToggleUi(); } ShowExtractMessage(); diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 3343d109..26351d76 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -1732,7 +1732,7 @@ private void SavePlayer(CoopPlayer player, ExitStatus exitStatus, string exitNam //Since we're bypassing saving on exiting, run this now. player.Profile.EftStats.LastPlayerState = null; player.StatisticsManager.EndStatisticsSession(exitStatus, PastTime); - player.CheckAndResetControllers(exitStatus, PastTime, Location_0.Id, exitName); + player.CheckAndResetControllers(exitStatus, PastTime, Location_0.Id, exitName); } //Method taken directly from AKI, can be found in the aki-singleplayer assembly as OfflineSaveProfilePatch diff --git a/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedFirearmController.cs b/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedFirearmController.cs index c3290abb..c7507469 100644 --- a/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedFirearmController.cs +++ b/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedFirearmController.cs @@ -3,8 +3,10 @@ using Comfort.Common; using EFT; using EFT.InventoryLogic; +using EFT.UI; using Fika.Core.Coop.Players; using Fika.Core.Networking; +using HarmonyLib; using System; using System.Collections; using System.Collections.Generic; @@ -28,6 +30,7 @@ public class CoopObservedFirearmController : FirearmController private float aimMovementSpeed = 1f; private bool hasFired = false; private WeaponPrefab weaponPrefab; + private GClass1582 underBarrelManager; public override bool IsAiming { get => base.IsAiming; @@ -43,7 +46,7 @@ public override bool IsAiming } _isAiming = value; - _player.Skills.FastAimTimer.Target = (value ? 0f : 2f); + _player.Skills.FastAimTimer.Target = value ? 0f : 2f; _player.MovementContext.SetAimingSlowdown(IsAiming, 0.33f + aimMovementSpeed); _player.Physical.Aim((!_isAiming || !(_player.MovementContext.StationaryWeapon == null)) ? 0f : ErgonomicWeight); coopPlayer.ProceduralWeaponAnimation.IsAiming = _isAiming; @@ -62,6 +65,10 @@ protected void Start() _objectInHandsAnimator.SetAiming(false); aimMovementSpeed = coopPlayer.Skills.GetWeaponInfo(Item).AimMovementSpeed; weaponPrefab = ControllerGameObject.GetComponent(); + if (UnderbarrelWeapon != null) + { + underBarrelManager = Traverse.Create(this).Field("gclass1582_0").GetValue(); + } } public static CoopObservedFirearmController Create(CoopPlayer player, Weapon weapon) @@ -226,7 +233,7 @@ public void HandleFirearmPacket(in WeaponPacket packet, InventoryControllerClass } BulletClass ammo = (BulletClass)Singleton.Instance.CreateItem(MongoID.Generate(), packet.ShotInfoPacket.AmmoTemplate, null); - InitiateShot(Item, ammo, packet.ShotInfoPacket.ShotPosition, packet.ShotInfoPacket.ShotDirection, + InitiateShot(packet.ShotInfoPacket.UnderbarrelShot ? UnderbarrelWeapon : Item, ammo, packet.ShotInfoPacket.ShotPosition, packet.ShotInfoPacket.ShotDirection, packet.ShotInfoPacket.FireportPosition, packet.ShotInfoPacket.ChamberIndex, packet.ShotInfoPacket.Overheat); if (Weapon.SelectedFireMode == Weapon.EFireMode.fullauto) @@ -254,6 +261,18 @@ public void HandleFirearmPacket(in WeaponPacket packet, InventoryControllerClass FirearmsAnimator.SetFire(true); + if (packet.ShotInfoPacket.UnderbarrelShot) + { + if (UnderbarrelWeapon.Chamber.ContainedItem is BulletClass grenadeBullet && !grenadeBullet.IsUsed) + { + grenadeBullet.IsUsed = true; + UnderbarrelWeapon.Chamber.RemoveItem(); + underBarrelManager?.DestroyPatronInWeapon(); + } + FirearmsAnimator.SetFire(false); + return; + } + if (Weapon.HasChambers) { if (Weapon.ReloadMode is Weapon.EReloadMode.OnlyBarrel) @@ -284,7 +303,7 @@ public void HandleFirearmPacket(in WeaponPacket packet, InventoryControllerClass } else { - Weapon.Chambers[0].RemoveItem(false); + Weapon.Chambers[0].RemoveItem(); if (weaponPrefab != null && weaponPrefab.ObjectInHands is GClass1668 weaponEffectsManager) { HandleShellEvent(weaponEffectsManager, packet, ammo, magazine); @@ -521,8 +540,6 @@ public void HandleFirearmPacket(in WeaponPacket packet, InventoryControllerClass { CurrentOperation.SetTriggerPressed(true); } - - }*/ if (packet.HasRollCylinder && Weapon is GClass2696 rollWeapon) @@ -594,6 +611,16 @@ public void HandleFirearmPacket(in WeaponPacket packet, InventoryControllerClass { StartCoroutine(ObservedBoltAction(FirearmsAnimator, this, inventoryController)); } + + if (packet.UnderbarrelSightingRangeUp) + { + UnderbarrelSightingRangeUp(); + } + + if (packet.UnderbarrelSightingRangeDown) + { + UnderbarrelSightingRangeDown(); + } } private IEnumerator ObservedBoltAction(FirearmsAnimator animator, FirearmController controller, InventoryControllerClass inventoryController) diff --git a/Fika.Core/Networking/Packets/FirearmController/WeaponPacket.cs b/Fika.Core/Networking/Packets/FirearmController/WeaponPacket.cs index ede93653..7a841088 100644 --- a/Fika.Core/Networking/Packets/FirearmController/WeaponPacket.cs +++ b/Fika.Core/Networking/Packets/FirearmController/WeaponPacket.cs @@ -54,6 +54,8 @@ public struct WeaponPacket(int netId) : INetSerializable public bool ReloadBoltAction = false; public bool HasRollCylinder = false; public bool RollToZeroCamora = false; + public bool UnderbarrelSightingRangeUp = false; + public bool UnderbarrelSightingRangeDown = false; public void Deserialize(NetDataReader reader) { @@ -123,6 +125,8 @@ public void Deserialize(NetDataReader reader) HasRollCylinder = reader.GetBool(); if (HasRollCylinder) RollToZeroCamora = reader.GetBool(); + UnderbarrelSightingRangeUp = reader.GetBool(); + UnderbarrelSightingRangeDown = reader.GetBool(); } public void Serialize(NetDataWriter writer) @@ -189,6 +193,8 @@ public void Serialize(NetDataWriter writer) writer.Put(HasRollCylinder); if (HasRollCylinder) writer.Put(RollToZeroCamora); + writer.Put(UnderbarrelSightingRangeUp); + writer.Put(UnderbarrelSightingRangeDown); } } }