Add battle tree/royal formes

fix pkm text output function
This commit is contained in:
Kurt
2017-01-01 15:28:13 -08:00
parent 1c009b9e3e
commit 7e8f79af2e
6 changed files with 157 additions and 139 deletions

View File

@@ -35,35 +35,36 @@ public byte[] Write()
}
public class Pokemon
{
public ushort Species, Item;
public byte EVs, Nature;
public ushort[] Moves;
public bool HP, ATK, DEF, SPE, SPA, SPD;
public ushort Species;
public readonly ushort[] Moves = new ushort[4];
private readonly byte EV;
public readonly bool[] EVs = new bool[6];
public byte Nature;
public ushort Item;
public ushort Form;
private readonly byte _u1;
private readonly byte _u2;
public int Move1 { get { return Moves[0]; } set { Moves[0] = (ushort)value; } }
public int Move2 { get { return Moves[1]; } set { Moves[1] = (ushort)value; } }
public int Move3 { get { return Moves[2]; } set { Moves[2] = (ushort)value; } }
public int Move4 { get { return Moves[3]; } set { Moves[3] = (ushort)value; } }
public bool HP { get { return EVs[0]; } set { EVs[0] = value; } }
public bool ATK { get { return EVs[1]; } set { EVs[1] = value; } }
public bool DEF { get { return EVs[2]; } set { EVs[2] = value; } }
public bool SPE { get { return EVs[3]; } set { EVs[3] = value; } }
public bool SPA { get { return EVs[4]; } set { EVs[4] = value; } }
public bool SPD { get { return EVs[5]; } set { EVs[5] = value; } }
public Pokemon(byte[] data)
{
Species = BitConverter.ToUInt16(data, 0);
Moves = new[]
{
BitConverter.ToUInt16(data, 2),
BitConverter.ToUInt16(data, 4),
BitConverter.ToUInt16(data, 6),
BitConverter.ToUInt16(data, 8)
};
EVs = data[0xA];
HP = (EVs >> 0 & 1) == 1;
ATK = (EVs >> 1 & 1) == 1;
DEF = (EVs >> 2 & 1) == 1;
SPE = (EVs >> 3 & 1) == 1;
SPA = (EVs >> 4 & 1) == 1;
SPD = (EVs >> 5 & 1) == 1;
for (int i = 0; i < 4; i++)
Moves[i] = BitConverter.ToUInt16(data, 2 + 2*i);
EV = data[0xA];
for (int i = 0; i < 6; i++)
EVs[i] = ((EV >> i) & 1) == 1;
Nature = data[0xB];
Item = BitConverter.ToUInt16(data, 0xC);
_u1 = data[0xE];
_u2 = data[0xF];
Form = BitConverter.ToUInt16(data, 0xE);
}
public byte[] Write()
{
@@ -74,19 +75,14 @@ public byte[] Write()
foreach (ushort Move in Moves)
bw.Write(Move);
EVs &= 0xC0;
EVs |= (byte)(HP ? 1 << 0 : 0);
EVs |= (byte)(ATK ? 1 << 1 : 0);
EVs |= (byte)(DEF ? 1 << 1 : 0);
EVs |= (byte)(SPE ? 1 << 1 : 0);
EVs |= (byte)(SPA ? 1 << 1 : 0);
EVs |= (byte)(SPD ? 1 << 1 : 0);
bw.Write(EVs);
int ev = EV & 0xC0;
for (int i = 0; i < EVs.Length; i++)
ev |= EVs[i] ? 1 << i : 0;
bw.Write((byte)ev);
bw.Write(Nature);
bw.Write(Item);
bw.Write(_u1);
bw.Write(_u2);
bw.Write(Form);
return ms.ToArray();
}
}

View File

@@ -35,35 +35,36 @@ public byte[] Write()
}
public class Pokemon
{
public ushort Species, Item;
public byte EVs, Nature;
public ushort[] Moves;
public bool HP, ATK, DEF, SPE, SPA, SPD;
public ushort Species;
public readonly ushort[] Moves = new ushort[4];
private readonly byte EV;
public readonly bool[] EVs = new bool[6];
public byte Nature;
public ushort Item;
public ushort Form;
private readonly byte _u1;
private readonly byte _u2;
public int Move1 { get { return Moves[0]; } set { Moves[0] = (ushort)value; } }
public int Move2 { get { return Moves[1]; } set { Moves[1] = (ushort)value; } }
public int Move3 { get { return Moves[2]; } set { Moves[2] = (ushort)value; } }
public int Move4 { get { return Moves[3]; } set { Moves[3] = (ushort)value; } }
public bool HP { get { return EVs[0]; } set { EVs[0] = value; } }
public bool ATK { get { return EVs[1]; } set { EVs[1] = value; } }
public bool DEF { get { return EVs[2]; } set { EVs[2] = value; } }
public bool SPE { get { return EVs[3]; } set { EVs[3] = value; } }
public bool SPA { get { return EVs[4]; } set { EVs[4] = value; } }
public bool SPD { get { return EVs[5]; } set { EVs[5] = value; } }
public Pokemon(byte[] data)
{
Species = BitConverter.ToUInt16(data, 0);
Moves = new[]
{
BitConverter.ToUInt16(data, 2),
BitConverter.ToUInt16(data, 4),
BitConverter.ToUInt16(data, 6),
BitConverter.ToUInt16(data, 8)
};
EVs = data[0xA];
HP = (EVs >> 0 & 1) == 1;
ATK = (EVs >> 1 & 1) == 1;
DEF = (EVs >> 2 & 1) == 1;
SPE = (EVs >> 3 & 1) == 1;
SPA = (EVs >> 4 & 1) == 1;
SPD = (EVs >> 5 & 1) == 1;
for (int i = 0; i < 4; i++)
Moves[i] = BitConverter.ToUInt16(data, 2 + 2 * i);
EV = data[0xA];
for (int i = 0; i < 6; i++)
EVs[i] = ((EV >> i) & 1) == 1;
Nature = data[0xB];
Item = BitConverter.ToUInt16(data, 0xC);
_u1 = data[0xE];
_u2 = data[0xF];
Form = BitConverter.ToUInt16(data, 0xE);
}
public byte[] Write()
{
@@ -74,19 +75,14 @@ public byte[] Write()
foreach (ushort Move in Moves)
bw.Write(Move);
EVs &= 0xC0;
EVs |= (byte)(HP ? 1 << 0 : 0);
EVs |= (byte)(ATK ? 1 << 1 : 0);
EVs |= (byte)(DEF ? 1 << 1 : 0);
EVs |= (byte)(SPE ? 1 << 1 : 0);
EVs |= (byte)(SPA ? 1 << 1 : 0);
EVs |= (byte)(SPD ? 1 << 1 : 0);
bw.Write(EVs);
int ev = EV & 0xC0;
for (int i = 0; i < EVs.Length; i++)
ev |= EVs[i] ? 1 << i : 0;
bw.Write((byte)ev);
bw.Write(Nature);
bw.Write(Item);
bw.Write(_u1);
bw.Write(_u2);
bw.Write(Form);
return ms.ToArray();
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;
using System.Windows.Forms;
@@ -219,43 +220,35 @@ private void DumpTRs_Click(object sender, EventArgs e)
}
private void B_DumpPKs_Click(object sender, EventArgs e)
{
dumping = true;
string[] stats = {"HP", "ATK", "DEF", "Spe", "SpA", "SpD"};
string result = "";
for (int i = 0; i < CB_Pokemon.Items.Count; i++)
for (int i = 0; i < pkFiles.Length; i++)
{
CB_Pokemon.SelectedIndex = i;
if (CB_Species.SelectedIndex > 0)
{
result += "======" + Environment.NewLine + i + " - " + CB_Species.Text + Environment.NewLine + "======" + Environment.NewLine;
result += string.Format("Held Item: {0}" + Environment.NewLine, CB_Item.Text);
result += string.Format("Nature: {0}" + Environment.NewLine, CB_Nature.Text);
result += string.Format("Move 1: {0}" + Environment.NewLine, CB_Move1.Text);
result += string.Format("Move 2: {0}" + Environment.NewLine, CB_Move2.Text);
result += string.Format("Move 3: {0}" + Environment.NewLine, CB_Move3.Text);
result += string.Format("Move 4: {0}" + Environment.NewLine, CB_Move4.Text);
var pk = new Maison6.Pokemon(pkFiles[i]);
if (pk.Species == 0)
continue;
result += "EV'd in: ";
result += CHK_HP.Checked ? "HP, " : "";
result += CHK_ATK.Checked ? "ATK, " : "";
result += CHK_DEF.Checked ? "DEF, " : "";
result += CHK_SpA.Checked ? "SpA, " : "";
result += CHK_SpD.Checked ? "SpD, " : "";
result += CHK_Spe.Checked ? "Spe, " : "";
result += Environment.NewLine;
result += "======" + Environment.NewLine;
result += $"{i} - {specieslist[pk.Species]}" + Environment.NewLine;
result += "======" + Environment.NewLine;
result += $"Held Item: {itemlist[pk.Item]}" + Environment.NewLine;
result += $"Nature: {natures[pk.Nature]}" + Environment.NewLine;
result += $"Move 1: {movelist[pk.Move1]}" + Environment.NewLine;
result += $"Move 2: {movelist[pk.Move2]}" + Environment.NewLine;
result += $"Move 3: {movelist[pk.Move3]}" + Environment.NewLine;
result += $"Move 4: {movelist[pk.Move4]}" + Environment.NewLine;
result += Environment.NewLine;
}
var EVstr = string.Join(",", pk.EVs.Select((iv, x) => iv ? stats[x] : string.Empty).Where(x => !string.IsNullOrWhiteSpace(x)));
result += $"EV'd in: {(pk.EVs.Any() ? EVstr : "None")}" + Environment.NewLine;
result += Environment.NewLine;
}
SaveFileDialog sfd = new SaveFileDialog {FileName = "Maison Pokemon.txt", Filter = "Text File|*.txt"};
SystemSounds.Asterisk.Play();
if (sfd.ShowDialog() == DialogResult.OK)
{
string path = sfd.FileName;
File.WriteAllText(path, result, Encoding.Unicode);
}
dumping = false;
CB_Trainer.SelectedIndex = 0;
if (sfd.ShowDialog() != DialogResult.OK)
return;
File.WriteAllText(sfd.FileName, result, Encoding.Unicode);
}
}
}

View File

@@ -59,9 +59,12 @@ private void InitializeComponent()
this.CB_Species = new System.Windows.Forms.ComboBox();
this.B_DumpPKs = new System.Windows.Forms.Button();
this.DumpTRs = new System.Windows.Forms.Button();
this.NUD_Form = new System.Windows.Forms.NumericUpDown();
this.L_Form = new System.Windows.Forms.Label();
this.GB_Trainer.SuspendLayout();
this.GB_Pokemon.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.PB_PKM)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.NUD_Form)).BeginInit();
this.SuspendLayout();
//
// CB_Trainer
@@ -170,6 +173,8 @@ private void InitializeComponent()
//
// GB_Pokemon
//
this.GB_Pokemon.Controls.Add(this.L_Form);
this.GB_Pokemon.Controls.Add(this.NUD_Form);
this.GB_Pokemon.Controls.Add(this.PB_PKM);
this.GB_Pokemon.Controls.Add(this.CHK_Spe);
this.GB_Pokemon.Controls.Add(this.CHK_SpD);
@@ -275,7 +280,7 @@ private void InitializeComponent()
// L_Item
//
this.L_Item.AutoSize = true;
this.L_Item.Location = new System.Drawing.Point(29, 159);
this.L_Item.Location = new System.Drawing.Point(29, 141);
this.L_Item.Name = "L_Item";
this.L_Item.Size = new System.Drawing.Size(30, 13);
this.L_Item.TabIndex = 17;
@@ -284,7 +289,7 @@ private void InitializeComponent()
// L_Nature
//
this.L_Nature.AutoSize = true;
this.L_Nature.Location = new System.Drawing.Point(17, 132);
this.L_Nature.Location = new System.Drawing.Point(17, 119);
this.L_Nature.Name = "L_Nature";
this.L_Nature.Size = new System.Drawing.Size(42, 13);
this.L_Nature.TabIndex = 16;
@@ -304,7 +309,7 @@ private void InitializeComponent()
this.CB_Item.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
this.CB_Item.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CB_Item.FormattingEnabled = true;
this.CB_Item.Location = new System.Drawing.Point(65, 156);
this.CB_Item.Location = new System.Drawing.Point(65, 138);
this.CB_Item.Name = "CB_Item";
this.CB_Item.Size = new System.Drawing.Size(101, 21);
this.CB_Item.TabIndex = 14;
@@ -314,7 +319,7 @@ private void InitializeComponent()
this.CB_Nature.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
this.CB_Nature.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CB_Nature.FormattingEnabled = true;
this.CB_Nature.Location = new System.Drawing.Point(65, 129);
this.CB_Nature.Location = new System.Drawing.Point(65, 116);
this.CB_Nature.Name = "CB_Nature";
this.CB_Nature.Size = new System.Drawing.Size(101, 21);
this.CB_Nature.TabIndex = 13;
@@ -390,11 +395,38 @@ private void InitializeComponent()
this.DumpTRs.UseVisualStyleBackColor = true;
this.DumpTRs.Click += new System.EventHandler(this.DumpTRs_Click);
//
// Maison
// NUD_Form
//
this.NUD_Form.Location = new System.Drawing.Point(107, 161);
this.NUD_Form.Maximum = new decimal(new int[] {
65535,
0,
0,
0});
this.NUD_Form.Name = "NUD_Form";
this.NUD_Form.Size = new System.Drawing.Size(59, 20);
this.NUD_Form.TabIndex = 26;
this.NUD_Form.Value = new decimal(new int[] {
65535,
0,
0,
0});
this.NUD_Form.ValueChanged += new System.EventHandler(this.changeSpecies);
//
// L_Form
//
this.L_Form.AutoSize = true;
this.L_Form.Location = new System.Drawing.Point(71, 163);
this.L_Form.Name = "L_Form";
this.L_Form.Size = new System.Drawing.Size(33, 13);
this.L_Form.TabIndex = 27;
this.L_Form.Text = "Form:";
//
// MaisonEditor7
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(579, 227);
this.ClientSize = new System.Drawing.Size(579, 226);
this.Controls.Add(this.DumpTRs);
this.Controls.Add(this.B_DumpPKs);
this.Controls.Add(this.GB_Pokemon);
@@ -406,7 +438,7 @@ private void InitializeComponent()
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(595, 265);
this.MinimumSize = new System.Drawing.Size(595, 265);
this.Name = "Maison";
this.Name = "MaisonEditor7";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Maison Editor";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.formClosing);
@@ -415,6 +447,7 @@ private void InitializeComponent()
this.GB_Pokemon.ResumeLayout(false);
this.GB_Pokemon.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.PB_PKM)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.NUD_Form)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -453,5 +486,7 @@ private void InitializeComponent()
private System.Windows.Forms.Button B_Set;
private System.Windows.Forms.ListBox LB_Choices;
private System.Windows.Forms.ComboBox CB_Class;
private System.Windows.Forms.Label L_Form;
private System.Windows.Forms.NumericUpDown NUD_Form;
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;
using System.Windows.Forms;
@@ -109,6 +110,7 @@ private void getPokemon()
CHK_SpD.Checked = pkm.SPD;
CB_Nature.SelectedIndex = pkm.Nature;
CB_Item.SelectedIndex = pkm.Item;
NUD_Form.Value = pkm.Form;
CB_Species.SelectedIndex = pkm.Species; // Loaded last in order to refresh the sprite with all info.
// Last 2 Bytes are unused.
@@ -129,13 +131,11 @@ private void setPokemon()
SPD = CHK_SpD.Checked,
Nature = (byte) CB_Nature.SelectedIndex,
Item = (ushort) CB_Item.SelectedIndex,
Moves =
{
[0] = (ushort) CB_Move1.SelectedIndex,
[1] = (ushort) CB_Move2.SelectedIndex,
[2] = (ushort) CB_Move3.SelectedIndex,
[3] = (ushort) CB_Move4.SelectedIndex
}
Move1 = CB_Move1.SelectedIndex,
Move2 = CB_Move2.SelectedIndex,
Move3 = CB_Move3.SelectedIndex,
Move4 = CB_Move4.SelectedIndex,
Form = (ushort)NUD_Form.Value,
};
byte[] data = pkm.Write();
@@ -144,7 +144,7 @@ private void setPokemon()
private void changeSpecies(object sender, EventArgs e)
{
PB_PKM.Image = Util.getSprite(CB_Species.SelectedIndex, 0, 0, CB_Item.SelectedIndex);
PB_PKM.Image = Util.getSprite(CB_Species.SelectedIndex, (int)NUD_Form.Value, 0, CB_Item.SelectedIndex);
}
private void B_Remove_Click(object sender, EventArgs e)
@@ -219,43 +219,39 @@ private void DumpTRs_Click(object sender, EventArgs e)
}
private void B_DumpPKs_Click(object sender, EventArgs e)
{
dumping = true;
//File.WriteAllBytes("maiz", pkFiles.SelectMany(t => t).ToArray());
string[] stats = {"HP", "ATK", "DEF", "Spe", "SpA", "SpD"};
string result = "";
for (int i = 0; i < CB_Pokemon.Items.Count; i++)
for (int i = 0; i < pkFiles.Length; i++)
{
CB_Pokemon.SelectedIndex = i;
if (CB_Species.SelectedIndex > 0)
{
result += "======" + Environment.NewLine + i + " - " + CB_Species.Text + Environment.NewLine + "======" + Environment.NewLine;
result += string.Format("Held Item: {0}" + Environment.NewLine, CB_Item.Text);
result += string.Format("Nature: {0}" + Environment.NewLine, CB_Nature.Text);
result += string.Format("Move 1: {0}" + Environment.NewLine, CB_Move1.Text);
result += string.Format("Move 2: {0}" + Environment.NewLine, CB_Move2.Text);
result += string.Format("Move 3: {0}" + Environment.NewLine, CB_Move3.Text);
result += string.Format("Move 4: {0}" + Environment.NewLine, CB_Move4.Text);
var pk = new Maison7.Pokemon(pkFiles[i]);
if (pk.Species == 0)
continue;
result += "EV'd in: ";
result += CHK_HP.Checked ? "HP, " : "";
result += CHK_ATK.Checked ? "ATK, " : "";
result += CHK_DEF.Checked ? "DEF, " : "";
result += CHK_SpA.Checked ? "SpA, " : "";
result += CHK_SpD.Checked ? "SpD, " : "";
result += CHK_Spe.Checked ? "Spe, " : "";
result += Environment.NewLine;
result += "======" + Environment.NewLine;
result += $"{i} - {specieslist[pk.Species]}" + Environment.NewLine;
result += "======" + Environment.NewLine;
result += $"Held Item: {itemlist[pk.Item]}" + Environment.NewLine;
result += $"Nature: {natures[pk.Nature]}" + Environment.NewLine;
result += $"Move 1: {movelist[pk.Move1]}" + Environment.NewLine;
result += $"Move 2: {movelist[pk.Move2]}" + Environment.NewLine;
result += $"Move 3: {movelist[pk.Move3]}" + Environment.NewLine;
result += $"Move 4: {movelist[pk.Move4]}" + Environment.NewLine;
result += Environment.NewLine;
}
var EVstr = string.Join(",", pk.EVs.Select((iv, x) => iv ? stats[x] : string.Empty).Where(x => !string.IsNullOrWhiteSpace(x)));
result += $"EV'd in: {(pk.EVs.Any() ? EVstr : "None")}" + Environment.NewLine;
if (pk.Form > 0)
result += $"Form: {pk.Form}" + Environment.NewLine;
result += Environment.NewLine;
}
SaveFileDialog sfd = new SaveFileDialog {FileName = "Maison Pokemon.txt", Filter = "Text File|*.txt"};
SystemSounds.Asterisk.Play();
if (sfd.ShowDialog() == DialogResult.OK)
{
string path = sfd.FileName;
File.WriteAllText(path, result, Encoding.Unicode);
}
dumping = false;
CB_Trainer.SelectedIndex = 0;
if (sfd.ShowDialog() != DialogResult.OK)
return;
File.WriteAllText(sfd.FileName, result, Encoding.Unicode);
}
}
}

View File

@@ -14,6 +14,8 @@ class Util
{ // Image Layering/Blending Utility
internal static Bitmap LayerImage(Image baseLayer, Image overLayer, int x, int y, double trans)
{
if (baseLayer == null)
return overLayer as Bitmap;
Bitmap img = new Bitmap(baseLayer.Width, baseLayer.Height);
using (Graphics gr = Graphics.FromImage(img))
{