// Update is called once per frame
    void Update()
    {
        if (mNumFleetingDemands < maxFleetingDemands)
        {
            mFleetingDemandTimer -= GameState.GameDeltaTime;
            if (mFleetingDemandTimer <= 0)
            {
                int             tier           = Mathf.FloorToInt(GameState.GameTimeElapsed / 120);
                SacrificeDemand demand         = DemandGenerator.ScaledDemand(tier);
                SacrificeResult satisfied      = null;
                SacrificeResult ignored        = null;
                float           negativeChance = 0.8f - GameState.Favour * 0.1f;
                float           specialChance  = 0.0f + GameState.Favour * 0.05f;
                float           roll           = Random.value;
                if (roll <= negativeChance)
                {
                    ignored = BoonLibrary.RandomTemporaryCurse();
                }
                else
                if (roll - negativeChance <= specialChance)
                {
                    satisfied = BoonLibrary.RandomBoon(tier, GameState.Favour);
                }
                else
                {
                    satisfied = BoonLibrary.RandomTemporaryBoon(tier, GameState.Favour);
                }

                GodDemand d = new GodDemand(demand, satisfied, ignored);
                d.mTimeLeft = 30;
                mDemands.Add(d);

                //mFleetingDemands.Add(new FleetingDemand(d, 30));
                mFleetingDemandTimer = Random.Range(fleetingDemandTimer - (fleetingDemandTimer / 2), fleetingDemandTimer + (fleetingDemandTimer / 2));
            }
        }

        for (int i = mDemands.Count - 1; i >= 0; --i)
        {
            GodDemand d = mDemands[i];
            if (d.mTimeLeft == -1)
            {
                // fleeting demands are tacked on to the end, so once we hit a non-fleeting we're done
                break;
            }

            if (d.mTimeLeft > 0)
            {
                d.mTimeLeft -= GameState.GameDeltaTime;
                if (d.mTimeLeft <= 0)
                {
                    if (d.mIgnoredResult != null)
                    {
                        d.mIgnoredResult.DoEffect();
                    }
                    mDemands.RemoveAt(i);
                }
            }
        }
    }
Beispiel #2
0
    public GodDemand(SacrificeDemand demand, SacrificeResult satisfiedResult, SacrificeResult ignoredResult)
    {
        mId = ++sId;

        mDemand          = demand;
        mSatisfiedResult = satisfiedResult;
        mIgnoredResult   = ignoredResult;
    }
    public static SacrificeDemand TierOneDemand()
    {
        SacrificeDemand d = new SacrificeDemand();

        Criterion c = new Criterion();

        c.mCount      = Random.Range(1, 3);
        c.mAttributes = GenerateRandomDemands(1);
        d.mCriteria.Add(c);

        return(d);
    }
    public static SacrificeDemand TierTwoDemand()
    {
        SacrificeDemand d = new SacrificeDemand();

        Criterion c = new Criterion();

        c.mMinLevel = 6;

        c.mAttributes = GenerateRandomDemands(2);

        d.mCriteria.Add(c);

        return(d);
    }
    public static SacrificeDemand EasiestDemand()
    {
        // guaranteed to be satisfiable now
        SacrificeDemand        d          = new SacrificeDemand();
        List <PersonAttribute> attributes = GenerateSatisfiableDemands(1);

        foreach (PersonAttribute attr in attributes)
        {
            Criterion c = new Criterion();
            c.mAttributes.Add(attr);
            d.mCriteria.Add(c);
        }

        return(d);
    }
    public List <GodDemand> GenerateInitialDemands()
    {
        SacrificeDemand victoryDemand = new SacrificeDemand();
        Criterion       profC         = new Criterion();

        profC.mMinLevel = 1;
        profC.mAttributes.Add(PersonAttribute.WARRIOR);
        profC.mCount = 1;
        victoryDemand.mCriteria.Add(profC);
        GodDemand victory = new GodDemand(victoryDemand, new VictoryResult(), null);

        return(new List <GodDemand>()
        {
            victory
        });
    }
    public static SacrificeDemand BuildDemand(int numGuaranteed, int numAny, int numPerCriterion)
    {
        SacrificeDemand d = new SacrificeDemand();

        // 11th hour special case hacks
        if (numPerCriterion == 2)
        {
            Criterion         doubleCrit  = new Criterion();
            PersonAttribute[] doubleAttrs = Person.RandomAttributes(1);
            doubleCrit.mAttributes = new List <PersonAttribute>(doubleAttrs);
            d.mCriteria.Add(doubleCrit);
            return(d);
        }

        List <PersonAttribute> attributes = GenerateSatisfiableDemands(numGuaranteed);
        List <PersonAttribute> anyAttrs   = GenerateRandomDemandsDumb(numAny);

        List <PersonAttribute> allAttrs = new List <PersonAttribute>();

        for (int i = 0; i < anyAttrs.Count; ++i)
        {
            allAttrs.Add(anyAttrs[i]);
        }
        for (int i = 0; i < attributes.Count; ++i)
        {
            PersonAttribute attr = attributes[i];
            if (!allAttrs.Contains(attr))
            {
                allAttrs.Add(attr);
            }
        }

        int idx = 0;

        while (idx < allAttrs.Count)
        {
            Criterion c = new Criterion();
            for (int i = 0; i < numPerCriterion && idx < allAttrs.Count; ++i)
            {
                c.mAttributes.Add(allAttrs[idx]);
                ++idx;
            }
            d.mCriteria.Add(c);
        }

        return(d);
    }
    // Returns a list of strings to be used in top-left, top-right, bottom-left, bottom-right order in a list of people
    // Icons (profession and health) are added by the UI Manager
    public string[] GetUIDescription(SacrificeDemand selectedDemand)
    {
        List <PersonAttribute> nonProfAttributes = NonProfessionAttributes;
        string attrString = "";

        for (int i = 0; i < nonProfAttributes.Count; ++i)
        {
            string attr       = System.Enum.GetName(typeof(PersonAttribute), (int)nonProfAttributes[i]);
            bool   isRelevant = selectedDemand != null && selectedDemand.IsRelevantAttribute(nonProfAttributes[i]);
            attrString += Utilities.ColorString(attr, "green", isRelevant) + ", ";
        }
        bool   isLevelRelevant = selectedDemand != null && selectedDemand.IsRelevantLevel(mLevel);
        string levelString     = "Lvl " + Utilities.ColorString(GetLevelString(), "green", isLevelRelevant);
        string lifeString      = (mIsHungry ? "<size=10>STARVING!</size> " : "") + " " + Utilities.ColorString(Utilities.ColorString(Mathf.Ceil(mHealth).ToString(), "red", mRecentHealthChange < 0f), "green", mRecentHealthChange > 0f);
        string ageString       = Utilities.ColorString(mName + " (Age " + Age + ")", "green", selectedDemand != null && selectedDemand.IsRelevantAge(Age));

        return(new [] { ageString, attrString, levelString, lifeString });
    }
    public static SacrificeDemand SimpleDemand(int tier)
    {
        SacrificeDemand d = new SacrificeDemand();

        int minAttr       = Mathf.Min(2, 1 + tier);
        int maxAttr       = Mathf.Min(3, 2 + tier);
        int numAttributes = Random.Range(minAttr, maxAttr + 1);
        List <PersonAttribute> attributes = GenerateSatisfiableDemands(numAttributes);

        // add them as separate criteria so that they're easier to satisfy
        foreach (PersonAttribute attr in attributes)
        {
            Criterion c = new Criterion();
            c.mAttributes.Add(attr);
            d.mCriteria.Add(c);
        }

        return(d);
    }
    public List <GodDemand> GenerateInitialDemands()
    {
        // Renewable demands
        List <GodDemand> result = new List <GodDemand>();

        foreach (SacrificeResult sr in BoonLibrary.sGuaranteedRenewableBoons)
        {
            GodDemand renewableDemand = new GodDemand(
                DemandGenerator.ScaledDemand(0),
                sr,
                null
                );
            renewableDemand.mIsRenewable = true;
            result.Add(renewableDemand);
        }
        // A group of random demands
        result.AddRange(GenerateDemandGroup(3));
        // The victory demand
        SacrificeDemand victoryDemand = new SacrificeDemand();
        int             numToChoose   = 1;
        int             requiredLevel = 7;
        int             requiredCount = 3;

        if (Random.value < 0.5)
        {
            numToChoose   = 3;
            requiredLevel = 6;
            requiredCount = 1;
        }
        PersonAttribute[] allProfessions    = PersonAttributeType.PROFESSION.GetAllValues();
        PersonAttribute[] randomProfessions = Utilities.RandomSubset <PersonAttribute>(allProfessions, numToChoose);
        foreach (PersonAttribute profession in randomProfessions)
        {
            Criterion profC = new Criterion();
            profC.mMinLevel = requiredLevel;
            profC.mAttributes.Add(profession);
            profC.mCount = requiredCount;
            victoryDemand.mCriteria.Add(profC);
        }
        result.Add(new GodDemand(victoryDemand, new VictoryResult(), null));
        return(result);
    }
    public static SacrificeDemand PersonDemand(int tier)
    {
        int numPeople = tier >= 6 ? 2 : 1;

        Person[] people = Utilities.RandomSubset <Person>(Utilities.GetPersonManager().People.ToArray(), numPeople);

        SacrificeDemand d = new SacrificeDemand();

        foreach (Person p in people)
        {
            Criterion c = new Criterion();
            c.mMinLevel = p.Level;
            c.mAttributes.Add(p.Profession);
            List <PersonAttribute> personAttributes = p.NonProfessionAttributes;
            c.mAttributes.Add(personAttributes[Random.Range(0, personAttributes.Count)]);
            d.mCriteria.Add(c);
        }

        return(d);
    }
    public static SacrificeDemand ScaledDemand(int tier, bool mustBeSatisfiable = false)
    {
        tier = Mathf.Max(0, tier + (Random.Range(0, 100) / 70));
        if (tier == 0)
        {
            // one attribute that you have
            return(EasiestDemand());
        }

        if (tier == 1)
        {
            // 1 attribute that you may not have
            if (!mustBeSatisfiable && Random.value < 0.5)
            {
                return(BuildDemand(0, 1, 1));
            }

            // 2 on the same person
            if (!mustBeSatisfiable && Random.value < 0.7)
            {
                return(BuildDemand(1, 1, 2));
            }

            return(BuildDemand(1, 0, 1));
        }

        if (tier == 2)
        {
            if (mustBeSatisfiable)
            {
                return(BuildDemand(1, 0, 1));
            }

            if (Random.value < 0.5)
            {
                // 2 on the same person
                return(BuildDemand(1, 1, 2));
            }

            // 1 attribute that you may not have, plus extra constraint
            SacrificeDemand d = BuildDemand(0, 1, 1);
            d.mCriteria[0].mMinLevel = Random.Range(2, 4);
            return(d);
        }

        // tier >= 3
        if (mustBeSatisfiable)
        {
            // demand a specific person
            return(PersonDemand(tier));
        }

        SacrificeDemand demand;

        if (Random.value < 0.5)
        {
            // 2 attributes you have
            demand = BuildDemand(2, 0, 1);
        }
        else if (Random.value < 0.5)
        {
            // one of each
            demand = BuildDemand(1, 1, 1);
        }
        else
        {
            // 2 attributes that you may not have
            demand = BuildDemand(0, 2, 1);
        }

        if (tier >= 4)
        {
            int personCount = Mathf.Min((tier / 2) + 1, 3);
            foreach (Criterion c in demand.mCriteria)
            {
                if (Random.value < 0.5)
                {
                    c.mMinLevel = tier + 1;
                }

                if (personCount > 0 && Random.value < 0.1 + (tier / 10))
                {
                    c.mCount     = Mathf.Min(Random.Range(1, personCount + 1), 3);
                    personCount -= c.mCount;
                }
            }
        }

        return(demand);
    }