示例#1
0
        /// <summary>
        /// Управляет созданием построек
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string BuildStructure(BaseAction obj)
        {
            if (CheckInput(obj) != "success")
            {
                return(CheckInput(obj));
            }

            try
            {
                if (IsOwner(obj.baseid, obj.token) && obj.result != null)
                {
                    obj.result = obj.result ?? "lifeComplex";

                    var Struct = HasBaseStructure(obj.baseid, obj.result);
                    if (Struct != null)
                    {
                        return("alreadyexists");
                    }
                    if (!CanAfford(obj.baseid, obj.result))
                    {
                        return("notenoughresources");
                    }

                    ProceedActions.DoBuyItem(obj.baseid, obj.result);

                    using (var db = new Entities())
                    {
                        db.Structures.Add(new Structure {
                            BaseID = obj.baseid, Type = obj.result, Level = 1
                        });
                        db.SaveChanges();
                    }
                    const string result = "success";
                    return(result);
                }
                else
                {
                    const string result = "notanowner";
                    return(result);
                }
            }
            catch (Exception ex)
            {
                ProceedActions.Log("Exception", $"Исключение: {ex.Message}, функция BaseManager.BuildStructure");
                return("Error#Exception: " + ex.Message);
            }
        }
示例#2
0
        /// <summary>
        /// Управляет улучшением построек
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string UpgradeStructure(BaseAction obj)
        {
            if (CheckInput(obj) != "success")
            {
                return(CheckInput(obj));
            }
            try
            {
                if (IsOwner(obj.baseid, obj.token) && obj.result != null)
                {
                    var Struct = HasBaseStructure(obj.baseid, obj.result);
                    if (Struct == null)
                    {
                        return("notexists");
                    }
                    if (!CanAfford(obj.baseid, obj.result, Struct.Level))
                    {
                        return("notenoughresources");
                    }

                    ProceedActions.DoBuyItem(obj.baseid, obj.result, Struct.Level);

                    using (var db = new Entities())
                    {
                        var str = db.Structures.FirstOrDefault(o => o.Type == obj.result && o.BaseID == obj.baseid);
                        str.Level++;
                        db.SaveChanges();
                    }

                    const string result = "success";
                    return(result);
                }
                else
                {
                    const string result = "notanowner";
                    return(result);
                }
            }
            catch (Exception ex)
            {
                ProceedActions.Log("Exception", $"Исключение: {ex.Message}, функция BaseManager.UpgradeStructure");
                return("Error#Exception: " + ex.Message);
            }
        }
示例#3
0
        /// <summary>
        /// Управляет починкой базы
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string RepairBase(BaseAction obj)
        {
            if (CheckInput(obj) != "success")
            {
                return(CheckInput(obj));
            }

            try
            {
                if (IsOwner(obj.baseid, obj.token))
                {
                    var BaseData = GetBaseByID(obj.baseid);
                    if (!CanAfford(obj.baseid, "repairBase", BaseData.Level - 2))
                    {
                        return("notenoughresources");
                    }
                    ProceedActions.DoBuyItem(obj.baseid, "repairBase", BaseData.Level - 2);

                    using (var db = new Entities())
                    {
                        var BaseEntry = db.Bases.FirstOrDefault(o => o.BaseID == obj.baseid);
                        BaseEntry.IsActive = !BaseEntry.IsActive;
                        db.SaveChanges();
                    }
                    const string result = "success";
                    return(result);
                }
                else
                {
                    const string result = "notanowner";
                    return(result);
                }
            }
            catch (Exception ex)
            {
                ProceedActions.Log("Exception", $"Исключение: {ex.Message}, функция BaseManager.RepairBase");
                return("Error#Exception: " + ex.Message);
            }
        }
示例#4
0
 /// <summary>
 /// Управляет улучшением базы
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static string UpgradeBase(BaseAction obj)
 {
     if (CheckInput(obj) != "success")
     {
         return(CheckInput(obj));
     }
     try
     {
         if (IsOwner(obj.baseid, obj.token))
         {
             var curbase = GetBaseByID(obj.baseid);
             if (!CanAfford(obj.baseid, "upgradeBase", curbase.Level))
             {
                 return("notenoughresources");
             }
             ProceedActions.DoBuyItem(obj.baseid, "upgradeBase", curbase.Level);
             using (Entities db = new Entities())
             {
                 var BaseEntry = db.Bases.FirstOrDefault(o => o.BaseID == obj.baseid);
                 BaseEntry.Level++;
                 db.SaveChanges();
             }
             ProceedActions.Log("Event", $"Base ID {obj.baseid} has been upgraded at 1 level up.");
             const string result = "success";
             return(result);
         }
         else
         {
             const string result = "notanowner";
             return(result);
         }
     }
     catch (Exception ex)
     {
         ProceedActions.Log("Exception", $"Исключение: {ex.Message}, функция BaseManager.UpgradeBase");
         return("Error#Exception: " + ex.Message);
     }
 }
示例#5
0
        /// <summary>
        /// Управляет созданием юнитов
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string MakeUnit(BaseAction obj)
        {
            if (CheckInput(obj) != "success")
            {
                return(CheckInput(obj));
            }
            try
            {
                if (IsOwner(obj.baseid, obj.token) && obj.result != null)
                {
                    if (HasBaseStructure(obj.baseid, "aircraftsComplex") == null)
                    {
                        return("noAircrafts");
                    }

                    if (!CanAfford(obj.baseid, obj.result))
                    {
                        return("notenoughresources");
                    }

                    var population = HasBaseStructure(obj.baseid, "lifeComplex");
                    if (population == null)
                    {
                        return("noLifeComplex");
                    }
                    ProceedActions.Log("Event", $"Игрок покупает юнит. На базе максимум популяции" +
                                       $" {ItemsVars.GetPopulation(population.Level)} и уже {GetBaseUnitsCount(obj.baseid)} юнитов создано");
                    if (ItemsVars.GetPopulation(population.Level) <= GetBaseUnitsCount(obj.baseid))
                    {
                        return("populationLimit");
                    }

                    ProceedActions.DoBuyItem(obj.baseid, obj.result);

                    var u = SquadManager.GetUnit("bas" + obj.baseid.ToString(), obj.result);

                    using (var db = new Entities())
                    {
                        if (u == null)
                        {
                            db.Units.Add(new Unit {
                                Instance = "bas" + obj.baseid.ToString(), Type = obj.result, Count = 1
                            });
                        }
                        else
                        {
                            ProceedActions.Log("Event", $"В инстансе {obj.baseid.ToString()} {u.Count} юнитов типа {obj.result}");
                            var unit = db.Units.FirstOrDefault(o => o.Instance == u.Instance && o.Type == u.Type);
                            unit.Count++;
                        }
                        db.SaveChanges();
                    }

                    const string result = "success";
                    return(result);
                }
                else
                {
                    const string result = "notanowner";
                    return(result);
                }
            }
            catch (Exception ex)
            {
                ProceedActions.Log("Exception", $"Исключение: {ex.Message}, функция BaseManager.MakeUnit");
                return("Error#Exception: " + ex.Message);
            }
        }