2023-08-15 16:36:29 +01:00
using LootDumpProcessor.Logger ;
using LootDumpProcessor.Model.Tarkov ;
2023-08-12 19:08:38 +01:00
using LootDumpProcessor.Serializers.Json ;
namespace LootDumpProcessor.Process ;
public class TarkovItems
{
private static readonly IJsonSerializer _jsonSerializer = JsonSerializerFactory . GetInstance ( ) ;
private Dictionary < string , TemplateFileItem > _items ;
2023-08-15 16:36:29 +01:00
public TarkovItems ( string items )
2023-08-12 19:08:38 +01:00
{
_items = _jsonSerializer . Deserialize < Dictionary < string , TemplateFileItem > > ( File . ReadAllText ( items ) ) ;
}
public virtual bool IsBaseClass ( string tpl , string baseclass_id )
{
2023-08-15 16:36:29 +01:00
if ( ! _items . TryGetValue ( tpl , out var item_template ) )
{
LoggerFactory . GetInstance ( ) . Log ( $"[IsBaseClass] Item template '{tpl}' with base class id '{baseclass_id}' was not found on the server items!" , LogLevel . Error ) ;
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 )
{
2023-08-15 16:36:29 +01:00
if ( ! _items . TryGetValue ( tpl , out var item_template ) )
{
LoggerFactory . GetInstance ( ) . Log ( $"[IsQuestItem] Item template '{tpl}' was not found on the server items!" , LogLevel . Error ) ;
return false ;
}
2023-08-12 19:08:38 +01:00
return item_template . Props . QuestItem ;
}
public virtual string? MaxDurability ( string tpl )
{
2023-08-15 16:36:29 +01:00
if ( ! _items . TryGetValue ( tpl , out var item_template ) )
{
LoggerFactory . GetInstance ( ) . Log ( $"[MaxDurability] Item template '{tpl}' was not found on the server items!" , LogLevel . Error ) ;
return null ;
}
2023-08-12 19:08:38 +01:00
return item_template . Props . MaxDurability ? . ToString ( ) ? ? "" ;
}
public virtual string? AmmoCaliber ( string tpl )
{
2023-08-15 16:36:29 +01:00
if ( ! _items . TryGetValue ( tpl , out var item_template ) )
{
LoggerFactory . GetInstance ( ) . Log ( $"[AmmoCaliber] Item template '{tpl}' was not found on the server items!" , LogLevel . Error ) ;
return null ;
}
2023-08-12 19:08:38 +01:00
return item_template . Props . Caliber ;
}
}