Esempio n. 1
0
        public void TickCrafting()
        {
            if (!IsCrafting)
            {
                return;
            }

            if (_currentCrafter == null)
            {
                throw new Exception("Attempted to tick crafting, but no crafter.");
            }

            if (_currentCraftingState == null)
            {
                throw new Exception("Attempted to tick crafting, but no crafting state.");
            }

            // TODO: Logic for crafting work per tick;
            _currentCraftingState.AddWork(_currentCraftingState.CraftingDef.BaseWorkPerTick, _currentCrafter);

            if (_currentCraftingState.PercentDone >= 1)
            {
                var itemController = GameMaster.Instance.GetController <IItemController>();
                var def            = itemController.GetDef(_currentCraftingState.CraftingDef.OutputItemDefName);
                itemController.CreateNewItems(def, _outputInventory, _currentCraftingState.CraftingDef.OutputCount);

                _currentCraftingState = null;
                _currentCrafter       = null;
            }
        }
Esempio n. 2
0
 void OnDragAndClear_CraftingIngredientSlot(int slotIndex)
 {
     if (craftingState != CraftingState.InProgress)
     {
         indices[slotIndex] = -1;
         craftingState      = CraftingState.None;
     }
 }
Esempio n. 3
0
        internal BaseManufacturerBuilding(ManufacturingBuildingDef def, string layerName, MapSpot anchor, IMapController controller, MapRotation rotation)
            : base(def, layerName, anchor, controller, rotation)
        {
            _manufacturingBuildingDef = def ?? throw new ArgumentNullException(nameof(def));

            _outputInventory      = new DefaultInventory(GameMaster.Instance.GetController <IItemController>(), this, _manufacturingBuildingDef.OutputConfig);
            _inputInventory       = new DefaultInventory(GameMaster.Instance.GetController <IItemController>(), this, _manufacturingBuildingDef.InputConfig);
            _currentCraftingState = null;
        }
Esempio n. 4
0
 void OnDragAndClear_CraftingIngredientSlot(int slotIndex)
 {
     // only if not crafting right now
     if (state != CraftingState.InProgress)
     {
         indices[slotIndex] = -1;
         state = CraftingState.None; // reset state
     }
 }
Esempio n. 5
0
 void OnDragAndDrop_CraftingIngredientSlot_CraftingIngredientSlot(int[] slotIndices)
 {
     if (craftingState != CraftingState.InProgress)
     {
         int temp = indices[slotIndices[0]];
         indices[slotIndices[0]] = indices[slotIndices[1]];
         indices[slotIndices[1]] = temp;
         craftingState           = CraftingState.None;
     }
 }
Esempio n. 6
0
 void OnDragAndDrop_InventorySlot_CraftingIngredientSlot(int[] slotIndices)
 {
     if (craftingState != CraftingState.InProgress)
     {
         if (!indices.Contains(slotIndices[0]))
         {
             indices[slotIndices[1]] = slotIndices[0];
             craftingState           = CraftingState.None;
         }
     }
 }
Esempio n. 7
0
 void OnDragAndDrop_CraftingIngredientSlot_CraftingIngredientSlot(int[] slotIndices)
 {
     // slotIndices[0] = slotFrom; slotIndices[1] = slotTo
     // only if not crafting right now
     if (state != CraftingState.InProgress)
     {
         // just swap them clientsided
         int temp = indices[slotIndices[0]];
         indices[slotIndices[0]] = indices[slotIndices[1]];
         indices[slotIndices[1]] = temp;
         state = CraftingState.None; // reset state
     }
 }
Esempio n. 8
0
 // drag & drop /////////////////////////////////////////////////////////////
 void OnDragAndDrop_InventorySlot_CraftingIngredientSlot(int[] slotIndices)
 {
     // slotIndices[0] = slotFrom; slotIndices[1] = slotTo
     // only if not crafting right now
     if (state != CraftingState.InProgress)
     {
         if (!indices.Contains(slotIndices[0]))
         {
             indices[slotIndices[1]] = slotIndices[0];
             state = CraftingState.None; // reset state
         }
     }
 }
Esempio n. 9
0
    [HideInInspector] public CraftingState craftingState = CraftingState.None; // // client sided

    // craft the current combination of items and put result into inventory
    public void Craft(int[] indices)
    {
        // validate: between 1 and 6, all valid, no duplicates?
        if (health.current > 0 &&
            0 < indices.Length && indices.Length <= ScriptableRecipe.recipeSize &&
            indices.All(index => 0 <= index && index < inventory.slots.Count && inventory.slots[index].amount > 0) &&
            !indices.ToList().HasDuplicates())
        {
            // build list of item templates from indices
            List <ItemSlot> items = indices.Select(index => inventory.slots[index]).ToList();

            // find recipe
            ScriptableRecipe recipe = ScriptableRecipe.dict.Values.ToList().Find(r => r.CanCraftWith(items)); // good enough for now
            if (recipe != null && recipe.result != null)
            {
                // enough space?
                Item result = new Item(recipe.result);
                if (inventory.CanAdd(result, 1))
                {
                    // remove the ingredients from inventory in any case
                    foreach (ScriptableItemAndAmount ingredient in recipe.ingredients)
                    {
                        if (ingredient.amount > 0 && ingredient.item != null)
                        {
                            inventory.Remove(new Item(ingredient.item), ingredient.amount);
                        }
                    }

                    // roll the dice to decide if we add the result or not
                    // IMPORTANT: we use rand() < probability to decide.
                    // => UnityEngine.Random.value is [0,1] inclusive:
                    //    for 0% probability it's fine because it's never '< 0'
                    //    for 100% probability it's not because it's not always '< 1', it might be == 1
                    //    and if we use '<=' instead then it won't work for 0%
                    // => C#'s Random value is [0,1) exclusive like most random
                    //    functions. this works fine.
                    if (new System.Random().NextDouble() < recipe.probability)
                    {
                        // add result item to inventory
                        inventory.Add(result, 1);
                        craftingState = CraftingState.Success;
                    }
                    else
                    {
                        craftingState = CraftingState.Failed;
                    }
                }
            }
        }
    }
Esempio n. 10
0
        public string TryStartCrafting(string craftingDefName, ICrafter crafter)
        {
            // TODO: Logic for filtering crafters
            //if (false)
            //    return false;

            if (!_manufacturingBuildingDef.CraftingDefs.Where(x => x.DefName == craftingDefName).Any())
            {
                throw new Exception("Crafting def '{craftingDefName}' not found.");
            }

            _currentCrafter       = crafter;
            _currentCraftingState = new CraftingState(_manufacturingBuildingDef.CraftingDefs.Single(x => x.DefName == craftingDefName));
            return(CraftingResults.Success);
        }
Esempio n. 11
0
    private void OnStateChanged(int state)
    {
        //changing state either leaves the scene and wants to Reset the Pentagram, or crafts and also wants to Reset.
        //clears away ingredients from pentagram, and updatesHotbar
        ResetScene();

        CraftingState enumState = (CraftingState)state;

        switch (enumState)
        {
        case CraftingState.Crafting:
            //hides results panel
            _potionResultsUI.SetActive(false);

            //save then Entering Scene to run Initializer Settings and update Hotbar needs
            fileUtility.Save();
            break;

        case CraftingState.Achievements:
            SceneManager.LoadScene("Achievement");
            break;

        case CraftingState.Store:
            SceneManager.LoadScene("Shop");
            break;

        case CraftingState.Journal:
            SceneManager.LoadScene("Journal");
            break;

        case CraftingState.PotionResult:
            _potionResultsUI.SetActive(true);

            //only Saving() after PotionResult to update Hotbar Qty. and record PotionHistory
            fileUtility.Save();

            //update goldText, after crafting and earning gold
            _goldText.text = fileUtility.SaveObject.gold.ToString();
            break;

        default:
            Debug.Log("state not implemented");
            break;
        }
    }
 private void OnPushOrPopScreen(ScreenBase _)
 {
     craftingState = Game.Current?.GameStateManager.ActiveState as CraftingState;
 }
Esempio n. 13
0
 public void StopCrafting()
 {
     _currentCrafter       = null;
     _currentCraftingState = null;
 }
Esempio n. 14
0
 [TargetRpc] // only send to one client
 public void TargetCraftingFailed()
 {
     state = CraftingState.Failed;
 }
Esempio n. 15
0
 [TargetRpc] // only send to one client
 public void TargetCraftingSuccess()
 {
     state = CraftingState.Success;
 }