Ejemplo n.º 1
0
        public static bool OnEntity(Entity entity)
        {
            var ent = BaseNetworkable.Get(entity.baseNetworkable.uid);

            if (ent != null)
            {
                ent.OnEntityUpdate(entity);
                return(ent.OnEntity(entity));
            }
            var prefabId = entity.baseNetworkable.prefabID;

            if (prefabId == (UInt32)EPrefabUID.BasePlayer)
            {
                ent = new BasePlayer();
            }
            else if (prefabId == (UInt32)EPrefabUID.OreBonus)
            {
                ent = new OreBonus();
            }
            else if (entity.resource != null && Database.IsOreResource(prefabId))
            {
                ent = new OreResource();
            }
            else if (entity.heldEntity != null)
            {
                ent = new BaseHeldEntity();
            }
            else if (OpCodes.IsStorage(entity.baseNetworkable.prefabID))
            {
                ent = new StorageContainer();
            }
            else if (Database.IsCollectible(prefabId))
            {
                ent = new CollectibleEntity();
            }
            else if (Database.IsBaseResource(prefabId))
            {
                ent = new BaseResource();
            }
            else if (entity.worldItem != null && Database.IsComponent(entity.worldItem.item.itemid))
            {
                //new WorldItem();
            }

            if (ent == null)
            {
                return(false);
            }
            ent.OnEntityCreate(entity);
            return(ent.OnEntity(entity));
        }
Ejemplo n.º 2
0
        private Item(ItemInformation _info, uint _amount, ulong _skinid)
        {
            this.UID = BaseNetworkable.TakeUID();
            ListItemsInWorld[this.UID] = this;

            this.Information = _info;

            this.SkinID    = _skinid;
            this.Condition = this.Information.MaxCondition;

            if (_amount <= 0)
            {
                this.Amount = 1;
            }
            else if (_amount > this.Information.MaxStack)
            {
                this.Amount = (uint)this.Information.MaxStack;
            }
            else
            {
                this.Amount = _amount;
            }

            if (this.Information.IsHoldable())
            {
                if (ItemInformation.GetHeldType(_info.HeldType, out Type type) == false)
                {
                    ConsoleSystem.LogError($"[{nameof(Item)}] Unrealized class for <{_info.Shortname}>");
                }
                this.HeldEntity = (BaseHeldEntity)Framework.Bootstraper.AddType(type);
                this.HeldEntity.Spawn(this.Information.HeldEntity.PrefabID);
                this.HeldEntity.SendNetworkUpdate();

                this.HeldEntity.ItemOwner = this;
                this.HeldEntity.Initialization();
            }
        }