feat: add items #wip

This commit is contained in:
k0t9i
2023-02-02 16:54:38 +04:00
parent 03423d0c41
commit c35f4e317a
14 changed files with 273 additions and 49 deletions

View File

@@ -39,6 +39,9 @@ namespace Client.Infrastructure.Factories
case MessageTypeEnum.Skill:
result = serviceProvider.GetService<SkillHandler>();
break;
case MessageTypeEnum.Item:
result = serviceProvider.GetService<ItemHander>();
break;
}
if (result == null)

View File

@@ -0,0 +1,48 @@
using Client.Domain.Entities;
using Client.Domain.Enums;
using Client.Domain.Factories;
using Client.Infrastructure.Parsers.Converters;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Infrastructure.Factories
{
public class ItemFactory : EntityFactoryInterface<BaseItem>
{
public BaseItem? Create(string data)
{
var type = JsonConvert.DeserializeObject<ItemType>(data, settings);
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
switch (type.Type)
{
case ItemTypeEnum.Etc:
return JsonConvert.DeserializeObject<EtcItem>(data, settings);
default:
return JsonConvert.DeserializeObject<EtcItem>(data, settings); //fixme temporary
}
throw new ArgumentException("Invalid item type " + type.Type.ToString());
}
public void Update(BaseItem entity, string data)
{
JsonConvert.PopulateObject(data, entity, settings);
}
private JsonSerializerSettings settings = new JsonSerializerSettings { Converters = { new BooleanConverter() } };
private class ItemType
{
public ItemTypeEnum Type { get; set; }
}
}
}