private EncounterArea2(byte[] data, GameVersion game) : base(game) { Location = data[0]; Time = (EncounterTime)data[1]; var type = Type = (SlotType)data[2]; var rate = data[3]; if (type > SlotType.Surf) // Not Grass/Surf { const int size = 5; int count = (data.Length - 4) / size; var rates = new byte[count]; for (int i = 0; i < rates.Length; i++) { rates[i] = data[4 + i]; } Rates = rates; Slots = ReadSlots(data, count, 4 + count); } else { Rate = rate; const int size = 4; int count = (data.Length - 4) / size; Rates = type == SlotType.BugContest ? BCC_SlotRates : (type == SlotType.Grass) ? RatesGrass : RatesSurf; Slots = ReadSlots(data, count, 4); } }
internal static int RandomValidTime(this EncounterTime t1) { int val = Util.Rand.Next(1, 4); if (t1 == EncounterTime.Any) { return(val); } while (!t1.Contains(val)) { val = Util.Rand.Next(1, 4); } return(val); }
private static bool Contains(this EncounterTime t1, EncounterTime t2) { if (t1 == t2 || t1 == EncounterTime.Any || t2 == EncounterTime.Any) { return(true); } if (t1 == EncounterTime.MorningDay) { return(t2 == EncounterTime.Morning || t2 == EncounterTime.Day); } if (t2 == EncounterTime.MorningDay) { return(t1 == EncounterTime.Morning || t1 == EncounterTime.Day); } return(false); }
//--------------------------------------------------------------------- // Ctor //--------------------------------------------------------------------- public RandomEncounter( XmlNode node, string facet, string regionType, string regionName, string probability, string shortest, string farthest, string landType, string time, string level, string levelType, string scaleUp ) { m_XmlNode = node; m_Facet = facet; m_RegionType = regionType; m_RegionName = regionName; if (probability == "*") { m_Probability = -1; m_Inclusive = true; } else { m_Probability = float.Parse(probability, RandomEncounterEngine.Language); m_Inclusive = false; } m_Shortest = int.Parse(shortest); m_Farthest = int.Parse(farthest); m_LandType = (LandType)Enum.Parse(typeof(LandType), landType); m_EncounterTime = (EncounterTime)Enum.Parse(typeof(EncounterTime), time); m_Level = double.Parse(level); m_LevelType = (LevelType)Enum.Parse(typeof(LevelType), levelType); m_ScaleUp = bool.Parse(scaleUp); m_Elements = new ArrayList(); }
private static byte[] WriteTableOfTime(EncounterArea2 area, EncounterTime t) { using var ms = new MemoryStream(); using var bw = new BinaryWriter(ms); var slots = area.Slots.Cast <EncounterSlot2>() .Where(z => z.Time == EncounterTime.Any || z.Time == t).ToArray(); bw.Write((byte)area.Location); bw.Write((byte)t); bw.Write((byte)area.Type); bw.Write((byte)0xFF); foreach (byte b in area.Rates) { bw.Write(b); } foreach (var s in slots) { WriteSlot(bw, s); } return(ms.ToArray()); }
//--------------------------------------------------------------------- // Ctor //--------------------------------------------------------------------- public RandomEncounter( XmlNode node, string facet, string regionType, string regionName, string probability, string shortest, string farthest, string landType, string time, string level, string levelType, string scaleUp ) { m_XmlNode = node; m_Facet = facet; m_RegionType = regionType; m_RegionName = regionName; if( probability=="*" ) { m_Probability = -1; m_Inclusive = true; } else { m_Probability = float.Parse( probability, RandomEncounterEngine.Language ); m_Inclusive = false; } m_Shortest = int.Parse( shortest ); m_Farthest = int.Parse( farthest ); m_LandType = (LandType) Enum.Parse( typeof( LandType ), landType ); m_EncounterTime = (EncounterTime) Enum.Parse( typeof( EncounterTime ), time ); m_Level = double.Parse( level ); m_LevelType = (LevelType) Enum.Parse( typeof( LevelType ), levelType ); m_ScaleUp = bool.Parse( scaleUp ); m_Elements = new ArrayList(); }
internal static bool Contains(this EncounterTime t1, int t2) => t1 == EncounterTime.Any || t1.HasFlag((EncounterTime)(1 << t2));
internal static bool Contains(this EncounterTime t1, int t2) => t1 == EncounterTime.Any || (t1 & (EncounterTime)(1 << t2)) != 0;
public static bool Contains(this EncounterTime t1, int t2) => t1.Contains((EncounterTime)t2);