Exemple #1
0
        private object OnRecycleItem(Recycler r, Item i)
        {
            if (this.IsRecycleBox(r))
            {
                BasePlayer p = this.PlayerFromRecycler(r.net.ID);
                if (p != null && r.transform.position != p.transform.position)
                {
                    Vector3 old = r.transform.position;
                    r.transform.position = p.transform.position;
                    r.SendNetworkUpdateImmediate();
                    this.NextFrame(() => {
                        if (r == null)
                        {
                            return;
                        }
                        r.transform.position = old;
                        r.SendNetworkUpdateImmediate();
                    });
                }
            }

            return(null);
        }
Exemple #2
0
        private void CreateRecycler(BasePlayer p)
        {
            Recycler r = GameManager.server.CreateEntity(Recycle.RecyclePrefab, p.transform.position + Vector3.up * 4000) as Recycler;

            r.recycleEfficiency = this.Data.Settings.RefundRatio;
            r.enableSaving      = false;
            r.SetFlag(BaseEntity.Flags.Locked, true);
            r.UpdateNetworkGroup();
            r.Spawn();
            if (!r.isSpawned)
            {
                return;
            }
            r.gameObject.layer = 0;
            r.SendNetworkUpdateImmediate(true);
            this.Subscribe(nameof(CanNetworkTo));
            this.OpenContainer(p, r);
            this.Recyclers.Add(r.net.ID, new EntityAndPlayer {
                Entity = r, Player = p
            });
        }
        /// <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);
        }
Exemple #4
0
        private object CanAcceptItem(ItemContainer con, Item i, int target)
        {
            if (con.entityOwner is Recycler)
            {
                Recycler r = con.entityOwner as Recycler;
                if (this.IsRecycleBox(r))
                {
                    BasePlayer p = this.PlayerFromRecycler(r.net.ID);
                    if (p == null)
                    {
                        return(null);
                    }

                    if (target < 6)
                    {
                        if (!this.Data.Settings.RecyclableTypes.Contains(Enum.GetName(typeof(ItemCategory), i.info.category)) ||
                            this.Data.Settings.Blacklist.Contains(i.info.shortname))
                        {
                            if (p != null)
                            {
                                this.PrintToChat(p, this.GetMessage("Recycle", "Invalid", p));
                            }
                            return(ItemContainer.CanAcceptResult.CannotAcceptRightNow);
                        }
                        else
                        {
                            NextFrame(() => {
                                if (r == null || !r.HasRecyclable())
                                {
                                    return;
                                }

                                if (this.Data.Settings.InstantRecycling)
                                {
                                    if (!r.IsOn())
                                    {
                                        r.InvokeRepeating(new Action(r.RecycleThink), 0, 0);
                                        r.SetFlag(BaseEntity.Flags.On, true, false, true);
                                        r.SendNetworkUpdateImmediate();
                                    }
                                }
                                else
                                {
                                    r.StartRecycling();
                                }
                            });
                        }
                    }
                    else if (this.Data.Settings.ToInventory)
                    {
                        NextFrame(() => {
                            if (p == null || p.inventory == null || p.inventory.containerMain == null ||
                                p.inventory.containerBelt == null || i == null)
                            {
                                return;
                            }

                            bool flag = false;
                            if (!p.inventory.containerMain.IsFull())
                            {
                                flag = i.MoveToContainer(p.inventory.containerMain);
                            }
                            if (!flag && !p.inventory.containerBelt.IsFull())
                            {
                                i.MoveToContainer(p.inventory.containerBelt);
                            }
                        });
                    }
                }
            }
            return(null);
        }