2024-04-16 18:29:40 +00:00
using LootDumpProcessor.Logger ;
2023-08-15 16:36:29 +01:00
using LootDumpProcessor.Model.Tarkov ;
2023-08-12 19:08:38 +01:00
using LootDumpProcessor.Serializers.Json ;
namespace LootDumpProcessor.Process ;
2024-04-16 18:29:40 +00:00
public class TarkovItems ( string items )
2023-08-12 19:08:38 +01:00
{
private static readonly IJsonSerializer _jsonSerializer = JsonSerializerFactory . GetInstance ( ) ;
2024-04-16 18:29:40 +00:00
private readonly Dictionary < string , TemplateFileItem > ? _items = _jsonSerializer . Deserialize < Dictionary < string , TemplateFileItem > > ( File . ReadAllText ( items ) ) ;
2023-08-12 19:08:38 +01:00
public virtual bool IsBaseClass ( string tpl , string baseclass_id )
{
2024-04-16 18:29:40 +00:00
if ( _items = = null )
throw new Exception ( "The server items couldnt be found or loaded. Check server config is pointing to the correct place" ) ;
2023-08-15 16:36:29 +01:00
if ( ! _items . TryGetValue ( tpl , out var item_template ) )
{
2024-04-16 18:29:40 +00:00
if ( LoggerFactory . GetInstance ( ) . CanBeLogged ( LogLevel . Error ) )
LoggerFactory . GetInstance ( ) . Log ( $"[IsBaseClass] Item template '{tpl}' with base class id '{baseclass_id}' was not found on the server items!" , LogLevel . Error ) ;
2023-08-15 16:36:29 +01:00
return false ;
}
2023-08-12 19:08:38 +01:00
if ( string . IsNullOrEmpty ( item_template . Parent ) )
return false ;
return item_template . Parent = = baseclass_id | | IsBaseClass ( item_template . Parent , baseclass_id ) ;
}
public virtual bool IsQuestItem ( string tpl )
{
2024-04-16 18:29:40 +00:00
if ( _items = = null )
throw new Exception ( "The server items couldnt be found or loaded. Check server config is pointing to the correct place" ) ;
2023-08-15 16:36:29 +01:00
if ( ! _items . TryGetValue ( tpl , out var item_template ) )
{
2024-04-16 18:29:40 +00:00
if ( LoggerFactory . GetInstance ( ) . CanBeLogged ( LogLevel . Error ) )
LoggerFactory . GetInstance ( ) . Log ( $"[IsQuestItem] Item template '{tpl}' was not found on the server items!" , LogLevel . Error ) ;
2023-08-15 16:36:29 +01:00
return false ;
}
2023-08-12 19:08:38 +01:00
return item_template . Props . QuestItem ;
}
public virtual string? MaxDurability ( string tpl )
{
2024-04-16 18:29:40 +00:00
if ( _items = = null )
throw new Exception ( "The server items couldnt be found or loaded. Check server config is pointing to the correct place" ) ;
2023-08-15 16:36:29 +01:00
if ( ! _items . TryGetValue ( tpl , out var item_template ) )
{
2024-04-16 18:29:40 +00:00
if ( LoggerFactory . GetInstance ( ) . CanBeLogged ( LogLevel . Error ) )
LoggerFactory . GetInstance ( ) . Log ( $"[MaxDurability] Item template '{tpl}' was not found on the server items!" , LogLevel . Error ) ;
2023-08-15 16:36:29 +01:00
return null ;
}
2023-08-12 19:08:38 +01:00
return item_template . Props . MaxDurability ? . ToString ( ) ? ? "" ;
}
public virtual string? AmmoCaliber ( string tpl )
{
2024-04-16 18:29:40 +00:00
if ( _items = = null )
throw new Exception ( "The server items couldnt be found or loaded. Check server config is pointing to the correct place" ) ;
2023-08-15 16:36:29 +01:00
if ( ! _items . TryGetValue ( tpl , out var item_template ) )
{
2024-04-16 18:29:40 +00:00
if ( LoggerFactory . GetInstance ( ) . CanBeLogged ( LogLevel . Error ) )
LoggerFactory . GetInstance ( ) . Log ( $"[AmmoCaliber] Item template '{tpl}' was not found on the server items!" , LogLevel . Error ) ;
2023-08-15 16:36:29 +01:00
return null ;
}
2023-08-12 19:08:38 +01:00
return item_template . Props . Caliber ;
}
}