Skip to content

Commit

Permalink
Поправка для спонсорки (#303)
Browse files Browse the repository at this point in the history
* улучшение спонсорки

* Update ChatManager.cs

забыл убрать лишнее

* доработка спонсорки
  • Loading branch information
SpicyDarkFox authored Oct 25, 2024
1 parent 5119e56 commit eca2d3e
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 25 deletions.
33 changes: 30 additions & 3 deletions Content.Client/Lobby/LobbyUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
using Robust.Client.UserInterface.Controllers;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Player;
using Robust.Client.Player;
#if LPP_Sponsors
using Content.Client._LostParadise.Sponsors;
#endif

namespace Content.Client.Lobby;

Expand All @@ -28,6 +33,7 @@ public sealed partial class LobbyUIController : UIController, IOnStateEntered<Lo
[UISystemDependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
[UISystemDependency] private readonly ClientInventorySystem _inventory = default!;
[UISystemDependency] private readonly LoadoutSystem _loadouts = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

private LobbyCharacterPanel? _previewPanel;
private HumanoidProfileEditor? _profileEditor;
Expand Down Expand Up @@ -118,15 +124,25 @@ public void UpdateCharacterUI()
_previewPanel?.SetSummaryText(maybeProfile.Summary);
_humanoid.LoadProfile(_previewDummy.Value, maybeProfile);


#if LPP_Sponsors
var sys = IoCManager.Resolve<SponsorsManager>();
var sponsorTier = 0;
if (sys.TryGetInfo(out var sponsorInfo))
sponsorTier = sponsorInfo.Tier;
var uuid = _playerManager.LocalUser != null ? _playerManager.LocalUser.ToString() ?? "" : "";
#endif
if (UpdateClothes)
{
RemoveDummyClothes(_previewDummy.Value);
if (ShowClothes)
GiveDummyJobClothes(_previewDummy.Value, GetPreferredJob(maybeProfile), maybeProfile);
if (ShowLoadouts)
_loadouts.ApplyCharacterLoadout(_previewDummy.Value, GetPreferredJob(maybeProfile), maybeProfile,
_jobRequirements.GetRawPlayTimeTrackers(), _jobRequirements.IsWhitelisted());
_jobRequirements.GetRawPlayTimeTrackers(), _jobRequirements.IsWhitelisted()
#if LPP_Sponsors
, sponsorTier, uuid
#endif
);
UpdateClothes = false;
}

Expand Down Expand Up @@ -171,9 +187,20 @@ public void RemoveDummyClothes(EntityUid dummy)
/// </summary>
public void GiveDummyJobClothesLoadout(EntityUid dummy, HumanoidCharacterProfile profile)
{
#if LPP_Sponsors
var sys = IoCManager.Resolve<SponsorsManager>();
var sponsorTier = 0;
if (sys.TryGetInfo(out var sponsorInfo))
sponsorTier = sponsorInfo.Tier;
var uuid = _playerManager.LocalUser != null ? _playerManager.LocalUser.ToString() ?? "" : "";
#endif
var job = GetPreferredJob(profile);
GiveDummyJobClothes(dummy, job, profile);
_loadouts.ApplyCharacterLoadout(dummy, job, profile, _jobRequirements.GetRawPlayTimeTrackers(), _jobRequirements.IsWhitelisted());
_loadouts.ApplyCharacterLoadout(dummy, job, profile, _jobRequirements.GetRawPlayTimeTrackers(), _jobRequirements.IsWhitelisted()
#if LPP_Sponsors
, sponsorTier, uuid
#endif
);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Content.Client/Preferences/ClientPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public void UpdateCharacter(ICharacterProfile profile, int slot)
if (sponsorMarkings is not null && sponsorMarkings.Count() > 0)
allowedMarkings = allowedMarkings.Concat(sponsorMarkings).ToArray();
}
var session = _playerManager.LocalSession!;
profile.EnsureValid(session, collection, allowedMarkings);
var session = _playerManager.LocalSession!;
profile.EnsureValid(session, collection, allowedMarkings);
#else
profile.EnsureValid(_playerManager.LocalSession!, collection);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ private void UpdateTraits(bool showUnusable)
_configurationManager,
out _
#if LPP_Sponsors
, 0, sponsorTier, uuid
, 0, sponsorTier, uuid
#endif
);
_traits.Add(trait, usable);
Expand Down
18 changes: 16 additions & 2 deletions Content.Server/Clothing/Systems/LoadoutSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using Content.Shared.Storage;
using Content.Shared.Storage.EntitySystems;
using Robust.Shared.Configuration;
#if LPP_Sponsors
using Content.Server._LostParadise.Sponsors;
#endif

namespace Content.Server.Clothing.Systems;

Expand All @@ -17,7 +20,9 @@ public sealed class LoadoutSystem : EntitySystem
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly SharedStorageSystem _storage = default!;
[Dependency] private readonly PlayTimeTrackingManager _playTimeTracking = default!;

#if LPP_Sponsors
[Dependency] private readonly CheckSponsorSystem _checkSponsor = default!;
#endif

public override void Initialize()
{
Expand All @@ -27,13 +32,22 @@ public override void Initialize()

private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent ev)
{
#if LPP_Sponsors
var sponsorTier = _checkSponsor.CheckUser(ev.Player.UserId).Item2 ?? 0;
var uuid = ev.Player.UserId.ToString();
#endif

if (ev.JobId == null ||
!_configurationManager.GetCVar(CCVars.GameLoadoutsEnabled))
return;

// Spawn the loadout, get a list of items that failed to equip
var failedLoadouts = _loadout.ApplyCharacterLoadout(ev.Mob, ev.JobId, ev.Profile,
_playTimeTracking.GetTrackerTimes(ev.Player), ev.Player.ContentData()?.Whitelisted ?? false);
_playTimeTracking.GetTrackerTimes(ev.Player), ev.Player.ContentData()?.Whitelisted ?? false
#if LPP_Sponsors
, sponsorTier, uuid
#endif
);

// Try to find back-mounted storage apparatus
if (!_inventory.TryGetSlotEntity(ev.Mob, "back", out var item) ||
Expand Down
17 changes: 16 additions & 1 deletion Content.Server/Traits/TraitSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
using Content.Shared.Psionics;
using Content.Server.Language;
using Content.Shared.Mood;
#if LPP_Sponsors
using Content.Server._LostParadise.Sponsors;
#endif

namespace Content.Server.Traits;

Expand All @@ -28,6 +31,9 @@ public sealed class TraitSystem : EntitySystem
[Dependency] private readonly PsionicAbilitiesSystem _psionicAbilities = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly LanguageSystem _languageSystem = default!;
#if LPP_Sponsors
[Dependency] private readonly CheckSponsorSystem _checkSponsor = default!;
#endif

public override void Initialize()
{
Expand All @@ -39,6 +45,11 @@ public override void Initialize()
// When the player is spawned in, add all trait components selected during character creation
private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent args)
{

#if LPP_Sponsors
var sponsorTier = _checkSponsor.CheckUser(args.Player.UserId).Item2 ?? 0;
var uuid = args.Player.UserId.ToString();
#endif
foreach (var traitId in args.Profile.TraitPreferences)
{
if (!_prototype.TryIndex<TraitPrototype>(traitId, out var traitPrototype))
Expand All @@ -52,7 +63,11 @@ private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent args)
_prototype.Index<JobPrototype>(args.JobId ?? _prototype.EnumeratePrototypes<JobPrototype>().First().ID),
args.Profile, _playTimeTracking.GetTrackerTimes(args.Player), args.Player.ContentData()?.Whitelisted ?? false, traitPrototype,
EntityManager, _prototype, _configuration,
out _))
out _
#if LPP_Sponsors
, 0, sponsorTier, uuid
#endif
))
continue;

AddTrait(args.Mob, traitPrototype);
Expand Down
24 changes: 20 additions & 4 deletions Content.Shared/Clothing/Loadouts/Systems/LoadoutSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent a


public List<EntityUid> ApplyCharacterLoadout(EntityUid uid, ProtoId<JobPrototype> job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted)
Dictionary<string, TimeSpan> playTimes, bool whitelisted
#if LPP_Sponsors
, int sponsorTier = 0, string uuid = ""
#endif
)
{
var jobPrototype = _prototype.Index(job);
return ApplyCharacterLoadout(uid, jobPrototype, profile, playTimes, whitelisted);
return ApplyCharacterLoadout(uid, jobPrototype, profile, playTimes, whitelisted
#if LPP_Sponsors
, sponsorTier, uuid
#endif
);
}

/// <summary>
Expand All @@ -56,7 +64,11 @@ public List<EntityUid> ApplyCharacterLoadout(EntityUid uid, ProtoId<JobPrototype
/// <param name="whitelisted">If the player is whitelisted</param>
/// <returns>A list of loadout items that couldn't be equipped but passed checks</returns>
public List<EntityUid> ApplyCharacterLoadout(EntityUid uid, JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted)
Dictionary<string, TimeSpan> playTimes, bool whitelisted
#if LPP_Sponsors
, int sponsorTier = 0, string uuid = ""
#endif
)
{
var failedLoadouts = new List<EntityUid>();

Expand All @@ -72,7 +84,11 @@ public List<EntityUid> ApplyCharacterLoadout(EntityUid uid, JobPrototype job, Hu
if (!_characterRequirements.CheckRequirementsValid(
loadoutProto.Requirements, job, profile, playTimes, whitelisted, loadoutProto,
EntityManager, _prototype, _configuration,
out _))
out _
#if LPP_Sponsors
, 0, sponsorTier, uuid
#endif
))
continue;


Expand Down
23 changes: 11 additions & 12 deletions Content.Shared/Customization/Systems/CharacterRequirementsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ public bool CheckRequirementValid(CharacterRequirement requirement, JobPrototype
)
{
var validation = false;
#if LPP_Sponsors
validation = requirement.IsValid(job, profile, playTimes, whitelisted, prototype,
entityManager, prototypeManager, configManager,
out reason, depth, sponsorTier, uuid);
#else

validation = requirement.IsValid(job, profile, playTimes, whitelisted, prototype,
entityManager, prototypeManager, configManager,
out reason, depth);
out reason, depth
#if LPP_Sponsors
, sponsorTier, uuid
#endif
);

// Return false if the requirement is invalid and not inverted
// If it's inverted return false when it's valid
Expand All @@ -56,15 +55,15 @@ public bool CheckRequirementsValid(List<CharacterRequirement> requirements, JobP
{
var validation = false;
FormattedMessage? reason;
#if LPP_Sponsors
validation = requirement.IsValid(job, profile, playTimes, whitelisted, prototype,
entityManager, prototypeManager, configManager,
out reason, depth, sponsorTier, uuid);
#else

validation = requirement.IsValid(job, profile, playTimes, whitelisted, prototype,
entityManager, prototypeManager, configManager,
out reason, depth);
out reason, depth
#if LPP_Sponsors
, sponsorTier, uuid
#endif
);

// Set valid to false if the requirement is invalid and not inverted
// If it's inverted set valid to false when it's valid
if (!validation)
Expand Down

0 comments on commit eca2d3e

Please sign in to comment.