public bool CheckCompletion(IOrderable q) { var queue = (ConstructionQueue)q; isComplete = Item.ConstructionProgress >= Item.Cost || GetErrors(queue).Any(); return(IsComplete); }
public virtual void BatchUpdataSort(ICollection <TEntity> entities) { if (entities.Any()) { IQueryable <TEntity> all = this.GetAll(); using (IEnumerator <TEntity> enumerator = entities.GetEnumerator()) { while (enumerator.MoveNext()) { IOrderable orderable = (IOrderable)enumerator.Current; using (IEnumerator <TEntity> enumerator2 = all.GetEnumerator()) { while (enumerator2.MoveNext()) { IOrderable orderable2 = (IOrderable)enumerator2.Current; if (orderable2.ComparisonObject(orderable)) { orderable2.Order = orderable.Order; break; } } } } } TDbContext dbContext = this.DbContext; dbContext.SaveChanges(); } }
public static IOrderable <TEntity, TProperty> OrderBy <TEntity, TProperty>(this IOrderable <TEntity> orders, Expression <Func <TEntity, TProperty> > propertySelector) where TEntity : class { var result = ((Orderable <TEntity>)orders).Input.OrderBy(propertySelector); return(new Orderable <TEntity, TProperty>(result)); }
/// <summary> /// Objects are enabled if they do not support disabling (<see cref="IDisableable"/>) or are <see cref="IDisableable.IsDisabled"/> = false /// </summary> /// <returns></returns> private bool IsEnabled(IOrderable arg) { //skip disabled things var dis = arg as IDisableable; return(dis == null || !dis.IsDisabled); }
private static void MoveOrderableUp(IOrderable orderable) { GameObject parentGameObject = orderable.gameObject.transform.parent.gameObject; int time = orderable.Ordinal; int nextTime = time - 1; foreach (Transform transform in parentGameObject.transform) { IOrderable sibling = transform.GetComponent <EventFilter>(); if (sibling != null && !sibling.Equals(orderable) && sibling.Ordinal == nextTime) { orderable.Ordinal = nextTime; sibling.Ordinal = time; return; } sibling = transform.GetComponent <EventResponder>(); if (sibling != null && !sibling.Equals(orderable) && sibling.Ordinal == nextTime) { orderable.Ordinal = nextTime; sibling.Ordinal = time; return; } } }
/// <summary> /// Moves all children containers/identifier lists (See <see cref="GetOrderedContents"/>) to make space for inserting a new one at the specified /// Order (See <see cref="Order"/>). /// </summary> /// <param name="makeRoomFor"></param> /// <param name="order"></param> /// <param name="incrementOrderOfCollisions"></param> public void CreateInsertionPointAtOrder(IOrderable makeRoomFor, int order, bool incrementOrderOfCollisions) { var contents = GetOrderedContents().ToArray(); //if there is nobody at that order then we are good if (contents.All(c => c.Order != order)) { return; } foreach (var orderable in contents) { if (orderable.Order < order) { orderable.Order--; } else if (orderable.Order > order) { orderable.Order++; } else //collision on order { orderable.Order += incrementOrderOfCollisions ? 1 : -1; } ((ISaveable)orderable).SaveToDatabase(); } }
public void Execute(IOrderable x) { if (x is IMobileSpaceObject executor) { var errors = GetErrors(executor); if (errors.Any()) { if (Owner != null) { foreach (var e in errors) { Owner.Log.Add(e); } } else { IsComplete = true; } return; } } Behavior.Execute(Target); IsComplete = true; }
public IEnumerable <LogMessage> GetErrors(IOrderable v) { if (PathfindingError != null) { yield return(PathfindingError); } }
public void Execute(IOrderable ord) { if (ord is ICargoTransferrer executor) { var errors = GetErrors(executor); if (executor.Owner != null) { foreach (var error in errors) { executor.Owner.Log.Add(error); } } if (!errors.Any()) { if (IsLoadOrder) { Target.TransferCargo(CargoDelta, executor, executor.Owner); } else { executor.TransferCargo(CargoDelta, Target, executor.Owner); } } IsComplete = true; } }
private static IOrderable GetPreviousOrderable(IOrderable orderable) { GameObject parentGameObject = orderable.gameObject.transform.parent.gameObject; int time = orderable.Ordinal - 1; return(GetOrderableAtTime(parentGameObject, time)); }
public IEnumerable <LogMessage> GetErrors(IOrderable ord) { if (ord is ConstructionQueue queue) { // validate that new facility is unlocked if (!queue.Owner.HasUnlocked(Upgrade.New)) { yield return(Upgrade.Old.CreateLogMessage(Upgrade.Old + " on " + queue.Container + " could not be upgraded to a " + Upgrade.New + " because we have not yet researched the " + Upgrade.New + ".")); } // validate that new and old facilities are in the same family if (Upgrade.New.Family.Value != Upgrade.Old.Family.Value) { yield return(Upgrade.Old.CreateLogMessage(Upgrade.Old + " on " + queue.Container + " could not be upgraded to a " + Upgrade.New + " because facilities cannot be upgraded to facilities of a different family.")); } // validate that there is a facility to upgrade var planet = (Planet)queue.Container; var colony = planet.Colony; if (!colony.Facilities.Any(f => f.Template == Upgrade.Old)) { yield return(planet.CreateLogMessage("There are no " + Upgrade.Old + "s on " + planet + " to upgrade.")); } } else { yield return(ord.CreateLogMessage($"{ord} cannot upgrade facilities because it is not a construction queue.")); } }
public IEnumerable <LogMessage> GetErrors(IOrderable o) { if (o is IMobileSpaceObject sobj) { if (sobj.Sector != Planet.Sector) { // can't colonize here, maybe the GUI should have issued a move order? yield return(sobj.CreateLogMessage(sobj + " cannot colonize " + Planet + " because it is not currently located at the planet.", LogMessageType.Warning)); } if (Planet.Colony != null) { // planet is already colonized! yield return(Planet.CreateLogMessage(Planet + " cannot be colonized by " + sobj + " because there is already a colony there belonging to the " + Planet.Colony.Owner + ".", LogMessageType.Warning)); } if (!(sobj.HasAbility(Planet.ColonizationAbilityName) || sobj is Fleet f && f.LeafVehicles.Any(v => v.HasAbility(Planet.ColonizationAbilityName)))) { // no such colony module yield return(sobj.CreateLogMessage(sobj + " cannot colonize " + Planet + " because it lacks a " + Planet.Surface + " colony module.", LogMessageType.Warning)); } if (Galaxy.Current.CanColonizeOnlyBreathable && Planet.Atmosphere != sobj.Owner.PrimaryRace.NativeAtmosphere) { // can only colonize breathable atmosphere (due to game setup option) yield return(sobj.CreateLogMessage(sobj + " cannot colonize " + Planet + " because we can only colonize " + sobj.Owner.PrimaryRace.NativeAtmosphere + " planets.", LogMessageType.Warning)); } if (Galaxy.Current.CanColonizeOnlyHomeworldSurface && Planet.Surface != sobj.Owner.PrimaryRace.NativeSurface) { // can only colonize breathable atmosphere (due to game setup option) yield return(sobj.CreateLogMessage(sobj + " cannot colonize " + Planet + " because we can only colonize " + sobj.Owner.PrimaryRace.NativeSurface + " planets.", LogMessageType.Warning)); } } else { yield return(o.CreateLogMessage($"{o} cannot colonize {Planet} because it is not a mobile space object.", LogMessageType.Error)); } }
public static void IssueOrder(this IOrderable obj, IOrder order) { if (obj.Owner != Empire.Current) { throw new Exception("Cannot issue orders to another empire's objects."); } Empire.Current.IssueOrder(obj, order); }
public void AddItem(IOrderable itemToOrder, int quantity, long forOrganizationRoleUserId, long dataRecorderCreatorId, SourceCode sourceCode, EventCustomer eventCustomer, ShippingDetail shippingDetail, OrderStatusState orderStatusState, long?sourceId = null) { if (sourceId == null && (itemToOrder is EventPackage || itemToOrder is EventTest)) { var customerId = forOrganizationRoleUserId; if (itemToOrder is EventTest) { var preApprovedTestList = _preApprovedTestRepository.GetByCustomerId(customerId).Select(x => x.TestId); if (preApprovedTestList.Contains(((EventTest)itemToOrder).TestId)) { sourceId = (long)OrderSource.PreApproved; } } else if (itemToOrder is EventPackage) { var preApprovedPackageList = _preApprovedPackageRepository.GetByCustomerId(customerId).Select(x => x.PackageId); if (preApprovedPackageList.Contains(((EventPackage)itemToOrder).PackageId)) { sourceId = (long)OrderSource.PreApproved; } } if (sourceId == null) { var oru = _organizationRoleUserRepository.GetOrganizationRoleUser(dataRecorderCreatorId); if (oru.RoleId == (long)Roles.FranchiseeAdmin) { sourceId = (long)OrderSource.Admin; } else if (oru.RoleId == (long)Roles.CallCenterRep) { sourceId = (long)OrderSource.CallCenter; } else if (oru.RoleId == (long)Roles.Technician) { sourceId = (long)OrderSource.Technician; } else if (oru.RoleId == (long)Roles.NursePractitioner) { sourceId = (long)OrderSource.NursePractioner; } } } OrderDetail orderDetail = _orderDetailFactory.CreateNewOrderDetail(itemToOrder, quantity, forOrganizationRoleUserId, dataRecorderCreatorId, sourceCode, eventCustomer, shippingDetail, sourceId); orderDetail.OrderItemStatus = _orderItemStatusFactory.CreateOrderItemStatus(itemToOrder.OrderItemType, (int)orderStatusState); var pair = new OrderedPair <OrderDetail, IOrderable>(orderDetail, itemToOrder); _lineItems.Add(pair); }
private void HandleReorder(ExtractableColumn sourceColumn, IOrderable targetOrderable, DropTargetLocation location) { if (targetOrderable == null) { targetOrderable = olvSelected.Objects.Cast <IOrderable>().OrderByDescending(o => o.Order).FirstOrDefault(); } if (targetOrderable == null) { return; } int destinationOrder = targetOrderable.Order; switch (location) { case DropTargetLocation.AboveItem: //bump down the other columns foreach (ConcreteColumn c in olvSelected.Objects.OfType <ConcreteColumn>().ToArray()) { if (c.Order >= destinationOrder && !Equals(c, sourceColumn)) { c.Order++; c.SaveToDatabase(); } } //should now be space at the destination order position sourceColumn.Order = destinationOrder; break; case DropTargetLocation.None: case DropTargetLocation.BelowItem: //bump up other columns foreach (ConcreteColumn c in olvSelected.Objects.OfType <ConcreteColumn>().ToArray()) { if (c.Order <= destinationOrder && !Equals(c, sourceColumn)) { c.Order--; c.SaveToDatabase(); } } sourceColumn.Order = destinationOrder; break; default: throw new ArgumentOutOfRangeException(); } sourceColumn.SaveToDatabase(); olvSelected.RefreshObjects(olvSelected.Objects.OfType <object>().ToArray()); SortSelectedByOrder(); }
public IEnumerable<LogMessage> GetErrors(IOrderable executor) { if (!Source.IntrinsicAbilities.Contains(Ability)) yield return executor.CreateLogMessage(executor + " does not intrinsically possess the ability \"" + Ability + "\" with ID=" + Ability.ID + "."); if (!Ability.Rule.IsActivatable) yield return executor.CreateLogMessage("The ability \"" + Ability + "\" cannot be activated. It is a passive ability."); if (Source is IDamageable && (Source as IDamageable).IsDestroyed) yield return executor.CreateLogMessage(executor + " cannot activate " + Source + "'s ability because " + Source + " is destroyed."); }
public bool CheckCompletion(IOrderable queue) { if (NewFacility == null) { return(false); } isComplete = NewFacility.ConstructionProgress >= Cost || GetErrors(queue).Any(); return(IsComplete); }
private ExecuteCommandReOrderAggregate(IActivateItems activator, IOrderable target, InsertOption insertOption) : base(activator) { _targetOrder = target; _insertOption = insertOption; if (target is IMightBeReadOnly ro && ro.ShouldBeReadOnly(out string reason)) { SetImpossible(reason); } }
public void Execute(IOrderable ord) { var errors = GetErrors(ord); foreach (var error in errors) { Owner.Log.Add(error); } var sobj = (IMobileSpaceObject)ord; if (!errors.Any()) { var here = sobj.Sector; if (here == WarpPoint.Sector) { // warp now!!! here.Remove(sobj); // warp point turbulence damage? if (WarpPoint.HasAbility("Warp Point - Turbulence")) { var dmg = WarpPoint.GetAbilityValue("Warp Point - Turbulence").ToInt(); sobj.TakeNormalDamage(dmg); if (sobj.IsDestroyed) { sobj.Owner.Log.Add(sobj.CreateLogMessage(sobj + " was destroyed by turbulence when traversing " + WarpPoint + ".", LogMessageType.Generic)); return; } else { sobj.Owner.Log.Add(sobj.CreateLogMessage(sobj + " took " + dmg + " points of damage from turbulence when traversing " + WarpPoint + ".", LogMessageType.Generic)); } } sobj.Sector = WarpPoint.Target; sobj.RefreshDijkstraMap(); // mark system explored WarpPoint.TargetStarSystemLocation.Item.MarkAsExploredBy(((ISpaceObject)sobj).Owner); // done warping IsComplete = true; } else { // can'IMobileSpaceObject warp here, maybe the GUI should have issued a move order? ((ISpaceObject)sobj).Owner.Log.Add(sobj.CreateLogMessage(sobj + " cannot warp via " + WarpPoint + " because it is not currently located at the warp point.", LogMessageType.Warning)); } } // spend time sobj.SpendTime(sobj.TimePerMove); }
public Order RefundOrder(IOrderable refundOrderItem, Order order, DomainObjectBase creatorOrganizationRoleUser, DomainObjectBase forOrganizationRoleUser) { IOrderController orderController = new OrderController(); orderController.AddItem(refundOrderItem, 1, forOrganizationRoleUser.Id, creatorOrganizationRoleUser.Id, null, null, null, RefundItemStatus.Applied.OrderStatusState); order = orderController.RefundOrder(order); return(order); }
public IEnumerable <LogMessage> GetErrors(IOrderable v) { if (!(v is IMobileSpaceObject)) { yield return(v.CreateLogMessage($"{v} cannot move to a waypoint because it is not a mobile space object.", LogMessageType.Error)); } if (PathfindingError != null) { yield return(PathfindingError); } }
public static void UpdateOrder(this IEnumerable <IOrderable> items, IEnumerable <int> idsWithNewOrder) { for (int i = 0; i < idsWithNewOrder.Count(); i++) { int id = idsWithNewOrder.ElementAt(i); IOrderable orderable = items.FirstOrDefault(item => item.Id == id); if (orderable != null) { orderable.OrderNumber = i; } } }
public static IOrderedEnumerable <TSource> OrderByDescending <TSource>(this IEnumerable <TSource> source, Func <TSource, IOrderable> keySelector) { return(source.OrderByDescending(o => { IOrderable orderable = keySelector(o); if (orderable == null) { return null; } return orderable.GetOrderValue(); })); }
/// <summary> /// Does 1 turn's worth of building. /// </summary> public void Execute(IOrderable q) { var queue = (ConstructionQueue)q; var errors = GetErrors(queue); foreach (var error in errors) { queue.Owner.Log.Add(error); } if (!errors.Any()) { // create item if needed if (Item == null) { Item = Template.Instantiate(); if (!(Item is Facility)) { Item.Owner = queue.Owner; } if (Item is SpaceVehicle) { // space vehicles need their supplies filled up var sv = (SpaceVehicle)(IConstructable)Item; sv.SupplyRemaining = sv.SupplyStorage; } } // apply build rate var costLeft = Item.Cost - Item.ConstructionProgress; var spending = ResourceQuantity.Min(costLeft, queue.UnspentRate); if (!(spending <= queue.Owner.StoredResources)) { spending = ResourceQuantity.Min(spending, queue.Owner.StoredResources); if (spending.IsEmpty) { if (!queue.IsConstructionDelayed) // don't spam messages! { Owner.Log.Add(queue.Container.CreateLogMessage("Construction of " + Template + " at " + queue.Container + " was paused due to lack of resources.")); } } else { Owner.Log.Add(queue.Container.CreateLogMessage("Construction of " + Template + " at " + queue.Container + " was slowed due to lack of resources.")); } queue.IsConstructionDelayed = true; } queue.Owner.StoredResources -= spending; queue.UnspentRate -= spending; Item.ConstructionProgress += spending; } }
/// <summary> /// Creates new child according to the contractor's defaults and attaches it to the parent <see cref="BusinessObject"/>. /// </summary> /// <returns>A new child.</returns> public virtual T CreateNew() { T bo = (T)Activator.CreateInstance(typeof(T), new object[] { this.Parent }); IOrderable orderable = (IOrderable)bo; if (orderable != null) { orderable.Order = this.Children.Count + 1; } this.Children.Add(bo); return(bo); }
public IEnumerable <LogMessage> GetErrors(IOrderable executor) { if (executor is ICargoTransferrer t) { if (Target != null && t.Sector != Target.Sector) { yield return(t.CreateLogMessage(executor + " cannot transfer cargo to " + Target + " because they are not in the same sector.")); } } else { yield return(executor.CreateLogMessage($"{executor} cannot transfer cargo.")); } }
/// <summary> /// Updates order for <see cref="IOrderable"/> objects. /// </summary> public void UpdateOrder() { if (typeof(IOrderable).IsAssignableFrom(typeof(T))) { int i = 1; foreach (T child in this.Children) { IOrderable obj = (IOrderable)child; obj.Order = i++; } } }
public OrderByParameter(IOrderable orderable) { var text = orderable.OrderBy.Split(":"); if (!text[0].Contains("asc", StringComparison.OrdinalIgnoreCase) && !text[0].Contains("desc", StringComparison.OrdinalIgnoreCase)) { return; } SortDirection = text[0].Contains("asc", StringComparison.OrdinalIgnoreCase) ? ListSortDirection.Ascending : ListSortDirection.Descending; Node = text[1]; }
/// <summary> /// Objects are enabled if they do not support disabling (<see cref="IDisableable"/>) or are <see cref="IDisableable.IsDisabled"/> = false /// </summary> /// <returns></returns> private bool IsEnabled(IOrderable arg) { var parentDisabled = ChildProvider.GetDescendancyListIfAnyFor(arg)?.Parents.Any(p => p is IDisableable d && d.IsDisabled); //if a parent is disabled if (parentDisabled.HasValue && parentDisabled.Value) { return(false); } //or you yourself are disabled var dis = arg as IDisableable; return(dis == null || !dis.IsDisabled); }
public IEnumerable <LogMessage> GetErrors(IOrderable q) { var queue = (ConstructionQueue)q; // do we have a valid template? if (Template == null) { yield return(Owner.CreateLogMessage($"{queue.Container} cannot build a nonexistent template; skipping it. Probably a bug...")); } // validate that what's being built is unlocked if (!queue.Owner.HasUnlocked(Template)) { yield return(Template.CreateLogMessage(Template + " cannot be built at " + queue.Container + " because we have not yet researched it.")); } }
public bool InteractWith(IOrderable obj) { return false; }
private void CalculateInteraction(IOrderable obj, HoverOver hoveringOver, ref InteractionState interactionState) { if (obj.IsAttackable()) { if (hoverOver == HoverOver.EnemyUnit || hoverOver == HoverOver.EnemyBuilding) { //Attack Interaction interactionState = InteractionState.Attack; return; } } if (obj.IsDeployable()) { if (((RTSObject)obj).gameObject.Equals (currentObject)) { //Deploy Interaction interactionState = InteractionState.Deploy; return; } } if (obj.IsInteractable ()) { if (hoverOver == HoverOver.FriendlyUnit) { //Check if object can interact with unit (carry all for example) if (((IInteractable)obj).InteractWith(currentObject)) { //Interact Interaction interactionState = InteractionState.Interact; return; } } } if (obj.IsMoveable()) { if (hoverOver == HoverOver.Land) { //Move Interaction interactionState = InteractionState.Move; return; } } if (hoverOver == HoverOver.FriendlyBuilding) { //Check if building can interact with object (repair building for example) if (currentObject.GetComponent<Building>().InteractWith (obj)) { //Interact Interaction interactionState = InteractionState.Interact; return; } } if (hoverOver == HoverOver.FriendlyUnit || hoverOver == HoverOver.FriendlyBuilding || hoverOver == HoverOver.EnemyUnit || hoverOver == HoverOver.EnemyBuilding) { //Select Interaction interactionState = InteractionState.Select; return; } //Invalid interaction interactionState = InteractionState.Invalid; }