Skip to content

Commit

Permalink
Fix grenade launchers
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed May 23, 2024
1 parent 186df30 commit 1e08ee1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions Fika.Core/Coop/FreeCamera/FreeCameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using TMPro;
using UnityEngine;

Expand Down Expand Up @@ -120,7 +119,7 @@ protected void Update()
if (_player.PlayerHealthController == null)
{
return;
}
}

CoopHandler.EQuitState quitState = coopHandler.GetQuitState();

Expand Down Expand Up @@ -201,7 +200,7 @@ private IEnumerator DeathRoutine()
if (!_freeCamScript.IsActive)
{
ToggleCamera();
ToggleUi();
ToggleUi();
}
ShowExtractMessage();

Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -62,6 +65,10 @@ protected void Start()
_objectInHandsAnimator.SetAiming(false);
aimMovementSpeed = coopPlayer.Skills.GetWeaponInfo(Item).AimMovementSpeed;
weaponPrefab = ControllerGameObject.GetComponent<WeaponPrefab>();
if (UnderbarrelWeapon != null)
{
underBarrelManager = Traverse.Create(this).Field("gclass1582_0").GetValue<GClass1582>();
}
}

public static CoopObservedFirearmController Create(CoopPlayer player, Weapon weapon)
Expand Down Expand Up @@ -226,7 +233,7 @@ public void HandleFirearmPacket(in WeaponPacket packet, InventoryControllerClass
}

BulletClass ammo = (BulletClass)Singleton<ItemFactory>.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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -521,8 +540,6 @@ public void HandleFirearmPacket(in WeaponPacket packet, InventoryControllerClass
{
CurrentOperation.SetTriggerPressed(true);
}
}*/

if (packet.HasRollCylinder && Weapon is GClass2696 rollWeapon)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -189,6 +193,8 @@ public void Serialize(NetDataWriter writer)
writer.Put(HasRollCylinder);
if (HasRollCylinder)
writer.Put(RollToZeroCamora);
writer.Put(UnderbarrelSightingRangeUp);
writer.Put(UnderbarrelSightingRangeDown);
}
}
}

0 comments on commit 1e08ee1

Please sign in to comment.