From e04be3817df82aaf5a1a42a106c0402f40e1eeec Mon Sep 17 00:00:00 2001 From: Banalny-Banan Date: Wed, 5 Feb 2025 20:30:56 +0200 Subject: [PATCH 1/2] first --- EXILED/Exiled.API/Features/Items/Firearm.cs | 27 +++++++++---------- .../Features/Pickups/FirearmPickup.cs | 22 +++++---------- .../Patches/Generic/FirearmDistribution.cs | 27 ------------------- 3 files changed, 20 insertions(+), 56 deletions(-) delete mode 100644 EXILED/Exiled.Events/Patches/Generic/FirearmDistribution.cs 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..5422c5b5fc 100644 --- a/EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs +++ b/EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs @@ -53,11 +53,6 @@ internal FirearmPickup(ItemType type) /// public new BaseFirearm Base { get; } - /// - /// Gets a value indicating whether the pickup is already distributed. - /// - public bool IsDistributed { get; internal set; } - /// /// Gets or sets a value indicating how much ammo can contain this . /// @@ -104,7 +99,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 +116,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 From 1be9a13b81ebf16593c03252e71e6e20ff386b78 Mon Sep 17 00:00:00 2001 From: Banalny-Banan Date: Wed, 5 Feb 2025 20:39:04 +0200 Subject: [PATCH 2/2] backward compatibility --- EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs b/EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs index 5422c5b5fc..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; @@ -53,6 +55,12 @@ internal FirearmPickup(ItemType type) /// public new BaseFirearm Base { get; } + /// + /// Gets a value indicating whether the pickup is already distributed. + /// + [Obsolete("Feature deprecated")] + public bool IsDistributed { get; } + /// /// Gets or sets a value indicating how much ammo can contain this . ///