[feat]MeatyOre panel

This commit is contained in:
rhailrake
2023-04-28 06:07:50 +06:00
committed by Aviu00
parent c71ac26fdc
commit 4f6be99853
21 changed files with 2058 additions and 7 deletions

View File

@@ -71,7 +71,7 @@ public sealed partial class StoreMenu : DefaultWindow
disabled = false;
}
WithdrawButton.Disabled = disabled;
WithdrawButton.Visible = !disabled;
}
public void UpdateListing(List<ListingData> listings)

View File

@@ -9,6 +9,7 @@ using Content.Client.UserInterface.Systems.Gameplay;
using Content.Client.UserInterface.Systems.Guidebook;
using Content.Client.UserInterface.Systems.MenuBar.Widgets;
using Content.Client.UserInterface.Systems.Sandbox;
using Content.Client.White.MeatyOre;
using Robust.Client.UserInterface.Controllers;
namespace Content.Client.UserInterface.Systems.MenuBar;
@@ -24,6 +25,8 @@ public sealed class GameTopMenuBarUIController : UIController
[Dependency] private readonly SandboxUIController _sandbox = default!;
[Dependency] private readonly GuidebookUIController _guidebook = default!;
[Dependency] private readonly EmotionsUIController _emotions = default!;
[Dependency] private readonly MeatyOreUIController _meatyOreUIController = default!;
private GameTopMenuBar? GameTopMenuBar => UIManager.GetActiveUIWidgetOrNull<GameTopMenuBar>();
@@ -47,6 +50,7 @@ public sealed class GameTopMenuBarUIController : UIController
_action.UnloadButton();
_sandbox.UnloadButton();
_emotions.UnloadButton();
_meatyOreUIController.UnloadButton();
}
public void LoadButtons()
@@ -60,5 +64,6 @@ public sealed class GameTopMenuBarUIController : UIController
_action.LoadButton();
_sandbox.LoadButton();
_emotions.LoadButton();
_meatyOreUIController.LoadButton();
}
}

View File

@@ -93,6 +93,16 @@
HorizontalExpand="True"
AppendStyleClass="{x:Static style:StyleBase.ButtonSquare}"
/>
<ui:MenuButton
Name="MeatyOreButton"
Access="Internal"
MinSize="42 64"
HorizontalExpand="True"
Icon="{xe:Tex '/Textures/Interface/meatyore-shop-icon.png'}"
AppendStyleClass="{x:Static style:StyleBase.ButtonSquare}"
ToolTip="Магазин метеора"
ToggleMode="False"
/>
<ui:MenuButton
Name="AHelpButton"
Access="Internal"

View File

@@ -0,0 +1,65 @@
using Content.Client.Administration.Managers;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.MenuBar.Widgets;
using Content.Client.White.Sponsors;
using Content.Shared.Administration;
using Content.Shared.Humanoid;
using Content.Shared.White.MeatyOre;
using Robust.Client.Player;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
namespace Content.Client.White.MeatyOre;
public sealed class MeatyOreUIController : UIController
{
[Dependency] private readonly IClientAdminManager _clientAdminManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IEntityNetworkManager _entityNetworkManager = default!;
[Dependency] private readonly SponsorsManager _sponsorsManager = default!;
private bool _buttonLoaded;
private MenuButton? MeatyOreButton => UIManager.GetActiveUIWidgetOrNull<GameTopMenuBar>()?.MeatyOreButton;
public void LoadButton()
{
MeatyOreButton!.OnPressed += MeatyOreButtonPressed;
_buttonLoaded = true;
}
public void UnloadButton()
{
MeatyOreButton!.OnPressed -= MeatyOreButtonPressed;
_buttonLoaded = false;
}
private void MeatyOreButtonPressed(BaseButton.ButtonEventArgs obj)
{
_entityNetworkManager.SendSystemNetworkMessage(new MeatyOreShopRequestEvent());
}
public override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if(!_buttonLoaded) return;
var shouldBeVisible = CheckButtonVisibility();
MeatyOreButton!.Visible = shouldBeVisible;
}
private bool CheckButtonVisibility()
{
if(!_sponsorsManager.TryGetInfo(out var sponsor)) return false;
if(sponsor?.Tier == null || sponsor?.MeatyOreCoin == 0) return false;
var controlledEntity = _playerManager!.LocalPlayer!.ControlledEntity;
if(controlledEntity == null) return false;
if (!_entityManager.HasComponent<HumanoidAppearanceComponent>(controlledEntity)) return false;
return true;
}
}

View File

@@ -31,7 +31,7 @@ public sealed partial class AdminVerbSystem
var player = actor.PlayerSession;
if (!_adminManager.HasAdminFlag(player, AdminFlags.MeatyOre) && !_adminManager.HasAdminFlag(player, AdminFlags.Fun))
if (!_adminManager.HasAdminFlag(player, AdminFlags.Fun))
return;
if (!TryComp<MindContainerComponent>(args.Target, out var targetMindComp))

View File

@@ -0,0 +1,24 @@
using Content.Server.Mind.Components;
using Content.Server.Traitor;
using Content.Shared.Store;
namespace Content.Server.Store.Conditions;
public sealed class BuyerBlockForAntagCondition : ListingCondition
{
public override bool Condition(ListingConditionArgs args)
{
var ent = args.EntityManager;
if (!ent.TryGetComponent<MindComponent>(args.Buyer, out var mind) || mind.Mind == null)
return false;
foreach (var role in mind.Mind.AllRoles)
{
if (role is TraitorRole traitorRole)
return false;
}
return true;
}
}

View File

@@ -0,0 +1,21 @@
using Content.Server.Mind.Components;
using Content.Shared.Store;
namespace Content.Server.Store.Conditions;
public sealed class BuyerBlockForMindProtected : ListingCondition
{
public override bool Condition(ListingConditionArgs args)
{
var buyer = args.Buyer;
var ent = args.EntityManager;
if (!ent.TryGetComponent<MindComponent>(buyer, out var mind) || mind.Mind == null)
return false;
if (mind.Mind.CurrentJob?.CanBeAntag != true)
return false;
return true;
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.White.Sponsors;
using Content.Shared.Store;
using Robust.Server.GameObjects;
namespace Content.Server.Store.Conditions;
public sealed class DonationTierLockCondition : ListingCondition
{
[DataField("tier", required: true)]
public int Tier;
public override bool Condition(ListingConditionArgs args)
{
var entityManager = args.EntityManager;
var sponsorsManager = IoCManager.Resolve<SponsorsManager>();
if(!entityManager.TryGetComponent<ActorComponent>(args.Buyer, out var actor)) return false;
if(!sponsorsManager.TryGetInfo(actor.PlayerSession.UserId, out var sponsorInfo)) return false;
if (sponsorInfo.Tier < Tier) return false;
return true;
}
}

View File

@@ -173,7 +173,7 @@ public sealed partial class StoreSystem
//broadcast event
if (listing.ProductEvent != null)
{
RaiseLocalEvent(listing.ProductEvent);
RaiseLocalEvent(buyer, listing.ProductEvent);
}
//log dat shit.
@@ -226,4 +226,12 @@ public sealed partial class StoreSystem
component.Balance[msg.Currency] -= msg.Amount;
UpdateUserInterface(buyer, uid, component);
}
public void CloseUi(EntityUid user, StoreComponent component)
{
if (!TryComp<ActorComponent>(user, out var actor))
return;
_ui.TryClose(component.Owner, StoreUiKey.Key, actor.PlayerSession);
}
}

View File

@@ -0,0 +1,197 @@
using System.Linq;
using Content.Server.Actions;
using Content.Server.Administration.Managers;
using Content.Server.Chat.Managers;
using Content.Server.GameTicking.Rules;
using Content.Server.Mind.Components;
using Content.Server.Store.Components;
using Content.Server.Store.Systems;
using Content.Server.White.Sponsors;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Content.Shared.FixedPoint;
using Content.Shared.GameTicking;
using Content.Shared.Humanoid;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Nuke;
using Content.Shared.Verbs;
using Content.Shared.White;
using Content.Shared.White.MeatyOre;
using Content.Shared.White.Sponsors;
using Robust.Server.GameObjects;
using Robust.Server.GameStates;
using Robust.Server.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Players;
using Robust.Shared.Random;
using Robust.Shared.Utility;
namespace Content.Server.White;
public sealed class MeatyOreStoreSystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly StoreSystem _storeSystem = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly TraitorRuleSystem _traitorRuleSystem = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly SponsorsManager _sponsorsManager = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly PVSOverrideSystem _pvsOverrideSystem = default!;
private static readonly string StorePresetPrototype = "StorePresetMeatyOre";
private static readonly string MeatyOreCurrensyPrototype = "MeatyOreCoin";
private static bool MeatyOrePanelEnabled;
private readonly Dictionary<NetUserId, StoreComponent> _meatyOreStores = new();
public override void Initialize()
{
base.Initialize();
_configurationManager.OnValueChanged(WhiteCVars.MeatyOrePanelEnabled, OnPanelEnableChanged, true);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnPostRoundCleanup);
SubscribeNetworkEvent<MeatyOreShopRequestEvent>(OnShopRequested);
SubscribeLocalEvent<MindComponent, MeatyTraitorRequestActionEvent>(OnAntagPurchase);
SubscribeLocalEvent<GetVerbsEvent<Verb>>(MeatyOreVerbs);
}
private void MeatyOreVerbs(GetVerbsEvent<Verb> ev)
{
if(ev.User == ev.Target) return;
if(!EntityManager.TryGetComponent<ActorComponent>(ev.User, out var actorComponent)) return;
if(!_sponsorsManager.TryGetInfo(actorComponent.PlayerSession.UserId, out _)) return;
if(!HasComp<HumanoidAppearanceComponent>(ev.Target)) return;
if(!TryComp<MobStateComponent>(ev.Target, out var state) || state?.CurrentState != MobState.Alive) return;
if(!TryGetStore(actorComponent.PlayerSession, out var store)) return;
if(!TryComp<MindComponent>(ev.Target, out var targetMind) || !targetMind.HasMind) return;
if (targetMind!.Mind!.AllRoles.Any(x => x.Antagonist)) return;
if(targetMind.Mind.CurrentJob?.CanBeAntag != true) return;
if(targetMind.Mind.Session == null) return;
if (!store.Balance.TryGetValue("MeatyOreCoin", out var currency)) return;
if(currency - 10 < 0) return;
var verb = new Verb()
{
Text = $"Выдать роль.",
ConfirmationPopup = true,
Message = $"Цена - {MeatyOreCurrensyPrototype}:10",
Act = () =>
{
_storeSystem.TryAddCurrency(new Dictionary<string, FixedPoint2> {{MeatyOreCurrensyPrototype, -10}}, store.Owner, store);
_traitorRuleSystem.MakeTraitor(targetMind.Mind.Session);
},
Category = VerbCategory.MeatyOre
};
ev.Verbs.Add(verb);
}
private void OnPanelEnableChanged(bool newValue)
{
if (newValue != true)
{
foreach (var meatyOreStoreData in _meatyOreStores)
{
var session = _playerManager.GetSessionByUserId(meatyOreStoreData.Key);
if(session == null) continue;
var playerEntity = session.AttachedEntity;
if(!playerEntity.HasValue) continue;
_storeSystem.CloseUi(playerEntity.Value, meatyOreStoreData.Value);
}
}
MeatyOrePanelEnabled = newValue;
}
private void OnAntagPurchase(EntityUid uid, MindComponent component, MeatyTraitorRequestActionEvent args)
{
if(component.Mind == null) return;
if(component.Mind.Session == null) return;
_traitorRuleSystem.MakeTraitor(component.Mind?.Session!);
}
private void OnShopRequested(MeatyOreShopRequestEvent msg, EntitySessionEventArgs args)
{
var playerSession = args.SenderSession as IPlayerSession;
if (!MeatyOrePanelEnabled)
{
_chatManager.DispatchServerMessage(playerSession!, "Мясная панель отключена на данном сервере! Приятной игры!");
return;
}
var playerEntity = args.SenderSession.AttachedEntity;
if(!playerEntity.HasValue) return;
if(!HasComp<HumanoidAppearanceComponent>(playerEntity.Value)) return;
if(!TryGetStore(playerSession!, out var storeComponent)) return;
_pvsOverrideSystem.AddSessionOverride(storeComponent.Owner, playerSession!);
_storeSystem.ToggleUi(playerEntity.Value, storeComponent.Owner, storeComponent);
}
private bool TryGetStore(IPlayerSession session, out StoreComponent store)
{
store = null!;
if (!_sponsorsManager.TryGetInfo(session.UserId, out var sponsorInfo))
{
return false;
}
if (_meatyOreStores.TryGetValue(session.UserId, out store!)) return true;
if (sponsorInfo.MeatyOreCoin == 0) return false;
store = CreateStore(session.UserId, sponsorInfo.MeatyOreCoin);
return true;
}
private void OnPostRoundCleanup(RoundRestartCleanupEvent ev)
{
foreach (var store in _meatyOreStores.Values)
{
Del(store.Owner);
}
_meatyOreStores.Clear();
}
private StoreComponent CreateStore(NetUserId userId, int balance)
{
var session = _playerManager.GetSessionByUserId(userId);
var shopEntity = _entityManager.SpawnEntity("StoreMeatyOreEntity", MapCoordinates.Nullspace);
var storeComponent = Comp<StoreComponent>(shopEntity);
_storeSystem.InitializeFromPreset("StorePresetMeatyOre", shopEntity, storeComponent);
storeComponent.Balance.Clear();
_storeSystem.TryAddCurrency(new Dictionary<string, FixedPoint2>() { { MeatyOreCurrensyPrototype, balance } }, storeComponent.Owner, storeComponent);
_meatyOreStores[userId] = storeComponent;
_pvsOverrideSystem.AddSessionOverride(shopEntity, session);
return storeComponent;
}
}

View File

@@ -23,6 +23,8 @@ using Content.Shared.Tag;
using Content.Shared.Timing;
using Content.Shared.Verbs;
using Content.Shared.Wall;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.White.MeatyOre;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.Input;
@@ -125,6 +127,11 @@ namespace Content.Shared.Interaction
return;
}
if (CompOrNull<IgnorBUIInteractionRangeComponent>(ev.Target) != null)
{
return;
}
if (!InRangeUnobstructed(user, ev.Target))
{
ev.Cancel();

View File

@@ -104,8 +104,7 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
Name != listing.Name ||
Description != listing.Description ||
ProductEntity != listing.ProductEntity ||
ProductAction != listing.ProductAction ||
ProductEvent != listing.ProductEvent)
ProductAction != listing.ProductAction)
return false;
if (Icon != null && !Icon.Equals(listing.Icon))

View File

@@ -38,6 +38,9 @@ namespace Content.Shared.Verbs
public static readonly VerbCategory Admin =
new("verb-categories-admin", "/Textures/Interface/character.svg.192dpi.png");
public static readonly VerbCategory MeatyOre =
new("MeatyOre", null);
public static readonly VerbCategory Antag =
new("verb-categories-antag", "/Textures/Interface/VerbIcons/antag-e_sword-temp.192dpi.png", iconsOnly: true) { Columns = 5 };

View File

@@ -0,0 +1,23 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Component = Robust.Shared.GameObjects.Component;
namespace Content.Shared.White.MeatyOre;
[Serializable, NetSerializable]
public sealed class MeatyOreShopRequestEvent : EntityEventArgs {}
[Serializable, NetSerializable]
public sealed class MeatyTraitorRequestActionEvent
{
public override bool Equals(object? obj)
{
return true;
}
}
[NetworkedComponent, RegisterComponent]
public sealed class IgnorBUIInteractionRangeComponent : Component
{
}

View File

@@ -24,6 +24,9 @@ public sealed class SponsorInfo
[JsonPropertyName("extraSlots")]
public int ExtraSlots { get; set; }
[JsonPropertyName("MeatyOreCoin")]
public int MeatyOreCoin { get; set; }
}
/// <summary>

View File

@@ -122,4 +122,22 @@ public sealed class WhiteCVars
public static readonly CVarDef<bool> EmergencyShuttleCallEnabled =
CVarDef.Create("shuttle.emergency_shuttle_call", true, CVar.SERVER | CVar.REPLICATED | CVar.ARCHIVE);
/*
* Xenophobia
*/
public static readonly CVarDef<bool> FanaticXenophobiaEnabled =
CVarDef.Create("white.fanatic_xenophobia", true, CVar.SERVERONLY | CVar.ARCHIVE);
/*
* MeatyOre
*/
public static readonly CVarDef<bool> MeatyOrePanelEnabled =
CVarDef.Create("white.meatyore_panel_enabled", true, CVar.REPLICATED | CVar.SERVER | CVar.ARCHIVE);
public static readonly CVarDef<int> MeatyOreDefaultBalance =
CVarDef.Create("white.meatyore_default_balance", 15, CVar.SERVER | CVar.ARCHIVE);
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
- type: currency
id: Telecrystal
displayName: store-currency-display-telecrystal
cash:
cash:
1: Telecrystal1
canWithdraw: true
@@ -10,7 +10,12 @@
displayName: store-currency-display-stolen-essence
canWithdraw: false
- type: currency
id: MeatyOreCoin
displayName: Meaty Ore Coin
canWithdraw: false
#debug
- type: currency
id: DebugDollar
displayName: store-currency-display-debugdollar
displayName: store-currency-display-debugdollar

View File

@@ -0,0 +1,51 @@
- type: storeCategory
id: MeatyOreHats
name: meatyore-store-category-hats
- type: storeCategory
id: MeatyOreMasks
name: meatyore-store-category-masks
- type: storeCategory
id: MeatyOreBoots
name: meatyore-store-category-boots
- type: storeCategory
id: MeatyOreGlasses
name: meatyore-store-category-glasses
- type: storeCategory
id: MeatyOrePersonal
name: meatyore-store-category-personal
- type: storeCategory
id: MeatyOreSuits
name: meatyore-store-category-suits
- type: storeCategory
id: MeatyOreUniforms
name: meatyore-store-category-uniforms
- type: storeCategory
id: MeatyOreGloves
name: meatyore-store-category-gloves
- type: storeCategory
id: MeatyOreCloaks
name: meatyore-store-category-cloaks
- type: storeCategory
id: MeatyOreToys
name: meatyore-store-category-toys
- type: storeCategory
id: MeatyOreSpecial
name: meatyore-store-category-special
- type: storeCategory
id: MeatyOreAntag
name: meatyore-store-category-antag
- type: storeCategory
id: DjJukeboxCategory
name: dj-jukebox-store-category

View File

@@ -0,0 +1,35 @@
- type: storePreset
id: StorePresetMeatyOre
storeName: MeatyOreStore
categories:
- MeatyOreHats
- MeatyOreMasks
- MeatyOreBoots
- MeatyOreGlasses
- MeatyOrePersonal
- MeatyOreSuits
- MeatyOreUniforms
- MeatyOreGloves
- MeatyOreCloaks
- MeatyOreToys
- MeatyOreSpecial
- MeatyOreAntag
- DjJukeboxCategory
currencyWhitelist:
- MeatyOreCoin
- type: entity
id: StoreMeatyOreEntity
name: ThisIsDumb
noSpawn: true
components:
- type: Store
preset: StorePresetMeatyOre
balance:
MeatyOreCoin: 0
- type: UserInterface
interfaces:
- key: enum.StoreUiKey.Key
type: StoreBoundUserInterface
range: -1
- type: IgnorBUIInteractionRange

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB