Rewrite helper to read from asset files instead of using hard coded values
This commit is contained in:
parent
df0e01afaf
commit
0cad6b769f
@ -1,81 +1,64 @@
|
|||||||
using Generator.Models.Output;
|
using Generator.Models.Output;
|
||||||
|
using Generator.Models.Output.Difficulty;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Generator.Helpers
|
namespace Generator.Helpers
|
||||||
{
|
{
|
||||||
public static class DifficultyHelper
|
public static class DifficultyHelper
|
||||||
{
|
{
|
||||||
public static void AddAssaultDifficulties(Bot bot)
|
private static readonly string[] _difficulties = new[] { "easy", "normal", "hard", "impossible" };
|
||||||
{
|
|
||||||
bot.difficulty.easy = new Models.Output.Difficulty.DifficultySettings
|
|
||||||
{
|
|
||||||
Lay = EasyHelper.GenerateLay(),
|
|
||||||
Aiming = EasyHelper.GenerateAiming(),
|
|
||||||
Look = EasyHelper.GenerateLook(),
|
|
||||||
Shoot = EasyHelper.GenerateShoot(),
|
|
||||||
Move = EasyHelper.GenerateMove(),
|
|
||||||
Grenade = EasyHelper.GenerateGrenade(),
|
|
||||||
Change = EasyHelper.GenerateChange(),
|
|
||||||
Cover = EasyHelper.GenerateCover(),
|
|
||||||
Patrol = EasyHelper.GeneratePatrol(),
|
|
||||||
Hearing = EasyHelper.GenerateHearing(),
|
|
||||||
Mind = EasyHelper.GenerateMind(),
|
|
||||||
Boss = EasyHelper.GenerateBoss(),
|
|
||||||
Core = EasyHelper.GenerateCore(),
|
|
||||||
Scattering = EasyHelper.GenerateScattering()
|
|
||||||
};
|
|
||||||
|
|
||||||
bot.difficulty.normal = new Models.Output.Difficulty.DifficultySettings(){
|
public static void AddDifficultySettings(Bot bot, List<string> difficultyFilePaths)
|
||||||
Lay = NormalHelper.GenerateLay(),
|
{
|
||||||
Aiming = NormalHelper.GenerateAiming(),
|
// Read bot setting files from assets folder that match this bots type
|
||||||
Look = NormalHelper.GenerateLook(),
|
// Save into dictionary with difficulty as key
|
||||||
Shoot = NormalHelper.GenerateShoot(),
|
var difficultySettingsJsons = new Dictionary<string, DifficultySettings>();
|
||||||
Move = NormalHelper.GenerateMove(),
|
foreach (var path in difficultyFilePaths.Where(x=>x.Contains(bot.botType.ToString())))
|
||||||
Grenade = NormalHelper.GenerateGrenade(),
|
{
|
||||||
Change = NormalHelper.GenerateChange(),
|
var json = File.ReadAllText(path);
|
||||||
Cover = NormalHelper.GenerateCover(),
|
var serialisedObject = JsonConvert.DeserializeObject<DifficultySettings>(json);
|
||||||
Patrol = NormalHelper.GeneratePatrol(),
|
|
||||||
Hearing = NormalHelper.GenerateHearing(),
|
|
||||||
Mind = NormalHelper.GenerateMind(),
|
|
||||||
Boss = NormalHelper.GenerateBoss(),
|
|
||||||
Core = NormalHelper.GenerateCore(),
|
|
||||||
Scattering = NormalHelper.GenerateScattering()
|
|
||||||
};
|
|
||||||
|
|
||||||
bot.difficulty.hard = new Models.Output.Difficulty.DifficultySettings()
|
var difficultyOfFile = GetFileDifficultyFromPath(path);
|
||||||
{
|
difficultySettingsJsons.Add(difficultyOfFile, serialisedObject);
|
||||||
Lay = HardHelper.GenerateLay(),
|
|
||||||
Aiming = HardHelper.GenerateAiming(),
|
|
||||||
Look = HardHelper.GenerateLook(),
|
|
||||||
Shoot = HardHelper.GenerateShoot(),
|
|
||||||
Move = HardHelper.GenerateMove(),
|
|
||||||
Grenade = HardHelper.GenerateGrenade(),
|
|
||||||
Change = HardHelper.GenerateChange(),
|
|
||||||
Cover = HardHelper.GenerateCover(),
|
|
||||||
Patrol = HardHelper.GeneratePatrol(),
|
|
||||||
Hearing = HardHelper.GenerateHearing(),
|
|
||||||
Mind = HardHelper.GenerateMind(),
|
|
||||||
Boss = HardHelper.GenerateBoss(),
|
|
||||||
Core = HardHelper.GenerateCore(),
|
|
||||||
Scattering = HardHelper.GenerateScattering()
|
|
||||||
};
|
|
||||||
bot.difficulty.impossible = new Models.Output.Difficulty.DifficultySettings()
|
|
||||||
{
|
|
||||||
Lay = ImpossibleHelper.GenerateLay(),
|
|
||||||
Aiming = ImpossibleHelper.GenerateAiming(),
|
|
||||||
Look = ImpossibleHelper.GenerateLook(),
|
|
||||||
Shoot = ImpossibleHelper.GenerateShoot(),
|
|
||||||
Move = ImpossibleHelper.GenerateMove(),
|
|
||||||
Grenade = ImpossibleHelper.GenerateGrenade(),
|
|
||||||
Change = ImpossibleHelper.GenerateChange(),
|
|
||||||
Cover = ImpossibleHelper.GenerateCover(),
|
|
||||||
Patrol = ImpossibleHelper.GeneratePatrol(),
|
|
||||||
Hearing = ImpossibleHelper.GenerateHearing(),
|
|
||||||
Mind = ImpossibleHelper.GenerateMind(),
|
|
||||||
Boss = ImpossibleHelper.GenerateBoss(),
|
|
||||||
Core = ImpossibleHelper.GenerateCore(),
|
|
||||||
Scattering = ImpossibleHelper.GenerateScattering()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find each difficulty in dictionary and save into bot
|
||||||
|
foreach (var difficulty in _difficulties)
|
||||||
|
{
|
||||||
|
var settings = difficultySettingsJsons.FirstOrDefault(x => x.Key.Contains(difficulty));
|
||||||
|
|
||||||
|
SaveSettingsIntoBotFile(bot, difficulty, settings.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetFileDifficultyFromPath(string path)
|
||||||
|
{
|
||||||
|
// Split path into parts and find the last part (filename)
|
||||||
|
// Split filename and take the first part (difficulty, easy/normal etc)
|
||||||
|
var splitPath = path.Split("\\");
|
||||||
|
return splitPath.Last().Split("_").First();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SaveSettingsIntoBotFile(Bot bot, string difficulty, DifficultySettings settings)
|
||||||
|
{
|
||||||
|
switch (difficulty)
|
||||||
|
{
|
||||||
|
case "easy":
|
||||||
|
bot.difficulty.easy = settings;
|
||||||
|
break;
|
||||||
|
case "normal":
|
||||||
|
bot.difficulty.normal = settings;
|
||||||
|
break;
|
||||||
|
case "hard":
|
||||||
|
bot.difficulty.hard = settings;
|
||||||
|
break;
|
||||||
|
case "impossible":
|
||||||
|
bot.difficulty.impossible = settings;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user