namespace TaleWorlds.CampaignSystem
{
[SaveableClass(20256)]
public abstract class SettlementComponent : MBObjectBase
{
[SaveableEnum(20653)]
public enum ProsperityLevel
{
Low,
Mid,
High,
NumberOfLevels
}
[SaveableEnum(20654)]
public enum ManagmentType
{
Tax,
Militia,
Project
}
public static int NumberOfWorkshopSpotsAtTown = 9;
[SaveableField(55)]
public static int NumberOfWorkshopSpotsAtVillage = 4;
[SaveableField(56)]
public bool IsTaken;
private PartyBase _owner;
protected const int UnrestMilitiaAddition = 200;
[SaveableField(58)]
public Settlement TradeBound;
[SaveableProperty(50)]
public int Gold
{
get;
private set;
}
public float BackgroundCropPosition
{
get;
protected set;
}
public string BackgroundMeshName
{
get;
protected set;
}
public string WaitMeshName
{
get;
protected set;
}
public string CastleBackgroundMeshName
{
get;
protected set;
}
public PartyBase Owner
{
get
{
return _owner;
}
internal set
{
if (_owner != value)
{
if (_owner != null)
{
_owner.ItemRoster.RosterUpdatedEvent -= OnInventoryUpdated;
}
_owner = value;
if (_owner != null)
{
_owner.ItemRoster.RosterUpdatedEvent += OnInventoryUpdated;
}
}
}
}
public Settlement Settlement => _owner.Settlement;
public TextObject Name => Owner.Name;
public virtual bool IsTown => false;
public virtual bool IsCastle => false;
public virtual ProsperityLevel GetProsperityLevel()
{
return ProsperityLevel.Mid;
}
protected abstract void OnInventoryUpdated(ItemRosterElement item, int count);
public virtual void OnPartyEntered(MobileParty mobileParty)
{
mobileParty.Ai.SetAIState(AIState.Undefined);
}
public virtual void OnPartyLeft(MobileParty mobileParty)
{
}
public virtual void OnStart()
{
}
public virtual void OnInit()
{
}
public virtual void DecideOwnerFaction()
{
}
public virtual void OnFinishLoadState()
{
}
public virtual float GetNeededWallScoreForNextLevel()
{
return 0f;
}
public void ChangeGold(int changeAmount)
{
Gold += changeAmount;
if (Gold < 0)
{
Gold = 0;
}
}
public virtual int GetMaximumTroopNumber()
{
return 0;
}
public int GetNumberOfTroops()
{
int num = 0;
foreach (MobileParty party in Owner.Settlement.Parties)
{
if (party.IsMilitia || party.IsGarrison)
{
num += party.Party.NumberOfAllMembers;
}
}
return num;
}
public override void Deserialize(MBObjectManager objectManager, XmlNode node)
{
base.Deserialize(objectManager, node);
}
public virtual int GetItemPrice(ItemObject item, MobileParty tradingParty = null, bool isSelling = false)
{
return 0;
}
public virtual int GetItemPrice(ItemRosterElement itemRosterElement, MobileParty tradingParty = null, bool isSelling = false)
{
return 0;
}
public virtual string OnGetInfoText()
{
return "";
}
public virtual bool OnEncountered(PartyBase defenderParty, ref bool isHandled)
{
isHandled = false;
return false;
}
public virtual void StartRaid(MobileParty party)
{
}
public virtual bool IsAmbush()
{
return false;
}
public virtual bool IsHideout()
{
return false;
}
public virtual bool IsMinorFactionBase()
{
return false;
}
public virtual bool IsThereManagement(ManagmentType type)
{
return false;
}
public virtual bool CheckProvacating()
{
return false;
}
public bool CheckExistingMapEvent()
{
foreach (MobileParty party in Owner.Settlement.Parties)
{
if (!party.IsMainParty && party.MapEvent != null)
{
return true;
}
}
return false;
}
public virtual float GetUnrestProbabilityChange(bool addEffectOfExtraRelationChange)
{
return 0f;
}
public virtual void OnRelatedPartyRemoved(MobileParty mobileParty)
{
}
public List<CharacterObject> GetPrisonerHeroes()
{
List<PartyBase> list = new List<PartyBase>
{
Owner
};
foreach (MobileParty party in Owner.Settlement.Parties)
{
if (party.IsCommonAreaParty || party.IsGarrison)
{
list.Add(party.Party);
}
}
List<CharacterObject> list2 = new List<CharacterObject>();
foreach (PartyBase item in list)
{
for (int i = 0; i < item.PrisonRoster.Count; i++)
{
for (int j = 0; j < item.PrisonRoster.GetElementNumber(i); j++)
{
CharacterObject character = item.PrisonRoster.GetElementCopyAtIndex(i).Character;
if (character.IsHero)
{
list2.Add(character);
}
}
}
}
return list2;
}
}
}