ThePix / QuestJS

A major re-write of Quest that is written in JavaScript and will run in the browser.
MIT License
66 stars 12 forks source link

Talk to: add a facultative greeting with topics #61

Closed Kln95130 closed 3 years ago

Kln95130 commented 3 years ago

Hello again.

Another small improvement, that I think would increase dialog variety. If I want my NPC to greet the player before he gets the list of topics, I need to tweak the npc_utilities.talkto function.

Just like previous issue, I think it could be useful to include it in the next version.

The property and the update talkto:

npc_utilities.greeting = false;
npc_utilities.talkto = function() {
  if (!game.player.canTalk(this)) {
    return false;
  }
  if (settings.noTalkTo !== false) {
    metamsg(settings.noTalkTo);
    return false;
  }

  const topics = this.getTopics(this);
  game.player.conversingWithNpc = this
  if (topics.length === 0) return failedmsg(lang.no_topics, {char:game.player, item:this});

  topics.push(lang.never_mind);

  if (this.greeting) {
    printOrRun(this, this, "greeting");
  }

  if (settings.dropdownForConv) {
    showDropDown(lang.speak_to_menu_title(this), topics, function(result) {
      if (result !== lang.never_mind) {
        result.runscript();
      }
    });
  }
  else {
    showMenu(lang.speak_to_menu_title(this), topics, function(result) {
      if (result !== lang.never_mind) {
        result.runscript();
      }
    });
  }

  return world.SUCCESS_NO_TURNSCRIPTS;
}

Your greeting can be a string or a function, like "examine".

greeting: "Hello."
greeting: function() => {
if (this.talktocount == 0) {
  msg("Hello.");
} else {
  msg("Is it me you're looking for?");
}
}
ThePix commented 3 years ago

That is a great idea... not sure why I did not do it myself (I do not think the first line is necessary, though). Also highlighted that talktoCount is not getting incremented. Note that it gets incremented before the greeting, so the first will be 1. I set up my function like this:

  greeting: function() {
    if (this.talktoCount === 1) {
      msg("'Hello,' says Lara.");
    } else {
      msg("'You again?' says Lara.");
    }
  }  
ThePix commented 3 years ago

I feel I am close to releasing version 1.0, so any further ideas, say them sooner rather than later.

Kln95130 commented 3 years ago

Sure thing.

Other than ticket #60, the only "extra" stuff that I had in mind and custom coded was a template for a "RELOADABLE" thing. It can be a gun, but anything that needs a compenent could work too. I will isolate the template and open a ticket about it.