public static List <PrisonerInfo> GetPrisonersInSettlement(SettlementComponent sc)
        {
            List <PartyBase> list = new List <PartyBase>
            {
                sc.Owner
            };

            foreach (MobileParty mobileParty in sc.Owner.Settlement.Parties)
            {
                if (mobileParty.IsCommonAreaParty || mobileParty.IsGarrison)
                {
                    list.Add(mobileParty.Party);
                }
            }
            List <PrisonerInfo> list2 = new List <PrisonerInfo>();

            foreach (PartyBase partyBase in list)
            {
                for (int i = 0; i < partyBase.PrisonRoster.Count; i++)
                {
                    list2.Add(new PrisonerInfo()
                    {
                        prisoner   = partyBase.PrisonRoster.GetCharacterAtIndex(i),
                        count      = partyBase.PrisonRoster.GetTroopCount(partyBase.PrisonRoster.GetCharacterAtIndex(i)),
                        ownerParty = partyBase
                    });
                }
            }
            return(list2);
        }
Exemple #2
0
        public CEBrothelClanFinanceItemVM(CEBrothel brothel, Workshop workshop, Action <ClanFinanceIncomeItemBaseVM> onSelection, Action onRefresh) : base(workshop, onSelection, onRefresh)
        {
            _brothel = brothel;

            IncomeTypeAsEnum = IncomeTypes.Workshop;
            SettlementComponent component = _brothel.Settlement.GetComponent <SettlementComponent>();

            ImageName = component != null ? component.WaitMeshName : "";
            RefreshValues();
        }
        public static int GetGarrisonCountInSettlement(SettlementComponent sc)
        {
            int returned = 0;

            foreach (MobileParty mobileParty in sc.Owner.Settlement.Parties)
            {
                if (mobileParty.IsCommonAreaParty || mobileParty.IsGarrison)
                {
                    returned += mobileParty.MemberRoster.TotalManCount;
                }
            }
            return(returned);
        }
        public GrantFiefItemVM(Settlement settlement, Hero targetHero, Action <GrantFiefItemVM> onSelect)
        {
            this.Settlement = settlement;
            this.Name       = settlement.Name.ToString();
            SettlementComponent component = settlement.GetComponent <SettlementComponent>();

            this.SettlementImagePath = ((component == null) ? "placeholder" : (component.BackgroundMeshName + "_t"));
            Town component2 = settlement.GetComponent <Town>();

            if (component2 != null)
            {
                this.Prosperity = MBMath.Round(component2.Prosperity);
                this.IconPath   = component2.BackgroundMeshName;
            }
            else if (settlement.IsCastle)
            {
                this.Prosperity = MBMath.Round(settlement.Prosperity);
                this.IconPath   = "";
            }
            this.Garrison      = this.Settlement.Town.GarrisonParty?.Party.NumberOfAllMembers ?? 0;
            this._onSelect     = onSelect;
            this.RelationBonus = String.Concat(new string[] { GrantFiefAction.PreviewPositiveRelationChange(this.Settlement, targetHero).ToString(), "+" });
        }
        public static void OnSettlementEntered(MobileParty mobileParty, Settlement settlement, Hero hero)
        {
            if (!Campaign.Current.GameStarted)
            {
                return;
            }

            SettlementComponent component = settlement.GetComponent <SettlementComponent>();

            if (mobileParty != null &&
                mobileParty != MobileParty.MainParty &&
                mobileParty.IsLordParty &&
                !mobileParty.IsDisbanding &&
                mobileParty.LeaderHero != null &&
                mobileParty.LeaderHero.MapFaction.IsKingdomFaction &&
                FactionManager.IsAlliedWithFaction(mobileParty.MapFaction, settlement.MapFaction) &&
                component.IsOwnerUnassigned &&
                settlement.OwnerClan == Clan.PlayerClan &&
                settlement.IsFortification)
            {
                float currentTime = Campaign.CurrentTime;
                float num         = mobileParty.LeaderHero.VisitedSettlements.ContainsKey(settlement) ? mobileParty.LeaderHero.VisitedSettlements[settlement] : 0f;
                if (currentTime - num > 12f)
                {
                    BasicCharacterObject tmp = Game.Current.PlayerTroop;
                    Game.Current.PlayerTroop = mobileParty.Leader;
                    int num2 = Campaign.Current.Models.SettlementGarrisonModel.FindNumberOfTroopsToLeaveToGarrison(mobileParty, mobileParty.CurrentSettlement);
                    Game.Current.PlayerTroop = tmp;
                    if (num2 > 0)
                    {
                        LeaveTroopsToSettlementAction.Apply(mobileParty, settlement, num2, true);
                        return;
                    }
                }
            }
        }
        private void OnSettlementEntered(MobileParty party, Settlement settlement, Hero hero)
        {
            if (party?.LeaderHero == null || !settlement.IsTown && !settlement.IsVillage || !party.IsLordParty && !party.IsCaravan)
            {
                return;
            }
            Dictionary <ItemCategory, int> dictionary1 = new Dictionary <ItemCategory, int>(5);
            MobileParty mobileParty = party;
            TroopRoster troopRoster1;

            if (mobileParty == null)
            {
                troopRoster1 = (TroopRoster)null;
            }
            else
            {
                Hero leaderHero = mobileParty.LeaderHero;
                troopRoster1 = leaderHero != null?leaderHero.getTemplate() : (TroopRoster)null;
            }
            TroopRoster troopRoster2 = troopRoster1;
            Town        town         = (Town)null;

            if (settlement.IsTown)
            {
                town = settlement.GetComponent <Town>();
            }
            foreach (TroopRosterElement troopRosterElement in party.MemberRoster)
            {
                int val1 = troopRosterElement.NumberReadyToUpgrade;
                if (val1 > 0)
                {
                    foreach (CharacterObject upgradeTarget in troopRosterElement.Character.UpgradeTargets)
                    {
                        ItemCategory itemFromCategory = upgradeTarget.UpgradeRequiresItemFromCategory;
                        if ((town == null || town.MarketData.GetItemCountOfCategory(itemFromCategory) != 0) && itemFromCategory != null)
                        {
                            if (troopRoster2 != (TroopRoster)null)
                            {
                                int troopCount = troopRoster2.GetTroopCount(upgradeTarget);
                                if (troopCount != 0)
                                {
                                    if (troopCount > 1)
                                    {
                                        val1 = Math.Min(val1, troopCount - party.MemberRoster.GetTroopCount(upgradeTarget));
                                        if (val1 <= 0)
                                        {
                                            continue;
                                        }
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            if (dictionary1.ContainsKey(itemFromCategory))
                            {
                                dictionary1[itemFromCategory] += val1;
                            }
                            else
                            {
                                dictionary1[itemFromCategory] = val1;
                            }
                        }
                    }
                }
            }
            if (dictionary1.Count <= 0)
            {
                return;
            }
            if (town != null)
            {
                foreach (ItemCategory key in dictionary1.Keys)
                {
                    if (dictionary1[key] > town.MarketData.GetItemCountOfCategory(key))
                    {
                        dictionary1[key] = town.MarketData.GetItemCountOfCategory(key);
                    }
                }
            }
            Hero leaderHero1 = party.LeaderHero;
            Dictionary <ItemCategory, List <ItemRosterElement> > dictionary2 = new Dictionary <ItemCategory, List <ItemRosterElement> >(dictionary1.Count);
            SettlementComponent market = settlement.GetComponent(typeof(SettlementComponent));

            foreach (ItemRosterElement itemRosterElement in settlement.ItemRoster)
            {
                ItemCategory itemCategory = itemRosterElement.EquipmentElement.Item.ItemCategory;
                if (dictionary1.ContainsKey(itemCategory) && !dictionary2.ContainsKey(itemCategory))
                {
                    dictionary2[itemCategory] = new List <ItemRosterElement>();
                }
                dictionary2[itemCategory].Add(itemRosterElement);
            }
            foreach (KeyValuePair <ItemCategory, List <ItemRosterElement> > keyValuePair in dictionary2)
            {
                foreach (ItemRosterElement subject in keyValuePair.Value.OrderBy <ItemRosterElement, int>((Func <ItemRosterElement, int>)(o => market.GetItemPrice(o.EquipmentElement, party))).ToList <ItemRosterElement>())
                {
                    int num = Math.Min(subject.Amount, dictionary1[keyValuePair.Key]);
                    while (num > 0 && leaderHero1.Gold > market.GetItemPrice(subject.EquipmentElement, party))
                    {
                        SellItemsAction.Apply(settlement.Party, party.Party, subject, 1, settlement);
                        --num;
                        dictionary1[keyValuePair.Key]--;
                    }
                    if (num <= 0)
                    {
                        if (dictionary1[keyValuePair.Key] == 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }