mirror of
https://github.com/kwsch/pkNX.git
synced 2026-10-01 05:37:29 -05:00
Add force fully evolved implementation
use current evo data instead of hardcoded max-evolved table for each game
This commit is contained in:
@@ -22,15 +22,16 @@ public class TrainerRandomizer : Randomizer
|
||||
public MoveRandomizer RandMove { get; set; }
|
||||
public int ClassCount { get; set; }
|
||||
public Func<TrainerPoke> GetBlank { get; set; }
|
||||
public IList<int> FinalEvo { get; set; } = Array.Empty<int>();
|
||||
public EvolutionSet[] Evos { get; set; }
|
||||
|
||||
private TrainerRandSettings Settings;
|
||||
|
||||
public TrainerRandomizer(GameInfo info, PersonalTable t, VsTrainer[] trainers)
|
||||
public TrainerRandomizer(GameInfo info, PersonalTable t, VsTrainer[] trainers, EvolutionSet[] evos)
|
||||
{
|
||||
Trainers = trainers;
|
||||
Info = info;
|
||||
Personal = t;
|
||||
Evos = evos;
|
||||
|
||||
PossibleHeldItems = Legal.GetRandomItemList(Info.Game);
|
||||
MegaDictionary = Legal.GetMegaDictionary(Info.Game);
|
||||
@@ -127,14 +128,6 @@ private void DetermineSpecies(IPokeData pk)
|
||||
pk.Gender = 0; // random
|
||||
pk.Nature = Util.Random.Next(25); // random
|
||||
}
|
||||
|
||||
if (Settings.ForceFullyEvolved && pk.Level >= Settings.ForceFullyEvolvedAtLevel && !FinalEvo.Contains(pk.Species))
|
||||
{
|
||||
int randFinalEvo() => Util.Random.Next(FinalEvo.Count);
|
||||
if (FinalEvo.Count != 0)
|
||||
pk.Species = FinalEvo[randFinalEvo()];
|
||||
pk.Form = Legal.GetRandomForme(pk.Species, Settings.AllowRandomMegaForms, true, Personal);
|
||||
}
|
||||
}
|
||||
|
||||
private void RandomizeSpecFormItem(IPokeData pk, int Type)
|
||||
@@ -157,6 +150,7 @@ private void RandomizeSpecFormItem(IPokeData pk, int Type)
|
||||
else // every other pkm
|
||||
{
|
||||
pk.Species = RandSpec.GetRandomSpeciesType(pk.Species, Type);
|
||||
TryForceEvolve(pk);
|
||||
pk.HeldItem = PossibleHeldItems[Util.Random.Next(PossibleHeldItems.Length)];
|
||||
pk.Form = Legal.GetRandomForme(pk.Species, Settings.AllowRandomMegaForms, true, Personal);
|
||||
}
|
||||
@@ -177,9 +171,46 @@ private void RandomizeSpecForm(TrainerPoke7b pk, int type)
|
||||
|
||||
pk.MegaFormChoice = 0;
|
||||
pk.Species = RandSpec.GetRandomSpeciesType(pk.Species, type);
|
||||
TryForceEvolve(pk);
|
||||
pk.Form = Legal.GetRandomForme(pk.Species, Settings.AllowRandomMegaForms, true, Personal);
|
||||
}
|
||||
|
||||
private void TryForceEvolve(IPokeData pk)
|
||||
{
|
||||
if (!Settings.ForceFullyEvolved || pk.Level < Settings.ForceFullyEvolvedAtLevel)
|
||||
return;
|
||||
|
||||
var evos = Evos;
|
||||
int species = pk.Species;
|
||||
int form = pk.Form;
|
||||
|
||||
int timesEvolved = TryForceEvolve(evos, ref species, ref form);
|
||||
if (timesEvolved == 0)
|
||||
return;
|
||||
pk.Species = species;
|
||||
pk.Form = form;
|
||||
}
|
||||
|
||||
private int TryForceEvolve(IReadOnlyList<EvolutionSet> evos, ref int species, ref int form)
|
||||
{
|
||||
int timesEvolved = 0;
|
||||
do
|
||||
{
|
||||
var index = Personal.GetFormeIndex(species, form);
|
||||
var eSet = evos[index].PossibleEvolutions;
|
||||
int evoCount = eSet.Count(z => z.HasData);
|
||||
if (evoCount == 0)
|
||||
break;
|
||||
++timesEvolved;
|
||||
var next = Util.Random.Next(evoCount);
|
||||
var nextEvo = eSet[next];
|
||||
species = nextEvo.Species;
|
||||
form = nextEvo.Form >= 0 ? nextEvo.Form : form;
|
||||
}
|
||||
while (timesEvolved < 3); // prevent randomized evos from looping excessively
|
||||
return timesEvolved;
|
||||
}
|
||||
|
||||
private void UpdatePKMFromSettings(TrainerPoke pk)
|
||||
{
|
||||
if (Settings.BoostLevel)
|
||||
|
||||
@@ -24,5 +24,7 @@ public EvolutionMethod Copy(int species = -1)
|
||||
Level = Level
|
||||
};
|
||||
}
|
||||
|
||||
public bool HasData => Species != 0;
|
||||
}
|
||||
}
|
||||
@@ -540,7 +540,8 @@ private void B_Randomize_Click(object sender, EventArgs e)
|
||||
var rspec = new SpeciesRandomizer(Game.Info, Personal);
|
||||
rspec.Initialize((SpeciesSettings)PG_Species.SelectedObject);
|
||||
learn.Moves = moves;
|
||||
var trand = new TrainerRandomizer(Game.Info, Personal, Trainers.LoadAll())
|
||||
var evos = Game.Data.EvolutionData;
|
||||
var trand = new TrainerRandomizer(Game.Info, Personal, Trainers.LoadAll(), evos.LoadAll())
|
||||
{
|
||||
ClassCount = CB_Trainer_Class.Items.Count,
|
||||
Learn = learn,
|
||||
|
||||
Reference in New Issue
Block a user