Skip to content

Commit

Permalink
Update fields and props on oFirearmController
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Jan 7, 2025
1 parent fa44175 commit 03e6586
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,30 @@ namespace Fika.Core.Coop.ObservedClasses
{
public class CoopObservedFirearmController : FirearmController
{
public WeaponPrefab WeaponPrefab
public WeaponManagerClass WeaponManager
{
get
{
return weaponPrefab;
}
set
{
weaponPrefab = value;
return weaponManager;
}
}

private CoopPlayer coopPlayer;
private bool triggerPressed;
private bool needsReset;
private float lastFireTime = 0f;
public override bool IsTriggerPressed
{
get
{
return triggerPressed;
}
}

private CoopPlayer coopPlayer;
private bool triggerPressed;
private bool needsReset;
private float lastFireTime = 0f;
private float overlapCounter = 0f;
private float aimMovementSpeed = 1f;
private bool hasFired = false;
private WeaponPrefab weaponPrefab;
private WeaponManagerClass weaponManager;
private GClass1773 underBarrelManager;
private bool boltActionReload;
private bool isThrowingPatron;
Expand Down Expand Up @@ -120,7 +117,9 @@ protected void Start()
{
_objectInHandsAnimator.SetAiming(false);
aimMovementSpeed = coopPlayer.Skills.GetWeaponInfo(Item).AimMovementSpeed;
WeaponPrefab = ControllerGameObject.GetComponent<WeaponPrefab>();
WeaponPrefab prefab = ControllerGameObject.GetComponent<WeaponPrefab>();
weaponPrefab = prefab;
weaponManager = weaponPrefab.ObjectInHands as WeaponManagerClass;
if (UnderbarrelWeapon != null)
{
underBarrelManager = Traverse.Create(this).Field<GClass1773>("GClass1773_0").Value;
Expand Down Expand Up @@ -229,23 +228,20 @@ public override void IEventsConsumerOnShellEject()
return;
}

if (WeaponPrefab != null && WeaponPrefab.ObjectInHands is WeaponManagerClass weaponEffectsManager)
weaponManager.StartSpawnShell(coopPlayer.Velocity * 0.66f, 0);
if (boltActionReload)
{
weaponEffectsManager.StartSpawnShell(coopPlayer.Velocity * 0.66f, 0);
if (boltActionReload)
MagazineItemClass magazine = Item.GetCurrentMagazine();
Weapon weapon = Weapon;
if (magazine != null && magazine is not CylinderMagazineItemClass && weapon.HasChambers)
{
MagazineItemClass magazine = Item.GetCurrentMagazine();
Weapon weapon = Weapon;
if (magazine != null && magazine is not CylinderMagazineItemClass && weapon.HasChambers)
{
magazine.Cartridges.PopTo(coopPlayer.InventoryController, Item.Chambers[0].CreateItemAddress());
}
magazine.Cartridges.PopTo(coopPlayer.InventoryController, Item.Chambers[0].CreateItemAddress());
}

FirearmsAnimator.SetBoltActionReload(false);
FirearmsAnimator.SetFire(false);
FirearmsAnimator.SetBoltActionReload(false);
FirearmsAnimator.SetFire(false);

boltActionReload = false;
}
boltActionReload = false;
}
}

Expand Down Expand Up @@ -330,22 +326,15 @@ public void HandleShotInfoPacket(ref ShotInfoPacket packet, InventoryController
AmmoItemClass ammo = (AmmoItemClass)Singleton<ItemFactoryClass>.Instance.CreateItem(MongoID.Generate(), packet.AmmoTemplate.Value, null);
Weapon.MalfState.MalfunctionedAmmo = ammo;
Weapon.MalfState.AmmoToFire = ammo;
if (WeaponPrefab != null)
if (Weapon.HasChambers && Weapon.Chambers[0].ContainedItem is AmmoItemClass)
{
if (Weapon.HasChambers && Weapon.Chambers[0].ContainedItem is AmmoItemClass)
{
Weapon.Chambers[0].RemoveItemWithoutRestrictions();
}
WeaponPrefab.InitMalfunctionState(Weapon, false, false, out _);
if (Weapon.MalfState.State == Weapon.EMalfunctionState.Misfire)
{
WeaponPrefab.RevertMalfunctionState(Weapon, true, true);
coopPlayer.InventoryController.ExamineMalfunction(Weapon, true);
}
Weapon.Chambers[0].RemoveItemWithoutRestrictions();
}
else
weaponPrefab.InitMalfunctionState(Weapon, false, false, out _);
if (Weapon.MalfState.State == Weapon.EMalfunctionState.Misfire)
{
FikaPlugin.Instance.FikaLogger.LogError("CoopObservedFirearmController::HandleShotInfoPacket: WeaponPrefab was null!");
weaponPrefab.RevertMalfunctionState(Weapon, true, true);
coopPlayer.InventoryController.ExamineMalfunction(Weapon, true);
}
return;
}
Expand Down Expand Up @@ -440,10 +429,7 @@ private void HandleObservedShot(ref ShotInfoPacket packet, InventoryController i
{
grenadeBullet.IsUsed = true;
slot.RemoveItem();
if (WeaponPrefab.ObjectInHands is WeaponManagerClass weaponEffectsManager)
{
weaponEffectsManager.MoveAmmoFromChamberToShellPort(true, index);
}
weaponManager.MoveAmmoFromChamberToShellPort(true, index);
Weapon.ShellsInChambers[index] = grenadeBullet.AmmoTemplate;
FirearmsAnimator.SetAmmoInChamber(Weapon.ChamberAmmoCount);
FirearmsAnimator.SetShellsInWeapon(Weapon.ShellsInWeaponCount);
Expand All @@ -461,16 +447,13 @@ private void HandleObservedShot(ref ShotInfoPacket packet, InventoryController i
if (Weapon.Chambers[i].ContainedItem is AmmoItemClass bClass && !bClass.IsUsed)
{
bClass.IsUsed = true;
if (WeaponPrefab != null && WeaponPrefab.ObjectInHands is WeaponManagerClass weaponEffectsManager)
if (!bClass.AmmoTemplate.RemoveShellAfterFire)
{
weaponManager.MoveAmmoFromChamberToShellPort(bClass.IsUsed, i);
}
else
{
if (!bClass.AmmoTemplate.RemoveShellAfterFire)
{
weaponEffectsManager.MoveAmmoFromChamberToShellPort(bClass.IsUsed, i);
}
else
{
weaponEffectsManager.DestroyPatronInWeapon();
}
weaponManager.DestroyPatronInWeapon();
}
if (!bClass.AmmoTemplate.RemoveShellAfterFire)
{
Expand All @@ -482,10 +465,7 @@ private void HandleObservedShot(ref ShotInfoPacket packet, InventoryController i
else
{
Weapon.Chambers[0].RemoveItem(false);
if (WeaponPrefab != null && WeaponPrefab.ObjectInHands is WeaponManagerClass weaponEffectsManager)
{
HandleShellEvent(weaponEffectsManager, packet.ChamberIndex, ammo, magazine);
}
HandleShellEvent(weaponManager, packet.ChamberIndex, ammo, magazine);
}
FirearmsAnimator.SetAmmoInChamber(Weapon.ChamberAmmoCount);
}
Expand Down Expand Up @@ -515,10 +495,7 @@ private void HandleObservedShot(ref ShotInfoPacket packet, InventoryController i
FirearmsAnimator.SetCamoraIndex(cylinderMagazine.CurrentCamoraIndex);
FirearmsAnimator.SetDoubleAction(Convert.ToSingle(Weapon.CylinderHammerClosed));
FirearmsAnimator.SetHammerArmed(!Weapon.CylinderHammerClosed);
if (WeaponPrefab != null && WeaponPrefab.ObjectInHands is WeaponManagerClass weaponEffectsManager)
{
weaponEffectsManager.MoveAmmoFromChamberToShellPort(cylinderAmmo.IsUsed, firstIndex);
}
weaponManager.MoveAmmoFromChamberToShellPort(cylinderAmmo.IsUsed, firstIndex);

FirearmsAnimator.SetAmmoOnMag(cylinderMagazine.Count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,10 +1044,7 @@ public void Execute(CoopPlayer player)
AmmoItemClass bulletClass = (AmmoItemClass)Singleton<ItemFactoryClass>.Instance.CreateItem(MongoID.Generate(), AmmoTemplateId, null);
controller.InitiateFlare(bulletClass, ShotPosition, ShotForward);
bulletClass.IsUsed = true;
if (controller.WeaponPrefab.ObjectInHands is WeaponManagerClass weaponEffectsManager)
{
weaponEffectsManager.MoveAmmoFromChamberToShellPort(bulletClass.IsUsed, 0);
}
controller.WeaponManager.MoveAmmoFromChamberToShellPort(bulletClass.IsUsed, 0);
bulletClass = null;
controller.FirearmsAnimator.SetFire(false);
}
Expand Down

0 comments on commit 03e6586

Please sign in to comment.