Add level down support#2492
Conversation
| public readonly LocalizedString Left = @"{00} has left {01}."; | ||
|
|
||
| [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] | ||
| public readonly LocalizedString LevelDown = @"You have leveled down! You are now level {00}!"; |
There was a problem hiding this comment.
This isn't super natural in english, it would be better to say You have lost a level! You are now level {00}!
There was a problem hiding this comment.
Also change the name of the string to LevelLost
| else | ||
| { | ||
| var levelCount = 0; | ||
| while (Exp < 0 && Level - levelCount > 1) |
| Exp += GetExperienceToNextLevel(Level - levelCount - 1); | ||
| levelCount++; |
There was a problem hiding this comment.
Swap these
First line should be --levelCount; this takes into account that - 1 implicitly
Second line should be Exp += GetExperienceToNextLevel(Level + levelCount);
| } | ||
|
|
||
| PacketSender.SendExperience(this); | ||
| AddLevels(-levelCount); |
There was a problem hiding this comment.
AddLevels(levelCount);
With the negative counting there's no reason to flip the sign.
| if (Exp < 0) | ||
| { | ||
| Exp = 0; | ||
| PacketSender.SendExperience(this); |
There was a problem hiding this comment.
Shouldn't this be outside of the if so that the changed EXP is sent above level 1?
There was a problem hiding this comment.
Any exp for any other level is sent at the end of AddLevels()
I added this if because, when I went down a level and was at level 1, after AddLevels() was executed, the exp would become negative if I removed more than I had
So I added this if as "if after removing the player's levels, the exp remains negative, reset and send"
the exp will never be negative after AddLevels(), if when the function finishes its level is above 1
It only happened exclusively in this situation, because the exp is not reset when leveling down, and it does not reset when it is negative when the player is at level 1.
| Name | ||
| ); | ||
|
|
||
| if (ClassBase.TryGet(ClassId, out var classDescriptor) && classDescriptor?.Spells != default) |
There was a problem hiding this comment.
Put ClassBase? classDescriptor = null; before if (levels > 0)
Here, change the if to if ((classDescriptor?.Id == ClassId || ClassBase.TryGet(ClassId, out classDescriptor)) && classDescriptor?.Spells != default)
| Name | ||
| ); | ||
|
|
||
| if (ClassBase.TryGet(ClassId, out var classDescriptor) && classDescriptor?.Spells != default) |
There was a problem hiding this comment.
Here, change the if to if ((classDescriptor?.Id == ClassId || ClassBase.TryGet(ClassId, out classDescriptor)) && classDescriptor?.Spells != default)
| } | ||
|
|
||
| public void TakeExperience(long amount) | ||
| public void TakeExperience(long amount, bool enableLevelDown = false) |
There was a problem hiding this comment.
Add , bool force = false as the final parameter
| public void TakeExperience(long amount, bool enableLevelDown = false) | ||
| { | ||
| if (this is Player && Options.Instance.Map.DisableExpLossInArenaMaps && Map.ZoneType == MapZone.Arena) | ||
| if (Options.Instance.Map.DisableExpLossInArenaMaps && Map.ZoneType == MapZone.Arena) |
There was a problem hiding this comment.
Change this to if (force || (Options.Instance.Map.DisableExpLossInArenaMaps && Map.ZoneType == MapZone.Arena))
There was a problem hiding this comment.
Events taking experience should not be stopped by map type
| } | ||
| else if (quantity < 0) | ||
| { | ||
| player.TakeExperience(Math.Abs(quantity), command.EnableLevelDown); |
There was a problem hiding this comment.
add , force: true to the end of the args
a189c03 to
b9cd717
Compare
resolves #2491
Intersect_Client_nSBWzaJB3i.mp4