SES-144 Add seed methods for monster seeding
This commit is contained in:
parent
100d8a6806
commit
151d63fc24
@ -35,9 +35,20 @@ namespace SessionCompanion.Database
|
|||||||
public virtual DbSet<CharacterWeapon> CharacterWeapons { get; set; }
|
public virtual DbSet<CharacterWeapon> CharacterWeapons { get; set; }
|
||||||
public virtual DbSet<OtherEquipment> OtherEquipment { get; set; }
|
public virtual DbSet<OtherEquipment> OtherEquipment { get; set; }
|
||||||
public virtual DbSet<CharacterOtherEquipment> CharacterOtherEquipment { get; set; }
|
public virtual DbSet<CharacterOtherEquipment> CharacterOtherEquipment { get; set; }
|
||||||
|
public virtual DbSet<Monster> Monsters { get; set; }
|
||||||
|
public virtual DbSet<MonsterAction> MonsterActions { get; set; }
|
||||||
|
public virtual DbSet<MonsterLegendaryAction> MonsterLegendaryActions { get; set; }
|
||||||
|
public virtual DbSet<MonsterSpecialAbility> MonsterSpecialAbilities { get; set; }
|
||||||
|
public virtual DbSet<GameAction> GameActions { get; set; }
|
||||||
|
public virtual DbSet<LegendaryAction> LegendaryActions { get; set; }
|
||||||
|
public virtual DbSet<SpecialAbility> SpecialAbilities { get; set; }
|
||||||
|
|
||||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
|
||||||
|
|
||||||
|
public List<SpecialAbility> SpecialAbilitiesList { get; set; }
|
||||||
|
public List<LegendaryAction> LegendaryActionsList { get; set; }
|
||||||
|
public List<GameAction> GameActionsList { get; set; }
|
||||||
|
|
||||||
protected IEnumerable<Weapon> SeedWeapon()
|
protected IEnumerable<Weapon> SeedWeapon()
|
||||||
{
|
{
|
||||||
const string file = "../SessionCompanion.Database/JsonData/weapons.json";
|
const string file = "../SessionCompanion.Database/JsonData/weapons.json";
|
||||||
@ -98,6 +109,178 @@ namespace SessionCompanion.Database
|
|||||||
}
|
}
|
||||||
return spells;
|
return spells;
|
||||||
}
|
}
|
||||||
|
protected IEnumerable<SpecialAbility> SeedSpecialAbilities()
|
||||||
|
{
|
||||||
|
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
|
||||||
|
List<SpecialAbility> specAbilities = new List<SpecialAbility>();
|
||||||
|
using (StreamReader reader = new StreamReader(file))
|
||||||
|
{
|
||||||
|
var json = reader.ReadToEnd();
|
||||||
|
dynamic jabilites = JArray.Parse(json);
|
||||||
|
int id = 1;
|
||||||
|
foreach (dynamic item in jabilites)
|
||||||
|
{
|
||||||
|
if (item.special_abilities != null)
|
||||||
|
{
|
||||||
|
foreach (dynamic sp in item.special_abilities)
|
||||||
|
{
|
||||||
|
if (specAbilities.Find(x => x.Name == (string)sp.name) is null)
|
||||||
|
{
|
||||||
|
specAbilities.Add(SeedFromJsons.SingleSpecialAbilitySeeder(sp, id));
|
||||||
|
id++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SpecialAbilitiesList = specAbilities;
|
||||||
|
return specAbilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IEnumerable<GameAction> SeedActions()
|
||||||
|
{
|
||||||
|
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
|
||||||
|
List<GameAction> gameActions = new List<GameAction>();
|
||||||
|
using (StreamReader reader = new StreamReader(file))
|
||||||
|
{
|
||||||
|
var json = reader.ReadToEnd();
|
||||||
|
dynamic jactions = JArray.Parse(json);
|
||||||
|
int id = 1;
|
||||||
|
foreach (dynamic item in jactions)
|
||||||
|
{
|
||||||
|
if (item.actions != null)
|
||||||
|
{
|
||||||
|
foreach (dynamic a in item.actions)
|
||||||
|
{
|
||||||
|
if (gameActions.Find(x => x.Name == (string)a.name) is null)
|
||||||
|
{
|
||||||
|
gameActions.Add(SeedFromJsons.SingleActionSeeder(a, id));
|
||||||
|
id++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GameActionsList = gameActions;
|
||||||
|
return gameActions;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IEnumerable<LegendaryAction> SeedLegendaryActions()
|
||||||
|
{
|
||||||
|
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
|
||||||
|
List<LegendaryAction> legendaryActions = new List<LegendaryAction>();
|
||||||
|
using (StreamReader reader = new StreamReader(file))
|
||||||
|
{
|
||||||
|
var json = reader.ReadToEnd();
|
||||||
|
dynamic jlegendaryactions = JArray.Parse(json);
|
||||||
|
int id = 1;
|
||||||
|
foreach (dynamic item in jlegendaryactions)
|
||||||
|
{
|
||||||
|
if (item.legendary_actions != null)
|
||||||
|
{
|
||||||
|
foreach (dynamic la in item.legendary_actions)
|
||||||
|
{
|
||||||
|
if (legendaryActions.Find(x => x.Name == (string)la.name) is null)
|
||||||
|
{
|
||||||
|
legendaryActions.Add(SeedFromJsons.SingleLegendaryActionSeeder(la, id));
|
||||||
|
id++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LegendaryActionsList = legendaryActions;
|
||||||
|
return legendaryActions;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IEnumerable<Monster> SeedMonster()
|
||||||
|
{
|
||||||
|
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
|
||||||
|
List<Monster> monsters = new List<Monster>();
|
||||||
|
using (StreamReader reader = new StreamReader(file))
|
||||||
|
{
|
||||||
|
var json = reader.ReadToEnd();
|
||||||
|
dynamic jmonsters = JArray.Parse(json);
|
||||||
|
foreach (dynamic item in jmonsters)
|
||||||
|
monsters.Add(SeedFromJsons.SingleMonsterSeeder(item));
|
||||||
|
}
|
||||||
|
return monsters;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IEnumerable<MonsterSpecialAbility> SeedMonsterSpecialAbilities()
|
||||||
|
{
|
||||||
|
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
|
||||||
|
List<MonsterSpecialAbility> monsterSpecialAbilities = new List<MonsterSpecialAbility>();
|
||||||
|
using (StreamReader reader = new StreamReader(file))
|
||||||
|
{
|
||||||
|
var json = reader.ReadToEnd();
|
||||||
|
dynamic jabilities = JArray.Parse(json);
|
||||||
|
int id = 1;
|
||||||
|
foreach (dynamic item in jabilities)
|
||||||
|
{
|
||||||
|
if (item.special_abilities != null)
|
||||||
|
{
|
||||||
|
foreach (dynamic a in item.special_abilities)
|
||||||
|
{
|
||||||
|
var abilityId = SpecialAbilitiesList.Find(x => x.Name == (string)a.name).Id;
|
||||||
|
monsterSpecialAbilities.Add(new MonsterSpecialAbility { Id = id, MonsterId = (int)item.index, SpecialAbilityId = abilityId });
|
||||||
|
id++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return monsterSpecialAbilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IEnumerable<MonsterAction> SeedMonsterActions()
|
||||||
|
{
|
||||||
|
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
|
||||||
|
List<MonsterAction> monsterActions = new List<MonsterAction>();
|
||||||
|
using (StreamReader reader = new StreamReader(file))
|
||||||
|
{
|
||||||
|
var json = reader.ReadToEnd();
|
||||||
|
dynamic jactions = JArray.Parse(json);
|
||||||
|
int id = 1;
|
||||||
|
foreach (dynamic item in jactions)
|
||||||
|
{
|
||||||
|
if (item.actions != null)
|
||||||
|
{
|
||||||
|
foreach (dynamic a in item.actions)
|
||||||
|
{
|
||||||
|
var abilityId = GameActionsList.Find(x => x.Name == (string)a.name).Id;
|
||||||
|
monsterActions.Add(new MonsterAction { Id = id, MonsterId = (int)item.index, GameActionId = abilityId });
|
||||||
|
id++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return monsterActions;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IEnumerable<MonsterLegendaryAction> SeedMonsterLegendaryActions()
|
||||||
|
{
|
||||||
|
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
|
||||||
|
List<MonsterLegendaryAction> monsterLegendaryActions = new List<MonsterLegendaryAction>();
|
||||||
|
using (StreamReader reader = new StreamReader(file))
|
||||||
|
{
|
||||||
|
var json = reader.ReadToEnd();
|
||||||
|
dynamic jactions = JArray.Parse(json);
|
||||||
|
int id = 1;
|
||||||
|
foreach (dynamic item in jactions)
|
||||||
|
{
|
||||||
|
if (item.legendary_actions != null)
|
||||||
|
{
|
||||||
|
foreach (dynamic a in item.legendary_actions)
|
||||||
|
{
|
||||||
|
var actionId = LegendaryActionsList.Find(x => x.Name == (string)a.name).Id;
|
||||||
|
monsterLegendaryActions.Add(new MonsterLegendaryAction { Id = id, MonsterId = (int)item.index, LegendaryActionId = actionId });
|
||||||
|
id++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return monsterLegendaryActions;
|
||||||
|
}
|
||||||
protected override void OnModelCreating(ModelBuilder builder)
|
protected override void OnModelCreating(ModelBuilder builder)
|
||||||
{
|
{
|
||||||
base.OnModelCreating(builder);
|
base.OnModelCreating(builder);
|
||||||
@ -124,6 +307,13 @@ namespace SessionCompanion.Database
|
|||||||
builder.Entity<Spell>().HasData(SeedSpell());
|
builder.Entity<Spell>().HasData(SeedSpell());
|
||||||
builder.Entity<CharacterSpell>().HasData(SeedData.SeedCharacterSpell());
|
builder.Entity<CharacterSpell>().HasData(SeedData.SeedCharacterSpell());
|
||||||
builder.Entity<CharacterSpellSlots>().HasData(SeedData.SeedCharacterSpellSlot());
|
builder.Entity<CharacterSpellSlots>().HasData(SeedData.SeedCharacterSpellSlot());
|
||||||
|
builder.Entity<Monster>().HasData(SeedMonster());
|
||||||
|
builder.Entity<SpecialAbility>().HasData(SeedSpecialAbilities());
|
||||||
|
builder.Entity<LegendaryAction>().HasData(SeedLegendaryActions());
|
||||||
|
builder.Entity<GameAction>().HasData(SeedActions());
|
||||||
|
builder.Entity<MonsterSpecialAbility>().HasData(SeedMonsterSpecialAbilities());
|
||||||
|
builder.Entity<MonsterAction>().HasData(SeedMonsterActions());
|
||||||
|
builder.Entity<MonsterLegendaryAction>().HasData(SeedMonsterLegendaryActions());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,5 +320,138 @@ namespace SessionCompanion.Database
|
|||||||
|
|
||||||
return spell;
|
return spell;
|
||||||
}
|
}
|
||||||
|
static public SpecialAbility SingleSpecialAbilitySeeder(dynamic item, int id)
|
||||||
|
{
|
||||||
|
SpecialAbility monsterSpecialAbility = new SpecialAbility();
|
||||||
|
|
||||||
|
monsterSpecialAbility.Id = id;
|
||||||
|
|
||||||
|
monsterSpecialAbility.Name = item.name;
|
||||||
|
|
||||||
|
if (item.damage_dice != null)
|
||||||
|
{
|
||||||
|
var dice = SplitDice((string)item.damage_dice);
|
||||||
|
monsterSpecialAbility.DamageDiceAmount = dice.Item1;
|
||||||
|
monsterSpecialAbility.DamageDice = dice.Item2;
|
||||||
|
}
|
||||||
|
|
||||||
|
monsterSpecialAbility.Description = item.desc;
|
||||||
|
|
||||||
|
return monsterSpecialAbility;
|
||||||
|
}
|
||||||
|
static public GameAction SingleActionSeeder(dynamic item, int id)
|
||||||
|
{
|
||||||
|
GameAction monsterAction = new GameAction();
|
||||||
|
|
||||||
|
monsterAction.Id = id;
|
||||||
|
|
||||||
|
monsterAction.Name = item.name;
|
||||||
|
|
||||||
|
monsterAction.AttackBonus = item.attack_bonus;
|
||||||
|
|
||||||
|
monsterAction.DamageBonus = item.damage_bonus;
|
||||||
|
if (item.damage_dice != null)
|
||||||
|
{
|
||||||
|
var dice = SplitDice((string)item.damage_dice);
|
||||||
|
monsterAction.DamageDiceAmount = dice.Item1;
|
||||||
|
monsterAction.DamageDice = dice.Item2;
|
||||||
|
}
|
||||||
|
monsterAction.Description = item.desc;
|
||||||
|
return monsterAction;
|
||||||
|
}
|
||||||
|
static public LegendaryAction SingleLegendaryActionSeeder(dynamic item, int id)
|
||||||
|
{
|
||||||
|
LegendaryAction monsterLegendaryAction = new LegendaryAction();
|
||||||
|
|
||||||
|
monsterLegendaryAction.Id = id;
|
||||||
|
|
||||||
|
monsterLegendaryAction.Name = item.name;
|
||||||
|
|
||||||
|
monsterLegendaryAction.Description = item.desc;
|
||||||
|
|
||||||
|
return monsterLegendaryAction;
|
||||||
|
}
|
||||||
|
static public Monster SingleMonsterSeeder(dynamic item)
|
||||||
|
{
|
||||||
|
Monster monster = new Monster();
|
||||||
|
|
||||||
|
monster.Id = item.index;
|
||||||
|
|
||||||
|
monster.Name = item.name;
|
||||||
|
|
||||||
|
monster.Size = item.size;
|
||||||
|
|
||||||
|
monster.Type = item.type;
|
||||||
|
|
||||||
|
monster.Subtype = item.subtype;
|
||||||
|
|
||||||
|
monster.Alignment = item.alignment;
|
||||||
|
|
||||||
|
monster.ArmorClass = item.armor_class;
|
||||||
|
|
||||||
|
monster.HitPoints = item.hit_points;
|
||||||
|
|
||||||
|
var dice = SplitDice((string)item.hit_dice);
|
||||||
|
monster.HitDiceAmount = dice.Item1;
|
||||||
|
monster.HitDiceType = dice.Item2;
|
||||||
|
|
||||||
|
monster.WalkSpeed = item.speed.walk;
|
||||||
|
monster.FlySpeed = item.speed.fly;
|
||||||
|
monster.SwimSpeed = item.speed.swim;
|
||||||
|
|
||||||
|
monster.Strength = item.strength;
|
||||||
|
monster.StrengthSave = item.strength_save;
|
||||||
|
|
||||||
|
monster.Dexterity = item.dexterity;
|
||||||
|
monster.DexteritySave = item.dexterity_save;
|
||||||
|
|
||||||
|
monster.Constitution = item.constitution;
|
||||||
|
monster.ConstitutionSave = item.constitution_save;
|
||||||
|
|
||||||
|
monster.Wisdom = item.wisdom;
|
||||||
|
monster.WisdomSave = item.wisdom_save;
|
||||||
|
|
||||||
|
monster.Charisma = item.charisma;
|
||||||
|
monster.CharismaSave = item.charsisma_save;
|
||||||
|
|
||||||
|
monster.Intelligence = item.intelligence;
|
||||||
|
monster.IntelligenceSave = item.intelligence_save;
|
||||||
|
|
||||||
|
foreach (dynamic dv in item.damage_vulnerabilities)
|
||||||
|
monster.MonsterDamageVulnerabilities += dv + ";";
|
||||||
|
if (monster.MonsterDamageVulnerabilities != null)
|
||||||
|
monster.MonsterDamageVulnerabilities = monster.MonsterDamageVulnerabilities.Remove(monster.MonsterDamageVulnerabilities.Length - 1);
|
||||||
|
|
||||||
|
foreach (dynamic dr in item.damage_resistances)
|
||||||
|
monster.MonsterDamageResistances += dr + ";";
|
||||||
|
if (monster.MonsterDamageResistances != null)
|
||||||
|
monster.MonsterDamageResistances = monster.MonsterDamageResistances.Remove(monster.MonsterDamageResistances.Length - 1);
|
||||||
|
|
||||||
|
foreach (dynamic di in item.damage_immunities)
|
||||||
|
monster.MonsterDamageImmunities += di + ";";
|
||||||
|
if (monster.MonsterDamageImmunities != null)
|
||||||
|
monster.MonsterDamageImmunities = monster.MonsterDamageImmunities.Remove(monster.MonsterDamageImmunities.Length - 1);
|
||||||
|
|
||||||
|
foreach (dynamic ci in item.condition_immunities)
|
||||||
|
monster.MonsterConditionImmunities += ci + ";";
|
||||||
|
if (monster.MonsterConditionImmunities != null)
|
||||||
|
monster.MonsterConditionImmunities = monster.MonsterConditionImmunities.Remove(monster.MonsterConditionImmunities.Length - 1);
|
||||||
|
|
||||||
|
monster.MonsterSenses = item.senses;
|
||||||
|
|
||||||
|
monster.MonsterLanguages = item.languages;
|
||||||
|
|
||||||
|
monster.ChallengeRating = item.challenge_rating;
|
||||||
|
|
||||||
|
return monster;
|
||||||
|
}
|
||||||
|
static public Tuple<int, int> SplitDice(string dice)
|
||||||
|
{
|
||||||
|
int stop = dice.IndexOf('d');
|
||||||
|
var amount = int.Parse(dice.Substring(0, stop));
|
||||||
|
stop++;
|
||||||
|
var value = int.Parse(dice.Substring(stop, dice.Length - stop));
|
||||||
|
return new Tuple<int, int>(amount, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user