2018-12-04 23:20:31 -05:00
|
|
|
|
using OpenDiablo2.Common.Enums;
|
2018-12-08 12:08:01 -05:00
|
|
|
|
using OpenDiablo2.Common.Exceptions;
|
2018-12-04 23:20:31 -05:00
|
|
|
|
using OpenDiablo2.Common.Interfaces.Mobs;
|
2018-11-29 21:20:29 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-12-10 21:43:06 -05:00
|
|
|
|
using System.Collections.Immutable;
|
2018-11-29 21:20:29 -05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace OpenDiablo2.Common.Models.Mobs
|
|
|
|
|
{
|
|
|
|
|
public class LevelExperienceConfig : ILevelExperienceConfig
|
|
|
|
|
{
|
2018-12-08 13:11:52 -05:00
|
|
|
|
private readonly List<long> ExperiencePerLevel;
|
2018-11-29 21:20:29 -05:00
|
|
|
|
|
2018-12-04 23:20:31 -05:00
|
|
|
|
public LevelExperienceConfig(List<long> expperlevel)
|
2018-11-29 21:20:29 -05:00
|
|
|
|
{
|
|
|
|
|
ExperiencePerLevel = expperlevel;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 23:20:31 -05:00
|
|
|
|
public long GetTotalExperienceForLevel(int level)
|
2018-11-29 21:20:29 -05:00
|
|
|
|
{
|
|
|
|
|
if(ExperiencePerLevel.Count <= level)
|
|
|
|
|
{
|
|
|
|
|
return -1; // note: a value of -1 means this level is unattainable!
|
|
|
|
|
}
|
|
|
|
|
return ExperiencePerLevel[level];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetMaxLevel()
|
|
|
|
|
{
|
|
|
|
|
return ExperiencePerLevel.Count - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-04 23:20:31 -05:00
|
|
|
|
|
|
|
|
|
public static class LevelExperienceConfigHelper
|
|
|
|
|
{
|
2018-12-10 21:43:06 -05:00
|
|
|
|
public static ImmutableDictionary<eHero, ILevelExperienceConfig> ToLevelExperienceConfigs(this string[][] data)
|
2018-12-04 23:20:31 -05:00
|
|
|
|
{
|
|
|
|
|
Dictionary<eHero, ILevelExperienceConfig> result = new Dictionary<eHero, ILevelExperienceConfig>();
|
|
|
|
|
for (int i = 1; i < data[0].Length; i++)
|
|
|
|
|
{
|
|
|
|
|
// i starts at 1 because we want to skip the first column
|
|
|
|
|
// the first column is just the row titles
|
|
|
|
|
string heroname = data[i][0]; // first row is the hero name
|
2018-12-08 09:32:09 -05:00
|
|
|
|
if (!Enum.TryParse<eHero>(heroname, out eHero herotype))
|
2018-12-04 23:20:31 -05:00
|
|
|
|
{
|
|
|
|
|
continue; // skip this hero if we can't parse the name into a valid hero type
|
|
|
|
|
}
|
|
|
|
|
int maxlevel = -1;
|
|
|
|
|
if(!int.TryParse(data[1][i], out maxlevel))
|
|
|
|
|
{
|
|
|
|
|
maxlevel = -1;// we don't need to fail in this case since maxlevel
|
|
|
|
|
// can be inferred from the number of experience listings
|
|
|
|
|
}
|
|
|
|
|
List<long> expperlevel = new List<long>();
|
|
|
|
|
for (int o = 2; o < data.Length && (o-2 < maxlevel || maxlevel == -1); o++)
|
|
|
|
|
{
|
2018-12-08 09:32:09 -05:00
|
|
|
|
if (!long.TryParse(data[o][i], out long exp))
|
2018-12-04 23:20:31 -05:00
|
|
|
|
{
|
2018-12-08 12:08:01 -05:00
|
|
|
|
throw new OpenDiablo2Exception("Could not parse experience number '" + data[o][i] + "'.");
|
2018-12-04 23:20:31 -05:00
|
|
|
|
}
|
|
|
|
|
expperlevel.Add(exp);
|
|
|
|
|
}
|
|
|
|
|
result.Add(herotype, new LevelExperienceConfig(expperlevel));
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-10 21:43:06 -05:00
|
|
|
|
return result.ToImmutableDictionary();
|
2018-12-04 23:20:31 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-29 21:20:29 -05:00
|
|
|
|
}
|