|
@@ -13,10 +13,75 @@ class ActionTalk extends Action {
|
|
|
public static carry: Rulebook<ActionTalk> = new Rulebook("Carry out Talking");
|
|
|
|
|
|
public static defaultCarryTalkingRule = ActionTalk.carry.createAndAddRule({
|
|
|
+ name : "Talking - Check with the AI",
|
|
|
+ firstPriority : Rule.PRIORITY_HIGHEST,
|
|
|
+ priority : Rule.PRIORITY_HIGHEST,
|
|
|
+ code : async (rulebook : RulebookRunner<ActionTalk>) => {
|
|
|
+ let action = <ActionGo> rulebook.noun;
|
|
|
+ //let actor = action.actor;
|
|
|
+ let thing = (<Thing>action.getNoun(0));
|
|
|
+
|
|
|
+ if (thing instanceof Person && action.actor instanceof Person) {
|
|
|
+ let runAndStop : Array<DialogueTree> = [];
|
|
|
+ let runAndContinue : Array<DialogueTree> = [];
|
|
|
+ let circumstantialOptions : Array<DialogueHook> = [];
|
|
|
+
|
|
|
+ await thing.AI.answerTo({greeter : action.actor, answerer : thing, options : circumstantialOptions, runAndStop : runAndStop, runFirst : runAndContinue});
|
|
|
+
|
|
|
+ if (runAndStop.length > 0) {
|
|
|
+ return await runAndStop[0].execute();
|
|
|
+ } else if (runAndContinue.length > 0) {
|
|
|
+ for (let i = 0; i < runAndContinue.length; i++) {
|
|
|
+ await runAndContinue[i].execute();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let investigativeOptions : Array<DialogueHook> = [];
|
|
|
+ await thing.AI.interrogateTo({greeter : action.actor, answerer : thing, options : investigativeOptions, runAndStop : runAndStop, runFirst : runAndContinue});
|
|
|
+
|
|
|
+
|
|
|
+ let choices : Array<Say> = [];
|
|
|
+ let results = [];
|
|
|
+ if (investigativeOptions.length > 0) {
|
|
|
+ // TODO: Add more textx
|
|
|
+ choices.push(new Say(new OneOf(OneOf.PURELY_AT_RANDOM, "Ask about...")));
|
|
|
+ results.push(null);
|
|
|
+ }
|
|
|
+ for (let i = 0; i < circumstantialOptions.length; i++) {
|
|
|
+ choices.push(circumstantialOptions[i].text);
|
|
|
+ results.push(circumstantialOptions[i].tree);
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: Add more texts
|
|
|
+ choices.push(new Say(new OneOf(OneOf.PURELY_AT_RANDOM, "Goodbye")));
|
|
|
+ results.push(undefined);
|
|
|
+
|
|
|
+
|
|
|
+ let choice = await Controls.giveChoices(true, ...choices);
|
|
|
+
|
|
|
+ if (results[choice[1]] === null) {
|
|
|
+ choices = [];
|
|
|
+ results = [];
|
|
|
+ for (let i = 0; i < investigativeOptions.length; i++) {
|
|
|
+ choices.push(investigativeOptions[i].text);
|
|
|
+ results.push(investigativeOptions[i].tree);
|
|
|
+ }
|
|
|
+ choice = await Controls.giveChoices(true, ...choices);
|
|
|
+ if (results[choice[1]] instanceof DialogueTree) {
|
|
|
+ await (results[choice[1]]).execute();
|
|
|
+ }
|
|
|
+ } else if (results[choice[1]] instanceof DialogueTree) {
|
|
|
+ await (results[choice[1]]).execute();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ public static lastCarryTalkingRule = ActionTalk.carry.createAndAddRule({
|
|
|
name : "Talking - Doesn't want to talk",
|
|
|
firstPriority : -1,
|
|
|
priority : -1,
|
|
|
- code : (rulebook : RulebookRunner<ActionTake>) => {
|
|
|
+ code : (rulebook : RulebookRunner<ActionTalk>) => {
|
|
|
let action = <ActionGo> rulebook.noun;
|
|
|
//let actor = action.actor;
|
|
|
let thing = (<Thing>action.getNoun(0));
|