Beispiel #1
0
        public bool Test(Parameters parameters, string name, SimDescription sim, SimDescription potential, bool testScore, out int score)
        {
            score = 0;

            if (SimTypes.IsDead(potential))
            {
                parameters.IncStat(name + " Dead Fail");
                return false;
            }

            if (!parameters.CustomTestAllow (potential))
            {
                parameters.IncStat(name + " Custom Fail");
                return false;
            }

            if ((mCustomTest.Valid) && (!mCustomTest.Invoke<bool>(new object[] { parameters, sim, potential })))
            {
                parameters.IncStat(name + " Custom Test Fail");
                return false;
            }

            parameters.IncStat("Testing " + potential.FullName, Common.DebugLevel.Logging);

            CASAgeGenderFlags age = (mAgeGender & CASAgeGenderFlags.AgeMask);

            if ((age == CASAgeGenderFlags.None) && (potential.ToddlerOrBelow))
            {
                parameters.IncStat(name + " Too Young");
                return false;
            }
            else if ((age != CASAgeGenderFlags.None) && ((mAgeGender & potential.Age) != potential.Age))
            {
                parameters.IncStat(name + " Age Fail");
                return false;
            }
            else if (((mAgeGender & CASAgeGenderFlags.GenderMask) != CASAgeGenderFlags.None) && ((mAgeGender & potential.Gender) != potential.Gender))
            {
                parameters.IncStat(name + " Gender Fail");
                return false;
            }
            else if (!mSpecies.Contains(potential.Species))
            {
                parameters.IncStat(name + " Species Fail");
                return false;
            }

            if ((!mAllowAffair) && (parameters.mIsRomantic) && (sim != null))
            {
                if (((potential.Partner != null) || (sim.Partner != null)) && (potential.Partner != sim))
                {
                    parameters.IncStat(name + " Affair Denied");
                    return false;
                }
            }

            if ((sim != null) && (sim != potential))
            {
                if ((mStandardDisallowPartner) && (sim.Partner == potential))
                {
                    parameters.IncStat(name + " Partner Fail");
                    return false;
                }

                if ((!mAllowOpposing) && (StoryProgression.Main.Personalities.IsOpposing(parameters, sim, potential, false)))
                {
                    parameters.IncStat(name + " Clan Opposing Fail");
                    return false;
                }

                if (!parameters.mIsFriendly)
                {
                    if (StoryProgression.Main.Personalities.IsFriendly(parameters, sim, potential))
                    {
                        parameters.IncStat(name + " Clan Friendly Denied");
                        return false;
                    }
                }

                int liking = 0;

                Relationship relation = Relationship.Get(sim, potential, false);
                if (relation != null)
                {
                    liking = (int)relation.LTR.Liking;
                }

                if (liking < mRelationshipMinimum)
                {
                    parameters.IncStat(name + " Relationship Underscore");
                    return false;
                }
                else if (liking > mRelationshipMaximum)
                {
                    parameters.IncStat(name + " Relationship Overscore");
                    return false;
                }
            }

            foreach (IValueTestOption value in mValueTestOptions)
            {
                if (!value.Satisfies())
                {
                    parameters.IncStat(name + " " + value.ToString() + " Value Fail");
                    return false;
                }
            }

            foreach (AgeGenderOption ageGender in mAgeGenderOptions)
            {
                if (!ageGender.Satisfies(potential.Age, potential.Gender, potential.Species))
                {
                    parameters.IncStat(name + " " + ageGender.Name + " User Fail");
                    return false;
                }
            }

            if (mDisallowRelated)
            {
                if (parameters.mManager.Flirts.IsCloselyRelated(sim, potential))
                {
                    parameters.IncStat(name + " Closely Related");
                    return false;
                }
            }

            if ((testScore) && (Score(potential, sim, parameters.mAbsoluteScoring, out score)))
            {
                int scoringMinimum = mScoringMinimum + parameters.mScoreDelta;
                int scoringMaximum = mScoringMaximum + parameters.mScoreDelta;

                if (score < scoringMinimum)
                {
                    parameters.AddScoring(name + " Under Scoring Fail", score);
                    return false;
                }
                else if (score > scoringMaximum)
                {
                    parameters.AddScoring(name + " Over Scoring Fail", score);
                    return false;
                }

                parameters.AddStat(name + " Score Success", score);
                return true;
            }
            else
            {
                parameters.IncStat(name + " No Scoring");
                return true;
            }
        }
Beispiel #2
0
        public bool Test(Parameters parameters, string name, SimDescription sim, SimDescription potential, bool testScore, out int score)
        {
            score = 0;

            if (SimTypes.IsDead(potential))
            {
                parameters.IncStat(name + " Dead Fail");
                return(false);
            }

            if (!parameters.CustomTestAllow(potential))
            {
                parameters.IncStat(name + " Custom Fail");
                return(false);
            }

            if ((mCustomTest.Valid) && (!mCustomTest.Invoke <bool>(new object[] { parameters, sim, potential })))
            {
                parameters.IncStat(name + " Custom Test Fail");
                return(false);
            }

            parameters.IncStat("Testing " + potential.FullName, Common.DebugLevel.Logging);

            CASAgeGenderFlags age = (mAgeGender & CASAgeGenderFlags.AgeMask);

            if ((age == CASAgeGenderFlags.None) && (potential.ToddlerOrBelow))
            {
                parameters.IncStat(name + " Too Young");
                return(false);
            }
            else if ((age != CASAgeGenderFlags.None) && ((mAgeGender & potential.Age) != potential.Age))
            {
                parameters.IncStat(name + " Age Fail");
                return(false);
            }
            else if (((mAgeGender & CASAgeGenderFlags.GenderMask) != CASAgeGenderFlags.None) && ((mAgeGender & potential.Gender) != potential.Gender))
            {
                parameters.IncStat(name + " Gender Fail");
                return(false);
            }
            else if (!mSpecies.Contains(potential.Species))
            {
                parameters.IncStat(name + " Species Fail");
                return(false);
            }

            if ((!mAllowAffair) && (parameters.mIsRomantic) && (sim != null))
            {
                if (((potential.Partner != null) || (sim.Partner != null)) && (potential.Partner != sim))
                {
                    parameters.IncStat(name + " Affair Denied");
                    return(false);
                }
            }

            if ((sim != null) && (sim != potential))
            {
                if ((mStandardDisallowPartner) && (sim.Partner == potential))
                {
                    parameters.IncStat(name + " Partner Fail");
                    return(false);
                }

                if ((!mAllowOpposing) && (StoryProgression.Main.Personalities.IsOpposing(parameters, sim, potential, false)))
                {
                    parameters.IncStat(name + " Clan Opposing Fail");
                    return(false);
                }

                if (!parameters.mIsFriendly)
                {
                    if (StoryProgression.Main.Personalities.IsFriendly(parameters, sim, potential))
                    {
                        parameters.IncStat(name + " Clan Friendly Denied");
                        return(false);
                    }
                }

                int liking = 0;

                Relationship relation = Relationship.Get(sim, potential, false);
                if (relation != null)
                {
                    liking = (int)relation.LTR.Liking;
                }

                if (liking < mRelationshipMinimum)
                {
                    parameters.IncStat(name + " Relationship Underscore");
                    return(false);
                }
                else if (liking > mRelationshipMaximum)
                {
                    parameters.IncStat(name + " Relationship Overscore");
                    return(false);
                }
            }

            foreach (IValueTestOption value in mValueTestOptions)
            {
                if (!value.Satisfies())
                {
                    parameters.IncStat(name + " " + value.ToString() + " Value Fail");
                    return(false);
                }
            }

            foreach (AgeGenderOption ageGender in mAgeGenderOptions)
            {
                if (!ageGender.Satisfies(potential.Age, potential.Gender, potential.Species))
                {
                    parameters.IncStat(name + " " + ageGender.Name + " User Fail");
                    return(false);
                }
            }

            if (mDisallowRelated)
            {
                if (parameters.mManager.Flirts.IsCloselyRelated(sim, potential))
                {
                    parameters.IncStat(name + " Closely Related");
                    return(false);
                }
            }

            if ((testScore) && (Score(potential, sim, parameters.mAbsoluteScoring, out score)))
            {
                int scoringMinimum = mScoringMinimum + parameters.mScoreDelta;
                int scoringMaximum = mScoringMaximum + parameters.mScoreDelta;

                if (score < scoringMinimum)
                {
                    parameters.AddScoring(name + " Under Scoring Fail", score);
                    return(false);
                }
                else if (score > scoringMaximum)
                {
                    parameters.AddScoring(name + " Over Scoring Fail", score);
                    return(false);
                }

                parameters.AddStat(name + " Score Success", score);
                return(true);
            }
            else
            {
                parameters.IncStat(name + " No Scoring");
                return(true);
            }
        }
Beispiel #3
0
        public ICollection<SimDescription> Filter(Parameters parameters, string name, SimDescription sim, ICollection<SimDescription> potentials)
        {
            if (!mEnabled)
            {
                parameters.IncStat(name + " Disabled");

                if (parameters.mDefaultAll)
                {
                    return parameters.mManager.Sims.All;
                }
                else
                {
                    return potentials;
                }
            }

            Collect(sim);

            if ((sim != null) && (potentials == null))
            {
                switch (mStandardFilter)
                {
                    case StandardFilter.Me:
                        potentials = new List<SimDescription>();
                        potentials.Add(sim);
                        break;
                    case StandardFilter.Partner:
                        potentials = new List<SimDescription>();
                        if (sim.Partner != null)
                        {
                            potentials.Add(sim.Partner);
                        }
                        break;
                    case StandardFilter.AnyFlirt:
                        potentials = parameters.mManager.Flirts.FindAnyFor(parameters, sim, mAllowAffair, false);
                        break;
                    case StandardFilter.ExistingFriend:
                        potentials = parameters.mManager.Friends.FindExistingFriendFor(parameters, sim, mStandardGate, mStandardIgnoreBusy);
                        break;
                    case StandardFilter.Partnered:
                        potentials = parameters.mManager.Romances.FindPartneredFor(sim);
                        break;
                    case StandardFilter.ExistingFlirt:
                        potentials = parameters.mManager.Flirts.FindExistingFor(parameters, sim, mStandardDisallowPartner);
                        break;
                    case StandardFilter.ExistingOrAnyFlirt:
                        potentials = parameters.mManager.Flirts.FindExistingFor(parameters, sim, mStandardDisallowPartner);
                        if ((potentials == null) || (potentials.Count == 0))
                        {
                            potentials = parameters.mManager.Flirts.FindAnyFor(parameters, sim, mAllowAffair, false);
                        }
                        break;
                    case StandardFilter.ExistingEnemy:
                        potentials = parameters.mManager.Friends.FindExistingEnemyFor(parameters, sim, mStandardGate, mStandardIgnoreBusy);
                        break;
                    case StandardFilter.Nemesis:
                        potentials = parameters.mManager.Friends.FindNemesisFor(parameters, sim, mStandardIgnoreBusy);
                        break;
                }

                if (potentials != null)
                {
                    parameters.AddStat(name + " " + mStandardFilter.ToString(), potentials.Count);
                }
            }

            SimPersonality clan = parameters.mManager as SimPersonality;

            if (!string.IsNullOrEmpty(mClan))
            {
                clan = parameters.mManager.Personalities.GetPersonality(mClan);
                if (clan == null)
                {
                    parameters.IncStat(mClan + " Missing");
                    return new List<SimDescription>();
                }
            }

            if (clan != null)
            {
                if (potentials == null)
                {
                    if (mClanMembers)
                    {
                        potentials = clan.GetClanMembers(mClanLeader);

                        parameters.mIsFriendly = true;
                    }
                    else if (mClanLeader)
                    {
                        potentials = clan.MeAsList;

                        parameters.mIsFriendly = true;
                    }

                    if (potentials != null)
                    {
                        parameters.AddStat(name + " Clan", potentials.Count);
                    }
                }
                else if ((mClanLeader) || (mClanMembers))
                {
                    List<SimDescription> clanPotentials = new List<SimDescription>();

                    foreach (SimDescription potential in potentials)
                    {
                        if (clan.Me == potential)
                        {
                            if (!mClanLeader)
                            {
                                parameters.IncStat(name + " Leader Denied");
                                continue;
                            }
                        }
                        else if (clan.IsMember(potential))
                        {
                            if (!mClanMembers)
                            {
                                parameters.IncStat(name + " Member Denied");
                                continue;
                            }
                        }
                        else
                        {
                            parameters.IncStat(name + " Non-clan Denied");
                            continue;
                        }

                        clanPotentials.Add(potential);
                    }

                    potentials = clanPotentials;
                }
            }

            if (potentials == null)
            {
                potentials = parameters.mManager.Sims.All;

                parameters.AddStat(name + " All", potentials.Count);
            }

            parameters.AddStat(name + " Potentials", potentials.Count);

            ScoringList<SimDescription> list = new ScoringList<SimDescription>();

            foreach (SimDescription potential in potentials)
            {
                int score = 0;
                if (!Test(parameters, name, sim, potential, true, out score)) continue;

                list.Add(potential, score);

                parameters.mManager.Main.Sleep("SimScenarioFilter:Filter");
            }

            List<SimDescription> results = list.GetBestByPercent(100);

            parameters.AddStat(name + " Results", results.Count);

            if (mThirdPartyFilter != ThirdPartyFilter.None)
            {
                Dictionary<SimDescription, bool> lookup = new Dictionary<SimDescription, bool>();

                foreach (SimDescription result in results)
                {
                    switch (mThirdPartyFilter)
                    {
                        case ThirdPartyFilter.Romantic:
                            foreach (Relationship relation in Relationship.Get(result))
                            {
                                if (!relation.AreRomantic()) continue;

                                SimDescription other = relation.GetOtherSimDescription(result);
                                if (other == null) continue;

                                lookup[other] = true;
                            }
                            break;
                        case ThirdPartyFilter.Friend:
                            foreach (Relationship relation in Relationship.Get(result))
                            {
                                if (!relation.AreFriends()) continue;

                                SimDescription other = relation.GetOtherSimDescription(result);
                                if (other == null) continue;

                                lookup[other] = true;
                            }
                            break;
                        case ThirdPartyFilter.Enemy:
                            foreach (Relationship relation in Relationship.Get(result))
                            {
                                if (!relation.AreEnemies()) continue;

                                SimDescription other = relation.GetOtherSimDescription(result);
                                if (other == null) continue;

                                lookup[other] = true;
                            }
                            break;
                        case ThirdPartyFilter.Partner:
                            if (result.Partner == null) continue;

                            lookup[result.Partner] = true;
                            break;
                        case ThirdPartyFilter.Parents:
                            foreach (SimDescription parent in Relationships.GetParents(result))
                            {
                                lookup[parent] = true;
                            }
                            break;
                        case ThirdPartyFilter.Siblings:
                            foreach (SimDescription sibling in Relationships.GetSiblings(result))
                            {
                                lookup[sibling] = true;
                            }
                            break;
                        case ThirdPartyFilter.Children:
                            foreach (SimDescription child in Relationships.GetChildren(result))
                            {
                                lookup[child] = true;
                            }
                            break;
                    }

                    parameters.mManager.Main.Sleep("SimScenarioFilter:Filter");
                }

                results.Clear();
                results.AddRange(lookup.Keys);

                parameters.AddStat(name + " " + mThirdPartyFilter, results.Count);
            }

            return results;
        }
Beispiel #4
0
        public ICollection <SimDescription> Filter(Parameters parameters, string name, SimDescription sim, ICollection <SimDescription> potentials)
        {
            if (!mEnabled)
            {
                parameters.IncStat(name + " Disabled");

                if (parameters.mDefaultAll)
                {
                    return(parameters.mManager.Sims.All);
                }
                else
                {
                    return(potentials);
                }
            }

            Collect(sim);

            if ((sim != null) && (potentials == null))
            {
                switch (mStandardFilter)
                {
                case StandardFilter.Me:
                    potentials = new List <SimDescription>();
                    potentials.Add(sim);
                    break;

                case StandardFilter.Partner:
                    potentials = new List <SimDescription>();
                    if (sim.Partner != null)
                    {
                        potentials.Add(sim.Partner);
                    }
                    break;

                case StandardFilter.AnyFlirt:
                    potentials = parameters.mManager.Flirts.FindAnyFor(parameters, sim, mAllowAffair, false);
                    break;

                case StandardFilter.ExistingFriend:
                    potentials = parameters.mManager.Friends.FindExistingFriendFor(parameters, sim, mStandardGate, mStandardIgnoreBusy);
                    break;

                case StandardFilter.Partnered:
                    potentials = parameters.mManager.Romances.FindPartneredFor(sim);
                    break;

                case StandardFilter.ExistingFlirt:
                    potentials = parameters.mManager.Flirts.FindExistingFor(parameters, sim, mStandardDisallowPartner);
                    break;

                case StandardFilter.ExistingOrAnyFlirt:
                    potentials = parameters.mManager.Flirts.FindExistingFor(parameters, sim, mStandardDisallowPartner);
                    if ((potentials == null) || (potentials.Count == 0))
                    {
                        potentials = parameters.mManager.Flirts.FindAnyFor(parameters, sim, mAllowAffair, false);
                    }
                    break;

                case StandardFilter.ExistingEnemy:
                    potentials = parameters.mManager.Friends.FindExistingEnemyFor(parameters, sim, mStandardGate, mStandardIgnoreBusy);
                    break;

                case StandardFilter.Nemesis:
                    potentials = parameters.mManager.Friends.FindNemesisFor(parameters, sim, mStandardIgnoreBusy);
                    break;
                }

                if (potentials != null)
                {
                    parameters.AddStat(name + " " + mStandardFilter.ToString(), potentials.Count);
                }
            }

            SimPersonality clan = parameters.mManager as SimPersonality;

            if (!string.IsNullOrEmpty(mClan))
            {
                clan = parameters.mManager.Personalities.GetPersonality(mClan);
                if (clan == null)
                {
                    parameters.IncStat(mClan + " Missing");
                    return(new List <SimDescription>());
                }
            }

            if (clan != null)
            {
                if (potentials == null)
                {
                    if (mClanMembers)
                    {
                        potentials = clan.GetClanMembers(mClanLeader);

                        parameters.mIsFriendly = true;
                    }
                    else if (mClanLeader)
                    {
                        potentials = clan.MeAsList;

                        parameters.mIsFriendly = true;
                    }

                    if (potentials != null)
                    {
                        parameters.AddStat(name + " Clan", potentials.Count);
                    }
                }
                else if ((mClanLeader) || (mClanMembers))
                {
                    List <SimDescription> clanPotentials = new List <SimDescription>();

                    foreach (SimDescription potential in potentials)
                    {
                        if (clan.Me == potential)
                        {
                            if (!mClanLeader)
                            {
                                parameters.IncStat(name + " Leader Denied");
                                continue;
                            }
                        }
                        else if (clan.IsMember(potential))
                        {
                            if (!mClanMembers)
                            {
                                parameters.IncStat(name + " Member Denied");
                                continue;
                            }
                        }
                        else
                        {
                            parameters.IncStat(name + " Non-clan Denied");
                            continue;
                        }

                        clanPotentials.Add(potential);
                    }

                    potentials = clanPotentials;
                }
            }

            if (potentials == null)
            {
                potentials = parameters.mManager.Sims.All;

                parameters.AddStat(name + " All", potentials.Count);
            }

            parameters.AddStat(name + " Potentials", potentials.Count);

            ScoringList <SimDescription> list = new ScoringList <SimDescription>();

            foreach (SimDescription potential in potentials)
            {
                int score = 0;
                if (!Test(parameters, name, sim, potential, true, out score))
                {
                    continue;
                }

                list.Add(potential, score);

                parameters.mManager.Main.Sleep("SimScenarioFilter:Filter");
            }

            List <SimDescription> results = list.GetBestByPercent(100);

            parameters.AddStat(name + " Results", results.Count);

            if (mThirdPartyFilter != ThirdPartyFilter.None)
            {
                Dictionary <SimDescription, bool> lookup = new Dictionary <SimDescription, bool>();

                foreach (SimDescription result in results)
                {
                    switch (mThirdPartyFilter)
                    {
                    case ThirdPartyFilter.Romantic:
                        foreach (Relationship relation in Relationship.Get(result))
                        {
                            if (!relation.AreRomantic())
                            {
                                continue;
                            }

                            SimDescription other = relation.GetOtherSimDescription(result);
                            if (other == null)
                            {
                                continue;
                            }

                            lookup[other] = true;
                        }
                        break;

                    case ThirdPartyFilter.Friend:
                        foreach (Relationship relation in Relationship.Get(result))
                        {
                            if (!relation.AreFriends())
                            {
                                continue;
                            }

                            SimDescription other = relation.GetOtherSimDescription(result);
                            if (other == null)
                            {
                                continue;
                            }

                            lookup[other] = true;
                        }
                        break;

                    case ThirdPartyFilter.Enemy:
                        foreach (Relationship relation in Relationship.Get(result))
                        {
                            if (!relation.AreEnemies())
                            {
                                continue;
                            }

                            SimDescription other = relation.GetOtherSimDescription(result);
                            if (other == null)
                            {
                                continue;
                            }

                            lookup[other] = true;
                        }
                        break;

                    case ThirdPartyFilter.Partner:
                        if (result.Partner == null)
                        {
                            continue;
                        }

                        lookup[result.Partner] = true;
                        break;

                    case ThirdPartyFilter.Parents:
                        foreach (SimDescription parent in Relationships.GetParents(result))
                        {
                            lookup[parent] = true;
                        }
                        break;

                    case ThirdPartyFilter.Siblings:
                        foreach (SimDescription sibling in Relationships.GetSiblings(result))
                        {
                            lookup[sibling] = true;
                        }
                        break;

                    case ThirdPartyFilter.Children:
                        foreach (SimDescription child in Relationships.GetChildren(result))
                        {
                            lookup[child] = true;
                        }
                        break;
                    }

                    parameters.mManager.Main.Sleep("SimScenarioFilter:Filter");
                }

                results.Clear();
                results.AddRange(lookup.Keys);

                parameters.AddStat(name + " " + mThirdPartyFilter, results.Count);
            }

            return(results);
        }