Beispiel #1
0
        public Item CreateItem(ItemDefinition itemDefinition, int objectId, Vector3 position, bool dispatchWorldListener)
        {
            Item item;

            if (itemDefinition.type == CubeWorld.World.Objects.CWDefinition.DefinitionType.ItemTile)
            {
                item = new ItemTile(world, (ItemTileDefinition)itemDefinition, objectId);
            }
            else
            {
                item = new Item(world, itemDefinition, objectId);
            }

            item.position = position;
            item.AddComponent(new ItemComponentGravity());
            item.AddComponent(new ItemComponentGoToPlayer());
            item.AddComponent(new ItemComponentAutoDestroy());

            items.Add(item);

            if (dispatchWorldListener)
            {
                world.cwListener.CreateObject(item);
            }

            return(item);
        }
Beispiel #2
0
        public void Load(System.IO.BinaryReader br)
        {
            entries.Clear();

            int n = br.ReadInt32();

            for (int i = 0; i < n; i++)
            {
                string id       = br.ReadString();
                int    position = br.ReadInt32();
                int    quantity = br.ReadInt32();

                TileDefinition tileDefinition = owner.world.tileManager.GetTileDefinitionById(id);
                CWObject       cwobject       = null;

                if (tileDefinition != null)
                {
                    //It's a tile
                    DynamicTile dynamicTile = new DynamicTile(owner.world, tileDefinition, -1);

                    cwobject = dynamicTile;
                }
                else
                {
                    ItemDefinition itemDefinition = owner.world.itemManager.GetItemDefinitionById(id);

                    if (itemDefinition != null)
                    {
                        //It's an item
                        Item item;

                        if (itemDefinition.type == CubeWorld.World.Objects.CWDefinition.DefinitionType.ItemTile)
                        {
                            item = new ItemTile(owner.world, (ItemTileDefinition)itemDefinition, -1);
                        }
                        else
                        {
                            item = new Item(owner.world, itemDefinition, -1);
                        }

                        cwobject = item;
                    }
                }

                cwobject.Load(br);

                InventoryEntry ie = new InventoryEntry();
                ie.position = position;
                ie.quantity = quantity;
                ie.cwobject = cwobject;

                entries.Add(ie);
            }
        }
Beispiel #3
0
        public Item CreateItem(ItemDefinition itemDefinition, int objectId, Vector3 position, bool dispatchWorldListener)
        {
            Item item;

            if (itemDefinition.type == CubeWorld.World.Objects.CWDefinition.DefinitionType.ItemTile)
                item = new ItemTile(world, (ItemTileDefinition) itemDefinition, objectId);
            else
                item = new Item(world, itemDefinition, objectId);

            item.position = position;
            item.AddComponent(new ItemComponentGravity());
            item.AddComponent(new ItemComponentGoToPlayer());
            item.AddComponent(new ItemComponentAutoDestroy());

            items.Add(item);

            if (dispatchWorldListener)
                world.cwListener.CreateObject(item);

            return item;
        }
Beispiel #4
0
        public void Load(System.IO.BinaryReader br)
        {
            entries.Clear();

            int n = br.ReadInt32();

            for (int i = 0; i < n; i++)
            {
                string id = br.ReadString();
                int position = br.ReadInt32();
                int quantity = br.ReadInt32();

                TileDefinition tileDefinition = owner.world.tileManager.GetTileDefinitionById(id);
                CWObject cwobject = null;

                if (tileDefinition != null)
                {
                    //It's a tile
                    DynamicTile dynamicTile = new DynamicTile(owner.world, tileDefinition, -1);

                    cwobject = dynamicTile;
                }
                else
                {
                    ItemDefinition itemDefinition = owner.world.itemManager.GetItemDefinitionById(id);

                    if (itemDefinition != null)
                    {
                        //It's an item
                        Item item;

                        if (itemDefinition.type == CubeWorld.World.Objects.CWDefinition.DefinitionType.ItemTile)
                            item = new ItemTile(owner.world, (ItemTileDefinition)itemDefinition, -1);
                        else
                            item = new Item(owner.world, itemDefinition, -1);

                        cwobject = item;
                    }
                }

                cwobject.Load(br);

                InventoryEntry ie = new InventoryEntry();
                ie.position = position;
                ie.quantity = quantity;
                ie.cwobject = cwobject;

                entries.Add(ie);
            }
        }
    public GameObject CreateItemTileGameObject(ItemTile item)
    {
        GameObject g = new GameObject();
        ItemTileUnity itemTileUnity = (ItemTileUnity)g.AddComponent(typeof(ItemTileUnity));
        itemTileUnity.gameManagerUnity = gameManagerUnity;
        itemTileUnity.item = item;

        unityItemTiles.Add(itemTileUnity);

        return g;
    }