Merge branch 'ServersComments' of https://github.com/tetrisdev/server-csharp into ServicesComments
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using Core.Utils.Cloners;
|
||||
using SptCommon.Annotations;
|
||||
|
||||
namespace Core.Services;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class InMemoryCacheService(
|
||||
ICloner _cloner
|
||||
)
|
||||
{
|
||||
protected Dictionary<string, object?> _cacheData = new();
|
||||
|
||||
// Store data into an in-memory object
|
||||
// key to store data against
|
||||
// Data to store in cache
|
||||
public void StoreByKey<T>(string key, T dataToCache)
|
||||
{
|
||||
_cacheData[key] = _cloner.Clone(dataToCache);
|
||||
}
|
||||
|
||||
// Retrieve data stored by a key
|
||||
// key
|
||||
// Stored data
|
||||
public T? GetDataByKey<T>(string key)
|
||||
{
|
||||
if (_cacheData.ContainsKey(key))
|
||||
{
|
||||
return (T) _cacheData[key];
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
// Does data exist against the provided key
|
||||
// Key to check for data against
|
||||
// true if exists
|
||||
public bool HasStoredDataByKey(string key)
|
||||
{
|
||||
return _cacheData.ContainsKey(key);
|
||||
}
|
||||
|
||||
// Remove data stored against key
|
||||
// Key to remove data against
|
||||
public void ClearDataStoredByKey(string key)
|
||||
{
|
||||
_cacheData.Remove(key);
|
||||
}
|
||||
|
||||
// Remove all data stored
|
||||
public void ClearCache()
|
||||
{
|
||||
_cacheData.Clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
using Core.Models.Spt.Config;
|
||||
using Core.Models.Utils;
|
||||
using Core.Servers;
|
||||
using Core.Utils.Cloners;
|
||||
using SptCommon.Annotations;
|
||||
|
||||
namespace Core.Services;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class ItemFilterService(
|
||||
ISptLogger<ItemFilterService> _logger,
|
||||
ICloner _cloner,
|
||||
ConfigServer _configServer
|
||||
)
|
||||
{
|
||||
protected HashSet<string>? _itemBlacklistCache = [];
|
||||
protected ItemConfig _itemConfig = _configServer.GetConfig<ItemConfig>();
|
||||
|
||||
protected HashSet<string>? _lootableItemBlacklistCache = [];
|
||||
|
||||
/**
|
||||
* Check if the provided template id is blacklisted in config/item.json/blacklist
|
||||
* @param tpl template id
|
||||
* @returns true if blacklisted
|
||||
*/
|
||||
public bool ItemBlacklisted(string tpl)
|
||||
{
|
||||
if (_itemBlacklistCache.Count == 0)
|
||||
{
|
||||
_itemBlacklistCache.UnionWith(_itemConfig.Blacklist);
|
||||
}
|
||||
|
||||
return _itemBlacklistCache.Contains(tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if item is blacklisted from being a reward for player
|
||||
* @param tpl item tpl to check is on blacklist
|
||||
* @returns True when blacklisted
|
||||
*/
|
||||
public bool ItemRewardBlacklisted(string tpl)
|
||||
{
|
||||
return _itemConfig.RewardItemBlacklist.Contains(tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of items that should never be given as a reward to player
|
||||
* @returns string array of item tpls
|
||||
*/
|
||||
public HashSet<string> GetItemRewardBlacklist()
|
||||
{
|
||||
return _cloner.Clone(_itemConfig.RewardItemBlacklist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of item types that should never be given as a reward to player
|
||||
* @returns string array of item base ids
|
||||
*/
|
||||
public HashSet<string> GetItemRewardBaseTypeBlacklist()
|
||||
{
|
||||
return _cloner.Clone(_itemConfig.RewardItemTypeBlacklist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return every template id blacklisted in config/item.json
|
||||
* @returns string array of blacklisted template ids
|
||||
*/
|
||||
public HashSet<string> GetBlacklistedItems()
|
||||
{
|
||||
return _cloner.Clone(_itemConfig.Blacklist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return every template id blacklisted in config/item.json/lootableItemBlacklist
|
||||
* @returns string array of blacklisted template ids
|
||||
*/
|
||||
public HashSet<string> GetBlacklistedLootableItems()
|
||||
{
|
||||
return _cloner.Clone(_itemConfig.LootableItemBlacklist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the provided template id is boss item in config/item.json
|
||||
* @param tpl template id
|
||||
* @returns true if boss item
|
||||
*/
|
||||
public bool BossItem(string tpl)
|
||||
{
|
||||
return _itemConfig.BossItems.Contains(tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return boss items in config/item.json
|
||||
* @returns string array of boss item template ids
|
||||
*/
|
||||
public HashSet<string> GetBossItems()
|
||||
{
|
||||
return _cloner.Clone(_itemConfig.BossItems).ToHashSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the provided template id is blacklisted in config/item.json/lootableItemBlacklist
|
||||
* @param tpl template id
|
||||
* @returns true if blacklisted
|
||||
*/
|
||||
public bool IsLootableItemBlacklisted(string itemKey)
|
||||
{
|
||||
if (!_lootableItemBlacklistCache.Any())
|
||||
{
|
||||
HydrateLootableItemBlacklist();
|
||||
}
|
||||
|
||||
return _lootableItemBlacklistCache.Contains(itemKey);
|
||||
}
|
||||
|
||||
public bool IsItemBlacklisted(string tpl)
|
||||
{
|
||||
if (!_itemBlacklistCache.Any())
|
||||
{
|
||||
HydrateBlacklist();
|
||||
}
|
||||
|
||||
return _itemBlacklistCache.Contains(tpl);
|
||||
}
|
||||
|
||||
protected void HydrateLootableItemBlacklist()
|
||||
{
|
||||
foreach (var item in _itemConfig.LootableItemBlacklist)
|
||||
{
|
||||
_lootableItemBlacklistCache.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
protected void HydrateBlacklist()
|
||||
{
|
||||
foreach (var item in _itemConfig.Blacklist)
|
||||
{
|
||||
_itemBlacklistCache.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the provided template id is boss item in config/item.json
|
||||
* @param tpl template id
|
||||
* @returns true if boss item
|
||||
*/
|
||||
public bool IsBossItem(string tpl)
|
||||
{
|
||||
return _itemConfig.BossItems.Contains(tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if item is blacklisted from being a reward for player
|
||||
* @param tpl item tpl to check is on blacklist
|
||||
* @returns True when blacklisted
|
||||
*/
|
||||
public bool IsItemRewardBlacklisted(string tpl)
|
||||
{
|
||||
return _itemConfig.RewardItemBlacklist.Contains(tpl);
|
||||
}
|
||||
}
|
||||
@@ -322,6 +322,12 @@ public class LocationLifecycleService
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a maps base location (cloned) and loot
|
||||
/// </summary>
|
||||
/// <param name="name"> Map name </param>
|
||||
/// <param name="generateLoot"> OPTIONAL - Should loot be generated for the map before being returned </param>
|
||||
/// <returns> LocationBase </returns>
|
||||
/// <returns> LocationBase </returns>
|
||||
/// <param name="generateLoot"> OPTIONAL - Should loot be generated for the map before being returned </param>
|
||||
/// <param name="name"> Map name </param>
|
||||
@@ -1178,8 +1184,8 @@ public class LocationLifecycleService
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// Is the player dead after a raid - dead = anything other than "survived" / "runner"
|
||||
/// </summary>
|
||||
/// <param name="results"> Post raid request </param>
|
||||
/// <returns> True if dead </returns>
|
||||
protected bool IsPlayerDead(EndRaidResult results)
|
||||
|
||||
Reference in New Issue
Block a user