public GotTrainsMessage(Int2 superGridPosition, ImmutableList <Tile> tiles)
 {
     DebugEx.Assert(tiles.All(item => item.Data is IRailTileData));
     DebugEx.Assert(
         tiles.All(
             item => World.GridToSuperGrid(item.BaseData.GridPosition).Equals(superGridPosition)));
     SuperGridPosition = superGridPosition;
     TrainTiles        = tiles;
 }
예제 #2
0
        /// <summary>
        /// Checks if supplied <see cref="InventoryLocation"/> and bag index valid for <see cref="Item"/>.
        /// </summary>
        private bool IsValidLocationForItem(Item item, InventoryLocation location, uint bagIndex)
        {
            Bag bag = GetBag(location);

            if (bag == null)
            {
                return(false);
            }

            if (location == InventoryLocation.Equipped)
            {
                Item2TypeEntry typeEntry = GameTableManager.ItemType.GetEntry(item.Entry.Item2TypeId);
                if (typeEntry.ItemSlotId == 0)
                {
                    return(false);
                }

                ImmutableList <EquippedItem> bagIndexes = AssetManager.GetEquippedBagIndexes((ItemSlot)typeEntry.ItemSlotId);
                if (bagIndexes.All(i => i != (EquippedItem)bagIndex))
                {
                    return(false);
                }

                /*if (owner.Character.Class != item.Entry.ClassRequired)
                 *  return false;
                 *
                 * if (owner.Character.Race != item.Entry.RaceRequired)
                 *  return false;*/
            }

            return(true);
        }
예제 #3
0
        protected override bool TryParseArguments(ImmutableList <IMessageData> arguments)
        {
            if (arguments.Count != 2)
            {
                return(false);
            }

            _mailbox = MessageData.GetString(arguments[0], Encoding.UTF8);

            if (string.IsNullOrEmpty(_mailbox))
            {
                return(false);
            }

            var itemList = arguments[1] as ListMessageData;

            if (itemList == null)
            {
                return(false);
            }

            _items = ImmutableList.CreateRange(itemList.Items.Select(i => MessageData.GetString(i, Encoding.UTF8)));

            if (!_items.All(i => ValidStatusItems.Contains(i, StringComparer.Ordinal)))
            {
                return(false);
            }

            return(true);
        }
 public GotRegionMessage(Int2 superGridPosition, ImmutableList <Tile> tiles)
 {
     DebugEx.Assert(
         tiles.All(
             item => World.GridToSuperGrid(item.BaseData.GridPosition).Equals(superGridPosition)));
     SuperGridPosition = superGridPosition;
     Tiles             = tiles;
 }
예제 #5
0
        private void Process()
        {
            // Each iteration here we'll call a round
            while (true)
            {
                // Process any requests that have come in that want to perform blocking work on the processor thread.
                ProcessDispatches();

                var wasItemDequeued = false;
                foreach (var queue in queues)
                {
                    if (queue.IsAvailable && (!queue.cancellationToken.IsCancellationRequested || stopReason.IsCancellable(this, queue.Type)))
                    {
                        var queueItem = queue.Dequeue();
                        wasItemDequeued = true;
                        queue.Activate(queueItem);

                        Task.Run(() => queueItem.Execute().ContinueWith(_ => Dispatch(processor => queue.Deactivate(queueItem))));
                    }
                    else
                    {
                        queue.MarkWaiting();
                    }
                }
                if (!wasItemDequeued && !dispatches.Any())
                {
                    if (stopReason != null)
                    {
                        break;
                    }

                    if (queues.All(x => x.IsIdle))
                    {
                        Log("All queues idle, triggering idle task");
                        idled.SetResult(null);
                        idled = new TaskCompletionSource <object>();
                    }

                    // Wait for either a new item to be enqueued (waiter) or for the cancellation token to be triggered
                    Log("Round finished, waiting");
                    waiting.SetResult(null);
                    waiting = new TaskCompletionSource <object>();
                    waiter.WaitOne();
                }
            }
            Debug.Assert(stopped != null);

            stopReason = null;
            stopped.SetResult(null);
        }
예제 #6
0
        private static bool CheckRequiredServices(Type type)
        {
            RequiredServicesAttribute attribute = type.GetCustomAttribute <RequiredServicesAttribute>();

            if (attribute is null)
            {
                return(true);
            }
            foreach (Type rt in attribute.RequiredServices)
            {
                if (services.All(p => !rt.IsAssignableFrom(p.GetType())))
                {
                    return(false);
                }
            }
            return(true);
        }