public DiplomacyFactionRelationshipVM(IFaction faction, HintViewModel hint) { this.Faction = faction; this.ImageIdentifier = new ImageIdentifierVM(BannerCode.CreateFrom(faction.Banner), true); this.NameText = this.Faction.Name.ToString(); this.Hint = hint; }
public override void RefreshValues() { this._faction = (base.Obj as IFaction); this.Allies = new MBBindingList <EncyclopediaFactionVM>(); this.AlliesText = new TextObject("{=KqfNSsBE}Allies", null).ToString(); base.RefreshValues(); }
internal Upgrade( string name, int cost, string cardText, bool unique, bool limited, IFaction faction, IUpgradeType upgradeType, UpgradeModifierPackage modifiers, IReadOnlyList <IXWingSpecification <IPilot> > upgradeRestrictions) { Id = Guid.NewGuid(); Name = name; Cost = cost; CardText = cardText; Unique = unique; Limited = limited; Faction = faction; UpgradeType = upgradeType; AddActionModifiers = modifiers.AddActionModifiers; RemoveActionModifiers = modifiers.RemoveActionModifiers; AddUpgradeModifiers = modifiers.AddUpgradeModifiers; RemoveUpgradeModifiers = modifiers.RemoveUpgradeModifiers; PilotAttributeModifiers = modifiers.PilotAttributeModifiers; SelectableAddedUpgrades = modifiers.ChooseableUpgradeModifiers; UpgradeRestrictions = upgradeRestrictions; }
//CalculateRelationshipFactor private double CalculateRelationshipFactor(DecisionMaker decisionMaker, IFaction factionToChangeStateWith) { bool atWar = decisionMaker.Hero.MapFaction.IsAtWarWith(factionToChangeStateWith); Dictionary <Hero, int> otherFactionHeroRelations = factionToChangeStateWith.Heroes.Where(h => decisionMaker.Hero.IsFriend(h) || decisionMaker.Hero.IsEnemy(h)).ToDictionary(keySelector: h => h, elementSelector: h => decisionMaker.Hero.GetModifiedRelation(h) / 10); return(otherFactionHeroRelations.Count() > 0 ? otherFactionHeroRelations.Sum(f => f.Value) / (double)otherFactionHeroRelations.Count() * 10 : 0); }
public static bool FactionInScope(IFaction faction, DropdownDefault <string>?scope) { if (faction is null || faction.MapFaction is null || scope is null || scope.SelectedIndex < 0 || scope.SelectedIndex > 2) { return(false); } switch (scope.SelectedIndex) { case 0: break; case 1: if (Clan.PlayerClan.MapFaction is null || !Clan.PlayerClan.MapFaction.IsKingdomFaction || Clan.PlayerClan.MapFaction != faction.MapFaction) { return(false); } break; case 2: if (Clan.PlayerClan.MapFaction is null || !Clan.PlayerClan.MapFaction.IsKingdomFaction || !(faction.MapFaction.IsKingdomFaction && faction.MapFaction.Leader != Hero.MainHero)) { return(false); } break; default: break; } return(true); }
public IFaction Kingdom(IFaction clan) { if (clan == null) { throw new TechnicalException("Cannot get the kingdom of a null clan"); } if (clan.IsEliminated) { throw new FunctionalException("The faction with id + " + clan.StringId + " and name " + clan.Name + " has been eliminated. Therefore, the kingdom for this faction can not be retrieved"); } if (clan.IsKingdomFaction) { return(clan); } if (clan.IsClan && ClanInKingdoms.ContainsKey(clan.StringId)) { return(ClanInKingdoms[clan.StringId]); } throw new TechnicalException("Clan " + clan.StringId + " can not be found in the tracked clans list from the TrackClanKingdomBehaviour object." + "Normally all clans should be initialised in the tracked clans list." + " Some behaviour in the mod has deleted this clan from this list. Maybe the list was not initialised at all and is empty ?"); }
private bool IsPlayerActionAgainstCustomSpawnFaction(IFaction attacker, IFaction warTarget) { return(_customSpawnsClanData.ContainsKey(warTarget.StringId) && !_clanKingdom.IsPartOfAKingdom(warTarget) && (attacker.StringId.Equals(PlayerFactionId) || attacker.IsKingdomFaction && attacker.Leader == Hero.MainHero)); }
// Ripped off from TaleWorlds.CampaignSystem.FactionManager.DeclareAlliance which is currently bugged (sets stance to Neutral, not Alliance). public static void DeclareAlliance(IFaction faction1, IFaction faction2) { if (faction1 != faction2 && !faction1.IsBanditFaction && !faction2.IsBanditFaction) { typeof(FactionManager).GetMethod("SetStance", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { faction1, faction2, 2 }); } }
public TInfoType Get(IFaction gameObject) { if (gameObject == null) { return(null); } var infos = Infos.Where(i => i.Id == gameObject.StringId); var baseFactionInfos = infos as TInfoType[] ?? infos.ToArray(); if (baseFactionInfos.Length > 1) { RemoveDuplicates(); } var info = baseFactionInfos.FirstOrDefault(); if (info != null) { return(info); } info = (TInfoType)Activator.CreateInstance(typeof(TInfoType), gameObject); Infos.Add(info); return(info); }
public CharacterObject GetLordWithLeastFiefs(IFaction faction) { var validNobles = faction.Heroes.Where(hero => hero.StringId != Hero.MainHero.StringId && !hero.IsPrisoner && hero.IsAlive && !hero.IsOccupiedByAnEvent() && hero.PartyBelongedTo?.IsJoiningArmy == false && !hero.Noncombatant && hero.CharacterObject.Occupation == Occupation.Lord || hero.CharacterObject.Occupation == Occupation.Lady); var noble = validNobles.Aggregate((currentResult, current) => current.Clan.Settlements.Count() < currentResult.Clan.Settlements.Count() ? current : currentResult); return(noble.Clan != null ? noble.CharacterObject : faction.Leader.CharacterObject); }
private void CardEventManager_OnCardReceived(ICard card, IFaction player) { if (player == this && HandManager.GetOpenHandSize() == 0) { _uiManager.HideDrawView(); } }
public Squadron(IFaction faction) { Pilots = new Dictionary <Guid, IPilot>(); Faction = faction ?? throw new ArgumentNullException(nameof(faction)); Id = Guid.NewGuid(); CostCap = defaultCostCap; }
private static void CheckIfPartyIconIsDirty(Clan clan, Kingdom oldKingdom) { IFaction faction; if (clan.Kingdom == null) { faction = clan; } else { IFaction kingdom = clan.Kingdom; faction = kingdom; } IFaction faction2 = faction; IFaction faction3 = (IFaction)oldKingdom ?? clan; foreach (MobileParty mobileParty in MobileParty.All) { if (mobileParty.IsVisible && ((mobileParty.Party.Owner != null && mobileParty.Party.Owner.Clan == clan) || (clan == Clan.PlayerClan && ((!FactionManager.IsAtWarAgainstFaction(mobileParty.MapFaction, faction2) && FactionManager.IsAtWarAgainstFaction(mobileParty.MapFaction, faction3)) || (FactionManager.IsAtWarAgainstFaction(mobileParty.MapFaction, faction2) && !FactionManager.IsAtWarAgainstFaction(mobileParty.MapFaction, faction3)))))) { mobileParty.Party.Visuals.SetMapIconAsDirty(); } } foreach (Settlement settlement in clan.Settlements) { settlement.Party.Visuals.SetMapIconAsDirty(); } }
/// <summary> /// Checks if peace is possible between two factions. /// A faction can be a clan or a kingdom. /// </summary> /// <para>If both factions are non custom spawns factions then peace is never possible.</para> /// <para>If one of the factions is a custom spawn faction (for instance the attacker), then peace will be possible</para> /// <para>if one of the following conditions is met:</para> /// <para>1. The attacker forced war behaviour is not specified</para> /// <para>2. The attacker forced war behaviour is specified and</para> /// <para>2.1 The attacker is a clan and is not part of a kingdom and</para> /// <para>2.1.1 peaceTarget is a kingdom and is in the kingdom exception list</para> /// <para>2.1.2 peaceTarget is a clan in a kingdom which is in the kingdom exception list</para> /// <para>2.1.3 peaceTarget is a clan and is in the clan exception list</para> /// <para>2.2 The attacker is a clan in a kingdom and</para> /// <para>2.2.1 peaceTarget is a clan in a different kingdom which is in the kingdom exception list</para> /// <para>2.2.2 peaceTarget is a clan not in a kingdom and is in the clan exception list</para> /// <br/> /// <para>If both factions are custom spawn factions, then both factions need to at least meet a condition as attacker as /// described above.</para> /// <br/> /// <para>Peace is not possible if one of the factions is eliminated or if the faction is "test_clan" or "neutral" /// or if both factions are already at peace</para> /// <br/> /// <param name="attacker">Clan or kingdom faction</param> /// <param name="peaceTarget">Clan or kingdom faction</param> /// <returns>true if peace is possible between both factions or not</returns> public bool IsPeaceDeclarationPossible(IFaction attacker, IFaction warTarget) { if (attacker == null || warTarget == null) { return(false); } var hasAttackerForcedWarPeaceBehaviour = attacker != null && _customSpawnsClanData.ContainsKey(attacker.StringId) && _customSpawnsClanData[attacker.StringId].ForcedWarPeaceDataInstance != null; var hasWarTargetForcedWarPeaceBehaviour = warTarget != null && _customSpawnsClanData.ContainsKey(warTarget.StringId) && _customSpawnsClanData[warTarget.StringId].ForcedWarPeaceDataInstance != null; if (IsPlayerActionAgainstCustomSpawnFaction(attacker, warTarget)) { return(false); } if (hasAttackerForcedWarPeaceBehaviour && hasWarTargetForcedWarPeaceBehaviour) { return(IsCustomSpawnsClanPeaceDeclarationPossible(attacker, warTarget) && IsCustomSpawnsClanPeaceDeclarationPossible(warTarget, attacker)); } if (hasAttackerForcedWarPeaceBehaviour) { return(IsCustomSpawnsClanPeaceDeclarationPossible(attacker, warTarget)); } if (hasWarTargetForcedWarPeaceBehaviour) { return(IsCustomSpawnsClanPeaceDeclarationPossible(warTarget, attacker)); } return(false); }
public void FillFrom(Hero hero, int seed = -1) { if (FaceGen.GetMaturityTypeWithAge(hero.Age) > BodyMeshMaturityType.Child) { this._hero = hero; this.isNonEquipment = false; base.FillFrom(hero.CharacterObject, seed); base.MountCreationKey = TaleWorlds.Core.MountCreationKey.GetRandomMountKey(hero.CharacterObject.Equipment[10].Item, hero.CharacterObject.GetMountKeySeed()); this.IsDead = hero.IsDead; if (hero.Noncombatant) { Equipment expr_69 = hero.CivilianEquipment; this._equipment = ((expr_69 != null) ? expr_69.Clone(false) : null); } else { Equipment expr_84 = hero.BattleEquipment; this._equipment = ((expr_84 != null) ? expr_84.Clone(false) : null); } Equipment expr_9D = this._equipment; base.EquipmentCode = ((expr_9D != null) ? expr_9D.CalculateEquipmentCode() : null); if (((hero != null) ? hero.ClanBanner : null) != null) { base.BannerCodeText = BannerCode.CreateFrom(hero.ClanBanner).Code; } IFaction expr_D9 = hero.MapFaction; base.ArmorColor1 = ((expr_D9 != null) ? expr_D9.Color : 0u); IFaction expr_F1 = hero.MapFaction; base.ArmorColor2 = ((expr_F1 != null) ? expr_F1.Color2 : 0u); } }
public virtual void Create(IWorld world, IRoom room, IFaction faction, RoomBlueprint roomBlueprintIfAny) { var max = roomBlueprintIfAny?.OptionalActorsMax ?? 5; if (max <= 0) { return; } var min = roomBlueprintIfAny?.OptionalActorsMin ?? 1; if (min > max) { throw new ArgumentOutOfRangeException($"OptionalActorsMin should be lower than OptionalActorsMax for room blueprint '{roomBlueprintIfAny}'"); } int numberOfNpc = world.R.Next(min, max + 1); var pickFrom = Blueprints.Where(b => b.SuitsFaction(faction)).ToList(); if (roomBlueprintIfAny != null) { pickFrom = pickFrom.Union(roomBlueprintIfAny.OptionalActors).ToList(); } if (pickFrom.Any()) { for (int i = 0; i < numberOfNpc; i++) { Create(world, room, faction, pickFrom.GetRandom(world.R), roomBlueprintIfAny); } } }
public ICollection <Planet> GetAttackOptions(IFaction faction) { var linkedPlanets = GetLinkedPlanets(GetPlanets(faction), GetEnemyPlanets(faction)); var enemyLinkedPlanets = linkedPlanets.Where(p => GetFaction(p).Name != faction.Name).ToArray(); // this will get planets that have fleets, unless enemy has 2 more fleets there List <Planet> invasiblePlanets = new List <Planet>(); var planetFleets = Fleets.Where(f => f.Arrives <= Turn && f.TargetPlanetID >= 0 && GetPlanet(f.TargetPlanetID).FactionName != faction.Name).GroupBy(p => p.TargetPlanetID).ToArray(); // get fleets in orbits of planets, grouped by planets foreach (var pf in planetFleets) { var byFactions = pf.GroupBy(x => GetPlayer(x.OwnerName).FactionName).OrderByDescending(x => x.Count()).ToList(); var allyFleets = byFactions.Find(k => k.Key == faction.Name); if (allyFleets != null) { if (byFactions[0].Key == faction.Name || byFactions[0].Count() < allyFleets.Count() + 2) { invasiblePlanets.Add(GetPlanet(pf.Key)); } } } return(enemyLinkedPlanets.Union(invasiblePlanets).ToArray()); }
public IRoom Create(IWorld world, RoomBlueprint blueprint) { if (blueprint == null) { return(new Room("Empty Room", world, 'e')); } HandleInheritance(blueprint); IFaction faction = null; //if not unaligned if (!blueprint.Unaligned) { //pick blueprint faction (or random one if it isn't themed to a specific faction) if (blueprint.Faction != null) { var match = world.Factions.SingleOrDefault(f => f.Identifier == blueprint.Faction); faction = match ?? throw new Exception($"Could not find Faction {blueprint.Faction} listed by blueprint {blueprint}"); } else { faction = world.Factions.GetRandomFaction(world.R); } } var room = new Room(blueprint.Name, world, blueprint.Tile) { ControllingFaction = faction }; //does the blueprint override the leave directions? if (blueprint.LeaveDirections != null && blueprint.LeaveDirections.Any()) { room.LeaveDirections.Clear(); room.LeaveDirections = new HashSet <Direction>(blueprint.LeaveDirections); } AddBasicProperties(world, room, blueprint, "look"); world.AdjectiveFactory.AddAdjectives(world, room, blueprint); //get some actors for the room world.ActorFactory.Create(world, room, faction, blueprint); //get some items for the room world.ItemFactory.Create(world, room, faction, blueprint); foreach (var a in blueprint.MandatoryActors) { world.ActorFactory.Create(world, room, room.ControllingFaction, a, blueprint); } foreach (var i in blueprint.MandatoryItems) { room.Items.Add(world.ItemFactory.Create(world, i)); } return(room); }
public BuildAction(StructureDefinition.StructureType structureType, IFaction owner) { _structureType = structureType; _owner = owner; _spawnManager = Locator.Instance.Find <ISpawnManager>(); _structureDefinitionManager = Locator.Instance.Find <IStructureDefinitionManager>(); }
private static CalAudioClip Create(string subTypeName, IFaction faction, string subtitle, int disappearTimeMs = 4200) { var id = _nextId++; var clip = new CalAudioClip(id, subTypeName, faction, subtitle, disappearTimeMs); Index.Add(id, clip); return(clip); }
private void AddNonAggressionPactRelationships(Kingdom kingdom, IFaction faction, MBBindingList <DiplomacyFactionRelationshipVM> FactionPacts) { if (DiplomaticAgreementManager.Instance.HasNonAggressionPact(kingdom, faction as Kingdom, out NonAggressionPactAgreement pact)) { var textObject = new TextObject(StringConstants.DaysRemaining).SetTextVariable("DAYS_LEFT", (int)Math.Round(pact.EndDate.RemainingDaysFromNow)); FactionPacts.Add(new DiplomacyFactionRelationshipVM(kingdom, new HintViewModel(textObject))); } }
public bool IsFriend(IFaction other) { if (other is EntityFaction) { return((other as EntityFaction).m_faction == m_faction); } return(false); }
public KingdomTruceItemVMExtensionVM(IFaction faction1, IFaction faction2, Action <KingdomDiplomacyItemVM> onSelection, Action <KingdomTruceItemVM> onAction) : base(faction1, faction2, onSelection, onAction) { this.SendMessengerActionName = new TextObject("{=cXfcwzPp}Send Messenger").ToString(); this.AllianceActionName = new TextObject("{=0WPWbx70}Form Alliance").ToString(); this.InfluenceCost = (int)DiplomacyCostCalculator.DetermineInfluenceCostForDeclaringWar(Faction1 as Kingdom); this.ActionName = GameTexts.FindText("str_kingdom_declate_war_action", null).ToString(); UpdateDiplomacyProperties(); }
ICollection <Planet> GetNeutralAdjacentPlanets(IFaction faction) { if (faction == null) { throw new ArgumentNullException("faction"); } return(GetNeutralAdjacentPlanets(faction.Name)); }
public ICollection <Planet> GetClaimablePlanets(IFaction faction) { if (faction == null) { throw new ArgumentNullException("faction"); } return(GetClaimablePlanets(faction.Name)); }
public ICollection <Player> GetPlayers(IFaction faction) { if (faction == null) { throw new ArgumentNullException("faction"); } return(GetPlayers(faction.Name)); }
public override float GetScoreOfDeclaringWar(IFaction factionDeclaresWar, IFaction factionDeclaredWar, IFaction evaluatingClan) { if (Kingdom.All.Any(k => k.IsAtWarWith(factionDeclaresWar))) { return(0); } return(base.GetScoreOfDeclaringWar(factionDeclaresWar, factionDeclaredWar, evaluatingClan)); }
private static string CreateKey(IFaction faction1, IFaction faction2) { List <IFaction> factions = new List <IFaction> { faction1, faction2 }; IEnumerable <string> keyArguments = factions.OrderBy(faction => faction.StringId).Select(faction => faction.StringId); return(string.Join("+", keyArguments)); }
public static CampaignTime?GetLastWarTimeBetweenFactions(IFaction faction1, IFaction faction2) { if (LastWarTime.TryGetValue(CreateKey(faction1, faction2), out CampaignTime value)) { return(value); } else { return(default);
private TextObject GetMessengerArrivedText(IFaction faction1, IFaction faction2, Hero targetHero) { TextObject textObject = new TextObject("{=YnRmSele}The messenger from {FACTION1_NAME} has arrived at {HERO_NAME} of {FACTION2_NAME}."); textObject.SetTextVariable("FACTION1_NAME", faction1.Name.ToString()); textObject.SetTextVariable("FACTION2_NAME", faction2.Name.ToString()); textObject.SetTextVariable("HERO_NAME", targetHero.Name.ToString()); return(textObject); }
/// <summary> /// Constructor /// </summary> /// <param name="faction">Model faction</param> public FactionView(IFaction faction) { Faction = faction; UnitViews = new Dictionary<IUnit, UnitView>(); foreach (IUnit unit in faction.Units) { UnitView unitView = new UnitView(unit); MainWindow.INSTANCE.MapView.TilesView[unit.Position].grid.Children.Add(unitView); UnitViews.Add(unit, unitView); } }
ICollection<IPlanet> GetAttackOptions(AuthInfo springieLogin, IFaction faction) { if (faction == null) { throw new ArgumentNullException("faction"); } SpringieState state; if (SpringieStates.TryGetValue(springieLogin.Login, out state)) { state.LastUpdate = DateTime.Now; } var localFaction = Galaxy.Factions.Single(f => f.Name == faction.Name); var alreadyAttacked = from kvp in SpringieStates where (kvp.Key != springieLogin.Login) && (kvp.Value.ReminderEvent == ReminderEvent.OnBattleStarted) && (DateTime.Now - kvp.Value.LastUpdate).TotalMinutes < SpringieTimeout let status = kvp.Value.GameStartedStatus select Galaxy.GetPlanet(status.PlanetID); var mightBeEncircled = new List<Planet>(); foreach (var planet in alreadyAttacked) { var speculativeGalaxy = Galaxy.BinaryClone(); var conqueredPlanet = speculativeGalaxy.GetPlanet(planet.ID); conqueredPlanet.FactionName = speculativeGalaxy.OffensiveFaction.Name; var encircledPlanets = speculativeGalaxy.Planets.Where(speculativeGalaxy.IsPlanetEncircled); mightBeEncircled.AddRange(encircledPlanets); } var dontAttack = alreadyAttacked.Concat(mightBeEncircled); return Galaxy.GetAttackOptions(localFaction).Except(dontAttack).Cast<IPlanet>().ToArray(); }
public ICollection<Planet> GetAttackOptions(IFaction faction) { var linkedPlanets = GetLinkedPlanets(GetPlanets(faction), GetEnemyPlanets(faction)); var enemyLinkedPlanets = linkedPlanets.Where(p => GetFaction(p).Name != faction.Name).ToArray(); // this will get planets that have fleets, unless enemy has 2 more fleets there List<Planet> invasiblePlanets = new List<Planet>(); var planetFleets = Fleets.Where(f => f.Arrives <= Turn && f.TargetPlanetID >= 0 && GetPlanet(f.TargetPlanetID).FactionName != faction.Name).GroupBy(p => p.TargetPlanetID).ToArray(); // get fleets in orbits of planets, grouped by planets foreach (var pf in planetFleets) { var byFactions = pf.GroupBy(x => GetPlayer(x.OwnerName).FactionName).OrderByDescending(x => x.Count()).ToList(); var allyFleets = byFactions.Find(k => k.Key == faction.Name); if (allyFleets != null) { if (byFactions[0].Key == faction.Name || byFactions[0].Count() < allyFleets.Count() + 2) { invasiblePlanets.Add(GetPlanet(pf.Key)); } } } return enemyLinkedPlanets.Union(invasiblePlanets).ToArray(); }
ICollection<Planet> GetNeutralAdjacentPlanets(IFaction faction) { if (faction == null) { throw new ArgumentNullException("faction"); } return GetNeutralAdjacentPlanets(faction.Name); }
public ICollection<Planet> GetClaimablePlanets(IFaction faction) { if (faction == null) { throw new ArgumentNullException("faction"); } return GetClaimablePlanets(faction.Name); }
public ICollection<Planet> GetEnemyPlanets(IFaction faction) { return GetEnemyPlanets(faction.Name); }
/// <summary> /// Find links between two planets of a faction; /// </summary> public ICollection<Link> GetLinks(IFaction faction) { return GetLinks(faction.Name); }
public ICollection<Player> GetPlayers(IFaction faction) { if (faction == null) { throw new ArgumentNullException("faction"); } return GetPlayers(faction.Name); }
public Player GetCommanderInChief(IFaction faction) { return GetPlayers(faction).SingleOrDefault(p => p.IsCommanderInChief); }