convert class from as3 to typescript

package heroclickerlib.managers
{
   import com.playsaurus.numbers.BigNumber;
   import com.playsaurus.utils.CurrentUser;
   import models.Hero;
   import models.Monster;
   import models.UserData;
   
   public class Formulas
   {
      
      private static var _INSTANCE:Formulas;
      
      private static var cachedMonsterLife:Object = {};
      
      private static var earlyBase:Number = 1.55;
      
      private static var lateBase:Number = 1.145;
      
      private static var levelWhereScaleChanges:Number = 140;
      
      private static var increasePerFiveHundredLevels:Number = 0.001;
      
      private static var healthAt200k:BigNumber = new BigNumber("1.240e25409");
      
      {
         cachedMonsterLife[levelWhereScaleChanges] = new BigNumber(earlyBase).pow(levelWhereScaleChanges - 1).multiplyN(10);
         cachedMonsterLife[500] = new BigNumber(lateBase).pow(500 - levelWhereScaleChanges).multiply(cachedMonsterLife[levelWhereScaleChanges]);
      }
      
      public function Formulas()
      {
         super();
      }
      
      public static function get instance() : Formulas
      {
         if(_INSTANCE == null)
         {
            _INSTANCE = new Formulas();
         }
         return _INSTANCE;
      }
      
      public function processHeroFormula(param1:String, param2:Hero, param3:int = 0, param4:int = 1) : *
      {
         if(param3 == 0)
         {
            param3 = param2.level;
         }
         if(param1 in this)
         {
            if(param1 == "heroCostFormula1")
            {
               return this.heroCostFormula1(param2,param3,param4);
            }
            return this[param1](param2,param3);
         }
         return new BigNumber(0);
      }
      
      public function processMonsterFormula(param1:String, param2:Monster) : *
      {
         if(param1 in this)
         {
            return this[param1](param2);
         }
         trace("WARNING: ",param1,"not found in",this);
         return new BigNumber(0);
      }
      
      public function heroAttackFormula1(param1:Hero, param2:int) : BigNumber
      {
         return param1.baseAttack.multiply(new BigNumber(param2)).multiply(param1.damageMultiplier).multiply(new BigNumber((CurrentUser.instance as UserData).allDpsMultiplier)).multiply((CurrentUser.instance as UserData).getHeroSoulWorldDamageBonus().percentIncreaseToMultiplier()).multiply((CurrentUser.instance as UserData).outsiders.ancientSoulDamageBonus.percentIncreaseToMultiplier()).multiply(new BigNumber(param1.getEpicBonus())).multiply(new BigNumber((CurrentUser.instance as UserData).getRubyDamageMultiple()));
      }
      
      public function heroClickDamageFormula1(param1:Hero, param2:int) : BigNumber
      {
         return new BigNumber(param1.baseClickDamage).multiply(new BigNumber(param2)).multiply(param1.damageMultiplier).multiply(new BigNumber((CurrentUser.instance as UserData).clickMultiplier)).multiply(new BigNumber((CurrentUser.instance as UserData).allDpsMultiplier)).multiply((CurrentUser.instance as UserData).getHeroSoulWorldDamageBonus().percentIncreaseToMultiplier()).multiply((CurrentUser.instance as UserData).outsiders.ancientSoulDamageBonus.percentIncreaseToMultiplier());
      }
      
      public function heroGoldPerSecondFormula1(param1:Hero, param2:Number) : BigNumber
      {
         return new BigNumber(0);
      }
      
      public function heroCostUpToLevel(param1:Hero, param2:Number, param3:Number) : BigNumber
      {
         var _loc4_:BigNumber = new BigNumber(0);
         var _loc5_:Number = 0;
         while(_loc5_ < param3)
         {
            _loc4_ = _loc4_.add(this.heroCostFormula1(param1,param2,param2 + _loc5_));
            _loc5_++;
         }
         return _loc4_;
      }
      
      public function heroCostFormula1(param1:Hero, param2:int, param3:int) : BigNumber
      {
         var _loc5_:BigNumber = null;
         var _loc7_:BigNumber = null;
         var _loc9_:int = 0;
         var _loc10_:* = undefined;
         var _loc11_:* = undefined;
         var _loc12_:* = undefined;
         var _loc13_:* = undefined;
         var _loc4_:Number = 1.07;
         if(param1.id > 50)
         {
            _loc4_ = 1.22;
         }
         var _loc6_:Number = 1 - (CurrentUser.instance as UserData).ancients.heroLevelCostPercent.multiplyN(0.01).numberValue();
         if(param1.id == 1)
         {
            if(param2 <= 15)
            {
               _loc5_ = new BigNumber(0);
               if(param3 <= 15)
               {
                  _loc9_ = param2;
                  while(_loc9_ < param3)
                  {
                     _loc5_ = _loc5_.add(new BigNumber((5 + _loc9_) * Math.pow(_loc4_,_loc9_) * _loc6_));
                     _loc9_++;
                  }
                  return _loc5_.floor();
               }
               _loc9_ = param2;
               while(_loc9_ < 15)
               {
                  _loc5_ = _loc5_.add(new BigNumber((5 + _loc9_) * Math.pow(_loc4_,_loc9_) * _loc6_));
                  _loc9_++;
               }
               return (_loc5_ = _loc5_.add(new BigNumber(20 * ((Math.pow(_loc4_,param3) - Math.pow(_loc4_,15)) / (_loc4_ - 1)) * _loc6_))).floor();
            }
            _loc5_ = new BigNumber(_loc6_ * 20);
            _loc7_ = (_loc7_ = new BigNumber(_loc4_)).pow(param3);
            _loc10_ = new BigNumber(_loc4_);
            _loc11_ = param2;
            _loc10_ = _loc10_.pow(_loc11_);
            _loc12_ = _loc7_.subtract(_loc10_);
            _loc13_ = new BigNumber(_loc4_ - 1);
            _loc12_ = _loc12_.divide(_loc13_);
            return (_loc5_ = _loc5_.multiply(_loc12_)).floor();
         }
         _loc7_ = param1.baseCost;
         var _loc8_:BigNumber = (_loc8_ = (_loc8_ = new BigNumber(_loc4_).pow(param3)).subtract(new BigNumber(_loc4_).pow(param2))).divide(new BigNumber(_loc4_ - 1));
         return (_loc7_ = (_loc7_ = _loc7_.multiply(_loc8_)).multiply(new BigNumber(_loc6_))).floor();
      }
      
      public function heroCostFormula46(param1:Hero, param2:int, param3:int) : BigNumber
      {
         var _loc5_:BigNumber = null;
         var _loc4_:Number = 1.07;
         var _loc6_:Number = 1 - (CurrentUser.instance as UserData).ancients.heroLevelCostPercent.multiplyN(0.01).numberValue();
         var _loc7_:BigNumber = param1.baseCost;
         var _loc8_:BigNumber = (_loc8_ = (_loc8_ = new BigNumber(_loc4_).pow(param3)).subtract(new BigNumber(_loc4_).pow(param2))).divide(new BigNumber(_loc4_ - 1));
         return (_loc7_ = (_loc7_ = _loc7_.multiply(_loc8_)).multiply(new BigNumber(_loc6_))).floor();
      }
      
      public function oldMonsterLifeFormula1(param1:Monster) : BigNumber
      {
         var _loc2_:BigNumber = null;
         var _loc5_:Number = NaN;
         var _loc6_:Number = NaN;
         var _loc10_:BigNumber = null;
         var _loc3_:Number = 1.6;
         var _loc4_:Number = 1.15;
         var _loc7_:Number = 140;
         if(param1.level < _loc7_)
         {
            _loc5_ = param1.level;
            _loc6_ = 0;
         }
         else
         {
            _loc5_ = _loc7_;
            _loc6_ = param1.level - _loc7_;
         }
         var _loc8_:Number = 0;
         var _loc9_:BigNumber = (_loc9_ = new BigNumber(_loc3_)).pow(_loc5_ - 1);
         _loc2_ = param1.baseLife;
         _loc2_ = _loc2_.multiply(_loc9_);
         _loc2_ = _loc2_.add(new BigNumber((_loc5_ - 1) * 10));
         if(param1.isBoss)
         {
            _loc2_ = _loc2_.multiply(new BigNumber((CurrentUser.instance as UserData).getBossHpMultiplier(param1.level)));
         }
         if(_loc6_)
         {
            _loc10_ = (_loc10_ = new BigNumber(_loc4_)).pow(_loc6_);
            _loc2_ = _loc2_.multiply(_loc10_);
         }
         return _loc2_.ceil();
      }
      
      private function monsterLifeByFiveHundreds(param1:Number) : BigNumber
      {
         var _loc2_:BigNumber = null;
         var _loc3_:Number = NaN;
         var _loc4_:Number = NaN;
         if(cachedMonsterLife[param1] != null)
         {
            _loc2_ = cachedMonsterLife[param1];
         }
         else
         {
            _loc3_ = Math.floor(param1 / 500);
            _loc4_ = lateBase + (_loc3_ - 1) * increasePerFiveHundredLevels;
            _loc2_ = new BigNumber(_loc4_).pow(500).multiply(this.monsterLifeByFiveHundreds(param1 - 500));
            cachedMonsterLife[param1] = _loc2_;
         }
         return _loc2_;
      }
      
      public function monsterLifeFormula1(param1:Monster) : BigNumber
      {
         var _loc3_:BigNumber = null;
         var _loc4_:Number = NaN;
         var _loc5_:Number = NaN;
         var _loc6_:Number = NaN;
         var _loc7_:Number = NaN;
         var _loc8_:Number = NaN;
         var _loc9_:Number = NaN;
         var _loc10_:BigNumber = null;
         var _loc2_:UserData = CurrentUser.instance as UserData;
         if(!_loc2_.transcendent && _loc2_.highestFinishedZonePersist > 500)
         {
            return this.oldMonsterLifeFormula1(param1);
         }
         if(param1.level <= levelWhereScaleChanges)
         {
            _loc3_ = new BigNumber(earlyBase).pow(param1.level - 1).multiply(param1.baseLife);
            _loc4_ = param1.level;
            _loc5_ = 0;
         }
         else if(param1.level <= 500)
         {
            _loc3_ = new BigNumber(lateBase).pow(param1.level - levelWhereScaleChanges).multiply(cachedMonsterLife[levelWhereScaleChanges]);
            _loc4_ = levelWhereScaleChanges;
         }
         else if(param1.level > 200000)
         {
            _loc3_ = healthAt200k.multiply(new BigNumber(1.545).pow(param1.level - 200001));
         }
         else
         {
            _loc7_ = (_loc6_ = Math.floor(param1.level / 500)) * 500;
            _loc8_ = param1.level - _loc7_;
            _loc9_ = lateBase + _loc6_ * increasePerFiveHundredLevels;
            _loc10_ = this.monsterLifeByFiveHundreds(_loc7_);
            _loc3_ = new BigNumber(_loc9_).pow(_loc8_).multiply(_loc10_);
            _loc4_ = levelWhereScaleChanges;
         }
         _loc3_ = _loc3_.add(new BigNumber((_loc4_ - 1) * 10));
         if(param1.isBoss)
         {
            _loc3_ = _loc3_.multiply(new BigNumber((CurrentUser.instance as UserData).getBossHpMultiplier(param1.level)));
         }
         return _loc3_.ceil();
      }
      
      public function monsterGoldFormula1(param1:Monster, param2:Boolean = false) : BigNumber
      {
         var _loc3_:UserData = CurrentUser.instance as UserData;
         var _loc4_:BigNumber = new BigNumber(1);
         var _loc5_:Number = 1;
         if(param1.level > 75)
         {
            _loc5_ = Math.min(3,Math.pow(1.025,param1.level - 75));
         }
         if(param1.id == 86)
         {
            _loc4_ = _loc3_.getTreasureChestMultiplier();
         }
         var _loc6_:BigNumber;
         return (_loc6_ = (_loc6_ = (_loc6_ = (_loc6_ = (_loc6_ = (_loc6_ = (_loc6_ = this.oldMonsterLifeFormula1(param1)).divide(new BigNumber(15))).multiply(new BigNumber(_loc3_.goldMultiplier))).multiply(new BigNumber(param2 ? 1 : _loc3_.getSkillBonus("skillGoldBonus") + 1))).multiply(_loc4_)).multiply(_loc3_.ancients.goldPercent.multiplyN(0.01).add(new BigNumber(1)))).multiply(new BigNumber(_loc5_))).ceil();
      }
   }
}