Add GetRandomFeeling

fixes tests & transfers where an explicit range is not legal
This commit is contained in:
Kurt 2018-04-28 12:59:11 -07:00
parent f060bab844
commit ea357cd57a
6 changed files with 18 additions and 7 deletions

View File

@ -2229,5 +2229,16 @@ public static LanguageID GetSafeLanguage(int generation, LanguageID prefer, Game
return LanguageID.English;
}
}
public static int GetRandomFeeling(int memory, int max = 24)
{
var bits = MemoryFeelings[memory];
while (true)
{
int feel = Util.Rand.Next(0, max);
if ((bits & (1 << feel)) != 0)
return feel;
}
}
}
}

View File

@ -363,14 +363,14 @@ public override PKM ConvertToPKM(ITrainerInfo SAV)
pk.OT_Memory = 3;
pk.OT_TextVar = 9;
pk.OT_Intensity = 1;
pk.OT_Feeling = Util.Rand.Next(0, 10); // 0-9
pk.OT_Feeling = Legal.GetRandomFeeling(pk.OT_Memory, 10); // 0-9
}
else
{
pk.HT_Memory = 3;
pk.HT_TextVar = 9;
pk.HT_Intensity = 1;
pk.HT_Feeling = Util.Rand.Next(0, 10); // 0-9
pk.HT_Feeling = Legal.GetRandomFeeling(pk.HT_Memory, 10); // 0-9
pk.HT_Friendship = pk.OT_Friendship;
}
pk.IsNicknamed = IsNicknamed;

View File

@ -559,7 +559,7 @@ public static void SetHatchMemory6(this PKM pk)
{
pk.OT_Memory = 2;
pk.OT_Affection = 0;
pk.OT_Feeling = Util.Rand.Next(0, 10);
Legal.GetRandomFeeling(pk.OT_Memory);
pk.OT_Intensity = 1;
pk.OT_TextVar = pk.XY ? 43 : 27; // riverside road : battling spot
}
@ -569,7 +569,7 @@ public static void SetRandomMemory6(this PKM pk)
// for lack of better randomization :)
pk.OT_Memory = 63;
pk.OT_Intensity = 6;
pk.OT_Feeling = 3;
Legal.GetRandomFeeling(pk.OT_Memory);
}
}
}

View File

@ -493,7 +493,7 @@ public PK6 ConvertToPK6()
pk6.Geo1_Country = PKMConverter.Country;
pk6.HT_Intensity = 1;
pk6.HT_Memory = 4;
pk6.HT_Feeling = (int)(Util.Rand32() % 10);
pk6.HT_Feeling = Legal.GetRandomFeeling(pk6.HT_Memory);
// When transferred, friendship gets reset.
pk6.OT_Friendship = pk6.HT_Friendship = PersonalInfo.BaseFriendship;

View File

@ -559,7 +559,7 @@ public void TradeMemory(bool Bank)
HT_Memory = 4; // Link trade to [VAR: General Location]
HT_TextVar = Bank ? 0 : 9; // Somewhere (Bank) : Pokécenter (Trade)
HT_Intensity = 1;
HT_Feeling = Util.Rand.Next(0, Bank ? 10 : 20); // 0-9 Bank, 0-19 Trade
HT_Feeling = Legal.GetRandomFeeling(HT_Memory, Bank ? 10 : 20); // 0-9 Bank, 0-19 Trade
}
// Legality Properties

View File

@ -596,7 +596,7 @@ public void TradeMemory(bool Bank)
HT_Memory = 4; // Link trade to [VAR: General Location]
HT_TextVar = 0; // Somewhere (Bank)
HT_Intensity = 1;
HT_Feeling = Util.Rand.Next(0, 10); // 0-9 Bank
HT_Feeling = Legal.GetRandomFeeling(HT_Memory, 10); // 0-9 Bank
}
// Legality Properties