Skip to content

Rewards: how they are built ​

A reward is a Resource stored inside the resource that grants it (a quest, a quest line, a conversation action, a skill node ...). It has no id of its own. The Basic guide explains how to use them.

The base class ​

Reward extends Resource:

MemberWhat it does
apply_to_player(player: Player) -> DictionaryGives the reward. Returns {"success": bool} plus whatever is needed to undo it (an instance id, an amount). A type must implement it
get_summary() -> StringA user-facing line: "Ability: Fireball (Active)", "Skill Points: +5 Combat". A type must implement it
supports_unapply() -> boolCan the reward be taken back? false by default: a type opts in
unapply_from_player(player, tracking_data) -> boolTakes it back, using the dictionary apply_to_player returned. Only called when supports_unapply() is true
should_apply_on_load() -> boolMust the reward be given again when a game is loaded? true for what is rebuilt at load (an ability), false for what is saved elsewhere (currency, experience, skill points). false by default
get_block_reason(player) -> StringWhy the reward cannot be given right now ("" = it can). A reward that needs room overrides it
to_pending_data() -> DictionaryWhat a reward that waits needs to be saved ({} = it never waits)
validate() -> Array[Dictionary]Configuration problems for the editor

LevelReward is not a reward but a container: a description and an Array[Reward]. apply_to_player grants each one through Player.grant_reward and counts a reward that waits as given.

Giving a reward ​

Always go through Player.grant_reward(reward), not apply_to_player directly:

  1. It asks get_block_reason(player). When the answer is not empty the reward is appended to Player.pending_rewards, the player is warned, reward_blocked(reward, reason) is emitted and the result is {"success": false, "pending": true, "reason": ...}.
  2. Otherwise it calls apply_to_player, and on success emits reward_given(reward).
  3. Whenever the inventory changes the player tries the pending rewards again (_deliver_pending_rewards), and gives those that now fit.

The GrantRewardEffect is the exception: it works on a Player target only and calls apply_to_player itself, so an item reward that does not fit is not queued there.

Pending rewards are saved with the player (pending_rewards in the save data, using to_pending_data) and restored on load. In the shipped types only ItemReward waits: it blocks when the bag cannot hold all of quantity items. A quest with a blocked reward does not complete until it can be given.

Where rewards are stored ​

OwnerProperty
Questrewards: Array[Reward] (signal reward_applied)
QuestLinecompletion_rewards: Array[Reward]
PlayerClassDefinitionlevel_rewards: Array[LevelReward], index = level − 1; every level from the old level + 1 to the new one is applied when the level rises
RankedSkillNoderewards for each rank
ConversationGrantReward (conversation action), GrantRewardAction (event action)reward: Reward
GrantRewardEffectreward: Reward, taken back when the effect ends if the type supports it

Writing your own reward ​

  1. Make a script that extends Reward, with @tool and a class_name, in your project folder res://src/rewards/ (the addon's own data_classes/rewards/types/ is found too, but an update of the addon replaces it). The add dialog lists every script of both folders; the name in the list is made from the file name without _reward.
  2. Add @export properties for its settings.
  3. Implement apply_to_player and get_summary. Return {"success": false} and push_error when it is set up wrongly.
  4. If it can be undone, override supports_unapply and unapply_from_player, and put what you need in the returned dictionary.
gdscript
@tool
class_name TitleReward extends Reward
## Gives the player a title

@export var title: String = ""

func apply_to_player(player: Player) -> Dictionary:
    if title.is_empty() or player == null:
        return {"success": false}
    player.set_meta("title", title)
    return {"success": true, "previous": ""}

func supports_unapply() -> bool:
    return true

func unapply_from_player(player: Player, tracking_data: Dictionary) -> bool:
    player.set_meta("title", tracking_data.get("previous", ""))
    return true

func get_summary() -> String:
    return "Title: %s" % title

The classes ​

ClassWhat it is
AbilityRankRewardTrains an ability of the player one or more ranks: a skill tree node that raises Fireball, a level that gives rank 3 of an ability, a quest that teaches a new rank.
AbilityRewardGrants an ability to the player
CraftingRecipeRewardTeaches a crafting recipe to the player via the CraftingManager
CraftingSkillPointRewardGrants skill levels to a crafting school via the CraftingManager of the party
CurrencyRewardGrants currency to the player's inventory
EquipmentSlotUnlockRewardUnlocks a single equipment slot for use
ExperienceRewardGrants experience points to the player
FactionReputationRewardGrants or removes reputation with a faction
FactionStandingRewardSets reputation to a specific standing level with a faction
InventorySizeRewardMakes the bag of the player bigger for good: more slots, more carry capacity (a bigger backpack as the reward of a quest).
ItemRewardGrants items to the player's inventory.
LevelRewardContainer for rewards granted at a specific level
ProfessionRewardTeaches the player a profession (a craft school): a blacksmith trainer, a quest that opens alchemy.
ProficiencyRewardTrains the player in a proficiency: experience towards the next level, or whole levels.
RewardBase class for all reward types
SkillPointRewardGrants skill points to a specific point pool
SkillTierRewardTrains a proficiency or a profession into a tier (Journeyman, Expert, Master): the cap of its level goes up.
SkillTreeRewardGives the player a skill tree: the tree of a specialization that was chosen, of a rank, a quest, an event.
SpecializationRewardChooses a specialization of a proficiency or a profession for the player: mastering one aspect of it.