/// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication          ca     = ClientApplication.Instance;
            IDiplomaticTiePicker       picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));
            Collection <DiplomaticTie> ties   = new Collection <DiplomaticTie>();

            foreach (DiplomaticTie t in ca.Player.DiplomaticTies)
            {
                //TODO:  account for needed improvements
                if (t.HasEmbassy)
                {
                    ties.Add(t);
                }
            }
            picker.InitializePicker(ties);
            picker.ShowSimilizationControl();
            this.DiplomaticTie = picker.DiplomaticTie;
            this.City          = this.DiplomaticTie.ForeignCountry.CapitalCity;
            string          text   = string.Empty;
            EspionageResult result = this.DiplomaticTie.StealWorldMap();

            switch (result)
            {
            case EspionageResult.ImmuneToEspionage:
                text = ClientResources.GetString("stealworldmap_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Adjective);
                break;

            case EspionageResult.Success:
                text = ClientResources.GetString("stealworldmap_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Noun);
                break;

            case EspionageResult.Failure:
                text = ClientResources.GetString("stealworldmap_failure");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name);
                break;

            case EspionageResult.SpyCaught:
                text = ClientResources.GetString("stealworldmap_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;
            }
            OnInvoked();
        }
        /// <summary>
        /// Attempts to expose a spy in the embassy.
        /// </summary>
        /// <returns></returns>
        public EspionageResult ExposeSpy()
        {
            if (!this.hasEmbassy)
            {
                throw new InvalidOperationException(ServerResources.EmbassyRequired);
            }

            if (this.foreignCountry.Government.Fallback)
            {
                return(EspionageResult.ImmuneToEspionage);
            }

            EspionageResult result  = EspionageResult.Failure;
            int             randNum = RandomNumber.Between(1, 100);

            if (randNum <= 75)
            {
                //success.  spy captured?  35% chance.
                randNum = RandomNumber.Between(1, 100);
                if (randNum < 35)
                {
                    //spy captured.
                    result = EspionageResult.SuccessWithCapturedSpy;
                    this.foreignCountry.CaptureSpy(this, EspionageAction.ExposeSpy, true, this.foreignCountry.CapitalCity);
                    this.hasSpy = false;
                }
                else
                {
                    result = EspionageResult.Success;
                }
            }
            else
            {
                //failure.  spy captured? 50/50 chance.
                randNum = RandomNumber.Between(1, 100);
                if (randNum < 50)
                {
                    //spy caught
                    result = EspionageResult.SpyCaught;
                    this.foreignCountry.CaptureSpy(this, EspionageAction.ExposeSpy, false, this.foreignCountry.CapitalCity);
                    this.hasSpy = false;
                }
                else
                {
                    result = EspionageResult.Failure;
                }
            }
            return(result);
        }
        /// <summary>
        /// Invokes the Command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            string cityPickerTitle = ClientResources.GetString("propaganda_cityPickerTitle");

            SelectCity(cityPickerTitle);
            if (this.City == null)
            {
                OnCanceled();
                return;
            }
            EspionageResult result = this.DiplomaticTie.SpreadPropaganda(this.City);
            string          text   = string.Empty;

            switch (result)
            {
            case EspionageResult.Failure:
                text = ClientResources.GetString("propaganda_failure");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name);
                break;

            case EspionageResult.ImmuneToEspionage:
                text = ClientResources.GetString("propaganda_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Adjective);
                break;

            case EspionageResult.Success:
                text = ClientResources.GetString("propaganda_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name);
                break;
            }
            IGameWindow gw = ClientApplication.Instance.GameWindow;

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication          ca     = ClientApplication.Instance;
            IDiplomaticTiePicker       picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));
            Collection <DiplomaticTie> ties   = new Collection <DiplomaticTie>();

            foreach (DiplomaticTie t in ca.Player.DiplomaticTies)
            {
                //TODO:  account for needed improvements
                if (t.HasEmbassy)
                {
                    ties.Add(t);
                }
            }
            picker.InitializePicker(ties);
            picker.ShowSimilizationControl();
            this.DiplomaticTie = picker.DiplomaticTie;
            IGameWindow gw       = ClientApplication.Instance.GameWindow;
            bool        canSteal = CheckForStealableTechnologies();

            if (!canSteal)
            {
                string msg = ClientResources.GetString("stealtechnology_noneavailable");
                msg = string.Format(
                    CultureInfo.CurrentCulture,
                    ClientApplication.Instance.Player.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.Civilization.Noun);
                gw.ShowMessageBox(msg, ClientResources.GetString(StringKey.GameTitle));
                OnCanceled();
            }
            this.City = this.DiplomaticTie.ForeignCountry.CapitalCity;
            EspionageResult result = this.DiplomaticTie.StealTechnology();
            string          text   = string.Empty;

            switch (result)
            {
            case EspionageResult.Failure:
                text = ClientResources.GetString("stealtechnology_failure");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name);
                break;

            case EspionageResult.ImmuneToEspionage:
                text = ClientResources.GetString("stealtechnology_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Adjective);
                break;

            case EspionageResult.SpyCaught:
                text = ClientResources.GetString("stealtechnology_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;

            case EspionageResult.Success:
                text = ClientResources.GetString("stealtechnology_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Noun);
                break;
            }

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
        /// <summary>
        /// Attempts to get a foreign city to defect to the parent country by
        /// spreading propaganda.  Cities in anarchy are immune to proaganda.
        /// </summary>
        /// <param name="foreignCity"></param>
        /// <returns></returns>
        public EspionageResult SpreadPropaganda(City foreignCity)
        {
            if (!this.hasEmbassy)
            {
                throw new InvalidOperationException(ServerResources.EmbassyRequired);
            }
            if (!this.hasSpy)
            {
                throw new InvalidOperationException(ServerResources.SpyRequired);
            }
            //TODO: add code to account for continued resistance.
            //TODO: add code to account for more advanced governments.
            if (foreignCity == null)
            {
                throw new ArgumentNullException("foreignCity");
            }
            CulturalPerception perception;
            EspionageResult    result = EspionageResult.Failure;
            bool propogandaSpread;
            int  chanceForPropaganda          = 0;
            int  chanceForResistance          = 0;
            int  chanceForContinuedResistance = 0;

            //a quick check: if the foreign city is in anarchy,
            //the proganda campaign will automatically fail
            //(although there is no chance the spy will be caught).
            if (this.foreignCountry.Government.Fallback)
            {
                result = EspionageResult.Failure;
                return(result);
            }

            //there are 2 steps to taking over a city with propaganda.  The
            //first step is successfully spreading propaganda, and the second
            //step is not having that proaganda resisted.  These two taken
            //together make it very difficult for overall proaganda to succeed.
            perception = this.foreignCountry.GetCulturalPerception(this.parentCountry);

            switch (perception)
            {
            case CulturalPerception.InAwe:
                chanceForPropaganda          = 30;
                chanceForResistance          = 40;
                chanceForContinuedResistance = 30;
                break;

            case CulturalPerception.Admirer:
                chanceForPropaganda          = 25;
                chanceForResistance          = 50;
                chanceForContinuedResistance = 40;
                break;

            case CulturalPerception.Impressed:
                chanceForPropaganda          = 20;
                chanceForResistance          = 60;
                chanceForContinuedResistance = 50;
                break;

            case CulturalPerception.Unimpressed:
                chanceForPropaganda          = 10;
                chanceForResistance          = 70;
                chanceForContinuedResistance = 60;
                break;

            case CulturalPerception.Dismissive:
                chanceForPropaganda          = 5;
                chanceForResistance          = 80;
                chanceForContinuedResistance = 70;
                break;

            case CulturalPerception.Disdainful:
                chanceForPropaganda          = 3;
                chanceForResistance          = 90;
                chanceForContinuedResistance = 80;
                break;
            }

            int randNum = RandomNumber.Between(1, 100);

            if (randNum <= chanceForPropaganda)
            {
                propogandaSpread = true;
            }
            else
            {
                propogandaSpread = false;
                result           = EspionageResult.Failure;
            }

            if (propogandaSpread)
            {
                randNum = RandomNumber.Between(1, 100);
                if (randNum <= chanceForResistance)
                {
                    result = EspionageResult.Failure;
                }
                else
                {
                    //the propaganda was successfull.  The city now belongs
                    //to the parent.
                    result = EspionageResult.Success;
                    this.parentCountry.Cities.Add(foreignCity);
                    this.foreignCountry.Cities.Remove(foreignCity);
                    foreignCity.ParentCountry = this.parentCountry;
                }
            }

            if (result == EspionageResult.Failure)
            {
                //spy caught?
                randNum = RandomNumber.Between(1, 100);
                if (randNum >= 50)
                {
                    result = EspionageResult.SpyCaught;
                    this.foreignCountry.CaptureSpy(this, EspionageAction.SpreadPropaganda, false, foreignCity);
                    this.hasSpy = false;
                }
            }

            return(result);
        }
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            ClientApplication    ca     = ClientApplication.Instance;
            IDiplomaticTiePicker picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));

            picker.PickerTitle = ClientResources.GetString("exposespy_tiePickerTitle");
            Collection <DiplomaticTie> ties = new Collection <DiplomaticTie>();

            foreach (DiplomaticTie t in ca.Player.DiplomaticTies)
            {
                //TODO:  account for needed improvements
                if (t.HasEmbassy)
                {
                    ties.Add(t);
                }
            }
            picker.InitializePicker(ties);
            picker.ShowSimilizationControl();
            this.DiplomaticTie = picker.DiplomaticTie;
            IGameWindow gw = ClientApplication.Instance.GameWindow;

            this.City = this.DiplomaticTie.ForeignCountry.CapitalCity;
            EspionageResult result = this.DiplomaticTie.ExposeSpy();
            string          text   = string.Empty;

            switch (result)
            {
            case EspionageResult.ImmuneToEspionage:
                text = ClientResources.GetString("exposespy_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName,
                    ClientApplication.Instance.Player.CapitalCity.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;

            case EspionageResult.SpyCaught:
                text = ClientResources.GetString("exposespy_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;

            case EspionageResult.Success:
                text = ClientResources.GetString("exposespy_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text, this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName,
                    ClientApplication.Instance.Player.CapitalCity.Name);
                break;

            case EspionageResult.SuccessWithCapturedSpy:
                text = ClientResources.GetString("exposespy_success_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    ClientApplication.Instance.Player.CapitalCity.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;
            }

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
Beispiel #7
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();

            string cityPickerTitle = ClientResources.GetString("sabotage_cityPickerTitle");

            SelectCity(cityPickerTitle);
            if (this.City == null)
            {
                OnCanceled();
                return;
            }
            BuildableItem   improvement = this.City.NextImprovement;
            EspionageResult result      = this.DiplomaticTie.Sabotage(this.City);
            string          text        = string.Empty;

            switch (result)
            {
            case EspionageResult.Failure:
                break;

            case EspionageResult.ImmuneToEspionage:
                text = ClientResources.GetString("sabotage_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Adjective);
                break;

            case EspionageResult.SpyCaught:
                text = ClientResources.GetString("sabotage_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;

            case EspionageResult.Success:
                text = ClientResources.GetString("sabotage_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    improvement.Name);
                break;

            case EspionageResult.SuccessWithCapturedSpy:
                text = ClientResources.GetString("sabotage_success_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    improvement.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;
            }
            IGameWindow gw = ClientApplication.Instance.GameWindow;

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
Beispiel #8
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication ca        = ClientApplication.Instance;
            bool hasValidTies           = false;
            IDiplomaticTiePicker picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));

            picker.PickerTitle = ClientResources.GetString("plantSpy_tiePickerTitle");
            Collection <DiplomaticTie> ties = new Collection <DiplomaticTie>();

            foreach (DiplomaticTie t in ca.Player.DiplomaticTies)
            {
                //TODO:  account for needed improvements
                if (t.HasEmbassy)
                {
                    hasValidTies = true;
                    if (!t.HasSpy)
                    {
                        ties.Add(t);
                    }
                }
            }
            if (ties.Count == 0 && hasValidTies)
            {
                //all the valid civs already have spys.
                string msg = ClientResources.GetString("plantSpy_spysExists");
                ca.GameWindow.ShowMessageBox(msg, ClientResources.GetString(StringKey.GameTitle));
                OnCanceled();
                return;
            }
            picker.InitializePicker(ties);
            picker.ShowSimilizationControl();
            this.tie = picker.DiplomaticTie;
            EspionageResult result = this.DiplomaticTie.PlantSpy();
            string          text   = string.Empty;

            switch (result)
            {
            case EspionageResult.Success:
                text = ClientResources.GetString("plantspy_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.CapitalCity.Name);
                break;

            case EspionageResult.Failure:
                text = ClientResources.GetString("plantspy_failure");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.CapitalCity.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;
            }
            IGameWindow gw = ClientApplication.Instance.GameWindow;

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }