feat: add npc info (level and aggro radius)
This commit is contained in:
parent
a8734a4ca0
commit
89cec4f40f
@ -60,7 +60,8 @@ namespace Client
|
||||
{
|
||||
IConfiguration config = new ConfigurationBuilder()
|
||||
.AddJsonFile("config.json", optional: false, reloadOnChange: true)
|
||||
.AddJsonFile("experience.json", optional: false, reloadOnChange: true)
|
||||
.AddJsonFile("Assets/data/experience.json", optional: false, reloadOnChange: true)
|
||||
.AddJsonFile("Assets/data/npcInfo.json", optional: false, reloadOnChange: true)
|
||||
.Build();
|
||||
|
||||
services
|
||||
@ -84,6 +85,7 @@ namespace Client
|
||||
)
|
||||
)
|
||||
.AddSingleton(typeof(ExperienceHelperInterface), typeof(ConfigurationExperienceHelper))
|
||||
.AddSingleton(typeof(NpcInfoHelperInterface), typeof(ConfigurationNpcInfoHelper))
|
||||
|
||||
.AddTransient(typeof(EntityFactoryInterface<Hero>), typeof(EntityFactory<Hero>))
|
||||
.AddTransient(typeof(EntityFactoryInterface<Drop>), typeof(EntityFactory<Drop>))
|
||||
|
22
Client/Application/Converters/CenterOfParentConverter.cs
Normal file
22
Client/Application/Converters/CenterOfParentConverter.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Client.Application.Converters
|
||||
{
|
||||
public class CenterOfParentConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return (double)values[0] + (double)values[2] / 2 - (double)values[1] / 2;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -41,9 +41,12 @@ namespace Client.Application.ViewModels
|
||||
if (npc.IsHostile)
|
||||
{
|
||||
result = "Monster";
|
||||
//todo aggr
|
||||
if (npc.AggroRadius > 0)
|
||||
{
|
||||
result += "*";
|
||||
}
|
||||
}
|
||||
//todo level
|
||||
result += " " + npc.Level + "lvl";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
26380
Client/Assets/data/npcInfo.json
Normal file
26380
Client/Assets/data/npcInfo.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -12,15 +12,15 @@
|
||||
<Content Include="config.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="experience.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Assets\icons\*.*">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Assets\data\*.*">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -29,8 +29,4 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Assets\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Client.Domain.Enums;
|
||||
using Client.Domain.Common;
|
||||
using Client.Domain.Enums;
|
||||
using Client.Domain.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -9,7 +10,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Entities
|
||||
{
|
||||
public class NPC : EntityInterface
|
||||
public class NPC : NotifyPropertyChanged, EntityInterface
|
||||
{
|
||||
public uint Id { get; set; }
|
||||
public Transform Transform { get; set; }
|
||||
@ -18,6 +19,8 @@ namespace Client.Domain.Entities
|
||||
public SpoilStateEnum SpoilState { get; set; }
|
||||
public FullName FullName { get; set; }
|
||||
public VitalStats VitalStats { get; set; }
|
||||
public uint Level { get => level; set { if (value != level) { level = value; OnPropertyChanged("Level"); } } }
|
||||
public uint AggroRadius { get => aggroRadius; set { if (value != aggroRadius) { aggroRadius = value; OnPropertyChanged("AggroRadius"); } } }
|
||||
|
||||
public NPC(uint id, Transform transform, bool isHostile, uint npcId, SpoilStateEnum spoilState, FullName fullName, VitalStats vitalStats)
|
||||
{
|
||||
@ -34,5 +37,8 @@ namespace Client.Domain.Entities
|
||||
{
|
||||
return VitalStats.MaxHp > 0 && VitalStats.Hp <= 0;
|
||||
}
|
||||
|
||||
private uint level;
|
||||
private uint aggroRadius;
|
||||
}
|
||||
}
|
||||
|
14
Client/Domain/Helpers/NpcInfoHelperInterface.cs
Normal file
14
Client/Domain/Helpers/NpcInfoHelperInterface.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Helpers
|
||||
{
|
||||
public interface NpcInfoHelperInterface
|
||||
{
|
||||
uint GetLevel(uint id);
|
||||
uint GetAggroRadius(uint id);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Factories;
|
||||
using Client.Domain.Helpers;
|
||||
using Client.Domain.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -14,17 +15,21 @@ namespace Client.Domain.Service
|
||||
public override void OnCreate(NPC entity)
|
||||
{
|
||||
mainViewModel.AddNpc(entity);
|
||||
entity.Level = npcInfoHelper.GetLevel(entity.NpcId);
|
||||
entity.AggroRadius = npcInfoHelper.GetAggroRadius(entity.NpcId);
|
||||
}
|
||||
public override void OnDelete(NPC entity)
|
||||
{
|
||||
mainViewModel.RemoveNpc(entity);
|
||||
}
|
||||
|
||||
public NpcHandler(EntityFactoryInterface<NPC> factory, MainViewModelInterface mainViewModel) : base(factory)
|
||||
public NpcHandler(EntityFactoryInterface<NPC> factory, MainViewModelInterface mainViewModel, NpcInfoHelperInterface npcInfoHelper) : base(factory)
|
||||
{
|
||||
this.mainViewModel = mainViewModel;
|
||||
this.npcInfoHelper = npcInfoHelper;
|
||||
}
|
||||
|
||||
private readonly MainViewModelInterface mainViewModel;
|
||||
private readonly NpcInfoHelperInterface npcInfoHelper;
|
||||
}
|
||||
}
|
||||
|
@ -39,16 +39,10 @@ namespace Client.Infrastructure.Helpers
|
||||
private readonly IConfiguration configuration;
|
||||
private Dictionary<uint, ulong> experienceToLevel = new Dictionary<uint, ulong>();
|
||||
|
||||
public class ExpInfo
|
||||
private class ExpInfo
|
||||
{
|
||||
public uint level { get; set; }
|
||||
public ulong toLevel { get; set; }
|
||||
|
||||
/* public ExpInfo(uint level, ulong toLevel)
|
||||
{
|
||||
this.level = level;
|
||||
this.toLevel = toLevel;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
62
Client/Infrastructure/Helpers/ConfigurationNpcInfoHelper.cs
Normal file
62
Client/Infrastructure/Helpers/ConfigurationNpcInfoHelper.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using Client.Domain.Helpers;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using static Client.Infrastructure.Helpers.ConfigurationExperienceHelper;
|
||||
|
||||
namespace Client.Infrastructure.Helpers
|
||||
{
|
||||
public class ConfigurationNpcInfoHelper : NpcInfoHelperInterface
|
||||
{
|
||||
public uint GetLevel(uint id)
|
||||
{
|
||||
return GetNpcInfo(id).level;
|
||||
}
|
||||
|
||||
public uint GetAggroRadius(uint id)
|
||||
{
|
||||
return GetNpcInfo(id).aggroRadius;
|
||||
}
|
||||
|
||||
public ConfigurationNpcInfoHelper(IConfiguration configuration)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
private NpcInfo GetNpcInfo(uint id)
|
||||
{
|
||||
if (!npcInfo.ContainsKey(id))
|
||||
{
|
||||
var item = configuration.GetRequiredSection("npcInfo").GetChildren()
|
||||
.Where(x => x.Key == id.ToString())
|
||||
.FirstOrDefault();
|
||||
uint level = 0;
|
||||
uint aggroRadius = 0;
|
||||
if (item != null)
|
||||
{
|
||||
uint.TryParse(item.GetRequiredSection("level").Value, out level);
|
||||
uint.TryParse(item.GetRequiredSection("aggroRadius").Value, out aggroRadius);
|
||||
}
|
||||
npcInfo[id] = new NpcInfo
|
||||
{
|
||||
level = level,
|
||||
aggroRadius = aggroRadius
|
||||
};
|
||||
}
|
||||
return npcInfo[id];
|
||||
}
|
||||
|
||||
private readonly IConfiguration configuration;
|
||||
private Dictionary<uint, NpcInfo> npcInfo = new Dictionary<uint, NpcInfo>();
|
||||
|
||||
private class NpcInfo
|
||||
{
|
||||
public uint level { get; set; }
|
||||
public uint aggroRadius { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user