Exemplo n.º 1
0
 public void Bind(Crafter crafter)
 {
     _crafter = crafter;
     CraftButton.onClick.AddListener(() =>
     {
         var ammo = _crafter.Craft();
         if (ammo == AmmoType.None)
         {
             AboveText.Show("invalid combination", 2, Color.red);
         }
         else
         {
             foreach (Transform t in SlotParent)
             {
                 Destroy(t.gameObject);
             }
             AboveText.Show("Crafted " + ammo.ToString(), 2, Color.green);
             Cannon.SetTrigger("shoot");
             Observable.Timer(TimeSpan.FromSeconds(.25f)).Subscribe(ev =>
             {
                 var sp = Instantiate(Spark, AmmoPoint.position, Quaternion.identity);
                 Destroy(sp, 1);
                 var proj  = Instantiate(AmmoPrefab, AmmoPoint.position, Quaternion.identity).GetComponent <Projectile>();
                 proj.Type = ammo;
             });
         }
     });
 }
Exemplo n.º 2
0
    public void Accept()
    {
        var messageBox = GameController.instance.buttons.messageBox;

        if (crafter.isPrescripted)
        {
            string result = crafter.Craft(quantity);
            if (result == "TRUE")
            {
                if (!crafter.tutorial.isTutorialCompleted)
                {
                    crafter.tutorial.ContinueTutorial();
                    GameController.instance.buttons.ShowCancel();
                }
                messageBox.Show("x" + quantity + " " + crafter.recipeSelected.description.Name + " crafted", crafter.recipeSelected.description.sprite);
                Hide();
                GameController.instance.audio.MakeSound(onCraft);
            }
            else
            {
                NotifyAboutResources();
                return;
            }
        }
        else
        {
            // get name from input and craft new recipe with this name
            string recipeName = input.textComponent.text;
            if (recipeName == string.Empty)
            {
                recipeName = GenerateName();
            }
            Validator validate = new Validator();
            if (!validate.ValidateRecipeName(recipeName, GameController.instance.player.inventory) || recipeName == "Invalid name!")
            {
                input.textComponent.text = "";
                input.text        = "Invalid name!";
                redBorder.enabled = true;
                return;
            }
            int researchPointsNeeded = crafter.CalculateResearchPoints(crafter.selectedTalents);

            redBorder.enabled = false;
            string result = crafter.Craft(recipeName, quantity, recipeAvatar.sprite);
            if (result == "TRUE")
            {
                if (!crafter.tutorial.isTutorialCompleted)
                {
                    crafter.tutorial.ContinueTutorial();
                    GameController.instance.buttons.ShowCancel();
                }
                messageBox.Show(crafter.recipeSelected.description.Name + " was created", crafter.recipeSelected.description.sprite);
                Hide();
                GameController.instance.audio.MakeSound(onCraft);
            }

            else if (result == "FALSE")
            {
                NotifyAboutResources();
                return;
            }
            else if (result == "FULL")
            {
                messageBox.Show("Inventory is full. Delete one recipe");
                return;
            }
        }
    }