Ejemplo n.º 1
0
        public void Multiply(BigIntWithUnit elem2)
        {
            if (this == 0 || elem2 == 0)
            {
                Sub(this);
                return;
            }
            if (elem2 == 1)
            {
                return;
            }
            if (this == 1)
            {
                Sub(this);
                Add(elem2);
                return;
            }

            BigIntWithUnit Result     = 0;
            BigIntWithUnit SemiResult = elem2 * _intArray[0];

            SemiResult.ShiftRight(3);
            Result.Add(SemiResult);
            for (int i = 1; i < _intArray.Count; i++)
            {
                SemiResult = elem2 * _intArray[i];
                SemiResult.ShiftLeft((i - 1) * 3);
                Result.Add(SemiResult);
            }
            //There is no this set function :(
            Sub(this);
            Add(Result);
        }
Ejemplo n.º 2
0
        public void Sub(BigIntWithUnit other)
        {
            if (this <= other)
            {
                _intArray = new List <ushort> {
                    0
                };
                return;
            }

            for (var i = 0; i < _intArray.Count; i++)
            {
                if (_intArray[i] < other.SafeGetPart(i))
                {
                    var j = 1;
                    while (_intArray[i + j] == 0)
                    {
                        _intArray[i + j] += 999;
                        j++;
                    }
                    _intArray[i + j] -= 1;
                    _intArray[i]     += 1000;
                }
                _intArray[i] -= other.SafeGetPart(i);
            }
        }
Ejemplo n.º 3
0
 // Minion calls this function, when it is destroyed
 public void MinionDied(Minion minion, BigIntWithUnit currencyGivenOnDeath, float delay)
 {
     if (WaveManager.SafeRemove(minion))
     {
         IncreaseCurrency(currencyGivenOnDeath, minion.transform.position);
         if (_audioManager)
         {
             _audioManager.PlayMinionDeathSound();
         }
         if (minion.tag == "Boss")
         {
             if (minion.Data.HasMageLoot() && !Data.IsMageListFull() && WaveManager.AliveMinionCount == 0)
             {
                 // Add Mage after the "death" animation of boss finishes.
                 StartCoroutine(AddMage(minion, delay));
             }
             else
             {
                 Destroy(minion.gameObject, delay);
                 StartCoroutine(SendWave(minion, delay));
             }
         }
     }
     if (!WaveManager.Data.IsBossWave)
     {
         // Destroy the game object and also send a new wave after the "death" animation of boss finishes.
         Destroy(minion.gameObject, delay);
         if (WaveManager.AliveMinionCount == 0)
         {
             StartCoroutine(SendWave(minion, delay));
         }
     }
 }
Ejemplo n.º 4
0
        public static BigIntWithUnit operator *(BigIntWithUnit elem1, float elem2)
        {
            BigIntWithUnit result = new BigIntWithUnit();

            result.Add(elem1);
            result.Multiply(elem2, 2);
            return(result);
        }
Ejemplo n.º 5
0
        public static BigIntWithUnit operator *(BigIntWithUnit elem1, BigIntWithUnit elem2)
        {
            BigIntWithUnit result = 0;

            result.Add(elem1);
            result.Multiply(elem2);
            return(result);
        }
Ejemplo n.º 6
0
        public static BigIntWithUnit operator -(BigIntWithUnit elem1, BigIntWithUnit elem2)
        {
            BigIntWithUnit result = new BigIntWithUnit();

            result.Add(elem1);
            result.Sub(elem2);
            return(result);
        }
Ejemplo n.º 7
0
        public BigIntWithUnit DecreaseLife(BigIntWithUnit damage)
        {
            var updatedDamage = damage * _player.GetModifier(Player.AdSelector.Damage);
            var dmg           = Data.DecreaseLife(updatedDamage);
            var height        = new Vector3(-5f, 12f, 0f);

            _player.UIManager.CreateFloatingText(updatedDamage.ToString(), transform, transform.position + height, true);
            return(dmg);
        }
Ejemplo n.º 8
0
        public object Clone()
        {
            var clone = new BigIntWithUnit();

            for (var i = 0; i < _intArray.Count; i++)
            {
                clone.SafeSetPart(i, _intArray[i]);
            }
            return(clone);
        }
Ejemplo n.º 9
0
        public void DecreaseCurrency(BigIntWithUnit amount)
        {
            Data.DecreaseCurrency(amount);

            AchievementManager.RegisterEvent(AchievementType.Spend, amount);

            var currencyTextPos = new Vector3(-9f, 0f, 19f);

            UIManager.CreateFloatingText("-" + amount.ToString(), UIManager.CurrText.transform, UIManager.CurrText.transform.position + currencyTextPos, true);
        }
Ejemplo n.º 10
0
        private static BigIntWithUnit CreateNumberFromDecimalString(string[] numberAsString)
        {
            var result = new BigIntWithUnit(numberAsString[0]);

            if (numberAsString.Length > 1)
            {
                var decimalPart = numberAsString[1];
                decimalPart = decimalPart.PadRight(3, '0');
                result.SafeSetPart(0, ushort.Parse(decimalPart.Substring(0, 3)));
            }
            return(result);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Calculates elem1 * elem2/100
        /// </summary>
        /// <param name="elem1"></param>
        /// <param name="elem2"></param>
        /// <returns></returns>
        public static BigIntWithUnit MultiplyPercent(BigIntWithUnit elem1, double elem2)
        {
            var result = new BigIntWithUnit();

            if (elem2 < 100)
            {
                return(result);
            }
            result.Add(elem1);
            result.IncreasePercent((int)elem2 - 100);
            return(result);
        }
Ejemplo n.º 12
0
        public void IncreaseCurrency(BigIntWithUnit amount, Vector3 objpos)
        {
            if (amount == 0)
            {
                return;
            }

            amount *= _currencyModifier;
            Data.IncreaseCurrency(amount);

            AchievementManager.RegisterEvent(AchievementType.Earn, amount);
            var currencyTextPos = new Vector3(0f, 12f, 0f);

            UIManager.CreateFloatingText(amount.ToString(), UIManager.CurrText.transform, objpos + currencyTextPos, false);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Calculates number + (number * percent / 100)
        /// </summary>
        /// <param name="percent"></param>
        public void IncreasePercent(int percent)
        {
            var thousand = percent * 10;
            var toAdd    = new BigIntWithUnit();

            var overflow = (ushort)(_intArray[0] * thousand / 1000);

            for (var i = 1; i <= _intArray.Count + 1; i++)
            {
                var result = SafeGetPart(i) * thousand;
                result += overflow;
                toAdd.SafeSetPart(i - 1, (ushort)(result % 1000));
                overflow = (ushort)(result / 1000);
            }

            Add(toAdd);
        }
Ejemplo n.º 14
0
        public void Add(BigIntWithUnit other)
        {
            // +1 for overflow
            if (other == null)
            {
                return;
            }
            Pad((other.Length() / 3) + 1);
            ushort overflow = 0;

            for (var i = 0; i < _intArray.Count; i++)
            {
                _intArray[i] += (ushort)(other.SafeGetPart(i) + overflow);
                overflow      = (ushort)(_intArray[i] / 1000);
                _intArray[i]  = (ushort)(_intArray[i] % 1000);
            }
            Trim();
        }
Ejemplo n.º 15
0
 protected bool Equals(BigIntWithUnit other)
 {
     return(Equals(_intArray, other._intArray));
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Divides this to elem2 with presision of two digits after comma
        /// </summary>
        public BigIntWithUnit Divide(BigIntWithUnit elem2)
        {
            if (elem2 == 0 || this == 0)
            {
                return(0);
            }
            Trim();
            elem2.Trim();
            if (_intArray.Count - elem2._intArray.Count > 1)
            {
                BigIntWithUnit recursionTemp = (BigIntWithUnit)Clone();
                recursionTemp.ShiftRight(3);
                BigIntWithUnit recursionResult = recursionTemp.Divide(elem2);
                recursionResult.ShiftLeft(3);
                return(recursionResult);
            }
            if (elem2._intArray.Count - _intArray.Count > 1)
            {
                return(0);
            }

            //Actual division by substraction
            //Only need the first two parts because of accuracy
            BigIntWithUnit tempElem1 = 0;
            BigIntWithUnit tempElem2 = 0;

            if (_intArray.Count == elem2._intArray.Count)
            {
                tempElem1.SafeSetPart(0, SafeGetPart(_intArray.Count - 2));
                tempElem1.SafeSetPart(1, SafeGetPart(_intArray.Count - 1));
                tempElem2.SafeSetPart(0, elem2.SafeGetPart(elem2._intArray.Count - 2));
                tempElem2.SafeSetPart(1, elem2.SafeGetPart(elem2._intArray.Count - 1));
            }
            else if (elem2._intArray.Count > _intArray.Count)
            {
                tempElem1.SafeSetPart(0, SafeGetPart(_intArray.Count - 1));
                tempElem2.SafeSetPart(0, elem2.SafeGetPart(elem2._intArray.Count - 2));
                tempElem2.SafeSetPart(1, elem2.SafeGetPart(elem2._intArray.Count - 1));
            }
            else
            {
                tempElem1.SafeSetPart(0, SafeGetPart(_intArray.Count - 2));
                tempElem1.SafeSetPart(1, SafeGetPart(_intArray.Count - 1));
                tempElem2.SafeSetPart(0, elem2.SafeGetPart(elem2._intArray.Count - 1));
            }

            BigIntWithUnit result = 0;
            int            j      = 0;

            if (tempElem2 == 0)
            {
                return(0);
            }
            while (tempElem2 < 100)
            {
                tempElem2.ShiftLeft(1);
                j++;
            }
            for (var i = j; i > -3; i--)
            {
                while (tempElem1 >= tempElem2 && tempElem2 != 0)
                {
                    tempElem1.Sub(tempElem2);
                    result += Math.Pow(10, i);
                }
                var toAdd = (tempElem2.SafeGetPart(1) * 100) % 1000;
                tempElem2.SafeSetPart(1, (ushort)(tempElem2.SafeGetPart(1) / 10));
                tempElem2.SafeSetPart(0, (ushort)(tempElem2.SafeGetPart(0) / 10 + toAdd));
            }

            return(result);
        }