VeekunImport project inserts form stats.

This commit is contained in:
Greg Edwards
2014-12-27 03:17:39 -05:00
parent a102d75b63
commit f50e76c15d
6 changed files with 200 additions and 3 deletions

View File

@@ -17,6 +17,8 @@ namespace VeekunImport
{
class Program
{
const int GENERATIONS = 6;
static void Main(string[] args)
{
String veekunFilename;
@@ -229,7 +231,46 @@ namespace VeekunImport
}
rdForms.Close();
// todo: pkmncf_pokedex_pokemon_form_stats_x
// pkmncf_pokedex_pokemon_form_stats
for (int generation = 1; generation <= GENERATIONS; generation++)
{
String filename = String.Format("form_stats{0}.txt", generation);
if (!File.Exists(filename))
{
Console.WriteLine("File {0} not found, skipped.", filename);
continue;
}
using (FileStream fs = File.Open(filename, FileMode.Open))
{
StreamReader sr = new StreamReader(fs, Encoding.UTF8);
String line;
while ((line = sr.ReadLine()) != null)
{
String[] fields = line.Split('\t');
if (fields.Length <= 1) continue;
if (fields.Length != 15) throw new Exception(filename + " has a line with unexpected number of tabs.");
int[] fieldsInt = fields.Select(s => Convert.ToInt32(s)).ToArray();
FormStats f = new FormStats(null, fieldsInt[0], (Generations)generation, fieldsInt[1], fieldsInt[2],
new StatValues(fieldsInt[3],
fieldsInt[4],
fieldsInt[5],
fieldsInt[6],
fieldsInt[7],
fieldsInt[8]),
new StatValues(fieldsInt[9],
fieldsInt[10],
fieldsInt[11],
fieldsInt[12],
fieldsInt[13],
fieldsInt[14])
);
db.PokedexInsertFormStats(f);
}
}
}
// todo: pkmncf_pokedex_pokemon_evolutions
// pkmncf_pokedex_types
@@ -322,7 +363,7 @@ namespace VeekunImport
// pkmncf_pokedex_items
Dictionary<int, ItemLoading> items = new Dictionary<int, ItemLoading>();
for (int generation = 3; generation < 6; generation++)
for (int generation = 3; generation <= GENERATIONS; generation++)
{
String filename = String.Format("items{0}.txt", generation);
if (!File.Exists(filename))
@@ -418,7 +459,7 @@ namespace VeekunImport
{
List<ItemLoading> toProcess = new List<ItemLoading>(4);
for (int generation = 3; generation < 7; generation++)
for (int generation = 3; generation <= GENERATIONS; generation++)
{
String col = String.Format("value{0}", generation);
if (!(rdItems[col] is DBNull))

View File

@@ -2581,6 +2581,41 @@ namespace PkmnFoundations.Data
}
}
public override void PokedexInsertFormStats(FormStats f)
{
using (MySqlConnection db = CreateConnection())
{
db.Open();
db.ExecuteNonQuery("INSERT INTO pkmncf_pokedex_pokemon_form_stats " +
"(form_id, MinGeneration, Type1, Type2, " +
"BaseHP, BaseAttack, BaseDefense, BaseSpeed, BaseSpAttack, BaseSpDefense, " +
"RewardHP, RewardAttack, RewardDefense, RewardSpeed, RewardSpAttack, RewardSpDefense) " +
"VALUES (@form_id, @min_generation, @type1, @type2, " +
"@base_hp, @base_attack, @base_defense, @base_speed, @base_sp_attack, @base_sp_defense, " +
"@reward_hp, @reward_attack, @reward_defense, @reward_speed, @reward_sp_attack, @reward_sp_defense)",
new MySqlParameter("@form_id", f.FormID),
new MySqlParameter("@min_generation", (int)f.MinGeneration),
new MySqlParameter("@type1", f.Type1),
new MySqlParameter("@type2", f.Type2),
new MySqlParameter("@base_hp", f.BaseStats.Hp),
new MySqlParameter("@base_attack", f.BaseStats.Attack),
new MySqlParameter("@base_defense", f.BaseStats.Defense),
new MySqlParameter("@base_speed", f.BaseStats.Speed),
new MySqlParameter("@base_sp_attack", f.BaseStats.SpecialAttack),
new MySqlParameter("@base_sp_defense", f.BaseStats.SpecialDefense),
new MySqlParameter("@reward_hp", (byte)f.RewardEvs.Hp),
new MySqlParameter("@reward_attack", (byte)f.RewardEvs.Attack),
new MySqlParameter("@reward_defense", (byte)f.RewardEvs.Defense),
new MySqlParameter("@reward_speed", (byte)f.RewardEvs.Speed),
new MySqlParameter("@reward_sp_attack", (byte)f.RewardEvs.SpecialAttack),
new MySqlParameter("@reward_sp_defense", (byte)f.RewardEvs.SpecialDefense)
);
db.Close();
}
}
public override void PokedexInsertFamily(Family f)
{
using (MySqlConnection db = CreateConnection())

View File

@@ -155,6 +155,7 @@ namespace PkmnFoundations.Data
#region Pokedex creation
public abstract void PokedexInsertSpecies(Species s);
public abstract void PokedexInsertForm(Form f);
public abstract void PokedexInsertFormStats(FormStats f);
public abstract void PokedexInsertFamily(Family f);
public abstract void PokedexInsertEvolution(Evolution f);

View File

@@ -54,6 +54,7 @@
<Compile Include="Data\DataSqlite.cs" />
<Compile Include="Pokedex\Ability.cs" />
<Compile Include="Pokedex\Evolution.cs" />
<Compile Include="Pokedex\FormStats.cs" />
<Compile Include="Pokedex\Item.cs" />
<Compile Include="Pokedex\Move.cs" />
<Compile Include="Pokedex\Pokedex.cs" />
@@ -79,6 +80,7 @@
<Compile Include="Structures\Enums.cs" />
<Compile Include="Structures\GtsRecord4.cs" />
<Compile Include="Structures\MusicalRecord5.cs" />
<Compile Include="Structures\StatValues.cs" />
<Compile Include="Structures\TrainerProfile4.cs" />
<Compile Include="Structures\TrainerProfile5.cs" />
<Compile Include="Support\AssertHelper.cs" />

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PkmnFoundations.Structures;
namespace PkmnFoundations.Pokedex
{
public class FormStats
{
public FormStats(Pokedex pokedex, int form_id, Generations min_generation, int type1, int type2, StatValues base_stats, StatValues reward_evs)
{
m_pokedex = pokedex;
FormID = form_id;
MinGeneration = min_generation;
Type1 = type1;
Type2 = type2;
BaseStats = base_stats;
RewardEvs = reward_evs;
}
private Pokedex m_pokedex;
public int FormID { get; private set; }
public Generations MinGeneration { get; private set; }
public int Type1 { get; private set; }
public int Type2 { get; private set; }
public StatValues BaseStats { get; private set; }
public StatValues RewardEvs { get; private set; }
}
}

View File

@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PkmnFoundations.Structures
{
public struct StatValues
{
public StatValues(int hp, int attack, int defense, int speed, int special_attack, int special_defense) : this()
{
Hp = hp;
Attack = attack;
Defense = defense;
Speed = speed;
SpecialAttack = special_attack;
SpecialDefense = special_defense;
}
public int Hp { get; set; }
public int Attack { get; set; }
public int Defense { get; set; }
public int Speed { get; set; }
public int SpecialAttack { get; set; }
public int SpecialDefense { get; set; }
public int this[Stats stat]
{
get
{
switch (stat)
{
case Stats.Hp:
return Hp;
case Stats.Attack:
return Attack;
case Stats.Defense:
return Defense;
case Stats.Speed:
return Speed;
case Stats.SpecialAttack:
return SpecialAttack;
case Stats.SpecialDefense:
return SpecialDefense;
default:
throw new ArgumentException();
}
}
set
{
switch (stat)
{
case Stats.Hp:
Hp = value;
break;
case Stats.Attack:
Attack = value;
break;
case Stats.Defense:
Defense = value;
break;
case Stats.Speed:
Speed = value;
break;
case Stats.SpecialAttack:
SpecialAttack = value;
break;
case Stats.SpecialDefense:
SpecialDefense = value;
break;
default:
throw new ArgumentException();
}
}
}
public int[] ToArray()
{
return new int[] { Hp, Attack, Defense, Speed, SpecialAttack, SpecialDefense };
}
public byte[] ToByteArray()
{
return new byte[] { (byte)Hp, (byte)Attack, (byte)Defense, (byte)Speed, (byte)SpecialAttack, (byte)SpecialDefense };
}
}
}