private void UnassignHero(Army army) { if (army.Hero != null) { OrderChangeHeroAssignment orderChangeHeroAssignment = new OrderChangeHeroAssignment(army.Empire.Index, army.Hero.GUID, GameEntityGUID.Zero); orderChangeHeroAssignment.IgnoreCooldown = true; army.Empire.PlayerControllers.AI.PostOrder(orderChangeHeroAssignment, out this.heroTicket, null); } }
protected override bool TryComputeArmyMissionParameter() { base.ArmyMissionParameters.Clear(); if (base.AIDataArmyGUID == GameEntityGUID.Zero) { return(false); } if (this.POI == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } Army army = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID).Army; if (army.Hero != null) { OrderChangeHeroAssignment orderChangeHeroAssignment = new OrderChangeHeroAssignment(base.Commander.Empire.Index, army.Hero.GUID, GameEntityGUID.Zero); orderChangeHeroAssignment.IgnoreCooldown = true; base.Commander.Empire.PlayerControllers.AI.PostOrder(orderChangeHeroAssignment); return(true); } if (army.StandardUnits.Count((Unit x) => x.UnitDesign.UnitBodyDefinition.SubCategory == "SubCategoryFlying" && x.GetPropertyValue(SimulationProperties.LevelDisplayed) >= 4f) == 0) { this.Success(); } if (army.StandardUnits.Count <= 1) { return(base.TryCreateArmyMission("VisitQuestRuin", new List <object> { this.RegionTarget.Index, this.POI })); } Unit item = army.StandardUnits.First((Unit x) => x.UnitDesign.UnitBodyDefinition.SubCategory == "SubCategoryFlying" && x.GetPropertyValue(SimulationProperties.LevelDisplayed) >= 4f); List <Unit> second = new List <Unit> { item }; List <Unit> list = army.StandardUnits.Except(second).ToList <Unit>(); WorldPosition validArmySpawningPosition = AILayer_ArmyRecruitment.GetValidArmySpawningPosition(army, this.worldPositionningService, this.pathfindingService); if (!validArmySpawningPosition.IsValid || list.Count == 0) { return(base.TryCreateArmyMission("MajorFactionRoaming", new List <object> { this.RegionTarget.Index, true })); } OrderTransferGarrisonToNewArmy order = new OrderTransferGarrisonToNewArmy(base.Commander.Empire.Index, army.GUID, list.ConvertAll <GameEntityGUID>((Unit unit) => unit.GUID).ToArray(), validArmySpawningPosition, StaticString.Empty, false, true, true); base.Commander.Empire.PlayerControllers.Server.PostOrder(order); return(true); }
private void ConfirmAssignment(object sender, MessagePanelResultEventArgs e) { if (e.Result == MessagePanelResult.Yes && this.selectedHero != null) { IGameService service = Services.GetService <IGameService>(); IPlayerControllerRepositoryService service2 = service.Game.Services.GetService <IPlayerControllerRepositoryService>(); OrderChangeHeroAssignment order = new OrderChangeHeroAssignment(this.Army.Empire.Index, this.selectedHero.GUID, this.Army.GUID); Ticket ticket; service2.ActivePlayerController.PostOrder(order, out ticket, new EventHandler <TicketRaisedEventArgs>(this.OnOrderResponse)); } this.selectedHero = null; }
protected override void Success() { base.Success(); if (this.AICommanderRegroupArmies.MissionHasAllUnits(this) && this.AICommanderRegroupArmies.RequestUnitListMessageID != 0UL) { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); Diagnostics.Assert(aidata != null); RequestArmyMessage requestArmyMessage = base.Commander.AIPlayer.Blackboard.GetMessage(this.AICommanderRegroupArmies.RequestUnitListMessageID) as RequestArmyMessage; if (requestArmyMessage != null) { requestArmyMessage.ArmyGUID = aidata.Army.GUID; requestArmyMessage.ExecutionState = RequestUnitListMessage.RequestUnitListState.ArmyAvailable; requestArmyMessage.TimeOut = 1; if (requestArmyMessage.HeroGUID != GameEntityGUID.Zero) { OrderChangeHeroAssignment order = new OrderChangeHeroAssignment(base.Commander.Empire.Index, requestArmyMessage.HeroGUID, aidata.Army.GUID); Ticket ticket; base.Commander.Empire.PlayerControllers.Client.PostOrder(order, out ticket, null); } if (this.majorEmpireAIEntity != null && this.majorEmpireAIEntity.GetCommanderMissionBasedOnItsArmyRequestArmy(requestArmyMessage.ID) != null) { base.SetArmyFree(); this.Process(); return; } } else { RequestGarrisonMessage requestGarrisonMessage = base.Commander.AIPlayer.Blackboard.GetMessage(this.AICommanderRegroupArmies.RequestUnitListMessageID) as RequestGarrisonMessage; if (requestGarrisonMessage != null) { requestGarrisonMessage.ExecutionState = RequestUnitListMessage.RequestUnitListState.ArmyAvailable; requestGarrisonMessage.TimeOut = 1; this.TransferUnits(requestGarrisonMessage.CityGuid); } RequestGarrisonCampMessage requestGarrisonCampMessage = base.Commander.AIPlayer.Blackboard.GetMessage(this.AICommanderRegroupArmies.RequestUnitListMessageID) as RequestGarrisonCampMessage; if (requestGarrisonCampMessage != null) { requestGarrisonCampMessage.ExecutionState = RequestUnitListMessage.RequestUnitListState.ArmyAvailable; requestGarrisonCampMessage.TimeOut = 1; this.TransferUnits(requestGarrisonCampMessage.CampGuid); } } } base.SetArmyFree(); }
private void OrderSplitUnit(object sender, TicketRaisedEventArgs e) { if (e.Result == PostOrderResponse.Processed) { DepartmentOfEducation agency = base.Commander.Empire.GetAgency <DepartmentOfEducation>(); if (agency.Heroes.Count > 0) { OrderChangeHeroAssignment order = new OrderChangeHeroAssignment(base.Commander.Empire.Index, agency.Heroes[0].GUID, (e.Order as OrderTransferGarrisonToNewArmy).ArmyGuid); base.Commander.Empire.PlayerControllers.AI.PostOrder(order); } AILayer_ArmyManagement layer = base.Commander.AIPlayer.GetEntity <AIEntity_Empire>().GetLayer <AILayer_ArmyManagement>(); if (layer != null) { layer.AssignJoblessArmies(); } } }
private void ValidateHeroChoice(Unit hero) { IGameService service = Services.GetService <IGameService>(); IPlayerControllerRepositoryService service2 = service.Game.Services.GetService <IPlayerControllerRepositoryService>(); this.AgeTransform.Enable = false; this.selectedHero = hero; if (this.Army.IsPrivateers) { string message = string.Format(AgeLocalizer.Instance.LocalizeString("%ConfirmHeroAssignmentToPrivateers"), new object[0]); MessagePanel.Instance.Show(message, string.Empty, MessagePanelButtons.YesNo, new MessagePanel.EventHandler(this.ConfirmAssignment), MessagePanelType.IMPORTANT, new MessagePanelButton[0]); } else { OrderChangeHeroAssignment order = new OrderChangeHeroAssignment(this.Army.Empire.Index, hero.GUID, this.Army.GUID); Ticket ticket; service2.ActivePlayerController.PostOrder(order, out ticket, new EventHandler <TicketRaisedEventArgs>(this.OnOrderResponse)); this.selectedHero = null; } }
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters) { IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); if (this.orderTicket != null) { if (!this.orderTicket.Raised) { return(State.Running); } if (this.orderTicket.PostOrderResponse != PostOrderResponse.Processed) { aiBehaviorTree.ErrorCode = 36; return(State.Failure); } this.orderTicket = null; return(State.Success); } else if (this.heroTicket != null) { if (!this.heroTicket.Raised) { return(State.Running); } if (this.heroTicket.PostOrderResponse != PostOrderResponse.Processed) { aiBehaviorTree.ErrorCode = 36; return(State.Failure); } this.heroTicket = null; return(State.Running); } else { Army army; if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None) { return(State.Failure); } if (army.IsPrivateers) { return(State.Success); } using (IEnumerator <Unit> enumerator = army.StandardUnits.GetEnumerator()) { while (enumerator.MoveNext()) { if (!enumerator.Current.UnitDesign.Tags.Contains(TradableUnit.ReadOnlyMercenary)) { return(State.Failure); } } } if (army.Hero != null) { OrderChangeHeroAssignment orderChangeHeroAssignment = new OrderChangeHeroAssignment(aiBehaviorTree.AICommander.Empire.Index, army.Hero.GUID, GameEntityGUID.Zero); orderChangeHeroAssignment.IgnoreCooldown = true; aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(orderChangeHeroAssignment, out this.heroTicket, null); return(State.Running); } Region region = service.Game.Services.GetService <IWorldPositionningService>().GetRegion(army.WorldPosition); if (region != null && region.City != null && region.City.Empire == army.Empire) { OrderTogglePrivateers order = new OrderTogglePrivateers(army.Empire.Index, army.GUID, true); aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(order, out this.orderTicket, null); return(State.Running); } aiBehaviorTree.ErrorCode = 36; return(State.Failure); } }