Skip to content

How‐to Guide: Creating a Mission

Tom-Strooper edited this page Sep 6, 2023 · 1 revision

Introduction

Missions represent any in-game tasks. They are a super class which cover two types of sub-classes, Achievements and Quests. Since each Quest and Achievement are unique in the types of information they track, the progression of Quests and Achievements are assisted through the use of the MissionManagerService. This page will contain information that you will be able to use to create your own Quest or Achievement.

We will use an example Mission to demonstrate how this process should be done. The sample Mission will be a mandatory Quest to plant 50 crops within 10 days.

Common Steps

The stats that a Mission keeps track of are stored internally, within the Mission class. This decision was made to make Missions as self-contained as possible. However, updating the Mission’s internal stats necessarily requires communication with a wide variety of external systems. This is where the MissionManagerService comes in.

Step 1 - The MissionEvent enum

To start, figure out what stats your Mission needs to track. In our example, our Quest needs to store how many crops have been planted.

Once you have identified the stats that need to be tracked, go to the MissionManager class, find the MissionEvent enum at the top of the class, and look through the values to see if there is an enum value corresponding to the event which triggers when your stats should update.

In our example, we want our stat to update when a crop is planted. Looking through the MissionEvent enum, we find PLANT_CROP, which triggers when a crop is planted as per the comment. Here is a code snippet of the relevant section:

public enum MissionEvent {
   // Triggers when a crop is planted, single String representing plant type is provided as argument
   PLANT_CROP,
   // Triggers when a crop is fertilised
   FERTILISE_CROP
}

If you cannot find an enum which corresponds to the appropriate triggered event, then add your own to the end of the MissionEvent. You should make the name descriptive, and include a short comment afterwards explaining what triggers the event (including any parameters which are passed when the event is triggered).

Step 2 - Trigger your event

If you created a new enum value in the MissionManager.MissionEvent class, you should also ensure that your event is properly triggered. Go to all of the places in which your added event should be triggered, and add the logic for triggering your code. The name of the triggered event should be the enum value added, using the .name() method to get the string representation of the event. Here is the example for the lines added to get the PLANT_CROP event to trigger, in the CropTileComponent.plantCrop() method:

PlantComponent plantComponent = plant.getComponent(PlantComponent.class);
if (plantComponent != null) {
   ServiceLocator.getMissionManager().getEvents().trigger(
         MissionManager.MissionEvent.PLANT_CROP.name(),
         plantComponent.getPlantType()
   );
}

Step 3 - Creating your class

The next step is to create an override of a Quest or Achievement class. Quests are missions which have a time limit, and allow the player to collect a reward upon completion. Achievements are missions which are static across the entire game.

There may already exist Mission classes which closely match the Mission you wish to create, so look at what other classes have been implemented already.

If you are directly inheriting from a Quest or Achievement, the following methods must be overridden: isCompleted(), registerMission() and getDescription().

Overriding isCompleted()

The isCompleted() mission should return true when your mission is completed. That is, when your stats have reached the required level of achievement. isCompleted() should return false otherwise. Although your implementation is up to you, isCompleted() should probably not introduce any side effects.

Overriding registerMission()

The registerMission() is called when your Mission is added to the MissionManager. When this method is invoked, you should add all of the appropriate event listeners to the EventHandler provided as the parameter to the method.

Overriding getDescription()

The getDescription() method should return a string description of the Mission. You may choose the description to be as vague or descriptive as you would like. The description could even be dependent on the progress of the Mission. For instance, it may be useful to include a statement about how far the player has come in regards to the completion of the Mission.

Making a Quest

A Quest is a Mission which has a limited duration, and can result in a reward upon completion. This section contains details explaining what should be considered when creating a Quest.

The Reward

An instance of a Reward class needs to be provided to the constructor of a generic Quest. This should represent the reward the player receives if they complete the Quest before it expires. For more information about what a Reward should/can entail, read the Missions System wiki page, and the Rewards How-to Guide.

The Duration

The duration of the Quest is an integer representing the number of hours a Quest lasts before it expires. Generally, this number should not be too small, since it is decremented every hour. If the duration is too small, it may be possible for a Quest to be accepted just before the hour ticks over, in which case the player will have lost an hour of time to complete the Quest.

Is the Quest mandatory?

Mandatory Quests are Quests which will result in a game over if it expires before the Quest can be completed by the player. Most Quests should probably not be mandatory, and it is probably a good idea to check with the studio if you would like to create a mandatory quest.

Adding your Quests in-game

To add your Quest in-game, you should call the MissionManager’s addQuest() method, with a reference to an instance of your Quest as the parameter. This will make your Quest available to the player through the in-game quest NPC.

If you would like your Quest to be immediately added, you can directly call the acceptQuest() method on the MissionManager.

Making an Achievement

An Achievement is a Mission that is static across the entire game. Once it is completed, it is permanently completed. The completion of an Achievement does not result in any material benefit for the player.

Adding your Achievements in-game

Once you have created your Achievement class, you can add it in-game by navigating to the MissionManager and adding an instance of your created Achievement to the Achievement[] achievements property.

Clone this wiki locally