public int Sell(Craftable c, int amo)
    {
        int amoOfCraftables;

        if (craftables.TryGetValue(c, out amoOfCraftables))
        {
            if (amo > amoOfCraftables)
            {
                amo = amoOfCraftables;
            }

            craftables[c] = amoOfCraftables - amo;
            money        += c.GetPrice() * amo;

            if (OnMoneyChange != null)
            {
                OnMoneyChange(money);
            }


            if (OnCraftableSold != null)
            {
                OnCraftableSold(c, amo);
            }

            return(amo);
        }
        return(0);
    }
Example #2
0
    public void SetCraftableChoice(ChoiceOption choice, Craftable c)
    {
        int amo = Game.Instance.playerData.GetCraftableAmount(c);

        choice.SetText(c.GetName() + " (" + amo + ")\n<size=80%>    Price: $" + c.GetPrice());
    }
Example #3
0
    public void SetCraftable(Craftable c)
    {
        RemoveCraftable();

        ChoiceOption choiceOption;

        if (craftableChoices.TryGetValue(c, out choiceOption))
        {
            choiceOption.SetButtonEvent(() => {
                RemoveCraftable();
                AudioManager.Instance.PlaySound(choiceClickSound);
            });
            choiceOption.SetColors(ChoiceOption.defaultPressedColor, ChoiceOption.defaultHoverColor, ChoiceOption.defaultNormalColor);
            choiceOption.SetFocus(false);
        }

        currCraftable = c;

        int amo = Game.Instance.playerData.GetCraftableAmount(c);

        craftableImage.sprite = c.GetSprite();

        craftableNameText.text = c.GetName();
        craftableInfoText.text = "Price: $" + c.GetPrice() + "\nCurr Amo: " + amo;

        StringBuilder atomName = new StringBuilder();
        StringBuilder atomAmo  = new StringBuilder();
        StringBuilder atomHave = new StringBuilder();
        var           atoms    = c.GetAtomsForProduction();

        for (int i = 0; i < atoms.Length; i++)
        {
            Atom a = atoms[i].atom;

            AtomData data = Game.Instance.gameData.FindAtomData(a.GetAtomicNumber());
            if (data.GetCurrAmo() >= atoms[i].amo)
            {
                atomName.Append(a.GetName() + "\n");
                atomAmo.Append(atoms[i].amo + "\n");
                atomHave.Append(data.GetCurrAmo() + "\n");
            }
            else
            {
                atomName.Append("<color=#ff8080>" + a.GetName() + "\n</color>");
                atomAmo.Append("<color=#ff8080>" + atoms[i].amo + "\n</color>");
                atomHave.Append("<color=#ff8080>" + data.GetCurrAmo() + "\n</color>");
            }
        }

        atomsRequiredText.text  = atomName.ToString();
        atomAmountText.text     = atomAmo.ToString();
        currAtomAmountText.text = atomHave.ToString();

        var size = atomNeededRect.sizeDelta;

        size.y = atoms.Length * 36;
        atomNeededRect.sizeDelta = size;

        bool canCraft = Game.Instance.playerData.CanCraft(c);

        craftBtn.interactable     = canCraft;
        craftBtnx10.interactable  = canCraft;
        craftBtnx100.interactable = canCraft;

        bool canSell = Game.Instance.playerData.GetCraftableAmount(c) > 0;

        sellBtn.interactable     = canSell;
        sellBtnx10.interactable  = canSell;
        sellBtnx100.interactable = canSell;
    }