feat!: Add overloads for AddItem using AttachmentName#811
feat!: Add overloads for AddItem using AttachmentName#811Unbistrackted wants to merge 5 commits intoExMod-Team:devfrom
Conversation
Added check inside of ``Firearm::AddAttachment`` to prevent missmatches Added overload methods for ``Player`` when giving weapon with attachments using ``AttachmentName`` Fixed ``AttachmentIdentifier.TryParse`` giving wrong attachment by creating another overload that takes the weapon type
Someone-193
left a comment
There was a problem hiding this comment.
PR generally looks good, I just have a few nitpicks here and there. Just to confirm, you haven't removed or significantly changed any important methods right? Just making sure for Exiled 10 I don't get pinged with people being mad they cant find a method that used to exist lol
| /// <param name="itemType">The item to be added.</param> | ||
| /// <param name="amount">The amount of items to be added.</param> | ||
| /// <returns>An <see cref="IEnumerable{Item}"/> containing the items given.</returns> | ||
| public IEnumerable<Item> AddItem(ItemType itemType, int amount) |
There was a problem hiding this comment.
bro you should just return a list if that's what you have internally
There was a problem hiding this comment.
I just copied and pasted the overloads and changed it to accomodate the AttachmentName 😭
https://github.com/ExMod-Team/EXILED/blob/master/EXILED/Exiled.API/Features/Player.cs#L2828
I'm going to change it
| /// <returns>An <see cref="IEnumerable{Item}"/> containing the items given.</returns> | ||
| public IEnumerable<Item> AddItem(IEnumerable<ItemType> items) | ||
| { | ||
| List<ItemType> enumeratedItems = ListPool<ItemType>.Pool.Get(items); |
There was a problem hiding this comment.
Why are we using a pooled list for a single foreach loop 😭
You could just remove the listpool here, and also make this return a list as well
There was a problem hiding this comment.
https://github.com/ExMod-Team/EXILED/blob/master/EXILED/Exiled.API/Features/Player.cs#L2848
It was like that before, I didn't even noticed 😭
Imma change this
| /// <param name="identifier">The converted <see cref="string"/>.</param> | ||
| /// <returns><see langword="true"/> if <see cref="string"/> was converted successfully; otherwise, <see langword="false"/>.</returns> | ||
| public static bool TryParse(string s, out AttachmentIdentifier identifier) | ||
| [Obsolete("Use AttachmentIdentifier.TryParse(string, FirearmType, out AttachmentIdentifier) instead. Gives wrong Attachment for certain weapons.", true)] |
There was a problem hiding this comment.
you can remove this method, breaking changes are allowed on dev for Exiled 10
| /// <param name="items">The <see cref="Dictionary{TKey, TValue}"/> of <see cref="ItemType"/> and <see cref="IEnumerable{T}"/> of <see cref="AttachmentName"/> to be added.</param> | ||
| /// <returns>An <see cref="IEnumerable{Item}"/> containing the items given.</returns> | ||
| public IEnumerable<Item> AddItem(Dictionary<FirearmType, IEnumerable<AttachmentIdentifier>> items) | ||
| public IEnumerable<Item> AddItem(Dictionary<FirearmType, IEnumerable<AttachmentName>> items) |
| /// <param name="items">The <see cref="Dictionary{TKey, TValue}"/> of <see cref="ItemType"/> and <see cref="IEnumerable{T}"/> of <see cref="AttachmentIdentifier"/> to be added.</param> | ||
| /// <returns>An <see cref="IEnumerable{Item}"/> containing the items given.</returns> | ||
| public IEnumerable<Item> AddItem(IEnumerable<ItemType> items) | ||
| public IEnumerable<Item> AddItem(Dictionary<FirearmType, IEnumerable<AttachmentIdentifier>> items) |
| /// <param name="identifiers">The attachments to be added to the item.</param> | ||
| /// <returns>An <see cref="IEnumerable{Item}"/> containing the items given.</returns> | ||
| public IEnumerable<Item> AddItem(FirearmType firearmType, int amount, IEnumerable<AttachmentIdentifier> identifiers) | ||
| public IEnumerable<Item> AddItem(FirearmType firearmType, int amount, IEnumerable<AttachmentName> identifiers) |
The only thing I can see ppl being upset is the I mean |
|
Also do you know if a method for getting the |
Description
Describe the changes
Added check inside of
Firearm::AddAttachmentto prevent missmatchesAdded overload methods for
Playerwhen giving weapon with attachments usingAttachmentNameFixed
AttachmentIdentifier.TryParsegiving wrong attachment by creating another overload that takes the weapon typeWhat is the current behavior? (You can also link to an open issue here)
AttachmentIdentifier.TryParsegives wrong AttachmentIdentifier for certain weapons due to them having the same attachment name with different codesWhat is the new behavior? (if this is a feature change)
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
Other information:
Moved some of the methods to be closer to each other so it's easy to find
Props to @PUDGE133 for finding the bug
Types of changes
Submission checklist
Patches (if there are any changes related to Harmony patches)
Other