top of page
SpaceBackground.png
SpaceBackground.png

Developer Diary Week 3 - Jobs, Dialogue, and Player Interaction

  • Writer: gtristanitristani
    gtristanitristani
  • Jun 6, 2023
  • 4 min read

The past few days have been rather busy for this project, and as a result, I have a lot of things to showcase! With a lot of the groundwork and setup in place, this week gave me the chance to dive into the implementation of several core features. Namely: the job system implementation, dialog banks and their selection behaviors, and the player’s ability to interact with NPCs. Let’s get to it!


With the day-night cycle wrapped up the previous week, I had the means to create the basic job system. After I finished work on it for this week, it allowed for the following behaviors:

  1. The user can specify the commute time (time an NPC begins walking to work), start time (time a job is set to start), and end time (time a job ends) for a given Job object. Each Job also includes an array of weekeday enums specifying the days that the NPC should come into work.

  2. The NPC will walk to their workstation (an actor in the world) at commute time, provided the current weekday is included in the job’s schedule.

  3. When the NPC reaches the workstation, they will stop and switch their state to Working.

  4. The NPC considers themselves at work and busy, and will lose affinity with the player if the player attempts to talk to them during this period.

  5. At the end time, the NPC switches to the idle state and is done their work for the day.

The next feature I worked on was the Dialog Bank system, which allows the user to specify sub banks of dialogue that the NPC can take responses from while interacting with the player if certain conditions (Mood, Energy, Affinity, Gifts, Busy) are met. Several of these conditions may be active at a time in the NPC, so a random response is chosen from the active sub-banks based on the interaction in question.

ree

ree

The Dialog Bank system operates differently depending on the player interaction chosen. Because of this, I designed a function for the behavior governing each of the three interactions. These interactions differed significantly in which sub-banks were searched in deriving responses, as well as impacts that each interaction had on the NPC’s affinity towards the player.

ree

ree

The diagram and code above represents how response selection is done by an NPC during the talk interaction type. If the NPC is working, a single busy response is derived from the job and personality banks. If the NPC is not working, three sub-banks are activated in both the job and personality dialog banks: one corresponding to their affinity level, one corresponding to their energy level, and one corresponding to their mood. Out of the six active sub-banks, one response is chosen to display.

ree

For gift interactions, only two sub-banks (one in the job and one in the personality dialog bank) are active at a time. Which is active is determined by what the gift name is. If the gift name provided appears in the NPC’s LikedGifts array, then they will activate the LikedGift sub banks. If the gift name provided appears in the NPC’s DislikedGifts array, then they will activate the DislikedGift sub banks. If the gift appears in neither, they will activate the MiddleGift sub banks. A single response is chosen from the active sub banks, and is printed to the text box. Liked and indifferent gifts will cause the NPC’s affinity towards the player to increase, while disliked gifts will cause the NPC’s affinity towards the player to decrease.

ree

Hitting the NPC steeply lowers the affinity that the NPC has towards the player. They will derive a response from the Hurt sub banks of the Job and Personality dialog banks, returning one to the text box.

To test the Dialog Bank system, I implemented a text box UI element that would print the NPC’s response on the screen. The text box remains onscreen until the user presses the left mouse button. While the text box is visible, the NPC is in the talking state, and plays a corresponding animation, as well as stopping in their tracks.


Since the Dialog Bank behavior changes based on the nature of the player interaction, I also implemented the three base player interactions (talk, gift, hurt), as well as a corresponding Interaction UI element. When the user presses a button, it will activate that specific interaction. In the case of the gift interaction, another textbox appears on screen asking the player to input the name of the gift.


As a final addition for this week, I added a text-based Widget that displays the name, affinity, energy, and state of an NPC onscreen when they are faced head-on by the player. I imagine it will be an incredibly useful resource for debugging when more NPC functionality is implemented!


This week, I ran into some issues with my implementation early on. One problem I faced was that I had originally constructed the DialogBank component on the NPC via C++. Because of this, I ran into an issue with the Dialog Bank’s settings being wiped clean after reloading the project, meaning that the dialog would need to be rewritten each time. This was remedied fairly quickly by removing the C++ construction line and adding it via the blueprint viewport instead. But I soon realized that I had made another mistake in preventing the modularization of the Job block. The job block was originally also an Actor Component. This unfortunately meant that I couldn’t easily apply the same job to several NPCs, as all the relevant data was specified in a component where specific instances couldn’t be prefabbed and used again. The solution to this was simply to make the Job class an Actor instead of an Actor component, and allow the NPC to store a pointer to it that the user could provide.


For the next week, my plans are to create the derived personality villagers and write dialog to fill their banks, create a coworker response array to talk about coworkers (activated with high player affinity), create derived job objects and dialog corresponding to each, and allow the World Manager to keep track of which NPCs have the same job type. I also plan to add a relaxing state where NPCs gain energy per ingame minute, and implement logic so that they relax when they are not currently working and have low energy. I would also like to add the ability of an NPC to pass out from exhaustion if their energy is less than or equal to 10, steadily gaining energy while unconscious and waking up when it reaches 100.

 
 

©2022 by Gabrielle Tristani's Portfolio. Proudly created with Wix.com

bottom of page