NRaas.StoryProgressionSpace.Scenarios.SimScenarioFilter.Parse C# (CSharp) Method

Parse() public method

public Parse ( XmlDbRow row, StoryProgressionObject manager, IUpdateManager updater, string prefix, bool errorIfNone, string &error ) : bool
row XmlDbRow
manager StoryProgressionObject
updater IUpdateManager
prefix string
errorIfNone bool
error string
return bool
        public bool Parse(XmlDbRow row, StoryProgressionObject manager, IUpdateManager updater, string prefix, bool errorIfNone, ref string error)
        {
            mDisallowRelated = row.GetBool(prefix + "DisallowRelated");

            if (row.Exists(prefix + "StandardFilter"))
            {
                mEnabled = true;

                if (!ParserFunctions.TryParseEnum<StandardFilter>(row.GetString(prefix + "StandardFilter"), out mStandardFilter, StandardFilter.None))
                {
                    error = prefix + "StandardFilter invalid";
                    return false;
                }
            }

            string customTest = row.GetString(prefix + "CustomTest");

            mCustomTest = new Common.MethodStore(customTest, new Type[] { typeof(Parameters), typeof(SimDescription), typeof(SimDescription) });
            if ((mCustomTest == null) && (!string.IsNullOrEmpty(customTest)))
            {
                error = prefix + "CustomTest Invalid";
                return false;
            }

            switch (mStandardFilter)
            {
                case StandardFilter.ExistingFriend:
                case StandardFilter.ExistingEnemy:
                case StandardFilter.Nemesis:
                    if (!row.Exists(prefix + "StandardIgnoreBusy"))
                    {
                        error = prefix + "StandardIgnoreBusy missing";
                        return false;
                    }

                    mStandardIgnoreBusy = row.GetBool(prefix + "StandardIgnoreBusy");
                    break;
            }

            switch (mStandardFilter)
            {
                case StandardFilter.ExistingFriend:
                case StandardFilter.ExistingEnemy:
                    RelationshipLevel standardLevel;
                    if (ParserFunctions.TryParseEnum<RelationshipLevel>(row.GetString(prefix + "StandardGate"), out standardLevel, RelationshipLevel.Neutral))
                    {
                        mStandardGate = (int)standardLevel;
                    }
                    else
                    {
                        RelationshipLevel defGate = RelationshipLevel.Neutral;
                        if (mStandardFilter == StandardFilter.ExistingFriend)
                        {
                            defGate = RelationshipLevel.Friend;
                        }
                        else
                        {
                            defGate = RelationshipLevel.Enemy;
                        }
                        mStandardGate = row.GetInt(prefix + "StandardGate", (int)defGate);
                    }

                    break;
                case StandardFilter.ExistingFlirt:
                case StandardFilter.ExistingOrAnyFlirt:
                    if (!row.Exists(prefix + "StandardDisallowPartner"))
                    {
                        error = prefix + "StandardDisallowPartner missing";
                        return false;
                    }

                    break;
            }

            // The default for DisallowPartner can be altered by the calling system, don't overwrite it
            if (row.Exists(prefix + "StandardDisallowPartner"))
            {
                mStandardDisallowPartner = row.GetBool(prefix + "StandardDisallowPartner");
            }

            switch (mStandardFilter)
            {
                case StandardFilter.AnyFlirt:
                case StandardFilter.ExistingOrAnyFlirt:
                    if (!row.Exists(prefix + "AllowAffair"))
                    {
                        error = prefix + "AllowAffair missing";
                        return false;
                    }

                    break;
            }

            if (row.Exists(prefix + "AllowOpposing"))
            {
                mAllowOpposing = row.GetBool(prefix + "AllowOpposing");
            }
            else
            {
                mAllowOpposing = true;
            }

            if (row.Exists("AllowAffair"))
            {
                error = prefix + "AllowAffair misdefined";
                return false;
            }
            else if (row.Exists(prefix + "AllowAffair"))
            {
                mAllowAffair = row.GetBool(prefix + "AllowAffair");
            }
            else
            {
                mAllowAffair = false;
            }

            if (row.Exists(prefix + "ThirdPartyFilter"))
            {
                mEnabled = true;

                if (!ParserFunctions.TryParseEnum<ThirdPartyFilter>(row.GetString(prefix + "ThirdPartyFilter"), out mThirdPartyFilter, ThirdPartyFilter.None))
                {
                    error = prefix + "ThirdPartyFilter invalid";
                    return false;
                }
            }

            mScoring = row.GetString(prefix + "Scoring");

            if (!string.IsNullOrEmpty(mScoring))
            {
                mEnabled = true;

                if (ScoringLookup.GetScoring(mScoring) == null)
                {
                    error = mScoring + " missing";
                    return false;
                }

                if ((!row.Exists(prefix + "ScoringMinimum")) && (!row.Exists(prefix + "ScoringMaximum")))
                {
                    error = prefix + "ScoringMinimum missing";
                    return false;
                }
            }

            mScoringMaximum = row.GetInt(prefix + "ScoringMaximum", int.MaxValue);
            mScoringMinimum = row.GetInt(prefix + "ScoringMinimum", int.MinValue);

            if (mScoringMinimum > mScoringMaximum)
            {
                int scoring = mScoringMinimum;
                mScoringMinimum = mScoringMaximum;
                mScoringMaximum = scoring;
            }

            if ((row.Exists(prefix + "RelationshipMinimum")) || (row.Exists(prefix + "RelationshipMaximum")))
            {
                mEnabled = true;
            }

            RelationshipLevel relationLevel;
            if (ParserFunctions.TryParseEnum<RelationshipLevel>(row.GetString(prefix + "RelationshipMaximum"), out relationLevel, RelationshipLevel.Neutral))
            {
                mRelationshipMaximum = (int)relationLevel;
            }
            else
            {
                mRelationshipMaximum = row.GetInt(prefix + "RelationshipMaximum", 101);
            }

            if (ParserFunctions.TryParseEnum<RelationshipLevel>(row.GetString(prefix + "RelationshipMinimum"), out relationLevel, RelationshipLevel.Neutral))
            {
                mRelationshipMinimum = (int)relationLevel;
            }
            else
            {
                mRelationshipMinimum = row.GetInt(prefix + "RelationshipMinimum", -101);
            }

            if (mRelationshipMinimum > mRelationshipMaximum)
            {
                int scoring = mRelationshipMinimum;
                mRelationshipMinimum = mRelationshipMaximum;
                mRelationshipMaximum = scoring;
            }

            mClan = row.GetString(prefix + "Clan");
            if (!string.IsNullOrEmpty(mClan))
            {
                mEnabled = true;
            }

            if (row.Exists(prefix + "ClanLeader"))
            {
                mEnabled = true;
            }

            mClanLeader = row.GetBool(prefix + "ClanLeader");

            if (row.Exists(prefix + "ClanMembers"))
            {
                mEnabled = true;
            }

            mClanMembers = row.GetBool(prefix + "ClanMembers");

            string ageGender = row.GetString(prefix + "AgeGender");
            if (!string.IsNullOrEmpty(ageGender))
            {
                mEnabled = true;

                if (!ParserFunctions.TryParseEnum<CASAgeGenderFlags>(ageGender, out mAgeGender, CASAgeGenderFlags.None))
                {
                    error = "Unknown AgeGender " + ageGender;
                    return false;
                }
            }

            StringToSpeciesList converter = new StringToSpeciesList();
            mSpecies = converter.Convert(row.GetString(prefix + "Species"));
            if (mSpecies == null)
            {
                error = converter.mError;
                return false;
            }

            if (mSpecies.Count == 0)
            {
                mSpecies.Add(CASAgeGenderFlags.Human);
            }

            for (int i = 0; i < 10; i++)
            {
                string key = prefix + "UserAgeGender" + i;
                if (!row.Exists(key)) break;

                mEnabled = true;

                string name = row.GetString(key);

                AgeGenderOption option = manager.GetOption<AgeGenderOption>(name);
                if (option == null)
                {
                    error = prefix + "UserAgeGender" + i + " " + name + " missing";
                    return false;
                }

                mUserAgeGenders.Add(name);
            }

            for (int i = 0; i < 10; i++)
            {
                string key = prefix + "ValueTest" + i;
                if (!row.Exists(key)) break;

                mEnabled = true;

                string name = row.GetString(key);

                int min = row.GetInt(key + "Minimum", int.MinValue);
                int max = row.GetInt(key + "Maximum", int.MaxValue);

                bool match = true;
                if (row.Exists(key + "Match"))
                {
                    match = row.GetBool(key + "Match");
                }

                mValueTestLoads.Add(new ValueTestLoadStore(name, min, max, match));
            }

            if ((!mEnabled) && (errorIfNone))
            {
                error = prefix + " Filter missing";
                return false;
            }

            updater.AddUpdater(this);
            return true;
        }

Usage Example

コード例 #1
0
        public override bool Parse(XmlDbRow row, ref string error)
        {
            mFilter = new SimScenarioFilter();

            if (!mFilter.Parse(row, Manager, this, "Actor", true, ref error))
            {
                return(false);
            }

            return(base.Parse(row, ref error));
        }
All Usage Examples Of NRaas.StoryProgressionSpace.Scenarios.SimScenarioFilter::Parse