public Line(Expression[] l, Enums.lineTypes t, Noun about) { type = t; line = l; keys = new HashSet <Enums.descriptors>(); for (int i = 0; i < line.Length; i++) { if (line[i] is Verb) { if (((Verb)line[i]).descriptors.Length > 0 && ((Verb)line[i]) != null) { for (int k = 0; k < ((Verb)line[i]).descriptors.Length; k++) { keys.Add(((Verb)line[i]).descriptors[k]); } } } else if (line[i] is Adjective) { if (((Adjective)line[i]).descriptors.Length > 0 && ((Adjective)line[i]) != null) { for (int k = 0; k < ((Adjective)line[i]).descriptors.Length; k++) { keys.Add(((Adjective)line[i]).descriptors[k]); } } } } }
public Enums.lineTypes determineLine(Person from, Person to, string person, Thing thing, string about, float feeling) { Enums.lineTypes type = Enums.lineTypes.answerDanger; if (feeling < 0) //this prevents people with high chill from threatening people cause that's not chill at all { feeling += from.GetFeatureFloatValue("chill") / 2; } if (about == "person") { if (to.name.Equals(person)) { if (feeling < -.8f) { type = Enums.lineTypes.threatDirected; } else if (feeling < -.45f) { type = Enums.lineTypes.insultDirected; } else { type = Enums.lineTypes.opinionDirected; } } else { type = Enums.lineTypes.opinionUndirected; } } else if (about == "string") { type = Enums.lineTypes.opinionUndirected; } else if (about == "line") { if (feeling < -.7f) { type = Enums.lineTypes.threatDirected; } else if (feeling < -.35f) { type = Enums.lineTypes.insultDirected; } else { type = Enums.lineTypes.opinionOpinionSimple; } } return(type); }
public List <string> getLineString(Enums.lineTypes type) { string line = ""; switch (type) { case Enums.lineTypes.opinionDirected: { int size = opinionDirected.Length; int index = Mathf.FloorToInt(Random.value * size); line = opinionDirected[index]; break; } case Enums.lineTypes.opinionUndirected: { int size = opinionUndirected.Length; int index = Mathf.FloorToInt(Random.value * size); line = opinionUndirected[index]; break; } case Enums.lineTypes.requestDirected: { int size = requestDirected.Length; int index = Mathf.FloorToInt(Random.value * size); line = requestDirected[index]; break; } case Enums.lineTypes.insultDirected: { int size = insultDirected.Length; int index = Mathf.FloorToInt(Random.value * size); line = insultDirected[index]; break; } case Enums.lineTypes.threatDirected: { int size = threatDirected.Length; int index = Mathf.FloorToInt(Random.value * size); line = threatDirected[index]; break; } case Enums.lineTypes.opinionOpinionSimple: { int size = opinionOpinionSimple.Length; int index = Mathf.FloorToInt(Random.value * size); line = opinionOpinionSimple[index]; break; } case Enums.lineTypes.questionReason: { int size = questionReason.Length; int index = Mathf.FloorToInt(Random.value * size); line = questionReason[index]; break; } case Enums.lineTypes.answerRequest: { int size = answerRequest.Length; int index = Mathf.FloorToInt(Random.value * size); line = answerRequest[index]; break; } case Enums.lineTypes.answerDanger: { int size = answerDanger.Length; int index = Mathf.FloorToInt(Random.value * size); line = answerDanger[index]; break; } default: { break; } } List <string> rLine = new List <string>(); int start = 0; for (int i = 1; i < line.Length; i++) { if (line[i] == '[' && line[i + 1] == '%') { //Main.print(line.Substring(start, i - start)); rLine.Add(line.Substring(start, i - start)); start = i; } if (line[i] == ']' && line[i - 1] == '%') { //Main.print(line.Substring(start + 2, (i - start) - 3)); rLine.Add(line.Substring(start + 1, (i - start) - 2)); start = i + 1; } } if (start != line.Length) { //Main.print(line.Substring(start, line.Length - start)); rLine.Add(line.Substring(start, line.Length - start)); } return(rLine); }
/* * public void speak(from, to, person, feeling, lower) * from - person who is speaking * to - person being spoken to * person - person being talked about * feeling - feeling toward person being talked about * lower - just make this == -1 for now */ public Line speak(Person from, Person to, object about, float feeling, int lower) //speaks about any object or string { if (about is Person) { Person person = (Person)about; Enums.lineTypes type = determineLine(from, to, person.name, null, "person", feeling); List <string> lineStrings = ll.getLineString(type); Expression[] eList = new Expression[lineStrings.Count]; Noun aboutNoun = null; for (int i = 0; i < lineStrings.Count; i++) { if (lineStrings[i][0] == '%') { Expression e = determineExpression(from, to, person.name, feeling, lineStrings[i], type, lower); if (e is Noun) { aboutNoun = (Noun)e; } eList[i] = e; } else { eList[i] = new Expression(lineStrings[i]); } } Line l = new Line(eList, type, aboutNoun); return(l); } if (about is Thing) { NotMain.print("Thing"); } if (about is Line) { Enums.lineTypes type = determineLine(from, to, null, null, "line", feeling); List <string> lineStrings = ll.getLineString(type); Expression[] eList = new Expression[lineStrings.Count]; Noun aboutNoun = null; for (int i = 0; i < lineStrings.Count; i++) { if (lineStrings[i][0] == '%') { Expression e = determineExpression(from, to, null, feeling, lineStrings[i], type, lower); if (e is Noun) { aboutNoun = (Noun)e; } eList[i] = e; } else { eList[i] = new Expression(lineStrings[i]); } } Line l = new Line(eList, type, aboutNoun); return(l); } if (about is string) { string thing = (string)about; Enums.lineTypes type = determineLine(from, to, null, null, "string", feeling); List <string> lineStrings = ll.getLineString(type); Expression[] eList = new Expression[lineStrings.Count]; Noun aboutNoun = null; for (int i = 0; i < lineStrings.Count; i++) { if (lineStrings[i][0] == '%') { Expression e = determineExpression(from, to, thing, feeling, lineStrings[i], type, lower); if (e is Noun) { aboutNoun = (Noun)e; } eList[i] = e; } else { eList[i] = new Expression(lineStrings[i]); } } Line l = new Line(eList, type, aboutNoun); return(l); } return(null); }
public Expression determineExpression(Person from, Person to, string person, float feeling, string tempExpression, Enums.lineTypes type, int lowerBound) { Expression e = new Expression("BAD"); switch (tempExpression) { case "%feelingVerb": { string f = el.getExpressionString(Enums.expressionTypes.feelingVerb, feeling, lowerBound); Enums.descriptors d; if (feeling > .5f) { d = Enums.descriptors.loving; } else if (feeling > .0f) //these are not mutually exclusive or anything, fix this later for sure { d = Enums.descriptors.friendly; } else if (feeling < -.66f) { d = Enums.descriptors.hostile; } else { d = Enums.descriptors.safe; } Enums.descriptors[] desc = new Enums.descriptors[1]; desc[0] = d; Noun n = new Noun(person, Enums.generalTypes.person, person); Verb v = new Verb(f, desc, n); e = v; break; } case "%amountAdverb": //later this should work together with other verbs/adjectives to offset and result in more dialogue variance { string f = el.getExpressionString(Enums.expressionTypes.amountAdverb, feeling, lowerBound); Adverb a = new Adverb(f, feeling + ((UnityEngine.Random.value - .5f) / 2), null); //this adds a bit of variance e = a; break; } case "%feelingAdjective": { string f = el.getExpressionString(Enums.expressionTypes.feelingAdjective, feeling, lowerBound); Enums.descriptors d; if (feeling > .5f) { d = Enums.descriptors.loving; } else if (feeling > .0f) //these are not mutually exclusive or anything, fix this later for sure { d = Enums.descriptors.friendly; } else if (feeling < -.666f) { d = Enums.descriptors.hostile; } else { d = Enums.descriptors.safe; } Enums.descriptors[] desc = new Enums.descriptors[1]; desc[0] = d; Adjective a = new Adjective(f, desc); e = a; break; } case "%person%feature": { string f = from.GetMatchingFeature(to, feeling); Noun n = new Noun(f, Enums.generalTypes.feature, person); e = n; break; } case "%noun": { if (type == Enums.lineTypes.threatDirected) { string near = "rubber duck"; //from.GetRandomNearbyItem().name; Noun n = new Noun(near, Enums.generalTypes.thing, "none"); e = n; } else { Noun n = new Noun(person, Enums.generalTypes.person, person); e = n; } break; } case "%noun%feature": { char[] splitPercent = new char[1]; splitPercent[0] = '%'; Noun n; if (person.Split(splitPercent).Length < 3) { n = new Noun("eyes", Enums.generalTypes.feature, person); e = n; break; } string f = person.Split(splitPercent)[2]; n = new Noun(f, Enums.generalTypes.feature, person.Split(splitPercent)[0]); e = n; break; } case "%agreementVerb": { Noun n = new Noun("line", Enums.generalTypes.line, to.name); Enums.descriptors d; Main.print(feeling + ", "); if (feeling > .33f) { d = Enums.descriptors.agreeable; } else if (feeling < -.33f) { d = Enums.descriptors.disagreeable; } else { d = Enums.descriptors.safe; } Enums.descriptors[] desc = new Enums.descriptors[1]; desc[0] = d; Verb v = new Verb(el.getExpressionString(Enums.expressionTypes.agreementVerb, feeling, lowerBound), desc, n); e = v; break; } default: { NotMain.print(tempExpression); break; } } return(e); }