コード例 #1
0
ファイル: Inventory.cs プロジェクト: carriercomm/CubeWorld
        /**
         * Adds an object to the inventory.
         * 
         * @returns true if the object was added, false if there was no space for the object
         */
        public bool Add(CWObject cwobject)
        {
            InventoryEntry existingEntry = FindInventoryEntryFromDefinition(cwobject.definition);

            if (existingEntry != null)
            {
                existingEntry.quantity++;
            }
            else
            {
                existingEntry = new InventoryEntry();
                existingEntry.quantity = 1;
                existingEntry.cwobject = cwobject;

                entries.Add(existingEntry);
            }

            return true;
        }
コード例 #2
0
        public override void FillPlayerInventory(Inventory inventory)
        {
            ItemDefinition itemDefinition;
            Item item;
            InventoryEntry ie;

            itemDefinition = world.itemManager.GetItemDefinitionById("item_weapon");
            item = new Item(world, itemDefinition, -1);
            ie = new InventoryEntry();
            ie.position = 0;
            ie.quantity = 1;
            ie.cwobject = item;
            inventory.entries.Add(ie);

            itemDefinition = world.itemManager.GetItemDefinitionById("item_fire");
            item = new Item(world, itemDefinition, -1);
            ie = new InventoryEntry();
            ie.position = 0;
            ie.quantity = 1;
            ie.cwobject = item;

            inventory.entries.Add(ie);
        }
コード例 #3
0
ファイル: BaseGameplay.cs プロジェクト: carriercomm/CubeWorld
        public virtual void FillPlayerInventory(Inventory inventory)
        {
            foreach (ItemDefinition itemDefinition in world.itemManager.itemDefinitions)
            {
                if (itemDefinition.type != CubeWorld.World.Objects.CWDefinition.DefinitionType.ItemTile)
                {
                    Item item = new Item(world, itemDefinition, -1);

                    InventoryEntry ie = new InventoryEntry();
                    ie.position = 0;
                    ie.quantity = 1;
                    ie.cwobject = item;

                    inventory.entries.Add(ie);
                }
            }

            foreach (TileDefinition tileDefinition in world.tileManager.tileDefinitions)
            {
                if (tileDefinition.tileType != TileDefinition.EMPTY_TILE_TYPE)
                {
                    DynamicTile dynamicTile = new DynamicTile(world, tileDefinition, -1);

                    InventoryEntry ie = new InventoryEntry();
                    ie.position = 0;
                    ie.quantity = 10;
                    ie.cwobject = dynamicTile;

                    inventory.entries.Add(ie);
                }
            }
        }
コード例 #4
0
ファイル: Inventory.cs プロジェクト: carriercomm/CubeWorld
        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);
            }
        }