Example #1
0
        public bool Craft(PlayerStatus inventory, BlockType blockType)
        {
            var craft = _craftingEntries.Find(s => s.CraftedItem.Type == blockType);

            foreach (var item in craft.NeededItems)
            {
                if (item.Count > inventory.Inventory.FindAll(s => s.Type == item.Type).Select(s => s.Count).Sum())
                {
                    return(false);
                }
            }

            foreach (var item in craft.NeededItems)
            {
                var requiredCount = craft.NeededItems.First(s => s.Type == item.Type).Count;
                var materil       = inventory.Inventory.FindAll(s => s.Type == item.Type);
                if (materil.First().Count < requiredCount)
                {
                    requiredCount -= materil.First().Count;
                    inventory.Inventory.Remove(materil.First());
                }
                inventory.Decrement(item.Type, requiredCount);
            }
            inventory.AddElement(craft.CraftedItem.Duplicate());
            return(true);
        }
Example #2
0
        private void PlaceBlock()
        {
            var blockType = status.GetItem();

            if (blockType is null)
            {
                return;
            }
            if (!blockType.IsPlaceable)
            {
                return;
            }

            foreach (var b in Tiles.VisiableBlocks)
            {
                if (CollideSystem.collide(b, this))
                {
                    return;
                }
            }
            Tiles.PlaceBlock(position.x, position.y, blockType.Type);
            status.Decrement(blockType.Type, 1);
            RemoveOverlappingWater();
            Sound.PlaySound(SoundType.Place);
        }