T4 Modules Howto Guide/Talents

From Tales of Maj'Eyal
Jump to: navigation, search

Talents: Your special skills

Talent Definitions

By default, Talent definitions are stored in the /data/talents.lua file. This file can include other files through the use of the Load(file) method.

Talent definitions require talent type definitions first. These are defined in newTalentType{...} blocks.

Important TalentType Variables Effect
name Display name of this talent type. REQUIRED.
type Identifier of this talent type. REQUIRED.
description String description of this talent type.
points Maximum amount of points in this talent type.

Note: If you are writing your own module you will need to add code to check how many points are in a talent as the engine's canLearnTalent function ignores the points definition when checking if a talent is learnable.

Talent definitions are defined in newTalent{...} blocks.

Important Talent Variables Effect
name Displayed Talent name. REQUIRED.
short_name Talent identifier. name is used if unset.
points Maximum amount of points that can be put into the talent.
require Requirements table for adding points. See the requirements definition below.
mode Talent mode. One of either: "passive" - always on, "sustained" - can be turned on or off and "activated" - can be used. Default is "activated".
info String description of the talent. REQUIRED.
type Talent group. REQUIRED.
cooldown Amount of turns to wait before a talent can be used again.
range Range of talent. May be a number or function, but use getTalentRange(t) below as a getter in that case.

Identifiers for the talents are created by uppercasing the short_name (or name if no short_name is defined), replacing spaces with underscores ('_') and appending T_ in the front. These can then be accessed statically through [ActorTalents.*].

In this way the talent "Wind Walk" can be accessed by [ActorTalents.T_WIND_WALK].

Some talent variables require functions to be defined. These are of the form function(self, t), where self is the invoking actor and t is the talent being invoked.

Important Talent Functions Use
action "activated" mode talents only. Function that gets used when talent is activated.
activate "sustained" mode talents only. Function that gets used when talent gets turned on.
deactivate "sustained" mode talents only. Function that gets used when talent gets turned off.
on_learn Function that gets used when talent is learned.
on_unlearn Function that gets used when talent is unlearned.

In order to add stat, level or other talent requirements, a requirement table is required. These are the recognised variables.

Requirement Definition Use
stat Actor must have these stats at these levels.
level Actor must be at least this level.
talent Prerequisite talents.

For instance if a talent requires another talent and stats you can use:

require = { stat = { str = 10, dex = 10 }, talent = { Talents.T_STONE_SKIN }, },

If a talent requires that another talent NOT be taken you can use

require = { talent = { { Talents.T_STONE_SKIN, false }, }, },

Talent Targeting

Many activatable talents require some user targeting input. This is done through a coroutine. This is an example of the standard targeting and dealing damage case:

local tg = {type="bolt", range=self:getTalentRange(t), talent=t}
local x, y = self:getTarget(tg)
if not x or not y then return nil end
self:project(tg, x, y, DamageType.FIRE, 10, nil)

In this case, tg contains the targeting and damage settings. Possible variables are:

Targeting Settings Effect
type Targeting type. See below.
range Range limit. Usually always self:getTalentRange(t).
talent The talent being used.
friendlyfire (?) Defaults to true.
no_restrict Makes no restrictions regarding targeting
stop_block Denotes that the projection will be blocked by entities that block move (bolts have this true by default)
radius "ball" and "cone" targeting modes use this.
cone_angle "cone" targeting mode uses this. Defaults to 55.
msg Message to display during targeting.

The possible targeting modes are:

type Effect
hit Simple single target.
bolt Hits first thing in path.
beam Hits everything in path.
ball Hits everything in a ball around the target.
cone Hits everything in a cone in the direction.

getTarget(tg) is a method that is overriden by an AI for NPCs, or by the game module class.

Note that the last parameter of the project() method is the particle system to use.

ActorTalents Class

By default, Actors inherit from the ActorTalents class, even in the example module. This class provides an interface for manipulating and accessing talents. These are some of the valuable methods.

Useful Talent Related ActorTalents class methods Use
useTalent(t) Forces the Actor to use the talent.
useTalents() Shows the use talent dialog.
knowTalent(t) Returns true if the talent is known.
knowTalentType(tt) Returns true if the talent group is known.
learnTalent(t, force, nb) Has an Actor learn a talent. force prevents a canLearnTalent(t) test. nb is the amount of points to put into the talent.
unlearnTalent(t) Makes the Actor forget the talent.
learnTalentType(tt, v) Has the Actor learns a Talent Type. (v is true or false?)
unlearnTalentType(tt) Has the Actor forget a Talent Type.
canLearnTalent(t) Returns true if the Actor meets the requirements for the talent.
getTalentLevel(t) Gets the amount of points in talent. 0 if unlearned.
isTalentCoolingDown(t) Returns true if the specified talent is in the process of cooldown.
getTalentRange(t) Returns the talent range. Use this instead of checking the range variable, since this allows the range variable to be either a function or a number.
cooldownTalents() Cools down all talents by 1. This needs to be in your act() method.

All of the above methods can also be redefined in your own class if their functionality needs to be expanded. In addition, the following may also be useful to redefine:

Method Use
preUseTalent(t) Called before an actor uses a talent. Not returning true stops the talent from invoking.
postUseTalent(t) Called after an actor uses a talent. Not returning true stops stops cooldown or sustained state from happening.
getTalentFullDescription(t) Used in Dialogs. Overload to add more information such as mana use.

Go back to T4 Modules Howto Guide