Ejemplo n.º 1
0
        private async void CreateRecipeComponent()
        {
            if (!IsValid)
            {
                await Application.Current.MainPage.DisplayAlert("Предупреждение", "Задайте название рецепта", "Ok");

                return;
            }

            if (Recipe.RecipeId == 0)
            {
                if (await Application.Current.MainPage.DisplayAlert("Предупреждение", "Для добавления компонента необходимо сохранить рецепт. Выполнить сохранение?", "Да", "Нет"))
                {
                    IsBack = false;
                    RecipesViewModel.SaveCommand.Execute(this);
                    IsBack = true;
                }
            }

            if (Recipe.RecipeId != 0)
            {
                RecipeComponent newRecipeComponent = new RecipeComponent()
                {
                    Recipe = this.Recipe
                };
                await Application.Current.MainPage.Navigation.PushAsync(new RecipeComponentPage(new RecipeComponentViewModel(newRecipeComponent)
                {
                    RecipeViewModel = this
                }));
            }
        }
Ejemplo n.º 2
0
        public RecipeComponent Update(RecipeComponent updatedRecipeComponent)
        {
            var entity = _db.RecipeComponents.Attach(updatedRecipeComponent);

            entity.State = EntityState.Modified;
            return(updatedRecipeComponent);
        }
Ejemplo n.º 3
0
        public RecipeComponentViewModel(RecipeComponent recipeComponent)
        {
            RecipeComponent = recipeComponent;
            LoadComponents();
            InitSelectedComponent();

            SelectComponentCommand = new Command(SelectComponent);
        }
Ejemplo n.º 4
0
 private void handleGameModelLoaded(AbstractMessage msg)
 {
     for (int i = 0; i < gameModel.Recipes.Count; i++)
     {
         GameObject      go = Instantiate(recipePrefab, gameObject.transform);
         RecipeComponent rc = go.GetComponent <RecipeComponent>();
         rc.Setup(gameModel.Recipes[i]);
     }
     _started = true;
 }
Ejemplo n.º 5
0
    public void GenerateComponents(int amount, Ingredient[] ingrList)
    {
        for (int i = 0; i < amount; i++)
        {
            RecipeComponent newComponent = new RecipeComponent();
            newComponent.GenerateEquation();
            newComponent.SetIngredient(ingrList[Random.Range(0, ingrList.Length)]); //Randomly assign an ingredient to it

            components.Add(newComponent);
        }
    }
Ejemplo n.º 6
0
        private static Point GetClosestMaterialPos(Creature c, RecipeComponent recipe, bool checkInventory)
        {
            int   currentFloor = c.CurrentFloor;
            Point worldIndex   = c.WorldIndex;

            Block[] blocks = currentFloor >= 0 ? Program.WorldMap[worldIndex.X, worldIndex.Y].Dungeon.Floors[currentFloor].Blocks : Program.WorldMap[worldIndex.X, worldIndex.Y].Blocks;
            int     width = Program.WorldMap.TileWidth, height = Program.WorldMap.TileHeight;

            // check inventory
            if (checkInventory)
            {
                foreach (Item item in c.Inventory)
                {
                    RecipeComponent itemC = item.ToComponent();
                    if (recipe.Equals(itemC))
                    {
                        return(new Point());
                    }
                }
            }

            // check map
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if (blocks[i * width + j] is Item item)
                    {
                        RecipeComponent itemC = item.ToComponent();
                        if (recipe.Equals(itemC))
                        {
                            return(new Point(i, j));
                        }
                    }
                    else if (blocks[i * width + j] is Chest chest)
                    {
                        foreach (Item cItem in chest.Inventory)
                        {
                            RecipeComponent itemC = cItem.ToComponent();
                            if (recipe.Equals(itemC))
                            {
                                return(new Point(i, j));
                            }
                        }
                    }
                }
            }


            return(null);
        }
Ejemplo n.º 7
0
    public RecipeComponent[] figureOutComponentCount(int recipeNumber)
    {
        RecipeComponent[] thingToReturn;
        thingToReturn = new RecipeComponent[(int)recipeData[recipeNumber]["ComponentCount"]];

        //lets say the list has 2 components

        for (int x = 0; x < (int)recipeData[recipeNumber]["ComponentCount"]; x++)
        {
            thingToReturn[x].componentType = (ComponentType)System.Enum.Parse(typeof(ComponentType), (string)recipeData[recipeNumber][x + "ComponentType"]);
            thingToReturn[x].Amount        = (int)recipeData[recipeNumber][x + "ComponentAmount"];
        }
        return(thingToReturn);
    }
        public IActionResult Edit(int?recipeComponentId)
        {
            var recipeComponent = new RecipeComponent();

            if (recipeComponentId.HasValue)
            {
                recipeComponent = _recipeComponentData.GetById(recipeComponentId.Value);
            }

            var viewModel = new RecipeComponentViewModel {
                RecipeComponent = recipeComponent
            };

            return(View(viewModel));
        }
Ejemplo n.º 9
0
        // LOGIC FOR DETERMINING PLAYER ACTION //

        internal static void DetermineCreatureAction(Creature c, bool calledFromCraftingScheduler = false)
        {
            if (!creatureStates.ContainsKey(c.ID))
            {
                creatureStates.Add(c.ID, CreatureState.Idle);
            }

            if (calledFromCraftingScheduler)
            {
                c.Wait();
                return;
            }

            DetermineNextConstruction();
            if (nextConstruction.Equals(new Point()) == false) // this means a pending construction has been found and it can definitely be built
            {
                RecipeComponent nextComponent = RecipeComponent.Null;
                if (currentConstructRecipe.Count > getIndex) // if get has not gotten up to the count
                {
                    nextComponent = currentConstructRecipe[getIndex];
                }
                else
                {
                    c.Path = null;
                    creatureStates[c.ID] = CreatureState.PlaceMaterials;
                }
                if (creatureStates[c.ID] == CreatureState.Idle)
                {
                    creatureStates[c.ID] = CreatureState.GetMaterial;
                }

                if (creatureStates[c.ID] == CreatureState.GetMaterial)
                {
                    HandleGetMaterial(c, nextComponent);
                }
                else if (creatureStates[c.ID] == CreatureState.PlaceMaterials)
                {
                    HandlePlaceMaterials(c, nextComponent);
                }
            }
            else /* there is no pending construction */
            {
                creatureStates[c.ID] = CreatureState.Idle;
                paused = true;
            }

            c.DetermineAction();
        }
Ejemplo n.º 10
0
        private string FormatIngredient(RecipeComponent component)
        {
            var ingredient = $"{component.Ingredient.Name}, {component.Size} {component.Unit}";

            if (component.Condition != null)
            {
                ingredient += $", {component.Condition}";
            }

            if (component.Optional)
            {
                ingredient += $" (optional)";
            }

            return(ingredient);
        }
Ejemplo n.º 11
0
        public static int ToSkillValue(this RecipeComponent rc)
        {
            switch (rc)
            {
            case RecipeComponent.Plank:
                return(5);

            case RecipeComponent.WoodWheel:
                return(75);

            case RecipeComponent.StoneWheel:
                return(125);

            default:
                return(0);
            }
        }
Ejemplo n.º 12
0
        private double?GetVolume(RecipeComponent recipeComponent, double?square)
        {
            double?doubleValue = 0.0;

            if (String.Equals(recipeComponent.VolumeRateUnit, VolumeRateUnit.Dry))
            {
                doubleValue = recipeComponent.Component.Density != 0 ? recipeComponent.VolumeRate / recipeComponent.Component.Density * square : 0.0;
            }
            else
            {
                doubleValue = recipeComponent.VolumeRate * square;
            }

            var decimalValue = (decimal)doubleValue;

            return((double)Math.Round(decimalValue, 2));
        }
Ejemplo n.º 13
0
        internal static Point GetClosestMaterialPos(RecipeComponent recipe, bool checkInventory)
        {
            // check player inventory
            if (checkInventory)
            {
                foreach (Item item in Program.Player.Inventory)
                {
                    RecipeComponent itemC = item.ToComponent();
                    if (recipe.Equals(itemC))
                    {
                        return(new Point());
                    }
                }
            }

            // check map
            for (int i = 0; i < Program.WorldMap.LocalTile.Width; i++)
            {
                for (int j = 0; j < Program.WorldMap.LocalTile.Height; j++)
                {
                    if (Program.WorldMap.LocalTile[i, j] is Item item)
                    {
                        RecipeComponent itemC = item.ToComponent();
                        if (recipe.Equals(itemC))
                        {
                            return(new Point(i, j));
                        }
                    }
                    else if (Program.WorldMap.LocalTile[i, j] is Chest chest)
                    {
                        foreach (Item cItem in chest.Inventory)
                        {
                            RecipeComponent itemC = cItem.ToComponent();
                            if (recipe.Equals(itemC))
                            {
                                return(new Point(i, j));
                            }
                        }
                    }
                }
            }


            return(null);
        }
Ejemplo n.º 14
0
        // LOGIC FOR DETERMINING PLAYER ACTION //

        internal static void DeterminePlayerAction(bool calledFromCraftingScheduler = false)
        {
            if (calledFromCraftingScheduler)
            {
                Program.Player.DetermineAction();
                return;
            }
            DetermineNextConstruction();
            if (currentConstructionPos.Equals(new Point()) == false) // this means a pending construction has been found and it can definitely be built
            {
                RecipeComponent nextComponent = RecipeComponent.Null;

                if (currentConstructRecipe.Count > getIndex)
                {
                    nextComponent = currentConstructRecipe[getIndex];
                }
                else
                {
                    Program.Player.Path = null;
                    playerState         = PlayerState.PlaceMaterials;
                }

                if (playerState == PlayerState.Idle)
                {
                    playerState = PlayerState.GetMaterial;
                }

                if (playerState == PlayerState.GetMaterial)
                {
                    HandleGetMaterial(nextComponent);
                }
                else if (playerState == PlayerState.PlaceMaterials)
                {
                    HandlePlaceMaterials(nextComponent);
                }
            }
            else // there is no pending construction
            {
                playerState = PlayerState.Idle;
                paused      = true;
            }

            Program.Player.DetermineAction();
        }
Ejemplo n.º 15
0
        public static int ToSkillValue(this RecipeComponent rc)
        {
            switch (rc)
            {
            case RecipeComponent.Log:
                return(0);

            case RecipeComponent.Leaf:
                return(0);

            case RecipeComponent.Stick:
                return(0);

            case RecipeComponent.Stone:
                return(0);

            case RecipeComponent.Coal:
                return(0);

            case RecipeComponent.Plank:
                return(10);

            case RecipeComponent.WoodWheel:
                return(75);

            case RecipeComponent.StoneWheel:
                return(150);

            case RecipeComponent.Handle:
                return(100);

            case RecipeComponent.Hilt:
                return(100);

            case RecipeComponent.Torch:
                return(100);

            default:
                return(0);
            }
        }
Ejemplo n.º 16
0
        public static Item ToItem(this RecipeComponent rc)
        {
            switch (rc)
            {
            case RecipeComponent.Log:
                return(new Log(true));

            case RecipeComponent.Leaf:
                return(new Leaf(true, "tree", Color.ForestGreen));

            case RecipeComponent.Stick:
                return(new Stick(true));

            case RecipeComponent.Stone:
                return(new Stone(true));

            case RecipeComponent.Coal:
                return(new CoalOre(true));

            case RecipeComponent.Plank:
                return(new Plank(true));

            case RecipeComponent.WoodWheel:
                return(new WoodWheel(true));

            case RecipeComponent.StoneWheel:
                return(new Stone(true));

            case RecipeComponent.Handle:
                return(new Handle(true, Material.Wood));

            case RecipeComponent.Hilt:
                return(new Hilt(true, Material.Wood));

            case RecipeComponent.Torch:
                return(new Torch(false));

            default:
                return(new EmptyBottle(true));
            }
        }
Ejemplo n.º 17
0
        public static string ToString(this RecipeComponent rc)
        {
            switch (rc)
            {
            case RecipeComponent.Log:
                return("log");

            case RecipeComponent.Leaf:
                return("leaf");

            case RecipeComponent.Stick:
                return("stick");

            case RecipeComponent.Stone:
                return("stone");

            case RecipeComponent.Coal:
                return("coal ore");

            case RecipeComponent.Plank:
                return("plank");

            case RecipeComponent.WoodWheel:
                return("wood wheel");

            case RecipeComponent.StoneWheel:
                return("stone wheel");

            case RecipeComponent.Handle:
                return("handle");

            case RecipeComponent.Hilt:
                return("hilt");

            case RecipeComponent.Torch:
                return("torch");

            default:
                return("null");
            }
        }
        public IActionResult Edit(RecipeComponent recipeComponent)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new RecipeComponentViewModel {
                    RecipeComponent = recipeComponent
                };
                return(View(viewModel));
            }

            if (recipeComponent.Id > 0)
            {
                _recipeComponentData.Update(recipeComponent);
            }
            else
            {
                _recipeComponentData.Add(recipeComponent);
            }
            _recipeComponentData.Commit();
            return(RedirectToAction("Detail", new { recipeComponentId = recipeComponent.Id }));
        }
Ejemplo n.º 19
0
        public static Item ToItem(this RecipeComponent rc)
        {
            switch (rc)
            {
            case RecipeComponent.Log:
                return(new Log(true));

            case RecipeComponent.Stone:
                return(new Stone(true));

            case RecipeComponent.Plank:
                return(new Plank(true));

            case RecipeComponent.WoodWheel:
                return(new WoodWheel(true));

            case RecipeComponent.StoneWheel:
                return(new Stone(true));

            default:
                return(new EmptyBottle(true));
            }
        }
Ejemplo n.º 20
0
        public static string ToString(this RecipeComponent rc)
        {
            switch (rc)
            {
            case RecipeComponent.Log:
                return("log");

            case RecipeComponent.Stone:
                return("stone");

            case RecipeComponent.Plank:
                return("plank");

            case RecipeComponent.WoodWheel:
                return("wood wheel");

            case RecipeComponent.StoneWheel:
                return("stone wheel");

            default:
                return("null");
            }
        }
Ejemplo n.º 21
0
        public void DownOrderComponent(RecipeComponent recipeComponent)
        {
            var currentOrder = recipeComponent.Order;

            if (currentOrder < RecipeComponents.Count())
            {
                var newOrder = currentOrder + 1;
                using (AppDbContext db = App.GetContext())
                {
                    var currentRecipeComponent = db.RecipeComponents.FirstOrDefault(rc => rc.Order == newOrder);
                    if (currentRecipeComponent != null)
                    {
                        currentRecipeComponent.Order = currentOrder;
                        recipeComponent.Order        = newOrder;

                        db.RecipeComponents.Update(currentRecipeComponent);
                        db.RecipeComponents.Update(recipeComponent);

                        db.SaveChanges();
                        LoadRecipeComponents();
                    }
                }
            }
        }
Ejemplo n.º 22
0
        private static bool DetermineIfEnoughMaterials()
        {
            List <RecipeComponent> recipe = GetConstructRecipe();

            if (recipe == null)
            {
                return(false);
            }

            // check player inventory
            foreach (Item item in Program.Player.Inventory)
            {
                RecipeComponent itemC = item.ToComponent();
                if (recipe.Contains(itemC))
                {
                    recipe.Remove(itemC);
                }
            }

            int   currentFloor = Program.Player.CurrentFloor;
            Point worldIndex   = Program.Player.WorldIndex;

            Block[] blocks = currentFloor >= 0 ? Program.WorldMap[worldIndex.X, worldIndex.Y].Dungeon.Floors[currentFloor].Blocks : Program.WorldMap[worldIndex.X, worldIndex.Y].Blocks;
            int     width = Program.WorldMap.TileWidth, height = Program.WorldMap.TileHeight;

            // check map
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if (blocks[i * width + j] is Item item)
                    {
                        RecipeComponent itemC = item.ToComponent();
                        if (recipe.Contains(itemC))
                        {
                            recipe.Remove(itemC);
                        }
                    }
                    else if (blocks[i * width + j] is Chest chest)
                    {
                        foreach (Item cItem in chest.Inventory)
                        {
                            RecipeComponent itemC = cItem.ToComponent();
                            if (recipe.Contains(itemC))
                            {
                                recipe.Remove(itemC);
                            }
                        }
                    }
                }
            }



            // check for other methods of resource aquisition
            if (recipe.Count > 0)
            {
                if (recipe.Contains(RecipeComponent.Log)) // find a tree if the recipe calls for a log
                {
                    for (int i = 0; i < width; i++)
                    {
                        for (int j = 0; j < height; j++)
                        {
                            if (blocks[i * width + j] is Tree)
                            {
                                recipe.RemoveAll(rc => rc == RecipeComponent.Log);
                            }
                        }
                    }
                }

                if (recipe.Contains(RecipeComponent.Plank)) // find a tree or a log if the recipe calls for a plank
                {
                    for (int i = 0; i < width; i++)
                    {
                        for (int j = 0; j < height; j++)
                        {
                            if (blocks[i * width + j] is Tree || blocks[i * width + j] is Log)
                            {
                                recipe.RemoveAll(rc => rc == RecipeComponent.Plank);
                            }
                        }
                    }
                }
            }

            if (recipe.Count == 0)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 23
0
 public RecipeComponent Add(RecipeComponent recipeComponent)
 {
     _db.Add(recipeComponent);
     return(recipeComponent);
 }
Ejemplo n.º 24
0
        private void DownRecipeComponent(object recipeComponentInstance)
        {
            RecipeComponent recipeComponent = recipeComponentInstance as RecipeComponent;

            DownOrderComponent(recipeComponent);
        }
Ejemplo n.º 25
0
        private void UpRecipeComponent(object recipeComponentInstance)
        {
            RecipeComponent recipeComponent = recipeComponentInstance as RecipeComponent;

            UpOrderComponent(recipeComponent);
        }
Ejemplo n.º 26
0
 private string GetDispenser(RecipeComponent recipeComponent)
 {
     return(String.Equals(recipeComponent.Component.Consistency, ComponentConsistency.Dry) ? "Загр. вручную" : recipeComponent.Dispenser);
 }
Ejemplo n.º 27
0
 private string GetVolumeUnit(RecipeComponent recipeComponent)
 {
     return(String.Equals(recipeComponent.Component.Consistency, ComponentConsistency.Dry) ? VolumeUnit.Dry : VolumeUnit.Liquid);
 }
Ejemplo n.º 28
0
        internal static bool DetermineIfEnoughMaterials()
        {
            List <RecipeComponent> recipe = GetConstructRecipe();

            if (recipe == null)
            {
                return(false);
            }

            // check player inventory
            foreach (Item item in Program.Player.Inventory)
            {
                RecipeComponent itemC = item.ToComponent();
                if (recipe.Contains(itemC))
                {
                    recipe.Remove(itemC);
                }
            }

            // check map
            for (int i = 0; i < Program.WorldMap.LocalTile.Width; i++)
            {
                for (int j = 0; j < Program.WorldMap.LocalTile.Height; j++)
                {
                    if (Program.WorldMap.LocalTile[i, j] is Item item)
                    {
                        RecipeComponent itemC = item.ToComponent();
                        if (recipe.Contains(itemC))
                        {
                            recipe.Remove(itemC);
                        }
                    }
                    else if (Program.WorldMap.LocalTile[i, j] is Chest chest)
                    {
                        foreach (Item cItem in chest.Inventory)
                        {
                            RecipeComponent itemC = cItem.ToComponent();
                            if (recipe.Contains(itemC))
                            {
                                recipe.Remove(itemC);
                            }
                        }
                    }
                }
            }



            // check for other methods of resource aquisition
            if (recipe.Count > 0)
            {
                if (recipe.Contains(RecipeComponent.Log)) // find a tree if the recipe calls for a log
                {
                    for (int i = 0; i < Program.WorldMap.LocalTile.Width; i++)
                    {
                        for (int j = 0; j < Program.WorldMap.LocalTile.Height; j++)
                        {
                            if (Program.WorldMap.LocalTile[i, j] is Tree)
                            {
                                recipe.RemoveAll(rc => rc == RecipeComponent.Log);
                            }
                        }
                    }
                }

                if (recipe.Contains(RecipeComponent.Plank)) // find a tree or a log if the recipe calls for a plank
                {
                    for (int i = 0; i < Program.WorldMap.LocalTile.Width; i++)
                    {
                        for (int j = 0; j < Program.WorldMap.LocalTile.Height; j++)
                        {
                            if (Program.WorldMap.LocalTile[i, j] is Tree || Program.WorldMap.LocalTile[i, j] is Log)
                            {
                                recipe.RemoveAll(rc => rc == RecipeComponent.Plank);
                            }
                        }
                    }
                }
            }

            if (recipe.Count == 0)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 29
0
        private static void HandleGetMaterial(Creature c, RecipeComponent nextComponent, bool forCrafting = false)
        {
            Point nextPos = GetClosestMaterialPos(c, nextComponent, true); // returns new Point() if item is in player's inventory, returns null if the object can't be found

            // if the material is not on the map or in your inventory
            if (nextPos == null)
            {
                if (nextComponent == RecipeComponent.Log)
                {
                    HandleChopTree(c);
                }
                else if (nextComponent == RecipeComponent.Stone)
                {
                    HandleMineRock(c);
                }
                else
                {
                    // if there is no crafting recipe stored and the player has a recipe pouch
                    if (currentCraftingRecipe == null && c.Inventory.Exists(i => i is RecipePouch))
                    {
                        RecipePouch rp = (RecipePouch)c.Inventory.Find(i => i is RecipePouch);
                        foreach (CraftingRecipe r in rp.Recipes)
                        {
                            if (r.CraftingTarget.Exists(e => e.ToComponent() == nextComponent))
                            {
                                currentCraftingRecipe = r;
                                break;
                            }
                        }
                    }
                    else if (currentCraftingRecipe != null)
                    {
                        if (!currentCraftingRecipe.CraftingTarget.Exists(e => e.ToComponent() == nextComponent))
                        {
                            currentCraftingRecipe = null;
                        }
                        if (c.Inventory.Exists(i => i.ToComponent() == currentCraftingRecipe.Recipe[0]))
                        {
                            HandleCraftComponent(c);
                        }
                        else
                        {
                            HandleGetMaterial(c, currentCraftingRecipe.Recipe[0], true);
                        }
                    }
                }
                return;
            }

            if (nextPos.Equals(new Point()))
            {
                nextPos = GetClosestMaterialPos(c, nextComponent, false);
            }


            if (nextPos == null)
            {
                creatureStates[c.ID] = CreatureState.PlaceMaterials;
                return;
            }

            if (!nextPos.Equals(new Point()) || c.CheckCanCarryItem(nextComponent.ToItem()) == true)
            {
                bool    nextToItem = c.Position.NextToPoint(nextPos);
                int     currentFloor = c.CurrentFloor;
                Point   worldIndex = c.WorldIndex;
                Block[] blocks = currentFloor >= 0 ? Program.WorldMap[worldIndex.X, worldIndex.Y].Dungeon.Floors[currentFloor].Blocks : Program.WorldMap[worldIndex.X, worldIndex.Y].Blocks;
                int     width = Program.WorldMap.TileWidth, height = Program.WorldMap.TileHeight;

                if (nextToItem)
                {
                    if (blocks[nextPos.X * width + nextPos.Y] is Chest chest)
                    {
                        for (int i = chest.Inventory.Count - 1; i >= 0; i--)
                        {
                            if (chest.Inventory[i].ToComponent() == nextComponent)
                            {
                                bool itemAdded = c.AddItem(chest.Inventory[i]);
                                if (itemAdded)
                                {
                                    chest.Inventory.RemoveAt(i);
                                }
                                else if (DropUnnecessaryItems(c, nextComponent))
                                {
                                    itemAdded = c.AddItem(chest.Inventory[i]);
                                    if (itemAdded)
                                    {
                                        chest.Inventory.RemoveAt(i);
                                    }
                                    else
                                    {
                                        creatureStates[c.ID] = CreatureState.PlaceMaterials;
                                    }
                                }
                                else
                                {
                                    creatureStates[c.ID] = CreatureState.PlaceMaterials;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (c.CheckCanCarryItem((Item)blocks[nextPos.X * width + nextPos.Y]))
                        {
                            c.GetItem(nextPos);
                            getIndex++;
                        }
                        else
                        {
                            bool droppedItems = DropUnnecessaryItems(c, nextComponent);
                            if (droppedItems == false)
                            {
                                creatureStates[c.ID] = CreatureState.PlaceMaterials;
                            }
                        }
                    }
                }
                else if (c.Path == null)
                {
                    c.SetPath(nextPos);
                }
            }
            else
            {
                c.Path = null;
                creatureStates[c.ID] = CreatureState.PlaceMaterials;
            }
        }
Ejemplo n.º 30
0
        private static void HandleGetMaterial(RecipeComponent nextComponent, bool forCrafting = false)
        {
            Point nextPos = GetClosestMaterialPos(nextComponent, true); // returns new Point() if item is in player's inventory, returns null if the object can't be found

            if (nextPos == null)
            {
                if (nextComponent == RecipeComponent.Log)
                {
                    HandleChopTree();
                }
                else if (nextComponent == RecipeComponent.Stone)
                {
                }
                else
                {
                    if (currentCraftingRecipe == null && Program.Player.Inventory.Exists(i => i is RecipePouch))
                    {
                        RecipePouch rp = (RecipePouch)Program.Player.Inventory.Find(i => i is RecipePouch);
                        foreach (CraftingRecipe r in rp.Recipes)
                        {
                            if (r.CraftingTarget.Exists(e => e.ToComponent() == nextComponent))
                            {
                                currentCraftingRecipe = r;
                                break;
                            }
                        }
                    }
                    if (currentCraftingRecipe != null)
                    {
                        if (Program.Player.Inventory.Exists(i => i.ToComponent() == currentCraftingRecipe.Recipe[0]))
                        {
                            HandleCraftComponent();
                        }
                        else
                        {
                            HandleGetMaterial(currentCraftingRecipe.Recipe[0], true);
                        }
                    }
                }

                return;
            }

            bool hasItem = nextPos.Equals(new Point());

            if (hasItem == true)
            {
                nextPos = GetClosestMaterialPos(nextComponent, false);
            }


            if (nextPos == null)
            {
                playerState = PlayerState.PlaceMaterials;
                return;
            }

            if (hasItem == false || Program.Player.CanCarryItem(nextComponent.ToItem()) == true)
            {
                bool nextToItem = Program.Player.PointNextToSelf(nextPos);
                if (nextToItem)
                {
                    if (Program.WorldMap.LocalTile[nextPos.X, nextPos.Y] is Chest chest)
                    {
                        for (int i = chest.Inventory.Count - 1; i >= 0; i--)
                        {
                            if (chest.Inventory[i].ToComponent() == nextComponent)
                            {
                                bool itemAdded = Program.Player.AddItem(chest.Inventory[i]);
                                if (itemAdded)
                                {
                                    chest.Inventory.RemoveAt(i);
                                }
                                else if (DropUnnecessaryItems(nextComponent))
                                {
                                    itemAdded = Program.Player.AddItem(chest.Inventory[i]);
                                    if (itemAdded)
                                    {
                                        chest.Inventory.RemoveAt(i);
                                    }
                                    else
                                    {
                                        playerState = PlayerState.PlaceMaterials;
                                    }
                                }
                                else
                                {
                                    playerState = PlayerState.PlaceMaterials;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (Program.Player.CanCarryItem((Item)Program.WorldMap.LocalTile[nextPos.X, nextPos.Y]))
                        {
                            Program.Player.GetItem(nextPos);
                            getIndex++;
                        }
                        else
                        {
                            bool droppedItems = DropUnnecessaryItems(nextComponent);
                            if (droppedItems == false)
                            {
                                playerState = PlayerState.PlaceMaterials;
                            }
                        }
                    }
                }
                else if (Program.Player.Path == null)
                {
                    Program.Player.SetPath(nextPos);
                }
            }
            else
            {
                Program.Player.Path = null;
                playerState         = PlayerState.PlaceMaterials;
            }
        }