Skip to content

Commit 90bf012

Browse files
committed
Give/TakeExperience parameter validation
1 parent c0a2a41 commit 90bf012

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Intersect.Server.Core/Entities/Player.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,18 @@ public void AddLevels(int levels = 1, bool resetExperience = true)
13581358

13591359
public void GiveExperience(long amount)
13601360
{
1361+
// ReSharper disable once ConvertIfStatementToSwitchStatement
1362+
if (amount == 0)
1363+
{
1364+
return;
1365+
}
1366+
1367+
if (amount < 0)
1368+
{
1369+
TakeExperience(-amount);
1370+
return;
1371+
}
1372+
13611373
Exp += (int)Math.Round(amount + (amount * (GetEquipmentBonusEffect(ItemEffect.EXP) / 100f)));
13621374
if (Exp < 0)
13631375
{
@@ -1372,6 +1384,18 @@ public void GiveExperience(long amount)
13721384

13731385
public void TakeExperience(long amount, bool enableLosingLevels = false, bool force = false)
13741386
{
1387+
// ReSharper disable once ConvertIfStatementToSwitchStatement
1388+
if (amount == 0)
1389+
{
1390+
return;
1391+
}
1392+
1393+
if (amount < 0)
1394+
{
1395+
GiveExperience(-amount);
1396+
return;
1397+
}
1398+
13751399
if (!force && Options.Instance.Map.DisableExpLossInArenaMaps && Map.ZoneType == MapZone.Arena)
13761400
{
13771401
return;

0 commit comments

Comments
 (0)