feat: Lots of new useful features and fix - #864
Conversation
|
If you have any questions, you can write here or to me on Discord: scaletta2019 |
| /// <summary> | ||
| /// Gets or sets a value indicating whether the magazine is attached from the weapon. | ||
| /// </summary> | ||
| public bool IsMagazineDeattached | ||
| { | ||
| get => !IsMagazineAttached; | ||
| set => IsMagazineAttached = !value; | ||
| } |
There was a problem hiding this comment.
If you think this section of code is useless, then let's think this code is useless too:
It may be useless, but it is not beneficial to remove it because that would be a breaking change. There is also no reason to add new junk code.
There was a problem hiding this comment.
If you think this section of code is useless, then let's think this code is useless too:
It may be useless, but it is not beneficial to remove it because that would be a breaking change. There is also no reason to add new junk code.
No, no, no... you've had enough of this "critical code." You shouldn't have added it and then been afraid to remove it. As long as these and similar properties exist in the code, the code I've submitted will comply with Exiled standards.
This is excellent code; it reduces the cognitive load when reading it in plugins. There is no problem with it.
|
|
||
| /// <inheritdoc cref="Player.Count"/> | ||
| public static int PlayerCount => Player.Count; | ||
| /// <summary> | ||
| /// Gets the number of players excluding NPCs. | ||
| /// </summary> | ||
| public static int PlayerCount => Player.Dictionary.Values.Count(x => !x.IsNPC); |
There was a problem hiding this comment.
No please don't break all plugin that would use that
There was a problem hiding this comment.
No please don't break all plugin that would use that
Okay, I'll change it back. However, I don't understand why this property originally included NPCs. It once took me quite a while to figure out what was causing the bug. The problem was that someone misnamed the property. You should have named it something that would make it clear it included NPCs as well. If necessary, I can change the documentation for this property.
| { | ||
| if (gameObject != null) | ||
| { | ||
| // ParentDoor requires enabling "unsafe code" |
There was a problem hiding this comment.
Weird comment?
I will remove this comment.
| if (room.Type == RoomType.Surface) | ||
| return relativePos; |
There was a problem hiding this comment.
Surface is a functional room technically i only see the purpose of this for Unknown Room
Or if you do it with the surface let's do it to all non dynamic rooms (i prefer to only do it on null that would be unknown)
Surface and pocket
There was a problem hiding this comment.
Surface is a functional room technically i only see the purpose of this for Unknown Room
Or if you do it with the surface let's do it to all non dynamic rooms (i prefer to only do it on null that would be unknown)
Surface and pocket
I don't understand what you didn't like about this code.
| public static string ToHumanReadable(this TimeSpan timeSpan) | ||
| { | ||
| if (timeSpan.TotalHours < 1) | ||
| return timeSpan.ToString(@"mm\:ss"); | ||
|
|
||
| if (timeSpan.TotalDays < 1) | ||
| return timeSpan.ToString(@"hh\:mm\:ss"); | ||
|
|
||
| string daysPart = timeSpan.Days == 1 ? "1 day" : $"{timeSpan.Days} days"; | ||
| string timePart = timeSpan.ToString(@"hh\:mm\:ss"); | ||
| return $"{daysPart}, {timePart}"; | ||
| } |
There was a problem hiding this comment.
How does it handle differences like language/ 24h or 12h Am/Pm
There was a problem hiding this comment.
How does it handle differences like language/ 24h or 12h Am/Pm
Normal people use the 24-hour clock. In any case, I didn't intend for this method to be universal. If someone needs it, they can always add their own extension method to this class with a different name or a different overload. I don't see any problem with that.
There was a problem hiding this comment.
Normal people use the 24-hour clock. In any case, I didn't intend for this method to be universal. If someone needs it, they can always add their own extension method to this class with a different name or a different overload. I don't see any problem with that.
It's an API meant for many people to use. A lot of this code is pretty pointless or not helpful to many people.
There was a problem hiding this comment.
Normal people use the 24-hour clock. In any case, I didn't intend for this method to be universal. If someone needs it, they can always add their own extension method to this class with a different name or a different overload. I don't see any problem with that.
It's an API meant for many people to use. A lot of this code is pretty pointless or not helpful to many people.
Write your own method and add it. Be sure to take into account the 250 official languages. Keep in mind that each language has its own vocabulary and grammar. I used one specific method for 99% of tasks. But you can add your own.
| public static bool NextBool(this Random rnd) | ||
| { | ||
| return rnd.Next(2) == 0; | ||
| } |
There was a problem hiding this comment.
Pretty sure this is very badly optimised
There was a problem hiding this comment.
Pretty sure this is very badly optimised
I don't see any particular problem here, but you can do it like this:
(rnd.Next() & 1) == 0
| /// <summary> | ||
| /// Generate a random float. | ||
| /// </summary> | ||
| /// <param name="rnd"><see cref="Random"/> object.</param> | ||
| /// <param name="min">Minimum value.</param> | ||
| /// <param name="max">Maximum value.</param> | ||
| /// <returns>Random value between minimum and maximum.</returns> | ||
| public static float NextFloat(this Random rnd, float min, float max) | ||
| { | ||
| return (float)((rnd.NextDouble() * (max - min)) + min); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Generate a random float. | ||
| /// </summary> | ||
| /// <param name="rnd"><see cref="Random"/> object.</param> | ||
| /// <param name="min">Minimum value.</param> | ||
| /// <param name="max">Maximum value.</param> | ||
| /// <returns>Random value between minimum and maximum.</returns> | ||
| public static float NextFloat(this Random rnd, double min, float max) | ||
| { | ||
| return (float)((rnd.NextDouble() * (max - min)) + min); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Generate a random float. | ||
| /// </summary> | ||
| /// <param name="rnd"><see cref="Random"/> object.</param> | ||
| /// <param name="min">Minimum value.</param> | ||
| /// <param name="max">Maximum value.</param> | ||
| /// <returns>Random value between minimum and maximum.</returns> | ||
| public static float NextFloat(this Random rnd, float min, double max) | ||
| { | ||
| return (float)((rnd.NextDouble() * (max - min)) + min); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Generate a random float. | ||
| /// </summary> | ||
| /// <param name="rnd"><see cref="Random"/> object.</param> | ||
| /// <param name="min">Minimum value.</param> | ||
| /// <param name="max">Maximum value.</param> | ||
| /// <returns>Random value between minimum and maximum.</returns> | ||
| public static float NextFloat(this Random rnd, double min, double max) | ||
| { | ||
| return (float)((rnd.NextDouble() * (max - min)) + min); | ||
| } |
There was a problem hiding this comment.
Doesn't Unity Random already handle some of these ?
There was a problem hiding this comment.
Doesn't Unity Random already handle some of these ?
Because not everyone likes Random from unity.
There was a problem hiding this comment.
Because not everyone likes Random from unity.
??? What is wrong with unity randoms?
There was a problem hiding this comment.
Because not everyone likes Random from unity.
??? What is wrong with unity randoms?
What difference does it make to you? What changes for you? Use the randomness you want.
| /// <summary> | ||
| /// Perform an action on each element of a collection. | ||
| /// </summary> | ||
| /// <typeparam name="T">Type of <see cref="IEnumerable{T}"/> elements.</typeparam> | ||
| /// <param name="enumerable"><see cref="IEnumerable{T}"/> in this collection, the elements will perform actions.</param> | ||
| /// <param name="action">Action that needs to be performed.</param> | ||
| public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action) | ||
| { | ||
| if (enumerable is null || action is null) | ||
| return; | ||
|
|
||
| foreach (T e in enumerable) | ||
| action(e); | ||
| } |
7d85cb3 to
de125a4
Compare
| where T : Door => Get(doorVariant) as T; | ||
|
|
||
| /// <summary> | ||
| /// Gets the door object associated with a specific <see cref="ButtonVariant"/>, or creates a new one if there isn't one. |
There was a problem hiding this comment.
Why would you create a new door if there is not a door associated with that buttonvariant?
There was a problem hiding this comment.
Why would you create a new door if there is not a door associated with that buttonvariant?
fixed
| /// </summary> | ||
| /// <param name="message">The message to be sent.</param> | ||
| public static void Error(string message) => Send($"[{Assembly.GetCallingAssembly().GetName().Name}] {message}", Discord.LogLevel.Error, ConsoleColor.DarkRed); | ||
| public static void Error(string message = "") => Send($"[{Assembly.GetCallingAssembly().GetName().Name}] {message}", Discord.LogLevel.Error, ConsoleColor.DarkRed); |
There was a problem hiding this comment.
Why would anyone call a method meant to print to the console without passing a string to the method to be printed?
There was a problem hiding this comment.
Why would anyone call a method meant to print to the console without passing a string to the method to be printed?
Have you ever split console logs to make them easier to read?

Description
Describe the changes
Getmethod forDoor.Door.Get(GameObject)methodFirearmLogclass methodsPlayerServer.ReservedSlotsTypes of changes
Submission checklist
Other