Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There are so many changes that I don't know what to put in the title. #217

Open
wants to merge 6 commits into
base: 13.1
Choose a base branch
from

Conversation

SrLicht
Copy link
Contributor

@SrLicht SrLicht commented Jul 26, 2023

Player

  • Added IEnumerable<Player> GetPlayers(RoleTypeId roleType): Gets a filtered collection of players based on their role type.
  • Added IEnumerable<Player> GetPlayers(Team team): Gets a filtered collection of players based on their team.
  • Added Player Get(Collider collider) and TryGet(Collider collider, out Player player): Methods to get or try getting the player associated with a collider.
  • Added Player Get(Footprint footprint) and TryGet(Footprint footprint, out Player player): Methods to get or try getting the player associated with a footprint.
  • Added Footprint Footprint: Property to get the player's footprint.
  • Modified DropAmmo(ItemType item, ushort amount, bool checkMinimals = false): Un-commented the method to allow the player to drop ammo.
  • Modified SetRole(RoleTypeId newRole, RoleChangeReason reason = RoleChangeReason.RemoteAdmin): Added an optional parameter to specify the role spawn flags for the role change.

Facility doors

  • Added a method to try getting a FacilityDoor from a DoorVariant.
  • TryGet(DoorVariant baseDoor, out FacilityDoor facilityDoor): Tries to get the FacilityDoor associated with the provided DoorVariant. If found, the facilityDoor parameter will be set; otherwise, it will be null.

ItemExtensions

  • Created an ItemExtensions class with various extension methods for ItemType and Firearm.
  • Added methods to check if an ItemType is of a specific category: IsAmmo, IsFirearm, IsMedical, IsUtility, IsArmor, IsKeycard, IsThrowable.
  • Implemented a method to get a Firearm's ItemBase using InventoryItemLoader.
  • Added a method to get a random attachments code for a given ItemType.
  • Introduced a method to apply attachments to a Firearm.
  • Provided a method to apply a set of random attachments directly to a Firearm.
  • Implemented a method to attempt applying a player's attachments preferences to a Firearm.
  • Implemented a method to gets the maximum ammunition a Firearm can have.
    • You can also use it by giving an ItemType
  • Implemented a method to refill the magazine of a weapon
  • Implemented a method to remove ammunition from the magazine of a gun.

Note: This was originally just going to add the Footprint to Player but then I started doing the Get methods and by the time I realized I had already made 1 new extension class and modified 3 classes.

# Player

- Added `IEnumerable<Player> GetPlayers(RoleTypeId roleType)`: Gets a filtered collection of players based on their role type.
- Added `IEnumerable<Player> GetPlayers(Team team)`: Gets a filtered collection of players based on their team.
- Added `Player Get(Collider collider)` and `TryGet(Collider collider, out Player player)`: Methods to get or try getting the player associated with a collider.
- Added `Player Get(Footprint footprint)` and `TryGet(Footprint footprint, out Player player)`: Methods to get or try getting the player associated with a footprint.
- Added `Footprint Footprint`: Property to get the player's footprint.
- Modified `DropAmmo(ItemType item, ushort amount, bool checkMinimals = false)`: Un-commented the method to allow the player to drop ammo.
- Modified `SetRole(RoleTypeId newRole, RoleChangeReason reason = RoleChangeReason.RemoteAdmin)`: Added an optional parameter to specify the role spawn flags for the role change.

# Facility doors

- Added a method to try getting a `FacilityDoor` from a `DoorVariant`.
- `TryGet(DoorVariant baseDoor, out FacilityDoor facilityDoor)`: Tries to get the `FacilityDoor` associated with the provided `DoorVariant`. If found, the `facilityDoor` parameter will be set; otherwise, it will be `null`.

# ItemExtensions

- Created an `ItemExtensions` class with various extension methods for `ItemType` and `Firearm`.
- Added methods to check if an `ItemType` is of a specific category: `IsAmmo`, `IsFirearm`, `IsMedical`, `IsUtility`, `IsArmor`, `IsKeycard`, `IsThrowable`.
- Implemented a method to get a `Firearm`'s `ItemBase` using `InventoryItemLoader`.
- Added a method to get a random attachments code for a given `ItemType`.
- Introduced a method to apply attachments to a `Firearm`.
- Provided a method to apply a set of random attachments directly to a `Firearm`.
- Implemented a method to attempt applying a player's attachments preferences to a `Firearm`.
@SrLicht SrLicht changed the title I thought it would be shorter There are so many changes that I don't know what to put in the title. Jul 26, 2023
* Added summary to `IsAmmo(this ItemType type)`
@SrLicht
Copy link
Contributor Author

SrLicht commented Jul 26, 2023

Github is not putting the commit I uploaded SrLicht@fe1ba46

@moddedmcplayer
Copy link
Contributor

there are still a bunch of indented preprocessor directives

/// </summary>
/// <param name="firearm">The <see cref="Firearm"/> to which the attachments will be applied.</param>
/// <param name="attachmentCode">The attachments code representing the set of attachments to apply.</param>
public static void ApllyAttachments(this Firearm firearm, uint attachmentCode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should say ApplyAttachments

/// </summary>
/// <param name="firearm">The <see cref="Firearm"/> to which random attachments will be applied.</param>
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="firearm"/> is null.</exception>
public static void ApllyRandomAttachments(this Firearm firearm)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply, couldn't you also call ApplyAttachment using the value from the GetRandomAttachmentsCode instead of copy-pasting the function.

}

/// <summary>
/// Applies the preferences of a <see cref="Player"/>'s attachments to a given <see cref="Firearm"/>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could "Tries to apply the pref...." be better in this case?

/// <param name="player">The <see cref="Player"/> whose attachments preferences are to be applied.</param>
/// <param name="reloadWeapon">If this value is true, the weapon will be fully reloaded with ammunition when the attachment is applied.</param>
/// <returns>Returns true if the weapon was modified with the attachments; otherwise, false.</returns>
public static bool TryApplyAttachmentsPreferences(this Firearm firearm, Player player, bool reloadWeapon = false)
Copy link
Member

@ced777ric ced777ric Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps ApplyAttachment could be used here to prevent copy-pasting the same code.

firearmStatusFlags |= FirearmStatusFlags.FlashlightEnabled;
}

if(reloadWeapon)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldnt this either force ammo to 0, or to the max, and not retain current ammunition?

NwPluginAPI/Core/Extensions/ItemExtensions.cs Show resolved Hide resolved
FirearmStatusFlags firearmStatusFlags = FirearmStatusFlags.MagazineInserted;
if (firearm.HasAdvantageFlag(AttachmentDescriptiveAdvantages.Flashlight))
{
firearmStatusFlags |= FirearmStatusFlags.FlashlightEnabled;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially check what the old state of the flashlight is, as this will always enable it if there is a flashlight, or we could pass an argument that decides to enable it, disable it, or leave it as is when a flashlight is present.

Perhaps an enum flag could be introduced to decide these modifications, to avoid having a lot of method parameters, please let me know what you think of that idea.

public static bool TryApplyAttachmentsPreferences(this Firearm firearm, Player player, bool reloadWeapon = false)
{
if(firearm == null)
throw new ArgumentNullException(nameof(Firearm), "Firearm is null");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps returning false here could be better, as it is a "Try" style method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense I will do it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants