[feat] Donate extra slots

This commit is contained in:
rhailrake
2023-04-28 01:06:54 +06:00
committed by Aviu00
parent df7aadd830
commit 663cae3181
4 changed files with 22 additions and 7 deletions

View File

@@ -36,7 +36,7 @@ namespace Content.Server.Preferences.Managers
private readonly Dictionary<NetUserId, PlayerPrefData> _cachedPlayerPrefs =
new();
private int MaxCharacterSlots => _cfg.GetCVar(CCVars.GameMaxCharacterSlots);
//private int MaxCharacterSlots => _cfg.GetCVar(CCVars.GameMaxCharacterSlots);
public void Init()
{
@@ -57,7 +57,7 @@ namespace Content.Server.Preferences.Managers
return;
}
if (index < 0 || index >= MaxCharacterSlots)
if (index < 0 || index >= GetMaxUserCharacterSlots(userId))
{
return;
}
@@ -97,7 +97,7 @@ namespace Content.Server.Preferences.Managers
return;
}
if (slot < 0 || slot >= MaxCharacterSlots)
if (slot < 0 || slot >= GetMaxUserCharacterSlots(userId))
{
return;
}
@@ -133,7 +133,7 @@ namespace Content.Server.Preferences.Managers
return;
}
if (slot < 0 || slot >= MaxCharacterSlots)
if (slot < 0 || slot >= GetMaxUserCharacterSlots(userId))
{
return;
}
@@ -217,7 +217,7 @@ namespace Content.Server.Preferences.Managers
msg.Preferences = prefs;
msg.Settings = new GameSettings
{
MaxCharacterSlots = MaxCharacterSlots
MaxCharacterSlots = GetMaxUserCharacterSlots(session.UserId)
};
_netManager.ServerSendMessage(msg, session.ConnectedClient);
}
@@ -234,6 +234,12 @@ namespace Content.Server.Preferences.Managers
return _cachedPlayerPrefs.ContainsKey(session.UserId);
}
private int GetMaxUserCharacterSlots(NetUserId userId)
{
var maxSlots = _cfg.GetCVar(CCVars.GameMaxCharacterSlots);
var extraSlots = _sponsors.TryGetInfo(userId, out var sponsor) ? sponsor.ExtraSlots : 0;
return maxSlots + extraSlots;
}
/// <summary>
/// Tries to get the preferences from the cache