diff --git a/EXILED/Exiled.API/Features/Items/Firearm.cs b/EXILED/Exiled.API/Features/Items/Firearm.cs index 663144ff8f..eeee66adcd 100644 --- a/EXILED/Exiled.API/Features/Items/Firearm.cs +++ b/EXILED/Exiled.API/Features/Items/Firearm.cs @@ -364,30 +364,29 @@ public static Firearm Create(FirearmType type) /// The to add. public void AddAttachment(AttachmentIdentifier identifier) { - uint toRemove = 0; - uint code = 1; + // Fallback addedCode onto AvailableAttachments' code in case it's 0 + uint addedCode = identifier.Code == 0 + ? AvailableAttachments[FirearmType].FirstOrDefault(attId => attId.Name == identifier.Name).Code + : identifier.Code; + + // Look for conflicting attachment (attachment that occupies the same slot) + uint conflicting = 0; + uint current = 1; foreach (Attachment attachment in Base.Attachments) { if (attachment.Slot == identifier.Slot && attachment.IsEnabled) { - toRemove = code; + conflicting = current; break; } - code *= 2; + current *= 2; } - uint newCode = identifier.Code == 0 - ? AvailableAttachments[FirearmType].FirstOrDefault( - attId => - attId.Name == identifier.Name).Code - : identifier.Code; - - Base.ApplyAttachmentsCode((Base.GetCurrentAttachmentsCode() & ~toRemove) | newCode, true); - - // TODO Not finish - // Base.Status = new FirearmStatus(Math.Min(Ammo, MaxAmmo), Base.Status.Flags, Base.GetCurrentAttachmentsCode()); + uint code = Base.ValidateAttachmentsCode((Base.GetCurrentAttachmentsCode() & ~conflicting) | addedCode); + Base.ApplyAttachmentsCode(code, false); + AttachmentCodeSync.ServerSetCode(Serial, code); } /// diff --git a/EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs b/EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs index feb8d4c57e..b1534a0ef8 100644 --- a/EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs +++ b/EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs @@ -7,6 +7,8 @@ namespace Exiled.API.Features.Pickups { + using System; + using Exiled.API.Interfaces; using InventorySystem.Items; @@ -56,7 +58,8 @@ internal FirearmPickup(ItemType type) /// /// Gets a value indicating whether the pickup is already distributed. /// - public bool IsDistributed { get; internal set; } + [Obsolete("Feature deprecated")] + public bool IsDistributed { get; } /// /// Gets or sets a value indicating how much ammo can contain this . @@ -104,7 +107,7 @@ public int Ammo } /// - /// Gets or sets a ammo drain per shoot. + /// Gets or sets the ammo drain per shoot. /// /// /// Always by default. @@ -121,19 +124,16 @@ public uint Attachments set => Base.Worldmodel.Setup(Base.CurId, Base.Worldmodel.WorldmodelType, value); } - /// - public override void Spawn() - { - base.Spawn(); - if (!IsDistributed) - Base.OnDistributed(); - } + /// + /// Initializes the item as if it was spawned naturally by map generation. + /// + public void Distribute() => Base.OnDistributed(); /// - /// Returns the FirearmPickup in a human readable format. + /// Returns the FirearmPickup in a human-readable format. /// /// A string containing FirearmPickup related data. - public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* |{IsDistributed}| -{/*Ammo*/0}-"; + public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}*"; /// internal override void ReadItemInfo(Items.Item item) diff --git a/EXILED/Exiled.Events/Patches/Generic/FirearmDistribution.cs b/EXILED/Exiled.Events/Patches/Generic/FirearmDistribution.cs deleted file mode 100644 index 30deefa442..0000000000 --- a/EXILED/Exiled.Events/Patches/Generic/FirearmDistribution.cs +++ /dev/null @@ -1,27 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) ExMod Team. All rights reserved. -// Licensed under the CC BY-SA 3.0 license. -// -// ----------------------------------------------------------------------- - -namespace Exiled.Events.Patches.Generic -{ -#pragma warning disable SA1313 - using Exiled.API.Features.Pickups; - using HarmonyLib; - - using BaseFirearm = InventorySystem.Items.Firearms.FirearmPickup; - - /// - /// Patch to add . - /// - [HarmonyPatch(typeof(BaseFirearm), nameof(BaseFirearm.OnDistributed))] - internal static class FirearmDistribution - { - private static void Postfix(BaseFirearm __instance) - { - Pickup.Get(__instance).IsDistributed = true; - } - } -} \ No newline at end of file