@@ -12,118 +12,117 @@ import Pokemon from "./pokemon"
12
12
const SHARDS_PER_ENCOUNTER = 50
13
13
14
14
export default class UnownManager {
15
+ uid : string
16
+ scene : GameScene
17
+ animationManager : AnimationManager
18
+
19
+ constructor (
20
+ scene : GameScene ,
21
+ animationManager : AnimationManager ,
15
22
uid : string
16
- scene : GameScene
17
- animationManager : AnimationManager
18
-
19
- constructor (
20
- scene : GameScene ,
21
- animationManager : AnimationManager ,
22
- uid : string
23
- ) {
24
- this . uid = uid
25
- this . scene = scene
26
- this . animationManager = animationManager
27
- }
23
+ ) {
24
+ this . uid = uid
25
+ this . scene = scene
26
+ this . animationManager = animationManager
27
+ }
28
28
29
- onNewPickPhase ( ) {
30
- /* with 28 characters to unlock, expected number of encounters to
31
- complete the collection are 28*sum(i=1..28, 1/i) = 110
32
- We aim for 120 games to complete the collection, with an average duration
33
- of 25 stages per game, hence a prob of random unown encounter of
34
- 110 / (120*25) ~= 0,037 */
35
- if ( Math . random ( ) < 0.037 ) {
36
- setTimeout ( ( ) => this . addWanderingUnown ( ) , Math . round ( ( 5 + 15 * Math . random ( ) ) * 1000 ) )
37
- }
38
- }
29
+ addWanderingUnown ( ) {
30
+ const unowns = ( Object . keys ( PkmFamily ) as Pkm [ ] ) . filter (
31
+ ( pkm ) => PkmFamily [ pkm ] === Pkm . UNOWN_A
32
+ )
33
+ const [ startX , endX ] = coinflip ( )
34
+ ? [ - 100 , + window . innerWidth + 100 ]
35
+ : [ + window . innerWidth + 100 , - 100 ]
36
+ const [ startY , endY ] = [
37
+ 100 + Math . round ( Math . random ( ) * 400 ) ,
38
+ 100 + Math . round ( Math . random ( ) * 400 )
39
+ ]
39
40
40
- addWanderingUnown ( ) {
41
- const unowns = ( Object . keys ( PkmFamily ) as Pkm [ ] ) . filter ( pkm => PkmFamily [ pkm ] === Pkm . UNOWN_A )
42
- const [ startX , endX ] = coinflip ( ) ? [ - 100 , + window . innerWidth + 100 ] : [ + window . innerWidth + 100 , - 100 ]
43
- const [ startY , endY ] = [ 100 + Math . round ( Math . random ( ) * 400 ) , 100 + Math . round ( Math . random ( ) * 400 ) ]
41
+ const unown = new Pokemon (
42
+ this . scene ,
43
+ startX ,
44
+ startY ,
45
+ PokemonFactory . createPokemonFromName ( pickRandomIn ( unowns ) ) ,
46
+ "unown" ,
47
+ false
48
+ )
49
+ this . animationManager . animatePokemon ( unown , PokemonActionState . IDLE )
44
50
45
- const unown = new Pokemon (
46
- this . scene ,
47
- startX ,
48
- startY ,
49
- PokemonFactory . createPokemonFromName ( pickRandomIn ( unowns ) ) ,
50
- "unown" ,
51
- false
52
- )
53
- this . animationManager . animatePokemon ( unown , PokemonActionState . IDLE )
54
-
55
- const tween = this . scene . tweens . add ( {
56
- targets : unown ,
57
- x : endX ,
58
- y : endY ,
59
- ease : "Linear" ,
60
- duration : 5000 ,
61
- onComplete : ( ) => {
62
- if ( unown ) {
63
- unown . destroy ( )
64
- }
51
+ const tween = this . scene . tweens . add ( {
52
+ targets : unown ,
53
+ x : endX ,
54
+ y : endY ,
55
+ ease : "Linear" ,
56
+ duration : 5000 ,
57
+ onComplete : ( ) => {
58
+ if ( unown ) {
59
+ unown . destroy ( )
65
60
}
66
- } )
61
+ }
62
+ } )
67
63
68
- unown . isDisabled = true
69
- unown . sprite . setInteractive ( )
70
- unown . sprite . on ( 'pointerdown' , ( pointer ) => {
71
- getGameContainer ( ) . room . send ( Transfer . UNOWN_ENCOUNTER , unown . index )
72
- this . displayShardGain ( [ pointer . x , pointer . y ] , unown . index )
73
- tween . stop ( )
74
- unown . destroy ( )
75
- } )
64
+ unown . isDisabled = true
65
+ unown . sprite . setInteractive ( )
66
+ unown . sprite . on ( "pointerdown" , ( pointer ) => {
67
+ getGameContainer ( ) . room . send ( Transfer . UNOWN_ENCOUNTER , unown . index )
68
+ this . displayShardGain ( [ pointer . x , pointer . y ] , unown . index )
69
+ tween . stop ( )
70
+ unown . destroy ( )
71
+ } )
72
+ }
73
+
74
+ displayShardGain ( coordinates : number [ ] , index : string ) {
75
+ const textStyle = {
76
+ fontSize : "25px" ,
77
+ fontFamily : "Verdana" ,
78
+ color : "#fff" ,
79
+ align : "center" ,
80
+ strokeThickness : 2 ,
81
+ stroke : "#000"
76
82
}
77
83
78
- displayShardGain (
79
- coordinates : number [ ] ,
80
- index : string
81
- ) {
82
- const textStyle = {
83
- fontSize : "25px" ,
84
- fontFamily : "Verdana" ,
85
- color : "#fff" ,
86
- align : "center" ,
87
- strokeThickness : 2 ,
88
- stroke : "#000"
89
- }
90
-
91
- const image = this . scene . add . existing (
92
- new GameObjects . Image ( this . scene , 0 , 0 , `portrait-${ index } ` )
93
- . setScale ( 0.5 , 0.5 )
94
- . setOrigin ( 0 , 0 )
95
- )
96
- const text = this . scene . add . existing (
97
- new GameObjects . Text ( this . scene , 25 , 0 , SHARDS_PER_ENCOUNTER . toString ( ) , textStyle )
84
+ const image = this . scene . add . existing (
85
+ new GameObjects . Image ( this . scene , 0 , 0 , `portrait-${ index } ` )
86
+ . setScale ( 0.5 , 0.5 )
87
+ . setOrigin ( 0 , 0 )
88
+ )
89
+ const text = this . scene . add . existing (
90
+ new GameObjects . Text (
91
+ this . scene ,
92
+ 25 ,
93
+ 0 ,
94
+ SHARDS_PER_ENCOUNTER . toString ( ) ,
95
+ textStyle
98
96
)
99
- image . setDepth ( 9 )
100
- text . setDepth ( 10 )
101
-
102
- const container = this . scene . add . existing (
103
- new GameObjects . Container (
104
- this . scene ,
105
- coordinates [ 0 ] ,
106
- coordinates [ 1 ] - 50 ,
107
- [ text , image ]
108
- )
97
+ )
98
+ image . setDepth ( 9 )
99
+ text . setDepth ( 10 )
100
+
101
+ const container = this . scene . add . existing (
102
+ new GameObjects . Container (
103
+ this . scene ,
104
+ coordinates [ 0 ] ,
105
+ coordinates [ 1 ] - 50 ,
106
+ [ text , image ]
109
107
)
110
-
111
- this . scene . add . tween ( {
112
- targets : [ container ] ,
113
- ease : "linear" ,
114
- duration : 1500 ,
115
- delay : 0 ,
116
- alpha : {
117
- getStart : ( ) => 1 ,
118
- getEnd : ( ) => 0
119
- } ,
120
- y : {
121
- getStart : ( ) => coordinates [ 1 ] - 50 ,
122
- getEnd : ( ) => coordinates [ 1 ] - 110
123
- } ,
124
- onComplete : ( ) => {
125
- container . destroy ( true )
126
- }
127
- } )
128
- }
129
- }
108
+ )
109
+
110
+ this . scene . add . tween ( {
111
+ targets : [ container ] ,
112
+ ease : "linear" ,
113
+ duration : 1500 ,
114
+ delay : 0 ,
115
+ alpha : {
116
+ getStart : ( ) => 1 ,
117
+ getEnd : ( ) => 0
118
+ } ,
119
+ y : {
120
+ getStart : ( ) => coordinates [ 1 ] - 50 ,
121
+ getEnd : ( ) => coordinates [ 1 ] - 110
122
+ } ,
123
+ onComplete : ( ) => {
124
+ container . destroy ( true )
125
+ }
126
+ } )
127
+ }
128
+ }
0 commit comments