Job-specific traitor items (#9601)
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using Content.Client.Message;
|
||||
using Content.Shared.PDA;
|
||||
using Content.Shared.Traitor.Uplink;
|
||||
@@ -9,8 +8,6 @@ using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Traitor.Uplink
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.Traitor.Uplink.Components;
|
||||
using Content.Shared.Stacks;
|
||||
using Content.Shared.Traitor.Uplink;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Traitor.Uplink.Account
|
||||
{
|
||||
@@ -68,10 +70,14 @@ namespace Content.Server.Traitor.Uplink.Account
|
||||
|
||||
}
|
||||
|
||||
public bool TryPurchaseItem(UplinkAccount acc, string itemId, EntityCoordinates spawnCoords, [NotNullWhen(true)] out EntityUid? purchasedItem)
|
||||
public bool TryPurchaseItem(UplinkComponent component, string itemId, EntityCoordinates spawnCoords, [NotNullWhen(true)] out EntityUid? purchasedItem)
|
||||
{
|
||||
var acc = component.UplinkAccount;
|
||||
purchasedItem = null;
|
||||
|
||||
if (acc == null) return false;
|
||||
if (acc.AccountHolder == null) return false;
|
||||
|
||||
if (!_listingSystem.TryGetListing(itemId, out var listing))
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Traitor.Uplink;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server.Traitor.Uplink.Components
|
||||
{
|
||||
@@ -22,6 +24,9 @@ namespace Content.Server.Traitor.Uplink.Components
|
||||
|
||||
[ViewVariables] public UplinkAccount? UplinkAccount;
|
||||
|
||||
[ViewVariables, DataField("jobWhiteList", customTypeSerializer:typeof(PrototypeIdHashSetSerializer<JobPrototype>))]
|
||||
public HashSet<string>? JobWhitelist = null;
|
||||
|
||||
[Serializable]
|
||||
[DataDefinition]
|
||||
public sealed class PresetUplinkInfo
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Content.Server.Traitor.Uplink
|
||||
foreach (var item in _prototypeManager.EnumeratePrototypes<UplinkStoreListingPrototype>())
|
||||
{
|
||||
var newListing = new UplinkListingData(item.ListingName, item.ItemId,
|
||||
item.Price, item.Category, item.Description, item.Icon);
|
||||
item.Price, item.Category, item.Description, item.Icon, item.JobWhitelist);
|
||||
|
||||
RegisterUplinkListing(newListing);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Roles;
|
||||
using Content.Server.Traitor.Uplink.Account;
|
||||
using Content.Server.Traitor.Uplink.Components;
|
||||
using Content.Server.UserInterface;
|
||||
@@ -106,10 +108,10 @@ namespace Content.Server.Traitor.Uplink
|
||||
|
||||
private void OnBuy(EntityUid uid, UplinkComponent uplink, UplinkBuyListingMessage message)
|
||||
{
|
||||
if (message.Session.AttachedEntity is not {Valid: true} player) return;
|
||||
if (message.Session.AttachedEntity is not { Valid: true } player) return;
|
||||
if (uplink.UplinkAccount == null) return;
|
||||
|
||||
if (!_accounts.TryPurchaseItem(uplink.UplinkAccount, message.ItemId,
|
||||
if (!_accounts.TryPurchaseItem(uplink, message.ItemId,
|
||||
EntityManager.GetComponent<TransformComponent>(player).Coordinates, out var entity))
|
||||
{
|
||||
SoundSystem.Play(uplink.InsufficientFundsSound.GetSound(),
|
||||
@@ -132,7 +134,7 @@ namespace Content.Server.Traitor.Uplink
|
||||
if (acc == null)
|
||||
return;
|
||||
|
||||
if (args.Session.AttachedEntity is not {Valid: true} player) return;
|
||||
if (args.Session.AttachedEntity is not { Valid: true } player) return;
|
||||
var cords = EntityManager.GetComponent<TransformComponent>(player).Coordinates;
|
||||
|
||||
// try to withdraw TCs from account
|
||||
@@ -163,16 +165,60 @@ namespace Content.Server.Traitor.Uplink
|
||||
if (ui == null)
|
||||
return;
|
||||
|
||||
var listings = _listing.GetListings().Values.ToArray();
|
||||
var listings = _listing.GetListings().Values.ToList();
|
||||
var acc = component.UplinkAccount;
|
||||
|
||||
UplinkAccountData accData;
|
||||
if (acc != null)
|
||||
accData = new UplinkAccountData(acc.AccountHolder, acc.Balance);
|
||||
else
|
||||
accData = new UplinkAccountData(null, 0);
|
||||
{
|
||||
// if we don't have a jobwhitelist stored, get a new one
|
||||
if (component.JobWhitelist == null &&
|
||||
acc.AccountHolder != null &&
|
||||
TryComp<MindComponent>(acc.AccountHolder, out var mind) &&
|
||||
mind.Mind != null)
|
||||
{
|
||||
HashSet<string>? jobList = new();
|
||||
foreach (var role in mind.Mind.AllRoles.ToList())
|
||||
{
|
||||
if (role.GetType() == typeof(Job))
|
||||
{
|
||||
var job = (Job) role;
|
||||
jobList.Add(job.Prototype.ID);
|
||||
}
|
||||
}
|
||||
component.JobWhitelist = jobList;
|
||||
}
|
||||
|
||||
ui.SetState(new UplinkUpdateState(accData, listings));
|
||||
// filter out items not on the whitelist
|
||||
if (component.JobWhitelist != null)
|
||||
{
|
||||
for (var i = 0; i < listings.Count; i++)
|
||||
{
|
||||
var entry = listings[i];
|
||||
if (entry.JobWhitelist != null)
|
||||
{
|
||||
var found = false;
|
||||
foreach (var job in component.JobWhitelist)
|
||||
{
|
||||
if (entry.JobWhitelist.Contains(job))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
listings.Remove(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
accData = new UplinkAccountData(acc.AccountHolder, acc.Balance);
|
||||
}
|
||||
else
|
||||
{
|
||||
accData = new UplinkAccountData(null, 0);
|
||||
}
|
||||
|
||||
ui.SetState(new UplinkUpdateState(accData, listings.ToArray()));
|
||||
}
|
||||
|
||||
public bool AddUplink(EntityUid user, UplinkAccount account, EntityUid? uplinkEntity = null)
|
||||
@@ -204,9 +250,9 @@ namespace Content.Server.Traitor.Uplink
|
||||
{
|
||||
while (containerSlotEnumerator.MoveNext(out var pdaUid))
|
||||
{
|
||||
if(!pdaUid.ContainedEntity.HasValue) continue;
|
||||
if (!pdaUid.ContainedEntity.HasValue) continue;
|
||||
|
||||
if(HasComp<PDAComponent>(pdaUid.ContainedEntity.Value))
|
||||
if (HasComp<PDAComponent>(pdaUid.ContainedEntity.Value))
|
||||
return pdaUid.ContainedEntity.Value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Content.Shared.PDA
|
||||
Bundles,
|
||||
Tools,
|
||||
Utility,
|
||||
Job,
|
||||
Armor,
|
||||
Pointless,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.PDA
|
||||
@@ -29,6 +31,9 @@ namespace Content.Shared.PDA
|
||||
[DataField("icon")]
|
||||
public SpriteSpecifier? Icon { get; } = null;
|
||||
|
||||
[DataField("jobWhitelist", customTypeSerializer:typeof(PrototypeIdHashSetSerializer<JobPrototype>))]
|
||||
public HashSet<string>? JobWhitelist;
|
||||
|
||||
[DataField("surplus")]
|
||||
public bool CanSurplus = true;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Traitor.Uplink
|
||||
@@ -7,7 +8,6 @@ namespace Content.Shared.Traitor.Uplink
|
||||
{
|
||||
public EntityUid? DataAccountHolder;
|
||||
public int DataBalance;
|
||||
|
||||
public UplinkAccountData(EntityUid? dataAccountHolder, int dataBalance)
|
||||
{
|
||||
DataAccountHolder = dataAccountHolder;
|
||||
|
||||
@@ -13,10 +13,11 @@ namespace Content.Shared.Traitor.Uplink
|
||||
public readonly string Description;
|
||||
public readonly string ListingName;
|
||||
public readonly SpriteSpecifier? Icon;
|
||||
public readonly HashSet<string>? JobWhitelist;
|
||||
|
||||
public UplinkListingData(string listingName, string itemId,
|
||||
int price, UplinkCategory category,
|
||||
string description, SpriteSpecifier? icon)
|
||||
string description, SpriteSpecifier? icon, HashSet<string>? jobWhitelist)
|
||||
{
|
||||
ListingName = listingName;
|
||||
Price = price;
|
||||
@@ -24,6 +25,7 @@ namespace Content.Shared.Traitor.Uplink
|
||||
Description = description;
|
||||
ItemId = itemId;
|
||||
Icon = icon;
|
||||
JobWhitelist = jobWhitelist;
|
||||
}
|
||||
|
||||
public bool Equals(UplinkListingData? other)
|
||||
|
||||
@@ -304,6 +304,17 @@
|
||||
itemId: DehydratedSpaceCarp
|
||||
price: 3
|
||||
|
||||
# Job Specific
|
||||
|
||||
- type: uplinkListing
|
||||
id: uplinkNecronomicon
|
||||
category: Job
|
||||
itemId: BibleNecronomicon
|
||||
description: An unholy book capable of summoning a demonic familiar.
|
||||
price: 6
|
||||
jobWhitelist:
|
||||
- Chaplain
|
||||
|
||||
# Armor
|
||||
|
||||
# Should be cameleon shoes, change when implemented.
|
||||
|
||||
Reference in New Issue
Block a user