[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

@@ -8,5 +8,7 @@
<cc:CommandButton Command="shutdown" Text="{Loc server-shutdown}" />
<cc:CommandButton Name="SetOocButton" Command="setooc" Text="{Loc server-ooc-toggle}" ToggleMode="True" />
<cc:CommandButton Name="SetLoocButton" Command="setlooc" Text="{Loc server-looc-toggle}" ToggleMode="True" />
<cc:CommandButton Name="SetPanicbunkerButton" Command="panicbunker" Text="{Loc server-panicbunker-toggle}" ToggleMode="True" />
<cc:CommandButton Name="SetStalinBunker" Command="stalinbunker" Text="{Loc server-stalin-toggle}" ToggleMode="True" />
</GridContainer>
</Control>

View File

@@ -118,6 +118,7 @@ namespace Content.Client.Preferences.UI
Loc.GetString("character-setup-gui-create-new-character-button-tooltip",
("maxCharacters", _preferencesManager.Settings!.MaxCharacterSlots));
var isDisplayedMaxSlots = false;
foreach (var (slot, character) in _preferencesManager.Preferences!.Characters)
{
if (character is null)
@@ -125,6 +126,10 @@ namespace Content.Client.Preferences.UI
continue;
}
isDisplayedMaxSlots = numberOfFullSlots >= _preferencesManager.Settings.MaxCharacterSlots;
if (isDisplayedMaxSlots)
break;
numberOfFullSlots++;
var characterPickerButton = new CharacterPickerButton(_entityManager,
_preferencesManager,
@@ -145,8 +150,7 @@ namespace Content.Client.Preferences.UI
};
}
_createNewCharacterButton.Disabled =
numberOfFullSlots >= _preferencesManager.Settings.MaxCharacterSlots;
_createNewCharacterButton.Disabled = isDisplayedMaxSlots;
Characters.AddChild(_createNewCharacterButton);
}

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

View File

@@ -21,6 +21,9 @@ public sealed class SponsorInfo
[JsonPropertyName("allowedMarkings")]
public string[] AllowedMarkings { get; set; } = Array.Empty<string>();
[JsonPropertyName("extraSlots")]
public int ExtraSlots { get; set; }
}
/// <summary>