private DialogCriteria GetPersonalityCriteria(PersonalityTraitData inTrait, string inString) { DialogCriteria dialogCriteria = (DialogCriteria)null; DialogCriteria.CriteriaOperator criteriaOperator = !inString.Contains(">=") ? (!inString.Contains("<=") ? (!inString.Contains("<") ? (!inString.Contains(">") ? DialogCriteria.CriteriaOperator.Equals : DialogCriteria.CriteriaOperator.Greater) : DialogCriteria.CriteriaOperator.Smaller) : DialogCriteria.CriteriaOperator.SmallerOrEquals) : DialogCriteria.CriteriaOperator.GreaterOrEquals; string[] separator = new string[5] { "=", ">", ">=", "<", "<=" }; string[] strArray = inString.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (strArray.Length == 1) { if (!string.IsNullOrEmpty(strArray[0]) && strArray[0] != "0") { dialogCriteria = new DialogCriteria(strArray[0].Trim(), string.Empty); dialogCriteria.criteriaOperator = criteriaOperator; } } else if (strArray.Length == 2) { dialogCriteria = new DialogCriteria(strArray[0].Trim(), strArray[1].Trim()); dialogCriteria.criteriaOperator = criteriaOperator; } else { throw new Exception(string.Format("Personality Trait with ID {0} has bad formatted requirements! Check database Personality Traits", (object)inTrait.ID)); } return(dialogCriteria); }
public bool CriteriaMatch(DialogCriteria inCriteria) { if (this.mType.Equals(inCriteria.mType, StringComparison.OrdinalIgnoreCase)) { switch (this.criteriaOperator) { case DialogCriteria.CriteriaOperator.Equals: return(this.mCriteriaInfo.Equals(inCriteria.mCriteriaInfo, StringComparison.OrdinalIgnoreCase)); case DialogCriteria.CriteriaOperator.Greater: float result1 = 0.0f; this.CanParseToFloat(inCriteria, out result1); return((double)result1 > (double)this.mParsedData); case DialogCriteria.CriteriaOperator.GreaterOrEquals: float result2 = 0.0f; this.CanParseToFloat(inCriteria, out result2); return((double)result2 >= (double)this.mParsedData); case DialogCriteria.CriteriaOperator.Smaller: float result3 = 0.0f; this.CanParseToFloat(inCriteria, out result3); return((double)result3 < (double)this.mParsedData); case DialogCriteria.CriteriaOperator.SmallerOrEquals: float result4 = 0.0f; this.CanParseToFloat(inCriteria, out result4); return((double)result4 <= (double)this.mParsedData); case DialogCriteria.CriteriaOperator.Different: return(!this.mCriteriaInfo.Equals(inCriteria.mCriteriaInfo, StringComparison.OrdinalIgnoreCase)); } } return(false); }
private void CanParseToFloat(DialogCriteria inCriteria, out float result) { float result1 = 0.0f; if (!float.TryParse(inCriteria.mCriteriaInfo, out result1)) { throw new Exception(string.Format("{0} has {1} as criteria info, should be float.", (object)inCriteria.mType, (object)inCriteria.mCriteriaInfo), null); } result = result1; }
private static DialogQuery GetMessageCriteria(string inString) { DialogQuery dialogQuery = new DialogQuery(); inString = inString.Trim(); string[] strArray1 = inString.Split(';'); dialogQuery.who = new DialogCriteria("Who", "MediaPerson"); dialogQuery.criteriaList.Add(new DialogCriteria() { mType = "Type", mCriteriaInfo = "Header" }); for (int index1 = 0; index1 < strArray1.Length; ++index1) { DialogCriteria dialogCriteria = new DialogCriteria(); string[] strArray2 = strArray1[index1].Split('='); for (int index2 = 0; index2 < strArray2.Length; ++index2) { strArray2[index2] = strArray2[index2].Trim(); if (index2 == 0) { dialogCriteria.mType = strArray2[index2]; } else if (index2 == 1) { dialogCriteria.mCriteriaInfo = strArray2[index2]; } else { Console.WriteLine("Error, criteria split in more than 2 strings, database entry badly formated"); } } if (dialogCriteria.mType == "Who") { dialogQuery.who = dialogCriteria; } else { dialogQuery.criteriaList.Add(dialogCriteria); } } return(dialogQuery); }
private void LoadTraitRequirements(PersonalityTraitData inTrait, DatabaseEntry inEntry) { List <DialogCriteria> dialogCriteriaList = new List <DialogCriteria>(); string stringValue = inEntry.GetStringValue("Requirement"); if (!string.IsNullOrEmpty(stringValue)) { string str = stringValue; char[] chArray = new char[1] { ';' }; foreach (string inString in str.Split(chArray)) { DialogCriteria personalityCriteria = this.GetPersonalityCriteria(inTrait, inString); if (personalityCriteria != null) { dialogCriteriaList.Add(personalityCriteria); } } } inTrait.requirements = dialogCriteriaList; }