Advertisement
Deukhoofd

Untitled

Mar 4th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.59 KB | None | 0 0
  1. private static PokemonStats GetPokemonInternalValues(Pokemon mother, Pokemon father)
  2.         {
  3.             // By default 3 stats are inherited
  4.             var numberOfStatsInherited = new NumberRef<int>(3);
  5.             // But this can be overridden by held items on the mother or father
  6.             DataHolder.BaseLibrary.GenericScriptHolder.ExecuteScripts<Void>(
  7.                 new[] {mother.HeldItem, father.HeldItem,}, "modifyNumberOfIVsInherited",
  8.                 new object[] {mother, father, numberOfStatsInherited});
  9.  
  10.             // We create a stat array, with -1 as uninitialized value
  11.             var statsArray = new short[] {-1, -1, -1, -1, -1, -1};
  12.  
  13.             // Script hook on held item of the mother to inherit a stat
  14.             var motherStatsInherited = DataHolder.BaseLibrary.GenericScriptHolder.ExecuteScripts<string>(
  15.                 new[] {mother.HeldItem}, "inheritStat",
  16.                 new object[] {mother, father}).FirstOrDefault();
  17.  
  18.             // If the mothers held item overrides a stat
  19.             if (motherStatsInherited != null)
  20.             {
  21.                 // Inherit this stat
  22.                 motherStatsInherited = motherStatsInherited.ToLower();
  23.                 switch (motherStatsInherited)
  24.                 {
  25.                     case "hp":
  26.                         statsArray[0] = mother.InternalValues.HP;
  27.                         break;
  28.                     case "attack":
  29.                         statsArray[1] = mother.InternalValues.Attack;
  30.                         break;
  31.                     case "defense":
  32.                         statsArray[2] = mother.InternalValues.Defense;
  33.                         break;
  34.                     case "special_attack":
  35.                         statsArray[3] = mother.InternalValues.SpecialAttack;
  36.                         break;
  37.                     case "special_defense":
  38.                         statsArray[4] = mother.InternalValues.SpecialDefense;
  39.                         break;
  40.                     case "speed":
  41.                         statsArray[5] = mother.InternalValues.Speed;
  42.                         break;
  43.                     default:
  44.                         throw new Exception("");
  45.                 }
  46.  
  47.                 // And subtract from the number of stats we should still inherit
  48.                 numberOfStatsInherited--;
  49.             }
  50.  
  51.             // Script hook on held item of the father to inherit a stat
  52.             var fatherStatsInherited = DataHolder.BaseLibrary.GenericScriptHolder.ExecuteScripts<string>(
  53.                 new[] {father.HeldItem}, "inheritStat",
  54.                 new object[] {mother, father}).FirstOrDefault();
  55.  
  56.             // If the fathers held item overrides a stat
  57.             if (fatherStatsInherited != null)
  58.             {
  59.                 // Inherit this stat
  60.                 fatherStatsInherited = fatherStatsInherited.ToLower();
  61.                 switch (fatherStatsInherited)
  62.                 {
  63.                     case "hp":
  64.                         statsArray[0] = father.InternalValues.HP;
  65.                         break;
  66.                     case "attack":
  67.                         statsArray[1] = father.InternalValues.Attack;
  68.                         break;
  69.                     case "defense":
  70.                         statsArray[2] = father.InternalValues.Defense;
  71.                         break;
  72.                     case "special_attack":
  73.                         statsArray[3] = father.InternalValues.SpecialAttack;
  74.                         break;
  75.                     case "special_defense":
  76.                         statsArray[4] = father.InternalValues.SpecialDefense;
  77.                         break;
  78.                     case "speed":
  79.                         statsArray[5] = father.InternalValues.Speed;
  80.                         break;
  81.                     default:
  82.                         throw new Exception("");
  83.                 }
  84.  
  85.                 // And subtract from the number of stats we should still inherit
  86.                 numberOfStatsInherited--;
  87.             }
  88.  
  89.             var random = new Random();
  90.             // While we either still need to inherit stats, or all stats have already been initialized
  91.             while (numberOfStatsInherited > 0 && statsArray.Contains((short) -1))
  92.             {
  93.                 // Generate a random IV index to inherit
  94.                 var statIndex = random.Next(0, 6);
  95.                 // If the IV at this index is already initialized, continue and don't override
  96.                 if (statsArray[statIndex] != -1)
  97.                     continue;
  98.                 // 50/50 chance whether to inherit from the mother or the father
  99.                 var inheritFromMother = random.Next(0, 2) == 0;
  100.                 if (inheritFromMother)
  101.                 {
  102.                     statsArray[statIndex] = mother.InternalValues.GetStatFromIndex(statIndex);
  103.                 }
  104.                 else
  105.                 {
  106.                     statsArray[statIndex] = father.InternalValues.GetStatFromIndex(statIndex);
  107.                 }
  108.                 // subtract from the number of stats we still need to inherit
  109.                 numberOfStatsInherited--;
  110.             }
  111.  
  112.             // Iterate over all stats
  113.             for (var index = 0; index < statsArray.Length; index++)
  114.             {
  115.                 // Everything that's not been set yet needs to be a random IV, between 0 and 31
  116.                 var stat = statsArray[index];
  117.                 if (stat == -1)
  118.                 {
  119.                     statsArray[index] = (short) random.Next(0, 32);
  120.                 }
  121.             }
  122.  
  123.             return PokemonStats.CreateFromArray(statsArray);
  124.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement