private static void Postfix(MobileParty mobileParty, PartyThinkParams p)
        {
            Hero owner = mobileParty.Party.Owner;

            if (mobileParty?.LeaderHero == null)
            {
                return;
            }
            Equipment owner_equipment   = owner.BattleEquipment;
            float     total_owner_armor = owner_equipment.GetHeadArmorSum() + owner_equipment.GetHumanBodyArmorSum() +
                                          owner_equipment.GetLegArmorSum() + owner_equipment.GetArmArmorSum();
            Equipment leader_equipment   = owner.BattleEquipment;
            float     total_leader_armor = leader_equipment.GetHeadArmorSum() + leader_equipment.GetHumanBodyArmorSum() +
                                           leader_equipment.GetLegArmorSum() + leader_equipment.GetArmArmorSum();

            if (total_owner_armor < 9000)
            {
                return;
            }
            foreach (KeyValuePair <AIBehaviorTuple, float> keyValuePair in p.AIBehaviorScores.ToList())
            {
                float     value  = keyValuePair.Value;
                IMapPoint target = keyValuePair.Key.Party;
                if (keyValuePair.Key.AiBehavior == AiBehavior.GoToSettlement)
                {
                    p.AIBehaviorScores[keyValuePair.Key] = value * 1.7f;
                }
                else if (keyValuePair.Key.AiBehavior == AiBehavior.DefendSettlement || keyValuePair.Key.AiBehavior == AiBehavior.PatrolAroundPoint)
                {
                    if (((Settlement)keyValuePair.Key.Party).OwnerClan == mobileParty.LeaderHero.Clan)
                    {
                        p.AIBehaviorScores[keyValuePair.Key] = value * 1.4f;
                    }
                    else
                    {
                        p.AIBehaviorScores[keyValuePair.Key] = value * 1.4f;
                    }
                }
                else if (keyValuePair.Key.AiBehavior == AiBehavior.BesiegeSettlement || keyValuePair.Key.AiBehavior == AiBehavior.AssaultSettlement)
                {
                    p.AIBehaviorScores[keyValuePair.Key] = value * 2.0f;
                }
                else if (keyValuePair.Key.AiBehavior == AiBehavior.RaidSettlement)
                {
                    p.AIBehaviorScores[keyValuePair.Key] = 0f;
                }
                else if (keyValuePair.Key.AiBehavior == AiBehavior.EngageParty)
                {
                    InformationManager.DisplayMessage(new InformationMessage("EngageParty: " + keyValuePair.Key.Party.Name?.ToString() + " " + keyValuePair.Value));
                }
            }
        }
        private void AiKeepPatrollingPlayerLands(MobileParty mobileParty, PartyThinkParams thoughts)
        {
            Hero companion = mobileParty.LeaderHero;

            if (mobileParty == MobileParty.MainParty ||
                companion == null ||
                !mobileParty.IsLordParty ||
                companion.Clan != Clan.PlayerClan)
            {
                return;
            }

            // backward-compatibility
            if (companion.GetHeroOccupiedEvents().Contains(EvtPatrolLands))
            {
                companion.RemoveEventFromOccupiedHero(EvtPatrolLands);
                companion.HeroDeveloper.SetPropertyValue(CompanionAiPatrolProperty, 1);
            }

            if (mobileParty.Army != null || companion.HeroDeveloper.GetPropertyValue(CompanionAiPatrolProperty) == 0)
            {
                return;
            }

            Settlement target = SettlementHelper.FindNearestSettlementToMapPoint(mobileParty, s => s.OwnerClan == Clan.PlayerClan && s.Notables.Any(n => n.GetRelationWithPlayer() < 1));

            if (target == null)
            {
                target = SettlementHelper.FindNearestSettlementToMapPoint(mobileParty, s => s.OwnerClan == Clan.PlayerClan && s.Notables.Any(n => n.GetRelationWithPlayer() < 51));
                if (target == null)
                {
                    target = SettlementHelper.FindNearestSettlementToMapPoint(mobileParty, s => s.OwnerClan == Clan.PlayerClan);
                    if (target == null)
                    {
                        return;
                    }
                }
            }

            AIBehaviorTuple patrol = new AIBehaviorTuple(target, AiBehavior.PatrolAroundPoint, false);
            float           weight = 0;

            thoughts.AIBehaviorScores.TryGetValue(patrol, out weight);
            thoughts.AIBehaviorScores[patrol] = weight + 0.6f;
        }
Пример #3
0
        private static void Postfix(Army.ArmyTypes missionType, PartyThinkParams p)
        {
            if (missionType != Army.ArmyTypes.Besieger)
            {
                return;
            }
            MobileParty mobilePartyOf = p.MobilePartyOf;

            if (mobilePartyOf?.Army?.LeaderParty != mobilePartyOf || mobilePartyOf?.LeaderHero?.Clan?.Kingdom == null)
            {
                return;
            }
            Dictionary <AIBehaviorTuple, float> dictionary = new Dictionary <AIBehaviorTuple, float>(10);
            float      num1           = 99999f;
            Settlement fromSettlement = mobilePartyOf.LeaderHero.HomeSettlement ?? mobilePartyOf.LastVisitedSettlement;

            if (fromSettlement == null)
            {
                return;
            }
            Settlement settlement = (Settlement)null;

            foreach (KeyValuePair <AIBehaviorTuple, float> aiBehaviorScore in p.AIBehaviorScores)
            {
                if ((double)aiBehaviorScore.Value > 0.0 && aiBehaviorScore.Key.AiBehavior == AiBehavior.BesiegeSettlement && (aiBehaviorScore.Key.Party != null && aiBehaviorScore.Key.Party is Settlement))
                {
                    dictionary.Add(aiBehaviorScore.Key, aiBehaviorScore.Value);
                    float distance = Campaign.Current.Models.MapDistanceModel.GetDistance(fromSettlement, aiBehaviorScore.Key.Party as Settlement);
                    if ((double)distance < (double)num1)
                    {
                        num1       = distance;
                        settlement = aiBehaviorScore.Key.Party as Settlement;
                    }
                }
            }
            foreach (KeyValuePair <AIBehaviorTuple, float> keyValuePair in dictionary)
            {
                Settlement party    = keyValuePair.Key.Party as Settlement;
                float      distance = Campaign.Current.Models.MapDistanceModel.GetDistance(fromSettlement, party);
                float      num2     = keyValuePair.Value * 1.2f * Math.Max(0.0f, (float)(1.0 - ((double)distance - (double)num1) / (party.Culture != mobilePartyOf.LeaderHero.Culture || settlement.Culture == mobilePartyOf.LeaderHero.Culture ? (double)Campaign.AverageDistanceBetweenTwoTowns / 3.0 : (double)Campaign.AverageDistanceBetweenTwoTowns)));
                p.AIBehaviorScores[keyValuePair.Key] = num2;
            }
        }
Пример #4
0
        private static bool Prefix(MobileParty mobileParty, PartyThinkParams p)
        {
            PartyOrder partyOrder;

            if (mobileParty == null)
            {
                partyOrder = (PartyOrder)null;
            }
            else
            {
                Hero leaderHero = mobileParty.LeaderHero;
                partyOrder = leaderHero != null?leaderHero.getOrder() : (PartyOrder)null;
            }
            if (partyOrder == null || mobileParty.Army == null || (mobileParty.Army.LeaderParty == mobileParty || mobileParty.IsDeserterParty) || (mobileParty.LeaderHero.getOrder().AllowJoiningArmies || mobileParty.Army.LeaderParty == Hero.MainHero.PartyBelongedTo))
            {
                return(true);
            }
            mobileParty.Army = (Army)null;
            return(false);
        }
        private static void Postfix(MobileParty mobileParty, PartyThinkParams p)
        {
            PartyOrder partyOrder;

            if (mobileParty == null)
            {
                partyOrder = (PartyOrder)null;
            }
            else
            {
                Hero leaderHero = mobileParty.LeaderHero;
                partyOrder = leaderHero != null?leaderHero.getOrder() : (PartyOrder)null;
            }
            if (partyOrder == null)
            {
                return;
            }
            PartyOrder order = mobileParty.LeaderHero.getOrder();

            foreach (KeyValuePair <AIBehaviorTuple, float> keyValuePair in p.AIBehaviorScores.ToList <KeyValuePair <AIBehaviorTuple, float> >())
            {
                float     num   = keyValuePair.Value;
                IMapPoint party = keyValuePair.Key.Party;
                if (keyValuePair.Key.AiBehavior == AiBehavior.GoToSettlement)
                {
                    if (!order.LeaveTroopsToGarrisonOtherClans)
                    {
                        num *= AiMilitaryBehaviorHourlyTickPatch.getDoNotReplenishGarrisonCorrectionMult(mobileParty, (Settlement)party);
                    }
                    p.AIBehaviorScores[keyValuePair.Key] = num * order.PartyMaintenanceScoreMultiplier;
                }
                else if (keyValuePair.Key.AiBehavior == AiBehavior.DefendSettlement || keyValuePair.Key.AiBehavior == AiBehavior.PatrolAroundPoint)
                {
                    p.AIBehaviorScores[keyValuePair.Key] = ((Settlement)keyValuePair.Key.Party).OwnerClan != mobileParty.LeaderHero.Clan ? num * order.FriendlyVillagesScoreMultiplier : num * order.OwnClanVillagesScoreMultiplier;
                }
                else if (keyValuePair.Key.AiBehavior == AiBehavior.BesiegeSettlement || keyValuePair.Key.AiBehavior == AiBehavior.AssaultSettlement)
                {
                    p.AIBehaviorScores[keyValuePair.Key] = num * order.HostileSettlementsScoreMultiplier;
                }
                else if (keyValuePair.Key.AiBehavior == AiBehavior.RaidSettlement)
                {
                    if (!order.AllowRaidingVillages)
                    {
                        p.AIBehaviorScores[keyValuePair.Key] = 0.0f;
                    }
                }
                else if (keyValuePair.Key.AiBehavior == AiBehavior.EngageParty)
                {
                    InformationManager.DisplayMessage(new InformationMessage("EngageParty: " + keyValuePair.Key.Party.Name?.ToString() + " " + keyValuePair.Value.ToString()));
                }
            }
            if (mobileParty.IsDisbanding)
            {
                mobileParty.LeaderHero.cancelOrder();
            }
            else
            {
                if (order.Behavior == AiBehavior.None)
                {
                    return;
                }
                if (mobileParty.Army != null && mobileParty.Army.LeaderParty == Hero.MainHero.PartyBelongedTo)
                {
                    mobileParty.LeaderHero.cancelOrder();
                }
                else if (order.Behavior == AiBehavior.PatrolAroundPoint)
                {
                    if (order.TargetSettlement == null)
                    {
                        int num = (int)MessageBox.Show("Patrol target settlement not set, please report this bug to the developer of Party Ai Overhaul.");
                    }
                    AIBehaviorTuple key = new AIBehaviorTuple((IMapPoint)order.TargetSettlement, order.Behavior);
                    if (p.AIBehaviorScores.ContainsKey(key))
                    {
                        p.AIBehaviorScores[key] = order.getScore(p.AIBehaviorScores[key]);
                    }
                    else
                    {
                        p.AIBehaviorScores.Add(key, order.getScore());
                    }
                }
                else
                {
                    if (order.Behavior != AiBehavior.EscortParty)
                    {
                        return;
                    }
                    AIBehaviorTuple key = new AIBehaviorTuple((IMapPoint)order.TargetParty, order.Behavior);
                    if (p.AIBehaviorScores.ContainsKey(key))
                    {
                        p.AIBehaviorScores[key] = order.getScore(p.AIBehaviorScores[key]);
                    }
                    else
                    {
                        p.AIBehaviorScores.Add(key, order.getScore());
                    }
                    if ((double)order.ScoreMinimum <= 1.0 || order.TargetParty != Hero.MainHero.PartyBelongedTo || mobileParty.GetNumDaysForFoodToLast() >= 3)
                    {
                        return;
                    }
                    InformationManager.DisplayMessage(new InformationMessage(mobileParty.Name?.ToString() + " is short on food.", Colors.Red));
                }
            }
        }