class TrgParrot:TrGEV3{
var maxTolerance:Int = 10
var tolerance:Int = 10
var kokoro:Kokoro
// responses
var defaultResponse:Responder = Responder("hadouken","talk","chi3","chi4","shoryuken")
let repeatedResponder:RepeatedElements = RepeatedElements()
let forcedResponses:ForcedLearn = ForcedLearn()
let replenisher:String = "hey"
private(set) var output:String = ""
var convo:Bool = false
let pl:PlayGround = PlayGround()
var trgMinute:TrgMinute = TrgMinute()
let shutUp:Responder = Responder("ok","okay","stop","shut up","quiet")
let emoRecognizer:EmoRecognizer = EmoRecognizer()
init(kokoro:Kokoro) {
self.kokoro = kokoro
}
override func reset() {
// replenish
tolerance = maxTolerance
}
override func trigger() -> Bool {
return false
}
override func input(ear: String, skin: String, eye: String) {
// learn new responses
if !ear.contains(forcedResponses.keyWord){
repeatedResponder.input(in1: ear)}
forcedResponses.input(in1: ear)
if pl.isNight() {return}
// force convo
if ear == replenisher {
reset();calcResponse(ear: ear)
convo = true
return
}
if kokoro.standBy {
reset()
convo = false
return
}
// shut up ()
if shutUp.contains(str: ear){
reset()
convo = false
return
}
// engage or continue convo
if detectedInput(ear: ear) {
if tolerance == 0 {convo = false}
else if !ear.isEmpty {tolerance -= 1;calcResponse(ear: ear);return}
}
if trgMinute.trigger() {
calcResponse(ear: ear)
}
}
func calcResponse(ear:String) {
let path:Int = Int.random(in: 0...2)
if emoRecognizer.isAngry(in1: ear) {
output = "chii angry";return
}
if emoRecognizer.isCurious(in1: ear) {
output = "chii Curious";return
}
if emoRecognizer.isHappy(in1: ear) {
output = "chii Happy";return
}
switch (path) {
case 1:
output = forcedResponses.getRandomElement()
case 2:
output = repeatedResponder.getRandomElement()
default:
output = defaultResponse.getAResponse()
}
}
func detectedInput(ear: String) -> Bool {
if defaultResponse.contains(str: ear) || forcedResponses.contains(str: ear) || repeatedResponder.contains(str: ear){
convo = true
}
return convo
}
func getOutput() -> String{
let temp = output;output = ""
return temp
}
func setMaxTolerance(newMaxTolerance:Int) {
maxTolerance = newMaxTolerance
}
}