mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 20:43:07 +00:00
Update rare flag logic
Closes #2601 Add ComponentModel attributes for properties, add u64 typeconverter for propertygrid
This commit is contained in:
parent
6c7065fb7b
commit
9ee2b08ce5
2 changed files with 50 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
|
@ -51,50 +52,62 @@ namespace PKHeX.Core
|
|||
Offset = ofs;
|
||||
}
|
||||
|
||||
private const string General = nameof(General);
|
||||
private const string Derived = nameof(Derived);
|
||||
|
||||
[Category(General), Description("FNV Hash for fetching the Raid data table (64bit)."), TypeConverter(typeof(TypeConverterU64))]
|
||||
public ulong Hash
|
||||
{
|
||||
get => BitConverter.ToUInt64(Data, Offset + 0);
|
||||
set => BitConverter.GetBytes(value).CopyTo(Data, Offset + 0);
|
||||
}
|
||||
|
||||
[Category(General), Description("RNG Seed for generating the Raid's content (64bit)."), TypeConverter(typeof(TypeConverterU64))]
|
||||
public ulong Seed
|
||||
{
|
||||
get => BitConverter.ToUInt64(Data, Offset + 8);
|
||||
set => BitConverter.GetBytes(value).CopyTo(Data, Offset + 8);
|
||||
}
|
||||
|
||||
[Category(General), Description("Star Count for the Raid's content (0-4).")]
|
||||
public byte Stars
|
||||
{
|
||||
get => Data[Offset + 0x10];
|
||||
set => Data[Offset + 0x10] = value;
|
||||
}
|
||||
|
||||
[Category(General), Description("Random value which picks out the encounter from the Raid data table (0-99).")]
|
||||
public byte RandRoll
|
||||
{
|
||||
get => Data[Offset + 0x11];
|
||||
set => Data[Offset + 0x11] = value;
|
||||
}
|
||||
|
||||
[Category(General), Description("First set of Den Flags.")]
|
||||
public byte DenType
|
||||
{
|
||||
get => Data[Offset + 0x12];
|
||||
set => Data[Offset + 0x12] = value;
|
||||
}
|
||||
|
||||
[Category(General), Description("Second set of Den Flags.")]
|
||||
public byte Flags
|
||||
{
|
||||
get => Data[Offset + 0x13];
|
||||
set => Data[Offset + 0x13] = value;
|
||||
}
|
||||
|
||||
[Category(Derived), Description("Active Nest")]
|
||||
public bool IsActive => DenType > 0;
|
||||
|
||||
[Category(Derived), Description("Rare encounter details used instead of Common details.")]
|
||||
public bool IsRare
|
||||
{
|
||||
get => IsActive && (DenType & 1) != 0;
|
||||
set => DenType = 2;
|
||||
get => IsActive && (DenType & 1) == 0;
|
||||
set => DenType = 2; // set the 1th bit; the 2th bit has a similar-unknown function (?)
|
||||
}
|
||||
|
||||
[Category(Derived), Description("Distribution (event) details used for Raid encounter.")]
|
||||
public bool IsEvent
|
||||
{
|
||||
get => IsActive && ((Flags >> 1) & 1) == 1;
|
||||
|
@ -113,4 +126,33 @@ namespace PKHeX.Core
|
|||
|
||||
// The games use a xoroshiro RNG to create the PKM from the stored seed.
|
||||
}
|
||||
|
||||
public class TypeConverterU64 : TypeConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
|
||||
{
|
||||
return destinationType == typeof(string) || base.CanConvertTo(context, destinationType);
|
||||
}
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string) && value is ulong)
|
||||
return $"{value:X16}"; // no 0x prefix
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
|
||||
{
|
||||
if (!(value is string input))
|
||||
return base.ConvertFrom(context, culture, value);
|
||||
if (input.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
|
||||
input = input.Substring(2);
|
||||
return ulong.TryParse(input, System.Globalization.NumberStyles.HexNumber, culture, out var result) ? result : 0ul;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -82,7 +82,7 @@
|
|||
// B_Cancel
|
||||
//
|
||||
this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.B_Cancel.Location = new System.Drawing.Point(145, 244);
|
||||
this.B_Cancel.Location = new System.Drawing.Point(146, 289);
|
||||
this.B_Cancel.Name = "B_Cancel";
|
||||
this.B_Cancel.Size = new System.Drawing.Size(75, 23);
|
||||
this.B_Cancel.TabIndex = 0;
|
||||
|
@ -93,7 +93,7 @@
|
|||
// B_Save
|
||||
//
|
||||
this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.B_Save.Location = new System.Drawing.Point(226, 244);
|
||||
this.B_Save.Location = new System.Drawing.Point(227, 289);
|
||||
this.B_Save.Name = "B_Save";
|
||||
this.B_Save.Size = new System.Drawing.Size(75, 23);
|
||||
this.B_Save.TabIndex = 1;
|
||||
|
@ -414,10 +414,10 @@
|
|||
this.PG_Den.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.PG_Den.HelpVisible = false;
|
||||
this.PG_Den.Location = new System.Drawing.Point(12, 32);
|
||||
this.PG_Den.Name = "PG_Den";
|
||||
this.PG_Den.Size = new System.Drawing.Size(289, 206);
|
||||
this.PG_Den.PropertySort = System.Windows.Forms.PropertySort.NoSort;
|
||||
this.PG_Den.Size = new System.Drawing.Size(290, 251);
|
||||
this.PG_Den.TabIndex = 2;
|
||||
this.PG_Den.ToolbarVisible = false;
|
||||
//
|
||||
|
@ -434,7 +434,7 @@
|
|||
// B_ActivateAll
|
||||
//
|
||||
this.B_ActivateAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.B_ActivateAll.Location = new System.Drawing.Point(12, 244);
|
||||
this.B_ActivateAll.Location = new System.Drawing.Point(13, 289);
|
||||
this.B_ActivateAll.Name = "B_ActivateAll";
|
||||
this.B_ActivateAll.Size = new System.Drawing.Size(103, 23);
|
||||
this.B_ActivateAll.TabIndex = 4;
|
||||
|
@ -446,7 +446,7 @@
|
|||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(313, 276);
|
||||
this.ClientSize = new System.Drawing.Size(314, 321);
|
||||
this.Controls.Add(this.B_ActivateAll);
|
||||
this.Controls.Add(this.CB_Den);
|
||||
this.Controls.Add(this.PG_Den);
|
||||
|
|
Loading…
Reference in a new issue