Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static PokemonStats GetPokemonInternalValues(Pokemon mother, Pokemon father)
- {
- // By default 3 stats are inherited
- var numberOfStatsInherited = new NumberRef<int>(3);
- // But this can be overridden by held items on the mother or father
- DataHolder.BaseLibrary.GenericScriptHolder.ExecuteScripts<Void>(
- new[] {mother.HeldItem, father.HeldItem,}, "modifyNumberOfIVsInherited",
- new object[] {mother, father, numberOfStatsInherited});
- // We create a stat array, with -1 as uninitialized value
- var statsArray = new short[] {-1, -1, -1, -1, -1, -1};
- // Script hook on held item of the mother to inherit a stat
- var motherStatsInherited = DataHolder.BaseLibrary.GenericScriptHolder.ExecuteScripts<string>(
- new[] {mother.HeldItem}, "inheritStat",
- new object[] {mother, father}).FirstOrDefault();
- // If the mothers held item overrides a stat
- if (motherStatsInherited != null)
- {
- // Inherit this stat
- motherStatsInherited = motherStatsInherited.ToLower();
- switch (motherStatsInherited)
- {
- case "hp":
- statsArray[0] = mother.InternalValues.HP;
- break;
- case "attack":
- statsArray[1] = mother.InternalValues.Attack;
- break;
- case "defense":
- statsArray[2] = mother.InternalValues.Defense;
- break;
- case "special_attack":
- statsArray[3] = mother.InternalValues.SpecialAttack;
- break;
- case "special_defense":
- statsArray[4] = mother.InternalValues.SpecialDefense;
- break;
- case "speed":
- statsArray[5] = mother.InternalValues.Speed;
- break;
- default:
- throw new Exception("");
- }
- // And subtract from the number of stats we should still inherit
- numberOfStatsInherited--;
- }
- // Script hook on held item of the father to inherit a stat
- var fatherStatsInherited = DataHolder.BaseLibrary.GenericScriptHolder.ExecuteScripts<string>(
- new[] {father.HeldItem}, "inheritStat",
- new object[] {mother, father}).FirstOrDefault();
- // If the fathers held item overrides a stat
- if (fatherStatsInherited != null)
- {
- // Inherit this stat
- fatherStatsInherited = fatherStatsInherited.ToLower();
- switch (fatherStatsInherited)
- {
- case "hp":
- statsArray[0] = father.InternalValues.HP;
- break;
- case "attack":
- statsArray[1] = father.InternalValues.Attack;
- break;
- case "defense":
- statsArray[2] = father.InternalValues.Defense;
- break;
- case "special_attack":
- statsArray[3] = father.InternalValues.SpecialAttack;
- break;
- case "special_defense":
- statsArray[4] = father.InternalValues.SpecialDefense;
- break;
- case "speed":
- statsArray[5] = father.InternalValues.Speed;
- break;
- default:
- throw new Exception("");
- }
- // And subtract from the number of stats we should still inherit
- numberOfStatsInherited--;
- }
- var random = new Random();
- // While we either still need to inherit stats, or all stats have already been initialized
- while (numberOfStatsInherited > 0 && statsArray.Contains((short) -1))
- {
- // Generate a random IV index to inherit
- var statIndex = random.Next(0, 6);
- // If the IV at this index is already initialized, continue and don't override
- if (statsArray[statIndex] != -1)
- continue;
- // 50/50 chance whether to inherit from the mother or the father
- var inheritFromMother = random.Next(0, 2) == 0;
- if (inheritFromMother)
- {
- statsArray[statIndex] = mother.InternalValues.GetStatFromIndex(statIndex);
- }
- else
- {
- statsArray[statIndex] = father.InternalValues.GetStatFromIndex(statIndex);
- }
- // subtract from the number of stats we still need to inherit
- numberOfStatsInherited--;
- }
- // Iterate over all stats
- for (var index = 0; index < statsArray.Length; index++)
- {
- // Everything that's not been set yet needs to be a random IV, between 0 and 31
- var stat = statsArray[index];
- if (stat == -1)
- {
- statsArray[index] = (short) random.Next(0, 32);
- }
- }
- return PokemonStats.CreateFromArray(statsArray);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement