Esempio n. 1
0
    private void AttemptToLureBuyer()
    {
        List <House> partyingHouses = GetPartyingHouses();
        List <Buyer> targets        = GetAimlessBuyers();

        if (partyingHouses.Count == 0 || targets.Count == 0)
        {
            return;
        }

        // Pick a random index
        System.Random random     = new System.Random();
        int           houseIndex = random.Next(partyingHouses.Count);

        List <House> partyingHousesByGenre = GetPartyingHousesByGenre(partyingHouses[houseIndex].genre);

        Dictionary <FactionLogic.Genre, float> probabilities = buyersFactionLogic.GetProbabilities();
        float attraction;
        bool  successfulRetrieval = probabilities.TryGetValue(partyingHouses[houseIndex].genre, out attraction);

        if (!successfulRetrieval)
        {
            Debug.LogError("Failed to retrieve value from a genre!");
            return;
        }

        float ratioGenreHouses = ((float)partyingHousesByGenre.Count) / ((float)partyingHouses.Count);
        float totalProbability = attraction * ratioGenreHouses;

        if (Random.Range(0.0f, 1.0f) > totalProbability)
        {
            int targetIndex = random.Next(targets.Count);
            targets[targetIndex].SetHouse(partyingHouses[houseIndex]);
        }
    }
Esempio n. 2
0
    private FactionLogic.Genre PickGenre()
    {
        Dictionary<FactionLogic.Genre, float> probabilities = factionLogic.GetProbabilities();

        float randomValue = Random.Range(0.0f, 1.0f);
        float rangeStart = 0.0f;
        float rangeEnd = 0.0f;

        foreach (KeyValuePair<FactionLogic.Genre, float> entry in probabilities)
        {
            rangeEnd += entry.Value;

            if (randomValue > rangeStart && randomValue < rangeEnd)
            {
                return entry.Key;
            }
            rangeStart = rangeEnd;
        }

        Debug.LogError("PickGenre failed to calculate a genre to pick!");
        return FactionLogic.Genre.METAL;
    }