Esempio n. 1
0
        private static void OnPlayerLeaveCrafter(Crafter crafter, BasePlayer player)
        {
            numActiveCrafters[player]--;

            if (numActiveCrafters[player] <= 0)
            {
                numActiveCrafters.Remove(player);
                UiManager.RemoveUI(activeCrafterUi, player);
            }
        }
Esempio n. 2
0
        private static void OnPlayerEnterCrafter(Crafter crafter, BasePlayer player)
        {
            if (!numActiveCrafters.ContainsKey(player))
            {
                numActiveCrafters[player] = 0;
            }

            numActiveCrafters[player]++;

            // Only add ui for the first crafter, otherwise we'll add the player multiple times.
            if (numActiveCrafters[player] == 1)
            {
                UiManager.AddPlayerUI(activeCrafterUi, player);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Destroys the given crafter and optionally spawns a research table in its place.
        /// </summary>
        /// <param name="crafter">The crafter to destroy.</param>
        /// <param name="downgrade">If true, then the recycler will be replaced with a research table.</param>
        public static void DestroyCrafter(Crafter crafter, bool downgrade, bool destroyOutputContainer, bool unloading = false)
        {
            Crafters.Remove(crafter.Position);
            crafterLookup.Remove(crafter.Recycler);

            if (downgrade)
            {
                crafter.Downgrade(destroyOutputContainer);
            }
            else
            {
                crafter.Destroy(destroyOutputContainer, unloading);
            }

            crafter.PlayerEnter -= OnPlayerEnterCrafter;
            crafter.PlayerLeave -= OnPlayerLeaveCrafter;
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a crafter from the given recycler.
        /// </summary>
        /// <param name="recycler"></param>
        /// <returns></returns>
        public static Crafter CreateCrafter(Recycler recycler)
        {
            var crafter = new Crafter(recycler);

            crafter.PlayerEnter += OnPlayerEnterCrafter;
            crafter.PlayerLeave += OnPlayerLeaveCrafter;

            var gears = ItemManager.Create(ItemManager.FindItemDefinition("gears"), Constants.RecyclerNumInputSlots);

            for (int i = 0; i < Constants.RecyclerNumInputSlots; ++i)
            {
                var split = gears.SplitItem(1) ?? gears;
                split.MoveToContainer(recycler.inventory, i, false);
            }

            recycler.inventory.SetLocked(true);
            recycler.SendNetworkUpdateImmediate();

            Crafters.Add(recycler.ServerPosition, crafter);
            crafterLookup.Add(recycler, crafter);

            return(crafter);
        }