public void UpgradeCrystal(GameState state, Crystal crystalToUpgrade, CDouble moduleLevel, CDouble count)
        {
            Crystal newCrystal = crystalToUpgrade.Upgrade(state, moduleLevel, count);

            if (newCrystal.Count > 0)
            {
                Crystal crystal = this.Crystals.FirstOrDefault((Crystal x) => x.Level == newCrystal.Level);
                if (crystal == null)
                {
                    this.Crystals.Add(newCrystal);
                }
                else
                {
                    crystal.Count += newCrystal.Count;
                }
            }
            List <Crystal> list = new List <Crystal>();

            foreach (Crystal current in this.Crystals)
            {
                if (current.Count > 0)
                {
                    list.Add(current);
                }
            }
            this.Crystals = (from x in list
                             orderby x.Level.ToInt()
                             select x).ToList <Crystal>();
        }
        internal static FactoryModule Deserialize(string base64String)
        {
            if (string.IsNullOrEmpty(base64String))
            {
                Log.Error("FactoryModule.FromString with empty value!");
                return(new FactoryModule());
            }
            string[]      parts         = Conv.StringPartsFromBase64(base64String, "FactoryModule");
            FactoryModule factoryModule = new FactoryModule();

            factoryModule.Type            = (ModuleType)Conv.getIntFromParts(parts, "a");
            factoryModule.MaxLevel        = new CDouble(Conv.getStringFromParts(parts, "b"));
            factoryModule.ShadowClones    = Conv.getCDoubleFromParts(parts, "c", false);
            factoryModule.CurrentDuration = Conv.getLongFromParts(parts, "d");
            factoryModule.Crystals        = new List <Crystal>();
            string stringFromParts = Conv.getStringFromParts(parts, "e");

            string[] array = stringFromParts.Split(new char[]
            {
                '&'
            });
            string[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                string text = array2[i];
                if (!string.IsNullOrEmpty(text))
                {
                    factoryModule.Crystals.Add(Crystal.Deserialize(text));
                }
            }
            factoryModule.Level = new CDouble(Conv.getStringFromParts(parts, "f"));
            return(factoryModule);
        }
Exemplo n.º 3
0
        internal static CrystalFactory Deserialize(string base64String)
        {
            if (string.IsNullOrEmpty(base64String))
            {
                Log.Error("CrystalFactory.FromString with empty value!");
                return(new CrystalFactory());
            }
            string[]       parts          = Conv.StringPartsFromBase64(base64String, "CrystalFactory");
            CrystalFactory crystalFactory = new CrystalFactory();

            crystalFactory.DefenderClones = new CDouble(Conv.getStringFromParts(parts, "a"));
            crystalFactory.AllModules     = new List <FactoryModule>();
            string stringFromParts = Conv.getStringFromParts(parts, "b");

            string[] array = stringFromParts.Split(new char[]
            {
                '&'
            });
            string[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                string text = array2[i];
                if (!string.IsNullOrEmpty(text))
                {
                    crystalFactory.AllModules.Add(FactoryModule.Deserialize(text));
                }
            }
            if (crystalFactory.AllModules.Count == 0)
            {
                crystalFactory.AllModules = crystalFactory.Initial();
            }
            crystalFactory.Energy           = new CDouble(Conv.getStringFromParts(parts, "c"));
            crystalFactory.LastUBAttack     = Conv.getLongFromParts(parts, "d");
            crystalFactory.EquippedCrystals = new List <Crystal>();
            stringFromParts = Conv.getStringFromParts(parts, "e");
            array           = stringFromParts.Split(new char[]
            {
                '&'
            });
            string[] array3 = array;
            for (int j = 0; j < array3.Length; j++)
            {
                string text2 = array3[j];
                if (!string.IsNullOrEmpty(text2))
                {
                    crystalFactory.EquippedCrystals.Add(Crystal.Deserialize(text2));
                }
            }
            return(crystalFactory);
        }
        public void AddCrystal(Crystal crystal, CDouble count)
        {
            Crystal crystal2 = this.Crystals.FirstOrDefault((Crystal x) => x.Level == crystal.Level);

            if (crystal2 == null)
            {
                crystal.Count = 1;
                this.Crystals.Add(crystal);
            }
            else
            {
                crystal2.Count += count;
            }
            this.Crystals = (from x in this.Crystals
                             orderby x.Level.ToInt()
                             select x).ToList <Crystal>();
        }
Exemplo n.º 5
0
        public void CheckForUbAttack()
        {
            if (App.State.Statistic.HasStarted1kChallenge)
            {
                return;
            }
            long num  = 0L;
            long num2 = 600000L;

            if (App.State.Statistic.NoRbChallengesFinished > 0)
            {
                int num3 = App.State.Statistic.NoRbChallengesFinished.ToInt();
                if (num3 > 20)
                {
                    num3 = 20;
                }
                num2 = num2 * (long)(100 - num3) / 100L;
            }
            UltimateBeing        ultimateBeing = null;
            List <UltimateBeing> list          = (from x in App.State.HomePlanet.UltimateBeings
                                                  orderby x.Tier descending
                                                  select x).ToList <UltimateBeing>();

            foreach (UltimateBeing current in list)
            {
                if (current.IsAvailable)
                {
                    if (current.HPPercent > 0.0)
                    {
                        long num4 = current.TimeUntilComeBack + num2 - current.TimeUntilComeBackBase;
                        if (num == 0L || num > num4)
                        {
                            num = num4;
                        }
                        ultimateBeing = current;
                    }
                    else if (num == 0L || num > current.TimeUntilComeBack + num2)
                    {
                        num = current.TimeUntilComeBack + num2;
                    }
                }
            }
            if (this.LastUBAttack < num2 && num < num2 - this.LastUBAttack)
            {
                num = num2 - this.LastUBAttack;
            }
            if (num <= 0L && ultimateBeing != null)
            {
                string text = ultimateBeing.Fight(App.State, 0, 0, 0, this.DefenderClones, true);
                this.DefenderClones.Round();
                if (text.Contains("lost the fight"))
                {
                    int     value   = ultimateBeing.Tier * 10;
                    CDouble cDouble = this.Energy * value / 100;
                    this.Energy -= cDouble;
                    if (cDouble > 0)
                    {
                        text = text + "\nHe stole " + cDouble.GuiText + " energy!\n";
                    }
                    bool   flag  = false;
                    string text2 = "He also stole ";
                    if (cDouble > 0)
                    {
                        text2 = "He stole ";
                    }
                    foreach (FactoryModule current2 in this.AllModules)
                    {
                        Crystal crystal = current2.Crystals.FirstOrDefault((Crystal x) => x.Level == 1);
                        if (crystal != null && crystal.Count > 0)
                        {
                            flag = true;
                            CDouble cDouble2 = ultimateBeing.Tier;
                            if (cDouble2 > crystal.Count)
                            {
                                cDouble2 = crystal.Count;
                            }
                            crystal.Count -= cDouble2;
                            text2          = string.Concat(new object[]
                            {
                                text2,
                                cDouble2.GuiText,
                                " ",
                                crystal.Type
                            });
                            if (cDouble2 == 1)
                            {
                                text2 += " Crystal, ";
                            }
                            else
                            {
                                text2 += " Crystals, ";
                            }
                        }
                    }
                    if (flag)
                    {
                        text2 = Conv.ReplaceLastOccurrence(text2, "Crystals, ", "Crystals of grade 1!");
                        text2 = Conv.ReplaceLastOccurrence(text2, "Crystal, ", "Crystal of grade 1!");
                        text += text2;
                    }
                    if (!flag && cDouble == 0)
                    {
                        text = ultimateBeing.Name + " tried to attack, but there was nothing of interest on your planet, so he left.\n\n";
                    }
                }
                this.DefenderFightsText.Append(text + "\n\n");
                this.LastUBAttack = 0L;
            }
            this.TimeUntilAttack = num;
        }
 public string UpdateDuration(long ms, GameState state)
 {
     this.UpdateInfoText();
     if (this.ShadowClones > 0)
     {
         bool flag = true;
         using (List <CreationCost> .Enumerator enumerator = this.RequiredCreations.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 CreationCost cost     = enumerator.Current;
                 Creation     creation = state.AllCreations.FirstOrDefault((Creation x) => x.TypeEnum == cost.TypeEnum);
                 CDouble      leftSide = ms * cost.CountNeeded * this.Level;
                 if (leftSide > creation.Count)
                 {
                     if (state.IsBuyUnlocked && state.GameSettings.AutoBuyForCrystal && creation.CanBuy)
                     {
                         CDouble leftSide2 = cost.CountNeeded * this.Level * (this.BaseDuration - this.CurrentDuration);
                         CDouble cDouble   = leftSide2 - creation.Count;
                         CDouble rightSide = cDouble * creation.BuyCost * (120 - state.PremiumBoni.AutoBuyCostReduction) / 100;
                         if (state.Money >= rightSide)
                         {
                             state.Money    -= rightSide;
                             creation.count += cDouble;
                             state.Statistic.TotalMoneySpent += rightSide;
                         }
                         else
                         {
                             CDouble cDouble2   = leftSide - creation.Count;
                             CDouble rightSide2 = cDouble2 * creation.BuyCost * (120 - state.PremiumBoni.AutoBuyCostReduction) / 100;
                             if (state.Money >= rightSide2)
                             {
                                 state.Money    -= rightSide2;
                                 creation.count += cDouble2;
                                 state.Statistic.TotalMoneySpent += rightSide2;
                             }
                             else
                             {
                                 flag = false;
                             }
                         }
                     }
                     else
                     {
                         flag = false;
                     }
                 }
             }
         }
         this.hasEnoughCreations = flag;
         if (flag)
         {
             using (List <CreationCost> .Enumerator enumerator2 = this.RequiredCreations.GetEnumerator())
             {
                 while (enumerator2.MoveNext())
                 {
                     CreationCost cost       = enumerator2.Current;
                     Creation     creation2  = state.AllCreations.FirstOrDefault((Creation x) => x.TypeEnum == cost.TypeEnum);
                     CDouble      rightSide3 = ms * cost.CountNeeded * this.Level;
                     creation2.count -= rightSide3;
                 }
             }
             this.CurrentDuration += ms;
             double num  = (double)this.CurrentDuration / (double)this.BaseDuration;
             int    num2 = (int)num;
             if (num2 > 0)
             {
                 this.CurrentDuration = (long)((num - (double)num2) * (double)this.BaseDuration);
                 Crystal crystal = this.Crystals.FirstOrDefault((Crystal x) => x.Level == 1);
                 if (crystal == null)
                 {
                     this.Crystals.Add(new Crystal
                     {
                         Type  = this.Type,
                         Level = 1,
                         Count = this.Level * num2
                     });
                 }
                 else
                 {
                     crystal.Count += this.Level * num2;
                 }
                 this.Crystals = (from x in this.Crystals
                                  orderby x.Level.ToInt()
                                  select x).ToList <Crystal>();
                 return(string.Concat(new object[]
                 {
                     "- ",
                     this.Level * num2,
                     " x ",
                     this.Type.ToString(),
                     " Crystal\n"
                 }));
             }
         }
         return(string.Empty);
     }
     return(string.Empty);
 }