session-companion/SessionCompanion/SessionCompanion.Database/SeedFromJsons.cs

125 lines
3.6 KiB
C#
Raw Normal View History

using SessionCompanion.Database.Tables;
using SessionCompanion.ViewModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SessionCompanion.Database
{
public static class SeedFromJsons
{
static public Weapon SingleWeaponSeeder(dynamic item)
{
Weapon weapon = new Weapon();
// Id
weapon.Id = item.index;
// Name
weapon.Name = item.name;
// Weapon type
weapon.WeaponType = item.category_range;
// Cost
weapon.Cost = item.cost.quantity;
// CurrnecyType
switch ((string)item.cost.unit)
{
case "sp":
weapon.CurrencyType = CurrencyType.sp;
break;
case "gp":
weapon.CurrencyType = CurrencyType.gp;
break;
}
// DiceCount
weapon.DiceCount = item.damage.dice_count;
// DiceValue
weapon.DiceValue = item.damage.dice_value;
// RangeMeele
weapon.RangeMeele = item.range.normal;
// RangeLong
weapon.RangeLong = item.range._long;
// RangeThrow
if (item.throw_range != null)
{
weapon.RangeThrowNormal = item.throw_range.normal;
weapon.RangeThrowLong = item.throw_range._long;
}
// Weight
weapon.Weight = item.weight;
// Twohand
if (item.two_hand_damage != null)
{
weapon.TwoHandDiceCount = item.two_hand_damage.dice_count;
weapon.TwoHandDiceValue = item.two_hand_damage.dice_value;
}
if (item.special != null)
weapon.Description = item.special[0];
return weapon;
}
static public Armor SingleArmorSeeder(dynamic item, int id)
{
Armor armor = new Armor();
armor.Id = id;
armor.Name = item.name;
armor.Category = item.armor_category;
armor.ArmorClassBase = item.armor_class["base"];
armor.HaveDexterityBonus = item.armor_class["dex_bonus"];
armor.MinimumStrength = item.str_minimum;
armor.HaveStealthDisadvantage = item.stealth_disadvantage;
armor.Weight = item.weight;
armor.Cost = item.cost.quantity;
switch ((string)item.cost.unit)
{
case "sp":
armor.CurrencyType = CurrencyType.sp;
break;
case "gp":
armor.CurrencyType = CurrencyType.gp;
break;
}
return armor;
}
static public OtherEquipment SingleOtherEquipmentSeeder(dynamic item, int id)
{
OtherEquipment otherEq = new OtherEquipment();
otherEq.Id = id;
otherEq.Name = item.name;
if (item.desc != null)
foreach (dynamic description in item.desc)
otherEq.Description += " " + description;
else
otherEq.Description = string.Empty;
otherEq.Cost = item.cost.quantity;
switch ((string)item.cost.unit)
{
case "sp":
otherEq.CurrencyType = CurrencyType.sp;
break;
case "gp":
otherEq.CurrencyType = CurrencyType.gp;
break;
}
return otherEq;
}
}
}