mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
26b1453002
Fix RibbonVerifier4 not checking gen4 contest ribbons correctly Split IRibbonCommon6 to have memory ribbons separate, as they are not implemented in mystery gifts. Also, we can add the boolean flags to the interface, and check that the boolean is set if count is nonzero. Fix adding ribbons to Gen8 gift templates Improve Gen8 template ribbon fetch (no closure, faster IndexOf)
73 lines
1.8 KiB
C#
73 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Provides ribbon information about the state of a given ribbon.
|
|
/// </summary>
|
|
public sealed class RibbonInfo
|
|
{
|
|
public const string PropertyPrefix = "Ribbon";
|
|
|
|
public readonly string Name;
|
|
public readonly RibbonValueType Type;
|
|
|
|
public bool HasRibbon { get; set; }
|
|
public byte RibbonCount { get; set; }
|
|
|
|
private RibbonInfo(string name, bool hasRibbon)
|
|
{
|
|
Name = name;
|
|
HasRibbon = hasRibbon;
|
|
Type = RibbonValueType.Boolean;
|
|
}
|
|
|
|
private RibbonInfo(string name, byte count)
|
|
{
|
|
Name = name;
|
|
Type = RibbonValueType.Byte;
|
|
RibbonCount = count;
|
|
}
|
|
|
|
public int MaxCount
|
|
{
|
|
get
|
|
{
|
|
if (Type is RibbonValueType.Boolean)
|
|
throw new ArgumentOutOfRangeException(nameof(Type));
|
|
|
|
return Name switch
|
|
{
|
|
nameof(IRibbonSetMemory6.RibbonCountMemoryContest) => 40,
|
|
nameof(IRibbonSetMemory6.RibbonCountMemoryBattle) => 8,
|
|
_ => 4, // Gen3/4 Contest Ribbons
|
|
};
|
|
}
|
|
}
|
|
|
|
public static List<RibbonInfo> GetRibbonInfo(PKM pk)
|
|
{
|
|
// Get a list of all Ribbon Attributes in the PKM
|
|
var riblist = new List<RibbonInfo>();
|
|
var names = ReflectUtil.GetPropertiesStartWithPrefix(pk.GetType(), PropertyPrefix);
|
|
foreach (var name in names)
|
|
{
|
|
object? RibbonValue = ReflectUtil.GetValue(pk, name);
|
|
if (RibbonValue is bool b)
|
|
riblist.Add(new RibbonInfo(name, b));
|
|
else if (RibbonValue is byte x)
|
|
riblist.Add(new RibbonInfo(name, x));
|
|
}
|
|
return riblist;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Type of Ribbon Value
|
|
/// </summary>
|
|
public enum RibbonValueType
|
|
{
|
|
Boolean,
|
|
Byte,
|
|
}
|