Skip to content

Commit

Permalink
Fix MaxAmmo and CustomItem Weapon (#2302)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 authored Nov 29, 2023
1 parent 0c7a9cb commit 0e5842e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Exiled.API/Features/Items/Firearm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ public byte MaxAmmo
switch (Base.AmmoManagerModule)
{
case TubularMagazineAmmoManager tubularMagazineAmmoManager:
tubularMagazineAmmoManager.MaxAmmo = value;
tubularMagazineAmmoManager.MaxAmmo = (byte)(value - Base.AttachmentsValue(AttachmentParam.MagazineCapacityModifier) - (Base.Status.Flags.HasFlagFast(FirearmStatusFlags.Cocked) ? tubularMagazineAmmoManager.ChamberedRounds : 0));
break;
case ClipLoadedInternalMagAmmoManager clipLoadedInternalMagAmmoManager:
clipLoadedInternalMagAmmoManager.MaxAmmo = value;
clipLoadedInternalMagAmmoManager.MaxAmmo = (byte)(value - Base.AttachmentsValue(AttachmentParam.MagazineCapacityModifier));
break;
case AutomaticAmmoManager automaticAmmoManager:
automaticAmmoManager.MaxAmmo = value;
automaticAmmoManager.MaxAmmo = (byte)(value - Base.AttachmentsValue(AttachmentParam.MagazineCapacityModifier) - automaticAmmoManager.ChamberedAmount);
break;
default:
Log.Warn($"MaxAmmo can't be used for this Item: {Type} ({Base.AmmoManagerModule})");
Expand Down
7 changes: 5 additions & 2 deletions Exiled.CustomItems/API/Features/CustomWeapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Exiled.CustomItems.API.Features
{
using System;

using Exiled.API.Enums;
using Exiled.API.Extensions;
using Exiled.API.Features;
using Exiled.API.Features.DamageHandlers;
Expand All @@ -19,7 +18,6 @@ namespace Exiled.CustomItems.API.Features

using InventorySystem.Items.Firearms.Attachments;
using InventorySystem.Items.Firearms.Attachments.Components;
using InventorySystem.Items.Firearms.BasicMessages;

using UnityEngine;

Expand Down Expand Up @@ -77,6 +75,7 @@ public override ItemType Type
firearm.AddAttachment(Attachments);

firearm.Ammo = ClipSize;
firearm.MaxAmmo = ClipSize;

Pickup? pickup = firearm.CreatePickup(position);

Expand All @@ -102,7 +101,9 @@ public override ItemType Type
{
if (!Attachments.IsEmpty())
firearm.AddAttachment(Attachments);

byte ammo = firearm.Ammo;
firearm.MaxAmmo = ClipSize;
Log.Debug($"{nameof(Name)}.{nameof(Spawn)}: Spawning weapon with {ammo} ammo.");
Pickup? pickup = firearm.CreatePickup(position);
pickup.Scale = Scale;
Expand All @@ -126,7 +127,9 @@ public override void Give(Player player, bool displayMessage = true)
{
if (!Attachments.IsEmpty())
firearm.AddAttachment(Attachments);

firearm.Ammo = ClipSize;
firearm.MaxAmmo = ClipSize;
}

Log.Debug($"{nameof(Give)}: Adding {item.Serial} to tracker.");
Expand Down

0 comments on commit 0e5842e

Please sign in to comment.