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
19 changes: 19 additions & 0 deletions EXILED/Exiled.CustomItems/API/Features/CustomWeapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Exiled.CustomItems.API.Features
using Exiled.API.Features.DamageHandlers;
using Exiled.API.Features.Items;
using Exiled.API.Features.Pickups;
using Exiled.Events.EventArgs.Item;
using Exiled.Events.EventArgs.Player;
using InventorySystem.Items.Firearms.Attachments;
using InventorySystem.Items.Firearms.Attachments.Components;
Expand Down Expand Up @@ -150,6 +151,7 @@ protected override void SubscribeEvents()
Exiled.Events.Handlers.Player.Shooting += OnInternalShooting;
Exiled.Events.Handlers.Player.Shot += OnInternalShot;
Exiled.Events.Handlers.Player.Hurting += OnInternalHurting;
Exiled.Events.Handlers.Item.ChangingAttachments += OnInternalChangingAttachment;

base.SubscribeEvents();
}
Expand All @@ -162,6 +164,7 @@ protected override void UnsubscribeEvents()
Exiled.Events.Handlers.Player.Shooting -= OnInternalShooting;
Exiled.Events.Handlers.Player.Shot -= OnInternalShot;
Exiled.Events.Handlers.Player.Hurting -= OnInternalHurting;
Exiled.Events.Handlers.Item.ChangingAttachments -= OnInternalChangingAttachment;

base.UnsubscribeEvents();
}
Expand Down Expand Up @@ -208,6 +211,14 @@ protected virtual void OnHurting(HurtingEventArgs ev)
ev.Amount = Damage;
}

/// <summary>
/// Handles attachment changing for custom weapons.
/// </summary>
/// <param name="ev"><see cref="ChangingAttachmentsEventArgs"/>.</param>
protected virtual void OnChangingAttachment(ChangingAttachmentsEventArgs ev)
{
}

private void OnInternalReloading(ReloadingWeaponEventArgs ev)
{
if (!Check(ev.Player.CurrentItem))
Expand Down Expand Up @@ -320,5 +331,13 @@ private void OnInternalHurting(HurtingEventArgs ev)

OnHurting(ev);
}

private void OnInternalChangingAttachment(ChangingAttachmentsEventArgs ev)
{
if (!Check(ev.Player.CurrentItem))
return;

OnChangingAttachment(ev);
}
}
}
10 changes: 9 additions & 1 deletion EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Exiled.CustomRoles.API.Features
using Exiled.API.Extensions;
using Exiled.API.Features;
using Exiled.API.Features.Attributes;
using Exiled.API.Features.Items;
using Exiled.API.Features.Pools;
using Exiled.API.Features.Roles;
using Exiled.API.Features.Spawn;
Expand Down Expand Up @@ -558,7 +559,14 @@ public virtual void AddRole(Player player)
foreach (string itemName in Inventory)
{
Log.Debug($"{Name}: Adding {itemName} to inventory.");
TryAddItem(player, itemName);
if (TryAddItem(player, itemName) && CustomItem.TryGet(itemName, out CustomItem? customItem) && customItem is CustomWeapon customWeapon)
{
if (player.CurrentItem is Firearm firearm && !customWeapon.Attachments.IsEmpty())
{
firearm.AddAttachment(customWeapon.Attachments);
Log.Debug($"{Name}: Applied attachments to {itemName}.");
}
}
}

if (Ammo.Count > 0)
Expand Down
Loading