Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions EXILED/Exiled.API/Features/Items/Firearm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,30 +364,29 @@ public static Firearm Create(FirearmType type)
/// <param name="identifier">The <see cref="AttachmentIdentifier"/> to add.</param>
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);
}

/// <summary>
Expand Down
22 changes: 11 additions & 11 deletions EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

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

using Exiled.API.Interfaces;

using InventorySystem.Items;
Expand Down Expand Up @@ -56,7 +58,8 @@ internal FirearmPickup(ItemType type)
/// <summary>
/// Gets a value indicating whether the pickup is already distributed.
/// </summary>
public bool IsDistributed { get; internal set; }
[Obsolete("Feature deprecated")]
public bool IsDistributed { get; }

/// <summary>
/// Gets or sets a value indicating how much ammo can contain this <see cref="FirearmPickup"/>.
Expand Down Expand Up @@ -104,7 +107,7 @@ public int Ammo
}

/// <summary>
/// Gets or sets a ammo drain per shoot.
/// Gets or sets the ammo drain per shoot.
/// </summary>
/// <remarks>
/// Always <see langword="1"/> by default.
Expand All @@ -121,19 +124,16 @@ public uint Attachments
set => Base.Worldmodel.Setup(Base.CurId, Base.Worldmodel.WorldmodelType, value);
}

/// <inheritdoc />
public override void Spawn()
{
base.Spawn();
if (!IsDistributed)
Base.OnDistributed();
}
/// <summary>
/// Initializes the item as if it was spawned naturally by map generation.
/// </summary>
public void Distribute() => Base.OnDistributed();

/// <summary>
/// Returns the FirearmPickup in a human readable format.
/// 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*/0}-";
public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}*";

/// <inheritdoc/>
internal override void ReadItemInfo(Items.Item item)
Expand Down
27 changes: 0 additions & 27 deletions EXILED/Exiled.Events/Patches/Generic/FirearmDistribution.cs

This file was deleted.