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:
| Member | What it does |
|---|---|
apply_to_player(player: Player) -> Dictionary | Gives the reward. Returns {"success": bool} plus whatever is needed to undo it (an instance id, an amount). A type must implement it |
get_summary() -> String | A user-facing line: "Ability: Fireball (Active)", "Skill Points: +5 Combat". A type must implement it |
supports_unapply() -> bool | Can the reward be taken back? false by default: a type opts in |
unapply_from_player(player, tracking_data) -> bool | Takes it back, using the dictionary apply_to_player returned. Only called when supports_unapply() is true |
should_apply_on_load() -> bool | Must 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) -> String | Why the reward cannot be given right now ("" = it can). A reward that needs room overrides it |
to_pending_data() -> Dictionary | What 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:
- It asks
get_block_reason(player). When the answer is not empty the reward is appended toPlayer.pending_rewards, the player is warned,reward_blocked(reward, reason)is emitted and the result is{"success": false, "pending": true, "reason": ...}. - Otherwise it calls
apply_to_player, and on success emitsreward_given(reward). - 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 ​
| Owner | Property |
|---|---|
Quest | rewards: Array[Reward] (signal reward_applied) |
QuestLine | completion_rewards: Array[Reward] |
PlayerClassDefinition | level_rewards: Array[LevelReward], index = level − 1; every level from the old level + 1 to the new one is applied when the level rises |
RankedSkillNode | rewards for each rank |
ConversationGrantReward (conversation action), GrantRewardAction (event action) | reward: Reward |
GrantRewardEffect | reward: Reward, taken back when the effect ends if the type supports it |
Writing your own reward ​
- Make a script that
extends Reward, with@tooland aclass_name, in your project folderres://src/rewards/(the addon's owndata_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. - Add
@exportproperties for its settings. - Implement
apply_to_playerandget_summary. Return{"success": false}andpush_errorwhen it is set up wrongly. - If it can be undone, override
supports_unapplyandunapply_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" % titleThe classes ​
| Class | What it is |
|---|---|
| AbilityRankReward | Trains 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. |
| AbilityReward | Grants an ability to the player |
| CraftingRecipeReward | Teaches a crafting recipe to the player via the CraftingManager |
| CraftingSkillPointReward | Grants skill levels to a crafting school via the CraftingManager of the party |
| CurrencyReward | Grants currency to the player's inventory |
| EquipmentSlotUnlockReward | Unlocks a single equipment slot for use |
| ExperienceReward | Grants experience points to the player |
| FactionReputationReward | Grants or removes reputation with a faction |
| FactionStandingReward | Sets reputation to a specific standing level with a faction |
| InventorySizeReward | Makes the bag of the player bigger for good: more slots, more carry capacity (a bigger backpack as the reward of a quest). |
| ItemReward | Grants items to the player's inventory. |
| LevelReward | Container for rewards granted at a specific level |
| ProfessionReward | Teaches the player a profession (a craft school): a blacksmith trainer, a quest that opens alchemy. |
| ProficiencyReward | Trains the player in a proficiency: experience towards the next level, or whole levels. |
| Reward | Base class for all reward types |
| SkillPointReward | Grants skill points to a specific point pool |
| SkillTierReward | Trains a proficiency or a profession into a tier (Journeyman, Expert, Master): the cap of its level goes up. |
| SkillTreeReward | Gives the player a skill tree: the tree of a specialization that was chosen, of a rank, a quest, an event. |
| SpecializationReward | Chooses a specialization of a proficiency or a profession for the player: mastering one aspect of it. |