Example #1
0
        private void TryInitializeFurnace(FurnaceState state, IEventScheduler scheduler, IWorld world,
                                          Coordinates3D coords, IItemRepository itemRepository)
        {
            if (TrackedFurnaces.ContainsKey(coords))
            {
                return;
            }

            var inputStack  = state.Items[FurnaceWindow.IngredientIndex];
            var fuelStack   = state.Items[FurnaceWindow.FuelIndex];
            var outputStack = state.Items[FurnaceWindow.OutputIndex];

            var input = itemRepository.GetItemProvider(inputStack.ID) as ISmeltableItem;
            var fuel  = itemRepository.GetItemProvider(fuelStack.ID) as IBurnableItem;

            if (state.BurnTimeRemaining > 0)
            {
                if (state.CookTime == -1 && input != null && (outputStack.Empty || outputStack.CanMerge(input.SmeltingOutput)))
                {
                    state.CookTime = 0;
                    SetState(world, coords, state);
                }
                var subject = new FurnaceEventSubject();
                TrackedFurnaces[coords] = subject;
                scheduler.ScheduleEvent("smelting", subject, TimeSpan.FromSeconds(1),
                                        server => UpdateFurnace(server.Scheduler, world, coords, itemRepository));
                return;
            }

            if (fuel != null && input != null) // We can maybe start
            {
                if (outputStack.Empty || outputStack.CanMerge(input.SmeltingOutput))
                {
                    // We can definitely start
                    state.BurnTimeRemaining = state.BurnTimeTotal = (short)(fuel.BurnTime.TotalSeconds * 20);
                    state.CookTime          = 0;
                    state.Items[FurnaceWindow.FuelIndex].Count--;
                    SetState(world, coords, state);
                    world.SetBlockID(coords, LitFurnaceBlock.BlockID);
                    var subject = new FurnaceEventSubject();
                    TrackedFurnaces[coords] = subject;
                    scheduler.ScheduleEvent("smelting", subject, TimeSpan.FromSeconds(1),
                                            server => UpdateFurnace(server.Scheduler, world, coords, itemRepository));
                }
            }
        }
Example #2
0
        private void RegisterEntropySources(IEnumerable <IEntropyProvider> entropyProviders)
        {
            foreach (var entropyProvider in entropyProviders)
            {
                var eventSource = _sourceCount++;
                if (eventSource > MaxNumberOfSources)
                {
                    throw new InvalidOperationException($"Cannot configure more than {MaxNumberOfSources} for accumulating entropy.");
                }

                _eventScheduler.ScheduleEvent(eventSource, entropyProvider.GetScheduledEvent());
            }
        }
Example #3
0
        private void TryInitializeFurnace(FurnaceState state, IEventScheduler scheduler, IWorld world,
                                          Coordinates3D coords, IItemRepository itemRepository)
        {
            if (TrackedFurnaces.ContainsKey(coords))
                return;

            var inputStack = state.Items[FurnaceWindow.IngredientIndex];
            var fuelStack = state.Items[FurnaceWindow.FuelIndex];
            var outputStack = state.Items[FurnaceWindow.OutputIndex];

            var input = itemRepository.GetItemProvider(inputStack.ID) as ISmeltableItem;
            var fuel = itemRepository.GetItemProvider(fuelStack.ID) as IBurnableItem;

            if (state.BurnTimeRemaining > 0)
            {
                if (state.CookTime == -1 && input != null && (outputStack.Empty || outputStack.CanMerge(input.SmeltingOutput)))
                {
                    state.CookTime = 0;
                    SetState(world, coords, state);
                }
                var subject = new FurnaceEventSubject();
                TrackedFurnaces[coords] = subject;
                scheduler.ScheduleEvent("smelting", subject, TimeSpan.FromSeconds(1),
                    server => UpdateFurnace(server.Scheduler, world, coords, itemRepository));
                return;
            }

            if (fuel != null && input != null) // We can maybe start
            {
                if (outputStack.Empty || outputStack.CanMerge(input.SmeltingOutput))
                {
                    // We can definitely start
                    state.BurnTimeRemaining = state.BurnTimeTotal = (short)(fuel.BurnTime.TotalSeconds * 20);
                    state.CookTime = 0;
                    state.Items[FurnaceWindow.FuelIndex].Count--;
                    SetState(world, coords, state);
                    world.SetBlockID(coords, LitFurnaceBlock.BlockID);
                    var subject = new FurnaceEventSubject();
                    TrackedFurnaces[coords] = subject;
                    scheduler.ScheduleEvent("smelting", subject, TimeSpan.FromSeconds(1),
                        server => UpdateFurnace(server.Scheduler, world, coords, itemRepository));
                }
            }
        }