1
1
import type {
2
2
ActiveEffectSource ,
3
+ EffectChangeData ,
3
4
EffectDurationData ,
4
5
} from "../../../common/documents/active-effect.d.ts" ;
5
6
import type { ClientBaseActiveEffect } from "./client-base-mixes.d.ts" ;
@@ -13,16 +14,88 @@ declare global {
13
14
class ActiveEffect <
14
15
TParent extends Actor | Item | null ,
15
16
> extends ClientBaseActiveEffect < TParent > {
16
- constructor (
17
- data : PreCreate < ActiveEffectSource > ,
18
- context ?: DocumentConstructionContext < TParent > ,
19
- ) ;
17
+ /**
18
+ * Create an ActiveEffect instance from some status effect ID.
19
+ * Delegates to {@link ActiveEffect._fromStatusEffect} to create the ActiveEffect instance
20
+ * after creating the ActiveEffect data from the status effect data if `CONFIG.statusEffects`.
21
+ * @param statusId The status effect ID.
22
+ * @param options Additional options to pass to the ActiveEffect constructor.
23
+ * @returns The created ActiveEffect instance.
24
+ *
25
+ * @throws {Error } An error if there is no status effect in `CONFIG.statusEffects` with the given status ID and if
26
+ * the status has implicit statuses but doesn't have a static _id.
27
+ */
28
+ static fromStatusEffect (
29
+ statusId : string ,
30
+ options ?: DocumentConstructionContext < foundry . abstract . Document | null > ,
31
+ ) : Promise < ActiveEffect < Actor | Item > | undefined > ;
32
+
33
+ /**
34
+ * Create an ActiveEffect instance from status effect data.
35
+ * Called by {@link ActiveEffect.fromStatusEffect}.
36
+ * @param statusId The status effect ID.
37
+ * @param effectData The status effect data.
38
+ * @param options Additional options to pass to the ActiveEffect constructor.
39
+ * @returns The created ActiveEffect instance.
40
+ */
41
+ protected static _fromStatusEffect (
42
+ statusId : string ,
43
+ effectData : Partial < ActiveEffectSource > ,
44
+ options ?: DocumentConstructionContext < foundry . abstract . Document | null > ,
45
+ ) : Promise < ActiveEffect < Actor | Item > | undefined > ;
46
+
47
+ /* -------------------------------------------- */
48
+ /* Properties */
49
+ /* -------------------------------------------- */
20
50
21
- /** A cached reference to the source name to avoid recurring database lookups */
22
- protected _sourceName : string | null ;
51
+ /**
52
+ * Is there some system logic that makes this active effect ineligible for application?
53
+ */
54
+ get isSuppressed ( ) : boolean ;
23
55
24
- /** A cached reference to the ActiveEffectConfig instance which configures this effect */
25
- protected override _sheet : ActiveEffectConfig < this> | null ;
56
+ /**
57
+ * Retrieve the Document that this ActiveEffect targets for modification.
58
+ */
59
+ get target ( ) : foundry . abstract . Document | null ;
60
+
61
+ /**
62
+ * Whether the Active Effect currently applying its changes to the target.
63
+ */
64
+ get active ( ) : boolean ;
65
+
66
+ /**
67
+ * Does this Active Effect currently modify an Actor?
68
+ */
69
+ get modifiesActor ( ) : boolean ;
70
+
71
+ override prepareBaseData ( ) : void ;
72
+
73
+ override prepareDerivedData ( ) : void ;
74
+
75
+ /**
76
+ * Update derived Active Effect duration data.
77
+ * Configure the remaining and label properties to be getters which lazily recompute only when necessary.
78
+ */
79
+ updateDuration ( ) : EffectDurationData ;
80
+
81
+ /**
82
+ * Determine whether the ActiveEffect requires a duration update.
83
+ * True if the worldTime has changed for an effect whose duration is tracked in seconds.
84
+ * True if the combat turn has changed for an effect tracked in turns where the effect target is a combatant.
85
+ */
86
+ protected _requiresDurationUpdate ( ) : boolean ;
87
+
88
+ /**
89
+ * Compute derived data related to active effect duration.
90
+ */
91
+ _prepareDuration ( ) : {
92
+ type : string ;
93
+ duration : number | null ;
94
+ remaining : number | null ;
95
+ label : string ;
96
+ _worldTime ?: number ;
97
+ _combatTime ?: number ;
98
+ } ;
26
99
27
100
/**
28
101
* Format a round+turn combination as a decimal
@@ -45,100 +118,70 @@ declare global {
45
118
*/
46
119
protected _getDurationLabel ( rounds : number , turns : number ) : string ;
47
120
48
- /** Describe whether the ActiveEffect has a temporary duration based on combat turns or rounds. */
121
+ /**
122
+ * Describe whether the ActiveEffect has a temporary duration based on combat turns or rounds.
123
+ */
49
124
get isTemporary ( ) : boolean ;
50
125
51
- /** A cached property for obtaining the source name */
52
- get sourceName ( ) : string ;
53
-
54
126
/**
55
- * An instance of the ActiveEffectConfig sheet to use for this ActiveEffect instance.
56
- * The reference to the sheet is cached so the same sheet instance is reused.
127
+ * A cached property for obtaining the source name
57
128
*/
58
- override get sheet ( ) : ActiveEffectConfig < this > ;
129
+ get sourceName ( ) : string ;
59
130
60
131
/* -------------------------------------------- */
61
132
/* Methods */
62
133
/* -------------------------------------------- */
63
134
64
135
/**
65
- * Apply this ActiveEffect to a provided Actor.
66
- * @param actor The Actor to whom this effect should be applied
67
- * @param change The change data being applied
68
- * @return The resulting applied value
136
+ * Apply EffectChangeData to a field within a DataModel.
137
+ * @param model The model instance.
138
+ * @param change The change to apply.
139
+ * @param field The field. If not supplied, it will be retrieved from the supplied model.
140
+ * @returns The updated value.
69
141
*/
70
- apply (
71
- actor : Actor < TokenDocument > ,
72
- change : ActiveEffectSource [ "changes" ] [ number ] ,
142
+ static applyField (
143
+ model : foundry . abstract . Document ,
144
+ change : EffectChangeData ,
145
+ field ?: foundry . data . fields . DataField ,
73
146
) : unknown ;
74
147
75
148
/**
76
- * Apply an ActiveEffect that uses an ADD application mode.
77
- * The way that effects are added depends on the data type of the current value.
78
- *
79
- * If the current value is null, the change value is assigned directly.
80
- * If the current type is a string, the change value is concatenated.
81
- * If the current type is a number, the change value is cast to numeric and added.
82
- * If the current type is an array, the change value is appended to the existing array if it matches in type.
83
- *
84
- * @param actor The Actor to whom this effect should be applied
85
- * @param change The change data being applied
86
- * @return The resulting applied value
87
- */
88
- protected _applyAdd (
89
- actor : Actor < TokenDocument > ,
90
- change : ActiveEffectSource [ "changes" ] [ number ] ,
91
- ) : unknown ;
92
-
93
- /**
94
- * Apply an ActiveEffect that uses a MULTIPLY application mode.
95
- * Changes which MULTIPLY must be numeric to allow for multiplication.
149
+ * Apply this ActiveEffect to a provided Actor.
150
+ * TODO: This method is poorly conceived. Its functionality is static, applying a provided change to an Actor
151
+ * TODO: When we revisit this in Active Effects V2 this should become an Actor method, or a static method
96
152
* @param actor The Actor to whom this effect should be applied
97
153
* @param change The change data being applied
98
- * @return The resulting applied value
154
+ * @returns An object of property paths and their updated values.
99
155
*/
100
- protected _applyMultiply (
101
- actor : Actor < TokenDocument > ,
102
- change : ActiveEffectSource [ "changes" ] [ number ] ,
103
- ) : unknown ;
156
+ apply ( actor : Actor , change : EffectChangeData ) : Record < string , unknown > ;
104
157
105
158
/**
106
- * Apply an ActiveEffect that uses an OVERRIDE application mode.
107
- * Numeric data is overridden by numbers, while other data types are overridden by any value
108
- * @param actor The Actor to whom this effect should be applied
109
- * @param change The change data being applied
110
- * @return The resulting applied value
159
+ * Apply this ActiveEffect to a provided Actor using a heuristic to infer the value types based on the current value
160
+ * and/or the default value in the template.json.
161
+ * @param actor The Actor to whom this effect should be applied.
162
+ * @param change The change data being applied.
163
+ * @param changes The aggregate update paths and their updated values.
111
164
*/
112
- protected _applyOverride (
113
- actor : Actor < TokenDocument > ,
114
- change : ActiveEffectSource [ "changes" ] [ number ] ,
115
- ) : unknown ;
165
+ protected _applyLegacy (
166
+ actor : Actor ,
167
+ change : EffectChangeData ,
168
+ changes : Record < string , unknown > ,
169
+ ) : void ;
116
170
117
171
/**
118
- * Apply an ActiveEffect that uses an UPGRADE, or DOWNGRADE application mode.
119
- * Changes which UPGRADE or DOWNGRADE must be numeric to allow for comparison.
120
- * @param actor The Actor to whom this effect should be applied
121
- * @param change The change data being applied
122
- * @return The resulting applied value
172
+ * Retrieve the initial duration configuration.
123
173
*/
124
- protected _applyUpgrade (
125
- actor : Actor < TokenDocument > ,
126
- change : ActiveEffectSource [ "changes" ] [ number ] ,
127
- ) : unknown ;
174
+ static getInitialDuration ( ) : {
175
+ startTime : number ;
176
+ startRound ?: number ;
177
+ startTurn ?: number ;
178
+ } ;
128
179
129
- /**
130
- * Apply an ActiveEffect that uses a CUSTOM application mode.
131
- * @param actor The Actor to whom this effect should be applied
132
- * @param change The change data being applied
133
- * @return The resulting applied value
134
- */
135
- protected _applyCustom (
136
- actor : Actor < TokenDocument > ,
137
- change : ActiveEffectSource [ "changes" ] [ number ] ,
138
- ) : unknown ;
180
+ /* -------------------------------------------- */
181
+ /* Flag Operations */
182
+ /* -------------------------------------------- */
139
183
140
- /** Get the name of the source of the Active Effect */
141
- protected _getSourceName ( ) : Promise < string > ;
184
+ override getFlag ( scope : string , key : string ) : unknown ;
142
185
143
186
/* -------------------------------------------- */
144
187
/* Event Handlers */
@@ -149,6 +192,36 @@ declare global {
149
192
operation : DatabaseCreateOperation < TParent > ,
150
193
user : User ,
151
194
) : Promise < boolean | void > ;
195
+
196
+ protected override _onCreate (
197
+ data : this[ "_source" ] ,
198
+ options : DatabaseCreateOperation < TParent > ,
199
+ userId : string ,
200
+ ) : void ;
201
+
202
+ override _preUpdate (
203
+ changed : Record < string , unknown > ,
204
+ options : DatabaseUpdateOperation < TParent > ,
205
+ user : User ,
206
+ ) : Promise < boolean | void > ;
207
+
208
+ override _onUpdate (
209
+ changed : Record < string , unknown > ,
210
+ options : DatabaseUpdateOperation < TParent > ,
211
+ userId : string ,
212
+ ) : void ;
213
+
214
+ /** @inheritDoc */
215
+ _onDelete (
216
+ options : DatabaseDeleteOperation < TParent > ,
217
+ userId : string ,
218
+ ) : void ;
219
+
220
+ /**
221
+ * Display changes to active effects as scrolling Token status text.
222
+ * @param enabled Is the active effect currently enabled?
223
+ */
224
+ protected _displayScrollingStatus ( enabled : boolean ) : void ;
152
225
}
153
226
154
227
interface ActiveEffect < TParent extends Actor | Item | null >
0 commit comments