static bool CheckSpeakerViability(Character potentialSpeaker, NPCConversation selectedConversation, List <Character> checkedSpeakers, bool ignoreFlags) { //check if the character has an appropriate job to say the line if ((potentialSpeaker.Info?.Job != null && potentialSpeaker.Info.Job.Prefab.OnlyJobSpecificDialog) || selectedConversation.AllowedJobs.Count > 0) { if (!selectedConversation.AllowedJobs.Contains(potentialSpeaker.Info?.Job.Prefab)) { return(false); } } //check if the character has all required flags to say the line if (!ignoreFlags) { var characterFlags = GetCurrentFlags(potentialSpeaker); if (!selectedConversation.Flags.All(flag => characterFlags.Contains(flag))) { return(false); } } //check if the character is close enough to hear the rest of the speakers if (checkedSpeakers.Any(s => !potentialSpeaker.CanHearCharacter(s))) { return(false); } //check if the character is close enough to see the rest of the speakers (this should be replaced with a more performant method) if (checkedSpeakers.Any(s => !potentialSpeaker.CanSeeCharacter(s))) { return(false); } //check if the character has an appropriate personality if (selectedConversation.allowedSpeakerTags.Count > 0) { if (potentialSpeaker.Info?.PersonalityTrait == null) { return(false); } if (!selectedConversation.allowedSpeakerTags.Any(t => potentialSpeaker.Info.PersonalityTrait.AllowedDialogTags.Any(t2 => t2 == t))) { return(false); } } else { if (potentialSpeaker.Info?.PersonalityTrait != null && !potentialSpeaker.Info.PersonalityTrait.AllowedDialogTags.Contains("none")) { return(false); } } return(true); }