Beispiel #1
0
    private void OnAtomDiscover(Atom a, float amo)
    {
        if (undiscoveredOptions.Count == 0)
        {
            Game.Instance.gameData.OnAtomDiscover -= OnAtomDiscover;
            return;
        }

        for (int i = 0; i < undiscoveredOptions.Count; i++)
        {
            Craftable c = undiscoveredOptions[i];

            bool canCraft      = true;
            var  atomsForCraft = c.GetAtomsForProduction();
            for (int y = 0; y < atomsForCraft.Length; y++)
            {
                var atomAmo = atomsForCraft[y];
                if (!Game.Instance.gameData.FindAtomData(atomAmo.atom.GetAtomicNumber()).IsDiscovered())
                {
                    canCraft = false;
                    break;
                }
            }
            if (canCraft)
            {
                AddCraftable(craftableChoices[c]);
                undiscoveredOptions.RemoveAt(i);
                i--;
            }
        }
    }
    public CraftResult Craft(Craftable c, int amount)
    {
        CraftResult result = new CraftResult();

        result.atomsUsed = new List <AtomAmo>();

        var atoms = c.GetAtomsForProduction();

        for (int i = 0; i < atoms.Length; i++)  // Find Minumum
        {
            var atomAmo = atoms[i];

            AtomData data = Game.Instance.gameData.FindAtomData(atomAmo.atom.GetAtomicNumber());

            int needed = atomAmo.amo * amount;
            if (data.GetCurrAmo() < needed)
            {
                amount = data.GetCurrAmo() / atomAmo.amo;
            }
        }

        for (int i = 0; i < atoms.Length; i++)
        {
            var atomAmo = atoms[i];

            AtomData data = Game.Instance.gameData.FindAtomData(atomAmo.atom.GetAtomicNumber());

            int needed = atomAmo.amo * amount;
            data.Lose(needed);

            AtomAmo atomUsed = new AtomAmo();
            atomUsed.atom = atomAmo.atom;
            atomUsed.amo  = needed;
            result.atomsUsed.Add(atomUsed);
        }
        result.amountCreated = amount;

        int amoOfCraftables;

        if (!craftables.TryGetValue(c, out amoOfCraftables))
        {
            craftables[c] = amount;
        }
        else
        {
            craftables[c] = amoOfCraftables + amount;
        }

        if (OnCraftableProduced != null)
        {
            OnCraftableProduced(c, amount);
        }

        return(result);
    }
    public bool CanCraft(Craftable c)
    {
        int amount = 1;

        var atoms = c.GetAtomsForProduction();

        for (int i = 0; i < atoms.Length; i++)   // Find Minumum
        {
            var atomAmo = atoms[i];

            AtomData data = Game.Instance.gameData.FindAtomData(atomAmo.atom.GetAtomicNumber());

            int needed = atomAmo.amo * amount;
            if (data.GetCurrAmo() < needed)
            {
                amount = data.GetCurrAmo() / atomAmo.amo;
            }
        }

        return(amount != 0);
    }
Beispiel #4
0
    private void OnCraftableDiscover(Craftable c, float amo)
    {
        var craftablChoice = Instantiate(choicePrefab);

        // Pos
        craftablChoice.transform.SetParent(craftableListRect, false);
        craftablChoice.transform.localScale = Vector3.one;

        // Data / Functionality
        SetCraftableChoice(craftablChoice, c);
        craftablChoice.SetButtonEvent(() => { // Event should never change
            SetCraftable(c);
            AudioManager.Instance.PlaySound(choiceClickSound);
        });
        craftablChoice.SetColors(ChoiceOption.defaultNormalColor, ChoiceOption.defaultHoverColor, ChoiceOption.defaultPressedColor);

        craftableChoices.Add(c, craftablChoice);

        bool canCraft      = true;
        var  atomsForCraft = c.GetAtomsForProduction();

        for (int y = 0; y < atomsForCraft.Length; y++)
        {
            var atomAmo = atomsForCraft[y];
            if (!Game.Instance.gameData.FindAtomData(atomAmo.atom.GetAtomicNumber()).IsDiscovered())
            {
                canCraft = false;
                break;
            }
        }
        if (canCraft)
        {
            AddCraftable(craftablChoice);
        }
        else
        {
            undiscoveredOptions.Add(c);
            craftablChoice.gameObject.SetActive(false);
        }
    }
Beispiel #5
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;
    }