From f52ce35b5f90b33baa1e61e44cb93033ed68e1eb Mon Sep 17 00:00:00 2001 From: Benjamin Popp Date: Fri, 1 Nov 2019 18:39:07 -0500 Subject: [PATCH] 'Find' works for TPT runs TPT runs contain pokemon, moves, and items. Now you can search for them. --- .../Models/Runs/TrainerPokemonTeamRun.cs | 30 +++++++++++++++++-- src/HexManiac.Core/ViewModels/ViewPort.cs | 6 ++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/HexManiac.Core/Models/Runs/TrainerPokemonTeamRun.cs b/src/HexManiac.Core/Models/Runs/TrainerPokemonTeamRun.cs index 21a415d6..f13a3e29 100644 --- a/src/HexManiac.Core/Models/Runs/TrainerPokemonTeamRun.cs +++ b/src/HexManiac.Core/Models/Runs/TrainerPokemonTeamRun.cs @@ -9,11 +9,16 @@ namespace HavenSoft.HexManiac.Core.Models.Runs { public const int TrainerFormat_StructTypeOffset = 0; public const int TrainerFormat_PokemonCountOffset = 32; public const int TrainerFormat_PointerOffset = 36; + public const byte INCLUDE_MOVES = 1; + public const byte INCLUDE_ITEM = 2; + + public const int PokemonFormat_FixedIVStart = 0; + public const int PokemonFormat_LevelStart = 2; + public const int PokemonFormat_PokemonStart = 4; + public const int PokemonFormat_MoveStart = 6; public static readonly string SharedFormatString = AsciiRun.StreamDelimeter + "tpt" + AsciiRun.StreamDelimeter; - private const byte INCLUDE_MOVES = 1; - private const byte INCLUDE_ITEM = 2; private readonly IDataModel model; public byte StructType { get; } @@ -49,6 +54,27 @@ namespace HavenSoft.HexManiac.Core.Models.Runs { ElementLength = ElementContent.Sum(segment => segment.Length); } + public IEnumerable Search(string parentArrayName, int id) { + for (int i = 0; i < ElementCount; i++) { + int start = Start + i * ElementLength; + if (parentArrayName == EggMoveRun.MoveNamesTable && (StructType & INCLUDE_MOVES) != 0) { + for (int j = 0; j < 4; j++) { + var index = start + PokemonFormat_MoveStart + j * 2; + var moveID = model.ReadMultiByteValue(index, 2); + if (moveID == id) yield return index; + } + } else if (parentArrayName == EggMoveRun.PokemonNameTable) { + var index = start + PokemonFormat_PokemonStart; + var pokemonID = model.ReadMultiByteValue(index, 2); + if (pokemonID == id) yield return index; + } else if (parentArrayName == HardcodeTablesModel.ItemsTableName && (StructType & INCLUDE_ITEM) != 0) { + var index = start + ElementLength - 2; + var itemID = model.ReadMultiByteValue(index, 2); + if (itemID == id) yield return index; + } + } + } + #region BaseRun public override int Length => ElementLength * ElementCount; diff --git a/src/HexManiac.Core/ViewModels/ViewPort.cs b/src/HexManiac.Core/ViewModels/ViewPort.cs index 77d02c3b..59f4f763 100644 --- a/src/HexManiac.Core/ViewModels/ViewPort.cs +++ b/src/HexManiac.Core/ViewModels/ViewPort.cs @@ -847,6 +847,12 @@ namespace HavenSoft.HexManiac.Core.ViewModels { } } } + // option 3: the value is a move used by trainer teams + if (child is TrainerPokemonTeamRun team) { + foreach (var result in team.Search(parentArrayName, offsets.ElementIndex)) { + yield return (result, result + 1); + } + } } }