Skip to content

Add role checks (like IsScp) to Role Extensions / RoleTypeId#177

Merged
VALERA771 merged 15 commits intoExMod-Team:devfrom
LumiFae:master
Nov 20, 2024
Merged

Add role checks (like IsScp) to Role Extensions / RoleTypeId#177
VALERA771 merged 15 commits intoExMod-Team:devfrom
LumiFae:master

Conversation

@LumiFae
Copy link
Copy Markdown

@LumiFae LumiFae commented Nov 13, 2024

Description

Add IsScp to Role Extensions to easily check if the Role is an SCP role, I noticed there was .IsHuman and .IsAlive, but no .IsScp which could be useful to some people

What is the current behavior? (You can also link to an open issue here)

You either have to do !RoleTypeId.IsHuman && RoleTypeId.IsAlive or RoleTypeId.Team == Team.SCPs to check if the team is SCPs

What is the new behavior? (if this is a feature change)

You can now check with RoleTypeId.IsScp to see if the team is an SCP team or not.

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

No, nobody will need to change anything if they don't want to.

Other information:


Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentations

Submission checklist

  • I have checked the project can be compiled
  • I have tested my changes and it worked as expected

Patches (if there are any changes related to Harmony patches)

  • I have checked no IL patching errors in the console

Other

  • Still requires more testing

@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 13, 2024

No clue why this added 2 others, also no clue why the version got changed what

@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 13, 2024

There, fixed

@LumiFae LumiFae mentioned this pull request Nov 13, 2024
8 tasks
@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 13, 2024

Ok, so after discussing with moddedmcplayer, they said I should add IsHuman even though it exists natively inside PlayerRoles.RoleTypeId, should I add loads of other teams too based on what Exiled.API.Features.Player has before we merge this?

@moddedmcplayer
Copy link
Copy Markdown

Could be very subjective, discussing with Exiled maintainers.

@moddedmcplayer
Copy link
Copy Markdown

ohhh
that's what you mean
yeah I can see that being useful if nw changes things for whatever reason
@Mikihero

Hm
Sounds good
@VALERA771

I'd add them and then replace the ones in Player to wrap these.

@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 13, 2024

Wait so you'll add some of the methods or me? I don't mind making them. Just tell me what you think may be useful and I'll start

Copy link
Copy Markdown

@louis1706 louis1706 left a comment

Choose a reason for hiding this comment

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

Remove the change that removes "," character

Copy link
Copy Markdown

@louis1706 louis1706 left a comment

Choose a reason for hiding this comment

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

I don't think this is needed "here"

@louis1706
Copy link
Copy Markdown

Would be better to have it where you have the IsNtf property's

@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 14, 2024

Hey @louis1706 those characters being removed do nothing in actuality, just my code editor told me they should be removed so I removed them. Code still works fine. I will go ahead and move it to the IsNtf property

@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 14, 2024

Just had a look, there is no IsNtf property in this file. Should I move it beside IsFpcRole?

@LumiFae LumiFae requested a review from louis1706 November 14, 2024 08:12
@louis1706
Copy link
Copy Markdown

Hey @louis1706 those characters being removed do nothing in actuality, just my code editor told me they should be removed so I removed them. Code still works fine. I will go ahead and move it to the IsNtf property

They actually needed to prevent warning that put error in our repo because we wanted them to be put preventing useless changed line when you just add a new value under it

@louis1706
Copy link
Copy Markdown

Just had a look, there is no IsNtf property in this file. Should I move it beside IsFpcRole?

Could you add it in both

@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 14, 2024

Hey @louis1706 those characters being removed do nothing in actuality, just my code editor told me they should be removed so I removed them. Code still works fine. I will go ahead and move it to the IsNtf property

They actually needed to prevent warning that put error in our repo because we wanted them to be put preventing useless changed line when you just add a new value under it

Sorry but I don't understand any of that

@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 14, 2024

Just had a look, there is no IsNtf property in this file. Should I move it beside IsFpcRole?

Could you add it in both

Add both IsNtf and IsScp? Ok I'll try add IsChaos and stuff too

@louis1706
Copy link
Copy Markdown

Just had a look, there is no IsNtf property in this file. Should I move it beside IsFpcRole?

Could you add it in both

Add both IsNtf and IsScp? Ok I'll try add IsChaos and stuff too

I mean both file but that not bad too

@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 14, 2024

@louis1706 have a look at the changes now

@LumiFae LumiFae changed the title Add IsScp to Role Extensions / RoleTypeId Add role checks (like IsScp) to Role Extensions / RoleTypeId Nov 14, 2024
@VALERA771
Copy link
Copy Markdown

Won't this create a problem with ambiguous reference? Like I think that if yes then some plugins will require recompiling

@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 15, 2024

Unfortunately, yes I think it will, but blame @moddedmcplayer for that as he was adamant that I had to add IsHuman. What would you recommend @VALERA771

@moddedmcplayer
Copy link
Copy Markdown

Won't this create a problem with ambiguous reference? Like I think that if yes then some plugins will require recompiling

Correct if I'm wrong but like quite certain the compiler turns extensions methods into normal calls..?
And then when editing it only happens when referencing both PlayerRoles and API.Extensions.

@VALERA771
Copy link
Copy Markdown

I'll try to find time to test it but would be good if somebody do it faster than me (I'll be home only in 4 hours). I think we can leave this methods if they won't cause issues on plugins but imho one day we should stop replacing base game methods

@moddedmcplayer
Copy link
Copy Markdown

somebody

image
I'm not for replace, I am for adding wrappers and/or fill gaps that don't make sense. In this case calling base game is just not worth it.

@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 15, 2024

Yeah if PlayerRoles exists it makes sense for it to only use PlayerRoles.RoleTypeId.IsHuman as shown by the above screenshot. I don't think this will cause any errors honestly. But just let me know what you want me to do and I'll do it. But I just want this PR merged at some point lol

@github-actions github-actions bot removed the Events label Nov 18, 2024
Copy link
Copy Markdown

@Mikihero Mikihero left a comment

Choose a reason for hiding this comment

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

imo these could be changed as well

/// </summary>
/// <param name="roleType">The <see cref="RoleTypeId"/>.</param>
/// <returns>A boolean which is true when the role is a military role.</returns>
public static bool IsMilitary(this RoleTypeId roleType) => roleType.IsNtf() || roleType.IsChaos();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

currently this includes Guards because of the other thing I mentioned, I think you should specify that this doesn't (or does if it's intended) include them

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It should grab guards as they are military, but if you want the docs to be changed to mention guards are included in both foundation and military I can do that

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

personally I wouldn't count guards as military, that's why I'd like you to specifically mention if they're counted or not

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Maybe I'll add smth to remove guards from military as I agree it's weird for them to be in there

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removing from IsNtf

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If you could specify in its docs that doesn't include guards that'd be great as well since some people might be confused

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Member

@obvEve obvEve left a comment

Choose a reason for hiding this comment

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

Looks fine imo

@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 19, 2024

@louis1706 @Mikihero can you all check out these changes and let me know what you think.

@VALERA771 VALERA771 requested a review from louis1706 November 19, 2024 08:59
Copy link
Copy Markdown

@Mikihero Mikihero left a comment

Choose a reason for hiding this comment

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

lgtm

/// </summary>
/// <param name="roleType">The <see cref="RoleTypeId"/>.</param>
/// <returns>A boolean which is true when the role is a military role. Does not include Facility Guards.</returns>
public static bool IsMilitary(this RoleTypeId roleType) => roleType.IsNtf() || roleType.IsChaos();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just does
Ismilitary(this RoleTypeId roletype) => !roletype.IsCivilian()

I know this goes against what miki said but that what basegame believe for armor consumption of stamina for example

Copy link
Copy Markdown

@VALERA771 VALERA771 Nov 20, 2024

Choose a reason for hiding this comment

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

Idk can we count tutorial as civilian (iirc when I checked it last time RoleTypeId.Tutorial.IsCivilian() will return false)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Tutorial is not civilian, no. so it will count as military, this change shouldn't be done @louis1706 as what I've done is perfect, this is just adding more work and more calculations for no reason.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

technically guard is a military class, I've said otherwise before because it doesn't make sense to me but that's how they're classified on the wiki, this method should reflect that

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Way to late to say that now @Mikihero 😭

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

to make it work you can just add || roletype == RoleTypeId.FacilityGuard, I don't think there really is a better solution since negating IsCivilian would return shit like tutorial etc.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yeah, but this PR has been merged, if I could directly commit I would

@LumiFae
Copy link
Copy Markdown
Author

LumiFae commented Nov 20, 2024

@VALERA771 I honestly think this can just be committed, we have 4 approvals for petes sake. I don't think there will be any more good requests to come out of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants