1- import { LocationalItemModel } from "./components/locational" ;
1+ import { LocationalItemModel } from "./components/locational" ;
2+
23let fields = foundry . data . fields ;
34
4- export class InjuryModel extends LocationalItemModel
5+ export class InjuryModel extends LocationalItemModel
56{
6- static defineSchema ( )
7+ static defineSchema ( )
8+ {
9+ let schema = super . defineSchema ( ) ;
10+ schema . penalty = new fields . SchemaField ( {
11+ value : new fields . StringField ( ) ,
12+ } )
13+ schema . duration = new fields . SchemaField ( {
14+ value : new fields . StringField ( ) ,
15+ active : new fields . BooleanField ( ) ,
16+ permanent : new fields . BooleanField ( ) ,
17+ } ) ;
18+ return schema ;
19+ }
20+
21+ /**
22+ * Used to identify an Item as one being a child or instance of InjuryModel
23+ *
24+ * @final
25+ * @returns {boolean }
26+ */
27+ get isInjury ( ) {
28+ return true ;
29+ }
30+
31+ chatData ( ) {
32+ let properties = [ ] ;
33+ properties . push ( `<b>${ game . i18n . localize ( "Location" ) } </b>: ${ this . location . value } ` ) ;
34+ if ( this . penalty . value )
35+ properties . push ( `<b>${ game . i18n . localize ( "Penalty" ) } </b>: ${ this . penalty . value } ` ) ;
36+ return properties ;
37+ }
38+
39+ async increment ( ) {
40+ if ( this . duration . active )
741 {
8- let schema = super . defineSchema ( ) ;
9- schema . penalty = new fields . SchemaField ( {
10- value : new fields . StringField ( ) ,
11- } )
12- schema . duration = new fields . SchemaField ( {
13- value : new fields . StringField ( ) ,
14- active : new fields . BooleanField ( ) ,
15- permanent : new fields . BooleanField ( ) ,
16- } ) ;
17- return schema ;
42+ return await this . parent . update ( { "system.duration.value" : Number ( this . duration . value ) + 1 } )
1843 }
44+ }
45+
46+ async decrement ( ) {
47+ if ( isNaN ( this . duration . value ) ) {
48+ return await this . start ( ) ;
49+ }
50+
51+ let update = { } ;
52+ let duration = Number ( this . duration . value ) - 1 ;
1953
20- /**
21- * Used to identify an Item as one being a child or instance of InjuryModel
22- *
23- * @final
24- * @returns {boolean }
25- */
26- get isInjury ( ) {
27- return true ;
54+ if ( duration == 0 ) {
55+ return await this . finish ( ) ;
56+ } else {
57+ update [ "system.duration.value" ] = duration ;
2858 }
2959
30- chatData ( ) {
31- let properties = [ ] ;
32- properties . push ( `<b>${ game . i18n . localize ( "Location" ) } </b>: ${ this . location . value } ` ) ;
33- if ( this . penalty . value )
34- properties . push ( `<b>${ game . i18n . localize ( "Penalty" ) } </b>: ${ this . penalty . value } ` ) ;
35- return properties ;
36- }
60+ return await this . parent . update ( update ) ;
61+ }
62+
63+ async start ( ) {
64+ try {
65+ let roll = await new Roll ( this . duration . value , this . parent . actor ) . roll ( ) ;
66+ roll . toMessage ( { speaker : { alias : this . parent . actor . name } , flavor : this . parent . name } ) ;
67+
68+ return await this . parent . update ( {
69+ "system.duration.value" : roll . total ,
70+ "system.duration.active" : true
71+ } ) ;
72+ } catch ( error ) {
73+ return ui . notifications . error ( game . i18n . localize ( "ERROR.ParseInjury" ) ) ;
74+ }
75+ }
76+
77+ async finish ( ) {
78+ let msg = game . i18n . format ( "CHAT.InjuryFinish" , { injury : this . parent . name } ) ;
79+
80+ ChatMessage . create ( foundry . utils . mergeObject ( this . getMessageData ( msg ) , { whisper : ChatMessage . getWhisperRecipients ( "GM" ) } ) ) ;
81+
82+ await this . parent . delete ( ) ;
83+ }
3784
85+ getMessageData ( content = "" ) {
86+ return { content, speaker : { alias : this . parent . name } , flavor : this . parent . actor . name } ;
87+ }
3888}
0 commit comments