Beispiel #1
0
 void leaderTypeBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     leaderAmountBox.Items.Clear();
     if (leaderTypeBox.SelectedIndex == 0)
     {
         leaderAmountBox.Enabled = false;
         Build.Leader.SetTo(0);
     }
     else
     {
         LeaderType lt = (LeaderType)leaderTypeBox.SelectedItem;
         foreach (var o in lt.values)
         {
             leaderAmountBox.Items.Add(o);
         }
         leaderAmountBox.Enabled = true;
         if (loading)
         {
             leaderAmountBox.SelectedIndex = lt.values.FindIndex(l => l.value == Build.Leader.Sum());
         }
         else
         {
             leaderAmountBox.SelectedIndex = 0;
         }
     }
 }
Beispiel #2
0
        internal override void Export(string table)
        {
            var vals = new List <object>
            {
                Name.DBExport(),
                Hf.DBExport(),
                LeaderType.DBExport(LeaderTypes),
                Race.DBExport(),
                Birth.DBExport(true),
                Birth.DBExport(false),
                Death.DBExport(true),
                Death.DBExport(false),
                ReignBegan.DBExport(true),
                Inheritance.DBExport(InheritanceTypes),
                InheritedFromSource.ToString(),
                InheritedFrom.DBExport(),
                Civilization.DBExport(),
                Site.DBExport(),
                Worship == null ? DBNull.Value : Worship.Name.DBExport(),
                WorshipPercent,
                Spouse.DBExport()
            };

            Database.ExportWorldItem(table, vals);
        }
        private void mod_Resolve(int checkMargin, AlignmentMaskType alignment, LeaderType type)
        {
            if (!KingmakerPatchSettings.KingdomAlignment.Enabled && !KingmakerPatchSettings.KingdomEvents.MaximumEffort)
            {
                this.source_Resolve(checkMargin, alignment, type);
                return;
            }

            if (KingmakerPatchSettings.KingdomAlignment.Enabled)
            {
                string alignmentString = KingmakerPatchSettings.KingdomAlignment.Alignment.ToLowerInvariant();
                alignment = new_GetAlignment(alignmentString) ?? alignment;
            }

            if (!KingmakerPatchSettings.KingdomEvents.MaximumEffort)
            {
                this.source_Resolve(checkMargin, alignment, type);
                return;
            }

            EventResult.MarginType overrideMargin = this.new_GetOverrideMargin();

            if (overrideMargin == EventResult.MarginType.Success || overrideMargin == EventResult.MarginType.GreatSuccess)
            {
                checkMargin = EventResult.MarginToInt(overrideMargin);
            }

            this.source_Resolve(checkMargin, alignment, type);
        }
        public Task <LeaderPipResult> CalculateAverageLeaderPipsAsync(
            double tradition,
            LeaderType leaderType,
            ILeaderPipDistributionStrategy leaderPipDistributionStrategy,
            LeaderPipModifiers leaderPipModifiers = null)
        {
            double effectiveTradition = CalculateEffectiveTradition(tradition, leaderType);

            return(CalculateAndDistributePips(leaderPipDistributionStrategy, leaderPipModifiers, effectiveTradition));
        }
        private double CalculateEffectiveTradition(double tradition, LeaderType leaderType)
        {
            switch (leaderType)
            {
            case LeaderType.General:
            case LeaderType.Admiral:
                return(tradition);

            case LeaderType.Conquistador:
            case LeaderType.Explorer:
                return(0.8 * tradition);

            default:
                throw new ArgumentException($"Unknown leader type: {leaderType.ToString()}");
            }
        }
 static string FormatResult(KingdomEvent kingdomEvent, EventResult.MarginType margin, AlignmentMaskType alignment, LeaderType leaderType)
 {
     string text = "";
     var statChanges = CalculateEventResult(kingdomEvent, margin, alignment, leaderType);
     var statChangesText = statChanges.ToStringWithPrefix(" ");
     text += string.Format("{0}:{1}",
         margin,
         statChangesText == "" ? " No Change" : statChangesText);
     //TODO: Solution for presenting actions
     text += "\n";
     return text;
 }
        public static KingdomStats.Changes CalculateEventResult(KingdomEvent kingdomEvent, EventResult.MarginType margin, AlignmentMaskType alignment, LeaderType leaderType)
        {
            var checkMargin = EventResult.MarginToInt(margin);
            var result = new KingdomStats.Changes();
            var m_TriggerChange = Traverse.Create(kingdomEvent).Field("m_TriggerChange").GetValue<KingdomStats.Changes>();
            var m_SuccessCount = Traverse.Create(kingdomEvent).Field("m_SuccessCount").GetValue<int>();
            BlueprintKingdomEvent blueprintKingdomEvent = kingdomEvent.EventBlueprint as BlueprintKingdomEvent;
            if (blueprintKingdomEvent && blueprintKingdomEvent.UnapplyTriggerOnResolve && m_TriggerChange != null)
            {
                result.Accumulate(m_TriggerChange.Opposite(), 1);
            }
            var resolutions = kingdomEvent.EventBlueprint.Solutions.GetResolutions(leaderType);
            if (resolutions == null) resolutions = Array.Empty<EventResult>();
            foreach (var eventResult in resolutions)
            {
                var validConditions = eventResult.Condition == null || eventResult.Condition.Check(kingdomEvent.EventBlueprint);
                if (eventResult.MatchesMargin(checkMargin) && (alignment & eventResult.LeaderAlignment) != AlignmentMaskType.None && validConditions)
                {
                    result.Accumulate(eventResult.StatChanges, 1);
                    m_SuccessCount += eventResult.SuccessCount;
                }
            }
            if(checkMargin >= 0 && blueprintKingdomEvent != null)
            {
                result.Accumulate((KingdomStats.Type)leaderType, Game.Instance.BlueprintRoot.Kingdom.StatIncreaseOnEvent);
            }
            bool willBeFinished = true;
            if(blueprintKingdomEvent != null && blueprintKingdomEvent.IsRecurrent)
            {
                willBeFinished = m_SuccessCount >= blueprintKingdomEvent.Solutions.GetSuccessCount(leaderType);
            }
            if (willBeFinished)
            {
                var eventFinalResults = kingdomEvent.EventBlueprint.GetComponent<EventFinalResults>();
                if(eventFinalResults != null && eventFinalResults.Results != null)
                {
                    foreach(var eventResult in eventFinalResults.Results)
                    {
                        var validConditions = eventResult.Condition == null || eventResult.Condition.Check(kingdomEvent.EventBlueprint);
                        if (eventResult.MatchesMargin(checkMargin) && (alignment & eventResult.LeaderAlignment) != AlignmentMaskType.None && validConditions)
                        {
                            result.Accumulate(eventResult.StatChanges, 1);
                        }
                    }
                }
            }
            return result;

        }
            static void Postfix(KingdomUIEventWindow __instance, KingdomEventUIView kingdomEventView)
            {
                try
                {
                    if (!Main.enabled) return;
                    if (!Main.settings.previewEventResults) return;
                    if (kingdomEventView.Task == null || kingdomEventView.Task.Event == null)
                    {
                        return; //Task is null on event results;
                    }
                    //Calculate results for current leader
                    var solutionText = Traverse.Create(__instance).Field("m_Description").GetValue<TextMeshProUGUI>();
                    solutionText.text += "\n";
                    var leader = kingdomEventView.Task.AssignedLeader;
                    if (leader == null)
                    {
                        solutionText.text += "<size=75%>Select a leader to preview results</size>";
                        return;
                    }
                    var blueprint = kingdomEventView.Blueprint;
                    var solutions = blueprint.Solutions;
                    var resolutions = solutions.GetResolutions(leader.Type);
                    solutionText.text += "<size=75%>";

                    var leaderAlignmentMask = leader.LeaderSelection.Alignment.ToMask();
                    bool isValid(EventResult result) => (leaderAlignmentMask & result.LeaderAlignment) != AlignmentMaskType.None;
                    var validResults = resolutions.Where(isValid);
                    solutionText.text += "Leader " + leader.LeaderSelection.CharacterName + " - Alignment " + leaderAlignmentMask + "\n";
                    foreach (var eventResult in validResults)
                    {
                        solutionText.text += FormatResult(kingdomEventView.Task.Event, eventResult.Margin, leaderAlignmentMask, leader.Type);
                    }
                    //Calculate best result
                    int bestResult = 0;
                    KingdomStats.Changes bestEventResult = null;
                    LeaderType bestLeader = 0;
                    AlignmentMaskType bestAlignment = 0;
                    foreach (var solution in solutions.Entries)
                    {
                        if (!solution.CanBeSolved) continue;
                        foreach(var alignmentMask in solution.Resolutions.Select(s => s.LeaderAlignment).Distinct())
                        {
                            var eventResult = CalculateEventResult(kingdomEventView.Task.Event, EventResult.MarginType.GreatSuccess, alignmentMask, solution.Leader);
                            int sum = 0;
                            for (int i = 0; i < 10; i++) sum += eventResult[(KingdomStats.Type)i];
                            if (sum > bestResult)
                            {
                                bestResult = sum;
                                bestLeader = solution.Leader;
                                bestEventResult = eventResult;
                                bestAlignment = alignmentMask;
                            }
                        }
                    }

                    if (bestEventResult != null)
                    {
                        solutionText.text += "<size=50%>\n<size=75%>";
                        solutionText.text += "Best Result: Leader " + bestLeader + " - Alignment " + bestAlignment + "\n";
                        if (bestLeader == leader.Type && (leaderAlignmentMask & bestAlignment) != AlignmentMaskType.None)
                        {
                            solutionText.text += "<color=#308014>";
                        }
                        else
                        {
                            solutionText.text += "<color=#808080>";
                        }
                        solutionText.text += FormatResult(kingdomEventView.Task.Event, EventResult.MarginType.GreatSuccess, bestAlignment, bestLeader);
                        solutionText.text += "</color>";
                    }
                    solutionText.text += "</size>";
                }

                catch (Exception ex)
                {
                    Main.Error(ex);
                }
            }
        /// <summary>
        /// Fills the database with default data.
        /// </summary>
        /// <param name="context">The dbcontext to use.</param>
        /// <returns>The task representing the operation.</returns>
        public static async Task FillWithDefaultAsync(this UnderSeaDatabaseContext context)
        {
            // Effects, Buildings, researches
            // áramlásirányító
            var popIn = new Effect {
                Name = KnownValues.PopulationIncrease, Value = 50
            };
            var cp = new Effect {
                Name = KnownValues.CoralProductionIncrease, Value = 200
            };
            var currentController = new BuildingType {
                CostPearl = 1000, CostCoral = 0, BuildTime = 5, MaxCount = -1
            };

            // zátonyvár
            var bsIn = new Effect {
                Name = KnownValues.BarrackSpaceIncrease, Value = 200
            };
            var reefCastle = new BuildingType {
                CostPearl = 1000, CostCoral = 0, BuildTime = 5, MaxCount = -1
            };

            // Iszaptraktor
            var harvMod1 = new Effect {
                Name = KnownValues.HarvestModifier, Value = 0.1
            };
            var mudT = new ResearchType {
                CostPearl = 1000, CostCoral = 0, ResearchTime = 15, MaxCompletedAmount = 1
            };

            // Iszapkombájn
            var harvMod2 = new Effect {
                Name = KnownValues.HarvestModifier, Value = 0.15
            };
            var mudC = new ResearchType {
                CostPearl = 1000, CostCoral = 0, ResearchTime = 15, MaxCompletedAmount = 1
            };

            // korallfal
            var defMod1 = new Effect {
                Name = KnownValues.UnitDefenseModifier, Value = 0.2
            };
            var wall = new ResearchType {
                CostPearl = 1000, CostCoral = 0, ResearchTime = 15, MaxCompletedAmount = 1
            };

            // Szonárágyú
            var attMod1 = new Effect {
                Name = KnownValues.UnitAttackModifier, Value = 0.2
            };
            var canon = new ResearchType {
                CostPearl = 1000, CostCoral = 0, ResearchTime = 15, MaxCompletedAmount = 1
            };

            // Harcművészet
            var combModA = new Effect {
                Name = KnownValues.UnitAttackModifier, Value = 0.1
            };
            var combModD = new Effect {
                Name = KnownValues.UnitDefenseModifier, Value = 0.1
            };
            var martialArts = new ResearchType {
                CostPearl = 1000, CostCoral = 0, ResearchTime = 15, MaxCompletedAmount = 1
            };

            // Alchemy
            var taxMod1 = new Effect {
                Name = KnownValues.TaxationModifier, Value = 0.3
            };
            var alchemy = new ResearchType {
                CostPearl = 1000, CostCoral = 0, ResearchTime = 15, MaxCompletedAmount = 1
            };


            // Add effects, buildings, researches
            context.Effects.AddRange(popIn, cp, bsIn, harvMod1, harvMod2,
                                     defMod1, attMod1, combModA, combModD, taxMod1);
            context.BuildingTypes.AddRange(currentController, reefCastle);
            context.ResearchTypes.AddRange(mudT, mudC, wall, canon, martialArts, alchemy);
            await context.SaveChangesAsync();


            // Add effects to buildings and researches
            context.BuildingEffects.AddRange(
                new BuildingEffect {
                Building = currentController, Effect = popIn
            },
                new BuildingEffect {
                Building = currentController, Effect = cp
            },
                new BuildingEffect {
                Building = reefCastle, Effect = bsIn
            });

            context.ResearchEffects.AddRange(
                new ResearchEffect {
                Research = mudT, Effect = harvMod1
            },
                new ResearchEffect {
                Research = mudC, Effect = harvMod2
            },
                new ResearchEffect {
                Research = wall, Effect = defMod1
            },
                new ResearchEffect {
                Research = canon, Effect = attMod1
            },
                new ResearchEffect {
                Research = martialArts, Effect = combModA
            },
                new ResearchEffect {
                Research = martialArts, Effect = combModD
            },
                new ResearchEffect {
                Research = alchemy, Effect = taxMod1
            });
            await context.SaveChangesAsync();


            // Add units
            // rohamfóka
            var seal = new UnitType
            {
                AttackPower = 6, DefensePower = 2, CostPearl = 50, CostCoral = 0, MaintenancePearl = 1, MaintenanceCoral = 1
            };
            // csatacsikó
            var pony = new UnitType
            {
                AttackPower = 2, DefensePower = 6, CostPearl = 50, CostCoral = 0, MaintenancePearl = 1, MaintenanceCoral = 1
            };
            // lézercápa
            var lazor = new UnitType
            {
                AttackPower = 5, DefensePower = 5, CostPearl = 100, CostCoral = 0, MaintenancePearl = 3, MaintenanceCoral = 2
            };
            // hadvezér
            var leader = new LeaderType
            {
                AttackPower = 0, DefensePower = 0, CostPearl = 400, CostCoral = 0, MaintenancePearl = 4, MaintenanceCoral = 2
            };

            context.UnitTypes.AddRange(seal, pony, lazor, leader);
            await context.SaveChangesAsync();


            // Add events
            var plague        = new RandomEvent();
            var removeCurrent = new Effect
            {
                TargetId = currentController.Id, Name = KnownValues.AddBuildingEffect, Value = -1
            };

            var fire         = new RandomEvent();
            var removeCastle = new Effect
            {
                TargetId = reefCastle.Id, Name = KnownValues.AddBuildingEffect, Value = -1
            };

            var mine     = new RandomEvent();
            var addPearl = new Effect
            {
                Value = 1000, Name = KnownValues.PearlProductionIncrease
            };

            var goodHarvest = new RandomEvent();
            var extraCoral  = new Effect
            {
                Name = KnownValues.BuildingProductionIncrease, Value = 50
            };

            var badHarvest = new RandomEvent();
            var lessCoral  = new Effect
            {
                Name = KnownValues.BuildingProductionIncrease, Value = -50
            };

            var contentPopulation = new RandomEvent();
            var addCurrent        = new Effect
            {
                Name = KnownValues.AddBuildingEffect, TargetId = currentController.Id, Value = 1
            };
            var discontentPopulation = new RandomEvent();

            var contentSoldiers = new RandomEvent();
            var addAttack       = new Effect
            {
                Name = KnownValues.IncreaseUnitAttack, Value = 1
            };

            var discontentSoldiers = new RandomEvent();
            var removeAttack       = new Effect
            {
                Name = KnownValues.IncreaseUnitAttack, Value = -1
            };

            await context.SaveChangesAsync();

            // Add event effects
            context.EventEffects.AddRange(
                new EventEffect {
                Effect = removeCurrent, Event = plague
            },
                new EventEffect {
                Effect = removeCastle, Event = fire
            },
                new EventEffect {
                Effect = addPearl, Event = mine
            },
                new EventEffect {
                Effect = extraCoral, Event = goodHarvest
            },
                new EventEffect {
                Effect = lessCoral, Event = badHarvest
            },
                new EventEffect {
                Effect = addCurrent, Event = contentPopulation
            },
                new EventEffect {
                Effect = removeCurrent, Event = discontentPopulation
            },
                new EventEffect {
                Effect = addAttack, Event = contentSoldiers
            },
                new EventEffect {
                Effect = removeAttack, Event = discontentSoldiers
            }
                );
            await context.SaveChangesAsync();


            // Add contents
            var currentCont = new BuildingContent
            {
                Parent       = currentController,
                Name         = "Áramlásirányító",
                Description  = "+50 lakos, 200 korall / kör",
                ImageUrl     = "images/static/buildings/aramlasiranyito-lg.png",
                IconImageUrl = "images/static/buildings/aramlasiranyito-icon.png"
            };

            var reefCastCont = new BuildingContent
            {
                Parent       = reefCastle,
                Name         = "Zátonyvár",
                Description  = "+200 szállás",
                ImageUrl     = "images/static/buildings/zatonyvar-lg.png",
                IconImageUrl = "images/static/buildings/zatonyvar-icon.png"
            };

            context.BuildingContents.AddRange(currentCont, reefCastCont);

            var sealCont = new UnitContent
            {
                Parent       = seal,
                Name         = "Rohamfóka",
                Description  = "Jól támad de rosszul véd",
                ImageUrl     = "images/static/units/rohamfoka.svg",
                IconImageUrl = "images/static/units/rohamfoka.svg"
            };
            var ponyCont = new UnitContent
            {
                Parent       = pony,
                Name         = "Csatacsikó",
                Description  = "Jól véd de rosszul támad",
                ImageUrl     = "images/static/units/csatacsiko.svg",
                IconImageUrl = "images/static/units/csatacsiko.svg"
            };
            var lazorCont = new UnitContent
            {
                Parent       = lazor,
                Name         = "Lézercápa",
                Description  = "lazers man",
                ImageUrl     = "images/static/units/lezercapa.svg",
                IconImageUrl = "images/static/units/lezercapa.svg"
            };
            var leaderCont = new UnitContent
            {
                Parent      = leader,
                Name        = "Parancsnok",
                Description = "Támadást csak parancsnok tud vezetni",
            };

            context.UnitContents.AddRange(sealCont, ponyCont, lazorCont, leaderCont);

            var mudTCont = new ResearchContent
            {
                Parent       = mudT,
                Name         = "Iszap traktor",
                Description  = "Iszapozza a korallt (amitől amúgy IRL meghalna, korall nem növény nem kell neki föld), +10% korall termelés",
                ImageUrl     = "images/static/researches/iszaptraktor-lg.png",
                IconImageUrl = "images/static/researches/iszaptraktor-sm.png"
            };
            var mudCCont = new ResearchContent
            {
                Parent       = mudC,
                Name         = "Iszap kombájn",
                Description  = "Nagyon iszapozza a korallt, +15% korall termelés",
                ImageUrl     = "images/static/researches/iszapkombajn-lg.png",
                IconImageUrl = "images/static/researches/iszapkombajn-sm.png"
            };
            var defCont = new ResearchContent
            {
                Parent       = wall,
                Name         = "Korallfal",
                Description  = "Fal, korallból. +20% védekezés",
                ImageUrl     = "images/static/buildings/korallfal.svg",
                IconImageUrl = "images/static/buildings/korallfal.svg"
            };
            var attCont = new ResearchContent
            {
                Parent       = canon,
                Name         = "Szonárágyú",
                Description  = "Mint a denevér, echo-lokáció. +20% támadás",
                ImageUrl     = "images/static/researches/szonaragyu-lg.png",
                IconImageUrl = "images/static/researches/szonaragyu-sm.png"
            };
            var cCont = new ResearchContent
            {
                Parent       = martialArts,
                Name         = "Vízalatti harcművészetek",
                Description  = "\"A különbség a lehetetlen és a lehetséges között az egyén akarata.\", +10% védekezés és támadás",
                ImageUrl     = "images/static/buildings/vizalatti-harcmuveszetek.svg",
                IconImageUrl = "images/static/buildings/vizalatti-harcmuveszetek.svg"
            };
            var taxCont = new ResearchContent
            {
                Parent       = alchemy,
                Name         = "Alkímia",
                Description  = "A népesség pénzt csinál, +30% adó bevétel",
                ImageUrl     = "images/static/buildings/alkimia.svg",
                IconImageUrl = "images/static/buildings/alkimia.svg"
            };

            context.ResearchContents.AddRange(mudTCont, mudCCont, defCont, attCont, cCont, taxCont);

            var plagueCont = new EventContent
            {
                Parent      = plague,
                Name        = "Pestis",
                Description = "Az országodban kitört a pestis, elveszítesz 50 embert és egy áramlásirányítót.",
                FlavourText = "Hozzátok a halottakat!"
            };
            var fireCont = new EventContent
            {
                Parent      = fire,
                Name        = "Víz alatti tűz",
                Description = "Az országodban tűz ütött ki és leégett egy zátonyvár.",
                FlavourText = "Tűz víz alatt? Micsoda?!"
            };
            var mineCont = new EventContent
            {
                Parent      = mine,
                Name        = "Aranybánya",
                Description = "Az embereid felfedeztek egy új aranybányát, kapsz 1000 bónusz aranyat.",
                FlavourText = "Nagyon fényes"
            };
            var goodhvCont = new EventContent
            {
                Parent      = goodHarvest,
                Name        = "Jó termés",
                Description = "Minden áramlásirányító +50 korallt ad ebben a körben.",
                FlavourText = "A termés egy stabil ország alapja"
            };
            var badhvCont = new EventContent
            {
                Parent      = badHarvest,
                Name        = "Rossz termés",
                Description = "Minden áramlásirányító -50 korallt ad ebben a körben.",
                FlavourText = "A király lakomázik, a paraszt éhezik"
            };
            var contPopCont = new EventContent
            {
                Parent      = contentPopulation,
                Name        = "Elégedett emberek",
                Description = "Az országodban elégedettek az emberek, ezért extra 50 ember költözött be és építettek maguknak egy áramlásirányítót.",
                FlavourText = "Nő a nép, nő a felelősség"
            };
            var discontPopCont = new EventContent
            {
                Parent      = discontentPopulation,
                Name        = "Elégedetlen emberek",
                Description = "Az országodban elégedetlenek az emberek, ezért 50 ember elköltözött és az áramlásirányítójukat lerombolták.",
                FlavourText = "A paraszt elmegy, pusztítást hagy maga után"
            };
            var contSolCont = new EventContent
            {
                Parent      = contentSoldiers,
                Name        = "Elégedett katonák",
                Description = "Katonáid elégedettek ebben a körben, minden katona támadása nő eggyel.",
                FlavourText = "Elégedett katona motivált katona"
            };
            var disconSolCont = new EventContent
            {
                Parent      = discontentSoldiers,
                Name        = "Elégedetlen katonák",
                Description = "Katonáid elégedetlenek ebben a körben, minden katona támadása csökken eggyel.",
                FlavourText = "Elsőnek a morál, utána a hűség"
            };

            context.EventContents.AddRange(plagueCont, mineCont, fireCont, goodhvCont, badhvCont,
                                           contPopCont, contSolCont, disconSolCont, discontPopCont);
            await context.SaveChangesAsync();


            // globals
            context.GlobalValues.Add(new GlobalValue
            {
                BaseTaxation              = 25,
                Round                     = 1,
                StartingBarrackSpace      = 0,
                StartingCorals            = 2000,
                StartingPearls            = 2000,
                StartingPopulation        = 0,
                LootPercentage            = 0.5,
                UnitLossOnLostBatle       = 0.1,
                RandomEventChance         = 0.1,
                RandomEventGraceTimer     = 10,
                ScoreBuildingMultiplier   = 50,
                ScoreResearchMultiplier   = 100,
                ScorePopulationMultiplier = 1,
                ScoreUnitMultiplier       = 5,
                FirstStartingBuilding     = reefCastle,
                SecondStartingBuilding    = currentController,
                RandomAttackModifier      = 0.1
            });
            await context.SaveChangesAsync();
        }
 private void source_Resolve(int checkMargin, AlignmentMaskType alignment, LeaderType type)
 {
     throw new DeadEndException("source_Resolve");
 }