Example #1
0
        public Rarelity Lottery(bool containsNone, Rarelity[] table)
        {
            ValueTuple <Rarelity, float>[]       probabilities = this.GetProbabilities();
            List <ValueTuple <Rarelity, float> > toRelease     = ListPool <ValueTuple <Rarelity, float> > .Get();

            foreach (ValueTuple <Rarelity, float> valueTuple in probabilities)
            {
                foreach (Rarelity rarelity in table)
                {
                    if ((containsNone || rarelity != Rarelity.None) && (Rarelity)valueTuple.Item1 == rarelity)
                    {
                        toRelease.Add(valueTuple);
                    }
                }
            }
            float num1 = 0.0f;

            using (List <ValueTuple <Rarelity, float> > .Enumerator enumerator = toRelease.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ValueTuple <Rarelity, float> current = enumerator.Current;
                    num1 += (float)current.Item2;
                }
            }
            float    num2      = Random.Range(0.0f, num1);
            Rarelity rarelity1 = ~Rarelity.None;

            using (List <ValueTuple <Rarelity, float> > .Enumerator enumerator = toRelease.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ValueTuple <Rarelity, float> current = enumerator.Current;
                    if ((double)num2 <= current.Item2)
                    {
                        rarelity1 = (Rarelity)current.Item1;
                        break;
                    }
                    num2 -= (float)current.Item2;
                }
            }
            ListPool <ValueTuple <Rarelity, float> > .Release(toRelease);

            return(rarelity1);
        }
Example #2
0
        public Rarelity Lottery(bool containsNone)
        {
            float num1 = this.Normal + this.Rare + this.SuperRare + this.HighRare + this.UltraRare;

            if (containsNone)
            {
                num1 += this._none;
            }
            float    num2     = Random.Range(0.0f, num1);
            Rarelity rarelity = ~Rarelity.None;

            foreach (ValueTuple <Rarelity, float> probability in this.GetProbabilities())
            {
                if ((double)num2 <= probability.Item2)
                {
                    rarelity = (Rarelity)probability.Item1;
                    break;
                }
                num2 -= (float)probability.Item2;
            }
            return(rarelity);
        }
 public static bool Contains(this Rarelity source, Rarelity shape)
 {
     return(source == (source | shape) && shape != Rarelity.None);
 }