public void OnForceShiftCB(GameObject obj) { if (this.Garrison != null) { DepartmentOfScience agency = this.Garrison.Empire.GetAgency <DepartmentOfScience>(); if (agency == null || agency.GetTechnologyState("TechnologyDefinitionOrbUnlock17WinterShifters") != DepartmentOfScience.ConstructibleElement.State.Researched) { return; } List <Unit> list = new List <Unit>(this.selectedUnits); list.RemoveAll((Unit unit) => !unit.IsShifter() || !unit.IsInCurrentSeasonForm()); if (list.Count > 0) { OrderForceShiftUnits order = new OrderForceShiftUnits(this.Garrison.Empire.Index, list.ToArray()); IPlayerControllerRepositoryService service = base.Game.Services.GetService <IPlayerControllerRepositoryService>(); Ticket ticket; service.ActivePlayerController.PostOrder(order, out ticket, new EventHandler <TicketRaisedEventArgs>(this.OnOrderResponse)); EventForceShift eventToNotify = new EventForceShift(this.Garrison.Empire, list.Count, true); IEventService service2 = Services.GetService <IEventService>(); if (service2 != null) { service2.Notify(eventToNotify); } } } }
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters) { if (this.ticket != null) { if (!this.orderExecuted) { return(State.Running); } if (this.ticket.PostOrderResponse == PostOrderResponse.PreprocessHasFailed) { this.orderExecuted = false; this.ticket = null; aiBehaviorTree.ErrorCode = 1; return(State.Failure); } this.orderExecuted = false; this.ticket = null; return(State.Success); } else { if (!this.isDlcActive) { return(State.Success); } Army army; if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None) { return(State.Failure); } foreach (Unit unit in army.Units) { if (unit.IsShifter() && !unit.IsInCurrentSeasonForm()) { return(State.Success); } } AIData_Army aidata_Army; if (!this.aiDataRepositoryHelper.TryGetAIData <AIData_Army>(army.GUID, out aidata_Army) || !aiBehaviorTree.AICommander.MayUseShift(aidata_Army.CommanderMission)) { return(State.Success); } if (!this.orbAIHelper.MaySwitchUnit(aiBehaviorTree.AICommander.Empire.Index)) { return(State.Success); } if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName)) { aiBehaviorTree.LogError("${0} not set", new object[] { this.TargetVarName }); return(State.Failure); } IGameEntity gameEntity = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity; if (!(gameEntity is IWorldPositionable)) { return(State.Failure); } if (!this.gameEntityRepositoryService.Contains(gameEntity.GUID)) { return(State.Failure); } Garrison garrison = gameEntity as Garrison; if (gameEntity is Kaiju) { garrison = (gameEntity as Kaiju).GetActiveTroops(); } if (garrison == null) { return(State.Success); } if (garrison.IsInEncounter) { return(State.Running); } float expensePriority = this.ComputeShiftPriority(aidata_Army, garrison); float availableAmount = this.accountManager.GetAvailableAmount(AILayer_AccountManager.OrbAccountName, expensePriority); if (availableAmount <= 0f) { return(State.Success); } GameEntityGUID[] shiftingUnitGuids = null; float expense = 0f; this.SelectUnitToShift(aidata_Army, availableAmount, out expense, out shiftingUnitGuids); if (!this.accountManager.TryMakeUnexpectedImmediateExpense(AILayer_AccountManager.OrbAccountName, expense, expensePriority)) { return(State.Success); } OrderForceShiftUnits order = new OrderForceShiftUnits(aiBehaviorTree.AICommander.Empire.Index, shiftingUnitGuids); this.orderExecuted = false; aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(order, out this.ticket, new EventHandler <TicketRaisedEventArgs>(this.Order_TicketRaised)); return(State.Running); } }