Exemple #1
0
 public EscortableNoble(BaseCamp c) : base(c)
 {
     Title = "the noble";
     SetSkill(SkillName.Parry, 80.0, 100.0);
     SetSkill(SkillName.Swords, 80.0, 100.0);
     SetSkill(SkillName.Tactics, 80.0, 100.0);
 }
Exemple #2
0
        /// <summary>
        /// Ask the user if he wants to purchase more units
        /// </summary>
        /// <param name="camp"></param>
        private void AddMoreUnits(BaseCamp camp)
        {
            Console.WriteLine($"You currently have {camp.Resources} bfc");
            Console.WriteLine("Would you like to add more units? (1)Yes  (2)No");

            try
            {
                var continueShopping = int.Parse(Console.ReadKey().KeyChar.ToString());
                Console.WriteLine();

                if (continueShopping == 1)
                {
                    this.Shop(camp);
                }
            }
            catch (Exception e)
            {
                ErrorLogging(e, "AddMoreUnits");
                Console.WriteLine();
                Console.WriteLine("Something went wrong while adding more units (error 102)!");
                Console.WriteLine();

                this.AddMoreUnits(camp);
            }
        }
Exemple #3
0
        /// <summary>
        /// Iterates over the players army by given type, returns the attacked unit by ID
        /// </summary>
        /// <param name="p2"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private ArmyUnit GetAttackedUnit(BaseCamp p2, Type type)
        {
            ArmyUnit selectedUnit = null;

            try
            {
                var units = p2.Army
                            .Where(u => u.GetType() == type)
                            .OrderByDescending(u => u.Health)
                            .ThenByDescending(u => u.Defense)
                            .ToList();

                foreach (var unit in units)
                {
                    Console.WriteLine($"Unit #{unit.Id} has {unit.Health} health, {unit.Defense} defense and {unit.Range} range");
                }

                Console.Write("Choose a unit: ");
                var unitId = int.Parse(Console.ReadLine());
                Console.WriteLine();

                selectedUnit = units.FirstOrDefault(u => u.Id == unitId);
            }
            catch (Exception e)
            {
                ErrorLogging(e, "GetAttackedUnit");
                Console.WriteLine();
                Console.WriteLine("Something went wrong when choosing a unit (error 106)!");
                Console.WriteLine();

                this.GetAttackedUnit(p2, type);
            }

            return(selectedUnit);
        }
        public void StartImport()
        {
            HttpContext.Current = null;
            try
            {
                LogStatus("started");

                CoreContext.TenantManager.SetCurrentTenant(Id);
                Thread.CurrentPrincipal = _principal;

                HttpContext.Current = new HttpContext(
                    new HttpRequest("fake", CommonLinkUtility.GetFullAbsolutePath("/"), string.Empty),
                    new HttpResponse(new StringWriter()));

                Status.LogInfo(ImportResource.ImportStarted);
                var basecampManager = BaseCamp.GetInstance(_url, _userName, _password);
                LogStatus("import users");
                SaveUsers(basecampManager);
                LogStatus("import projects");
                SaveProjects(basecampManager);
                Status.LogInfo(ImportResource.ImportCompleted);
            }
            finally
            {
                if (HttpContext.Current != null)
                {
                    new DisposableHttpContext(HttpContext.Current).Dispose();
                    HttpContext.Current = null;
                }
            }
        }
Exemple #5
0
 private void GainResource(BaseCamp p1, ArmyUnit armyUnit)
 {
     if (armyUnit != null && p1 != null)
     {
         p1.Resources += ( int )(armyUnit.Cost * 0.65);
     }
 }
Exemple #6
0
        private void Attack(BaseCamp p1, BaseCamp p2, string attacker = "AI")
        {
            var ready = this.Ready(p1);
            var aim   = this.Aim(p2, attacker);

            this.Fire(p1, p2, ready, aim);
        }
Exemple #7
0
        private void ShopAgain(BaseCamp p1)
        {
            try
            {
                Console.WriteLine();
                Console.WriteLine("Would you like to add more units to your army: (1)Yes, (2)No");
                var input = int.Parse(Console.ReadKey().KeyChar.ToString());
                Console.WriteLine();

                if (input == 1)
                {
                    this.Shop(p1);
                    Console.WriteLine("The battle continues!");
                }
                else
                {
                    Console.WriteLine("The battle continues!");
                }
            }
            catch (Exception e)
            {
                ErrorLogging(e, "ShopAgain");

                Console.WriteLine();
                Console.WriteLine("Something went wrong while confirming accessing the shop (error 109)!");
                Console.WriteLine();

                this.ShopAgain(p1);
            }
        }
 public BaseEscortable(BaseCamp camp)
     : base(AIType.AI_Melee, FightMode.Aggressor, 22, 1, 0.4, 1.0)
 {
     m_Camp = camp;
     #endregion
     this.InitBody();
     this.InitOutfit();
 }
Exemple #9
0
        public static IEnumerable <Project> GetProjects(string url, string userName, string password)
        {
            var basecampManager = BaseCamp.GetInstance(ImportFromBasecamp.PrepUrl(url).ToString().TrimEnd('/') + "/api/v1", userName, password);

            return(basecampManager.Projects.Select(r => new Project {
                ID = r.ID, Title = r.Name, Status = r.IsClosed ? ProjectStatus.Closed : ProjectStatus.Open
            }).ToList());
        }
Exemple #10
0
        /// <summary>
        /// Return the selected unit with which the player wants attack
        /// </summary>
        /// <param name="p1"></param>
        /// <returns></returns>
        private ArmyUnit Ready(BaseCamp p1)
        {
            Console.WriteLine(
                $"Select a unit: (1){nameof( Airplane )}, (2){nameof( Artillery )}, (3){nameof( Infantry )}, (4){nameof( Tank )}");

            ArmyUnit selectedUnit = null;

            try
            {
                var choice = int.Parse(Console.ReadKey().KeyChar.ToString());
                Console.WriteLine();

                switch (choice)
                {
                case 1:
                    selectedUnit = this.GetSelectedUnit(p1, typeof(Airplane));

                    break;

                case 2:

                    selectedUnit = this.GetSelectedUnit(p1, typeof(Artillery));

                    break;

                case 3:

                    selectedUnit = this.GetSelectedUnit(p1, typeof(Infantry));

                    break;

                case 4:

                    selectedUnit = this.GetSelectedUnit(p1, typeof(Tank));

                    break;

                default:
                    Console.WriteLine("Please select one of the provided options!");
                    this.Ready(p1);

                    break;
                }
            }
            catch (Exception e)
            {
                ErrorLogging(e, "Ready");
                Console.WriteLine();
                Console.WriteLine("Something went wrong when preparing the selected unit (error 107)!");
                Console.WriteLine();

                this.Ready(p1);
            }

            return(selectedUnit);
        }
Exemple #11
0
    public void ShowCampInfo(BaseCamp camp)
    {
        Root.gameObject.SetActive(true);

        campIcon.sprite = FactoryManger.AssetFactory.LoadSprite(camp.IconName);
        campName.text   = camp.Name;
        campLv.text     = "兵营等级:" + camp.Lv;
        weaponLv.text   = "武器等级:" + FactoryManger.AttributeFactory.GetWeaponShareAttribute(camp.WeaponType).Name;

        currentCamp = camp;
    }
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
            case 0:
                m_Camp = reader.ReadItem() as BaseCamp;
                break;
            }
        }
Exemple #13
0
        public static int CheckUsersQuota(string url, string userName, string password)
        {
            var basecampManager    = BaseCamp.GetInstance(ImportFromBasecamp.PrepUrl(url).ToString().TrimEnd('/') + "/api/v1", userName, password);
            var countImportedUsers = basecampManager.People.Count();
            var remainingAmount    = TenantExtra.GetRemainingCountUsers();

            if (remainingAmount == 0)
            {
                return(0);
            }

            var difference = remainingAmount - countImportedUsers;

            return(difference >= 0 ? remainingAmount : -remainingAmount);
        }
Exemple #14
0
        /// <summary>
        /// Attack the selected enemy unit.
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="unit"></param>
        /// <param name="attackedUnit"></param>
        private void Fire(BaseCamp p1, BaseCamp p2, ArmyUnit unit, ArmyUnit attackedUnit)
        {
            try
            {
                var attackedUnitHealth = attackedUnit.Health;
                var damageDealt        = unit.Attack(attackedUnit);
                int remainingDamage    = 0;

                if (attackedUnitHealth - damageDealt < 0)
                {
                    remainingDamage = Math.Abs(attackedUnitHealth - damageDealt);
                }

                Console.Write(
                    $"{unit.GetType().Name}#{unit.Id} did {damageDealt} damage to {attackedUnit.GetType().Name}#{attackedUnit.Id}");

                if (!attackedUnit.IsDead())
                {
                    Console.WriteLine($" which has {attackedUnit.Health} health left after the attack.");
                }
                else
                {
                    this.GainResource(p1, attackedUnit);
                    p2.RemoveFromArmy(attackedUnit);
                    Console.WriteLine(" and killed it.");
                }

                if (p2.CanTakeDamage())
                {
                    Console.WriteLine($"The enemy's army numbers are dwindeling! His Base took {remainingDamage} damage!");
                    p2.TakeDamage(remainingDamage);
                }

                this.lastAttackingUnit = unit.Id;
                this.IsGameOver();
            }
            catch (Exception e)
            {
                ErrorLogging(e, "Fire");
                Console.WriteLine();
                Console.WriteLine("Something went from when attacking the enemy (error 108)!");
                Console.WriteLine();

                this.Fire(p1, p2, unit, attackedUnit);
            }
        }
        public void StartImport()
        {
            LogStatus("started");

            CoreContext.TenantManager.SetCurrentTenant(Id);
            Thread.CurrentPrincipal = _principal;

            Status.LogInfo(SettingsResource.ImportStarted);
            var basecampManager = BaseCamp.GetInstance(_url, _token, "X");

            LogStatus("import users");
            SaveUsers(basecampManager);
            LogStatus("import projects");
            SaveProjects(basecampManager);
            LogStatus("import files");
            SaveFiles(basecampManager, Attachments);
            Status.LogInfo(SettingsResource.ImportCompleted);
        }
Exemple #16
0
        public Noble(BaseCamp c)
            : base(c)
        {
            #endregion

            if (this.Female)
            {
                this.Title = "the noblewoman";
            }
            else
            {
                this.Title = "the nobleman";
            }

            //this.Title = "the noble";

            this.SetSkill(SkillName.Parry, 80.0, 100.0);
            this.SetSkill(SkillName.Swords, 80.0, 100.0);
            this.SetSkill(SkillName.Tactics, 80.0, 100.0);
        }
Exemple #17
0
        /// <summary>
        /// Purchases the specified quantity of the chosen unit and adds it to the player's army.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="quantity"></param>
        /// <param name="className"></param>
        private void Buy(BaseCamp player, int quantity, Type className)
        {
            try
            {
                for (int i = 0; i < quantity; i++)
                {
                    var a = Activator.CreateInstance(className);
                    player.PurchaseUnit(( ArmyUnit )a);
                }

                Console.WriteLine($"{quantity} {className.Name} units successfully purchased!");
            }
            catch (Exception ex)
            {
                ErrorLogging(ex, "Buy");
                Console.WriteLine();
                Console.WriteLine("Something went wrong with purchasing the Unit (error 100)!");
                Console.WriteLine();

                this.Buy(player, quantity, className);
            }
        }
Exemple #18
0
        /// <summary>
        /// Initializes the BaseCamp class,  for loops use the .AddToArmy() to fill the army units, displays the health and
        /// if the base is damageable with the .IsDamageable() method.
        /// </summary>
        private static void InitializeBaseCamp()
        {
            var camp = new BaseCamp();

            Console.WriteLine();
            Console.WriteLine(new string( '-', 74 ));
            Console.Write($"The Base Camp has {camp.Health} hp with ");

            for (int i = 0; i < 25; i++)
            {
                camp.PurchaseUnit(new Airplane());
            }

            for (int i = 0; i < 25; i++)
            {
                camp.PurchaseUnit(new Artillery());
            }

            Console.Write($"{camp.Army.Count()} units available.\n");

            Console.WriteLine("Is the camp attackable currently: {0}", camp.CanTakeDamage() ? "Yes" : "No");
            Console.WriteLine(new string( '-', 74 ));
        }
        private void SaveFiles(BaseCamp basecampManeger, IEnumerable <IAttachment> attachments)
        {
            var step = 100.0 / attachments.Count();

            Status.LogInfo(string.Format(SettingsResource.ImportFileStarted, attachments.Count()));

            //select last version
            foreach (var attachment in attachments.GroupBy(a => a.Collection).Select(g => g.OrderByDescending(a => a.Vers).FirstOrDefault()))
            {
                Status.FileProgress += step;
                try
                {
                    HttpWebRequest HttpWReq = basecampManeger.Service.GetRequest(attachment.DownloadUrl);
                    using (HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse())
                    {
                        if (attachment.ByteSize > SetupInfo.MaxUploadSize)
                        {
                            break;
                        }

                        var file = new ASC.Files.Core.File();
                        file.FolderID      = attachment.CategoryID != -1 ? FindFileCategory(attachment.CategoryID) : FileEngine2.GetRoot(FindProject(attachment.ProjectID));
                        file.Title         = attachment.Name;
                        file.ContentLength = attachment.ByteSize;
                        file.ContentType   = MimeMapping.GetMimeMapping(attachment.Name);
                        file.CreateBy      = FindUser(attachment.AuthorID);
                        file.CreateOn      = attachment.CreatedOn.ToUniversalTime();
                        if (file.Title.LastIndexOf('\\') != -1)
                        {
                            file.Title = file.Title.Substring(file.Title.LastIndexOf('\\') + 1);
                        }

                        file = FileEngine2.SaveFile(file, HttpWResp.GetResponseStream());

                        if ("Post".Equals(attachment.OwnerType, StringComparison.OrdinalIgnoreCase))
                        {
                            try
                            {
                                var messageId = FindMessage(attachment.OwnerID);
                                FileEngine2.AttachFileToMessage(messageId, file.ID);//It's not critical
                            }
                            catch (Exception e)
                            {
                                LogError(string.Format("not critical. attaching file '{0}' to message  failed", attachment.Name), e);
                            }
                        }

                        NewFilesID.Add(new FileIDWrapper
                        {
                            inBasecamp = attachment.ID,
                            inProjects = file.ID,
                            version    = attachment.Vers,
                            collection = attachment.Collection
                        });
                    }
                }
                catch (Exception e)
                {
                    try
                    {
                        Status.LogError(string.Format(SettingsResource.FailedToSaveFile, attachment.Name), e);
                        LogError(string.Format("file '{0}' failed", attachment.Name), e);
                        NewFilesID.RemoveAll(x => x.inBasecamp == attachment.ID && x.version == attachment.Vers);
                    }
                    catch (Exception ex)
                    {
                        LogError(string.Format("file remove after error failed"), ex);
                    }
                }
            }
        }
        public PrisonerMessage(BaseCamp c, BaseEscortable escort)
            : base(c.Prisoner, null, "", null)
        {
            m_Camp = c;

            switch (Utility.Random(13))
            {
            case 0: Subject = "A kidnapping!"; break;

            case 1: Subject = "Help!"; break;

            case 2: Subject = "Help us, please!"; break;

            case 3: Subject = "Adventurers needed!"; break;

            case 4: Subject = "Seeking assistance"; break;

            case 5: Subject = "In need of aid"; break;

            case 6: Subject = "Canst thou help us?"; break;

            case 7: Subject = "Shall any save our friend?"; break;

            case 8: Subject = "A friend was kidnapped!"; break;

            case 9: Subject = "Heroes wanted!"; break;

            case 10: Subject = "Can any assist us?"; break;

            case 11: Subject = "Kidnapped!"; break;

            case 12: Subject = "Taken prisoner"; break;
            }

            double        distance;
            BulletinBoard board = FindClosestBB(c.Prisoner, out distance);

            List <String> myLines = new List <String>();

            string[] subtext1 = { "foul", "vile", "evil", "dark", "cruel", "vicious", "scoundrelly", "dastardly", "cowardly", "craven", "foul and monstrous", "monstrous", "hideous", "terrible", "cruel, evil", "truly vile", "vicious and cunning", "" };

            string camp;

            switch (c.Camp)
            {
            default:
            case CampType.Default: camp = ""; break;

            //case CampType.EvilMage: camp = "evil mages"; break;
            //case CampType.GoodMage: camp = "mages"; break;
            case CampType.Lizardman: camp = "lizardmen"; break;

            case CampType.Orc: camp = "orcs"; break;

            case CampType.Ratman: camp = "ratmen"; break;

            case CampType.Brigand: camp = "brigands"; break;
                //case CampType.Gypsy: camp = "gypsys"; break;
                //case CampType.Warlord: camp = "a warlord"; break;
            }

            myLines.Add(String.Format("Help us please! {0} hath", escort.Name));
            myLines.Add(String.Format("been kidnapped by "));
            myLines.Add(String.Format("{0} {1}!", subtext1[Utility.Random(subtext1.Length)], camp));
            myLines.Add(String.Format("We believe that {0} is held at", escort.Female ? "she" : "he"));

            int  xLong = 0, yLat = 0;
            int  xMins = 0, yMins = 0;
            bool xEast = false, ySouth = false;

            if (Sextant.Format(c.Location, c.Map, ref xLong, ref yLat, ref xMins, ref yMins, ref xEast, ref ySouth))
            {
                myLines.Add(String.Format("{0}o {1}'{2}, {3}o {4}'{5}", yLat, yMins, ySouth ? "S" : "N", xLong, xMins, xEast ? "E" : "W"));
            }

            /*myLines.Add(String.Format("{0}"));
            *  myLines.Add(String.Format("{0}."));
            *  myLines.Add(String.Format("{0}"));*/

            Lines = myLines.ToArray();

            if (board != null)
            {
                board.AddItem(this);
            }
            else
            {
                Delete();
            }
        }
Exemple #21
0
        /// <summary>
        /// Return the target enemy unit by ID
        /// </summary>
        /// <param name="p2"></param>
        /// <param name="attacker"></param>
        /// <returns></returns>
        private ArmyUnit Aim(BaseCamp p2, string attacker)
        {
            var      airplanes    = p2.Army.Where(a => a.GetType() == typeof(Airplane)).ToList().Count;
            var      artillery    = p2.Army.Where(a => a.GetType() == typeof(Artillery)).ToList().Count;
            var      infantry     = p2.Army.Where(a => a.GetType() == typeof(Infantry)).ToList().Count;
            var      tanks        = p2.Army.Where(a => a.GetType() == typeof(Tank)).ToList().Count;
            ArmyUnit selectedUnit = null;

            Console.WriteLine(
                $"{attacker} has {airplanes} Airplanes, {artillery} Artilleries, {infantry} Infantries and {tanks} Tanks");

            Console.WriteLine(
                $"Show more details about which unit devision: (1){nameof( Airplane )} (2){nameof( Artillery )} (3){nameof( Infantry )} (4){nameof( Tank )}");

            try
            {
                var choice = int.Parse(Console.ReadKey().KeyChar.ToString());
                Console.WriteLine();

                switch (choice)
                {
                case 1:

                    selectedUnit = this.GetAttackedUnit(p2, typeof(Airplane));

                    break;

                case 2:

                    selectedUnit = this.GetAttackedUnit(p2, typeof(Artillery));

                    break;

                case 3:

                    selectedUnit = this.GetAttackedUnit(p2, typeof(Infantry));

                    break;

                case 4:

                    selectedUnit = this.GetAttackedUnit(p2, typeof(Tank));

                    break;

                default:
                    Console.WriteLine("Please select one of the provided options!");
                    this.Aim(p2, attacker);

                    break;
                }
            }
            catch (Exception e)
            {
                ErrorLogging(e, "Aim");

                Console.WriteLine();
                Console.WriteLine("Something went wrong when aiming the unit (error 107)!");
                Console.WriteLine();

                this.Aim(p2, attacker);
            }

            return(selectedUnit);
        }
Exemple #22
0
 public void Setup()
 {
     _baseCamp = BaseCamp.GetInstance(@"https://omts.basecamphq.com", "d5d07ef81cc0225521a73075edefb32933f15071", "X");
 }
Exemple #23
0
 public void Setup()
 {
     _baseCamp = BaseCamp.GetInstance(@"https://omts.basecamphq.com", "d5d07ef81cc0225521a73075edefb32933f15071", "X");
 }
Exemple #24
0
 private Battle()
 {
     this.player1 = new BaseCamp();
     this.player2 = new BaseCamp();
 }
Exemple #25
0
        /// <summary>
        /// Display the shop, presenting the available units to purchase and probides the option to buy them.
        /// </summary>
        /// <param name="camp"></param>
        private void Shop(BaseCamp camp)
        {
            Console.WriteLine(
                $"Please select which units do you wish to have in your army: \r\n(1){nameof( Airplane )}, (2){nameof( Artillery )}, (3){nameof( Infantry )}, (4){nameof( Tank )}");

            var userInput = Console.ReadKey().KeyChar.ToString();
            int unitChoice;

            if (!int.TryParse(userInput, out unitChoice))
            {
                userInput = Console.ReadKey().KeyChar.ToString();
            }

            try
            {
                unitChoice = int.Parse(userInput);

                int continuePurchase;
                int confirmPurchase;

                Console.WriteLine();
                Console.Write("You have selected ");

                switch (unitChoice)
                {
                    #region case 1

                case 1:
                    Console.WriteLine(nameof(Airplane) + ".");
                    Console.WriteLine($"\t{nameof( Airplane )} has the following statistics:");
                    Console.WriteLine($"\t  Health: {AirplaneConstants.minHealth}-{AirplaneConstants.maxHealth} pts");
                    Console.WriteLine($"\t  Defense: {AirplaneConstants.minDefense}-{AirplaneConstants.maxDefense} pts");
                    Console.WriteLine($"\t  Attack: {AirplaneConstants.minAttackPower}-{AirplaneConstants.maxAttackPower} pts");
                    Console.WriteLine($"\t  Range: {AirplaneConstants.minAttackRange}-{AirplaneConstants.maxAttackRange} pts");
                    Console.WriteLine($"\t  Cost: {AirplaneConstants.Cost} bfc");
                    continuePurchase = this.CheckIfUserWantsSelectedUnit();

                    if (continuePurchase == 1)
                    {
                        int quantity = this.ConfirmUnitQuantity();
                        var sum      = quantity * AirplaneConstants.Cost;

                        if (sum <= camp.Resources)
                        {
                            confirmPurchase = this.ConfirmPurchase();

                            if (confirmPurchase == 1)
                            {
                                this.Buy(camp, quantity, typeof(Airplane));
                            }
                            else
                            {
                                this.Shop(camp);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Invalid funds!");
                            this.Shop(camp);
                        }
                    }
                    else
                    {
                        this.Shop(camp);
                    }

                    break;

                    #endregion

                    #region case 2

                case 2:
                    Console.WriteLine(nameof(Artillery) + ".");
                    Console.WriteLine($"\t{nameof( Artillery )} has the following statistics:");
                    Console.WriteLine($"\t  Health: {ArtilleryConstants.minHealth}-{ArtilleryConstants.maxHealth} pts");
                    Console.WriteLine($"\t  Defense: {ArtilleryConstants.minDefense}-{ArtilleryConstants.maxDefense} pts");
                    Console.WriteLine($"\t  Attack: {ArtilleryConstants.minAttackPower}-{ArtilleryConstants.maxAttackPower} pts");
                    Console.WriteLine($"\t  Range: {ArtilleryConstants.minAttackRange}-{ArtilleryConstants.maxAttackRange} pts");
                    Console.WriteLine($"\t  Cost: {ArtilleryConstants.Cost} bfc");
                    continuePurchase = this.CheckIfUserWantsSelectedUnit();

                    if (continuePurchase == 1)
                    {
                        var quantity = this.ConfirmUnitQuantity();
                        var sum      = quantity * ArtilleryConstants.Cost;

                        if (sum <= camp.Resources)
                        {
                            confirmPurchase = this.ConfirmPurchase();

                            if (confirmPurchase == 1)
                            {
                                this.Buy(camp, quantity, typeof(Artillery));
                            }
                            else
                            {
                                this.Shop(camp);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Invalid funds!");
                            this.Shop(camp);
                        }
                    }
                    else
                    {
                        this.Shop(camp);
                    }

                    break;

                    #endregion

                    #region case 3

                case 3:
                    Console.WriteLine(nameof(Infantry) + ".");
                    Console.WriteLine($"\t{nameof( Infantry )} has the following statistics:");
                    Console.WriteLine($"\t  Health: {InfantryConstants.minHealth}-{InfantryConstants.maxHealth} pts");
                    Console.WriteLine($"\t  Defense: {InfantryConstants.minDefense}-{InfantryConstants.maxDefense} pts");
                    Console.WriteLine($"\t  Attack: {InfantryConstants.minAttackPower}-{InfantryConstants.maxAttackPower} pts");
                    Console.WriteLine($"\t  Range: {InfantryConstants.minAttackRange}-{InfantryConstants.maxAttackRange} pts");
                    Console.WriteLine($"\t  Cost: {InfantryConstants.Cost} bfc");
                    continuePurchase = this.CheckIfUserWantsSelectedUnit();

                    if (continuePurchase == 1)
                    {
                        var quantity = this.ConfirmUnitQuantity();
                        var sum      = quantity * InfantryConstants.Cost;

                        if (sum <= camp.Resources)
                        {
                            confirmPurchase = this.ConfirmPurchase();

                            if (confirmPurchase == 1)
                            {
                                this.Buy(camp, quantity, typeof(Infantry));
                            }
                            else
                            {
                                this.Shop(camp);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Invalid funds!");
                            this.Shop(camp);
                        }
                    }
                    else
                    {
                        this.Shop(camp);
                    }

                    break;

                    #endregion

                    #region case 4

                case 4:
                    Console.WriteLine(nameof(Tank) + ".");
                    Console.WriteLine($"\t{nameof( Tank )} has the following statistics:");
                    Console.WriteLine($"\t  Health: {TankConstants.minHealth}-{TankConstants.maxHealth} pts");
                    Console.WriteLine($"\t  Defense: {TankConstants.minDefense}-{TankConstants.maxDefense} pts");
                    Console.WriteLine($"\t  Attack: {TankConstants.minAttackPower}-{TankConstants.maxAttackPower} pts");
                    Console.WriteLine($"\t  Range: {TankConstants.minAttackRange}-{TankConstants.maxAttackRange} pts");
                    Console.WriteLine($"\t  Cost: {TankConstants.Cost} bfc");
                    continuePurchase = this.CheckIfUserWantsSelectedUnit();

                    if (continuePurchase == 1)
                    {
                        var quantity = this.ConfirmUnitQuantity();
                        var sum      = quantity * TankConstants.Cost;

                        if (sum <= camp.Resources)
                        {
                            confirmPurchase = this.ConfirmPurchase();

                            if (confirmPurchase == 1)
                            {
                                this.Buy(camp, quantity, typeof(Tank));
                            }
                            else
                            {
                                this.Shop(camp);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Invalid funds!");
                            this.Shop(camp);
                        }
                    }
                    else
                    {
                        this.Shop(camp);
                    }

                    break;

                    #endregion
                }

                this.AddMoreUnits(camp);
            }
            catch (Exception ex)
            {
                ErrorLogging(ex, "Shop");
                Console.WriteLine();
                Console.WriteLine("Something went wrong while shopping (error 101)!");
                Console.WriteLine();

                this.Shop(camp);
            }
        }
Exemple #26
0
 public SeekerOfAdventure(BaseCamp c)
     : base(c)
 {
     #endregion
     this.Title = "the seeker of adventure";
 }
 public SeekerOfAdventure(BaseCamp c) : base(c)
 {
     Title = "the seeker of adventure";
 }
        private void SaveUsers(BaseCamp basecampManager)
        {
            var employees = basecampManager.People;
            var step      = 100.0 / employees.Count();

            foreach (var person in employees.Where(x => _withClosed ? true : !x.Deleted))
            {
                try
                {
                    Status.UserProgress += step;
                    Guid userID = FindUserByEmail(person.EmailAddress);

                    if (userID.Equals(Guid.Empty))
                    {
                        UserInfo userInfo = new UserInfo()
                        {
                            Email     = person.EmailAddress,
                            FirstName = person.FirstName,
                            LastName  = person.LastName,
                            Title     = person.Title,
                            Status    = person.Deleted ? EmployeeStatus.Terminated : EmployeeStatus.Active,
                        };

                        if (!string.IsNullOrEmpty(person.PhoneNumberMobile))
                        {
                            userInfo.AddSocialContact(SocialContactsManager.ContactType_mobphone, person.PhoneNumberMobile);
                        }
                        if (!string.IsNullOrEmpty(person.PhoneNumberHome))
                        {
                            userInfo.AddSocialContact(SocialContactsManager.ContactType_phone, person.PhoneNumberHome);
                        }
                        if (!string.IsNullOrEmpty(person.PhoneNumberOffice))
                        {
                            userInfo.AddSocialContact(SocialContactsManager.ContactType_phone, person.PhoneNumberOffice);
                        }
                        if (!string.IsNullOrEmpty(person.PhoneNumberFax))
                        {
                            userInfo.AddSocialContact(SocialContactsManager.ContactType_phone, person.PhoneNumberFax);
                        }
                        if (!string.IsNullOrEmpty(person.ImHandle))
                        {
                            switch (person.ImService)
                            {
                            case "MSN":
                                userInfo.AddSocialContact(SocialContactsManager.ContactType_msn, person.ImHandle);
                                break;

                            case "ICQ":
                                userInfo.AddSocialContact(SocialContactsManager.ContactType_icq, person.ImHandle);
                                break;

                            case "Yahoo":
                                userInfo.AddSocialContact(SocialContactsManager.ContactType_yahoo, person.ImHandle);
                                break;

                            case "Jabber":
                                userInfo.AddSocialContact(SocialContactsManager.ContactType_jabber, person.ImHandle);
                                break;

                            case "Skype":
                                userInfo.AddSocialContact(SocialContactsManager.ContactType_skype, person.ImHandle);
                                break;

                            case "Google":
                                userInfo.AddSocialContact(SocialContactsManager.ContactType_gmail, person.ImHandle);
                                break;
                            }
                        }

                        var newUserInfo = UserManagerWrapper.AddUser(userInfo, UserManagerWrapper.GeneratePassword(), false, !_disableNotifications);
                        if (person.Administrator)
                        {
                            CoreContext.UserManager.AddUserIntoGroup(newUserInfo.ID, ASC.Core.Users.Constants.GroupAdmin.ID);
                        }
                        NewUsersID.Add(new UserIDWrapper()
                        {
                            inBasecamp = person.ID, inProjects = newUserInfo.ID
                        });

                        //save user avatar
                        const string emptyAvatar = "http://asset1.37img.com/global/missing/avatar.png?r=3";//TODO:?!!! Wtf??!!
                        if (person.AvatarUrl != emptyAvatar)
                        {
                            UserPhotoManager.SaveOrUpdatePhoto(newUserInfo.ID, StreamFile(person.AvatarUrl));
                        }
                    }
                    else
                    {
                        NewUsersID.Add(new UserIDWrapper()
                        {
                            inBasecamp = person.ID, inProjects = userID
                        });
                    }
                }
                catch (Exception e)
                {
                    Status.LogError(string.Format(SettingsResource.FailedToSaveUser, person.EmailAddress), e);
                    LogError(string.Format("user '{0}' failed", person.EmailAddress), e);
                    NewUsersID.RemoveAll(x => x.inBasecamp == person.ID);
                }
            }
        }
        private void SaveProjects(BaseCamp basecampManager)
        {
            var projects          = basecampManager.Projects;
            var step              = 50.0 / projects.Count();
            var projectEngine     = _engineFactory.GetProjectEngine();
            var participantEngine = _engineFactory.GetParticipantEngine();

            foreach (var project in projects.Where(x => _withClosed ? true : x.Status == "active"))
            {
                try
                {
                    Status.LogInfo(string.Format(SettingsResource.ImportProjectStarted, project.Name));
                    Status.ProjectProgress += step;
                    var newProject = new Project()
                    {
                        Status      = project.Status == "active" ? ProjectStatus.Open : ProjectStatus.Closed,
                        Title       = ReplaceLineSeparator(project.Name),
                        Description = project.Description,
                        Responsible = _initiatorId,
                        Private     = true
                    };

                    projectEngine.SaveOrUpdate(newProject, true);
                    Participant prt = participantEngine.GetByID(newProject.Responsible);
                    projectEngine.AddToTeam(newProject, prt, true);

                    foreach (var wrapper in
                             project.People.SelectMany(user => NewUsersID.Where(wrapper => user.ID == wrapper.inBasecamp)))
                    {
                        prt = participantEngine.GetByID(wrapper.inProjects);
                        projectEngine.AddToTeam(newProject, prt, true);

                        //check permission
                        var user = project.People.ToList().Find(p => p.ID == wrapper.inBasecamp);
                        if (user != null)
                        {
                            if (!user.HasAccessToNewProjects)
                            {
                                switch (user.CanPost)
                                {
                                case 1:
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Messages, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Files, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Tasks, false);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Milestone, false);
                                    break;

                                case 2:
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Messages, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Files, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Tasks, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Milestone, false);
                                    break;

                                case 3:
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Messages, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Files, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Tasks, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Milestone, true);
                                    break;
                                }
                            }
                        }
                    }
                    NewProjectsID.Add(new ProjectIDWrapper()
                    {
                        inBasecamp = project.ID, inProjects = newProject.ID
                    });
                }
                catch (Exception e)
                {
                    Status.LogError(string.Format(SettingsResource.FailedToSaveProject, project.Name), e);
                    LogError(string.Format("project '{0}' failed", project.Name), e);
                    NewProjectsID.RemoveAll(x => x.inBasecamp == project.ID);
                }
            }

            //Select only suceeded projects
            var projectsToProcess = projects.Where(x => NewProjectsID.Count(y => y.inBasecamp == x.ID) > 0).ToList();

            step = 50.0 / projectsToProcess.Count;
            foreach (var project in projectsToProcess)
            {
                Status.LogInfo(string.Format(SettingsResource.ImportProjectDataStarted, project.Name));

                Status.ProjectProgress += step;
                SaveMilestones(project.Milestones);

                var messages = project.RecentMessages;
                foreach (var message in messages)
                {
                    SaveMessages(message);
                }

                var todoLists = project.ToDoLists;
                foreach (var todoList in todoLists)
                {
                    SaveTasks(todoList);
                }
                SaveFileCategories(project.Categories);
                SaveTimeSpends(project.TimeEntries);
                Attachments.AddRange(project.Attachments);
            }
        }