コード例 #1
0
    public MeatData ChooseMeatToBuy()
    {
        WeightedList <MeatPopularity> meatsToChooseFrom = new WeightedList <MeatPopularity>(NpcCharacterBehaviour.CurrentCityRegion.meatsPopularity.List);
        MeatData chosenMeat = null;

        while (!chosenMeat && meatsToChooseFrom.List.Count > 0)
        {
            MeatPopularity tempChosenMeatPopularity = meatsToChooseFrom.GetRandomWeightedElement();
            chosenMeat = GameManager.Instance.Player.Inventory.HasMeatType(tempChosenMeatPopularity.meatData) ? tempChosenMeatPopularity.meatData : null;
            if (!chosenMeat)
            {
                if (tempChosenMeatPopularity.thisOrNothing)
                {
                    break;
                }
                else
                {
                    meatsToChooseFrom.List.Remove(tempChosenMeatPopularity);
                }
            }
        }

        if (!chosenMeat)
        {
            NoMeatBought();
        }

        return(chosenMeat);
    }
コード例 #2
0
    public void CustomerBuy(NpcCharacterBehaviour customer, MeatData meatDataBought)
    {
        if (meatDataBought)
        {
            MeatBehaviour spawnedMeatBehaviourBought = spawnedMeats.Find(meatBehaviour => meatBehaviour.meat.Data == meatDataBought);
            spawnedMeats.Remove(spawnedMeatBehaviourBought);
            GameManager.Instance.Player.Inventory.Meats.Remove(spawnedMeatBehaviourBought.meat);

            MeatPopularity boughtMeatPopularity = customer.CurrentCityRegion.meatsPopularity.List.Find(meatPopularity => meatPopularity.meatData == meatDataBought);
            boughtMeatPopularity.DecreasePopularityAfterBuy();

            spawnedMeatBehaviourBought.JumpTo(customer.mainRigidbody.position, true, () => Destroy(spawnedMeatBehaviourBought.gameObject), true);

            int cashValueEarned = boughtMeatPopularity.GetMeatFinalValue();
            for (int i = 0; i < cashValueEarned; i++)
            {
                spawnedEarnedCash.Add(Instantiate(cashTable.CashValues[1], customer.mainRigidbody.position, Quaternion.identity, transform));
            }
            GameManager.Instance.Player.Inventory.Cash += cashValueEarned;
        }
    }