Skip to content

Commit

Permalink
FirearmPickup fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xNexusACS committed Dec 3, 2024
1 parent 15f0ce6 commit 8c2b705
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Exiled.API/Features/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Exiled.API.Features.Items
using System.Collections.Generic;
using System.Linq;

using Exiled.API.Features.Core;
using Core;
using Exiled.API.Features.Core.Attributes;
using Exiled.API.Features.Pickups;
using Exiled.API.Interfaces;
Expand Down
39 changes: 11 additions & 28 deletions Exiled.API/Features/Pickups/FirearmPickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

namespace Exiled.API.Features.Pickups
{
using System.Linq;

using Exiled.API.Enums;
using Exiled.API.Extensions;
using Exiled.API.Features.Core.Attributes;
using Exiled.API.Features.Items;
using Exiled.API.Interfaces;
using InventorySystem.Items;
using InventorySystem.Items.Firearms.Modules;

using BaseFirearm = InventorySystem.Items.Firearms.FirearmPickup;
using FirearmItem = InventorySystem.Items.Firearms.Firearm;
Expand Down Expand Up @@ -42,8 +45,8 @@ internal FirearmPickup(ItemType type)
Base = (BaseFirearm)((Pickup)this).Base;
Base.OnDistributed();

if (type is ItemType.ParticleDisruptor && Status.Ammo <= 0)
Status = new FirearmStatus(5, FirearmStatusFlags.MagazineInserted, 0);
if (type is ItemType.ParticleDisruptor && Base.Template.Modules.OfType<MagazineModule>().FirstOrDefault()!.AmmoStored <= 0)
Base.Template.Modules.OfType<MagazineModule>().FirstOrDefault()!.AmmoStored = 5;
}

/// <summary>
Expand All @@ -63,24 +66,14 @@ internal FirearmPickup(ItemType type)
[EProperty(category: nameof(FirearmPickup))]
public AmmoType AmmoType { get; set; }

/// <summary>
/// Gets or sets the <see cref="FirearmStatus"/>.
/// </summary>
[EProperty(category: nameof(FirearmPickup))]
public FirearmStatus Status
{
get => Base.NetworkStatus;
set => Base.NetworkStatus = value;
}

/// <summary>
/// Gets or sets a value indicating how many ammo have this <see cref="FirearmPickup"/>.
/// </summary>
[EProperty(category: nameof(FirearmPickup))]
public byte Ammo
public int Ammo
{
get => Base.NetworkStatus.Ammo;
set => Base.NetworkStatus = new(value, Base.NetworkStatus.Flags, Base.NetworkStatus.Attachments);
get => Base.Template.Modules.OfType<MagazineModule>().FirstOrDefault()?.AmmoStored ?? 0;
set => Base.Template.Modules.OfType<MagazineModule>().FirstOrDefault()!.AmmoStored = value;
}

/// <summary>
Expand All @@ -89,31 +82,21 @@ public byte Ammo
[EProperty(category: nameof(FirearmPickup))]
public int MaxAmmo { get; set; }

/// <summary>
/// Gets or sets the <see cref="FirearmStatusFlags"/>.
/// </summary>
[EProperty(category: nameof(FirearmPickup))]
public FirearmStatusFlags Flags
{
get => Base.NetworkStatus.Flags;
set => Base.NetworkStatus = new(Base.NetworkStatus.Ammo, value, Base.NetworkStatus.Attachments);
}

/// <summary>
/// Gets or sets a value indicating whether the attachment code have this <see cref="FirearmPickup"/>.
/// </summary>
[EProperty(category: nameof(FirearmPickup))]
public uint Attachments
{
get => Base.NetworkStatus.Attachments;
set => Base.NetworkStatus = new(Base.NetworkStatus.Ammo, Base.NetworkStatus.Flags, value);
get => Base.Worldmodel.AttachmentCode;
set => Base.Worldmodel.AttachmentCode = value;
}

/// <summary>
/// Returns the FirearmPickup in a human readable format.
/// </summary>
/// <returns>A string containing FirearmPickup related data.</returns>
public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* |{IsDistributed}| -{Ammo}-";
public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* -{Ammo}-";

/// <inheritdoc/>
internal override void ReadItemInfo(Item item)
Expand Down

0 comments on commit 8c2b705

Please sign in to comment.